Fix "thread apply $conv_var" and misc other related problems
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
618f726f 2@c Copyright (C) 1988-2016 Free Software Foundation, Inc.
c906108c 3@c
5d161b24 4@c %**start of header
c906108c
SS
5@c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
6@c of @set vars. However, you can override filename with makeinfo -o.
7@setfilename gdb.info
8@c
43662968 9@c man begin INCLUDE
c906108c 10@include gdb-cfg.texi
43662968 11@c man end
c906108c 12@c
c906108c 13@settitle Debugging with @value{GDBN}
c906108c
SS
14@setchapternewpage odd
15@c %**end of header
16
17@iftex
18@c @smallbook
19@c @cropmarks
20@end iftex
21
22@finalout
00595b5e
EZ
23@c To avoid file-name clashes between index.html and Index.html, when
24@c the manual is produced on a Posix host and then moved to a
25@c case-insensitive filesystem (e.g., MS-Windows), we separate the
26@c indices into two: Concept Index and all the rest.
27@syncodeindex ky fn
28@syncodeindex tp fn
c906108c 29
41afff9a 30@c readline appendices use @vindex, @findex and @ftable,
48e934c6 31@c annotate.texi and gdbmi use @findex.
00595b5e 32@syncodeindex vr fn
c906108c
SS
33
34@c !!set GDB manual's edition---not the same as GDB version!
9fe8321b 35@c This is updated by GNU Press.
26829f2b 36@set EDITION Tenth
c906108c 37
87885426
FN
38@c !!set GDB edit command default editor
39@set EDITOR /bin/ex
c906108c 40
6c0e9fb3 41@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
c906108c 42
c906108c 43@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 44@c manuals to an info tree.
03727ca6 45@dircategory Software development
96a2c332 46@direntry
03727ca6 47* Gdb: (gdb). The GNU debugger.
6cb999f8 48* gdbserver: (gdb) Server. The GNU debugging server.
96a2c332
SS
49@end direntry
50
a67ec3f4 51@copying
43662968 52@c man begin COPYRIGHT
618f726f 53Copyright @copyright{} 1988-2016 Free Software Foundation, Inc.
c906108c 54
e9c75b65 55Permission is granted to copy, distribute and/or modify this document
4f5d9f07 56under the terms of the GNU Free Documentation License, Version 1.3 or
e9c75b65 57any later version published by the Free Software Foundation; with the
959acfd1
EZ
58Invariant Sections being ``Free Software'' and ``Free Software Needs
59Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
60and with the Back-Cover Texts as in (a) below.
c906108c 61
b8533aec
DJ
62(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
63this GNU Manual. Buying copies from GNU Press supports the FSF in
64developing GNU and promoting software freedom.''
43662968 65@c man end
a67ec3f4
JM
66@end copying
67
68@ifnottex
69This file documents the @sc{gnu} debugger @value{GDBN}.
70
71This is the @value{EDITION} Edition, of @cite{Debugging with
72@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
73@ifset VERSION_PACKAGE
74@value{VERSION_PACKAGE}
75@end ifset
76Version @value{GDBVN}.
77
78@insertcopying
79@end ifnottex
c906108c
SS
80
81@titlepage
82@title Debugging with @value{GDBN}
83@subtitle The @sc{gnu} Source-Level Debugger
c906108c 84@sp 1
c906108c 85@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
c16158bc
JM
86@ifset VERSION_PACKAGE
87@sp 1
88@subtitle @value{VERSION_PACKAGE}
89@end ifset
9e9c5ae7 90@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 91@page
c906108c
SS
92@tex
93{\parskip=0pt
c16158bc 94\hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
c906108c
SS
95\hfill {\it Debugging with @value{GDBN}}\par
96\hfill \TeX{}info \texinfoversion\par
97}
98@end tex
53a5351d 99
c906108c 100@vskip 0pt plus 1filll
c906108c 101Published by the Free Software Foundation @*
c02a867d
EZ
10251 Franklin Street, Fifth Floor,
103Boston, MA 02110-1301, USA@*
26829f2b 104ISBN 978-0-9831592-3-0 @*
e9c75b65 105
a67ec3f4 106@insertcopying
c906108c
SS
107@end titlepage
108@page
109
6c0e9fb3 110@ifnottex
6d2ebf8b
SS
111@node Top, Summary, (dir), (dir)
112
c906108c
SS
113@top Debugging with @value{GDBN}
114
115This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
c16158bc
JM
117This is the @value{EDITION} Edition, for @value{GDBN}
118@ifset VERSION_PACKAGE
119@value{VERSION_PACKAGE}
120@end ifset
121Version @value{GDBVN}.
c906108c 122
618f726f 123Copyright (C) 1988-2016 Free Software Foundation, Inc.
6d2ebf8b 124
3fb6a982
JB
125This edition of the GDB manual is dedicated to the memory of Fred
126Fish. Fred was a long-standing contributor to GDB and to Free
127software in general. We will miss him.
128
6d2ebf8b
SS
129@menu
130* Summary:: Summary of @value{GDBN}
131* Sample Session:: A sample @value{GDBN} session
132
133* Invocation:: Getting in and out of @value{GDBN}
134* Commands:: @value{GDBN} commands
135* Running:: Running programs under @value{GDBN}
136* Stopping:: Stopping and continuing
bacec72f 137* Reverse Execution:: Running programs backward
a2311334 138* Process Record and Replay:: Recording inferior's execution and replaying it
6d2ebf8b
SS
139* Stack:: Examining the stack
140* Source:: Examining source files
141* Data:: Examining data
edb3359d 142* Optimized Code:: Debugging optimized code
e2e0bcd1 143* Macros:: Preprocessor Macros
b37052ae 144* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 145* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
146
147* Languages:: Using @value{GDBN} with different languages
148
149* Symbols:: Examining the symbol table
150* Altering:: Altering execution
151* GDB Files:: @value{GDBN} files
152* Targets:: Specifying a debugging target
6b2f586d 153* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
154* Configurations:: Configuration-specific information
155* Controlling GDB:: Controlling @value{GDBN}
d57a3c85 156* Extending GDB:: Extending @value{GDBN}
21c294e6 157* Interpreters:: Command Interpreters
c8f4133a 158* TUI:: @value{GDBN} Text User Interface
6d2ebf8b 159* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
7162c0ca 160* GDB/MI:: @value{GDBN}'s Machine Interface.
c8f4133a 161* Annotations:: @value{GDBN}'s annotation interface.
4efc6507 162* JIT Interface:: Using the JIT debugging interface.
d1feda86 163* In-Process Agent:: In-Process Agent
6d2ebf8b
SS
164
165* GDB Bugs:: Reporting bugs in @value{GDBN}
6d2ebf8b 166
39037522
TT
167@ifset SYSTEM_READLINE
168* Command Line Editing: (rluserman). Command Line Editing
169* Using History Interactively: (history). Using History Interactively
170@end ifset
171@ifclear SYSTEM_READLINE
6d2ebf8b
SS
172* Command Line Editing:: Command Line Editing
173* Using History Interactively:: Using History Interactively
39037522 174@end ifclear
4ceed123 175* In Memoriam:: In Memoriam
0869d01b 176* Formatting Documentation:: How to format and print @value{GDBN} documentation
6d2ebf8b 177* Installing GDB:: Installing GDB
eb12ee30 178* Maintenance Commands:: Maintenance Commands
e0ce93ac 179* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 180* Agent Expressions:: The GDB Agent Expression Mechanism
23181151
DJ
181* Target Descriptions:: How targets can describe themselves to
182 @value{GDBN}
07e059b5
VP
183* Operating System Information:: Getting additional information from
184 the operating system
00bf0b85 185* Trace File Format:: GDB trace file format
90476074 186* Index Section Format:: .gdb_index section format
43662968 187* Man Pages:: Manual pages
aab4e0ec
AC
188* Copying:: GNU General Public License says
189 how you can copy and share GDB
6826cf00 190* GNU Free Documentation License:: The license for this documentation
00595b5e
EZ
191* Concept Index:: Index of @value{GDBN} concepts
192* Command and Variable Index:: Index of @value{GDBN} commands, variables,
193 functions, and Python data types
6d2ebf8b
SS
194@end menu
195
6c0e9fb3 196@end ifnottex
c906108c 197
449f3b6c 198@contents
449f3b6c 199
6d2ebf8b 200@node Summary
c906108c
SS
201@unnumbered Summary of @value{GDBN}
202
203The purpose of a debugger such as @value{GDBN} is to allow you to see what is
204going on ``inside'' another program while it executes---or what another
205program was doing at the moment it crashed.
206
207@value{GDBN} can do four main kinds of things (plus other things in support of
208these) to help you catch bugs in the act:
209
210@itemize @bullet
211@item
212Start your program, specifying anything that might affect its behavior.
213
214@item
215Make your program stop on specified conditions.
216
217@item
218Examine what has happened, when your program has stopped.
219
220@item
221Change things in your program, so you can experiment with correcting the
222effects of one bug and go on to learn about another.
223@end itemize
224
49efadf5 225You can use @value{GDBN} to debug programs written in C and C@t{++}.
79a6e687 226For more information, see @ref{Supported Languages,,Supported Languages}.
c906108c
SS
227For more information, see @ref{C,,C and C++}.
228
6aecb9c2
JB
229Support for D is partial. For information on D, see
230@ref{D,,D}.
231
cce74817 232@cindex Modula-2
e632838e
AC
233Support for Modula-2 is partial. For information on Modula-2, see
234@ref{Modula-2,,Modula-2}.
c906108c 235
f4b8a18d
KW
236Support for OpenCL C is partial. For information on OpenCL C, see
237@ref{OpenCL C,,OpenCL C}.
238
cce74817
JM
239@cindex Pascal
240Debugging Pascal programs which use sets, subranges, file variables, or
241nested functions does not currently work. @value{GDBN} does not support
242entering expressions, printing values, or similar features using Pascal
243syntax.
c906108c 244
c906108c
SS
245@cindex Fortran
246@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 247it may be necessary to refer to some variables with a trailing
cce74817 248underscore.
c906108c 249
b37303ee
AF
250@value{GDBN} can be used to debug programs written in Objective-C,
251using either the Apple/NeXT or the GNU Objective-C runtime.
252
c906108c
SS
253@menu
254* Free Software:: Freely redistributable software
984359d2 255* Free Documentation:: Free Software Needs Free Documentation
c906108c
SS
256* Contributors:: Contributors to GDB
257@end menu
258
6d2ebf8b 259@node Free Software
79a6e687 260@unnumberedsec Free Software
c906108c 261
5d161b24 262@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
263General Public License
264(GPL). The GPL gives you the freedom to copy or adapt a licensed
265program---but every person getting a copy also gets with it the
266freedom to modify that copy (which means that they must get access to
267the source code), and the freedom to distribute further copies.
268Typical software companies use copyrights to limit your freedoms; the
269Free Software Foundation uses the GPL to preserve these freedoms.
270
271Fundamentally, the General Public License is a license which says that
272you have these freedoms and that you cannot take these freedoms away
273from anyone else.
274
984359d2 275@node Free Documentation
2666264b 276@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
277
278The biggest deficiency in the free software community today is not in
279the software---it is the lack of good free documentation that we can
280include with the free software. Many of our most important
281programs do not come with free reference manuals and free introductory
282texts. Documentation is an essential part of any software package;
283when an important free software package does not come with a free
284manual and a free tutorial, that is a major gap. We have many such
285gaps today.
286
287Consider Perl, for instance. The tutorial manuals that people
288normally use are non-free. How did this come about? Because the
289authors of those manuals published them with restrictive terms---no
290copying, no modification, source files not available---which exclude
291them from the free software world.
292
293That wasn't the first time this sort of thing happened, and it was far
294from the last. Many times we have heard a GNU user eagerly describe a
295manual that he is writing, his intended contribution to the community,
296only to learn that he had ruined everything by signing a publication
297contract to make it non-free.
298
299Free documentation, like free software, is a matter of freedom, not
300price. The problem with the non-free manual is not that publishers
301charge a price for printed copies---that in itself is fine. (The Free
302Software Foundation sells printed copies of manuals, too.) The
303problem is the restrictions on the use of the manual. Free manuals
304are available in source code form, and give you permission to copy and
305modify. Non-free manuals do not allow this.
306
307The criteria of freedom for a free manual are roughly the same as for
308free software. Redistribution (including the normal kinds of
309commercial redistribution) must be permitted, so that the manual can
310accompany every copy of the program, both on-line and on paper.
311
312Permission for modification of the technical content is crucial too.
313When people modify the software, adding or changing features, if they
314are conscientious they will change the manual too---so they can
315provide accurate and clear documentation for the modified program. A
316manual that leaves you no choice but to write a new manual to document
317a changed version of the program is not really available to our
318community.
319
320Some kinds of limits on the way modification is handled are
321acceptable. For example, requirements to preserve the original
322author's copyright notice, the distribution terms, or the list of
323authors, are ok. It is also no problem to require modified versions
324to include notice that they were modified. Even entire sections that
325may not be deleted or changed are acceptable, as long as they deal
326with nontechnical topics (like this one). These kinds of restrictions
327are acceptable because they don't obstruct the community's normal use
328of the manual.
329
330However, it must be possible to modify all the @emph{technical}
331content of the manual, and then distribute the result in all the usual
332media, through all the usual channels. Otherwise, the restrictions
333obstruct the use of the manual, it is not free, and we need another
334manual to replace it.
335
336Please spread the word about this issue. Our community continues to
337lose manuals to proprietary publishing. If we spread the word that
338free software needs free reference manuals and free tutorials, perhaps
339the next person who wants to contribute by writing documentation will
340realize, before it is too late, that only free manuals contribute to
341the free software community.
342
343If you are writing documentation, please insist on publishing it under
344the GNU Free Documentation License or another free documentation
345license. Remember that this decision requires your approval---you
346don't have to let the publisher decide. Some commercial publishers
347will use a free license if you insist, but they will not propose the
348option; it is up to you to raise the issue and say firmly that this is
349what you want. If the publisher you are dealing with refuses, please
350try other publishers. If you're not sure whether a proposed license
42584a72 351is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
352
353You can encourage commercial publishers to sell more free, copylefted
354manuals and tutorials by buying them, and particularly by buying
355copies from the publishers that paid for their writing or for major
356improvements. Meanwhile, try to avoid buying non-free documentation
357at all. Check the distribution terms of a manual before you buy it,
358and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
359Check the history of the book, and try to reward the publishers that
360have paid or pay the authors to work on it.
959acfd1
EZ
361
362The Free Software Foundation maintains a list of free documentation
363published by other publishers, at
364@url{http://www.fsf.org/doc/other-free-books.html}.
365
6d2ebf8b 366@node Contributors
96a2c332
SS
367@unnumberedsec Contributors to @value{GDBN}
368
369Richard Stallman was the original author of @value{GDBN}, and of many
370other @sc{gnu} programs. Many others have contributed to its
371development. This section attempts to credit major contributors. One
372of the virtues of free software is that everyone is free to contribute
373to it; with regret, we cannot actually acknowledge everyone here. The
374file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
375blow-by-blow account.
376
377Changes much prior to version 2.0 are lost in the mists of time.
378
379@quotation
380@emph{Plea:} Additions to this section are particularly welcome. If you
381or your friends (or enemies, to be evenhanded) have been unfairly
382omitted from this list, we would like to add your names!
383@end quotation
384
385So that they may not regard their many labors as thankless, we
386particularly thank those who shepherded @value{GDBN} through major
387releases:
7ba3cf9c 388Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
389Jim Blandy (release 4.18);
390Jason Molenda (release 4.17);
391Stan Shebs (release 4.14);
392Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
393Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
394John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
395Jim Kingdon (releases 3.5, 3.4, and 3.3);
396and Randy Smith (releases 3.2, 3.1, and 3.0).
397
398Richard Stallman, assisted at various times by Peter TerMaat, Chris
399Hanson, and Richard Mlynarik, handled releases through 2.8.
400
b37052ae
EZ
401Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
402in @value{GDBN}, with significant additional contributions from Per
403Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
404demangler. Early work on C@t{++} was by Peter TerMaat (who also did
405much general update work leading to release 3.0).
c906108c 406
b37052ae 407@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
408object-file formats; BFD was a joint project of David V.
409Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
410
411David Johnson wrote the original COFF support; Pace Willison did
412the original support for encapsulated COFF.
413
0179ffac 414Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
415
416Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
417Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
418support.
419Jean-Daniel Fekete contributed Sun 386i support.
420Chris Hanson improved the HP9000 support.
421Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
422David Johnson contributed Encore Umax support.
423Jyrki Kuoppala contributed Altos 3068 support.
424Jeff Law contributed HP PA and SOM support.
425Keith Packard contributed NS32K support.
426Doug Rabson contributed Acorn Risc Machine support.
427Bob Rusk contributed Harris Nighthawk CX-UX support.
428Chris Smith contributed Convex support (and Fortran debugging).
429Jonathan Stone contributed Pyramid support.
430Michael Tiemann contributed SPARC support.
431Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
432Pace Willison contributed Intel 386 support.
433Jay Vosburgh contributed Symmetry support.
a37295f9 434Marko Mlinar contributed OpenRISC 1000 support.
c906108c 435
1104b9e7 436Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
437
438Rich Schaefer and Peter Schauer helped with support of SunOS shared
439libraries.
440
441Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
442about several machine instruction sets.
443
444Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
445remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
446contributed remote debugging modules for the i960, VxWorks, A29K UDI,
447and RDI targets, respectively.
448
449Brian Fox is the author of the readline libraries providing
450command-line editing and command history.
451
7a292a7a
SS
452Andrew Beers of SUNY Buffalo wrote the language-switching code, the
453Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 454
5d161b24 455Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 456He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 457symbols.
c906108c 458
f24c5e49
KI
459Hitachi America (now Renesas America), Ltd. sponsored the support for
460H8/300, H8/500, and Super-H processors.
c906108c
SS
461
462NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
463
f24c5e49
KI
464Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
465processors.
c906108c
SS
466
467Toshiba sponsored the support for the TX39 Mips processor.
468
469Matsushita sponsored the support for the MN10200 and MN10300 processors.
470
96a2c332 471Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
472
473Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
474watchpoints.
475
476Michael Snyder added support for tracepoints.
477
478Stu Grossman wrote gdbserver.
479
480Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 481nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
482
483The following people at the Hewlett-Packard Company contributed
484support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 485(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
486compiler, and the Text User Interface (nee Terminal User Interface):
487Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
488Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
489provided HP-specific information in this manual.
c906108c 490
b37052ae
EZ
491DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
492Robert Hoehne made significant contributions to the DJGPP port.
493
96a2c332
SS
494Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
495development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
496fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
497Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
498Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
499Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
500Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
501addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
502JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
503Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
504Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
505Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
506Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
507Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
508Zuhn have made contributions both large and small.
c906108c 509
ffed4509
AC
510Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
511Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
512
e2e0bcd1
JB
513Jim Blandy added support for preprocessor macros, while working for Red
514Hat.
c906108c 515
a9967aef
AC
516Andrew Cagney designed @value{GDBN}'s architecture vector. Many
517people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
518Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
519Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
520Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
521with the migration of old architectures to this new framework.
522
c5e30d01
AC
523Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
524unwinder framework, this consisting of a fresh new design featuring
525frame IDs, independent frame sniffers, and the sentinel frame. Mark
526Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
527libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
db2e3e2e 528trad unwinders. The architecture-specific changes, each involving a
c5e30d01
AC
529complete rewrite of the architecture's frame code, were carried out by
530Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
531Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
532Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
533Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
534Weigand.
535
ca3bf3bd
DJ
536Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
537Tensilica, Inc.@: contributed support for Xtensa processors. Others
538who have worked on the Xtensa port of @value{GDBN} in the past include
539Steve Tjiang, John Newlin, and Scott Foehner.
540
08be9d71
ME
541Michael Eager and staff of Xilinx, Inc., contributed support for the
542Xilinx MicroBlaze architecture.
543
6d2ebf8b 544@node Sample Session
c906108c
SS
545@chapter A Sample @value{GDBN} Session
546
547You can use this manual at your leisure to read all about @value{GDBN}.
548However, a handful of commands are enough to get started using the
549debugger. This chapter illustrates those commands.
550
551@iftex
552In this sample session, we emphasize user input like this: @b{input},
553to make it easier to pick out from the surrounding output.
554@end iftex
555
556@c FIXME: this example may not be appropriate for some configs, where
557@c FIXME...primary interest is in remote use.
558
559One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
560processor) exhibits the following bug: sometimes, when we change its
561quote strings from the default, the commands used to capture one macro
562definition within another stop working. In the following short @code{m4}
563session, we define a macro @code{foo} which expands to @code{0000}; we
564then use the @code{m4} built-in @code{defn} to define @code{bar} as the
565same thing. However, when we change the open quote string to
566@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
567procedure fails to define a new synonym @code{baz}:
568
569@smallexample
570$ @b{cd gnu/m4}
571$ @b{./m4}
572@b{define(foo,0000)}
573
574@b{foo}
5750000
576@b{define(bar,defn(`foo'))}
577
578@b{bar}
5790000
580@b{changequote(<QUOTE>,<UNQUOTE>)}
581
582@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
583@b{baz}
c8aa23ab 584@b{Ctrl-d}
c906108c
SS
585m4: End of input: 0: fatal error: EOF in string
586@end smallexample
587
588@noindent
589Let us use @value{GDBN} to try to see what is going on.
590
c906108c
SS
591@smallexample
592$ @b{@value{GDBP} m4}
593@c FIXME: this falsifies the exact text played out, to permit smallbook
594@c FIXME... format to come out better.
595@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 596 of it under certain conditions; type "show copying" to see
c906108c 597 the conditions.
5d161b24 598There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
599 for details.
600
601@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
602(@value{GDBP})
603@end smallexample
c906108c
SS
604
605@noindent
606@value{GDBN} reads only enough symbol data to know where to find the
607rest when needed; as a result, the first prompt comes up very quickly.
608We now tell @value{GDBN} to use a narrower display width than usual, so
609that examples fit in this manual.
610
611@smallexample
612(@value{GDBP}) @b{set width 70}
613@end smallexample
614
615@noindent
616We need to see how the @code{m4} built-in @code{changequote} works.
617Having looked at the source, we know the relevant subroutine is
618@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
619@code{break} command.
620
621@smallexample
622(@value{GDBP}) @b{break m4_changequote}
623Breakpoint 1 at 0x62f4: file builtin.c, line 879.
624@end smallexample
625
626@noindent
627Using the @code{run} command, we start @code{m4} running under @value{GDBN}
628control; as long as control does not reach the @code{m4_changequote}
629subroutine, the program runs as usual:
630
631@smallexample
632(@value{GDBP}) @b{run}
633Starting program: /work/Editorial/gdb/gnu/m4/m4
634@b{define(foo,0000)}
635
636@b{foo}
6370000
638@end smallexample
639
640@noindent
641To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
642suspends execution of @code{m4}, displaying information about the
643context where it stops.
644
645@smallexample
646@b{changequote(<QUOTE>,<UNQUOTE>)}
647
5d161b24 648Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
649 at builtin.c:879
650879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
651@end smallexample
652
653@noindent
654Now we use the command @code{n} (@code{next}) to advance execution to
655the next line of the current function.
656
657@smallexample
658(@value{GDBP}) @b{n}
659882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
660 : nil,
661@end smallexample
662
663@noindent
664@code{set_quotes} looks like a promising subroutine. We can go into it
665by using the command @code{s} (@code{step}) instead of @code{next}.
666@code{step} goes to the next line to be executed in @emph{any}
667subroutine, so it steps into @code{set_quotes}.
668
669@smallexample
670(@value{GDBP}) @b{s}
671set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
672 at input.c:530
673530 if (lquote != def_lquote)
674@end smallexample
675
676@noindent
677The display that shows the subroutine where @code{m4} is now
678suspended (and its arguments) is called a stack frame display. It
679shows a summary of the stack. We can use the @code{backtrace}
680command (which can also be spelled @code{bt}), to see where we are
681in the stack as a whole: the @code{backtrace} command displays a
682stack frame for each active subroutine.
683
684@smallexample
685(@value{GDBP}) @b{bt}
686#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
687 at input.c:530
5d161b24 688#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
689 at builtin.c:882
690#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
691#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
692 at macro.c:71
693#4 0x79dc in expand_input () at macro.c:40
694#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
695@end smallexample
696
697@noindent
698We step through a few more lines to see what happens. The first two
699times, we can use @samp{s}; the next two times we use @code{n} to avoid
700falling into the @code{xstrdup} subroutine.
701
702@smallexample
703(@value{GDBP}) @b{s}
7040x3b5c 532 if (rquote != def_rquote)
705(@value{GDBP}) @b{s}
7060x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
707def_lquote : xstrdup(lq);
708(@value{GDBP}) @b{n}
709536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
710 : xstrdup(rq);
711(@value{GDBP}) @b{n}
712538 len_lquote = strlen(rquote);
713@end smallexample
714
715@noindent
716The last line displayed looks a little odd; we can examine the variables
717@code{lquote} and @code{rquote} to see if they are in fact the new left
718and right quotes we specified. We use the command @code{p}
719(@code{print}) to see their values.
720
721@smallexample
722(@value{GDBP}) @b{p lquote}
723$1 = 0x35d40 "<QUOTE>"
724(@value{GDBP}) @b{p rquote}
725$2 = 0x35d50 "<UNQUOTE>"
726@end smallexample
727
728@noindent
729@code{lquote} and @code{rquote} are indeed the new left and right quotes.
730To look at some context, we can display ten lines of source
731surrounding the current line with the @code{l} (@code{list}) command.
732
733@smallexample
734(@value{GDBP}) @b{l}
735533 xfree(rquote);
736534
737535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
738 : xstrdup (lq);
739536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
740 : xstrdup (rq);
741537
742538 len_lquote = strlen(rquote);
743539 len_rquote = strlen(lquote);
744540 @}
745541
746542 void
747@end smallexample
748
749@noindent
750Let us step past the two lines that set @code{len_lquote} and
751@code{len_rquote}, and then examine the values of those variables.
752
753@smallexample
754(@value{GDBP}) @b{n}
755539 len_rquote = strlen(lquote);
756(@value{GDBP}) @b{n}
757540 @}
758(@value{GDBP}) @b{p len_lquote}
759$3 = 9
760(@value{GDBP}) @b{p len_rquote}
761$4 = 7
762@end smallexample
763
764@noindent
765That certainly looks wrong, assuming @code{len_lquote} and
766@code{len_rquote} are meant to be the lengths of @code{lquote} and
767@code{rquote} respectively. We can set them to better values using
768the @code{p} command, since it can print the value of
769any expression---and that expression can include subroutine calls and
770assignments.
771
772@smallexample
773(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
774$5 = 7
775(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
776$6 = 9
777@end smallexample
778
779@noindent
780Is that enough to fix the problem of using the new quotes with the
781@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
782executing with the @code{c} (@code{continue}) command, and then try the
783example that caused trouble initially:
784
785@smallexample
786(@value{GDBP}) @b{c}
787Continuing.
788
789@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
790
791baz
7920000
793@end smallexample
794
795@noindent
796Success! The new quotes now work just as well as the default ones. The
797problem seems to have been just the two typos defining the wrong
798lengths. We allow @code{m4} exit by giving it an EOF as input:
799
800@smallexample
c8aa23ab 801@b{Ctrl-d}
c906108c
SS
802Program exited normally.
803@end smallexample
804
805@noindent
806The message @samp{Program exited normally.} is from @value{GDBN}; it
807indicates @code{m4} has finished executing. We can end our @value{GDBN}
808session with the @value{GDBN} @code{quit} command.
809
810@smallexample
811(@value{GDBP}) @b{quit}
812@end smallexample
c906108c 813
6d2ebf8b 814@node Invocation
c906108c
SS
815@chapter Getting In and Out of @value{GDBN}
816
817This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 818The essentials are:
c906108c 819@itemize @bullet
5d161b24 820@item
53a5351d 821type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 822@item
c8aa23ab 823type @kbd{quit} or @kbd{Ctrl-d} to exit.
c906108c
SS
824@end itemize
825
826@menu
827* Invoking GDB:: How to start @value{GDBN}
828* Quitting GDB:: How to quit @value{GDBN}
829* Shell Commands:: How to use shell commands inside @value{GDBN}
79a6e687 830* Logging Output:: How to log @value{GDBN}'s output to a file
c906108c
SS
831@end menu
832
6d2ebf8b 833@node Invoking GDB
c906108c
SS
834@section Invoking @value{GDBN}
835
c906108c
SS
836Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
837@value{GDBN} reads commands from the terminal until you tell it to exit.
838
839You can also run @code{@value{GDBP}} with a variety of arguments and options,
840to specify more of your debugging environment at the outset.
841
c906108c
SS
842The command-line options described here are designed
843to cover a variety of situations; in some environments, some of these
5d161b24 844options may effectively be unavailable.
c906108c
SS
845
846The most usual way to start @value{GDBN} is with one argument,
847specifying an executable program:
848
474c8240 849@smallexample
c906108c 850@value{GDBP} @var{program}
474c8240 851@end smallexample
c906108c 852
c906108c
SS
853@noindent
854You can also start with both an executable program and a core file
855specified:
856
474c8240 857@smallexample
c906108c 858@value{GDBP} @var{program} @var{core}
474c8240 859@end smallexample
c906108c
SS
860
861You can, instead, specify a process ID as a second argument, if you want
862to debug a running process:
863
474c8240 864@smallexample
c906108c 865@value{GDBP} @var{program} 1234
474c8240 866@end smallexample
c906108c
SS
867
868@noindent
869would attach @value{GDBN} to process @code{1234} (unless you also have a file
870named @file{1234}; @value{GDBN} does check for a core file first).
871
c906108c 872Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
873complete operating system; when you use @value{GDBN} as a remote
874debugger attached to a bare board, there may not be any notion of
875``process'', and there is often no way to get a core dump. @value{GDBN}
876will warn you if it is unable to attach or to read core dumps.
c906108c 877
aa26fa3a
TT
878You can optionally have @code{@value{GDBP}} pass any arguments after the
879executable file to the inferior using @code{--args}. This option stops
880option processing.
474c8240 881@smallexample
3f94c067 882@value{GDBP} --args gcc -O2 -c foo.c
474c8240 883@end smallexample
aa26fa3a
TT
884This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
885@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
886
96a2c332 887You can run @code{@value{GDBP}} without printing the front material, which describes
adcc0a31 888@value{GDBN}'s non-warranty, by specifying @code{--silent}
889(or @code{-q}/@code{--quiet}):
c906108c
SS
890
891@smallexample
adcc0a31 892@value{GDBP} --silent
c906108c
SS
893@end smallexample
894
895@noindent
896You can further control how @value{GDBN} starts up by using command-line
897options. @value{GDBN} itself can remind you of the options available.
898
899@noindent
900Type
901
474c8240 902@smallexample
c906108c 903@value{GDBP} -help
474c8240 904@end smallexample
c906108c
SS
905
906@noindent
907to display all available options and briefly describe their use
908(@samp{@value{GDBP} -h} is a shorter equivalent).
909
910All options and command line arguments you give are processed
911in sequential order. The order makes a difference when the
912@samp{-x} option is used.
913
914
915@menu
c906108c
SS
916* File Options:: Choosing files
917* Mode Options:: Choosing modes
6fc08d32 918* Startup:: What @value{GDBN} does during startup
c906108c
SS
919@end menu
920
6d2ebf8b 921@node File Options
79a6e687 922@subsection Choosing Files
c906108c 923
2df3850c 924When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
925specifying an executable file and core file (or process ID). This is
926the same as if the arguments were specified by the @samp{-se} and
d52fb0e9 927@samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
19837790
MS
928first argument that does not have an associated option flag as
929equivalent to the @samp{-se} option followed by that argument; and the
930second argument that does not have an associated option flag, if any, as
931equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
932If the second argument begins with a decimal digit, @value{GDBN} will
933first attempt to attach to it as a process, and if that fails, attempt
934to open it as a corefile. If you have a corefile whose name begins with
b383017d 935a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 936prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
937
938If @value{GDBN} has not been configured to included core file support,
939such as for most embedded targets, then it will complain about a second
940argument and ignore it.
c906108c
SS
941
942Many options have both long and short forms; both are shown in the
943following list. @value{GDBN} also recognizes the long forms if you truncate
944them, so long as enough of the option is present to be unambiguous.
945(If you prefer, you can flag option arguments with @samp{--} rather
946than @samp{-}, though we illustrate the more usual convention.)
947
d700128c
EZ
948@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
949@c way, both those who look for -foo and --foo in the index, will find
950@c it.
951
c906108c
SS
952@table @code
953@item -symbols @var{file}
954@itemx -s @var{file}
d700128c
EZ
955@cindex @code{--symbols}
956@cindex @code{-s}
c906108c
SS
957Read symbol table from file @var{file}.
958
959@item -exec @var{file}
960@itemx -e @var{file}
d700128c
EZ
961@cindex @code{--exec}
962@cindex @code{-e}
7a292a7a
SS
963Use file @var{file} as the executable file to execute when appropriate,
964and for examining pure data in conjunction with a core dump.
c906108c
SS
965
966@item -se @var{file}
d700128c 967@cindex @code{--se}
c906108c
SS
968Read symbol table from file @var{file} and use it as the executable
969file.
970
c906108c
SS
971@item -core @var{file}
972@itemx -c @var{file}
d700128c
EZ
973@cindex @code{--core}
974@cindex @code{-c}
b383017d 975Use file @var{file} as a core dump to examine.
c906108c 976
19837790
MS
977@item -pid @var{number}
978@itemx -p @var{number}
979@cindex @code{--pid}
980@cindex @code{-p}
981Connect to process ID @var{number}, as with the @code{attach} command.
c906108c
SS
982
983@item -command @var{file}
984@itemx -x @var{file}
d700128c
EZ
985@cindex @code{--command}
986@cindex @code{-x}
95433b34
JB
987Execute commands from file @var{file}. The contents of this file is
988evaluated exactly as the @code{source} command would.
8150ff9c 989@xref{Command Files,, Command files}.
c906108c 990
8a5a3c82
AS
991@item -eval-command @var{command}
992@itemx -ex @var{command}
993@cindex @code{--eval-command}
994@cindex @code{-ex}
995Execute a single @value{GDBN} command.
996
997This option may be used multiple times to call multiple commands. It may
998also be interleaved with @samp{-command} as required.
999
1000@smallexample
1001@value{GDBP} -ex 'target sim' -ex 'load' \
1002 -x setbreakpoints -ex 'run' a.out
1003@end smallexample
1004
8320cc4f
JK
1005@item -init-command @var{file}
1006@itemx -ix @var{file}
1007@cindex @code{--init-command}
1008@cindex @code{-ix}
2d7b58e8
JK
1009Execute commands from file @var{file} before loading the inferior (but
1010after loading gdbinit files).
8320cc4f
JK
1011@xref{Startup}.
1012
1013@item -init-eval-command @var{command}
1014@itemx -iex @var{command}
1015@cindex @code{--init-eval-command}
1016@cindex @code{-iex}
2d7b58e8
JK
1017Execute a single @value{GDBN} command before loading the inferior (but
1018after loading gdbinit files).
8320cc4f
JK
1019@xref{Startup}.
1020
c906108c
SS
1021@item -directory @var{directory}
1022@itemx -d @var{directory}
d700128c
EZ
1023@cindex @code{--directory}
1024@cindex @code{-d}
4b505b12 1025Add @var{directory} to the path to search for source and script files.
c906108c 1026
c906108c
SS
1027@item -r
1028@itemx -readnow
d700128c
EZ
1029@cindex @code{--readnow}
1030@cindex @code{-r}
c906108c
SS
1031Read each symbol file's entire symbol table immediately, rather than
1032the default, which is to read it incrementally as it is needed.
1033This makes startup slower, but makes future operations faster.
53a5351d 1034
c906108c
SS
1035@end table
1036
6d2ebf8b 1037@node Mode Options
79a6e687 1038@subsection Choosing Modes
c906108c
SS
1039
1040You can run @value{GDBN} in various alternative modes---for example, in
1041batch mode or quiet mode.
1042
1043@table @code
bf88dd68 1044@anchor{-nx}
c906108c
SS
1045@item -nx
1046@itemx -n
d700128c
EZ
1047@cindex @code{--nx}
1048@cindex @code{-n}
07540c15
DE
1049Do not execute commands found in any initialization file.
1050There are three init files, loaded in the following order:
1051
1052@table @code
1053@item @file{system.gdbinit}
1054This is the system-wide init file.
1055Its location is specified with the @code{--with-system-gdbinit}
1056configure option (@pxref{System-wide configuration}).
1057It is loaded first when @value{GDBN} starts, before command line options
1058have been processed.
1059@item @file{~/.gdbinit}
1060This is the init file in your home directory.
1061It is loaded next, after @file{system.gdbinit}, and before
1062command options have been processed.
1063@item @file{./.gdbinit}
1064This is the init file in the current directory.
1065It is loaded last, after command line options other than @code{-x} and
1066@code{-ex} have been processed. Command line options @code{-x} and
1067@code{-ex} are processed last, after @file{./.gdbinit} has been loaded.
1068@end table
1069
1070For further documentation on startup processing, @xref{Startup}.
1071For documentation on how to write command files,
1072@xref{Command Files,,Command Files}.
1073
1074@anchor{-nh}
1075@item -nh
1076@cindex @code{--nh}
1077Do not execute commands found in @file{~/.gdbinit}, the init file
1078in your home directory.
1079@xref{Startup}.
c906108c
SS
1080
1081@item -quiet
d700128c 1082@itemx -silent
c906108c 1083@itemx -q
d700128c
EZ
1084@cindex @code{--quiet}
1085@cindex @code{--silent}
1086@cindex @code{-q}
c906108c
SS
1087``Quiet''. Do not print the introductory and copyright messages. These
1088messages are also suppressed in batch mode.
1089
1090@item -batch
d700128c 1091@cindex @code{--batch}
c906108c
SS
1092Run in batch mode. Exit with status @code{0} after processing all the
1093command files specified with @samp{-x} (and all commands from
1094initialization files, if not inhibited with @samp{-n}). Exit with
1095nonzero status if an error occurs in executing the @value{GDBN} commands
5da1313b
JK
1096in the command files. Batch mode also disables pagination, sets unlimited
1097terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1098off} were in effect (@pxref{Messages/Warnings}).
c906108c 1099
2df3850c
JM
1100Batch mode may be useful for running @value{GDBN} as a filter, for
1101example to download and run a program on another computer; in order to
1102make this more useful, the message
c906108c 1103
474c8240 1104@smallexample
c906108c 1105Program exited normally.
474c8240 1106@end smallexample
c906108c
SS
1107
1108@noindent
2df3850c
JM
1109(which is ordinarily issued whenever a program running under
1110@value{GDBN} control terminates) is not issued when running in batch
1111mode.
1112
1a088d06
AS
1113@item -batch-silent
1114@cindex @code{--batch-silent}
1115Run in batch mode exactly like @samp{-batch}, but totally silently. All
1116@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1117unaffected). This is much quieter than @samp{-silent} and would be useless
1118for an interactive session.
1119
1120This is particularly useful when using targets that give @samp{Loading section}
1121messages, for example.
1122
1123Note that targets that give their output via @value{GDBN}, as opposed to
1124writing directly to @code{stdout}, will also be made silent.
1125
4b0ad762
AS
1126@item -return-child-result
1127@cindex @code{--return-child-result}
1128The return code from @value{GDBN} will be the return code from the child
1129process (the process being debugged), with the following exceptions:
1130
1131@itemize @bullet
1132@item
1133@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1134internal error. In this case the exit code is the same as it would have been
1135without @samp{-return-child-result}.
1136@item
1137The user quits with an explicit value. E.g., @samp{quit 1}.
1138@item
1139The child process never runs, or is not allowed to terminate, in which case
1140the exit code will be -1.
1141@end itemize
1142
1143This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1144when @value{GDBN} is being used as a remote program loader or simulator
1145interface.
1146
2df3850c
JM
1147@item -nowindows
1148@itemx -nw
d700128c
EZ
1149@cindex @code{--nowindows}
1150@cindex @code{-nw}
2df3850c 1151``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1152(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1153interface. If no GUI is available, this option has no effect.
1154
1155@item -windows
1156@itemx -w
d700128c
EZ
1157@cindex @code{--windows}
1158@cindex @code{-w}
2df3850c
JM
1159If @value{GDBN} includes a GUI, then this option requires it to be
1160used if possible.
c906108c
SS
1161
1162@item -cd @var{directory}
d700128c 1163@cindex @code{--cd}
c906108c
SS
1164Run @value{GDBN} using @var{directory} as its working directory,
1165instead of the current directory.
1166
aae1c79a 1167@item -data-directory @var{directory}
8d551b02 1168@itemx -D @var{directory}
aae1c79a 1169@cindex @code{--data-directory}
8d551b02 1170@cindex @code{-D}
aae1c79a
DE
1171Run @value{GDBN} using @var{directory} as its data directory.
1172The data directory is where @value{GDBN} searches for its
1173auxiliary files. @xref{Data Files}.
1174
c906108c
SS
1175@item -fullname
1176@itemx -f
d700128c
EZ
1177@cindex @code{--fullname}
1178@cindex @code{-f}
7a292a7a
SS
1179@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1180subprocess. It tells @value{GDBN} to output the full file name and line
1181number in a standard, recognizable fashion each time a stack frame is
1182displayed (which includes each time your program stops). This
1183recognizable format looks like two @samp{\032} characters, followed by
1184the file name, line number and character position separated by colons,
1185and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1186@samp{\032} characters as a signal to display the source code for the
1187frame.
c906108c 1188
d700128c
EZ
1189@item -annotate @var{level}
1190@cindex @code{--annotate}
1191This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1192effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1193(@pxref{Annotations}). The annotation @var{level} controls how much
1194information @value{GDBN} prints together with its prompt, values of
1195expressions, source lines, and other types of output. Level 0 is the
1196normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1197@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1198that control @value{GDBN}, and level 2 has been deprecated.
1199
265eeb58 1200The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1201(@pxref{GDB/MI}).
d700128c 1202
aa26fa3a
TT
1203@item --args
1204@cindex @code{--args}
1205Change interpretation of command line so that arguments following the
1206executable file are passed as command line arguments to the inferior.
1207This option stops option processing.
1208
2df3850c
JM
1209@item -baud @var{bps}
1210@itemx -b @var{bps}
d700128c
EZ
1211@cindex @code{--baud}
1212@cindex @code{-b}
c906108c
SS
1213Set the line speed (baud rate or bits per second) of any serial
1214interface used by @value{GDBN} for remote debugging.
c906108c 1215
f47b1503
AS
1216@item -l @var{timeout}
1217@cindex @code{-l}
1218Set the timeout (in seconds) of any communication used by @value{GDBN}
1219for remote debugging.
1220
c906108c 1221@item -tty @var{device}
d700128c
EZ
1222@itemx -t @var{device}
1223@cindex @code{--tty}
1224@cindex @code{-t}
c906108c
SS
1225Run using @var{device} for your program's standard input and output.
1226@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1227
53a5351d 1228@c resolve the situation of these eventually
c4555f82
SC
1229@item -tui
1230@cindex @code{--tui}
d0d5df6f
AC
1231Activate the @dfn{Text User Interface} when starting. The Text User
1232Interface manages several text windows on the terminal, showing
1233source, assembly, registers and @value{GDBN} command outputs
217bff3e
JK
1234(@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1235option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1236Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d 1237
d700128c
EZ
1238@item -interpreter @var{interp}
1239@cindex @code{--interpreter}
1240Use the interpreter @var{interp} for interface with the controlling
1241program or device. This option is meant to be set by programs which
94bbb2c0 1242communicate with @value{GDBN} using it as a back end.
21c294e6 1243@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1244
da0f9dcd 1245@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1246@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1247The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1248previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1249selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1250@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1251
1252@item -write
1253@cindex @code{--write}
1254Open the executable and core files for both reading and writing. This
1255is equivalent to the @samp{set write on} command inside @value{GDBN}
1256(@pxref{Patching}).
1257
1258@item -statistics
1259@cindex @code{--statistics}
1260This option causes @value{GDBN} to print statistics about time and
1261memory usage after it completes each command and returns to the prompt.
1262
1263@item -version
1264@cindex @code{--version}
1265This option causes @value{GDBN} to print its version number and
1266no-warranty blurb, and exit.
1267
6eaaf48b
EZ
1268@item -configuration
1269@cindex @code{--configuration}
1270This option causes @value{GDBN} to print details about its build-time
1271configuration parameters, and then exit. These details can be
1272important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1273
c906108c
SS
1274@end table
1275
6fc08d32 1276@node Startup
79a6e687 1277@subsection What @value{GDBN} Does During Startup
6fc08d32
EZ
1278@cindex @value{GDBN} startup
1279
1280Here's the description of what @value{GDBN} does during session startup:
1281
1282@enumerate
1283@item
1284Sets up the command interpreter as specified by the command line
1285(@pxref{Mode Options, interpreter}).
1286
1287@item
1288@cindex init file
098b41a6
JG
1289Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1290used when building @value{GDBN}; @pxref{System-wide configuration,
1291 ,System-wide configuration and settings}) and executes all the commands in
1292that file.
1293
bf88dd68 1294@anchor{Home Directory Init File}
098b41a6
JG
1295@item
1296Reads the init file (if any) in your home directory@footnote{On
6fc08d32
EZ
1297DOS/Windows systems, the home directory is the one pointed to by the
1298@code{HOME} environment variable.} and executes all the commands in
1299that file.
1300
2d7b58e8
JK
1301@anchor{Option -init-eval-command}
1302@item
1303Executes commands and command files specified by the @samp{-iex} and
1304@samp{-ix} options in their specified order. Usually you should use the
1305@samp{-ex} and @samp{-x} options instead, but this way you can apply
1306settings before @value{GDBN} init files get executed and before inferior
1307gets loaded.
1308
6fc08d32
EZ
1309@item
1310Processes command line options and operands.
1311
bf88dd68 1312@anchor{Init File in the Current Directory during Startup}
6fc08d32
EZ
1313@item
1314Reads and executes the commands from init file (if any) in the current
bf88dd68
JK
1315working directory as long as @samp{set auto-load local-gdbinit} is set to
1316@samp{on} (@pxref{Init File in the Current Directory}).
1317This is only done if the current directory is
119b882a
EZ
1318different from your home directory. Thus, you can have more than one
1319init file, one generic in your home directory, and another, specific
1320to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1321@value{GDBN}.
1322
a86caf66
DE
1323@item
1324If the command line specified a program to debug, or a process to
1325attach to, or a core file, @value{GDBN} loads any auto-loaded
1326scripts provided for the program or for its loaded shared libraries.
1327@xref{Auto-loading}.
1328
1329If you wish to disable the auto-loading during startup,
1330you must do something like the following:
1331
1332@smallexample
bf88dd68 1333$ gdb -iex "set auto-load python-scripts off" myprogram
a86caf66
DE
1334@end smallexample
1335
8320cc4f
JK
1336Option @samp{-ex} does not work because the auto-loading is then turned
1337off too late.
a86caf66 1338
6fc08d32 1339@item
6fe37d23
JK
1340Executes commands and command files specified by the @samp{-ex} and
1341@samp{-x} options in their specified order. @xref{Command Files}, for
1342more details about @value{GDBN} command files.
6fc08d32
EZ
1343
1344@item
1345Reads the command history recorded in the @dfn{history file}.
d620b259 1346@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1347files where @value{GDBN} records it.
1348@end enumerate
1349
1350Init files use the same syntax as @dfn{command files} (@pxref{Command
1351Files}) and are processed by @value{GDBN} in the same way. The init
1352file in your home directory can set options (such as @samp{set
1353complaints}) that affect subsequent processing of command line options
1354and operands. Init files are not executed if you use the @samp{-nx}
79a6e687 1355option (@pxref{Mode Options, ,Choosing Modes}).
6fc08d32 1356
098b41a6
JG
1357To display the list of init files loaded by gdb at startup, you
1358can use @kbd{gdb --help}.
1359
6fc08d32
EZ
1360@cindex init file name
1361@cindex @file{.gdbinit}
119b882a 1362@cindex @file{gdb.ini}
8807d78b 1363The @value{GDBN} init files are normally called @file{.gdbinit}.
119b882a
EZ
1364The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1365the limitations of file names imposed by DOS filesystems. The Windows
4d3f93a2
JB
1366port of @value{GDBN} uses the standard name, but if it finds a
1367@file{gdb.ini} file in your home directory, it warns you about that
1368and suggests to rename the file to the standard name.
119b882a 1369
6fc08d32 1370
6d2ebf8b 1371@node Quitting GDB
c906108c
SS
1372@section Quitting @value{GDBN}
1373@cindex exiting @value{GDBN}
1374@cindex leaving @value{GDBN}
1375
1376@table @code
1377@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1378@kindex q @r{(@code{quit})}
96a2c332
SS
1379@item quit @r{[}@var{expression}@r{]}
1380@itemx q
1381To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1382@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1383do not supply @var{expression}, @value{GDBN} will terminate normally;
1384otherwise it will terminate using the result of @var{expression} as the
1385error code.
c906108c
SS
1386@end table
1387
1388@cindex interrupt
c8aa23ab 1389An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1390terminates the action of any @value{GDBN} command that is in progress and
1391returns to @value{GDBN} command level. It is safe to type the interrupt
1392character at any time because @value{GDBN} does not allow it to take effect
1393until a time when it is safe.
1394
c906108c
SS
1395If you have been using @value{GDBN} to control an attached process or
1396device, you can release it with the @code{detach} command
79a6e687 1397(@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 1398
6d2ebf8b 1399@node Shell Commands
79a6e687 1400@section Shell Commands
c906108c
SS
1401
1402If you need to execute occasional shell commands during your
1403debugging session, there is no need to leave or suspend @value{GDBN}; you can
1404just use the @code{shell} command.
1405
1406@table @code
1407@kindex shell
ed59ded5 1408@kindex !
c906108c 1409@cindex shell escape
ed59ded5
DE
1410@item shell @var{command-string}
1411@itemx !@var{command-string}
1412Invoke a standard shell to execute @var{command-string}.
1413Note that no space is needed between @code{!} and @var{command-string}.
c906108c 1414If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1415shell to run. Otherwise @value{GDBN} uses the default shell
1416(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1417@end table
1418
1419The utility @code{make} is often needed in development environments.
1420You do not have to use the @code{shell} command for this purpose in
1421@value{GDBN}:
1422
1423@table @code
1424@kindex make
1425@cindex calling make
1426@item make @var{make-args}
1427Execute the @code{make} program with the specified
1428arguments. This is equivalent to @samp{shell make @var{make-args}}.
1429@end table
1430
79a6e687
BW
1431@node Logging Output
1432@section Logging Output
0fac0b41 1433@cindex logging @value{GDBN} output
9c16f35a 1434@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1435
1436You may want to save the output of @value{GDBN} commands to a file.
1437There are several commands to control @value{GDBN}'s logging.
1438
1439@table @code
1440@kindex set logging
1441@item set logging on
1442Enable logging.
1443@item set logging off
1444Disable logging.
9c16f35a 1445@cindex logging file name
0fac0b41
DJ
1446@item set logging file @var{file}
1447Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1448@item set logging overwrite [on|off]
1449By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1450you want @code{set logging on} to overwrite the logfile instead.
1451@item set logging redirect [on|off]
1452By default, @value{GDBN} output will go to both the terminal and the logfile.
1453Set @code{redirect} if you want output to go only to the log file.
1454@kindex show logging
1455@item show logging
1456Show the current values of the logging settings.
1457@end table
1458
6d2ebf8b 1459@node Commands
c906108c
SS
1460@chapter @value{GDBN} Commands
1461
1462You can abbreviate a @value{GDBN} command to the first few letters of the command
1463name, if that abbreviation is unambiguous; and you can repeat certain
1464@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1465key to get @value{GDBN} to fill out the rest of a word in a command (or to
1466show you the alternatives available, if there is more than one possibility).
1467
1468@menu
1469* Command Syntax:: How to give commands to @value{GDBN}
1470* Completion:: Command completion
1471* Help:: How to ask @value{GDBN} for help
1472@end menu
1473
6d2ebf8b 1474@node Command Syntax
79a6e687 1475@section Command Syntax
c906108c
SS
1476
1477A @value{GDBN} command is a single line of input. There is no limit on
1478how long it can be. It starts with a command name, which is followed by
1479arguments whose meaning depends on the command name. For example, the
1480command @code{step} accepts an argument which is the number of times to
1481step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1482with no arguments. Some commands do not allow any arguments.
c906108c
SS
1483
1484@cindex abbreviation
1485@value{GDBN} command names may always be truncated if that abbreviation is
1486unambiguous. Other possible command abbreviations are listed in the
1487documentation for individual commands. In some cases, even ambiguous
1488abbreviations are allowed; for example, @code{s} is specially defined as
1489equivalent to @code{step} even though there are other commands whose
1490names start with @code{s}. You can test abbreviations by using them as
1491arguments to the @code{help} command.
1492
1493@cindex repeating commands
41afff9a 1494@kindex RET @r{(repeat last command)}
c906108c 1495A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1496repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1497will not repeat this way; these are commands whose unintentional
1498repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1499repeat. User-defined commands can disable this feature; see
1500@ref{Define, dont-repeat}.
c906108c
SS
1501
1502The @code{list} and @code{x} commands, when you repeat them with
1503@key{RET}, construct new arguments rather than repeating
1504exactly as typed. This permits easy scanning of source or memory.
1505
1506@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1507output, in a way similar to the common utility @code{more}
79a6e687 1508(@pxref{Screen Size,,Screen Size}). Since it is easy to press one
c906108c
SS
1509@key{RET} too many in this situation, @value{GDBN} disables command
1510repetition after any command that generates this sort of display.
1511
41afff9a 1512@kindex # @r{(a comment)}
c906108c
SS
1513@cindex comment
1514Any text from a @kbd{#} to the end of the line is a comment; it does
1515nothing. This is useful mainly in command files (@pxref{Command
79a6e687 1516Files,,Command Files}).
c906108c 1517
88118b3a 1518@cindex repeating command sequences
c8aa23ab
EZ
1519@kindex Ctrl-o @r{(operate-and-get-next)}
1520The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1521commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1522then fetches the next line relative to the current line from the history
1523for editing.
1524
6d2ebf8b 1525@node Completion
79a6e687 1526@section Command Completion
c906108c
SS
1527
1528@cindex completion
1529@cindex word completion
1530@value{GDBN} can fill in the rest of a word in a command for you, if there is
1531only one possibility; it can also show you what the valid possibilities
1532are for the next word in a command, at any time. This works for @value{GDBN}
1533commands, @value{GDBN} subcommands, and the names of symbols in your program.
1534
1535Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1536of a word. If there is only one possibility, @value{GDBN} fills in the
1537word, and waits for you to finish the command (or press @key{RET} to
1538enter it). For example, if you type
1539
1540@c FIXME "@key" does not distinguish its argument sufficiently to permit
1541@c complete accuracy in these examples; space introduced for clarity.
1542@c If texinfo enhancements make it unnecessary, it would be nice to
1543@c replace " @key" by "@key" in the following...
474c8240 1544@smallexample
c906108c 1545(@value{GDBP}) info bre @key{TAB}
474c8240 1546@end smallexample
c906108c
SS
1547
1548@noindent
1549@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1550the only @code{info} subcommand beginning with @samp{bre}:
1551
474c8240 1552@smallexample
c906108c 1553(@value{GDBP}) info breakpoints
474c8240 1554@end smallexample
c906108c
SS
1555
1556@noindent
1557You can either press @key{RET} at this point, to run the @code{info
1558breakpoints} command, or backspace and enter something else, if
1559@samp{breakpoints} does not look like the command you expected. (If you
1560were sure you wanted @code{info breakpoints} in the first place, you
1561might as well just type @key{RET} immediately after @samp{info bre},
1562to exploit command abbreviations rather than command completion).
1563
1564If there is more than one possibility for the next word when you press
1565@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1566characters and try again, or just press @key{TAB} a second time;
1567@value{GDBN} displays all the possible completions for that word. For
1568example, you might want to set a breakpoint on a subroutine whose name
1569begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1570just sounds the bell. Typing @key{TAB} again displays all the
1571function names in your program that begin with those characters, for
1572example:
1573
474c8240 1574@smallexample
c906108c
SS
1575(@value{GDBP}) b make_ @key{TAB}
1576@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1577make_a_section_from_file make_environ
1578make_abs_section make_function_type
1579make_blockvector make_pointer_type
1580make_cleanup make_reference_type
c906108c
SS
1581make_command make_symbol_completion_list
1582(@value{GDBP}) b make_
474c8240 1583@end smallexample
c906108c
SS
1584
1585@noindent
1586After displaying the available possibilities, @value{GDBN} copies your
1587partial input (@samp{b make_} in the example) so you can finish the
1588command.
1589
1590If you just want to see the list of alternatives in the first place, you
b37052ae 1591can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1592means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1593key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1594one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c 1595
ef0b411a
GB
1596If the number of possible completions is large, @value{GDBN} will
1597print as much of the list as it has collected, as well as a message
1598indicating that the list may be truncated.
1599
1600@smallexample
1601(@value{GDBP}) b m@key{TAB}@key{TAB}
1602main
1603<... the rest of the possible completions ...>
1604*** List may be truncated, max-completions reached. ***
1605(@value{GDBP}) b m
1606@end smallexample
1607
1608@noindent
1609This behavior can be controlled with the following commands:
1610
1611@table @code
1612@kindex set max-completions
1613@item set max-completions @var{limit}
1614@itemx set max-completions unlimited
1615Set the maximum number of completion candidates. @value{GDBN} will
1616stop looking for more completions once it collects this many candidates.
1617This is useful when completing on things like function names as collecting
1618all the possible candidates can be time consuming.
1619The default value is 200. A value of zero disables tab-completion.
1620Note that setting either no limit or a very large limit can make
1621completion slow.
1622@kindex show max-completions
1623@item show max-completions
1624Show the maximum number of candidates that @value{GDBN} will collect and show
1625during completion.
1626@end table
1627
c906108c
SS
1628@cindex quotes in commands
1629@cindex completion of quoted strings
1630Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1631parentheses or other characters that @value{GDBN} normally excludes from
1632its notion of a word. To permit word completion to work in this
1633situation, you may enclose words in @code{'} (single quote marks) in
1634@value{GDBN} commands.
c906108c 1635
c906108c 1636The most likely situation where you might need this is in typing the
b37052ae
EZ
1637name of a C@t{++} function. This is because C@t{++} allows function
1638overloading (multiple definitions of the same function, distinguished
1639by argument type). For example, when you want to set a breakpoint you
1640may need to distinguish whether you mean the version of @code{name}
1641that takes an @code{int} parameter, @code{name(int)}, or the version
1642that takes a @code{float} parameter, @code{name(float)}. To use the
1643word-completion facilities in this situation, type a single quote
1644@code{'} at the beginning of the function name. This alerts
1645@value{GDBN} that it may need to consider more information than usual
1646when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1647
474c8240 1648@smallexample
96a2c332 1649(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1650bubble(double,double) bubble(int,int)
1651(@value{GDBP}) b 'bubble(
474c8240 1652@end smallexample
c906108c
SS
1653
1654In some cases, @value{GDBN} can tell that completing a name requires using
1655quotes. When this happens, @value{GDBN} inserts the quote for you (while
1656completing as much as it can) if you do not type the quote in the first
1657place:
1658
474c8240 1659@smallexample
c906108c
SS
1660(@value{GDBP}) b bub @key{TAB}
1661@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1662(@value{GDBP}) b 'bubble(
474c8240 1663@end smallexample
c906108c
SS
1664
1665@noindent
1666In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1667you have not yet started typing the argument list when you ask for
1668completion on an overloaded symbol.
1669
79a6e687
BW
1670For more information about overloaded functions, see @ref{C Plus Plus
1671Expressions, ,C@t{++} Expressions}. You can use the command @code{set
c906108c 1672overload-resolution off} to disable overload resolution;
79a6e687 1673see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
c906108c 1674
65d12d83
TT
1675@cindex completion of structure field names
1676@cindex structure field name completion
1677@cindex completion of union field names
1678@cindex union field name completion
1679When completing in an expression which looks up a field in a
1680structure, @value{GDBN} also tries@footnote{The completer can be
1681confused by certain kinds of invalid expressions. Also, it only
1682examines the static type of the expression, not the dynamic type.} to
1683limit completions to the field names available in the type of the
1684left-hand-side:
1685
1686@smallexample
1687(@value{GDBP}) p gdb_stdout.@kbd{M-?}
01124a23
DE
1688magic to_fputs to_rewind
1689to_data to_isatty to_write
1690to_delete to_put to_write_async_safe
1691to_flush to_read
65d12d83
TT
1692@end smallexample
1693
1694@noindent
1695This is because the @code{gdb_stdout} is a variable of the type
1696@code{struct ui_file} that is defined in @value{GDBN} sources as
1697follows:
1698
1699@smallexample
1700struct ui_file
1701@{
1702 int *magic;
1703 ui_file_flush_ftype *to_flush;
1704 ui_file_write_ftype *to_write;
01124a23 1705 ui_file_write_async_safe_ftype *to_write_async_safe;
65d12d83
TT
1706 ui_file_fputs_ftype *to_fputs;
1707 ui_file_read_ftype *to_read;
1708 ui_file_delete_ftype *to_delete;
1709 ui_file_isatty_ftype *to_isatty;
1710 ui_file_rewind_ftype *to_rewind;
1711 ui_file_put_ftype *to_put;
1712 void *to_data;
1713@}
1714@end smallexample
1715
c906108c 1716
6d2ebf8b 1717@node Help
79a6e687 1718@section Getting Help
c906108c
SS
1719@cindex online documentation
1720@kindex help
1721
5d161b24 1722You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1723using the command @code{help}.
1724
1725@table @code
41afff9a 1726@kindex h @r{(@code{help})}
c906108c
SS
1727@item help
1728@itemx h
1729You can use @code{help} (abbreviated @code{h}) with no arguments to
1730display a short list of named classes of commands:
1731
1732@smallexample
1733(@value{GDBP}) help
1734List of classes of commands:
1735
2df3850c 1736aliases -- Aliases of other commands
c906108c 1737breakpoints -- Making program stop at certain points
2df3850c 1738data -- Examining data
c906108c 1739files -- Specifying and examining files
2df3850c
JM
1740internals -- Maintenance commands
1741obscure -- Obscure features
1742running -- Running the program
1743stack -- Examining the stack
c906108c
SS
1744status -- Status inquiries
1745support -- Support facilities
12c27660 1746tracepoints -- Tracing of program execution without
96a2c332 1747 stopping the program
c906108c 1748user-defined -- User-defined commands
c906108c 1749
5d161b24 1750Type "help" followed by a class name for a list of
c906108c 1751commands in that class.
5d161b24 1752Type "help" followed by command name for full
c906108c
SS
1753documentation.
1754Command name abbreviations are allowed if unambiguous.
1755(@value{GDBP})
1756@end smallexample
96a2c332 1757@c the above line break eliminates huge line overfull...
c906108c
SS
1758
1759@item help @var{class}
1760Using one of the general help classes as an argument, you can get a
1761list of the individual commands in that class. For example, here is the
1762help display for the class @code{status}:
1763
1764@smallexample
1765(@value{GDBP}) help status
1766Status inquiries.
1767
1768List of commands:
1769
1770@c Line break in "show" line falsifies real output, but needed
1771@c to fit in smallbook page size.
2df3850c 1772info -- Generic command for showing things
12c27660 1773 about the program being debugged
2df3850c 1774show -- Generic command for showing things
12c27660 1775 about the debugger
c906108c 1776
5d161b24 1777Type "help" followed by command name for full
c906108c
SS
1778documentation.
1779Command name abbreviations are allowed if unambiguous.
1780(@value{GDBP})
1781@end smallexample
1782
1783@item help @var{command}
1784With a command name as @code{help} argument, @value{GDBN} displays a
1785short paragraph on how to use that command.
1786
6837a0a2
DB
1787@kindex apropos
1788@item apropos @var{args}
09d4efe1 1789The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2 1790commands, and their documentation, for the regular expression specified in
99e008fe 1791@var{args}. It prints out all matches found. For example:
6837a0a2
DB
1792
1793@smallexample
16899756 1794apropos alias
6837a0a2
DB
1795@end smallexample
1796
b37052ae
EZ
1797@noindent
1798results in:
6837a0a2
DB
1799
1800@smallexample
6d2ebf8b 1801@c @group
16899756
DE
1802alias -- Define a new command that is an alias of an existing command
1803aliases -- Aliases of other commands
1804d -- Delete some breakpoints or auto-display expressions
1805del -- Delete some breakpoints or auto-display expressions
1806delete -- Delete some breakpoints or auto-display expressions
6d2ebf8b 1807@c @end group
6837a0a2
DB
1808@end smallexample
1809
c906108c
SS
1810@kindex complete
1811@item complete @var{args}
1812The @code{complete @var{args}} command lists all the possible completions
1813for the beginning of a command. Use @var{args} to specify the beginning of the
1814command you want completed. For example:
1815
1816@smallexample
1817complete i
1818@end smallexample
1819
1820@noindent results in:
1821
1822@smallexample
1823@group
2df3850c
JM
1824if
1825ignore
c906108c
SS
1826info
1827inspect
c906108c
SS
1828@end group
1829@end smallexample
1830
1831@noindent This is intended for use by @sc{gnu} Emacs.
1832@end table
1833
1834In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1835and @code{show} to inquire about the state of your program, or the state
1836of @value{GDBN} itself. Each command supports many topics of inquiry; this
1837manual introduces each of them in the appropriate context. The listings
00595b5e
EZ
1838under @code{info} and under @code{show} in the Command, Variable, and
1839Function Index point to all the sub-commands. @xref{Command and Variable
1840Index}.
c906108c
SS
1841
1842@c @group
1843@table @code
1844@kindex info
41afff9a 1845@kindex i @r{(@code{info})}
c906108c
SS
1846@item info
1847This command (abbreviated @code{i}) is for describing the state of your
cda4ce5a 1848program. For example, you can show the arguments passed to a function
c906108c
SS
1849with @code{info args}, list the registers currently in use with @code{info
1850registers}, or list the breakpoints you have set with @code{info breakpoints}.
1851You can get a complete list of the @code{info} sub-commands with
1852@w{@code{help info}}.
1853
1854@kindex set
1855@item set
5d161b24 1856You can assign the result of an expression to an environment variable with
c906108c
SS
1857@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1858@code{set prompt $}.
1859
1860@kindex show
1861@item show
5d161b24 1862In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1863@value{GDBN} itself.
1864You can change most of the things you can @code{show}, by using the
1865related command @code{set}; for example, you can control what number
1866system is used for displays with @code{set radix}, or simply inquire
1867which is currently in use with @code{show radix}.
1868
1869@kindex info set
1870To display all the settable parameters and their current
1871values, you can use @code{show} with no arguments; you may also use
1872@code{info set}. Both commands produce the same display.
1873@c FIXME: "info set" violates the rule that "info" is for state of
1874@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1875@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1876@end table
1877@c @end group
1878
6eaaf48b 1879Here are several miscellaneous @code{show} subcommands, all of which are
c906108c
SS
1880exceptional in lacking corresponding @code{set} commands:
1881
1882@table @code
1883@kindex show version
9c16f35a 1884@cindex @value{GDBN} version number
c906108c
SS
1885@item show version
1886Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1887information in @value{GDBN} bug-reports. If multiple versions of
1888@value{GDBN} are in use at your site, you may need to determine which
1889version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1890commands are introduced, and old ones may wither away. Also, many
1891system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1892variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1893The version number is the same as the one announced when you start
1894@value{GDBN}.
c906108c
SS
1895
1896@kindex show copying
09d4efe1 1897@kindex info copying
9c16f35a 1898@cindex display @value{GDBN} copyright
c906108c 1899@item show copying
09d4efe1 1900@itemx info copying
c906108c
SS
1901Display information about permission for copying @value{GDBN}.
1902
1903@kindex show warranty
09d4efe1 1904@kindex info warranty
c906108c 1905@item show warranty
09d4efe1 1906@itemx info warranty
2df3850c 1907Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1908if your version of @value{GDBN} comes with one.
2df3850c 1909
6eaaf48b
EZ
1910@kindex show configuration
1911@item show configuration
1912Display detailed information about the way @value{GDBN} was configured
1913when it was built. This displays the optional arguments passed to the
1914@file{configure} script and also configuration parameters detected
1915automatically by @command{configure}. When reporting a @value{GDBN}
1916bug (@pxref{GDB Bugs}), it is important to include this information in
1917your report.
1918
c906108c
SS
1919@end table
1920
6d2ebf8b 1921@node Running
c906108c
SS
1922@chapter Running Programs Under @value{GDBN}
1923
1924When you run a program under @value{GDBN}, you must first generate
1925debugging information when you compile it.
7a292a7a
SS
1926
1927You may start @value{GDBN} with its arguments, if any, in an environment
1928of your choice. If you are doing native debugging, you may redirect
1929your program's input and output, debug an already running process, or
1930kill a child process.
c906108c
SS
1931
1932@menu
1933* Compilation:: Compiling for debugging
1934* Starting:: Starting your program
c906108c
SS
1935* Arguments:: Your program's arguments
1936* Environment:: Your program's environment
c906108c
SS
1937
1938* Working Directory:: Your program's working directory
1939* Input/Output:: Your program's input and output
1940* Attach:: Debugging an already-running process
1941* Kill Process:: Killing the child process
c906108c 1942
6c95b8df 1943* Inferiors and Programs:: Debugging multiple inferiors and programs
c906108c 1944* Threads:: Debugging programs with multiple threads
6c95b8df 1945* Forks:: Debugging forks
5c95884b 1946* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
1947@end menu
1948
6d2ebf8b 1949@node Compilation
79a6e687 1950@section Compiling for Debugging
c906108c
SS
1951
1952In order to debug a program effectively, you need to generate
1953debugging information when you compile it. This debugging information
1954is stored in the object file; it describes the data type of each
1955variable or function and the correspondence between source line numbers
1956and addresses in the executable code.
1957
1958To request debugging information, specify the @samp{-g} option when you run
1959the compiler.
1960
514c4d71 1961Programs that are to be shipped to your customers are compiled with
edb3359d 1962optimizations, using the @samp{-O} compiler option. However, some
514c4d71
EZ
1963compilers are unable to handle the @samp{-g} and @samp{-O} options
1964together. Using those compilers, you cannot generate optimized
c906108c
SS
1965executables containing debugging information.
1966
514c4d71 1967@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1968without @samp{-O}, making it possible to debug optimized code. We
1969recommend that you @emph{always} use @samp{-g} whenever you compile a
1970program. You may think your program is correct, but there is no sense
edb3359d 1971in pushing your luck. For more information, see @ref{Optimized Code}.
c906108c
SS
1972
1973Older versions of the @sc{gnu} C compiler permitted a variant option
1974@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1975format; if your @sc{gnu} C compiler has this option, do not use it.
1976
514c4d71
EZ
1977@value{GDBN} knows about preprocessor macros and can show you their
1978expansion (@pxref{Macros}). Most compilers do not include information
1979about preprocessor macros in the debugging information if you specify
e0f8f636
TT
1980the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
1981the @sc{gnu} C compiler, provides macro information if you are using
1982the DWARF debugging format, and specify the option @option{-g3}.
1983
1984@xref{Debugging Options,,Options for Debugging Your Program or GCC,
1985gcc.info, Using the @sc{gnu} Compiler Collection (GCC)}, for more
1986information on @value{NGCC} options affecting debug information.
1987
1988You will have the best debugging experience if you use the latest
1989version of the DWARF debugging format that your compiler supports.
1990DWARF is currently the most expressive and best supported debugging
1991format in @value{GDBN}.
514c4d71 1992
c906108c 1993@need 2000
6d2ebf8b 1994@node Starting
79a6e687 1995@section Starting your Program
c906108c
SS
1996@cindex starting
1997@cindex running
1998
1999@table @code
2000@kindex run
41afff9a 2001@kindex r @r{(@code{run})}
c906108c
SS
2002@item run
2003@itemx r
7a292a7a 2004Use the @code{run} command to start your program under @value{GDBN}.
deb8ff2b
PA
2005You must first specify the program name with an argument to
2006@value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2007@value{GDBN}}), or by using the @code{file} or @code{exec-file}
2008command (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
2009
2010@end table
2011
c906108c
SS
2012If you are running your program in an execution environment that
2013supports processes, @code{run} creates an inferior process and makes
8edfe269
DJ
2014that process run your program. In some environments without processes,
2015@code{run} jumps to the start of your program. Other targets,
2016like @samp{remote}, are always running. If you get an error
2017message like this one:
2018
2019@smallexample
2020The "remote" target does not support "run".
2021Try "help target" or "continue".
2022@end smallexample
2023
2024@noindent
2025then use @code{continue} to run your program. You may need @code{load}
2026first (@pxref{load}).
c906108c
SS
2027
2028The execution of a program is affected by certain information it
2029receives from its superior. @value{GDBN} provides ways to specify this
2030information, which you must do @emph{before} starting your program. (You
2031can change it after starting your program, but such changes only affect
2032your program the next time you start it.) This information may be
2033divided into four categories:
2034
2035@table @asis
2036@item The @emph{arguments.}
2037Specify the arguments to give your program as the arguments of the
2038@code{run} command. If a shell is available on your target, the shell
2039is used to pass the arguments, so that you may use normal conventions
2040(such as wildcard expansion or variable substitution) in describing
2041the arguments.
2042In Unix systems, you can control which shell is used with the
98882a26
PA
2043@code{SHELL} environment variable. If you do not define @code{SHELL},
2044@value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2045use of any shell with the @code{set startup-with-shell} command (see
2046below for details).
c906108c
SS
2047
2048@item The @emph{environment.}
2049Your program normally inherits its environment from @value{GDBN}, but you can
2050use the @value{GDBN} commands @code{set environment} and @code{unset
2051environment} to change parts of the environment that affect
79a6e687 2052your program. @xref{Environment, ,Your Program's Environment}.
c906108c
SS
2053
2054@item The @emph{working directory.}
2055Your program inherits its working directory from @value{GDBN}. You can set
2056the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
79a6e687 2057@xref{Working Directory, ,Your Program's Working Directory}.
c906108c
SS
2058
2059@item The @emph{standard input and output.}
2060Your program normally uses the same device for standard input and
2061standard output as @value{GDBN} is using. You can redirect input and output
2062in the @code{run} command line, or you can use the @code{tty} command to
2063set a different device for your program.
79a6e687 2064@xref{Input/Output, ,Your Program's Input and Output}.
c906108c
SS
2065
2066@cindex pipes
2067@emph{Warning:} While input and output redirection work, you cannot use
2068pipes to pass the output of the program you are debugging to another
2069program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2070wrong program.
2071@end table
c906108c
SS
2072
2073When you issue the @code{run} command, your program begins to execute
79a6e687 2074immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
c906108c
SS
2075of how to arrange for your program to stop. Once your program has
2076stopped, you may call functions in your program, using the @code{print}
2077or @code{call} commands. @xref{Data, ,Examining Data}.
2078
2079If the modification time of your symbol file has changed since the last
2080time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2081table, and reads it again. When it does this, @value{GDBN} tries to retain
2082your current breakpoints.
2083
4e8b0763
JB
2084@table @code
2085@kindex start
2086@item start
2087@cindex run to main procedure
2088The name of the main procedure can vary from language to language.
2089With C or C@t{++}, the main procedure name is always @code{main}, but
2090other languages such as Ada do not require a specific name for their
2091main procedure. The debugger provides a convenient way to start the
2092execution of the program and to stop at the beginning of the main
2093procedure, depending on the language used.
2094
2095The @samp{start} command does the equivalent of setting a temporary
2096breakpoint at the beginning of the main procedure and then invoking
2097the @samp{run} command.
2098
f018e82f
EZ
2099@cindex elaboration phase
2100Some programs contain an @dfn{elaboration} phase where some startup code is
2101executed before the main procedure is called. This depends on the
2102languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
2103constructors for static and global objects are executed before
2104@code{main} is called. It is therefore possible that the debugger stops
2105before reaching the main procedure. However, the temporary breakpoint
2106will remain to halt execution.
2107
2108Specify the arguments to give to your program as arguments to the
2109@samp{start} command. These arguments will be given verbatim to the
2110underlying @samp{run} command. Note that the same arguments will be
2111reused if no argument is provided during subsequent calls to
2112@samp{start} or @samp{run}.
2113
2114It is sometimes necessary to debug the program during elaboration. In
2115these cases, using the @code{start} command would stop the execution of
2116your program too late, as the program would have already completed the
2117elaboration phase. Under these circumstances, insert breakpoints in your
2118elaboration code before running your program.
ccd213ac 2119
41ef2965 2120@anchor{set exec-wrapper}
ccd213ac
DJ
2121@kindex set exec-wrapper
2122@item set exec-wrapper @var{wrapper}
2123@itemx show exec-wrapper
2124@itemx unset exec-wrapper
2125When @samp{exec-wrapper} is set, the specified wrapper is used to
2126launch programs for debugging. @value{GDBN} starts your program
2127with a shell command of the form @kbd{exec @var{wrapper}
2128@var{program}}. Quoting is added to @var{program} and its
2129arguments, but not to @var{wrapper}, so you should add quotes if
2130appropriate for your shell. The wrapper runs until it executes
2131your program, and then @value{GDBN} takes control.
2132
2133You can use any program that eventually calls @code{execve} with
2134its arguments as a wrapper. Several standard Unix utilities do
2135this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2136with @code{exec "$@@"} will also work.
2137
2138For example, you can use @code{env} to pass an environment variable to
2139the debugged program, without setting the variable in your shell's
2140environment:
2141
2142@smallexample
2143(@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2144(@value{GDBP}) run
2145@end smallexample
2146
2147This command is available when debugging locally on most targets, excluding
2148@sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2149
98882a26
PA
2150@kindex set startup-with-shell
2151@item set startup-with-shell
2152@itemx set startup-with-shell on
2153@itemx set startup-with-shell off
2154@itemx show set startup-with-shell
2155On Unix systems, by default, if a shell is available on your target,
2156@value{GDBN}) uses it to start your program. Arguments of the
2157@code{run} command are passed to the shell, which does variable
2158substitution, expands wildcard characters and performs redirection of
2159I/O. In some circumstances, it may be useful to disable such use of a
2160shell, for example, when debugging the shell itself or diagnosing
2161startup failures such as:
2162
2163@smallexample
2164(@value{GDBP}) run
2165Starting program: ./a.out
2166During startup program terminated with signal SIGSEGV, Segmentation fault.
2167@end smallexample
2168
2169@noindent
2170which indicates the shell or the wrapper specified with
2171@samp{exec-wrapper} crashed, not your program. Most often, this is
afa332ce
PA
2172caused by something odd in your shell's non-interactive mode
2173initialization file---such as @file{.cshrc} for C-shell,
2174$@file{.zshenv} for the Z shell, or the file specified in the
2175@samp{BASH_ENV} environment variable for BASH.
98882a26 2176
6a3cb8e8
PA
2177@anchor{set auto-connect-native-target}
2178@kindex set auto-connect-native-target
2179@item set auto-connect-native-target
2180@itemx set auto-connect-native-target on
2181@itemx set auto-connect-native-target off
2182@itemx show auto-connect-native-target
2183
2184By default, if not connected to any target yet (e.g., with
2185@code{target remote}), the @code{run} command starts your program as a
2186native process under @value{GDBN}, on your local machine. If you're
2187sure you don't want to debug programs on your local machine, you can
2188tell @value{GDBN} to not connect to the native target automatically
2189with the @code{set auto-connect-native-target off} command.
2190
2191If @code{on}, which is the default, and if @value{GDBN} is not
2192connected to a target already, the @code{run} command automaticaly
2193connects to the native target, if one is available.
2194
2195If @code{off}, and if @value{GDBN} is not connected to a target
2196already, the @code{run} command fails with an error:
2197
2198@smallexample
2199(@value{GDBP}) run
2200Don't know how to run. Try "help target".
2201@end smallexample
2202
2203If @value{GDBN} is already connected to a target, @value{GDBN} always
2204uses it with the @code{run} command.
2205
2206In any case, you can explicitly connect to the native target with the
2207@code{target native} command. For example,
2208
2209@smallexample
2210(@value{GDBP}) set auto-connect-native-target off
2211(@value{GDBP}) run
2212Don't know how to run. Try "help target".
2213(@value{GDBP}) target native
2214(@value{GDBP}) run
2215Starting program: ./a.out
2216[Inferior 1 (process 10421) exited normally]
2217@end smallexample
2218
2219In case you connected explicitly to the @code{native} target,
2220@value{GDBN} remains connected even if all inferiors exit, ready for
2221the next @code{run} command. Use the @code{disconnect} command to
2222disconnect.
2223
2224Examples of other commands that likewise respect the
2225@code{auto-connect-native-target} setting: @code{attach}, @code{info
2226proc}, @code{info os}.
2227
10568435
JK
2228@kindex set disable-randomization
2229@item set disable-randomization
2230@itemx set disable-randomization on
2231This option (enabled by default in @value{GDBN}) will turn off the native
2232randomization of the virtual address space of the started program. This option
2233is useful for multiple debugging sessions to make the execution better
2234reproducible and memory addresses reusable across debugging sessions.
2235
03583c20
UW
2236This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2237On @sc{gnu}/Linux you can get the same behavior using
10568435
JK
2238
2239@smallexample
2240(@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2241@end smallexample
2242
2243@item set disable-randomization off
2244Leave the behavior of the started executable unchanged. Some bugs rear their
2245ugly heads only when the program is loaded at certain addresses. If your bug
2246disappears when you run the program under @value{GDBN}, that might be because
2247@value{GDBN} by default disables the address randomization on platforms, such
2248as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2249disable-randomization off} to try to reproduce such elusive bugs.
2250
03583c20
UW
2251On targets where it is available, virtual address space randomization
2252protects the programs against certain kinds of security attacks. In these
10568435
JK
2253cases the attacker needs to know the exact location of a concrete executable
2254code. Randomizing its location makes it impossible to inject jumps misusing
2255a code at its expected addresses.
2256
2257Prelinking shared libraries provides a startup performance advantage but it
2258makes addresses in these libraries predictable for privileged processes by
2259having just unprivileged access at the target system. Reading the shared
2260library binary gives enough information for assembling the malicious code
2261misusing it. Still even a prelinked shared library can get loaded at a new
2262random address just requiring the regular relocation process during the
2263startup. Shared libraries not already prelinked are always loaded at
2264a randomly chosen address.
2265
2266Position independent executables (PIE) contain position independent code
2267similar to the shared libraries and therefore such executables get loaded at
2268a randomly chosen address upon startup. PIE executables always load even
2269already prelinked shared libraries at a random address. You can build such
2270executable using @command{gcc -fPIE -pie}.
2271
2272Heap (malloc storage), stack and custom mmap areas are always placed randomly
2273(as long as the randomization is enabled).
2274
2275@item show disable-randomization
2276Show the current setting of the explicit disable of the native randomization of
2277the virtual address space of the started program.
2278
4e8b0763
JB
2279@end table
2280
6d2ebf8b 2281@node Arguments
79a6e687 2282@section Your Program's Arguments
c906108c
SS
2283
2284@cindex arguments (to your program)
2285The arguments to your program can be specified by the arguments of the
5d161b24 2286@code{run} command.
c906108c
SS
2287They are passed to a shell, which expands wildcard characters and
2288performs redirection of I/O, and thence to your program. Your
2289@code{SHELL} environment variable (if it exists) specifies what shell
2290@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
2291the default shell (@file{/bin/sh} on Unix).
2292
2293On non-Unix systems, the program is usually invoked directly by
2294@value{GDBN}, which emulates I/O redirection via the appropriate system
2295calls, and the wildcard characters are expanded by the startup code of
2296the program, not by the shell.
c906108c
SS
2297
2298@code{run} with no arguments uses the same arguments used by the previous
2299@code{run}, or those set by the @code{set args} command.
2300
c906108c 2301@table @code
41afff9a 2302@kindex set args
c906108c
SS
2303@item set args
2304Specify the arguments to be used the next time your program is run. If
2305@code{set args} has no arguments, @code{run} executes your program
2306with no arguments. Once you have run your program with arguments,
2307using @code{set args} before the next @code{run} is the only way to run
2308it again without arguments.
2309
2310@kindex show args
2311@item show args
2312Show the arguments to give your program when it is started.
2313@end table
2314
6d2ebf8b 2315@node Environment
79a6e687 2316@section Your Program's Environment
c906108c
SS
2317
2318@cindex environment (of your program)
2319The @dfn{environment} consists of a set of environment variables and
2320their values. Environment variables conventionally record such things as
2321your user name, your home directory, your terminal type, and your search
2322path for programs to run. Usually you set up environment variables with
2323the shell and they are inherited by all the other programs you run. When
2324debugging, it can be useful to try running your program with a modified
2325environment without having to start @value{GDBN} over again.
2326
2327@table @code
2328@kindex path
2329@item path @var{directory}
2330Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
2331(the search path for executables) that will be passed to your program.
2332The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
2333You may specify several directory names, separated by whitespace or by a
2334system-dependent separator character (@samp{:} on Unix, @samp{;} on
2335MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2336is moved to the front, so it is searched sooner.
c906108c
SS
2337
2338You can use the string @samp{$cwd} to refer to whatever is the current
2339working directory at the time @value{GDBN} searches the path. If you
2340use @samp{.} instead, it refers to the directory where you executed the
2341@code{path} command. @value{GDBN} replaces @samp{.} in the
2342@var{directory} argument (with the current path) before adding
2343@var{directory} to the search path.
2344@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2345@c document that, since repeating it would be a no-op.
2346
2347@kindex show paths
2348@item show paths
2349Display the list of search paths for executables (the @code{PATH}
2350environment variable).
2351
2352@kindex show environment
2353@item show environment @r{[}@var{varname}@r{]}
2354Print the value of environment variable @var{varname} to be given to
2355your program when it starts. If you do not supply @var{varname},
2356print the names and values of all environment variables to be given to
2357your program. You can abbreviate @code{environment} as @code{env}.
2358
2359@kindex set environment
53a5351d 2360@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c 2361Set environment variable @var{varname} to @var{value}. The value
41ef2965 2362changes for your program (and the shell @value{GDBN} uses to launch
697aa1b7 2363it), not for @value{GDBN} itself. The @var{value} may be any string; the
41ef2965
PA
2364values of environment variables are just strings, and any
2365interpretation is supplied by your program itself. The @var{value}
c906108c
SS
2366parameter is optional; if it is eliminated, the variable is set to a
2367null value.
2368@c "any string" here does not include leading, trailing
2369@c blanks. Gnu asks: does anyone care?
2370
2371For example, this command:
2372
474c8240 2373@smallexample
c906108c 2374set env USER = foo
474c8240 2375@end smallexample
c906108c
SS
2376
2377@noindent
d4f3574e 2378tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2379@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2380are not actually required.)
2381
41ef2965
PA
2382Note that on Unix systems, @value{GDBN} runs your program via a shell,
2383which also inherits the environment set with @code{set environment}.
2384If necessary, you can avoid that by using the @samp{env} program as a
2385wrapper instead of using @code{set environment}. @xref{set
2386exec-wrapper}, for an example doing just that.
2387
c906108c
SS
2388@kindex unset environment
2389@item unset environment @var{varname}
2390Remove variable @var{varname} from the environment to be passed to your
2391program. This is different from @samp{set env @var{varname} =};
2392@code{unset environment} removes the variable from the environment,
2393rather than assigning it an empty value.
2394@end table
2395
d4f3574e 2396@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
afa332ce
PA
2397the shell indicated by your @code{SHELL} environment variable if it
2398exists (or @code{/bin/sh} if not). If your @code{SHELL} variable
2399names a shell that runs an initialization file when started
2400non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2401for the Z shell, or the file specified in the @samp{BASH_ENV}
2402environment variable for BASH---any variables you set in that file
2403affect your program. You may wish to move setting of environment
2404variables to files that are only run when you sign on, such as
2405@file{.login} or @file{.profile}.
c906108c 2406
6d2ebf8b 2407@node Working Directory
79a6e687 2408@section Your Program's Working Directory
c906108c
SS
2409
2410@cindex working directory (of your program)
2411Each time you start your program with @code{run}, it inherits its
2412working directory from the current working directory of @value{GDBN}.
2413The @value{GDBN} working directory is initially whatever it inherited
2414from its parent process (typically the shell), but you can specify a new
2415working directory in @value{GDBN} with the @code{cd} command.
2416
2417The @value{GDBN} working directory also serves as a default for the commands
2418that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
79a6e687 2419Specify Files}.
c906108c
SS
2420
2421@table @code
2422@kindex cd
721c2651 2423@cindex change working directory
f3c8a52a
JK
2424@item cd @r{[}@var{directory}@r{]}
2425Set the @value{GDBN} working directory to @var{directory}. If not
2426given, @var{directory} uses @file{'~'}.
c906108c
SS
2427
2428@kindex pwd
2429@item pwd
2430Print the @value{GDBN} working directory.
2431@end table
2432
60bf7e09
EZ
2433It is generally impossible to find the current working directory of
2434the process being debugged (since a program can change its directory
2435during its run). If you work on a system where @value{GDBN} is
2436configured with the @file{/proc} support, you can use the @code{info
2437proc} command (@pxref{SVR4 Process Information}) to find out the
2438current working directory of the debuggee.
2439
6d2ebf8b 2440@node Input/Output
79a6e687 2441@section Your Program's Input and Output
c906108c
SS
2442
2443@cindex redirection
2444@cindex i/o
2445@cindex terminal
2446By default, the program you run under @value{GDBN} does input and output to
5d161b24 2447the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2448to its own terminal modes to interact with you, but it records the terminal
2449modes your program was using and switches back to them when you continue
2450running your program.
2451
2452@table @code
2453@kindex info terminal
2454@item info terminal
2455Displays information recorded by @value{GDBN} about the terminal modes your
2456program is using.
2457@end table
2458
2459You can redirect your program's input and/or output using shell
2460redirection with the @code{run} command. For example,
2461
474c8240 2462@smallexample
c906108c 2463run > outfile
474c8240 2464@end smallexample
c906108c
SS
2465
2466@noindent
2467starts your program, diverting its output to the file @file{outfile}.
2468
2469@kindex tty
2470@cindex controlling terminal
2471Another way to specify where your program should do input and output is
2472with the @code{tty} command. This command accepts a file name as
2473argument, and causes this file to be the default for future @code{run}
2474commands. It also resets the controlling terminal for the child
2475process, for future @code{run} commands. For example,
2476
474c8240 2477@smallexample
c906108c 2478tty /dev/ttyb
474c8240 2479@end smallexample
c906108c
SS
2480
2481@noindent
2482directs that processes started with subsequent @code{run} commands
2483default to do input and output on the terminal @file{/dev/ttyb} and have
2484that as their controlling terminal.
2485
2486An explicit redirection in @code{run} overrides the @code{tty} command's
2487effect on the input/output device, but not its effect on the controlling
2488terminal.
2489
2490When you use the @code{tty} command or redirect input in the @code{run}
2491command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2492for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2493for @code{set inferior-tty}.
2494
2495@cindex inferior tty
2496@cindex set inferior controlling terminal
2497You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2498display the name of the terminal that will be used for future runs of your
2499program.
2500
2501@table @code
2502@item set inferior-tty /dev/ttyb
2503@kindex set inferior-tty
2504Set the tty for the program being debugged to /dev/ttyb.
2505
2506@item show inferior-tty
2507@kindex show inferior-tty
2508Show the current tty for the program being debugged.
2509@end table
c906108c 2510
6d2ebf8b 2511@node Attach
79a6e687 2512@section Debugging an Already-running Process
c906108c
SS
2513@kindex attach
2514@cindex attach
2515
2516@table @code
2517@item attach @var{process-id}
2518This command attaches to a running process---one that was started
2519outside @value{GDBN}. (@code{info files} shows your active
2520targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2521find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2522or with the @samp{jobs -l} shell command.
2523
2524@code{attach} does not repeat if you press @key{RET} a second time after
2525executing the command.
2526@end table
2527
2528To use @code{attach}, your program must be running in an environment
2529which supports processes; for example, @code{attach} does not work for
2530programs on bare-board targets that lack an operating system. You must
2531also have permission to send the process a signal.
2532
2533When you use @code{attach}, the debugger finds the program running in
2534the process first by looking in the current working directory, then (if
2535the program is not found) by using the source file search path
79a6e687 2536(@pxref{Source Path, ,Specifying Source Directories}). You can also use
c906108c
SS
2537the @code{file} command to load the program. @xref{Files, ,Commands to
2538Specify Files}.
2539
2540The first thing @value{GDBN} does after arranging to debug the specified
2541process is to stop it. You can examine and modify an attached process
53a5351d
JM
2542with all the @value{GDBN} commands that are ordinarily available when
2543you start processes with @code{run}. You can insert breakpoints; you
2544can step and continue; you can modify storage. If you would rather the
2545process continue running, you may use the @code{continue} command after
c906108c
SS
2546attaching @value{GDBN} to the process.
2547
2548@table @code
2549@kindex detach
2550@item detach
2551When you have finished debugging the attached process, you can use the
2552@code{detach} command to release it from @value{GDBN} control. Detaching
2553the process continues its execution. After the @code{detach} command,
2554that process and @value{GDBN} become completely independent once more, and you
2555are ready to @code{attach} another process or start one with @code{run}.
2556@code{detach} does not repeat if you press @key{RET} again after
2557executing the command.
2558@end table
2559
159fcc13
JK
2560If you exit @value{GDBN} while you have an attached process, you detach
2561that process. If you use the @code{run} command, you kill that process.
2562By default, @value{GDBN} asks for confirmation if you try to do either of these
2563things; you can control whether or not you need to confirm by using the
2564@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
79a6e687 2565Messages}).
c906108c 2566
6d2ebf8b 2567@node Kill Process
79a6e687 2568@section Killing the Child Process
c906108c
SS
2569
2570@table @code
2571@kindex kill
2572@item kill
2573Kill the child process in which your program is running under @value{GDBN}.
2574@end table
2575
2576This command is useful if you wish to debug a core dump instead of a
2577running process. @value{GDBN} ignores any core dump file while your program
2578is running.
2579
2580On some operating systems, a program cannot be executed outside @value{GDBN}
2581while you have breakpoints set on it inside @value{GDBN}. You can use the
2582@code{kill} command in this situation to permit running your program
2583outside the debugger.
2584
2585The @code{kill} command is also useful if you wish to recompile and
2586relink your program, since on many systems it is impossible to modify an
2587executable file while it is running in a process. In this case, when you
2588next type @code{run}, @value{GDBN} notices that the file has changed, and
2589reads the symbol table again (while trying to preserve your current
2590breakpoint settings).
2591
6c95b8df
PA
2592@node Inferiors and Programs
2593@section Debugging Multiple Inferiors and Programs
b77209e0 2594
6c95b8df
PA
2595@value{GDBN} lets you run and debug multiple programs in a single
2596session. In addition, @value{GDBN} on some systems may let you run
2597several programs simultaneously (otherwise you have to exit from one
2598before starting another). In the most general case, you can have
2599multiple threads of execution in each of multiple processes, launched
2600from multiple executables.
b77209e0
PA
2601
2602@cindex inferior
2603@value{GDBN} represents the state of each program execution with an
2604object called an @dfn{inferior}. An inferior typically corresponds to
2605a process, but is more general and applies also to targets that do not
2606have processes. Inferiors may be created before a process runs, and
6c95b8df
PA
2607may be retained after a process exits. Inferiors have unique
2608identifiers that are different from process ids. Usually each
2609inferior will also have its own distinct address space, although some
2610embedded targets may have several inferiors running in different parts
2611of a single address space. Each inferior may in turn have multiple
2612threads running in it.
b77209e0 2613
6c95b8df
PA
2614To find out what inferiors exist at any moment, use @w{@code{info
2615inferiors}}:
b77209e0
PA
2616
2617@table @code
2618@kindex info inferiors
2619@item info inferiors
2620Print a list of all inferiors currently being managed by @value{GDBN}.
3a1ff0b6
PA
2621
2622@value{GDBN} displays for each inferior (in this order):
2623
2624@enumerate
2625@item
2626the inferior number assigned by @value{GDBN}
2627
2628@item
2629the target system's inferior identifier
6c95b8df
PA
2630
2631@item
2632the name of the executable the inferior is running.
2633
3a1ff0b6
PA
2634@end enumerate
2635
2636@noindent
2637An asterisk @samp{*} preceding the @value{GDBN} inferior number
2638indicates the current inferior.
2639
2640For example,
2277426b 2641@end table
3a1ff0b6
PA
2642@c end table here to get a little more width for example
2643
2644@smallexample
2645(@value{GDBP}) info inferiors
6c95b8df
PA
2646 Num Description Executable
2647 2 process 2307 hello
2648* 1 process 3401 goodbye
3a1ff0b6 2649@end smallexample
2277426b
PA
2650
2651To switch focus between inferiors, use the @code{inferior} command:
2652
2653@table @code
3a1ff0b6
PA
2654@kindex inferior @var{infno}
2655@item inferior @var{infno}
2656Make inferior number @var{infno} the current inferior. The argument
2657@var{infno} is the inferior number assigned by @value{GDBN}, as shown
2658in the first field of the @samp{info inferiors} display.
2277426b
PA
2659@end table
2660
e3940304
PA
2661@vindex $_inferior@r{, convenience variable}
2662The debugger convenience variable @samp{$_inferior} contains the
2663number of the current inferior. You may find this useful in writing
2664breakpoint conditional expressions, command scripts, and so forth.
2665@xref{Convenience Vars,, Convenience Variables}, for general
2666information on convenience variables.
6c95b8df
PA
2667
2668You can get multiple executables into a debugging session via the
2669@code{add-inferior} and @w{@code{clone-inferior}} commands. On some
2670systems @value{GDBN} can add inferiors to the debug session
2671automatically by following calls to @code{fork} and @code{exec}. To
2672remove inferiors from the debugging session use the
af624141 2673@w{@code{remove-inferiors}} command.
6c95b8df
PA
2674
2675@table @code
2676@kindex add-inferior
2677@item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ]
2678Adds @var{n} inferiors to be run using @var{executable} as the
697aa1b7 2679executable; @var{n} defaults to 1. If no executable is specified,
6c95b8df
PA
2680the inferiors begins empty, with no program. You can still assign or
2681change the program assigned to the inferior at any time by using the
2682@code{file} command with the executable name as its argument.
2683
2684@kindex clone-inferior
2685@item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
2686Adds @var{n} inferiors ready to execute the same program as inferior
697aa1b7 2687@var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
6c95b8df
PA
2688number of the current inferior. This is a convenient command when you
2689want to run another instance of the inferior you are debugging.
2690
2691@smallexample
2692(@value{GDBP}) info inferiors
2693 Num Description Executable
2694* 1 process 29964 helloworld
2695(@value{GDBP}) clone-inferior
2696Added inferior 2.
26971 inferiors added.
2698(@value{GDBP}) info inferiors
2699 Num Description Executable
2700 2 <null> helloworld
2701* 1 process 29964 helloworld
2702@end smallexample
2703
2704You can now simply switch focus to inferior 2 and run it.
2705
af624141
MS
2706@kindex remove-inferiors
2707@item remove-inferiors @var{infno}@dots{}
2708Removes the inferior or inferiors @var{infno}@dots{}. It is not
2709possible to remove an inferior that is running with this command. For
2710those, use the @code{kill} or @code{detach} command first.
6c95b8df
PA
2711
2712@end table
2713
2714To quit debugging one of the running inferiors that is not the current
2715inferior, you can either detach from it by using the @w{@code{detach
2716inferior}} command (allowing it to run independently), or kill it
af624141 2717using the @w{@code{kill inferiors}} command:
2277426b
PA
2718
2719@table @code
af624141
MS
2720@kindex detach inferiors @var{infno}@dots{}
2721@item detach inferior @var{infno}@dots{}
2722Detach from the inferior or inferiors identified by @value{GDBN}
5e30da2c 2723inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
af624141
MS
2724still stays on the list of inferiors shown by @code{info inferiors},
2725but its Description will show @samp{<null>}.
2726
2727@kindex kill inferiors @var{infno}@dots{}
2728@item kill inferiors @var{infno}@dots{}
2729Kill the inferior or inferiors identified by @value{GDBN} inferior
2730number(s) @var{infno}@dots{}. Note that the inferior's entry still
2731stays on the list of inferiors shown by @code{info inferiors}, but its
2732Description will show @samp{<null>}.
2277426b
PA
2733@end table
2734
6c95b8df 2735After the successful completion of a command such as @code{detach},
af624141 2736@code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
6c95b8df
PA
2737a normal process exit, the inferior is still valid and listed with
2738@code{info inferiors}, ready to be restarted.
2739
2740
2277426b
PA
2741To be notified when inferiors are started or exit under @value{GDBN}'s
2742control use @w{@code{set print inferior-events}}:
b77209e0 2743
2277426b 2744@table @code
b77209e0
PA
2745@kindex set print inferior-events
2746@cindex print messages on inferior start and exit
2747@item set print inferior-events
2748@itemx set print inferior-events on
2749@itemx set print inferior-events off
2750The @code{set print inferior-events} command allows you to enable or
2751disable printing of messages when @value{GDBN} notices that new
2752inferiors have started or that inferiors have exited or have been
2753detached. By default, these messages will not be printed.
2754
2755@kindex show print inferior-events
2756@item show print inferior-events
2757Show whether messages will be printed when @value{GDBN} detects that
2758inferiors have started, exited or have been detached.
2759@end table
2760
6c95b8df
PA
2761Many commands will work the same with multiple programs as with a
2762single program: e.g., @code{print myglobal} will simply display the
2763value of @code{myglobal} in the current inferior.
2764
2765
2766Occasionaly, when debugging @value{GDBN} itself, it may be useful to
2767get more info about the relationship of inferiors, programs, address
2768spaces in a debug session. You can do that with the @w{@code{maint
2769info program-spaces}} command.
2770
2771@table @code
2772@kindex maint info program-spaces
2773@item maint info program-spaces
2774Print a list of all program spaces currently being managed by
2775@value{GDBN}.
2776
2777@value{GDBN} displays for each program space (in this order):
2778
2779@enumerate
2780@item
2781the program space number assigned by @value{GDBN}
2782
2783@item
2784the name of the executable loaded into the program space, with e.g.,
2785the @code{file} command.
2786
2787@end enumerate
2788
2789@noindent
2790An asterisk @samp{*} preceding the @value{GDBN} program space number
2791indicates the current program space.
2792
2793In addition, below each program space line, @value{GDBN} prints extra
2794information that isn't suitable to display in tabular form. For
2795example, the list of inferiors bound to the program space.
2796
2797@smallexample
2798(@value{GDBP}) maint info program-spaces
2799 Id Executable
b05b1202 2800* 1 hello
6c95b8df
PA
2801 2 goodbye
2802 Bound inferiors: ID 1 (process 21561)
6c95b8df
PA
2803@end smallexample
2804
2805Here we can see that no inferior is running the program @code{hello},
2806while @code{process 21561} is running the program @code{goodbye}. On
2807some targets, it is possible that multiple inferiors are bound to the
2808same program space. The most common example is that of debugging both
2809the parent and child processes of a @code{vfork} call. For example,
2810
2811@smallexample
2812(@value{GDBP}) maint info program-spaces
2813 Id Executable
2814* 1 vfork-test
2815 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
2816@end smallexample
2817
2818Here, both inferior 2 and inferior 1 are running in the same program
2819space as a result of inferior 1 having executed a @code{vfork} call.
2820@end table
2821
6d2ebf8b 2822@node Threads
79a6e687 2823@section Debugging Programs with Multiple Threads
c906108c
SS
2824
2825@cindex threads of execution
2826@cindex multiple threads
2827@cindex switching threads
b1236ac3 2828In some operating systems, such as GNU/Linux and Solaris, a single program
c906108c
SS
2829may have more than one @dfn{thread} of execution. The precise semantics
2830of threads differ from one operating system to another, but in general
2831the threads of a single program are akin to multiple processes---except
2832that they share one address space (that is, they can all examine and
2833modify the same variables). On the other hand, each thread has its own
2834registers and execution stack, and perhaps private memory.
2835
2836@value{GDBN} provides these facilities for debugging multi-thread
2837programs:
2838
2839@itemize @bullet
2840@item automatic notification of new threads
5d5658a1 2841@item @samp{thread @var{thread-id}}, a command to switch among threads
c906108c 2842@item @samp{info threads}, a command to inquire about existing threads
5d5658a1 2843@item @samp{thread apply [@var{thread-id-list}] [@var{all}] @var{args}},
c906108c
SS
2844a command to apply a command to a list of threads
2845@item thread-specific breakpoints
93815fbf
VP
2846@item @samp{set print thread-events}, which controls printing of
2847messages on thread start and exit.
17a37d48
PP
2848@item @samp{set libthread-db-search-path @var{path}}, which lets
2849the user specify which @code{libthread_db} to use if the default choice
2850isn't compatible with the program.
c906108c
SS
2851@end itemize
2852
c906108c
SS
2853@cindex focus of debugging
2854@cindex current thread
2855The @value{GDBN} thread debugging facility allows you to observe all
2856threads while your program runs---but whenever @value{GDBN} takes
2857control, one thread in particular is always the focus of debugging.
2858This thread is called the @dfn{current thread}. Debugging commands show
2859program information from the perspective of the current thread.
2860
41afff9a 2861@cindex @code{New} @var{systag} message
c906108c
SS
2862@cindex thread identifier (system)
2863@c FIXME-implementors!! It would be more helpful if the [New...] message
2864@c included GDB's numeric thread handle, so you could just go to that
2865@c thread without first checking `info threads'.
2866Whenever @value{GDBN} detects a new thread in your program, it displays
2867the target system's identification for the thread with a message in the
697aa1b7 2868form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
c906108c 2869whose form varies depending on the particular system. For example, on
8807d78b 2870@sc{gnu}/Linux, you might see
c906108c 2871
474c8240 2872@smallexample
08e796bc 2873[New Thread 0x41e02940 (LWP 25582)]
474c8240 2874@end smallexample
c906108c
SS
2875
2876@noindent
b1236ac3 2877when @value{GDBN} notices a new thread. In contrast, on other systems,
c906108c
SS
2878the @var{systag} is simply something like @samp{process 368}, with no
2879further qualifier.
2880
2881@c FIXME!! (1) Does the [New...] message appear even for the very first
2882@c thread of a program, or does it only appear for the
6ca652b0 2883@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2884@c program?
2885@c (2) *Is* there necessarily a first thread always? Or do some
2886@c multithread systems permit starting a program with multiple
5d161b24 2887@c threads ab initio?
c906108c 2888
5d5658a1
PA
2889@anchor{thread numbers}
2890@cindex thread number, per inferior
c906108c 2891@cindex thread identifier (GDB)
5d5658a1
PA
2892For debugging purposes, @value{GDBN} associates its own thread number
2893---always a single integer---with each thread of an inferior. This
2894number is unique between all threads of an inferior, but not unique
2895between threads of different inferiors.
2896
2897@cindex qualified thread ID
2898You can refer to a given thread in an inferior using the qualified
2899@var{inferior-num}.@var{thread-num} syntax, also known as
2900@dfn{qualified thread ID}, with @var{inferior-num} being the inferior
2901number and @var{thread-num} being the thread number of the given
2902inferior. For example, thread @code{2.3} refers to thread number 3 of
2903inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
2904then @value{GDBN} infers you're referring to a thread of the current
2905inferior.
2906
2907Until you create a second inferior, @value{GDBN} does not show the
2908@var{inferior-num} part of thread IDs, even though you can always use
2909the full @var{inferior-num}.@var{thread-num} form to refer to threads
2910of inferior 1, the initial inferior.
2911
2912@anchor{thread ID lists}
2913@cindex thread ID lists
2914Some commands accept a space-separated @dfn{thread ID list} as
2915argument. A list element can be a thread ID as shown in the first
2916field of the @samp{info threads} display, with or without an inferior
2917qualifier (e.g., @samp{2.1} or @samp{1}); or can be a range of thread
2918numbers, again with or without an inferior qualifier, as in
2919@var{inf1}.@var{thr1}-@var{thr2} or @var{thr1}-@var{thr2} (e.g.,
2920@samp{1.2-4} or @samp{2-4}). For example, if the current inferior is
29211, the thread list @samp{1 2-3 4.5 6.7-9} includes threads 1 to 3 of
2922inferior 1, thread 5 of inferior 4 and threads 7 to 9 of inferior 6.
2923That is, in expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5
29246.7 6.8 6.9}.
2925
2926@anchor{global thread numbers}
2927@cindex global thread number
2928@cindex global thread identifier (GDB)
2929In addition to a @emph{per-inferior} number, each thread is also
2930assigned a unique @emph{global} number, also known as @dfn{global
2931thread ID}, a single integer. Unlike the thread number component of
2932the thread ID, no two threads have the same global ID, even when
2933you're debugging multiple inferiors.
c906108c 2934
f4f4330e
PA
2935From @value{GDBN}'s perspective, a process always has at least one
2936thread. In other words, @value{GDBN} assigns a thread number to the
2937program's ``main thread'' even if the program is not multi-threaded.
2938
5d5658a1 2939@vindex $_thread@r{, convenience variable}
663f6d42
PA
2940@vindex $_gthread@r{, convenience variable}
2941The debugger convenience variables @samp{$_thread} and
2942@samp{$_gthread} contain, respectively, the per-inferior thread number
2943and the global thread number of the current thread. You may find this
5d5658a1
PA
2944useful in writing breakpoint conditional expressions, command scripts,
2945and so forth. @xref{Convenience Vars,, Convenience Variables}, for
2946general information on convenience variables.
2947
c906108c
SS
2948@table @code
2949@kindex info threads
5d5658a1
PA
2950@item info threads @r{[}@var{thread-id-list}@r{]}
2951
2952Display information about one or more threads. With no arguments
2953displays information about all threads. You can specify the list of
2954threads that you want to display using the thread ID list syntax
2955(@pxref{thread ID lists}).
2956
60f98dde 2957@value{GDBN} displays for each thread (in this order):
c906108c
SS
2958
2959@enumerate
09d4efe1 2960@item
5d5658a1 2961the per-inferior thread number assigned by @value{GDBN}
c906108c 2962
c84f6bbf
PA
2963@item
2964the global thread number assigned by @value{GDBN}, if the @samp{-gid}
2965option was specified
2966
09d4efe1
EZ
2967@item
2968the target system's thread identifier (@var{systag})
c906108c 2969
4694da01
TT
2970@item
2971the thread's name, if one is known. A thread can either be named by
2972the user (see @code{thread name}, below), or, in some cases, by the
2973program itself.
2974
09d4efe1
EZ
2975@item
2976the current stack frame summary for that thread
c906108c
SS
2977@end enumerate
2978
2979@noindent
2980An asterisk @samp{*} to the left of the @value{GDBN} thread number
2981indicates the current thread.
2982
5d161b24 2983For example,
c906108c
SS
2984@end table
2985@c end table here to get a little more width for example
2986
2987@smallexample
2988(@value{GDBP}) info threads
13fd8b81 2989 Id Target Id Frame
c0ecb95f 2990* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
b05b1202
PA
2991 2 process 35 thread 23 0x34e5 in sigpause ()
2992 3 process 35 thread 27 0x34e5 in sigpause ()
c906108c
SS
2993 at threadtest.c:68
2994@end smallexample
53a5351d 2995
5d5658a1
PA
2996If you're debugging multiple inferiors, @value{GDBN} displays thread
2997IDs using the qualified @var{inferior-num}.@var{thread-num} format.
c84f6bbf
PA
2998Otherwise, only @var{thread-num} is shown.
2999
3000If you specify the @samp{-gid} option, @value{GDBN} displays a column
3001indicating each thread's global thread ID:
5d5658a1
PA
3002
3003@smallexample
3004(@value{GDBP}) info threads
c84f6bbf
PA
3005 Id GId Target Id Frame
3006 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3007 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3008 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3009* 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
5d5658a1
PA
3010@end smallexample
3011
c45da7e6
EZ
3012On Solaris, you can display more information about user threads with a
3013Solaris-specific command:
3014
3015@table @code
3016@item maint info sol-threads
3017@kindex maint info sol-threads
3018@cindex thread info (Solaris)
3019Display info on Solaris user threads.
3020@end table
3021
c906108c 3022@table @code
5d5658a1
PA
3023@kindex thread @var{thread-id}
3024@item thread @var{thread-id}
3025Make thread ID @var{thread-id} the current thread. The command
3026argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3027the first field of the @samp{info threads} display, with or without an
3028inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3029
3030@value{GDBN} responds by displaying the system identifier of the
3031thread you selected, and its current stack frame summary:
c906108c
SS
3032
3033@smallexample
c906108c 3034(@value{GDBP}) thread 2
13fd8b81
TT
3035[Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3036#0 some_function (ignore=0x0) at example.c:8
30378 printf ("hello\n");
c906108c
SS
3038@end smallexample
3039
3040@noindent
3041As with the @samp{[New @dots{}]} message, the form of the text after
3042@samp{Switching to} depends on your system's conventions for identifying
5d161b24 3043threads.
c906108c 3044
9c16f35a 3045@kindex thread apply
638ac427 3046@cindex apply command to several threads
5d5658a1 3047@item thread apply [@var{thread-id-list} | all [-ascending]] @var{command}
839c27b7 3048The @code{thread apply} command allows you to apply the named
5d5658a1
PA
3049@var{command} to one or more threads. Specify the threads that you
3050want affected using the thread ID list syntax (@pxref{thread ID
3051lists}), or specify @code{all} to apply to all threads. To apply a
3052command to all threads in descending order, type @kbd{thread apply all
253828f1
JK
3053@var{command}}. To apply a command to all threads in ascending order,
3054type @kbd{thread apply all -ascending @var{command}}.
3055
93815fbf 3056
4694da01
TT
3057@kindex thread name
3058@cindex name a thread
3059@item thread name [@var{name}]
3060This command assigns a name to the current thread. If no argument is
3061given, any existing user-specified name is removed. The thread name
3062appears in the @samp{info threads} display.
3063
3064On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3065determine the name of the thread as given by the OS. On these
3066systems, a name specified with @samp{thread name} will override the
3067system-give name, and removing the user-specified name will cause
3068@value{GDBN} to once again display the system-specified name.
3069
60f98dde
MS
3070@kindex thread find
3071@cindex search for a thread
3072@item thread find [@var{regexp}]
3073Search for and display thread ids whose name or @var{systag}
3074matches the supplied regular expression.
3075
3076As well as being the complement to the @samp{thread name} command,
3077this command also allows you to identify a thread by its target
3078@var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3079is the LWP id.
3080
3081@smallexample
3082(@value{GDBN}) thread find 26688
3083Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3084(@value{GDBN}) info thread 4
3085 Id Target Id Frame
3086 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3087@end smallexample
3088
93815fbf
VP
3089@kindex set print thread-events
3090@cindex print messages on thread start and exit
3091@item set print thread-events
3092@itemx set print thread-events on
3093@itemx set print thread-events off
3094The @code{set print thread-events} command allows you to enable or
3095disable printing of messages when @value{GDBN} notices that new threads have
3096started or that threads have exited. By default, these messages will
3097be printed if detection of these events is supported by the target.
3098Note that these messages cannot be disabled on all targets.
3099
3100@kindex show print thread-events
3101@item show print thread-events
3102Show whether messages will be printed when @value{GDBN} detects that threads
3103have started and exited.
c906108c
SS
3104@end table
3105
79a6e687 3106@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
c906108c
SS
3107more information about how @value{GDBN} behaves when you stop and start
3108programs with multiple threads.
3109
79a6e687 3110@xref{Set Watchpoints,,Setting Watchpoints}, for information about
c906108c 3111watchpoints in programs with multiple threads.
c906108c 3112
bf88dd68 3113@anchor{set libthread-db-search-path}
17a37d48
PP
3114@table @code
3115@kindex set libthread-db-search-path
3116@cindex search path for @code{libthread_db}
3117@item set libthread-db-search-path @r{[}@var{path}@r{]}
3118If this variable is set, @var{path} is a colon-separated list of
3119directories @value{GDBN} will use to search for @code{libthread_db}.
3120If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
98a5dd13 3121its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
7e0396aa
DE
3122Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3123macro.
17a37d48
PP
3124
3125On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3126@code{libthread_db} library to obtain information about threads in the
3127inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
bf88dd68
JK
3128to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3129specific thread debugging library loading is enabled
3130by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3131
3132A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3133refers to the default system directories that are
bf88dd68
JK
3134normally searched for loading shared libraries. The @samp{$sdir} entry
3135is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3136(@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3137
3138A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3139refers to the directory from which @code{libpthread}
3140was loaded in the inferior process.
17a37d48
PP
3141
3142For any @code{libthread_db} library @value{GDBN} finds in above directories,
3143@value{GDBN} attempts to initialize it with the current inferior process.
3144If this initialization fails (which could happen because of a version
3145mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3146will unload @code{libthread_db}, and continue with the next directory.
3147If none of @code{libthread_db} libraries initialize successfully,
3148@value{GDBN} will issue a warning and thread debugging will be disabled.
3149
3150Setting @code{libthread-db-search-path} is currently implemented
3151only on some platforms.
3152
3153@kindex show libthread-db-search-path
3154@item show libthread-db-search-path
3155Display current libthread_db search path.
02d868e8
PP
3156
3157@kindex set debug libthread-db
3158@kindex show debug libthread-db
3159@cindex debugging @code{libthread_db}
3160@item set debug libthread-db
3161@itemx show debug libthread-db
3162Turns on or off display of @code{libthread_db}-related events.
3163Use @code{1} to enable, @code{0} to disable.
17a37d48
PP
3164@end table
3165
6c95b8df
PA
3166@node Forks
3167@section Debugging Forks
c906108c
SS
3168
3169@cindex fork, debugging programs which call
3170@cindex multiple processes
3171@cindex processes, multiple
53a5351d
JM
3172On most systems, @value{GDBN} has no special support for debugging
3173programs which create additional processes using the @code{fork}
3174function. When a program forks, @value{GDBN} will continue to debug the
3175parent process and the child process will run unimpeded. If you have
3176set a breakpoint in any code which the child then executes, the child
3177will get a @code{SIGTRAP} signal which (unless it catches the signal)
3178will cause it to terminate.
c906108c
SS
3179
3180However, if you want to debug the child process there is a workaround
3181which isn't too painful. Put a call to @code{sleep} in the code which
3182the child process executes after the fork. It may be useful to sleep
3183only if a certain environment variable is set, or a certain file exists,
3184so that the delay need not occur when you don't want to run @value{GDBN}
3185on the child. While the child is sleeping, use the @code{ps} program to
3186get its process ID. Then tell @value{GDBN} (a new invocation of
3187@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 3188the child process (@pxref{Attach}). From that point on you can debug
c906108c 3189the child process just like any other process which you attached to.
c906108c 3190
b1236ac3
PA
3191On some systems, @value{GDBN} provides support for debugging programs
3192that create additional processes using the @code{fork} or @code{vfork}
3193functions. On @sc{gnu}/Linux platforms, this feature is supported
19d9d4ef 3194with kernel version 2.5.46 and later.
c906108c 3195
19d9d4ef
DB
3196The fork debugging commands are supported in native mode and when
3197connected to @code{gdbserver} in either @code{target remote} mode or
3198@code{target extended-remote} mode.
0d71eef5 3199
c906108c
SS
3200By default, when a program forks, @value{GDBN} will continue to debug
3201the parent process and the child process will run unimpeded.
3202
3203If you want to follow the child process instead of the parent process,
3204use the command @w{@code{set follow-fork-mode}}.
3205
3206@table @code
3207@kindex set follow-fork-mode
3208@item set follow-fork-mode @var{mode}
3209Set the debugger response to a program call of @code{fork} or
3210@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 3211process. The @var{mode} argument can be:
c906108c
SS
3212
3213@table @code
3214@item parent
3215The original process is debugged after a fork. The child process runs
2df3850c 3216unimpeded. This is the default.
c906108c
SS
3217
3218@item child
3219The new process is debugged after a fork. The parent process runs
3220unimpeded.
3221
c906108c
SS
3222@end table
3223
9c16f35a 3224@kindex show follow-fork-mode
c906108c 3225@item show follow-fork-mode
2df3850c 3226Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
3227@end table
3228
5c95884b
MS
3229@cindex debugging multiple processes
3230On Linux, if you want to debug both the parent and child processes, use the
3231command @w{@code{set detach-on-fork}}.
3232
3233@table @code
3234@kindex set detach-on-fork
3235@item set detach-on-fork @var{mode}
3236Tells gdb whether to detach one of the processes after a fork, or
3237retain debugger control over them both.
3238
3239@table @code
3240@item on
3241The child process (or parent process, depending on the value of
3242@code{follow-fork-mode}) will be detached and allowed to run
3243independently. This is the default.
3244
3245@item off
3246Both processes will be held under the control of @value{GDBN}.
3247One process (child or parent, depending on the value of
3248@code{follow-fork-mode}) is debugged as usual, while the other
3249is held suspended.
3250
3251@end table
3252
11310833
NR
3253@kindex show detach-on-fork
3254@item show detach-on-fork
3255Show whether detach-on-fork mode is on/off.
5c95884b
MS
3256@end table
3257
2277426b
PA
3258If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3259will retain control of all forked processes (including nested forks).
3260You can list the forked processes under the control of @value{GDBN} by
3261using the @w{@code{info inferiors}} command, and switch from one fork
6c95b8df
PA
3262to another by using the @code{inferior} command (@pxref{Inferiors and
3263Programs, ,Debugging Multiple Inferiors and Programs}).
5c95884b
MS
3264
3265To quit debugging one of the forked processes, you can either detach
af624141
MS
3266from it by using the @w{@code{detach inferiors}} command (allowing it
3267to run independently), or kill it using the @w{@code{kill inferiors}}
6c95b8df
PA
3268command. @xref{Inferiors and Programs, ,Debugging Multiple Inferiors
3269and Programs}.
5c95884b 3270
c906108c
SS
3271If you ask to debug a child process and a @code{vfork} is followed by an
3272@code{exec}, @value{GDBN} executes the new target up to the first
3273breakpoint in the new target. If you have a breakpoint set on
3274@code{main} in your original program, the breakpoint will also be set on
3275the child process's @code{main}.
3276
2277426b
PA
3277On some systems, when a child process is spawned by @code{vfork}, you
3278cannot debug the child or parent until an @code{exec} call completes.
c906108c
SS
3279
3280If you issue a @code{run} command to @value{GDBN} after an @code{exec}
6c95b8df
PA
3281call executes, the new target restarts. To restart the parent
3282process, use the @code{file} command with the parent executable name
3283as its argument. By default, after an @code{exec} call executes,
3284@value{GDBN} discards the symbols of the previous executable image.
3285You can change this behaviour with the @w{@code{set follow-exec-mode}}
3286command.
3287
3288@table @code
3289@kindex set follow-exec-mode
3290@item set follow-exec-mode @var{mode}
3291
3292Set debugger response to a program call of @code{exec}. An
3293@code{exec} call replaces the program image of a process.
3294
3295@code{follow-exec-mode} can be:
3296
3297@table @code
3298@item new
3299@value{GDBN} creates a new inferior and rebinds the process to this
3300new inferior. The program the process was running before the
3301@code{exec} call can be restarted afterwards by restarting the
3302original inferior.
3303
3304For example:
3305
3306@smallexample
3307(@value{GDBP}) info inferiors
3308(gdb) info inferior
3309 Id Description Executable
3310* 1 <null> prog1
3311(@value{GDBP}) run
3312process 12020 is executing new program: prog2
3313Program exited normally.
3314(@value{GDBP}) info inferiors
3315 Id Description Executable
c0ecb95f 3316 1 <null> prog1
b05b1202 3317* 2 <null> prog2
6c95b8df
PA
3318@end smallexample
3319
3320@item same
3321@value{GDBN} keeps the process bound to the same inferior. The new
3322executable image replaces the previous executable loaded in the
3323inferior. Restarting the inferior after the @code{exec} call, with
3324e.g., the @code{run} command, restarts the executable the process was
3325running after the @code{exec} call. This is the default mode.
3326
3327For example:
3328
3329@smallexample
3330(@value{GDBP}) info inferiors
3331 Id Description Executable
3332* 1 <null> prog1
3333(@value{GDBP}) run
3334process 12020 is executing new program: prog2
3335Program exited normally.
3336(@value{GDBP}) info inferiors
3337 Id Description Executable
3338* 1 <null> prog2
3339@end smallexample
3340
3341@end table
3342@end table
c906108c 3343
19d9d4ef
DB
3344@code{follow-exec-mode} is supported in native mode and
3345@code{target extended-remote} mode.
3346
c906108c
SS
3347You can use the @code{catch} command to make @value{GDBN} stop whenever
3348a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
79a6e687 3349Catchpoints, ,Setting Catchpoints}.
c906108c 3350
5c95884b 3351@node Checkpoint/Restart
79a6e687 3352@section Setting a @emph{Bookmark} to Return to Later
5c95884b
MS
3353
3354@cindex checkpoint
3355@cindex restart
3356@cindex bookmark
3357@cindex snapshot of a process
3358@cindex rewind program state
3359
3360On certain operating systems@footnote{Currently, only
3361@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3362program's state, called a @dfn{checkpoint}, and come back to it
3363later.
3364
3365Returning to a checkpoint effectively undoes everything that has
3366happened in the program since the @code{checkpoint} was saved. This
3367includes changes in memory, registers, and even (within some limits)
3368system state. Effectively, it is like going back in time to the
3369moment when the checkpoint was saved.
3370
3371Thus, if you're stepping thru a program and you think you're
3372getting close to the point where things go wrong, you can save
3373a checkpoint. Then, if you accidentally go too far and miss
3374the critical statement, instead of having to restart your program
3375from the beginning, you can just go back to the checkpoint and
3376start again from there.
3377
3378This can be especially useful if it takes a lot of time or
3379steps to reach the point where you think the bug occurs.
3380
3381To use the @code{checkpoint}/@code{restart} method of debugging:
3382
3383@table @code
3384@kindex checkpoint
3385@item checkpoint
3386Save a snapshot of the debugged program's current execution state.
3387The @code{checkpoint} command takes no arguments, but each checkpoint
3388is assigned a small integer id, similar to a breakpoint id.
3389
3390@kindex info checkpoints
3391@item info checkpoints
3392List the checkpoints that have been saved in the current debugging
3393session. For each checkpoint, the following information will be
3394listed:
3395
3396@table @code
3397@item Checkpoint ID
3398@item Process ID
3399@item Code Address
3400@item Source line, or label
3401@end table
3402
3403@kindex restart @var{checkpoint-id}
3404@item restart @var{checkpoint-id}
3405Restore the program state that was saved as checkpoint number
3406@var{checkpoint-id}. All program variables, registers, stack frames
3407etc.@: will be returned to the values that they had when the checkpoint
3408was saved. In essence, gdb will ``wind back the clock'' to the point
3409in time when the checkpoint was saved.
3410
3411Note that breakpoints, @value{GDBN} variables, command history etc.
3412are not affected by restoring a checkpoint. In general, a checkpoint
3413only restores things that reside in the program being debugged, not in
3414the debugger.
3415
b8db102d
MS
3416@kindex delete checkpoint @var{checkpoint-id}
3417@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
3418Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
3419
3420@end table
3421
3422Returning to a previously saved checkpoint will restore the user state
3423of the program being debugged, plus a significant subset of the system
3424(OS) state, including file pointers. It won't ``un-write'' data from
3425a file, but it will rewind the file pointer to the previous location,
3426so that the previously written data can be overwritten. For files
3427opened in read mode, the pointer will also be restored so that the
3428previously read data can be read again.
3429
3430Of course, characters that have been sent to a printer (or other
3431external device) cannot be ``snatched back'', and characters received
3432from eg.@: a serial device can be removed from internal program buffers,
3433but they cannot be ``pushed back'' into the serial pipeline, ready to
3434be received again. Similarly, the actual contents of files that have
3435been changed cannot be restored (at this time).
3436
3437However, within those constraints, you actually can ``rewind'' your
3438program to a previously saved point in time, and begin debugging it
3439again --- and you can change the course of events so as to debug a
3440different execution path this time.
3441
3442@cindex checkpoints and process id
3443Finally, there is one bit of internal program state that will be
3444different when you return to a checkpoint --- the program's process
3445id. Each checkpoint will have a unique process id (or @var{pid}),
3446and each will be different from the program's original @var{pid}.
3447If your program has saved a local copy of its process id, this could
3448potentially pose a problem.
3449
79a6e687 3450@subsection A Non-obvious Benefit of Using Checkpoints
5c95884b
MS
3451
3452On some systems such as @sc{gnu}/Linux, address space randomization
3453is performed on new processes for security reasons. This makes it
3454difficult or impossible to set a breakpoint, or watchpoint, on an
3455absolute address if you have to restart the program, since the
3456absolute location of a symbol will change from one execution to the
3457next.
3458
3459A checkpoint, however, is an @emph{identical} copy of a process.
3460Therefore if you create a checkpoint at (eg.@:) the start of main,
3461and simply return to that checkpoint instead of restarting the
3462process, you can avoid the effects of address randomization and
3463your symbols will all stay in the same place.
3464
6d2ebf8b 3465@node Stopping
c906108c
SS
3466@chapter Stopping and Continuing
3467
3468The principal purposes of using a debugger are so that you can stop your
3469program before it terminates; or so that, if your program runs into
3470trouble, you can investigate and find out why.
3471
7a292a7a
SS
3472Inside @value{GDBN}, your program may stop for any of several reasons,
3473such as a signal, a breakpoint, or reaching a new line after a
3474@value{GDBN} command such as @code{step}. You may then examine and
3475change variables, set new breakpoints or remove old ones, and then
3476continue execution. Usually, the messages shown by @value{GDBN} provide
3477ample explanation of the status of your program---but you can also
3478explicitly request this information at any time.
c906108c
SS
3479
3480@table @code
3481@kindex info program
3482@item info program
3483Display information about the status of your program: whether it is
7a292a7a 3484running or not, what process it is, and why it stopped.
c906108c
SS
3485@end table
3486
3487@menu
3488* Breakpoints:: Breakpoints, watchpoints, and catchpoints
3489* Continuing and Stepping:: Resuming execution
aad1c02c
TT
3490* Skipping Over Functions and Files::
3491 Skipping over functions and files
c906108c 3492* Signals:: Signals
c906108c 3493* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
3494@end menu
3495
6d2ebf8b 3496@node Breakpoints
79a6e687 3497@section Breakpoints, Watchpoints, and Catchpoints
c906108c
SS
3498
3499@cindex breakpoints
3500A @dfn{breakpoint} makes your program stop whenever a certain point in
3501the program is reached. For each breakpoint, you can add conditions to
3502control in finer detail whether your program stops. You can set
3503breakpoints with the @code{break} command and its variants (@pxref{Set
79a6e687 3504Breaks, ,Setting Breakpoints}), to specify the place where your program
c906108c
SS
3505should stop by line number, function name or exact address in the
3506program.
3507
09d4efe1 3508On some systems, you can set breakpoints in shared libraries before
b1236ac3 3509the executable is run.
c906108c
SS
3510
3511@cindex watchpoints
fd60e0df 3512@cindex data breakpoints
c906108c
SS
3513@cindex memory tracing
3514@cindex breakpoint on memory address
3515@cindex breakpoint on variable modification
3516A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 3517when the value of an expression changes. The expression may be a value
0ced0c34 3518of a variable, or it could involve values of one or more variables
fd60e0df
EZ
3519combined by operators, such as @samp{a + b}. This is sometimes called
3520@dfn{data breakpoints}. You must use a different command to set
79a6e687 3521watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
fd60e0df
EZ
3522from that, you can manage a watchpoint like any other breakpoint: you
3523enable, disable, and delete both breakpoints and watchpoints using the
3524same commands.
c906108c
SS
3525
3526You can arrange to have values from your program displayed automatically
3527whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
79a6e687 3528Automatic Display}.
c906108c
SS
3529
3530@cindex catchpoints
3531@cindex breakpoint on events
3532A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 3533when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
3534exception or the loading of a library. As with watchpoints, you use a
3535different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
79a6e687 3536Catchpoints}), but aside from that, you can manage a catchpoint like any
c906108c 3537other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 3538@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
3539
3540@cindex breakpoint numbers
3541@cindex numbers for breakpoints
3542@value{GDBN} assigns a number to each breakpoint, watchpoint, or
3543catchpoint when you create it; these numbers are successive integers
3544starting with one. In many of the commands for controlling various
3545features of breakpoints you use the breakpoint number to say which
3546breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
3547@dfn{disabled}; if disabled, it has no effect on your program until you
3548enable it again.
3549
c5394b80
JM
3550@cindex breakpoint ranges
3551@cindex ranges of breakpoints
3552Some @value{GDBN} commands accept a range of breakpoints on which to
3553operate. A breakpoint range is either a single breakpoint number, like
3554@samp{5}, or two such numbers, in increasing order, separated by a
3555hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
d52fb0e9 3556all breakpoints in that range are operated on.
c5394b80 3557
c906108c
SS
3558@menu
3559* Set Breaks:: Setting breakpoints
3560* Set Watchpoints:: Setting watchpoints
3561* Set Catchpoints:: Setting catchpoints
3562* Delete Breaks:: Deleting breakpoints
3563* Disabling:: Disabling breakpoints
3564* Conditions:: Break conditions
3565* Break Commands:: Breakpoint command lists
e7e0cddf 3566* Dynamic Printf:: Dynamic printf
6149aea9 3567* Save Breakpoints:: How to save breakpoints in a file
62e5f89c 3568* Static Probe Points:: Listing static probe points
d4f3574e 3569* Error in Breakpoints:: ``Cannot insert breakpoints''
79a6e687 3570* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
c906108c
SS
3571@end menu
3572
6d2ebf8b 3573@node Set Breaks
79a6e687 3574@subsection Setting Breakpoints
c906108c 3575
5d161b24 3576@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
3577@c consider in particular declaration with/without initialization.
3578@c
3579@c FIXME 2 is there stuff on this already? break at fun start, already init?
3580
3581@kindex break
41afff9a
EZ
3582@kindex b @r{(@code{break})}
3583@vindex $bpnum@r{, convenience variable}
c906108c
SS
3584@cindex latest breakpoint
3585Breakpoints are set with the @code{break} command (abbreviated
5d161b24 3586@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 3587number of the breakpoint you've set most recently; see @ref{Convenience
79a6e687 3588Vars,, Convenience Variables}, for a discussion of what you can do with
c906108c
SS
3589convenience variables.
3590
c906108c 3591@table @code
2a25a5ba
EZ
3592@item break @var{location}
3593Set a breakpoint at the given @var{location}, which can specify a
3594function name, a line number, or an address of an instruction.
3595(@xref{Specify Location}, for a list of all the possible ways to
3596specify a @var{location}.) The breakpoint will stop your program just
3597before it executes any of the code in the specified @var{location}.
3598
c906108c 3599When using source languages that permit overloading of symbols, such as
2a25a5ba 3600C@t{++}, a function name may refer to more than one possible place to break.
6ba66d6a
JB
3601@xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
3602that situation.
c906108c 3603
45ac276d 3604It is also possible to insert a breakpoint that will stop the program
2c88c651
JB
3605only if a specific thread (@pxref{Thread-Specific Breakpoints})
3606or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
45ac276d 3607
c906108c
SS
3608@item break
3609When called without any arguments, @code{break} sets a breakpoint at
3610the next instruction to be executed in the selected stack frame
3611(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
3612innermost, this makes your program stop as soon as control
3613returns to that frame. This is similar to the effect of a
3614@code{finish} command in the frame inside the selected frame---except
3615that @code{finish} does not leave an active breakpoint. If you use
3616@code{break} without an argument in the innermost frame, @value{GDBN} stops
3617the next time it reaches the current location; this may be useful
3618inside loops.
3619
3620@value{GDBN} normally ignores breakpoints when it resumes execution, until at
3621least one instruction has been executed. If it did not do this, you
3622would be unable to proceed past a breakpoint without first disabling the
3623breakpoint. This rule applies whether or not the breakpoint already
3624existed when your program stopped.
3625
3626@item break @dots{} if @var{cond}
3627Set a breakpoint with condition @var{cond}; evaluate the expression
3628@var{cond} each time the breakpoint is reached, and stop only if the
3629value is nonzero---that is, if @var{cond} evaluates as true.
3630@samp{@dots{}} stands for one of the possible arguments described
3631above (or no argument) specifying where to break. @xref{Conditions,
79a6e687 3632,Break Conditions}, for more information on breakpoint conditions.
c906108c
SS
3633
3634@kindex tbreak
3635@item tbreak @var{args}
697aa1b7 3636Set a breakpoint enabled only for one stop. The @var{args} are the
c906108c
SS
3637same as for the @code{break} command, and the breakpoint is set in the same
3638way, but the breakpoint is automatically deleted after the first time your
79a6e687 3639program stops there. @xref{Disabling, ,Disabling Breakpoints}.
c906108c 3640
c906108c 3641@kindex hbreak
ba04e063 3642@cindex hardware breakpoints
c906108c 3643@item hbreak @var{args}
697aa1b7 3644Set a hardware-assisted breakpoint. The @var{args} are the same as for the
d4f3574e 3645@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
3646breakpoint requires hardware support and some target hardware may not
3647have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
3648debugging, so you can set a breakpoint at an instruction without
3649changing the instruction. This can be used with the new trap-generation
09d4efe1 3650provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
3651will generate traps when a program accesses some data or instruction
3652address that is assigned to the debug registers. However the hardware
3653breakpoint registers can take a limited number of breakpoints. For
3654example, on the DSU, only two data breakpoints can be set at a time, and
3655@value{GDBN} will reject this command if more than two are used. Delete
3656or disable unused hardware breakpoints before setting new ones
79a6e687
BW
3657(@pxref{Disabling, ,Disabling Breakpoints}).
3658@xref{Conditions, ,Break Conditions}.
9c16f35a
EZ
3659For remote targets, you can restrict the number of hardware
3660breakpoints @value{GDBN} will use, see @ref{set remote
3661hardware-breakpoint-limit}.
501eef12 3662
c906108c
SS
3663@kindex thbreak
3664@item thbreak @var{args}
697aa1b7 3665Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
c906108c 3666are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 3667the same way. However, like the @code{tbreak} command,
c906108c
SS
3668the breakpoint is automatically deleted after the
3669first time your program stops there. Also, like the @code{hbreak}
5d161b24 3670command, the breakpoint requires hardware support and some target hardware
79a6e687
BW
3671may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
3672See also @ref{Conditions, ,Break Conditions}.
c906108c
SS
3673
3674@kindex rbreak
3675@cindex regular expression
8bd10a10 3676@cindex breakpoints at functions matching a regexp
c45da7e6 3677@cindex set breakpoints in many functions
c906108c 3678@item rbreak @var{regex}
c906108c 3679Set breakpoints on all functions matching the regular expression
11cf8741
JM
3680@var{regex}. This command sets an unconditional breakpoint on all
3681matches, printing a list of all breakpoints it set. Once these
3682breakpoints are set, they are treated just like the breakpoints set with
3683the @code{break} command. You can delete them, disable them, or make
3684them conditional the same way as any other breakpoint.
3685
3686The syntax of the regular expression is the standard one used with tools
3687like @file{grep}. Note that this is different from the syntax used by
3688shells, so for instance @code{foo*} matches all functions that include
3689an @code{fo} followed by zero or more @code{o}s. There is an implicit
3690@code{.*} leading and trailing the regular expression you supply, so to
3691match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 3692
f7dc1244 3693@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 3694When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
3695breakpoints on overloaded functions that are not members of any special
3696classes.
c906108c 3697
f7dc1244
EZ
3698@cindex set breakpoints on all functions
3699The @code{rbreak} command can be used to set breakpoints in
3700@strong{all} the functions in a program, like this:
3701
3702@smallexample
3703(@value{GDBP}) rbreak .
3704@end smallexample
3705
8bd10a10
CM
3706@item rbreak @var{file}:@var{regex}
3707If @code{rbreak} is called with a filename qualification, it limits
3708the search for functions matching the given regular expression to the
3709specified @var{file}. This can be used, for example, to set breakpoints on
3710every function in a given file:
3711
3712@smallexample
3713(@value{GDBP}) rbreak file.c:.
3714@end smallexample
3715
3716The colon separating the filename qualifier from the regex may
3717optionally be surrounded by spaces.
3718
c906108c
SS
3719@kindex info breakpoints
3720@cindex @code{$_} and @code{info breakpoints}
e5a67952
MS
3721@item info breakpoints @r{[}@var{n}@dots{}@r{]}
3722@itemx info break @r{[}@var{n}@dots{}@r{]}
c906108c 3723Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734 3724not deleted. Optional argument @var{n} means print information only
e5a67952
MS
3725about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
3726For each breakpoint, following columns are printed:
c906108c
SS
3727
3728@table @emph
3729@item Breakpoint Numbers
3730@item Type
3731Breakpoint, watchpoint, or catchpoint.
3732@item Disposition
3733Whether the breakpoint is marked to be disabled or deleted when hit.
3734@item Enabled or Disabled
3735Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
b3db7447 3736that are not enabled.
c906108c 3737@item Address
fe6fbf8b 3738Where the breakpoint is in your program, as a memory address. For a
b3db7447
NR
3739pending breakpoint whose address is not yet known, this field will
3740contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
3741library that has the symbol or line referred by breakpoint is loaded.
3742See below for details. A breakpoint with several locations will
3b784c4f 3743have @samp{<MULTIPLE>} in this field---see below for details.
c906108c
SS
3744@item What
3745Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
3746line number. For a pending breakpoint, the original string passed to
3747the breakpoint command will be listed as it cannot be resolved until
3748the appropriate shared library is loaded in the future.
c906108c
SS
3749@end table
3750
3751@noindent
83364271
LM
3752If a breakpoint is conditional, there are two evaluation modes: ``host'' and
3753``target''. If mode is ``host'', breakpoint condition evaluation is done by
3754@value{GDBN} on the host's side. If it is ``target'', then the condition
3755is evaluated by the target. The @code{info break} command shows
3756the condition on the line following the affected breakpoint, together with
3757its condition evaluation mode in between parentheses.
3758
3759Breakpoint commands, if any, are listed after that. A pending breakpoint is
3760allowed to have a condition specified for it. The condition is not parsed for
3761validity until a shared library is loaded that allows the pending
3762breakpoint to resolve to a valid location.
c906108c
SS
3763
3764@noindent
3765@code{info break} with a breakpoint
3766number @var{n} as argument lists only that breakpoint. The
3767convenience variable @code{$_} and the default examining-address for
3768the @code{x} command are set to the address of the last breakpoint
79a6e687 3769listed (@pxref{Memory, ,Examining Memory}).
c906108c
SS
3770
3771@noindent
3772@code{info break} displays a count of the number of times the breakpoint
3773has been hit. This is especially useful in conjunction with the
3774@code{ignore} command. You can ignore a large number of breakpoint
3775hits, look at the breakpoint info to see how many times the breakpoint
3776was hit, and then run again, ignoring one less than that number. This
3777will get you quickly to the last hit of that breakpoint.
816338b5
SS
3778
3779@noindent
3780For a breakpoints with an enable count (xref) greater than 1,
3781@code{info break} also displays that count.
3782
c906108c
SS
3783@end table
3784
3785@value{GDBN} allows you to set any number of breakpoints at the same place in
3786your program. There is nothing silly or meaningless about this. When
3787the breakpoints are conditional, this is even useful
79a6e687 3788(@pxref{Conditions, ,Break Conditions}).
c906108c 3789
2e9132cc
EZ
3790@cindex multiple locations, breakpoints
3791@cindex breakpoints, multiple locations
fcda367b 3792It is possible that a breakpoint corresponds to several locations
fe6fbf8b
VP
3793in your program. Examples of this situation are:
3794
3795@itemize @bullet
f8eba3c6
TT
3796@item
3797Multiple functions in the program may have the same name.
3798
fe6fbf8b
VP
3799@item
3800For a C@t{++} constructor, the @value{NGCC} compiler generates several
3801instances of the function body, used in different cases.
3802
3803@item
3804For a C@t{++} template function, a given line in the function can
3805correspond to any number of instantiations.
3806
3807@item
3808For an inlined function, a given source line can correspond to
3809several places where that function is inlined.
fe6fbf8b
VP
3810@end itemize
3811
3812In all those cases, @value{GDBN} will insert a breakpoint at all
f8eba3c6 3813the relevant locations.
fe6fbf8b 3814
3b784c4f
EZ
3815A breakpoint with multiple locations is displayed in the breakpoint
3816table using several rows---one header row, followed by one row for
3817each breakpoint location. The header row has @samp{<MULTIPLE>} in the
3818address column. The rows for individual locations contain the actual
3819addresses for locations, and show the functions to which those
3820locations belong. The number column for a location is of the form
fe6fbf8b
VP
3821@var{breakpoint-number}.@var{location-number}.
3822
3823For example:
3b784c4f 3824
fe6fbf8b
VP
3825@smallexample
3826Num Type Disp Enb Address What
38271 breakpoint keep y <MULTIPLE>
3828 stop only if i==1
3829 breakpoint already hit 1 time
38301.1 y 0x080486a2 in void foo<int>() at t.cc:8
38311.2 y 0x080486ca in void foo<double>() at t.cc:8
3832@end smallexample
3833
3834Each location can be individually enabled or disabled by passing
3835@var{breakpoint-number}.@var{location-number} as argument to the
3b784c4f
EZ
3836@code{enable} and @code{disable} commands. Note that you cannot
3837delete the individual locations from the list, you can only delete the
16bfc218 3838entire list of locations that belong to their parent breakpoint (with
3b784c4f
EZ
3839the @kbd{delete @var{num}} command, where @var{num} is the number of
3840the parent breakpoint, 1 in the above example). Disabling or enabling
3841the parent breakpoint (@pxref{Disabling}) affects all of the locations
3842that belong to that breakpoint.
fe6fbf8b 3843
2650777c 3844@cindex pending breakpoints
fe6fbf8b 3845It's quite common to have a breakpoint inside a shared library.
3b784c4f 3846Shared libraries can be loaded and unloaded explicitly,
fe6fbf8b
VP
3847and possibly repeatedly, as the program is executed. To support
3848this use case, @value{GDBN} updates breakpoint locations whenever
3849any shared library is loaded or unloaded. Typically, you would
fcda367b 3850set a breakpoint in a shared library at the beginning of your
fe6fbf8b
VP
3851debugging session, when the library is not loaded, and when the
3852symbols from the library are not available. When you try to set
3853breakpoint, @value{GDBN} will ask you if you want to set
3b784c4f 3854a so called @dfn{pending breakpoint}---breakpoint whose address
fe6fbf8b
VP
3855is not yet resolved.
3856
3857After the program is run, whenever a new shared library is loaded,
3858@value{GDBN} reevaluates all the breakpoints. When a newly loaded
3859shared library contains the symbol or line referred to by some
3860pending breakpoint, that breakpoint is resolved and becomes an
3861ordinary breakpoint. When a library is unloaded, all breakpoints
3862that refer to its symbols or source lines become pending again.
3863
3864This logic works for breakpoints with multiple locations, too. For
3865example, if you have a breakpoint in a C@t{++} template function, and
3866a newly loaded shared library has an instantiation of that template,
3867a new location is added to the list of locations for the breakpoint.
3868
3869Except for having unresolved address, pending breakpoints do not
3870differ from regular breakpoints. You can set conditions or commands,
3871enable and disable them and perform other breakpoint operations.
3872
3873@value{GDBN} provides some additional commands for controlling what
3874happens when the @samp{break} command cannot resolve breakpoint
3875address specification to an address:
dd79a6cf
JJ
3876
3877@kindex set breakpoint pending
3878@kindex show breakpoint pending
3879@table @code
3880@item set breakpoint pending auto
3881This is the default behavior. When @value{GDBN} cannot find the breakpoint
3882location, it queries you whether a pending breakpoint should be created.
3883
3884@item set breakpoint pending on
3885This indicates that an unrecognized breakpoint location should automatically
3886result in a pending breakpoint being created.
3887
3888@item set breakpoint pending off
3889This indicates that pending breakpoints are not to be created. Any
3890unrecognized breakpoint location results in an error. This setting does
3891not affect any pending breakpoints previously created.
3892
3893@item show breakpoint pending
3894Show the current behavior setting for creating pending breakpoints.
3895@end table
2650777c 3896
fe6fbf8b
VP
3897The settings above only affect the @code{break} command and its
3898variants. Once breakpoint is set, it will be automatically updated
3899as shared libraries are loaded and unloaded.
2650777c 3900
765dc015
VP
3901@cindex automatic hardware breakpoints
3902For some targets, @value{GDBN} can automatically decide if hardware or
3903software breakpoints should be used, depending on whether the
3904breakpoint address is read-only or read-write. This applies to
3905breakpoints set with the @code{break} command as well as to internal
3906breakpoints set by commands like @code{next} and @code{finish}. For
fcda367b 3907breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
765dc015
VP
3908breakpoints.
3909
3910You can control this automatic behaviour with the following commands::
3911
3912@kindex set breakpoint auto-hw
3913@kindex show breakpoint auto-hw
3914@table @code
3915@item set breakpoint auto-hw on
3916This is the default behavior. When @value{GDBN} sets a breakpoint, it
3917will try to use the target memory map to decide if software or hardware
3918breakpoint must be used.
3919
3920@item set breakpoint auto-hw off
3921This indicates @value{GDBN} should not automatically select breakpoint
3922type. If the target provides a memory map, @value{GDBN} will warn when
3923trying to set software breakpoint at a read-only address.
3924@end table
3925
74960c60
VP
3926@value{GDBN} normally implements breakpoints by replacing the program code
3927at the breakpoint address with a special instruction, which, when
3928executed, given control to the debugger. By default, the program
3929code is so modified only when the program is resumed. As soon as
3930the program stops, @value{GDBN} restores the original instructions. This
3931behaviour guards against leaving breakpoints inserted in the
3932target should gdb abrubptly disconnect. However, with slow remote
3933targets, inserting and removing breakpoint can reduce the performance.
3934This behavior can be controlled with the following commands::
3935
3936@kindex set breakpoint always-inserted
3937@kindex show breakpoint always-inserted
3938@table @code
3939@item set breakpoint always-inserted off
33e5cbd6
PA
3940All breakpoints, including newly added by the user, are inserted in
3941the target only when the target is resumed. All breakpoints are
a25a5a45 3942removed from the target when it stops. This is the default mode.
74960c60
VP
3943
3944@item set breakpoint always-inserted on
3945Causes all breakpoints to be inserted in the target at all times. If
3946the user adds a new breakpoint, or changes an existing breakpoint, the
3947breakpoints in the target are updated immediately. A breakpoint is
a25a5a45 3948removed from the target only when breakpoint itself is deleted.
342cc091 3949@end table
765dc015 3950
83364271
LM
3951@value{GDBN} handles conditional breakpoints by evaluating these conditions
3952when a breakpoint breaks. If the condition is true, then the process being
3953debugged stops, otherwise the process is resumed.
3954
3955If the target supports evaluating conditions on its end, @value{GDBN} may
3956download the breakpoint, together with its conditions, to it.
3957
3958This feature can be controlled via the following commands:
3959
3960@kindex set breakpoint condition-evaluation
3961@kindex show breakpoint condition-evaluation
3962@table @code
3963@item set breakpoint condition-evaluation host
3964This option commands @value{GDBN} to evaluate the breakpoint
3965conditions on the host's side. Unconditional breakpoints are sent to
3966the target which in turn receives the triggers and reports them back to GDB
3967for condition evaluation. This is the standard evaluation mode.
3968
3969@item set breakpoint condition-evaluation target
3970This option commands @value{GDBN} to download breakpoint conditions
3971to the target at the moment of their insertion. The target
3972is responsible for evaluating the conditional expression and reporting
3973breakpoint stop events back to @value{GDBN} whenever the condition
3974is true. Due to limitations of target-side evaluation, some conditions
3975cannot be evaluated there, e.g., conditions that depend on local data
3976that is only known to the host. Examples include
3977conditional expressions involving convenience variables, complex types
3978that cannot be handled by the agent expression parser and expressions
3979that are too long to be sent over to the target, specially when the
3980target is a remote system. In these cases, the conditions will be
3981evaluated by @value{GDBN}.
3982
3983@item set breakpoint condition-evaluation auto
3984This is the default mode. If the target supports evaluating breakpoint
3985conditions on its end, @value{GDBN} will download breakpoint conditions to
3986the target (limitations mentioned previously apply). If the target does
3987not support breakpoint condition evaluation, then @value{GDBN} will fallback
3988to evaluating all these conditions on the host's side.
3989@end table
3990
3991
c906108c
SS
3992@cindex negative breakpoint numbers
3993@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
3994@value{GDBN} itself sometimes sets breakpoints in your program for
3995special purposes, such as proper handling of @code{longjmp} (in C
3996programs). These internal breakpoints are assigned negative numbers,
3997starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 3998You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 3999@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
4000
4001
6d2ebf8b 4002@node Set Watchpoints
79a6e687 4003@subsection Setting Watchpoints
c906108c
SS
4004
4005@cindex setting watchpoints
c906108c
SS
4006You can use a watchpoint to stop execution whenever the value of an
4007expression changes, without having to predict a particular place where
fd60e0df
EZ
4008this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4009The expression may be as simple as the value of a single variable, or
4010as complex as many variables combined by operators. Examples include:
4011
4012@itemize @bullet
4013@item
4014A reference to the value of a single variable.
4015
4016@item
4017An address cast to an appropriate data type. For example,
4018@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4019address (assuming an @code{int} occupies 4 bytes).
4020
4021@item
4022An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4023expression can use any operators valid in the program's native
4024language (@pxref{Languages}).
4025@end itemize
c906108c 4026
fa4727a6
DJ
4027You can set a watchpoint on an expression even if the expression can
4028not be evaluated yet. For instance, you can set a watchpoint on
4029@samp{*global_ptr} before @samp{global_ptr} is initialized.
4030@value{GDBN} will stop when your program sets @samp{global_ptr} and
4031the expression produces a valid value. If the expression becomes
4032valid in some other way than changing a variable (e.g.@: if the memory
4033pointed to by @samp{*global_ptr} becomes readable as the result of a
4034@code{malloc} call), @value{GDBN} may not stop until the next time
4035the expression changes.
4036
82f2d802
EZ
4037@cindex software watchpoints
4038@cindex hardware watchpoints
c906108c 4039Depending on your system, watchpoints may be implemented in software or
2df3850c 4040hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
4041program and testing the variable's value each time, which is hundreds of
4042times slower than normal execution. (But this may still be worth it, to
4043catch errors where you have no clue what part of your program is the
4044culprit.)
4045
b1236ac3
PA
4046On some systems, such as most PowerPC or x86-based targets,
4047@value{GDBN} includes support for hardware watchpoints, which do not
4048slow down the running of your program.
c906108c
SS
4049
4050@table @code
4051@kindex watch
5d5658a1 4052@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
fd60e0df
EZ
4053Set a watchpoint for an expression. @value{GDBN} will break when the
4054expression @var{expr} is written into by the program and its value
4055changes. The simplest (and the most popular) use of this command is
4056to watch the value of a single variable:
4057
4058@smallexample
4059(@value{GDBP}) watch foo
4060@end smallexample
c906108c 4061
5d5658a1 4062If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
9c06b0b4 4063argument, @value{GDBN} breaks only when the thread identified by
5d5658a1 4064@var{thread-id} changes the value of @var{expr}. If any other threads
d8b2a693
JB
4065change the value of @var{expr}, @value{GDBN} will not break. Note
4066that watchpoints restricted to a single thread in this way only work
4067with Hardware Watchpoints.
4068
06a64a0b
TT
4069Ordinarily a watchpoint respects the scope of variables in @var{expr}
4070(see below). The @code{-location} argument tells @value{GDBN} to
4071instead watch the memory referred to by @var{expr}. In this case,
4072@value{GDBN} will evaluate @var{expr}, take the address of the result,
4073and watch the memory at that address. The type of the result is used
4074to determine the size of the watched memory. If the expression's
4075result does not have an address, then @value{GDBN} will print an
4076error.
4077
9c06b0b4
TJB
4078The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4079of masked watchpoints, if the current architecture supports this
4080feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4081Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4082to an address to watch. The mask specifies that some bits of an address
4083(the bits which are reset in the mask) should be ignored when matching
4084the address accessed by the inferior against the watchpoint address.
4085Thus, a masked watchpoint watches many addresses simultaneously---those
4086addresses whose unmasked bits are identical to the unmasked bits in the
4087watchpoint address. The @code{mask} argument implies @code{-location}.
4088Examples:
4089
4090@smallexample
4091(@value{GDBP}) watch foo mask 0xffff00ff
4092(@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4093@end smallexample
4094
c906108c 4095@kindex rwatch
5d5658a1 4096@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4097Set a watchpoint that will break when the value of @var{expr} is read
4098by the program.
c906108c
SS
4099
4100@kindex awatch
5d5658a1 4101@item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4102Set a watchpoint that will break when @var{expr} is either read from
4103or written into by the program.
c906108c 4104
e5a67952
MS
4105@kindex info watchpoints @r{[}@var{n}@dots{}@r{]}
4106@item info watchpoints @r{[}@var{n}@dots{}@r{]}
d77f58be
SS
4107This command prints a list of watchpoints, using the same format as
4108@code{info break} (@pxref{Set Breaks}).
c906108c
SS
4109@end table
4110
65d79d4b
SDJ
4111If you watch for a change in a numerically entered address you need to
4112dereference it, as the address itself is just a constant number which will
4113never change. @value{GDBN} refuses to create a watchpoint that watches
4114a never-changing value:
4115
4116@smallexample
4117(@value{GDBP}) watch 0x600850
4118Cannot watch constant value 0x600850.
4119(@value{GDBP}) watch *(int *) 0x600850
4120Watchpoint 1: *(int *) 6293584
4121@end smallexample
4122
c906108c
SS
4123@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4124watchpoints execute very quickly, and the debugger reports a change in
4125value at the exact instruction where the change occurs. If @value{GDBN}
4126cannot set a hardware watchpoint, it sets a software watchpoint, which
4127executes more slowly and reports the change in value at the next
82f2d802
EZ
4128@emph{statement}, not the instruction, after the change occurs.
4129
82f2d802
EZ
4130@cindex use only software watchpoints
4131You can force @value{GDBN} to use only software watchpoints with the
4132@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4133zero, @value{GDBN} will never try to use hardware watchpoints, even if
4134the underlying system supports them. (Note that hardware-assisted
4135watchpoints that were set @emph{before} setting
4136@code{can-use-hw-watchpoints} to zero will still use the hardware
d3e8051b 4137mechanism of watching expression values.)
c906108c 4138
9c16f35a
EZ
4139@table @code
4140@item set can-use-hw-watchpoints
4141@kindex set can-use-hw-watchpoints
4142Set whether or not to use hardware watchpoints.
4143
4144@item show can-use-hw-watchpoints
4145@kindex show can-use-hw-watchpoints
4146Show the current mode of using hardware watchpoints.
4147@end table
4148
4149For remote targets, you can restrict the number of hardware
4150watchpoints @value{GDBN} will use, see @ref{set remote
4151hardware-breakpoint-limit}.
4152
c906108c
SS
4153When you issue the @code{watch} command, @value{GDBN} reports
4154
474c8240 4155@smallexample
c906108c 4156Hardware watchpoint @var{num}: @var{expr}
474c8240 4157@end smallexample
c906108c
SS
4158
4159@noindent
4160if it was able to set a hardware watchpoint.
4161
7be570e7
JM
4162Currently, the @code{awatch} and @code{rwatch} commands can only set
4163hardware watchpoints, because accesses to data that don't change the
4164value of the watched expression cannot be detected without examining
4165every instruction as it is being executed, and @value{GDBN} does not do
4166that currently. If @value{GDBN} finds that it is unable to set a
4167hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4168will print a message like this:
4169
4170@smallexample
4171Expression cannot be implemented with read/access watchpoint.
4172@end smallexample
4173
4174Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4175data type of the watched expression is wider than what a hardware
4176watchpoint on the target machine can handle. For example, some systems
4177can only watch regions that are up to 4 bytes wide; on such systems you
4178cannot set hardware watchpoints for an expression that yields a
4179double-precision floating-point number (which is typically 8 bytes
4180wide). As a work-around, it might be possible to break the large region
4181into a series of smaller ones and watch them with separate watchpoints.
4182
4183If you set too many hardware watchpoints, @value{GDBN} might be unable
4184to insert all of them when you resume the execution of your program.
4185Since the precise number of active watchpoints is unknown until such
4186time as the program is about to be resumed, @value{GDBN} might not be
4187able to warn you about this when you set the watchpoints, and the
4188warning will be printed only when the program is resumed:
4189
4190@smallexample
4191Hardware watchpoint @var{num}: Could not insert watchpoint
4192@end smallexample
4193
4194@noindent
4195If this happens, delete or disable some of the watchpoints.
4196
fd60e0df
EZ
4197Watching complex expressions that reference many variables can also
4198exhaust the resources available for hardware-assisted watchpoints.
4199That's because @value{GDBN} needs to watch every variable in the
4200expression with separately allocated resources.
4201
c906108c 4202If you call a function interactively using @code{print} or @code{call},
2df3850c 4203any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
4204kind of breakpoint or the call completes.
4205
7be570e7
JM
4206@value{GDBN} automatically deletes watchpoints that watch local
4207(automatic) variables, or expressions that involve such variables, when
4208they go out of scope, that is, when the execution leaves the block in
4209which these variables were defined. In particular, when the program
4210being debugged terminates, @emph{all} local variables go out of scope,
4211and so only watchpoints that watch global variables remain set. If you
4212rerun the program, you will need to set all such watchpoints again. One
4213way of doing that would be to set a code breakpoint at the entry to the
4214@code{main} function and when it breaks, set all the watchpoints.
4215
c906108c
SS
4216@cindex watchpoints and threads
4217@cindex threads and watchpoints
d983da9c
DJ
4218In multi-threaded programs, watchpoints will detect changes to the
4219watched expression from every thread.
4220
4221@quotation
4222@emph{Warning:} In multi-threaded programs, software watchpoints
53a5351d
JM
4223have only limited usefulness. If @value{GDBN} creates a software
4224watchpoint, it can only watch the value of an expression @emph{in a
4225single thread}. If you are confident that the expression can only
4226change due to the current thread's activity (and if you are also
4227confident that no other thread can become current), then you can use
4228software watchpoints as usual. However, @value{GDBN} may not notice
4229when a non-current thread's activity changes the expression. (Hardware
4230watchpoints, in contrast, watch an expression in all threads.)
c906108c 4231@end quotation
c906108c 4232
501eef12
AC
4233@xref{set remote hardware-watchpoint-limit}.
4234
6d2ebf8b 4235@node Set Catchpoints
79a6e687 4236@subsection Setting Catchpoints
d4f3574e 4237@cindex catchpoints, setting
c906108c
SS
4238@cindex exception handlers
4239@cindex event handling
4240
4241You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 4242kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
4243shared library. Use the @code{catch} command to set a catchpoint.
4244
4245@table @code
4246@kindex catch
4247@item catch @var{event}
697aa1b7 4248Stop when @var{event} occurs. The @var{event} can be any of the following:
591f19e8 4249
c906108c 4250@table @code
cc16e6c9
TT
4251@item throw @r{[}@var{regexp}@r{]}
4252@itemx rethrow @r{[}@var{regexp}@r{]}
4253@itemx catch @r{[}@var{regexp}@r{]}
1a4f73eb
TT
4254@kindex catch throw
4255@kindex catch rethrow
4256@kindex catch catch
4644b6e3 4257@cindex stop on C@t{++} exceptions
591f19e8
TT
4258The throwing, re-throwing, or catching of a C@t{++} exception.
4259
cc16e6c9
TT
4260If @var{regexp} is given, then only exceptions whose type matches the
4261regular expression will be caught.
4262
72f1fe8a
TT
4263@vindex $_exception@r{, convenience variable}
4264The convenience variable @code{$_exception} is available at an
4265exception-related catchpoint, on some systems. This holds the
4266exception being thrown.
4267
591f19e8
TT
4268There are currently some limitations to C@t{++} exception handling in
4269@value{GDBN}:
c906108c 4270
591f19e8
TT
4271@itemize @bullet
4272@item
4273The support for these commands is system-dependent. Currently, only
4274systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
4275supported.
4276
72f1fe8a 4277@item
cc16e6c9
TT
4278The regular expression feature and the @code{$_exception} convenience
4279variable rely on the presence of some SDT probes in @code{libstdc++}.
4280If these probes are not present, then these features cannot be used.
dee368d3
TT
4281These probes were first available in the GCC 4.8 release, but whether
4282or not they are available in your GCC also depends on how it was
4283built.
72f1fe8a
TT
4284
4285@item
4286The @code{$_exception} convenience variable is only valid at the
4287instruction at which an exception-related catchpoint is set.
4288
591f19e8
TT
4289@item
4290When an exception-related catchpoint is hit, @value{GDBN} stops at a
4291location in the system library which implements runtime exception
4292support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
4293(@pxref{Selection}) to get to your code.
4294
4295@item
4296If you call a function interactively, @value{GDBN} normally returns
4297control to you when the function has finished executing. If the call
4298raises an exception, however, the call may bypass the mechanism that
4299returns control to you and cause your program either to abort or to
4300simply continue running until it hits a breakpoint, catches a signal
4301that @value{GDBN} is listening for, or exits. This is the case even if
4302you set a catchpoint for the exception; catchpoints on exceptions are
4303disabled within interactive calls. @xref{Calling}, for information on
4304controlling this with @code{set unwind-on-terminating-exception}.
4305
4306@item
4307You cannot raise an exception interactively.
4308
4309@item
4310You cannot install an exception handler interactively.
4311@end itemize
c906108c 4312
8936fcda 4313@item exception
1a4f73eb 4314@kindex catch exception
8936fcda
JB
4315@cindex Ada exception catching
4316@cindex catch Ada exceptions
4317An Ada exception being raised. If an exception name is specified
4318at the end of the command (eg @code{catch exception Program_Error}),
4319the debugger will stop only when this specific exception is raised.
4320Otherwise, the debugger stops execution when any Ada exception is raised.
4321
87f67dba
JB
4322When inserting an exception catchpoint on a user-defined exception whose
4323name is identical to one of the exceptions defined by the language, the
4324fully qualified name must be used as the exception name. Otherwise,
4325@value{GDBN} will assume that it should stop on the pre-defined exception
4326rather than the user-defined one. For instance, assuming an exception
4327called @code{Constraint_Error} is defined in package @code{Pck}, then
4328the command to use to catch such exceptions is @kbd{catch exception
4329Pck.Constraint_Error}.
4330
8936fcda 4331@item exception unhandled
1a4f73eb 4332@kindex catch exception unhandled
8936fcda
JB
4333An exception that was raised but is not handled by the program.
4334
4335@item assert
1a4f73eb 4336@kindex catch assert
8936fcda
JB
4337A failed Ada assertion.
4338
c906108c 4339@item exec
1a4f73eb 4340@kindex catch exec
4644b6e3 4341@cindex break on fork/exec
b1236ac3 4342A call to @code{exec}.
c906108c 4343
a96d9b2e 4344@item syscall
ee8e71d4 4345@itemx syscall @r{[}@var{name} @r{|} @var{number}@r{]} @dots{}
1a4f73eb 4346@kindex catch syscall
a96d9b2e
SDJ
4347@cindex break on a system call.
4348A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
4349syscall is a mechanism for application programs to request a service
4350from the operating system (OS) or one of the OS system services.
4351@value{GDBN} can catch some or all of the syscalls issued by the
4352debuggee, and show the related information for each syscall. If no
4353argument is specified, calls to and returns from all system calls
4354will be caught.
4355
4356@var{name} can be any system call name that is valid for the
4357underlying OS. Just what syscalls are valid depends on the OS. On
4358GNU and Unix systems, you can find the full list of valid syscall
4359names on @file{/usr/include/asm/unistd.h}.
4360
4361@c For MS-Windows, the syscall names and the corresponding numbers
4362@c can be found, e.g., on this URL:
4363@c http://www.metasploit.com/users/opcode/syscalls.html
4364@c but we don't support Windows syscalls yet.
4365
4366Normally, @value{GDBN} knows in advance which syscalls are valid for
4367each OS, so you can use the @value{GDBN} command-line completion
4368facilities (@pxref{Completion,, command completion}) to list the
4369available choices.
4370
4371You may also specify the system call numerically. A syscall's
4372number is the value passed to the OS's syscall dispatcher to
4373identify the requested service. When you specify the syscall by its
4374name, @value{GDBN} uses its database of syscalls to convert the name
4375into the corresponding numeric code, but using the number directly
4376may be useful if @value{GDBN}'s database does not have the complete
4377list of syscalls on your system (e.g., because @value{GDBN} lags
4378behind the OS upgrades).
4379
4380The example below illustrates how this command works if you don't provide
4381arguments to it:
4382
4383@smallexample
4384(@value{GDBP}) catch syscall
4385Catchpoint 1 (syscall)
4386(@value{GDBP}) r
4387Starting program: /tmp/catch-syscall
4388
4389Catchpoint 1 (call to syscall 'close'), \
4390 0xffffe424 in __kernel_vsyscall ()
4391(@value{GDBP}) c
4392Continuing.
4393
4394Catchpoint 1 (returned from syscall 'close'), \
4395 0xffffe424 in __kernel_vsyscall ()
4396(@value{GDBP})
4397@end smallexample
4398
4399Here is an example of catching a system call by name:
4400
4401@smallexample
4402(@value{GDBP}) catch syscall chroot
4403Catchpoint 1 (syscall 'chroot' [61])
4404(@value{GDBP}) r
4405Starting program: /tmp/catch-syscall
4406
4407Catchpoint 1 (call to syscall 'chroot'), \
4408 0xffffe424 in __kernel_vsyscall ()
4409(@value{GDBP}) c
4410Continuing.
4411
4412Catchpoint 1 (returned from syscall 'chroot'), \
4413 0xffffe424 in __kernel_vsyscall ()
4414(@value{GDBP})
4415@end smallexample
4416
4417An example of specifying a system call numerically. In the case
4418below, the syscall number has a corresponding entry in the XML
4419file, so @value{GDBN} finds its name and prints it:
4420
4421@smallexample
4422(@value{GDBP}) catch syscall 252
4423Catchpoint 1 (syscall(s) 'exit_group')
4424(@value{GDBP}) r
4425Starting program: /tmp/catch-syscall
4426
4427Catchpoint 1 (call to syscall 'exit_group'), \
4428 0xffffe424 in __kernel_vsyscall ()
4429(@value{GDBP}) c
4430Continuing.
4431
4432Program exited normally.
4433(@value{GDBP})
4434@end smallexample
4435
4436However, there can be situations when there is no corresponding name
4437in XML file for that syscall number. In this case, @value{GDBN} prints
4438a warning message saying that it was not able to find the syscall name,
4439but the catchpoint will be set anyway. See the example below:
4440
4441@smallexample
4442(@value{GDBP}) catch syscall 764
4443warning: The number '764' does not represent a known syscall.
4444Catchpoint 2 (syscall 764)
4445(@value{GDBP})
4446@end smallexample
4447
4448If you configure @value{GDBN} using the @samp{--without-expat} option,
4449it will not be able to display syscall names. Also, if your
4450architecture does not have an XML file describing its system calls,
4451you will not be able to see the syscall names. It is important to
4452notice that these two features are used for accessing the syscall
4453name database. In either case, you will see a warning like this:
4454
4455@smallexample
4456(@value{GDBP}) catch syscall
4457warning: Could not open "syscalls/i386-linux.xml"
4458warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
4459GDB will not be able to display syscall names.
4460Catchpoint 1 (syscall)
4461(@value{GDBP})
4462@end smallexample
4463
4464Of course, the file name will change depending on your architecture and system.
4465
4466Still using the example above, you can also try to catch a syscall by its
4467number. In this case, you would see something like:
4468
4469@smallexample
4470(@value{GDBP}) catch syscall 252
4471Catchpoint 1 (syscall(s) 252)
4472@end smallexample
4473
4474Again, in this case @value{GDBN} would not be able to display syscall's names.
4475
c906108c 4476@item fork
1a4f73eb 4477@kindex catch fork
b1236ac3 4478A call to @code{fork}.
c906108c
SS
4479
4480@item vfork
1a4f73eb 4481@kindex catch vfork
b1236ac3 4482A call to @code{vfork}.
c906108c 4483
edcc5120
TT
4484@item load @r{[}regexp@r{]}
4485@itemx unload @r{[}regexp@r{]}
1a4f73eb
TT
4486@kindex catch load
4487@kindex catch unload
edcc5120
TT
4488The loading or unloading of a shared library. If @var{regexp} is
4489given, then the catchpoint will stop only if the regular expression
4490matches one of the affected libraries.
4491
ab04a2af 4492@item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
1a4f73eb 4493@kindex catch signal
ab04a2af
TT
4494The delivery of a signal.
4495
4496With no arguments, this catchpoint will catch any signal that is not
4497used internally by @value{GDBN}, specifically, all signals except
4498@samp{SIGTRAP} and @samp{SIGINT}.
4499
4500With the argument @samp{all}, all signals, including those used by
4501@value{GDBN}, will be caught. This argument cannot be used with other
4502signal names.
4503
4504Otherwise, the arguments are a list of signal names as given to
4505@code{handle} (@pxref{Signals}). Only signals specified in this list
4506will be caught.
4507
4508One reason that @code{catch signal} can be more useful than
4509@code{handle} is that you can attach commands and conditions to the
4510catchpoint.
4511
4512When a signal is caught by a catchpoint, the signal's @code{stop} and
4513@code{print} settings, as specified by @code{handle}, are ignored.
4514However, whether the signal is still delivered to the inferior depends
4515on the @code{pass} setting; this can be changed in the catchpoint's
4516commands.
4517
c906108c
SS
4518@end table
4519
4520@item tcatch @var{event}
1a4f73eb 4521@kindex tcatch
c906108c
SS
4522Set a catchpoint that is enabled only for one stop. The catchpoint is
4523automatically deleted after the first time the event is caught.
4524
4525@end table
4526
4527Use the @code{info break} command to list the current catchpoints.
4528
c906108c 4529
6d2ebf8b 4530@node Delete Breaks
79a6e687 4531@subsection Deleting Breakpoints
c906108c
SS
4532
4533@cindex clearing breakpoints, watchpoints, catchpoints
4534@cindex deleting breakpoints, watchpoints, catchpoints
4535It is often necessary to eliminate a breakpoint, watchpoint, or
4536catchpoint once it has done its job and you no longer want your program
4537to stop there. This is called @dfn{deleting} the breakpoint. A
4538breakpoint that has been deleted no longer exists; it is forgotten.
4539
4540With the @code{clear} command you can delete breakpoints according to
4541where they are in your program. With the @code{delete} command you can
4542delete individual breakpoints, watchpoints, or catchpoints by specifying
4543their breakpoint numbers.
4544
4545It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
4546automatically ignores breakpoints on the first instruction to be executed
4547when you continue execution without changing the execution address.
4548
4549@table @code
4550@kindex clear
4551@item clear
4552Delete any breakpoints at the next instruction to be executed in the
79a6e687 4553selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
c906108c
SS
4554the innermost frame is selected, this is a good way to delete a
4555breakpoint where your program just stopped.
4556
2a25a5ba
EZ
4557@item clear @var{location}
4558Delete any breakpoints set at the specified @var{location}.
4559@xref{Specify Location}, for the various forms of @var{location}; the
4560most useful ones are listed below:
4561
4562@table @code
c906108c
SS
4563@item clear @var{function}
4564@itemx clear @var{filename}:@var{function}
09d4efe1 4565Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
4566
4567@item clear @var{linenum}
4568@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
4569Delete any breakpoints set at or within the code of the specified
4570@var{linenum} of the specified @var{filename}.
2a25a5ba 4571@end table
c906108c
SS
4572
4573@cindex delete breakpoints
4574@kindex delete
41afff9a 4575@kindex d @r{(@code{delete})}
c5394b80
JM
4576@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4577Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
4578ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
4579breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
4580confirm off}). You can abbreviate this command as @code{d}.
4581@end table
4582
6d2ebf8b 4583@node Disabling
79a6e687 4584@subsection Disabling Breakpoints
c906108c 4585
4644b6e3 4586@cindex enable/disable a breakpoint
c906108c
SS
4587Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
4588prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
4589it had been deleted, but remembers the information on the breakpoint so
4590that you can @dfn{enable} it again later.
4591
4592You disable and enable breakpoints, watchpoints, and catchpoints with
d77f58be
SS
4593the @code{enable} and @code{disable} commands, optionally specifying
4594one or more breakpoint numbers as arguments. Use @code{info break} to
4595print a list of all breakpoints, watchpoints, and catchpoints if you
4596do not know which numbers to use.
c906108c 4597
3b784c4f
EZ
4598Disabling and enabling a breakpoint that has multiple locations
4599affects all of its locations.
4600
816338b5
SS
4601A breakpoint, watchpoint, or catchpoint can have any of several
4602different states of enablement:
c906108c
SS
4603
4604@itemize @bullet
4605@item
4606Enabled. The breakpoint stops your program. A breakpoint set
4607with the @code{break} command starts out in this state.
4608@item
4609Disabled. The breakpoint has no effect on your program.
4610@item
4611Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 4612disabled.
c906108c 4613@item
816338b5
SS
4614Enabled for a count. The breakpoint stops your program for the next
4615N times, then becomes disabled.
4616@item
c906108c 4617Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
4618immediately after it does so it is deleted permanently. A breakpoint
4619set with the @code{tbreak} command starts out in this state.
c906108c
SS
4620@end itemize
4621
4622You can use the following commands to enable or disable breakpoints,
4623watchpoints, and catchpoints:
4624
4625@table @code
c906108c 4626@kindex disable
41afff9a 4627@kindex dis @r{(@code{disable})}
c5394b80 4628@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4629Disable the specified breakpoints---or all breakpoints, if none are
4630listed. A disabled breakpoint has no effect but is not forgotten. All
4631options such as ignore-counts, conditions and commands are remembered in
4632case the breakpoint is enabled again later. You may abbreviate
4633@code{disable} as @code{dis}.
4634
c906108c 4635@kindex enable
c5394b80 4636@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4637Enable the specified breakpoints (or all defined breakpoints). They
4638become effective once again in stopping your program.
4639
c5394b80 4640@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
4641Enable the specified breakpoints temporarily. @value{GDBN} disables any
4642of these breakpoints immediately after stopping your program.
4643
816338b5
SS
4644@item enable @r{[}breakpoints@r{]} count @var{count} @var{range}@dots{}
4645Enable the specified breakpoints temporarily. @value{GDBN} records
4646@var{count} with each of the specified breakpoints, and decrements a
4647breakpoint's count when it is hit. When any count reaches 0,
4648@value{GDBN} disables that breakpoint. If a breakpoint has an ignore
4649count (@pxref{Conditions, ,Break Conditions}), that will be
4650decremented to 0 before @var{count} is affected.
4651
c5394b80 4652@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
4653Enable the specified breakpoints to work once, then die. @value{GDBN}
4654deletes any of these breakpoints as soon as your program stops there.
09d4efe1 4655Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
4656@end table
4657
d4f3574e
SS
4658@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
4659@c confusing: tbreak is also initially enabled.
c906108c 4660Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
79a6e687 4661,Setting Breakpoints}), breakpoints that you set are initially enabled;
c906108c
SS
4662subsequently, they become disabled or enabled only when you use one of
4663the commands above. (The command @code{until} can set and delete a
4664breakpoint of its own, but it does not change the state of your other
4665breakpoints; see @ref{Continuing and Stepping, ,Continuing and
79a6e687 4666Stepping}.)
c906108c 4667
6d2ebf8b 4668@node Conditions
79a6e687 4669@subsection Break Conditions
c906108c
SS
4670@cindex conditional breakpoints
4671@cindex breakpoint conditions
4672
4673@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 4674@c in particular for a watchpoint?
c906108c
SS
4675The simplest sort of breakpoint breaks every time your program reaches a
4676specified place. You can also specify a @dfn{condition} for a
4677breakpoint. A condition is just a Boolean expression in your
4678programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
4679a condition evaluates the expression each time your program reaches it,
4680and your program stops only if the condition is @emph{true}.
4681
4682This is the converse of using assertions for program validation; in that
4683situation, you want to stop when the assertion is violated---that is,
4684when the condition is false. In C, if you want to test an assertion expressed
4685by the condition @var{assert}, you should set the condition
4686@samp{! @var{assert}} on the appropriate breakpoint.
4687
4688Conditions are also accepted for watchpoints; you may not need them,
4689since a watchpoint is inspecting the value of an expression anyhow---but
4690it might be simpler, say, to just set a watchpoint on a variable name,
4691and specify a condition that tests whether the new value is an interesting
4692one.
4693
4694Break conditions can have side effects, and may even call functions in
4695your program. This can be useful, for example, to activate functions
4696that log program progress, or to use your own print functions to
99e008fe 4697format special data structures. The effects are completely predictable
c906108c
SS
4698unless there is another enabled breakpoint at the same address. (In
4699that case, @value{GDBN} might see the other breakpoint first and stop your
4700program without checking the condition of this one.) Note that
d4f3574e
SS
4701breakpoint commands are usually more convenient and flexible than break
4702conditions for the
c906108c 4703purpose of performing side effects when a breakpoint is reached
79a6e687 4704(@pxref{Break Commands, ,Breakpoint Command Lists}).
c906108c 4705
83364271
LM
4706Breakpoint conditions can also be evaluated on the target's side if
4707the target supports it. Instead of evaluating the conditions locally,
4708@value{GDBN} encodes the expression into an agent expression
4709(@pxref{Agent Expressions}) suitable for execution on the target,
4710independently of @value{GDBN}. Global variables become raw memory
4711locations, locals become stack accesses, and so forth.
4712
4713In this case, @value{GDBN} will only be notified of a breakpoint trigger
4714when its condition evaluates to true. This mechanism may provide faster
4715response times depending on the performance characteristics of the target
4716since it does not need to keep @value{GDBN} informed about
4717every breakpoint trigger, even those with false conditions.
4718
c906108c
SS
4719Break conditions can be specified when a breakpoint is set, by using
4720@samp{if} in the arguments to the @code{break} command. @xref{Set
79a6e687 4721Breaks, ,Setting Breakpoints}. They can also be changed at any time
c906108c 4722with the @code{condition} command.
53a5351d 4723
c906108c
SS
4724You can also use the @code{if} keyword with the @code{watch} command.
4725The @code{catch} command does not recognize the @code{if} keyword;
4726@code{condition} is the only way to impose a further condition on a
4727catchpoint.
c906108c
SS
4728
4729@table @code
4730@kindex condition
4731@item condition @var{bnum} @var{expression}
4732Specify @var{expression} as the break condition for breakpoint,
4733watchpoint, or catchpoint number @var{bnum}. After you set a condition,
4734breakpoint @var{bnum} stops your program only if the value of
4735@var{expression} is true (nonzero, in C). When you use
4736@code{condition}, @value{GDBN} checks @var{expression} immediately for
4737syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
4738referents in the context of your breakpoint. If @var{expression} uses
4739symbols not referenced in the context of the breakpoint, @value{GDBN}
4740prints an error message:
4741
474c8240 4742@smallexample
d4f3574e 4743No symbol "foo" in current context.
474c8240 4744@end smallexample
d4f3574e
SS
4745
4746@noindent
c906108c
SS
4747@value{GDBN} does
4748not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
4749command (or a command that sets a breakpoint with a condition, like
4750@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
4751
4752@item condition @var{bnum}
4753Remove the condition from breakpoint number @var{bnum}. It becomes
4754an ordinary unconditional breakpoint.
4755@end table
4756
4757@cindex ignore count (of breakpoint)
4758A special case of a breakpoint condition is to stop only when the
4759breakpoint has been reached a certain number of times. This is so
4760useful that there is a special way to do it, using the @dfn{ignore
4761count} of the breakpoint. Every breakpoint has an ignore count, which
4762is an integer. Most of the time, the ignore count is zero, and
4763therefore has no effect. But if your program reaches a breakpoint whose
4764ignore count is positive, then instead of stopping, it just decrements
4765the ignore count by one and continues. As a result, if the ignore count
4766value is @var{n}, the breakpoint does not stop the next @var{n} times
4767your program reaches it.
4768
4769@table @code
4770@kindex ignore
4771@item ignore @var{bnum} @var{count}
4772Set the ignore count of breakpoint number @var{bnum} to @var{count}.
4773The next @var{count} times the breakpoint is reached, your program's
4774execution does not stop; other than to decrement the ignore count, @value{GDBN}
4775takes no action.
4776
4777To make the breakpoint stop the next time it is reached, specify
4778a count of zero.
4779
4780When you use @code{continue} to resume execution of your program from a
4781breakpoint, you can specify an ignore count directly as an argument to
4782@code{continue}, rather than using @code{ignore}. @xref{Continuing and
79a6e687 4783Stepping,,Continuing and Stepping}.
c906108c
SS
4784
4785If a breakpoint has a positive ignore count and a condition, the
4786condition is not checked. Once the ignore count reaches zero,
4787@value{GDBN} resumes checking the condition.
4788
4789You could achieve the effect of the ignore count with a condition such
4790as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
4791is decremented each time. @xref{Convenience Vars, ,Convenience
79a6e687 4792Variables}.
c906108c
SS
4793@end table
4794
4795Ignore counts apply to breakpoints, watchpoints, and catchpoints.
4796
4797
6d2ebf8b 4798@node Break Commands
79a6e687 4799@subsection Breakpoint Command Lists
c906108c
SS
4800
4801@cindex breakpoint commands
4802You can give any breakpoint (or watchpoint or catchpoint) a series of
4803commands to execute when your program stops due to that breakpoint. For
4804example, you might want to print the values of certain expressions, or
4805enable other breakpoints.
4806
4807@table @code
4808@kindex commands
ca91424e 4809@kindex end@r{ (breakpoint commands)}
95a42b64 4810@item commands @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4811@itemx @dots{} @var{command-list} @dots{}
4812@itemx end
95a42b64 4813Specify a list of commands for the given breakpoints. The commands
c906108c
SS
4814themselves appear on the following lines. Type a line containing just
4815@code{end} to terminate the commands.
4816
4817To remove all commands from a breakpoint, type @code{commands} and
4818follow it immediately with @code{end}; that is, give no commands.
4819
95a42b64
TT
4820With no argument, @code{commands} refers to the last breakpoint,
4821watchpoint, or catchpoint set (not to the breakpoint most recently
4822encountered). If the most recent breakpoints were set with a single
4823command, then the @code{commands} will apply to all the breakpoints
4824set by that command. This applies to breakpoints set by
86b17b60
PA
4825@code{rbreak}, and also applies when a single @code{break} command
4826creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
4827Expressions}).
c906108c
SS
4828@end table
4829
4830Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
4831disabled within a @var{command-list}.
4832
4833You can use breakpoint commands to start your program up again. Simply
4834use the @code{continue} command, or @code{step}, or any other command
4835that resumes execution.
4836
4837Any other commands in the command list, after a command that resumes
4838execution, are ignored. This is because any time you resume execution
4839(even with a simple @code{next} or @code{step}), you may encounter
4840another breakpoint---which could have its own command list, leading to
4841ambiguities about which list to execute.
4842
4843@kindex silent
4844If the first command you specify in a command list is @code{silent}, the
4845usual message about stopping at a breakpoint is not printed. This may
4846be desirable for breakpoints that are to print a specific message and
4847then continue. If none of the remaining commands print anything, you
4848see no sign that the breakpoint was reached. @code{silent} is
4849meaningful only at the beginning of a breakpoint command list.
4850
4851The commands @code{echo}, @code{output}, and @code{printf} allow you to
4852print precisely controlled output, and are often useful in silent
79a6e687 4853breakpoints. @xref{Output, ,Commands for Controlled Output}.
c906108c
SS
4854
4855For example, here is how you could use breakpoint commands to print the
4856value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
4857
474c8240 4858@smallexample
c906108c
SS
4859break foo if x>0
4860commands
4861silent
4862printf "x is %d\n",x
4863cont
4864end
474c8240 4865@end smallexample
c906108c
SS
4866
4867One application for breakpoint commands is to compensate for one bug so
4868you can test for another. Put a breakpoint just after the erroneous line
4869of code, give it a condition to detect the case in which something
4870erroneous has been done, and give it commands to assign correct values
4871to any variables that need them. End with the @code{continue} command
4872so that your program does not stop, and start with the @code{silent}
4873command so that no output is produced. Here is an example:
4874
474c8240 4875@smallexample
c906108c
SS
4876break 403
4877commands
4878silent
4879set x = y + 4
4880cont
4881end
474c8240 4882@end smallexample
c906108c 4883
e7e0cddf
SS
4884@node Dynamic Printf
4885@subsection Dynamic Printf
4886
4887@cindex dynamic printf
4888@cindex dprintf
4889The dynamic printf command @code{dprintf} combines a breakpoint with
4890formatted printing of your program's data to give you the effect of
4891inserting @code{printf} calls into your program on-the-fly, without
4892having to recompile it.
4893
4894In its most basic form, the output goes to the GDB console. However,
4895you can set the variable @code{dprintf-style} for alternate handling.
4896For instance, you can ask to format the output by calling your
4897program's @code{printf} function. This has the advantage that the
4898characters go to the program's output device, so they can recorded in
4899redirects to files and so forth.
4900
d3ce09f5
SS
4901If you are doing remote debugging with a stub or agent, you can also
4902ask to have the printf handled by the remote agent. In addition to
4903ensuring that the output goes to the remote program's device along
4904with any other output the program might produce, you can also ask that
4905the dprintf remain active even after disconnecting from the remote
4906target. Using the stub/agent is also more efficient, as it can do
4907everything without needing to communicate with @value{GDBN}.
4908
e7e0cddf
SS
4909@table @code
4910@kindex dprintf
4911@item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
4912Whenever execution reaches @var{location}, print the values of one or
4913more @var{expressions} under the control of the string @var{template}.
4914To print several values, separate them with commas.
4915
4916@item set dprintf-style @var{style}
4917Set the dprintf output to be handled in one of several different
4918styles enumerated below. A change of style affects all existing
4919dynamic printfs immediately. (If you need individual control over the
4920print commands, simply define normal breakpoints with
4921explicitly-supplied command lists.)
4922
4923@item gdb
4924@kindex dprintf-style gdb
4925Handle the output using the @value{GDBN} @code{printf} command.
4926
4927@item call
4928@kindex dprintf-style call
4929Handle the output by calling a function in your program (normally
4930@code{printf}).
4931
d3ce09f5
SS
4932@item agent
4933@kindex dprintf-style agent
4934Have the remote debugging agent (such as @code{gdbserver}) handle
4935the output itself. This style is only available for agents that
4936support running commands on the target.
4937
e7e0cddf
SS
4938@item set dprintf-function @var{function}
4939Set the function to call if the dprintf style is @code{call}. By
4940default its value is @code{printf}. You may set it to any expression.
4941that @value{GDBN} can evaluate to a function, as per the @code{call}
4942command.
4943
4944@item set dprintf-channel @var{channel}
4945Set a ``channel'' for dprintf. If set to a non-empty value,
4946@value{GDBN} will evaluate it as an expression and pass the result as
4947a first argument to the @code{dprintf-function}, in the manner of
4948@code{fprintf} and similar functions. Otherwise, the dprintf format
4949string will be the first argument, in the manner of @code{printf}.
4950
4951As an example, if you wanted @code{dprintf} output to go to a logfile
4952that is a standard I/O stream assigned to the variable @code{mylog},
4953you could do the following:
4954
4955@example
4956(gdb) set dprintf-style call
4957(gdb) set dprintf-function fprintf
4958(gdb) set dprintf-channel mylog
4959(gdb) dprintf 25,"at line 25, glob=%d\n",glob
4960Dprintf 1 at 0x123456: file main.c, line 25.
4961(gdb) info break
49621 dprintf keep y 0x00123456 in main at main.c:25
4963 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
4964 continue
4965(gdb)
4966@end example
4967
4968Note that the @code{info break} displays the dynamic printf commands
4969as normal breakpoint commands; you can thus easily see the effect of
4970the variable settings.
4971
d3ce09f5
SS
4972@item set disconnected-dprintf on
4973@itemx set disconnected-dprintf off
4974@kindex set disconnected-dprintf
4975Choose whether @code{dprintf} commands should continue to run if
4976@value{GDBN} has disconnected from the target. This only applies
4977if the @code{dprintf-style} is @code{agent}.
4978
4979@item show disconnected-dprintf off
4980@kindex show disconnected-dprintf
4981Show the current choice for disconnected @code{dprintf}.
4982
e7e0cddf
SS
4983@end table
4984
4985@value{GDBN} does not check the validity of function and channel,
4986relying on you to supply values that are meaningful for the contexts
4987in which they are being used. For instance, the function and channel
4988may be the values of local variables, but if that is the case, then
4989all enabled dynamic prints must be at locations within the scope of
4990those locals. If evaluation fails, @value{GDBN} will report an error.
4991
6149aea9
PA
4992@node Save Breakpoints
4993@subsection How to save breakpoints to a file
4994
4995To save breakpoint definitions to a file use the @w{@code{save
4996breakpoints}} command.
4997
4998@table @code
4999@kindex save breakpoints
5000@cindex save breakpoints to a file for future sessions
5001@item save breakpoints [@var{filename}]
5002This command saves all current breakpoint definitions together with
5003their commands and ignore counts, into a file @file{@var{filename}}
5004suitable for use in a later debugging session. This includes all
5005types of breakpoints (breakpoints, watchpoints, catchpoints,
5006tracepoints). To read the saved breakpoint definitions, use the
5007@code{source} command (@pxref{Command Files}). Note that watchpoints
5008with expressions involving local variables may fail to be recreated
5009because it may not be possible to access the context where the
5010watchpoint is valid anymore. Because the saved breakpoint definitions
5011are simply a sequence of @value{GDBN} commands that recreate the
5012breakpoints, you can edit the file in your favorite editing program,
5013and remove the breakpoint definitions you're not interested in, or
5014that can no longer be recreated.
5015@end table
5016
62e5f89c
SDJ
5017@node Static Probe Points
5018@subsection Static Probe Points
5019
5020@cindex static probe point, SystemTap
3133f8c1 5021@cindex static probe point, DTrace
62e5f89c
SDJ
5022@value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5023for Statically Defined Tracing, and the probes are designed to have a tiny
3133f8c1
JM
5024runtime code and data footprint, and no dynamic relocations.
5025
5026Currently, the following types of probes are supported on
5027ELF-compatible systems:
5028
5029@itemize @bullet
62e5f89c 5030
3133f8c1
JM
5031@item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5032@acronym{SDT} probes@footnote{See
62e5f89c 5033@uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
3133f8c1
JM
5034for more information on how to add @code{SystemTap} @acronym{SDT}
5035probes in your applications.}. @code{SystemTap} probes are usable
5036from assembly, C and C@t{++} languages@footnote{See
5037@uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5038for a good reference on how the @acronym{SDT} probes are implemented.}.
5039
5040@item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5041@acronym{USDT} probes. @code{DTrace} probes are usable from C and
5042C@t{++} languages.
5043@end itemize
62e5f89c
SDJ
5044
5045@cindex semaphores on static probe points
3133f8c1
JM
5046Some @code{SystemTap} probes have an associated semaphore variable;
5047for instance, this happens automatically if you defined your probe
5048using a DTrace-style @file{.d} file. If your probe has a semaphore,
5049@value{GDBN} will automatically enable it when you specify a
5050breakpoint using the @samp{-probe-stap} notation. But, if you put a
5051breakpoint at a probe's location by some other method (e.g.,
5052@code{break file:line}), then @value{GDBN} will not automatically set
5053the semaphore. @code{DTrace} probes do not support semaphores.
62e5f89c
SDJ
5054
5055You can examine the available static static probes using @code{info
5056probes}, with optional arguments:
5057
5058@table @code
5059@kindex info probes
3133f8c1
JM
5060@item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5061If given, @var{type} is either @code{stap} for listing
5062@code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5063probes. If omitted all probes are listed regardless of their types.
5064
62e5f89c
SDJ
5065If given, @var{provider} is a regular expression used to match against provider
5066names when selecting which probes to list. If omitted, probes by all
5067probes from all providers are listed.
5068
5069If given, @var{name} is a regular expression to match against probe names
5070when selecting which probes to list. If omitted, probe names are not
5071considered when deciding whether to display them.
5072
5073If given, @var{objfile} is a regular expression used to select which
5074object files (executable or shared libraries) to examine. If not
5075given, all object files are considered.
5076
5077@item info probes all
5078List the available static probes, from all types.
5079@end table
5080
9aca2ff8
JM
5081@cindex enabling and disabling probes
5082Some probe points can be enabled and/or disabled. The effect of
5083enabling or disabling a probe depends on the type of probe being
3133f8c1
JM
5084handled. Some @code{DTrace} probes can be enabled or
5085disabled, but @code{SystemTap} probes cannot be disabled.
9aca2ff8
JM
5086
5087You can enable (or disable) one or more probes using the following
5088commands, with optional arguments:
5089
5090@table @code
5091@kindex enable probes
5092@item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5093If given, @var{provider} is a regular expression used to match against
5094provider names when selecting which probes to enable. If omitted,
5095all probes from all providers are enabled.
5096
5097If given, @var{name} is a regular expression to match against probe
5098names when selecting which probes to enable. If omitted, probe names
5099are not considered when deciding whether to enable them.
5100
5101If given, @var{objfile} is a regular expression used to select which
5102object files (executable or shared libraries) to examine. If not
5103given, all object files are considered.
5104
5105@kindex disable probes
5106@item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5107See the @code{enable probes} command above for a description of the
5108optional arguments accepted by this command.
5109@end table
5110
62e5f89c
SDJ
5111@vindex $_probe_arg@r{, convenience variable}
5112A probe may specify up to twelve arguments. These are available at the
5113point at which the probe is defined---that is, when the current PC is
5114at the probe's location. The arguments are available using the
5115convenience variables (@pxref{Convenience Vars})
3133f8c1
JM
5116@code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
5117probes each probe argument is an integer of the appropriate size;
5118types are not preserved. In @code{DTrace} probes types are preserved
5119provided that they are recognized as such by @value{GDBN}; otherwise
5120the value of the probe argument will be a long integer. The
62e5f89c
SDJ
5121convenience variable @code{$_probe_argc} holds the number of arguments
5122at the current probe point.
5123
5124These variables are always available, but attempts to access them at
5125any location other than a probe point will cause @value{GDBN} to give
5126an error message.
5127
5128
c906108c 5129@c @ifclear BARETARGET
6d2ebf8b 5130@node Error in Breakpoints
d4f3574e 5131@subsection ``Cannot insert breakpoints''
c906108c 5132
fa3a767f
PA
5133If you request too many active hardware-assisted breakpoints and
5134watchpoints, you will see this error message:
d4f3574e
SS
5135
5136@c FIXME: the precise wording of this message may change; the relevant
5137@c source change is not committed yet (Sep 3, 1999).
5138@smallexample
5139Stopped; cannot insert breakpoints.
5140You may have requested too many hardware breakpoints and watchpoints.
5141@end smallexample
5142
5143@noindent
5144This message is printed when you attempt to resume the program, since
5145only then @value{GDBN} knows exactly how many hardware breakpoints and
5146watchpoints it needs to insert.
5147
5148When this message is printed, you need to disable or remove some of the
5149hardware-assisted breakpoints and watchpoints, and then continue.
5150
79a6e687 5151@node Breakpoint-related Warnings
1485d690
KB
5152@subsection ``Breakpoint address adjusted...''
5153@cindex breakpoint address adjusted
5154
5155Some processor architectures place constraints on the addresses at
5156which breakpoints may be placed. For architectures thus constrained,
5157@value{GDBN} will attempt to adjust the breakpoint's address to comply
5158with the constraints dictated by the architecture.
5159
5160One example of such an architecture is the Fujitsu FR-V. The FR-V is
5161a VLIW architecture in which a number of RISC-like instructions may be
5162bundled together for parallel execution. The FR-V architecture
5163constrains the location of a breakpoint instruction within such a
5164bundle to the instruction with the lowest address. @value{GDBN}
5165honors this constraint by adjusting a breakpoint's address to the
5166first in the bundle.
5167
5168It is not uncommon for optimized code to have bundles which contain
5169instructions from different source statements, thus it may happen that
5170a breakpoint's address will be adjusted from one source statement to
5171another. Since this adjustment may significantly alter @value{GDBN}'s
5172breakpoint related behavior from what the user expects, a warning is
5173printed when the breakpoint is first set and also when the breakpoint
5174is hit.
5175
5176A warning like the one below is printed when setting a breakpoint
5177that's been subject to address adjustment:
5178
5179@smallexample
5180warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
5181@end smallexample
5182
5183Such warnings are printed both for user settable and @value{GDBN}'s
5184internal breakpoints. If you see one of these warnings, you should
5185verify that a breakpoint set at the adjusted address will have the
5186desired affect. If not, the breakpoint in question may be removed and
b383017d 5187other breakpoints may be set which will have the desired behavior.
1485d690
KB
5188E.g., it may be sufficient to place the breakpoint at a later
5189instruction. A conditional breakpoint may also be useful in some
5190cases to prevent the breakpoint from triggering too often.
5191
5192@value{GDBN} will also issue a warning when stopping at one of these
5193adjusted breakpoints:
5194
5195@smallexample
5196warning: Breakpoint 1 address previously adjusted from 0x00010414
5197to 0x00010410.
5198@end smallexample
5199
5200When this warning is encountered, it may be too late to take remedial
5201action except in cases where the breakpoint is hit earlier or more
5202frequently than expected.
d4f3574e 5203
6d2ebf8b 5204@node Continuing and Stepping
79a6e687 5205@section Continuing and Stepping
c906108c
SS
5206
5207@cindex stepping
5208@cindex continuing
5209@cindex resuming execution
5210@dfn{Continuing} means resuming program execution until your program
5211completes normally. In contrast, @dfn{stepping} means executing just
5212one more ``step'' of your program, where ``step'' may mean either one
5213line of source code, or one machine instruction (depending on what
7a292a7a
SS
5214particular command you use). Either when continuing or when stepping,
5215your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e 5216it stops due to a signal, you may want to use @code{handle}, or use
e5f8a7cc
PA
5217@samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
5218or you may step into the signal's handler (@pxref{stepping and signal
5219handlers}).)
c906108c
SS
5220
5221@table @code
5222@kindex continue
41afff9a
EZ
5223@kindex c @r{(@code{continue})}
5224@kindex fg @r{(resume foreground execution)}
c906108c
SS
5225@item continue @r{[}@var{ignore-count}@r{]}
5226@itemx c @r{[}@var{ignore-count}@r{]}
5227@itemx fg @r{[}@var{ignore-count}@r{]}
5228Resume program execution, at the address where your program last stopped;
5229any breakpoints set at that address are bypassed. The optional argument
5230@var{ignore-count} allows you to specify a further number of times to
5231ignore a breakpoint at this location; its effect is like that of
79a6e687 5232@code{ignore} (@pxref{Conditions, ,Break Conditions}).
c906108c
SS
5233
5234The argument @var{ignore-count} is meaningful only when your program
5235stopped due to a breakpoint. At other times, the argument to
5236@code{continue} is ignored.
5237
d4f3574e
SS
5238The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
5239debugged program is deemed to be the foreground program) are provided
5240purely for convenience, and have exactly the same behavior as
5241@code{continue}.
c906108c
SS
5242@end table
5243
5244To resume execution at a different place, you can use @code{return}
79a6e687 5245(@pxref{Returning, ,Returning from a Function}) to go back to the
c906108c 5246calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
79a6e687 5247Different Address}) to go to an arbitrary location in your program.
c906108c
SS
5248
5249A typical technique for using stepping is to set a breakpoint
79a6e687 5250(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
c906108c
SS
5251beginning of the function or the section of your program where a problem
5252is believed to lie, run your program until it stops at that breakpoint,
5253and then step through the suspect area, examining the variables that are
5254interesting, until you see the problem happen.
5255
5256@table @code
5257@kindex step
41afff9a 5258@kindex s @r{(@code{step})}
c906108c
SS
5259@item step
5260Continue running your program until control reaches a different source
5261line, then stop it and return control to @value{GDBN}. This command is
5262abbreviated @code{s}.
5263
5264@quotation
5265@c "without debugging information" is imprecise; actually "without line
5266@c numbers in the debugging information". (gcc -g1 has debugging info but
5267@c not line numbers). But it seems complex to try to make that
5268@c distinction here.
5269@emph{Warning:} If you use the @code{step} command while control is
5270within a function that was compiled without debugging information,
5271execution proceeds until control reaches a function that does have
5272debugging information. Likewise, it will not step into a function which
5273is compiled without debugging information. To step through functions
5274without debugging information, use the @code{stepi} command, described
5275below.
5276@end quotation
5277
4a92d011
EZ
5278The @code{step} command only stops at the first instruction of a source
5279line. This prevents the multiple stops that could otherwise occur in
5280@code{switch} statements, @code{for} loops, etc. @code{step} continues
5281to stop if a function that has debugging information is called within
5282the line. In other words, @code{step} @emph{steps inside} any functions
5283called within the line.
c906108c 5284
d4f3574e
SS
5285Also, the @code{step} command only enters a function if there is line
5286number information for the function. Otherwise it acts like the
5d161b24 5287@code{next} command. This avoids problems when using @code{cc -gl}
eb17f351 5288on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5d161b24 5289was any debugging information about the routine.
c906108c
SS
5290
5291@item step @var{count}
5292Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
5293breakpoint is reached, or a signal not related to stepping occurs before
5294@var{count} steps, stepping stops right away.
c906108c
SS
5295
5296@kindex next
41afff9a 5297@kindex n @r{(@code{next})}
c906108c
SS
5298@item next @r{[}@var{count}@r{]}
5299Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
5300This is similar to @code{step}, but function calls that appear within
5301the line of code are executed without stopping. Execution stops when
5302control reaches a different line of code at the original stack level
5303that was executing when you gave the @code{next} command. This command
5304is abbreviated @code{n}.
c906108c
SS
5305
5306An argument @var{count} is a repeat count, as for @code{step}.
5307
5308
5309@c FIX ME!! Do we delete this, or is there a way it fits in with
5310@c the following paragraph? --- Vctoria
5311@c
5312@c @code{next} within a function that lacks debugging information acts like
5313@c @code{step}, but any function calls appearing within the code of the
5314@c function are executed without stopping.
5315
d4f3574e
SS
5316The @code{next} command only stops at the first instruction of a
5317source line. This prevents multiple stops that could otherwise occur in
4a92d011 5318@code{switch} statements, @code{for} loops, etc.
c906108c 5319
b90a5f51
CF
5320@kindex set step-mode
5321@item set step-mode
5322@cindex functions without line info, and stepping
5323@cindex stepping into functions with no line info
5324@itemx set step-mode on
4a92d011 5325The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
5326stop at the first instruction of a function which contains no debug line
5327information rather than stepping over it.
5328
4a92d011
EZ
5329This is useful in cases where you may be interested in inspecting the
5330machine instructions of a function which has no symbolic info and do not
5331want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
5332
5333@item set step-mode off
4a92d011 5334Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
5335debug information. This is the default.
5336
9c16f35a
EZ
5337@item show step-mode
5338Show whether @value{GDBN} will stop in or step over functions without
5339source line debug information.
5340
c906108c 5341@kindex finish
8dfa32fc 5342@kindex fin @r{(@code{finish})}
c906108c
SS
5343@item finish
5344Continue running until just after function in the selected stack frame
8dfa32fc
JB
5345returns. Print the returned value (if any). This command can be
5346abbreviated as @code{fin}.
c906108c
SS
5347
5348Contrast this with the @code{return} command (@pxref{Returning,
79a6e687 5349,Returning from a Function}).
c906108c
SS
5350
5351@kindex until
41afff9a 5352@kindex u @r{(@code{until})}
09d4efe1 5353@cindex run until specified location
c906108c
SS
5354@item until
5355@itemx u
5356Continue running until a source line past the current line, in the
5357current stack frame, is reached. This command is used to avoid single
5358stepping through a loop more than once. It is like the @code{next}
5359command, except that when @code{until} encounters a jump, it
5360automatically continues execution until the program counter is greater
5361than the address of the jump.
5362
5363This means that when you reach the end of a loop after single stepping
5364though it, @code{until} makes your program continue execution until it
5365exits the loop. In contrast, a @code{next} command at the end of a loop
5366simply steps back to the beginning of the loop, which forces you to step
5367through the next iteration.
5368
5369@code{until} always stops your program if it attempts to exit the current
5370stack frame.
5371
5372@code{until} may produce somewhat counterintuitive results if the order
5373of machine code does not match the order of the source lines. For
5374example, in the following excerpt from a debugging session, the @code{f}
5375(@code{frame}) command shows that execution is stopped at line
5376@code{206}; yet when we use @code{until}, we get to line @code{195}:
5377
474c8240 5378@smallexample
c906108c
SS
5379(@value{GDBP}) f
5380#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
5381206 expand_input();
5382(@value{GDBP}) until
5383195 for ( ; argc > 0; NEXTARG) @{
474c8240 5384@end smallexample
c906108c
SS
5385
5386This happened because, for execution efficiency, the compiler had
5387generated code for the loop closure test at the end, rather than the
5388start, of the loop---even though the test in a C @code{for}-loop is
5389written before the body of the loop. The @code{until} command appeared
5390to step back to the beginning of the loop when it advanced to this
5391expression; however, it has not really gone to an earlier
5392statement---not in terms of the actual machine code.
5393
5394@code{until} with no argument works by means of single
5395instruction stepping, and hence is slower than @code{until} with an
5396argument.
5397
5398@item until @var{location}
5399@itemx u @var{location}
697aa1b7
EZ
5400Continue running your program until either the specified @var{location} is
5401reached, or the current stack frame returns. The location is any of
2a25a5ba
EZ
5402the forms described in @ref{Specify Location}.
5403This form of the command uses temporary breakpoints, and
c60eb6f1
EZ
5404hence is quicker than @code{until} without an argument. The specified
5405location is actually reached only if it is in the current frame. This
5406implies that @code{until} can be used to skip over recursive function
5407invocations. For instance in the code below, if the current location is
5408line @code{96}, issuing @code{until 99} will execute the program up to
db2e3e2e 5409line @code{99} in the same invocation of factorial, i.e., after the inner
c60eb6f1
EZ
5410invocations have returned.
5411
5412@smallexample
541394 int factorial (int value)
541495 @{
541596 if (value > 1) @{
541697 value *= factorial (value - 1);
541798 @}
541899 return (value);
5419100 @}
5420@end smallexample
5421
5422
5423@kindex advance @var{location}
984359d2 5424@item advance @var{location}
09d4efe1 5425Continue running the program up to the given @var{location}. An argument is
2a25a5ba
EZ
5426required, which should be of one of the forms described in
5427@ref{Specify Location}.
5428Execution will also stop upon exit from the current stack
c60eb6f1
EZ
5429frame. This command is similar to @code{until}, but @code{advance} will
5430not skip over recursive function calls, and the target location doesn't
5431have to be in the same frame as the current one.
5432
c906108c
SS
5433
5434@kindex stepi
41afff9a 5435@kindex si @r{(@code{stepi})}
c906108c 5436@item stepi
96a2c332 5437@itemx stepi @var{arg}
c906108c
SS
5438@itemx si
5439Execute one machine instruction, then stop and return to the debugger.
5440
5441It is often useful to do @samp{display/i $pc} when stepping by machine
5442instructions. This makes @value{GDBN} automatically display the next
5443instruction to be executed, each time your program stops. @xref{Auto
79a6e687 5444Display,, Automatic Display}.
c906108c
SS
5445
5446An argument is a repeat count, as in @code{step}.
5447
5448@need 750
5449@kindex nexti
41afff9a 5450@kindex ni @r{(@code{nexti})}
c906108c 5451@item nexti
96a2c332 5452@itemx nexti @var{arg}
c906108c
SS
5453@itemx ni
5454Execute one machine instruction, but if it is a function call,
5455proceed until the function returns.
5456
5457An argument is a repeat count, as in @code{next}.
c1e36e3e
PA
5458
5459@end table
5460
5461@anchor{range stepping}
5462@cindex range stepping
5463@cindex target-assisted range stepping
5464By default, and if available, @value{GDBN} makes use of
5465target-assisted @dfn{range stepping}. In other words, whenever you
5466use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
5467tells the target to step the corresponding range of instruction
5468addresses instead of issuing multiple single-steps. This speeds up
5469line stepping, particularly for remote targets. Ideally, there should
5470be no reason you would want to turn range stepping off. However, it's
5471possible that a bug in the debug info, a bug in the remote stub (for
5472remote targets), or even a bug in @value{GDBN} could make line
5473stepping behave incorrectly when target-assisted range stepping is
5474enabled. You can use the following command to turn off range stepping
5475if necessary:
5476
5477@table @code
5478@kindex set range-stepping
5479@kindex show range-stepping
5480@item set range-stepping
5481@itemx show range-stepping
5482Control whether range stepping is enabled.
5483
5484If @code{on}, and the target supports it, @value{GDBN} tells the
5485target to step a range of addresses itself, instead of issuing
5486multiple single-steps. If @code{off}, @value{GDBN} always issues
5487single-steps, even if range stepping is supported by the target. The
5488default is @code{on}.
5489
c906108c
SS
5490@end table
5491
aad1c02c
TT
5492@node Skipping Over Functions and Files
5493@section Skipping Over Functions and Files
1bfeeb0f
JL
5494@cindex skipping over functions and files
5495
5496The program you are debugging may contain some functions which are
5497uninteresting to debug. The @code{skip} comand lets you tell @value{GDBN} to
5498skip a function or all functions in a file when stepping.
5499
5500For example, consider the following C function:
5501
5502@smallexample
5503101 int func()
5504102 @{
5505103 foo(boring());
5506104 bar(boring());
5507105 @}
5508@end smallexample
5509
5510@noindent
5511Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
5512are not interested in stepping through @code{boring}. If you run @code{step}
5513at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
5514step over both @code{foo} and @code{boring}!
5515
5516One solution is to @code{step} into @code{boring} and use the @code{finish}
5517command to immediately exit it. But this can become tedious if @code{boring}
5518is called from many places.
5519
5520A more flexible solution is to execute @kbd{skip boring}. This instructs
5521@value{GDBN} never to step into @code{boring}. Now when you execute
5522@code{step} at line 103, you'll step over @code{boring} and directly into
5523@code{foo}.
5524
5525You can also instruct @value{GDBN} to skip all functions in a file, with, for
5526example, @code{skip file boring.c}.
5527
5528@table @code
5529@kindex skip function
5530@item skip @r{[}@var{linespec}@r{]}
5531@itemx skip function @r{[}@var{linespec}@r{]}
5532After running this command, the function named by @var{linespec} or the
5533function containing the line named by @var{linespec} will be skipped over when
983fb131 5534stepping. @xref{Specify Location}.
1bfeeb0f
JL
5535
5536If you do not specify @var{linespec}, the function you're currently debugging
5537will be skipped.
5538
5539(If you have a function called @code{file} that you want to skip, use
5540@kbd{skip function file}.)
5541
5542@kindex skip file
5543@item skip file @r{[}@var{filename}@r{]}
5544After running this command, any function whose source lives in @var{filename}
5545will be skipped over when stepping.
5546
5547If you do not specify @var{filename}, functions whose source lives in the file
5548you're currently debugging will be skipped.
5549@end table
5550
5551Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
5552These are the commands for managing your list of skips:
5553
5554@table @code
5555@kindex info skip
5556@item info skip @r{[}@var{range}@r{]}
5557Print details about the specified skip(s). If @var{range} is not specified,
5558print a table with details about all functions and files marked for skipping.
5559@code{info skip} prints the following information about each skip:
5560
5561@table @emph
5562@item Identifier
5563A number identifying this skip.
5564@item Type
5565The type of this skip, either @samp{function} or @samp{file}.
5566@item Enabled or Disabled
5567Enabled skips are marked with @samp{y}. Disabled skips are marked with @samp{n}.
5568@item Address
5569For function skips, this column indicates the address in memory of the function
5570being skipped. If you've set a function skip on a function which has not yet
5571been loaded, this field will contain @samp{<PENDING>}. Once a shared library
5572which has the function is loaded, @code{info skip} will show the function's
5573address here.
5574@item What
5575For file skips, this field contains the filename being skipped. For functions
5576skips, this field contains the function name and its line number in the file
5577where it is defined.
5578@end table
5579
5580@kindex skip delete
5581@item skip delete @r{[}@var{range}@r{]}
5582Delete the specified skip(s). If @var{range} is not specified, delete all
5583skips.
5584
5585@kindex skip enable
5586@item skip enable @r{[}@var{range}@r{]}
5587Enable the specified skip(s). If @var{range} is not specified, enable all
5588skips.
5589
5590@kindex skip disable
5591@item skip disable @r{[}@var{range}@r{]}
5592Disable the specified skip(s). If @var{range} is not specified, disable all
5593skips.
5594
5595@end table
5596
6d2ebf8b 5597@node Signals
c906108c
SS
5598@section Signals
5599@cindex signals
5600
5601A signal is an asynchronous event that can happen in a program. The
5602operating system defines the possible kinds of signals, and gives each
5603kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 5604signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
5605@code{SIGSEGV} is the signal a program gets from referencing a place in
5606memory far away from all the areas in use; @code{SIGALRM} occurs when
5607the alarm clock timer goes off (which happens only if your program has
5608requested an alarm).
5609
5610@cindex fatal signals
5611Some signals, including @code{SIGALRM}, are a normal part of the
5612functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 5613errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
5614program has not specified in advance some other way to handle the signal.
5615@code{SIGINT} does not indicate an error in your program, but it is normally
5616fatal so it can carry out the purpose of the interrupt: to kill the program.
5617
5618@value{GDBN} has the ability to detect any occurrence of a signal in your
5619program. You can tell @value{GDBN} in advance what to do for each kind of
5620signal.
5621
5622@cindex handling signals
24f93129
EZ
5623Normally, @value{GDBN} is set up to let the non-erroneous signals like
5624@code{SIGALRM} be silently passed to your program
5625(so as not to interfere with their role in the program's functioning)
c906108c
SS
5626but to stop your program immediately whenever an error signal happens.
5627You can change these settings with the @code{handle} command.
5628
5629@table @code
5630@kindex info signals
09d4efe1 5631@kindex info handle
c906108c 5632@item info signals
96a2c332 5633@itemx info handle
c906108c
SS
5634Print a table of all the kinds of signals and how @value{GDBN} has been told to
5635handle each one. You can use this to see the signal numbers of all
5636the defined types of signals.
5637
45ac1734
EZ
5638@item info signals @var{sig}
5639Similar, but print information only about the specified signal number.
5640
d4f3574e 5641@code{info handle} is an alias for @code{info signals}.
c906108c 5642
ab04a2af
TT
5643@item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
5644Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
5645for details about this command.
5646
c906108c 5647@kindex handle
45ac1734 5648@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
697aa1b7 5649Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
5ece1a18 5650can be the number of a signal or its name (with or without the
24f93129 5651@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 5652@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
5653known signals. Optional arguments @var{keywords}, described below,
5654say what change to make.
c906108c
SS
5655@end table
5656
5657@c @group
5658The keywords allowed by the @code{handle} command can be abbreviated.
5659Their full names are:
5660
5661@table @code
5662@item nostop
5663@value{GDBN} should not stop your program when this signal happens. It may
5664still print a message telling you that the signal has come in.
5665
5666@item stop
5667@value{GDBN} should stop your program when this signal happens. This implies
5668the @code{print} keyword as well.
5669
5670@item print
5671@value{GDBN} should print a message when this signal happens.
5672
5673@item noprint
5674@value{GDBN} should not mention the occurrence of the signal at all. This
5675implies the @code{nostop} keyword as well.
5676
5677@item pass
5ece1a18 5678@itemx noignore
c906108c
SS
5679@value{GDBN} should allow your program to see this signal; your program
5680can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 5681and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
5682
5683@item nopass
5ece1a18 5684@itemx ignore
c906108c 5685@value{GDBN} should not allow your program to see this signal.
5ece1a18 5686@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
5687@end table
5688@c @end group
5689
d4f3574e
SS
5690When a signal stops your program, the signal is not visible to the
5691program until you
c906108c
SS
5692continue. Your program sees the signal then, if @code{pass} is in
5693effect for the signal in question @emph{at that time}. In other words,
5694after @value{GDBN} reports a signal, you can use the @code{handle}
5695command with @code{pass} or @code{nopass} to control whether your
5696program sees that signal when you continue.
5697
24f93129
EZ
5698The default is set to @code{nostop}, @code{noprint}, @code{pass} for
5699non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
5700@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
5701erroneous signals.
5702
c906108c
SS
5703You can also use the @code{signal} command to prevent your program from
5704seeing a signal, or cause it to see a signal it normally would not see,
5705or to give it any signal at any time. For example, if your program stopped
5706due to some sort of memory reference error, you might store correct
5707values into the erroneous variables and continue, hoping to see more
5708execution; but your program would probably terminate immediately as
5709a result of the fatal signal once it saw the signal. To prevent this,
5710you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
79a6e687 5711Program a Signal}.
c906108c 5712
e5f8a7cc
PA
5713@cindex stepping and signal handlers
5714@anchor{stepping and signal handlers}
5715
5716@value{GDBN} optimizes for stepping the mainline code. If a signal
5717that has @code{handle nostop} and @code{handle pass} set arrives while
5718a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
5719in progress, @value{GDBN} lets the signal handler run and then resumes
5720stepping the mainline code once the signal handler returns. In other
5721words, @value{GDBN} steps over the signal handler. This prevents
5722signals that you've specified as not interesting (with @code{handle
5723nostop}) from changing the focus of debugging unexpectedly. Note that
5724the signal handler itself may still hit a breakpoint, stop for another
5725signal that has @code{handle stop} in effect, or for any other event
5726that normally results in stopping the stepping command sooner. Also
5727note that @value{GDBN} still informs you that the program received a
5728signal if @code{handle print} is set.
5729
5730@anchor{stepping into signal handlers}
5731
5732If you set @code{handle pass} for a signal, and your program sets up a
5733handler for it, then issuing a stepping command, such as @code{step}
5734or @code{stepi}, when your program is stopped due to the signal will
5735step @emph{into} the signal handler (if the target supports that).
5736
5737Likewise, if you use the @code{queue-signal} command to queue a signal
5738to be delivered to the current thread when execution of the thread
5739resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
5740stepping command will step into the signal handler.
5741
5742Here's an example, using @code{stepi} to step to the first instruction
5743of @code{SIGUSR1}'s handler:
5744
5745@smallexample
5746(@value{GDBP}) handle SIGUSR1
5747Signal Stop Print Pass to program Description
5748SIGUSR1 Yes Yes Yes User defined signal 1
5749(@value{GDBP}) c
5750Continuing.
5751
5752Program received signal SIGUSR1, User defined signal 1.
5753main () sigusr1.c:28
575428 p = 0;
5755(@value{GDBP}) si
5756sigusr1_handler () at sigusr1.c:9
57579 @{
5758@end smallexample
5759
5760The same, but using @code{queue-signal} instead of waiting for the
5761program to receive the signal first:
5762
5763@smallexample
5764(@value{GDBP}) n
576528 p = 0;
5766(@value{GDBP}) queue-signal SIGUSR1
5767(@value{GDBP}) si
5768sigusr1_handler () at sigusr1.c:9
57699 @{
5770(@value{GDBP})
5771@end smallexample
5772
4aa995e1
PA
5773@cindex extra signal information
5774@anchor{extra signal information}
5775
5776On some targets, @value{GDBN} can inspect extra signal information
5777associated with the intercepted signal, before it is actually
5778delivered to the program being debugged. This information is exported
5779by the convenience variable @code{$_siginfo}, and consists of data
5780that is passed by the kernel to the signal handler at the time of the
5781receipt of a signal. The data type of the information itself is
5782target dependent. You can see the data type using the @code{ptype
5783$_siginfo} command. On Unix systems, it typically corresponds to the
5784standard @code{siginfo_t} type, as defined in the @file{signal.h}
5785system header.
5786
5787Here's an example, on a @sc{gnu}/Linux system, printing the stray
5788referenced address that raised a segmentation fault.
5789
5790@smallexample
5791@group
5792(@value{GDBP}) continue
5793Program received signal SIGSEGV, Segmentation fault.
57940x0000000000400766 in main ()
579569 *(int *)p = 0;
5796(@value{GDBP}) ptype $_siginfo
5797type = struct @{
5798 int si_signo;
5799 int si_errno;
5800 int si_code;
5801 union @{
5802 int _pad[28];
5803 struct @{...@} _kill;
5804 struct @{...@} _timer;
5805 struct @{...@} _rt;
5806 struct @{...@} _sigchld;
5807 struct @{...@} _sigfault;
5808 struct @{...@} _sigpoll;
5809 @} _sifields;
5810@}
5811(@value{GDBP}) ptype $_siginfo._sifields._sigfault
5812type = struct @{
5813 void *si_addr;
5814@}
5815(@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
5816$1 = (void *) 0x7ffff7ff7000
5817@end group
5818@end smallexample
5819
5820Depending on target support, @code{$_siginfo} may also be writable.
5821
6d2ebf8b 5822@node Thread Stops
79a6e687 5823@section Stopping and Starting Multi-thread Programs
c906108c 5824
0606b73b
SL
5825@cindex stopped threads
5826@cindex threads, stopped
5827
5828@cindex continuing threads
5829@cindex threads, continuing
5830
5831@value{GDBN} supports debugging programs with multiple threads
5832(@pxref{Threads,, Debugging Programs with Multiple Threads}). There
5833are two modes of controlling execution of your program within the
5834debugger. In the default mode, referred to as @dfn{all-stop mode},
5835when any thread in your program stops (for example, at a breakpoint
5836or while being stepped), all other threads in the program are also stopped by
5837@value{GDBN}. On some targets, @value{GDBN} also supports
5838@dfn{non-stop mode}, in which other threads can continue to run freely while
5839you examine the stopped thread in the debugger.
5840
5841@menu
5842* All-Stop Mode:: All threads stop when GDB takes control
5843* Non-Stop Mode:: Other threads continue to execute
5844* Background Execution:: Running your program asynchronously
5845* Thread-Specific Breakpoints:: Controlling breakpoints
5846* Interrupted System Calls:: GDB may interfere with system calls
d914c394 5847* Observer Mode:: GDB does not alter program behavior
0606b73b
SL
5848@end menu
5849
5850@node All-Stop Mode
5851@subsection All-Stop Mode
5852
5853@cindex all-stop mode
5854
5855In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
5856@emph{all} threads of execution stop, not just the current thread. This
5857allows you to examine the overall state of the program, including
5858switching between threads, without worrying that things may change
5859underfoot.
5860
5861Conversely, whenever you restart the program, @emph{all} threads start
5862executing. @emph{This is true even when single-stepping} with commands
5863like @code{step} or @code{next}.
5864
5865In particular, @value{GDBN} cannot single-step all threads in lockstep.
5866Since thread scheduling is up to your debugging target's operating
5867system (not controlled by @value{GDBN}), other threads may
5868execute more than one statement while the current thread completes a
5869single step. Moreover, in general other threads stop in the middle of a
5870statement, rather than at a clean statement boundary, when the program
5871stops.
5872
5873You might even find your program stopped in another thread after
5874continuing or even single-stepping. This happens whenever some other
5875thread runs into a breakpoint, a signal, or an exception before the
5876first thread completes whatever you requested.
5877
5878@cindex automatic thread selection
5879@cindex switching threads automatically
5880@cindex threads, automatic switching
5881Whenever @value{GDBN} stops your program, due to a breakpoint or a
5882signal, it automatically selects the thread where that breakpoint or
5883signal happened. @value{GDBN} alerts you to the context switch with a
5884message such as @samp{[Switching to Thread @var{n}]} to identify the
5885thread.
5886
5887On some OSes, you can modify @value{GDBN}'s default behavior by
5888locking the OS scheduler to allow only a single thread to run.
5889
5890@table @code
5891@item set scheduler-locking @var{mode}
5892@cindex scheduler locking mode
5893@cindex lock scheduler
f2665db5
MM
5894Set the scheduler locking mode. It applies to normal execution,
5895record mode, and replay mode. If it is @code{off}, then there is no
5896locking and any thread may run at any time. If @code{on}, then only
5897the current thread may run when the inferior is resumed. The
5898@code{step} mode optimizes for single-stepping; it prevents other
5899threads from preempting the current thread while you are stepping, so
5900that the focus of debugging does not change unexpectedly. Other
5901threads never get a chance to run when you step, and they are
5902completely free to run when you use commands like @samp{continue},
5903@samp{until}, or @samp{finish}. However, unless another thread hits a
5904breakpoint during its timeslice, @value{GDBN} does not change the
5905current thread away from the thread that you are debugging. The
5906@code{replay} mode behaves like @code{off} in record mode and like
5907@code{on} in replay mode.
0606b73b
SL
5908
5909@item show scheduler-locking
5910Display the current scheduler locking mode.
5911@end table
5912
d4db2f36
PA
5913@cindex resume threads of multiple processes simultaneously
5914By default, when you issue one of the execution commands such as
5915@code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
5916threads of the current inferior to run. For example, if @value{GDBN}
5917is attached to two inferiors, each with two threads, the
5918@code{continue} command resumes only the two threads of the current
5919inferior. This is useful, for example, when you debug a program that
5920forks and you want to hold the parent stopped (so that, for instance,
5921it doesn't run to exit), while you debug the child. In other
5922situations, you may not be interested in inspecting the current state
5923of any of the processes @value{GDBN} is attached to, and you may want
5924to resume them all until some breakpoint is hit. In the latter case,
5925you can instruct @value{GDBN} to allow all threads of all the
5926inferiors to run with the @w{@code{set schedule-multiple}} command.
5927
5928@table @code
5929@kindex set schedule-multiple
5930@item set schedule-multiple
5931Set the mode for allowing threads of multiple processes to be resumed
5932when an execution command is issued. When @code{on}, all threads of
5933all processes are allowed to run. When @code{off}, only the threads
5934of the current process are resumed. The default is @code{off}. The
5935@code{scheduler-locking} mode takes precedence when set to @code{on},
5936or while you are stepping and set to @code{step}.
5937
5938@item show schedule-multiple
5939Display the current mode for resuming the execution of threads of
5940multiple processes.
5941@end table
5942
0606b73b
SL
5943@node Non-Stop Mode
5944@subsection Non-Stop Mode
5945
5946@cindex non-stop mode
5947
5948@c This section is really only a place-holder, and needs to be expanded
97d8f0ee 5949@c with more details.
0606b73b
SL
5950
5951For some multi-threaded targets, @value{GDBN} supports an optional
5952mode of operation in which you can examine stopped program threads in
5953the debugger while other threads continue to execute freely. This
97d8f0ee
DE
5954minimizes intrusion when debugging live systems, such as programs
5955where some threads have real-time constraints or must continue to
0606b73b
SL
5956respond to external events. This is referred to as @dfn{non-stop} mode.
5957
5958In non-stop mode, when a thread stops to report a debugging event,
5959@emph{only} that thread is stopped; @value{GDBN} does not stop other
5960threads as well, in contrast to the all-stop mode behavior. Additionally,
5961execution commands such as @code{continue} and @code{step} apply by default
5962only to the current thread in non-stop mode, rather than all threads as
5963in all-stop mode. This allows you to control threads explicitly in
97d8f0ee 5964ways that are not possible in all-stop mode --- for example, stepping
0606b73b 5965one thread while allowing others to run freely, stepping
97d8f0ee 5966one thread while holding all others stopped, or stepping several threads
0606b73b
SL
5967independently and simultaneously.
5968
5969To enter non-stop mode, use this sequence of commands before you run
5970or attach to your program:
5971
0606b73b 5972@smallexample
0606b73b
SL
5973# If using the CLI, pagination breaks non-stop.
5974set pagination off
5975
5976# Finally, turn it on!
5977set non-stop on
5978@end smallexample
5979
5980You can use these commands to manipulate the non-stop mode setting:
5981
5982@table @code
5983@kindex set non-stop
5984@item set non-stop on
5985Enable selection of non-stop mode.
5986@item set non-stop off
5987Disable selection of non-stop mode.
5988@kindex show non-stop
5989@item show non-stop
5990Show the current non-stop enablement setting.
5991@end table
5992
5993Note these commands only reflect whether non-stop mode is enabled,
97d8f0ee 5994not whether the currently-executing program is being run in non-stop mode.
0606b73b 5995In particular, the @code{set non-stop} preference is only consulted when
97d8f0ee 5996@value{GDBN} starts or connects to the target program, and it is generally
0606b73b
SL
5997not possible to switch modes once debugging has started. Furthermore,
5998since not all targets support non-stop mode, even when you have enabled
5999non-stop mode, @value{GDBN} may still fall back to all-stop operation by
6000default.
6001
6002In non-stop mode, all execution commands apply only to the current thread
97d8f0ee 6003by default. That is, @code{continue} only continues one thread.
0606b73b
SL
6004To continue all threads, issue @code{continue -a} or @code{c -a}.
6005
97d8f0ee 6006You can use @value{GDBN}'s background execution commands
0606b73b 6007(@pxref{Background Execution}) to run some threads in the background
97d8f0ee 6008while you continue to examine or step others from @value{GDBN}.
0606b73b
SL
6009The MI execution commands (@pxref{GDB/MI Program Execution}) are
6010always executed asynchronously in non-stop mode.
6011
6012Suspending execution is done with the @code{interrupt} command when
97d8f0ee
DE
6013running in the background, or @kbd{Ctrl-c} during foreground execution.
6014In all-stop mode, this stops the whole process;
6015but in non-stop mode the interrupt applies only to the current thread.
0606b73b
SL
6016To stop the whole program, use @code{interrupt -a}.
6017
6018Other execution commands do not currently support the @code{-a} option.
6019
6020In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
6021that thread current, as it does in all-stop mode. This is because the
97d8f0ee 6022thread stop notifications are asynchronous with respect to @value{GDBN}'s
0606b73b
SL
6023command interpreter, and it would be confusing if @value{GDBN} unexpectedly
6024changed to a different thread just as you entered a command to operate on the
6025previously current thread.
6026
6027@node Background Execution
6028@subsection Background Execution
6029
6030@cindex foreground execution
6031@cindex background execution
6032@cindex asynchronous execution
6033@cindex execution, foreground, background and asynchronous
6034
6035@value{GDBN}'s execution commands have two variants: the normal
6036foreground (synchronous) behavior, and a background
97d8f0ee 6037(asynchronous) behavior. In foreground execution, @value{GDBN} waits for
0606b73b
SL
6038the program to report that some thread has stopped before prompting for
6039another command. In background execution, @value{GDBN} immediately gives
6040a command prompt so that you can issue other commands while your program runs.
6041
32fc0df9
PA
6042If the target doesn't support async mode, @value{GDBN} issues an error
6043message if you attempt to use the background execution commands.
6044
0606b73b
SL
6045To specify background execution, add a @code{&} to the command. For example,
6046the background form of the @code{continue} command is @code{continue&}, or
6047just @code{c&}. The execution commands that accept background execution
6048are:
6049
6050@table @code
6051@kindex run&
6052@item run
6053@xref{Starting, , Starting your Program}.
6054
6055@item attach
6056@kindex attach&
6057@xref{Attach, , Debugging an Already-running Process}.
6058
6059@item step
6060@kindex step&
6061@xref{Continuing and Stepping, step}.
6062
6063@item stepi
6064@kindex stepi&
6065@xref{Continuing and Stepping, stepi}.
6066
6067@item next
6068@kindex next&
6069@xref{Continuing and Stepping, next}.
6070
7ce58dd2
DE
6071@item nexti
6072@kindex nexti&
6073@xref{Continuing and Stepping, nexti}.
6074
0606b73b
SL
6075@item continue
6076@kindex continue&
6077@xref{Continuing and Stepping, continue}.
6078
6079@item finish
6080@kindex finish&
6081@xref{Continuing and Stepping, finish}.
6082
6083@item until
6084@kindex until&
6085@xref{Continuing and Stepping, until}.
6086
6087@end table
6088
6089Background execution is especially useful in conjunction with non-stop
6090mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
6091However, you can also use these commands in the normal all-stop mode with
6092the restriction that you cannot issue another execution command until the
6093previous one finishes. Examples of commands that are valid in all-stop
6094mode while the program is running include @code{help} and @code{info break}.
6095
6096You can interrupt your program while it is running in the background by
6097using the @code{interrupt} command.
6098
6099@table @code
6100@kindex interrupt
6101@item interrupt
6102@itemx interrupt -a
6103
97d8f0ee 6104Suspend execution of the running program. In all-stop mode,
0606b73b 6105@code{interrupt} stops the whole process, but in non-stop mode, it stops
97d8f0ee 6106only the current thread. To stop the whole program in non-stop mode,
0606b73b
SL
6107use @code{interrupt -a}.
6108@end table
6109
0606b73b
SL
6110@node Thread-Specific Breakpoints
6111@subsection Thread-Specific Breakpoints
6112
c906108c 6113When your program has multiple threads (@pxref{Threads,, Debugging
79a6e687 6114Programs with Multiple Threads}), you can choose whether to set
c906108c
SS
6115breakpoints on all threads, or on a particular thread.
6116
6117@table @code
6118@cindex breakpoints and threads
6119@cindex thread breakpoints
5d5658a1
PA
6120@kindex break @dots{} thread @var{thread-id}
6121@item break @var{location} thread @var{thread-id}
6122@itemx break @var{location} thread @var{thread-id} if @dots{}
629500fa 6123@var{location} specifies source lines; there are several ways of
2a25a5ba
EZ
6124writing them (@pxref{Specify Location}), but the effect is always to
6125specify some source line.
c906108c 6126
5d5658a1 6127Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
c906108c 6128to specify that you only want @value{GDBN} to stop the program when a
5d5658a1
PA
6129particular thread reaches this breakpoint. The @var{thread-id} specifier
6130is one of the thread identifiers assigned by @value{GDBN}, shown
697aa1b7 6131in the first column of the @samp{info threads} display.
c906108c 6132
5d5658a1 6133If you do not specify @samp{thread @var{thread-id}} when you set a
c906108c
SS
6134breakpoint, the breakpoint applies to @emph{all} threads of your
6135program.
6136
6137You can use the @code{thread} qualifier on conditional breakpoints as
5d5658a1 6138well; in this case, place @samp{thread @var{thread-id}} before or
b6199126 6139after the breakpoint condition, like this:
c906108c
SS
6140
6141@smallexample
2df3850c 6142(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
6143@end smallexample
6144
6145@end table
6146
f4fb82a1
PA
6147Thread-specific breakpoints are automatically deleted when
6148@value{GDBN} detects the corresponding thread is no longer in the
6149thread list. For example:
6150
6151@smallexample
6152(@value{GDBP}) c
6153Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
6154@end smallexample
6155
6156There are several ways for a thread to disappear, such as a regular
6157thread exit, but also when you detach from the process with the
6158@code{detach} command (@pxref{Attach, ,Debugging an Already-running
6159Process}), or if @value{GDBN} loses the remote connection
6160(@pxref{Remote Debugging}), etc. Note that with some targets,
6161@value{GDBN} is only able to detect a thread has exited when the user
6162explictly asks for the thread list with the @code{info threads}
6163command.
6164
0606b73b
SL
6165@node Interrupted System Calls
6166@subsection Interrupted System Calls
c906108c 6167
36d86913
MC
6168@cindex thread breakpoints and system calls
6169@cindex system calls and thread breakpoints
6170@cindex premature return from system calls
0606b73b
SL
6171There is an unfortunate side effect when using @value{GDBN} to debug
6172multi-threaded programs. If one thread stops for a
36d86913
MC
6173breakpoint, or for some other reason, and another thread is blocked in a
6174system call, then the system call may return prematurely. This is a
6175consequence of the interaction between multiple threads and the signals
6176that @value{GDBN} uses to implement breakpoints and other events that
6177stop execution.
6178
6179To handle this problem, your program should check the return value of
6180each system call and react appropriately. This is good programming
6181style anyways.
6182
6183For example, do not write code like this:
6184
6185@smallexample
6186 sleep (10);
6187@end smallexample
6188
6189The call to @code{sleep} will return early if a different thread stops
6190at a breakpoint or for some other reason.
6191
6192Instead, write this:
6193
6194@smallexample
6195 int unslept = 10;
6196 while (unslept > 0)
6197 unslept = sleep (unslept);
6198@end smallexample
6199
6200A system call is allowed to return early, so the system is still
6201conforming to its specification. But @value{GDBN} does cause your
6202multi-threaded program to behave differently than it would without
6203@value{GDBN}.
6204
6205Also, @value{GDBN} uses internal breakpoints in the thread library to
6206monitor certain events such as thread creation and thread destruction.
6207When such an event happens, a system call in another thread may return
6208prematurely, even though your program does not appear to stop.
6209
d914c394
SS
6210@node Observer Mode
6211@subsection Observer Mode
6212
6213If you want to build on non-stop mode and observe program behavior
6214without any chance of disruption by @value{GDBN}, you can set
6215variables to disable all of the debugger's attempts to modify state,
6216whether by writing memory, inserting breakpoints, etc. These operate
6217at a low level, intercepting operations from all commands.
6218
6219When all of these are set to @code{off}, then @value{GDBN} is said to
6220be @dfn{observer mode}. As a convenience, the variable
6221@code{observer} can be set to disable these, plus enable non-stop
6222mode.
6223
6224Note that @value{GDBN} will not prevent you from making nonsensical
6225combinations of these settings. For instance, if you have enabled
6226@code{may-insert-breakpoints} but disabled @code{may-write-memory},
6227then breakpoints that work by writing trap instructions into the code
6228stream will still not be able to be placed.
6229
6230@table @code
6231
6232@kindex observer
6233@item set observer on
6234@itemx set observer off
6235When set to @code{on}, this disables all the permission variables
6236below (except for @code{insert-fast-tracepoints}), plus enables
6237non-stop debugging. Setting this to @code{off} switches back to
6238normal debugging, though remaining in non-stop mode.
6239
6240@item show observer
6241Show whether observer mode is on or off.
6242
6243@kindex may-write-registers
6244@item set may-write-registers on
6245@itemx set may-write-registers off
6246This controls whether @value{GDBN} will attempt to alter the values of
6247registers, such as with assignment expressions in @code{print}, or the
6248@code{jump} command. It defaults to @code{on}.
6249
6250@item show may-write-registers
6251Show the current permission to write registers.
6252
6253@kindex may-write-memory
6254@item set may-write-memory on
6255@itemx set may-write-memory off
6256This controls whether @value{GDBN} will attempt to alter the contents
6257of memory, such as with assignment expressions in @code{print}. It
6258defaults to @code{on}.
6259
6260@item show may-write-memory
6261Show the current permission to write memory.
6262
6263@kindex may-insert-breakpoints
6264@item set may-insert-breakpoints on
6265@itemx set may-insert-breakpoints off
6266This controls whether @value{GDBN} will attempt to insert breakpoints.
6267This affects all breakpoints, including internal breakpoints defined
6268by @value{GDBN}. It defaults to @code{on}.
6269
6270@item show may-insert-breakpoints
6271Show the current permission to insert breakpoints.
6272
6273@kindex may-insert-tracepoints
6274@item set may-insert-tracepoints on
6275@itemx set may-insert-tracepoints off
6276This controls whether @value{GDBN} will attempt to insert (regular)
6277tracepoints at the beginning of a tracing experiment. It affects only
6278non-fast tracepoints, fast tracepoints being under the control of
6279@code{may-insert-fast-tracepoints}. It defaults to @code{on}.
6280
6281@item show may-insert-tracepoints
6282Show the current permission to insert tracepoints.
6283
6284@kindex may-insert-fast-tracepoints
6285@item set may-insert-fast-tracepoints on
6286@itemx set may-insert-fast-tracepoints off
6287This controls whether @value{GDBN} will attempt to insert fast
6288tracepoints at the beginning of a tracing experiment. It affects only
6289fast tracepoints, regular (non-fast) tracepoints being under the
6290control of @code{may-insert-tracepoints}. It defaults to @code{on}.
6291
6292@item show may-insert-fast-tracepoints
6293Show the current permission to insert fast tracepoints.
6294
6295@kindex may-interrupt
6296@item set may-interrupt on
6297@itemx set may-interrupt off
6298This controls whether @value{GDBN} will attempt to interrupt or stop
6299program execution. When this variable is @code{off}, the
6300@code{interrupt} command will have no effect, nor will
6301@kbd{Ctrl-c}. It defaults to @code{on}.
6302
6303@item show may-interrupt
6304Show the current permission to interrupt or stop the program.
6305
6306@end table
c906108c 6307
bacec72f
MS
6308@node Reverse Execution
6309@chapter Running programs backward
6310@cindex reverse execution
6311@cindex running programs backward
6312
6313When you are debugging a program, it is not unusual to realize that
6314you have gone too far, and some event of interest has already happened.
6315If the target environment supports it, @value{GDBN} can allow you to
6316``rewind'' the program by running it backward.
6317
6318A target environment that supports reverse execution should be able
6319to ``undo'' the changes in machine state that have taken place as the
6320program was executing normally. Variables, registers etc.@: should
6321revert to their previous values. Obviously this requires a great
6322deal of sophistication on the part of the target environment; not
6323all target environments can support reverse execution.
6324
6325When a program is executed in reverse, the instructions that
6326have most recently been executed are ``un-executed'', in reverse
6327order. The program counter runs backward, following the previous
6328thread of execution in reverse. As each instruction is ``un-executed'',
6329the values of memory and/or registers that were changed by that
6330instruction are reverted to their previous states. After executing
6331a piece of source code in reverse, all side effects of that code
6332should be ``undone'', and all variables should be returned to their
6333prior values@footnote{
6334Note that some side effects are easier to undo than others. For instance,
6335memory and registers are relatively easy, but device I/O is hard. Some
6336targets may be able undo things like device I/O, and some may not.
6337
6338The contract between @value{GDBN} and the reverse executing target
6339requires only that the target do something reasonable when
6340@value{GDBN} tells it to execute backwards, and then report the
6341results back to @value{GDBN}. Whatever the target reports back to
6342@value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
6343assumes that the memory and registers that the target reports are in a
6344consistant state, but @value{GDBN} accepts whatever it is given.
6345}.
6346
6347If you are debugging in a target environment that supports
6348reverse execution, @value{GDBN} provides the following commands.
6349
6350@table @code
6351@kindex reverse-continue
6352@kindex rc @r{(@code{reverse-continue})}
6353@item reverse-continue @r{[}@var{ignore-count}@r{]}
6354@itemx rc @r{[}@var{ignore-count}@r{]}
6355Beginning at the point where your program last stopped, start executing
6356in reverse. Reverse execution will stop for breakpoints and synchronous
6357exceptions (signals), just like normal execution. Behavior of
6358asynchronous signals depends on the target environment.
6359
6360@kindex reverse-step
6361@kindex rs @r{(@code{step})}
6362@item reverse-step @r{[}@var{count}@r{]}
6363Run the program backward until control reaches the start of a
6364different source line; then stop it, and return control to @value{GDBN}.
6365
6366Like the @code{step} command, @code{reverse-step} will only stop
6367at the beginning of a source line. It ``un-executes'' the previously
6368executed source line. If the previous source line included calls to
6369debuggable functions, @code{reverse-step} will step (backward) into
6370the called function, stopping at the beginning of the @emph{last}
6371statement in the called function (typically a return statement).
6372
6373Also, as with the @code{step} command, if non-debuggable functions are
6374called, @code{reverse-step} will run thru them backward without stopping.
6375
6376@kindex reverse-stepi
6377@kindex rsi @r{(@code{reverse-stepi})}
6378@item reverse-stepi @r{[}@var{count}@r{]}
6379Reverse-execute one machine instruction. Note that the instruction
6380to be reverse-executed is @emph{not} the one pointed to by the program
6381counter, but the instruction executed prior to that one. For instance,
6382if the last instruction was a jump, @code{reverse-stepi} will take you
6383back from the destination of the jump to the jump instruction itself.
6384
6385@kindex reverse-next
6386@kindex rn @r{(@code{reverse-next})}
6387@item reverse-next @r{[}@var{count}@r{]}
6388Run backward to the beginning of the previous line executed in
6389the current (innermost) stack frame. If the line contains function
6390calls, they will be ``un-executed'' without stopping. Starting from
6391the first line of a function, @code{reverse-next} will take you back
6392to the caller of that function, @emph{before} the function was called,
6393just as the normal @code{next} command would take you from the last
6394line of a function back to its return to its caller
16af530a 6395@footnote{Unless the code is too heavily optimized.}.
bacec72f
MS
6396
6397@kindex reverse-nexti
6398@kindex rni @r{(@code{reverse-nexti})}
6399@item reverse-nexti @r{[}@var{count}@r{]}
6400Like @code{nexti}, @code{reverse-nexti} executes a single instruction
6401in reverse, except that called functions are ``un-executed'' atomically.
6402That is, if the previously executed instruction was a return from
540aa8e7 6403another function, @code{reverse-nexti} will continue to execute
bacec72f
MS
6404in reverse until the call to that function (from the current stack
6405frame) is reached.
6406
6407@kindex reverse-finish
6408@item reverse-finish
6409Just as the @code{finish} command takes you to the point where the
6410current function returns, @code{reverse-finish} takes you to the point
6411where it was called. Instead of ending up at the end of the current
6412function invocation, you end up at the beginning.
6413
6414@kindex set exec-direction
6415@item set exec-direction
6416Set the direction of target execution.
984359d2 6417@item set exec-direction reverse
bacec72f
MS
6418@cindex execute forward or backward in time
6419@value{GDBN} will perform all execution commands in reverse, until the
6420exec-direction mode is changed to ``forward''. Affected commands include
6421@code{step, stepi, next, nexti, continue, and finish}. The @code{return}
6422command cannot be used in reverse mode.
6423@item set exec-direction forward
6424@value{GDBN} will perform all execution commands in the normal fashion.
6425This is the default.
6426@end table
6427
c906108c 6428
a2311334
EZ
6429@node Process Record and Replay
6430@chapter Recording Inferior's Execution and Replaying It
53cc454a
HZ
6431@cindex process record and replay
6432@cindex recording inferior's execution and replaying it
6433
8e05493c
EZ
6434On some platforms, @value{GDBN} provides a special @dfn{process record
6435and replay} target that can record a log of the process execution, and
6436replay it later with both forward and reverse execution commands.
a2311334
EZ
6437
6438@cindex replay mode
6439When this target is in use, if the execution log includes the record
6440for the next instruction, @value{GDBN} will debug in @dfn{replay
6441mode}. In the replay mode, the inferior does not really execute code
6442instructions. Instead, all the events that normally happen during
6443code execution are taken from the execution log. While code is not
6444really executed in replay mode, the values of registers (including the
6445program counter register) and the memory of the inferior are still
8e05493c
EZ
6446changed as they normally would. Their contents are taken from the
6447execution log.
a2311334
EZ
6448
6449@cindex record mode
6450If the record for the next instruction is not in the execution log,
6451@value{GDBN} will debug in @dfn{record mode}. In this mode, the
6452inferior executes normally, and @value{GDBN} records the execution log
6453for future replay.
6454
8e05493c
EZ
6455The process record and replay target supports reverse execution
6456(@pxref{Reverse Execution}), even if the platform on which the
6457inferior runs does not. However, the reverse execution is limited in
6458this case by the range of the instructions recorded in the execution
6459log. In other words, reverse execution on platforms that don't
6460support it directly can only be done in the replay mode.
6461
6462When debugging in the reverse direction, @value{GDBN} will work in
6463replay mode as long as the execution log includes the record for the
6464previous instruction; otherwise, it will work in record mode, if the
6465platform supports reverse execution, or stop if not.
6466
a2311334
EZ
6467For architecture environments that support process record and replay,
6468@value{GDBN} provides the following commands:
53cc454a
HZ
6469
6470@table @code
6471@kindex target record
59ea5688
MM
6472@kindex target record-full
6473@kindex target record-btrace
53cc454a 6474@kindex record
59ea5688
MM
6475@kindex record full
6476@kindex record btrace
f4abbc16 6477@kindex record btrace bts
b20a6524 6478@kindex record btrace pt
f4abbc16 6479@kindex record bts
b20a6524 6480@kindex record pt
53cc454a 6481@kindex rec
59ea5688
MM
6482@kindex rec full
6483@kindex rec btrace
f4abbc16 6484@kindex rec btrace bts
b20a6524 6485@kindex rec btrace pt
f4abbc16 6486@kindex rec bts
b20a6524 6487@kindex rec pt
59ea5688
MM
6488@item record @var{method}
6489This command starts the process record and replay target. The
6490recording method can be specified as parameter. Without a parameter
6491the command uses the @code{full} recording method. The following
6492recording methods are available:
a2311334 6493
59ea5688
MM
6494@table @code
6495@item full
6496Full record/replay recording using @value{GDBN}'s software record and
6497replay implementation. This method allows replaying and reverse
6498execution.
6499
f4abbc16 6500@item btrace @var{format}
52834460
MM
6501Hardware-supported instruction recording. This method does not record
6502data. Further, the data is collected in a ring buffer so old data will
b20a6524
MM
6503be overwritten when the buffer is full. It allows limited reverse
6504execution. Variables and registers are not available during reverse
6505execution.
59ea5688 6506
f4abbc16
MM
6507The recording format can be specified as parameter. Without a parameter
6508the command chooses the recording format. The following recording
6509formats are available:
6510
6511@table @code
6512@item bts
6513@cindex branch trace store
6514Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
6515this format, the processor stores a from/to record for each executed
6516branch in the btrace ring buffer.
b20a6524
MM
6517
6518@item pt
bc504a31
PA
6519@cindex Intel Processor Trace
6520Use the @dfn{Intel Processor Trace} recording format. In this
b20a6524
MM
6521format, the processor stores the execution trace in a compressed form
6522that is afterwards decoded by @value{GDBN}.
6523
6524The trace can be recorded with very low overhead. The compressed
6525trace format also allows small trace buffers to already contain a big
6526number of instructions compared to @acronym{BTS}.
6527
6528Decoding the recorded execution trace, on the other hand, is more
6529expensive than decoding @acronym{BTS} trace. This is mostly due to the
6530increased number of instructions to process. You should increase the
6531buffer-size with care.
f4abbc16
MM
6532@end table
6533
6534Not all recording formats may be available on all processors.
59ea5688
MM
6535@end table
6536
6537The process record and replay target can only debug a process that is
6538already running. Therefore, you need first to start the process with
6539the @kbd{run} or @kbd{start} commands, and then start the recording
6540with the @kbd{record @var{method}} command.
6541
a2311334
EZ
6542@cindex displaced stepping, and process record and replay
6543Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
6544will be automatically disabled when process record and replay target
6545is started. That's because the process record and replay target
6546doesn't support displaced stepping.
6547
6548@cindex non-stop mode, and process record and replay
6549@cindex asynchronous execution, and process record and replay
6550If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
59ea5688
MM
6551the asynchronous execution mode (@pxref{Background Execution}), not
6552all recording methods are available. The @code{full} recording method
6553does not support these two modes.
53cc454a
HZ
6554
6555@kindex record stop
6556@kindex rec s
6557@item record stop
a2311334
EZ
6558Stop the process record and replay target. When process record and
6559replay target stops, the entire execution log will be deleted and the
6560inferior will either be terminated, or will remain in its final state.
53cc454a 6561
a2311334
EZ
6562When you stop the process record and replay target in record mode (at
6563the end of the execution log), the inferior will be stopped at the
6564next instruction that would have been recorded. In other words, if
6565you record for a while and then stop recording, the inferior process
6566will be left in the same state as if the recording never happened.
53cc454a 6567
a2311334
EZ
6568On the other hand, if the process record and replay target is stopped
6569while in replay mode (that is, not at the end of the execution log,
6570but at some earlier point), the inferior process will become ``live''
6571at that earlier state, and it will then be possible to continue the
6572usual ``live'' debugging of the process from that state.
53cc454a 6573
a2311334
EZ
6574When the inferior process exits, or @value{GDBN} detaches from it,
6575process record and replay target will automatically stop itself.
53cc454a 6576
742ce053
MM
6577@kindex record goto
6578@item record goto
6579Go to a specific location in the execution log. There are several
6580ways to specify the location to go to:
6581
6582@table @code
6583@item record goto begin
6584@itemx record goto start
6585Go to the beginning of the execution log.
6586
6587@item record goto end
6588Go to the end of the execution log.
6589
6590@item record goto @var{n}
6591Go to instruction number @var{n} in the execution log.
6592@end table
6593
24e933df
HZ
6594@kindex record save
6595@item record save @var{filename}
6596Save the execution log to a file @file{@var{filename}}.
6597Default filename is @file{gdb_record.@var{process_id}}, where
6598@var{process_id} is the process ID of the inferior.
6599
59ea5688
MM
6600This command may not be available for all recording methods.
6601
24e933df
HZ
6602@kindex record restore
6603@item record restore @var{filename}
6604Restore the execution log from a file @file{@var{filename}}.
6605File must have been created with @code{record save}.
6606
59ea5688
MM
6607@kindex set record full
6608@item set record full insn-number-max @var{limit}
f81d1120 6609@itemx set record full insn-number-max unlimited
59ea5688
MM
6610Set the limit of instructions to be recorded for the @code{full}
6611recording method. Default value is 200000.
53cc454a 6612
a2311334
EZ
6613If @var{limit} is a positive number, then @value{GDBN} will start
6614deleting instructions from the log once the number of the record
6615instructions becomes greater than @var{limit}. For every new recorded
6616instruction, @value{GDBN} will delete the earliest recorded
6617instruction to keep the number of recorded instructions at the limit.
6618(Since deleting recorded instructions loses information, @value{GDBN}
6619lets you control what happens when the limit is reached, by means of
6620the @code{stop-at-limit} option, described below.)
53cc454a 6621
f81d1120
PA
6622If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
6623delete recorded instructions from the execution log. The number of
6624recorded instructions is limited only by the available memory.
53cc454a 6625
59ea5688
MM
6626@kindex show record full
6627@item show record full insn-number-max
6628Show the limit of instructions to be recorded with the @code{full}
6629recording method.
53cc454a 6630
59ea5688
MM
6631@item set record full stop-at-limit
6632Control the behavior of the @code{full} recording method when the
6633number of recorded instructions reaches the limit. If ON (the
6634default), @value{GDBN} will stop when the limit is reached for the
6635first time and ask you whether you want to stop the inferior or
6636continue running it and recording the execution log. If you decide
6637to continue recording, each new recorded instruction will cause the
6638oldest one to be deleted.
53cc454a 6639
a2311334
EZ
6640If this option is OFF, @value{GDBN} will automatically delete the
6641oldest record to make room for each new one, without asking.
53cc454a 6642
59ea5688 6643@item show record full stop-at-limit
a2311334 6644Show the current setting of @code{stop-at-limit}.
53cc454a 6645
59ea5688 6646@item set record full memory-query
bb08c432 6647Control the behavior when @value{GDBN} is unable to record memory
59ea5688
MM
6648changes caused by an instruction for the @code{full} recording method.
6649If ON, @value{GDBN} will query whether to stop the inferior in that
6650case.
bb08c432
HZ
6651
6652If this option is OFF (the default), @value{GDBN} will automatically
6653ignore the effect of such instructions on memory. Later, when
6654@value{GDBN} replays this execution log, it will mark the log of this
6655instruction as not accessible, and it will not affect the replay
6656results.
6657
59ea5688 6658@item show record full memory-query
bb08c432
HZ
6659Show the current setting of @code{memory-query}.
6660
67b5c0c1
MM
6661@kindex set record btrace
6662The @code{btrace} record target does not trace data. As a
6663convenience, when replaying, @value{GDBN} reads read-only memory off
6664the live program directly, assuming that the addresses of the
6665read-only areas don't change. This for example makes it possible to
6666disassemble code while replaying, but not to print variables.
6667In some cases, being able to inspect variables might be useful.
6668You can use the following command for that:
6669
6670@item set record btrace replay-memory-access
6671Control the behavior of the @code{btrace} recording method when
6672accessing memory during replay. If @code{read-only} (the default),
6673@value{GDBN} will only allow accesses to read-only memory.
6674If @code{read-write}, @value{GDBN} will allow accesses to read-only
6675and to read-write memory. Beware that the accessed memory corresponds
6676to the live target and not necessarily to the current replay
6677position.
6678
6679@kindex show record btrace
6680@item show record btrace replay-memory-access
6681Show the current setting of @code{replay-memory-access}.
6682
d33501a5
MM
6683@kindex set record btrace bts
6684@item set record btrace bts buffer-size @var{size}
6685@itemx set record btrace bts buffer-size unlimited
6686Set the requested ring buffer size for branch tracing in @acronym{BTS}
6687format. Default is 64KB.
6688
6689If @var{size} is a positive number, then @value{GDBN} will try to
6690allocate a buffer of at least @var{size} bytes for each new thread
6691that uses the btrace recording method and the @acronym{BTS} format.
6692The actually obtained buffer size may differ from the requested
6693@var{size}. Use the @code{info record} command to see the actual
6694buffer size for each thread that uses the btrace recording method and
6695the @acronym{BTS} format.
6696
6697If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
6698allocate a buffer of 4MB.
6699
6700Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
6701also need longer to process the branch trace data before it can be used.
6702
6703@item show record btrace bts buffer-size @var{size}
6704Show the current setting of the requested ring buffer size for branch
6705tracing in @acronym{BTS} format.
6706
b20a6524
MM
6707@kindex set record btrace pt
6708@item set record btrace pt buffer-size @var{size}
6709@itemx set record btrace pt buffer-size unlimited
bc504a31 6710Set the requested ring buffer size for branch tracing in Intel
b20a6524
MM
6711Processor Trace format. Default is 16KB.
6712
6713If @var{size} is a positive number, then @value{GDBN} will try to
6714allocate a buffer of at least @var{size} bytes for each new thread
bc504a31 6715that uses the btrace recording method and the Intel Processor Trace
b20a6524
MM
6716format. The actually obtained buffer size may differ from the
6717requested @var{size}. Use the @code{info record} command to see the
6718actual buffer size for each thread.
6719
6720If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
6721allocate a buffer of 4MB.
6722
6723Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
6724also need longer to process the branch trace data before it can be used.
6725
6726@item show record btrace pt buffer-size @var{size}
6727Show the current setting of the requested ring buffer size for branch
bc504a31 6728tracing in Intel Processor Trace format.
b20a6524 6729
29153c24
MS
6730@kindex info record
6731@item info record
59ea5688
MM
6732Show various statistics about the recording depending on the recording
6733method:
6734
6735@table @code
6736@item full
6737For the @code{full} recording method, it shows the state of process
6738record and its in-memory execution log buffer, including:
29153c24
MS
6739
6740@itemize @bullet
6741@item
6742Whether in record mode or replay mode.
6743@item
6744Lowest recorded instruction number (counting from when the current execution log started recording instructions).
6745@item
6746Highest recorded instruction number.
6747@item
6748Current instruction about to be replayed (if in replay mode).
6749@item
6750Number of instructions contained in the execution log.
6751@item
6752Maximum number of instructions that may be contained in the execution log.
6753@end itemize
53cc454a 6754
59ea5688 6755@item btrace
d33501a5
MM
6756For the @code{btrace} recording method, it shows:
6757
6758@itemize @bullet
6759@item
6760Recording format.
6761@item
6762Number of instructions that have been recorded.
6763@item
6764Number of blocks of sequential control-flow formed by the recorded
6765instructions.
6766@item
6767Whether in record mode or replay mode.
6768@end itemize
6769
6770For the @code{bts} recording format, it also shows:
6771@itemize @bullet
6772@item
6773Size of the perf ring buffer.
6774@end itemize
b20a6524
MM
6775
6776For the @code{pt} recording format, it also shows:
6777@itemize @bullet
6778@item
6779Size of the perf ring buffer.
6780@end itemize
59ea5688
MM
6781@end table
6782
53cc454a
HZ
6783@kindex record delete
6784@kindex rec del
6785@item record delete
a2311334 6786When record target runs in replay mode (``in the past''), delete the
53cc454a 6787subsequent execution log and begin to record a new execution log starting
a2311334 6788from the current address. This means you will abandon the previously
53cc454a 6789recorded ``future'' and begin recording a new ``future''.
59ea5688
MM
6790
6791@kindex record instruction-history
6792@kindex rec instruction-history
6793@item record instruction-history
6794Disassembles instructions from the recorded execution log. By
6795default, ten instructions are disassembled. This can be changed using
6796the @code{set record instruction-history-size} command. Instructions
da8c46d2
MM
6797are printed in execution order.
6798
0c532a29
MM
6799It can also print mixed source+disassembly if you specify the the
6800@code{/m} or @code{/s} modifier, and print the raw instructions in hex
6801as well as in symbolic form by specifying the @code{/r} modifier.
6802
6803The current position marker is printed for the instruction at the
6804current program counter value. This instruction can appear multiple
6805times in the trace and the current position marker will be printed
6806every time. To omit the current position marker, specify the
6807@code{/p} modifier.
6808
6809To better align the printed instructions when the trace contains
6810instructions from more than one function, the function name may be
6811omitted by specifying the @code{/f} modifier.
6812
da8c46d2
MM
6813Speculatively executed instructions are prefixed with @samp{?}. This
6814feature is not available for all recording formats.
6815
6816There are several ways to specify what part of the execution log to
6817disassemble:
59ea5688
MM
6818
6819@table @code
6820@item record instruction-history @var{insn}
6821Disassembles ten instructions starting from instruction number
6822@var{insn}.
6823
6824@item record instruction-history @var{insn}, +/-@var{n}
6825Disassembles @var{n} instructions around instruction number
6826@var{insn}. If @var{n} is preceded with @code{+}, disassembles
6827@var{n} instructions after instruction number @var{insn}. If
6828@var{n} is preceded with @code{-}, disassembles @var{n}
6829instructions before instruction number @var{insn}.
6830
6831@item record instruction-history
6832Disassembles ten more instructions after the last disassembly.
6833
6834@item record instruction-history -
6835Disassembles ten more instructions before the last disassembly.
6836
792005b0 6837@item record instruction-history @var{begin}, @var{end}
59ea5688
MM
6838Disassembles instructions beginning with instruction number
6839@var{begin} until instruction number @var{end}. The instruction
0688d04e 6840number @var{end} is included.
59ea5688
MM
6841@end table
6842
6843This command may not be available for all recording methods.
6844
6845@kindex set record
f81d1120
PA
6846@item set record instruction-history-size @var{size}
6847@itemx set record instruction-history-size unlimited
59ea5688
MM
6848Define how many instructions to disassemble in the @code{record
6849instruction-history} command. The default value is 10.
f81d1120 6850A @var{size} of @code{unlimited} means unlimited instructions.
59ea5688
MM
6851
6852@kindex show record
6853@item show record instruction-history-size
6854Show how many instructions to disassemble in the @code{record
6855instruction-history} command.
6856
6857@kindex record function-call-history
6858@kindex rec function-call-history
6859@item record function-call-history
6860Prints the execution history at function granularity. It prints one
6861line for each sequence of instructions that belong to the same
6862function giving the name of that function, the source lines
6863for this instruction sequence (if the @code{/l} modifier is
6864specified), and the instructions numbers that form the sequence (if
8710b709
MM
6865the @code{/i} modifier is specified). The function names are indented
6866to reflect the call stack depth if the @code{/c} modifier is
6867specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be
6868given together.
59ea5688
MM
6869
6870@smallexample
6871(@value{GDBP}) @b{list 1, 10}
68721 void foo (void)
68732 @{
68743 @}
68754
68765 void bar (void)
68776 @{
68787 ...
68798 foo ();
68809 ...
688110 @}
8710b709
MM
6882(@value{GDBP}) @b{record function-call-history /ilc}
68831 bar inst 1,4 at foo.c:6,8
68842 foo inst 5,10 at foo.c:2,3
68853 bar inst 11,13 at foo.c:9,10
59ea5688
MM
6886@end smallexample
6887
6888By default, ten lines are printed. This can be changed using the
6889@code{set record function-call-history-size} command. Functions are
6890printed in execution order. There are several ways to specify what
6891to print:
6892
6893@table @code
6894@item record function-call-history @var{func}
6895Prints ten functions starting from function number @var{func}.
6896
6897@item record function-call-history @var{func}, +/-@var{n}
6898Prints @var{n} functions around function number @var{func}. If
6899@var{n} is preceded with @code{+}, prints @var{n} functions after
6900function number @var{func}. If @var{n} is preceded with @code{-},
6901prints @var{n} functions before function number @var{func}.
6902
6903@item record function-call-history
6904Prints ten more functions after the last ten-line print.
6905
6906@item record function-call-history -
6907Prints ten more functions before the last ten-line print.
6908
792005b0 6909@item record function-call-history @var{begin}, @var{end}
59ea5688 6910Prints functions beginning with function number @var{begin} until
0688d04e 6911function number @var{end}. The function number @var{end} is included.
59ea5688
MM
6912@end table
6913
6914This command may not be available for all recording methods.
6915
f81d1120
PA
6916@item set record function-call-history-size @var{size}
6917@itemx set record function-call-history-size unlimited
59ea5688
MM
6918Define how many lines to print in the
6919@code{record function-call-history} command. The default value is 10.
f81d1120 6920A size of @code{unlimited} means unlimited lines.
59ea5688
MM
6921
6922@item show record function-call-history-size
6923Show how many lines to print in the
6924@code{record function-call-history} command.
53cc454a
HZ
6925@end table
6926
6927
6d2ebf8b 6928@node Stack
c906108c
SS
6929@chapter Examining the Stack
6930
6931When your program has stopped, the first thing you need to know is where it
6932stopped and how it got there.
6933
6934@cindex call stack
5d161b24
DB
6935Each time your program performs a function call, information about the call
6936is generated.
6937That information includes the location of the call in your program,
6938the arguments of the call,
c906108c 6939and the local variables of the function being called.
5d161b24 6940The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
6941The stack frames are allocated in a region of memory called the @dfn{call
6942stack}.
6943
6944When your program stops, the @value{GDBN} commands for examining the
6945stack allow you to see all of this information.
6946
6947@cindex selected frame
6948One of the stack frames is @dfn{selected} by @value{GDBN} and many
6949@value{GDBN} commands refer implicitly to the selected frame. In
6950particular, whenever you ask @value{GDBN} for the value of a variable in
6951your program, the value is found in the selected frame. There are
6952special @value{GDBN} commands to select whichever frame you are
79a6e687 6953interested in. @xref{Selection, ,Selecting a Frame}.
c906108c
SS
6954
6955When your program stops, @value{GDBN} automatically selects the
5d161b24 6956currently executing frame and describes it briefly, similar to the
79a6e687 6957@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
c906108c
SS
6958
6959@menu
6960* Frames:: Stack frames
6961* Backtrace:: Backtraces
6962* Selection:: Selecting a frame
6963* Frame Info:: Information on a frame
0f59c28f 6964* Frame Filter Management:: Managing frame filters
c906108c
SS
6965
6966@end menu
6967
6d2ebf8b 6968@node Frames
79a6e687 6969@section Stack Frames
c906108c 6970
d4f3574e 6971@cindex frame, definition
c906108c
SS
6972@cindex stack frame
6973The call stack is divided up into contiguous pieces called @dfn{stack
6974frames}, or @dfn{frames} for short; each frame is the data associated
6975with one call to one function. The frame contains the arguments given
6976to the function, the function's local variables, and the address at
6977which the function is executing.
6978
6979@cindex initial frame
6980@cindex outermost frame
6981@cindex innermost frame
6982When your program is started, the stack has only one frame, that of the
6983function @code{main}. This is called the @dfn{initial} frame or the
6984@dfn{outermost} frame. Each time a function is called, a new frame is
6985made. Each time a function returns, the frame for that function invocation
6986is eliminated. If a function is recursive, there can be many frames for
6987the same function. The frame for the function in which execution is
6988actually occurring is called the @dfn{innermost} frame. This is the most
6989recently created of all the stack frames that still exist.
6990
6991@cindex frame pointer
6992Inside your program, stack frames are identified by their addresses. A
6993stack frame consists of many bytes, each of which has its own address; each
6994kind of computer has a convention for choosing one byte whose
6995address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
6996in a register called the @dfn{frame pointer register}
6997(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
6998
6999@cindex frame number
7000@value{GDBN} assigns numbers to all existing stack frames, starting with
7001zero for the innermost frame, one for the frame that called it,
7002and so on upward. These numbers do not really exist in your program;
7003they are assigned by @value{GDBN} to give you a way of designating stack
7004frames in @value{GDBN} commands.
7005
6d2ebf8b
SS
7006@c The -fomit-frame-pointer below perennially causes hbox overflow
7007@c underflow problems.
c906108c
SS
7008@cindex frameless execution
7009Some compilers provide a way to compile functions so that they operate
e22ea452 7010without stack frames. (For example, the @value{NGCC} option
474c8240 7011@smallexample
6d2ebf8b 7012@samp{-fomit-frame-pointer}
474c8240 7013@end smallexample
6d2ebf8b 7014generates functions without a frame.)
c906108c
SS
7015This is occasionally done with heavily used library functions to save
7016the frame setup time. @value{GDBN} has limited facilities for dealing
7017with these function invocations. If the innermost function invocation
7018has no stack frame, @value{GDBN} nevertheless regards it as though
7019it had a separate frame, which is numbered zero as usual, allowing
7020correct tracing of the function call chain. However, @value{GDBN} has
7021no provision for frameless functions elsewhere in the stack.
7022
6d2ebf8b 7023@node Backtrace
c906108c
SS
7024@section Backtraces
7025
09d4efe1
EZ
7026@cindex traceback
7027@cindex call stack traces
c906108c
SS
7028A backtrace is a summary of how your program got where it is. It shows one
7029line per frame, for many frames, starting with the currently executing
7030frame (frame zero), followed by its caller (frame one), and on up the
7031stack.
7032
1e611234 7033@anchor{backtrace-command}
c906108c
SS
7034@table @code
7035@kindex backtrace
41afff9a 7036@kindex bt @r{(@code{backtrace})}
c906108c
SS
7037@item backtrace
7038@itemx bt
7039Print a backtrace of the entire stack: one line per frame for all
7040frames in the stack.
7041
7042You can stop the backtrace at any time by typing the system interrupt
c8aa23ab 7043character, normally @kbd{Ctrl-c}.
c906108c
SS
7044
7045@item backtrace @var{n}
7046@itemx bt @var{n}
7047Similar, but print only the innermost @var{n} frames.
7048
7049@item backtrace -@var{n}
7050@itemx bt -@var{n}
7051Similar, but print only the outermost @var{n} frames.
0f061b69
NR
7052
7053@item backtrace full
0f061b69 7054@itemx bt full
dd74f6ae
NR
7055@itemx bt full @var{n}
7056@itemx bt full -@var{n}
697aa1b7
EZ
7057Print the values of the local variables also. As described above,
7058@var{n} specifies the number of frames to print.
1e611234
PM
7059
7060@item backtrace no-filters
7061@itemx bt no-filters
7062@itemx bt no-filters @var{n}
7063@itemx bt no-filters -@var{n}
7064@itemx bt no-filters full
7065@itemx bt no-filters full @var{n}
7066@itemx bt no-filters full -@var{n}
7067Do not run Python frame filters on this backtrace. @xref{Frame
7068Filter API}, for more information. Additionally use @ref{disable
7069frame-filter all} to turn off all frame filters. This is only
7070relevant when @value{GDBN} has been configured with @code{Python}
7071support.
c906108c
SS
7072@end table
7073
7074@kindex where
7075@kindex info stack
c906108c
SS
7076The names @code{where} and @code{info stack} (abbreviated @code{info s})
7077are additional aliases for @code{backtrace}.
7078
839c27b7
EZ
7079@cindex multiple threads, backtrace
7080In a multi-threaded program, @value{GDBN} by default shows the
7081backtrace only for the current thread. To display the backtrace for
7082several or all of the threads, use the command @code{thread apply}
7083(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
7084apply all backtrace}, @value{GDBN} will display the backtrace for all
7085the threads; this is handy when you debug a core dump of a
7086multi-threaded program.
7087
c906108c
SS
7088Each line in the backtrace shows the frame number and the function name.
7089The program counter value is also shown---unless you use @code{set
7090print address off}. The backtrace also shows the source file name and
7091line number, as well as the arguments to the function. The program
7092counter value is omitted if it is at the beginning of the code for that
7093line number.
7094
7095Here is an example of a backtrace. It was made with the command
7096@samp{bt 3}, so it shows the innermost three frames.
7097
7098@smallexample
7099@group
5d161b24 7100#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c 7101 at builtin.c:993
4f5376b2 7102#1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
c906108c
SS
7103#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
7104 at macro.c:71
7105(More stack frames follow...)
7106@end group
7107@end smallexample
7108
7109@noindent
7110The display for frame zero does not begin with a program counter
7111value, indicating that your program has stopped at the beginning of the
7112code for line @code{993} of @code{builtin.c}.
7113
4f5376b2
JB
7114@noindent
7115The value of parameter @code{data} in frame 1 has been replaced by
7116@code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
7117only if it is a scalar (integer, pointer, enumeration, etc). See command
7118@kbd{set print frame-arguments} in @ref{Print Settings} for more details
7119on how to configure the way function parameter values are printed.
7120
585fdaa1 7121@cindex optimized out, in backtrace
18999be5
EZ
7122@cindex function call arguments, optimized out
7123If your program was compiled with optimizations, some compilers will
7124optimize away arguments passed to functions if those arguments are
7125never used after the call. Such optimizations generate code that
7126passes arguments through registers, but doesn't store those arguments
7127in the stack frame. @value{GDBN} has no way of displaying such
7128arguments in stack frames other than the innermost one. Here's what
7129such a backtrace might look like:
7130
7131@smallexample
7132@group
7133#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
7134 at builtin.c:993
585fdaa1
PA
7135#1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
7136#2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
18999be5
EZ
7137 at macro.c:71
7138(More stack frames follow...)
7139@end group
7140@end smallexample
7141
7142@noindent
7143The values of arguments that were not saved in their stack frames are
585fdaa1 7144shown as @samp{<optimized out>}.
18999be5
EZ
7145
7146If you need to display the values of such optimized-out arguments,
7147either deduce that from other variables whose values depend on the one
7148you are interested in, or recompile without optimizations.
7149
a8f24a35
EZ
7150@cindex backtrace beyond @code{main} function
7151@cindex program entry point
7152@cindex startup code, and backtrace
25d29d70
AC
7153Most programs have a standard user entry point---a place where system
7154libraries and startup code transition into user code. For C this is
d416eeec
EZ
7155@code{main}@footnote{
7156Note that embedded programs (the so-called ``free-standing''
7157environment) are not required to have a @code{main} function as the
7158entry point. They could even have multiple entry points.}.
7159When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
7160it will terminate the backtrace, to avoid tracing into highly
7161system-specific (and generally uninteresting) code.
7162
7163If you need to examine the startup code, or limit the number of levels
7164in a backtrace, you can change this behavior:
95f90d25
DJ
7165
7166@table @code
25d29d70
AC
7167@item set backtrace past-main
7168@itemx set backtrace past-main on
4644b6e3 7169@kindex set backtrace
25d29d70
AC
7170Backtraces will continue past the user entry point.
7171
7172@item set backtrace past-main off
95f90d25
DJ
7173Backtraces will stop when they encounter the user entry point. This is the
7174default.
7175
25d29d70 7176@item show backtrace past-main
4644b6e3 7177@kindex show backtrace
25d29d70
AC
7178Display the current user entry point backtrace policy.
7179
2315ffec
RC
7180@item set backtrace past-entry
7181@itemx set backtrace past-entry on
a8f24a35 7182Backtraces will continue past the internal entry point of an application.
2315ffec
RC
7183This entry point is encoded by the linker when the application is built,
7184and is likely before the user entry point @code{main} (or equivalent) is called.
7185
7186@item set backtrace past-entry off
d3e8051b 7187Backtraces will stop when they encounter the internal entry point of an
2315ffec
RC
7188application. This is the default.
7189
7190@item show backtrace past-entry
7191Display the current internal entry point backtrace policy.
7192
25d29d70
AC
7193@item set backtrace limit @var{n}
7194@itemx set backtrace limit 0
f81d1120 7195@itemx set backtrace limit unlimited
25d29d70 7196@cindex backtrace limit
f81d1120
PA
7197Limit the backtrace to @var{n} levels. A value of @code{unlimited}
7198or zero means unlimited levels.
95f90d25 7199
25d29d70
AC
7200@item show backtrace limit
7201Display the current limit on backtrace levels.
95f90d25
DJ
7202@end table
7203
1b56eb55
JK
7204You can control how file names are displayed.
7205
7206@table @code
7207@item set filename-display
7208@itemx set filename-display relative
7209@cindex filename-display
7210Display file names relative to the compilation directory. This is the default.
7211
7212@item set filename-display basename
7213Display only basename of a filename.
7214
7215@item set filename-display absolute
7216Display an absolute filename.
7217
7218@item show filename-display
7219Show the current way to display filenames.
7220@end table
7221
6d2ebf8b 7222@node Selection
79a6e687 7223@section Selecting a Frame
c906108c
SS
7224
7225Most commands for examining the stack and other data in your program work on
7226whichever stack frame is selected at the moment. Here are the commands for
7227selecting a stack frame; all of them finish by printing a brief description
7228of the stack frame just selected.
7229
7230@table @code
d4f3574e 7231@kindex frame@r{, selecting}
41afff9a 7232@kindex f @r{(@code{frame})}
c906108c
SS
7233@item frame @var{n}
7234@itemx f @var{n}
7235Select frame number @var{n}. Recall that frame zero is the innermost
7236(currently executing) frame, frame one is the frame that called the
7237innermost one, and so on. The highest-numbered frame is the one for
7238@code{main}.
7239
7c7f93f6
AB
7240@item frame @var{stack-addr} [ @var{pc-addr} ]
7241@itemx f @var{stack-addr} [ @var{pc-addr} ]
7242Select the frame at address @var{stack-addr}. This is useful mainly if the
c906108c
SS
7243chaining of stack frames has been damaged by a bug, making it
7244impossible for @value{GDBN} to assign numbers properly to all frames. In
7245addition, this can be useful when your program has multiple stacks and
7c7f93f6
AB
7246switches between them. The optional @var{pc-addr} can also be given to
7247specify the value of PC for the stack frame.
c906108c
SS
7248
7249@kindex up
7250@item up @var{n}
697aa1b7
EZ
7251Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
7252numbers @var{n}, this advances toward the outermost frame, to higher
7253frame numbers, to frames that have existed longer.
c906108c
SS
7254
7255@kindex down
41afff9a 7256@kindex do @r{(@code{down})}
c906108c 7257@item down @var{n}
697aa1b7
EZ
7258Move @var{n} frames down the stack; @var{n} defaults to 1. For
7259positive numbers @var{n}, this advances toward the innermost frame, to
7260lower frame numbers, to frames that were created more recently.
7261You may abbreviate @code{down} as @code{do}.
c906108c
SS
7262@end table
7263
7264All of these commands end by printing two lines of output describing the
7265frame. The first line shows the frame number, the function name, the
7266arguments, and the source file and line number of execution in that
5d161b24 7267frame. The second line shows the text of that source line.
c906108c
SS
7268
7269@need 1000
7270For example:
7271
7272@smallexample
7273@group
7274(@value{GDBP}) up
7275#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
7276 at env.c:10
727710 read_input_file (argv[i]);
7278@end group
7279@end smallexample
7280
7281After such a printout, the @code{list} command with no arguments
7282prints ten lines centered on the point of execution in the frame.
87885426
FN
7283You can also edit the program at the point of execution with your favorite
7284editing program by typing @code{edit}.
79a6e687 7285@xref{List, ,Printing Source Lines},
87885426 7286for details.
c906108c
SS
7287
7288@table @code
fc58fa65
AB
7289@kindex select-frame
7290@item select-frame
7291The @code{select-frame} command is a variant of @code{frame} that does
7292not display the new frame after selecting it. This command is
7293intended primarily for use in @value{GDBN} command scripts, where the
7294output might be unnecessary and distracting.
7295
c906108c
SS
7296@kindex down-silently
7297@kindex up-silently
7298@item up-silently @var{n}
7299@itemx down-silently @var{n}
7300These two commands are variants of @code{up} and @code{down},
7301respectively; they differ in that they do their work silently, without
7302causing display of the new frame. They are intended primarily for use
7303in @value{GDBN} command scripts, where the output might be unnecessary and
7304distracting.
7305@end table
7306
6d2ebf8b 7307@node Frame Info
79a6e687 7308@section Information About a Frame
c906108c
SS
7309
7310There are several other commands to print information about the selected
7311stack frame.
7312
7313@table @code
7314@item frame
7315@itemx f
7316When used without any argument, this command does not change which
7317frame is selected, but prints a brief description of the currently
7318selected stack frame. It can be abbreviated @code{f}. With an
7319argument, this command is used to select a stack frame.
79a6e687 7320@xref{Selection, ,Selecting a Frame}.
c906108c
SS
7321
7322@kindex info frame
41afff9a 7323@kindex info f @r{(@code{info frame})}
c906108c
SS
7324@item info frame
7325@itemx info f
7326This command prints a verbose description of the selected stack frame,
7327including:
7328
7329@itemize @bullet
5d161b24
DB
7330@item
7331the address of the frame
c906108c
SS
7332@item
7333the address of the next frame down (called by this frame)
7334@item
7335the address of the next frame up (caller of this frame)
7336@item
7337the language in which the source code corresponding to this frame is written
7338@item
7339the address of the frame's arguments
7340@item
d4f3574e
SS
7341the address of the frame's local variables
7342@item
c906108c
SS
7343the program counter saved in it (the address of execution in the caller frame)
7344@item
7345which registers were saved in the frame
7346@end itemize
7347
7348@noindent The verbose description is useful when
7349something has gone wrong that has made the stack format fail to fit
7350the usual conventions.
7351
7352@item info frame @var{addr}
7353@itemx info f @var{addr}
7354Print a verbose description of the frame at address @var{addr}, without
7355selecting that frame. The selected frame remains unchanged by this
7356command. This requires the same kind of address (more than one for some
7357architectures) that you specify in the @code{frame} command.
79a6e687 7358@xref{Selection, ,Selecting a Frame}.
c906108c
SS
7359
7360@kindex info args
7361@item info args
7362Print the arguments of the selected frame, each on a separate line.
7363
7364@item info locals
7365@kindex info locals
7366Print the local variables of the selected frame, each on a separate
7367line. These are all variables (declared either static or automatic)
7368accessible at the point of execution of the selected frame.
7369
c906108c
SS
7370@end table
7371
fc58fa65
AB
7372@node Frame Filter Management
7373@section Management of Frame Filters.
7374@cindex managing frame filters
7375
7376Frame filters are Python based utilities to manage and decorate the
7377output of frames. @xref{Frame Filter API}, for further information.
7378
7379Managing frame filters is performed by several commands available
7380within @value{GDBN}, detailed here.
7381
7382@table @code
7383@kindex info frame-filter
7384@item info frame-filter
7385Print a list of installed frame filters from all dictionaries, showing
7386their name, priority and enabled status.
7387
7388@kindex disable frame-filter
7389@anchor{disable frame-filter all}
7390@item disable frame-filter @var{filter-dictionary} @var{filter-name}
7391Disable a frame filter in the dictionary matching
7392@var{filter-dictionary} and @var{filter-name}. The
7393@var{filter-dictionary} may be @code{all}, @code{global},
7394@code{progspace}, or the name of the object file where the frame filter
7395dictionary resides. When @code{all} is specified, all frame filters
7396across all dictionaries are disabled. The @var{filter-name} is the name
7397of the frame filter and is used when @code{all} is not the option for
7398@var{filter-dictionary}. A disabled frame-filter is not deleted, it
7399may be enabled again later.
7400
7401@kindex enable frame-filter
7402@item enable frame-filter @var{filter-dictionary} @var{filter-name}
7403Enable a frame filter in the dictionary matching
7404@var{filter-dictionary} and @var{filter-name}. The
7405@var{filter-dictionary} may be @code{all}, @code{global},
7406@code{progspace} or the name of the object file where the frame filter
7407dictionary resides. When @code{all} is specified, all frame filters across
7408all dictionaries are enabled. The @var{filter-name} is the name of the frame
7409filter and is used when @code{all} is not the option for
7410@var{filter-dictionary}.
7411
7412Example:
7413
7414@smallexample
7415(gdb) info frame-filter
7416
7417global frame-filters:
7418 Priority Enabled Name
7419 1000 No PrimaryFunctionFilter
7420 100 Yes Reverse
7421
7422progspace /build/test frame-filters:
7423 Priority Enabled Name
7424 100 Yes ProgspaceFilter
7425
7426objfile /build/test frame-filters:
7427 Priority Enabled Name
7428 999 Yes BuildProgra Filter
7429
7430(gdb) disable frame-filter /build/test BuildProgramFilter
7431(gdb) info frame-filter
7432
7433global frame-filters:
7434 Priority Enabled Name
7435 1000 No PrimaryFunctionFilter
7436 100 Yes Reverse
7437
7438progspace /build/test frame-filters:
7439 Priority Enabled Name
7440 100 Yes ProgspaceFilter
7441
7442objfile /build/test frame-filters:
7443 Priority Enabled Name
7444 999 No BuildProgramFilter
7445
7446(gdb) enable frame-filter global PrimaryFunctionFilter
7447(gdb) info frame-filter
7448
7449global frame-filters:
7450 Priority Enabled Name
7451 1000 Yes PrimaryFunctionFilter
7452 100 Yes Reverse
7453
7454progspace /build/test frame-filters:
7455 Priority Enabled Name
7456 100 Yes ProgspaceFilter
7457
7458objfile /build/test frame-filters:
7459 Priority Enabled Name
7460 999 No BuildProgramFilter
7461@end smallexample
7462
7463@kindex set frame-filter priority
7464@item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
7465Set the @var{priority} of a frame filter in the dictionary matching
7466@var{filter-dictionary}, and the frame filter name matching
7467@var{filter-name}. The @var{filter-dictionary} may be @code{global},
7468@code{progspace} or the name of the object file where the frame filter
7469dictionary resides. The @var{priority} is an integer.
7470
7471@kindex show frame-filter priority
7472@item show frame-filter priority @var{filter-dictionary} @var{filter-name}
7473Show the @var{priority} of a frame filter in the dictionary matching
7474@var{filter-dictionary}, and the frame filter name matching
7475@var{filter-name}. The @var{filter-dictionary} may be @code{global},
7476@code{progspace} or the name of the object file where the frame filter
7477dictionary resides.
7478
7479Example:
7480
7481@smallexample
7482(gdb) info frame-filter
7483
7484global frame-filters:
7485 Priority Enabled Name
7486 1000 Yes PrimaryFunctionFilter
7487 100 Yes Reverse
7488
7489progspace /build/test frame-filters:
7490 Priority Enabled Name
7491 100 Yes ProgspaceFilter
7492
7493objfile /build/test frame-filters:
7494 Priority Enabled Name
7495 999 No BuildProgramFilter
7496
7497(gdb) set frame-filter priority global Reverse 50
7498(gdb) info frame-filter
7499
7500global frame-filters:
7501 Priority Enabled Name
7502 1000 Yes PrimaryFunctionFilter
7503 50 Yes Reverse
7504
7505progspace /build/test frame-filters:
7506 Priority Enabled Name
7507 100 Yes ProgspaceFilter
7508
7509objfile /build/test frame-filters:
7510 Priority Enabled Name
7511 999 No BuildProgramFilter
7512@end smallexample
7513@end table
c906108c 7514
6d2ebf8b 7515@node Source
c906108c
SS
7516@chapter Examining Source Files
7517
7518@value{GDBN} can print parts of your program's source, since the debugging
7519information recorded in the program tells @value{GDBN} what source files were
7520used to build it. When your program stops, @value{GDBN} spontaneously prints
7521the line where it stopped. Likewise, when you select a stack frame
79a6e687 7522(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
c906108c
SS
7523execution in that frame has stopped. You can print other portions of
7524source files by explicit command.
7525
7a292a7a 7526If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 7527prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 7528@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
7529
7530@menu
7531* List:: Printing source lines
2a25a5ba 7532* Specify Location:: How to specify code locations
87885426 7533* Edit:: Editing source files
c906108c 7534* Search:: Searching source files
c906108c
SS
7535* Source Path:: Specifying source directories
7536* Machine Code:: Source and machine code
7537@end menu
7538
6d2ebf8b 7539@node List
79a6e687 7540@section Printing Source Lines
c906108c
SS
7541
7542@kindex list
41afff9a 7543@kindex l @r{(@code{list})}
c906108c 7544To print lines from a source file, use the @code{list} command
5d161b24 7545(abbreviated @code{l}). By default, ten lines are printed.
2a25a5ba
EZ
7546There are several ways to specify what part of the file you want to
7547print; see @ref{Specify Location}, for the full list.
c906108c
SS
7548
7549Here are the forms of the @code{list} command most commonly used:
7550
7551@table @code
7552@item list @var{linenum}
7553Print lines centered around line number @var{linenum} in the
7554current source file.
7555
7556@item list @var{function}
7557Print lines centered around the beginning of function
7558@var{function}.
7559
7560@item list
7561Print more lines. If the last lines printed were printed with a
7562@code{list} command, this prints lines following the last lines
7563printed; however, if the last line printed was a solitary line printed
7564as part of displaying a stack frame (@pxref{Stack, ,Examining the
7565Stack}), this prints lines centered around that line.
7566
7567@item list -
7568Print lines just before the lines last printed.
7569@end table
7570
9c16f35a 7571@cindex @code{list}, how many lines to display
c906108c
SS
7572By default, @value{GDBN} prints ten source lines with any of these forms of
7573the @code{list} command. You can change this using @code{set listsize}:
7574
7575@table @code
7576@kindex set listsize
7577@item set listsize @var{count}
f81d1120 7578@itemx set listsize unlimited
c906108c
SS
7579Make the @code{list} command display @var{count} source lines (unless
7580the @code{list} argument explicitly specifies some other number).
f81d1120 7581Setting @var{count} to @code{unlimited} or 0 means there's no limit.
c906108c
SS
7582
7583@kindex show listsize
7584@item show listsize
7585Display the number of lines that @code{list} prints.
7586@end table
7587
7588Repeating a @code{list} command with @key{RET} discards the argument,
7589so it is equivalent to typing just @code{list}. This is more useful
7590than listing the same lines again. An exception is made for an
7591argument of @samp{-}; that argument is preserved in repetition so that
7592each repetition moves up in the source file.
7593
c906108c 7594In general, the @code{list} command expects you to supply zero, one or two
629500fa 7595@dfn{locations}. Locations specify source lines; there are several ways
2a25a5ba
EZ
7596of writing them (@pxref{Specify Location}), but the effect is always
7597to specify some source line.
7598
c906108c
SS
7599Here is a complete description of the possible arguments for @code{list}:
7600
7601@table @code
629500fa
KS
7602@item list @var{location}
7603Print lines centered around the line specified by @var{location}.
c906108c
SS
7604
7605@item list @var{first},@var{last}
7606Print lines from @var{first} to @var{last}. Both arguments are
629500fa
KS
7607locations. When a @code{list} command has two locations, and the
7608source file of the second location is omitted, this refers to
7609the same source file as the first location.
c906108c
SS
7610
7611@item list ,@var{last}
7612Print lines ending with @var{last}.
7613
7614@item list @var{first},
7615Print lines starting with @var{first}.
7616
7617@item list +
7618Print lines just after the lines last printed.
7619
7620@item list -
7621Print lines just before the lines last printed.
7622
7623@item list
7624As described in the preceding table.
7625@end table
7626
2a25a5ba
EZ
7627@node Specify Location
7628@section Specifying a Location
7629@cindex specifying location
629500fa
KS
7630@cindex location
7631@cindex source location
7632
7633@menu
7634* Linespec Locations:: Linespec locations
7635* Explicit Locations:: Explicit locations
7636* Address Locations:: Address locations
7637@end menu
c906108c 7638
2a25a5ba
EZ
7639Several @value{GDBN} commands accept arguments that specify a location
7640of your program's code. Since @value{GDBN} is a source-level
629500fa
KS
7641debugger, a location usually specifies some line in the source code.
7642Locations may be specified using three different formats:
7643linespec locations, explicit locations, or address locations.
c906108c 7644
629500fa
KS
7645@node Linespec Locations
7646@subsection Linespec Locations
7647@cindex linespec locations
7648
7649A @dfn{linespec} is a colon-separated list of source location parameters such
7650as file name, function name, etc. Here are all the different ways of
7651specifying a linespec:
c906108c 7652
2a25a5ba
EZ
7653@table @code
7654@item @var{linenum}
7655Specifies the line number @var{linenum} of the current source file.
c906108c 7656
2a25a5ba
EZ
7657@item -@var{offset}
7658@itemx +@var{offset}
7659Specifies the line @var{offset} lines before or after the @dfn{current
7660line}. For the @code{list} command, the current line is the last one
7661printed; for the breakpoint commands, this is the line at which
7662execution stopped in the currently selected @dfn{stack frame}
7663(@pxref{Frames, ,Frames}, for a description of stack frames.) When
7664used as the second of the two linespecs in a @code{list} command,
7665this specifies the line @var{offset} lines up or down from the first
7666linespec.
7667
7668@item @var{filename}:@var{linenum}
7669Specifies the line @var{linenum} in the source file @var{filename}.
4aac40c8
TT
7670If @var{filename} is a relative file name, then it will match any
7671source file name with the same trailing components. For example, if
7672@var{filename} is @samp{gcc/expr.c}, then it will match source file
7673name of @file{/build/trunk/gcc/expr.c}, but not
7674@file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
c906108c
SS
7675
7676@item @var{function}
7677Specifies the line that begins the body of the function @var{function}.
2a25a5ba 7678For example, in C, this is the line with the open brace.
c906108c 7679
9ef07c8c
TT
7680@item @var{function}:@var{label}
7681Specifies the line where @var{label} appears in @var{function}.
7682
c906108c 7683@item @var{filename}:@var{function}
2a25a5ba
EZ
7684Specifies the line that begins the body of the function @var{function}
7685in the file @var{filename}. You only need the file name with a
7686function name to avoid ambiguity when there are identically named
7687functions in different source files.
c906108c 7688
0f5238ed 7689@item @var{label}
629500fa
KS
7690Specifies the line at which the label named @var{label} appears
7691in the function corresponding to the currently selected stack frame.
7692If there is no current selected stack frame (for instance, if the inferior
7693is not running), then @value{GDBN} will not search for a label.
7694
7695@cindex breakpoint at static probe point
7696@item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
7697The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
7698applications to embed static probes. @xref{Static Probe Points}, for more
7699information on finding and using static probes. This form of linespec
7700specifies the location of such a static probe.
7701
7702If @var{objfile} is given, only probes coming from that shared library
7703or executable matching @var{objfile} as a regular expression are considered.
7704If @var{provider} is given, then only probes from that provider are considered.
7705If several probes match the spec, @value{GDBN} will insert a breakpoint at
7706each one of those probes.
7707@end table
7708
7709@node Explicit Locations
7710@subsection Explicit Locations
7711@cindex explicit locations
7712
7713@dfn{Explicit locations} allow the user to directly specify the source
7714location's parameters using option-value pairs.
7715
7716Explicit locations are useful when several functions, labels, or
7717file names have the same name (base name for files) in the program's
7718sources. In these cases, explicit locations point to the source
7719line you meant more accurately and unambiguously. Also, using
7720explicit locations might be faster in large programs.
7721
7722For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
7723defined in the file named @file{foo} or the label @code{bar} in a function
7724named @code{foo}. @value{GDBN} must search either the file system or
7725the symbol table to know.
7726
7727The list of valid explicit location options is summarized in the
7728following table:
7729
7730@table @code
7731@item -source @var{filename}
7732The value specifies the source file name. To differentiate between
7733files with the same base name, prepend as many directories as is necessary
7734to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
7735@value{GDBN} will use the first file it finds with the given base
7736name. This option requires the use of either @code{-function} or @code{-line}.
7737
7738@item -function @var{function}
7739The value specifies the name of a function. Operations
7740on function locations unmodified by other options (such as @code{-label}
7741or @code{-line}) refer to the line that begins the body of the function.
7742In C, for example, this is the line with the open brace.
7743
7744@item -label @var{label}
7745The value specifies the name of a label. When the function
7746name is not specified, the label is searched in the function of the currently
7747selected stack frame.
7748
7749@item -line @var{number}
7750The value specifies a line offset for the location. The offset may either
7751be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
7752the command. When specified without any other options, the line offset is
7753relative to the current line.
7754@end table
7755
7756Explicit location options may be abbreviated by omitting any non-unique
7757trailing characters from the option name, e.g., @code{break -s main.c -li 3}.
7758
7759@node Address Locations
7760@subsection Address Locations
7761@cindex address locations
7762
7763@dfn{Address locations} indicate a specific program address. They have
7764the generalized form *@var{address}.
7765
7766For line-oriented commands, such as @code{list} and @code{edit}, this
7767specifies a source line that contains @var{address}. For @code{break} and
7768other breakpoint-oriented commands, this can be used to set breakpoints in
2a25a5ba
EZ
7769parts of your program which do not have debugging information or
7770source files.
7771
7772Here @var{address} may be any expression valid in the current working
7773language (@pxref{Languages, working language}) that specifies a code
5fa54e5d 7774address. In addition, as a convenience, @value{GDBN} extends the
629500fa
KS
7775semantics of expressions used in locations to cover several situations
7776that frequently occur during debugging. Here are the various forms
5fa54e5d 7777of @var{address}:
2a25a5ba
EZ
7778
7779@table @code
7780@item @var{expression}
7781Any expression valid in the current working language.
7782
7783@item @var{funcaddr}
7784An address of a function or procedure derived from its name. In C,
7785C@t{++}, Java, Objective-C, Fortran, minimal, and assembly, this is
7786simply the function's name @var{function} (and actually a special case
7787of a valid expression). In Pascal and Modula-2, this is
7788@code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
7789(although the Pascal form also works).
7790
7791This form specifies the address of the function's first instruction,
7792before the stack frame and arguments have been set up.
7793
9a284c97 7794@item '@var{filename}':@var{funcaddr}
2a25a5ba
EZ
7795Like @var{funcaddr} above, but also specifies the name of the source
7796file explicitly. This is useful if the name of the function does not
7797specify the function unambiguously, e.g., if there are several
7798functions with identical names in different source files.
c906108c
SS
7799@end table
7800
87885426 7801@node Edit
79a6e687 7802@section Editing Source Files
87885426
FN
7803@cindex editing source files
7804
7805@kindex edit
7806@kindex e @r{(@code{edit})}
7807To edit the lines in a source file, use the @code{edit} command.
7808The editing program of your choice
7809is invoked with the current line set to
7810the active line in the program.
7811Alternatively, there are several ways to specify what part of the file you
2a25a5ba 7812want to print if you want to see other parts of the program:
87885426
FN
7813
7814@table @code
2a25a5ba
EZ
7815@item edit @var{location}
7816Edit the source file specified by @code{location}. Editing starts at
7817that @var{location}, e.g., at the specified source line of the
7818specified file. @xref{Specify Location}, for all the possible forms
7819of the @var{location} argument; here are the forms of the @code{edit}
7820command most commonly used:
87885426 7821
2a25a5ba 7822@table @code
87885426
FN
7823@item edit @var{number}
7824Edit the current source file with @var{number} as the active line number.
7825
7826@item edit @var{function}
7827Edit the file containing @var{function} at the beginning of its definition.
2a25a5ba 7828@end table
87885426 7829
87885426
FN
7830@end table
7831
79a6e687 7832@subsection Choosing your Editor
87885426
FN
7833You can customize @value{GDBN} to use any editor you want
7834@footnote{
7835The only restriction is that your editor (say @code{ex}), recognizes the
7836following command-line syntax:
10998722 7837@smallexample
87885426 7838ex +@var{number} file
10998722 7839@end smallexample
15387254
EZ
7840The optional numeric value +@var{number} specifies the number of the line in
7841the file where to start editing.}.
7842By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
7843by setting the environment variable @code{EDITOR} before using
7844@value{GDBN}. For example, to configure @value{GDBN} to use the
7845@code{vi} editor, you could use these commands with the @code{sh} shell:
7846@smallexample
87885426
FN
7847EDITOR=/usr/bin/vi
7848export EDITOR
15387254 7849gdb @dots{}
10998722 7850@end smallexample
87885426 7851or in the @code{csh} shell,
10998722 7852@smallexample
87885426 7853setenv EDITOR /usr/bin/vi
15387254 7854gdb @dots{}
10998722 7855@end smallexample
87885426 7856
6d2ebf8b 7857@node Search
79a6e687 7858@section Searching Source Files
15387254 7859@cindex searching source files
c906108c
SS
7860
7861There are two commands for searching through the current source file for a
7862regular expression.
7863
7864@table @code
7865@kindex search
7866@kindex forward-search
1e96de83 7867@kindex fo @r{(@code{forward-search})}
c906108c
SS
7868@item forward-search @var{regexp}
7869@itemx search @var{regexp}
7870The command @samp{forward-search @var{regexp}} checks each line,
7871starting with the one following the last line listed, for a match for
5d161b24 7872@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
7873synonym @samp{search @var{regexp}} or abbreviate the command name as
7874@code{fo}.
7875
09d4efe1 7876@kindex reverse-search
c906108c
SS
7877@item reverse-search @var{regexp}
7878The command @samp{reverse-search @var{regexp}} checks each line, starting
7879with the one before the last line listed and going backward, for a match
7880for @var{regexp}. It lists the line that is found. You can abbreviate
7881this command as @code{rev}.
7882@end table
c906108c 7883
6d2ebf8b 7884@node Source Path
79a6e687 7885@section Specifying Source Directories
c906108c
SS
7886
7887@cindex source path
7888@cindex directories for source files
7889Executable programs sometimes do not record the directories of the source
7890files from which they were compiled, just the names. Even when they do,
7891the directories could be moved between the compilation and your debugging
7892session. @value{GDBN} has a list of directories to search for source files;
7893this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
7894it tries all the directories in the list, in the order they are present
0b66e38c
EZ
7895in the list, until it finds a file with the desired name.
7896
7897For example, suppose an executable references the file
7898@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
7899@file{/mnt/cross}. The file is first looked up literally; if this
7900fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
7901fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
7902message is printed. @value{GDBN} does not look up the parts of the
7903source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
7904Likewise, the subdirectories of the source path are not searched: if
7905the source path is @file{/mnt/cross}, and the binary refers to
7906@file{foo.c}, @value{GDBN} would not find it under
7907@file{/mnt/cross/usr/src/foo-1.0/lib}.
7908
7909Plain file names, relative file names with leading directories, file
7910names containing dots, etc.@: are all treated as described above; for
7911instance, if the source path is @file{/mnt/cross}, and the source file
7912is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
7913@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
7914that---@file{/mnt/cross/foo.c}.
7915
7916Note that the executable search path is @emph{not} used to locate the
cd852561 7917source files.
c906108c
SS
7918
7919Whenever you reset or rearrange the source path, @value{GDBN} clears out
7920any information it has cached about where source files are found and where
7921each line is in the file.
7922
7923@kindex directory
7924@kindex dir
d4f3574e
SS
7925When you start @value{GDBN}, its source path includes only @samp{cdir}
7926and @samp{cwd}, in that order.
c906108c
SS
7927To add other directories, use the @code{directory} command.
7928
4b505b12
AS
7929The search path is used to find both program source files and @value{GDBN}
7930script files (read using the @samp{-command} option and @samp{source} command).
7931
30daae6c
JB
7932In addition to the source path, @value{GDBN} provides a set of commands
7933that manage a list of source path substitution rules. A @dfn{substitution
7934rule} specifies how to rewrite source directories stored in the program's
7935debug information in case the sources were moved to a different
7936directory between compilation and debugging. A rule is made of
7937two strings, the first specifying what needs to be rewritten in
7938the path, and the second specifying how it should be rewritten.
7939In @ref{set substitute-path}, we name these two parts @var{from} and
7940@var{to} respectively. @value{GDBN} does a simple string replacement
7941of @var{from} with @var{to} at the start of the directory part of the
7942source file name, and uses that result instead of the original file
7943name to look up the sources.
7944
7945Using the previous example, suppose the @file{foo-1.0} tree has been
7946moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
3f94c067 7947@value{GDBN} to replace @file{/usr/src} in all source path names with
30daae6c
JB
7948@file{/mnt/cross}. The first lookup will then be
7949@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
7950of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
7951substitution rule, use the @code{set substitute-path} command
7952(@pxref{set substitute-path}).
7953
7954To avoid unexpected substitution results, a rule is applied only if the
7955@var{from} part of the directory name ends at a directory separator.
7956For instance, a rule substituting @file{/usr/source} into
7957@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
7958not to @file{/usr/sourceware/foo-2.0}. And because the substitution
d3e8051b 7959is applied only at the beginning of the directory name, this rule will
30daae6c
JB
7960not be applied to @file{/root/usr/source/baz.c} either.
7961
7962In many cases, you can achieve the same result using the @code{directory}
7963command. However, @code{set substitute-path} can be more efficient in
7964the case where the sources are organized in a complex tree with multiple
7965subdirectories. With the @code{directory} command, you need to add each
7966subdirectory of your project. If you moved the entire tree while
7967preserving its internal organization, then @code{set substitute-path}
7968allows you to direct the debugger to all the sources with one single
7969command.
7970
7971@code{set substitute-path} is also more than just a shortcut command.
7972The source path is only used if the file at the original location no
7973longer exists. On the other hand, @code{set substitute-path} modifies
7974the debugger behavior to look at the rewritten location instead. So, if
7975for any reason a source file that is not relevant to your executable is
7976located at the original location, a substitution rule is the only
3f94c067 7977method available to point @value{GDBN} at the new location.
30daae6c 7978
29b0e8a2
JM
7979@cindex @samp{--with-relocated-sources}
7980@cindex default source path substitution
7981You can configure a default source path substitution rule by
7982configuring @value{GDBN} with the
7983@samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
7984should be the name of a directory under @value{GDBN}'s configured
7985prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
7986directory names in debug information under @var{dir} will be adjusted
7987automatically if the installed @value{GDBN} is moved to a new
7988location. This is useful if @value{GDBN}, libraries or executables
7989with debug information and corresponding source code are being moved
7990together.
7991
c906108c
SS
7992@table @code
7993@item directory @var{dirname} @dots{}
7994@item dir @var{dirname} @dots{}
7995Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
7996directory names may be given to this command, separated by @samp{:}
7997(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
7998part of absolute file names) or
c906108c
SS
7999whitespace. You may specify a directory that is already in the source
8000path; this moves it forward, so @value{GDBN} searches it sooner.
8001
8002@kindex cdir
8003@kindex cwd
41afff9a 8004@vindex $cdir@r{, convenience variable}
d3e8051b 8005@vindex $cwd@r{, convenience variable}
c906108c
SS
8006@cindex compilation directory
8007@cindex current directory
8008@cindex working directory
8009@cindex directory, current
8010@cindex directory, compilation
8011You can use the string @samp{$cdir} to refer to the compilation
8012directory (if one is recorded), and @samp{$cwd} to refer to the current
8013working directory. @samp{$cwd} is not the same as @samp{.}---the former
8014tracks the current working directory as it changes during your @value{GDBN}
8015session, while the latter is immediately expanded to the current
8016directory at the time you add an entry to the source path.
8017
8018@item directory
cd852561 8019Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
8020
8021@c RET-repeat for @code{directory} is explicitly disabled, but since
8022@c repeating it would be a no-op we do not say that. (thanks to RMS)
8023
99e7ae30
DE
8024@item set directories @var{path-list}
8025@kindex set directories
8026Set the source path to @var{path-list}.
8027@samp{$cdir:$cwd} are added if missing.
8028
c906108c
SS
8029@item show directories
8030@kindex show directories
8031Print the source path: show which directories it contains.
30daae6c
JB
8032
8033@anchor{set substitute-path}
8034@item set substitute-path @var{from} @var{to}
8035@kindex set substitute-path
8036Define a source path substitution rule, and add it at the end of the
8037current list of existing substitution rules. If a rule with the same
8038@var{from} was already defined, then the old rule is also deleted.
8039
8040For example, if the file @file{/foo/bar/baz.c} was moved to
8041@file{/mnt/cross/baz.c}, then the command
8042
8043@smallexample
c58b006b 8044(@value{GDBP}) set substitute-path /foo/bar /mnt/cross
30daae6c
JB
8045@end smallexample
8046
8047@noindent
c58b006b 8048will tell @value{GDBN} to replace @samp{/foo/bar} with
30daae6c
JB
8049@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
8050@file{baz.c} even though it was moved.
8051
8052In the case when more than one substitution rule have been defined,
8053the rules are evaluated one by one in the order where they have been
8054defined. The first one matching, if any, is selected to perform
8055the substitution.
8056
8057For instance, if we had entered the following commands:
8058
8059@smallexample
8060(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
8061(@value{GDBP}) set substitute-path /usr/src /mnt/src
8062@end smallexample
8063
8064@noindent
8065@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
8066@file{/mnt/include/defs.h} by using the first rule. However, it would
8067use the second rule to rewrite @file{/usr/src/lib/foo.c} into
8068@file{/mnt/src/lib/foo.c}.
8069
8070
8071@item unset substitute-path [path]
8072@kindex unset substitute-path
8073If a path is specified, search the current list of substitution rules
8074for a rule that would rewrite that path. Delete that rule if found.
8075A warning is emitted by the debugger if no rule could be found.
8076
8077If no path is specified, then all substitution rules are deleted.
8078
8079@item show substitute-path [path]
8080@kindex show substitute-path
8081If a path is specified, then print the source path substitution rule
8082which would rewrite that path, if any.
8083
8084If no path is specified, then print all existing source path substitution
8085rules.
8086
c906108c
SS
8087@end table
8088
8089If your source path is cluttered with directories that are no longer of
8090interest, @value{GDBN} may sometimes cause confusion by finding the wrong
8091versions of source. You can correct the situation as follows:
8092
8093@enumerate
8094@item
cd852561 8095Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
8096
8097@item
8098Use @code{directory} with suitable arguments to reinstall the
8099directories you want in the source path. You can add all the
8100directories in one command.
8101@end enumerate
8102
6d2ebf8b 8103@node Machine Code
79a6e687 8104@section Source and Machine Code
15387254 8105@cindex source line and its code address
c906108c
SS
8106
8107You can use the command @code{info line} to map source lines to program
8108addresses (and vice versa), and the command @code{disassemble} to display
91440f57
HZ
8109a range of addresses as machine instructions. You can use the command
8110@code{set disassemble-next-line} to set whether to disassemble next
8111source line when execution stops. When run under @sc{gnu} Emacs
d4f3574e 8112mode, the @code{info line} command causes the arrow to point to the
5d161b24 8113line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
8114well as hex.
8115
8116@table @code
8117@kindex info line
629500fa 8118@item info line @var{location}
c906108c 8119Print the starting and ending addresses of the compiled code for
629500fa 8120source line @var{location}. You can specify source lines in any of
2a25a5ba 8121the ways documented in @ref{Specify Location}.
c906108c
SS
8122@end table
8123
8124For example, we can use @code{info line} to discover the location of
8125the object code for the first line of function
8126@code{m4_changequote}:
8127
d4f3574e
SS
8128@c FIXME: I think this example should also show the addresses in
8129@c symbolic form, as they usually would be displayed.
c906108c 8130@smallexample
96a2c332 8131(@value{GDBP}) info line m4_changequote
c906108c
SS
8132Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
8133@end smallexample
8134
8135@noindent
15387254 8136@cindex code address and its source line
c906108c 8137We can also inquire (using @code{*@var{addr}} as the form for
629500fa 8138@var{location}) what source line covers a particular address:
c906108c
SS
8139@smallexample
8140(@value{GDBP}) info line *0x63ff
8141Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
8142@end smallexample
8143
8144@cindex @code{$_} and @code{info line}
15387254 8145@cindex @code{x} command, default address
41afff9a 8146@kindex x@r{(examine), and} info line
c906108c
SS
8147After @code{info line}, the default address for the @code{x} command
8148is changed to the starting address of the line, so that @samp{x/i} is
8149sufficient to begin examining the machine code (@pxref{Memory,
79a6e687 8150,Examining Memory}). Also, this address is saved as the value of the
c906108c 8151convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
79a6e687 8152Variables}).
c906108c
SS
8153
8154@table @code
8155@kindex disassemble
8156@cindex assembly instructions
8157@cindex instructions, assembly
8158@cindex machine instructions
8159@cindex listing machine instructions
8160@item disassemble
d14508fe 8161@itemx disassemble /m
6ff0ba5f 8162@itemx disassemble /s
9b117ef3 8163@itemx disassemble /r
c906108c 8164This specialized command dumps a range of memory as machine
d14508fe 8165instructions. It can also print mixed source+disassembly by specifying
6ff0ba5f
DE
8166the @code{/m} or @code{/s} modifier and print the raw instructions in hex
8167as well as in symbolic form by specifying the @code{/r} modifier.
d14508fe 8168The default memory range is the function surrounding the
c906108c
SS
8169program counter of the selected frame. A single argument to this
8170command is a program counter value; @value{GDBN} dumps the function
21a0512e
PP
8171surrounding this value. When two arguments are given, they should
8172be separated by a comma, possibly surrounded by whitespace. The
53a71c06
CR
8173arguments specify a range of addresses to dump, in one of two forms:
8174
8175@table @code
8176@item @var{start},@var{end}
8177the addresses from @var{start} (inclusive) to @var{end} (exclusive)
8178@item @var{start},+@var{length}
8179the addresses from @var{start} (inclusive) to
8180@code{@var{start}+@var{length}} (exclusive).
8181@end table
8182
8183@noindent
8184When 2 arguments are specified, the name of the function is also
8185printed (since there could be several functions in the given range).
21a0512e
PP
8186
8187The argument(s) can be any expression yielding a numeric value, such as
8188@samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
2b28d209
PP
8189
8190If the range of memory being disassembled contains current program counter,
8191the instruction at that location is shown with a @code{=>} marker.
c906108c
SS
8192@end table
8193
c906108c
SS
8194The following example shows the disassembly of a range of addresses of
8195HP PA-RISC 2.0 code:
8196
8197@smallexample
21a0512e 8198(@value{GDBP}) disas 0x32c4, 0x32e4
c906108c 8199Dump of assembler code from 0x32c4 to 0x32e4:
2b28d209
PP
8200 0x32c4 <main+204>: addil 0,dp
8201 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
8202 0x32cc <main+212>: ldil 0x3000,r31
8203 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
8204 0x32d4 <main+220>: ldo 0(r31),rp
8205 0x32d8 <main+224>: addil -0x800,dp
8206 0x32dc <main+228>: ldo 0x588(r1),r26
8207 0x32e0 <main+232>: ldil 0x3000,r31
c906108c
SS
8208End of assembler dump.
8209@end smallexample
c906108c 8210
6ff0ba5f
DE
8211Here is an example showing mixed source+assembly for Intel x86
8212with @code{/m} or @code{/s}, when the program is stopped just after
8213function prologue in a non-optimized function with no inline code.
d14508fe
DE
8214
8215@smallexample
8216(@value{GDBP}) disas /m main
8217Dump of assembler code for function main:
82185 @{
9c419145
PP
8219 0x08048330 <+0>: push %ebp
8220 0x08048331 <+1>: mov %esp,%ebp
8221 0x08048333 <+3>: sub $0x8,%esp
8222 0x08048336 <+6>: and $0xfffffff0,%esp
8223 0x08048339 <+9>: sub $0x10,%esp
d14508fe
DE
8224
82256 printf ("Hello.\n");
9c419145
PP
8226=> 0x0804833c <+12>: movl $0x8048440,(%esp)
8227 0x08048343 <+19>: call 0x8048284 <puts@@plt>
d14508fe
DE
8228
82297 return 0;
82308 @}
9c419145
PP
8231 0x08048348 <+24>: mov $0x0,%eax
8232 0x0804834d <+29>: leave
8233 0x0804834e <+30>: ret
d14508fe
DE
8234
8235End of assembler dump.
8236@end smallexample
8237
6ff0ba5f
DE
8238The @code{/m} option is deprecated as its output is not useful when
8239there is either inlined code or re-ordered code.
8240The @code{/s} option is the preferred choice.
8241Here is an example for AMD x86-64 showing the difference between
8242@code{/m} output and @code{/s} output.
8243This example has one inline function defined in a header file,
8244and the code is compiled with @samp{-O2} optimization.
8245Note how the @code{/m} output is missing the disassembly of
8246several instructions that are present in the @code{/s} output.
8247
8248@file{foo.h}:
8249
8250@smallexample
8251int
8252foo (int a)
8253@{
8254 if (a < 0)
8255 return a * 2;
8256 if (a == 0)
8257 return 1;
8258 return a + 10;
8259@}
8260@end smallexample
8261
8262@file{foo.c}:
8263
8264@smallexample
8265#include "foo.h"
8266volatile int x, y;
8267int
8268main ()
8269@{
8270 x = foo (y);
8271 return 0;
8272@}
8273@end smallexample
8274
8275@smallexample
8276(@value{GDBP}) disas /m main
8277Dump of assembler code for function main:
82785 @{
8279
82806 x = foo (y);
8281 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
8282 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
8283
82847 return 0;
82858 @}
8286 0x000000000040041d <+29>: xor %eax,%eax
8287 0x000000000040041f <+31>: retq
8288 0x0000000000400420 <+32>: add %eax,%eax
8289 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
8290
8291End of assembler dump.
8292(@value{GDBP}) disas /s main
8293Dump of assembler code for function main:
8294foo.c:
82955 @{
82966 x = foo (y);
8297 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
8298
8299foo.h:
83004 if (a < 0)
8301 0x0000000000400406 <+6>: test %eax,%eax
8302 0x0000000000400408 <+8>: js 0x400420 <main+32>
8303
83046 if (a == 0)
83057 return 1;
83068 return a + 10;
8307 0x000000000040040a <+10>: lea 0xa(%rax),%edx
8308 0x000000000040040d <+13>: test %eax,%eax
8309 0x000000000040040f <+15>: mov $0x1,%eax
8310 0x0000000000400414 <+20>: cmovne %edx,%eax
8311
8312foo.c:
83136 x = foo (y);
8314 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
8315
83167 return 0;
83178 @}
8318 0x000000000040041d <+29>: xor %eax,%eax
8319 0x000000000040041f <+31>: retq
8320
8321foo.h:
83225 return a * 2;
8323 0x0000000000400420 <+32>: add %eax,%eax
8324 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
8325End of assembler dump.
8326@end smallexample
8327
53a71c06
CR
8328Here is another example showing raw instructions in hex for AMD x86-64,
8329
8330@smallexample
8331(gdb) disas /r 0x400281,+10
8332Dump of assembler code from 0x400281 to 0x40028b:
8333 0x0000000000400281: 38 36 cmp %dh,(%rsi)
8334 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
8335 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
8336 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
8337End of assembler dump.
8338@end smallexample
8339
629500fa 8340Addresses cannot be specified as a location (@pxref{Specify Location}).
7e1e0340
DE
8341So, for example, if you want to disassemble function @code{bar}
8342in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
8343and not @samp{disassemble foo.c:bar}.
8344
c906108c
SS
8345Some architectures have more than one commonly-used set of instruction
8346mnemonics or other syntax.
8347
76d17f34
EZ
8348For programs that were dynamically linked and use shared libraries,
8349instructions that call functions or branch to locations in the shared
8350libraries might show a seemingly bogus location---it's actually a
8351location of the relocation table. On some architectures, @value{GDBN}
8352might be able to resolve these to actual function names.
8353
c906108c 8354@table @code
d4f3574e 8355@kindex set disassembly-flavor
d4f3574e
SS
8356@cindex Intel disassembly flavor
8357@cindex AT&T disassembly flavor
8358@item set disassembly-flavor @var{instruction-set}
c906108c
SS
8359Select the instruction set to use when disassembling the
8360program via the @code{disassemble} or @code{x/i} commands.
8361
8362Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
8363can set @var{instruction-set} to either @code{intel} or @code{att}.
8364The default is @code{att}, the AT&T flavor used by default by Unix
8365assemblers for x86-based targets.
9c16f35a
EZ
8366
8367@kindex show disassembly-flavor
8368@item show disassembly-flavor
8369Show the current setting of the disassembly flavor.
c906108c
SS
8370@end table
8371
91440f57
HZ
8372@table @code
8373@kindex set disassemble-next-line
8374@kindex show disassemble-next-line
8375@item set disassemble-next-line
8376@itemx show disassemble-next-line
32ae1842
EZ
8377Control whether or not @value{GDBN} will disassemble the next source
8378line or instruction when execution stops. If ON, @value{GDBN} will
8379display disassembly of the next source line when execution of the
8380program being debugged stops. This is @emph{in addition} to
8381displaying the source line itself, which @value{GDBN} always does if
8382possible. If the next source line cannot be displayed for some reason
8383(e.g., if @value{GDBN} cannot find the source file, or there's no line
8384info in the debug info), @value{GDBN} will display disassembly of the
8385next @emph{instruction} instead of showing the next source line. If
8386AUTO, @value{GDBN} will display disassembly of next instruction only
8387if the source line cannot be displayed. This setting causes
8388@value{GDBN} to display some feedback when you step through a function
8389with no line info or whose source file is unavailable. The default is
8390OFF, which means never display the disassembly of the next line or
8391instruction.
91440f57
HZ
8392@end table
8393
c906108c 8394
6d2ebf8b 8395@node Data
c906108c
SS
8396@chapter Examining Data
8397
8398@cindex printing data
8399@cindex examining data
8400@kindex print
8401@kindex inspect
c906108c 8402The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
8403command (abbreviated @code{p}), or its synonym @code{inspect}. It
8404evaluates and prints the value of an expression of the language your
8405program is written in (@pxref{Languages, ,Using @value{GDBN} with
78e2826b
TT
8406Different Languages}). It may also print the expression using a
8407Python-based pretty-printer (@pxref{Pretty Printing}).
c906108c
SS
8408
8409@table @code
d4f3574e
SS
8410@item print @var{expr}
8411@itemx print /@var{f} @var{expr}
8412@var{expr} is an expression (in the source language). By default the
8413value of @var{expr} is printed in a format appropriate to its data type;
c906108c 8414you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 8415@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
79a6e687 8416Formats}.
c906108c
SS
8417
8418@item print
8419@itemx print /@var{f}
15387254 8420@cindex reprint the last value
d4f3574e 8421If you omit @var{expr}, @value{GDBN} displays the last value again (from the
79a6e687 8422@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
c906108c
SS
8423conveniently inspect the same value in an alternative format.
8424@end table
8425
8426A more low-level way of examining data is with the @code{x} command.
8427It examines data in memory at a specified address and prints it in a
79a6e687 8428specified format. @xref{Memory, ,Examining Memory}.
c906108c 8429
7a292a7a 8430If you are interested in information about types, or about how the
d4f3574e
SS
8431fields of a struct or a class are declared, use the @code{ptype @var{exp}}
8432command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 8433Table}.
c906108c 8434
06fc020f
SCR
8435@cindex exploring hierarchical data structures
8436@kindex explore
8437Another way of examining values of expressions and type information is
8438through the Python extension command @code{explore} (available only if
8439the @value{GDBN} build is configured with @code{--with-python}). It
8440offers an interactive way to start at the highest level (or, the most
8441abstract level) of the data type of an expression (or, the data type
8442itself) and explore all the way down to leaf scalar values/fields
8443embedded in the higher level data types.
8444
8445@table @code
8446@item explore @var{arg}
8447@var{arg} is either an expression (in the source language), or a type
8448visible in the current context of the program being debugged.
8449@end table
8450
8451The working of the @code{explore} command can be illustrated with an
8452example. If a data type @code{struct ComplexStruct} is defined in your
8453C program as
8454
8455@smallexample
8456struct SimpleStruct
8457@{
8458 int i;
8459 double d;
8460@};
8461
8462struct ComplexStruct
8463@{
8464 struct SimpleStruct *ss_p;
8465 int arr[10];
8466@};
8467@end smallexample
8468
8469@noindent
8470followed by variable declarations as
8471
8472@smallexample
8473struct SimpleStruct ss = @{ 10, 1.11 @};
8474struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
8475@end smallexample
8476
8477@noindent
8478then, the value of the variable @code{cs} can be explored using the
8479@code{explore} command as follows.
8480
8481@smallexample
8482(gdb) explore cs
8483The value of `cs' is a struct/class of type `struct ComplexStruct' with
8484the following fields:
8485
8486 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
8487 arr = <Enter 1 to explore this field of type `int [10]'>
8488
8489Enter the field number of choice:
8490@end smallexample
8491
8492@noindent
8493Since the fields of @code{cs} are not scalar values, you are being
8494prompted to chose the field you want to explore. Let's say you choose
8495the field @code{ss_p} by entering @code{0}. Then, since this field is a
8496pointer, you will be asked if it is pointing to a single value. From
8497the declaration of @code{cs} above, it is indeed pointing to a single
8498value, hence you enter @code{y}. If you enter @code{n}, then you will
8499be asked if it were pointing to an array of values, in which case this
8500field will be explored as if it were an array.
8501
8502@smallexample
8503`cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
8504Continue exploring it as a pointer to a single value [y/n]: y
8505The value of `*(cs.ss_p)' is a struct/class of type `struct
8506SimpleStruct' with the following fields:
8507
8508 i = 10 .. (Value of type `int')
8509 d = 1.1100000000000001 .. (Value of type `double')
8510
8511Press enter to return to parent value:
8512@end smallexample
8513
8514@noindent
8515If the field @code{arr} of @code{cs} was chosen for exploration by
8516entering @code{1} earlier, then since it is as array, you will be
8517prompted to enter the index of the element in the array that you want
8518to explore.
8519
8520@smallexample
8521`cs.arr' is an array of `int'.
8522Enter the index of the element you want to explore in `cs.arr': 5
8523
8524`(cs.arr)[5]' is a scalar value of type `int'.
8525
8526(cs.arr)[5] = 4
8527
8528Press enter to return to parent value:
8529@end smallexample
8530
8531In general, at any stage of exploration, you can go deeper towards the
8532leaf values by responding to the prompts appropriately, or hit the
8533return key to return to the enclosing data structure (the @i{higher}
8534level data structure).
8535
8536Similar to exploring values, you can use the @code{explore} command to
8537explore types. Instead of specifying a value (which is typically a
8538variable name or an expression valid in the current context of the
8539program being debugged), you specify a type name. If you consider the
8540same example as above, your can explore the type
8541@code{struct ComplexStruct} by passing the argument
8542@code{struct ComplexStruct} to the @code{explore} command.
8543
8544@smallexample
8545(gdb) explore struct ComplexStruct
8546@end smallexample
8547
8548@noindent
8549By responding to the prompts appropriately in the subsequent interactive
8550session, you can explore the type @code{struct ComplexStruct} in a
8551manner similar to how the value @code{cs} was explored in the above
8552example.
8553
8554The @code{explore} command also has two sub-commands,
8555@code{explore value} and @code{explore type}. The former sub-command is
8556a way to explicitly specify that value exploration of the argument is
8557being invoked, while the latter is a way to explicitly specify that type
8558exploration of the argument is being invoked.
8559
8560@table @code
8561@item explore value @var{expr}
8562@cindex explore value
8563This sub-command of @code{explore} explores the value of the
8564expression @var{expr} (if @var{expr} is an expression valid in the
8565current context of the program being debugged). The behavior of this
8566command is identical to that of the behavior of the @code{explore}
8567command being passed the argument @var{expr}.
8568
8569@item explore type @var{arg}
8570@cindex explore type
8571This sub-command of @code{explore} explores the type of @var{arg} (if
8572@var{arg} is a type visible in the current context of program being
8573debugged), or the type of the value/expression @var{arg} (if @var{arg}
8574is an expression valid in the current context of the program being
8575debugged). If @var{arg} is a type, then the behavior of this command is
8576identical to that of the @code{explore} command being passed the
8577argument @var{arg}. If @var{arg} is an expression, then the behavior of
8578this command will be identical to that of the @code{explore} command
8579being passed the type of @var{arg} as the argument.
8580@end table
8581
c906108c
SS
8582@menu
8583* Expressions:: Expressions
6ba66d6a 8584* Ambiguous Expressions:: Ambiguous Expressions
c906108c
SS
8585* Variables:: Program variables
8586* Arrays:: Artificial arrays
8587* Output Formats:: Output formats
8588* Memory:: Examining memory
8589* Auto Display:: Automatic display
8590* Print Settings:: Print settings
4c374409 8591* Pretty Printing:: Python pretty printing
c906108c
SS
8592* Value History:: Value history
8593* Convenience Vars:: Convenience variables
a72c3253 8594* Convenience Funs:: Convenience functions
c906108c 8595* Registers:: Registers
c906108c 8596* Floating Point Hardware:: Floating point hardware
53c69bd7 8597* Vector Unit:: Vector Unit
721c2651 8598* OS Information:: Auxiliary data provided by operating system
29e57380 8599* Memory Region Attributes:: Memory region attributes
16d9dec6 8600* Dump/Restore Files:: Copy between memory and a file
384ee23f 8601* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
8602* Character Sets:: Debugging programs that use a different
8603 character set than GDB does
b12039c6 8604* Caching Target Data:: Data caching for targets
08388c79 8605* Searching Memory:: Searching memory for a sequence of bytes
c906108c
SS
8606@end menu
8607
6d2ebf8b 8608@node Expressions
c906108c
SS
8609@section Expressions
8610
8611@cindex expressions
8612@code{print} and many other @value{GDBN} commands accept an expression and
8613compute its value. Any kind of constant, variable or operator defined
8614by the programming language you are using is valid in an expression in
e2e0bcd1
JB
8615@value{GDBN}. This includes conditional expressions, function calls,
8616casts, and string constants. It also includes preprocessor macros, if
8617you compiled your program to include this information; see
8618@ref{Compilation}.
c906108c 8619
15387254 8620@cindex arrays in expressions
d4f3574e
SS
8621@value{GDBN} supports array constants in expressions input by
8622the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
63092375
DJ
8623you can use the command @code{print @{1, 2, 3@}} to create an array
8624of three integers. If you pass an array to a function or assign it
8625to a program variable, @value{GDBN} copies the array to memory that
8626is @code{malloc}ed in the target program.
c906108c 8627
c906108c
SS
8628Because C is so widespread, most of the expressions shown in examples in
8629this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
8630Languages}, for information on how to use expressions in other
8631languages.
8632
8633In this section, we discuss operators that you can use in @value{GDBN}
8634expressions regardless of your programming language.
8635
15387254 8636@cindex casts, in expressions
c906108c
SS
8637Casts are supported in all languages, not just in C, because it is so
8638useful to cast a number into a pointer in order to examine a structure
8639at that address in memory.
8640@c FIXME: casts supported---Mod2 true?
c906108c
SS
8641
8642@value{GDBN} supports these operators, in addition to those common
8643to programming languages:
8644
8645@table @code
8646@item @@
8647@samp{@@} is a binary operator for treating parts of memory as arrays.
79a6e687 8648@xref{Arrays, ,Artificial Arrays}, for more information.
c906108c
SS
8649
8650@item ::
8651@samp{::} allows you to specify a variable in terms of the file or
79a6e687 8652function where it is defined. @xref{Variables, ,Program Variables}.
c906108c
SS
8653
8654@cindex @{@var{type}@}
8655@cindex type casting memory
8656@cindex memory, viewing as typed object
8657@cindex casts, to view memory
8658@item @{@var{type}@} @var{addr}
8659Refers to an object of type @var{type} stored at address @var{addr} in
697aa1b7
EZ
8660memory. The address @var{addr} may be any expression whose value is
8661an integer or pointer (but parentheses are required around binary
8662operators, just as in a cast). This construct is allowed regardless
8663of what kind of data is normally supposed to reside at @var{addr}.
c906108c
SS
8664@end table
8665
6ba66d6a
JB
8666@node Ambiguous Expressions
8667@section Ambiguous Expressions
8668@cindex ambiguous expressions
8669
8670Expressions can sometimes contain some ambiguous elements. For instance,
8671some programming languages (notably Ada, C@t{++} and Objective-C) permit
8672a single function name to be defined several times, for application in
8673different contexts. This is called @dfn{overloading}. Another example
8674involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
8675templates and is typically instantiated several times, resulting in
8676the same function name being defined in different contexts.
8677
8678In some cases and depending on the language, it is possible to adjust
8679the expression to remove the ambiguity. For instance in C@t{++}, you
8680can specify the signature of the function you want to break on, as in
8681@kbd{break @var{function}(@var{types})}. In Ada, using the fully
8682qualified name of your function often makes the expression unambiguous
8683as well.
8684
8685When an ambiguity that needs to be resolved is detected, the debugger
8686has the capability to display a menu of numbered choices for each
8687possibility, and then waits for the selection with the prompt @samp{>}.
8688The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
8689aborts the current command. If the command in which the expression was
8690used allows more than one choice to be selected, the next option in the
8691menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
8692choices.
8693
8694For example, the following session excerpt shows an attempt to set a
8695breakpoint at the overloaded symbol @code{String::after}.
8696We choose three particular definitions of that function name:
8697
8698@c FIXME! This is likely to change to show arg type lists, at least
8699@smallexample
8700@group
8701(@value{GDBP}) b String::after
8702[0] cancel
8703[1] all
8704[2] file:String.cc; line number:867
8705[3] file:String.cc; line number:860
8706[4] file:String.cc; line number:875
8707[5] file:String.cc; line number:853
8708[6] file:String.cc; line number:846
8709[7] file:String.cc; line number:735
8710> 2 4 6
8711Breakpoint 1 at 0xb26c: file String.cc, line 867.
8712Breakpoint 2 at 0xb344: file String.cc, line 875.
8713Breakpoint 3 at 0xafcc: file String.cc, line 846.
8714Multiple breakpoints were set.
8715Use the "delete" command to delete unwanted
8716 breakpoints.
8717(@value{GDBP})
8718@end group
8719@end smallexample
8720
8721@table @code
8722@kindex set multiple-symbols
8723@item set multiple-symbols @var{mode}
8724@cindex multiple-symbols menu
8725
8726This option allows you to adjust the debugger behavior when an expression
8727is ambiguous.
8728
8729By default, @var{mode} is set to @code{all}. If the command with which
8730the expression is used allows more than one choice, then @value{GDBN}
8731automatically selects all possible choices. For instance, inserting
8732a breakpoint on a function using an ambiguous name results in a breakpoint
8733inserted on each possible match. However, if a unique choice must be made,
8734then @value{GDBN} uses the menu to help you disambiguate the expression.
8735For instance, printing the address of an overloaded function will result
8736in the use of the menu.
8737
8738When @var{mode} is set to @code{ask}, the debugger always uses the menu
8739when an ambiguity is detected.
8740
8741Finally, when @var{mode} is set to @code{cancel}, the debugger reports
8742an error due to the ambiguity and the command is aborted.
8743
8744@kindex show multiple-symbols
8745@item show multiple-symbols
8746Show the current value of the @code{multiple-symbols} setting.
8747@end table
8748
6d2ebf8b 8749@node Variables
79a6e687 8750@section Program Variables
c906108c
SS
8751
8752The most common kind of expression to use is the name of a variable
8753in your program.
8754
8755Variables in expressions are understood in the selected stack frame
79a6e687 8756(@pxref{Selection, ,Selecting a Frame}); they must be either:
c906108c
SS
8757
8758@itemize @bullet
8759@item
8760global (or file-static)
8761@end itemize
8762
5d161b24 8763@noindent or
c906108c
SS
8764
8765@itemize @bullet
8766@item
8767visible according to the scope rules of the
8768programming language from the point of execution in that frame
5d161b24 8769@end itemize
c906108c
SS
8770
8771@noindent This means that in the function
8772
474c8240 8773@smallexample
c906108c
SS
8774foo (a)
8775 int a;
8776@{
8777 bar (a);
8778 @{
8779 int b = test ();
8780 bar (b);
8781 @}
8782@}
474c8240 8783@end smallexample
c906108c
SS
8784
8785@noindent
8786you can examine and use the variable @code{a} whenever your program is
8787executing within the function @code{foo}, but you can only use or
8788examine the variable @code{b} while your program is executing inside
8789the block where @code{b} is declared.
8790
8791@cindex variable name conflict
8792There is an exception: you can refer to a variable or function whose
8793scope is a single source file even if the current execution point is not
8794in this file. But it is possible to have more than one such variable or
8795function with the same name (in different source files). If that
8796happens, referring to that name has unpredictable effects. If you wish,
72384ba3 8797you can specify a static variable in a particular function or file by
15387254 8798using the colon-colon (@code{::}) notation:
c906108c 8799
d4f3574e 8800@cindex colon-colon, context for variables/functions
12c27660 8801@ifnotinfo
c906108c 8802@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 8803@cindex @code{::}, context for variables/functions
12c27660 8804@end ifnotinfo
474c8240 8805@smallexample
c906108c
SS
8806@var{file}::@var{variable}
8807@var{function}::@var{variable}
474c8240 8808@end smallexample
c906108c
SS
8809
8810@noindent
8811Here @var{file} or @var{function} is the name of the context for the
8812static @var{variable}. In the case of file names, you can use quotes to
8813make sure @value{GDBN} parses the file name as a single word---for example,
8814to print a global value of @code{x} defined in @file{f2.c}:
8815
474c8240 8816@smallexample
c906108c 8817(@value{GDBP}) p 'f2.c'::x
474c8240 8818@end smallexample
c906108c 8819
72384ba3
PH
8820The @code{::} notation is normally used for referring to
8821static variables, since you typically disambiguate uses of local variables
8822in functions by selecting the appropriate frame and using the
8823simple name of the variable. However, you may also use this notation
8824to refer to local variables in frames enclosing the selected frame:
8825
8826@smallexample
8827void
8828foo (int a)
8829@{
8830 if (a < 10)
8831 bar (a);
8832 else
8833 process (a); /* Stop here */
8834@}
8835
8836int
8837bar (int a)
8838@{
8839 foo (a + 5);
8840@}
8841@end smallexample
8842
8843@noindent
8844For example, if there is a breakpoint at the commented line,
8845here is what you might see
8846when the program stops after executing the call @code{bar(0)}:
8847
8848@smallexample
8849(@value{GDBP}) p a
8850$1 = 10
8851(@value{GDBP}) p bar::a
8852$2 = 5
8853(@value{GDBP}) up 2
8854#2 0x080483d0 in foo (a=5) at foobar.c:12
8855(@value{GDBP}) p a
8856$3 = 5
8857(@value{GDBP}) p bar::a
8858$4 = 0
8859@end smallexample
8860
b37052ae 8861@cindex C@t{++} scope resolution
805e1f19
TT
8862These uses of @samp{::} are very rarely in conflict with the very
8863similar use of the same notation in C@t{++}. When they are in
8864conflict, the C@t{++} meaning takes precedence; however, this can be
8865overridden by quoting the file or function name with single quotes.
8866
8867For example, suppose the program is stopped in a method of a class
8868that has a field named @code{includefile}, and there is also an
8869include file named @file{includefile} that defines a variable,
8870@code{some_global}.
8871
8872@smallexample
8873(@value{GDBP}) p includefile
8874$1 = 23
8875(@value{GDBP}) p includefile::some_global
8876A syntax error in expression, near `'.
8877(@value{GDBP}) p 'includefile'::some_global
8878$2 = 27
8879@end smallexample
c906108c
SS
8880
8881@cindex wrong values
8882@cindex variable values, wrong
15387254
EZ
8883@cindex function entry/exit, wrong values of variables
8884@cindex optimized code, wrong values of variables
c906108c
SS
8885@quotation
8886@emph{Warning:} Occasionally, a local variable may appear to have the
8887wrong value at certain points in a function---just after entry to a new
8888scope, and just before exit.
8889@end quotation
8890You may see this problem when you are stepping by machine instructions.
8891This is because, on most machines, it takes more than one instruction to
8892set up a stack frame (including local variable definitions); if you are
8893stepping by machine instructions, variables may appear to have the wrong
8894values until the stack frame is completely built. On exit, it usually
8895also takes more than one machine instruction to destroy a stack frame;
8896after you begin stepping through that group of instructions, local
8897variable definitions may be gone.
8898
8899This may also happen when the compiler does significant optimizations.
8900To be sure of always seeing accurate values, turn off all optimization
8901when compiling.
8902
d4f3574e
SS
8903@cindex ``No symbol "foo" in current context''
8904Another possible effect of compiler optimizations is to optimize
8905unused variables out of existence, or assign variables to registers (as
8906opposed to memory addresses). Depending on the support for such cases
8907offered by the debug info format used by the compiler, @value{GDBN}
8908might not be able to display values for such local variables. If that
8909happens, @value{GDBN} will print a message like this:
8910
474c8240 8911@smallexample
d4f3574e 8912No symbol "foo" in current context.
474c8240 8913@end smallexample
d4f3574e
SS
8914
8915To solve such problems, either recompile without optimizations, or use a
8916different debug info format, if the compiler supports several such
e0f8f636
TT
8917formats. @xref{Compilation}, for more information on choosing compiler
8918options. @xref{C, ,C and C@t{++}}, for more information about debug
8919info formats that are best suited to C@t{++} programs.
d4f3574e 8920
ab1adacd
EZ
8921If you ask to print an object whose contents are unknown to
8922@value{GDBN}, e.g., because its data type is not completely specified
8923by the debug information, @value{GDBN} will say @samp{<incomplete
8924type>}. @xref{Symbols, incomplete type}, for more about this.
8925
36b11add
JK
8926If you append @kbd{@@entry} string to a function parameter name you get its
8927value at the time the function got called. If the value is not available an
8928error message is printed. Entry values are available only with some compilers.
8929Entry values are normally also printed at the function parameter list according
8930to @ref{set print entry-values}.
8931
8932@smallexample
8933Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
893429 i++;
8935(gdb) next
893630 e (i);
8937(gdb) print i
8938$1 = 31
8939(gdb) print i@@entry
8940$2 = 30
8941@end smallexample
8942
3a60f64e
JK
8943Strings are identified as arrays of @code{char} values without specified
8944signedness. Arrays of either @code{signed char} or @code{unsigned char} get
8945printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
8946@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
8947defines literal string type @code{"char"} as @code{char} without a sign.
8948For program code
8949
8950@smallexample
8951char var0[] = "A";
8952signed char var1[] = "A";
8953@end smallexample
8954
8955You get during debugging
8956@smallexample
8957(gdb) print var0
8958$1 = "A"
8959(gdb) print var1
8960$2 = @{65 'A', 0 '\0'@}
8961@end smallexample
8962
6d2ebf8b 8963@node Arrays
79a6e687 8964@section Artificial Arrays
c906108c
SS
8965
8966@cindex artificial array
15387254 8967@cindex arrays
41afff9a 8968@kindex @@@r{, referencing memory as an array}
c906108c
SS
8969It is often useful to print out several successive objects of the
8970same type in memory; a section of an array, or an array of
8971dynamically determined size for which only a pointer exists in the
8972program.
8973
8974You can do this by referring to a contiguous span of memory as an
8975@dfn{artificial array}, using the binary operator @samp{@@}. The left
8976operand of @samp{@@} should be the first element of the desired array
8977and be an individual object. The right operand should be the desired length
8978of the array. The result is an array value whose elements are all of
8979the type of the left argument. The first element is actually the left
8980argument; the second element comes from bytes of memory immediately
8981following those that hold the first element, and so on. Here is an
8982example. If a program says
8983
474c8240 8984@smallexample
c906108c 8985int *array = (int *) malloc (len * sizeof (int));
474c8240 8986@end smallexample
c906108c
SS
8987
8988@noindent
8989you can print the contents of @code{array} with
8990
474c8240 8991@smallexample
c906108c 8992p *array@@len
474c8240 8993@end smallexample
c906108c
SS
8994
8995The left operand of @samp{@@} must reside in memory. Array values made
8996with @samp{@@} in this way behave just like other arrays in terms of
8997subscripting, and are coerced to pointers when used in expressions.
8998Artificial arrays most often appear in expressions via the value history
79a6e687 8999(@pxref{Value History, ,Value History}), after printing one out.
c906108c
SS
9000
9001Another way to create an artificial array is to use a cast.
9002This re-interprets a value as if it were an array.
9003The value need not be in memory:
474c8240 9004@smallexample
c906108c
SS
9005(@value{GDBP}) p/x (short[2])0x12345678
9006$1 = @{0x1234, 0x5678@}
474c8240 9007@end smallexample
c906108c
SS
9008
9009As a convenience, if you leave the array length out (as in
c3f6f71d 9010@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 9011the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 9012@smallexample
c906108c
SS
9013(@value{GDBP}) p/x (short[])0x12345678
9014$2 = @{0x1234, 0x5678@}
474c8240 9015@end smallexample
c906108c
SS
9016
9017Sometimes the artificial array mechanism is not quite enough; in
9018moderately complex data structures, the elements of interest may not
9019actually be adjacent---for example, if you are interested in the values
9020of pointers in an array. One useful work-around in this situation is
9021to use a convenience variable (@pxref{Convenience Vars, ,Convenience
79a6e687 9022Variables}) as a counter in an expression that prints the first
c906108c
SS
9023interesting value, and then repeat that expression via @key{RET}. For
9024instance, suppose you have an array @code{dtab} of pointers to
9025structures, and you are interested in the values of a field @code{fv}
9026in each structure. Here is an example of what you might type:
9027
474c8240 9028@smallexample
c906108c
SS
9029set $i = 0
9030p dtab[$i++]->fv
9031@key{RET}
9032@key{RET}
9033@dots{}
474c8240 9034@end smallexample
c906108c 9035
6d2ebf8b 9036@node Output Formats
79a6e687 9037@section Output Formats
c906108c
SS
9038
9039@cindex formatted output
9040@cindex output formats
9041By default, @value{GDBN} prints a value according to its data type. Sometimes
9042this is not what you want. For example, you might want to print a number
9043in hex, or a pointer in decimal. Or you might want to view data in memory
9044at a certain address as a character string or as an instruction. To do
9045these things, specify an @dfn{output format} when you print a value.
9046
9047The simplest use of output formats is to say how to print a value
9048already computed. This is done by starting the arguments of the
9049@code{print} command with a slash and a format letter. The format
9050letters supported are:
9051
9052@table @code
9053@item x
9054Regard the bits of the value as an integer, and print the integer in
9055hexadecimal.
9056
9057@item d
9058Print as integer in signed decimal.
9059
9060@item u
9061Print as integer in unsigned decimal.
9062
9063@item o
9064Print as integer in octal.
9065
9066@item t
9067Print as integer in binary. The letter @samp{t} stands for ``two''.
9068@footnote{@samp{b} cannot be used because these format letters are also
9069used with the @code{x} command, where @samp{b} stands for ``byte'';
79a6e687 9070see @ref{Memory,,Examining Memory}.}
c906108c
SS
9071
9072@item a
9073@cindex unknown address, locating
3d67e040 9074@cindex locate address
c906108c
SS
9075Print as an address, both absolute in hexadecimal and as an offset from
9076the nearest preceding symbol. You can use this format used to discover
9077where (in what function) an unknown address is located:
9078
474c8240 9079@smallexample
c906108c
SS
9080(@value{GDBP}) p/a 0x54320
9081$3 = 0x54320 <_initialize_vx+396>
474c8240 9082@end smallexample
c906108c 9083
3d67e040
EZ
9084@noindent
9085The command @code{info symbol 0x54320} yields similar results.
9086@xref{Symbols, info symbol}.
9087
c906108c 9088@item c
51274035
EZ
9089Regard as an integer and print it as a character constant. This
9090prints both the numerical value and its character representation. The
9091character representation is replaced with the octal escape @samp{\nnn}
9092for characters outside the 7-bit @sc{ascii} range.
c906108c 9093
ea37ba09
DJ
9094Without this format, @value{GDBN} displays @code{char},
9095@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
9096constants. Single-byte members of vectors are displayed as integer
9097data.
9098
c906108c
SS
9099@item f
9100Regard the bits of the value as a floating point number and print
9101using typical floating point syntax.
ea37ba09
DJ
9102
9103@item s
9104@cindex printing strings
9105@cindex printing byte arrays
9106Regard as a string, if possible. With this format, pointers to single-byte
9107data are displayed as null-terminated strings and arrays of single-byte data
9108are displayed as fixed-length strings. Other values are displayed in their
9109natural types.
9110
9111Without this format, @value{GDBN} displays pointers to and arrays of
9112@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
9113strings. Single-byte members of a vector are displayed as an integer
9114array.
a6bac58e 9115
6fbe845e
AB
9116@item z
9117Like @samp{x} formatting, the value is treated as an integer and
9118printed as hexadecimal, but leading zeros are printed to pad the value
9119to the size of the integer type.
9120
a6bac58e
TT
9121@item r
9122@cindex raw printing
9123Print using the @samp{raw} formatting. By default, @value{GDBN} will
78e2826b
TT
9124use a Python-based pretty-printer, if one is available (@pxref{Pretty
9125Printing}). This typically results in a higher-level display of the
9126value's contents. The @samp{r} format bypasses any Python
9127pretty-printer which might exist.
c906108c
SS
9128@end table
9129
9130For example, to print the program counter in hex (@pxref{Registers}), type
9131
474c8240 9132@smallexample
c906108c 9133p/x $pc
474c8240 9134@end smallexample
c906108c
SS
9135
9136@noindent
9137Note that no space is required before the slash; this is because command
9138names in @value{GDBN} cannot contain a slash.
9139
9140To reprint the last value in the value history with a different format,
9141you can use the @code{print} command with just a format and no
9142expression. For example, @samp{p/x} reprints the last value in hex.
9143
6d2ebf8b 9144@node Memory
79a6e687 9145@section Examining Memory
c906108c
SS
9146
9147You can use the command @code{x} (for ``examine'') to examine memory in
9148any of several formats, independently of your program's data types.
9149
9150@cindex examining memory
9151@table @code
41afff9a 9152@kindex x @r{(examine memory)}
c906108c
SS
9153@item x/@var{nfu} @var{addr}
9154@itemx x @var{addr}
9155@itemx x
9156Use the @code{x} command to examine memory.
9157@end table
9158
9159@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
9160much memory to display and how to format it; @var{addr} is an
9161expression giving the address where you want to start displaying memory.
9162If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
9163Several commands set convenient defaults for @var{addr}.
9164
9165@table @r
9166@item @var{n}, the repeat count
9167The repeat count is a decimal integer; the default is 1. It specifies
9168how much memory (counting by units @var{u}) to display.
9169@c This really is **decimal**; unaffected by 'set radix' as of GDB
9170@c 4.1.2.
9171
9172@item @var{f}, the display format
51274035
EZ
9173The display format is one of the formats used by @code{print}
9174(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
ea37ba09
DJ
9175@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
9176The default is @samp{x} (hexadecimal) initially. The default changes
9177each time you use either @code{x} or @code{print}.
c906108c
SS
9178
9179@item @var{u}, the unit size
9180The unit size is any of
9181
9182@table @code
9183@item b
9184Bytes.
9185@item h
9186Halfwords (two bytes).
9187@item w
9188Words (four bytes). This is the initial default.
9189@item g
9190Giant words (eight bytes).
9191@end table
9192
9193Each time you specify a unit size with @code{x}, that size becomes the
9a22f0d0
PM
9194default unit the next time you use @code{x}. For the @samp{i} format,
9195the unit size is ignored and is normally not written. For the @samp{s} format,
9196the unit size defaults to @samp{b}, unless it is explicitly given.
9197Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
919832-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
9199Note that the results depend on the programming language of the
9200current compilation unit. If the language is C, the @samp{s}
9201modifier will use the UTF-16 encoding while @samp{w} will use
9202UTF-32. The encoding is set by the programming language and cannot
9203be altered.
c906108c
SS
9204
9205@item @var{addr}, starting display address
9206@var{addr} is the address where you want @value{GDBN} to begin displaying
9207memory. The expression need not have a pointer value (though it may);
9208it is always interpreted as an integer address of a byte of memory.
9209@xref{Expressions, ,Expressions}, for more information on expressions. The default for
9210@var{addr} is usually just after the last address examined---but several
9211other commands also set the default address: @code{info breakpoints} (to
9212the address of the last breakpoint listed), @code{info line} (to the
9213starting address of a line), and @code{print} (if you use it to display
9214a value from memory).
9215@end table
9216
9217For example, @samp{x/3uh 0x54320} is a request to display three halfwords
9218(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
9219starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
9220words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 9221@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
9222
9223Since the letters indicating unit sizes are all distinct from the
9224letters specifying output formats, you do not have to remember whether
9225unit size or format comes first; either order works. The output
9226specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
9227(However, the count @var{n} must come first; @samp{wx4} does not work.)
9228
9229Even though the unit size @var{u} is ignored for the formats @samp{s}
9230and @samp{i}, you might still want to use a count @var{n}; for example,
9231@samp{3i} specifies that you want to see three machine instructions,
a4642986
MR
9232including any operands. For convenience, especially when used with
9233the @code{display} command, the @samp{i} format also prints branch delay
9234slot instructions, if any, beyond the count specified, which immediately
9235follow the last instruction that is within the count. The command
9236@code{disassemble} gives an alternative way of inspecting machine
9237instructions; see @ref{Machine Code,,Source and Machine Code}.
c906108c
SS
9238
9239All the defaults for the arguments to @code{x} are designed to make it
9240easy to continue scanning memory with minimal specifications each time
9241you use @code{x}. For example, after you have inspected three machine
9242instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
9243with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
9244the repeat count @var{n} is used again; the other arguments default as
9245for successive uses of @code{x}.
9246
2b28d209
PP
9247When examining machine instructions, the instruction at current program
9248counter is shown with a @code{=>} marker. For example:
9249
9250@smallexample
9251(@value{GDBP}) x/5i $pc-6
9252 0x804837f <main+11>: mov %esp,%ebp
9253 0x8048381 <main+13>: push %ecx
9254 0x8048382 <main+14>: sub $0x4,%esp
9255=> 0x8048385 <main+17>: movl $0x8048460,(%esp)
9256 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
9257@end smallexample
9258
c906108c
SS
9259@cindex @code{$_}, @code{$__}, and value history
9260The addresses and contents printed by the @code{x} command are not saved
9261in the value history because there is often too much of them and they
9262would get in the way. Instead, @value{GDBN} makes these values available for
9263subsequent use in expressions as values of the convenience variables
9264@code{$_} and @code{$__}. After an @code{x} command, the last address
9265examined is available for use in expressions in the convenience variable
9266@code{$_}. The contents of that address, as examined, are available in
9267the convenience variable @code{$__}.
9268
9269If the @code{x} command has a repeat count, the address and contents saved
9270are from the last memory unit printed; this is not the same as the last
9271address printed if several units were printed on the last line of output.
9272
a86c90e6
SM
9273@anchor{addressable memory unit}
9274@cindex addressable memory unit
9275Most targets have an addressable memory unit size of 8 bits. This means
9276that to each memory address are associated 8 bits of data. Some
9277targets, however, have other addressable memory unit sizes.
9278Within @value{GDBN} and this document, the term
9279@dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
9280when explicitly referring to a chunk of data of that size. The word
9281@dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
9282the addressable memory unit size of the target. For most systems,
9283addressable memory unit is a synonym of byte.
9284
09d4efe1 9285@cindex remote memory comparison
936d2992 9286@cindex target memory comparison
09d4efe1 9287@cindex verify remote memory image
936d2992 9288@cindex verify target memory image
09d4efe1 9289When you are debugging a program running on a remote target machine
936d2992
PA
9290(@pxref{Remote Debugging}), you may wish to verify the program's image
9291in the remote machine's memory against the executable file you
9292downloaded to the target. Or, on any target, you may want to check
9293whether the program has corrupted its own read-only sections. The
9294@code{compare-sections} command is provided for such situations.
09d4efe1
EZ
9295
9296@table @code
9297@kindex compare-sections
95cf3b38 9298@item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
09d4efe1
EZ
9299Compare the data of a loadable section @var{section-name} in the
9300executable file of the program being debugged with the same section in
936d2992 9301the target machine's memory, and report any mismatches. With no
95cf3b38 9302arguments, compares all loadable sections. With an argument of
936d2992
PA
9303@code{-r}, compares all loadable read-only sections.
9304
9305Note: for remote targets, this command can be accelerated if the
9306target supports computing the CRC checksum of a block of memory
9307(@pxref{qCRC packet}).
09d4efe1
EZ
9308@end table
9309
6d2ebf8b 9310@node Auto Display
79a6e687 9311@section Automatic Display
c906108c
SS
9312@cindex automatic display
9313@cindex display of expressions
9314
9315If you find that you want to print the value of an expression frequently
9316(to see how it changes), you might want to add it to the @dfn{automatic
9317display list} so that @value{GDBN} prints its value each time your program stops.
9318Each expression added to the list is given a number to identify it;
9319to remove an expression from the list, you specify that number.
9320The automatic display looks like this:
9321
474c8240 9322@smallexample
c906108c
SS
93232: foo = 38
93243: bar[5] = (struct hack *) 0x3804
474c8240 9325@end smallexample
c906108c
SS
9326
9327@noindent
9328This display shows item numbers, expressions and their current values. As with
9329displays you request manually using @code{x} or @code{print}, you can
9330specify the output format you prefer; in fact, @code{display} decides
ea37ba09
DJ
9331whether to use @code{print} or @code{x} depending your format
9332specification---it uses @code{x} if you specify either the @samp{i}
9333or @samp{s} format, or a unit size; otherwise it uses @code{print}.
c906108c
SS
9334
9335@table @code
9336@kindex display
d4f3574e
SS
9337@item display @var{expr}
9338Add the expression @var{expr} to the list of expressions to display
c906108c
SS
9339each time your program stops. @xref{Expressions, ,Expressions}.
9340
9341@code{display} does not repeat if you press @key{RET} again after using it.
9342
d4f3574e 9343@item display/@var{fmt} @var{expr}
c906108c 9344For @var{fmt} specifying only a display format and not a size or
d4f3574e 9345count, add the expression @var{expr} to the auto-display list but
c906108c 9346arrange to display it each time in the specified format @var{fmt}.
79a6e687 9347@xref{Output Formats,,Output Formats}.
c906108c
SS
9348
9349@item display/@var{fmt} @var{addr}
9350For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
9351number of units, add the expression @var{addr} as a memory address to
9352be examined each time your program stops. Examining means in effect
79a6e687 9353doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
c906108c
SS
9354@end table
9355
9356For example, @samp{display/i $pc} can be helpful, to see the machine
9357instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 9358is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
9359
9360@table @code
9361@kindex delete display
9362@kindex undisplay
9363@item undisplay @var{dnums}@dots{}
9364@itemx delete display @var{dnums}@dots{}
c9174737
PA
9365Remove items from the list of expressions to display. Specify the
9366numbers of the displays that you want affected with the command
9367argument @var{dnums}. It can be a single display number, one of the
9368numbers shown in the first field of the @samp{info display} display;
9369or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
9370
9371@code{undisplay} does not repeat if you press @key{RET} after using it.
9372(Otherwise you would just get the error @samp{No display number @dots{}}.)
9373
9374@kindex disable display
9375@item disable display @var{dnums}@dots{}
9376Disable the display of item numbers @var{dnums}. A disabled display
9377item is not printed automatically, but is not forgotten. It may be
c9174737
PA
9378enabled again later. Specify the numbers of the displays that you
9379want affected with the command argument @var{dnums}. It can be a
9380single display number, one of the numbers shown in the first field of
9381the @samp{info display} display; or it could be a range of display
9382numbers, as in @code{2-4}.
c906108c
SS
9383
9384@kindex enable display
9385@item enable display @var{dnums}@dots{}
9386Enable display of item numbers @var{dnums}. It becomes effective once
9387again in auto display of its expression, until you specify otherwise.
c9174737
PA
9388Specify the numbers of the displays that you want affected with the
9389command argument @var{dnums}. It can be a single display number, one
9390of the numbers shown in the first field of the @samp{info display}
9391display; or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
9392
9393@item display
9394Display the current values of the expressions on the list, just as is
9395done when your program stops.
9396
9397@kindex info display
9398@item info display
9399Print the list of expressions previously set up to display
9400automatically, each one with its item number, but without showing the
9401values. This includes disabled expressions, which are marked as such.
9402It also includes expressions which would not be displayed right now
9403because they refer to automatic variables not currently available.
9404@end table
9405
15387254 9406@cindex display disabled out of scope
c906108c
SS
9407If a display expression refers to local variables, then it does not make
9408sense outside the lexical context for which it was set up. Such an
9409expression is disabled when execution enters a context where one of its
9410variables is not defined. For example, if you give the command
9411@code{display last_char} while inside a function with an argument
9412@code{last_char}, @value{GDBN} displays this argument while your program
9413continues to stop inside that function. When it stops elsewhere---where
9414there is no variable @code{last_char}---the display is disabled
9415automatically. The next time your program stops where @code{last_char}
9416is meaningful, you can enable the display expression once again.
9417
6d2ebf8b 9418@node Print Settings
79a6e687 9419@section Print Settings
c906108c
SS
9420
9421@cindex format options
9422@cindex print settings
9423@value{GDBN} provides the following ways to control how arrays, structures,
9424and symbols are printed.
9425
9426@noindent
9427These settings are useful for debugging programs in any language:
9428
9429@table @code
4644b6e3 9430@kindex set print
c906108c
SS
9431@item set print address
9432@itemx set print address on
4644b6e3 9433@cindex print/don't print memory addresses
c906108c
SS
9434@value{GDBN} prints memory addresses showing the location of stack
9435traces, structure values, pointer values, breakpoints, and so forth,
9436even when it also displays the contents of those addresses. The default
9437is @code{on}. For example, this is what a stack frame display looks like with
9438@code{set print address on}:
9439
9440@smallexample
9441@group
9442(@value{GDBP}) f
9443#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
9444 at input.c:530
9445530 if (lquote != def_lquote)
9446@end group
9447@end smallexample
9448
9449@item set print address off
9450Do not print addresses when displaying their contents. For example,
9451this is the same stack frame displayed with @code{set print address off}:
9452
9453@smallexample
9454@group
9455(@value{GDBP}) set print addr off
9456(@value{GDBP}) f
9457#0 set_quotes (lq="<<", rq=">>") at input.c:530
9458530 if (lquote != def_lquote)
9459@end group
9460@end smallexample
9461
9462You can use @samp{set print address off} to eliminate all machine
9463dependent displays from the @value{GDBN} interface. For example, with
9464@code{print address off}, you should get the same text for backtraces on
9465all machines---whether or not they involve pointer arguments.
9466
4644b6e3 9467@kindex show print
c906108c
SS
9468@item show print address
9469Show whether or not addresses are to be printed.
9470@end table
9471
9472When @value{GDBN} prints a symbolic address, it normally prints the
9473closest earlier symbol plus an offset. If that symbol does not uniquely
9474identify the address (for example, it is a name whose scope is a single
9475source file), you may need to clarify. One way to do this is with
9476@code{info line}, for example @samp{info line *0x4537}. Alternately,
9477you can set @value{GDBN} to print the source file and line number when
9478it prints a symbolic address:
9479
9480@table @code
c906108c 9481@item set print symbol-filename on
9c16f35a
EZ
9482@cindex source file and line of a symbol
9483@cindex symbol, source file and line
c906108c
SS
9484Tell @value{GDBN} to print the source file name and line number of a
9485symbol in the symbolic form of an address.
9486
9487@item set print symbol-filename off
9488Do not print source file name and line number of a symbol. This is the
9489default.
9490
c906108c
SS
9491@item show print symbol-filename
9492Show whether or not @value{GDBN} will print the source file name and
9493line number of a symbol in the symbolic form of an address.
9494@end table
9495
9496Another situation where it is helpful to show symbol filenames and line
9497numbers is when disassembling code; @value{GDBN} shows you the line
9498number and source file that corresponds to each instruction.
9499
9500Also, you may wish to see the symbolic form only if the address being
9501printed is reasonably close to the closest earlier symbol:
9502
9503@table @code
c906108c 9504@item set print max-symbolic-offset @var{max-offset}
f81d1120 9505@itemx set print max-symbolic-offset unlimited
4644b6e3 9506@cindex maximum value for offset of closest symbol
c906108c
SS
9507Tell @value{GDBN} to only display the symbolic form of an address if the
9508offset between the closest earlier symbol and the address is less than
f81d1120
PA
9509@var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
9510to always print the symbolic form of an address if any symbol precedes
9511it. Zero is equivalent to @code{unlimited}.
c906108c 9512
c906108c
SS
9513@item show print max-symbolic-offset
9514Ask how large the maximum offset is that @value{GDBN} prints in a
9515symbolic address.
9516@end table
9517
9518@cindex wild pointer, interpreting
9519@cindex pointer, finding referent
9520If you have a pointer and you are not sure where it points, try
9521@samp{set print symbol-filename on}. Then you can determine the name
9522and source file location of the variable where it points, using
9523@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
9524For example, here @value{GDBN} shows that a variable @code{ptt} points
9525at another variable @code{t}, defined in @file{hi2.c}:
9526
474c8240 9527@smallexample
c906108c
SS
9528(@value{GDBP}) set print symbol-filename on
9529(@value{GDBP}) p/a ptt
9530$4 = 0xe008 <t in hi2.c>
474c8240 9531@end smallexample
c906108c
SS
9532
9533@quotation
9534@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
9535does not show the symbol name and filename of the referent, even with
9536the appropriate @code{set print} options turned on.
9537@end quotation
9538
9cb709b6
TT
9539You can also enable @samp{/a}-like formatting all the time using
9540@samp{set print symbol on}:
9541
9542@table @code
9543@item set print symbol on
9544Tell @value{GDBN} to print the symbol corresponding to an address, if
9545one exists.
9546
9547@item set print symbol off
9548Tell @value{GDBN} not to print the symbol corresponding to an
9549address. In this mode, @value{GDBN} will still print the symbol
9550corresponding to pointers to functions. This is the default.
9551
9552@item show print symbol
9553Show whether @value{GDBN} will display the symbol corresponding to an
9554address.
9555@end table
9556
c906108c
SS
9557Other settings control how different kinds of objects are printed:
9558
9559@table @code
c906108c
SS
9560@item set print array
9561@itemx set print array on
4644b6e3 9562@cindex pretty print arrays
c906108c
SS
9563Pretty print arrays. This format is more convenient to read,
9564but uses more space. The default is off.
9565
9566@item set print array off
9567Return to compressed format for arrays.
9568
c906108c
SS
9569@item show print array
9570Show whether compressed or pretty format is selected for displaying
9571arrays.
9572
3c9c013a
JB
9573@cindex print array indexes
9574@item set print array-indexes
9575@itemx set print array-indexes on
9576Print the index of each element when displaying arrays. May be more
9577convenient to locate a given element in the array or quickly find the
9578index of a given element in that printed array. The default is off.
9579
9580@item set print array-indexes off
9581Stop printing element indexes when displaying arrays.
9582
9583@item show print array-indexes
9584Show whether the index of each element is printed when displaying
9585arrays.
9586
c906108c 9587@item set print elements @var{number-of-elements}
f81d1120 9588@itemx set print elements unlimited
4644b6e3 9589@cindex number of array elements to print
9c16f35a 9590@cindex limit on number of printed array elements
c906108c
SS
9591Set a limit on how many elements of an array @value{GDBN} will print.
9592If @value{GDBN} is printing a large array, it stops printing after it has
9593printed the number of elements set by the @code{set print elements} command.
9594This limit also applies to the display of strings.
d4f3574e 9595When @value{GDBN} starts, this limit is set to 200.
f81d1120
PA
9596Setting @var{number-of-elements} to @code{unlimited} or zero means
9597that the number of elements to print is unlimited.
c906108c 9598
c906108c
SS
9599@item show print elements
9600Display the number of elements of a large array that @value{GDBN} will print.
9601If the number is 0, then the printing is unlimited.
9602
b4740add 9603@item set print frame-arguments @var{value}
a0381d3a 9604@kindex set print frame-arguments
b4740add
JB
9605@cindex printing frame argument values
9606@cindex print all frame argument values
9607@cindex print frame argument values for scalars only
9608@cindex do not print frame argument values
9609This command allows to control how the values of arguments are printed
9610when the debugger prints a frame (@pxref{Frames}). The possible
9611values are:
9612
9613@table @code
9614@item all
4f5376b2 9615The values of all arguments are printed.
b4740add
JB
9616
9617@item scalars
9618Print the value of an argument only if it is a scalar. The value of more
9619complex arguments such as arrays, structures, unions, etc, is replaced
4f5376b2
JB
9620by @code{@dots{}}. This is the default. Here is an example where
9621only scalar arguments are shown:
b4740add
JB
9622
9623@smallexample
9624#1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
9625 at frame-args.c:23
9626@end smallexample
9627
9628@item none
9629None of the argument values are printed. Instead, the value of each argument
9630is replaced by @code{@dots{}}. In this case, the example above now becomes:
9631
9632@smallexample
9633#1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
9634 at frame-args.c:23
9635@end smallexample
9636@end table
9637
4f5376b2
JB
9638By default, only scalar arguments are printed. This command can be used
9639to configure the debugger to print the value of all arguments, regardless
9640of their type. However, it is often advantageous to not print the value
9641of more complex parameters. For instance, it reduces the amount of
9642information printed in each frame, making the backtrace more readable.
9643Also, it improves performance when displaying Ada frames, because
9644the computation of large arguments can sometimes be CPU-intensive,
9645especially in large applications. Setting @code{print frame-arguments}
9646to @code{scalars} (the default) or @code{none} avoids this computation,
9647thus speeding up the display of each Ada frame.
b4740add
JB
9648
9649@item show print frame-arguments
9650Show how the value of arguments should be displayed when printing a frame.
9651
e7045703
DE
9652@item set print raw frame-arguments on
9653Print frame arguments in raw, non pretty-printed, form.
9654
9655@item set print raw frame-arguments off
9656Print frame arguments in pretty-printed form, if there is a pretty-printer
9657for the value (@pxref{Pretty Printing}),
9658otherwise print the value in raw form.
9659This is the default.
9660
9661@item show print raw frame-arguments
9662Show whether to print frame arguments in raw form.
9663
36b11add 9664@anchor{set print entry-values}
e18b2753
JK
9665@item set print entry-values @var{value}
9666@kindex set print entry-values
9667Set printing of frame argument values at function entry. In some cases
9668@value{GDBN} can determine the value of function argument which was passed by
9669the function caller, even if the value was modified inside the called function
9670and therefore is different. With optimized code, the current value could be
9671unavailable, but the entry value may still be known.
9672
9673The default value is @code{default} (see below for its description). Older
9674@value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
9675this feature will behave in the @code{default} setting the same way as with the
9676@code{no} setting.
9677
9678This functionality is currently supported only by DWARF 2 debugging format and
9679the compiler has to produce @samp{DW_TAG_GNU_call_site} tags. With
9680@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
9681this information.
9682
9683The @var{value} parameter can be one of the following:
9684
9685@table @code
9686@item no
9687Print only actual parameter values, never print values from function entry
9688point.
9689@smallexample
9690#0 equal (val=5)
9691#0 different (val=6)
9692#0 lost (val=<optimized out>)
9693#0 born (val=10)
9694#0 invalid (val=<optimized out>)
9695@end smallexample
9696
9697@item only
9698Print only parameter values from function entry point. The actual parameter
9699values are never printed.
9700@smallexample
9701#0 equal (val@@entry=5)
9702#0 different (val@@entry=5)
9703#0 lost (val@@entry=5)
9704#0 born (val@@entry=<optimized out>)
9705#0 invalid (val@@entry=<optimized out>)
9706@end smallexample
9707
9708@item preferred
9709Print only parameter values from function entry point. If value from function
9710entry point is not known while the actual value is known, print the actual
9711value for such parameter.
9712@smallexample
9713#0 equal (val@@entry=5)
9714#0 different (val@@entry=5)
9715#0 lost (val@@entry=5)
9716#0 born (val=10)
9717#0 invalid (val@@entry=<optimized out>)
9718@end smallexample
9719
9720@item if-needed
9721Print actual parameter values. If actual parameter value is not known while
9722value from function entry point is known, print the entry point value for such
9723parameter.
9724@smallexample
9725#0 equal (val=5)
9726#0 different (val=6)
9727#0 lost (val@@entry=5)
9728#0 born (val=10)
9729#0 invalid (val=<optimized out>)
9730@end smallexample
9731
9732@item both
9733Always print both the actual parameter value and its value from function entry
9734point, even if values of one or both are not available due to compiler
9735optimizations.
9736@smallexample
9737#0 equal (val=5, val@@entry=5)
9738#0 different (val=6, val@@entry=5)
9739#0 lost (val=<optimized out>, val@@entry=5)
9740#0 born (val=10, val@@entry=<optimized out>)
9741#0 invalid (val=<optimized out>, val@@entry=<optimized out>)
9742@end smallexample
9743
9744@item compact
9745Print the actual parameter value if it is known and also its value from
9746function entry point if it is known. If neither is known, print for the actual
9747value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
9748values are known and identical, print the shortened
9749@code{param=param@@entry=VALUE} notation.
9750@smallexample
9751#0 equal (val=val@@entry=5)
9752#0 different (val=6, val@@entry=5)
9753#0 lost (val@@entry=5)
9754#0 born (val=10)
9755#0 invalid (val=<optimized out>)
9756@end smallexample
9757
9758@item default
9759Always print the actual parameter value. Print also its value from function
9760entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
9761if both values are known and identical, print the shortened
9762@code{param=param@@entry=VALUE} notation.
9763@smallexample
9764#0 equal (val=val@@entry=5)
9765#0 different (val=6, val@@entry=5)
9766#0 lost (val=<optimized out>, val@@entry=5)
9767#0 born (val=10)
9768#0 invalid (val=<optimized out>)
9769@end smallexample
9770@end table
9771
9772For analysis messages on possible failures of frame argument values at function
9773entry resolution see @ref{set debug entry-values}.
9774
9775@item show print entry-values
9776Show the method being used for printing of frame argument values at function
9777entry.
9778
f81d1120
PA
9779@item set print repeats @var{number-of-repeats}
9780@itemx set print repeats unlimited
9c16f35a
EZ
9781@cindex repeated array elements
9782Set the threshold for suppressing display of repeated array
d3e8051b 9783elements. When the number of consecutive identical elements of an
9c16f35a
EZ
9784array exceeds the threshold, @value{GDBN} prints the string
9785@code{"<repeats @var{n} times>"}, where @var{n} is the number of
9786identical repetitions, instead of displaying the identical elements
f81d1120
PA
9787themselves. Setting the threshold to @code{unlimited} or zero will
9788cause all elements to be individually printed. The default threshold
9789is 10.
9c16f35a
EZ
9790
9791@item show print repeats
9792Display the current threshold for printing repeated identical
9793elements.
9794
c906108c 9795@item set print null-stop
4644b6e3 9796@cindex @sc{null} elements in arrays
c906108c 9797Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 9798@sc{null} is encountered. This is useful when large arrays actually
c906108c 9799contain only short strings.
d4f3574e 9800The default is off.
c906108c 9801
9c16f35a
EZ
9802@item show print null-stop
9803Show whether @value{GDBN} stops printing an array on the first
9804@sc{null} character.
9805
c906108c 9806@item set print pretty on
9c16f35a
EZ
9807@cindex print structures in indented form
9808@cindex indentation in structure display
5d161b24 9809Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
9810per line, like this:
9811
9812@smallexample
9813@group
9814$1 = @{
9815 next = 0x0,
9816 flags = @{
9817 sweet = 1,
9818 sour = 1
9819 @},
9820 meat = 0x54 "Pork"
9821@}
9822@end group
9823@end smallexample
9824
9825@item set print pretty off
9826Cause @value{GDBN} to print structures in a compact format, like this:
9827
9828@smallexample
9829@group
9830$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
9831meat = 0x54 "Pork"@}
9832@end group
9833@end smallexample
9834
9835@noindent
9836This is the default format.
9837
c906108c
SS
9838@item show print pretty
9839Show which format @value{GDBN} is using to print structures.
9840
c906108c 9841@item set print sevenbit-strings on
4644b6e3
EZ
9842@cindex eight-bit characters in strings
9843@cindex octal escapes in strings
c906108c
SS
9844Print using only seven-bit characters; if this option is set,
9845@value{GDBN} displays any eight-bit characters (in strings or
9846character values) using the notation @code{\}@var{nnn}. This setting is
9847best if you are working in English (@sc{ascii}) and you use the
9848high-order bit of characters as a marker or ``meta'' bit.
9849
9850@item set print sevenbit-strings off
9851Print full eight-bit characters. This allows the use of more
9852international character sets, and is the default.
9853
c906108c
SS
9854@item show print sevenbit-strings
9855Show whether or not @value{GDBN} is printing only seven-bit characters.
9856
c906108c 9857@item set print union on
4644b6e3 9858@cindex unions in structures, printing
9c16f35a
EZ
9859Tell @value{GDBN} to print unions which are contained in structures
9860and other unions. This is the default setting.
c906108c
SS
9861
9862@item set print union off
9c16f35a
EZ
9863Tell @value{GDBN} not to print unions which are contained in
9864structures and other unions. @value{GDBN} will print @code{"@{...@}"}
9865instead.
c906108c 9866
c906108c
SS
9867@item show print union
9868Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 9869structures and other unions.
c906108c
SS
9870
9871For example, given the declarations
9872
9873@smallexample
9874typedef enum @{Tree, Bug@} Species;
9875typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 9876typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
9877 Bug_forms;
9878
9879struct thing @{
9880 Species it;
9881 union @{
9882 Tree_forms tree;
9883 Bug_forms bug;
9884 @} form;
9885@};
9886
9887struct thing foo = @{Tree, @{Acorn@}@};
9888@end smallexample
9889
9890@noindent
9891with @code{set print union on} in effect @samp{p foo} would print
9892
9893@smallexample
9894$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
9895@end smallexample
9896
9897@noindent
9898and with @code{set print union off} in effect it would print
9899
9900@smallexample
9901$1 = @{it = Tree, form = @{...@}@}
9902@end smallexample
9c16f35a
EZ
9903
9904@noindent
9905@code{set print union} affects programs written in C-like languages
9906and in Pascal.
c906108c
SS
9907@end table
9908
c906108c
SS
9909@need 1000
9910@noindent
b37052ae 9911These settings are of interest when debugging C@t{++} programs:
c906108c
SS
9912
9913@table @code
4644b6e3 9914@cindex demangling C@t{++} names
c906108c
SS
9915@item set print demangle
9916@itemx set print demangle on
b37052ae 9917Print C@t{++} names in their source form rather than in the encoded
c906108c 9918(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 9919linkage. The default is on.
c906108c 9920
c906108c 9921@item show print demangle
b37052ae 9922Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 9923
c906108c
SS
9924@item set print asm-demangle
9925@itemx set print asm-demangle on
b37052ae 9926Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
9927in assembler code printouts such as instruction disassemblies.
9928The default is off.
9929
c906108c 9930@item show print asm-demangle
b37052ae 9931Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
9932or demangled form.
9933
b37052ae
EZ
9934@cindex C@t{++} symbol decoding style
9935@cindex symbol decoding style, C@t{++}
a8f24a35 9936@kindex set demangle-style
c906108c
SS
9937@item set demangle-style @var{style}
9938Choose among several encoding schemes used by different compilers to
b37052ae 9939represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
9940
9941@table @code
9942@item auto
9943Allow @value{GDBN} to choose a decoding style by inspecting your program.
891df0ea 9944This is the default.
c906108c
SS
9945
9946@item gnu
b37052ae 9947Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c
SS
9948
9949@item hp
b37052ae 9950Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
9951
9952@item lucid
b37052ae 9953Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
9954
9955@item arm
b37052ae 9956Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
9957@strong{Warning:} this setting alone is not sufficient to allow
9958debugging @code{cfront}-generated executables. @value{GDBN} would
9959require further enhancement to permit that.
9960
9961@end table
9962If you omit @var{style}, you will see a list of possible formats.
9963
c906108c 9964@item show demangle-style
b37052ae 9965Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 9966
c906108c
SS
9967@item set print object
9968@itemx set print object on
4644b6e3 9969@cindex derived type of an object, printing
9c16f35a 9970@cindex display derived types
c906108c
SS
9971When displaying a pointer to an object, identify the @emph{actual}
9972(derived) type of the object rather than the @emph{declared} type, using
625c0d47
TT
9973the virtual function table. Note that the virtual function table is
9974required---this feature can only work for objects that have run-time
9975type identification; a single virtual method in the object's declared
8264ba82
AG
9976type is sufficient. Note that this setting is also taken into account when
9977working with variable objects via MI (@pxref{GDB/MI}).
c906108c
SS
9978
9979@item set print object off
9980Display only the declared type of objects, without reference to the
9981virtual function table. This is the default setting.
9982
c906108c
SS
9983@item show print object
9984Show whether actual, or declared, object types are displayed.
9985
c906108c
SS
9986@item set print static-members
9987@itemx set print static-members on
4644b6e3 9988@cindex static members of C@t{++} objects
b37052ae 9989Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
9990
9991@item set print static-members off
b37052ae 9992Do not print static members when displaying a C@t{++} object.
c906108c 9993
c906108c 9994@item show print static-members
9c16f35a
EZ
9995Show whether C@t{++} static members are printed or not.
9996
9997@item set print pascal_static-members
9998@itemx set print pascal_static-members on
d3e8051b
EZ
9999@cindex static members of Pascal objects
10000@cindex Pascal objects, static members display
9c16f35a
EZ
10001Print static members when displaying a Pascal object. The default is on.
10002
10003@item set print pascal_static-members off
10004Do not print static members when displaying a Pascal object.
10005
10006@item show print pascal_static-members
10007Show whether Pascal static members are printed or not.
c906108c
SS
10008
10009@c These don't work with HP ANSI C++ yet.
c906108c
SS
10010@item set print vtbl
10011@itemx set print vtbl on
4644b6e3 10012@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
10013@cindex virtual functions (C@t{++}) display
10014@cindex VTBL display
b37052ae 10015Pretty print C@t{++} virtual function tables. The default is off.
c906108c 10016(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 10017ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
10018
10019@item set print vtbl off
b37052ae 10020Do not pretty print C@t{++} virtual function tables.
c906108c 10021
c906108c 10022@item show print vtbl
b37052ae 10023Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 10024@end table
c906108c 10025
4c374409
JK
10026@node Pretty Printing
10027@section Pretty Printing
10028
10029@value{GDBN} provides a mechanism to allow pretty-printing of values using
10030Python code. It greatly simplifies the display of complex objects. This
10031mechanism works for both MI and the CLI.
10032
7b51bc51
DE
10033@menu
10034* Pretty-Printer Introduction:: Introduction to pretty-printers
10035* Pretty-Printer Example:: An example pretty-printer
10036* Pretty-Printer Commands:: Pretty-printer commands
10037@end menu
10038
10039@node Pretty-Printer Introduction
10040@subsection Pretty-Printer Introduction
10041
10042When @value{GDBN} prints a value, it first sees if there is a pretty-printer
10043registered for the value. If there is then @value{GDBN} invokes the
10044pretty-printer to print the value. Otherwise the value is printed normally.
10045
10046Pretty-printers are normally named. This makes them easy to manage.
10047The @samp{info pretty-printer} command will list all the installed
10048pretty-printers with their names.
10049If a pretty-printer can handle multiple data types, then its
10050@dfn{subprinters} are the printers for the individual data types.
10051Each such subprinter has its own name.
4e04c971 10052The format of the name is @var{printer-name};@var{subprinter-name}.
7b51bc51
DE
10053
10054Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
10055Typically they are automatically loaded and registered when the corresponding
10056debug information is loaded, thus making them available without having to
10057do anything special.
10058
10059There are three places where a pretty-printer can be registered.
10060
10061@itemize @bullet
10062@item
10063Pretty-printers registered globally are available when debugging
10064all inferiors.
10065
10066@item
10067Pretty-printers registered with a program space are available only
10068when debugging that program.
10069@xref{Progspaces In Python}, for more details on program spaces in Python.
10070
10071@item
10072Pretty-printers registered with an objfile are loaded and unloaded
10073with the corresponding objfile (e.g., shared library).
10074@xref{Objfiles In Python}, for more details on objfiles in Python.
10075@end itemize
10076
10077@xref{Selecting Pretty-Printers}, for further information on how
10078pretty-printers are selected,
10079
10080@xref{Writing a Pretty-Printer}, for implementing pretty printers
10081for new types.
10082
10083@node Pretty-Printer Example
10084@subsection Pretty-Printer Example
10085
10086Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
4c374409
JK
10087
10088@smallexample
10089(@value{GDBP}) print s
10090$1 = @{
10091 static npos = 4294967295,
10092 _M_dataplus = @{
10093 <std::allocator<char>> = @{
10094 <__gnu_cxx::new_allocator<char>> = @{
10095 <No data fields>@}, <No data fields>
10096 @},
10097 members of std::basic_string<char, std::char_traits<char>,
10098 std::allocator<char> >::_Alloc_hider:
10099 _M_p = 0x804a014 "abcd"
10100 @}
10101@}
10102@end smallexample
10103
10104With a pretty-printer for @code{std::string} only the contents are printed:
10105
10106@smallexample
10107(@value{GDBP}) print s
10108$2 = "abcd"
10109@end smallexample
10110
7b51bc51
DE
10111@node Pretty-Printer Commands
10112@subsection Pretty-Printer Commands
10113@cindex pretty-printer commands
10114
10115@table @code
10116@kindex info pretty-printer
10117@item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
10118Print the list of installed pretty-printers.
10119This includes disabled pretty-printers, which are marked as such.
10120
10121@var{object-regexp} is a regular expression matching the objects
10122whose pretty-printers to list.
10123Objects can be @code{global}, the program space's file
10124(@pxref{Progspaces In Python}),
10125and the object files within that program space (@pxref{Objfiles In Python}).
10126@xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
10127looks up a printer from these three objects.
10128
10129@var{name-regexp} is a regular expression matching the name of the printers
10130to list.
10131
10132@kindex disable pretty-printer
10133@item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
10134Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
10135A disabled pretty-printer is not forgotten, it may be enabled again later.
10136
10137@kindex enable pretty-printer
10138@item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
10139Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
10140@end table
10141
10142Example:
10143
10144Suppose we have three pretty-printers installed: one from library1.so
10145named @code{foo} that prints objects of type @code{foo}, and
10146another from library2.so named @code{bar} that prints two types of objects,
10147@code{bar1} and @code{bar2}.
10148
10149@smallexample
10150(gdb) info pretty-printer
10151library1.so:
10152 foo
10153library2.so:
10154 bar
10155 bar1
10156 bar2
10157(gdb) info pretty-printer library2
10158library2.so:
10159 bar
10160 bar1
10161 bar2
10162(gdb) disable pretty-printer library1
101631 printer disabled
101642 of 3 printers enabled
10165(gdb) info pretty-printer
10166library1.so:
10167 foo [disabled]
10168library2.so:
10169 bar
10170 bar1
10171 bar2
10172(gdb) disable pretty-printer library2 bar:bar1
101731 printer disabled
101741 of 3 printers enabled
10175(gdb) info pretty-printer library2
10176library1.so:
10177 foo [disabled]
10178library2.so:
10179 bar
10180 bar1 [disabled]
10181 bar2
10182(gdb) disable pretty-printer library2 bar
101831 printer disabled
101840 of 3 printers enabled
10185(gdb) info pretty-printer library2
10186library1.so:
10187 foo [disabled]
10188library2.so:
10189 bar [disabled]
10190 bar1 [disabled]
10191 bar2
10192@end smallexample
10193
10194Note that for @code{bar} the entire printer can be disabled,
10195as can each individual subprinter.
4c374409 10196
6d2ebf8b 10197@node Value History
79a6e687 10198@section Value History
c906108c
SS
10199
10200@cindex value history
9c16f35a 10201@cindex history of values printed by @value{GDBN}
5d161b24
DB
10202Values printed by the @code{print} command are saved in the @value{GDBN}
10203@dfn{value history}. This allows you to refer to them in other expressions.
10204Values are kept until the symbol table is re-read or discarded
10205(for example with the @code{file} or @code{symbol-file} commands).
10206When the symbol table changes, the value history is discarded,
10207since the values may contain pointers back to the types defined in the
c906108c
SS
10208symbol table.
10209
10210@cindex @code{$}
10211@cindex @code{$$}
10212@cindex history number
10213The values printed are given @dfn{history numbers} by which you can
10214refer to them. These are successive integers starting with one.
10215@code{print} shows you the history number assigned to a value by
10216printing @samp{$@var{num} = } before the value; here @var{num} is the
10217history number.
10218
10219To refer to any previous value, use @samp{$} followed by the value's
10220history number. The way @code{print} labels its output is designed to
10221remind you of this. Just @code{$} refers to the most recent value in
10222the history, and @code{$$} refers to the value before that.
10223@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
10224is the value just prior to @code{$$}, @code{$$1} is equivalent to
10225@code{$$}, and @code{$$0} is equivalent to @code{$}.
10226
10227For example, suppose you have just printed a pointer to a structure and
10228want to see the contents of the structure. It suffices to type
10229
474c8240 10230@smallexample
c906108c 10231p *$
474c8240 10232@end smallexample
c906108c
SS
10233
10234If you have a chain of structures where the component @code{next} points
10235to the next one, you can print the contents of the next one with this:
10236
474c8240 10237@smallexample
c906108c 10238p *$.next
474c8240 10239@end smallexample
c906108c
SS
10240
10241@noindent
10242You can print successive links in the chain by repeating this
10243command---which you can do by just typing @key{RET}.
10244
10245Note that the history records values, not expressions. If the value of
10246@code{x} is 4 and you type these commands:
10247
474c8240 10248@smallexample
c906108c
SS
10249print x
10250set x=5
474c8240 10251@end smallexample
c906108c
SS
10252
10253@noindent
10254then the value recorded in the value history by the @code{print} command
10255remains 4 even though the value of @code{x} has changed.
10256
10257@table @code
10258@kindex show values
10259@item show values
10260Print the last ten values in the value history, with their item numbers.
10261This is like @samp{p@ $$9} repeated ten times, except that @code{show
10262values} does not change the history.
10263
10264@item show values @var{n}
10265Print ten history values centered on history item number @var{n}.
10266
10267@item show values +
10268Print ten history values just after the values last printed. If no more
10269values are available, @code{show values +} produces no display.
10270@end table
10271
10272Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
10273same effect as @samp{show values +}.
10274
6d2ebf8b 10275@node Convenience Vars
79a6e687 10276@section Convenience Variables
c906108c
SS
10277
10278@cindex convenience variables
9c16f35a 10279@cindex user-defined variables
c906108c
SS
10280@value{GDBN} provides @dfn{convenience variables} that you can use within
10281@value{GDBN} to hold on to a value and refer to it later. These variables
10282exist entirely within @value{GDBN}; they are not part of your program, and
10283setting a convenience variable has no direct effect on further execution
10284of your program. That is why you can use them freely.
10285
10286Convenience variables are prefixed with @samp{$}. Any name preceded by
10287@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 10288the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c 10289(Value history references, in contrast, are @emph{numbers} preceded
79a6e687 10290by @samp{$}. @xref{Value History, ,Value History}.)
c906108c
SS
10291
10292You can save a value in a convenience variable with an assignment
10293expression, just as you would set a variable in your program.
10294For example:
10295
474c8240 10296@smallexample
c906108c 10297set $foo = *object_ptr
474c8240 10298@end smallexample
c906108c
SS
10299
10300@noindent
10301would save in @code{$foo} the value contained in the object pointed to by
10302@code{object_ptr}.
10303
10304Using a convenience variable for the first time creates it, but its
10305value is @code{void} until you assign a new value. You can alter the
10306value with another assignment at any time.
10307
10308Convenience variables have no fixed types. You can assign a convenience
10309variable any type of value, including structures and arrays, even if
10310that variable already has a value of a different type. The convenience
10311variable, when used as an expression, has the type of its current value.
10312
10313@table @code
10314@kindex show convenience
f47f77df 10315@cindex show all user variables and functions
c906108c 10316@item show convenience
f47f77df
DE
10317Print a list of convenience variables used so far, and their values,
10318as well as a list of the convenience functions.
d4f3574e 10319Abbreviated @code{show conv}.
53e5f3cf
AS
10320
10321@kindex init-if-undefined
10322@cindex convenience variables, initializing
10323@item init-if-undefined $@var{variable} = @var{expression}
10324Set a convenience variable if it has not already been set. This is useful
10325for user-defined commands that keep some state. It is similar, in concept,
10326to using local static variables with initializers in C (except that
10327convenience variables are global). It can also be used to allow users to
10328override default values used in a command script.
10329
10330If the variable is already defined then the expression is not evaluated so
10331any side-effects do not occur.
c906108c
SS
10332@end table
10333
10334One of the ways to use a convenience variable is as a counter to be
10335incremented or a pointer to be advanced. For example, to print
10336a field from successive elements of an array of structures:
10337
474c8240 10338@smallexample
c906108c
SS
10339set $i = 0
10340print bar[$i++]->contents
474c8240 10341@end smallexample
c906108c 10342
d4f3574e
SS
10343@noindent
10344Repeat that command by typing @key{RET}.
c906108c
SS
10345
10346Some convenience variables are created automatically by @value{GDBN} and given
10347values likely to be useful.
10348
10349@table @code
41afff9a 10350@vindex $_@r{, convenience variable}
c906108c
SS
10351@item $_
10352The variable @code{$_} is automatically set by the @code{x} command to
79a6e687 10353the last address examined (@pxref{Memory, ,Examining Memory}). Other
c906108c
SS
10354commands which provide a default address for @code{x} to examine also
10355set @code{$_} to that address; these commands include @code{info line}
10356and @code{info breakpoint}. The type of @code{$_} is @code{void *}
10357except when set by the @code{x} command, in which case it is a pointer
10358to the type of @code{$__}.
10359
41afff9a 10360@vindex $__@r{, convenience variable}
c906108c
SS
10361@item $__
10362The variable @code{$__} is automatically set by the @code{x} command
10363to the value found in the last address examined. Its type is chosen
10364to match the format in which the data was printed.
10365
10366@item $_exitcode
41afff9a 10367@vindex $_exitcode@r{, convenience variable}
0c557179
SDJ
10368When the program being debugged terminates normally, @value{GDBN}
10369automatically sets this variable to the exit code of the program, and
10370resets @code{$_exitsignal} to @code{void}.
10371
10372@item $_exitsignal
10373@vindex $_exitsignal@r{, convenience variable}
10374When the program being debugged dies due to an uncaught signal,
10375@value{GDBN} automatically sets this variable to that signal's number,
10376and resets @code{$_exitcode} to @code{void}.
10377
10378To distinguish between whether the program being debugged has exited
10379(i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
10380@code{$_exitsignal} is not @code{void}), the convenience function
10381@code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
10382Functions}). For example, considering the following source code:
10383
10384@smallexample
10385#include <signal.h>
10386
10387int
10388main (int argc, char *argv[])
10389@{
10390 raise (SIGALRM);
10391 return 0;
10392@}
10393@end smallexample
10394
10395A valid way of telling whether the program being debugged has exited
10396or signalled would be:
10397
10398@smallexample
10399(@value{GDBP}) define has_exited_or_signalled
10400Type commands for definition of ``has_exited_or_signalled''.
10401End with a line saying just ``end''.
10402>if $_isvoid ($_exitsignal)
10403 >echo The program has exited\n
10404 >else
10405 >echo The program has signalled\n
10406 >end
10407>end
10408(@value{GDBP}) run
10409Starting program:
10410
10411Program terminated with signal SIGALRM, Alarm clock.
10412The program no longer exists.
10413(@value{GDBP}) has_exited_or_signalled
10414The program has signalled
10415@end smallexample
10416
10417As can be seen, @value{GDBN} correctly informs that the program being
10418debugged has signalled, since it calls @code{raise} and raises a
10419@code{SIGALRM} signal. If the program being debugged had not called
10420@code{raise}, then @value{GDBN} would report a normal exit:
10421
10422@smallexample
10423(@value{GDBP}) has_exited_or_signalled
10424The program has exited
10425@end smallexample
4aa995e1 10426
72f1fe8a
TT
10427@item $_exception
10428The variable @code{$_exception} is set to the exception object being
10429thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
10430
62e5f89c
SDJ
10431@item $_probe_argc
10432@itemx $_probe_arg0@dots{}$_probe_arg11
10433Arguments to a static probe. @xref{Static Probe Points}.
10434
0fb4aa4b
PA
10435@item $_sdata
10436@vindex $_sdata@r{, inspect, convenience variable}
10437The variable @code{$_sdata} contains extra collected static tracepoint
10438data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
10439@code{$_sdata} could be empty, if not inspecting a trace buffer, or
10440if extra static tracepoint data has not been collected.
10441
4aa995e1
PA
10442@item $_siginfo
10443@vindex $_siginfo@r{, convenience variable}
ec7e75e7
PP
10444The variable @code{$_siginfo} contains extra signal information
10445(@pxref{extra signal information}). Note that @code{$_siginfo}
10446could be empty, if the application has not yet received any signals.
10447For example, it will be empty before you execute the @code{run} command.
711e434b
PM
10448
10449@item $_tlb
10450@vindex $_tlb@r{, convenience variable}
10451The variable @code{$_tlb} is automatically set when debugging
10452applications running on MS-Windows in native mode or connected to
10453gdbserver that supports the @code{qGetTIBAddr} request.
10454@xref{General Query Packets}.
10455This variable contains the address of the thread information block.
10456
e3940304
PA
10457@item $_inferior
10458The number of the current inferior. @xref{Inferiors and
10459Programs, ,Debugging Multiple Inferiors and Programs}.
10460
5d5658a1
PA
10461@item $_thread
10462The thread number of the current thread. @xref{thread numbers}.
10463
663f6d42
PA
10464@item $_gthread
10465The global number of the current thread. @xref{global thread numbers}.
10466
c906108c
SS
10467@end table
10468
a72c3253
DE
10469@node Convenience Funs
10470@section Convenience Functions
10471
bc3b79fd
TJB
10472@cindex convenience functions
10473@value{GDBN} also supplies some @dfn{convenience functions}. These
10474have a syntax similar to convenience variables. A convenience
10475function can be used in an expression just like an ordinary function;
10476however, a convenience function is implemented internally to
10477@value{GDBN}.
10478
a280dbd1
SDJ
10479These functions do not require @value{GDBN} to be configured with
10480@code{Python} support, which means that they are always available.
10481
10482@table @code
10483
10484@item $_isvoid (@var{expr})
10485@findex $_isvoid@r{, convenience function}
10486Return one if the expression @var{expr} is @code{void}. Otherwise it
10487returns zero.
10488
10489A @code{void} expression is an expression where the type of the result
10490is @code{void}. For example, you can examine a convenience variable
10491(see @ref{Convenience Vars,, Convenience Variables}) to check whether
10492it is @code{void}:
10493
10494@smallexample
10495(@value{GDBP}) print $_exitcode
10496$1 = void
10497(@value{GDBP}) print $_isvoid ($_exitcode)
10498$2 = 1
10499(@value{GDBP}) run
10500Starting program: ./a.out
10501[Inferior 1 (process 29572) exited normally]
10502(@value{GDBP}) print $_exitcode
10503$3 = 0
10504(@value{GDBP}) print $_isvoid ($_exitcode)
10505$4 = 0
10506@end smallexample
10507
10508In the example above, we used @code{$_isvoid} to check whether
10509@code{$_exitcode} is @code{void} before and after the execution of the
10510program being debugged. Before the execution there is no exit code to
10511be examined, therefore @code{$_exitcode} is @code{void}. After the
10512execution the program being debugged returned zero, therefore
10513@code{$_exitcode} is zero, which means that it is not @code{void}
10514anymore.
10515
10516The @code{void} expression can also be a call of a function from the
10517program being debugged. For example, given the following function:
10518
10519@smallexample
10520void
10521foo (void)
10522@{
10523@}
10524@end smallexample
10525
10526The result of calling it inside @value{GDBN} is @code{void}:
10527
10528@smallexample
10529(@value{GDBP}) print foo ()
10530$1 = void
10531(@value{GDBP}) print $_isvoid (foo ())
10532$2 = 1
10533(@value{GDBP}) set $v = foo ()
10534(@value{GDBP}) print $v
10535$3 = void
10536(@value{GDBP}) print $_isvoid ($v)
10537$4 = 1
10538@end smallexample
10539
10540@end table
10541
a72c3253
DE
10542These functions require @value{GDBN} to be configured with
10543@code{Python} support.
10544
10545@table @code
10546
10547@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
10548@findex $_memeq@r{, convenience function}
10549Returns one if the @var{length} bytes at the addresses given by
10550@var{buf1} and @var{buf2} are equal.
10551Otherwise it returns zero.
10552
10553@item $_regex(@var{str}, @var{regex})
10554@findex $_regex@r{, convenience function}
10555Returns one if the string @var{str} matches the regular expression
10556@var{regex}. Otherwise it returns zero.
10557The syntax of the regular expression is that specified by @code{Python}'s
10558regular expression support.
10559
10560@item $_streq(@var{str1}, @var{str2})
10561@findex $_streq@r{, convenience function}
10562Returns one if the strings @var{str1} and @var{str2} are equal.
10563Otherwise it returns zero.
10564
10565@item $_strlen(@var{str})
10566@findex $_strlen@r{, convenience function}
10567Returns the length of string @var{str}.
10568
faa42425
DE
10569@item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
10570@findex $_caller_is@r{, convenience function}
10571Returns one if the calling function's name is equal to @var{name}.
10572Otherwise it returns zero.
10573
10574If the optional argument @var{number_of_frames} is provided,
10575it is the number of frames up in the stack to look.
10576The default is 1.
10577
10578Example:
10579
10580@smallexample
10581(gdb) backtrace
10582#0 bottom_func ()
10583 at testsuite/gdb.python/py-caller-is.c:21
10584#1 0x00000000004005a0 in middle_func ()
10585 at testsuite/gdb.python/py-caller-is.c:27
10586#2 0x00000000004005ab in top_func ()
10587 at testsuite/gdb.python/py-caller-is.c:33
10588#3 0x00000000004005b6 in main ()
10589 at testsuite/gdb.python/py-caller-is.c:39
10590(gdb) print $_caller_is ("middle_func")
10591$1 = 1
10592(gdb) print $_caller_is ("top_func", 2)
10593$1 = 1
10594@end smallexample
10595
10596@item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
10597@findex $_caller_matches@r{, convenience function}
10598Returns one if the calling function's name matches the regular expression
10599@var{regexp}. Otherwise it returns zero.
10600
10601If the optional argument @var{number_of_frames} is provided,
10602it is the number of frames up in the stack to look.
10603The default is 1.
10604
10605@item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
10606@findex $_any_caller_is@r{, convenience function}
10607Returns one if any calling function's name is equal to @var{name}.
10608Otherwise it returns zero.
10609
10610If the optional argument @var{number_of_frames} is provided,
10611it is the number of frames up in the stack to look.
10612The default is 1.
10613
10614This function differs from @code{$_caller_is} in that this function
10615checks all stack frames from the immediate caller to the frame specified
10616by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
10617frame specified by @var{number_of_frames}.
10618
10619@item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
10620@findex $_any_caller_matches@r{, convenience function}
10621Returns one if any calling function's name matches the regular expression
10622@var{regexp}. Otherwise it returns zero.
10623
10624If the optional argument @var{number_of_frames} is provided,
10625it is the number of frames up in the stack to look.
10626The default is 1.
10627
10628This function differs from @code{$_caller_matches} in that this function
10629checks all stack frames from the immediate caller to the frame specified
10630by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
10631frame specified by @var{number_of_frames}.
10632
a72c3253
DE
10633@end table
10634
10635@value{GDBN} provides the ability to list and get help on
10636convenience functions.
10637
bc3b79fd
TJB
10638@table @code
10639@item help function
10640@kindex help function
10641@cindex show all convenience functions
10642Print a list of all convenience functions.
10643@end table
10644
6d2ebf8b 10645@node Registers
c906108c
SS
10646@section Registers
10647
10648@cindex registers
10649You can refer to machine register contents, in expressions, as variables
10650with names starting with @samp{$}. The names of registers are different
10651for each machine; use @code{info registers} to see the names used on
10652your machine.
10653
10654@table @code
10655@kindex info registers
10656@item info registers
10657Print the names and values of all registers except floating-point
c85508ee 10658and vector registers (in the selected stack frame).
c906108c
SS
10659
10660@kindex info all-registers
10661@cindex floating point registers
10662@item info all-registers
10663Print the names and values of all registers, including floating-point
c85508ee 10664and vector registers (in the selected stack frame).
c906108c
SS
10665
10666@item info registers @var{regname} @dots{}
10667Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24 10668As discussed in detail below, register values are normally relative to
697aa1b7 10669the selected stack frame. The @var{regname} may be any register name valid on
c906108c
SS
10670the machine you are using, with or without the initial @samp{$}.
10671@end table
10672
f5b95c01 10673@anchor{standard registers}
e09f16f9
EZ
10674@cindex stack pointer register
10675@cindex program counter register
10676@cindex process status register
10677@cindex frame pointer register
10678@cindex standard registers
c906108c
SS
10679@value{GDBN} has four ``standard'' register names that are available (in
10680expressions) on most machines---whenever they do not conflict with an
10681architecture's canonical mnemonics for registers. The register names
10682@code{$pc} and @code{$sp} are used for the program counter register and
10683the stack pointer. @code{$fp} is used for a register that contains a
10684pointer to the current stack frame, and @code{$ps} is used for a
10685register that contains the processor status. For example,
10686you could print the program counter in hex with
10687
474c8240 10688@smallexample
c906108c 10689p/x $pc
474c8240 10690@end smallexample
c906108c
SS
10691
10692@noindent
10693or print the instruction to be executed next with
10694
474c8240 10695@smallexample
c906108c 10696x/i $pc
474c8240 10697@end smallexample
c906108c
SS
10698
10699@noindent
10700or add four to the stack pointer@footnote{This is a way of removing
10701one word from the stack, on machines where stacks grow downward in
10702memory (most machines, nowadays). This assumes that the innermost
10703stack frame is selected; setting @code{$sp} is not allowed when other
10704stack frames are selected. To pop entire frames off the stack,
10705regardless of machine architecture, use @code{return};
79a6e687 10706see @ref{Returning, ,Returning from a Function}.} with
c906108c 10707
474c8240 10708@smallexample
c906108c 10709set $sp += 4
474c8240 10710@end smallexample
c906108c
SS
10711
10712Whenever possible, these four standard register names are available on
10713your machine even though the machine has different canonical mnemonics,
10714so long as there is no conflict. The @code{info registers} command
10715shows the canonical names. For example, on the SPARC, @code{info
10716registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
10717can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
10718is an alias for the @sc{eflags} register.
c906108c
SS
10719
10720@value{GDBN} always considers the contents of an ordinary register as an
10721integer when the register is examined in this way. Some machines have
10722special registers which can hold nothing but floating point; these
10723registers are considered to have floating point values. There is no way
10724to refer to the contents of an ordinary register as floating point value
10725(although you can @emph{print} it as a floating point value with
10726@samp{print/f $@var{regname}}).
10727
10728Some registers have distinct ``raw'' and ``virtual'' data formats. This
10729means that the data format in which the register contents are saved by
10730the operating system is not the same one that your program normally
10731sees. For example, the registers of the 68881 floating point
10732coprocessor are always saved in ``extended'' (raw) format, but all C
10733programs expect to work with ``double'' (virtual) format. In such
5d161b24 10734cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
10735that makes sense for your program), but the @code{info registers} command
10736prints the data in both formats.
10737
36b80e65
EZ
10738@cindex SSE registers (x86)
10739@cindex MMX registers (x86)
10740Some machines have special registers whose contents can be interpreted
10741in several different ways. For example, modern x86-based machines
10742have SSE and MMX registers that can hold several values packed
10743together in several different formats. @value{GDBN} refers to such
10744registers in @code{struct} notation:
10745
10746@smallexample
10747(@value{GDBP}) print $xmm1
10748$1 = @{
10749 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
10750 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
10751 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
10752 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
10753 v4_int32 = @{0, 20657912, 11, 13@},
10754 v2_int64 = @{88725056443645952, 55834574859@},
10755 uint128 = 0x0000000d0000000b013b36f800000000
10756@}
10757@end smallexample
10758
10759@noindent
10760To set values of such registers, you need to tell @value{GDBN} which
10761view of the register you wish to change, as if you were assigning
10762value to a @code{struct} member:
10763
10764@smallexample
10765 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
10766@end smallexample
10767
c906108c 10768Normally, register values are relative to the selected stack frame
79a6e687 10769(@pxref{Selection, ,Selecting a Frame}). This means that you get the
c906108c
SS
10770value that the register would contain if all stack frames farther in
10771were exited and their saved registers restored. In order to see the
10772true contents of hardware registers, you must select the innermost
10773frame (with @samp{frame 0}).
10774
901461f8
PA
10775@cindex caller-saved registers
10776@cindex call-clobbered registers
10777@cindex volatile registers
10778@cindex <not saved> values
10779Usually ABIs reserve some registers as not needed to be saved by the
10780callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
10781registers). It may therefore not be possible for @value{GDBN} to know
10782the value a register had before the call (in other words, in the outer
10783frame), if the register value has since been changed by the callee.
10784@value{GDBN} tries to deduce where the inner frame saved
10785(``callee-saved'') registers, from the debug info, unwind info, or the
10786machine code generated by your compiler. If some register is not
10787saved, and @value{GDBN} knows the register is ``caller-saved'' (via
10788its own knowledge of the ABI, or because the debug/unwind info
10789explicitly says the register's value is undefined), @value{GDBN}
10790displays @w{@samp{<not saved>}} as the register's value. With targets
10791that @value{GDBN} has no knowledge of the register saving convention,
10792if a register was not saved by the callee, then its value and location
10793in the outer frame are assumed to be the same of the inner frame.
10794This is usually harmless, because if the register is call-clobbered,
10795the caller either does not care what is in the register after the
10796call, or has code to restore the value that it does care about. Note,
10797however, that if you change such a register in the outer frame, you
10798may also be affecting the inner frame. Also, the more ``outer'' the
10799frame is you're looking at, the more likely a call-clobbered
10800register's value is to be wrong, in the sense that it doesn't actually
10801represent the value the register had just before the call.
c906108c 10802
6d2ebf8b 10803@node Floating Point Hardware
79a6e687 10804@section Floating Point Hardware
c906108c
SS
10805@cindex floating point
10806
10807Depending on the configuration, @value{GDBN} may be able to give
10808you more information about the status of the floating point hardware.
10809
10810@table @code
10811@kindex info float
10812@item info float
10813Display hardware-dependent information about the floating
10814point unit. The exact contents and layout vary depending on the
10815floating point chip. Currently, @samp{info float} is supported on
10816the ARM and x86 machines.
10817@end table
c906108c 10818
e76f1f2e
AC
10819@node Vector Unit
10820@section Vector Unit
10821@cindex vector unit
10822
10823Depending on the configuration, @value{GDBN} may be able to give you
10824more information about the status of the vector unit.
10825
10826@table @code
10827@kindex info vector
10828@item info vector
10829Display information about the vector unit. The exact contents and
10830layout vary depending on the hardware.
10831@end table
10832
721c2651 10833@node OS Information
79a6e687 10834@section Operating System Auxiliary Information
721c2651
EZ
10835@cindex OS information
10836
10837@value{GDBN} provides interfaces to useful OS facilities that can help
10838you debug your program.
10839
b383017d
RM
10840@cindex auxiliary vector
10841@cindex vector, auxiliary
b383017d
RM
10842Some operating systems supply an @dfn{auxiliary vector} to programs at
10843startup. This is akin to the arguments and environment that you
10844specify for a program, but contains a system-dependent variety of
10845binary values that tell system libraries important details about the
10846hardware, operating system, and process. Each value's purpose is
10847identified by an integer tag; the meanings are well-known but system-specific.
10848Depending on the configuration and operating system facilities,
9c16f35a
EZ
10849@value{GDBN} may be able to show you this information. For remote
10850targets, this functionality may further depend on the remote stub's
427c3a89
DJ
10851support of the @samp{qXfer:auxv:read} packet, see
10852@ref{qXfer auxiliary vector read}.
b383017d
RM
10853
10854@table @code
10855@kindex info auxv
10856@item info auxv
10857Display the auxiliary vector of the inferior, which can be either a
e4937fc1 10858live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
10859numerically, and also shows names and text descriptions for recognized
10860tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 10861pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
10862most appropriate form for a recognized tag, and in hexadecimal for
10863an unrecognized tag.
10864@end table
10865
85d4a676
SS
10866On some targets, @value{GDBN} can access operating system-specific
10867information and show it to you. The types of information available
10868will differ depending on the type of operating system running on the
10869target. The mechanism used to fetch the data is described in
10870@ref{Operating System Information}. For remote targets, this
10871functionality depends on the remote stub's support of the
07e059b5
VP
10872@samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
10873
10874@table @code
a61408f8 10875@kindex info os
85d4a676
SS
10876@item info os @var{infotype}
10877
10878Display OS information of the requested type.
a61408f8 10879
85d4a676
SS
10880On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
10881
10882@anchor{linux info os infotypes}
10883@table @code
d33279b3
AT
10884@kindex info os cpus
10885@item cpus
10886Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
10887the available fields from /proc/cpuinfo. For each supported architecture
10888different fields are available. Two common entries are processor which gives
10889CPU number and bogomips; a system constant that is calculated during
10890kernel initialization.
10891
10892@kindex info os files
10893@item files
10894Display the list of open file descriptors on the target. For each
10895file descriptor, @value{GDBN} prints the identifier of the process
10896owning the descriptor, the command of the owning process, the value
10897of the descriptor, and the target of the descriptor.
10898
10899@kindex info os modules
10900@item modules
10901Display the list of all loaded kernel modules on the target. For each
10902module, @value{GDBN} prints the module name, the size of the module in
10903bytes, the number of times the module is used, the dependencies of the
10904module, the status of the module, and the address of the loaded module
10905in memory.
10906
10907@kindex info os msg
10908@item msg
10909Display the list of all System V message queues on the target. For each
10910message queue, @value{GDBN} prints the message queue key, the message
10911queue identifier, the access permissions, the current number of bytes
10912on the queue, the current number of messages on the queue, the processes
10913that last sent and received a message on the queue, the user and group
10914of the owner and creator of the message queue, the times at which a
10915message was last sent and received on the queue, and the time at which
10916the message queue was last changed.
10917
07e059b5 10918@kindex info os processes
85d4a676 10919@item processes
07e059b5 10920Display the list of processes on the target. For each process,
85d4a676
SS
10921@value{GDBN} prints the process identifier, the name of the user, the
10922command corresponding to the process, and the list of processor cores
10923that the process is currently running on. (To understand what these
10924properties mean, for this and the following info types, please consult
10925the general @sc{gnu}/Linux documentation.)
10926
10927@kindex info os procgroups
10928@item procgroups
10929Display the list of process groups on the target. For each process,
10930@value{GDBN} prints the identifier of the process group that it belongs
10931to, the command corresponding to the process group leader, the process
10932identifier, and the command line of the process. The list is sorted
10933first by the process group identifier, then by the process identifier,
10934so that processes belonging to the same process group are grouped together
10935and the process group leader is listed first.
10936
d33279b3
AT
10937@kindex info os semaphores
10938@item semaphores
10939Display the list of all System V semaphore sets on the target. For each
10940semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
10941set identifier, the access permissions, the number of semaphores in the
10942set, the user and group of the owner and creator of the semaphore set,
10943and the times at which the semaphore set was operated upon and changed.
85d4a676
SS
10944
10945@kindex info os shm
10946@item shm
10947Display the list of all System V shared-memory regions on the target.
10948For each shared-memory region, @value{GDBN} prints the region key,
10949the shared-memory identifier, the access permissions, the size of the
10950region, the process that created the region, the process that last
10951attached to or detached from the region, the current number of live
10952attaches to the region, and the times at which the region was last
10953attached to, detach from, and changed.
10954
d33279b3
AT
10955@kindex info os sockets
10956@item sockets
10957Display the list of Internet-domain sockets on the target. For each
10958socket, @value{GDBN} prints the address and port of the local and
10959remote endpoints, the current state of the connection, the creator of
10960the socket, the IP address family of the socket, and the type of the
10961connection.
85d4a676 10962
d33279b3
AT
10963@kindex info os threads
10964@item threads
10965Display the list of threads running on the target. For each thread,
10966@value{GDBN} prints the identifier of the process that the thread
10967belongs to, the command of the process, the thread identifier, and the
10968processor core that it is currently running on. The main thread of a
10969process is not listed.
85d4a676
SS
10970@end table
10971
10972@item info os
10973If @var{infotype} is omitted, then list the possible values for
10974@var{infotype} and the kind of OS information available for each
10975@var{infotype}. If the target does not return a list of possible
10976types, this command will report an error.
07e059b5 10977@end table
721c2651 10978
29e57380 10979@node Memory Region Attributes
79a6e687 10980@section Memory Region Attributes
29e57380
C
10981@cindex memory region attributes
10982
b383017d 10983@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
10984required by regions of your target's memory. @value{GDBN} uses
10985attributes to determine whether to allow certain types of memory
10986accesses; whether to use specific width accesses; and whether to cache
10987target memory. By default the description of memory regions is
10988fetched from the target (if the current target supports this), but the
10989user can override the fetched regions.
29e57380
C
10990
10991Defined memory regions can be individually enabled and disabled. When a
10992memory region is disabled, @value{GDBN} uses the default attributes when
10993accessing memory in that region. Similarly, if no memory regions have
10994been defined, @value{GDBN} uses the default attributes when accessing
10995all memory.
10996
b383017d 10997When a memory region is defined, it is given a number to identify it;
29e57380
C
10998to enable, disable, or remove a memory region, you specify that number.
10999
11000@table @code
11001@kindex mem
bfac230e 11002@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
11003Define a memory region bounded by @var{lower} and @var{upper} with
11004attributes @var{attributes}@dots{}, and add it to the list of regions
11005monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
d3e8051b 11006case: it is treated as the target's maximum memory address.
bfac230e 11007(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 11008
fd79ecee
DJ
11009@item mem auto
11010Discard any user changes to the memory regions and use target-supplied
11011regions, if available, or no regions if the target does not support.
11012
29e57380
C
11013@kindex delete mem
11014@item delete mem @var{nums}@dots{}
09d4efe1
EZ
11015Remove memory regions @var{nums}@dots{} from the list of regions
11016monitored by @value{GDBN}.
29e57380
C
11017
11018@kindex disable mem
11019@item disable mem @var{nums}@dots{}
09d4efe1 11020Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 11021A disabled memory region is not forgotten.
29e57380
C
11022It may be enabled again later.
11023
11024@kindex enable mem
11025@item enable mem @var{nums}@dots{}
09d4efe1 11026Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
11027
11028@kindex info mem
11029@item info mem
11030Print a table of all defined memory regions, with the following columns
09d4efe1 11031for each region:
29e57380
C
11032
11033@table @emph
11034@item Memory Region Number
11035@item Enabled or Disabled.
b383017d 11036Enabled memory regions are marked with @samp{y}.
29e57380
C
11037Disabled memory regions are marked with @samp{n}.
11038
11039@item Lo Address
11040The address defining the inclusive lower bound of the memory region.
11041
11042@item Hi Address
11043The address defining the exclusive upper bound of the memory region.
11044
11045@item Attributes
11046The list of attributes set for this memory region.
11047@end table
11048@end table
11049
11050
11051@subsection Attributes
11052
b383017d 11053@subsubsection Memory Access Mode
29e57380
C
11054The access mode attributes set whether @value{GDBN} may make read or
11055write accesses to a memory region.
11056
11057While these attributes prevent @value{GDBN} from performing invalid
11058memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 11059etc.@: from accessing memory.
29e57380
C
11060
11061@table @code
11062@item ro
11063Memory is read only.
11064@item wo
11065Memory is write only.
11066@item rw
6ca652b0 11067Memory is read/write. This is the default.
29e57380
C
11068@end table
11069
11070@subsubsection Memory Access Size
d3e8051b 11071The access size attribute tells @value{GDBN} to use specific sized
29e57380
C
11072accesses in the memory region. Often memory mapped device registers
11073require specific sized accesses. If no access size attribute is
11074specified, @value{GDBN} may use accesses of any size.
11075
11076@table @code
11077@item 8
11078Use 8 bit memory accesses.
11079@item 16
11080Use 16 bit memory accesses.
11081@item 32
11082Use 32 bit memory accesses.
11083@item 64
11084Use 64 bit memory accesses.
11085@end table
11086
11087@c @subsubsection Hardware/Software Breakpoints
11088@c The hardware/software breakpoint attributes set whether @value{GDBN}
11089@c will use hardware or software breakpoints for the internal breakpoints
11090@c used by the step, next, finish, until, etc. commands.
11091@c
11092@c @table @code
11093@c @item hwbreak
b383017d 11094@c Always use hardware breakpoints
29e57380
C
11095@c @item swbreak (default)
11096@c @end table
11097
11098@subsubsection Data Cache
11099The data cache attributes set whether @value{GDBN} will cache target
11100memory. While this generally improves performance by reducing debug
11101protocol overhead, it can lead to incorrect results because @value{GDBN}
11102does not know about volatile variables or memory mapped device
11103registers.
11104
11105@table @code
11106@item cache
b383017d 11107Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
11108@item nocache
11109Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
11110@end table
11111
4b5752d0
VP
11112@subsection Memory Access Checking
11113@value{GDBN} can be instructed to refuse accesses to memory that is
11114not explicitly described. This can be useful if accessing such
11115regions has undesired effects for a specific target, or to provide
11116better error checking. The following commands control this behaviour.
11117
11118@table @code
11119@kindex set mem inaccessible-by-default
11120@item set mem inaccessible-by-default [on|off]
11121If @code{on} is specified, make @value{GDBN} treat memory not
11122explicitly described by the memory ranges as non-existent and refuse accesses
11123to such memory. The checks are only performed if there's at least one
11124memory range defined. If @code{off} is specified, make @value{GDBN}
11125treat the memory not explicitly described by the memory ranges as RAM.
56cf5405 11126The default value is @code{on}.
4b5752d0
VP
11127@kindex show mem inaccessible-by-default
11128@item show mem inaccessible-by-default
11129Show the current handling of accesses to unknown memory.
11130@end table
11131
11132
29e57380 11133@c @subsubsection Memory Write Verification
b383017d 11134@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
11135@c will re-reads data after each write to verify the write was successful.
11136@c
11137@c @table @code
11138@c @item verify
11139@c @item noverify (default)
11140@c @end table
11141
16d9dec6 11142@node Dump/Restore Files
79a6e687 11143@section Copy Between Memory and a File
16d9dec6
MS
11144@cindex dump/restore files
11145@cindex append data to a file
11146@cindex dump data to a file
11147@cindex restore data from a file
16d9dec6 11148
df5215a6
JB
11149You can use the commands @code{dump}, @code{append}, and
11150@code{restore} to copy data between target memory and a file. The
11151@code{dump} and @code{append} commands write data to a file, and the
11152@code{restore} command reads data from a file back into the inferior's
cf75d6c3
AB
11153memory. Files may be in binary, Motorola S-record, Intel hex,
11154Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
11155append to binary files, and cannot read from Verilog Hex files.
df5215a6
JB
11156
11157@table @code
11158
11159@kindex dump
11160@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
11161@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
11162Dump the contents of memory from @var{start_addr} to @var{end_addr},
11163or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 11164
df5215a6 11165The @var{format} parameter may be any one of:
16d9dec6 11166@table @code
df5215a6
JB
11167@item binary
11168Raw binary form.
11169@item ihex
11170Intel hex format.
11171@item srec
11172Motorola S-record format.
11173@item tekhex
11174Tektronix Hex format.
cf75d6c3
AB
11175@item verilog
11176Verilog Hex format.
df5215a6
JB
11177@end table
11178
11179@value{GDBN} uses the same definitions of these formats as the
11180@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
11181@var{format} is omitted, @value{GDBN} dumps the data in raw binary
11182form.
11183
11184@kindex append
11185@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
11186@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
11187Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 11188or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
11189(@value{GDBN} can only append data to files in raw binary form.)
11190
11191@kindex restore
11192@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
11193Restore the contents of file @var{filename} into memory. The
11194@code{restore} command can automatically recognize any known @sc{bfd}
11195file format, except for raw binary. To restore a raw binary file you
11196must specify the optional keyword @code{binary} after the filename.
16d9dec6 11197
b383017d 11198If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
11199contained in the file. Binary files always start at address zero, so
11200they will be restored at address @var{bias}. Other bfd files have
11201a built-in location; they will be restored at offset @var{bias}
11202from that location.
11203
11204If @var{start} and/or @var{end} are non-zero, then only data between
11205file offset @var{start} and file offset @var{end} will be restored.
b383017d 11206These offsets are relative to the addresses in the file, before
16d9dec6
MS
11207the @var{bias} argument is applied.
11208
11209@end table
11210
384ee23f
EZ
11211@node Core File Generation
11212@section How to Produce a Core File from Your Program
11213@cindex dump core from inferior
11214
11215A @dfn{core file} or @dfn{core dump} is a file that records the memory
11216image of a running process and its process status (register values
11217etc.). Its primary use is post-mortem debugging of a program that
11218crashed while it ran outside a debugger. A program that crashes
11219automatically produces a core file, unless this feature is disabled by
11220the user. @xref{Files}, for information on invoking @value{GDBN} in
11221the post-mortem debugging mode.
11222
11223Occasionally, you may wish to produce a core file of the program you
11224are debugging in order to preserve a snapshot of its state.
11225@value{GDBN} has a special command for that.
11226
11227@table @code
11228@kindex gcore
11229@kindex generate-core-file
11230@item generate-core-file [@var{file}]
11231@itemx gcore [@var{file}]
11232Produce a core dump of the inferior process. The optional argument
11233@var{file} specifies the file name where to put the core dump. If not
11234specified, the file name defaults to @file{core.@var{pid}}, where
11235@var{pid} is the inferior process ID.
11236
11237Note that this command is implemented only for some systems (as of
05b4bd79 11238this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
df8411da
SDJ
11239
11240On @sc{gnu}/Linux, this command can take into account the value of the
11241file @file{/proc/@var{pid}/coredump_filter} when generating the core
11242dump (@pxref{set use-coredump-filter}).
11243
11244@kindex set use-coredump-filter
11245@anchor{set use-coredump-filter}
11246@item set use-coredump-filter on
11247@itemx set use-coredump-filter off
11248Enable or disable the use of the file
11249@file{/proc/@var{pid}/coredump_filter} when generating core dump
11250files. This file is used by the Linux kernel to decide what types of
11251memory mappings will be dumped or ignored when generating a core dump
11252file. @var{pid} is the process ID of a currently running process.
11253
11254To make use of this feature, you have to write in the
11255@file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
11256which is a bit mask representing the memory mapping types. If a bit
11257is set in the bit mask, then the memory mappings of the corresponding
11258types will be dumped; otherwise, they will be ignored. This
11259configuration is inherited by child processes. For more information
11260about the bits that can be set in the
11261@file{/proc/@var{pid}/coredump_filter} file, please refer to the
11262manpage of @code{core(5)}.
11263
11264By default, this option is @code{on}. If this option is turned
11265@code{off}, @value{GDBN} does not read the @file{coredump_filter} file
11266and instead uses the same default value as the Linux kernel in order
11267to decide which pages will be dumped in the core dump file. This
11268value is currently @code{0x33}, which means that bits @code{0}
11269(anonymous private mappings), @code{1} (anonymous shared mappings),
11270@code{4} (ELF headers) and @code{5} (private huge pages) are active.
11271This will cause these memory mappings to be dumped automatically.
384ee23f
EZ
11272@end table
11273
a0eb71c5
KB
11274@node Character Sets
11275@section Character Sets
11276@cindex character sets
11277@cindex charset
11278@cindex translating between character sets
11279@cindex host character set
11280@cindex target character set
11281
11282If the program you are debugging uses a different character set to
11283represent characters and strings than the one @value{GDBN} uses itself,
11284@value{GDBN} can automatically translate between the character sets for
11285you. The character set @value{GDBN} uses we call the @dfn{host
11286character set}; the one the inferior program uses we call the
11287@dfn{target character set}.
11288
11289For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
11290uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
ea35711c 11291remote protocol (@pxref{Remote Debugging}) to debug a program
a0eb71c5
KB
11292running on an IBM mainframe, which uses the @sc{ebcdic} character set,
11293then the host character set is Latin-1, and the target character set is
11294@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 11295target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
11296@sc{ebcdic} and Latin 1 as you print character or string values, or use
11297character and string literals in expressions.
11298
11299@value{GDBN} has no way to automatically recognize which character set
11300the inferior program uses; you must tell it, using the @code{set
11301target-charset} command, described below.
11302
11303Here are the commands for controlling @value{GDBN}'s character set
11304support:
11305
11306@table @code
11307@item set target-charset @var{charset}
11308@kindex set target-charset
10af6951
EZ
11309Set the current target character set to @var{charset}. To display the
11310list of supported target character sets, type
11311@kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
a0eb71c5 11312
a0eb71c5
KB
11313@item set host-charset @var{charset}
11314@kindex set host-charset
11315Set the current host character set to @var{charset}.
11316
11317By default, @value{GDBN} uses a host character set appropriate to the
11318system it is running on; you can override that default using the
732f6a93
TT
11319@code{set host-charset} command. On some systems, @value{GDBN} cannot
11320automatically determine the appropriate host character set. In this
11321case, @value{GDBN} uses @samp{UTF-8}.
a0eb71c5
KB
11322
11323@value{GDBN} can only use certain character sets as its host character
c1b6b909 11324set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
10af6951 11325@value{GDBN} will list the host character sets it supports.
a0eb71c5
KB
11326
11327@item set charset @var{charset}
11328@kindex set charset
e33d66ec 11329Set the current host and target character sets to @var{charset}. As
10af6951
EZ
11330above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
11331@value{GDBN} will list the names of the character sets that can be used
e33d66ec
EZ
11332for both host and target.
11333
a0eb71c5 11334@item show charset
a0eb71c5 11335@kindex show charset
10af6951 11336Show the names of the current host and target character sets.
e33d66ec 11337
10af6951 11338@item show host-charset
a0eb71c5 11339@kindex show host-charset
10af6951 11340Show the name of the current host character set.
e33d66ec 11341
10af6951 11342@item show target-charset
a0eb71c5 11343@kindex show target-charset
10af6951 11344Show the name of the current target character set.
a0eb71c5 11345
10af6951
EZ
11346@item set target-wide-charset @var{charset}
11347@kindex set target-wide-charset
11348Set the current target's wide character set to @var{charset}. This is
11349the character set used by the target's @code{wchar_t} type. To
11350display the list of supported wide character sets, type
11351@kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
11352
11353@item show target-wide-charset
11354@kindex show target-wide-charset
11355Show the name of the current target's wide character set.
a0eb71c5
KB
11356@end table
11357
a0eb71c5
KB
11358Here is an example of @value{GDBN}'s character set support in action.
11359Assume that the following source code has been placed in the file
11360@file{charset-test.c}:
11361
11362@smallexample
11363#include <stdio.h>
11364
11365char ascii_hello[]
11366 = @{72, 101, 108, 108, 111, 44, 32, 119,
11367 111, 114, 108, 100, 33, 10, 0@};
11368char ibm1047_hello[]
11369 = @{200, 133, 147, 147, 150, 107, 64, 166,
11370 150, 153, 147, 132, 90, 37, 0@};
11371
11372main ()
11373@{
11374 printf ("Hello, world!\n");
11375@}
10998722 11376@end smallexample
a0eb71c5
KB
11377
11378In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
11379containing the string @samp{Hello, world!} followed by a newline,
11380encoded in the @sc{ascii} and @sc{ibm1047} character sets.
11381
11382We compile the program, and invoke the debugger on it:
11383
11384@smallexample
11385$ gcc -g charset-test.c -o charset-test
11386$ gdb -nw charset-test
11387GNU gdb 2001-12-19-cvs
11388Copyright 2001 Free Software Foundation, Inc.
11389@dots{}
f7dc1244 11390(@value{GDBP})
10998722 11391@end smallexample
a0eb71c5
KB
11392
11393We can use the @code{show charset} command to see what character sets
11394@value{GDBN} is currently using to interpret and display characters and
11395strings:
11396
11397@smallexample
f7dc1244 11398(@value{GDBP}) show charset
e33d66ec 11399The current host and target character set is `ISO-8859-1'.
f7dc1244 11400(@value{GDBP})
10998722 11401@end smallexample
a0eb71c5
KB
11402
11403For the sake of printing this manual, let's use @sc{ascii} as our
11404initial character set:
11405@smallexample
f7dc1244
EZ
11406(@value{GDBP}) set charset ASCII
11407(@value{GDBP}) show charset
e33d66ec 11408The current host and target character set is `ASCII'.
f7dc1244 11409(@value{GDBP})
10998722 11410@end smallexample
a0eb71c5
KB
11411
11412Let's assume that @sc{ascii} is indeed the correct character set for our
11413host system --- in other words, let's assume that if @value{GDBN} prints
11414characters using the @sc{ascii} character set, our terminal will display
11415them properly. Since our current target character set is also
11416@sc{ascii}, the contents of @code{ascii_hello} print legibly:
11417
11418@smallexample
f7dc1244 11419(@value{GDBP}) print ascii_hello
a0eb71c5 11420$1 = 0x401698 "Hello, world!\n"
f7dc1244 11421(@value{GDBP}) print ascii_hello[0]
a0eb71c5 11422$2 = 72 'H'
f7dc1244 11423(@value{GDBP})
10998722 11424@end smallexample
a0eb71c5
KB
11425
11426@value{GDBN} uses the target character set for character and string
11427literals you use in expressions:
11428
11429@smallexample
f7dc1244 11430(@value{GDBP}) print '+'
a0eb71c5 11431$3 = 43 '+'
f7dc1244 11432(@value{GDBP})
10998722 11433@end smallexample
a0eb71c5
KB
11434
11435The @sc{ascii} character set uses the number 43 to encode the @samp{+}
11436character.
11437
11438@value{GDBN} relies on the user to tell it which character set the
11439target program uses. If we print @code{ibm1047_hello} while our target
11440character set is still @sc{ascii}, we get jibberish:
11441
11442@smallexample
f7dc1244 11443(@value{GDBP}) print ibm1047_hello
a0eb71c5 11444$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 11445(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 11446$5 = 200 '\310'
f7dc1244 11447(@value{GDBP})
10998722 11448@end smallexample
a0eb71c5 11449
e33d66ec 11450If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
11451@value{GDBN} tells us the character sets it supports:
11452
11453@smallexample
f7dc1244 11454(@value{GDBP}) set target-charset
b383017d 11455ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 11456(@value{GDBP}) set target-charset
10998722 11457@end smallexample
a0eb71c5
KB
11458
11459We can select @sc{ibm1047} as our target character set, and examine the
11460program's strings again. Now the @sc{ascii} string is wrong, but
11461@value{GDBN} translates the contents of @code{ibm1047_hello} from the
11462target character set, @sc{ibm1047}, to the host character set,
11463@sc{ascii}, and they display correctly:
11464
11465@smallexample
f7dc1244
EZ
11466(@value{GDBP}) set target-charset IBM1047
11467(@value{GDBP}) show charset
e33d66ec
EZ
11468The current host character set is `ASCII'.
11469The current target character set is `IBM1047'.
f7dc1244 11470(@value{GDBP}) print ascii_hello
a0eb71c5 11471$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 11472(@value{GDBP}) print ascii_hello[0]
a0eb71c5 11473$7 = 72 '\110'
f7dc1244 11474(@value{GDBP}) print ibm1047_hello
a0eb71c5 11475$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 11476(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 11477$9 = 200 'H'
f7dc1244 11478(@value{GDBP})
10998722 11479@end smallexample
a0eb71c5
KB
11480
11481As above, @value{GDBN} uses the target character set for character and
11482string literals you use in expressions:
11483
11484@smallexample
f7dc1244 11485(@value{GDBP}) print '+'
a0eb71c5 11486$10 = 78 '+'
f7dc1244 11487(@value{GDBP})
10998722 11488@end smallexample
a0eb71c5 11489
e33d66ec 11490The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
11491character.
11492
b12039c6
YQ
11493@node Caching Target Data
11494@section Caching Data of Targets
11495@cindex caching data of targets
11496
11497@value{GDBN} caches data exchanged between the debugger and a target.
b26dfc9a
YQ
11498Each cache is associated with the address space of the inferior.
11499@xref{Inferiors and Programs}, about inferior and address space.
b12039c6
YQ
11500Such caching generally improves performance in remote debugging
11501(@pxref{Remote Debugging}), because it reduces the overhead of the
11502remote protocol by bundling memory reads and writes into large chunks.
11503Unfortunately, simply caching everything would lead to incorrect results,
11504since @value{GDBN} does not necessarily know anything about volatile
11505values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
11506(@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
11507is executing.
29b090c0
DE
11508Therefore, by default, @value{GDBN} only caches data
11509known to be on the stack@footnote{In non-stop mode, it is moderately
11510rare for a running thread to modify the stack of a stopped thread
11511in a way that would interfere with a backtrace, and caching of
29453a14
YQ
11512stack reads provides a significant speed up of remote backtraces.} or
11513in the code segment.
29b090c0 11514Other regions of memory can be explicitly marked as
27b81af3 11515cacheable; @pxref{Memory Region Attributes}.
09d4efe1
EZ
11516
11517@table @code
11518@kindex set remotecache
11519@item set remotecache on
11520@itemx set remotecache off
4e5d721f
DE
11521This option no longer does anything; it exists for compatibility
11522with old scripts.
09d4efe1
EZ
11523
11524@kindex show remotecache
11525@item show remotecache
4e5d721f
DE
11526Show the current state of the obsolete remotecache flag.
11527
11528@kindex set stack-cache
11529@item set stack-cache on
11530@itemx set stack-cache off
6dd315ba
YQ
11531Enable or disable caching of stack accesses. When @code{on}, use
11532caching. By default, this option is @code{on}.
4e5d721f
DE
11533
11534@kindex show stack-cache
11535@item show stack-cache
11536Show the current state of data caching for memory accesses.
09d4efe1 11537
29453a14
YQ
11538@kindex set code-cache
11539@item set code-cache on
11540@itemx set code-cache off
11541Enable or disable caching of code segment accesses. When @code{on},
11542use caching. By default, this option is @code{on}. This improves
11543performance of disassembly in remote debugging.
11544
11545@kindex show code-cache
11546@item show code-cache
11547Show the current state of target memory cache for code segment
11548accesses.
11549
09d4efe1 11550@kindex info dcache
4e5d721f 11551@item info dcache @r{[}line@r{]}
b26dfc9a
YQ
11552Print the information about the performance of data cache of the
11553current inferior's address space. The information displayed
11554includes the dcache width and depth, and for each cache line, its
11555number, address, and how many times it was referenced. This
11556command is useful for debugging the data cache operation.
4e5d721f
DE
11557
11558If a line number is specified, the contents of that line will be
11559printed in hex.
1a532630
PP
11560
11561@item set dcache size @var{size}
11562@cindex dcache size
11563@kindex set dcache size
11564Set maximum number of entries in dcache (dcache depth above).
11565
11566@item set dcache line-size @var{line-size}
11567@cindex dcache line-size
11568@kindex set dcache line-size
11569Set number of bytes each dcache entry caches (dcache width above).
11570Must be a power of 2.
11571
11572@item show dcache size
11573@kindex show dcache size
b12039c6 11574Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
1a532630
PP
11575
11576@item show dcache line-size
11577@kindex show dcache line-size
b12039c6 11578Show default size of dcache lines.
1a532630 11579
09d4efe1
EZ
11580@end table
11581
08388c79
DE
11582@node Searching Memory
11583@section Search Memory
11584@cindex searching memory
11585
11586Memory can be searched for a particular sequence of bytes with the
11587@code{find} command.
11588
11589@table @code
11590@kindex find
11591@item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
11592@itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
11593Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
11594etc. The search begins at address @var{start_addr} and continues for either
11595@var{len} bytes or through to @var{end_addr} inclusive.
11596@end table
11597
11598@var{s} and @var{n} are optional parameters.
11599They may be specified in either order, apart or together.
11600
11601@table @r
11602@item @var{s}, search query size
11603The size of each search query value.
11604
11605@table @code
11606@item b
11607bytes
11608@item h
11609halfwords (two bytes)
11610@item w
11611words (four bytes)
11612@item g
11613giant words (eight bytes)
11614@end table
11615
11616All values are interpreted in the current language.
11617This means, for example, that if the current source language is C/C@t{++}
11618then searching for the string ``hello'' includes the trailing '\0'.
11619
11620If the value size is not specified, it is taken from the
11621value's type in the current language.
11622This is useful when one wants to specify the search
11623pattern as a mixture of types.
11624Note that this means, for example, that in the case of C-like languages
11625a search for an untyped 0x42 will search for @samp{(int) 0x42}
11626which is typically four bytes.
11627
11628@item @var{n}, maximum number of finds
11629The maximum number of matches to print. The default is to print all finds.
11630@end table
11631
11632You can use strings as search values. Quote them with double-quotes
11633 (@code{"}).
11634The string value is copied into the search pattern byte by byte,
11635regardless of the endianness of the target and the size specification.
11636
11637The address of each match found is printed as well as a count of the
11638number of matches found.
11639
11640The address of the last value found is stored in convenience variable
11641@samp{$_}.
11642A count of the number of matches is stored in @samp{$numfound}.
11643
11644For example, if stopped at the @code{printf} in this function:
11645
11646@smallexample
11647void
11648hello ()
11649@{
11650 static char hello[] = "hello-hello";
11651 static struct @{ char c; short s; int i; @}
11652 __attribute__ ((packed)) mixed
11653 = @{ 'c', 0x1234, 0x87654321 @};
11654 printf ("%s\n", hello);
11655@}
11656@end smallexample
11657
11658@noindent
11659you get during debugging:
11660
11661@smallexample
11662(gdb) find &hello[0], +sizeof(hello), "hello"
116630x804956d <hello.1620+6>
116641 pattern found
11665(gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
116660x8049567 <hello.1620>
116670x804956d <hello.1620+6>
116682 patterns found
11669(gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
116700x8049567 <hello.1620>
116711 pattern found
11672(gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
116730x8049560 <mixed.1625>
116741 pattern found
11675(gdb) print $numfound
11676$1 = 1
11677(gdb) print $_
11678$2 = (void *) 0x8049560
11679@end smallexample
a0eb71c5 11680
edb3359d
DJ
11681@node Optimized Code
11682@chapter Debugging Optimized Code
11683@cindex optimized code, debugging
11684@cindex debugging optimized code
11685
11686Almost all compilers support optimization. With optimization
11687disabled, the compiler generates assembly code that corresponds
11688directly to your source code, in a simplistic way. As the compiler
11689applies more powerful optimizations, the generated assembly code
11690diverges from your original source code. With help from debugging
11691information generated by the compiler, @value{GDBN} can map from
11692the running program back to constructs from your original source.
11693
11694@value{GDBN} is more accurate with optimization disabled. If you
11695can recompile without optimization, it is easier to follow the
11696progress of your program during debugging. But, there are many cases
11697where you may need to debug an optimized version.
11698
11699When you debug a program compiled with @samp{-g -O}, remember that the
11700optimizer has rearranged your code; the debugger shows you what is
11701really there. Do not be too surprised when the execution path does not
11702exactly match your source file! An extreme example: if you define a
11703variable, but never use it, @value{GDBN} never sees that
11704variable---because the compiler optimizes it out of existence.
11705
11706Some things do not work as well with @samp{-g -O} as with just
11707@samp{-g}, particularly on machines with instruction scheduling. If in
11708doubt, recompile with @samp{-g} alone, and if this fixes the problem,
11709please report it to us as a bug (including a test case!).
11710@xref{Variables}, for more information about debugging optimized code.
11711
11712@menu
11713* Inline Functions:: How @value{GDBN} presents inlining
111c6489 11714* Tail Call Frames:: @value{GDBN} analysis of jumps to functions
edb3359d
DJ
11715@end menu
11716
11717@node Inline Functions
11718@section Inline Functions
11719@cindex inline functions, debugging
11720
11721@dfn{Inlining} is an optimization that inserts a copy of the function
11722body directly at each call site, instead of jumping to a shared
11723routine. @value{GDBN} displays inlined functions just like
11724non-inlined functions. They appear in backtraces. You can view their
11725arguments and local variables, step into them with @code{step}, skip
11726them with @code{next}, and escape from them with @code{finish}.
11727You can check whether a function was inlined by using the
11728@code{info frame} command.
11729
11730For @value{GDBN} to support inlined functions, the compiler must
11731record information about inlining in the debug information ---
11732@value{NGCC} using the @sc{dwarf 2} format does this, and several
11733other compilers do also. @value{GDBN} only supports inlined functions
11734when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
11735do not emit two required attributes (@samp{DW_AT_call_file} and
11736@samp{DW_AT_call_line}); @value{GDBN} does not display inlined
11737function calls with earlier versions of @value{NGCC}. It instead
11738displays the arguments and local variables of inlined functions as
11739local variables in the caller.
11740
11741The body of an inlined function is directly included at its call site;
11742unlike a non-inlined function, there are no instructions devoted to
11743the call. @value{GDBN} still pretends that the call site and the
11744start of the inlined function are different instructions. Stepping to
11745the call site shows the call site, and then stepping again shows
11746the first line of the inlined function, even though no additional
11747instructions are executed.
11748
11749This makes source-level debugging much clearer; you can see both the
11750context of the call and then the effect of the call. Only stepping by
11751a single instruction using @code{stepi} or @code{nexti} does not do
11752this; single instruction steps always show the inlined body.
11753
11754There are some ways that @value{GDBN} does not pretend that inlined
11755function calls are the same as normal calls:
11756
11757@itemize @bullet
edb3359d
DJ
11758@item
11759Setting breakpoints at the call site of an inlined function may not
11760work, because the call site does not contain any code. @value{GDBN}
11761may incorrectly move the breakpoint to the next line of the enclosing
11762function, after the call. This limitation will be removed in a future
11763version of @value{GDBN}; until then, set a breakpoint on an earlier line
11764or inside the inlined function instead.
11765
11766@item
11767@value{GDBN} cannot locate the return value of inlined calls after
11768using the @code{finish} command. This is a limitation of compiler-generated
11769debugging information; after @code{finish}, you can step to the next line
11770and print a variable where your program stored the return value.
11771
11772@end itemize
11773
111c6489
JK
11774@node Tail Call Frames
11775@section Tail Call Frames
11776@cindex tail call frames, debugging
11777
11778Function @code{B} can call function @code{C} in its very last statement. In
11779unoptimized compilation the call of @code{C} is immediately followed by return
11780instruction at the end of @code{B} code. Optimizing compiler may replace the
11781call and return in function @code{B} into one jump to function @code{C}
11782instead. Such use of a jump instruction is called @dfn{tail call}.
11783
11784During execution of function @code{C}, there will be no indication in the
11785function call stack frames that it was tail-called from @code{B}. If function
11786@code{A} regularly calls function @code{B} which tail-calls function @code{C},
11787then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
11788some cases @value{GDBN} can determine that @code{C} was tail-called from
11789@code{B}, and it will then create fictitious call frame for that, with the
11790return address set up as if @code{B} called @code{C} normally.
11791
11792This functionality is currently supported only by DWARF 2 debugging format and
11793the compiler has to produce @samp{DW_TAG_GNU_call_site} tags. With
11794@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11795this information.
11796
11797@kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
11798kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
11799
11800@smallexample
11801(gdb) x/i $pc - 2
11802 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
11803(gdb) info frame
11804Stack level 1, frame at 0x7fffffffda30:
11805 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
11806 tail call frame, caller of frame at 0x7fffffffda30
11807 source language c++.
11808 Arglist at unknown address.
11809 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
11810@end smallexample
11811
11812The detection of all the possible code path executions can find them ambiguous.
11813There is no execution history stored (possible @ref{Reverse Execution} is never
11814used for this purpose) and the last known caller could have reached the known
11815callee by multiple different jump sequences. In such case @value{GDBN} still
11816tries to show at least all the unambiguous top tail callers and all the
11817unambiguous bottom tail calees, if any.
11818
11819@table @code
e18b2753 11820@anchor{set debug entry-values}
111c6489
JK
11821@item set debug entry-values
11822@kindex set debug entry-values
11823When set to on, enables printing of analysis messages for both frame argument
11824values at function entry and tail calls. It will show all the possible valid
11825tail calls code paths it has considered. It will also print the intersection
11826of them with the final unambiguous (possibly partial or even empty) code path
11827result.
11828
11829@item show debug entry-values
11830@kindex show debug entry-values
11831Show the current state of analysis messages printing for both frame argument
11832values at function entry and tail calls.
11833@end table
11834
11835The analysis messages for tail calls can for example show why the virtual tail
11836call frame for function @code{c} has not been recognized (due to the indirect
11837reference by variable @code{x}):
11838
11839@smallexample
11840static void __attribute__((noinline, noclone)) c (void);
11841void (*x) (void) = c;
11842static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
11843static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
11844int main (void) @{ x (); return 0; @}
11845
11846Breakpoint 1, DW_OP_GNU_entry_value resolving cannot find
11847DW_TAG_GNU_call_site 0x40039a in main
11848a () at t.c:3
118493 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
11850(gdb) bt
11851#0 a () at t.c:3
11852#1 0x000000000040039a in main () at t.c:5
11853@end smallexample
11854
11855Another possibility is an ambiguous virtual tail call frames resolution:
11856
11857@smallexample
11858int i;
11859static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
11860static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
11861static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
11862static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
11863static void __attribute__((noinline, noclone)) b (void)
11864@{ if (i) c (); else e (); @}
11865static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
11866int main (void) @{ a (); return 0; @}
11867
11868tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
11869tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
11870tailcall: reduced: 0x4004d2(a) |
11871(gdb) bt
11872#0 f () at t.c:2
11873#1 0x00000000004004d2 in a () at t.c:8
11874#2 0x0000000000400395 in main () at t.c:9
11875@end smallexample
11876
5048e516
JK
11877@set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
11878@set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
11879
11880@c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
11881@ifset HAVE_MAKEINFO_CLICK
11882@set ARROW @click{}
11883@set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
11884@set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
11885@end ifset
11886@ifclear HAVE_MAKEINFO_CLICK
11887@set ARROW ->
11888@set CALLSEQ1B @value{CALLSEQ1A}
11889@set CALLSEQ2B @value{CALLSEQ2A}
11890@end ifclear
11891
11892Frames #0 and #2 are real, #1 is a virtual tail call frame.
11893The code can have possible execution paths @value{CALLSEQ1B} or
11894@value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
111c6489
JK
11895
11896@code{initial:} state shows some random possible calling sequence @value{GDBN}
11897has found. It then finds another possible calling sequcen - that one is
11898prefixed by @code{compare:}. The non-ambiguous intersection of these two is
11899printed as the @code{reduced:} calling sequence. That one could have many
11900futher @code{compare:} and @code{reduced:} statements as long as there remain
11901any non-ambiguous sequence entries.
11902
11903For the frame of function @code{b} in both cases there are different possible
11904@code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
11905also ambigous. The only non-ambiguous frame is the one for function @code{a},
11906therefore this one is displayed to the user while the ambiguous frames are
11907omitted.
edb3359d 11908
e18b2753
JK
11909There can be also reasons why printing of frame argument values at function
11910entry may fail:
11911
11912@smallexample
11913int v;
11914static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
11915static void __attribute__((noinline, noclone)) a (int i);
11916static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
11917static void __attribute__((noinline, noclone)) a (int i)
11918@{ if (i) b (i - 1); else c (0); @}
11919int main (void) @{ a (5); return 0; @}
11920
11921(gdb) bt
11922#0 c (i=i@@entry=0) at t.c:2
11923#1 0x0000000000400428 in a (DW_OP_GNU_entry_value resolving has found
11924function "a" at 0x400420 can call itself via tail calls
11925i=<optimized out>) at t.c:6
11926#2 0x000000000040036e in main () at t.c:7
11927@end smallexample
11928
11929@value{GDBN} cannot find out from the inferior state if and how many times did
11930function @code{a} call itself (via function @code{b}) as these calls would be
11931tail calls. Such tail calls would modify thue @code{i} variable, therefore
11932@value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
11933prints @code{<optimized out>} instead.
11934
e2e0bcd1
JB
11935@node Macros
11936@chapter C Preprocessor Macros
11937
49efadf5 11938Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
11939``preprocessor macros'' which expand into strings of tokens.
11940@value{GDBN} can evaluate expressions containing macro invocations, show
11941the result of macro expansion, and show a macro's definition, including
11942where it was defined.
11943
11944You may need to compile your program specially to provide @value{GDBN}
11945with information about preprocessor macros. Most compilers do not
11946include macros in their debugging information, even when you compile
11947with the @option{-g} flag. @xref{Compilation}.
11948
11949A program may define a macro at one point, remove that definition later,
11950and then provide a different definition after that. Thus, at different
11951points in the program, a macro may have different definitions, or have
11952no definition at all. If there is a current stack frame, @value{GDBN}
11953uses the macros in scope at that frame's source code line. Otherwise,
11954@value{GDBN} uses the macros in scope at the current listing location;
11955see @ref{List}.
11956
e2e0bcd1
JB
11957Whenever @value{GDBN} evaluates an expression, it always expands any
11958macro invocations present in the expression. @value{GDBN} also provides
11959the following commands for working with macros explicitly.
11960
11961@table @code
11962
11963@kindex macro expand
11964@cindex macro expansion, showing the results of preprocessor
11965@cindex preprocessor macro expansion, showing the results of
11966@cindex expanding preprocessor macros
11967@item macro expand @var{expression}
11968@itemx macro exp @var{expression}
11969Show the results of expanding all preprocessor macro invocations in
11970@var{expression}. Since @value{GDBN} simply expands macros, but does
11971not parse the result, @var{expression} need not be a valid expression;
11972it can be any string of tokens.
11973
09d4efe1 11974@kindex macro exp1
e2e0bcd1
JB
11975@item macro expand-once @var{expression}
11976@itemx macro exp1 @var{expression}
4644b6e3 11977@cindex expand macro once
e2e0bcd1
JB
11978@i{(This command is not yet implemented.)} Show the results of
11979expanding those preprocessor macro invocations that appear explicitly in
11980@var{expression}. Macro invocations appearing in that expansion are
11981left unchanged. This command allows you to see the effect of a
11982particular macro more clearly, without being confused by further
11983expansions. Since @value{GDBN} simply expands macros, but does not
11984parse the result, @var{expression} need not be a valid expression; it
11985can be any string of tokens.
11986
475b0867 11987@kindex info macro
e2e0bcd1 11988@cindex macro definition, showing
9b158ba0 11989@cindex definition of a macro, showing
11990@cindex macros, from debug info
71eba9c2 11991@item info macro [-a|-all] [--] @var{macro}
11992Show the current definition or all definitions of the named @var{macro},
11993and describe the source location or compiler command-line where that
11994definition was established. The optional double dash is to signify the end of
11995argument processing and the beginning of @var{macro} for non C-like macros where
11996the macro may begin with a hyphen.
e2e0bcd1 11997
9b158ba0 11998@kindex info macros
629500fa 11999@item info macros @var{location}
9b158ba0 12000Show all macro definitions that are in effect at the location specified
629500fa 12001by @var{location}, and describe the source location or compiler
9b158ba0 12002command-line where those definitions were established.
12003
e2e0bcd1
JB
12004@kindex macro define
12005@cindex user-defined macros
12006@cindex defining macros interactively
12007@cindex macros, user-defined
12008@item macro define @var{macro} @var{replacement-list}
12009@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
d7d9f01e
TT
12010Introduce a definition for a preprocessor macro named @var{macro},
12011invocations of which are replaced by the tokens given in
12012@var{replacement-list}. The first form of this command defines an
12013``object-like'' macro, which takes no arguments; the second form
12014defines a ``function-like'' macro, which takes the arguments given in
12015@var{arglist}.
12016
12017A definition introduced by this command is in scope in every
12018expression evaluated in @value{GDBN}, until it is removed with the
12019@code{macro undef} command, described below. The definition overrides
12020all definitions for @var{macro} present in the program being debugged,
12021as well as any previous user-supplied definition.
e2e0bcd1
JB
12022
12023@kindex macro undef
12024@item macro undef @var{macro}
d7d9f01e
TT
12025Remove any user-supplied definition for the macro named @var{macro}.
12026This command only affects definitions provided with the @code{macro
12027define} command, described above; it cannot remove definitions present
12028in the program being debugged.
e2e0bcd1 12029
09d4efe1
EZ
12030@kindex macro list
12031@item macro list
d7d9f01e 12032List all the macros defined using the @code{macro define} command.
e2e0bcd1
JB
12033@end table
12034
12035@cindex macros, example of debugging with
12036Here is a transcript showing the above commands in action. First, we
12037show our source files:
12038
12039@smallexample
12040$ cat sample.c
12041#include <stdio.h>
12042#include "sample.h"
12043
12044#define M 42
12045#define ADD(x) (M + x)
12046
12047main ()
12048@{
12049#define N 28
12050 printf ("Hello, world!\n");
12051#undef N
12052 printf ("We're so creative.\n");
12053#define N 1729
12054 printf ("Goodbye, world!\n");
12055@}
12056$ cat sample.h
12057#define Q <
12058$
12059@end smallexample
12060
e0f8f636
TT
12061Now, we compile the program using the @sc{gnu} C compiler,
12062@value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
12063minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
12064and @option{-gdwarf-4}; we recommend always choosing the most recent
12065version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
12066includes information about preprocessor macros in the debugging
e2e0bcd1
JB
12067information.
12068
12069@smallexample
12070$ gcc -gdwarf-2 -g3 sample.c -o sample
12071$
12072@end smallexample
12073
12074Now, we start @value{GDBN} on our sample program:
12075
12076@smallexample
12077$ gdb -nw sample
12078GNU gdb 2002-05-06-cvs
12079Copyright 2002 Free Software Foundation, Inc.
12080GDB is free software, @dots{}
f7dc1244 12081(@value{GDBP})
e2e0bcd1
JB
12082@end smallexample
12083
12084We can expand macros and examine their definitions, even when the
12085program is not running. @value{GDBN} uses the current listing position
12086to decide which macro definitions are in scope:
12087
12088@smallexample
f7dc1244 12089(@value{GDBP}) list main
e2e0bcd1
JB
120903
120914 #define M 42
120925 #define ADD(x) (M + x)
120936
120947 main ()
120958 @{
120969 #define N 28
1209710 printf ("Hello, world!\n");
1209811 #undef N
1209912 printf ("We're so creative.\n");
f7dc1244 12100(@value{GDBP}) info macro ADD
e2e0bcd1
JB
12101Defined at /home/jimb/gdb/macros/play/sample.c:5
12102#define ADD(x) (M + x)
f7dc1244 12103(@value{GDBP}) info macro Q
e2e0bcd1
JB
12104Defined at /home/jimb/gdb/macros/play/sample.h:1
12105 included at /home/jimb/gdb/macros/play/sample.c:2
12106#define Q <
f7dc1244 12107(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 12108expands to: (42 + 1)
f7dc1244 12109(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 12110expands to: once (M + 1)
f7dc1244 12111(@value{GDBP})
e2e0bcd1
JB
12112@end smallexample
12113
d7d9f01e 12114In the example above, note that @code{macro expand-once} expands only
e2e0bcd1
JB
12115the macro invocation explicit in the original text --- the invocation of
12116@code{ADD} --- but does not expand the invocation of the macro @code{M},
12117which was introduced by @code{ADD}.
12118
3f94c067
BW
12119Once the program is running, @value{GDBN} uses the macro definitions in
12120force at the source line of the current stack frame:
e2e0bcd1
JB
12121
12122@smallexample
f7dc1244 12123(@value{GDBP}) break main
e2e0bcd1 12124Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 12125(@value{GDBP}) run
b383017d 12126Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
12127
12128Breakpoint 1, main () at sample.c:10
1212910 printf ("Hello, world!\n");
f7dc1244 12130(@value{GDBP})
e2e0bcd1
JB
12131@end smallexample
12132
12133At line 10, the definition of the macro @code{N} at line 9 is in force:
12134
12135@smallexample
f7dc1244 12136(@value{GDBP}) info macro N
e2e0bcd1
JB
12137Defined at /home/jimb/gdb/macros/play/sample.c:9
12138#define N 28
f7dc1244 12139(@value{GDBP}) macro expand N Q M
e2e0bcd1 12140expands to: 28 < 42
f7dc1244 12141(@value{GDBP}) print N Q M
e2e0bcd1 12142$1 = 1
f7dc1244 12143(@value{GDBP})
e2e0bcd1
JB
12144@end smallexample
12145
12146As we step over directives that remove @code{N}'s definition, and then
12147give it a new definition, @value{GDBN} finds the definition (or lack
12148thereof) in force at each point:
12149
12150@smallexample
f7dc1244 12151(@value{GDBP}) next
e2e0bcd1
JB
12152Hello, world!
1215312 printf ("We're so creative.\n");
f7dc1244 12154(@value{GDBP}) info macro N
e2e0bcd1
JB
12155The symbol `N' has no definition as a C/C++ preprocessor macro
12156at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 12157(@value{GDBP}) next
e2e0bcd1
JB
12158We're so creative.
1215914 printf ("Goodbye, world!\n");
f7dc1244 12160(@value{GDBP}) info macro N
e2e0bcd1
JB
12161Defined at /home/jimb/gdb/macros/play/sample.c:13
12162#define N 1729
f7dc1244 12163(@value{GDBP}) macro expand N Q M
e2e0bcd1 12164expands to: 1729 < 42
f7dc1244 12165(@value{GDBP}) print N Q M
e2e0bcd1 12166$2 = 0
f7dc1244 12167(@value{GDBP})
e2e0bcd1
JB
12168@end smallexample
12169
484086b7
JK
12170In addition to source files, macros can be defined on the compilation command
12171line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
12172such a way, @value{GDBN} displays the location of their definition as line zero
12173of the source file submitted to the compiler.
12174
12175@smallexample
12176(@value{GDBP}) info macro __STDC__
12177Defined at /home/jimb/gdb/macros/play/sample.c:0
12178-D__STDC__=1
12179(@value{GDBP})
12180@end smallexample
12181
e2e0bcd1 12182
b37052ae
EZ
12183@node Tracepoints
12184@chapter Tracepoints
12185@c This chapter is based on the documentation written by Michael
12186@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
12187
12188@cindex tracepoints
12189In some applications, it is not feasible for the debugger to interrupt
12190the program's execution long enough for the developer to learn
12191anything helpful about its behavior. If the program's correctness
12192depends on its real-time behavior, delays introduced by a debugger
12193might cause the program to change its behavior drastically, or perhaps
12194fail, even when the code itself is correct. It is useful to be able
12195to observe the program's behavior without interrupting it.
12196
12197Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
12198specify locations in the program, called @dfn{tracepoints}, and
12199arbitrary expressions to evaluate when those tracepoints are reached.
12200Later, using the @code{tfind} command, you can examine the values
12201those expressions had when the program hit the tracepoints. The
12202expressions may also denote objects in memory---structures or arrays,
12203for example---whose values @value{GDBN} should record; while visiting
12204a particular tracepoint, you may inspect those objects as if they were
12205in memory at that moment. However, because @value{GDBN} records these
12206values without interacting with you, it can do so quickly and
12207unobtrusively, hopefully not disturbing the program's behavior.
12208
12209The tracepoint facility is currently available only for remote
9d29849a
JB
12210targets. @xref{Targets}. In addition, your remote target must know
12211how to collect trace data. This functionality is implemented in the
12212remote stub; however, none of the stubs distributed with @value{GDBN}
12213support tracepoints as of this writing. The format of the remote
12214packets used to implement tracepoints are described in @ref{Tracepoint
12215Packets}.
b37052ae 12216
00bf0b85
SS
12217It is also possible to get trace data from a file, in a manner reminiscent
12218of corefiles; you specify the filename, and use @code{tfind} to search
12219through the file. @xref{Trace Files}, for more details.
12220
b37052ae
EZ
12221This chapter describes the tracepoint commands and features.
12222
12223@menu
b383017d
RM
12224* Set Tracepoints::
12225* Analyze Collected Data::
12226* Tracepoint Variables::
00bf0b85 12227* Trace Files::
b37052ae
EZ
12228@end menu
12229
12230@node Set Tracepoints
12231@section Commands to Set Tracepoints
12232
12233Before running such a @dfn{trace experiment}, an arbitrary number of
1042e4c0
SS
12234tracepoints can be set. A tracepoint is actually a special type of
12235breakpoint (@pxref{Set Breaks}), so you can manipulate it using
12236standard breakpoint commands. For instance, as with breakpoints,
12237tracepoint numbers are successive integers starting from one, and many
12238of the commands associated with tracepoints take the tracepoint number
12239as their argument, to identify which tracepoint to work on.
b37052ae
EZ
12240
12241For each tracepoint, you can specify, in advance, some arbitrary set
12242of data that you want the target to collect in the trace buffer when
12243it hits that tracepoint. The collected data can include registers,
12244local variables, or global data. Later, you can use @value{GDBN}
12245commands to examine the values these data had at the time the
12246tracepoint was hit.
12247
7d13fe92
SS
12248Tracepoints do not support every breakpoint feature. Ignore counts on
12249tracepoints have no effect, and tracepoints cannot run @value{GDBN}
12250commands when they are hit. Tracepoints may not be thread-specific
12251either.
1042e4c0 12252
7a697b8d
SS
12253@cindex fast tracepoints
12254Some targets may support @dfn{fast tracepoints}, which are inserted in
12255a different way (such as with a jump instead of a trap), that is
12256faster but possibly restricted in where they may be installed.
12257
0fb4aa4b
PA
12258@cindex static tracepoints
12259@cindex markers, static tracepoints
12260@cindex probing markers, static tracepoints
12261Regular and fast tracepoints are dynamic tracing facilities, meaning
12262that they can be used to insert tracepoints at (almost) any location
12263in the target. Some targets may also support controlling @dfn{static
12264tracepoints} from @value{GDBN}. With static tracing, a set of
12265instrumentation points, also known as @dfn{markers}, are embedded in
12266the target program, and can be activated or deactivated by name or
12267address. These are usually placed at locations which facilitate
12268investigating what the target is actually doing. @value{GDBN}'s
12269support for static tracing includes being able to list instrumentation
12270points, and attach them with @value{GDBN} defined high level
12271tracepoints that expose the whole range of convenience of
8786b2bd 12272@value{GDBN}'s tracepoints support. Namely, support for collecting
0fb4aa4b
PA
12273registers values and values of global or local (to the instrumentation
12274point) variables; tracepoint conditions and trace state variables.
12275The act of installing a @value{GDBN} static tracepoint on an
12276instrumentation point, or marker, is referred to as @dfn{probing} a
12277static tracepoint marker.
12278
fa593d66
PA
12279@code{gdbserver} supports tracepoints on some target systems.
12280@xref{Server,,Tracepoints support in @code{gdbserver}}.
12281
b37052ae
EZ
12282This section describes commands to set tracepoints and associated
12283conditions and actions.
12284
12285@menu
b383017d
RM
12286* Create and Delete Tracepoints::
12287* Enable and Disable Tracepoints::
12288* Tracepoint Passcounts::
782b2b07 12289* Tracepoint Conditions::
f61e138d 12290* Trace State Variables::
b383017d
RM
12291* Tracepoint Actions::
12292* Listing Tracepoints::
0fb4aa4b 12293* Listing Static Tracepoint Markers::
79a6e687 12294* Starting and Stopping Trace Experiments::
c9429232 12295* Tracepoint Restrictions::
b37052ae
EZ
12296@end menu
12297
12298@node Create and Delete Tracepoints
12299@subsection Create and Delete Tracepoints
12300
12301@table @code
12302@cindex set tracepoint
12303@kindex trace
1042e4c0 12304@item trace @var{location}
b37052ae 12305The @code{trace} command is very similar to the @code{break} command.
629500fa
KS
12306Its argument @var{location} can be any valid location.
12307@xref{Specify Location}. The @code{trace} command defines a tracepoint,
12308which is a point in the target program where the debugger will briefly stop,
12309collect some data, and then allow the program to continue. Setting a tracepoint
12310or changing its actions takes effect immediately if the remote stub
1e4d1764
YQ
12311supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
12312in tracing}).
12313If remote stub doesn't support the @samp{InstallInTrace} feature, all
12314these changes don't take effect until the next @code{tstart}
1042e4c0 12315command, and once a trace experiment is running, further changes will
bfccc43c
YQ
12316not have any effect until the next trace experiment starts. In addition,
12317@value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
12318address is not yet resolved. (This is similar to pending breakpoints.)
12319Pending tracepoints are not downloaded to the target and not installed
12320until they are resolved. The resolution of pending tracepoints requires
12321@value{GDBN} support---when debugging with the remote target, and
12322@value{GDBN} disconnects from the remote stub (@pxref{disconnected
12323tracing}), pending tracepoints can not be resolved (and downloaded to
12324the remote stub) while @value{GDBN} is disconnected.
b37052ae
EZ
12325
12326Here are some examples of using the @code{trace} command:
12327
12328@smallexample
12329(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
12330
12331(@value{GDBP}) @b{trace +2} // 2 lines forward
12332
12333(@value{GDBP}) @b{trace my_function} // first source line of function
12334
12335(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
12336
12337(@value{GDBP}) @b{trace *0x2117c4} // an address
12338@end smallexample
12339
12340@noindent
12341You can abbreviate @code{trace} as @code{tr}.
12342
782b2b07
SS
12343@item trace @var{location} if @var{cond}
12344Set a tracepoint with condition @var{cond}; evaluate the expression
12345@var{cond} each time the tracepoint is reached, and collect data only
12346if the value is nonzero---that is, if @var{cond} evaluates as true.
12347@xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
12348information on tracepoint conditions.
12349
7a697b8d
SS
12350@item ftrace @var{location} [ if @var{cond} ]
12351@cindex set fast tracepoint
74c761c1 12352@cindex fast tracepoints, setting
7a697b8d
SS
12353@kindex ftrace
12354The @code{ftrace} command sets a fast tracepoint. For targets that
12355support them, fast tracepoints will use a more efficient but possibly
12356less general technique to trigger data collection, such as a jump
12357instruction instead of a trap, or some sort of hardware support. It
12358may not be possible to create a fast tracepoint at the desired
12359location, in which case the command will exit with an explanatory
12360message.
12361
12362@value{GDBN} handles arguments to @code{ftrace} exactly as for
12363@code{trace}.
12364
405f8e94
SS
12365On 32-bit x86-architecture systems, fast tracepoints normally need to
12366be placed at an instruction that is 5 bytes or longer, but can be
12367placed at 4-byte instructions if the low 64K of memory of the target
12368program is available to install trampolines. Some Unix-type systems,
12369such as @sc{gnu}/Linux, exclude low addresses from the program's
12370address space; but for instance with the Linux kernel it is possible
12371to let @value{GDBN} use this area by doing a @command{sysctl} command
12372to set the @code{mmap_min_addr} kernel parameter, as in
12373
12374@example
12375sudo sysctl -w vm.mmap_min_addr=32768
12376@end example
12377
12378@noindent
12379which sets the low address to 32K, which leaves plenty of room for
12380trampolines. The minimum address should be set to a page boundary.
12381
0fb4aa4b 12382@item strace @var{location} [ if @var{cond} ]
74c761c1
PA
12383@cindex set static tracepoint
12384@cindex static tracepoints, setting
12385@cindex probe static tracepoint marker
0fb4aa4b
PA
12386@kindex strace
12387The @code{strace} command sets a static tracepoint. For targets that
12388support it, setting a static tracepoint probes a static
12389instrumentation point, or marker, found at @var{location}. It may not
12390be possible to set a static tracepoint at the desired location, in
12391which case the command will exit with an explanatory message.
12392
12393@value{GDBN} handles arguments to @code{strace} exactly as for
12394@code{trace}, with the addition that the user can also specify
12395@code{-m @var{marker}} as @var{location}. This probes the marker
12396identified by the @var{marker} string identifier. This identifier
12397depends on the static tracepoint backend library your program is
12398using. You can find all the marker identifiers in the @samp{ID} field
12399of the @code{info static-tracepoint-markers} command output.
12400@xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
12401Markers}. For example, in the following small program using the UST
12402tracing engine:
12403
12404@smallexample
12405main ()
12406@{
12407 trace_mark(ust, bar33, "str %s", "FOOBAZ");
12408@}
12409@end smallexample
12410
12411@noindent
12412the marker id is composed of joining the first two arguments to the
12413@code{trace_mark} call with a slash, which translates to:
12414
12415@smallexample
12416(@value{GDBP}) info static-tracepoint-markers
12417Cnt Enb ID Address What
124181 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
12419 Data: "str %s"
12420[etc...]
12421@end smallexample
12422
12423@noindent
12424so you may probe the marker above with:
12425
12426@smallexample
12427(@value{GDBP}) strace -m ust/bar33
12428@end smallexample
12429
12430Static tracepoints accept an extra collect action --- @code{collect
12431$_sdata}. This collects arbitrary user data passed in the probe point
12432call to the tracing library. In the UST example above, you'll see
12433that the third argument to @code{trace_mark} is a printf-like format
12434string. The user data is then the result of running that formating
12435string against the following arguments. Note that @code{info
12436static-tracepoint-markers} command output lists that format string in
12437the @samp{Data:} field.
12438
12439You can inspect this data when analyzing the trace buffer, by printing
12440the $_sdata variable like any other variable available to
12441@value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
12442
b37052ae
EZ
12443@vindex $tpnum
12444@cindex last tracepoint number
12445@cindex recent tracepoint number
12446@cindex tracepoint number
12447The convenience variable @code{$tpnum} records the tracepoint number
12448of the most recently set tracepoint.
12449
12450@kindex delete tracepoint
12451@cindex tracepoint deletion
12452@item delete tracepoint @r{[}@var{num}@r{]}
12453Permanently delete one or more tracepoints. With no argument, the
1042e4c0
SS
12454default is to delete all tracepoints. Note that the regular
12455@code{delete} command can remove tracepoints also.
b37052ae
EZ
12456
12457Examples:
12458
12459@smallexample
12460(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
12461
12462(@value{GDBP}) @b{delete trace} // remove all tracepoints
12463@end smallexample
12464
12465@noindent
12466You can abbreviate this command as @code{del tr}.
12467@end table
12468
12469@node Enable and Disable Tracepoints
12470@subsection Enable and Disable Tracepoints
12471
1042e4c0
SS
12472These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
12473
b37052ae
EZ
12474@table @code
12475@kindex disable tracepoint
12476@item disable tracepoint @r{[}@var{num}@r{]}
12477Disable tracepoint @var{num}, or all tracepoints if no argument
12478@var{num} is given. A disabled tracepoint will have no effect during
d248b706 12479a trace experiment, but it is not forgotten. You can re-enable
b37052ae 12480a disabled tracepoint using the @code{enable tracepoint} command.
d248b706
KY
12481If the command is issued during a trace experiment and the debug target
12482has support for disabling tracepoints during a trace experiment, then the
12483change will be effective immediately. Otherwise, it will be applied to the
12484next trace experiment.
b37052ae
EZ
12485
12486@kindex enable tracepoint
12487@item enable tracepoint @r{[}@var{num}@r{]}
d248b706
KY
12488Enable tracepoint @var{num}, or all tracepoints. If this command is
12489issued during a trace experiment and the debug target supports enabling
12490tracepoints during a trace experiment, then the enabled tracepoints will
12491become effective immediately. Otherwise, they will become effective the
12492next time a trace experiment is run.
b37052ae
EZ
12493@end table
12494
12495@node Tracepoint Passcounts
12496@subsection Tracepoint Passcounts
12497
12498@table @code
12499@kindex passcount
12500@cindex tracepoint pass count
12501@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
12502Set the @dfn{passcount} of a tracepoint. The passcount is a way to
12503automatically stop a trace experiment. If a tracepoint's passcount is
12504@var{n}, then the trace experiment will be automatically stopped on
12505the @var{n}'th time that tracepoint is hit. If the tracepoint number
12506@var{num} is not specified, the @code{passcount} command sets the
12507passcount of the most recently defined tracepoint. If no passcount is
12508given, the trace experiment will run until stopped explicitly by the
12509user.
12510
12511Examples:
12512
12513@smallexample
b383017d 12514(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 12515@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
12516
12517(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 12518@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
12519(@value{GDBP}) @b{trace foo}
12520(@value{GDBP}) @b{pass 3}
12521(@value{GDBP}) @b{trace bar}
12522(@value{GDBP}) @b{pass 2}
12523(@value{GDBP}) @b{trace baz}
12524(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
12525@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
12526@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
12527@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
12528@end smallexample
12529@end table
12530
782b2b07
SS
12531@node Tracepoint Conditions
12532@subsection Tracepoint Conditions
12533@cindex conditional tracepoints
12534@cindex tracepoint conditions
12535
12536The simplest sort of tracepoint collects data every time your program
12537reaches a specified place. You can also specify a @dfn{condition} for
12538a tracepoint. A condition is just a Boolean expression in your
12539programming language (@pxref{Expressions, ,Expressions}). A
12540tracepoint with a condition evaluates the expression each time your
12541program reaches it, and data collection happens only if the condition
12542is true.
12543
12544Tracepoint conditions can be specified when a tracepoint is set, by
12545using @samp{if} in the arguments to the @code{trace} command.
12546@xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
12547also be set or changed at any time with the @code{condition} command,
12548just as with breakpoints.
12549
12550Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
12551the conditional expression itself. Instead, @value{GDBN} encodes the
6dcd5565 12552expression into an agent expression (@pxref{Agent Expressions})
782b2b07
SS
12553suitable for execution on the target, independently of @value{GDBN}.
12554Global variables become raw memory locations, locals become stack
12555accesses, and so forth.
12556
12557For instance, suppose you have a function that is usually called
12558frequently, but should not be called after an error has occurred. You
12559could use the following tracepoint command to collect data about calls
12560of that function that happen while the error code is propagating
12561through the program; an unconditional tracepoint could end up
12562collecting thousands of useless trace frames that you would have to
12563search through.
12564
12565@smallexample
12566(@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
12567@end smallexample
12568
f61e138d
SS
12569@node Trace State Variables
12570@subsection Trace State Variables
12571@cindex trace state variables
12572
12573A @dfn{trace state variable} is a special type of variable that is
12574created and managed by target-side code. The syntax is the same as
12575that for GDB's convenience variables (a string prefixed with ``$''),
12576but they are stored on the target. They must be created explicitly,
12577using a @code{tvariable} command. They are always 64-bit signed
12578integers.
12579
12580Trace state variables are remembered by @value{GDBN}, and downloaded
12581to the target along with tracepoint information when the trace
12582experiment starts. There are no intrinsic limits on the number of
12583trace state variables, beyond memory limitations of the target.
12584
12585@cindex convenience variables, and trace state variables
12586Although trace state variables are managed by the target, you can use
12587them in print commands and expressions as if they were convenience
12588variables; @value{GDBN} will get the current value from the target
12589while the trace experiment is running. Trace state variables share
12590the same namespace as other ``$'' variables, which means that you
12591cannot have trace state variables with names like @code{$23} or
12592@code{$pc}, nor can you have a trace state variable and a convenience
12593variable with the same name.
12594
12595@table @code
12596
12597@item tvariable $@var{name} [ = @var{expression} ]
12598@kindex tvariable
12599The @code{tvariable} command creates a new trace state variable named
12600@code{$@var{name}}, and optionally gives it an initial value of
697aa1b7 12601@var{expression}. The @var{expression} is evaluated when this command is
f61e138d
SS
12602entered; the result will be converted to an integer if possible,
12603otherwise @value{GDBN} will report an error. A subsequent
12604@code{tvariable} command specifying the same name does not create a
12605variable, but instead assigns the supplied initial value to the
12606existing variable of that name, overwriting any previous initial
12607value. The default initial value is 0.
12608
12609@item info tvariables
12610@kindex info tvariables
12611List all the trace state variables along with their initial values.
12612Their current values may also be displayed, if the trace experiment is
12613currently running.
12614
12615@item delete tvariable @r{[} $@var{name} @dots{} @r{]}
12616@kindex delete tvariable
12617Delete the given trace state variables, or all of them if no arguments
12618are specified.
12619
12620@end table
12621
b37052ae
EZ
12622@node Tracepoint Actions
12623@subsection Tracepoint Action Lists
12624
12625@table @code
12626@kindex actions
12627@cindex tracepoint actions
12628@item actions @r{[}@var{num}@r{]}
12629This command will prompt for a list of actions to be taken when the
12630tracepoint is hit. If the tracepoint number @var{num} is not
12631specified, this command sets the actions for the one that was most
12632recently defined (so that you can define a tracepoint and then say
12633@code{actions} without bothering about its number). You specify the
12634actions themselves on the following lines, one action at a time, and
12635terminate the actions list with a line containing just @code{end}. So
7d13fe92 12636far, the only defined actions are @code{collect}, @code{teval}, and
b37052ae
EZ
12637@code{while-stepping}.
12638
5a9351ae
SS
12639@code{actions} is actually equivalent to @code{commands} (@pxref{Break
12640Commands, ,Breakpoint Command Lists}), except that only the defined
12641actions are allowed; any other @value{GDBN} command is rejected.
12642
b37052ae
EZ
12643@cindex remove actions from a tracepoint
12644To remove all actions from a tracepoint, type @samp{actions @var{num}}
12645and follow it immediately with @samp{end}.
12646
12647@smallexample
12648(@value{GDBP}) @b{collect @var{data}} // collect some data
12649
6826cf00 12650(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 12651
6826cf00 12652(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
12653@end smallexample
12654
12655In the following example, the action list begins with @code{collect}
12656commands indicating the things to be collected when the tracepoint is
12657hit. Then, in order to single-step and collect additional data
12658following the tracepoint, a @code{while-stepping} command is used,
7d13fe92
SS
12659followed by the list of things to be collected after each step in a
12660sequence of single steps. The @code{while-stepping} command is
12661terminated by its own separate @code{end} command. Lastly, the action
12662list is terminated by an @code{end} command.
b37052ae
EZ
12663
12664@smallexample
12665(@value{GDBP}) @b{trace foo}
12666(@value{GDBP}) @b{actions}
12667Enter actions for tracepoint 1, one per line:
12668> collect bar,baz
12669> collect $regs
12670> while-stepping 12
5a9351ae 12671 > collect $pc, arr[i]
b37052ae
EZ
12672 > end
12673end
12674@end smallexample
12675
12676@kindex collect @r{(tracepoints)}
3065dfb6 12677@item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
b37052ae
EZ
12678Collect values of the given expressions when the tracepoint is hit.
12679This command accepts a comma-separated list of any valid expressions.
12680In addition to global, static, or local variables, the following
12681special arguments are supported:
12682
12683@table @code
12684@item $regs
0fb4aa4b 12685Collect all registers.
b37052ae
EZ
12686
12687@item $args
0fb4aa4b 12688Collect all function arguments.
b37052ae
EZ
12689
12690@item $locals
0fb4aa4b
PA
12691Collect all local variables.
12692
6710bf39
SS
12693@item $_ret
12694Collect the return address. This is helpful if you want to see more
12695of a backtrace.
12696
62e5f89c
SDJ
12697@item $_probe_argc
12698Collects the number of arguments from the static probe at which the
12699tracepoint is located.
12700@xref{Static Probe Points}.
12701
12702@item $_probe_arg@var{n}
12703@var{n} is an integer between 0 and 11. Collects the @var{n}th argument
12704from the static probe at which the tracepoint is located.
12705@xref{Static Probe Points}.
12706
0fb4aa4b
PA
12707@item $_sdata
12708@vindex $_sdata@r{, collect}
12709Collect static tracepoint marker specific data. Only available for
12710static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
12711Lists}. On the UST static tracepoints library backend, an
12712instrumentation point resembles a @code{printf} function call. The
12713tracing library is able to collect user specified data formatted to a
12714character string using the format provided by the programmer that
12715instrumented the program. Other backends have similar mechanisms.
12716Here's an example of a UST marker call:
12717
12718@smallexample
12719 const char master_name[] = "$your_name";
12720 trace_mark(channel1, marker1, "hello %s", master_name)
12721@end smallexample
12722
12723In this case, collecting @code{$_sdata} collects the string
12724@samp{hello $yourname}. When analyzing the trace buffer, you can
12725inspect @samp{$_sdata} like any other variable available to
12726@value{GDBN}.
b37052ae
EZ
12727@end table
12728
12729You can give several consecutive @code{collect} commands, each one
12730with a single argument, or one @code{collect} command with several
5a9351ae 12731arguments separated by commas; the effect is the same.
b37052ae 12732
3065dfb6
SS
12733The optional @var{mods} changes the usual handling of the arguments.
12734@code{s} requests that pointers to chars be handled as strings, in
12735particular collecting the contents of the memory being pointed at, up
12736to the first zero. The upper bound is by default the value of the
12737@code{print elements} variable; if @code{s} is followed by a decimal
12738number, that is the upper bound instead. So for instance
12739@samp{collect/s25 mystr} collects as many as 25 characters at
12740@samp{mystr}.
12741
f5c37c66
EZ
12742The command @code{info scope} (@pxref{Symbols, info scope}) is
12743particularly useful for figuring out what data to collect.
12744
6da95a67
SS
12745@kindex teval @r{(tracepoints)}
12746@item teval @var{expr1}, @var{expr2}, @dots{}
12747Evaluate the given expressions when the tracepoint is hit. This
12748command accepts a comma-separated list of expressions. The results
12749are discarded, so this is mainly useful for assigning values to trace
12750state variables (@pxref{Trace State Variables}) without adding those
12751values to the trace buffer, as would be the case if the @code{collect}
12752action were used.
12753
b37052ae
EZ
12754@kindex while-stepping @r{(tracepoints)}
12755@item while-stepping @var{n}
c9429232 12756Perform @var{n} single-step instruction traces after the tracepoint,
7d13fe92 12757collecting new data after each step. The @code{while-stepping}
c9429232
SS
12758command is followed by the list of what to collect while stepping
12759(followed by its own @code{end} command):
b37052ae
EZ
12760
12761@smallexample
12762> while-stepping 12
12763 > collect $regs, myglobal
12764 > end
12765>
12766@end smallexample
12767
12768@noindent
7d13fe92
SS
12769Note that @code{$pc} is not automatically collected by
12770@code{while-stepping}; you need to explicitly collect that register if
12771you need it. You may abbreviate @code{while-stepping} as @code{ws} or
b37052ae 12772@code{stepping}.
236f1d4d
SS
12773
12774@item set default-collect @var{expr1}, @var{expr2}, @dots{}
12775@kindex set default-collect
12776@cindex default collection action
12777This variable is a list of expressions to collect at each tracepoint
12778hit. It is effectively an additional @code{collect} action prepended
12779to every tracepoint action list. The expressions are parsed
12780individually for each tracepoint, so for instance a variable named
12781@code{xyz} may be interpreted as a global for one tracepoint, and a
12782local for another, as appropriate to the tracepoint's location.
12783
12784@item show default-collect
12785@kindex show default-collect
12786Show the list of expressions that are collected by default at each
12787tracepoint hit.
12788
b37052ae
EZ
12789@end table
12790
12791@node Listing Tracepoints
12792@subsection Listing Tracepoints
12793
12794@table @code
e5a67952
MS
12795@kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
12796@kindex info tp @r{[}@var{n}@dots{}@r{]}
b37052ae 12797@cindex information about tracepoints
e5a67952 12798@item info tracepoints @r{[}@var{num}@dots{}@r{]}
1042e4c0
SS
12799Display information about the tracepoint @var{num}. If you don't
12800specify a tracepoint number, displays information about all the
12801tracepoints defined so far. The format is similar to that used for
12802@code{info breakpoints}; in fact, @code{info tracepoints} is the same
12803command, simply restricting itself to tracepoints.
12804
12805A tracepoint's listing may include additional information specific to
12806tracing:
b37052ae
EZ
12807
12808@itemize @bullet
12809@item
b37052ae 12810its passcount as given by the @code{passcount @var{n}} command
f2a8bc8a
YQ
12811
12812@item
12813the state about installed on target of each location
b37052ae
EZ
12814@end itemize
12815
12816@smallexample
12817(@value{GDBP}) @b{info trace}
1042e4c0
SS
12818Num Type Disp Enb Address What
128191 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
5a9351ae
SS
12820 while-stepping 20
12821 collect globfoo, $regs
12822 end
12823 collect globfoo2
12824 end
1042e4c0 12825 pass count 1200
f2a8bc8a
YQ
128262 tracepoint keep y <MULTIPLE>
12827 collect $eip
128282.1 y 0x0804859c in func4 at change-loc.h:35
12829 installed on target
128302.2 y 0xb7ffc480 in func4 at change-loc.h:35
12831 installed on target
128322.3 y <PENDING> set_tracepoint
128333 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
12834 not installed on target
b37052ae
EZ
12835(@value{GDBP})
12836@end smallexample
12837
12838@noindent
12839This command can be abbreviated @code{info tp}.
12840@end table
12841
0fb4aa4b
PA
12842@node Listing Static Tracepoint Markers
12843@subsection Listing Static Tracepoint Markers
12844
12845@table @code
12846@kindex info static-tracepoint-markers
12847@cindex information about static tracepoint markers
12848@item info static-tracepoint-markers
12849Display information about all static tracepoint markers defined in the
12850program.
12851
12852For each marker, the following columns are printed:
12853
12854@table @emph
12855@item Count
12856An incrementing counter, output to help readability. This is not a
12857stable identifier.
12858@item ID
12859The marker ID, as reported by the target.
12860@item Enabled or Disabled
12861Probed markers are tagged with @samp{y}. @samp{n} identifies marks
12862that are not enabled.
12863@item Address
12864Where the marker is in your program, as a memory address.
12865@item What
12866Where the marker is in the source for your program, as a file and line
12867number. If the debug information included in the program does not
12868allow @value{GDBN} to locate the source of the marker, this column
12869will be left blank.
12870@end table
12871
12872@noindent
12873In addition, the following information may be printed for each marker:
12874
12875@table @emph
12876@item Data
12877User data passed to the tracing library by the marker call. In the
12878UST backend, this is the format string passed as argument to the
12879marker call.
12880@item Static tracepoints probing the marker
12881The list of static tracepoints attached to the marker.
12882@end table
12883
12884@smallexample
12885(@value{GDBP}) info static-tracepoint-markers
12886Cnt ID Enb Address What
128871 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
12888 Data: number1 %d number2 %d
12889 Probed by static tracepoints: #2
128902 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
12891 Data: str %s
12892(@value{GDBP})
12893@end smallexample
12894@end table
12895
79a6e687
BW
12896@node Starting and Stopping Trace Experiments
12897@subsection Starting and Stopping Trace Experiments
b37052ae
EZ
12898
12899@table @code
f196051f 12900@kindex tstart [ @var{notes} ]
b37052ae
EZ
12901@cindex start a new trace experiment
12902@cindex collected data discarded
12903@item tstart
f196051f
SS
12904This command starts the trace experiment, and begins collecting data.
12905It has the side effect of discarding all the data collected in the
12906trace buffer during the previous trace experiment. If any arguments
12907are supplied, they are taken as a note and stored with the trace
12908experiment's state. The notes may be arbitrary text, and are
12909especially useful with disconnected tracing in a multi-user context;
12910the notes can explain what the trace is doing, supply user contact
12911information, and so forth.
12912
12913@kindex tstop [ @var{notes} ]
b37052ae
EZ
12914@cindex stop a running trace experiment
12915@item tstop
f196051f
SS
12916This command stops the trace experiment. If any arguments are
12917supplied, they are recorded with the experiment as a note. This is
12918useful if you are stopping a trace started by someone else, for
12919instance if the trace is interfering with the system's behavior and
12920needs to be stopped quickly.
b37052ae 12921
68c71a2e 12922@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
12923automatically if any tracepoint's passcount is reached
12924(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
12925
12926@kindex tstatus
12927@cindex status of trace data collection
12928@cindex trace experiment, status of
12929@item tstatus
12930This command displays the status of the current trace data
12931collection.
12932@end table
12933
12934Here is an example of the commands we described so far:
12935
12936@smallexample
12937(@value{GDBP}) @b{trace gdb_c_test}
12938(@value{GDBP}) @b{actions}
12939Enter actions for tracepoint #1, one per line.
12940> collect $regs,$locals,$args
12941> while-stepping 11
12942 > collect $regs
12943 > end
12944> end
12945(@value{GDBP}) @b{tstart}
12946 [time passes @dots{}]
12947(@value{GDBP}) @b{tstop}
12948@end smallexample
12949
03f2bd59 12950@anchor{disconnected tracing}
d5551862
SS
12951@cindex disconnected tracing
12952You can choose to continue running the trace experiment even if
12953@value{GDBN} disconnects from the target, voluntarily or
12954involuntarily. For commands such as @code{detach}, the debugger will
12955ask what you want to do with the trace. But for unexpected
12956terminations (@value{GDBN} crash, network outage), it would be
12957unfortunate to lose hard-won trace data, so the variable
12958@code{disconnected-tracing} lets you decide whether the trace should
12959continue running without @value{GDBN}.
12960
12961@table @code
12962@item set disconnected-tracing on
12963@itemx set disconnected-tracing off
12964@kindex set disconnected-tracing
12965Choose whether a tracing run should continue to run if @value{GDBN}
12966has disconnected from the target. Note that @code{detach} or
12967@code{quit} will ask you directly what to do about a running trace no
12968matter what this variable's setting, so the variable is mainly useful
12969for handling unexpected situations, such as loss of the network.
12970
12971@item show disconnected-tracing
12972@kindex show disconnected-tracing
12973Show the current choice for disconnected tracing.
12974
12975@end table
12976
12977When you reconnect to the target, the trace experiment may or may not
12978still be running; it might have filled the trace buffer in the
12979meantime, or stopped for one of the other reasons. If it is running,
12980it will continue after reconnection.
12981
12982Upon reconnection, the target will upload information about the
12983tracepoints in effect. @value{GDBN} will then compare that
12984information to the set of tracepoints currently defined, and attempt
12985to match them up, allowing for the possibility that the numbers may
12986have changed due to creation and deletion in the meantime. If one of
12987the target's tracepoints does not match any in @value{GDBN}, the
12988debugger will create a new tracepoint, so that you have a number with
12989which to specify that tracepoint. This matching-up process is
12990necessarily heuristic, and it may result in useless tracepoints being
12991created; you may simply delete them if they are of no use.
b37052ae 12992
4daf5ac0
SS
12993@cindex circular trace buffer
12994If your target agent supports a @dfn{circular trace buffer}, then you
12995can run a trace experiment indefinitely without filling the trace
12996buffer; when space runs out, the agent deletes already-collected trace
12997frames, oldest first, until there is enough room to continue
12998collecting. This is especially useful if your tracepoints are being
12999hit too often, and your trace gets terminated prematurely because the
13000buffer is full. To ask for a circular trace buffer, simply set
81896e36 13001@samp{circular-trace-buffer} to on. You can set this at any time,
4daf5ac0
SS
13002including during tracing; if the agent can do it, it will change
13003buffer handling on the fly, otherwise it will not take effect until
13004the next run.
13005
13006@table @code
13007@item set circular-trace-buffer on
13008@itemx set circular-trace-buffer off
13009@kindex set circular-trace-buffer
13010Choose whether a tracing run should use a linear or circular buffer
13011for trace data. A linear buffer will not lose any trace data, but may
13012fill up prematurely, while a circular buffer will discard old trace
13013data, but it will have always room for the latest tracepoint hits.
13014
13015@item show circular-trace-buffer
13016@kindex show circular-trace-buffer
13017Show the current choice for the trace buffer. Note that this may not
13018match the agent's current buffer handling, nor is it guaranteed to
13019match the setting that might have been in effect during a past run,
13020for instance if you are looking at frames from a trace file.
13021
13022@end table
13023
f6f899bf
HAQ
13024@table @code
13025@item set trace-buffer-size @var{n}
f81d1120 13026@itemx set trace-buffer-size unlimited
f6f899bf
HAQ
13027@kindex set trace-buffer-size
13028Request that the target use a trace buffer of @var{n} bytes. Not all
13029targets will honor the request; they may have a compiled-in size for
13030the trace buffer, or some other limitation. Set to a value of
f81d1120
PA
13031@code{unlimited} or @code{-1} to let the target use whatever size it
13032likes. This is also the default.
f6f899bf
HAQ
13033
13034@item show trace-buffer-size
13035@kindex show trace-buffer-size
13036Show the current requested size for the trace buffer. Note that this
13037will only match the actual size if the target supports size-setting,
13038and was able to handle the requested size. For instance, if the
13039target can only change buffer size between runs, this variable will
13040not reflect the change until the next run starts. Use @code{tstatus}
13041to get a report of the actual buffer size.
13042@end table
13043
f196051f
SS
13044@table @code
13045@item set trace-user @var{text}
13046@kindex set trace-user
13047
13048@item show trace-user
13049@kindex show trace-user
13050
13051@item set trace-notes @var{text}
13052@kindex set trace-notes
13053Set the trace run's notes.
13054
13055@item show trace-notes
13056@kindex show trace-notes
13057Show the trace run's notes.
13058
13059@item set trace-stop-notes @var{text}
13060@kindex set trace-stop-notes
13061Set the trace run's stop notes. The handling of the note is as for
13062@code{tstop} arguments; the set command is convenient way to fix a
13063stop note that is mistaken or incomplete.
13064
13065@item show trace-stop-notes
13066@kindex show trace-stop-notes
13067Show the trace run's stop notes.
13068
13069@end table
13070
c9429232
SS
13071@node Tracepoint Restrictions
13072@subsection Tracepoint Restrictions
13073
13074@cindex tracepoint restrictions
13075There are a number of restrictions on the use of tracepoints. As
13076described above, tracepoint data gathering occurs on the target
13077without interaction from @value{GDBN}. Thus the full capabilities of
13078the debugger are not available during data gathering, and then at data
13079examination time, you will be limited by only having what was
13080collected. The following items describe some common problems, but it
13081is not exhaustive, and you may run into additional difficulties not
13082mentioned here.
13083
13084@itemize @bullet
13085
13086@item
13087Tracepoint expressions are intended to gather objects (lvalues). Thus
13088the full flexibility of GDB's expression evaluator is not available.
13089You cannot call functions, cast objects to aggregate types, access
13090convenience variables or modify values (except by assignment to trace
13091state variables). Some language features may implicitly call
13092functions (for instance Objective-C fields with accessors), and therefore
13093cannot be collected either.
13094
13095@item
13096Collection of local variables, either individually or in bulk with
13097@code{$locals} or @code{$args}, during @code{while-stepping} may
13098behave erratically. The stepping action may enter a new scope (for
13099instance by stepping into a function), or the location of the variable
13100may change (for instance it is loaded into a register). The
13101tracepoint data recorded uses the location information for the
13102variables that is correct for the tracepoint location. When the
13103tracepoint is created, it is not possible, in general, to determine
13104where the steps of a @code{while-stepping} sequence will advance the
13105program---particularly if a conditional branch is stepped.
13106
13107@item
13108Collection of an incompletely-initialized or partially-destroyed object
13109may result in something that @value{GDBN} cannot display, or displays
13110in a misleading way.
13111
13112@item
13113When @value{GDBN} displays a pointer to character it automatically
13114dereferences the pointer to also display characters of the string
13115being pointed to. However, collecting the pointer during tracing does
13116not automatically collect the string. You need to explicitly
13117dereference the pointer and provide size information if you want to
13118collect not only the pointer, but the memory pointed to. For example,
13119@code{*ptr@@50} can be used to collect the 50 element array pointed to
13120by @code{ptr}.
13121
13122@item
13123It is not possible to collect a complete stack backtrace at a
13124tracepoint. Instead, you may collect the registers and a few hundred
d99f7e48 13125bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
c9429232
SS
13126(adjust to use the name of the actual stack pointer register on your
13127target architecture, and the amount of stack you wish to capture).
13128Then the @code{backtrace} command will show a partial backtrace when
13129using a trace frame. The number of stack frames that can be examined
13130depends on the sizes of the frames in the collected stack. Note that
13131if you ask for a block so large that it goes past the bottom of the
13132stack, the target agent may report an error trying to read from an
13133invalid address.
13134
af54718e
SS
13135@item
13136If you do not collect registers at a tracepoint, @value{GDBN} can
13137infer that the value of @code{$pc} must be the same as the address of
13138the tracepoint and use that when you are looking at a trace frame
13139for that tracepoint. However, this cannot work if the tracepoint has
13140multiple locations (for instance if it was set in a function that was
13141inlined), or if it has a @code{while-stepping} loop. In those cases
13142@value{GDBN} will warn you that it can't infer @code{$pc}, and default
13143it to zero.
13144
c9429232
SS
13145@end itemize
13146
b37052ae 13147@node Analyze Collected Data
79a6e687 13148@section Using the Collected Data
b37052ae
EZ
13149
13150After the tracepoint experiment ends, you use @value{GDBN} commands
13151for examining the trace data. The basic idea is that each tracepoint
13152collects a trace @dfn{snapshot} every time it is hit and another
13153snapshot every time it single-steps. All these snapshots are
13154consecutively numbered from zero and go into a buffer, and you can
13155examine them later. The way you examine them is to @dfn{focus} on a
13156specific trace snapshot. When the remote stub is focused on a trace
13157snapshot, it will respond to all @value{GDBN} requests for memory and
13158registers by reading from the buffer which belongs to that snapshot,
13159rather than from @emph{real} memory or registers of the program being
13160debugged. This means that @strong{all} @value{GDBN} commands
13161(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
13162behave as if we were currently debugging the program state as it was
13163when the tracepoint occurred. Any requests for data that are not in
13164the buffer will fail.
13165
13166@menu
13167* tfind:: How to select a trace snapshot
13168* tdump:: How to display all data for a snapshot
6149aea9 13169* save tracepoints:: How to save tracepoints for a future run
b37052ae
EZ
13170@end menu
13171
13172@node tfind
13173@subsection @code{tfind @var{n}}
13174
13175@kindex tfind
13176@cindex select trace snapshot
13177@cindex find trace snapshot
13178The basic command for selecting a trace snapshot from the buffer is
13179@code{tfind @var{n}}, which finds trace snapshot number @var{n},
13180counting from zero. If no argument @var{n} is given, the next
13181snapshot is selected.
13182
13183Here are the various forms of using the @code{tfind} command.
13184
13185@table @code
13186@item tfind start
13187Find the first snapshot in the buffer. This is a synonym for
13188@code{tfind 0} (since 0 is the number of the first snapshot).
13189
13190@item tfind none
13191Stop debugging trace snapshots, resume @emph{live} debugging.
13192
13193@item tfind end
13194Same as @samp{tfind none}.
13195
13196@item tfind
13197No argument means find the next trace snapshot.
13198
13199@item tfind -
13200Find the previous trace snapshot before the current one. This permits
13201retracing earlier steps.
13202
13203@item tfind tracepoint @var{num}
13204Find the next snapshot associated with tracepoint @var{num}. Search
13205proceeds forward from the last examined trace snapshot. If no
13206argument @var{num} is given, it means find the next snapshot collected
13207for the same tracepoint as the current snapshot.
13208
13209@item tfind pc @var{addr}
13210Find the next snapshot associated with the value @var{addr} of the
13211program counter. Search proceeds forward from the last examined trace
13212snapshot. If no argument @var{addr} is given, it means find the next
13213snapshot with the same value of PC as the current snapshot.
13214
13215@item tfind outside @var{addr1}, @var{addr2}
13216Find the next snapshot whose PC is outside the given range of
081dfbf7 13217addresses (exclusive).
b37052ae
EZ
13218
13219@item tfind range @var{addr1}, @var{addr2}
13220Find the next snapshot whose PC is between @var{addr1} and
081dfbf7 13221@var{addr2} (inclusive).
b37052ae
EZ
13222
13223@item tfind line @r{[}@var{file}:@r{]}@var{n}
13224Find the next snapshot associated with the source line @var{n}. If
13225the optional argument @var{file} is given, refer to line @var{n} in
13226that source file. Search proceeds forward from the last examined
13227trace snapshot. If no argument @var{n} is given, it means find the
13228next line other than the one currently being examined; thus saying
13229@code{tfind line} repeatedly can appear to have the same effect as
13230stepping from line to line in a @emph{live} debugging session.
13231@end table
13232
13233The default arguments for the @code{tfind} commands are specifically
13234designed to make it easy to scan through the trace buffer. For
13235instance, @code{tfind} with no argument selects the next trace
13236snapshot, and @code{tfind -} with no argument selects the previous
13237trace snapshot. So, by giving one @code{tfind} command, and then
13238simply hitting @key{RET} repeatedly you can examine all the trace
13239snapshots in order. Or, by saying @code{tfind -} and then hitting
13240@key{RET} repeatedly you can examine the snapshots in reverse order.
13241The @code{tfind line} command with no argument selects the snapshot
13242for the next source line executed. The @code{tfind pc} command with
13243no argument selects the next snapshot with the same program counter
13244(PC) as the current frame. The @code{tfind tracepoint} command with
13245no argument selects the next trace snapshot collected by the same
13246tracepoint as the current one.
13247
13248In addition to letting you scan through the trace buffer manually,
13249these commands make it easy to construct @value{GDBN} scripts that
13250scan through the trace buffer and print out whatever collected data
13251you are interested in. Thus, if we want to examine the PC, FP, and SP
13252registers from each trace frame in the buffer, we can say this:
13253
13254@smallexample
13255(@value{GDBP}) @b{tfind start}
13256(@value{GDBP}) @b{while ($trace_frame != -1)}
13257> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
13258 $trace_frame, $pc, $sp, $fp
13259> tfind
13260> end
13261
13262Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
13263Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
13264Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
13265Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
13266Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
13267Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
13268Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
13269Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
13270Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
13271Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
13272Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
13273@end smallexample
13274
13275Or, if we want to examine the variable @code{X} at each source line in
13276the buffer:
13277
13278@smallexample
13279(@value{GDBP}) @b{tfind start}
13280(@value{GDBP}) @b{while ($trace_frame != -1)}
13281> printf "Frame %d, X == %d\n", $trace_frame, X
13282> tfind line
13283> end
13284
13285Frame 0, X = 1
13286Frame 7, X = 2
13287Frame 13, X = 255
13288@end smallexample
13289
13290@node tdump
13291@subsection @code{tdump}
13292@kindex tdump
13293@cindex dump all data collected at tracepoint
13294@cindex tracepoint data, display
13295
13296This command takes no arguments. It prints all the data collected at
13297the current trace snapshot.
13298
13299@smallexample
13300(@value{GDBP}) @b{trace 444}
13301(@value{GDBP}) @b{actions}
13302Enter actions for tracepoint #2, one per line:
13303> collect $regs, $locals, $args, gdb_long_test
13304> end
13305
13306(@value{GDBP}) @b{tstart}
13307
13308(@value{GDBP}) @b{tfind line 444}
13309#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
13310at gdb_test.c:444
13311444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
13312
13313(@value{GDBP}) @b{tdump}
13314Data collected at tracepoint 2, trace frame 1:
13315d0 0xc4aa0085 -995491707
13316d1 0x18 24
13317d2 0x80 128
13318d3 0x33 51
13319d4 0x71aea3d 119204413
13320d5 0x22 34
13321d6 0xe0 224
13322d7 0x380035 3670069
13323a0 0x19e24a 1696330
13324a1 0x3000668 50333288
13325a2 0x100 256
13326a3 0x322000 3284992
13327a4 0x3000698 50333336
13328a5 0x1ad3cc 1758156
13329fp 0x30bf3c 0x30bf3c
13330sp 0x30bf34 0x30bf34
13331ps 0x0 0
13332pc 0x20b2c8 0x20b2c8
13333fpcontrol 0x0 0
13334fpstatus 0x0 0
13335fpiaddr 0x0 0
13336p = 0x20e5b4 "gdb-test"
13337p1 = (void *) 0x11
13338p2 = (void *) 0x22
13339p3 = (void *) 0x33
13340p4 = (void *) 0x44
13341p5 = (void *) 0x55
13342p6 = (void *) 0x66
13343gdb_long_test = 17 '\021'
13344
13345(@value{GDBP})
13346@end smallexample
13347
af54718e
SS
13348@code{tdump} works by scanning the tracepoint's current collection
13349actions and printing the value of each expression listed. So
13350@code{tdump} can fail, if after a run, you change the tracepoint's
13351actions to mention variables that were not collected during the run.
13352
13353Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
13354uses the collected value of @code{$pc} to distinguish between trace
13355frames that were collected at the tracepoint hit, and frames that were
13356collected while stepping. This allows it to correctly choose whether
13357to display the basic list of collections, or the collections from the
13358body of the while-stepping loop. However, if @code{$pc} was not collected,
13359then @code{tdump} will always attempt to dump using the basic collection
13360list, and may fail if a while-stepping frame does not include all the
13361same data that is collected at the tracepoint hit.
13362@c This is getting pretty arcane, example would be good.
13363
6149aea9
PA
13364@node save tracepoints
13365@subsection @code{save tracepoints @var{filename}}
13366@kindex save tracepoints
b37052ae
EZ
13367@kindex save-tracepoints
13368@cindex save tracepoints for future sessions
13369
13370This command saves all current tracepoint definitions together with
13371their actions and passcounts, into a file @file{@var{filename}}
13372suitable for use in a later debugging session. To read the saved
13373tracepoint definitions, use the @code{source} command (@pxref{Command
6149aea9
PA
13374Files}). The @w{@code{save-tracepoints}} command is a deprecated
13375alias for @w{@code{save tracepoints}}
b37052ae
EZ
13376
13377@node Tracepoint Variables
13378@section Convenience Variables for Tracepoints
13379@cindex tracepoint variables
13380@cindex convenience variables for tracepoints
13381
13382@table @code
13383@vindex $trace_frame
13384@item (int) $trace_frame
13385The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
13386snapshot is selected.
13387
13388@vindex $tracepoint
13389@item (int) $tracepoint
13390The tracepoint for the current trace snapshot.
13391
13392@vindex $trace_line
13393@item (int) $trace_line
13394The line number for the current trace snapshot.
13395
13396@vindex $trace_file
13397@item (char []) $trace_file
13398The source file for the current trace snapshot.
13399
13400@vindex $trace_func
13401@item (char []) $trace_func
13402The name of the function containing @code{$tracepoint}.
13403@end table
13404
13405Note: @code{$trace_file} is not suitable for use in @code{printf},
13406use @code{output} instead.
13407
13408Here's a simple example of using these convenience variables for
13409stepping through all the trace snapshots and printing some of their
f61e138d
SS
13410data. Note that these are not the same as trace state variables,
13411which are managed by the target.
b37052ae
EZ
13412
13413@smallexample
13414(@value{GDBP}) @b{tfind start}
13415
13416(@value{GDBP}) @b{while $trace_frame != -1}
13417> output $trace_file
13418> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
13419> tfind
13420> end
13421@end smallexample
13422
00bf0b85
SS
13423@node Trace Files
13424@section Using Trace Files
13425@cindex trace files
13426
13427In some situations, the target running a trace experiment may no
13428longer be available; perhaps it crashed, or the hardware was needed
13429for a different activity. To handle these cases, you can arrange to
13430dump the trace data into a file, and later use that file as a source
13431of trace data, via the @code{target tfile} command.
13432
13433@table @code
13434
13435@kindex tsave
13436@item tsave [ -r ] @var{filename}
d0353e76 13437@itemx tsave [-ctf] @var{dirname}
00bf0b85
SS
13438Save the trace data to @var{filename}. By default, this command
13439assumes that @var{filename} refers to the host filesystem, so if
13440necessary @value{GDBN} will copy raw trace data up from the target and
13441then save it. If the target supports it, you can also supply the
13442optional argument @code{-r} (``remote'') to direct the target to save
13443the data directly into @var{filename} in its own filesystem, which may be
13444more efficient if the trace buffer is very large. (Note, however, that
13445@code{target tfile} can only read from files accessible to the host.)
d0353e76
YQ
13446By default, this command will save trace frame in tfile format.
13447You can supply the optional argument @code{-ctf} to save date in CTF
13448format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
13449that can be shared by multiple debugging and tracing tools. Please go to
13450@indicateurl{http://www.efficios.com/ctf} to get more information.
00bf0b85
SS
13451
13452@kindex target tfile
13453@kindex tfile
393fd4c3
YQ
13454@kindex target ctf
13455@kindex ctf
00bf0b85 13456@item target tfile @var{filename}
393fd4c3
YQ
13457@itemx target ctf @var{dirname}
13458Use the file named @var{filename} or directory named @var{dirname} as
13459a source of trace data. Commands that examine data work as they do with
13460a live target, but it is not possible to run any new trace experiments.
13461@code{tstatus} will report the state of the trace run at the moment
13462the data was saved, as well as the current trace frame you are examining.
697aa1b7 13463Both @var{filename} and @var{dirname} must be on a filesystem accessible to
393fd4c3
YQ
13464the host.
13465
13466@smallexample
13467(@value{GDBP}) target ctf ctf.ctf
13468(@value{GDBP}) tfind
13469Found trace frame 0, tracepoint 2
1347039 ++a; /* set tracepoint 1 here */
13471(@value{GDBP}) tdump
13472Data collected at tracepoint 2, trace frame 0:
13473i = 0
13474a = 0
13475b = 1 '\001'
13476c = @{"123", "456", "789", "123", "456", "789"@}
13477d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
13478(@value{GDBP}) p b
13479$1 = 1
13480@end smallexample
00bf0b85
SS
13481
13482@end table
13483
df0cd8c5
JB
13484@node Overlays
13485@chapter Debugging Programs That Use Overlays
13486@cindex overlays
13487
13488If your program is too large to fit completely in your target system's
13489memory, you can sometimes use @dfn{overlays} to work around this
13490problem. @value{GDBN} provides some support for debugging programs that
13491use overlays.
13492
13493@menu
13494* How Overlays Work:: A general explanation of overlays.
13495* Overlay Commands:: Managing overlays in @value{GDBN}.
13496* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
13497 mapped by asking the inferior.
13498* Overlay Sample Program:: A sample program using overlays.
13499@end menu
13500
13501@node How Overlays Work
13502@section How Overlays Work
13503@cindex mapped overlays
13504@cindex unmapped overlays
13505@cindex load address, overlay's
13506@cindex mapped address
13507@cindex overlay area
13508
13509Suppose you have a computer whose instruction address space is only 64
13510kilobytes long, but which has much more memory which can be accessed by
13511other means: special instructions, segment registers, or memory
13512management hardware, for example. Suppose further that you want to
13513adapt a program which is larger than 64 kilobytes to run on this system.
13514
13515One solution is to identify modules of your program which are relatively
13516independent, and need not call each other directly; call these modules
13517@dfn{overlays}. Separate the overlays from the main program, and place
13518their machine code in the larger memory. Place your main program in
13519instruction memory, but leave at least enough space there to hold the
13520largest overlay as well.
13521
13522Now, to call a function located in an overlay, you must first copy that
13523overlay's machine code from the large memory into the space set aside
13524for it in the instruction memory, and then jump to its entry point
13525there.
13526
c928edc0
AC
13527@c NB: In the below the mapped area's size is greater or equal to the
13528@c size of all overlays. This is intentional to remind the developer
13529@c that overlays don't necessarily need to be the same size.
13530
474c8240 13531@smallexample
df0cd8c5 13532@group
c928edc0
AC
13533 Data Instruction Larger
13534Address Space Address Space Address Space
13535+-----------+ +-----------+ +-----------+
13536| | | | | |
13537+-----------+ +-----------+ +-----------+<-- overlay 1
13538| program | | main | .----| overlay 1 | load address
13539| variables | | program | | +-----------+
13540| and heap | | | | | |
13541+-----------+ | | | +-----------+<-- overlay 2
13542| | +-----------+ | | | load address
13543+-----------+ | | | .-| overlay 2 |
13544 | | | | | |
13545 mapped --->+-----------+ | | +-----------+
13546 address | | | | | |
13547 | overlay | <-' | | |
13548 | area | <---' +-----------+<-- overlay 3
13549 | | <---. | | load address
13550 +-----------+ `--| overlay 3 |
13551 | | | |
13552 +-----------+ | |
13553 +-----------+
13554 | |
13555 +-----------+
13556
13557 @anchor{A code overlay}A code overlay
df0cd8c5 13558@end group
474c8240 13559@end smallexample
df0cd8c5 13560
c928edc0
AC
13561The diagram (@pxref{A code overlay}) shows a system with separate data
13562and instruction address spaces. To map an overlay, the program copies
13563its code from the larger address space to the instruction address space.
13564Since the overlays shown here all use the same mapped address, only one
13565may be mapped at a time. For a system with a single address space for
13566data and instructions, the diagram would be similar, except that the
13567program variables and heap would share an address space with the main
13568program and the overlay area.
df0cd8c5
JB
13569
13570An overlay loaded into instruction memory and ready for use is called a
13571@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
13572instruction memory. An overlay not present (or only partially present)
13573in instruction memory is called @dfn{unmapped}; its @dfn{load address}
13574is its address in the larger memory. The mapped address is also called
13575the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
13576called the @dfn{load memory address}, or @dfn{LMA}.
13577
13578Unfortunately, overlays are not a completely transparent way to adapt a
13579program to limited instruction memory. They introduce a new set of
13580global constraints you must keep in mind as you design your program:
13581
13582@itemize @bullet
13583
13584@item
13585Before calling or returning to a function in an overlay, your program
13586must make sure that overlay is actually mapped. Otherwise, the call or
13587return will transfer control to the right address, but in the wrong
13588overlay, and your program will probably crash.
13589
13590@item
13591If the process of mapping an overlay is expensive on your system, you
13592will need to choose your overlays carefully to minimize their effect on
13593your program's performance.
13594
13595@item
13596The executable file you load onto your system must contain each
13597overlay's instructions, appearing at the overlay's load address, not its
13598mapped address. However, each overlay's instructions must be relocated
13599and its symbols defined as if the overlay were at its mapped address.
13600You can use GNU linker scripts to specify different load and relocation
13601addresses for pieces of your program; see @ref{Overlay Description,,,
13602ld.info, Using ld: the GNU linker}.
13603
13604@item
13605The procedure for loading executable files onto your system must be able
13606to load their contents into the larger address space as well as the
13607instruction and data spaces.
13608
13609@end itemize
13610
13611The overlay system described above is rather simple, and could be
13612improved in many ways:
13613
13614@itemize @bullet
13615
13616@item
13617If your system has suitable bank switch registers or memory management
13618hardware, you could use those facilities to make an overlay's load area
13619contents simply appear at their mapped address in instruction space.
13620This would probably be faster than copying the overlay to its mapped
13621area in the usual way.
13622
13623@item
13624If your overlays are small enough, you could set aside more than one
13625overlay area, and have more than one overlay mapped at a time.
13626
13627@item
13628You can use overlays to manage data, as well as instructions. In
13629general, data overlays are even less transparent to your design than
13630code overlays: whereas code overlays only require care when you call or
13631return to functions, data overlays require care every time you access
13632the data. Also, if you change the contents of a data overlay, you
13633must copy its contents back out to its load address before you can copy a
13634different data overlay into the same mapped area.
13635
13636@end itemize
13637
13638
13639@node Overlay Commands
13640@section Overlay Commands
13641
13642To use @value{GDBN}'s overlay support, each overlay in your program must
13643correspond to a separate section of the executable file. The section's
13644virtual memory address and load memory address must be the overlay's
13645mapped and load addresses. Identifying overlays with sections allows
13646@value{GDBN} to determine the appropriate address of a function or
13647variable, depending on whether the overlay is mapped or not.
13648
13649@value{GDBN}'s overlay commands all start with the word @code{overlay};
13650you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
13651
13652@table @code
13653@item overlay off
4644b6e3 13654@kindex overlay
df0cd8c5
JB
13655Disable @value{GDBN}'s overlay support. When overlay support is
13656disabled, @value{GDBN} assumes that all functions and variables are
13657always present at their mapped addresses. By default, @value{GDBN}'s
13658overlay support is disabled.
13659
13660@item overlay manual
df0cd8c5
JB
13661@cindex manual overlay debugging
13662Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
13663relies on you to tell it which overlays are mapped, and which are not,
13664using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
13665commands described below.
13666
13667@item overlay map-overlay @var{overlay}
13668@itemx overlay map @var{overlay}
df0cd8c5
JB
13669@cindex map an overlay
13670Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
13671be the name of the object file section containing the overlay. When an
13672overlay is mapped, @value{GDBN} assumes it can find the overlay's
13673functions and variables at their mapped addresses. @value{GDBN} assumes
13674that any other overlays whose mapped ranges overlap that of
13675@var{overlay} are now unmapped.
13676
13677@item overlay unmap-overlay @var{overlay}
13678@itemx overlay unmap @var{overlay}
df0cd8c5
JB
13679@cindex unmap an overlay
13680Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
13681must be the name of the object file section containing the overlay.
13682When an overlay is unmapped, @value{GDBN} assumes it can find the
13683overlay's functions and variables at their load addresses.
13684
13685@item overlay auto
df0cd8c5
JB
13686Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
13687consults a data structure the overlay manager maintains in the inferior
13688to see which overlays are mapped. For details, see @ref{Automatic
13689Overlay Debugging}.
13690
13691@item overlay load-target
13692@itemx overlay load
df0cd8c5
JB
13693@cindex reloading the overlay table
13694Re-read the overlay table from the inferior. Normally, @value{GDBN}
13695re-reads the table @value{GDBN} automatically each time the inferior
13696stops, so this command should only be necessary if you have changed the
13697overlay mapping yourself using @value{GDBN}. This command is only
13698useful when using automatic overlay debugging.
13699
13700@item overlay list-overlays
13701@itemx overlay list
13702@cindex listing mapped overlays
13703Display a list of the overlays currently mapped, along with their mapped
13704addresses, load addresses, and sizes.
13705
13706@end table
13707
13708Normally, when @value{GDBN} prints a code address, it includes the name
13709of the function the address falls in:
13710
474c8240 13711@smallexample
f7dc1244 13712(@value{GDBP}) print main
df0cd8c5 13713$3 = @{int ()@} 0x11a0 <main>
474c8240 13714@end smallexample
df0cd8c5
JB
13715@noindent
13716When overlay debugging is enabled, @value{GDBN} recognizes code in
13717unmapped overlays, and prints the names of unmapped functions with
13718asterisks around them. For example, if @code{foo} is a function in an
13719unmapped overlay, @value{GDBN} prints it this way:
13720
474c8240 13721@smallexample
f7dc1244 13722(@value{GDBP}) overlay list
df0cd8c5 13723No sections are mapped.
f7dc1244 13724(@value{GDBP}) print foo
df0cd8c5 13725$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 13726@end smallexample
df0cd8c5
JB
13727@noindent
13728When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
13729name normally:
13730
474c8240 13731@smallexample
f7dc1244 13732(@value{GDBP}) overlay list
b383017d 13733Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 13734 mapped at 0x1016 - 0x104a
f7dc1244 13735(@value{GDBP}) print foo
df0cd8c5 13736$6 = @{int (int)@} 0x1016 <foo>
474c8240 13737@end smallexample
df0cd8c5
JB
13738
13739When overlay debugging is enabled, @value{GDBN} can find the correct
13740address for functions and variables in an overlay, whether or not the
13741overlay is mapped. This allows most @value{GDBN} commands, like
13742@code{break} and @code{disassemble}, to work normally, even on unmapped
13743code. However, @value{GDBN}'s breakpoint support has some limitations:
13744
13745@itemize @bullet
13746@item
13747@cindex breakpoints in overlays
13748@cindex overlays, setting breakpoints in
13749You can set breakpoints in functions in unmapped overlays, as long as
13750@value{GDBN} can write to the overlay at its load address.
13751@item
13752@value{GDBN} can not set hardware or simulator-based breakpoints in
13753unmapped overlays. However, if you set a breakpoint at the end of your
13754overlay manager (and tell @value{GDBN} which overlays are now mapped, if
13755you are using manual overlay management), @value{GDBN} will re-set its
13756breakpoints properly.
13757@end itemize
13758
13759
13760@node Automatic Overlay Debugging
13761@section Automatic Overlay Debugging
13762@cindex automatic overlay debugging
13763
13764@value{GDBN} can automatically track which overlays are mapped and which
13765are not, given some simple co-operation from the overlay manager in the
13766inferior. If you enable automatic overlay debugging with the
13767@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
13768looks in the inferior's memory for certain variables describing the
13769current state of the overlays.
13770
13771Here are the variables your overlay manager must define to support
13772@value{GDBN}'s automatic overlay debugging:
13773
13774@table @asis
13775
13776@item @code{_ovly_table}:
13777This variable must be an array of the following structures:
13778
474c8240 13779@smallexample
df0cd8c5
JB
13780struct
13781@{
13782 /* The overlay's mapped address. */
13783 unsigned long vma;
13784
13785 /* The size of the overlay, in bytes. */
13786 unsigned long size;
13787
13788 /* The overlay's load address. */
13789 unsigned long lma;
13790
13791 /* Non-zero if the overlay is currently mapped;
13792 zero otherwise. */
13793 unsigned long mapped;
13794@}
474c8240 13795@end smallexample
df0cd8c5
JB
13796
13797@item @code{_novlys}:
13798This variable must be a four-byte signed integer, holding the total
13799number of elements in @code{_ovly_table}.
13800
13801@end table
13802
13803To decide whether a particular overlay is mapped or not, @value{GDBN}
13804looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
13805@code{lma} members equal the VMA and LMA of the overlay's section in the
13806executable file. When @value{GDBN} finds a matching entry, it consults
13807the entry's @code{mapped} member to determine whether the overlay is
13808currently mapped.
13809
81d46470 13810In addition, your overlay manager may define a function called
def71bfa 13811@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
13812will silently set a breakpoint there. If the overlay manager then
13813calls this function whenever it has changed the overlay table, this
13814will enable @value{GDBN} to accurately keep track of which overlays
13815are in program memory, and update any breakpoints that may be set
b383017d 13816in overlays. This will allow breakpoints to work even if the
81d46470
MS
13817overlays are kept in ROM or other non-writable memory while they
13818are not being executed.
df0cd8c5
JB
13819
13820@node Overlay Sample Program
13821@section Overlay Sample Program
13822@cindex overlay example program
13823
13824When linking a program which uses overlays, you must place the overlays
13825at their load addresses, while relocating them to run at their mapped
13826addresses. To do this, you must write a linker script (@pxref{Overlay
13827Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
13828since linker scripts are specific to a particular host system, target
13829architecture, and target memory layout, this manual cannot provide
13830portable sample code demonstrating @value{GDBN}'s overlay support.
13831
13832However, the @value{GDBN} source distribution does contain an overlaid
13833program, with linker scripts for a few systems, as part of its test
13834suite. The program consists of the following files from
13835@file{gdb/testsuite/gdb.base}:
13836
13837@table @file
13838@item overlays.c
13839The main program file.
13840@item ovlymgr.c
13841A simple overlay manager, used by @file{overlays.c}.
13842@item foo.c
13843@itemx bar.c
13844@itemx baz.c
13845@itemx grbx.c
13846Overlay modules, loaded and used by @file{overlays.c}.
13847@item d10v.ld
13848@itemx m32r.ld
13849Linker scripts for linking the test program on the @code{d10v-elf}
13850and @code{m32r-elf} targets.
13851@end table
13852
13853You can build the test program using the @code{d10v-elf} GCC
13854cross-compiler like this:
13855
474c8240 13856@smallexample
df0cd8c5
JB
13857$ d10v-elf-gcc -g -c overlays.c
13858$ d10v-elf-gcc -g -c ovlymgr.c
13859$ d10v-elf-gcc -g -c foo.c
13860$ d10v-elf-gcc -g -c bar.c
13861$ d10v-elf-gcc -g -c baz.c
13862$ d10v-elf-gcc -g -c grbx.c
13863$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
13864 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 13865@end smallexample
df0cd8c5
JB
13866
13867The build process is identical for any other architecture, except that
13868you must substitute the appropriate compiler and linker script for the
13869target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
13870
13871
6d2ebf8b 13872@node Languages
c906108c
SS
13873@chapter Using @value{GDBN} with Different Languages
13874@cindex languages
13875
c906108c
SS
13876Although programming languages generally have common aspects, they are
13877rarely expressed in the same manner. For instance, in ANSI C,
13878dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
13879Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 13880represented (and displayed) differently. Hex numbers in C appear as
c906108c 13881@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
13882
13883@cindex working language
13884Language-specific information is built into @value{GDBN} for some languages,
13885allowing you to express operations like the above in your program's
13886native language, and allowing @value{GDBN} to output values in a manner
13887consistent with the syntax of your program's native language. The
13888language you use to build expressions is called the @dfn{working
13889language}.
13890
13891@menu
13892* Setting:: Switching between source languages
13893* Show:: Displaying the language
c906108c 13894* Checks:: Type and range checks
79a6e687
BW
13895* Supported Languages:: Supported languages
13896* Unsupported Languages:: Unsupported languages
c906108c
SS
13897@end menu
13898
6d2ebf8b 13899@node Setting
79a6e687 13900@section Switching Between Source Languages
c906108c
SS
13901
13902There are two ways to control the working language---either have @value{GDBN}
13903set it automatically, or select it manually yourself. You can use the
13904@code{set language} command for either purpose. On startup, @value{GDBN}
13905defaults to setting the language automatically. The working language is
13906used to determine how expressions you type are interpreted, how values
13907are printed, etc.
13908
13909In addition to the working language, every source file that
13910@value{GDBN} knows about has its own working language. For some object
13911file formats, the compiler might indicate which language a particular
13912source file is in. However, most of the time @value{GDBN} infers the
13913language from the name of the file. The language of a source file
b37052ae 13914controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 13915show each frame appropriately for its own language. There is no way to
d4f3574e
SS
13916set the language of a source file from within @value{GDBN}, but you can
13917set the language associated with a filename extension. @xref{Show, ,
79a6e687 13918Displaying the Language}.
c906108c
SS
13919
13920This is most commonly a problem when you use a program, such
5d161b24 13921as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
13922another language. In that case, make the
13923program use @code{#line} directives in its C output; that way
13924@value{GDBN} will know the correct language of the source code of the original
13925program, and will display that source code, not the generated C code.
13926
13927@menu
13928* Filenames:: Filename extensions and languages.
13929* Manually:: Setting the working language manually
13930* Automatically:: Having @value{GDBN} infer the source language
13931@end menu
13932
6d2ebf8b 13933@node Filenames
79a6e687 13934@subsection List of Filename Extensions and Languages
c906108c
SS
13935
13936If a source file name ends in one of the following extensions, then
13937@value{GDBN} infers that its language is the one indicated.
13938
13939@table @file
e07c999f
PH
13940@item .ada
13941@itemx .ads
13942@itemx .adb
13943@itemx .a
13944Ada source file.
c906108c
SS
13945
13946@item .c
13947C source file
13948
13949@item .C
13950@itemx .cc
13951@itemx .cp
13952@itemx .cpp
13953@itemx .cxx
13954@itemx .c++
b37052ae 13955C@t{++} source file
c906108c 13956
6aecb9c2
JB
13957@item .d
13958D source file
13959
b37303ee
AF
13960@item .m
13961Objective-C source file
13962
c906108c
SS
13963@item .f
13964@itemx .F
13965Fortran source file
13966
c906108c
SS
13967@item .mod
13968Modula-2 source file
c906108c
SS
13969
13970@item .s
13971@itemx .S
13972Assembler source file. This actually behaves almost like C, but
13973@value{GDBN} does not skip over function prologues when stepping.
13974@end table
13975
13976In addition, you may set the language associated with a filename
79a6e687 13977extension. @xref{Show, , Displaying the Language}.
c906108c 13978
6d2ebf8b 13979@node Manually
79a6e687 13980@subsection Setting the Working Language
c906108c
SS
13981
13982If you allow @value{GDBN} to set the language automatically,
13983expressions are interpreted the same way in your debugging session and
13984your program.
13985
13986@kindex set language
13987If you wish, you may set the language manually. To do this, issue the
13988command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 13989a language, such as
c906108c 13990@code{c} or @code{modula-2}.
c906108c
SS
13991For a list of the supported languages, type @samp{set language}.
13992
c906108c
SS
13993Setting the language manually prevents @value{GDBN} from updating the working
13994language automatically. This can lead to confusion if you try
13995to debug a program when the working language is not the same as the
13996source language, when an expression is acceptable to both
13997languages---but means different things. For instance, if the current
13998source file were written in C, and @value{GDBN} was parsing Modula-2, a
13999command such as:
14000
474c8240 14001@smallexample
c906108c 14002print a = b + c
474c8240 14003@end smallexample
c906108c
SS
14004
14005@noindent
14006might not have the effect you intended. In C, this means to add
14007@code{b} and @code{c} and place the result in @code{a}. The result
14008printed would be the value of @code{a}. In Modula-2, this means to compare
14009@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 14010
6d2ebf8b 14011@node Automatically
79a6e687 14012@subsection Having @value{GDBN} Infer the Source Language
c906108c
SS
14013
14014To have @value{GDBN} set the working language automatically, use
14015@samp{set language local} or @samp{set language auto}. @value{GDBN}
14016then infers the working language. That is, when your program stops in a
14017frame (usually by encountering a breakpoint), @value{GDBN} sets the
14018working language to the language recorded for the function in that
14019frame. If the language for a frame is unknown (that is, if the function
14020or block corresponding to the frame was defined in a source file that
14021does not have a recognized extension), the current working language is
14022not changed, and @value{GDBN} issues a warning.
14023
14024This may not seem necessary for most programs, which are written
14025entirely in one source language. However, program modules and libraries
14026written in one source language can be used by a main program written in
14027a different source language. Using @samp{set language auto} in this
14028case frees you from having to set the working language manually.
14029
6d2ebf8b 14030@node Show
79a6e687 14031@section Displaying the Language
c906108c
SS
14032
14033The following commands help you find out which language is the
14034working language, and also what language source files were written in.
14035
c906108c
SS
14036@table @code
14037@item show language
403cb6b1 14038@anchor{show language}
9c16f35a 14039@kindex show language
c906108c
SS
14040Display the current working language. This is the
14041language you can use with commands such as @code{print} to
14042build and compute expressions that may involve variables in your program.
14043
14044@item info frame
4644b6e3 14045@kindex info frame@r{, show the source language}
5d161b24 14046Display the source language for this frame. This language becomes the
c906108c 14047working language if you use an identifier from this frame.
79a6e687 14048@xref{Frame Info, ,Information about a Frame}, to identify the other
c906108c
SS
14049information listed here.
14050
14051@item info source
4644b6e3 14052@kindex info source@r{, show the source language}
c906108c 14053Display the source language of this source file.
5d161b24 14054@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
14055information listed here.
14056@end table
14057
14058In unusual circumstances, you may have source files with extensions
14059not in the standard list. You can then set the extension associated
14060with a language explicitly:
14061
c906108c 14062@table @code
09d4efe1 14063@item set extension-language @var{ext} @var{language}
9c16f35a 14064@kindex set extension-language
09d4efe1
EZ
14065Tell @value{GDBN} that source files with extension @var{ext} are to be
14066assumed as written in the source language @var{language}.
c906108c
SS
14067
14068@item info extensions
9c16f35a 14069@kindex info extensions
c906108c
SS
14070List all the filename extensions and the associated languages.
14071@end table
14072
6d2ebf8b 14073@node Checks
79a6e687 14074@section Type and Range Checking
c906108c 14075
c906108c
SS
14076Some languages are designed to guard you against making seemingly common
14077errors through a series of compile- and run-time checks. These include
a451cb65 14078checking the type of arguments to functions and operators and making
c906108c
SS
14079sure mathematical overflows are caught at run time. Checks such as
14080these help to ensure a program's correctness once it has been compiled
a451cb65 14081by eliminating type mismatches and providing active checks for range
c906108c
SS
14082errors when your program is running.
14083
a451cb65
KS
14084By default @value{GDBN} checks for these errors according to the
14085rules of the current source language. Although @value{GDBN} does not check
14086the statements in your program, it can check expressions entered directly
14087into @value{GDBN} for evaluation via the @code{print} command, for example.
c906108c
SS
14088
14089@menu
14090* Type Checking:: An overview of type checking
14091* Range Checking:: An overview of range checking
14092@end menu
14093
14094@cindex type checking
14095@cindex checks, type
6d2ebf8b 14096@node Type Checking
79a6e687 14097@subsection An Overview of Type Checking
c906108c 14098
a451cb65 14099Some languages, such as C and C@t{++}, are strongly typed, meaning that the
c906108c
SS
14100arguments to operators and functions have to be of the correct type,
14101otherwise an error occurs. These checks prevent type mismatch
14102errors from ever causing any run-time problems. For example,
14103
14104@smallexample
a451cb65
KS
14105int klass::my_method(char *b) @{ return b ? 1 : 2; @}
14106
14107(@value{GDBP}) print obj.my_method (0)
14108$1 = 2
c906108c 14109@exdent but
a451cb65
KS
14110(@value{GDBP}) print obj.my_method (0x1234)
14111Cannot resolve method klass::my_method to any overloaded instance
c906108c
SS
14112@end smallexample
14113
a451cb65
KS
14114The second example fails because in C@t{++} the integer constant
14115@samp{0x1234} is not type-compatible with the pointer parameter type.
c906108c 14116
a451cb65
KS
14117For the expressions you use in @value{GDBN} commands, you can tell
14118@value{GDBN} to not enforce strict type checking or
5d161b24 14119to treat any mismatches as errors and abandon the expression;
a451cb65
KS
14120When type checking is disabled, @value{GDBN} successfully evaluates
14121expressions like the second example above.
c906108c 14122
a451cb65 14123Even if type checking is off, there may be other reasons
5d161b24
DB
14124related to type that prevent @value{GDBN} from evaluating an expression.
14125For instance, @value{GDBN} does not know how to add an @code{int} and
14126a @code{struct foo}. These particular type errors have nothing to do
a451cb65
KS
14127with the language in use and usually arise from expressions which make
14128little sense to evaluate anyway.
c906108c 14129
a451cb65 14130@value{GDBN} provides some additional commands for controlling type checking:
c906108c 14131
c906108c
SS
14132@kindex set check type
14133@kindex show check type
14134@table @code
c906108c
SS
14135@item set check type on
14136@itemx set check type off
a451cb65 14137Set strict type checking on or off. If any type mismatches occur in
d4f3574e 14138evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
14139message and aborts evaluation of the expression.
14140
a451cb65
KS
14141@item show check type
14142Show the current setting of type checking and whether @value{GDBN}
14143is enforcing strict type checking rules.
c906108c
SS
14144@end table
14145
14146@cindex range checking
14147@cindex checks, range
6d2ebf8b 14148@node Range Checking
79a6e687 14149@subsection An Overview of Range Checking
c906108c
SS
14150
14151In some languages (such as Modula-2), it is an error to exceed the
14152bounds of a type; this is enforced with run-time checks. Such range
14153checking is meant to ensure program correctness by making sure
14154computations do not overflow, or indices on an array element access do
14155not exceed the bounds of the array.
14156
14157For expressions you use in @value{GDBN} commands, you can tell
14158@value{GDBN} to treat range errors in one of three ways: ignore them,
14159always treat them as errors and abandon the expression, or issue
14160warnings but evaluate the expression anyway.
14161
14162A range error can result from numerical overflow, from exceeding an
14163array index bound, or when you type a constant that is not a member
14164of any type. Some languages, however, do not treat overflows as an
14165error. In many implementations of C, mathematical overflow causes the
14166result to ``wrap around'' to lower values---for example, if @var{m} is
14167the largest integer value, and @var{s} is the smallest, then
14168
474c8240 14169@smallexample
c906108c 14170@var{m} + 1 @result{} @var{s}
474c8240 14171@end smallexample
c906108c
SS
14172
14173This, too, is specific to individual languages, and in some cases
79a6e687
BW
14174specific to individual compilers or machines. @xref{Supported Languages, ,
14175Supported Languages}, for further details on specific languages.
c906108c
SS
14176
14177@value{GDBN} provides some additional commands for controlling the range checker:
14178
c906108c
SS
14179@kindex set check range
14180@kindex show check range
14181@table @code
14182@item set check range auto
14183Set range checking on or off based on the current working language.
79a6e687 14184@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
14185each language.
14186
14187@item set check range on
14188@itemx set check range off
14189Set range checking on or off, overriding the default setting for the
14190current working language. A warning is issued if the setting does not
c3f6f71d
JM
14191match the language default. If a range error occurs and range checking is on,
14192then a message is printed and evaluation of the expression is aborted.
c906108c
SS
14193
14194@item set check range warn
14195Output messages when the @value{GDBN} range checker detects a range error,
14196but attempt to evaluate the expression anyway. Evaluating the
14197expression may still be impossible for other reasons, such as accessing
14198memory that the process does not own (a typical example from many Unix
14199systems).
14200
14201@item show range
14202Show the current setting of the range checker, and whether or not it is
14203being set automatically by @value{GDBN}.
14204@end table
c906108c 14205
79a6e687
BW
14206@node Supported Languages
14207@section Supported Languages
c906108c 14208
a766d390
DE
14209@value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran, Java,
14210OpenCL C, Pascal, assembly, Modula-2, and Ada.
cce74817 14211@c This is false ...
c906108c
SS
14212Some @value{GDBN} features may be used in expressions regardless of the
14213language you use: the @value{GDBN} @code{@@} and @code{::} operators,
14214and the @samp{@{type@}addr} construct (@pxref{Expressions,
14215,Expressions}) can be used with the constructs of any supported
14216language.
14217
14218The following sections detail to what degree each source language is
14219supported by @value{GDBN}. These sections are not meant to be language
14220tutorials or references, but serve only as a reference guide to what the
14221@value{GDBN} expression parser accepts, and what input and output
14222formats should look like for different languages. There are many good
14223books written on each of these languages; please look to these for a
14224language reference or tutorial.
14225
c906108c 14226@menu
b37303ee 14227* C:: C and C@t{++}
6aecb9c2 14228* D:: D
a766d390 14229* Go:: Go
b383017d 14230* Objective-C:: Objective-C
f4b8a18d 14231* OpenCL C:: OpenCL C
09d4efe1 14232* Fortran:: Fortran
9c16f35a 14233* Pascal:: Pascal
b37303ee 14234* Modula-2:: Modula-2
e07c999f 14235* Ada:: Ada
c906108c
SS
14236@end menu
14237
6d2ebf8b 14238@node C
b37052ae 14239@subsection C and C@t{++}
7a292a7a 14240
b37052ae
EZ
14241@cindex C and C@t{++}
14242@cindex expressions in C or C@t{++}
c906108c 14243
b37052ae 14244Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
14245to both languages. Whenever this is the case, we discuss those languages
14246together.
14247
41afff9a
EZ
14248@cindex C@t{++}
14249@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
14250@cindex @sc{gnu} C@t{++}
14251The C@t{++} debugging facilities are jointly implemented by the C@t{++}
14252compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
14253effectively, you must compile your C@t{++} programs with a supported
14254C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
14255compiler (@code{aCC}).
14256
c906108c 14257@menu
b37052ae
EZ
14258* C Operators:: C and C@t{++} operators
14259* C Constants:: C and C@t{++} constants
79a6e687 14260* C Plus Plus Expressions:: C@t{++} expressions
b37052ae
EZ
14261* C Defaults:: Default settings for C and C@t{++}
14262* C Checks:: C and C@t{++} type and range checks
c906108c 14263* Debugging C:: @value{GDBN} and C
79a6e687 14264* Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
febe4383 14265* Decimal Floating Point:: Numbers in Decimal Floating Point format
c906108c 14266@end menu
c906108c 14267
6d2ebf8b 14268@node C Operators
79a6e687 14269@subsubsection C and C@t{++} Operators
7a292a7a 14270
b37052ae 14271@cindex C and C@t{++} operators
c906108c
SS
14272
14273Operators must be defined on values of specific types. For instance,
14274@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 14275often defined on groups of types.
c906108c 14276
b37052ae 14277For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
14278
14279@itemize @bullet
53a5351d 14280
c906108c 14281@item
c906108c 14282@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 14283specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
14284
14285@item
d4f3574e
SS
14286@emph{Floating-point types} include @code{float}, @code{double}, and
14287@code{long double} (if supported by the target platform).
c906108c
SS
14288
14289@item
53a5351d 14290@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
14291
14292@item
14293@emph{Scalar types} include all of the above.
53a5351d 14294
c906108c
SS
14295@end itemize
14296
14297@noindent
14298The following operators are supported. They are listed here
14299in order of increasing precedence:
14300
14301@table @code
14302@item ,
14303The comma or sequencing operator. Expressions in a comma-separated list
14304are evaluated from left to right, with the result of the entire
14305expression being the last expression evaluated.
14306
14307@item =
14308Assignment. The value of an assignment expression is the value
14309assigned. Defined on scalar types.
14310
14311@item @var{op}=
14312Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
14313and translated to @w{@code{@var{a} = @var{a op b}}}.
697aa1b7 14314@w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
c906108c
SS
14315@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
14316@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
14317
14318@item ?:
14319The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
697aa1b7
EZ
14320of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
14321should be of an integral type.
c906108c
SS
14322
14323@item ||
14324Logical @sc{or}. Defined on integral types.
14325
14326@item &&
14327Logical @sc{and}. Defined on integral types.
14328
14329@item |
14330Bitwise @sc{or}. Defined on integral types.
14331
14332@item ^
14333Bitwise exclusive-@sc{or}. Defined on integral types.
14334
14335@item &
14336Bitwise @sc{and}. Defined on integral types.
14337
14338@item ==@r{, }!=
14339Equality and inequality. Defined on scalar types. The value of these
14340expressions is 0 for false and non-zero for true.
14341
14342@item <@r{, }>@r{, }<=@r{, }>=
14343Less than, greater than, less than or equal, greater than or equal.
14344Defined on scalar types. The value of these expressions is 0 for false
14345and non-zero for true.
14346
14347@item <<@r{, }>>
14348left shift, and right shift. Defined on integral types.
14349
14350@item @@
14351The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
14352
14353@item +@r{, }-
14354Addition and subtraction. Defined on integral types, floating-point types and
14355pointer types.
14356
14357@item *@r{, }/@r{, }%
14358Multiplication, division, and modulus. Multiplication and division are
14359defined on integral and floating-point types. Modulus is defined on
14360integral types.
14361
14362@item ++@r{, }--
14363Increment and decrement. When appearing before a variable, the
14364operation is performed before the variable is used in an expression;
14365when appearing after it, the variable's value is used before the
14366operation takes place.
14367
14368@item *
14369Pointer dereferencing. Defined on pointer types. Same precedence as
14370@code{++}.
14371
14372@item &
14373Address operator. Defined on variables. Same precedence as @code{++}.
14374
b37052ae
EZ
14375For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
14376allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
b17828ca 14377to examine the address
b37052ae 14378where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 14379stored.
c906108c
SS
14380
14381@item -
14382Negative. Defined on integral and floating-point types. Same
14383precedence as @code{++}.
14384
14385@item !
14386Logical negation. Defined on integral types. Same precedence as
14387@code{++}.
14388
14389@item ~
14390Bitwise complement operator. Defined on integral types. Same precedence as
14391@code{++}.
14392
14393
14394@item .@r{, }->
14395Structure member, and pointer-to-structure member. For convenience,
14396@value{GDBN} regards the two as equivalent, choosing whether to dereference a
14397pointer based on the stored type information.
14398Defined on @code{struct} and @code{union} data.
14399
c906108c
SS
14400@item .*@r{, }->*
14401Dereferences of pointers to members.
c906108c
SS
14402
14403@item []
14404Array indexing. @code{@var{a}[@var{i}]} is defined as
14405@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
14406
14407@item ()
14408Function parameter list. Same precedence as @code{->}.
14409
c906108c 14410@item ::
b37052ae 14411C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 14412and @code{class} types.
c906108c
SS
14413
14414@item ::
7a292a7a
SS
14415Doubled colons also represent the @value{GDBN} scope operator
14416(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
14417above.
c906108c
SS
14418@end table
14419
c906108c
SS
14420If an operator is redefined in the user code, @value{GDBN} usually
14421attempts to invoke the redefined version instead of using the operator's
14422predefined meaning.
c906108c 14423
6d2ebf8b 14424@node C Constants
79a6e687 14425@subsubsection C and C@t{++} Constants
c906108c 14426
b37052ae 14427@cindex C and C@t{++} constants
c906108c 14428
b37052ae 14429@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 14430following ways:
c906108c
SS
14431
14432@itemize @bullet
14433@item
14434Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
14435specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
14436by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
14437@samp{l}, specifying that the constant should be treated as a
14438@code{long} value.
14439
14440@item
14441Floating point constants are a sequence of digits, followed by a decimal
14442point, followed by a sequence of digits, and optionally followed by an
14443exponent. An exponent is of the form:
14444@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
14445sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
14446A floating-point constant may also end with a letter @samp{f} or
14447@samp{F}, specifying that the constant should be treated as being of
14448the @code{float} (as opposed to the default @code{double}) type; or with
14449a letter @samp{l} or @samp{L}, which specifies a @code{long double}
14450constant.
c906108c
SS
14451
14452@item
14453Enumerated constants consist of enumerated identifiers, or their
14454integral equivalents.
14455
14456@item
14457Character constants are a single character surrounded by single quotes
14458(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 14459(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
14460be represented by a letter or by @dfn{escape sequences}, which are of
14461the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
14462of the character's ordinal value; or of the form @samp{\@var{x}}, where
14463@samp{@var{x}} is a predefined special character---for example,
14464@samp{\n} for newline.
14465
e0f8f636
TT
14466Wide character constants can be written by prefixing a character
14467constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
14468form of @samp{x}. The target wide character set is used when
14469computing the value of this constant (@pxref{Character Sets}).
14470
c906108c 14471@item
96a2c332
SS
14472String constants are a sequence of character constants surrounded by
14473double quotes (@code{"}). Any valid character constant (as described
14474above) may appear. Double quotes within the string must be preceded by
14475a backslash, so for instance @samp{"a\"b'c"} is a string of five
14476characters.
c906108c 14477
e0f8f636
TT
14478Wide string constants can be written by prefixing a string constant
14479with @samp{L}, as in C. The target wide character set is used when
14480computing the value of this constant (@pxref{Character Sets}).
14481
c906108c
SS
14482@item
14483Pointer constants are an integral value. You can also write pointers
14484to constants using the C operator @samp{&}.
14485
14486@item
14487Array constants are comma-separated lists surrounded by braces @samp{@{}
14488and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
14489integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
14490and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
14491@end itemize
14492
79a6e687
BW
14493@node C Plus Plus Expressions
14494@subsubsection C@t{++} Expressions
b37052ae
EZ
14495
14496@cindex expressions in C@t{++}
14497@value{GDBN} expression handling can interpret most C@t{++} expressions.
14498
0179ffac
DC
14499@cindex debugging C@t{++} programs
14500@cindex C@t{++} compilers
14501@cindex debug formats and C@t{++}
14502@cindex @value{NGCC} and C@t{++}
c906108c 14503@quotation
e0f8f636
TT
14504@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
14505the proper compiler and the proper debug format. Currently,
14506@value{GDBN} works best when debugging C@t{++} code that is compiled
14507with the most recent version of @value{NGCC} possible. The DWARF
14508debugging format is preferred; @value{NGCC} defaults to this on most
14509popular platforms. Other compilers and/or debug formats are likely to
14510work badly or not at all when using @value{GDBN} to debug C@t{++}
14511code. @xref{Compilation}.
c906108c 14512@end quotation
c906108c
SS
14513
14514@enumerate
14515
14516@cindex member functions
14517@item
14518Member function calls are allowed; you can use expressions like
14519
474c8240 14520@smallexample
c906108c 14521count = aml->GetOriginal(x, y)
474c8240 14522@end smallexample
c906108c 14523
41afff9a 14524@vindex this@r{, inside C@t{++} member functions}
b37052ae 14525@cindex namespace in C@t{++}
c906108c
SS
14526@item
14527While a member function is active (in the selected stack frame), your
14528expressions have the same namespace available as the member function;
14529that is, @value{GDBN} allows implicit references to the class instance
e0f8f636
TT
14530pointer @code{this} following the same rules as C@t{++}. @code{using}
14531declarations in the current scope are also respected by @value{GDBN}.
c906108c 14532
c906108c 14533@cindex call overloaded functions
d4f3574e 14534@cindex overloaded functions, calling
b37052ae 14535@cindex type conversions in C@t{++}
c906108c
SS
14536@item
14537You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 14538call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
14539perform overload resolution involving user-defined type conversions,
14540calls to constructors, or instantiations of templates that do not exist
14541in the program. It also cannot handle ellipsis argument lists or
14542default arguments.
14543
14544It does perform integral conversions and promotions, floating-point
14545promotions, arithmetic conversions, pointer conversions, conversions of
14546class objects to base classes, and standard conversions such as those of
14547functions or arrays to pointers; it requires an exact match on the
14548number of function arguments.
14549
14550Overload resolution is always performed, unless you have specified
79a6e687
BW
14551@code{set overload-resolution off}. @xref{Debugging C Plus Plus,
14552,@value{GDBN} Features for C@t{++}}.
c906108c 14553
d4f3574e 14554You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
14555explicit function signature to call an overloaded function, as in
14556@smallexample
14557p 'foo(char,int)'('x', 13)
14558@end smallexample
d4f3574e 14559
c906108c 14560The @value{GDBN} command-completion facility can simplify this;
79a6e687 14561see @ref{Completion, ,Command Completion}.
c906108c 14562
c906108c
SS
14563@cindex reference declarations
14564@item
b37052ae
EZ
14565@value{GDBN} understands variables declared as C@t{++} references; you can use
14566them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
14567dereferenced.
14568
14569In the parameter list shown when @value{GDBN} displays a frame, the values of
14570reference variables are not displayed (unlike other variables); this
14571avoids clutter, since references are often used for large structures.
14572The @emph{address} of a reference variable is always shown, unless
14573you have specified @samp{set print address off}.
14574
14575@item
b37052ae 14576@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
14577expressions can use it just as expressions in your program do. Since
14578one scope may be defined in another, you can use @code{::} repeatedly if
14579necessary, for example in an expression like
14580@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 14581resolving name scope by reference to source files, in both C and C@t{++}
79a6e687 14582debugging (@pxref{Variables, ,Program Variables}).
c906108c 14583
e0f8f636
TT
14584@item
14585@value{GDBN} performs argument-dependent lookup, following the C@t{++}
14586specification.
14587@end enumerate
c906108c 14588
6d2ebf8b 14589@node C Defaults
79a6e687 14590@subsubsection C and C@t{++} Defaults
7a292a7a 14591
b37052ae 14592@cindex C and C@t{++} defaults
c906108c 14593
a451cb65
KS
14594If you allow @value{GDBN} to set range checking automatically, it
14595defaults to @code{off} whenever the working language changes to
b37052ae 14596C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 14597selects the working language.
c906108c
SS
14598
14599If you allow @value{GDBN} to set the language automatically, it
14600recognizes source files whose names end with @file{.c}, @file{.C}, or
14601@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 14602these files, it sets the working language to C or C@t{++}.
79a6e687 14603@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
c906108c
SS
14604for further details.
14605
6d2ebf8b 14606@node C Checks
79a6e687 14607@subsubsection C and C@t{++} Type and Range Checks
7a292a7a 14608
b37052ae 14609@cindex C and C@t{++} checks
c906108c 14610
a451cb65
KS
14611By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
14612checking is used. However, if you turn type checking off, @value{GDBN}
14613will allow certain non-standard conversions, such as promoting integer
14614constants to pointers.
c906108c
SS
14615
14616Range checking, if turned on, is done on mathematical operations. Array
14617indices are not checked, since they are often used to index a pointer
14618that is not itself an array.
c906108c 14619
6d2ebf8b 14620@node Debugging C
c906108c 14621@subsubsection @value{GDBN} and C
c906108c
SS
14622
14623The @code{set print union} and @code{show print union} commands apply to
14624the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
14625inside a @code{struct} or @code{class} is also printed. Otherwise, it
14626appears as @samp{@{...@}}.
c906108c
SS
14627
14628The @code{@@} operator aids in the debugging of dynamic arrays, formed
14629with pointers and a memory allocation function. @xref{Expressions,
14630,Expressions}.
14631
79a6e687
BW
14632@node Debugging C Plus Plus
14633@subsubsection @value{GDBN} Features for C@t{++}
c906108c 14634
b37052ae 14635@cindex commands for C@t{++}
7a292a7a 14636
b37052ae
EZ
14637Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
14638designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
14639
14640@table @code
14641@cindex break in overloaded functions
14642@item @r{breakpoint menus}
14643When you want a breakpoint in a function whose name is overloaded,
6ba66d6a
JB
14644@value{GDBN} has the capability to display a menu of possible breakpoint
14645locations to help you specify which function definition you want.
14646@xref{Ambiguous Expressions,,Ambiguous Expressions}.
c906108c 14647
b37052ae 14648@cindex overloading in C@t{++}
c906108c
SS
14649@item rbreak @var{regex}
14650Setting breakpoints using regular expressions is helpful for setting
14651breakpoints on overloaded functions that are not members of any special
14652classes.
79a6e687 14653@xref{Set Breaks, ,Setting Breakpoints}.
c906108c 14654
b37052ae 14655@cindex C@t{++} exception handling
c906108c 14656@item catch throw
591f19e8 14657@itemx catch rethrow
c906108c 14658@itemx catch catch
b37052ae 14659Debug C@t{++} exception handling using these commands. @xref{Set
79a6e687 14660Catchpoints, , Setting Catchpoints}.
c906108c
SS
14661
14662@cindex inheritance
14663@item ptype @var{typename}
14664Print inheritance relationships as well as other information for type
14665@var{typename}.
14666@xref{Symbols, ,Examining the Symbol Table}.
14667
c4aeac85
TT
14668@item info vtbl @var{expression}.
14669The @code{info vtbl} command can be used to display the virtual
14670method tables of the object computed by @var{expression}. This shows
14671one entry per virtual table; there may be multiple virtual tables when
14672multiple inheritance is in use.
14673
439250fb
DE
14674@cindex C@t{++} demangling
14675@item demangle @var{name}
14676Demangle @var{name}.
14677@xref{Symbols}, for a more complete description of the @code{demangle} command.
14678
b37052ae 14679@cindex C@t{++} symbol display
c906108c
SS
14680@item set print demangle
14681@itemx show print demangle
14682@itemx set print asm-demangle
14683@itemx show print asm-demangle
b37052ae
EZ
14684Control whether C@t{++} symbols display in their source form, both when
14685displaying code as C@t{++} source and when displaying disassemblies.
79a6e687 14686@xref{Print Settings, ,Print Settings}.
c906108c
SS
14687
14688@item set print object
14689@itemx show print object
14690Choose whether to print derived (actual) or declared types of objects.
79a6e687 14691@xref{Print Settings, ,Print Settings}.
c906108c
SS
14692
14693@item set print vtbl
14694@itemx show print vtbl
14695Control the format for printing virtual function tables.
79a6e687 14696@xref{Print Settings, ,Print Settings}.
c906108c 14697(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 14698ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
14699
14700@kindex set overload-resolution
d4f3574e 14701@cindex overloaded functions, overload resolution
c906108c 14702@item set overload-resolution on
b37052ae 14703Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
14704is on. For overloaded functions, @value{GDBN} evaluates the arguments
14705and searches for a function whose signature matches the argument types,
79a6e687
BW
14706using the standard C@t{++} conversion rules (see @ref{C Plus Plus
14707Expressions, ,C@t{++} Expressions}, for details).
14708If it cannot find a match, it emits a message.
c906108c
SS
14709
14710@item set overload-resolution off
b37052ae 14711Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
14712overloaded functions that are not class member functions, @value{GDBN}
14713chooses the first function of the specified name that it finds in the
14714symbol table, whether or not its arguments are of the correct type. For
14715overloaded functions that are class member functions, @value{GDBN}
14716searches for a function whose signature @emph{exactly} matches the
14717argument types.
c906108c 14718
9c16f35a
EZ
14719@kindex show overload-resolution
14720@item show overload-resolution
14721Show the current setting of overload resolution.
14722
c906108c
SS
14723@item @r{Overloaded symbol names}
14724You can specify a particular definition of an overloaded symbol, using
b37052ae 14725the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
14726@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
14727also use the @value{GDBN} command-line word completion facilities to list the
14728available choices, or to finish the type list for you.
79a6e687 14729@xref{Completion,, Command Completion}, for details on how to do this.
c906108c 14730@end table
c906108c 14731
febe4383
TJB
14732@node Decimal Floating Point
14733@subsubsection Decimal Floating Point format
14734@cindex decimal floating point format
14735
14736@value{GDBN} can examine, set and perform computations with numbers in
14737decimal floating point format, which in the C language correspond to the
14738@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
14739specified by the extension to support decimal floating-point arithmetic.
14740
14741There are two encodings in use, depending on the architecture: BID (Binary
14742Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
4ac33720
UW
14743PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
14744configured target.
febe4383
TJB
14745
14746Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
14747to manipulate decimal floating point numbers, it is not possible to convert
14748(using a cast, for example) integers wider than 32-bit to decimal float.
14749
14750In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
14751point computations, error checking in decimal float operations ignores
14752underflow, overflow and divide by zero exceptions.
14753
4acd40f3 14754In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
99e008fe
EZ
14755to inspect @code{_Decimal128} values stored in floating point registers.
14756See @ref{PowerPC,,PowerPC} for more details.
4acd40f3 14757
6aecb9c2
JB
14758@node D
14759@subsection D
14760
14761@cindex D
14762@value{GDBN} can be used to debug programs written in D and compiled with
14763GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
14764specific feature --- dynamic arrays.
14765
a766d390
DE
14766@node Go
14767@subsection Go
14768
14769@cindex Go (programming language)
14770@value{GDBN} can be used to debug programs written in Go and compiled with
14771@file{gccgo} or @file{6g} compilers.
14772
14773Here is a summary of the Go-specific features and restrictions:
14774
14775@table @code
14776@cindex current Go package
14777@item The current Go package
14778The name of the current package does not need to be specified when
14779specifying global variables and functions.
14780
14781For example, given the program:
14782
14783@example
14784package main
14785var myglob = "Shall we?"
14786func main () @{
14787 // ...
14788@}
14789@end example
14790
14791When stopped inside @code{main} either of these work:
14792
14793@example
14794(gdb) p myglob
14795(gdb) p main.myglob
14796@end example
14797
14798@cindex builtin Go types
14799@item Builtin Go types
14800The @code{string} type is recognized by @value{GDBN} and is printed
14801as a string.
14802
14803@cindex builtin Go functions
14804@item Builtin Go functions
14805The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
14806function and handles it internally.
a766d390
DE
14807
14808@cindex restrictions on Go expressions
14809@item Restrictions on Go expressions
14810All Go operators are supported except @code{&^}.
14811The Go @code{_} ``blank identifier'' is not supported.
14812Automatic dereferencing of pointers is not supported.
50f042b9 14813@end table
a766d390 14814
b37303ee
AF
14815@node Objective-C
14816@subsection Objective-C
14817
14818@cindex Objective-C
14819This section provides information about some commands and command
721c2651
EZ
14820options that are useful for debugging Objective-C code. See also
14821@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
14822few more commands specific to Objective-C support.
b37303ee
AF
14823
14824@menu
b383017d
RM
14825* Method Names in Commands::
14826* The Print Command with Objective-C::
b37303ee
AF
14827@end menu
14828
c8f4133a 14829@node Method Names in Commands
b37303ee
AF
14830@subsubsection Method Names in Commands
14831
14832The following commands have been extended to accept Objective-C method
14833names as line specifications:
14834
14835@kindex clear@r{, and Objective-C}
14836@kindex break@r{, and Objective-C}
14837@kindex info line@r{, and Objective-C}
14838@kindex jump@r{, and Objective-C}
14839@kindex list@r{, and Objective-C}
14840@itemize
14841@item @code{clear}
14842@item @code{break}
14843@item @code{info line}
14844@item @code{jump}
14845@item @code{list}
14846@end itemize
14847
14848A fully qualified Objective-C method name is specified as
14849
14850@smallexample
14851-[@var{Class} @var{methodName}]
14852@end smallexample
14853
c552b3bb
JM
14854where the minus sign is used to indicate an instance method and a
14855plus sign (not shown) is used to indicate a class method. The class
14856name @var{Class} and method name @var{methodName} are enclosed in
14857brackets, similar to the way messages are specified in Objective-C
14858source code. For example, to set a breakpoint at the @code{create}
14859instance method of class @code{Fruit} in the program currently being
14860debugged, enter:
b37303ee
AF
14861
14862@smallexample
14863break -[Fruit create]
14864@end smallexample
14865
14866To list ten program lines around the @code{initialize} class method,
14867enter:
14868
14869@smallexample
14870list +[NSText initialize]
14871@end smallexample
14872
c552b3bb
JM
14873In the current version of @value{GDBN}, the plus or minus sign is
14874required. In future versions of @value{GDBN}, the plus or minus
14875sign will be optional, but you can use it to narrow the search. It
14876is also possible to specify just a method name:
b37303ee
AF
14877
14878@smallexample
14879break create
14880@end smallexample
14881
14882You must specify the complete method name, including any colons. If
14883your program's source files contain more than one @code{create} method,
14884you'll be presented with a numbered list of classes that implement that
14885method. Indicate your choice by number, or type @samp{0} to exit if
14886none apply.
14887
14888As another example, to clear a breakpoint established at the
14889@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
14890
14891@smallexample
14892clear -[NSWindow makeKeyAndOrderFront:]
14893@end smallexample
14894
14895@node The Print Command with Objective-C
14896@subsubsection The Print Command With Objective-C
721c2651 14897@cindex Objective-C, print objects
c552b3bb
JM
14898@kindex print-object
14899@kindex po @r{(@code{print-object})}
b37303ee 14900
c552b3bb 14901The print command has also been extended to accept methods. For example:
b37303ee
AF
14902
14903@smallexample
c552b3bb 14904print -[@var{object} hash]
b37303ee
AF
14905@end smallexample
14906
14907@cindex print an Objective-C object description
c552b3bb
JM
14908@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
14909@noindent
14910will tell @value{GDBN} to send the @code{hash} message to @var{object}
14911and print the result. Also, an additional command has been added,
14912@code{print-object} or @code{po} for short, which is meant to print
14913the description of an object. However, this command may only work
14914with certain Objective-C libraries that have a particular hook
14915function, @code{_NSPrintForDebugger}, defined.
b37303ee 14916
f4b8a18d
KW
14917@node OpenCL C
14918@subsection OpenCL C
14919
14920@cindex OpenCL C
14921This section provides information about @value{GDBN}s OpenCL C support.
14922
14923@menu
14924* OpenCL C Datatypes::
14925* OpenCL C Expressions::
14926* OpenCL C Operators::
14927@end menu
14928
14929@node OpenCL C Datatypes
14930@subsubsection OpenCL C Datatypes
14931
14932@cindex OpenCL C Datatypes
14933@value{GDBN} supports the builtin scalar and vector datatypes specified
14934by OpenCL 1.1. In addition the half- and double-precision floating point
14935data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
14936extensions are also known to @value{GDBN}.
14937
14938@node OpenCL C Expressions
14939@subsubsection OpenCL C Expressions
14940
14941@cindex OpenCL C Expressions
14942@value{GDBN} supports accesses to vector components including the access as
14943lvalue where possible. Since OpenCL C is based on C99 most C expressions
14944supported by @value{GDBN} can be used as well.
14945
14946@node OpenCL C Operators
14947@subsubsection OpenCL C Operators
14948
14949@cindex OpenCL C Operators
14950@value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
14951vector data types.
14952
09d4efe1
EZ
14953@node Fortran
14954@subsection Fortran
14955@cindex Fortran-specific support in @value{GDBN}
14956
814e32d7
WZ
14957@value{GDBN} can be used to debug programs written in Fortran, but it
14958currently supports only the features of Fortran 77 language.
14959
14960@cindex trailing underscore, in Fortran symbols
14961Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
14962among them) append an underscore to the names of variables and
14963functions. When you debug programs compiled by those compilers, you
14964will need to refer to variables and functions with a trailing
14965underscore.
14966
14967@menu
14968* Fortran Operators:: Fortran operators and expressions
14969* Fortran Defaults:: Default settings for Fortran
79a6e687 14970* Special Fortran Commands:: Special @value{GDBN} commands for Fortran
814e32d7
WZ
14971@end menu
14972
14973@node Fortran Operators
79a6e687 14974@subsubsection Fortran Operators and Expressions
814e32d7
WZ
14975
14976@cindex Fortran operators and expressions
14977
14978Operators must be defined on values of specific types. For instance,
14979@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 14980arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
14981
14982@table @code
14983@item **
99e008fe 14984The exponentiation operator. It raises the first operand to the power
814e32d7
WZ
14985of the second one.
14986
14987@item :
14988The range operator. Normally used in the form of array(low:high) to
14989represent a section of array.
68837c9d
MD
14990
14991@item %
14992The access component operator. Normally used to access elements in derived
14993types. Also suitable for unions. As unions aren't part of regular Fortran,
14994this can only happen when accessing a register that uses a gdbarch-defined
14995union type.
814e32d7
WZ
14996@end table
14997
14998@node Fortran Defaults
14999@subsubsection Fortran Defaults
15000
15001@cindex Fortran Defaults
15002
15003Fortran symbols are usually case-insensitive, so @value{GDBN} by
15004default uses case-insensitive matches for Fortran symbols. You can
15005change that with the @samp{set case-insensitive} command, see
15006@ref{Symbols}, for the details.
15007
79a6e687
BW
15008@node Special Fortran Commands
15009@subsubsection Special Fortran Commands
814e32d7
WZ
15010
15011@cindex Special Fortran commands
15012
db2e3e2e
BW
15013@value{GDBN} has some commands to support Fortran-specific features,
15014such as displaying common blocks.
814e32d7 15015
09d4efe1
EZ
15016@table @code
15017@cindex @code{COMMON} blocks, Fortran
15018@kindex info common
15019@item info common @r{[}@var{common-name}@r{]}
15020This command prints the values contained in the Fortran @code{COMMON}
15021block whose name is @var{common-name}. With no argument, the names of
d52fb0e9 15022all @code{COMMON} blocks visible at the current program location are
09d4efe1
EZ
15023printed.
15024@end table
15025
9c16f35a
EZ
15026@node Pascal
15027@subsection Pascal
15028
15029@cindex Pascal support in @value{GDBN}, limitations
15030Debugging Pascal programs which use sets, subranges, file variables, or
15031nested functions does not currently work. @value{GDBN} does not support
15032entering expressions, printing values, or similar features using Pascal
15033syntax.
15034
15035The Pascal-specific command @code{set print pascal_static-members}
15036controls whether static members of Pascal objects are displayed.
15037@xref{Print Settings, pascal_static-members}.
15038
09d4efe1 15039@node Modula-2
c906108c 15040@subsection Modula-2
7a292a7a 15041
d4f3574e 15042@cindex Modula-2, @value{GDBN} support
c906108c
SS
15043
15044The extensions made to @value{GDBN} to support Modula-2 only support
15045output from the @sc{gnu} Modula-2 compiler (which is currently being
15046developed). Other Modula-2 compilers are not currently supported, and
15047attempting to debug executables produced by them is most likely
15048to give an error as @value{GDBN} reads in the executable's symbol
15049table.
15050
15051@cindex expressions in Modula-2
15052@menu
15053* M2 Operators:: Built-in operators
15054* Built-In Func/Proc:: Built-in functions and procedures
15055* M2 Constants:: Modula-2 constants
72019c9c 15056* M2 Types:: Modula-2 types
c906108c
SS
15057* M2 Defaults:: Default settings for Modula-2
15058* Deviations:: Deviations from standard Modula-2
15059* M2 Checks:: Modula-2 type and range checks
15060* M2 Scope:: The scope operators @code{::} and @code{.}
15061* GDB/M2:: @value{GDBN} and Modula-2
15062@end menu
15063
6d2ebf8b 15064@node M2 Operators
c906108c
SS
15065@subsubsection Operators
15066@cindex Modula-2 operators
15067
15068Operators must be defined on values of specific types. For instance,
15069@code{+} is defined on numbers, but not on structures. Operators are
15070often defined on groups of types. For the purposes of Modula-2, the
15071following definitions hold:
15072
15073@itemize @bullet
15074
15075@item
15076@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
15077their subranges.
15078
15079@item
15080@emph{Character types} consist of @code{CHAR} and its subranges.
15081
15082@item
15083@emph{Floating-point types} consist of @code{REAL}.
15084
15085@item
15086@emph{Pointer types} consist of anything declared as @code{POINTER TO
15087@var{type}}.
15088
15089@item
15090@emph{Scalar types} consist of all of the above.
15091
15092@item
15093@emph{Set types} consist of @code{SET} and @code{BITSET} types.
15094
15095@item
15096@emph{Boolean types} consist of @code{BOOLEAN}.
15097@end itemize
15098
15099@noindent
15100The following operators are supported, and appear in order of
15101increasing precedence:
15102
15103@table @code
15104@item ,
15105Function argument or array index separator.
15106
15107@item :=
15108Assignment. The value of @var{var} @code{:=} @var{value} is
15109@var{value}.
15110
15111@item <@r{, }>
15112Less than, greater than on integral, floating-point, or enumerated
15113types.
15114
15115@item <=@r{, }>=
96a2c332 15116Less than or equal to, greater than or equal to
c906108c
SS
15117on integral, floating-point and enumerated types, or set inclusion on
15118set types. Same precedence as @code{<}.
15119
15120@item =@r{, }<>@r{, }#
15121Equality and two ways of expressing inequality, valid on scalar types.
15122Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
15123available for inequality, since @code{#} conflicts with the script
15124comment character.
15125
15126@item IN
15127Set membership. Defined on set types and the types of their members.
15128Same precedence as @code{<}.
15129
15130@item OR
15131Boolean disjunction. Defined on boolean types.
15132
15133@item AND@r{, }&
d4f3574e 15134Boolean conjunction. Defined on boolean types.
c906108c
SS
15135
15136@item @@
15137The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
15138
15139@item +@r{, }-
15140Addition and subtraction on integral and floating-point types, or union
15141and difference on set types.
15142
15143@item *
15144Multiplication on integral and floating-point types, or set intersection
15145on set types.
15146
15147@item /
15148Division on floating-point types, or symmetric set difference on set
15149types. Same precedence as @code{*}.
15150
15151@item DIV@r{, }MOD
15152Integer division and remainder. Defined on integral types. Same
15153precedence as @code{*}.
15154
15155@item -
99e008fe 15156Negative. Defined on @code{INTEGER} and @code{REAL} data.
c906108c
SS
15157
15158@item ^
15159Pointer dereferencing. Defined on pointer types.
15160
15161@item NOT
15162Boolean negation. Defined on boolean types. Same precedence as
15163@code{^}.
15164
15165@item .
15166@code{RECORD} field selector. Defined on @code{RECORD} data. Same
15167precedence as @code{^}.
15168
15169@item []
15170Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
15171
15172@item ()
15173Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
15174as @code{^}.
15175
15176@item ::@r{, }.
15177@value{GDBN} and Modula-2 scope operators.
15178@end table
15179
15180@quotation
72019c9c 15181@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
15182treats the use of the operator @code{IN}, or the use of operators
15183@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
15184@code{<=}, and @code{>=} on sets as an error.
15185@end quotation
15186
cb51c4e0 15187
6d2ebf8b 15188@node Built-In Func/Proc
79a6e687 15189@subsubsection Built-in Functions and Procedures
cb51c4e0 15190@cindex Modula-2 built-ins
c906108c
SS
15191
15192Modula-2 also makes available several built-in procedures and functions.
15193In describing these, the following metavariables are used:
15194
15195@table @var
15196
15197@item a
15198represents an @code{ARRAY} variable.
15199
15200@item c
15201represents a @code{CHAR} constant or variable.
15202
15203@item i
15204represents a variable or constant of integral type.
15205
15206@item m
15207represents an identifier that belongs to a set. Generally used in the
15208same function with the metavariable @var{s}. The type of @var{s} should
15209be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
15210
15211@item n
15212represents a variable or constant of integral or floating-point type.
15213
15214@item r
15215represents a variable or constant of floating-point type.
15216
15217@item t
15218represents a type.
15219
15220@item v
15221represents a variable.
15222
15223@item x
15224represents a variable or constant of one of many types. See the
15225explanation of the function for details.
15226@end table
15227
15228All Modula-2 built-in procedures also return a result, described below.
15229
15230@table @code
15231@item ABS(@var{n})
15232Returns the absolute value of @var{n}.
15233
15234@item CAP(@var{c})
15235If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 15236equivalent, otherwise it returns its argument.
c906108c
SS
15237
15238@item CHR(@var{i})
15239Returns the character whose ordinal value is @var{i}.
15240
15241@item DEC(@var{v})
c3f6f71d 15242Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
15243
15244@item DEC(@var{v},@var{i})
15245Decrements the value in the variable @var{v} by @var{i}. Returns the
15246new value.
15247
15248@item EXCL(@var{m},@var{s})
15249Removes the element @var{m} from the set @var{s}. Returns the new
15250set.
15251
15252@item FLOAT(@var{i})
15253Returns the floating point equivalent of the integer @var{i}.
15254
15255@item HIGH(@var{a})
15256Returns the index of the last member of @var{a}.
15257
15258@item INC(@var{v})
c3f6f71d 15259Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
15260
15261@item INC(@var{v},@var{i})
15262Increments the value in the variable @var{v} by @var{i}. Returns the
15263new value.
15264
15265@item INCL(@var{m},@var{s})
15266Adds the element @var{m} to the set @var{s} if it is not already
15267there. Returns the new set.
15268
15269@item MAX(@var{t})
15270Returns the maximum value of the type @var{t}.
15271
15272@item MIN(@var{t})
15273Returns the minimum value of the type @var{t}.
15274
15275@item ODD(@var{i})
15276Returns boolean TRUE if @var{i} is an odd number.
15277
15278@item ORD(@var{x})
15279Returns the ordinal value of its argument. For example, the ordinal
697aa1b7
EZ
15280value of a character is its @sc{ascii} value (on machines supporting
15281the @sc{ascii} character set). The argument @var{x} must be of an
15282ordered type, which include integral, character and enumerated types.
c906108c
SS
15283
15284@item SIZE(@var{x})
697aa1b7
EZ
15285Returns the size of its argument. The argument @var{x} can be a
15286variable or a type.
c906108c
SS
15287
15288@item TRUNC(@var{r})
15289Returns the integral part of @var{r}.
15290
844781a1 15291@item TSIZE(@var{x})
697aa1b7
EZ
15292Returns the size of its argument. The argument @var{x} can be a
15293variable or a type.
844781a1 15294
c906108c
SS
15295@item VAL(@var{t},@var{i})
15296Returns the member of the type @var{t} whose ordinal value is @var{i}.
15297@end table
15298
15299@quotation
15300@emph{Warning:} Sets and their operations are not yet supported, so
15301@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
15302an error.
15303@end quotation
15304
15305@cindex Modula-2 constants
6d2ebf8b 15306@node M2 Constants
c906108c
SS
15307@subsubsection Constants
15308
15309@value{GDBN} allows you to express the constants of Modula-2 in the following
15310ways:
15311
15312@itemize @bullet
15313
15314@item
15315Integer constants are simply a sequence of digits. When used in an
15316expression, a constant is interpreted to be type-compatible with the
15317rest of the expression. Hexadecimal integers are specified by a
15318trailing @samp{H}, and octal integers by a trailing @samp{B}.
15319
15320@item
15321Floating point constants appear as a sequence of digits, followed by a
15322decimal point and another sequence of digits. An optional exponent can
15323then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
15324@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
15325digits of the floating point constant must be valid decimal (base 10)
15326digits.
15327
15328@item
15329Character constants consist of a single character enclosed by a pair of
15330like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 15331also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
15332followed by a @samp{C}.
15333
15334@item
15335String constants consist of a sequence of characters enclosed by a
15336pair of like quotes, either single (@code{'}) or double (@code{"}).
15337Escape sequences in the style of C are also allowed. @xref{C
79a6e687 15338Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
c906108c
SS
15339sequences.
15340
15341@item
15342Enumerated constants consist of an enumerated identifier.
15343
15344@item
15345Boolean constants consist of the identifiers @code{TRUE} and
15346@code{FALSE}.
15347
15348@item
15349Pointer constants consist of integral values only.
15350
15351@item
15352Set constants are not yet supported.
15353@end itemize
15354
72019c9c
GM
15355@node M2 Types
15356@subsubsection Modula-2 Types
15357@cindex Modula-2 types
15358
15359Currently @value{GDBN} can print the following data types in Modula-2
15360syntax: array types, record types, set types, pointer types, procedure
15361types, enumerated types, subrange types and base types. You can also
15362print the contents of variables declared using these type.
15363This section gives a number of simple source code examples together with
15364sample @value{GDBN} sessions.
15365
15366The first example contains the following section of code:
15367
15368@smallexample
15369VAR
15370 s: SET OF CHAR ;
15371 r: [20..40] ;
15372@end smallexample
15373
15374@noindent
15375and you can request @value{GDBN} to interrogate the type and value of
15376@code{r} and @code{s}.
15377
15378@smallexample
15379(@value{GDBP}) print s
15380@{'A'..'C', 'Z'@}
15381(@value{GDBP}) ptype s
15382SET OF CHAR
15383(@value{GDBP}) print r
1538421
15385(@value{GDBP}) ptype r
15386[20..40]
15387@end smallexample
15388
15389@noindent
15390Likewise if your source code declares @code{s} as:
15391
15392@smallexample
15393VAR
15394 s: SET ['A'..'Z'] ;
15395@end smallexample
15396
15397@noindent
15398then you may query the type of @code{s} by:
15399
15400@smallexample
15401(@value{GDBP}) ptype s
15402type = SET ['A'..'Z']
15403@end smallexample
15404
15405@noindent
15406Note that at present you cannot interactively manipulate set
15407expressions using the debugger.
15408
15409The following example shows how you might declare an array in Modula-2
15410and how you can interact with @value{GDBN} to print its type and contents:
15411
15412@smallexample
15413VAR
15414 s: ARRAY [-10..10] OF CHAR ;
15415@end smallexample
15416
15417@smallexample
15418(@value{GDBP}) ptype s
15419ARRAY [-10..10] OF CHAR
15420@end smallexample
15421
15422Note that the array handling is not yet complete and although the type
15423is printed correctly, expression handling still assumes that all
15424arrays have a lower bound of zero and not @code{-10} as in the example
844781a1 15425above.
72019c9c
GM
15426
15427Here are some more type related Modula-2 examples:
15428
15429@smallexample
15430TYPE
15431 colour = (blue, red, yellow, green) ;
15432 t = [blue..yellow] ;
15433VAR
15434 s: t ;
15435BEGIN
15436 s := blue ;
15437@end smallexample
15438
15439@noindent
15440The @value{GDBN} interaction shows how you can query the data type
15441and value of a variable.
15442
15443@smallexample
15444(@value{GDBP}) print s
15445$1 = blue
15446(@value{GDBP}) ptype t
15447type = [blue..yellow]
15448@end smallexample
15449
15450@noindent
15451In this example a Modula-2 array is declared and its contents
15452displayed. Observe that the contents are written in the same way as
15453their @code{C} counterparts.
15454
15455@smallexample
15456VAR
15457 s: ARRAY [1..5] OF CARDINAL ;
15458BEGIN
15459 s[1] := 1 ;
15460@end smallexample
15461
15462@smallexample
15463(@value{GDBP}) print s
15464$1 = @{1, 0, 0, 0, 0@}
15465(@value{GDBP}) ptype s
15466type = ARRAY [1..5] OF CARDINAL
15467@end smallexample
15468
15469The Modula-2 language interface to @value{GDBN} also understands
15470pointer types as shown in this example:
15471
15472@smallexample
15473VAR
15474 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
15475BEGIN
15476 NEW(s) ;
15477 s^[1] := 1 ;
15478@end smallexample
15479
15480@noindent
15481and you can request that @value{GDBN} describes the type of @code{s}.
15482
15483@smallexample
15484(@value{GDBP}) ptype s
15485type = POINTER TO ARRAY [1..5] OF CARDINAL
15486@end smallexample
15487
15488@value{GDBN} handles compound types as we can see in this example.
15489Here we combine array types, record types, pointer types and subrange
15490types:
15491
15492@smallexample
15493TYPE
15494 foo = RECORD
15495 f1: CARDINAL ;
15496 f2: CHAR ;
15497 f3: myarray ;
15498 END ;
15499
15500 myarray = ARRAY myrange OF CARDINAL ;
15501 myrange = [-2..2] ;
15502VAR
15503 s: POINTER TO ARRAY myrange OF foo ;
15504@end smallexample
15505
15506@noindent
15507and you can ask @value{GDBN} to describe the type of @code{s} as shown
15508below.
15509
15510@smallexample
15511(@value{GDBP}) ptype s
15512type = POINTER TO ARRAY [-2..2] OF foo = RECORD
15513 f1 : CARDINAL;
15514 f2 : CHAR;
15515 f3 : ARRAY [-2..2] OF CARDINAL;
15516END
15517@end smallexample
15518
6d2ebf8b 15519@node M2 Defaults
79a6e687 15520@subsubsection Modula-2 Defaults
c906108c
SS
15521@cindex Modula-2 defaults
15522
15523If type and range checking are set automatically by @value{GDBN}, they
15524both default to @code{on} whenever the working language changes to
d4f3574e 15525Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
15526selected the working language.
15527
15528If you allow @value{GDBN} to set the language automatically, then entering
15529code compiled from a file whose name ends with @file{.mod} sets the
79a6e687
BW
15530working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
15531Infer the Source Language}, for further details.
c906108c 15532
6d2ebf8b 15533@node Deviations
79a6e687 15534@subsubsection Deviations from Standard Modula-2
c906108c
SS
15535@cindex Modula-2, deviations from
15536
15537A few changes have been made to make Modula-2 programs easier to debug.
15538This is done primarily via loosening its type strictness:
15539
15540@itemize @bullet
15541@item
15542Unlike in standard Modula-2, pointer constants can be formed by
15543integers. This allows you to modify pointer variables during
15544debugging. (In standard Modula-2, the actual address contained in a
15545pointer variable is hidden from you; it can only be modified
15546through direct assignment to another pointer variable or expression that
15547returned a pointer.)
15548
15549@item
15550C escape sequences can be used in strings and characters to represent
15551non-printable characters. @value{GDBN} prints out strings with these
15552escape sequences embedded. Single non-printable characters are
15553printed using the @samp{CHR(@var{nnn})} format.
15554
15555@item
15556The assignment operator (@code{:=}) returns the value of its right-hand
15557argument.
15558
15559@item
15560All built-in procedures both modify @emph{and} return their argument.
15561@end itemize
15562
6d2ebf8b 15563@node M2 Checks
79a6e687 15564@subsubsection Modula-2 Type and Range Checks
c906108c
SS
15565@cindex Modula-2 checks
15566
15567@quotation
15568@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
15569range checking.
15570@end quotation
15571@c FIXME remove warning when type/range checks added
15572
15573@value{GDBN} considers two Modula-2 variables type equivalent if:
15574
15575@itemize @bullet
15576@item
15577They are of types that have been declared equivalent via a @code{TYPE
15578@var{t1} = @var{t2}} statement
15579
15580@item
15581They have been declared on the same line. (Note: This is true of the
15582@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
15583@end itemize
15584
15585As long as type checking is enabled, any attempt to combine variables
15586whose types are not equivalent is an error.
15587
15588Range checking is done on all mathematical operations, assignment, array
15589index bounds, and all built-in functions and procedures.
15590
6d2ebf8b 15591@node M2 Scope
79a6e687 15592@subsubsection The Scope Operators @code{::} and @code{.}
c906108c 15593@cindex scope
41afff9a 15594@cindex @code{.}, Modula-2 scope operator
c906108c
SS
15595@cindex colon, doubled as scope operator
15596@ifinfo
41afff9a 15597@vindex colon-colon@r{, in Modula-2}
c906108c
SS
15598@c Info cannot handle :: but TeX can.
15599@end ifinfo
a67ec3f4 15600@ifnotinfo
41afff9a 15601@vindex ::@r{, in Modula-2}
a67ec3f4 15602@end ifnotinfo
c906108c
SS
15603
15604There are a few subtle differences between the Modula-2 scope operator
15605(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
15606similar syntax:
15607
474c8240 15608@smallexample
c906108c
SS
15609
15610@var{module} . @var{id}
15611@var{scope} :: @var{id}
474c8240 15612@end smallexample
c906108c
SS
15613
15614@noindent
15615where @var{scope} is the name of a module or a procedure,
15616@var{module} the name of a module, and @var{id} is any declared
15617identifier within your program, except another module.
15618
15619Using the @code{::} operator makes @value{GDBN} search the scope
15620specified by @var{scope} for the identifier @var{id}. If it is not
15621found in the specified scope, then @value{GDBN} searches all scopes
15622enclosing the one specified by @var{scope}.
15623
15624Using the @code{.} operator makes @value{GDBN} search the current scope for
15625the identifier specified by @var{id} that was imported from the
15626definition module specified by @var{module}. With this operator, it is
15627an error if the identifier @var{id} was not imported from definition
15628module @var{module}, or if @var{id} is not an identifier in
15629@var{module}.
15630
6d2ebf8b 15631@node GDB/M2
c906108c
SS
15632@subsubsection @value{GDBN} and Modula-2
15633
15634Some @value{GDBN} commands have little use when debugging Modula-2 programs.
15635Five subcommands of @code{set print} and @code{show print} apply
b37052ae 15636specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 15637@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 15638apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
15639analogue in Modula-2.
15640
15641The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 15642with any language, is not useful with Modula-2. Its
c906108c 15643intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 15644created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 15645address can be specified by an integral constant, the construct
d4f3574e 15646@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
15647
15648@cindex @code{#} in Modula-2
15649In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
15650interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 15651
e07c999f
PH
15652@node Ada
15653@subsection Ada
15654@cindex Ada
15655
15656The extensions made to @value{GDBN} for Ada only support
15657output from the @sc{gnu} Ada (GNAT) compiler.
15658Other Ada compilers are not currently supported, and
15659attempting to debug executables produced by them is most likely
15660to be difficult.
15661
15662
15663@cindex expressions in Ada
15664@menu
15665* Ada Mode Intro:: General remarks on the Ada syntax
15666 and semantics supported by Ada mode
15667 in @value{GDBN}.
15668* Omissions from Ada:: Restrictions on the Ada expression syntax.
15669* Additions to Ada:: Extensions of the Ada expression syntax.
3685b09f
PMR
15670* Overloading support for Ada:: Support for expressions involving overloaded
15671 subprograms.
e07c999f 15672* Stopping Before Main Program:: Debugging the program during elaboration.
58d06528 15673* Ada Exceptions:: Ada Exceptions
20924a55
JB
15674* Ada Tasks:: Listing and setting breakpoints in tasks.
15675* Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
6e1bb179
JB
15676* Ravenscar Profile:: Tasking Support when using the Ravenscar
15677 Profile
e07c999f
PH
15678* Ada Glitches:: Known peculiarities of Ada mode.
15679@end menu
15680
15681@node Ada Mode Intro
15682@subsubsection Introduction
15683@cindex Ada mode, general
15684
15685The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
15686syntax, with some extensions.
15687The philosophy behind the design of this subset is
15688
15689@itemize @bullet
15690@item
15691That @value{GDBN} should provide basic literals and access to operations for
15692arithmetic, dereferencing, field selection, indexing, and subprogram calls,
15693leaving more sophisticated computations to subprograms written into the
15694program (which therefore may be called from @value{GDBN}).
15695
15696@item
15697That type safety and strict adherence to Ada language restrictions
15698are not particularly important to the @value{GDBN} user.
15699
15700@item
15701That brevity is important to the @value{GDBN} user.
15702@end itemize
15703
f3a2dd1a
JB
15704Thus, for brevity, the debugger acts as if all names declared in
15705user-written packages are directly visible, even if they are not visible
15706according to Ada rules, thus making it unnecessary to fully qualify most
15707names with their packages, regardless of context. Where this causes
15708ambiguity, @value{GDBN} asks the user's intent.
e07c999f
PH
15709
15710The debugger will start in Ada mode if it detects an Ada main program.
15711As for other languages, it will enter Ada mode when stopped in a program that
15712was translated from an Ada source file.
15713
15714While in Ada mode, you may use `@t{--}' for comments. This is useful
15715mostly for documenting command files. The standard @value{GDBN} comment
15716(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
15717middle (to allow based literals).
15718
e07c999f
PH
15719@node Omissions from Ada
15720@subsubsection Omissions from Ada
15721@cindex Ada, omissions from
15722
15723Here are the notable omissions from the subset:
15724
15725@itemize @bullet
15726@item
15727Only a subset of the attributes are supported:
15728
15729@itemize @minus
15730@item
15731@t{'First}, @t{'Last}, and @t{'Length}
15732 on array objects (not on types and subtypes).
15733
15734@item
15735@t{'Min} and @t{'Max}.
15736
15737@item
15738@t{'Pos} and @t{'Val}.
15739
15740@item
15741@t{'Tag}.
15742
15743@item
15744@t{'Range} on array objects (not subtypes), but only as the right
15745operand of the membership (@code{in}) operator.
15746
15747@item
15748@t{'Access}, @t{'Unchecked_Access}, and
15749@t{'Unrestricted_Access} (a GNAT extension).
15750
15751@item
15752@t{'Address}.
15753@end itemize
15754
15755@item
15756The names in
15757@code{Characters.Latin_1} are not available and
15758concatenation is not implemented. Thus, escape characters in strings are
15759not currently available.
15760
15761@item
15762Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
15763equality of representations. They will generally work correctly
15764for strings and arrays whose elements have integer or enumeration types.
15765They may not work correctly for arrays whose element
15766types have user-defined equality, for arrays of real values
15767(in particular, IEEE-conformant floating point, because of negative
15768zeroes and NaNs), and for arrays whose elements contain unused bits with
15769indeterminate values.
15770
15771@item
15772The other component-by-component array operations (@code{and}, @code{or},
15773@code{xor}, @code{not}, and relational tests other than equality)
15774are not implemented.
15775
15776@item
860701dc
PH
15777@cindex array aggregates (Ada)
15778@cindex record aggregates (Ada)
15779@cindex aggregates (Ada)
15780There is limited support for array and record aggregates. They are
15781permitted only on the right sides of assignments, as in these examples:
15782
15783@smallexample
077e0a52
JB
15784(@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
15785(@value{GDBP}) set An_Array := (1, others => 0)
15786(@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
15787(@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
15788(@value{GDBP}) set A_Record := (1, "Peter", True);
15789(@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
860701dc
PH
15790@end smallexample
15791
15792Changing a
15793discriminant's value by assigning an aggregate has an
15794undefined effect if that discriminant is used within the record.
15795However, you can first modify discriminants by directly assigning to
15796them (which normally would not be allowed in Ada), and then performing an
15797aggregate assignment. For example, given a variable @code{A_Rec}
15798declared to have a type such as:
15799
15800@smallexample
15801type Rec (Len : Small_Integer := 0) is record
15802 Id : Integer;
15803 Vals : IntArray (1 .. Len);
15804end record;
15805@end smallexample
15806
15807you can assign a value with a different size of @code{Vals} with two
15808assignments:
15809
15810@smallexample
077e0a52
JB
15811(@value{GDBP}) set A_Rec.Len := 4
15812(@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
860701dc
PH
15813@end smallexample
15814
15815As this example also illustrates, @value{GDBN} is very loose about the usual
15816rules concerning aggregates. You may leave out some of the
15817components of an array or record aggregate (such as the @code{Len}
15818component in the assignment to @code{A_Rec} above); they will retain their
15819original values upon assignment. You may freely use dynamic values as
15820indices in component associations. You may even use overlapping or
15821redundant component associations, although which component values are
15822assigned in such cases is not defined.
e07c999f
PH
15823
15824@item
15825Calls to dispatching subprograms are not implemented.
15826
15827@item
15828The overloading algorithm is much more limited (i.e., less selective)
ae21e955
BW
15829than that of real Ada. It makes only limited use of the context in
15830which a subexpression appears to resolve its meaning, and it is much
15831looser in its rules for allowing type matches. As a result, some
15832function calls will be ambiguous, and the user will be asked to choose
15833the proper resolution.
e07c999f
PH
15834
15835@item
15836The @code{new} operator is not implemented.
15837
15838@item
15839Entry calls are not implemented.
15840
15841@item
15842Aside from printing, arithmetic operations on the native VAX floating-point
15843formats are not supported.
15844
15845@item
15846It is not possible to slice a packed array.
158c7665
PH
15847
15848@item
15849The names @code{True} and @code{False}, when not part of a qualified name,
15850are interpreted as if implicitly prefixed by @code{Standard}, regardless of
15851context.
15852Should your program
15853redefine these names in a package or procedure (at best a dubious practice),
15854you will have to use fully qualified names to access their new definitions.
e07c999f
PH
15855@end itemize
15856
15857@node Additions to Ada
15858@subsubsection Additions to Ada
15859@cindex Ada, deviations from
15860
15861As it does for other languages, @value{GDBN} makes certain generic
15862extensions to Ada (@pxref{Expressions}):
15863
15864@itemize @bullet
15865@item
ae21e955
BW
15866If the expression @var{E} is a variable residing in memory (typically
15867a local variable or array element) and @var{N} is a positive integer,
15868then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
15869@var{N}-1 adjacent variables following it in memory as an array. In
15870Ada, this operator is generally not necessary, since its prime use is
15871in displaying parts of an array, and slicing will usually do this in
15872Ada. However, there are occasional uses when debugging programs in
15873which certain debugging information has been optimized away.
e07c999f
PH
15874
15875@item
ae21e955
BW
15876@code{@var{B}::@var{var}} means ``the variable named @var{var} that
15877appears in function or file @var{B}.'' When @var{B} is a file name,
15878you must typically surround it in single quotes.
e07c999f
PH
15879
15880@item
15881The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
15882@var{type} that appears at address @var{addr}.''
15883
15884@item
15885A name starting with @samp{$} is a convenience variable
15886(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
15887@end itemize
15888
ae21e955
BW
15889In addition, @value{GDBN} provides a few other shortcuts and outright
15890additions specific to Ada:
e07c999f
PH
15891
15892@itemize @bullet
15893@item
15894The assignment statement is allowed as an expression, returning
15895its right-hand operand as its value. Thus, you may enter
15896
15897@smallexample
077e0a52
JB
15898(@value{GDBP}) set x := y + 3
15899(@value{GDBP}) print A(tmp := y + 1)
e07c999f
PH
15900@end smallexample
15901
15902@item
15903The semicolon is allowed as an ``operator,'' returning as its value
15904the value of its right-hand operand.
15905This allows, for example,
15906complex conditional breaks:
15907
15908@smallexample
077e0a52
JB
15909(@value{GDBP}) break f
15910(@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
e07c999f
PH
15911@end smallexample
15912
15913@item
15914Rather than use catenation and symbolic character names to introduce special
15915characters into strings, one may instead use a special bracket notation,
15916which is also used to print strings. A sequence of characters of the form
15917@samp{["@var{XX}"]} within a string or character literal denotes the
15918(single) character whose numeric encoding is @var{XX} in hexadecimal. The
15919sequence of characters @samp{["""]} also denotes a single quotation mark
15920in strings. For example,
15921@smallexample
15922 "One line.["0a"]Next line.["0a"]"
15923@end smallexample
15924@noindent
ae21e955
BW
15925contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
15926after each period.
e07c999f
PH
15927
15928@item
15929The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
15930@t{'Max} is optional (and is ignored in any case). For example, it is valid
15931to write
15932
15933@smallexample
077e0a52 15934(@value{GDBP}) print 'max(x, y)
e07c999f
PH
15935@end smallexample
15936
15937@item
15938When printing arrays, @value{GDBN} uses positional notation when the
15939array has a lower bound of 1, and uses a modified named notation otherwise.
ae21e955
BW
15940For example, a one-dimensional array of three integers with a lower bound
15941of 3 might print as
e07c999f
PH
15942
15943@smallexample
15944(3 => 10, 17, 1)
15945@end smallexample
15946
15947@noindent
15948That is, in contrast to valid Ada, only the first component has a @code{=>}
15949clause.
15950
15951@item
15952You may abbreviate attributes in expressions with any unique,
15953multi-character subsequence of
15954their names (an exact match gets preference).
15955For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
15956in place of @t{a'length}.
15957
15958@item
15959@cindex quoting Ada internal identifiers
15960Since Ada is case-insensitive, the debugger normally maps identifiers you type
15961to lower case. The GNAT compiler uses upper-case characters for
15962some of its internal identifiers, which are normally of no interest to users.
15963For the rare occasions when you actually have to look at them,
15964enclose them in angle brackets to avoid the lower-case mapping.
15965For example,
15966@smallexample
077e0a52 15967(@value{GDBP}) print <JMPBUF_SAVE>[0]
e07c999f
PH
15968@end smallexample
15969
15970@item
15971Printing an object of class-wide type or dereferencing an
15972access-to-class-wide value will display all the components of the object's
15973specific type (as indicated by its run-time tag). Likewise, component
15974selection on such a value will operate on the specific type of the
15975object.
15976
15977@end itemize
15978
3685b09f
PMR
15979@node Overloading support for Ada
15980@subsubsection Overloading support for Ada
15981@cindex overloading, Ada
15982
15983The debugger supports limited overloading. Given a subprogram call in which
15984the function symbol has multiple definitions, it will use the number of
15985actual parameters and some information about their types to attempt to narrow
15986the set of definitions. It also makes very limited use of context, preferring
15987procedures to functions in the context of the @code{call} command, and
15988functions to procedures elsewhere.
15989
15990If, after narrowing, the set of matching definitions still contains more than
15991one definition, @value{GDBN} will display a menu to query which one it should
15992use, for instance:
15993
15994@smallexample
15995(@value{GDBP}) print f(1)
15996Multiple matches for f
15997[0] cancel
15998[1] foo.f (integer) return boolean at foo.adb:23
15999[2] foo.f (foo.new_integer) return boolean at foo.adb:28
16000>
16001@end smallexample
16002
16003In this case, just select one menu entry either to cancel expression evaluation
16004(type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
16005instance (type the corresponding number and press @key{RET}).
16006
16007Here are a couple of commands to customize @value{GDBN}'s behavior in this
16008case:
16009
16010@table @code
16011
16012@kindex set ada print-signatures
16013@item set ada print-signatures
16014Control whether parameter types and return types are displayed in overloads
16015selection menus. It is @code{on} by default.
16016@xref{Overloading support for Ada}.
16017
16018@kindex show ada print-signatures
16019@item show ada print-signatures
16020Show the current setting for displaying parameter types and return types in
16021overloads selection menu.
16022@xref{Overloading support for Ada}.
16023
16024@end table
16025
e07c999f
PH
16026@node Stopping Before Main Program
16027@subsubsection Stopping at the Very Beginning
16028
16029@cindex breakpointing Ada elaboration code
16030It is sometimes necessary to debug the program during elaboration, and
16031before reaching the main procedure.
16032As defined in the Ada Reference
16033Manual, the elaboration code is invoked from a procedure called
16034@code{adainit}. To run your program up to the beginning of
16035elaboration, simply use the following two commands:
16036@code{tbreak adainit} and @code{run}.
16037
58d06528
JB
16038@node Ada Exceptions
16039@subsubsection Ada Exceptions
16040
16041A command is provided to list all Ada exceptions:
16042
16043@table @code
16044@kindex info exceptions
16045@item info exceptions
16046@itemx info exceptions @var{regexp}
16047The @code{info exceptions} command allows you to list all Ada exceptions
16048defined within the program being debugged, as well as their addresses.
16049With a regular expression, @var{regexp}, as argument, only those exceptions
16050whose names match @var{regexp} are listed.
16051@end table
16052
16053Below is a small example, showing how the command can be used, first
16054without argument, and next with a regular expression passed as an
16055argument.
16056
16057@smallexample
16058(@value{GDBP}) info exceptions
16059All defined Ada exceptions:
16060constraint_error: 0x613da0
16061program_error: 0x613d20
16062storage_error: 0x613ce0
16063tasking_error: 0x613ca0
16064const.aint_global_e: 0x613b00
16065(@value{GDBP}) info exceptions const.aint
16066All Ada exceptions matching regular expression "const.aint":
16067constraint_error: 0x613da0
16068const.aint_global_e: 0x613b00
16069@end smallexample
16070
16071It is also possible to ask @value{GDBN} to stop your program's execution
16072when an exception is raised. For more details, see @ref{Set Catchpoints}.
16073
20924a55
JB
16074@node Ada Tasks
16075@subsubsection Extensions for Ada Tasks
16076@cindex Ada, tasking
16077
16078Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
16079@value{GDBN} provides the following task-related commands:
16080
16081@table @code
16082@kindex info tasks
16083@item info tasks
16084This command shows a list of current Ada tasks, as in the following example:
16085
16086
16087@smallexample
16088@iftex
16089@leftskip=0.5cm
16090@end iftex
16091(@value{GDBP}) info tasks
16092 ID TID P-ID Pri State Name
16093 1 8088000 0 15 Child Activation Wait main_task
16094 2 80a4000 1 15 Accept Statement b
16095 3 809a800 1 15 Child Activation Wait a
32cd1edc 16096* 4 80ae800 3 15 Runnable c
20924a55
JB
16097
16098@end smallexample
16099
16100@noindent
16101In this listing, the asterisk before the last task indicates it to be the
16102task currently being inspected.
16103
16104@table @asis
16105@item ID
16106Represents @value{GDBN}'s internal task number.
16107
16108@item TID
16109The Ada task ID.
16110
16111@item P-ID
16112The parent's task ID (@value{GDBN}'s internal task number).
16113
16114@item Pri
16115The base priority of the task.
16116
16117@item State
16118Current state of the task.
16119
16120@table @code
16121@item Unactivated
16122The task has been created but has not been activated. It cannot be
16123executing.
16124
20924a55
JB
16125@item Runnable
16126The task is not blocked for any reason known to Ada. (It may be waiting
16127for a mutex, though.) It is conceptually "executing" in normal mode.
16128
16129@item Terminated
16130The task is terminated, in the sense of ARM 9.3 (5). Any dependents
16131that were waiting on terminate alternatives have been awakened and have
16132terminated themselves.
16133
16134@item Child Activation Wait
16135The task is waiting for created tasks to complete activation.
16136
16137@item Accept Statement
16138The task is waiting on an accept or selective wait statement.
16139
16140@item Waiting on entry call
16141The task is waiting on an entry call.
16142
16143@item Async Select Wait
16144The task is waiting to start the abortable part of an asynchronous
16145select statement.
16146
16147@item Delay Sleep
16148The task is waiting on a select statement with only a delay
16149alternative open.
16150
16151@item Child Termination Wait
16152The task is sleeping having completed a master within itself, and is
16153waiting for the tasks dependent on that master to become terminated or
16154waiting on a terminate Phase.
16155
16156@item Wait Child in Term Alt
16157The task is sleeping waiting for tasks on terminate alternatives to
16158finish terminating.
16159
16160@item Accepting RV with @var{taskno}
16161The task is accepting a rendez-vous with the task @var{taskno}.
16162@end table
16163
16164@item Name
16165Name of the task in the program.
16166
16167@end table
16168
16169@kindex info task @var{taskno}
16170@item info task @var{taskno}
16171This command shows detailled informations on the specified task, as in
16172the following example:
16173@smallexample
16174@iftex
16175@leftskip=0.5cm
16176@end iftex
16177(@value{GDBP}) info tasks
16178 ID TID P-ID Pri State Name
16179 1 8077880 0 15 Child Activation Wait main_task
32cd1edc 16180* 2 807c468 1 15 Runnable task_1
20924a55
JB
16181(@value{GDBP}) info task 2
16182Ada Task: 0x807c468
16183Name: task_1
16184Thread: 0x807f378
16185Parent: 1 (main_task)
16186Base Priority: 15
16187State: Runnable
16188@end smallexample
16189
16190@item task
16191@kindex task@r{ (Ada)}
16192@cindex current Ada task ID
16193This command prints the ID of the current task.
16194
16195@smallexample
16196@iftex
16197@leftskip=0.5cm
16198@end iftex
16199(@value{GDBP}) info tasks
16200 ID TID P-ID Pri State Name
16201 1 8077870 0 15 Child Activation Wait main_task
32cd1edc 16202* 2 807c458 1 15 Runnable t
20924a55
JB
16203(@value{GDBP}) task
16204[Current task is 2]
16205@end smallexample
16206
16207@item task @var{taskno}
16208@cindex Ada task switching
5d5658a1 16209This command is like the @code{thread @var{thread-id}}
20924a55
JB
16210command (@pxref{Threads}). It switches the context of debugging
16211from the current task to the given task.
16212
16213@smallexample
16214@iftex
16215@leftskip=0.5cm
16216@end iftex
16217(@value{GDBP}) info tasks
16218 ID TID P-ID Pri State Name
16219 1 8077870 0 15 Child Activation Wait main_task
32cd1edc 16220* 2 807c458 1 15 Runnable t
20924a55
JB
16221(@value{GDBP}) task 1
16222[Switching to task 1]
16223#0 0x8067726 in pthread_cond_wait ()
16224(@value{GDBP}) bt
16225#0 0x8067726 in pthread_cond_wait ()
16226#1 0x8056714 in system.os_interface.pthread_cond_wait ()
16227#2 0x805cb63 in system.task_primitives.operations.sleep ()
16228#3 0x806153e in system.tasking.stages.activate_tasks ()
16229#4 0x804aacc in un () at un.adb:5
16230@end smallexample
16231
629500fa
KS
16232@item break @var{location} task @var{taskno}
16233@itemx break @var{location} task @var{taskno} if @dots{}
45ac276d
JB
16234@cindex breakpoints and tasks, in Ada
16235@cindex task breakpoints, in Ada
16236@kindex break @dots{} task @var{taskno}@r{ (Ada)}
16237These commands are like the @code{break @dots{} thread @dots{}}
697aa1b7 16238command (@pxref{Thread Stops}). The
629500fa 16239@var{location} argument specifies source lines, as described
45ac276d
JB
16240in @ref{Specify Location}.
16241
16242Use the qualifier @samp{task @var{taskno}} with a breakpoint command
16243to specify that you only want @value{GDBN} to stop the program when a
697aa1b7 16244particular Ada task reaches this breakpoint. The @var{taskno} is one of the
45ac276d
JB
16245numeric task identifiers assigned by @value{GDBN}, shown in the first
16246column of the @samp{info tasks} display.
16247
16248If you do not specify @samp{task @var{taskno}} when you set a
16249breakpoint, the breakpoint applies to @emph{all} tasks of your
16250program.
16251
16252You can use the @code{task} qualifier on conditional breakpoints as
16253well; in this case, place @samp{task @var{taskno}} before the
16254breakpoint condition (before the @code{if}).
16255
16256For example,
16257
16258@smallexample
16259@iftex
16260@leftskip=0.5cm
16261@end iftex
16262(@value{GDBP}) info tasks
16263 ID TID P-ID Pri State Name
16264 1 140022020 0 15 Child Activation Wait main_task
16265 2 140045060 1 15 Accept/Select Wait t2
16266 3 140044840 1 15 Runnable t1
16267* 4 140056040 1 15 Runnable t3
16268(@value{GDBP}) b 15 task 2
16269Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
16270(@value{GDBP}) cont
16271Continuing.
16272task # 1 running
16273task # 2 running
16274
16275Breakpoint 5, test_task_debug () at test_task_debug.adb:15
1627615 flush;
16277(@value{GDBP}) info tasks
16278 ID TID P-ID Pri State Name
16279 1 140022020 0 15 Child Activation Wait main_task
16280* 2 140045060 1 15 Runnable t2
16281 3 140044840 1 15 Runnable t1
16282 4 140056040 1 15 Delay Sleep t3
16283@end smallexample
20924a55
JB
16284@end table
16285
16286@node Ada Tasks and Core Files
16287@subsubsection Tasking Support when Debugging Core Files
16288@cindex Ada tasking and core file debugging
16289
16290When inspecting a core file, as opposed to debugging a live program,
16291tasking support may be limited or even unavailable, depending on
16292the platform being used.
16293For instance, on x86-linux, the list of tasks is available, but task
32a8097b 16294switching is not supported.
20924a55 16295
32a8097b 16296On certain platforms, the debugger needs to perform some
20924a55
JB
16297memory writes in order to provide Ada tasking support. When inspecting
16298a core file, this means that the core file must be opened with read-write
16299privileges, using the command @samp{"set write on"} (@pxref{Patching}).
16300Under these circumstances, you should make a backup copy of the core
16301file before inspecting it with @value{GDBN}.
16302
6e1bb179
JB
16303@node Ravenscar Profile
16304@subsubsection Tasking Support when using the Ravenscar Profile
16305@cindex Ravenscar Profile
16306
16307The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
16308specifically designed for systems with safety-critical real-time
16309requirements.
16310
16311@table @code
16312@kindex set ravenscar task-switching on
16313@cindex task switching with program using Ravenscar Profile
16314@item set ravenscar task-switching on
16315Allows task switching when debugging a program that uses the Ravenscar
16316Profile. This is the default.
16317
16318@kindex set ravenscar task-switching off
16319@item set ravenscar task-switching off
16320Turn off task switching when debugging a program that uses the Ravenscar
16321Profile. This is mostly intended to disable the code that adds support
16322for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
16323the Ravenscar runtime is preventing @value{GDBN} from working properly.
16324To be effective, this command should be run before the program is started.
16325
16326@kindex show ravenscar task-switching
16327@item show ravenscar task-switching
16328Show whether it is possible to switch from task to task in a program
16329using the Ravenscar Profile.
16330
16331@end table
16332
e07c999f
PH
16333@node Ada Glitches
16334@subsubsection Known Peculiarities of Ada Mode
16335@cindex Ada, problems
16336
16337Besides the omissions listed previously (@pxref{Omissions from Ada}),
16338we know of several problems with and limitations of Ada mode in
16339@value{GDBN},
16340some of which will be fixed with planned future releases of the debugger
16341and the GNU Ada compiler.
16342
16343@itemize @bullet
e07c999f
PH
16344@item
16345Static constants that the compiler chooses not to materialize as objects in
16346storage are invisible to the debugger.
16347
16348@item
16349Named parameter associations in function argument lists are ignored (the
16350argument lists are treated as positional).
16351
16352@item
16353Many useful library packages are currently invisible to the debugger.
16354
16355@item
16356Fixed-point arithmetic, conversions, input, and output is carried out using
16357floating-point arithmetic, and may give results that only approximate those on
16358the host machine.
16359
e07c999f
PH
16360@item
16361The GNAT compiler never generates the prefix @code{Standard} for any of
16362the standard symbols defined by the Ada language. @value{GDBN} knows about
16363this: it will strip the prefix from names when you use it, and will never
16364look for a name you have so qualified among local symbols, nor match against
16365symbols in other packages or subprograms. If you have
16366defined entities anywhere in your program other than parameters and
16367local variables whose simple names match names in @code{Standard},
16368GNAT's lack of qualification here can cause confusion. When this happens,
16369you can usually resolve the confusion
16370by qualifying the problematic names with package
16371@code{Standard} explicitly.
16372@end itemize
16373
95433b34
JB
16374Older versions of the compiler sometimes generate erroneous debugging
16375information, resulting in the debugger incorrectly printing the value
16376of affected entities. In some cases, the debugger is able to work
16377around an issue automatically. In other cases, the debugger is able
16378to work around the issue, but the work-around has to be specifically
16379enabled.
16380
16381@kindex set ada trust-PAD-over-XVS
16382@kindex show ada trust-PAD-over-XVS
16383@table @code
16384
16385@item set ada trust-PAD-over-XVS on
16386Configure GDB to strictly follow the GNAT encoding when computing the
16387value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
16388types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
16389a complete description of the encoding used by the GNAT compiler).
16390This is the default.
16391
16392@item set ada trust-PAD-over-XVS off
16393This is related to the encoding using by the GNAT compiler. If @value{GDBN}
16394sometimes prints the wrong value for certain entities, changing @code{ada
16395trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
16396the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
16397@code{off}, but this incurs a slight performance penalty, so it is
16398recommended to leave this setting to @code{on} unless necessary.
16399
16400@end table
16401
c6044dd1
JB
16402@cindex GNAT descriptive types
16403@cindex GNAT encoding
16404Internally, the debugger also relies on the compiler following a number
16405of conventions known as the @samp{GNAT Encoding}, all documented in
16406@file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
16407how the debugging information should be generated for certain types.
16408In particular, this convention makes use of @dfn{descriptive types},
16409which are artificial types generated purely to help the debugger.
16410
16411These encodings were defined at a time when the debugging information
16412format used was not powerful enough to describe some of the more complex
16413types available in Ada. Since DWARF allows us to express nearly all
16414Ada features, the long-term goal is to slowly replace these descriptive
16415types by their pure DWARF equivalent. To facilitate that transition,
16416a new maintenance option is available to force the debugger to ignore
16417those descriptive types. It allows the user to quickly evaluate how
16418well @value{GDBN} works without them.
16419
16420@table @code
16421
16422@kindex maint ada set ignore-descriptive-types
16423@item maintenance ada set ignore-descriptive-types [on|off]
16424Control whether the debugger should ignore descriptive types.
16425The default is not to ignore descriptives types (@code{off}).
16426
16427@kindex maint ada show ignore-descriptive-types
16428@item maintenance ada show ignore-descriptive-types
16429Show if descriptive types are ignored by @value{GDBN}.
16430
16431@end table
16432
79a6e687
BW
16433@node Unsupported Languages
16434@section Unsupported Languages
4e562065
JB
16435
16436@cindex unsupported languages
16437@cindex minimal language
16438In addition to the other fully-supported programming languages,
16439@value{GDBN} also provides a pseudo-language, called @code{minimal}.
16440It does not represent a real programming language, but provides a set
16441of capabilities close to what the C or assembly languages provide.
16442This should allow most simple operations to be performed while debugging
16443an application that uses a language currently not supported by @value{GDBN}.
16444
16445If the language is set to @code{auto}, @value{GDBN} will automatically
16446select this language if the current frame corresponds to an unsupported
16447language.
16448
6d2ebf8b 16449@node Symbols
c906108c
SS
16450@chapter Examining the Symbol Table
16451
d4f3574e 16452The commands described in this chapter allow you to inquire about the
c906108c
SS
16453symbols (names of variables, functions and types) defined in your
16454program. This information is inherent in the text of your program and
16455does not change as your program executes. @value{GDBN} finds it in your
16456program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
16457(@pxref{File Options, ,Choosing Files}), or by one of the
16458file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
16459
16460@cindex symbol names
16461@cindex names of symbols
16462@cindex quoting names
16463Occasionally, you may need to refer to symbols that contain unusual
16464characters, which @value{GDBN} ordinarily treats as word delimiters. The
16465most frequent case is in referring to static variables in other
79a6e687 16466source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
16467are recorded in object files as debugging symbols, but @value{GDBN} would
16468ordinarily parse a typical file name, like @file{foo.c}, as the three words
16469@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
16470@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
16471
474c8240 16472@smallexample
c906108c 16473p 'foo.c'::x
474c8240 16474@end smallexample
c906108c
SS
16475
16476@noindent
16477looks up the value of @code{x} in the scope of the file @file{foo.c}.
16478
16479@table @code
a8f24a35
EZ
16480@cindex case-insensitive symbol names
16481@cindex case sensitivity in symbol names
16482@kindex set case-sensitive
16483@item set case-sensitive on
16484@itemx set case-sensitive off
16485@itemx set case-sensitive auto
16486Normally, when @value{GDBN} looks up symbols, it matches their names
16487with case sensitivity determined by the current source language.
16488Occasionally, you may wish to control that. The command @code{set
16489case-sensitive} lets you do that by specifying @code{on} for
16490case-sensitive matches or @code{off} for case-insensitive ones. If
16491you specify @code{auto}, case sensitivity is reset to the default
16492suitable for the source language. The default is case-sensitive
16493matches for all languages except for Fortran, for which the default is
16494case-insensitive matches.
16495
9c16f35a
EZ
16496@kindex show case-sensitive
16497@item show case-sensitive
a8f24a35
EZ
16498This command shows the current setting of case sensitivity for symbols
16499lookups.
16500
53342f27
TT
16501@kindex set print type methods
16502@item set print type methods
16503@itemx set print type methods on
16504@itemx set print type methods off
16505Normally, when @value{GDBN} prints a class, it displays any methods
16506declared in that class. You can control this behavior either by
16507passing the appropriate flag to @code{ptype}, or using @command{set
16508print type methods}. Specifying @code{on} will cause @value{GDBN} to
16509display the methods; this is the default. Specifying @code{off} will
16510cause @value{GDBN} to omit the methods.
16511
16512@kindex show print type methods
16513@item show print type methods
16514This command shows the current setting of method display when printing
16515classes.
16516
16517@kindex set print type typedefs
16518@item set print type typedefs
16519@itemx set print type typedefs on
16520@itemx set print type typedefs off
16521
16522Normally, when @value{GDBN} prints a class, it displays any typedefs
16523defined in that class. You can control this behavior either by
16524passing the appropriate flag to @code{ptype}, or using @command{set
16525print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
16526display the typedef definitions; this is the default. Specifying
16527@code{off} will cause @value{GDBN} to omit the typedef definitions.
16528Note that this controls whether the typedef definition itself is
16529printed, not whether typedef names are substituted when printing other
16530types.
16531
16532@kindex show print type typedefs
16533@item show print type typedefs
16534This command shows the current setting of typedef display when
16535printing classes.
16536
c906108c 16537@kindex info address
b37052ae 16538@cindex address of a symbol
c906108c
SS
16539@item info address @var{symbol}
16540Describe where the data for @var{symbol} is stored. For a register
16541variable, this says which register it is kept in. For a non-register
16542local variable, this prints the stack-frame offset at which the variable
16543is always stored.
16544
16545Note the contrast with @samp{print &@var{symbol}}, which does not work
16546at all for a register variable, and for a stack local variable prints
16547the exact address of the current instantiation of the variable.
16548
3d67e040 16549@kindex info symbol
b37052ae 16550@cindex symbol from address
9c16f35a 16551@cindex closest symbol and offset for an address
3d67e040
EZ
16552@item info symbol @var{addr}
16553Print the name of a symbol which is stored at the address @var{addr}.
16554If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
16555nearest symbol and an offset from it:
16556
474c8240 16557@smallexample
3d67e040
EZ
16558(@value{GDBP}) info symbol 0x54320
16559_initialize_vx + 396 in section .text
474c8240 16560@end smallexample
3d67e040
EZ
16561
16562@noindent
16563This is the opposite of the @code{info address} command. You can use
16564it to find out the name of a variable or a function given its address.
16565
c14c28ba
PP
16566For dynamically linked executables, the name of executable or shared
16567library containing the symbol is also printed:
16568
16569@smallexample
16570(@value{GDBP}) info symbol 0x400225
16571_start + 5 in section .text of /tmp/a.out
16572(@value{GDBP}) info symbol 0x2aaaac2811cf
16573__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
16574@end smallexample
16575
439250fb
DE
16576@kindex demangle
16577@cindex demangle
16578@item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
16579Demangle @var{name}.
16580If @var{language} is provided it is the name of the language to demangle
16581@var{name} in. Otherwise @var{name} is demangled in the current language.
16582
16583The @samp{--} option specifies the end of options,
16584and is useful when @var{name} begins with a dash.
16585
16586The parameter @code{demangle-style} specifies how to interpret the kind
16587of mangling used. @xref{Print Settings}.
16588
c906108c 16589@kindex whatis
53342f27 16590@item whatis[/@var{flags}] [@var{arg}]
177bc839
JK
16591Print the data type of @var{arg}, which can be either an expression
16592or a name of a data type. With no argument, print the data type of
16593@code{$}, the last value in the value history.
16594
16595If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
16596is not actually evaluated, and any side-effecting operations (such as
16597assignments or function calls) inside it do not take place.
16598
16599If @var{arg} is a variable or an expression, @code{whatis} prints its
16600literal type as it is used in the source code. If the type was
16601defined using a @code{typedef}, @code{whatis} will @emph{not} print
16602the data type underlying the @code{typedef}. If the type of the
16603variable or the expression is a compound data type, such as
16604@code{struct} or @code{class}, @code{whatis} never prints their
16605fields or methods. It just prints the @code{struct}/@code{class}
16606name (a.k.a.@: its @dfn{tag}). If you want to see the members of
16607such a compound data type, use @code{ptype}.
16608
16609If @var{arg} is a type name that was defined using @code{typedef},
16610@code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
16611Unrolling means that @code{whatis} will show the underlying type used
16612in the @code{typedef} declaration of @var{arg}. However, if that
16613underlying type is also a @code{typedef}, @code{whatis} will not
16614unroll it.
16615
16616For C code, the type names may also have the form @samp{class
16617@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
16618@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 16619
53342f27
TT
16620@var{flags} can be used to modify how the type is displayed.
16621Available flags are:
16622
16623@table @code
16624@item r
16625Display in ``raw'' form. Normally, @value{GDBN} substitutes template
16626parameters and typedefs defined in a class when printing the class'
16627members. The @code{/r} flag disables this.
16628
16629@item m
16630Do not print methods defined in the class.
16631
16632@item M
16633Print methods defined in the class. This is the default, but the flag
16634exists in case you change the default with @command{set print type methods}.
16635
16636@item t
16637Do not print typedefs defined in the class. Note that this controls
16638whether the typedef definition itself is printed, not whether typedef
16639names are substituted when printing other types.
16640
16641@item T
16642Print typedefs defined in the class. This is the default, but the flag
16643exists in case you change the default with @command{set print type typedefs}.
16644@end table
16645
c906108c 16646@kindex ptype
53342f27 16647@item ptype[/@var{flags}] [@var{arg}]
62f3a2ba
FF
16648@code{ptype} accepts the same arguments as @code{whatis}, but prints a
16649detailed description of the type, instead of just the name of the type.
16650@xref{Expressions, ,Expressions}.
c906108c 16651
177bc839
JK
16652Contrary to @code{whatis}, @code{ptype} always unrolls any
16653@code{typedef}s in its argument declaration, whether the argument is
16654a variable, expression, or a data type. This means that @code{ptype}
16655of a variable or an expression will not print literally its type as
16656present in the source code---use @code{whatis} for that. @code{typedef}s at
16657the pointer or reference targets are also unrolled. Only @code{typedef}s of
16658fields, methods and inner @code{class typedef}s of @code{struct}s,
16659@code{class}es and @code{union}s are not unrolled even with @code{ptype}.
16660
c906108c
SS
16661For example, for this variable declaration:
16662
474c8240 16663@smallexample
177bc839
JK
16664typedef double real_t;
16665struct complex @{ real_t real; double imag; @};
16666typedef struct complex complex_t;
16667complex_t var;
16668real_t *real_pointer_var;
474c8240 16669@end smallexample
c906108c
SS
16670
16671@noindent
16672the two commands give this output:
16673
474c8240 16674@smallexample
c906108c 16675@group
177bc839
JK
16676(@value{GDBP}) whatis var
16677type = complex_t
16678(@value{GDBP}) ptype var
16679type = struct complex @{
16680 real_t real;
16681 double imag;
16682@}
16683(@value{GDBP}) whatis complex_t
16684type = struct complex
16685(@value{GDBP}) whatis struct complex
c906108c 16686type = struct complex
177bc839 16687(@value{GDBP}) ptype struct complex
c906108c 16688type = struct complex @{
177bc839 16689 real_t real;
c906108c
SS
16690 double imag;
16691@}
177bc839
JK
16692(@value{GDBP}) whatis real_pointer_var
16693type = real_t *
16694(@value{GDBP}) ptype real_pointer_var
16695type = double *
c906108c 16696@end group
474c8240 16697@end smallexample
c906108c
SS
16698
16699@noindent
16700As with @code{whatis}, using @code{ptype} without an argument refers to
16701the type of @code{$}, the last value in the value history.
16702
ab1adacd
EZ
16703@cindex incomplete type
16704Sometimes, programs use opaque data types or incomplete specifications
16705of complex data structure. If the debug information included in the
16706program does not allow @value{GDBN} to display a full declaration of
16707the data type, it will say @samp{<incomplete type>}. For example,
16708given these declarations:
16709
16710@smallexample
16711 struct foo;
16712 struct foo *fooptr;
16713@end smallexample
16714
16715@noindent
16716but no definition for @code{struct foo} itself, @value{GDBN} will say:
16717
16718@smallexample
ddb50cd7 16719 (@value{GDBP}) ptype foo
ab1adacd
EZ
16720 $1 = <incomplete type>
16721@end smallexample
16722
16723@noindent
16724``Incomplete type'' is C terminology for data types that are not
16725completely specified.
16726
c906108c
SS
16727@kindex info types
16728@item info types @var{regexp}
16729@itemx info types
09d4efe1
EZ
16730Print a brief description of all types whose names match the regular
16731expression @var{regexp} (or all types in your program, if you supply
16732no argument). Each complete typename is matched as though it were a
16733complete line; thus, @samp{i type value} gives information on all
16734types in your program whose names include the string @code{value}, but
16735@samp{i type ^value$} gives information only on types whose complete
16736name is @code{value}.
c906108c
SS
16737
16738This command differs from @code{ptype} in two ways: first, like
16739@code{whatis}, it does not print a detailed description; second, it
16740lists all source files where a type is defined.
16741
18a9fc12
TT
16742@kindex info type-printers
16743@item info type-printers
16744Versions of @value{GDBN} that ship with Python scripting enabled may
16745have ``type printers'' available. When using @command{ptype} or
16746@command{whatis}, these printers are consulted when the name of a type
16747is needed. @xref{Type Printing API}, for more information on writing
16748type printers.
16749
16750@code{info type-printers} displays all the available type printers.
16751
16752@kindex enable type-printer
16753@kindex disable type-printer
16754@item enable type-printer @var{name}@dots{}
16755@item disable type-printer @var{name}@dots{}
16756These commands can be used to enable or disable type printers.
16757
b37052ae
EZ
16758@kindex info scope
16759@cindex local variables
09d4efe1 16760@item info scope @var{location}
b37052ae 16761List all the variables local to a particular scope. This command
09d4efe1
EZ
16762accepts a @var{location} argument---a function name, a source line, or
16763an address preceded by a @samp{*}, and prints all the variables local
2a25a5ba
EZ
16764to the scope defined by that location. (@xref{Specify Location}, for
16765details about supported forms of @var{location}.) For example:
b37052ae
EZ
16766
16767@smallexample
16768(@value{GDBP}) @b{info scope command_line_handler}
16769Scope for command_line_handler:
16770Symbol rl is an argument at stack/frame offset 8, length 4.
16771Symbol linebuffer is in static storage at address 0x150a18, length 4.
16772Symbol linelength is in static storage at address 0x150a1c, length 4.
16773Symbol p is a local variable in register $esi, length 4.
16774Symbol p1 is a local variable in register $ebx, length 4.
16775Symbol nline is a local variable in register $edx, length 4.
16776Symbol repeat is a local variable at frame offset -8, length 4.
16777@end smallexample
16778
f5c37c66
EZ
16779@noindent
16780This command is especially useful for determining what data to collect
16781during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
16782collect}.
16783
c906108c
SS
16784@kindex info source
16785@item info source
919d772c
JB
16786Show information about the current source file---that is, the source file for
16787the function containing the current point of execution:
16788@itemize @bullet
16789@item
16790the name of the source file, and the directory containing it,
16791@item
16792the directory it was compiled in,
16793@item
16794its length, in lines,
16795@item
16796which programming language it is written in,
16797@item
b6577aab
DE
16798if the debug information provides it, the program that compiled the file
16799(which may include, e.g., the compiler version and command line arguments),
16800@item
919d772c
JB
16801whether the executable includes debugging information for that file, and
16802if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
16803@item
16804whether the debugging information includes information about
16805preprocessor macros.
16806@end itemize
16807
c906108c
SS
16808
16809@kindex info sources
16810@item info sources
16811Print the names of all source files in your program for which there is
16812debugging information, organized into two lists: files whose symbols
16813have already been read, and files whose symbols will be read when needed.
16814
16815@kindex info functions
16816@item info functions
16817Print the names and data types of all defined functions.
16818
16819@item info functions @var{regexp}
16820Print the names and data types of all defined functions
16821whose names contain a match for regular expression @var{regexp}.
16822Thus, @samp{info fun step} finds all functions whose names
16823include @code{step}; @samp{info fun ^step} finds those whose names
b383017d 16824start with @code{step}. If a function name contains characters
c1468174 16825that conflict with the regular expression language (e.g.@:
1c5dfdad 16826@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
16827
16828@kindex info variables
16829@item info variables
0fe7935b 16830Print the names and data types of all variables that are defined
6ca652b0 16831outside of functions (i.e.@: excluding local variables).
c906108c
SS
16832
16833@item info variables @var{regexp}
16834Print the names and data types of all variables (except for local
16835variables) whose names contain a match for regular expression
16836@var{regexp}.
16837
b37303ee 16838@kindex info classes
721c2651 16839@cindex Objective-C, classes and selectors
b37303ee
AF
16840@item info classes
16841@itemx info classes @var{regexp}
16842Display all Objective-C classes in your program, or
16843(with the @var{regexp} argument) all those matching a particular regular
16844expression.
16845
16846@kindex info selectors
16847@item info selectors
16848@itemx info selectors @var{regexp}
16849Display all Objective-C selectors in your program, or
16850(with the @var{regexp} argument) all those matching a particular regular
16851expression.
16852
c906108c
SS
16853@ignore
16854This was never implemented.
16855@kindex info methods
16856@item info methods
16857@itemx info methods @var{regexp}
16858The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
16859methods within C@t{++} program, or (with the @var{regexp} argument) a
16860specific set of methods found in the various C@t{++} classes. Many
16861C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
16862from the @code{ptype} command can be overwhelming and hard to use. The
16863@code{info-methods} command filters the methods, printing only those
16864which match the regular-expression @var{regexp}.
16865@end ignore
16866
9c16f35a 16867@cindex opaque data types
c906108c
SS
16868@kindex set opaque-type-resolution
16869@item set opaque-type-resolution on
16870Tell @value{GDBN} to resolve opaque types. An opaque type is a type
16871declared as a pointer to a @code{struct}, @code{class}, or
16872@code{union}---for example, @code{struct MyType *}---that is used in one
16873source file although the full declaration of @code{struct MyType} is in
16874another source file. The default is on.
16875
16876A change in the setting of this subcommand will not take effect until
16877the next time symbols for a file are loaded.
16878
16879@item set opaque-type-resolution off
16880Tell @value{GDBN} not to resolve opaque types. In this case, the type
16881is printed as follows:
16882@smallexample
16883@{<no data fields>@}
16884@end smallexample
16885
16886@kindex show opaque-type-resolution
16887@item show opaque-type-resolution
16888Show whether opaque types are resolved or not.
c906108c 16889
770e7fc7
DE
16890@kindex set print symbol-loading
16891@cindex print messages when symbols are loaded
16892@item set print symbol-loading
16893@itemx set print symbol-loading full
16894@itemx set print symbol-loading brief
16895@itemx set print symbol-loading off
16896The @code{set print symbol-loading} command allows you to control the
16897printing of messages when @value{GDBN} loads symbol information.
16898By default a message is printed for the executable and one for each
16899shared library, and normally this is what you want. However, when
16900debugging apps with large numbers of shared libraries these messages
16901can be annoying.
16902When set to @code{brief} a message is printed for each executable,
16903and when @value{GDBN} loads a collection of shared libraries at once
16904it will only print one message regardless of the number of shared
16905libraries. When set to @code{off} no messages are printed.
16906
16907@kindex show print symbol-loading
16908@item show print symbol-loading
16909Show whether messages will be printed when a @value{GDBN} command
16910entered from the keyboard causes symbol information to be loaded.
16911
c906108c
SS
16912@kindex maint print symbols
16913@cindex symbol dump
16914@kindex maint print psymbols
16915@cindex partial symbol dump
7c57fa1e
YQ
16916@kindex maint print msymbols
16917@cindex minimal symbol dump
c906108c
SS
16918@item maint print symbols @var{filename}
16919@itemx maint print psymbols @var{filename}
16920@itemx maint print msymbols @var{filename}
16921Write a dump of debugging symbol data into the file @var{filename}.
16922These commands are used to debug the @value{GDBN} symbol-reading code. Only
16923symbols with debugging data are included. If you use @samp{maint print
16924symbols}, @value{GDBN} includes all the symbols for which it has already
16925collected full details: that is, @var{filename} reflects symbols for
16926only those files whose symbols @value{GDBN} has read. You can use the
16927command @code{info sources} to find out which files these are. If you
16928use @samp{maint print psymbols} instead, the dump shows information about
16929symbols that @value{GDBN} only knows partially---that is, symbols defined in
16930files that @value{GDBN} has skimmed, but not yet read completely. Finally,
16931@samp{maint print msymbols} dumps just the minimal symbol information
16932required for each object file from which @value{GDBN} has read some symbols.
79a6e687 16933@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 16934@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 16935
5e7b2f39
JB
16936@kindex maint info symtabs
16937@kindex maint info psymtabs
44ea7b70
JB
16938@cindex listing @value{GDBN}'s internal symbol tables
16939@cindex symbol tables, listing @value{GDBN}'s internal
16940@cindex full symbol tables, listing @value{GDBN}'s internal
16941@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
16942@item maint info symtabs @r{[} @var{regexp} @r{]}
16943@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
16944
16945List the @code{struct symtab} or @code{struct partial_symtab}
16946structures whose names match @var{regexp}. If @var{regexp} is not
16947given, list them all. The output includes expressions which you can
16948copy into a @value{GDBN} debugging this one to examine a particular
16949structure in more detail. For example:
16950
16951@smallexample
5e7b2f39 16952(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
16953@{ objfile /home/gnu/build/gdb/gdb
16954 ((struct objfile *) 0x82e69d0)
b383017d 16955 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
16956 ((struct partial_symtab *) 0x8474b10)
16957 readin no
16958 fullname (null)
16959 text addresses 0x814d3c8 -- 0x8158074
16960 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
16961 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
16962 dependencies (none)
16963 @}
16964@}
5e7b2f39 16965(@value{GDBP}) maint info symtabs
44ea7b70
JB
16966(@value{GDBP})
16967@end smallexample
16968@noindent
16969We see that there is one partial symbol table whose filename contains
16970the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
16971and we see that @value{GDBN} has not read in any symtabs yet at all.
16972If we set a breakpoint on a function, that will cause @value{GDBN} to
16973read the symtab for the compilation unit containing that function:
16974
16975@smallexample
16976(@value{GDBP}) break dwarf2_psymtab_to_symtab
16977Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
16978line 1574.
5e7b2f39 16979(@value{GDBP}) maint info symtabs
b383017d 16980@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 16981 ((struct objfile *) 0x82e69d0)
b383017d 16982 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
16983 ((struct symtab *) 0x86c1f38)
16984 dirname (null)
16985 fullname (null)
16986 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 16987 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
16988 debugformat DWARF 2
16989 @}
16990@}
b383017d 16991(@value{GDBP})
44ea7b70 16992@end smallexample
44ea7b70 16993
f57d2163
DE
16994@kindex maint set symbol-cache-size
16995@cindex symbol cache size
16996@item maint set symbol-cache-size @var{size}
16997Set the size of the symbol cache to @var{size}.
16998The default size is intended to be good enough for debugging
16999most applications. This option exists to allow for experimenting
17000with different sizes.
17001
17002@kindex maint show symbol-cache-size
17003@item maint show symbol-cache-size
17004Show the size of the symbol cache.
17005
17006@kindex maint print symbol-cache
17007@cindex symbol cache, printing its contents
17008@item maint print symbol-cache
17009Print the contents of the symbol cache.
17010This is useful when debugging symbol cache issues.
17011
17012@kindex maint print symbol-cache-statistics
17013@cindex symbol cache, printing usage statistics
17014@item maint print symbol-cache-statistics
17015Print symbol cache usage statistics.
17016This helps determine how well the cache is being utilized.
17017
17018@kindex maint flush-symbol-cache
17019@cindex symbol cache, flushing
17020@item maint flush-symbol-cache
17021Flush the contents of the symbol cache, all entries are removed.
17022This command is useful when debugging the symbol cache.
17023It is also useful when collecting performance data.
17024
17025@end table
6a3ca067 17026
6d2ebf8b 17027@node Altering
c906108c
SS
17028@chapter Altering Execution
17029
17030Once you think you have found an error in your program, you might want to
17031find out for certain whether correcting the apparent error would lead to
17032correct results in the rest of the run. You can find the answer by
17033experiment, using the @value{GDBN} features for altering execution of the
17034program.
17035
17036For example, you can store new values into variables or memory
7a292a7a
SS
17037locations, give your program a signal, restart it at a different
17038address, or even return prematurely from a function.
c906108c
SS
17039
17040@menu
17041* Assignment:: Assignment to variables
17042* Jumping:: Continuing at a different address
c906108c 17043* Signaling:: Giving your program a signal
c906108c
SS
17044* Returning:: Returning from a function
17045* Calling:: Calling your program's functions
17046* Patching:: Patching your program
bb2ec1b3 17047* Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
c906108c
SS
17048@end menu
17049
6d2ebf8b 17050@node Assignment
79a6e687 17051@section Assignment to Variables
c906108c
SS
17052
17053@cindex assignment
17054@cindex setting variables
17055To alter the value of a variable, evaluate an assignment expression.
17056@xref{Expressions, ,Expressions}. For example,
17057
474c8240 17058@smallexample
c906108c 17059print x=4
474c8240 17060@end smallexample
c906108c
SS
17061
17062@noindent
17063stores the value 4 into the variable @code{x}, and then prints the
5d161b24 17064value of the assignment expression (which is 4).
c906108c
SS
17065@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
17066information on operators in supported languages.
c906108c
SS
17067
17068@kindex set variable
17069@cindex variables, setting
17070If you are not interested in seeing the value of the assignment, use the
17071@code{set} command instead of the @code{print} command. @code{set} is
17072really the same as @code{print} except that the expression's value is
17073not printed and is not put in the value history (@pxref{Value History,
79a6e687 17074,Value History}). The expression is evaluated only for its effects.
c906108c 17075
c906108c
SS
17076If the beginning of the argument string of the @code{set} command
17077appears identical to a @code{set} subcommand, use the @code{set
17078variable} command instead of just @code{set}. This command is identical
17079to @code{set} except for its lack of subcommands. For example, if your
17080program has a variable @code{width}, you get an error if you try to set
17081a new value with just @samp{set width=13}, because @value{GDBN} has the
17082command @code{set width}:
17083
474c8240 17084@smallexample
c906108c
SS
17085(@value{GDBP}) whatis width
17086type = double
17087(@value{GDBP}) p width
17088$4 = 13
17089(@value{GDBP}) set width=47
17090Invalid syntax in expression.
474c8240 17091@end smallexample
c906108c
SS
17092
17093@noindent
17094The invalid expression, of course, is @samp{=47}. In
17095order to actually set the program's variable @code{width}, use
17096
474c8240 17097@smallexample
c906108c 17098(@value{GDBP}) set var width=47
474c8240 17099@end smallexample
53a5351d 17100
c906108c
SS
17101Because the @code{set} command has many subcommands that can conflict
17102with the names of program variables, it is a good idea to use the
17103@code{set variable} command instead of just @code{set}. For example, if
17104your program has a variable @code{g}, you run into problems if you try
17105to set a new value with just @samp{set g=4}, because @value{GDBN} has
17106the command @code{set gnutarget}, abbreviated @code{set g}:
17107
474c8240 17108@smallexample
c906108c
SS
17109@group
17110(@value{GDBP}) whatis g
17111type = double
17112(@value{GDBP}) p g
17113$1 = 1
17114(@value{GDBP}) set g=4
2df3850c 17115(@value{GDBP}) p g
c906108c
SS
17116$2 = 1
17117(@value{GDBP}) r
17118The program being debugged has been started already.
17119Start it from the beginning? (y or n) y
17120Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
17121"/home/smith/cc_progs/a.out": can't open to read symbols:
17122 Invalid bfd target.
c906108c
SS
17123(@value{GDBP}) show g
17124The current BFD target is "=4".
17125@end group
474c8240 17126@end smallexample
c906108c
SS
17127
17128@noindent
17129The program variable @code{g} did not change, and you silently set the
17130@code{gnutarget} to an invalid value. In order to set the variable
17131@code{g}, use
17132
474c8240 17133@smallexample
c906108c 17134(@value{GDBP}) set var g=4
474c8240 17135@end smallexample
c906108c
SS
17136
17137@value{GDBN} allows more implicit conversions in assignments than C; you can
17138freely store an integer value into a pointer variable or vice versa,
17139and you can convert any structure to any other structure that is the
17140same length or shorter.
17141@comment FIXME: how do structs align/pad in these conversions?
17142@comment /doc@cygnus.com 18dec1990
17143
17144To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
17145construct to generate a value of specified type at a specified address
17146(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
17147to memory location @code{0x83040} as an integer (which implies a certain size
17148and representation in memory), and
17149
474c8240 17150@smallexample
c906108c 17151set @{int@}0x83040 = 4
474c8240 17152@end smallexample
c906108c
SS
17153
17154@noindent
17155stores the value 4 into that memory location.
17156
6d2ebf8b 17157@node Jumping
79a6e687 17158@section Continuing at a Different Address
c906108c
SS
17159
17160Ordinarily, when you continue your program, you do so at the place where
17161it stopped, with the @code{continue} command. You can instead continue at
17162an address of your own choosing, with the following commands:
17163
17164@table @code
17165@kindex jump
c1d780c2 17166@kindex j @r{(@code{jump})}
629500fa 17167@item jump @var{location}
c1d780c2 17168@itemx j @var{location}
629500fa
KS
17169Resume execution at @var{location}. Execution stops again immediately
17170if there is a breakpoint there. @xref{Specify Location}, for a description
17171of the different forms of @var{location}. It is common
2a25a5ba
EZ
17172practice to use the @code{tbreak} command in conjunction with
17173@code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
c906108c
SS
17174
17175The @code{jump} command does not change the current stack frame, or
17176the stack pointer, or the contents of any memory location or any
629500fa 17177register other than the program counter. If @var{location} is in
c906108c
SS
17178a different function from the one currently executing, the results may
17179be bizarre if the two functions expect different patterns of arguments or
17180of local variables. For this reason, the @code{jump} command requests
17181confirmation if the specified line is not in the function currently
17182executing. However, even bizarre results are predictable if you are
17183well acquainted with the machine-language code of your program.
c906108c
SS
17184@end table
17185
53a5351d
JM
17186On many systems, you can get much the same effect as the @code{jump}
17187command by storing a new value into the register @code{$pc}. The
17188difference is that this does not start your program running; it only
17189changes the address of where it @emph{will} run when you continue. For
17190example,
c906108c 17191
474c8240 17192@smallexample
c906108c 17193set $pc = 0x485
474c8240 17194@end smallexample
c906108c
SS
17195
17196@noindent
17197makes the next @code{continue} command or stepping command execute at
17198address @code{0x485}, rather than at the address where your program stopped.
79a6e687 17199@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
17200
17201The most common occasion to use the @code{jump} command is to back
17202up---perhaps with more breakpoints set---over a portion of a program
17203that has already executed, in order to examine its execution in more
17204detail.
17205
c906108c 17206@c @group
6d2ebf8b 17207@node Signaling
79a6e687 17208@section Giving your Program a Signal
9c16f35a 17209@cindex deliver a signal to a program
c906108c
SS
17210
17211@table @code
17212@kindex signal
17213@item signal @var{signal}
70509625 17214Resume execution where your program is stopped, but immediately give it the
697aa1b7 17215signal @var{signal}. The @var{signal} can be the name or the number of a
c906108c
SS
17216signal. For example, on many systems @code{signal 2} and @code{signal
17217SIGINT} are both ways of sending an interrupt signal.
17218
17219Alternatively, if @var{signal} is zero, continue execution without
17220giving a signal. This is useful when your program stopped on account of
ae606bee 17221a signal and would ordinarily see the signal when resumed with the
c906108c
SS
17222@code{continue} command; @samp{signal 0} causes it to resume without a
17223signal.
17224
70509625
PA
17225@emph{Note:} When resuming a multi-threaded program, @var{signal} is
17226delivered to the currently selected thread, not the thread that last
17227reported a stop. This includes the situation where a thread was
17228stopped due to a signal. So if you want to continue execution
17229suppressing the signal that stopped a thread, you should select that
17230same thread before issuing the @samp{signal 0} command. If you issue
17231the @samp{signal 0} command with another thread as the selected one,
17232@value{GDBN} detects that and asks for confirmation.
17233
c906108c
SS
17234Invoking the @code{signal} command is not the same as invoking the
17235@code{kill} utility from the shell. Sending a signal with @code{kill}
17236causes @value{GDBN} to decide what to do with the signal depending on
17237the signal handling tables (@pxref{Signals}). The @code{signal} command
17238passes the signal directly to your program.
17239
81219e53
DE
17240@code{signal} does not repeat when you press @key{RET} a second time
17241after executing the command.
17242
17243@kindex queue-signal
17244@item queue-signal @var{signal}
17245Queue @var{signal} to be delivered immediately to the current thread
17246when execution of the thread resumes. The @var{signal} can be the name or
17247the number of a signal. For example, on many systems @code{signal 2} and
17248@code{signal SIGINT} are both ways of sending an interrupt signal.
17249The handling of the signal must be set to pass the signal to the program,
17250otherwise @value{GDBN} will report an error.
17251You can control the handling of signals from @value{GDBN} with the
17252@code{handle} command (@pxref{Signals}).
17253
17254Alternatively, if @var{signal} is zero, any currently queued signal
17255for the current thread is discarded and when execution resumes no signal
17256will be delivered. This is useful when your program stopped on account
17257of a signal and would ordinarily see the signal when resumed with the
17258@code{continue} command.
17259
17260This command differs from the @code{signal} command in that the signal
17261is just queued, execution is not resumed. And @code{queue-signal} cannot
17262be used to pass a signal whose handling state has been set to @code{nopass}
17263(@pxref{Signals}).
17264@end table
17265@c @end group
c906108c 17266
e5f8a7cc
PA
17267@xref{stepping into signal handlers}, for information on how stepping
17268commands behave when the thread has a signal queued.
17269
6d2ebf8b 17270@node Returning
79a6e687 17271@section Returning from a Function
c906108c
SS
17272
17273@table @code
17274@cindex returning from a function
17275@kindex return
17276@item return
17277@itemx return @var{expression}
17278You can cancel execution of a function call with the @code{return}
17279command. If you give an
17280@var{expression} argument, its value is used as the function's return
17281value.
17282@end table
17283
17284When you use @code{return}, @value{GDBN} discards the selected stack frame
17285(and all frames within it). You can think of this as making the
17286discarded frame return prematurely. If you wish to specify a value to
17287be returned, give that value as the argument to @code{return}.
17288
17289This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 17290Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
17291innermost remaining frame. That frame becomes selected. The
17292specified value is stored in the registers used for returning values
17293of functions.
17294
17295The @code{return} command does not resume execution; it leaves the
17296program stopped in the state that would exist if the function had just
17297returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 17298and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
17299selected stack frame returns naturally.
17300
61ff14c6
JK
17301@value{GDBN} needs to know how the @var{expression} argument should be set for
17302the inferior. The concrete registers assignment depends on the OS ABI and the
17303type being returned by the selected stack frame. For example it is common for
17304OS ABI to return floating point values in FPU registers while integer values in
17305CPU registers. Still some ABIs return even floating point values in CPU
17306registers. Larger integer widths (such as @code{long long int}) also have
17307specific placement rules. @value{GDBN} already knows the OS ABI from its
17308current target so it needs to find out also the type being returned to make the
17309assignment into the right register(s).
17310
17311Normally, the selected stack frame has debug info. @value{GDBN} will always
17312use the debug info instead of the implicit type of @var{expression} when the
17313debug info is available. For example, if you type @kbd{return -1}, and the
17314function in the current stack frame is declared to return a @code{long long
17315int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
17316into a @code{long long int}:
17317
17318@smallexample
17319Breakpoint 1, func () at gdb.base/return-nodebug.c:29
1732029 return 31;
17321(@value{GDBP}) return -1
17322Make func return now? (y or n) y
17323#0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
1732443 printf ("result=%lld\n", func ());
17325(@value{GDBP})
17326@end smallexample
17327
17328However, if the selected stack frame does not have a debug info, e.g., if the
17329function was compiled without debug info, @value{GDBN} has to find out the type
17330to return from user. Specifying a different type by mistake may set the value
17331in different inferior registers than the caller code expects. For example,
17332typing @kbd{return -1} with its implicit type @code{int} would set only a part
17333of a @code{long long int} result for a debug info less function (on 32-bit
17334architectures). Therefore the user is required to specify the return type by
17335an appropriate cast explicitly:
17336
17337@smallexample
17338Breakpoint 2, 0x0040050b in func ()
17339(@value{GDBP}) return -1
17340Return value type not available for selected stack frame.
17341Please use an explicit cast of the value to return.
17342(@value{GDBP}) return (long long int) -1
17343Make selected stack frame return now? (y or n) y
17344#0 0x00400526 in main ()
17345(@value{GDBP})
17346@end smallexample
17347
6d2ebf8b 17348@node Calling
79a6e687 17349@section Calling Program Functions
c906108c 17350
f8568604 17351@table @code
c906108c 17352@cindex calling functions
f8568604
EZ
17353@cindex inferior functions, calling
17354@item print @var{expr}
d3e8051b 17355Evaluate the expression @var{expr} and display the resulting value.
697aa1b7 17356The expression may include calls to functions in the program being
f8568604
EZ
17357debugged.
17358
c906108c 17359@kindex call
c906108c
SS
17360@item call @var{expr}
17361Evaluate the expression @var{expr} without displaying @code{void}
17362returned values.
c906108c
SS
17363
17364You can use this variant of the @code{print} command if you want to
f8568604
EZ
17365execute a function from your program that does not return anything
17366(a.k.a.@: @dfn{a void function}), but without cluttering the output
17367with @code{void} returned values that @value{GDBN} will otherwise
17368print. If the result is not void, it is printed and saved in the
17369value history.
17370@end table
17371
9c16f35a
EZ
17372It is possible for the function you call via the @code{print} or
17373@code{call} command to generate a signal (e.g., if there's a bug in
17374the function, or if you passed it incorrect arguments). What happens
17375in that case is controlled by the @code{set unwindonsignal} command.
17376
7cd1089b
PM
17377Similarly, with a C@t{++} program it is possible for the function you
17378call via the @code{print} or @code{call} command to generate an
17379exception that is not handled due to the constraints of the dummy
17380frame. In this case, any exception that is raised in the frame, but has
17381an out-of-frame exception handler will not be found. GDB builds a
17382dummy-frame for the inferior function call, and the unwinder cannot
17383seek for exception handlers outside of this dummy-frame. What happens
17384in that case is controlled by the
17385@code{set unwind-on-terminating-exception} command.
17386
9c16f35a
EZ
17387@table @code
17388@item set unwindonsignal
17389@kindex set unwindonsignal
17390@cindex unwind stack in called functions
17391@cindex call dummy stack unwinding
17392Set unwinding of the stack if a signal is received while in a function
17393that @value{GDBN} called in the program being debugged. If set to on,
17394@value{GDBN} unwinds the stack it created for the call and restores
17395the context to what it was before the call. If set to off (the
17396default), @value{GDBN} stops in the frame where the signal was
17397received.
17398
17399@item show unwindonsignal
17400@kindex show unwindonsignal
17401Show the current setting of stack unwinding in the functions called by
17402@value{GDBN}.
7cd1089b
PM
17403
17404@item set unwind-on-terminating-exception
17405@kindex set unwind-on-terminating-exception
17406@cindex unwind stack in called functions with unhandled exceptions
17407@cindex call dummy stack unwinding on unhandled exception.
17408Set unwinding of the stack if a C@t{++} exception is raised, but left
17409unhandled while in a function that @value{GDBN} called in the program being
17410debugged. If set to on (the default), @value{GDBN} unwinds the stack
17411it created for the call and restores the context to what it was before
17412the call. If set to off, @value{GDBN} the exception is delivered to
17413the default C@t{++} exception handler and the inferior terminated.
17414
17415@item show unwind-on-terminating-exception
17416@kindex show unwind-on-terminating-exception
17417Show the current setting of stack unwinding in the functions called by
17418@value{GDBN}.
17419
9c16f35a
EZ
17420@end table
17421
f8568604
EZ
17422@cindex weak alias functions
17423Sometimes, a function you wish to call is actually a @dfn{weak alias}
17424for another function. In such case, @value{GDBN} might not pick up
17425the type information, including the types of the function arguments,
17426which causes @value{GDBN} to call the inferior function incorrectly.
17427As a result, the called function will function erroneously and may
17428even crash. A solution to that is to use the name of the aliased
17429function instead.
c906108c 17430
6d2ebf8b 17431@node Patching
79a6e687 17432@section Patching Programs
7a292a7a 17433
c906108c
SS
17434@cindex patching binaries
17435@cindex writing into executables
c906108c 17436@cindex writing into corefiles
c906108c 17437
7a292a7a
SS
17438By default, @value{GDBN} opens the file containing your program's
17439executable code (or the corefile) read-only. This prevents accidental
17440alterations to machine code; but it also prevents you from intentionally
17441patching your program's binary.
c906108c
SS
17442
17443If you'd like to be able to patch the binary, you can specify that
17444explicitly with the @code{set write} command. For example, you might
17445want to turn on internal debugging flags, or even to make emergency
17446repairs.
17447
17448@table @code
17449@kindex set write
17450@item set write on
17451@itemx set write off
7a292a7a 17452If you specify @samp{set write on}, @value{GDBN} opens executable and
20924a55 17453core files for both reading and writing; if you specify @kbd{set write
c906108c
SS
17454off} (the default), @value{GDBN} opens them read-only.
17455
17456If you have already loaded a file, you must load it again (using the
7a292a7a
SS
17457@code{exec-file} or @code{core-file} command) after changing @code{set
17458write}, for your new setting to take effect.
c906108c
SS
17459
17460@item show write
17461@kindex show write
7a292a7a
SS
17462Display whether executable files and core files are opened for writing
17463as well as reading.
c906108c
SS
17464@end table
17465
bb2ec1b3
TT
17466@node Compiling and Injecting Code
17467@section Compiling and injecting code in @value{GDBN}
17468@cindex injecting code
17469@cindex writing into executables
17470@cindex compiling code
17471
17472@value{GDBN} supports on-demand compilation and code injection into
17473programs running under @value{GDBN}. GCC 5.0 or higher built with
17474@file{libcc1.so} must be installed for this functionality to be enabled.
17475This functionality is implemented with the following commands.
17476
17477@table @code
17478@kindex compile code
17479@item compile code @var{source-code}
17480@itemx compile code -raw @var{--} @var{source-code}
17481Compile @var{source-code} with the compiler language found as the current
17482language in @value{GDBN} (@pxref{Languages}). If compilation and
17483injection is not supported with the current language specified in
17484@value{GDBN}, or the compiler does not support this feature, an error
17485message will be printed. If @var{source-code} compiles and links
17486successfully, @value{GDBN} will load the object-code emitted,
17487and execute it within the context of the currently selected inferior.
17488It is important to note that the compiled code is executed immediately.
17489After execution, the compiled code is removed from @value{GDBN} and any
17490new types or variables you have defined will be deleted.
17491
17492The command allows you to specify @var{source-code} in two ways.
17493The simplest method is to provide a single line of code to the command.
17494E.g.:
17495
17496@smallexample
17497compile code printf ("hello world\n");
17498@end smallexample
17499
17500If you specify options on the command line as well as source code, they
17501may conflict. The @samp{--} delimiter can be used to separate options
17502from actual source code. E.g.:
17503
17504@smallexample
17505compile code -r -- printf ("hello world\n");
17506@end smallexample
17507
17508Alternatively you can enter source code as multiple lines of text. To
17509enter this mode, invoke the @samp{compile code} command without any text
17510following the command. This will start the multiple-line editor and
17511allow you to type as many lines of source code as required. When you
17512have completed typing, enter @samp{end} on its own line to exit the
17513editor.
17514
17515@smallexample
17516compile code
17517>printf ("hello\n");
17518>printf ("world\n");
17519>end
17520@end smallexample
17521
17522Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
17523provided @var{source-code} in a callable scope. In this case, you must
17524specify the entry point of the code by defining a function named
17525@code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
17526inferior. Using @samp{-raw} option may be needed for example when
17527@var{source-code} requires @samp{#include} lines which may conflict with
17528inferior symbols otherwise.
17529
17530@kindex compile file
17531@item compile file @var{filename}
17532@itemx compile file -raw @var{filename}
17533Like @code{compile code}, but take the source code from @var{filename}.
17534
17535@smallexample
17536compile file /home/user/example.c
17537@end smallexample
17538@end table
17539
36de76f9
JK
17540@table @code
17541@item compile print @var{expr}
17542@itemx compile print /@var{f} @var{expr}
17543Compile and execute @var{expr} with the compiler language found as the
17544current language in @value{GDBN} (@pxref{Languages}). By default the
17545value of @var{expr} is printed in a format appropriate to its data type;
17546you can choose a different format by specifying @samp{/@var{f}}, where
17547@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
17548Formats}.
17549
17550@item compile print
17551@itemx compile print /@var{f}
17552@cindex reprint the last value
17553Alternatively you can enter the expression (source code producing it) as
17554multiple lines of text. To enter this mode, invoke the @samp{compile print}
17555command without any text following the command. This will start the
17556multiple-line editor.
17557@end table
17558
e7a8570f
JK
17559@noindent
17560The process of compiling and injecting the code can be inspected using:
17561
17562@table @code
17563@anchor{set debug compile}
17564@item set debug compile
17565@cindex compile command debugging info
17566Turns on or off display of @value{GDBN} process of compiling and
17567injecting the code. The default is off.
17568
17569@item show debug compile
17570Displays the current state of displaying @value{GDBN} process of
17571compiling and injecting the code.
17572@end table
17573
17574@subsection Compilation options for the @code{compile} command
17575
17576@value{GDBN} needs to specify the right compilation options for the code
17577to be injected, in part to make its ABI compatible with the inferior
17578and in part to make the injected code compatible with @value{GDBN}'s
17579injecting process.
17580
17581@noindent
17582The options used, in increasing precedence:
17583
17584@table @asis
17585@item target architecture and OS options (@code{gdbarch})
17586These options depend on target processor type and target operating
17587system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
17588(@code{-m64}) compilation option.
17589
17590@item compilation options recorded in the target
17591@value{NGCC} (since version 4.7) stores the options used for compilation
17592into @code{DW_AT_producer} part of DWARF debugging information according
17593to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
17594explicitly specify @code{-g} during inferior compilation otherwise
17595@value{NGCC} produces no DWARF. This feature is only relevant for
17596platforms where @code{-g} produces DWARF by default, otherwise one may
17597try to enforce DWARF by using @code{-gdwarf-4}.
17598
17599@item compilation options set by @code{set compile-args}
17600@end table
17601
17602@noindent
17603You can override compilation options using the following command:
17604
17605@table @code
17606@item set compile-args
17607@cindex compile command options override
17608Set compilation options used for compiling and injecting code with the
17609@code{compile} commands. These options override any conflicting ones
17610from the target architecture and/or options stored during inferior
17611compilation.
17612
17613@item show compile-args
17614Displays the current state of compilation options override.
17615This does not show all the options actually used during compilation,
17616use @ref{set debug compile} for that.
17617@end table
17618
bb2ec1b3
TT
17619@subsection Caveats when using the @code{compile} command
17620
17621There are a few caveats to keep in mind when using the @code{compile}
17622command. As the caveats are different per language, the table below
17623highlights specific issues on a per language basis.
17624
17625@table @asis
17626@item C code examples and caveats
17627When the language in @value{GDBN} is set to @samp{C}, the compiler will
17628attempt to compile the source code with a @samp{C} compiler. The source
17629code provided to the @code{compile} command will have much the same
17630access to variables and types as it normally would if it were part of
17631the program currently being debugged in @value{GDBN}.
17632
17633Below is a sample program that forms the basis of the examples that
17634follow. This program has been compiled and loaded into @value{GDBN},
17635much like any other normal debugging session.
17636
17637@smallexample
17638void function1 (void)
17639@{
17640 int i = 42;
17641 printf ("function 1\n");
17642@}
17643
17644void function2 (void)
17645@{
17646 int j = 12;
17647 function1 ();
17648@}
17649
17650int main(void)
17651@{
17652 int k = 6;
17653 int *p;
17654 function2 ();
17655 return 0;
17656@}
17657@end smallexample
17658
17659For the purposes of the examples in this section, the program above has
17660been compiled, loaded into @value{GDBN}, stopped at the function
17661@code{main}, and @value{GDBN} is awaiting input from the user.
17662
17663To access variables and types for any program in @value{GDBN}, the
17664program must be compiled and packaged with debug information. The
17665@code{compile} command is not an exception to this rule. Without debug
17666information, you can still use the @code{compile} command, but you will
17667be very limited in what variables and types you can access.
17668
17669So with that in mind, the example above has been compiled with debug
17670information enabled. The @code{compile} command will have access to
17671all variables and types (except those that may have been optimized
17672out). Currently, as @value{GDBN} has stopped the program in the
17673@code{main} function, the @code{compile} command would have access to
17674the variable @code{k}. You could invoke the @code{compile} command
17675and type some source code to set the value of @code{k}. You can also
17676read it, or do anything with that variable you would normally do in
17677@code{C}. Be aware that changes to inferior variables in the
17678@code{compile} command are persistent. In the following example:
17679
17680@smallexample
17681compile code k = 3;
17682@end smallexample
17683
17684@noindent
17685the variable @code{k} is now 3. It will retain that value until
17686something else in the example program changes it, or another
17687@code{compile} command changes it.
17688
17689Normal scope and access rules apply to source code compiled and
17690injected by the @code{compile} command. In the example, the variables
17691@code{j} and @code{k} are not accessible yet, because the program is
17692currently stopped in the @code{main} function, where these variables
17693are not in scope. Therefore, the following command
17694
17695@smallexample
17696compile code j = 3;
17697@end smallexample
17698
17699@noindent
17700will result in a compilation error message.
17701
17702Once the program is continued, execution will bring these variables in
17703scope, and they will become accessible; then the code you specify via
17704the @code{compile} command will be able to access them.
17705
17706You can create variables and types with the @code{compile} command as
17707part of your source code. Variables and types that are created as part
17708of the @code{compile} command are not visible to the rest of the program for
17709the duration of its run. This example is valid:
17710
17711@smallexample
17712compile code int ff = 5; printf ("ff is %d\n", ff);
17713@end smallexample
17714
17715However, if you were to type the following into @value{GDBN} after that
17716command has completed:
17717
17718@smallexample
17719compile code printf ("ff is %d\n'', ff);
17720@end smallexample
17721
17722@noindent
17723a compiler error would be raised as the variable @code{ff} no longer
17724exists. Object code generated and injected by the @code{compile}
17725command is removed when its execution ends. Caution is advised
17726when assigning to program variables values of variables created by the
17727code submitted to the @code{compile} command. This example is valid:
17728
17729@smallexample
17730compile code int ff = 5; k = ff;
17731@end smallexample
17732
17733The value of the variable @code{ff} is assigned to @code{k}. The variable
17734@code{k} does not require the existence of @code{ff} to maintain the value
17735it has been assigned. However, pointers require particular care in
17736assignment. If the source code compiled with the @code{compile} command
17737changed the address of a pointer in the example program, perhaps to a
17738variable created in the @code{compile} command, that pointer would point
17739to an invalid location when the command exits. The following example
17740would likely cause issues with your debugged program:
17741
17742@smallexample
17743compile code int ff = 5; p = &ff;
17744@end smallexample
17745
17746In this example, @code{p} would point to @code{ff} when the
17747@code{compile} command is executing the source code provided to it.
17748However, as variables in the (example) program persist with their
17749assigned values, the variable @code{p} would point to an invalid
17750location when the command exists. A general rule should be followed
17751in that you should either assign @code{NULL} to any assigned pointers,
17752or restore a valid location to the pointer before the command exits.
17753
17754Similar caution must be exercised with any structs, unions, and typedefs
17755defined in @code{compile} command. Types defined in the @code{compile}
17756command will no longer be available in the next @code{compile} command.
17757Therefore, if you cast a variable to a type defined in the
17758@code{compile} command, care must be taken to ensure that any future
17759need to resolve the type can be achieved.
17760
17761@smallexample
17762(gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
17763(gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
17764gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
17765Compilation failed.
17766(gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
1776742
17768@end smallexample
17769
17770Variables that have been optimized away by the compiler are not
17771accessible to the code submitted to the @code{compile} command.
17772Access to those variables will generate a compiler error which @value{GDBN}
17773will print to the console.
17774@end table
17775
e7a8570f
JK
17776@subsection Compiler search for the @code{compile} command
17777
17778@value{GDBN} needs to find @value{NGCC} for the inferior being debugged which
17779may not be obvious for remote targets of different architecture than where
17780@value{GDBN} is running. Environment variable @code{PATH} (@code{PATH} from
17781shell that executed @value{GDBN}, not the one set by @value{GDBN}
17782command @code{set environment}). @xref{Environment}. @code{PATH} on
17783@value{GDBN} host is searched for @value{NGCC} binary matching the
17784target architecture and operating system.
17785
17786Specifically @code{PATH} is searched for binaries matching regular expression
17787@code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
17788debugged. @var{arch} is processor name --- multiarch is supported, so for
17789example both @code{i386} and @code{x86_64} targets look for pattern
17790@code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
17791for pattern @code{s390x?}. @var{os} is currently supported only for
17792pattern @code{linux(-gnu)?}.
17793
6d2ebf8b 17794@node GDB Files
c906108c
SS
17795@chapter @value{GDBN} Files
17796
7a292a7a
SS
17797@value{GDBN} needs to know the file name of the program to be debugged,
17798both in order to read its symbol table and in order to start your
17799program. To debug a core dump of a previous run, you must also tell
17800@value{GDBN} the name of the core dump file.
c906108c
SS
17801
17802@menu
17803* Files:: Commands to specify files
2b4bf6af 17804* File Caching:: Information about @value{GDBN}'s file caching
5b5d99cf 17805* Separate Debug Files:: Debugging information in separate files
608e2dbb 17806* MiniDebugInfo:: Debugging information in a special section
9291a0cd 17807* Index Files:: Index files speed up GDB
c906108c 17808* Symbol Errors:: Errors reading symbol files
b14b1491 17809* Data Files:: GDB data files
c906108c
SS
17810@end menu
17811
6d2ebf8b 17812@node Files
79a6e687 17813@section Commands to Specify Files
c906108c 17814
7a292a7a 17815@cindex symbol table
c906108c 17816@cindex core dump file
7a292a7a
SS
17817
17818You may want to specify executable and core dump file names. The usual
17819way to do this is at start-up time, using the arguments to
17820@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
17821Out of @value{GDBN}}).
c906108c
SS
17822
17823Occasionally it is necessary to change to a different file during a
397ca115
EZ
17824@value{GDBN} session. Or you may run @value{GDBN} and forget to
17825specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
17826via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
17827Program}). In these situations the @value{GDBN} commands to specify
0869d01b 17828new files are useful.
c906108c
SS
17829
17830@table @code
17831@cindex executable file
17832@kindex file
17833@item file @var{filename}
17834Use @var{filename} as the program to be debugged. It is read for its
17835symbols and for the contents of pure memory. It is also the program
17836executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
17837directory and the file is not found in the @value{GDBN} working directory,
17838@value{GDBN} uses the environment variable @code{PATH} as a list of
17839directories to search, just as the shell does when looking for a program
17840to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
17841and your program, using the @code{path} command.
17842
fc8be69e
EZ
17843@cindex unlinked object files
17844@cindex patching object files
17845You can load unlinked object @file{.o} files into @value{GDBN} using
17846the @code{file} command. You will not be able to ``run'' an object
17847file, but you can disassemble functions and inspect variables. Also,
17848if the underlying BFD functionality supports it, you could use
17849@kbd{gdb -write} to patch object files using this technique. Note
17850that @value{GDBN} can neither interpret nor modify relocations in this
17851case, so branches and some initialized variables will appear to go to
17852the wrong place. But this feature is still handy from time to time.
17853
c906108c
SS
17854@item file
17855@code{file} with no argument makes @value{GDBN} discard any information it
17856has on both executable file and the symbol table.
17857
17858@kindex exec-file
17859@item exec-file @r{[} @var{filename} @r{]}
17860Specify that the program to be run (but not the symbol table) is found
17861in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
17862if necessary to locate your program. Omitting @var{filename} means to
17863discard information on the executable file.
17864
17865@kindex symbol-file
17866@item symbol-file @r{[} @var{filename} @r{]}
17867Read symbol table information from file @var{filename}. @code{PATH} is
17868searched when necessary. Use the @code{file} command to get both symbol
17869table and program to run from the same file.
17870
17871@code{symbol-file} with no argument clears out @value{GDBN} information on your
17872program's symbol table.
17873
ae5a43e0
DJ
17874The @code{symbol-file} command causes @value{GDBN} to forget the contents of
17875some breakpoints and auto-display expressions. This is because they may
17876contain pointers to the internal data recording symbols and data types,
17877which are part of the old symbol table data being discarded inside
17878@value{GDBN}.
c906108c
SS
17879
17880@code{symbol-file} does not repeat if you press @key{RET} again after
17881executing it once.
17882
17883When @value{GDBN} is configured for a particular environment, it
17884understands debugging information in whatever format is the standard
17885generated for that environment; you may use either a @sc{gnu} compiler, or
17886other compilers that adhere to the local conventions.
c906108c 17887Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 17888using @code{@value{NGCC}} you can generate debugging information for
c906108c 17889optimized code.
c906108c
SS
17890
17891For most kinds of object files, with the exception of old SVR3 systems
17892using COFF, the @code{symbol-file} command does not normally read the
17893symbol table in full right away. Instead, it scans the symbol table
17894quickly to find which source files and which symbols are present. The
17895details are read later, one source file at a time, as they are needed.
17896
17897The purpose of this two-stage reading strategy is to make @value{GDBN}
17898start up faster. For the most part, it is invisible except for
17899occasional pauses while the symbol table details for a particular source
17900file are being read. (The @code{set verbose} command can turn these
17901pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 17902Warnings and Messages}.)
c906108c 17903
c906108c
SS
17904We have not implemented the two-stage strategy for COFF yet. When the
17905symbol table is stored in COFF format, @code{symbol-file} reads the
17906symbol table data in full right away. Note that ``stabs-in-COFF''
17907still does the two-stage strategy, since the debug info is actually
17908in stabs format.
17909
17910@kindex readnow
17911@cindex reading symbols immediately
17912@cindex symbols, reading immediately
6ac33a4e
TT
17913@item symbol-file @r{[} -readnow @r{]} @var{filename}
17914@itemx file @r{[} -readnow @r{]} @var{filename}
c906108c
SS
17915You can override the @value{GDBN} two-stage strategy for reading symbol
17916tables by using the @samp{-readnow} option with any of the commands that
17917load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 17918entire symbol table available.
c906108c 17919
c906108c
SS
17920@c FIXME: for now no mention of directories, since this seems to be in
17921@c flux. 13mar1992 status is that in theory GDB would look either in
17922@c current dir or in same dir as myprog; but issues like competing
17923@c GDB's, or clutter in system dirs, mean that in practice right now
17924@c only current dir is used. FFish says maybe a special GDB hierarchy
17925@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
17926@c files.
17927
c906108c 17928@kindex core-file
09d4efe1 17929@item core-file @r{[}@var{filename}@r{]}
4644b6e3 17930@itemx core
c906108c
SS
17931Specify the whereabouts of a core dump file to be used as the ``contents
17932of memory''. Traditionally, core files contain only some parts of the
17933address space of the process that generated them; @value{GDBN} can access the
17934executable file itself for other parts.
17935
17936@code{core-file} with no argument specifies that no core file is
17937to be used.
17938
17939Note that the core file is ignored when your program is actually running
7a292a7a
SS
17940under @value{GDBN}. So, if you have been running your program and you
17941wish to debug a core file instead, you must kill the subprocess in which
17942the program is running. To do this, use the @code{kill} command
79a6e687 17943(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 17944
c906108c
SS
17945@kindex add-symbol-file
17946@cindex dynamic linking
17947@item add-symbol-file @var{filename} @var{address}
a94ab193 17948@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
24bdad53 17949@itemx add-symbol-file @var{filename} @var{address} -s @var{section} @var{address} @dots{}
96a2c332
SS
17950The @code{add-symbol-file} command reads additional symbol table
17951information from the file @var{filename}. You would use this command
17952when @var{filename} has been dynamically loaded (by some other means)
697aa1b7 17953into the program that is running. The @var{address} should give the memory
96a2c332 17954address at which the file has been loaded; @value{GDBN} cannot figure
d167840f 17955this out for itself. You can additionally specify an arbitrary number
24bdad53 17956of @samp{-s @var{section} @var{address}} pairs, to give an explicit
d167840f
EZ
17957section name and base address for that section. You can specify any
17958@var{address} as an expression.
c906108c
SS
17959
17960The symbol table of the file @var{filename} is added to the symbol table
17961originally read with the @code{symbol-file} command. You can use the
96a2c332 17962@code{add-symbol-file} command any number of times; the new symbol data
98297bf6
NB
17963thus read is kept in addition to the old.
17964
17965Changes can be reverted using the command @code{remove-symbol-file}.
c906108c 17966
17d9d558
JB
17967@cindex relocatable object files, reading symbols from
17968@cindex object files, relocatable, reading symbols from
17969@cindex reading symbols from relocatable object files
17970@cindex symbols, reading from relocatable object files
17971@cindex @file{.o} files, reading symbols from
17972Although @var{filename} is typically a shared library file, an
17973executable file, or some other object file which has been fully
17974relocated for loading into a process, you can also load symbolic
17975information from relocatable @file{.o} files, as long as:
17976
17977@itemize @bullet
17978@item
17979the file's symbolic information refers only to linker symbols defined in
17980that file, not to symbols defined by other object files,
17981@item
17982every section the file's symbolic information refers to has actually
17983been loaded into the inferior, as it appears in the file, and
17984@item
17985you can determine the address at which every section was loaded, and
17986provide these to the @code{add-symbol-file} command.
17987@end itemize
17988
17989@noindent
17990Some embedded operating systems, like Sun Chorus and VxWorks, can load
17991relocatable files into an already running program; such systems
17992typically make the requirements above easy to meet. However, it's
17993important to recognize that many native systems use complex link
49efadf5 17994procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
17995assembly, for example) that make the requirements difficult to meet. In
17996general, one cannot assume that using @code{add-symbol-file} to read a
17997relocatable object file's symbolic information will have the same effect
17998as linking the relocatable object file into the program in the normal
17999way.
18000
c906108c
SS
18001@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
18002
98297bf6
NB
18003@kindex remove-symbol-file
18004@item remove-symbol-file @var{filename}
18005@item remove-symbol-file -a @var{address}
18006Remove a symbol file added via the @code{add-symbol-file} command. The
18007file to remove can be identified by its @var{filename} or by an @var{address}
18008that lies within the boundaries of this symbol file in memory. Example:
18009
18010@smallexample
18011(gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
18012add symbol table from file "/home/user/gdb/mylib.so" at
18013 .text_addr = 0x7ffff7ff9480
18014(y or n) y
18015Reading symbols from /home/user/gdb/mylib.so...done.
18016(gdb) remove-symbol-file -a 0x7ffff7ff9480
18017Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
18018(gdb)
18019@end smallexample
18020
18021
18022@code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
18023
c45da7e6
EZ
18024@kindex add-symbol-file-from-memory
18025@cindex @code{syscall DSO}
18026@cindex load symbols from memory
18027@item add-symbol-file-from-memory @var{address}
18028Load symbols from the given @var{address} in a dynamically loaded
18029object file whose image is mapped directly into the inferior's memory.
18030For example, the Linux kernel maps a @code{syscall DSO} into each
18031process's address space; this DSO provides kernel-specific code for
18032some system calls. The argument can be any expression whose
18033evaluation yields the address of the file's shared object file header.
18034For this command to work, you must have used @code{symbol-file} or
18035@code{exec-file} commands in advance.
18036
c906108c 18037@kindex section
09d4efe1
EZ
18038@item section @var{section} @var{addr}
18039The @code{section} command changes the base address of the named
18040@var{section} of the exec file to @var{addr}. This can be used if the
18041exec file does not contain section addresses, (such as in the
18042@code{a.out} format), or when the addresses specified in the file
18043itself are wrong. Each section must be changed separately. The
18044@code{info files} command, described below, lists all the sections and
18045their addresses.
c906108c
SS
18046
18047@kindex info files
18048@kindex info target
18049@item info files
18050@itemx info target
7a292a7a
SS
18051@code{info files} and @code{info target} are synonymous; both print the
18052current target (@pxref{Targets, ,Specifying a Debugging Target}),
18053including the names of the executable and core dump files currently in
18054use by @value{GDBN}, and the files from which symbols were loaded. The
18055command @code{help target} lists all possible targets rather than
18056current ones.
18057
fe95c787
MS
18058@kindex maint info sections
18059@item maint info sections
18060Another command that can give you extra information about program sections
18061is @code{maint info sections}. In addition to the section information
18062displayed by @code{info files}, this command displays the flags and file
18063offset of each section in the executable and core dump files. In addition,
18064@code{maint info sections} provides the following command options (which
18065may be arbitrarily combined):
18066
18067@table @code
18068@item ALLOBJ
18069Display sections for all loaded object files, including shared libraries.
18070@item @var{sections}
6600abed 18071Display info only for named @var{sections}.
fe95c787
MS
18072@item @var{section-flags}
18073Display info only for sections for which @var{section-flags} are true.
18074The section flags that @value{GDBN} currently knows about are:
18075@table @code
18076@item ALLOC
18077Section will have space allocated in the process when loaded.
18078Set for all sections except those containing debug information.
18079@item LOAD
18080Section will be loaded from the file into the child process memory.
18081Set for pre-initialized code and data, clear for @code{.bss} sections.
18082@item RELOC
18083Section needs to be relocated before loading.
18084@item READONLY
18085Section cannot be modified by the child process.
18086@item CODE
18087Section contains executable code only.
6600abed 18088@item DATA
fe95c787
MS
18089Section contains data only (no executable code).
18090@item ROM
18091Section will reside in ROM.
18092@item CONSTRUCTOR
18093Section contains data for constructor/destructor lists.
18094@item HAS_CONTENTS
18095Section is not empty.
18096@item NEVER_LOAD
18097An instruction to the linker to not output the section.
18098@item COFF_SHARED_LIBRARY
18099A notification to the linker that the section contains
18100COFF shared library information.
18101@item IS_COMMON
18102Section contains common symbols.
18103@end table
18104@end table
6763aef9 18105@kindex set trust-readonly-sections
9c16f35a 18106@cindex read-only sections
6763aef9
MS
18107@item set trust-readonly-sections on
18108Tell @value{GDBN} that readonly sections in your object file
6ca652b0 18109really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
18110In that case, @value{GDBN} can fetch values from these sections
18111out of the object file, rather than from the target program.
18112For some targets (notably embedded ones), this can be a significant
18113enhancement to debugging performance.
18114
18115The default is off.
18116
18117@item set trust-readonly-sections off
15110bc3 18118Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
18119the contents of the section might change while the program is running,
18120and must therefore be fetched from the target when needed.
9c16f35a
EZ
18121
18122@item show trust-readonly-sections
18123Show the current setting of trusting readonly sections.
c906108c
SS
18124@end table
18125
18126All file-specifying commands allow both absolute and relative file names
18127as arguments. @value{GDBN} always converts the file name to an absolute file
18128name and remembers it that way.
18129
c906108c 18130@cindex shared libraries
9cceb671 18131@anchor{Shared Libraries}
b1236ac3
PA
18132@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
18133Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
18134DSBT (TIC6X) shared libraries.
53a5351d 18135
9cceb671
DJ
18136On MS-Windows @value{GDBN} must be linked with the Expat library to support
18137shared libraries. @xref{Expat}.
18138
c906108c
SS
18139@value{GDBN} automatically loads symbol definitions from shared libraries
18140when you use the @code{run} command, or when you examine a core file.
18141(Before you issue the @code{run} command, @value{GDBN} does not understand
18142references to a function in a shared library, however---unless you are
18143debugging a core file).
53a5351d 18144
c906108c
SS
18145@c FIXME: some @value{GDBN} release may permit some refs to undef
18146@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
18147@c FIXME...lib; check this from time to time when updating manual
18148
b7209cb4
FF
18149There are times, however, when you may wish to not automatically load
18150symbol definitions from shared libraries, such as when they are
18151particularly large or there are many of them.
18152
18153To control the automatic loading of shared library symbols, use the
18154commands:
18155
18156@table @code
18157@kindex set auto-solib-add
18158@item set auto-solib-add @var{mode}
18159If @var{mode} is @code{on}, symbols from all shared object libraries
18160will be loaded automatically when the inferior begins execution, you
18161attach to an independently started inferior, or when the dynamic linker
18162informs @value{GDBN} that a new library has been loaded. If @var{mode}
18163is @code{off}, symbols must be loaded manually, using the
18164@code{sharedlibrary} command. The default value is @code{on}.
18165
dcaf7c2c
EZ
18166@cindex memory used for symbol tables
18167If your program uses lots of shared libraries with debug info that
18168takes large amounts of memory, you can decrease the @value{GDBN}
18169memory footprint by preventing it from automatically loading the
18170symbols from shared libraries. To that end, type @kbd{set
18171auto-solib-add off} before running the inferior, then load each
18172library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 18173@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
18174the libraries whose symbols you want to be loaded.
18175
b7209cb4
FF
18176@kindex show auto-solib-add
18177@item show auto-solib-add
18178Display the current autoloading mode.
18179@end table
18180
c45da7e6 18181@cindex load shared library
b7209cb4
FF
18182To explicitly load shared library symbols, use the @code{sharedlibrary}
18183command:
18184
c906108c
SS
18185@table @code
18186@kindex info sharedlibrary
18187@kindex info share
55333a84
DE
18188@item info share @var{regex}
18189@itemx info sharedlibrary @var{regex}
18190Print the names of the shared libraries which are currently loaded
18191that match @var{regex}. If @var{regex} is omitted then print
18192all shared libraries that are loaded.
c906108c 18193
b30a0bc3
JB
18194@kindex info dll
18195@item info dll @var{regex}
18196This is an alias of @code{info sharedlibrary}.
18197
c906108c
SS
18198@kindex sharedlibrary
18199@kindex share
18200@item sharedlibrary @var{regex}
18201@itemx share @var{regex}
c906108c
SS
18202Load shared object library symbols for files matching a
18203Unix regular expression.
18204As with files loaded automatically, it only loads shared libraries
18205required by your program for a core file or after typing @code{run}. If
18206@var{regex} is omitted all shared libraries required by your program are
18207loaded.
c45da7e6
EZ
18208
18209@item nosharedlibrary
18210@kindex nosharedlibrary
18211@cindex unload symbols from shared libraries
18212Unload all shared object library symbols. This discards all symbols
18213that have been loaded from all shared libraries. Symbols from shared
18214libraries that were loaded by explicit user requests are not
18215discarded.
c906108c
SS
18216@end table
18217
721c2651 18218Sometimes you may wish that @value{GDBN} stops and gives you control
edcc5120
TT
18219when any of shared library events happen. The best way to do this is
18220to use @code{catch load} and @code{catch unload} (@pxref{Set
18221Catchpoints}).
18222
18223@value{GDBN} also supports the the @code{set stop-on-solib-events}
18224command for this. This command exists for historical reasons. It is
18225less useful than setting a catchpoint, because it does not allow for
18226conditions or commands as a catchpoint does.
721c2651
EZ
18227
18228@table @code
18229@item set stop-on-solib-events
18230@kindex set stop-on-solib-events
18231This command controls whether @value{GDBN} should give you control
18232when the dynamic linker notifies it about some shared library event.
18233The most common event of interest is loading or unloading of a new
18234shared library.
18235
18236@item show stop-on-solib-events
18237@kindex show stop-on-solib-events
18238Show whether @value{GDBN} stops and gives you control when shared
18239library events happen.
18240@end table
18241
f5ebfba0 18242Shared libraries are also supported in many cross or remote debugging
f1838a98
UW
18243configurations. @value{GDBN} needs to have access to the target's libraries;
18244this can be accomplished either by providing copies of the libraries
18245on the host system, or by asking @value{GDBN} to automatically retrieve the
18246libraries from the target. If copies of the target libraries are
18247provided, they need to be the same as the target libraries, although the
f5ebfba0
DJ
18248copies on the target can be stripped as long as the copies on the host are
18249not.
18250
59b7b46f
EZ
18251@cindex where to look for shared libraries
18252For remote debugging, you need to tell @value{GDBN} where the target
18253libraries are, so that it can load the correct copies---otherwise, it
18254may try to load the host's libraries. @value{GDBN} has two variables
18255to specify the search directories for target libraries.
f5ebfba0
DJ
18256
18257@table @code
a9a5a3d1 18258@cindex prefix for executable and shared library file names
f822c95b 18259@cindex system root, alternate
f5ebfba0 18260@kindex set solib-absolute-prefix
f822c95b
DJ
18261@kindex set sysroot
18262@item set sysroot @var{path}
18263Use @var{path} as the system root for the program being debugged. Any
18264absolute shared library paths will be prefixed with @var{path}; many
18265runtime loaders store the absolute paths to the shared library in the
a9a5a3d1
GB
18266target program's memory. When starting processes remotely, and when
18267attaching to already-running processes (local or remote), their
18268executable filenames will be prefixed with @var{path} if reported to
18269@value{GDBN} as absolute by the operating system. If you use
18270@code{set sysroot} to find executables and shared libraries, they need
18271to be laid out in the same way that they are on the target, with
18272e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
18273@var{path}.
f822c95b 18274
599bd15c
GB
18275If @var{path} starts with the sequence @file{target:} and the target
18276system is remote then @value{GDBN} will retrieve the target binaries
18277from the remote system. This is only supported when using a remote
18278target that supports the @code{remote get} command (@pxref{File
18279Transfer,,Sending files to a remote system}). The part of @var{path}
18280following the initial @file{target:} (if present) is used as system
18281root prefix on the remote file system. If @var{path} starts with the
18282sequence @file{remote:} this is converted to the sequence
18283@file{target:} by @code{set sysroot}@footnote{Historically the
18284functionality to retrieve binaries from the remote system was
18285provided by prefixing @var{path} with @file{remote:}}. If you want
18286to specify a local system root using a directory that happens to be
18287named @file{target:} or @file{remote:}, you need to use some
18288equivalent variant of the name like @file{./target:}.
f1838a98 18289
ab38a727
PA
18290For targets with an MS-DOS based filesystem, such as MS-Windows and
18291SymbianOS, @value{GDBN} tries prefixing a few variants of the target
18292absolute file name with @var{path}. But first, on Unix hosts,
18293@value{GDBN} converts all backslash directory separators into forward
18294slashes, because the backslash is not a directory separator on Unix:
18295
18296@smallexample
18297 c:\foo\bar.dll @result{} c:/foo/bar.dll
18298@end smallexample
18299
18300Then, @value{GDBN} attempts prefixing the target file name with
18301@var{path}, and looks for the resulting file name in the host file
18302system:
18303
18304@smallexample
18305 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
18306@end smallexample
18307
a9a5a3d1 18308If that does not find the binary, @value{GDBN} tries removing
ab38a727
PA
18309the @samp{:} character from the drive spec, both for convenience, and,
18310for the case of the host file system not supporting file names with
18311colons:
18312
18313@smallexample
18314 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
18315@end smallexample
18316
18317This makes it possible to have a system root that mirrors a target
18318with more than one drive. E.g., you may want to setup your local
18319copies of the target system shared libraries like so (note @samp{c} vs
18320@samp{z}):
18321
18322@smallexample
18323 @file{/path/to/sysroot/c/sys/bin/foo.dll}
18324 @file{/path/to/sysroot/c/sys/bin/bar.dll}
18325 @file{/path/to/sysroot/z/sys/bin/bar.dll}
18326@end smallexample
18327
18328@noindent
18329and point the system root at @file{/path/to/sysroot}, so that
18330@value{GDBN} can find the correct copies of both
18331@file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
18332
a9a5a3d1 18333If that still does not find the binary, @value{GDBN} tries
ab38a727
PA
18334removing the whole drive spec from the target file name:
18335
18336@smallexample
18337 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
18338@end smallexample
18339
18340This last lookup makes it possible to not care about the drive name,
18341if you don't want or need to.
18342
f822c95b
DJ
18343The @code{set solib-absolute-prefix} command is an alias for @code{set
18344sysroot}.
18345
18346@cindex default system root
59b7b46f 18347@cindex @samp{--with-sysroot}
f822c95b
DJ
18348You can set the default system root by using the configure-time
18349@samp{--with-sysroot} option. If the system root is inside
18350@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
18351@samp{--exec-prefix}), then the default system root will be updated
18352automatically if the installed @value{GDBN} is moved to a new
18353location.
18354
18355@kindex show sysroot
18356@item show sysroot
a9a5a3d1 18357Display the current executable and shared library prefix.
f5ebfba0
DJ
18358
18359@kindex set solib-search-path
18360@item set solib-search-path @var{path}
f822c95b
DJ
18361If this variable is set, @var{path} is a colon-separated list of
18362directories to search for shared libraries. @samp{solib-search-path}
18363is used after @samp{sysroot} fails to locate the library, or if the
18364path to the library is relative instead of absolute. If you want to
18365use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 18366@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 18367finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 18368it to a nonexistent directory may interfere with automatic loading
f822c95b 18369of shared library symbols.
f5ebfba0
DJ
18370
18371@kindex show solib-search-path
18372@item show solib-search-path
18373Display the current shared library search path.
ab38a727
PA
18374
18375@cindex DOS file-name semantics of file names.
18376@kindex set target-file-system-kind (unix|dos-based|auto)
18377@kindex show target-file-system-kind
18378@item set target-file-system-kind @var{kind}
18379Set assumed file system kind for target reported file names.
18380
18381Shared library file names as reported by the target system may not
18382make sense as is on the system @value{GDBN} is running on. For
18383example, when remote debugging a target that has MS-DOS based file
18384system semantics, from a Unix host, the target may be reporting to
18385@value{GDBN} a list of loaded shared libraries with file names such as
18386@file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
18387drive letters, so the @samp{c:\} prefix is not normally understood as
18388indicating an absolute file name, and neither is the backslash
18389normally considered a directory separator character. In that case,
18390the native file system would interpret this whole absolute file name
18391as a relative file name with no directory components. This would make
18392it impossible to point @value{GDBN} at a copy of the remote target's
18393shared libraries on the host using @code{set sysroot}, and impractical
18394with @code{set solib-search-path}. Setting
18395@code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
18396to interpret such file names similarly to how the target would, and to
18397map them to file names valid on @value{GDBN}'s native file system
18398semantics. The value of @var{kind} can be @code{"auto"}, in addition
18399to one of the supported file system kinds. In that case, @value{GDBN}
18400tries to determine the appropriate file system variant based on the
18401current target's operating system (@pxref{ABI, ,Configuring the
18402Current ABI}). The supported file system settings are:
18403
18404@table @code
18405@item unix
18406Instruct @value{GDBN} to assume the target file system is of Unix
18407kind. Only file names starting the forward slash (@samp{/}) character
18408are considered absolute, and the directory separator character is also
18409the forward slash.
18410
18411@item dos-based
18412Instruct @value{GDBN} to assume the target file system is DOS based.
18413File names starting with either a forward slash, or a drive letter
18414followed by a colon (e.g., @samp{c:}), are considered absolute, and
18415both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
18416considered directory separators.
18417
18418@item auto
18419Instruct @value{GDBN} to use the file system kind associated with the
18420target operating system (@pxref{ABI, ,Configuring the Current ABI}).
18421This is the default.
18422@end table
f5ebfba0
DJ
18423@end table
18424
c011a4f4
DE
18425@cindex file name canonicalization
18426@cindex base name differences
18427When processing file names provided by the user, @value{GDBN}
18428frequently needs to compare them to the file names recorded in the
18429program's debug info. Normally, @value{GDBN} compares just the
18430@dfn{base names} of the files as strings, which is reasonably fast
18431even for very large programs. (The base name of a file is the last
18432portion of its name, after stripping all the leading directories.)
18433This shortcut in comparison is based upon the assumption that files
18434cannot have more than one base name. This is usually true, but
18435references to files that use symlinks or similar filesystem
18436facilities violate that assumption. If your program records files
18437using such facilities, or if you provide file names to @value{GDBN}
18438using symlinks etc., you can set @code{basenames-may-differ} to
18439@code{true} to instruct @value{GDBN} to completely canonicalize each
18440pair of file names it needs to compare. This will make file-name
18441comparisons accurate, but at a price of a significant slowdown.
18442
18443@table @code
18444@item set basenames-may-differ
18445@kindex set basenames-may-differ
18446Set whether a source file may have multiple base names.
18447
18448@item show basenames-may-differ
18449@kindex show basenames-may-differ
18450Show whether a source file may have multiple base names.
18451@end table
5b5d99cf 18452
18989b3c
AB
18453@node File Caching
18454@section File Caching
18455@cindex caching of opened files
18456@cindex caching of bfd objects
18457
18458To speed up file loading, and reduce memory usage, @value{GDBN} will
18459reuse the @code{bfd} objects used to track open files. @xref{Top, ,
18460BFD, bfd, The Binary File Descriptor Library}. The following commands
18461allow visibility and control of the caching behavior.
18462
18463@table @code
18464@kindex maint info bfds
18465@item maint info bfds
18466This prints information about each @code{bfd} object that is known to
18467@value{GDBN}.
18468
18469@kindex maint set bfd-sharing
18470@kindex maint show bfd-sharing
18471@kindex bfd caching
18472@item maint set bfd-sharing
18473@item maint show bfd-sharing
18474Control whether @code{bfd} objects can be shared. When sharing is
18475enabled @value{GDBN} reuses already open @code{bfd} objects rather
18476than reopening the same file. Turning sharing off does not cause
18477already shared @code{bfd} objects to be unshared, but all future files
18478that are opened will create a new @code{bfd} object. Similarly,
18479re-enabling sharing does not cause multiple existing @code{bfd}
18480objects to be collapsed into a single shared @code{bfd} object.
566f5e3b
AB
18481
18482@kindex set debug bfd-cache @var{level}
18483@kindex bfd caching
18484@item set debug bfd-cache @var{level}
18485Turns on debugging of the bfd cache, setting the level to @var{level}.
18486
18487@kindex show debug bfd-cache
18488@kindex bfd caching
18489@item show debug bfd-cache
18490Show the current debugging level of the bfd cache.
18989b3c
AB
18491@end table
18492
5b5d99cf
JB
18493@node Separate Debug Files
18494@section Debugging Information in Separate Files
18495@cindex separate debugging information files
18496@cindex debugging information in separate files
18497@cindex @file{.debug} subdirectories
18498@cindex debugging information directory, global
f307c045 18499@cindex global debugging information directories
c7e83d54
EZ
18500@cindex build ID, and separate debugging files
18501@cindex @file{.build-id} directory
5b5d99cf
JB
18502
18503@value{GDBN} allows you to put a program's debugging information in a
18504file separate from the executable itself, in a way that allows
18505@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
18506Since debugging information can be very large---sometimes larger
18507than the executable code itself---some systems distribute debugging
5b5d99cf
JB
18508information for their executables in separate files, which users can
18509install only when they need to debug a problem.
18510
c7e83d54
EZ
18511@value{GDBN} supports two ways of specifying the separate debug info
18512file:
5b5d99cf
JB
18513
18514@itemize @bullet
18515@item
c7e83d54
EZ
18516The executable contains a @dfn{debug link} that specifies the name of
18517the separate debug info file. The separate debug file's name is
18518usually @file{@var{executable}.debug}, where @var{executable} is the
18519name of the corresponding executable file without leading directories
18520(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
99e008fe
EZ
18521debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
18522checksum for the debug file, which @value{GDBN} uses to validate that
18523the executable and the debug file came from the same build.
c7e83d54
EZ
18524
18525@item
7e27a47a 18526The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 18527also present in the corresponding debug info file. (This is supported
c74f7d1c 18528only on some operating systems, when using the ELF or PE file formats
7e27a47a
EZ
18529for binary files and the @sc{gnu} Binutils.) For more details about
18530this feature, see the description of the @option{--build-id}
18531command-line option in @ref{Options, , Command Line Options, ld.info,
18532The GNU Linker}. The debug info file's name is not specified
18533explicitly by the build ID, but can be computed from the build ID, see
18534below.
d3750b24
JK
18535@end itemize
18536
c7e83d54
EZ
18537Depending on the way the debug info file is specified, @value{GDBN}
18538uses two different methods of looking for the debug file:
d3750b24
JK
18539
18540@itemize @bullet
18541@item
c7e83d54
EZ
18542For the ``debug link'' method, @value{GDBN} looks up the named file in
18543the directory of the executable file, then in a subdirectory of that
f307c045
JK
18544directory named @file{.debug}, and finally under each one of the global debug
18545directories, in a subdirectory whose name is identical to the leading
c7e83d54
EZ
18546directories of the executable's absolute file name.
18547
18548@item
83f83d7f 18549For the ``build ID'' method, @value{GDBN} looks in the
f307c045
JK
18550@file{.build-id} subdirectory of each one of the global debug directories for
18551a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
18552first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
18553are the rest of the bit string. (Real build ID strings are 32 or more
18554hex characters, not 10.)
c7e83d54
EZ
18555@end itemize
18556
18557So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
18558@file{/usr/bin/ls}, which has a debug link that specifies the
18559file @file{ls.debug}, and a build ID whose value in hex is
f307c045 18560@code{abcdef1234}. If the list of the global debug directories includes
c7e83d54
EZ
18561@file{/usr/lib/debug}, then @value{GDBN} will look for the following
18562debug information files, in the indicated order:
18563
18564@itemize @minus
18565@item
18566@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 18567@item
c7e83d54 18568@file{/usr/bin/ls.debug}
5b5d99cf 18569@item
c7e83d54 18570@file{/usr/bin/.debug/ls.debug}
5b5d99cf 18571@item
c7e83d54 18572@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 18573@end itemize
5b5d99cf 18574
1564a261
JK
18575@anchor{debug-file-directory}
18576Global debugging info directories default to what is set by @value{GDBN}
18577configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
18578you can also set the global debugging info directories, and view the list
18579@value{GDBN} is currently using.
5b5d99cf
JB
18580
18581@table @code
18582
18583@kindex set debug-file-directory
24ddea62
JK
18584@item set debug-file-directory @var{directories}
18585Set the directories which @value{GDBN} searches for separate debugging
d9242c17
JK
18586information files to @var{directory}. Multiple path components can be set
18587concatenating them by a path separator.
5b5d99cf
JB
18588
18589@kindex show debug-file-directory
18590@item show debug-file-directory
24ddea62 18591Show the directories @value{GDBN} searches for separate debugging
5b5d99cf
JB
18592information files.
18593
18594@end table
18595
18596@cindex @code{.gnu_debuglink} sections
c7e83d54 18597@cindex debug link sections
5b5d99cf
JB
18598A debug link is a special section of the executable file named
18599@code{.gnu_debuglink}. The section must contain:
18600
18601@itemize
18602@item
18603A filename, with any leading directory components removed, followed by
18604a zero byte,
18605@item
18606zero to three bytes of padding, as needed to reach the next four-byte
18607boundary within the section, and
18608@item
18609a four-byte CRC checksum, stored in the same endianness used for the
18610executable file itself. The checksum is computed on the debugging
18611information file's full contents by the function given below, passing
18612zero as the @var{crc} argument.
18613@end itemize
18614
18615Any executable file format can carry a debug link, as long as it can
18616contain a section named @code{.gnu_debuglink} with the contents
18617described above.
18618
d3750b24 18619@cindex @code{.note.gnu.build-id} sections
c7e83d54 18620@cindex build ID sections
7e27a47a
EZ
18621The build ID is a special section in the executable file (and in other
18622ELF binary files that @value{GDBN} may consider). This section is
18623often named @code{.note.gnu.build-id}, but that name is not mandatory.
18624It contains unique identification for the built files---the ID remains
18625the same across multiple builds of the same build tree. The default
18626algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
18627content for the build ID string. The same section with an identical
18628value is present in the original built binary with symbols, in its
18629stripped variant, and in the separate debugging information file.
d3750b24 18630
5b5d99cf
JB
18631The debugging information file itself should be an ordinary
18632executable, containing a full set of linker symbols, sections, and
18633debugging information. The sections of the debugging information file
c7e83d54
EZ
18634should have the same names, addresses, and sizes as the original file,
18635but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
18636in an ordinary executable.
18637
7e27a47a 18638The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
18639@samp{objcopy} utility that can produce
18640the separated executable / debugging information file pairs using the
18641following commands:
18642
18643@smallexample
18644@kbd{objcopy --only-keep-debug foo foo.debug}
18645@kbd{strip -g foo}
c7e83d54
EZ
18646@end smallexample
18647
18648@noindent
18649These commands remove the debugging
83f83d7f
JK
18650information from the executable file @file{foo} and place it in the file
18651@file{foo.debug}. You can use the first, second or both methods to link the
18652two files:
18653
18654@itemize @bullet
18655@item
18656The debug link method needs the following additional command to also leave
18657behind a debug link in @file{foo}:
18658
18659@smallexample
18660@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
18661@end smallexample
18662
18663Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 18664a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
18665foo.debug} has the same functionality as the two @code{objcopy} commands and
18666the @code{ln -s} command above, together.
18667
18668@item
18669Build ID gets embedded into the main executable using @code{ld --build-id} or
18670the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
18671compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 18672utilities (Binutils) package since version 2.18.
83f83d7f
JK
18673@end itemize
18674
18675@noindent
d3750b24 18676
99e008fe
EZ
18677@cindex CRC algorithm definition
18678The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
18679IEEE 802.3 using the polynomial:
18680
18681@c TexInfo requires naked braces for multi-digit exponents for Tex
18682@c output, but this causes HTML output to barf. HTML has to be set using
18683@c raw commands. So we end up having to specify this equation in 2
18684@c different ways!
18685@ifhtml
18686@display
18687@html
18688 <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>
18689 + <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
18690@end html
18691@end display
18692@end ifhtml
18693@ifnothtml
18694@display
18695 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
18696 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
18697@end display
18698@end ifnothtml
18699
18700The function is computed byte at a time, taking the least
18701significant bit of each byte first. The initial pattern
18702@code{0xffffffff} is used, to ensure leading zeros affect the CRC and
18703the final result is inverted to ensure trailing zeros also affect the
18704CRC.
18705
18706@emph{Note:} This is the same CRC polynomial as used in handling the
936d2992
PA
18707@dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
18708However in the case of the Remote Serial Protocol, the CRC is computed
18709@emph{most} significant bit first, and the result is not inverted, so
18710trailing zeros have no effect on the CRC value.
99e008fe
EZ
18711
18712To complete the description, we show below the code of the function
18713which produces the CRC used in @code{.gnu_debuglink}. Inverting the
18714initially supplied @code{crc} argument means that an initial call to
18715this function passing in zero will start computing the CRC using
18716@code{0xffffffff}.
5b5d99cf 18717
4644b6e3 18718@kindex gnu_debuglink_crc32
5b5d99cf
JB
18719@smallexample
18720unsigned long
18721gnu_debuglink_crc32 (unsigned long crc,
18722 unsigned char *buf, size_t len)
18723@{
18724 static const unsigned long crc32_table[256] =
18725 @{
18726 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
18727 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
18728 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
18729 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
18730 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
18731 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
18732 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
18733 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
18734 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
18735 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
18736 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
18737 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
18738 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
18739 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
18740 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
18741 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
18742 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
18743 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
18744 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
18745 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
18746 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
18747 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
18748 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
18749 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
18750 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
18751 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
18752 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
18753 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
18754 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
18755 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
18756 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
18757 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
18758 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
18759 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
18760 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
18761 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
18762 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
18763 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
18764 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
18765 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
18766 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
18767 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
18768 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
18769 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
18770 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
18771 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
18772 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
18773 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
18774 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
18775 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
18776 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
18777 0x2d02ef8d
18778 @};
18779 unsigned char *end;
18780
18781 crc = ~crc & 0xffffffff;
18782 for (end = buf + len; buf < end; ++buf)
18783 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 18784 return ~crc & 0xffffffff;
5b5d99cf
JB
18785@}
18786@end smallexample
18787
c7e83d54
EZ
18788@noindent
18789This computation does not apply to the ``build ID'' method.
18790
608e2dbb
TT
18791@node MiniDebugInfo
18792@section Debugging information in a special section
18793@cindex separate debug sections
18794@cindex @samp{.gnu_debugdata} section
18795
18796Some systems ship pre-built executables and libraries that have a
18797special @samp{.gnu_debugdata} section. This feature is called
18798@dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
18799is used to supply extra symbols for backtraces.
18800
18801The intent of this section is to provide extra minimal debugging
18802information for use in simple backtraces. It is not intended to be a
18803replacement for full separate debugging information (@pxref{Separate
18804Debug Files}). The example below shows the intended use; however,
18805@value{GDBN} does not currently put restrictions on what sort of
18806debugging information might be included in the section.
18807
18808@value{GDBN} has support for this extension. If the section exists,
18809then it is used provided that no other source of debugging information
18810can be found, and that @value{GDBN} was configured with LZMA support.
18811
18812This section can be easily created using @command{objcopy} and other
18813standard utilities:
18814
18815@smallexample
18816# Extract the dynamic symbols from the main binary, there is no need
5423b017 18817# to also have these in the normal symbol table.
608e2dbb
TT
18818nm -D @var{binary} --format=posix --defined-only \
18819 | awk '@{ print $1 @}' | sort > dynsyms
18820
5423b017 18821# Extract all the text (i.e. function) symbols from the debuginfo.
1d236d23
JK
18822# (Note that we actually also accept "D" symbols, for the benefit
18823# of platforms like PowerPC64 that use function descriptors.)
608e2dbb 18824nm @var{binary} --format=posix --defined-only \
1d236d23 18825 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
608e2dbb
TT
18826 | sort > funcsyms
18827
18828# Keep all the function symbols not already in the dynamic symbol
18829# table.
18830comm -13 dynsyms funcsyms > keep_symbols
18831
edf9f00c
JK
18832# Separate full debug info into debug binary.
18833objcopy --only-keep-debug @var{binary} debug
18834
608e2dbb
TT
18835# Copy the full debuginfo, keeping only a minimal set of symbols and
18836# removing some unnecessary sections.
18837objcopy -S --remove-section .gdb_index --remove-section .comment \
edf9f00c
JK
18838 --keep-symbols=keep_symbols debug mini_debuginfo
18839
18840# Drop the full debug info from the original binary.
18841strip --strip-all -R .comment @var{binary}
608e2dbb
TT
18842
18843# Inject the compressed data into the .gnu_debugdata section of the
18844# original binary.
18845xz mini_debuginfo
18846objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
18847@end smallexample
5b5d99cf 18848
9291a0cd
TT
18849@node Index Files
18850@section Index Files Speed Up @value{GDBN}
18851@cindex index files
18852@cindex @samp{.gdb_index} section
18853
18854When @value{GDBN} finds a symbol file, it scans the symbols in the
18855file in order to construct an internal symbol table. This lets most
18856@value{GDBN} operations work quickly---at the cost of a delay early
18857on. For large programs, this delay can be quite lengthy, so
18858@value{GDBN} provides a way to build an index, which speeds up
18859startup.
18860
18861The index is stored as a section in the symbol file. @value{GDBN} can
18862write the index to a file, then you can put it into the symbol file
18863using @command{objcopy}.
18864
18865To create an index file, use the @code{save gdb-index} command:
18866
18867@table @code
18868@item save gdb-index @var{directory}
18869@kindex save gdb-index
18870Create an index file for each symbol file currently known by
18871@value{GDBN}. Each file is named after its corresponding symbol file,
18872with @samp{.gdb-index} appended, and is written into the given
18873@var{directory}.
18874@end table
18875
18876Once you have created an index file you can merge it into your symbol
18877file, here named @file{symfile}, using @command{objcopy}:
18878
18879@smallexample
18880$ objcopy --add-section .gdb_index=symfile.gdb-index \
18881 --set-section-flags .gdb_index=readonly symfile symfile
18882@end smallexample
18883
e615022a
DE
18884@value{GDBN} will normally ignore older versions of @file{.gdb_index}
18885sections that have been deprecated. Usually they are deprecated because
18886they are missing a new feature or have performance issues.
18887To tell @value{GDBN} to use a deprecated index section anyway
18888specify @code{set use-deprecated-index-sections on}.
18889The default is @code{off}.
18890This can speed up startup, but may result in some functionality being lost.
18891@xref{Index Section Format}.
18892
18893@emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
18894must be done before gdb reads the file. The following will not work:
18895
18896@smallexample
18897$ gdb -ex "set use-deprecated-index-sections on" <program>
18898@end smallexample
18899
18900Instead you must do, for example,
18901
18902@smallexample
18903$ gdb -iex "set use-deprecated-index-sections on" <program>
18904@end smallexample
18905
9291a0cd
TT
18906There are currently some limitation on indices. They only work when
18907for DWARF debugging information, not stabs. And, they do not
18908currently work for programs using Ada.
18909
6d2ebf8b 18910@node Symbol Errors
79a6e687 18911@section Errors Reading Symbol Files
c906108c
SS
18912
18913While reading a symbol file, @value{GDBN} occasionally encounters problems,
18914such as symbol types it does not recognize, or known bugs in compiler
18915output. By default, @value{GDBN} does not notify you of such problems, since
18916they are relatively common and primarily of interest to people
18917debugging compilers. If you are interested in seeing information
18918about ill-constructed symbol tables, you can either ask @value{GDBN} to print
18919only one message about each such type of problem, no matter how many
18920times the problem occurs; or you can ask @value{GDBN} to print more messages,
18921to see how many times the problems occur, with the @code{set
79a6e687
BW
18922complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
18923Messages}).
c906108c
SS
18924
18925The messages currently printed, and their meanings, include:
18926
18927@table @code
18928@item inner block not inside outer block in @var{symbol}
18929
18930The symbol information shows where symbol scopes begin and end
18931(such as at the start of a function or a block of statements). This
18932error indicates that an inner scope block is not fully contained
18933in its outer scope blocks.
18934
18935@value{GDBN} circumvents the problem by treating the inner block as if it had
18936the same scope as the outer block. In the error message, @var{symbol}
18937may be shown as ``@code{(don't know)}'' if the outer block is not a
18938function.
18939
18940@item block at @var{address} out of order
18941
18942The symbol information for symbol scope blocks should occur in
18943order of increasing addresses. This error indicates that it does not
18944do so.
18945
18946@value{GDBN} does not circumvent this problem, and has trouble
18947locating symbols in the source file whose symbols it is reading. (You
18948can often determine what source file is affected by specifying
79a6e687
BW
18949@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
18950Messages}.)
c906108c
SS
18951
18952@item bad block start address patched
18953
18954The symbol information for a symbol scope block has a start address
18955smaller than the address of the preceding source line. This is known
18956to occur in the SunOS 4.1.1 (and earlier) C compiler.
18957
18958@value{GDBN} circumvents the problem by treating the symbol scope block as
18959starting on the previous source line.
18960
18961@item bad string table offset in symbol @var{n}
18962
18963@cindex foo
18964Symbol number @var{n} contains a pointer into the string table which is
18965larger than the size of the string table.
18966
18967@value{GDBN} circumvents the problem by considering the symbol to have the
18968name @code{foo}, which may cause other problems if many symbols end up
18969with this name.
18970
18971@item unknown symbol type @code{0x@var{nn}}
18972
7a292a7a
SS
18973The symbol information contains new data types that @value{GDBN} does
18974not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 18975uncomprehended information, in hexadecimal.
c906108c 18976
7a292a7a
SS
18977@value{GDBN} circumvents the error by ignoring this symbol information.
18978This usually allows you to debug your program, though certain symbols
c906108c 18979are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
18980debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
18981on @code{complain}, then go up to the function @code{read_dbx_symtab}
18982and examine @code{*bufp} to see the symbol.
c906108c
SS
18983
18984@item stub type has NULL name
c906108c 18985
7a292a7a 18986@value{GDBN} could not find the full definition for a struct or class.
c906108c 18987
7a292a7a 18988@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 18989The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
18990information that recent versions of the compiler should have output for
18991it.
c906108c
SS
18992
18993@item info mismatch between compiler and debugger
18994
18995@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 18996
c906108c
SS
18997@end table
18998
b14b1491
TT
18999@node Data Files
19000@section GDB Data Files
19001
19002@cindex prefix for data files
19003@value{GDBN} will sometimes read an auxiliary data file. These files
19004are kept in a directory known as the @dfn{data directory}.
19005
19006You can set the data directory's name, and view the name @value{GDBN}
19007is currently using.
19008
19009@table @code
19010@kindex set data-directory
19011@item set data-directory @var{directory}
19012Set the directory which @value{GDBN} searches for auxiliary data files
19013to @var{directory}.
19014
19015@kindex show data-directory
19016@item show data-directory
19017Show the directory @value{GDBN} searches for auxiliary data files.
19018@end table
19019
19020@cindex default data directory
19021@cindex @samp{--with-gdb-datadir}
19022You can set the default data directory by using the configure-time
19023@samp{--with-gdb-datadir} option. If the data directory is inside
19024@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
19025@samp{--exec-prefix}), then the default data directory will be updated
19026automatically if the installed @value{GDBN} is moved to a new
19027location.
19028
aae1c79a
DE
19029The data directory may also be specified with the
19030@code{--data-directory} command line option.
19031@xref{Mode Options}.
19032
6d2ebf8b 19033@node Targets
c906108c 19034@chapter Specifying a Debugging Target
7a292a7a 19035
c906108c 19036@cindex debugging target
c906108c 19037A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
19038
19039Often, @value{GDBN} runs in the same host environment as your program;
19040in that case, the debugging target is specified as a side effect when
19041you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
19042flexibility---for example, running @value{GDBN} on a physically separate
19043host, or controlling a standalone system over a serial port or a
53a5351d
JM
19044realtime system over a TCP/IP connection---you can use the @code{target}
19045command to specify one of the target types configured for @value{GDBN}
79a6e687 19046(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 19047
a8f24a35
EZ
19048@cindex target architecture
19049It is possible to build @value{GDBN} for several different @dfn{target
19050architectures}. When @value{GDBN} is built like that, you can choose
19051one of the available architectures with the @kbd{set architecture}
19052command.
19053
19054@table @code
19055@kindex set architecture
19056@kindex show architecture
19057@item set architecture @var{arch}
19058This command sets the current target architecture to @var{arch}. The
19059value of @var{arch} can be @code{"auto"}, in addition to one of the
19060supported architectures.
19061
19062@item show architecture
19063Show the current target architecture.
9c16f35a
EZ
19064
19065@item set processor
19066@itemx processor
19067@kindex set processor
19068@kindex show processor
19069These are alias commands for, respectively, @code{set architecture}
19070and @code{show architecture}.
a8f24a35
EZ
19071@end table
19072
c906108c
SS
19073@menu
19074* Active Targets:: Active targets
19075* Target Commands:: Commands for managing targets
c906108c 19076* Byte Order:: Choosing target byte order
c906108c
SS
19077@end menu
19078
6d2ebf8b 19079@node Active Targets
79a6e687 19080@section Active Targets
7a292a7a 19081
c906108c
SS
19082@cindex stacking targets
19083@cindex active targets
19084@cindex multiple targets
19085
8ea5bce5 19086There are multiple classes of targets such as: processes, executable files or
c0edd9ed
JK
19087recording sessions. Core files belong to the process class, making core file
19088and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
19089on multiple active targets, one in each class. This allows you to (for
19090example) start a process and inspect its activity, while still having access to
19091the executable file after the process finishes. Or if you start process
19092recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
19093presented a virtual layer of the recording target, while the process target
19094remains stopped at the chronologically last point of the process execution.
19095
19096Use the @code{core-file} and @code{exec-file} commands to select a new core
19097file or executable target (@pxref{Files, ,Commands to Specify Files}). To
19098specify as a target a process that is already running, use the @code{attach}
19099command (@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 19100
6d2ebf8b 19101@node Target Commands
79a6e687 19102@section Commands for Managing Targets
c906108c
SS
19103
19104@table @code
19105@item target @var{type} @var{parameters}
7a292a7a
SS
19106Connects the @value{GDBN} host environment to a target machine or
19107process. A target is typically a protocol for talking to debugging
19108facilities. You use the argument @var{type} to specify the type or
19109protocol of the target machine.
c906108c
SS
19110
19111Further @var{parameters} are interpreted by the target protocol, but
19112typically include things like device names or host names to connect
19113with, process numbers, and baud rates.
c906108c
SS
19114
19115The @code{target} command does not repeat if you press @key{RET} again
19116after executing the command.
19117
19118@kindex help target
19119@item help target
19120Displays the names of all targets available. To display targets
19121currently selected, use either @code{info target} or @code{info files}
79a6e687 19122(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
19123
19124@item help target @var{name}
19125Describe a particular target, including any parameters necessary to
19126select it.
19127
19128@kindex set gnutarget
19129@item set gnutarget @var{args}
5d161b24 19130@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 19131knows whether it is reading an @dfn{executable},
5d161b24
DB
19132a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
19133with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
19134with @code{gnutarget} the @code{target} refers to a program, not a machine.
19135
d4f3574e 19136@quotation
c906108c
SS
19137@emph{Warning:} To specify a file format with @code{set gnutarget},
19138you must know the actual BFD name.
d4f3574e 19139@end quotation
c906108c 19140
d4f3574e 19141@noindent
79a6e687 19142@xref{Files, , Commands to Specify Files}.
c906108c 19143
5d161b24 19144@kindex show gnutarget
c906108c
SS
19145@item show gnutarget
19146Use the @code{show gnutarget} command to display what file format
19147@code{gnutarget} is set to read. If you have not set @code{gnutarget},
19148@value{GDBN} will determine the file format for each file automatically,
c4957902 19149and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
c906108c
SS
19150@end table
19151
4644b6e3 19152@cindex common targets
c906108c
SS
19153Here are some common targets (available, or not, depending on the GDB
19154configuration):
c906108c
SS
19155
19156@table @code
4644b6e3 19157@kindex target
c906108c 19158@item target exec @var{program}
4644b6e3 19159@cindex executable file target
c906108c
SS
19160An executable file. @samp{target exec @var{program}} is the same as
19161@samp{exec-file @var{program}}.
19162
c906108c 19163@item target core @var{filename}
4644b6e3 19164@cindex core dump file target
c906108c
SS
19165A core dump file. @samp{target core @var{filename}} is the same as
19166@samp{core-file @var{filename}}.
c906108c 19167
1a10341b 19168@item target remote @var{medium}
4644b6e3 19169@cindex remote target
1a10341b
JB
19170A remote system connected to @value{GDBN} via a serial line or network
19171connection. This command tells @value{GDBN} to use its own remote
19172protocol over @var{medium} for debugging. @xref{Remote Debugging}.
19173
19174For example, if you have a board connected to @file{/dev/ttya} on the
19175machine running @value{GDBN}, you could say:
19176
19177@smallexample
19178target remote /dev/ttya
19179@end smallexample
19180
19181@code{target remote} supports the @code{load} command. This is only
19182useful if you have some other way of getting the stub to the target
19183system, and you can put it somewhere in memory where it won't get
19184clobbered by the download.
c906108c 19185
ee8e71d4 19186@item target sim @r{[}@var{simargs}@r{]} @dots{}
4644b6e3 19187@cindex built-in simulator target
2df3850c 19188Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 19189In general,
474c8240 19190@smallexample
104c1213
JM
19191 target sim
19192 load
19193 run
474c8240 19194@end smallexample
d4f3574e 19195@noindent
104c1213 19196works; however, you cannot assume that a specific memory map, device
d4f3574e 19197drivers, or even basic I/O is available, although some simulators do
104c1213
JM
19198provide these. For info about any processor-specific simulator details,
19199see the appropriate section in @ref{Embedded Processors, ,Embedded
19200Processors}.
19201
6a3cb8e8
PA
19202@item target native
19203@cindex native target
19204Setup for local/native process debugging. Useful to make the
19205@code{run} command spawn native processes (likewise @code{attach},
19206etc.@:) even when @code{set auto-connect-native-target} is @code{off}
19207(@pxref{set auto-connect-native-target}).
19208
c906108c
SS
19209@end table
19210
5d161b24 19211Different targets are available on different configurations of @value{GDBN};
c906108c 19212your configuration may have more or fewer targets.
c906108c 19213
721c2651
EZ
19214Many remote targets require you to download the executable's code once
19215you've successfully established a connection. You may wish to control
3d00d119
DJ
19216various aspects of this process.
19217
19218@table @code
721c2651
EZ
19219
19220@item set hash
19221@kindex set hash@r{, for remote monitors}
19222@cindex hash mark while downloading
19223This command controls whether a hash mark @samp{#} is displayed while
19224downloading a file to the remote monitor. If on, a hash mark is
19225displayed after each S-record is successfully downloaded to the
19226monitor.
19227
19228@item show hash
19229@kindex show hash@r{, for remote monitors}
19230Show the current status of displaying the hash mark.
19231
19232@item set debug monitor
19233@kindex set debug monitor
19234@cindex display remote monitor communications
19235Enable or disable display of communications messages between
19236@value{GDBN} and the remote monitor.
19237
19238@item show debug monitor
19239@kindex show debug monitor
19240Show the current status of displaying communications between
19241@value{GDBN} and the remote monitor.
a8f24a35 19242@end table
c906108c
SS
19243
19244@table @code
19245
19246@kindex load @var{filename}
19247@item load @var{filename}
8edfe269 19248@anchor{load}
c906108c
SS
19249Depending on what remote debugging facilities are configured into
19250@value{GDBN}, the @code{load} command may be available. Where it exists, it
19251is meant to make @var{filename} (an executable) available for debugging
19252on the remote system---by downloading, or dynamic linking, for example.
19253@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
19254the @code{add-symbol-file} command.
19255
19256If your @value{GDBN} does not have a @code{load} command, attempting to
19257execute it gets the error message ``@code{You can't do that when your
19258target is @dots{}}''
c906108c
SS
19259
19260The file is loaded at whatever address is specified in the executable.
19261For some object file formats, you can specify the load address when you
19262link the program; for other formats, like a.out, the object file format
19263specifies a fixed address.
19264@c FIXME! This would be a good place for an xref to the GNU linker doc.
19265
68437a39
DJ
19266Depending on the remote side capabilities, @value{GDBN} may be able to
19267load programs into flash memory.
19268
c906108c
SS
19269@code{load} does not repeat if you press @key{RET} again after using it.
19270@end table
19271
6d2ebf8b 19272@node Byte Order
79a6e687 19273@section Choosing Target Byte Order
7a292a7a 19274
c906108c
SS
19275@cindex choosing target byte order
19276@cindex target byte order
c906108c 19277
eb17f351 19278Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
c906108c
SS
19279offer the ability to run either big-endian or little-endian byte
19280orders. Usually the executable or symbol will include a bit to
19281designate the endian-ness, and you will not need to worry about
19282which to use. However, you may still find it useful to adjust
d4f3574e 19283@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
19284
19285@table @code
4644b6e3 19286@kindex set endian
c906108c
SS
19287@item set endian big
19288Instruct @value{GDBN} to assume the target is big-endian.
19289
c906108c
SS
19290@item set endian little
19291Instruct @value{GDBN} to assume the target is little-endian.
19292
c906108c
SS
19293@item set endian auto
19294Instruct @value{GDBN} to use the byte order associated with the
19295executable.
19296
19297@item show endian
19298Display @value{GDBN}'s current idea of the target byte order.
19299
19300@end table
19301
19302Note that these commands merely adjust interpretation of symbolic
19303data on the host, and that they have absolutely no effect on the
19304target system.
19305
ea35711c
DJ
19306
19307@node Remote Debugging
19308@chapter Debugging Remote Programs
c906108c
SS
19309@cindex remote debugging
19310
19311If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
19312@value{GDBN} in the usual way, it is often useful to use remote debugging.
19313For example, you might use remote debugging on an operating system kernel,
c906108c
SS
19314or on a small system which does not have a general purpose operating system
19315powerful enough to run a full-featured debugger.
19316
19317Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
19318to make this work with particular debugging targets. In addition,
5d161b24 19319@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
19320but not specific to any particular target system) which you can use if you
19321write the remote stubs---the code that runs on the remote system to
19322communicate with @value{GDBN}.
19323
19324Other remote targets may be available in your
19325configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 19326
6b2f586d 19327@menu
07f31aa6 19328* Connecting:: Connecting to a remote target
a6b151f1 19329* File Transfer:: Sending files to a remote system
6b2f586d 19330* Server:: Using the gdbserver program
79a6e687
BW
19331* Remote Configuration:: Remote configuration
19332* Remote Stub:: Implementing a remote stub
6b2f586d
AC
19333@end menu
19334
07f31aa6 19335@node Connecting
79a6e687 19336@section Connecting to a Remote Target
19d9d4ef
DB
19337@cindex remote debugging, connecting
19338@cindex @code{gdbserver}, connecting
19339@cindex remote debugging, types of connections
19340@cindex @code{gdbserver}, types of connections
19341@cindex @code{gdbserver}, @code{target remote} mode
19342@cindex @code{gdbserver}, @code{target extended-remote} mode
19343
19344This section describes how to connect to a remote target, including the
19345types of connections and their differences, how to set up executable and
19346symbol files on the host and target, and the commands used for
19347connecting to and disconnecting from the remote target.
19348
19349@subsection Types of Remote Connections
19350
19351@value{GDBN} supports two types of remote connections, @code{target remote}
19352mode and @code{target extended-remote} mode. Note that many remote targets
19353support only @code{target remote} mode. There are several major
19354differences between the two types of connections, enumerated here:
19355
19356@table @asis
19357
19358@cindex remote debugging, detach and program exit
19359@item Result of detach or program exit
19360@strong{With target remote mode:} When the debugged program exits or you
19361detach from it, @value{GDBN} disconnects from the target. When using
19362@code{gdbserver}, @code{gdbserver} will exit.
19363
19364@strong{With target extended-remote mode:} When the debugged program exits or
19365you detach from it, @value{GDBN} remains connected to the target, even
19366though no program is running. You can rerun the program, attach to a
19367running program, or use @code{monitor} commands specific to the target.
19368
19369When using @code{gdbserver} in this case, it does not exit unless it was
19370invoked using the @option{--once} option. If the @option{--once} option
19371was not used, you can ask @code{gdbserver} to exit using the
19372@code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
19373
19374@item Specifying the program to debug
19375For both connection types you use the @code{file} command to specify the
19376program on the host system. If you are using @code{gdbserver} there are
19377some differences in how to specify the location of the program on the
19378target.
19379
19380@strong{With target remote mode:} You must either specify the program to debug
19381on the @code{gdbserver} command line or use the @option{--attach} option
19382(@pxref{Attaching to a program,,Attaching to a Running Program}).
19383
19384@cindex @option{--multi}, @code{gdbserver} option
19385@strong{With target extended-remote mode:} You may specify the program to debug
19386on the @code{gdbserver} command line, or you can load the program or attach
19387to it using @value{GDBN} commands after connecting to @code{gdbserver}.
19388
19389@anchor{--multi Option in Types of Remote Connnections}
19390You can start @code{gdbserver} without supplying an initial command to run
19391or process ID to attach. To do this, use the @option{--multi} command line
19392option. Then you can connect using @code{target extended-remote} and start
19393the program you want to debug (see below for details on using the
19394@code{run} command in this scenario). Note that the conditions under which
19395@code{gdbserver} terminates depend on how @value{GDBN} connects to it
19396(@code{target remote} or @code{target extended-remote}). The
19397@option{--multi} option to @code{gdbserver} has no influence on that.
07f31aa6 19398
19d9d4ef
DB
19399@item The @code{run} command
19400@strong{With target remote mode:} The @code{run} command is not
19401supported. Once a connection has been established, you can use all
19402the usual @value{GDBN} commands to examine and change data. The
19403remote program is already running, so you can use commands like
19404@kbd{step} and @kbd{continue}.
19405
19406@strong{With target extended-remote mode:} The @code{run} command is
19407supported. The @code{run} command uses the value set by
19408@code{set remote exec-file} (@pxref{set remote exec-file}) to select
19409the program to run. Command line arguments are supported, except for
19410wildcard expansion and I/O redirection (@pxref{Arguments}).
19411
19412If you specify the program to debug on the command line, then the
19413@code{run} command is not required to start execution, and you can
19414resume using commands like @kbd{step} and @kbd{continue} as with
19415@code{target remote} mode.
19416
19417@anchor{Attaching in Types of Remote Connections}
19418@item Attaching
19419@strong{With target remote mode:} The @value{GDBN} command @code{attach} is
19420not supported. To attach to a running program using @code{gdbserver}, you
19421must use the @option{--attach} option (@pxref{Running gdbserver}).
19422
19423@strong{With target extended-remote mode:} To attach to a running program,
19424you may use the @code{attach} command after the connection has been
19425established. If you are using @code{gdbserver}, you may also invoke
19426@code{gdbserver} using the @option{--attach} option
19427(@pxref{Running gdbserver}).
19428
19429@end table
19430
19431@anchor{Host and target files}
19432@subsection Host and Target Files
19433@cindex remote debugging, symbol files
19434@cindex symbol files, remote debugging
19435
19436@value{GDBN}, running on the host, needs access to symbol and debugging
19437information for your program running on the target. This requires
19438access to an unstripped copy of your program, and possibly any associated
19439symbol files. Note that this section applies equally to both @code{target
19440remote} mode and @code{target extended-remote} mode.
19441
19442Some remote targets (@pxref{qXfer executable filename read}, and
19443@pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
19444the same connection used to communicate with @value{GDBN}. With such a
19445target, if the remote program is unstripped, the only command you need is
19446@code{target remote} (or @code{target extended-remote}).
19447
19448If the remote program is stripped, or the target does not support remote
19449program file access, start up @value{GDBN} using the name of the local
1b6e6f5c 19450unstripped copy of your program as the first argument, or use the
19d9d4ef
DB
19451@code{file} command. Use @code{set sysroot} to specify the location (on
19452the host) of target libraries (unless your @value{GDBN} was compiled with
19453the correct sysroot using @code{--with-sysroot}). Alternatively, you
19454may use @code{set solib-search-path} to specify how @value{GDBN} locates
19455target libraries.
19456
19457The symbol file and target libraries must exactly match the executable
19458and libraries on the target, with one exception: the files on the host
19459system should not be stripped, even if the files on the target system
19460are. Mismatched or missing files will lead to confusing results
19461during debugging. On @sc{gnu}/Linux targets, mismatched or missing
19462files may also prevent @code{gdbserver} from debugging multi-threaded
19463programs.
07f31aa6 19464
19d9d4ef
DB
19465@subsection Remote Connection Commands
19466@cindex remote connection commands
86941c27
JB
19467@value{GDBN} can communicate with the target over a serial line, or
19468over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
19469each case, @value{GDBN} uses the same protocol for debugging your
19470program; only the medium carrying the debugging packets varies. The
19d9d4ef
DB
19471@code{target remote} and @code{target extended-remote} commands
19472establish a connection to the target. Both commands accept the same
19473arguments, which indicate the medium to use:
86941c27
JB
19474
19475@table @code
19476
19477@item target remote @var{serial-device}
19d9d4ef 19478@itemx target extended-remote @var{serial-device}
07f31aa6 19479@cindex serial line, @code{target remote}
86941c27
JB
19480Use @var{serial-device} to communicate with the target. For example,
19481to use a serial line connected to the device named @file{/dev/ttyb}:
19482
19483@smallexample
19484target remote /dev/ttyb
19485@end smallexample
19486
07f31aa6 19487If you're using a serial line, you may want to give @value{GDBN} the
2446f5ea 19488@samp{--baud} option, or use the @code{set serial baud} command
0d12017b 19489(@pxref{Remote Configuration, set serial baud}) before the
9c16f35a 19490@code{target} command.
07f31aa6 19491
86941c27
JB
19492@item target remote @code{@var{host}:@var{port}}
19493@itemx target remote @code{tcp:@var{host}:@var{port}}
19d9d4ef
DB
19494@itemx target extended-remote @code{@var{host}:@var{port}}
19495@itemx target extended-remote @code{tcp:@var{host}:@var{port}}
86941c27
JB
19496@cindex @acronym{TCP} port, @code{target remote}
19497Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
19498The @var{host} may be either a host name or a numeric @acronym{IP}
19499address; @var{port} must be a decimal number. The @var{host} could be
19500the target machine itself, if it is directly connected to the net, or
19501it might be a terminal server which in turn has a serial line to the
19502target.
07f31aa6 19503
86941c27
JB
19504For example, to connect to port 2828 on a terminal server named
19505@code{manyfarms}:
07f31aa6
DJ
19506
19507@smallexample
19508target remote manyfarms:2828
19509@end smallexample
19510
86941c27
JB
19511If your remote target is actually running on the same machine as your
19512debugger session (e.g.@: a simulator for your target running on the
19513same host), you can omit the hostname. For example, to connect to
19514port 1234 on your local machine:
07f31aa6
DJ
19515
19516@smallexample
19517target remote :1234
19518@end smallexample
19519@noindent
19520
19521Note that the colon is still required here.
19522
86941c27 19523@item target remote @code{udp:@var{host}:@var{port}}
19d9d4ef 19524@itemx target extended-remote @code{udp:@var{host}:@var{port}}
86941c27
JB
19525@cindex @acronym{UDP} port, @code{target remote}
19526Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
19527connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
19528
19529@smallexample
19530target remote udp:manyfarms:2828
19531@end smallexample
19532
86941c27
JB
19533When using a @acronym{UDP} connection for remote debugging, you should
19534keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
19535can silently drop packets on busy or unreliable networks, which will
19536cause havoc with your debugging session.
19537
66b8c7f6 19538@item target remote | @var{command}
19d9d4ef 19539@itemx target extended-remote | @var{command}
66b8c7f6
JB
19540@cindex pipe, @code{target remote} to
19541Run @var{command} in the background and communicate with it using a
19542pipe. The @var{command} is a shell command, to be parsed and expanded
19543by the system's command shell, @code{/bin/sh}; it should expect remote
19544protocol packets on its standard input, and send replies on its
19545standard output. You could use this to run a stand-alone simulator
19546that speaks the remote debugging protocol, to make net connections
19547using programs like @code{ssh}, or for other similar tricks.
19548
19549If @var{command} closes its standard output (perhaps by exiting),
19550@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
19551program has already exited, this will have no effect.)
19552
86941c27 19553@end table
07f31aa6 19554
07f31aa6
DJ
19555@cindex interrupting remote programs
19556@cindex remote programs, interrupting
19557Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 19558interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
19559program. This may or may not succeed, depending in part on the hardware
19560and the serial drivers the remote system uses. If you type the
19561interrupt character once again, @value{GDBN} displays this prompt:
19562
19563@smallexample
19564Interrupted while waiting for the program.
19565Give up (and stop debugging it)? (y or n)
19566@end smallexample
19567
19d9d4ef
DB
19568In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
19569the remote debugging session. (If you decide you want to try again later,
19570you can use @kbd{target remote} again to connect once more.) If you type
19571@kbd{n}, @value{GDBN} goes back to waiting.
19572
19573In @code{target extended-remote} mode, typing @kbd{n} will leave
19574@value{GDBN} connected to the target.
07f31aa6
DJ
19575
19576@table @code
19577@kindex detach (remote)
19578@item detach
19579When you have finished debugging the remote program, you can use the
19580@code{detach} command to release it from @value{GDBN} control.
19581Detaching from the target normally resumes its execution, but the results
19582will depend on your particular remote stub. After the @code{detach}
19d9d4ef
DB
19583command in @code{target remote} mode, @value{GDBN} is free to connect to
19584another target. In @code{target extended-remote} mode, @value{GDBN} is
19585still connected to the target.
07f31aa6
DJ
19586
19587@kindex disconnect
19588@item disconnect
19d9d4ef 19589The @code{disconnect} command closes the connection to the target, and
07f31aa6
DJ
19590the target is generally not resumed. It will wait for @value{GDBN}
19591(this instance or another one) to connect and continue debugging. After
19592the @code{disconnect} command, @value{GDBN} is again free to connect to
19593another target.
09d4efe1
EZ
19594
19595@cindex send command to remote monitor
fad38dfa
EZ
19596@cindex extend @value{GDBN} for remote targets
19597@cindex add new commands for external monitor
09d4efe1
EZ
19598@kindex monitor
19599@item monitor @var{cmd}
fad38dfa
EZ
19600This command allows you to send arbitrary commands directly to the
19601remote monitor. Since @value{GDBN} doesn't care about the commands it
19602sends like this, this command is the way to extend @value{GDBN}---you
19603can add new commands that only the external monitor will understand
19604and implement.
07f31aa6
DJ
19605@end table
19606
a6b151f1
DJ
19607@node File Transfer
19608@section Sending files to a remote system
19609@cindex remote target, file transfer
19610@cindex file transfer
19611@cindex sending files to remote systems
19612
19613Some remote targets offer the ability to transfer files over the same
19614connection used to communicate with @value{GDBN}. This is convenient
19615for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
19616running @code{gdbserver} over a network interface. For other targets,
19617e.g.@: embedded devices with only a single serial port, this may be
19618the only way to upload or download files.
19619
19620Not all remote targets support these commands.
19621
19622@table @code
19623@kindex remote put
19624@item remote put @var{hostfile} @var{targetfile}
19625Copy file @var{hostfile} from the host system (the machine running
19626@value{GDBN}) to @var{targetfile} on the target system.
19627
19628@kindex remote get
19629@item remote get @var{targetfile} @var{hostfile}
19630Copy file @var{targetfile} from the target system to @var{hostfile}
19631on the host system.
19632
19633@kindex remote delete
19634@item remote delete @var{targetfile}
19635Delete @var{targetfile} from the target system.
19636
19637@end table
19638
6f05cf9f 19639@node Server
79a6e687 19640@section Using the @code{gdbserver} Program
6f05cf9f
AC
19641
19642@kindex gdbserver
19643@cindex remote connection without stubs
19644@code{gdbserver} is a control program for Unix-like systems, which
19645allows you to connect your program with a remote @value{GDBN} via
19d9d4ef
DB
19646@code{target remote} or @code{target extended-remote}---but without
19647linking in the usual debugging stub.
6f05cf9f
AC
19648
19649@code{gdbserver} is not a complete replacement for the debugging stubs,
19650because it requires essentially the same operating-system facilities
19651that @value{GDBN} itself does. In fact, a system that can run
19652@code{gdbserver} to connect to a remote @value{GDBN} could also run
19653@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
19654because it is a much smaller program than @value{GDBN} itself. It is
19655also easier to port than all of @value{GDBN}, so you may be able to get
19656started more quickly on a new system by using @code{gdbserver}.
19657Finally, if you develop code for real-time systems, you may find that
19658the tradeoffs involved in real-time operation make it more convenient to
19659do as much development work as possible on another system, for example
19660by cross-compiling. You can use @code{gdbserver} to make a similar
19661choice for debugging.
19662
19663@value{GDBN} and @code{gdbserver} communicate via either a serial line
19664or a TCP connection, using the standard @value{GDBN} remote serial
19665protocol.
19666
2d717e4f
DJ
19667@quotation
19668@emph{Warning:} @code{gdbserver} does not have any built-in security.
19669Do not run @code{gdbserver} connected to any public network; a
19670@value{GDBN} connection to @code{gdbserver} provides access to the
19671target system with the same privileges as the user running
19672@code{gdbserver}.
19673@end quotation
19674
19d9d4ef 19675@anchor{Running gdbserver}
2d717e4f
DJ
19676@subsection Running @code{gdbserver}
19677@cindex arguments, to @code{gdbserver}
d9b1a651 19678@cindex @code{gdbserver}, command-line arguments
2d717e4f
DJ
19679
19680Run @code{gdbserver} on the target system. You need a copy of the
19681program you want to debug, including any libraries it requires.
6f05cf9f
AC
19682@code{gdbserver} does not need your program's symbol table, so you can
19683strip the program if necessary to save space. @value{GDBN} on the host
19684system does all the symbol handling.
19685
19686To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 19687the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
19688syntax is:
19689
19690@smallexample
19691target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
19692@end smallexample
19693
e0f9f062
DE
19694@var{comm} is either a device name (to use a serial line), or a TCP
19695hostname and portnumber, or @code{-} or @code{stdio} to use
19696stdin/stdout of @code{gdbserver}.
19697For example, to debug Emacs with the argument
6f05cf9f
AC
19698@samp{foo.txt} and communicate with @value{GDBN} over the serial port
19699@file{/dev/com1}:
19700
19701@smallexample
19702target> gdbserver /dev/com1 emacs foo.txt
19703@end smallexample
19704
19705@code{gdbserver} waits passively for the host @value{GDBN} to communicate
19706with it.
19707
19708To use a TCP connection instead of a serial line:
19709
19710@smallexample
19711target> gdbserver host:2345 emacs foo.txt
19712@end smallexample
19713
19714The only difference from the previous example is the first argument,
19715specifying that you are communicating with the host @value{GDBN} via
19716TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
19717expect a TCP connection from machine @samp{host} to local TCP port 2345.
19718(Currently, the @samp{host} part is ignored.) You can choose any number
19719you want for the port number as long as it does not conflict with any
19720TCP ports already in use on the target system (for example, @code{23} is
19721reserved for @code{telnet}).@footnote{If you choose a port number that
19722conflicts with another service, @code{gdbserver} prints an error message
19723and exits.} You must use the same port number with the host @value{GDBN}
19724@code{target remote} command.
19725
e0f9f062
DE
19726The @code{stdio} connection is useful when starting @code{gdbserver}
19727with ssh:
19728
19729@smallexample
19730(gdb) target remote | ssh -T hostname gdbserver - hello
19731@end smallexample
19732
19733The @samp{-T} option to ssh is provided because we don't need a remote pty,
19734and we don't want escape-character handling. Ssh does this by default when
19735a command is provided, the flag is provided to make it explicit.
19736You could elide it if you want to.
19737
19738Programs started with stdio-connected gdbserver have @file{/dev/null} for
19739@code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
19740display through a pipe connected to gdbserver.
19741Both @code{stdout} and @code{stderr} use the same pipe.
19742
19d9d4ef 19743@anchor{Attaching to a program}
2d717e4f 19744@subsubsection Attaching to a Running Program
d9b1a651
EZ
19745@cindex attach to a program, @code{gdbserver}
19746@cindex @option{--attach}, @code{gdbserver} option
2d717e4f 19747
56460a61
DJ
19748On some targets, @code{gdbserver} can also attach to running programs.
19749This is accomplished via the @code{--attach} argument. The syntax is:
19750
19751@smallexample
2d717e4f 19752target> gdbserver --attach @var{comm} @var{pid}
56460a61
DJ
19753@end smallexample
19754
19d9d4ef
DB
19755@var{pid} is the process ID of a currently running process. It isn't
19756necessary to point @code{gdbserver} at a binary for the running process.
19757
19758In @code{target extended-remote} mode, you can also attach using the
19759@value{GDBN} attach command
19760(@pxref{Attaching in Types of Remote Connections}).
56460a61 19761
b1fe9455 19762@pindex pidof
b1fe9455
DJ
19763You can debug processes by name instead of process ID if your target has the
19764@code{pidof} utility:
19765
19766@smallexample
2d717e4f 19767target> gdbserver --attach @var{comm} `pidof @var{program}`
b1fe9455
DJ
19768@end smallexample
19769
f822c95b 19770In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
19771has multiple threads, most versions of @code{pidof} support the
19772@code{-s} option to only return the first process ID.
19773
03f2bd59
JK
19774@subsubsection TCP port allocation lifecycle of @code{gdbserver}
19775
19d9d4ef
DB
19776This section applies only when @code{gdbserver} is run to listen on a TCP
19777port.
03f2bd59
JK
19778
19779@code{gdbserver} normally terminates after all of its debugged processes have
19780terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
19781extended-remote}, @code{gdbserver} stays running even with no processes left.
19782@value{GDBN} normally terminates the spawned debugged process on its exit,
19783which normally also terminates @code{gdbserver} in the @kbd{target remote}
19784mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
19785cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
19786stays running even in the @kbd{target remote} mode.
19787
19788When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
19789Such reconnecting is useful for features like @ref{disconnected tracing}. For
19790completeness, at most one @value{GDBN} can be connected at a time.
19791
19792@cindex @option{--once}, @code{gdbserver} option
19793By default, @code{gdbserver} keeps the listening TCP port open, so that
6e8c5661 19794subsequent connections are possible. However, if you start @code{gdbserver}
03f2bd59
JK
19795with the @option{--once} option, it will stop listening for any further
19796connection attempts after connecting to the first @value{GDBN} session. This
19797means no further connections to @code{gdbserver} will be possible after the
19798first one. It also means @code{gdbserver} will terminate after the first
19799connection with remote @value{GDBN} has closed, even for unexpectedly closed
19800connections and even in the @kbd{target extended-remote} mode. The
19801@option{--once} option allows reusing the same port number for connecting to
19802multiple instances of @code{gdbserver} running on the same host, since each
19803instance closes its port after the first connection.
2d717e4f 19804
87ce2a04 19805@anchor{Other Command-Line Arguments for gdbserver}
2d717e4f
DJ
19806@subsubsection Other Command-Line Arguments for @code{gdbserver}
19807
19d9d4ef
DB
19808You can use the @option{--multi} option to start @code{gdbserver} without
19809specifying a program to debug or a process to attach to. Then you can
19810attach in @code{target extended-remote} mode and run or attach to a
19811program. For more information,
19812@pxref{--multi Option in Types of Remote Connnections}.
19813
d9b1a651 19814@cindex @option{--debug}, @code{gdbserver} option
62709adf 19815The @option{--debug} option tells @code{gdbserver} to display extra
d9b1a651
EZ
19816status information about the debugging process.
19817@cindex @option{--remote-debug}, @code{gdbserver} option
19818The @option{--remote-debug} option tells @code{gdbserver} to display
62709adf
PA
19819remote protocol debug output. These options are intended for
19820@code{gdbserver} development and for bug reports to the developers.
2d717e4f 19821
87ce2a04
DE
19822@cindex @option{--debug-format}, @code{gdbserver} option
19823The @option{--debug-format=option1[,option2,...]} option tells
19824@code{gdbserver} to include additional information in each output.
19825Possible options are:
19826
19827@table @code
19828@item none
19829Turn off all extra information in debugging output.
19830@item all
19831Turn on all extra information in debugging output.
19832@item timestamps
19833Include a timestamp in each line of debugging output.
19834@end table
19835
19836Options are processed in order. Thus, for example, if @option{none}
19837appears last then no additional information is added to debugging output.
19838
d9b1a651 19839@cindex @option{--wrapper}, @code{gdbserver} option
ccd213ac
DJ
19840The @option{--wrapper} option specifies a wrapper to launch programs
19841for debugging. The option should be followed by the name of the
19842wrapper, then any command-line arguments to pass to the wrapper, then
19843@kbd{--} indicating the end of the wrapper arguments.
19844
19845@code{gdbserver} runs the specified wrapper program with a combined
19846command line including the wrapper arguments, then the name of the
19847program to debug, then any arguments to the program. The wrapper
19848runs until it executes your program, and then @value{GDBN} gains control.
19849
19850You can use any program that eventually calls @code{execve} with
19851its arguments as a wrapper. Several standard Unix utilities do
19852this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
19853with @code{exec "$@@"} will also work.
19854
19855For example, you can use @code{env} to pass an environment variable to
19856the debugged program, without setting the variable in @code{gdbserver}'s
19857environment:
19858
19859@smallexample
19860$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
19861@end smallexample
19862
2d717e4f
DJ
19863@subsection Connecting to @code{gdbserver}
19864
19d9d4ef
DB
19865The basic procedure for connecting to the remote target is:
19866@itemize
2d717e4f 19867
19d9d4ef
DB
19868@item
19869Run @value{GDBN} on the host system.
f822c95b 19870
19d9d4ef
DB
19871@item
19872Make sure you have the necessary symbol files
19873(@pxref{Host and target files}).
19874Load symbols for your application using the @code{file} command before you
19875connect. Use @code{set sysroot} to locate target libraries (unless your
19876@value{GDBN} was compiled with the correct sysroot using
19877@code{--with-sysroot}).
f822c95b 19878
19d9d4ef 19879@item
79a6e687 19880Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f 19881For TCP connections, you must start up @code{gdbserver} prior to using
19d9d4ef 19882the @code{target} command. Otherwise you may get an error whose
6f05cf9f 19883text depends on the host system, but which usually looks something like
2d717e4f 19884@samp{Connection refused}. Don't use the @code{load}
19d9d4ef
DB
19885command in @value{GDBN} when using @code{target remote} mode, since the
19886program is already on the target.
19887
19888@end itemize
07f31aa6 19889
19d9d4ef 19890@anchor{Monitor Commands for gdbserver}
79a6e687 19891@subsection Monitor Commands for @code{gdbserver}
c74d0ad8
DJ
19892@cindex monitor commands, for @code{gdbserver}
19893
19894During a @value{GDBN} session using @code{gdbserver}, you can use the
19895@code{monitor} command to send special requests to @code{gdbserver}.
2d717e4f 19896Here are the available commands.
c74d0ad8
DJ
19897
19898@table @code
19899@item monitor help
19900List the available monitor commands.
19901
19902@item monitor set debug 0
19903@itemx monitor set debug 1
19904Disable or enable general debugging messages.
19905
19906@item monitor set remote-debug 0
19907@itemx monitor set remote-debug 1
19908Disable or enable specific debugging messages associated with the remote
19909protocol (@pxref{Remote Protocol}).
19910
87ce2a04
DE
19911@item monitor set debug-format option1@r{[},option2,...@r{]}
19912Specify additional text to add to debugging messages.
19913Possible options are:
19914
19915@table @code
19916@item none
19917Turn off all extra information in debugging output.
19918@item all
19919Turn on all extra information in debugging output.
19920@item timestamps
19921Include a timestamp in each line of debugging output.
19922@end table
19923
19924Options are processed in order. Thus, for example, if @option{none}
19925appears last then no additional information is added to debugging output.
19926
cdbfd419
PP
19927@item monitor set libthread-db-search-path [PATH]
19928@cindex gdbserver, search path for @code{libthread_db}
19929When this command is issued, @var{path} is a colon-separated list of
19930directories to search for @code{libthread_db} (@pxref{Threads,,set
19931libthread-db-search-path}). If you omit @var{path},
84e578fb 19932@samp{libthread-db-search-path} will be reset to its default value.
cdbfd419 19933
98a5dd13
DE
19934The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
19935not supported in @code{gdbserver}.
19936
2d717e4f
DJ
19937@item monitor exit
19938Tell gdbserver to exit immediately. This command should be followed by
19939@code{disconnect} to close the debugging session. @code{gdbserver} will
19940detach from any attached processes and kill any processes it created.
19941Use @code{monitor exit} to terminate @code{gdbserver} at the end
19942of a multi-process mode debug session.
19943
c74d0ad8
DJ
19944@end table
19945
fa593d66
PA
19946@subsection Tracepoints support in @code{gdbserver}
19947@cindex tracepoints support in @code{gdbserver}
19948
0fb4aa4b
PA
19949On some targets, @code{gdbserver} supports tracepoints, fast
19950tracepoints and static tracepoints.
fa593d66 19951
0fb4aa4b 19952For fast or static tracepoints to work, a special library called the
fa593d66
PA
19953@dfn{in-process agent} (IPA), must be loaded in the inferior process.
19954This library is built and distributed as an integral part of
0fb4aa4b
PA
19955@code{gdbserver}. In addition, support for static tracepoints
19956requires building the in-process agent library with static tracepoints
19957support. At present, the UST (LTTng Userspace Tracer,
19958@url{http://lttng.org/ust}) tracing engine is supported. This support
19959is automatically available if UST development headers are found in the
19960standard include path when @code{gdbserver} is built, or if
19961@code{gdbserver} was explicitly configured using @option{--with-ust}
19962to point at such headers. You can explicitly disable the support
19963using @option{--with-ust=no}.
fa593d66
PA
19964
19965There are several ways to load the in-process agent in your program:
19966
19967@table @code
19968@item Specifying it as dependency at link time
19969
19970You can link your program dynamically with the in-process agent
19971library. On most systems, this is accomplished by adding
19972@code{-linproctrace} to the link command.
19973
19974@item Using the system's preloading mechanisms
19975
19976You can force loading the in-process agent at startup time by using
19977your system's support for preloading shared libraries. Many Unixes
19978support the concept of preloading user defined libraries. In most
19979cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
19980in the environment. See also the description of @code{gdbserver}'s
19981@option{--wrapper} command line option.
19982
19983@item Using @value{GDBN} to force loading the agent at run time
19984
19985On some systems, you can force the inferior to load a shared library,
19986by calling a dynamic loader function in the inferior that takes care
19987of dynamically looking up and loading a shared library. On most Unix
19988systems, the function is @code{dlopen}. You'll use the @code{call}
19989command for that. For example:
19990
19991@smallexample
19992(@value{GDBP}) call dlopen ("libinproctrace.so", ...)
19993@end smallexample
19994
19995Note that on most Unix systems, for the @code{dlopen} function to be
19996available, the program needs to be linked with @code{-ldl}.
19997@end table
19998
19999On systems that have a userspace dynamic loader, like most Unix
20000systems, when you connect to @code{gdbserver} using @code{target
20001remote}, you'll find that the program is stopped at the dynamic
20002loader's entry point, and no shared library has been loaded in the
20003program's address space yet, including the in-process agent. In that
0fb4aa4b
PA
20004case, before being able to use any of the fast or static tracepoints
20005features, you need to let the loader run and load the shared
20006libraries. The simplest way to do that is to run the program to the
20007main procedure. E.g., if debugging a C or C@t{++} program, start
fa593d66
PA
20008@code{gdbserver} like so:
20009
20010@smallexample
20011$ gdbserver :9999 myprogram
20012@end smallexample
20013
20014Start GDB and connect to @code{gdbserver} like so, and run to main:
20015
20016@smallexample
20017$ gdb myprogram
20018(@value{GDBP}) target remote myhost:9999
200190x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
20020(@value{GDBP}) b main
20021(@value{GDBP}) continue
20022@end smallexample
20023
20024The in-process tracing agent library should now be loaded into the
20025process; you can confirm it with the @code{info sharedlibrary}
20026command, which will list @file{libinproctrace.so} as loaded in the
0fb4aa4b
PA
20027process. You are now ready to install fast tracepoints, list static
20028tracepoint markers, probe static tracepoints markers, and start
fa593d66
PA
20029tracing.
20030
79a6e687
BW
20031@node Remote Configuration
20032@section Remote Configuration
501eef12 20033
9c16f35a
EZ
20034@kindex set remote
20035@kindex show remote
20036This section documents the configuration options available when
20037debugging remote programs. For the options related to the File I/O
fc320d37 20038extensions of the remote protocol, see @ref{system,
9c16f35a 20039system-call-allowed}.
501eef12
AC
20040
20041@table @code
9c16f35a 20042@item set remoteaddresssize @var{bits}
d3e8051b 20043@cindex address size for remote targets
9c16f35a
EZ
20044@cindex bits in remote address
20045Set the maximum size of address in a memory packet to the specified
20046number of bits. @value{GDBN} will mask off the address bits above
20047that number, when it passes addresses to the remote target. The
20048default value is the number of bits in the target's address.
20049
20050@item show remoteaddresssize
20051Show the current value of remote address size in bits.
20052
0d12017b 20053@item set serial baud @var{n}
9c16f35a
EZ
20054@cindex baud rate for remote targets
20055Set the baud rate for the remote serial I/O to @var{n} baud. The
20056value is used to set the speed of the serial port used for debugging
20057remote targets.
20058
0d12017b 20059@item show serial baud
9c16f35a
EZ
20060Show the current speed of the remote connection.
20061
236af5e3
YG
20062@item set serial parity @var{parity}
20063Set the parity for the remote serial I/O. Supported values of @var{parity} are:
20064@code{even}, @code{none}, and @code{odd}. The default is @code{none}.
20065
20066@item show serial parity
20067Show the current parity of the serial port.
20068
9c16f35a
EZ
20069@item set remotebreak
20070@cindex interrupt remote programs
20071@cindex BREAK signal instead of Ctrl-C
9a6253be 20072@anchor{set remotebreak}
9c16f35a 20073If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 20074when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 20075on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
20076character instead. The default is off, since most remote systems
20077expect to see @samp{Ctrl-C} as the interrupt signal.
20078
20079@item show remotebreak
20080Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
20081interrupt the remote program.
20082
23776285
MR
20083@item set remoteflow on
20084@itemx set remoteflow off
20085@kindex set remoteflow
20086Enable or disable hardware flow control (@code{RTS}/@code{CTS})
20087on the serial port used to communicate to the remote target.
20088
20089@item show remoteflow
20090@kindex show remoteflow
20091Show the current setting of hardware flow control.
20092
9c16f35a
EZ
20093@item set remotelogbase @var{base}
20094Set the base (a.k.a.@: radix) of logging serial protocol
20095communications to @var{base}. Supported values of @var{base} are:
20096@code{ascii}, @code{octal}, and @code{hex}. The default is
20097@code{ascii}.
20098
20099@item show remotelogbase
20100Show the current setting of the radix for logging remote serial
20101protocol.
20102
20103@item set remotelogfile @var{file}
20104@cindex record serial communications on file
20105Record remote serial communications on the named @var{file}. The
20106default is not to record at all.
20107
20108@item show remotelogfile.
20109Show the current setting of the file name on which to record the
20110serial communications.
20111
20112@item set remotetimeout @var{num}
20113@cindex timeout for serial communications
20114@cindex remote timeout
20115Set the timeout limit to wait for the remote target to respond to
20116@var{num} seconds. The default is 2 seconds.
20117
20118@item show remotetimeout
20119Show the current number of seconds to wait for the remote target
20120responses.
20121
20122@cindex limit hardware breakpoints and watchpoints
20123@cindex remote target, limit break- and watchpoints
501eef12
AC
20124@anchor{set remote hardware-watchpoint-limit}
20125@anchor{set remote hardware-breakpoint-limit}
20126@item set remote hardware-watchpoint-limit @var{limit}
20127@itemx set remote hardware-breakpoint-limit @var{limit}
20128Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
20129watchpoints. A limit of -1, the default, is treated as unlimited.
2d717e4f 20130
480a3f21
PW
20131@cindex limit hardware watchpoints length
20132@cindex remote target, limit watchpoints length
20133@anchor{set remote hardware-watchpoint-length-limit}
20134@item set remote hardware-watchpoint-length-limit @var{limit}
20135Restrict @value{GDBN} to using @var{limit} bytes for the maximum length of
20136a remote hardware watchpoint. A limit of -1, the default, is treated
20137as unlimited.
20138
20139@item show remote hardware-watchpoint-length-limit
20140Show the current limit (in bytes) of the maximum length of
20141a remote hardware watchpoint.
20142
2d717e4f
DJ
20143@item set remote exec-file @var{filename}
20144@itemx show remote exec-file
20145@anchor{set remote exec-file}
20146@cindex executable file, for remote target
20147Select the file used for @code{run} with @code{target
20148extended-remote}. This should be set to a filename valid on the
20149target system. If it is not set, the target will use a default
20150filename (e.g.@: the last program run).
84603566 20151
9a7071a8
JB
20152@item set remote interrupt-sequence
20153@cindex interrupt remote programs
20154@cindex select Ctrl-C, BREAK or BREAK-g
20155Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
20156@samp{BREAK-g} as the
20157sequence to the remote target in order to interrupt the execution.
20158@samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
20159is high level of serial line for some certain time.
20160Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
20161It is @code{BREAK} signal followed by character @code{g}.
20162
20163@item show interrupt-sequence
20164Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
20165is sent by @value{GDBN} to interrupt the remote program.
20166@code{BREAK-g} is BREAK signal followed by @code{g} and
20167also known as Magic SysRq g.
20168
20169@item set remote interrupt-on-connect
20170@cindex send interrupt-sequence on start
20171Specify whether interrupt-sequence is sent to remote target when
20172@value{GDBN} connects to it. This is mostly needed when you debug
20173Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
20174which is known as Magic SysRq g in order to connect @value{GDBN}.
20175
20176@item show interrupt-on-connect
20177Show whether interrupt-sequence is sent
20178to remote target when @value{GDBN} connects to it.
20179
84603566
SL
20180@kindex set tcp
20181@kindex show tcp
20182@item set tcp auto-retry on
20183@cindex auto-retry, for remote TCP target
20184Enable auto-retry for remote TCP connections. This is useful if the remote
20185debugging agent is launched in parallel with @value{GDBN}; there is a race
20186condition because the agent may not become ready to accept the connection
20187before @value{GDBN} attempts to connect. When auto-retry is
20188enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
20189to establish the connection using the timeout specified by
20190@code{set tcp connect-timeout}.
20191
20192@item set tcp auto-retry off
20193Do not auto-retry failed TCP connections.
20194
20195@item show tcp auto-retry
20196Show the current auto-retry setting.
20197
20198@item set tcp connect-timeout @var{seconds}
f81d1120 20199@itemx set tcp connect-timeout unlimited
84603566
SL
20200@cindex connection timeout, for remote TCP target
20201@cindex timeout, for remote target connection
20202Set the timeout for establishing a TCP connection to the remote target to
20203@var{seconds}. The timeout affects both polling to retry failed connections
20204(enabled by @code{set tcp auto-retry on}) and waiting for connections
20205that are merely slow to complete, and represents an approximate cumulative
f81d1120
PA
20206value. If @var{seconds} is @code{unlimited}, there is no timeout and
20207@value{GDBN} will keep attempting to establish a connection forever,
20208unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
84603566
SL
20209
20210@item show tcp connect-timeout
20211Show the current connection timeout setting.
501eef12
AC
20212@end table
20213
427c3a89
DJ
20214@cindex remote packets, enabling and disabling
20215The @value{GDBN} remote protocol autodetects the packets supported by
20216your debugging stub. If you need to override the autodetection, you
20217can use these commands to enable or disable individual packets. Each
20218packet can be set to @samp{on} (the remote target supports this
20219packet), @samp{off} (the remote target does not support this packet),
20220or @samp{auto} (detect remote target support for this packet). They
20221all default to @samp{auto}. For more information about each packet,
20222see @ref{Remote Protocol}.
20223
20224During normal use, you should not have to use any of these commands.
20225If you do, that may be a bug in your remote debugging stub, or a bug
20226in @value{GDBN}. You may want to report the problem to the
20227@value{GDBN} developers.
20228
cfa9d6d9
DJ
20229For each packet @var{name}, the command to enable or disable the
20230packet is @code{set remote @var{name}-packet}. The available settings
20231are:
427c3a89 20232
cfa9d6d9 20233@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
20234@item Command Name
20235@tab Remote Packet
20236@tab Related Features
20237
cfa9d6d9 20238@item @code{fetch-register}
427c3a89
DJ
20239@tab @code{p}
20240@tab @code{info registers}
20241
cfa9d6d9 20242@item @code{set-register}
427c3a89
DJ
20243@tab @code{P}
20244@tab @code{set}
20245
cfa9d6d9 20246@item @code{binary-download}
427c3a89
DJ
20247@tab @code{X}
20248@tab @code{load}, @code{set}
20249
cfa9d6d9 20250@item @code{read-aux-vector}
427c3a89
DJ
20251@tab @code{qXfer:auxv:read}
20252@tab @code{info auxv}
20253
cfa9d6d9 20254@item @code{symbol-lookup}
427c3a89
DJ
20255@tab @code{qSymbol}
20256@tab Detecting multiple threads
20257
2d717e4f
DJ
20258@item @code{attach}
20259@tab @code{vAttach}
20260@tab @code{attach}
20261
cfa9d6d9 20262@item @code{verbose-resume}
427c3a89
DJ
20263@tab @code{vCont}
20264@tab Stepping or resuming multiple threads
20265
2d717e4f
DJ
20266@item @code{run}
20267@tab @code{vRun}
20268@tab @code{run}
20269
cfa9d6d9 20270@item @code{software-breakpoint}
427c3a89
DJ
20271@tab @code{Z0}
20272@tab @code{break}
20273
cfa9d6d9 20274@item @code{hardware-breakpoint}
427c3a89
DJ
20275@tab @code{Z1}
20276@tab @code{hbreak}
20277
cfa9d6d9 20278@item @code{write-watchpoint}
427c3a89
DJ
20279@tab @code{Z2}
20280@tab @code{watch}
20281
cfa9d6d9 20282@item @code{read-watchpoint}
427c3a89
DJ
20283@tab @code{Z3}
20284@tab @code{rwatch}
20285
cfa9d6d9 20286@item @code{access-watchpoint}
427c3a89
DJ
20287@tab @code{Z4}
20288@tab @code{awatch}
20289
c78fa86a
GB
20290@item @code{pid-to-exec-file}
20291@tab @code{qXfer:exec-file:read}
20292@tab @code{attach}, @code{run}
20293
cfa9d6d9
DJ
20294@item @code{target-features}
20295@tab @code{qXfer:features:read}
20296@tab @code{set architecture}
20297
20298@item @code{library-info}
20299@tab @code{qXfer:libraries:read}
20300@tab @code{info sharedlibrary}
20301
20302@item @code{memory-map}
20303@tab @code{qXfer:memory-map:read}
20304@tab @code{info mem}
20305
0fb4aa4b
PA
20306@item @code{read-sdata-object}
20307@tab @code{qXfer:sdata:read}
20308@tab @code{print $_sdata}
20309
cfa9d6d9
DJ
20310@item @code{read-spu-object}
20311@tab @code{qXfer:spu:read}
20312@tab @code{info spu}
20313
20314@item @code{write-spu-object}
20315@tab @code{qXfer:spu:write}
20316@tab @code{info spu}
20317
4aa995e1
PA
20318@item @code{read-siginfo-object}
20319@tab @code{qXfer:siginfo:read}
20320@tab @code{print $_siginfo}
20321
20322@item @code{write-siginfo-object}
20323@tab @code{qXfer:siginfo:write}
20324@tab @code{set $_siginfo}
20325
dc146f7c
VP
20326@item @code{threads}
20327@tab @code{qXfer:threads:read}
20328@tab @code{info threads}
20329
cfa9d6d9 20330@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
20331@tab @code{qGetTLSAddr}
20332@tab Displaying @code{__thread} variables
20333
711e434b
PM
20334@item @code{get-thread-information-block-address}
20335@tab @code{qGetTIBAddr}
20336@tab Display MS-Windows Thread Information Block.
20337
08388c79
DE
20338@item @code{search-memory}
20339@tab @code{qSearch:memory}
20340@tab @code{find}
20341
427c3a89
DJ
20342@item @code{supported-packets}
20343@tab @code{qSupported}
20344@tab Remote communications parameters
20345
82075af2
JS
20346@item @code{catch-syscalls}
20347@tab @code{QCatchSyscalls}
20348@tab @code{catch syscall}
20349
cfa9d6d9 20350@item @code{pass-signals}
89be2091
DJ
20351@tab @code{QPassSignals}
20352@tab @code{handle @var{signal}}
20353
9b224c5e
PA
20354@item @code{program-signals}
20355@tab @code{QProgramSignals}
20356@tab @code{handle @var{signal}}
20357
a6b151f1
DJ
20358@item @code{hostio-close-packet}
20359@tab @code{vFile:close}
20360@tab @code{remote get}, @code{remote put}
20361
20362@item @code{hostio-open-packet}
20363@tab @code{vFile:open}
20364@tab @code{remote get}, @code{remote put}
20365
20366@item @code{hostio-pread-packet}
20367@tab @code{vFile:pread}
20368@tab @code{remote get}, @code{remote put}
20369
20370@item @code{hostio-pwrite-packet}
20371@tab @code{vFile:pwrite}
20372@tab @code{remote get}, @code{remote put}
20373
20374@item @code{hostio-unlink-packet}
20375@tab @code{vFile:unlink}
20376@tab @code{remote delete}
a6f3e723 20377
b9e7b9c3
UW
20378@item @code{hostio-readlink-packet}
20379@tab @code{vFile:readlink}
20380@tab Host I/O
20381
0a93529c
GB
20382@item @code{hostio-fstat-packet}
20383@tab @code{vFile:fstat}
20384@tab Host I/O
20385
15a201c8
GB
20386@item @code{hostio-setfs-packet}
20387@tab @code{vFile:setfs}
20388@tab Host I/O
20389
a6f3e723
SL
20390@item @code{noack-packet}
20391@tab @code{QStartNoAckMode}
20392@tab Packet acknowledgment
07e059b5
VP
20393
20394@item @code{osdata}
20395@tab @code{qXfer:osdata:read}
20396@tab @code{info os}
0b16c5cf
PA
20397
20398@item @code{query-attached}
20399@tab @code{qAttached}
20400@tab Querying remote process attach state.
b3b9301e 20401
a46c1e42
PA
20402@item @code{trace-buffer-size}
20403@tab @code{QTBuffer:size}
20404@tab @code{set trace-buffer-size}
20405
bd3eecc3
PA
20406@item @code{trace-status}
20407@tab @code{qTStatus}
20408@tab @code{tstatus}
20409
b3b9301e
PA
20410@item @code{traceframe-info}
20411@tab @code{qXfer:traceframe-info:read}
20412@tab Traceframe info
03583c20 20413
1e4d1764
YQ
20414@item @code{install-in-trace}
20415@tab @code{InstallInTrace}
20416@tab Install tracepoint in tracing
20417
03583c20
UW
20418@item @code{disable-randomization}
20419@tab @code{QDisableRandomization}
20420@tab @code{set disable-randomization}
83364271
LM
20421
20422@item @code{conditional-breakpoints-packet}
20423@tab @code{Z0 and Z1}
20424@tab @code{Support for target-side breakpoint condition evaluation}
f7e6eed5 20425
73b8c1fd
PA
20426@item @code{multiprocess-extensions}
20427@tab @code{multiprocess extensions}
20428@tab Debug multiple processes and remote process PID awareness
20429
f7e6eed5
PA
20430@item @code{swbreak-feature}
20431@tab @code{swbreak stop reason}
20432@tab @code{break}
20433
20434@item @code{hwbreak-feature}
20435@tab @code{hwbreak stop reason}
20436@tab @code{hbreak}
20437
0d71eef5
DB
20438@item @code{fork-event-feature}
20439@tab @code{fork stop reason}
20440@tab @code{fork}
20441
20442@item @code{vfork-event-feature}
20443@tab @code{vfork stop reason}
20444@tab @code{vfork}
20445
b459a59b
DB
20446@item @code{exec-event-feature}
20447@tab @code{exec stop reason}
20448@tab @code{exec}
20449
65706a29
PA
20450@item @code{thread-events}
20451@tab @code{QThreadEvents}
20452@tab Tracking thread lifetime.
20453
f2faf941
PA
20454@item @code{no-resumed-stop-reply}
20455@tab @code{no resumed thread left stop reply}
20456@tab Tracking thread lifetime.
20457
427c3a89
DJ
20458@end multitable
20459
79a6e687
BW
20460@node Remote Stub
20461@section Implementing a Remote Stub
7a292a7a 20462
8e04817f
AC
20463@cindex debugging stub, example
20464@cindex remote stub, example
20465@cindex stub example, remote debugging
20466The stub files provided with @value{GDBN} implement the target side of the
20467communication protocol, and the @value{GDBN} side is implemented in the
20468@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
20469these subroutines to communicate, and ignore the details. (If you're
20470implementing your own stub file, you can still ignore the details: start
20471with one of the existing stub files. @file{sparc-stub.c} is the best
20472organized, and therefore the easiest to read.)
20473
104c1213
JM
20474@cindex remote serial debugging, overview
20475To debug a program running on another machine (the debugging
20476@dfn{target} machine), you must first arrange for all the usual
20477prerequisites for the program to run by itself. For example, for a C
20478program, you need:
c906108c 20479
104c1213
JM
20480@enumerate
20481@item
20482A startup routine to set up the C runtime environment; these usually
20483have a name like @file{crt0}. The startup routine may be supplied by
20484your hardware supplier, or you may have to write your own.
96baa820 20485
5d161b24 20486@item
d4f3574e 20487A C subroutine library to support your program's
104c1213 20488subroutine calls, notably managing input and output.
96baa820 20489
104c1213
JM
20490@item
20491A way of getting your program to the other machine---for example, a
20492download program. These are often supplied by the hardware
20493manufacturer, but you may have to write your own from hardware
20494documentation.
20495@end enumerate
96baa820 20496
104c1213
JM
20497The next step is to arrange for your program to use a serial port to
20498communicate with the machine where @value{GDBN} is running (the @dfn{host}
20499machine). In general terms, the scheme looks like this:
96baa820 20500
104c1213
JM
20501@table @emph
20502@item On the host,
20503@value{GDBN} already understands how to use this protocol; when everything
20504else is set up, you can simply use the @samp{target remote} command
20505(@pxref{Targets,,Specifying a Debugging Target}).
20506
20507@item On the target,
20508you must link with your program a few special-purpose subroutines that
20509implement the @value{GDBN} remote serial protocol. The file containing these
20510subroutines is called a @dfn{debugging stub}.
20511
20512On certain remote targets, you can use an auxiliary program
20513@code{gdbserver} instead of linking a stub into your program.
79a6e687 20514@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 20515@end table
96baa820 20516
104c1213
JM
20517The debugging stub is specific to the architecture of the remote
20518machine; for example, use @file{sparc-stub.c} to debug programs on
20519@sc{sparc} boards.
96baa820 20520
104c1213
JM
20521@cindex remote serial stub list
20522These working remote stubs are distributed with @value{GDBN}:
96baa820 20523
104c1213
JM
20524@table @code
20525
20526@item i386-stub.c
41afff9a 20527@cindex @file{i386-stub.c}
104c1213
JM
20528@cindex Intel
20529@cindex i386
20530For Intel 386 and compatible architectures.
20531
20532@item m68k-stub.c
41afff9a 20533@cindex @file{m68k-stub.c}
104c1213
JM
20534@cindex Motorola 680x0
20535@cindex m680x0
20536For Motorola 680x0 architectures.
20537
20538@item sh-stub.c
41afff9a 20539@cindex @file{sh-stub.c}
172c2a43 20540@cindex Renesas
104c1213 20541@cindex SH
172c2a43 20542For Renesas SH architectures.
104c1213
JM
20543
20544@item sparc-stub.c
41afff9a 20545@cindex @file{sparc-stub.c}
104c1213
JM
20546@cindex Sparc
20547For @sc{sparc} architectures.
20548
20549@item sparcl-stub.c
41afff9a 20550@cindex @file{sparcl-stub.c}
104c1213
JM
20551@cindex Fujitsu
20552@cindex SparcLite
20553For Fujitsu @sc{sparclite} architectures.
20554
20555@end table
20556
20557The @file{README} file in the @value{GDBN} distribution may list other
20558recently added stubs.
20559
20560@menu
20561* Stub Contents:: What the stub can do for you
20562* Bootstrapping:: What you must do for the stub
20563* Debug Session:: Putting it all together
104c1213
JM
20564@end menu
20565
6d2ebf8b 20566@node Stub Contents
79a6e687 20567@subsection What the Stub Can Do for You
104c1213
JM
20568
20569@cindex remote serial stub
20570The debugging stub for your architecture supplies these three
20571subroutines:
20572
20573@table @code
20574@item set_debug_traps
4644b6e3 20575@findex set_debug_traps
104c1213
JM
20576@cindex remote serial stub, initialization
20577This routine arranges for @code{handle_exception} to run when your
2fb860fc
PA
20578program stops. You must call this subroutine explicitly in your
20579program's startup code.
104c1213
JM
20580
20581@item handle_exception
4644b6e3 20582@findex handle_exception
104c1213
JM
20583@cindex remote serial stub, main routine
20584This is the central workhorse, but your program never calls it
20585explicitly---the setup code arranges for @code{handle_exception} to
20586run when a trap is triggered.
20587
20588@code{handle_exception} takes control when your program stops during
20589execution (for example, on a breakpoint), and mediates communications
20590with @value{GDBN} on the host machine. This is where the communications
20591protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 20592representative on the target machine. It begins by sending summary
104c1213
JM
20593information on the state of your program, then continues to execute,
20594retrieving and transmitting any information @value{GDBN} needs, until you
20595execute a @value{GDBN} command that makes your program resume; at that point,
20596@code{handle_exception} returns control to your own code on the target
5d161b24 20597machine.
104c1213
JM
20598
20599@item breakpoint
20600@cindex @code{breakpoint} subroutine, remote
20601Use this auxiliary subroutine to make your program contain a
20602breakpoint. Depending on the particular situation, this may be the only
20603way for @value{GDBN} to get control. For instance, if your target
20604machine has some sort of interrupt button, you won't need to call this;
20605pressing the interrupt button transfers control to
20606@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
20607simply receiving characters on the serial port may also trigger a trap;
20608again, in that situation, you don't need to call @code{breakpoint} from
20609your own program---simply running @samp{target remote} from the host
5d161b24 20610@value{GDBN} session gets control.
104c1213
JM
20611
20612Call @code{breakpoint} if none of these is true, or if you simply want
20613to make certain your program stops at a predetermined point for the
20614start of your debugging session.
20615@end table
20616
6d2ebf8b 20617@node Bootstrapping
79a6e687 20618@subsection What You Must Do for the Stub
104c1213
JM
20619
20620@cindex remote stub, support routines
20621The debugging stubs that come with @value{GDBN} are set up for a particular
20622chip architecture, but they have no information about the rest of your
20623debugging target machine.
20624
20625First of all you need to tell the stub how to communicate with the
20626serial port.
20627
20628@table @code
20629@item int getDebugChar()
4644b6e3 20630@findex getDebugChar
104c1213
JM
20631Write this subroutine to read a single character from the serial port.
20632It may be identical to @code{getchar} for your target system; a
20633different name is used to allow you to distinguish the two if you wish.
20634
20635@item void putDebugChar(int)
4644b6e3 20636@findex putDebugChar
104c1213 20637Write this subroutine to write a single character to the serial port.
5d161b24 20638It may be identical to @code{putchar} for your target system; a
104c1213
JM
20639different name is used to allow you to distinguish the two if you wish.
20640@end table
20641
20642@cindex control C, and remote debugging
20643@cindex interrupting remote targets
20644If you want @value{GDBN} to be able to stop your program while it is
20645running, you need to use an interrupt-driven serial driver, and arrange
20646for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
20647character). That is the character which @value{GDBN} uses to tell the
20648remote system to stop.
20649
20650Getting the debugging target to return the proper status to @value{GDBN}
20651probably requires changes to the standard stub; one quick and dirty way
20652is to just execute a breakpoint instruction (the ``dirty'' part is that
20653@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
20654
20655Other routines you need to supply are:
20656
20657@table @code
20658@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 20659@findex exceptionHandler
104c1213
JM
20660Write this function to install @var{exception_address} in the exception
20661handling tables. You need to do this because the stub does not have any
20662way of knowing what the exception handling tables on your target system
20663are like (for example, the processor's table might be in @sc{rom},
20664containing entries which point to a table in @sc{ram}).
697aa1b7 20665The @var{exception_number} specifies the exception which should be changed;
104c1213
JM
20666its meaning is architecture-dependent (for example, different numbers
20667might represent divide by zero, misaligned access, etc). When this
20668exception occurs, control should be transferred directly to
20669@var{exception_address}, and the processor state (stack, registers,
20670and so on) should be just as it is when a processor exception occurs. So if
20671you want to use a jump instruction to reach @var{exception_address}, it
20672should be a simple jump, not a jump to subroutine.
20673
20674For the 386, @var{exception_address} should be installed as an interrupt
20675gate so that interrupts are masked while the handler runs. The gate
20676should be at privilege level 0 (the most privileged level). The
20677@sc{sparc} and 68k stubs are able to mask interrupts themselves without
20678help from @code{exceptionHandler}.
20679
20680@item void flush_i_cache()
4644b6e3 20681@findex flush_i_cache
d4f3574e 20682On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
20683instruction cache, if any, on your target machine. If there is no
20684instruction cache, this subroutine may be a no-op.
20685
20686On target machines that have instruction caches, @value{GDBN} requires this
20687function to make certain that the state of your program is stable.
20688@end table
20689
20690@noindent
20691You must also make sure this library routine is available:
20692
20693@table @code
20694@item void *memset(void *, int, int)
4644b6e3 20695@findex memset
104c1213
JM
20696This is the standard library function @code{memset} that sets an area of
20697memory to a known value. If you have one of the free versions of
20698@code{libc.a}, @code{memset} can be found there; otherwise, you must
20699either obtain it from your hardware manufacturer, or write your own.
20700@end table
20701
20702If you do not use the GNU C compiler, you may need other standard
20703library subroutines as well; this varies from one stub to another,
20704but in general the stubs are likely to use any of the common library
e22ea452 20705subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
20706
20707
6d2ebf8b 20708@node Debug Session
79a6e687 20709@subsection Putting it All Together
104c1213
JM
20710
20711@cindex remote serial debugging summary
20712In summary, when your program is ready to debug, you must follow these
20713steps.
20714
20715@enumerate
20716@item
6d2ebf8b 20717Make sure you have defined the supporting low-level routines
79a6e687 20718(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
20719@display
20720@code{getDebugChar}, @code{putDebugChar},
20721@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
20722@end display
20723
20724@item
2fb860fc
PA
20725Insert these lines in your program's startup code, before the main
20726procedure is called:
104c1213 20727
474c8240 20728@smallexample
104c1213
JM
20729set_debug_traps();
20730breakpoint();
474c8240 20731@end smallexample
104c1213 20732
2fb860fc
PA
20733On some machines, when a breakpoint trap is raised, the hardware
20734automatically makes the PC point to the instruction after the
20735breakpoint. If your machine doesn't do that, you may need to adjust
20736@code{handle_exception} to arrange for it to return to the instruction
20737after the breakpoint on this first invocation, so that your program
20738doesn't keep hitting the initial breakpoint instead of making
20739progress.
20740
104c1213
JM
20741@item
20742For the 680x0 stub only, you need to provide a variable called
20743@code{exceptionHook}. Normally you just use:
20744
474c8240 20745@smallexample
104c1213 20746void (*exceptionHook)() = 0;
474c8240 20747@end smallexample
104c1213 20748
d4f3574e 20749@noindent
104c1213 20750but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 20751function in your program, that function is called when
104c1213
JM
20752@code{@value{GDBN}} continues after stopping on a trap (for example, bus
20753error). The function indicated by @code{exceptionHook} is called with
20754one parameter: an @code{int} which is the exception number.
20755
20756@item
20757Compile and link together: your program, the @value{GDBN} debugging stub for
20758your target architecture, and the supporting subroutines.
20759
20760@item
20761Make sure you have a serial connection between your target machine and
20762the @value{GDBN} host, and identify the serial port on the host.
20763
20764@item
20765@c The "remote" target now provides a `load' command, so we should
20766@c document that. FIXME.
20767Download your program to your target machine (or get it there by
20768whatever means the manufacturer provides), and start it.
20769
20770@item
07f31aa6 20771Start @value{GDBN} on the host, and connect to the target
79a6e687 20772(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 20773
104c1213
JM
20774@end enumerate
20775
8e04817f
AC
20776@node Configurations
20777@chapter Configuration-Specific Information
104c1213 20778
8e04817f
AC
20779While nearly all @value{GDBN} commands are available for all native and
20780cross versions of the debugger, there are some exceptions. This chapter
20781describes things that are only available in certain configurations.
104c1213 20782
8e04817f
AC
20783There are three major categories of configurations: native
20784configurations, where the host and target are the same, embedded
20785operating system configurations, which are usually the same for several
20786different processor architectures, and bare embedded processors, which
20787are quite different from each other.
104c1213 20788
8e04817f
AC
20789@menu
20790* Native::
20791* Embedded OS::
20792* Embedded Processors::
20793* Architectures::
20794@end menu
104c1213 20795
8e04817f
AC
20796@node Native
20797@section Native
104c1213 20798
8e04817f
AC
20799This section describes details specific to particular native
20800configurations.
6cf7e474 20801
8e04817f 20802@menu
7561d450 20803* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
20804* SVR4 Process Information:: SVR4 process information
20805* DJGPP Native:: Features specific to the DJGPP port
78c47bea 20806* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 20807* Hurd Native:: Features specific to @sc{gnu} Hurd
a80b95ba 20808* Darwin:: Features specific to Darwin
8e04817f 20809@end menu
6cf7e474 20810
7561d450
MK
20811@node BSD libkvm Interface
20812@subsection BSD libkvm Interface
20813
20814@cindex libkvm
20815@cindex kernel memory image
20816@cindex kernel crash dump
20817
20818BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
20819interface that provides a uniform interface for accessing kernel virtual
20820memory images, including live systems and crash dumps. @value{GDBN}
20821uses this interface to allow you to debug live kernels and kernel crash
20822dumps on many native BSD configurations. This is implemented as a
20823special @code{kvm} debugging target. For debugging a live system, load
20824the currently running kernel into @value{GDBN} and connect to the
20825@code{kvm} target:
20826
20827@smallexample
20828(@value{GDBP}) @b{target kvm}
20829@end smallexample
20830
20831For debugging crash dumps, provide the file name of the crash dump as an
20832argument:
20833
20834@smallexample
20835(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
20836@end smallexample
20837
20838Once connected to the @code{kvm} target, the following commands are
20839available:
20840
20841@table @code
20842@kindex kvm
20843@item kvm pcb
721c2651 20844Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
20845
20846@item kvm proc
20847Set current context from proc address. This command isn't available on
20848modern FreeBSD systems.
20849@end table
20850
8e04817f 20851@node SVR4 Process Information
79a6e687 20852@subsection SVR4 Process Information
60bf7e09
EZ
20853@cindex /proc
20854@cindex examine process image
20855@cindex process info via @file{/proc}
104c1213 20856
60bf7e09
EZ
20857Many versions of SVR4 and compatible systems provide a facility called
20858@samp{/proc} that can be used to examine the image of a running
451b7c33
TT
20859process using file-system subroutines.
20860
20861If @value{GDBN} is configured for an operating system with this
20862facility, the command @code{info proc} is available to report
20863information about the process running your program, or about any
20864process running on your system. This includes, as of this writing,
b1236ac3 20865@sc{gnu}/Linux and Solaris, for example.
451b7c33
TT
20866
20867This command may also work on core files that were created on a system
20868that has the @samp{/proc} facility.
104c1213 20869
8e04817f
AC
20870@table @code
20871@kindex info proc
60bf7e09 20872@cindex process ID
8e04817f 20873@item info proc
60bf7e09
EZ
20874@itemx info proc @var{process-id}
20875Summarize available information about any running process. If a
20876process ID is specified by @var{process-id}, display information about
20877that process; otherwise display information about the program being
20878debugged. The summary includes the debugged process ID, the command
20879line used to invoke it, its current working directory, and its
20880executable file's absolute file name.
20881
20882On some systems, @var{process-id} can be of the form
20883@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
20884within a process. If the optional @var{pid} part is missing, it means
20885a thread from the process being debugged (the leading @samp{/} still
20886needs to be present, or else @value{GDBN} will interpret the number as
20887a process ID rather than a thread ID).
6cf7e474 20888
0c631110
TT
20889@item info proc cmdline
20890@cindex info proc cmdline
20891Show the original command line of the process. This command is
20892specific to @sc{gnu}/Linux.
20893
20894@item info proc cwd
20895@cindex info proc cwd
20896Show the current working directory of the process. This command is
20897specific to @sc{gnu}/Linux.
20898
20899@item info proc exe
20900@cindex info proc exe
20901Show the name of executable of the process. This command is specific
20902to @sc{gnu}/Linux.
20903
8e04817f 20904@item info proc mappings
60bf7e09
EZ
20905@cindex memory address space mappings
20906Report the memory address space ranges accessible in the program, with
20907information on whether the process has read, write, or execute access
20908rights to each range. On @sc{gnu}/Linux systems, each memory range
20909includes the object file which is mapped to that range, instead of the
20910memory access rights to that range.
20911
20912@item info proc stat
20913@itemx info proc status
20914@cindex process detailed status information
20915These subcommands are specific to @sc{gnu}/Linux systems. They show
20916the process-related information, including the user ID and group ID;
20917how many threads are there in the process; its virtual memory usage;
20918the signals that are pending, blocked, and ignored; its TTY; its
20919consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 20920value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
20921(type @kbd{man 5 proc} from your shell prompt).
20922
20923@item info proc all
20924Show all the information about the process described under all of the
20925above @code{info proc} subcommands.
20926
8e04817f
AC
20927@ignore
20928@comment These sub-options of 'info proc' were not included when
20929@comment procfs.c was re-written. Keep their descriptions around
20930@comment against the day when someone finds the time to put them back in.
20931@kindex info proc times
20932@item info proc times
20933Starting time, user CPU time, and system CPU time for your program and
20934its children.
6cf7e474 20935
8e04817f
AC
20936@kindex info proc id
20937@item info proc id
20938Report on the process IDs related to your program: its own process ID,
20939the ID of its parent, the process group ID, and the session ID.
8e04817f 20940@end ignore
721c2651
EZ
20941
20942@item set procfs-trace
20943@kindex set procfs-trace
20944@cindex @code{procfs} API calls
20945This command enables and disables tracing of @code{procfs} API calls.
20946
20947@item show procfs-trace
20948@kindex show procfs-trace
20949Show the current state of @code{procfs} API call tracing.
20950
20951@item set procfs-file @var{file}
20952@kindex set procfs-file
20953Tell @value{GDBN} to write @code{procfs} API trace to the named
20954@var{file}. @value{GDBN} appends the trace info to the previous
20955contents of the file. The default is to display the trace on the
20956standard output.
20957
20958@item show procfs-file
20959@kindex show procfs-file
20960Show the file to which @code{procfs} API trace is written.
20961
20962@item proc-trace-entry
20963@itemx proc-trace-exit
20964@itemx proc-untrace-entry
20965@itemx proc-untrace-exit
20966@kindex proc-trace-entry
20967@kindex proc-trace-exit
20968@kindex proc-untrace-entry
20969@kindex proc-untrace-exit
20970These commands enable and disable tracing of entries into and exits
20971from the @code{syscall} interface.
20972
20973@item info pidlist
20974@kindex info pidlist
20975@cindex process list, QNX Neutrino
20976For QNX Neutrino only, this command displays the list of all the
20977processes and all the threads within each process.
20978
20979@item info meminfo
20980@kindex info meminfo
20981@cindex mapinfo list, QNX Neutrino
20982For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 20983@end table
104c1213 20984
8e04817f
AC
20985@node DJGPP Native
20986@subsection Features for Debugging @sc{djgpp} Programs
20987@cindex @sc{djgpp} debugging
20988@cindex native @sc{djgpp} debugging
20989@cindex MS-DOS-specific commands
104c1213 20990
514c4d71
EZ
20991@cindex DPMI
20992@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
20993MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
20994that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
20995top of real-mode DOS systems and their emulations.
104c1213 20996
8e04817f
AC
20997@value{GDBN} supports native debugging of @sc{djgpp} programs, and
20998defines a few commands specific to the @sc{djgpp} port. This
20999subsection describes those commands.
104c1213 21000
8e04817f
AC
21001@table @code
21002@kindex info dos
21003@item info dos
21004This is a prefix of @sc{djgpp}-specific commands which print
21005information about the target system and important OS structures.
f1251bdd 21006
8e04817f
AC
21007@kindex sysinfo
21008@cindex MS-DOS system info
21009@cindex free memory information (MS-DOS)
21010@item info dos sysinfo
21011This command displays assorted information about the underlying
21012platform: the CPU type and features, the OS version and flavor, the
21013DPMI version, and the available conventional and DPMI memory.
104c1213 21014
8e04817f
AC
21015@cindex GDT
21016@cindex LDT
21017@cindex IDT
21018@cindex segment descriptor tables
21019@cindex descriptor tables display
21020@item info dos gdt
21021@itemx info dos ldt
21022@itemx info dos idt
21023These 3 commands display entries from, respectively, Global, Local,
21024and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
21025tables are data structures which store a descriptor for each segment
21026that is currently in use. The segment's selector is an index into a
21027descriptor table; the table entry for that index holds the
21028descriptor's base address and limit, and its attributes and access
21029rights.
104c1213 21030
8e04817f
AC
21031A typical @sc{djgpp} program uses 3 segments: a code segment, a data
21032segment (used for both data and the stack), and a DOS segment (which
21033allows access to DOS/BIOS data structures and absolute addresses in
21034conventional memory). However, the DPMI host will usually define
21035additional segments in order to support the DPMI environment.
d4f3574e 21036
8e04817f
AC
21037@cindex garbled pointers
21038These commands allow to display entries from the descriptor tables.
21039Without an argument, all entries from the specified table are
21040displayed. An argument, which should be an integer expression, means
21041display a single entry whose index is given by the argument. For
21042example, here's a convenient way to display information about the
21043debugged program's data segment:
104c1213 21044
8e04817f
AC
21045@smallexample
21046@exdent @code{(@value{GDBP}) info dos ldt $ds}
21047@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
21048@end smallexample
104c1213 21049
8e04817f
AC
21050@noindent
21051This comes in handy when you want to see whether a pointer is outside
21052the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 21053
8e04817f
AC
21054@cindex page tables display (MS-DOS)
21055@item info dos pde
21056@itemx info dos pte
21057These two commands display entries from, respectively, the Page
21058Directory and the Page Tables. Page Directories and Page Tables are
21059data structures which control how virtual memory addresses are mapped
21060into physical addresses. A Page Table includes an entry for every
21061page of memory that is mapped into the program's address space; there
21062may be several Page Tables, each one holding up to 4096 entries. A
21063Page Directory has up to 4096 entries, one each for every Page Table
21064that is currently in use.
104c1213 21065
8e04817f
AC
21066Without an argument, @kbd{info dos pde} displays the entire Page
21067Directory, and @kbd{info dos pte} displays all the entries in all of
21068the Page Tables. An argument, an integer expression, given to the
21069@kbd{info dos pde} command means display only that entry from the Page
21070Directory table. An argument given to the @kbd{info dos pte} command
21071means display entries from a single Page Table, the one pointed to by
21072the specified entry in the Page Directory.
104c1213 21073
8e04817f
AC
21074@cindex direct memory access (DMA) on MS-DOS
21075These commands are useful when your program uses @dfn{DMA} (Direct
21076Memory Access), which needs physical addresses to program the DMA
21077controller.
104c1213 21078
8e04817f 21079These commands are supported only with some DPMI servers.
104c1213 21080
8e04817f
AC
21081@cindex physical address from linear address
21082@item info dos address-pte @var{addr}
21083This command displays the Page Table entry for a specified linear
514c4d71
EZ
21084address. The argument @var{addr} is a linear address which should
21085already have the appropriate segment's base address added to it,
21086because this command accepts addresses which may belong to @emph{any}
21087segment. For example, here's how to display the Page Table entry for
21088the page where a variable @code{i} is stored:
104c1213 21089
b383017d 21090@smallexample
8e04817f
AC
21091@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
21092@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 21093@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 21094@end smallexample
104c1213 21095
8e04817f
AC
21096@noindent
21097This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 21098whose physical base address is @code{0x02698000}, and shows all the
8e04817f 21099attributes of that page.
104c1213 21100
8e04817f
AC
21101Note that you must cast the addresses of variables to a @code{char *},
21102since otherwise the value of @code{__djgpp_base_address}, the base
21103address of all variables and functions in a @sc{djgpp} program, will
21104be added using the rules of C pointer arithmetics: if @code{i} is
21105declared an @code{int}, @value{GDBN} will add 4 times the value of
21106@code{__djgpp_base_address} to the address of @code{i}.
104c1213 21107
8e04817f
AC
21108Here's another example, it displays the Page Table entry for the
21109transfer buffer:
104c1213 21110
8e04817f
AC
21111@smallexample
21112@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
21113@exdent @code{Page Table entry for address 0x29110:}
21114@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
21115@end smallexample
104c1213 21116
8e04817f
AC
21117@noindent
21118(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
211193rd member of the @code{_go32_info_block} structure.) The output
21120clearly shows that this DPMI server maps the addresses in conventional
21121memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
21122linear (@code{0x29110}) addresses are identical.
104c1213 21123
8e04817f
AC
21124This command is supported only with some DPMI servers.
21125@end table
104c1213 21126
c45da7e6 21127@cindex DOS serial data link, remote debugging
a8f24a35
EZ
21128In addition to native debugging, the DJGPP port supports remote
21129debugging via a serial data link. The following commands are specific
21130to remote serial debugging in the DJGPP port of @value{GDBN}.
21131
21132@table @code
21133@kindex set com1base
21134@kindex set com1irq
21135@kindex set com2base
21136@kindex set com2irq
21137@kindex set com3base
21138@kindex set com3irq
21139@kindex set com4base
21140@kindex set com4irq
21141@item set com1base @var{addr}
21142This command sets the base I/O port address of the @file{COM1} serial
21143port.
21144
21145@item set com1irq @var{irq}
21146This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
21147for the @file{COM1} serial port.
21148
21149There are similar commands @samp{set com2base}, @samp{set com3irq},
21150etc.@: for setting the port address and the @code{IRQ} lines for the
21151other 3 COM ports.
21152
21153@kindex show com1base
21154@kindex show com1irq
21155@kindex show com2base
21156@kindex show com2irq
21157@kindex show com3base
21158@kindex show com3irq
21159@kindex show com4base
21160@kindex show com4irq
21161The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
21162display the current settings of the base address and the @code{IRQ}
21163lines used by the COM ports.
c45da7e6
EZ
21164
21165@item info serial
21166@kindex info serial
21167@cindex DOS serial port status
21168This command prints the status of the 4 DOS serial ports. For each
21169port, it prints whether it's active or not, its I/O base address and
21170IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
21171counts of various errors encountered so far.
a8f24a35
EZ
21172@end table
21173
21174
78c47bea 21175@node Cygwin Native
79a6e687 21176@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
21177@cindex MS Windows debugging
21178@cindex native Cygwin debugging
21179@cindex Cygwin-specific commands
21180
be448670 21181@value{GDBN} supports native debugging of MS Windows programs, including
cbb8f428
EZ
21182DLLs with and without symbolic debugging information.
21183
21184@cindex Ctrl-BREAK, MS-Windows
21185@cindex interrupt debuggee on MS-Windows
21186MS-Windows programs that call @code{SetConsoleMode} to switch off the
21187special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
21188by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
21189supports @kbd{C-@key{BREAK}} as an alternative interrupt key
21190sequence, which can be used to interrupt the debuggee even if it
21191ignores @kbd{C-c}.
21192
21193There are various additional Cygwin-specific commands, described in
21194this section. Working with DLLs that have no debugging symbols is
21195described in @ref{Non-debug DLL Symbols}.
78c47bea
PM
21196
21197@table @code
21198@kindex info w32
21199@item info w32
db2e3e2e 21200This is a prefix of MS Windows-specific commands which print
78c47bea
PM
21201information about the target system and important OS structures.
21202
21203@item info w32 selector
21204This command displays information returned by
21205the Win32 API @code{GetThreadSelectorEntry} function.
21206It takes an optional argument that is evaluated to
21207a long value to give the information about this given selector.
21208Without argument, this command displays information
d3e8051b 21209about the six segment registers.
78c47bea 21210
711e434b
PM
21211@item info w32 thread-information-block
21212This command displays thread specific information stored in the
21213Thread Information Block (readable on the X86 CPU family using @code{$fs}
21214selector for 32-bit programs and @code{$gs} for 64-bit programs).
21215
be90c084 21216@kindex set cygwin-exceptions
e16b02ee
EZ
21217@cindex debugging the Cygwin DLL
21218@cindex Cygwin DLL, debugging
be90c084 21219@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
21220If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
21221happen inside the Cygwin DLL. If @var{mode} is @code{off},
21222@value{GDBN} will delay recognition of exceptions, and may ignore some
21223exceptions which seem to be caused by internal Cygwin DLL
21224``bookkeeping''. This option is meant primarily for debugging the
21225Cygwin DLL itself; the default value is @code{off} to avoid annoying
21226@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
21227
21228@kindex show cygwin-exceptions
21229@item show cygwin-exceptions
e16b02ee
EZ
21230Displays whether @value{GDBN} will break on exceptions that happen
21231inside the Cygwin DLL itself.
be90c084 21232
b383017d 21233@kindex set new-console
78c47bea 21234@item set new-console @var{mode}
b383017d 21235If @var{mode} is @code{on} the debuggee will
78c47bea 21236be started in a new console on next start.
e03e5e7b 21237If @var{mode} is @code{off}, the debuggee will
78c47bea
PM
21238be started in the same console as the debugger.
21239
21240@kindex show new-console
21241@item show new-console
21242Displays whether a new console is used
21243when the debuggee is started.
21244
21245@kindex set new-group
21246@item set new-group @var{mode}
21247This boolean value controls whether the debuggee should
21248start a new group or stay in the same group as the debugger.
21249This affects the way the Windows OS handles
c8aa23ab 21250@samp{Ctrl-C}.
78c47bea
PM
21251
21252@kindex show new-group
21253@item show new-group
21254Displays current value of new-group boolean.
21255
21256@kindex set debugevents
21257@item set debugevents
219eec71
EZ
21258This boolean value adds debug output concerning kernel events related
21259to the debuggee seen by the debugger. This includes events that
21260signal thread and process creation and exit, DLL loading and
21261unloading, console interrupts, and debugging messages produced by the
21262Windows @code{OutputDebugString} API call.
78c47bea
PM
21263
21264@kindex set debugexec
21265@item set debugexec
b383017d 21266This boolean value adds debug output concerning execute events
219eec71 21267(such as resume thread) seen by the debugger.
78c47bea
PM
21268
21269@kindex set debugexceptions
21270@item set debugexceptions
219eec71
EZ
21271This boolean value adds debug output concerning exceptions in the
21272debuggee seen by the debugger.
78c47bea
PM
21273
21274@kindex set debugmemory
21275@item set debugmemory
219eec71
EZ
21276This boolean value adds debug output concerning debuggee memory reads
21277and writes by the debugger.
78c47bea
PM
21278
21279@kindex set shell
21280@item set shell
21281This boolean values specifies whether the debuggee is called
21282via a shell or directly (default value is on).
21283
21284@kindex show shell
21285@item show shell
21286Displays if the debuggee will be started with a shell.
21287
21288@end table
21289
be448670 21290@menu
79a6e687 21291* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
21292@end menu
21293
79a6e687
BW
21294@node Non-debug DLL Symbols
21295@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
21296@cindex DLLs with no debugging symbols
21297@cindex Minimal symbols and DLLs
21298
21299Very often on windows, some of the DLLs that your program relies on do
21300not include symbolic debugging information (for example,
db2e3e2e 21301@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 21302symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 21303information contained in the DLL's export table. This section
be448670
CF
21304describes working with such symbols, known internally to @value{GDBN} as
21305``minimal symbols''.
21306
21307Note that before the debugged program has started execution, no DLLs
db2e3e2e 21308will have been loaded. The easiest way around this problem is simply to
be448670 21309start the program --- either by setting a breakpoint or letting the
95060284 21310program run once to completion.
be448670 21311
79a6e687 21312@subsubsection DLL Name Prefixes
be448670
CF
21313
21314In keeping with the naming conventions used by the Microsoft debugging
21315tools, DLL export symbols are made available with a prefix based on the
21316DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
21317also entered into the symbol table, so @code{CreateFileA} is often
99e008fe 21318sufficient. In some cases there will be name clashes within a program
be448670
CF
21319(particularly if the executable itself includes full debugging symbols)
21320necessitating the use of the fully qualified name when referring to the
99e008fe 21321contents of the DLL. Use single-quotes around the name to avoid the
be448670
CF
21322exclamation mark (``!'') being interpreted as a language operator.
21323
21324Note that the internal name of the DLL may be all upper-case, even
99e008fe 21325though the file name of the DLL is lower-case, or vice-versa. Since
be448670
CF
21326symbols within @value{GDBN} are @emph{case-sensitive} this may cause
21327some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
21328@code{info variables} commands or even @code{maint print msymbols}
21329(@pxref{Symbols}). Here's an example:
be448670
CF
21330
21331@smallexample
f7dc1244 21332(@value{GDBP}) info function CreateFileA
be448670
CF
21333All functions matching regular expression "CreateFileA":
21334
21335Non-debugging symbols:
213360x77e885f4 CreateFileA
213370x77e885f4 KERNEL32!CreateFileA
21338@end smallexample
21339
21340@smallexample
f7dc1244 21341(@value{GDBP}) info function !
be448670
CF
21342All functions matching regular expression "!":
21343
21344Non-debugging symbols:
213450x6100114c cygwin1!__assert
213460x61004034 cygwin1!_dll_crt0@@0
213470x61004240 cygwin1!dll_crt0(per_process *)
21348[etc...]
21349@end smallexample
21350
79a6e687 21351@subsubsection Working with Minimal Symbols
be448670
CF
21352
21353Symbols extracted from a DLL's export table do not contain very much
21354type information. All that @value{GDBN} can do is guess whether a symbol
21355refers to a function or variable depending on the linker section that
21356contains the symbol. Also note that the actual contents of the memory
21357contained in a DLL are not available unless the program is running. This
21358means that you cannot examine the contents of a variable or disassemble
21359a function within a DLL without a running program.
21360
21361Variables are generally treated as pointers and dereferenced
21362automatically. For this reason, it is often necessary to prefix a
21363variable name with the address-of operator (``&'') and provide explicit
21364type information in the command. Here's an example of the type of
21365problem:
21366
21367@smallexample
f7dc1244 21368(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
21369$1 = 268572168
21370@end smallexample
21371
21372@smallexample
f7dc1244 21373(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
213740x10021610: "\230y\""
21375@end smallexample
21376
21377And two possible solutions:
21378
21379@smallexample
f7dc1244 21380(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
21381$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
21382@end smallexample
21383
21384@smallexample
f7dc1244 21385(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 213860x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 21387(@value{GDBP}) x/x 0x10021608
be448670 213880x10021608: 0x0022fd98
f7dc1244 21389(@value{GDBP}) x/s 0x0022fd98
be448670
CF
213900x22fd98: "/cygdrive/c/mydirectory/myprogram"
21391@end smallexample
21392
21393Setting a break point within a DLL is possible even before the program
21394starts execution. However, under these circumstances, @value{GDBN} can't
21395examine the initial instructions of the function in order to skip the
21396function's frame set-up code. You can work around this by using ``*&''
21397to set the breakpoint at a raw memory address:
21398
21399@smallexample
f7dc1244 21400(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
21401Breakpoint 1 at 0x1e04eff0
21402@end smallexample
21403
21404The author of these extensions is not entirely convinced that setting a
21405break point within a shared DLL like @file{kernel32.dll} is completely
21406safe.
21407
14d6dd68 21408@node Hurd Native
79a6e687 21409@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
21410@cindex @sc{gnu} Hurd debugging
21411
21412This subsection describes @value{GDBN} commands specific to the
21413@sc{gnu} Hurd native debugging.
21414
21415@table @code
21416@item set signals
21417@itemx set sigs
21418@kindex set signals@r{, Hurd command}
21419@kindex set sigs@r{, Hurd command}
21420This command toggles the state of inferior signal interception by
21421@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
21422affected by this command. @code{sigs} is a shorthand alias for
21423@code{signals}.
21424
21425@item show signals
21426@itemx show sigs
21427@kindex show signals@r{, Hurd command}
21428@kindex show sigs@r{, Hurd command}
21429Show the current state of intercepting inferior's signals.
21430
21431@item set signal-thread
21432@itemx set sigthread
21433@kindex set signal-thread
21434@kindex set sigthread
21435This command tells @value{GDBN} which thread is the @code{libc} signal
21436thread. That thread is run when a signal is delivered to a running
21437process. @code{set sigthread} is the shorthand alias of @code{set
21438signal-thread}.
21439
21440@item show signal-thread
21441@itemx show sigthread
21442@kindex show signal-thread
21443@kindex show sigthread
21444These two commands show which thread will run when the inferior is
21445delivered a signal.
21446
21447@item set stopped
21448@kindex set stopped@r{, Hurd command}
21449This commands tells @value{GDBN} that the inferior process is stopped,
21450as with the @code{SIGSTOP} signal. The stopped process can be
21451continued by delivering a signal to it.
21452
21453@item show stopped
21454@kindex show stopped@r{, Hurd command}
21455This command shows whether @value{GDBN} thinks the debuggee is
21456stopped.
21457
21458@item set exceptions
21459@kindex set exceptions@r{, Hurd command}
21460Use this command to turn off trapping of exceptions in the inferior.
21461When exception trapping is off, neither breakpoints nor
21462single-stepping will work. To restore the default, set exception
21463trapping on.
21464
21465@item show exceptions
21466@kindex show exceptions@r{, Hurd command}
21467Show the current state of trapping exceptions in the inferior.
21468
21469@item set task pause
21470@kindex set task@r{, Hurd commands}
21471@cindex task attributes (@sc{gnu} Hurd)
21472@cindex pause current task (@sc{gnu} Hurd)
21473This command toggles task suspension when @value{GDBN} has control.
21474Setting it to on takes effect immediately, and the task is suspended
21475whenever @value{GDBN} gets control. Setting it to off will take
21476effect the next time the inferior is continued. If this option is set
21477to off, you can use @code{set thread default pause on} or @code{set
21478thread pause on} (see below) to pause individual threads.
21479
21480@item show task pause
21481@kindex show task@r{, Hurd commands}
21482Show the current state of task suspension.
21483
21484@item set task detach-suspend-count
21485@cindex task suspend count
21486@cindex detach from task, @sc{gnu} Hurd
21487This command sets the suspend count the task will be left with when
21488@value{GDBN} detaches from it.
21489
21490@item show task detach-suspend-count
21491Show the suspend count the task will be left with when detaching.
21492
21493@item set task exception-port
21494@itemx set task excp
21495@cindex task exception port, @sc{gnu} Hurd
21496This command sets the task exception port to which @value{GDBN} will
21497forward exceptions. The argument should be the value of the @dfn{send
21498rights} of the task. @code{set task excp} is a shorthand alias.
21499
21500@item set noninvasive
21501@cindex noninvasive task options
21502This command switches @value{GDBN} to a mode that is the least
21503invasive as far as interfering with the inferior is concerned. This
21504is the same as using @code{set task pause}, @code{set exceptions}, and
21505@code{set signals} to values opposite to the defaults.
21506
21507@item info send-rights
21508@itemx info receive-rights
21509@itemx info port-rights
21510@itemx info port-sets
21511@itemx info dead-names
21512@itemx info ports
21513@itemx info psets
21514@cindex send rights, @sc{gnu} Hurd
21515@cindex receive rights, @sc{gnu} Hurd
21516@cindex port rights, @sc{gnu} Hurd
21517@cindex port sets, @sc{gnu} Hurd
21518@cindex dead names, @sc{gnu} Hurd
21519These commands display information about, respectively, send rights,
21520receive rights, port rights, port sets, and dead names of a task.
21521There are also shorthand aliases: @code{info ports} for @code{info
21522port-rights} and @code{info psets} for @code{info port-sets}.
21523
21524@item set thread pause
21525@kindex set thread@r{, Hurd command}
21526@cindex thread properties, @sc{gnu} Hurd
21527@cindex pause current thread (@sc{gnu} Hurd)
21528This command toggles current thread suspension when @value{GDBN} has
21529control. Setting it to on takes effect immediately, and the current
21530thread is suspended whenever @value{GDBN} gets control. Setting it to
21531off will take effect the next time the inferior is continued.
21532Normally, this command has no effect, since when @value{GDBN} has
21533control, the whole task is suspended. However, if you used @code{set
21534task pause off} (see above), this command comes in handy to suspend
21535only the current thread.
21536
21537@item show thread pause
21538@kindex show thread@r{, Hurd command}
21539This command shows the state of current thread suspension.
21540
21541@item set thread run
d3e8051b 21542This command sets whether the current thread is allowed to run.
14d6dd68
EZ
21543
21544@item show thread run
21545Show whether the current thread is allowed to run.
21546
21547@item set thread detach-suspend-count
21548@cindex thread suspend count, @sc{gnu} Hurd
21549@cindex detach from thread, @sc{gnu} Hurd
21550This command sets the suspend count @value{GDBN} will leave on a
21551thread when detaching. This number is relative to the suspend count
21552found by @value{GDBN} when it notices the thread; use @code{set thread
21553takeover-suspend-count} to force it to an absolute value.
21554
21555@item show thread detach-suspend-count
21556Show the suspend count @value{GDBN} will leave on the thread when
21557detaching.
21558
21559@item set thread exception-port
21560@itemx set thread excp
21561Set the thread exception port to which to forward exceptions. This
21562overrides the port set by @code{set task exception-port} (see above).
21563@code{set thread excp} is the shorthand alias.
21564
21565@item set thread takeover-suspend-count
21566Normally, @value{GDBN}'s thread suspend counts are relative to the
21567value @value{GDBN} finds when it notices each thread. This command
21568changes the suspend counts to be absolute instead.
21569
21570@item set thread default
21571@itemx show thread default
21572@cindex thread default settings, @sc{gnu} Hurd
21573Each of the above @code{set thread} commands has a @code{set thread
21574default} counterpart (e.g., @code{set thread default pause}, @code{set
21575thread default exception-port}, etc.). The @code{thread default}
21576variety of commands sets the default thread properties for all
21577threads; you can then change the properties of individual threads with
21578the non-default commands.
21579@end table
21580
a80b95ba
TG
21581@node Darwin
21582@subsection Darwin
21583@cindex Darwin
21584
21585@value{GDBN} provides the following commands specific to the Darwin target:
21586
21587@table @code
21588@item set debug darwin @var{num}
21589@kindex set debug darwin
21590When set to a non zero value, enables debugging messages specific to
21591the Darwin support. Higher values produce more verbose output.
21592
21593@item show debug darwin
21594@kindex show debug darwin
21595Show the current state of Darwin messages.
21596
21597@item set debug mach-o @var{num}
21598@kindex set debug mach-o
21599When set to a non zero value, enables debugging messages while
21600@value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
21601file format used on Darwin for object and executable files.) Higher
21602values produce more verbose output. This is a command to diagnose
21603problems internal to @value{GDBN} and should not be needed in normal
21604usage.
21605
21606@item show debug mach-o
21607@kindex show debug mach-o
21608Show the current state of Mach-O file messages.
21609
21610@item set mach-exceptions on
21611@itemx set mach-exceptions off
21612@kindex set mach-exceptions
21613On Darwin, faults are first reported as a Mach exception and are then
21614mapped to a Posix signal. Use this command to turn on trapping of
21615Mach exceptions in the inferior. This might be sometimes useful to
21616better understand the cause of a fault. The default is off.
21617
21618@item show mach-exceptions
21619@kindex show mach-exceptions
21620Show the current state of exceptions trapping.
21621@end table
21622
a64548ea 21623
8e04817f
AC
21624@node Embedded OS
21625@section Embedded Operating Systems
104c1213 21626
8e04817f
AC
21627This section describes configurations involving the debugging of
21628embedded operating systems that are available for several different
21629architectures.
d4f3574e 21630
8e04817f
AC
21631@value{GDBN} includes the ability to debug programs running on
21632various real-time operating systems.
104c1213 21633
6d2ebf8b 21634@node Embedded Processors
104c1213
JM
21635@section Embedded Processors
21636
21637This section goes into details specific to particular embedded
21638configurations.
21639
c45da7e6
EZ
21640@cindex send command to simulator
21641Whenever a specific embedded processor has a simulator, @value{GDBN}
21642allows to send an arbitrary command to the simulator.
21643
21644@table @code
21645@item sim @var{command}
21646@kindex sim@r{, a command}
21647Send an arbitrary @var{command} string to the simulator. Consult the
21648documentation for the specific simulator in use for information about
21649acceptable commands.
21650@end table
21651
7d86b5d5 21652
104c1213 21653@menu
bb615428
PA
21654* ARM:: ARM
21655* M32R/SDI:: Renesas M32R/SDI
104c1213 21656* M68K:: Motorola M68K
08be9d71 21657* MicroBlaze:: Xilinx MicroBlaze
104c1213 21658* MIPS Embedded:: MIPS Embedded
4acd40f3 21659* PowerPC Embedded:: PowerPC Embedded
a64548ea
EZ
21660* AVR:: Atmel AVR
21661* CRIS:: CRIS
21662* Super-H:: Renesas Super-H
104c1213
JM
21663@end menu
21664
6d2ebf8b 21665@node ARM
104c1213 21666@subsection ARM
8e04817f 21667
e2f4edfd
EZ
21668@value{GDBN} provides the following ARM-specific commands:
21669
21670@table @code
21671@item set arm disassembler
21672@kindex set arm
21673This commands selects from a list of disassembly styles. The
21674@code{"std"} style is the standard style.
21675
21676@item show arm disassembler
21677@kindex show arm
21678Show the current disassembly style.
21679
21680@item set arm apcs32
21681@cindex ARM 32-bit mode
21682This command toggles ARM operation mode between 32-bit and 26-bit.
21683
21684@item show arm apcs32
21685Display the current usage of the ARM 32-bit mode.
21686
21687@item set arm fpu @var{fputype}
21688This command sets the ARM floating-point unit (FPU) type. The
21689argument @var{fputype} can be one of these:
21690
21691@table @code
21692@item auto
21693Determine the FPU type by querying the OS ABI.
21694@item softfpa
21695Software FPU, with mixed-endian doubles on little-endian ARM
21696processors.
21697@item fpa
21698GCC-compiled FPA co-processor.
21699@item softvfp
21700Software FPU with pure-endian doubles.
21701@item vfp
21702VFP co-processor.
21703@end table
21704
21705@item show arm fpu
21706Show the current type of the FPU.
21707
21708@item set arm abi
21709This command forces @value{GDBN} to use the specified ABI.
21710
21711@item show arm abi
21712Show the currently used ABI.
21713
0428b8f5
DJ
21714@item set arm fallback-mode (arm|thumb|auto)
21715@value{GDBN} uses the symbol table, when available, to determine
21716whether instructions are ARM or Thumb. This command controls
21717@value{GDBN}'s default behavior when the symbol table is not
21718available. The default is @samp{auto}, which causes @value{GDBN} to
21719use the current execution mode (from the @code{T} bit in the @code{CPSR}
21720register).
21721
21722@item show arm fallback-mode
21723Show the current fallback instruction mode.
21724
21725@item set arm force-mode (arm|thumb|auto)
21726This command overrides use of the symbol table to determine whether
21727instructions are ARM or Thumb. The default is @samp{auto}, which
21728causes @value{GDBN} to use the symbol table and then the setting
21729of @samp{set arm fallback-mode}.
21730
21731@item show arm force-mode
21732Show the current forced instruction mode.
21733
e2f4edfd
EZ
21734@item set debug arm
21735Toggle whether to display ARM-specific debugging messages from the ARM
21736target support subsystem.
21737
21738@item show debug arm
21739Show whether ARM-specific debugging messages are enabled.
21740@end table
21741
ee8e71d4
EZ
21742@table @code
21743@item target sim @r{[}@var{simargs}@r{]} @dots{}
21744The @value{GDBN} ARM simulator accepts the following optional arguments.
21745
21746@table @code
21747@item --swi-support=@var{type}
697aa1b7 21748Tell the simulator which SWI interfaces to support. The argument
ee8e71d4
EZ
21749@var{type} may be a comma separated list of the following values.
21750The default value is @code{all}.
21751
21752@table @code
21753@item none
21754@item demon
21755@item angel
21756@item redboot
21757@item all
21758@end table
21759@end table
21760@end table
e2f4edfd 21761
bb615428
PA
21762@node M32R/SDI
21763@subsection Renesas M32R/SDI
8e04817f 21764
ba04e063
EZ
21765The following commands are available for M32R/SDI:
21766
21767@table @code
21768@item sdireset
21769@kindex sdireset
21770@cindex reset SDI connection, M32R
21771This command resets the SDI connection.
21772
21773@item sdistatus
21774@kindex sdistatus
21775This command shows the SDI connection status.
21776
21777@item debug_chaos
21778@kindex debug_chaos
21779@cindex M32R/Chaos debugging
21780Instructs the remote that M32R/Chaos debugging is to be used.
21781
21782@item use_debug_dma
21783@kindex use_debug_dma
21784Instructs the remote to use the DEBUG_DMA method of accessing memory.
21785
21786@item use_mon_code
21787@kindex use_mon_code
21788Instructs the remote to use the MON_CODE method of accessing memory.
21789
21790@item use_ib_break
21791@kindex use_ib_break
21792Instructs the remote to set breakpoints by IB break.
21793
21794@item use_dbt_break
21795@kindex use_dbt_break
21796Instructs the remote to set breakpoints by DBT.
21797@end table
21798
8e04817f
AC
21799@node M68K
21800@subsection M68k
21801
bb615428 21802The Motorola m68k configuration includes ColdFire support.
8e04817f 21803
08be9d71
ME
21804@node MicroBlaze
21805@subsection MicroBlaze
21806@cindex Xilinx MicroBlaze
21807@cindex XMD, Xilinx Microprocessor Debugger
21808
21809The MicroBlaze is a soft-core processor supported on various Xilinx
21810FPGAs, such as Spartan or Virtex series. Boards with these processors
21811usually have JTAG ports which connect to a host system running the Xilinx
21812Embedded Development Kit (EDK) or Software Development Kit (SDK).
21813This host system is used to download the configuration bitstream to
21814the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
21815communicates with the target board using the JTAG interface and
21816presents a @code{gdbserver} interface to the board. By default
21817@code{xmd} uses port @code{1234}. (While it is possible to change
21818this default port, it requires the use of undocumented @code{xmd}
21819commands. Contact Xilinx support if you need to do this.)
21820
21821Use these GDB commands to connect to the MicroBlaze target processor.
21822
21823@table @code
21824@item target remote :1234
21825Use this command to connect to the target if you are running @value{GDBN}
21826on the same system as @code{xmd}.
21827
21828@item target remote @var{xmd-host}:1234
21829Use this command to connect to the target if it is connected to @code{xmd}
21830running on a different system named @var{xmd-host}.
21831
21832@item load
21833Use this command to download a program to the MicroBlaze target.
21834
21835@item set debug microblaze @var{n}
21836Enable MicroBlaze-specific debugging messages if non-zero.
21837
21838@item show debug microblaze @var{n}
21839Show MicroBlaze-specific debugging level.
21840@end table
21841
8e04817f 21842@node MIPS Embedded
eb17f351 21843@subsection @acronym{MIPS} Embedded
8e04817f 21844
eb17f351
EZ
21845@cindex @acronym{MIPS} boards
21846@value{GDBN} can use the @acronym{MIPS} remote debugging protocol to talk to a
21847@acronym{MIPS} board attached to a serial line. This is available when
cc30c4bd 21848you configure @value{GDBN} with @samp{--target=mips-elf}.
104c1213 21849
8e04817f
AC
21850@need 1000
21851Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 21852
8e04817f
AC
21853@table @code
21854@item target mips @var{port}
21855@kindex target mips @var{port}
21856To run a program on the board, start up @code{@value{GDBP}} with the
21857name of your program as the argument. To connect to the board, use the
21858command @samp{target mips @var{port}}, where @var{port} is the name of
21859the serial port connected to the board. If the program has not already
21860been downloaded to the board, you may use the @code{load} command to
21861download it. You can then use all the usual @value{GDBN} commands.
104c1213 21862
8e04817f
AC
21863For example, this sequence connects to the target board through a serial
21864port, and loads and runs a program called @var{prog} through the
21865debugger:
104c1213 21866
474c8240 21867@smallexample
8e04817f
AC
21868host$ @value{GDBP} @var{prog}
21869@value{GDBN} is free software and @dots{}
21870(@value{GDBP}) target mips /dev/ttyb
21871(@value{GDBP}) load @var{prog}
21872(@value{GDBP}) run
474c8240 21873@end smallexample
104c1213 21874
8e04817f
AC
21875@item target mips @var{hostname}:@var{portnumber}
21876On some @value{GDBN} host configurations, you can specify a TCP
21877connection (for instance, to a serial line managed by a terminal
21878concentrator) instead of a serial port, using the syntax
21879@samp{@var{hostname}:@var{portnumber}}.
104c1213 21880
8e04817f
AC
21881@item target pmon @var{port}
21882@kindex target pmon @var{port}
21883PMON ROM monitor.
104c1213 21884
8e04817f
AC
21885@item target ddb @var{port}
21886@kindex target ddb @var{port}
21887NEC's DDB variant of PMON for Vr4300.
104c1213 21888
8e04817f
AC
21889@item target lsi @var{port}
21890@kindex target lsi @var{port}
21891LSI variant of PMON.
104c1213 21892
8e04817f 21893@end table
104c1213 21894
104c1213 21895
8e04817f 21896@noindent
eb17f351 21897@value{GDBN} also supports these special commands for @acronym{MIPS} targets:
104c1213 21898
8e04817f 21899@table @code
8e04817f
AC
21900@item set mipsfpu double
21901@itemx set mipsfpu single
21902@itemx set mipsfpu none
a64548ea 21903@itemx set mipsfpu auto
8e04817f
AC
21904@itemx show mipsfpu
21905@kindex set mipsfpu
21906@kindex show mipsfpu
eb17f351
EZ
21907@cindex @acronym{MIPS} remote floating point
21908@cindex floating point, @acronym{MIPS} remote
21909If your target board does not support the @acronym{MIPS} floating point
8e04817f
AC
21910coprocessor, you should use the command @samp{set mipsfpu none} (if you
21911need this, you may wish to put the command in your @value{GDBN} init
21912file). This tells @value{GDBN} how to find the return value of
21913functions which return floating point values. It also allows
21914@value{GDBN} to avoid saving the floating point registers when calling
21915functions on the board. If you are using a floating point coprocessor
21916with only single precision floating point support, as on the @sc{r4650}
21917processor, use the command @samp{set mipsfpu single}. The default
21918double precision floating point coprocessor may be selected using
21919@samp{set mipsfpu double}.
104c1213 21920
8e04817f
AC
21921In previous versions the only choices were double precision or no
21922floating point, so @samp{set mipsfpu on} will select double precision
21923and @samp{set mipsfpu off} will select no floating point.
104c1213 21924
8e04817f
AC
21925As usual, you can inquire about the @code{mipsfpu} variable with
21926@samp{show mipsfpu}.
104c1213 21927
8e04817f
AC
21928@item set timeout @var{seconds}
21929@itemx set retransmit-timeout @var{seconds}
21930@itemx show timeout
21931@itemx show retransmit-timeout
eb17f351
EZ
21932@cindex @code{timeout}, @acronym{MIPS} protocol
21933@cindex @code{retransmit-timeout}, @acronym{MIPS} protocol
8e04817f
AC
21934@kindex set timeout
21935@kindex show timeout
21936@kindex set retransmit-timeout
21937@kindex show retransmit-timeout
eb17f351 21938You can control the timeout used while waiting for a packet, in the @acronym{MIPS}
8e04817f
AC
21939remote protocol, with the @code{set timeout @var{seconds}} command. The
21940default is 5 seconds. Similarly, you can control the timeout used while
a6f3e723 21941waiting for an acknowledgment of a packet with the @code{set
8e04817f
AC
21942retransmit-timeout @var{seconds}} command. The default is 3 seconds.
21943You can inspect both values with @code{show timeout} and @code{show
21944retransmit-timeout}. (These commands are @emph{only} available when
cc30c4bd 21945@value{GDBN} is configured for @samp{--target=mips-elf}.)
104c1213 21946
8e04817f
AC
21947The timeout set by @code{set timeout} does not apply when @value{GDBN}
21948is waiting for your program to stop. In that case, @value{GDBN} waits
21949forever because it has no way of knowing how long the program is going
21950to run before stopping.
ba04e063
EZ
21951
21952@item set syn-garbage-limit @var{num}
eb17f351
EZ
21953@kindex set syn-garbage-limit@r{, @acronym{MIPS} remote}
21954@cindex synchronize with remote @acronym{MIPS} target
ba04e063
EZ
21955Limit the maximum number of characters @value{GDBN} should ignore when
21956it tries to synchronize with the remote target. The default is 10
21957characters. Setting the limit to -1 means there's no limit.
21958
21959@item show syn-garbage-limit
eb17f351 21960@kindex show syn-garbage-limit@r{, @acronym{MIPS} remote}
ba04e063
EZ
21961Show the current limit on the number of characters to ignore when
21962trying to synchronize with the remote system.
21963
21964@item set monitor-prompt @var{prompt}
eb17f351 21965@kindex set monitor-prompt@r{, @acronym{MIPS} remote}
ba04e063
EZ
21966@cindex remote monitor prompt
21967Tell @value{GDBN} to expect the specified @var{prompt} string from the
21968remote monitor. The default depends on the target:
21969@table @asis
21970@item pmon target
21971@samp{PMON}
21972@item ddb target
21973@samp{NEC010}
21974@item lsi target
21975@samp{PMON>}
21976@end table
21977
21978@item show monitor-prompt
eb17f351 21979@kindex show monitor-prompt@r{, @acronym{MIPS} remote}
ba04e063
EZ
21980Show the current strings @value{GDBN} expects as the prompt from the
21981remote monitor.
21982
21983@item set monitor-warnings
eb17f351 21984@kindex set monitor-warnings@r{, @acronym{MIPS} remote}
ba04e063
EZ
21985Enable or disable monitor warnings about hardware breakpoints. This
21986has effect only for the @code{lsi} target. When on, @value{GDBN} will
21987display warning messages whose codes are returned by the @code{lsi}
21988PMON monitor for breakpoint commands.
21989
21990@item show monitor-warnings
eb17f351 21991@kindex show monitor-warnings@r{, @acronym{MIPS} remote}
ba04e063
EZ
21992Show the current setting of printing monitor warnings.
21993
21994@item pmon @var{command}
eb17f351 21995@kindex pmon@r{, @acronym{MIPS} remote}
ba04e063
EZ
21996@cindex send PMON command
21997This command allows sending an arbitrary @var{command} string to the
21998monitor. The monitor must be in debug mode for this to work.
8e04817f 21999@end table
104c1213 22000
4acd40f3
TJB
22001@node PowerPC Embedded
22002@subsection PowerPC Embedded
104c1213 22003
66b73624
TJB
22004@cindex DVC register
22005@value{GDBN} supports using the DVC (Data Value Compare) register to
22006implement in hardware simple hardware watchpoint conditions of the form:
22007
22008@smallexample
22009(@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
22010 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
22011@end smallexample
22012
e09342b5
TJB
22013The DVC register will be automatically used when @value{GDBN} detects
22014such pattern in a condition expression, and the created watchpoint uses one
22015debug register (either the @code{exact-watchpoints} option is on and the
22016variable is scalar, or the variable has a length of one byte). This feature
22017is available in native @value{GDBN} running on a Linux kernel version 2.6.34
22018or newer.
22019
22020When running on PowerPC embedded processors, @value{GDBN} automatically uses
22021ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
22022in which case watchpoints using only one debug register are created when
22023watching variables of scalar types.
22024
22025You can create an artificial array to watch an arbitrary memory
22026region using one of the following commands (@pxref{Expressions}):
22027
22028@smallexample
22029(@value{GDBP}) watch *((char *) @var{address})@@@var{length}
22030(@value{GDBP}) watch @{char[@var{length}]@} @var{address}
22031@end smallexample
66b73624 22032
9c06b0b4
TJB
22033PowerPC embedded processors support masked watchpoints. See the discussion
22034about the @code{mask} argument in @ref{Set Watchpoints}.
22035
f1310107
TJB
22036@cindex ranged breakpoint
22037PowerPC embedded processors support hardware accelerated
22038@dfn{ranged breakpoints}. A ranged breakpoint stops execution of
22039the inferior whenever it executes an instruction at any address within
22040the range it specifies. To set a ranged breakpoint in @value{GDBN},
22041use the @code{break-range} command.
22042
55eddb0f
DJ
22043@value{GDBN} provides the following PowerPC-specific commands:
22044
104c1213 22045@table @code
f1310107
TJB
22046@kindex break-range
22047@item break-range @var{start-location}, @var{end-location}
697aa1b7
EZ
22048Set a breakpoint for an address range given by
22049@var{start-location} and @var{end-location}, which can specify a function name,
f1310107
TJB
22050a line number, an offset of lines from the current line or from the start
22051location, or an address of an instruction (see @ref{Specify Location},
22052for a list of all the possible ways to specify a @var{location}.)
22053The breakpoint will stop execution of the inferior whenever it
22054executes an instruction at any address within the specified range,
22055(including @var{start-location} and @var{end-location}.)
22056
55eddb0f
DJ
22057@kindex set powerpc
22058@item set powerpc soft-float
22059@itemx show powerpc soft-float
22060Force @value{GDBN} to use (or not use) a software floating point calling
22061convention. By default, @value{GDBN} selects the calling convention based
22062on the selected architecture and the provided executable file.
22063
22064@item set powerpc vector-abi
22065@itemx show powerpc vector-abi
22066Force @value{GDBN} to use the specified calling convention for vector
22067arguments and return values. The valid options are @samp{auto};
22068@samp{generic}, to avoid vector registers even if they are present;
22069@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
22070registers. By default, @value{GDBN} selects the calling convention
22071based on the selected architecture and the provided executable file.
22072
e09342b5
TJB
22073@item set powerpc exact-watchpoints
22074@itemx show powerpc exact-watchpoints
22075Allow @value{GDBN} to use only one debug register when watching a variable
22076of scalar type, thus assuming that the variable is accessed through the
22077address of its first byte.
22078
104c1213
JM
22079@end table
22080
a64548ea
EZ
22081@node AVR
22082@subsection Atmel AVR
22083@cindex AVR
22084
22085When configured for debugging the Atmel AVR, @value{GDBN} supports the
22086following AVR-specific commands:
22087
22088@table @code
22089@item info io_registers
22090@kindex info io_registers@r{, AVR}
22091@cindex I/O registers (Atmel AVR)
22092This command displays information about the AVR I/O registers. For
22093each register, @value{GDBN} prints its number and value.
22094@end table
22095
22096@node CRIS
22097@subsection CRIS
22098@cindex CRIS
22099
22100When configured for debugging CRIS, @value{GDBN} provides the
22101following CRIS-specific commands:
22102
22103@table @code
22104@item set cris-version @var{ver}
22105@cindex CRIS version
e22e55c9
OF
22106Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
22107The CRIS version affects register names and sizes. This command is useful in
22108case autodetection of the CRIS version fails.
a64548ea
EZ
22109
22110@item show cris-version
22111Show the current CRIS version.
22112
22113@item set cris-dwarf2-cfi
22114@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
22115Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
22116Change to @samp{off} when using @code{gcc-cris} whose version is below
22117@code{R59}.
a64548ea
EZ
22118
22119@item show cris-dwarf2-cfi
22120Show the current state of using DWARF-2 CFI.
e22e55c9
OF
22121
22122@item set cris-mode @var{mode}
22123@cindex CRIS mode
22124Set the current CRIS mode to @var{mode}. It should only be changed when
22125debugging in guru mode, in which case it should be set to
22126@samp{guru} (the default is @samp{normal}).
22127
22128@item show cris-mode
22129Show the current CRIS mode.
a64548ea
EZ
22130@end table
22131
22132@node Super-H
22133@subsection Renesas Super-H
22134@cindex Super-H
22135
22136For the Renesas Super-H processor, @value{GDBN} provides these
22137commands:
22138
22139@table @code
c055b101
CV
22140@item set sh calling-convention @var{convention}
22141@kindex set sh calling-convention
22142Set the calling-convention used when calling functions from @value{GDBN}.
22143Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
22144With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
22145convention. If the DWARF-2 information of the called function specifies
22146that the function follows the Renesas calling convention, the function
22147is called using the Renesas calling convention. If the calling convention
22148is set to @samp{renesas}, the Renesas calling convention is always used,
22149regardless of the DWARF-2 information. This can be used to override the
22150default of @samp{gcc} if debug information is missing, or the compiler
22151does not emit the DWARF-2 calling convention entry for a function.
22152
22153@item show sh calling-convention
22154@kindex show sh calling-convention
22155Show the current calling convention setting.
22156
a64548ea
EZ
22157@end table
22158
22159
8e04817f
AC
22160@node Architectures
22161@section Architectures
104c1213 22162
8e04817f
AC
22163This section describes characteristics of architectures that affect
22164all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 22165
8e04817f 22166@menu
430ed3f0 22167* AArch64::
9c16f35a 22168* i386::
8e04817f
AC
22169* Alpha::
22170* MIPS::
a64548ea 22171* HPPA:: HP PA architecture
23d964e7 22172* SPU:: Cell Broadband Engine SPU architecture
4acd40f3 22173* PowerPC::
a1217d97 22174* Nios II::
8e04817f 22175@end menu
104c1213 22176
430ed3f0
MS
22177@node AArch64
22178@subsection AArch64
22179@cindex AArch64 support
22180
22181When @value{GDBN} is debugging the AArch64 architecture, it provides the
22182following special commands:
22183
22184@table @code
22185@item set debug aarch64
22186@kindex set debug aarch64
22187This command determines whether AArch64 architecture-specific debugging
22188messages are to be displayed.
22189
22190@item show debug aarch64
22191Show whether AArch64 debugging messages are displayed.
22192
22193@end table
22194
9c16f35a 22195@node i386
db2e3e2e 22196@subsection x86 Architecture-specific Issues
9c16f35a
EZ
22197
22198@table @code
22199@item set struct-convention @var{mode}
22200@kindex set struct-convention
22201@cindex struct return convention
22202@cindex struct/union returned in registers
22203Set the convention used by the inferior to return @code{struct}s and
22204@code{union}s from functions to @var{mode}. Possible values of
22205@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
22206default). @code{"default"} or @code{"pcc"} means that @code{struct}s
22207are returned on the stack, while @code{"reg"} means that a
22208@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
22209be returned in a register.
22210
22211@item show struct-convention
22212@kindex show struct-convention
22213Show the current setting of the convention to return @code{struct}s
22214from functions.
966f0aef 22215@end table
29c1c244 22216
ca8941bb 22217
bc504a31
PA
22218@subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
22219@cindex Intel Memory Protection Extensions (MPX).
ca8941bb 22220
ca8941bb
WT
22221Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
22222@footnote{The register named with capital letters represent the architecture
22223registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
22224which are the lower bound and upper bound. Bounds are effective addresses or
22225memory locations. The upper bounds are architecturally represented in 1's
22226complement form. A bound having lower bound = 0, and upper bound = 0
22227(1's complement of all bits set) will allow access to the entire address space.
22228
22229@samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
22230through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
22231display the upper bound performing the complement of one operation on the
22232upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
22233@value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
22234can also be noted that the upper bounds are inclusive.
22235
22236As an example, assume that the register BND0 holds bounds for a pointer having
22237access allowed for the range between 0x32 and 0x71. The values present on
22238bnd0raw and bnd registers are presented as follows:
22239
22240@smallexample
22241 bnd0raw = @{0x32, 0xffffffff8e@}
22242 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
22243@end smallexample
22244
22f25c9d
EZ
22245This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
22246change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
22247counterpart. When the bnd0@dots{}bnd3 registers are displayed via
22248Python, the display includes the memory size, in bits, accessible to
22249the pointer.
9c16f35a 22250
29c1c244
WT
22251Bounds can also be stored in bounds tables, which are stored in
22252application memory. These tables store bounds for pointers by specifying
22253the bounds pointer's value along with its bounds. Evaluating and changing
22254bounds located in bound tables is therefore interesting while investigating
22255bugs on MPX context. @value{GDBN} provides commands for this purpose:
22256
966f0aef 22257@table @code
29c1c244
WT
22258@item show mpx bound @var{pointer}
22259@kindex show mpx bound
22260Display bounds of the given @var{pointer}.
22261
22262@item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
22263@kindex set mpx bound
22264Set the bounds of a pointer in the bound table.
22265This command takes three parameters: @var{pointer} is the pointers
22266whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
22267for lower and upper bounds respectively.
22268@end table
22269
8e04817f
AC
22270@node Alpha
22271@subsection Alpha
104c1213 22272
8e04817f 22273See the following section.
104c1213 22274
8e04817f 22275@node MIPS
eb17f351 22276@subsection @acronym{MIPS}
104c1213 22277
8e04817f 22278@cindex stack on Alpha
eb17f351 22279@cindex stack on @acronym{MIPS}
8e04817f 22280@cindex Alpha stack
eb17f351
EZ
22281@cindex @acronym{MIPS} stack
22282Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
8e04817f
AC
22283sometimes requires @value{GDBN} to search backward in the object code to
22284find the beginning of a function.
104c1213 22285
eb17f351 22286@cindex response time, @acronym{MIPS} debugging
8e04817f
AC
22287To improve response time (especially for embedded applications, where
22288@value{GDBN} may be restricted to a slow serial line for this search)
22289you may want to limit the size of this search, using one of these
22290commands:
104c1213 22291
8e04817f 22292@table @code
eb17f351 22293@cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
8e04817f
AC
22294@item set heuristic-fence-post @var{limit}
22295Restrict @value{GDBN} to examining at most @var{limit} bytes in its
22296search for the beginning of a function. A value of @var{0} (the
22297default) means there is no limit. However, except for @var{0}, the
22298larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
22299and therefore the longer it takes to run. You should only need to use
22300this command when debugging a stripped executable.
104c1213 22301
8e04817f
AC
22302@item show heuristic-fence-post
22303Display the current limit.
22304@end table
104c1213
JM
22305
22306@noindent
8e04817f 22307These commands are available @emph{only} when @value{GDBN} is configured
eb17f351 22308for debugging programs on Alpha or @acronym{MIPS} processors.
104c1213 22309
eb17f351 22310Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
a64548ea
EZ
22311programs:
22312
22313@table @code
a64548ea
EZ
22314@item set mips abi @var{arg}
22315@kindex set mips abi
eb17f351
EZ
22316@cindex set ABI for @acronym{MIPS}
22317Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
a64548ea
EZ
22318values of @var{arg} are:
22319
22320@table @samp
22321@item auto
22322The default ABI associated with the current binary (this is the
22323default).
22324@item o32
22325@item o64
22326@item n32
22327@item n64
22328@item eabi32
22329@item eabi64
a64548ea
EZ
22330@end table
22331
22332@item show mips abi
22333@kindex show mips abi
eb17f351 22334Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
a64548ea 22335
4cc0665f
MR
22336@item set mips compression @var{arg}
22337@kindex set mips compression
22338@cindex code compression, @acronym{MIPS}
22339Tell @value{GDBN} which @acronym{MIPS} compressed
22340@acronym{ISA, Instruction Set Architecture} encoding is used by the
22341inferior. @value{GDBN} uses this for code disassembly and other
22342internal interpretation purposes. This setting is only referred to
22343when no executable has been associated with the debugging session or
22344the executable does not provide information about the encoding it uses.
22345Otherwise this setting is automatically updated from information
22346provided by the executable.
22347
22348Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
22349The default compressed @acronym{ISA} encoding is @samp{mips16}, as
22350executables containing @acronym{MIPS16} code frequently are not
22351identified as such.
22352
22353This setting is ``sticky''; that is, it retains its value across
22354debugging sessions until reset either explicitly with this command or
22355implicitly from an executable.
22356
22357The compiler and/or assembler typically add symbol table annotations to
22358identify functions compiled for the @acronym{MIPS16} or
22359@acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
22360are present, @value{GDBN} uses them in preference to the global
22361compressed @acronym{ISA} encoding setting.
22362
22363@item show mips compression
22364@kindex show mips compression
22365Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
22366@value{GDBN} to debug the inferior.
22367
a64548ea
EZ
22368@item set mipsfpu
22369@itemx show mipsfpu
22370@xref{MIPS Embedded, set mipsfpu}.
22371
22372@item set mips mask-address @var{arg}
22373@kindex set mips mask-address
eb17f351 22374@cindex @acronym{MIPS} addresses, masking
a64548ea 22375This command determines whether the most-significant 32 bits of 64-bit
eb17f351 22376@acronym{MIPS} addresses are masked off. The argument @var{arg} can be
a64548ea
EZ
22377@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
22378setting, which lets @value{GDBN} determine the correct value.
22379
22380@item show mips mask-address
22381@kindex show mips mask-address
eb17f351 22382Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
a64548ea
EZ
22383not.
22384
22385@item set remote-mips64-transfers-32bit-regs
22386@kindex set remote-mips64-transfers-32bit-regs
eb17f351
EZ
22387This command controls compatibility with 64-bit @acronym{MIPS} targets that
22388transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
a64548ea
EZ
22389that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
22390and 64 bits for other registers, set this option to @samp{on}.
22391
22392@item show remote-mips64-transfers-32bit-regs
22393@kindex show remote-mips64-transfers-32bit-regs
eb17f351 22394Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
a64548ea
EZ
22395
22396@item set debug mips
22397@kindex set debug mips
eb17f351 22398This command turns on and off debugging messages for the @acronym{MIPS}-specific
a64548ea
EZ
22399target code in @value{GDBN}.
22400
22401@item show debug mips
22402@kindex show debug mips
eb17f351 22403Show the current setting of @acronym{MIPS} debugging messages.
a64548ea
EZ
22404@end table
22405
22406
22407@node HPPA
22408@subsection HPPA
22409@cindex HPPA support
22410
d3e8051b 22411When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
22412following special commands:
22413
22414@table @code
22415@item set debug hppa
22416@kindex set debug hppa
db2e3e2e 22417This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
22418messages are to be displayed.
22419
22420@item show debug hppa
22421Show whether HPPA debugging messages are displayed.
22422
22423@item maint print unwind @var{address}
22424@kindex maint print unwind@r{, HPPA}
22425This command displays the contents of the unwind table entry at the
22426given @var{address}.
22427
22428@end table
22429
104c1213 22430
23d964e7
UW
22431@node SPU
22432@subsection Cell Broadband Engine SPU architecture
22433@cindex Cell Broadband Engine
22434@cindex SPU
22435
22436When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
22437it provides the following special commands:
22438
22439@table @code
22440@item info spu event
22441@kindex info spu
22442Display SPU event facility status. Shows current event mask
22443and pending event status.
22444
22445@item info spu signal
22446Display SPU signal notification facility status. Shows pending
22447signal-control word and signal notification mode of both signal
22448notification channels.
22449
22450@item info spu mailbox
22451Display SPU mailbox facility status. Shows all pending entries,
22452in order of processing, in each of the SPU Write Outbound,
22453SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
22454
22455@item info spu dma
22456Display MFC DMA status. Shows all pending commands in the MFC
22457DMA queue. For each entry, opcode, tag, class IDs, effective
22458and local store addresses and transfer size are shown.
22459
22460@item info spu proxydma
22461Display MFC Proxy-DMA status. Shows all pending commands in the MFC
22462Proxy-DMA queue. For each entry, opcode, tag, class IDs, effective
22463and local store addresses and transfer size are shown.
22464
22465@end table
22466
3285f3fe
UW
22467When @value{GDBN} is debugging a combined PowerPC/SPU application
22468on the Cell Broadband Engine, it provides in addition the following
22469special commands:
22470
22471@table @code
22472@item set spu stop-on-load @var{arg}
22473@kindex set spu
22474Set whether to stop for new SPE threads. When set to @code{on}, @value{GDBN}
22475will give control to the user when a new SPE thread enters its @code{main}
22476function. The default is @code{off}.
22477
22478@item show spu stop-on-load
22479@kindex show spu
22480Show whether to stop for new SPE threads.
22481
ff1a52c6
UW
22482@item set spu auto-flush-cache @var{arg}
22483Set whether to automatically flush the software-managed cache. When set to
22484@code{on}, @value{GDBN} will automatically cause the SPE software-managed
22485cache to be flushed whenever SPE execution stops. This provides a consistent
22486view of PowerPC memory that is accessed via the cache. If an application
22487does not use the software-managed cache, this option has no effect.
22488
22489@item show spu auto-flush-cache
22490Show whether to automatically flush the software-managed cache.
22491
3285f3fe
UW
22492@end table
22493
4acd40f3
TJB
22494@node PowerPC
22495@subsection PowerPC
22496@cindex PowerPC architecture
22497
22498When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
22499pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
22500numbers stored in the floating point registers. These values must be stored
22501in two consecutive registers, always starting at an even register like
22502@code{f0} or @code{f2}.
22503
22504The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
22505by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
22506@code{f2} and @code{f3} for @code{$dl1} and so on.
22507
aeac0ff9 22508For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
677c5bb1
LM
22509wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
22510
a1217d97
SL
22511@node Nios II
22512@subsection Nios II
22513@cindex Nios II architecture
22514
22515When @value{GDBN} is debugging the Nios II architecture,
22516it provides the following special commands:
22517
22518@table @code
22519
22520@item set debug nios2
22521@kindex set debug nios2
22522This command turns on and off debugging messages for the Nios II
22523target code in @value{GDBN}.
22524
22525@item show debug nios2
22526@kindex show debug nios2
22527Show the current setting of Nios II debugging messages.
22528@end table
23d964e7 22529
8e04817f
AC
22530@node Controlling GDB
22531@chapter Controlling @value{GDBN}
22532
22533You can alter the way @value{GDBN} interacts with you by using the
22534@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 22535data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
22536described here.
22537
22538@menu
22539* Prompt:: Prompt
22540* Editing:: Command editing
d620b259 22541* Command History:: Command history
8e04817f
AC
22542* Screen Size:: Screen size
22543* Numbers:: Numbers
1e698235 22544* ABI:: Configuring the current ABI
bf88dd68 22545* Auto-loading:: Automatically loading associated files
8e04817f
AC
22546* Messages/Warnings:: Optional warnings and messages
22547* Debugging Output:: Optional messages about internal happenings
14fb1bac 22548* Other Misc Settings:: Other Miscellaneous Settings
8e04817f
AC
22549@end menu
22550
22551@node Prompt
22552@section Prompt
104c1213 22553
8e04817f 22554@cindex prompt
104c1213 22555
8e04817f
AC
22556@value{GDBN} indicates its readiness to read a command by printing a string
22557called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
22558can change the prompt string with the @code{set prompt} command. For
22559instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
22560the prompt in one of the @value{GDBN} sessions so that you can always tell
22561which one you are talking to.
104c1213 22562
8e04817f
AC
22563@emph{Note:} @code{set prompt} does not add a space for you after the
22564prompt you set. This allows you to set a prompt which ends in a space
22565or a prompt that does not.
104c1213 22566
8e04817f
AC
22567@table @code
22568@kindex set prompt
22569@item set prompt @var{newprompt}
22570Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 22571
8e04817f
AC
22572@kindex show prompt
22573@item show prompt
22574Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
22575@end table
22576
fa3a4f15
PM
22577Versions of @value{GDBN} that ship with Python scripting enabled have
22578prompt extensions. The commands for interacting with these extensions
22579are:
22580
22581@table @code
22582@kindex set extended-prompt
22583@item set extended-prompt @var{prompt}
22584Set an extended prompt that allows for substitutions.
22585@xref{gdb.prompt}, for a list of escape sequences that can be used for
22586substitution. Any escape sequences specified as part of the prompt
22587string are replaced with the corresponding strings each time the prompt
22588is displayed.
22589
22590For example:
22591
22592@smallexample
22593set extended-prompt Current working directory: \w (gdb)
22594@end smallexample
22595
22596Note that when an extended-prompt is set, it takes control of the
22597@var{prompt_hook} hook. @xref{prompt_hook}, for further information.
22598
22599@kindex show extended-prompt
22600@item show extended-prompt
22601Prints the extended prompt. Any escape sequences specified as part of
22602the prompt string with @code{set extended-prompt}, are replaced with the
22603corresponding strings each time the prompt is displayed.
22604@end table
22605
8e04817f 22606@node Editing
79a6e687 22607@section Command Editing
8e04817f
AC
22608@cindex readline
22609@cindex command line editing
104c1213 22610
703663ab 22611@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
22612@sc{gnu} library provides consistent behavior for programs which provide a
22613command line interface to the user. Advantages are @sc{gnu} Emacs-style
22614or @dfn{vi}-style inline editing of commands, @code{csh}-like history
22615substitution, and a storage and recall of command history across
22616debugging sessions.
104c1213 22617
8e04817f
AC
22618You may control the behavior of command line editing in @value{GDBN} with the
22619command @code{set}.
104c1213 22620
8e04817f
AC
22621@table @code
22622@kindex set editing
22623@cindex editing
22624@item set editing
22625@itemx set editing on
22626Enable command line editing (enabled by default).
104c1213 22627
8e04817f
AC
22628@item set editing off
22629Disable command line editing.
104c1213 22630
8e04817f
AC
22631@kindex show editing
22632@item show editing
22633Show whether command line editing is enabled.
104c1213
JM
22634@end table
22635
39037522
TT
22636@ifset SYSTEM_READLINE
22637@xref{Command Line Editing, , , rluserman, GNU Readline Library},
22638@end ifset
22639@ifclear SYSTEM_READLINE
22640@xref{Command Line Editing},
22641@end ifclear
22642for more details about the Readline
703663ab
EZ
22643interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
22644encouraged to read that chapter.
22645
d620b259 22646@node Command History
79a6e687 22647@section Command History
703663ab 22648@cindex command history
8e04817f
AC
22649
22650@value{GDBN} can keep track of the commands you type during your
22651debugging sessions, so that you can be certain of precisely what
22652happened. Use these commands to manage the @value{GDBN} command
22653history facility.
104c1213 22654
703663ab 22655@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
39037522
TT
22656package, to provide the history facility.
22657@ifset SYSTEM_READLINE
22658@xref{Using History Interactively, , , history, GNU History Library},
22659@end ifset
22660@ifclear SYSTEM_READLINE
22661@xref{Using History Interactively},
22662@end ifclear
22663for the detailed description of the History library.
703663ab 22664
d620b259 22665To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
22666the state which is seen by users, prefix it with @samp{server }
22667(@pxref{Server Prefix}). This
d620b259
NR
22668means that this command will not affect the command history, nor will it
22669affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
22670pressed on a line by itself.
22671
22672@cindex @code{server}, command prefix
22673The server prefix does not affect the recording of values into the value
22674history; to print a value without recording it into the value history,
22675use the @code{output} command instead of the @code{print} command.
22676
703663ab
EZ
22677Here is the description of @value{GDBN} commands related to command
22678history.
22679
104c1213 22680@table @code
8e04817f
AC
22681@cindex history substitution
22682@cindex history file
22683@kindex set history filename
4644b6e3 22684@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
22685@item set history filename @var{fname}
22686Set the name of the @value{GDBN} command history file to @var{fname}.
22687This is the file where @value{GDBN} reads an initial command history
22688list, and where it writes the command history from this session when it
22689exits. You can access this list through history expansion or through
22690the history command editing characters listed below. This file defaults
22691to the value of the environment variable @code{GDBHISTFILE}, or to
22692@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
22693is not set.
104c1213 22694
9c16f35a
EZ
22695@cindex save command history
22696@kindex set history save
8e04817f
AC
22697@item set history save
22698@itemx set history save on
22699Record command history in a file, whose name may be specified with the
22700@code{set history filename} command. By default, this option is disabled.
104c1213 22701
8e04817f
AC
22702@item set history save off
22703Stop recording command history in a file.
104c1213 22704
8e04817f 22705@cindex history size
9c16f35a 22706@kindex set history size
b58c513b 22707@cindex @env{GDBHISTSIZE}, environment variable
8e04817f 22708@item set history size @var{size}
f81d1120 22709@itemx set history size unlimited
8e04817f 22710Set the number of commands which @value{GDBN} keeps in its history list.
bc460514
PP
22711This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
22712to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
0eacb298
PP
22713are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
22714either a negative number or the empty string, then the number of commands
22715@value{GDBN} keeps in the history list is unlimited.
fc637f04
PP
22716
22717@cindex remove duplicate history
22718@kindex set history remove-duplicates
22719@item set history remove-duplicates @var{count}
22720@itemx set history remove-duplicates unlimited
22721Control the removal of duplicate history entries in the command history list.
22722If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
22723history entries and remove the first entry that is a duplicate of the current
22724entry being added to the command history list. If @var{count} is
22725@code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
22726removal of duplicate history entries is disabled.
22727
22728Only history entries added during the current session are considered for
22729removal. This option is set to 0 by default.
22730
104c1213
JM
22731@end table
22732
8e04817f 22733History expansion assigns special meaning to the character @kbd{!}.
39037522
TT
22734@ifset SYSTEM_READLINE
22735@xref{Event Designators, , , history, GNU History Library},
22736@end ifset
22737@ifclear SYSTEM_READLINE
22738@xref{Event Designators},
22739@end ifclear
22740for more details.
8e04817f 22741
703663ab 22742@cindex history expansion, turn on/off
8e04817f
AC
22743Since @kbd{!} is also the logical not operator in C, history expansion
22744is off by default. If you decide to enable history expansion with the
22745@code{set history expansion on} command, you may sometimes need to
22746follow @kbd{!} (when it is used as logical not, in an expression) with
22747a space or a tab to prevent it from being expanded. The readline
22748history facilities do not attempt substitution on the strings
22749@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
22750
22751The commands to control history expansion are:
104c1213
JM
22752
22753@table @code
8e04817f
AC
22754@item set history expansion on
22755@itemx set history expansion
703663ab 22756@kindex set history expansion
8e04817f 22757Enable history expansion. History expansion is off by default.
104c1213 22758
8e04817f
AC
22759@item set history expansion off
22760Disable history expansion.
104c1213 22761
8e04817f
AC
22762@c @group
22763@kindex show history
22764@item show history
22765@itemx show history filename
22766@itemx show history save
22767@itemx show history size
22768@itemx show history expansion
22769These commands display the state of the @value{GDBN} history parameters.
22770@code{show history} by itself displays all four states.
22771@c @end group
22772@end table
22773
22774@table @code
9c16f35a
EZ
22775@kindex show commands
22776@cindex show last commands
22777@cindex display command history
8e04817f
AC
22778@item show commands
22779Display the last ten commands in the command history.
104c1213 22780
8e04817f
AC
22781@item show commands @var{n}
22782Print ten commands centered on command number @var{n}.
22783
22784@item show commands +
22785Print ten commands just after the commands last printed.
104c1213
JM
22786@end table
22787
8e04817f 22788@node Screen Size
79a6e687 22789@section Screen Size
8e04817f 22790@cindex size of screen
f179cf97
EZ
22791@cindex screen size
22792@cindex pagination
22793@cindex page size
8e04817f 22794@cindex pauses in output
104c1213 22795
8e04817f
AC
22796Certain commands to @value{GDBN} may produce large amounts of
22797information output to the screen. To help you read all of it,
22798@value{GDBN} pauses and asks you for input at the end of each page of
22799output. Type @key{RET} when you want to continue the output, or @kbd{q}
22800to discard the remaining output. Also, the screen width setting
22801determines when to wrap lines of output. Depending on what is being
22802printed, @value{GDBN} tries to break the line at a readable place,
22803rather than simply letting it overflow onto the following line.
22804
22805Normally @value{GDBN} knows the size of the screen from the terminal
22806driver software. For example, on Unix @value{GDBN} uses the termcap data base
22807together with the value of the @code{TERM} environment variable and the
22808@code{stty rows} and @code{stty cols} settings. If this is not correct,
22809you can override it with the @code{set height} and @code{set
22810width} commands:
22811
22812@table @code
22813@kindex set height
22814@kindex set width
22815@kindex show width
22816@kindex show height
22817@item set height @var{lpp}
f81d1120 22818@itemx set height unlimited
8e04817f
AC
22819@itemx show height
22820@itemx set width @var{cpl}
f81d1120 22821@itemx set width unlimited
8e04817f
AC
22822@itemx show width
22823These @code{set} commands specify a screen height of @var{lpp} lines and
22824a screen width of @var{cpl} characters. The associated @code{show}
22825commands display the current settings.
104c1213 22826
f81d1120
PA
22827If you specify a height of either @code{unlimited} or zero lines,
22828@value{GDBN} does not pause during output no matter how long the
22829output is. This is useful if output is to a file or to an editor
22830buffer.
104c1213 22831
f81d1120
PA
22832Likewise, you can specify @samp{set width unlimited} or @samp{set
22833width 0} to prevent @value{GDBN} from wrapping its output.
9c16f35a
EZ
22834
22835@item set pagination on
22836@itemx set pagination off
22837@kindex set pagination
22838Turn the output pagination on or off; the default is on. Turning
f81d1120 22839pagination off is the alternative to @code{set height unlimited}. Note that
7c953934
TT
22840running @value{GDBN} with the @option{--batch} option (@pxref{Mode
22841Options, -batch}) also automatically disables pagination.
9c16f35a
EZ
22842
22843@item show pagination
22844@kindex show pagination
22845Show the current pagination mode.
104c1213
JM
22846@end table
22847
8e04817f
AC
22848@node Numbers
22849@section Numbers
22850@cindex number representation
22851@cindex entering numbers
104c1213 22852
8e04817f
AC
22853You can always enter numbers in octal, decimal, or hexadecimal in
22854@value{GDBN} by the usual conventions: octal numbers begin with
22855@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
22856begin with @samp{0x}. Numbers that neither begin with @samp{0} or
22857@samp{0x}, nor end with a @samp{.} are, by default, entered in base
2285810; likewise, the default display for numbers---when no particular
22859format is specified---is base 10. You can change the default base for
22860both input and output with the commands described below.
104c1213 22861
8e04817f
AC
22862@table @code
22863@kindex set input-radix
22864@item set input-radix @var{base}
22865Set the default base for numeric input. Supported choices
697aa1b7 22866for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 22867specified either unambiguously or using the current input radix; for
8e04817f 22868example, any of
104c1213 22869
8e04817f 22870@smallexample
9c16f35a
EZ
22871set input-radix 012
22872set input-radix 10.
22873set input-radix 0xa
8e04817f 22874@end smallexample
104c1213 22875
8e04817f 22876@noindent
9c16f35a 22877sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
22878leaves the input radix unchanged, no matter what it was, since
22879@samp{10}, being without any leading or trailing signs of its base, is
22880interpreted in the current radix. Thus, if the current radix is 16,
22881@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
22882change the radix.
104c1213 22883
8e04817f
AC
22884@kindex set output-radix
22885@item set output-radix @var{base}
22886Set the default base for numeric display. Supported choices
697aa1b7 22887for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 22888specified either unambiguously or using the current input radix.
104c1213 22889
8e04817f
AC
22890@kindex show input-radix
22891@item show input-radix
22892Display the current default base for numeric input.
104c1213 22893
8e04817f
AC
22894@kindex show output-radix
22895@item show output-radix
22896Display the current default base for numeric display.
9c16f35a
EZ
22897
22898@item set radix @r{[}@var{base}@r{]}
22899@itemx show radix
22900@kindex set radix
22901@kindex show radix
22902These commands set and show the default base for both input and output
22903of numbers. @code{set radix} sets the radix of input and output to
22904the same base; without an argument, it resets the radix back to its
22905default value of 10.
22906
8e04817f 22907@end table
104c1213 22908
1e698235 22909@node ABI
79a6e687 22910@section Configuring the Current ABI
1e698235
DJ
22911
22912@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
22913application automatically. However, sometimes you need to override its
22914conclusions. Use these commands to manage @value{GDBN}'s view of the
22915current ABI.
22916
98b45e30
DJ
22917@cindex OS ABI
22918@kindex set osabi
b4e9345d 22919@kindex show osabi
430ed3f0 22920@cindex Newlib OS ABI and its influence on the longjmp handling
98b45e30
DJ
22921
22922One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 22923system targets, either via remote debugging or native emulation.
98b45e30
DJ
22924@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
22925but you can override its conclusion using the @code{set osabi} command.
22926One example where this is useful is in debugging of binaries which use
22927an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
22928not have the same identifying marks that the standard C library for your
22929platform provides.
22930
430ed3f0
MS
22931When @value{GDBN} is debugging the AArch64 architecture, it provides a
22932``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
22933@code{longjmp} when debugging binaries that use the @sc{newlib} C library.
22934The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
22935
98b45e30
DJ
22936@table @code
22937@item show osabi
22938Show the OS ABI currently in use.
22939
22940@item set osabi
22941With no argument, show the list of registered available OS ABI's.
22942
22943@item set osabi @var{abi}
22944Set the current OS ABI to @var{abi}.
22945@end table
22946
1e698235 22947@cindex float promotion
1e698235
DJ
22948
22949Generally, the way that an argument of type @code{float} is passed to a
22950function depends on whether the function is prototyped. For a prototyped
22951(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
22952according to the architecture's convention for @code{float}. For unprototyped
22953(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
22954@code{double} and then passed.
22955
22956Unfortunately, some forms of debug information do not reliably indicate whether
22957a function is prototyped. If @value{GDBN} calls a function that is not marked
22958as prototyped, it consults @kbd{set coerce-float-to-double}.
22959
22960@table @code
a8f24a35 22961@kindex set coerce-float-to-double
1e698235
DJ
22962@item set coerce-float-to-double
22963@itemx set coerce-float-to-double on
22964Arguments of type @code{float} will be promoted to @code{double} when passed
22965to an unprototyped function. This is the default setting.
22966
22967@item set coerce-float-to-double off
22968Arguments of type @code{float} will be passed directly to unprototyped
22969functions.
9c16f35a
EZ
22970
22971@kindex show coerce-float-to-double
22972@item show coerce-float-to-double
22973Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
22974@end table
22975
f1212245
DJ
22976@kindex set cp-abi
22977@kindex show cp-abi
22978@value{GDBN} needs to know the ABI used for your program's C@t{++}
22979objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
22980used to build your application. @value{GDBN} only fully supports
22981programs with a single C@t{++} ABI; if your program contains code using
22982multiple C@t{++} ABI's or if @value{GDBN} can not identify your
22983program's ABI correctly, you can tell @value{GDBN} which ABI to use.
22984Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
22985before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
22986``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
22987use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
22988``auto''.
22989
22990@table @code
22991@item show cp-abi
22992Show the C@t{++} ABI currently in use.
22993
22994@item set cp-abi
22995With no argument, show the list of supported C@t{++} ABI's.
22996
22997@item set cp-abi @var{abi}
22998@itemx set cp-abi auto
22999Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
23000@end table
23001
bf88dd68
JK
23002@node Auto-loading
23003@section Automatically loading associated files
23004@cindex auto-loading
23005
23006@value{GDBN} sometimes reads files with commands and settings automatically,
23007without being explicitly told so by the user. We call this feature
23008@dfn{auto-loading}. While auto-loading is useful for automatically adapting
23009@value{GDBN} to the needs of your project, it can sometimes produce unexpected
23010results or introduce security risks (e.g., if the file comes from untrusted
23011sources).
23012
71b8c845
DE
23013@menu
23014* Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
23015* libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
23016
23017* Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
23018* Auto-loading verbose mode:: @samp{set/show debug auto-load}
23019@end menu
23020
23021There are various kinds of files @value{GDBN} can automatically load.
23022In addition to these files, @value{GDBN} supports auto-loading code written
23023in various extension languages. @xref{Auto-loading extensions}.
23024
c1668e4e
JK
23025Note that loading of these associated files (including the local @file{.gdbinit}
23026file) requires accordingly configured @code{auto-load safe-path}
23027(@pxref{Auto-loading safe path}).
23028
bf88dd68
JK
23029For these reasons, @value{GDBN} includes commands and options to let you
23030control when to auto-load files and which files should be auto-loaded.
23031
23032@table @code
23033@anchor{set auto-load off}
23034@kindex set auto-load off
23035@item set auto-load off
23036Globally disable loading of all auto-loaded files.
23037You may want to use this command with the @samp{-iex} option
23038(@pxref{Option -init-eval-command}) such as:
23039@smallexample
23040$ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
23041@end smallexample
23042
23043Be aware that system init file (@pxref{System-wide configuration})
23044and init files from your home directory (@pxref{Home Directory Init File})
23045still get read (as they come from generally trusted directories).
23046To prevent @value{GDBN} from auto-loading even those init files, use the
23047@option{-nx} option (@pxref{Mode Options}), in addition to
23048@code{set auto-load no}.
23049
23050@anchor{show auto-load}
23051@kindex show auto-load
23052@item show auto-load
23053Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
23054or disabled.
23055
23056@smallexample
23057(gdb) show auto-load
23058gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
23059libthread-db: Auto-loading of inferior specific libthread_db is on.
1ccacbcd
JK
23060local-gdbinit: Auto-loading of .gdbinit script from current directory
23061 is on.
bf88dd68 23062python-scripts: Auto-loading of Python scripts is on.
bccbefd2 23063safe-path: List of directories from which it is safe to auto-load files
1564a261 23064 is $debugdir:$datadir/auto-load.
7349ff92 23065scripts-directory: List of directories from which to load auto-loaded scripts
1564a261 23066 is $debugdir:$datadir/auto-load.
bf88dd68
JK
23067@end smallexample
23068
23069@anchor{info auto-load}
23070@kindex info auto-load
23071@item info auto-load
23072Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
23073not.
23074
23075@smallexample
23076(gdb) info auto-load
23077gdb-scripts:
23078Loaded Script
23079Yes /home/user/gdb/gdb-gdb.gdb
23080libthread-db: No auto-loaded libthread-db.
1ccacbcd
JK
23081local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
23082 loaded.
bf88dd68
JK
23083python-scripts:
23084Loaded Script
23085Yes /home/user/gdb/gdb-gdb.py
23086@end smallexample
23087@end table
23088
bf88dd68
JK
23089These are @value{GDBN} control commands for the auto-loading:
23090
23091@multitable @columnfractions .5 .5
23092@item @xref{set auto-load off}.
23093@tab Disable auto-loading globally.
23094@item @xref{show auto-load}.
23095@tab Show setting of all kinds of files.
23096@item @xref{info auto-load}.
23097@tab Show state of all kinds of files.
23098@item @xref{set auto-load gdb-scripts}.
23099@tab Control for @value{GDBN} command scripts.
23100@item @xref{show auto-load gdb-scripts}.
23101@tab Show setting of @value{GDBN} command scripts.
23102@item @xref{info auto-load gdb-scripts}.
23103@tab Show state of @value{GDBN} command scripts.
23104@item @xref{set auto-load python-scripts}.
23105@tab Control for @value{GDBN} Python scripts.
23106@item @xref{show auto-load python-scripts}.
23107@tab Show setting of @value{GDBN} Python scripts.
23108@item @xref{info auto-load python-scripts}.
23109@tab Show state of @value{GDBN} Python scripts.
ed3ef339
DE
23110@item @xref{set auto-load guile-scripts}.
23111@tab Control for @value{GDBN} Guile scripts.
23112@item @xref{show auto-load guile-scripts}.
23113@tab Show setting of @value{GDBN} Guile scripts.
23114@item @xref{info auto-load guile-scripts}.
23115@tab Show state of @value{GDBN} Guile scripts.
7349ff92
JK
23116@item @xref{set auto-load scripts-directory}.
23117@tab Control for @value{GDBN} auto-loaded scripts location.
23118@item @xref{show auto-load scripts-directory}.
23119@tab Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
23120@item @xref{add-auto-load-scripts-directory}.
23121@tab Add directory for auto-loaded scripts location list.
bf88dd68
JK
23122@item @xref{set auto-load local-gdbinit}.
23123@tab Control for init file in the current directory.
23124@item @xref{show auto-load local-gdbinit}.
23125@tab Show setting of init file in the current directory.
23126@item @xref{info auto-load local-gdbinit}.
23127@tab Show state of init file in the current directory.
23128@item @xref{set auto-load libthread-db}.
23129@tab Control for thread debugging library.
23130@item @xref{show auto-load libthread-db}.
23131@tab Show setting of thread debugging library.
23132@item @xref{info auto-load libthread-db}.
23133@tab Show state of thread debugging library.
bccbefd2
JK
23134@item @xref{set auto-load safe-path}.
23135@tab Control directories trusted for automatic loading.
23136@item @xref{show auto-load safe-path}.
23137@tab Show directories trusted for automatic loading.
23138@item @xref{add-auto-load-safe-path}.
23139@tab Add directory trusted for automatic loading.
bf88dd68
JK
23140@end multitable
23141
bf88dd68
JK
23142@node Init File in the Current Directory
23143@subsection Automatically loading init file in the current directory
23144@cindex auto-loading init file in the current directory
23145
23146By default, @value{GDBN} reads and executes the canned sequences of commands
23147from init file (if any) in the current working directory,
23148see @ref{Init File in the Current Directory during Startup}.
23149
c1668e4e
JK
23150Note that loading of this local @file{.gdbinit} file also requires accordingly
23151configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
23152
bf88dd68
JK
23153@table @code
23154@anchor{set auto-load local-gdbinit}
23155@kindex set auto-load local-gdbinit
23156@item set auto-load local-gdbinit [on|off]
23157Enable or disable the auto-loading of canned sequences of commands
23158(@pxref{Sequences}) found in init file in the current directory.
23159
23160@anchor{show auto-load local-gdbinit}
23161@kindex show auto-load local-gdbinit
23162@item show auto-load local-gdbinit
23163Show whether auto-loading of canned sequences of commands from init file in the
23164current directory is enabled or disabled.
23165
23166@anchor{info auto-load local-gdbinit}
23167@kindex info auto-load local-gdbinit
23168@item info auto-load local-gdbinit
23169Print whether canned sequences of commands from init file in the
23170current directory have been auto-loaded.
23171@end table
23172
23173@node libthread_db.so.1 file
23174@subsection Automatically loading thread debugging library
23175@cindex auto-loading libthread_db.so.1
23176
23177This feature is currently present only on @sc{gnu}/Linux native hosts.
23178
23179@value{GDBN} reads in some cases thread debugging library from places specific
23180to the inferior (@pxref{set libthread-db-search-path}).
23181
23182The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
23183without checking this @samp{set auto-load libthread-db} switch as system
23184libraries have to be trusted in general. In all other cases of
23185@samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
23186auto-load libthread-db} is enabled before trying to open such thread debugging
23187library.
23188
c1668e4e
JK
23189Note that loading of this debugging library also requires accordingly configured
23190@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
23191
bf88dd68
JK
23192@table @code
23193@anchor{set auto-load libthread-db}
23194@kindex set auto-load libthread-db
23195@item set auto-load libthread-db [on|off]
23196Enable or disable the auto-loading of inferior specific thread debugging library.
23197
23198@anchor{show auto-load libthread-db}
23199@kindex show auto-load libthread-db
23200@item show auto-load libthread-db
23201Show whether auto-loading of inferior specific thread debugging library is
23202enabled or disabled.
23203
23204@anchor{info auto-load libthread-db}
23205@kindex info auto-load libthread-db
23206@item info auto-load libthread-db
23207Print the list of all loaded inferior specific thread debugging libraries and
23208for each such library print list of inferior @var{pid}s using it.
23209@end table
23210
bccbefd2
JK
23211@node Auto-loading safe path
23212@subsection Security restriction for auto-loading
23213@cindex auto-loading safe-path
23214
23215As the files of inferior can come from untrusted source (such as submitted by
23216an application user) @value{GDBN} does not always load any files automatically.
23217@value{GDBN} provides the @samp{set auto-load safe-path} setting to list
23218directories trusted for loading files not explicitly requested by user.
202cbf1c 23219Each directory can also be a shell wildcard pattern.
bccbefd2
JK
23220
23221If the path is not set properly you will see a warning and the file will not
23222get loaded:
23223
23224@smallexample
23225$ ./gdb -q ./gdb
23226Reading symbols from /home/user/gdb/gdb...done.
23227warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
1564a261
JK
23228 declined by your `auto-load safe-path' set
23229 to "$debugdir:$datadir/auto-load".
bccbefd2 23230warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
1564a261
JK
23231 declined by your `auto-load safe-path' set
23232 to "$debugdir:$datadir/auto-load".
bccbefd2
JK
23233@end smallexample
23234
2c91021c
JK
23235@noindent
23236To instruct @value{GDBN} to go ahead and use the init files anyway,
23237invoke @value{GDBN} like this:
23238
23239@smallexample
23240$ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
23241@end smallexample
23242
bccbefd2
JK
23243The list of trusted directories is controlled by the following commands:
23244
23245@table @code
23246@anchor{set auto-load safe-path}
23247@kindex set auto-load safe-path
af2c1515 23248@item set auto-load safe-path @r{[}@var{directories}@r{]}
bccbefd2
JK
23249Set the list of directories (and their subdirectories) trusted for automatic
23250loading and execution of scripts. You can also enter a specific trusted file.
202cbf1c
JK
23251Each directory can also be a shell wildcard pattern; wildcards do not match
23252directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
23253(@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
af2c1515
JK
23254If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
23255its default value as specified during @value{GDBN} compilation.
23256
d9242c17 23257The list of directories uses path separator (@samp{:} on GNU and Unix
bccbefd2
JK
23258systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
23259to the @env{PATH} environment variable.
23260
23261@anchor{show auto-load safe-path}
23262@kindex show auto-load safe-path
23263@item show auto-load safe-path
23264Show the list of directories trusted for automatic loading and execution of
23265scripts.
23266
23267@anchor{add-auto-load-safe-path}
23268@kindex add-auto-load-safe-path
23269@item add-auto-load-safe-path
413b59ae
JK
23270Add an entry (or list of entries) to the list of directories trusted for
23271automatic loading and execution of scripts. Multiple entries may be delimited
23272by the host platform path separator in use.
bccbefd2
JK
23273@end table
23274
7349ff92 23275This variable defaults to what @code{--with-auto-load-dir} has been configured
1564a261
JK
23276to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
23277substitution applies the same as for @ref{set auto-load scripts-directory}.
23278The default @code{set auto-load safe-path} value can be also overriden by
23279@value{GDBN} configuration option @option{--with-auto-load-safe-path}.
6dea1fbd 23280
6dea1fbd
JK
23281Setting this variable to @file{/} disables this security protection,
23282corresponding @value{GDBN} configuration option is
23283@option{--without-auto-load-safe-path}.
bccbefd2
JK
23284This variable is supposed to be set to the system directories writable by the
23285system superuser only. Users can add their source directories in init files in
23286their home directories (@pxref{Home Directory Init File}). See also deprecated
23287init file in the current directory
23288(@pxref{Init File in the Current Directory during Startup}).
23289
23290To force @value{GDBN} to load the files it declined to load in the previous
23291example, you could use one of the following ways:
23292
0511cc75
JK
23293@table @asis
23294@item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
bccbefd2
JK
23295Specify this trusted directory (or a file) as additional component of the list.
23296You have to specify also any existing directories displayed by
23297by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
23298
174bb630 23299@item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
bccbefd2
JK
23300Specify this directory as in the previous case but just for a single
23301@value{GDBN} session.
23302
af2c1515 23303@item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
bccbefd2
JK
23304Disable auto-loading safety for a single @value{GDBN} session.
23305This assumes all the files you debug during this @value{GDBN} session will come
23306from trusted sources.
23307
23308@item @kbd{./configure --without-auto-load-safe-path}
23309During compilation of @value{GDBN} you may disable any auto-loading safety.
23310This assumes all the files you will ever debug with this @value{GDBN} come from
23311trusted sources.
0511cc75 23312@end table
bccbefd2
JK
23313
23314On the other hand you can also explicitly forbid automatic files loading which
23315also suppresses any such warning messages:
23316
0511cc75 23317@table @asis
174bb630 23318@item @kbd{gdb -iex "set auto-load no" @dots{}}
bccbefd2
JK
23319You can use @value{GDBN} command-line option for a single @value{GDBN} session.
23320
0511cc75 23321@item @file{~/.gdbinit}: @samp{set auto-load no}
bccbefd2
JK
23322Disable auto-loading globally for the user
23323(@pxref{Home Directory Init File}). While it is improbable, you could also
23324use system init file instead (@pxref{System-wide configuration}).
0511cc75 23325@end table
bccbefd2
JK
23326
23327This setting applies to the file names as entered by user. If no entry matches
23328@value{GDBN} tries as a last resort to also resolve all the file names into
23329their canonical form (typically resolving symbolic links) and compare the
23330entries again. @value{GDBN} already canonicalizes most of the filenames on its
23331own before starting the comparison so a canonical form of directories is
23332recommended to be entered.
23333
4dc84fd1
JK
23334@node Auto-loading verbose mode
23335@subsection Displaying files tried for auto-load
23336@cindex auto-loading verbose mode
23337
23338For better visibility of all the file locations where you can place scripts to
23339be auto-loaded with inferior --- or to protect yourself against accidental
23340execution of untrusted scripts --- @value{GDBN} provides a feature for printing
23341all the files attempted to be loaded. Both existing and non-existing files may
23342be printed.
23343
23344For example the list of directories from which it is safe to auto-load files
23345(@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
23346may not be too obvious while setting it up.
23347
23348@smallexample
0070f25a 23349(gdb) set debug auto-load on
4dc84fd1
JK
23350(gdb) file ~/src/t/true
23351auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
23352 for objfile "/tmp/true".
23353auto-load: Updating directories of "/usr:/opt".
23354auto-load: Using directory "/usr".
23355auto-load: Using directory "/opt".
23356warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
23357 by your `auto-load safe-path' set to "/usr:/opt".
23358@end smallexample
23359
23360@table @code
23361@anchor{set debug auto-load}
23362@kindex set debug auto-load
23363@item set debug auto-load [on|off]
23364Set whether to print the filenames attempted to be auto-loaded.
23365
23366@anchor{show debug auto-load}
23367@kindex show debug auto-load
23368@item show debug auto-load
23369Show whether printing of the filenames attempted to be auto-loaded is turned
23370on or off.
23371@end table
23372
8e04817f 23373@node Messages/Warnings
79a6e687 23374@section Optional Warnings and Messages
104c1213 23375
9c16f35a
EZ
23376@cindex verbose operation
23377@cindex optional warnings
8e04817f
AC
23378By default, @value{GDBN} is silent about its inner workings. If you are
23379running on a slow machine, you may want to use the @code{set verbose}
23380command. This makes @value{GDBN} tell you when it does a lengthy
23381internal operation, so you will not think it has crashed.
104c1213 23382
8e04817f
AC
23383Currently, the messages controlled by @code{set verbose} are those
23384which announce that the symbol table for a source file is being read;
79a6e687 23385see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 23386
8e04817f
AC
23387@table @code
23388@kindex set verbose
23389@item set verbose on
23390Enables @value{GDBN} output of certain informational messages.
104c1213 23391
8e04817f
AC
23392@item set verbose off
23393Disables @value{GDBN} output of certain informational messages.
104c1213 23394
8e04817f
AC
23395@kindex show verbose
23396@item show verbose
23397Displays whether @code{set verbose} is on or off.
23398@end table
104c1213 23399
8e04817f
AC
23400By default, if @value{GDBN} encounters bugs in the symbol table of an
23401object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
23402find this information useful (@pxref{Symbol Errors, ,Errors Reading
23403Symbol Files}).
104c1213 23404
8e04817f 23405@table @code
104c1213 23406
8e04817f
AC
23407@kindex set complaints
23408@item set complaints @var{limit}
23409Permits @value{GDBN} to output @var{limit} complaints about each type of
23410unusual symbols before becoming silent about the problem. Set
23411@var{limit} to zero to suppress all complaints; set it to a large number
23412to prevent complaints from being suppressed.
104c1213 23413
8e04817f
AC
23414@kindex show complaints
23415@item show complaints
23416Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 23417
8e04817f 23418@end table
104c1213 23419
d837706a 23420@anchor{confirmation requests}
8e04817f
AC
23421By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
23422lot of stupid questions to confirm certain commands. For example, if
23423you try to run a program which is already running:
104c1213 23424
474c8240 23425@smallexample
8e04817f
AC
23426(@value{GDBP}) run
23427The program being debugged has been started already.
23428Start it from the beginning? (y or n)
474c8240 23429@end smallexample
104c1213 23430
8e04817f
AC
23431If you are willing to unflinchingly face the consequences of your own
23432commands, you can disable this ``feature'':
104c1213 23433
8e04817f 23434@table @code
104c1213 23435
8e04817f
AC
23436@kindex set confirm
23437@cindex flinching
23438@cindex confirmation
23439@cindex stupid questions
23440@item set confirm off
7c953934
TT
23441Disables confirmation requests. Note that running @value{GDBN} with
23442the @option{--batch} option (@pxref{Mode Options, -batch}) also
23443automatically disables confirmation requests.
104c1213 23444
8e04817f
AC
23445@item set confirm on
23446Enables confirmation requests (the default).
104c1213 23447
8e04817f
AC
23448@kindex show confirm
23449@item show confirm
23450Displays state of confirmation requests.
23451
23452@end table
104c1213 23453
16026cd7
AS
23454@cindex command tracing
23455If you need to debug user-defined commands or sourced files you may find it
23456useful to enable @dfn{command tracing}. In this mode each command will be
23457printed as it is executed, prefixed with one or more @samp{+} symbols, the
23458quantity denoting the call depth of each command.
23459
23460@table @code
23461@kindex set trace-commands
23462@cindex command scripts, debugging
23463@item set trace-commands on
23464Enable command tracing.
23465@item set trace-commands off
23466Disable command tracing.
23467@item show trace-commands
23468Display the current state of command tracing.
23469@end table
23470
8e04817f 23471@node Debugging Output
79a6e687 23472@section Optional Messages about Internal Happenings
4644b6e3
EZ
23473@cindex optional debugging messages
23474
da316a69
EZ
23475@value{GDBN} has commands that enable optional debugging messages from
23476various @value{GDBN} subsystems; normally these commands are of
23477interest to @value{GDBN} maintainers, or when reporting a bug. This
23478section documents those commands.
23479
104c1213 23480@table @code
a8f24a35
EZ
23481@kindex set exec-done-display
23482@item set exec-done-display
23483Turns on or off the notification of asynchronous commands'
23484completion. When on, @value{GDBN} will print a message when an
23485asynchronous command finishes its execution. The default is off.
23486@kindex show exec-done-display
23487@item show exec-done-display
23488Displays the current setting of asynchronous command completion
23489notification.
4644b6e3 23490@kindex set debug
be9a8770
PA
23491@cindex ARM AArch64
23492@item set debug aarch64
23493Turns on or off display of debugging messages related to ARM AArch64.
23494The default is off.
23495@kindex show debug
23496@item show debug aarch64
23497Displays the current state of displaying debugging messages related to
23498ARM AArch64.
4644b6e3 23499@cindex gdbarch debugging info
a8f24a35 23500@cindex architecture debugging info
8e04817f 23501@item set debug arch
a8f24a35 23502Turns on or off display of gdbarch debugging info. The default is off
8e04817f
AC
23503@item show debug arch
23504Displays the current state of displaying gdbarch debugging info.
9a005eb9
JB
23505@item set debug aix-solib
23506@cindex AIX shared library debugging
23507Control display of debugging messages from the AIX shared library
23508support module. The default is off.
23509@item show debug aix-thread
23510Show the current state of displaying AIX shared library debugging messages.
721c2651
EZ
23511@item set debug aix-thread
23512@cindex AIX threads
23513Display debugging messages about inner workings of the AIX thread
23514module.
23515@item show debug aix-thread
23516Show the current state of AIX thread debugging info display.
900e11f9
JK
23517@item set debug check-physname
23518@cindex physname
23519Check the results of the ``physname'' computation. When reading DWARF
23520debugging information for C@t{++}, @value{GDBN} attempts to compute
23521each entity's name. @value{GDBN} can do this computation in two
23522different ways, depending on exactly what information is present.
23523When enabled, this setting causes @value{GDBN} to compute the names
23524both ways and display any discrepancies.
23525@item show debug check-physname
23526Show the current state of ``physname'' checking.
be9a8770
PA
23527@item set debug coff-pe-read
23528@cindex COFF/PE exported symbols
23529Control display of debugging messages related to reading of COFF/PE
23530exported symbols. The default is off.
23531@item show debug coff-pe-read
23532Displays the current state of displaying debugging messages related to
23533reading of COFF/PE exported symbols.
b4f54984
DE
23534@item set debug dwarf-die
23535@cindex DWARF DIEs
23536Dump DWARF DIEs after they are read in.
d97bc12b
DE
23537The value is the number of nesting levels to print.
23538A value of zero turns off the display.
b4f54984
DE
23539@item show debug dwarf-die
23540Show the current state of DWARF DIE debugging.
27e0867f
DE
23541@item set debug dwarf-line
23542@cindex DWARF Line Tables
23543Turns on or off display of debugging messages related to reading
23544DWARF line tables. The default is 0 (off).
23545A value of 1 provides basic information.
23546A value greater than 1 provides more verbose information.
23547@item show debug dwarf-line
23548Show the current state of DWARF line table debugging.
b4f54984
DE
23549@item set debug dwarf-read
23550@cindex DWARF Reading
45cfd468 23551Turns on or off display of debugging messages related to reading
73be47f5
DE
23552DWARF debug info. The default is 0 (off).
23553A value of 1 provides basic information.
23554A value greater than 1 provides more verbose information.
b4f54984
DE
23555@item show debug dwarf-read
23556Show the current state of DWARF reader debugging.
237fc4c9
PA
23557@item set debug displaced
23558@cindex displaced stepping debugging info
23559Turns on or off display of @value{GDBN} debugging info for the
23560displaced stepping support. The default is off.
23561@item show debug displaced
23562Displays the current state of displaying @value{GDBN} debugging info
23563related to displaced stepping.
8e04817f 23564@item set debug event
4644b6e3 23565@cindex event debugging info
a8f24a35 23566Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 23567default is off.
8e04817f
AC
23568@item show debug event
23569Displays the current state of displaying @value{GDBN} event debugging
23570info.
8e04817f 23571@item set debug expression
4644b6e3 23572@cindex expression debugging info
721c2651
EZ
23573Turns on or off display of debugging info about @value{GDBN}
23574expression parsing. The default is off.
8e04817f 23575@item show debug expression
721c2651
EZ
23576Displays the current state of displaying debugging info about
23577@value{GDBN} expression parsing.
7453dc06 23578@item set debug frame
4644b6e3 23579@cindex frame debugging info
7453dc06
AC
23580Turns on or off display of @value{GDBN} frame debugging info. The
23581default is off.
7453dc06
AC
23582@item show debug frame
23583Displays the current state of displaying @value{GDBN} frame debugging
23584info.
cbe54154
PA
23585@item set debug gnu-nat
23586@cindex @sc{gnu}/Hurd debug messages
23587Turns on or off debugging messages from the @sc{gnu}/Hurd debug support.
23588@item show debug gnu-nat
23589Show the current state of @sc{gnu}/Hurd debugging messages.
30e91e0b
RC
23590@item set debug infrun
23591@cindex inferior debugging info
23592Turns on or off display of @value{GDBN} debugging info for running the inferior.
23593The default is off. @file{infrun.c} contains GDB's runtime state machine used
23594for implementing operations such as single-stepping the inferior.
23595@item show debug infrun
23596Displays the current state of @value{GDBN} inferior debugging.
a255712f
PP
23597@item set debug jit
23598@cindex just-in-time compilation, debugging messages
23599Turns on or off debugging messages from JIT debug support.
23600@item show debug jit
23601Displays the current state of @value{GDBN} JIT debugging.
da316a69
EZ
23602@item set debug lin-lwp
23603@cindex @sc{gnu}/Linux LWP debug messages
23604@cindex Linux lightweight processes
721c2651 23605Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
23606@item show debug lin-lwp
23607Show the current state of Linux LWP debugging messages.
7a6a1731
GB
23608@item set debug linux-namespaces
23609@cindex @sc{gnu}/Linux namespaces debug messages
23610Turns on or off debugging messages from the Linux namespaces debug support.
23611@item show debug linux-namespaces
23612Show the current state of Linux namespaces debugging messages.
be9a8770
PA
23613@item set debug mach-o
23614@cindex Mach-O symbols processing
23615Control display of debugging messages related to Mach-O symbols
23616processing. The default is off.
23617@item show debug mach-o
23618Displays the current state of displaying debugging messages related to
23619reading of COFF/PE exported symbols.
c9b6281a
YQ
23620@item set debug notification
23621@cindex remote async notification debugging info
23622Turns on or off debugging messages about remote async notification.
23623The default is off.
23624@item show debug notification
23625Displays the current state of remote async notification debugging messages.
2b4855ab 23626@item set debug observer
4644b6e3 23627@cindex observer debugging info
2b4855ab
AC
23628Turns on or off display of @value{GDBN} observer debugging. This
23629includes info such as the notification of observable events.
2b4855ab
AC
23630@item show debug observer
23631Displays the current state of observer debugging.
8e04817f 23632@item set debug overload
4644b6e3 23633@cindex C@t{++} overload debugging info
8e04817f 23634Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 23635info. This includes info such as ranking of functions, etc. The default
8e04817f 23636is off.
8e04817f
AC
23637@item show debug overload
23638Displays the current state of displaying @value{GDBN} C@t{++} overload
23639debugging info.
92981e24
TT
23640@cindex expression parser, debugging info
23641@cindex debug expression parser
23642@item set debug parser
23643Turns on or off the display of expression parser debugging output.
23644Internally, this sets the @code{yydebug} variable in the expression
23645parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
23646details. The default is off.
23647@item show debug parser
23648Show the current state of expression parser debugging.
8e04817f
AC
23649@cindex packets, reporting on stdout
23650@cindex serial connections, debugging
605a56cb
DJ
23651@cindex debug remote protocol
23652@cindex remote protocol debugging
23653@cindex display remote packets
8e04817f
AC
23654@item set debug remote
23655Turns on or off display of reports on all packets sent back and forth across
23656the serial line to the remote machine. The info is printed on the
23657@value{GDBN} standard output stream. The default is off.
8e04817f
AC
23658@item show debug remote
23659Displays the state of display of remote packets.
8e04817f
AC
23660@item set debug serial
23661Turns on or off display of @value{GDBN} serial debugging info. The
23662default is off.
8e04817f
AC
23663@item show debug serial
23664Displays the current state of displaying @value{GDBN} serial debugging
23665info.
c45da7e6
EZ
23666@item set debug solib-frv
23667@cindex FR-V shared-library debugging
23668Turns on or off debugging messages for FR-V shared-library code.
23669@item show debug solib-frv
23670Display the current state of FR-V shared-library code debugging
23671messages.
cc485e62
DE
23672@item set debug symbol-lookup
23673@cindex symbol lookup
23674Turns on or off display of debugging messages related to symbol lookup.
23675The default is 0 (off).
23676A value of 1 provides basic information.
23677A value greater than 1 provides more verbose information.
23678@item show debug symbol-lookup
23679Show the current state of symbol lookup debugging messages.
8fb8eb5c
DE
23680@item set debug symfile
23681@cindex symbol file functions
23682Turns on or off display of debugging messages related to symbol file functions.
23683The default is off. @xref{Files}.
23684@item show debug symfile
23685Show the current state of symbol file debugging messages.
45cfd468
DE
23686@item set debug symtab-create
23687@cindex symbol table creation
23688Turns on or off display of debugging messages related to symbol table creation.
db0fec5c
DE
23689The default is 0 (off).
23690A value of 1 provides basic information.
23691A value greater than 1 provides more verbose information.
45cfd468
DE
23692@item show debug symtab-create
23693Show the current state of symbol table creation debugging.
8e04817f 23694@item set debug target
4644b6e3 23695@cindex target debugging info
8e04817f
AC
23696Turns on or off display of @value{GDBN} target debugging info. This info
23697includes what is going on at the target level of GDB, as it happens. The
701b08bb 23698default is 0. Set it to 1 to track events, and to 2 to also track the
3cecbbbe 23699value of large memory transfers.
8e04817f
AC
23700@item show debug target
23701Displays the current state of displaying @value{GDBN} target debugging
23702info.
75feb17d
DJ
23703@item set debug timestamp
23704@cindex timestampping debugging info
23705Turns on or off display of timestamps with @value{GDBN} debugging info.
23706When enabled, seconds and microseconds are displayed before each debugging
23707message.
23708@item show debug timestamp
23709Displays the current state of displaying timestamps with @value{GDBN}
23710debugging info.
f989a1c8 23711@item set debug varobj
4644b6e3 23712@cindex variable object debugging info
8e04817f
AC
23713Turns on or off display of @value{GDBN} variable object debugging
23714info. The default is off.
f989a1c8 23715@item show debug varobj
8e04817f
AC
23716Displays the current state of displaying @value{GDBN} variable object
23717debugging info.
e776119f
DJ
23718@item set debug xml
23719@cindex XML parser debugging
23720Turns on or off debugging messages for built-in XML parsers.
23721@item show debug xml
23722Displays the current state of XML debugging messages.
8e04817f 23723@end table
104c1213 23724
14fb1bac
JB
23725@node Other Misc Settings
23726@section Other Miscellaneous Settings
23727@cindex miscellaneous settings
23728
23729@table @code
23730@kindex set interactive-mode
23731@item set interactive-mode
7bfc9434
JB
23732If @code{on}, forces @value{GDBN} to assume that GDB was started
23733in a terminal. In practice, this means that @value{GDBN} should wait
23734for the user to answer queries generated by commands entered at
23735the command prompt. If @code{off}, forces @value{GDBN} to operate
23736in the opposite mode, and it uses the default answers to all queries.
23737If @code{auto} (the default), @value{GDBN} tries to determine whether
23738its standard input is a terminal, and works in interactive-mode if it
23739is, non-interactively otherwise.
14fb1bac
JB
23740
23741In the vast majority of cases, the debugger should be able to guess
23742correctly which mode should be used. But this setting can be useful
23743in certain specific cases, such as running a MinGW @value{GDBN}
23744inside a cygwin window.
23745
23746@kindex show interactive-mode
23747@item show interactive-mode
23748Displays whether the debugger is operating in interactive mode or not.
23749@end table
23750
d57a3c85
TJB
23751@node Extending GDB
23752@chapter Extending @value{GDBN}
23753@cindex extending GDB
23754
71b8c845
DE
23755@value{GDBN} provides several mechanisms for extension.
23756@value{GDBN} also provides the ability to automatically load
23757extensions when it reads a file for debugging. This allows the
23758user to automatically customize @value{GDBN} for the program
23759being debugged.
d57a3c85 23760
71b8c845
DE
23761@menu
23762* Sequences:: Canned Sequences of @value{GDBN} Commands
23763* Python:: Extending @value{GDBN} using Python
ed3ef339 23764* Guile:: Extending @value{GDBN} using Guile
71b8c845 23765* Auto-loading extensions:: Automatically loading extensions
ed3ef339 23766* Multiple Extension Languages:: Working with multiple extension languages
71b8c845
DE
23767* Aliases:: Creating new spellings of existing commands
23768@end menu
23769
23770To facilitate the use of extension languages, @value{GDBN} is capable
95433b34 23771of evaluating the contents of a file. When doing so, @value{GDBN}
71b8c845 23772can recognize which extension language is being used by looking at
95433b34
JB
23773the filename extension. Files with an unrecognized filename extension
23774are always treated as a @value{GDBN} Command Files.
23775@xref{Command Files,, Command files}.
23776
23777You can control how @value{GDBN} evaluates these files with the following
23778setting:
23779
23780@table @code
23781@kindex set script-extension
23782@kindex show script-extension
23783@item set script-extension off
23784All scripts are always evaluated as @value{GDBN} Command Files.
23785
23786@item set script-extension soft
23787The debugger determines the scripting language based on filename
23788extension. If this scripting language is supported, @value{GDBN}
23789evaluates the script using that language. Otherwise, it evaluates
23790the file as a @value{GDBN} Command File.
23791
23792@item set script-extension strict
23793The debugger determines the scripting language based on filename
23794extension, and evaluates the script using that language. If the
23795language is not supported, then the evaluation fails.
23796
23797@item show script-extension
23798Display the current value of the @code{script-extension} option.
23799
23800@end table
23801
8e04817f 23802@node Sequences
d57a3c85 23803@section Canned Sequences of Commands
104c1213 23804
8e04817f 23805Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 23806Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
23807commands for execution as a unit: user-defined commands and command
23808files.
104c1213 23809
8e04817f 23810@menu
fcc73fe3
EZ
23811* Define:: How to define your own commands
23812* Hooks:: Hooks for user-defined commands
23813* Command Files:: How to write scripts of commands to be stored in a file
23814* Output:: Commands for controlled output
71b8c845 23815* Auto-loading sequences:: Controlling auto-loaded command files
8e04817f 23816@end menu
104c1213 23817
8e04817f 23818@node Define
d57a3c85 23819@subsection User-defined Commands
104c1213 23820
8e04817f 23821@cindex user-defined command
fcc73fe3 23822@cindex arguments, to user-defined commands
8e04817f
AC
23823A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
23824which you assign a new name as a command. This is done with the
23825@code{define} command. User commands may accept up to 10 arguments
23826separated by whitespace. Arguments are accessed within the user command
c03c782f 23827via @code{$arg0@dots{}$arg9}. A trivial example:
104c1213 23828
8e04817f
AC
23829@smallexample
23830define adder
23831 print $arg0 + $arg1 + $arg2
c03c782f 23832end
8e04817f 23833@end smallexample
104c1213
JM
23834
23835@noindent
8e04817f 23836To execute the command use:
104c1213 23837
8e04817f
AC
23838@smallexample
23839adder 1 2 3
23840@end smallexample
104c1213 23841
8e04817f
AC
23842@noindent
23843This defines the command @code{adder}, which prints the sum of
23844its three arguments. Note the arguments are text substitutions, so they may
23845reference variables, use complex expressions, or even perform inferior
23846functions calls.
104c1213 23847
fcc73fe3
EZ
23848@cindex argument count in user-defined commands
23849@cindex how many arguments (user-defined commands)
c03c782f
AS
23850In addition, @code{$argc} may be used to find out how many arguments have
23851been passed. This expands to a number in the range 0@dots{}10.
23852
23853@smallexample
23854define adder
23855 if $argc == 2
23856 print $arg0 + $arg1
23857 end
23858 if $argc == 3
23859 print $arg0 + $arg1 + $arg2
23860 end
23861end
23862@end smallexample
23863
104c1213 23864@table @code
104c1213 23865
8e04817f
AC
23866@kindex define
23867@item define @var{commandname}
23868Define a command named @var{commandname}. If there is already a command
23869by that name, you are asked to confirm that you want to redefine it.
697aa1b7 23870The argument @var{commandname} may be a bare command name consisting of letters,
adb483fe
DJ
23871numbers, dashes, and underscores. It may also start with any predefined
23872prefix command. For example, @samp{define target my-target} creates
23873a user-defined @samp{target my-target} command.
104c1213 23874
8e04817f
AC
23875The definition of the command is made up of other @value{GDBN} command lines,
23876which are given following the @code{define} command. The end of these
23877commands is marked by a line containing @code{end}.
104c1213 23878
8e04817f 23879@kindex document
ca91424e 23880@kindex end@r{ (user-defined commands)}
8e04817f
AC
23881@item document @var{commandname}
23882Document the user-defined command @var{commandname}, so that it can be
23883accessed by @code{help}. The command @var{commandname} must already be
23884defined. This command reads lines of documentation just as @code{define}
23885reads the lines of the command definition, ending with @code{end}.
23886After the @code{document} command is finished, @code{help} on command
23887@var{commandname} displays the documentation you have written.
104c1213 23888
8e04817f
AC
23889You may use the @code{document} command again to change the
23890documentation of a command. Redefining the command with @code{define}
23891does not change the documentation.
104c1213 23892
c45da7e6
EZ
23893@kindex dont-repeat
23894@cindex don't repeat command
23895@item dont-repeat
23896Used inside a user-defined command, this tells @value{GDBN} that this
23897command should not be repeated when the user hits @key{RET}
23898(@pxref{Command Syntax, repeat last command}).
23899
8e04817f
AC
23900@kindex help user-defined
23901@item help user-defined
7d74f244
DE
23902List all user-defined commands and all python commands defined in class
23903COMAND_USER. The first line of the documentation or docstring is
23904included (if any).
104c1213 23905
8e04817f
AC
23906@kindex show user
23907@item show user
23908@itemx show user @var{commandname}
23909Display the @value{GDBN} commands used to define @var{commandname} (but
23910not its documentation). If no @var{commandname} is given, display the
23911definitions for all user-defined commands.
7d74f244 23912This does not work for user-defined python commands.
104c1213 23913
fcc73fe3 23914@cindex infinite recursion in user-defined commands
20f01a46
DH
23915@kindex show max-user-call-depth
23916@kindex set max-user-call-depth
23917@item show max-user-call-depth
5ca0cb28
DH
23918@itemx set max-user-call-depth
23919The value of @code{max-user-call-depth} controls how many recursion
3f94c067 23920levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 23921infinite recursion and aborts the command.
7d74f244 23922This does not apply to user-defined python commands.
104c1213
JM
23923@end table
23924
fcc73fe3
EZ
23925In addition to the above commands, user-defined commands frequently
23926use control flow commands, described in @ref{Command Files}.
23927
8e04817f
AC
23928When user-defined commands are executed, the
23929commands of the definition are not printed. An error in any command
23930stops execution of the user-defined command.
104c1213 23931
8e04817f
AC
23932If used interactively, commands that would ask for confirmation proceed
23933without asking when used inside a user-defined command. Many @value{GDBN}
23934commands that normally print messages to say what they are doing omit the
23935messages when used in a user-defined command.
104c1213 23936
8e04817f 23937@node Hooks
d57a3c85 23938@subsection User-defined Command Hooks
8e04817f
AC
23939@cindex command hooks
23940@cindex hooks, for commands
23941@cindex hooks, pre-command
104c1213 23942
8e04817f 23943@kindex hook
8e04817f
AC
23944You may define @dfn{hooks}, which are a special kind of user-defined
23945command. Whenever you run the command @samp{foo}, if the user-defined
23946command @samp{hook-foo} exists, it is executed (with no arguments)
23947before that command.
104c1213 23948
8e04817f
AC
23949@cindex hooks, post-command
23950@kindex hookpost
8e04817f
AC
23951A hook may also be defined which is run after the command you executed.
23952Whenever you run the command @samp{foo}, if the user-defined command
23953@samp{hookpost-foo} exists, it is executed (with no arguments) after
23954that command. Post-execution hooks may exist simultaneously with
23955pre-execution hooks, for the same command.
104c1213 23956
8e04817f 23957It is valid for a hook to call the command which it hooks. If this
9f1c6395 23958occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 23959
8e04817f
AC
23960@c It would be nice if hookpost could be passed a parameter indicating
23961@c if the command it hooks executed properly or not. FIXME!
104c1213 23962
8e04817f
AC
23963@kindex stop@r{, a pseudo-command}
23964In addition, a pseudo-command, @samp{stop} exists. Defining
23965(@samp{hook-stop}) makes the associated commands execute every time
23966execution stops in your program: before breakpoint commands are run,
23967displays are printed, or the stack frame is printed.
104c1213 23968
8e04817f
AC
23969For example, to ignore @code{SIGALRM} signals while
23970single-stepping, but treat them normally during normal execution,
23971you could define:
104c1213 23972
474c8240 23973@smallexample
8e04817f
AC
23974define hook-stop
23975handle SIGALRM nopass
23976end
104c1213 23977
8e04817f
AC
23978define hook-run
23979handle SIGALRM pass
23980end
104c1213 23981
8e04817f 23982define hook-continue
d3e8051b 23983handle SIGALRM pass
8e04817f 23984end
474c8240 23985@end smallexample
104c1213 23986
d3e8051b 23987As a further example, to hook at the beginning and end of the @code{echo}
b383017d 23988command, and to add extra text to the beginning and end of the message,
8e04817f 23989you could define:
104c1213 23990
474c8240 23991@smallexample
8e04817f
AC
23992define hook-echo
23993echo <<<---
23994end
104c1213 23995
8e04817f
AC
23996define hookpost-echo
23997echo --->>>\n
23998end
104c1213 23999
8e04817f
AC
24000(@value{GDBP}) echo Hello World
24001<<<---Hello World--->>>
24002(@value{GDBP})
104c1213 24003
474c8240 24004@end smallexample
104c1213 24005
8e04817f
AC
24006You can define a hook for any single-word command in @value{GDBN}, but
24007not for command aliases; you should define a hook for the basic command
c1468174 24008name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
24009@c FIXME! So how does Joe User discover whether a command is an alias
24010@c or not?
adb483fe
DJ
24011You can hook a multi-word command by adding @code{hook-} or
24012@code{hookpost-} to the last word of the command, e.g.@:
24013@samp{define target hook-remote} to add a hook to @samp{target remote}.
24014
8e04817f
AC
24015If an error occurs during the execution of your hook, execution of
24016@value{GDBN} commands stops and @value{GDBN} issues a prompt
24017(before the command that you actually typed had a chance to run).
104c1213 24018
8e04817f
AC
24019If you try to define a hook which does not match any known command, you
24020get a warning from the @code{define} command.
c906108c 24021
8e04817f 24022@node Command Files
d57a3c85 24023@subsection Command Files
c906108c 24024
8e04817f 24025@cindex command files
fcc73fe3 24026@cindex scripting commands
6fc08d32
EZ
24027A command file for @value{GDBN} is a text file made of lines that are
24028@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
24029also be included. An empty line in a command file does nothing; it
24030does not mean to repeat the last command, as it would from the
24031terminal.
c906108c 24032
6fc08d32 24033You can request the execution of a command file with the @code{source}
95433b34
JB
24034command. Note that the @code{source} command is also used to evaluate
24035scripts that are not Command Files. The exact behavior can be configured
24036using the @code{script-extension} setting.
24037@xref{Extending GDB,, Extending GDB}.
c906108c 24038
8e04817f
AC
24039@table @code
24040@kindex source
ca91424e 24041@cindex execute commands from a file
3f7b2faa 24042@item source [-s] [-v] @var{filename}
8e04817f 24043Execute the command file @var{filename}.
c906108c
SS
24044@end table
24045
fcc73fe3
EZ
24046The lines in a command file are generally executed sequentially,
24047unless the order of execution is changed by one of the
24048@emph{flow-control commands} described below. The commands are not
a71ec265
DH
24049printed as they are executed. An error in any command terminates
24050execution of the command file and control is returned to the console.
c906108c 24051
08001717
DE
24052@value{GDBN} first searches for @var{filename} in the current directory.
24053If the file is not found there, and @var{filename} does not specify a
24054directory, then @value{GDBN} also looks for the file on the source search path
24055(specified with the @samp{directory} command);
24056except that @file{$cdir} is not searched because the compilation directory
24057is not relevant to scripts.
4b505b12 24058
3f7b2faa
DE
24059If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
24060on the search path even if @var{filename} specifies a directory.
24061The search is done by appending @var{filename} to each element of the
24062search path. So, for example, if @var{filename} is @file{mylib/myscript}
24063and the search path contains @file{/home/user} then @value{GDBN} will
24064look for the script @file{/home/user/mylib/myscript}.
24065The search is also done if @var{filename} is an absolute path.
24066For example, if @var{filename} is @file{/tmp/myscript} and
24067the search path contains @file{/home/user} then @value{GDBN} will
24068look for the script @file{/home/user/tmp/myscript}.
24069For DOS-like systems, if @var{filename} contains a drive specification,
24070it is stripped before concatenation. For example, if @var{filename} is
24071@file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
24072will look for the script @file{c:/tmp/myscript}.
24073
16026cd7
AS
24074If @code{-v}, for verbose mode, is given then @value{GDBN} displays
24075each command as it is executed. The option must be given before
24076@var{filename}, and is interpreted as part of the filename anywhere else.
24077
8e04817f
AC
24078Commands that would ask for confirmation if used interactively proceed
24079without asking when used in a command file. Many @value{GDBN} commands that
24080normally print messages to say what they are doing omit the messages
24081when called from command files.
c906108c 24082
8e04817f
AC
24083@value{GDBN} also accepts command input from standard input. In this
24084mode, normal output goes to standard output and error output goes to
24085standard error. Errors in a command file supplied on standard input do
6fc08d32 24086not terminate execution of the command file---execution continues with
8e04817f 24087the next command.
c906108c 24088
474c8240 24089@smallexample
8e04817f 24090gdb < cmds > log 2>&1
474c8240 24091@end smallexample
c906108c 24092
8e04817f
AC
24093(The syntax above will vary depending on the shell used.) This example
24094will execute commands from the file @file{cmds}. All output and errors
24095would be directed to @file{log}.
c906108c 24096
fcc73fe3
EZ
24097Since commands stored on command files tend to be more general than
24098commands typed interactively, they frequently need to deal with
24099complicated situations, such as different or unexpected values of
24100variables and symbols, changes in how the program being debugged is
24101built, etc. @value{GDBN} provides a set of flow-control commands to
24102deal with these complexities. Using these commands, you can write
24103complex scripts that loop over data structures, execute commands
24104conditionally, etc.
24105
24106@table @code
24107@kindex if
24108@kindex else
24109@item if
24110@itemx else
24111This command allows to include in your script conditionally executed
24112commands. The @code{if} command takes a single argument, which is an
24113expression to evaluate. It is followed by a series of commands that
24114are executed only if the expression is true (its value is nonzero).
24115There can then optionally be an @code{else} line, followed by a series
24116of commands that are only executed if the expression was false. The
24117end of the list is marked by a line containing @code{end}.
24118
24119@kindex while
24120@item while
24121This command allows to write loops. Its syntax is similar to
24122@code{if}: the command takes a single argument, which is an expression
24123to evaluate, and must be followed by the commands to execute, one per
24124line, terminated by an @code{end}. These commands are called the
24125@dfn{body} of the loop. The commands in the body of @code{while} are
24126executed repeatedly as long as the expression evaluates to true.
24127
24128@kindex loop_break
24129@item loop_break
24130This command exits the @code{while} loop in whose body it is included.
24131Execution of the script continues after that @code{while}s @code{end}
24132line.
24133
24134@kindex loop_continue
24135@item loop_continue
24136This command skips the execution of the rest of the body of commands
24137in the @code{while} loop in whose body it is included. Execution
24138branches to the beginning of the @code{while} loop, where it evaluates
24139the controlling expression.
ca91424e
EZ
24140
24141@kindex end@r{ (if/else/while commands)}
24142@item end
24143Terminate the block of commands that are the body of @code{if},
24144@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
24145@end table
24146
24147
8e04817f 24148@node Output
d57a3c85 24149@subsection Commands for Controlled Output
c906108c 24150
8e04817f
AC
24151During the execution of a command file or a user-defined command, normal
24152@value{GDBN} output is suppressed; the only output that appears is what is
24153explicitly printed by the commands in the definition. This section
24154describes three commands useful for generating exactly the output you
24155want.
c906108c
SS
24156
24157@table @code
8e04817f
AC
24158@kindex echo
24159@item echo @var{text}
24160@c I do not consider backslash-space a standard C escape sequence
24161@c because it is not in ANSI.
24162Print @var{text}. Nonprinting characters can be included in
24163@var{text} using C escape sequences, such as @samp{\n} to print a
24164newline. @strong{No newline is printed unless you specify one.}
24165In addition to the standard C escape sequences, a backslash followed
24166by a space stands for a space. This is useful for displaying a
24167string with spaces at the beginning or the end, since leading and
24168trailing spaces are otherwise trimmed from all arguments.
24169To print @samp{@w{ }and foo =@w{ }}, use the command
24170@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 24171
8e04817f
AC
24172A backslash at the end of @var{text} can be used, as in C, to continue
24173the command onto subsequent lines. For example,
c906108c 24174
474c8240 24175@smallexample
8e04817f
AC
24176echo This is some text\n\
24177which is continued\n\
24178onto several lines.\n
474c8240 24179@end smallexample
c906108c 24180
8e04817f 24181produces the same output as
c906108c 24182
474c8240 24183@smallexample
8e04817f
AC
24184echo This is some text\n
24185echo which is continued\n
24186echo onto several lines.\n
474c8240 24187@end smallexample
c906108c 24188
8e04817f
AC
24189@kindex output
24190@item output @var{expression}
24191Print the value of @var{expression} and nothing but that value: no
24192newlines, no @samp{$@var{nn} = }. The value is not entered in the
24193value history either. @xref{Expressions, ,Expressions}, for more information
24194on expressions.
c906108c 24195
8e04817f
AC
24196@item output/@var{fmt} @var{expression}
24197Print the value of @var{expression} in format @var{fmt}. You can use
24198the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 24199Formats}, for more information.
c906108c 24200
8e04817f 24201@kindex printf
82160952
EZ
24202@item printf @var{template}, @var{expressions}@dots{}
24203Print the values of one or more @var{expressions} under the control of
24204the string @var{template}. To print several values, make
24205@var{expressions} be a comma-separated list of individual expressions,
24206which may be either numbers or pointers. Their values are printed as
24207specified by @var{template}, exactly as a C program would do by
24208executing the code below:
c906108c 24209
474c8240 24210@smallexample
82160952 24211printf (@var{template}, @var{expressions}@dots{});
474c8240 24212@end smallexample
c906108c 24213
82160952
EZ
24214As in @code{C} @code{printf}, ordinary characters in @var{template}
24215are printed verbatim, while @dfn{conversion specification} introduced
24216by the @samp{%} character cause subsequent @var{expressions} to be
24217evaluated, their values converted and formatted according to type and
24218style information encoded in the conversion specifications, and then
24219printed.
24220
8e04817f 24221For example, you can print two values in hex like this:
c906108c 24222
8e04817f
AC
24223@smallexample
24224printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
24225@end smallexample
c906108c 24226
82160952
EZ
24227@code{printf} supports all the standard @code{C} conversion
24228specifications, including the flags and modifiers between the @samp{%}
24229character and the conversion letter, with the following exceptions:
24230
24231@itemize @bullet
24232@item
24233The argument-ordering modifiers, such as @samp{2$}, are not supported.
24234
24235@item
24236The modifier @samp{*} is not supported for specifying precision or
24237width.
24238
24239@item
24240The @samp{'} flag (for separation of digits into groups according to
24241@code{LC_NUMERIC'}) is not supported.
24242
24243@item
24244The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
24245supported.
24246
24247@item
24248The conversion letter @samp{n} (as in @samp{%n}) is not supported.
24249
24250@item
24251The conversion letters @samp{a} and @samp{A} are not supported.
24252@end itemize
24253
24254@noindent
24255Note that the @samp{ll} type modifier is supported only if the
24256underlying @code{C} implementation used to build @value{GDBN} supports
24257the @code{long long int} type, and the @samp{L} type modifier is
24258supported only if @code{long double} type is available.
24259
24260As in @code{C}, @code{printf} supports simple backslash-escape
24261sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
24262@samp{\a}, and @samp{\f}, that consist of backslash followed by a
24263single character. Octal and hexadecimal escape sequences are not
24264supported.
1a619819
LM
24265
24266Additionally, @code{printf} supports conversion specifications for DFP
0aea4bf3
LM
24267(@dfn{Decimal Floating Point}) types using the following length modifiers
24268together with a floating point specifier.
1a619819
LM
24269letters:
24270
24271@itemize @bullet
24272@item
24273@samp{H} for printing @code{Decimal32} types.
24274
24275@item
24276@samp{D} for printing @code{Decimal64} types.
24277
24278@item
24279@samp{DD} for printing @code{Decimal128} types.
24280@end itemize
24281
24282If the underlying @code{C} implementation used to build @value{GDBN} has
0aea4bf3 24283support for the three length modifiers for DFP types, other modifiers
3b784c4f 24284such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
24285
24286In case there is no such @code{C} support, no additional modifiers will be
24287available and the value will be printed in the standard way.
24288
24289Here's an example of printing DFP types using the above conversion letters:
24290@smallexample
0aea4bf3 24291printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
1a619819
LM
24292@end smallexample
24293
f1421989
HZ
24294@kindex eval
24295@item eval @var{template}, @var{expressions}@dots{}
24296Convert the values of one or more @var{expressions} under the control of
24297the string @var{template} to a command line, and call it.
24298
c906108c
SS
24299@end table
24300
71b8c845
DE
24301@node Auto-loading sequences
24302@subsection Controlling auto-loading native @value{GDBN} scripts
24303@cindex native script auto-loading
24304
24305When a new object file is read (for example, due to the @code{file}
24306command, or because the inferior has loaded a shared library),
24307@value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
24308@xref{Auto-loading extensions}.
24309
24310Auto-loading can be enabled or disabled,
24311and the list of auto-loaded scripts can be printed.
24312
24313@table @code
24314@anchor{set auto-load gdb-scripts}
24315@kindex set auto-load gdb-scripts
24316@item set auto-load gdb-scripts [on|off]
24317Enable or disable the auto-loading of canned sequences of commands scripts.
24318
24319@anchor{show auto-load gdb-scripts}
24320@kindex show auto-load gdb-scripts
24321@item show auto-load gdb-scripts
24322Show whether auto-loading of canned sequences of commands scripts is enabled or
24323disabled.
24324
24325@anchor{info auto-load gdb-scripts}
24326@kindex info auto-load gdb-scripts
24327@cindex print list of auto-loaded canned sequences of commands scripts
24328@item info auto-load gdb-scripts [@var{regexp}]
24329Print the list of all canned sequences of commands scripts that @value{GDBN}
24330auto-loaded.
24331@end table
24332
24333If @var{regexp} is supplied only canned sequences of commands scripts with
24334matching names are printed.
24335
329baa95
DE
24336@c Python docs live in a separate file.
24337@include python.texi
0e3509db 24338
ed3ef339
DE
24339@c Guile docs live in a separate file.
24340@include guile.texi
24341
71b8c845
DE
24342@node Auto-loading extensions
24343@section Auto-loading extensions
24344@cindex auto-loading extensions
24345
24346@value{GDBN} provides two mechanisms for automatically loading extensions
24347when a new object file is read (for example, due to the @code{file}
24348command, or because the inferior has loaded a shared library):
24349@file{@var{objfile}-gdb.@var{ext}} and the @code{.debug_gdb_scripts}
24350section of modern file formats like ELF.
24351
24352@menu
24353* objfile-gdb.ext file: objfile-gdbdotext file. The @file{@var{objfile}-gdb.@var{ext}} file
24354* .debug_gdb_scripts section: dotdebug_gdb_scripts section. The @code{.debug_gdb_scripts} section
24355* Which flavor to choose?::
24356@end menu
24357
24358The auto-loading feature is useful for supplying application-specific
24359debugging commands and features.
24360
24361Auto-loading can be enabled or disabled,
24362and the list of auto-loaded scripts can be printed.
24363See the @samp{auto-loading} section of each extension language
24364for more information.
24365For @value{GDBN} command files see @ref{Auto-loading sequences}.
24366For Python files see @ref{Python Auto-loading}.
24367
24368Note that loading of this script file also requires accordingly configured
24369@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
24370
24371@node objfile-gdbdotext file
24372@subsection The @file{@var{objfile}-gdb.@var{ext}} file
24373@cindex @file{@var{objfile}-gdb.gdb}
24374@cindex @file{@var{objfile}-gdb.py}
24375@cindex @file{@var{objfile}-gdb.scm}
24376
24377When a new object file is read, @value{GDBN} looks for a file named
24378@file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
24379where @var{objfile} is the object file's name and
24380where @var{ext} is the file extension for the extension language:
24381
24382@table @code
24383@item @file{@var{objfile}-gdb.gdb}
24384GDB's own command language
24385@item @file{@var{objfile}-gdb.py}
24386Python
ed3ef339
DE
24387@item @file{@var{objfile}-gdb.scm}
24388Guile
71b8c845
DE
24389@end table
24390
24391@var{script-name} is formed by ensuring that the file name of @var{objfile}
24392is absolute, following all symlinks, and resolving @code{.} and @code{..}
24393components, and appending the @file{-gdb.@var{ext}} suffix.
24394If this file exists and is readable, @value{GDBN} will evaluate it as a
24395script in the specified extension language.
24396
24397If this file does not exist, then @value{GDBN} will look for
24398@var{script-name} file in all of the directories as specified below.
24399
24400Note that loading of these files requires an accordingly configured
24401@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
24402
24403For object files using @file{.exe} suffix @value{GDBN} tries to load first the
24404scripts normally according to its @file{.exe} filename. But if no scripts are
24405found @value{GDBN} also tries script filenames matching the object file without
24406its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
24407is attempted on any platform. This makes the script filenames compatible
24408between Unix and MS-Windows hosts.
24409
24410@table @code
24411@anchor{set auto-load scripts-directory}
24412@kindex set auto-load scripts-directory
24413@item set auto-load scripts-directory @r{[}@var{directories}@r{]}
24414Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
24415may be delimited by the host platform path separator in use
24416(@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
24417
24418Each entry here needs to be covered also by the security setting
24419@code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
24420
24421@anchor{with-auto-load-dir}
24422This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
24423@code{set auto-load safe-path} value can be also overriden by @value{GDBN}
24424configuration option @option{--with-auto-load-dir}.
24425
24426Any reference to @file{$debugdir} will get replaced by
24427@var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
24428reference to @file{$datadir} will get replaced by @var{data-directory} which is
24429determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
24430@file{$datadir} must be placed as a directory component --- either alone or
24431delimited by @file{/} or @file{\} directory separators, depending on the host
24432platform.
24433
24434The list of directories uses path separator (@samp{:} on GNU and Unix
24435systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
24436to the @env{PATH} environment variable.
24437
24438@anchor{show auto-load scripts-directory}
24439@kindex show auto-load scripts-directory
24440@item show auto-load scripts-directory
24441Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
24442
24443@anchor{add-auto-load-scripts-directory}
24444@kindex add-auto-load-scripts-directory
24445@item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
24446Add an entry (or list of entries) to the list of auto-loaded scripts locations.
24447Multiple entries may be delimited by the host platform path separator in use.
71b8c845
DE
24448@end table
24449
24450@value{GDBN} does not track which files it has already auto-loaded this way.
24451@value{GDBN} will load the associated script every time the corresponding
24452@var{objfile} is opened.
24453So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
24454is evaluated more than once.
24455
24456@node dotdebug_gdb_scripts section
24457@subsection The @code{.debug_gdb_scripts} section
24458@cindex @code{.debug_gdb_scripts} section
24459
24460For systems using file formats like ELF and COFF,
24461when @value{GDBN} loads a new object file
24462it will look for a special section named @code{.debug_gdb_scripts}.
9f050062
DE
24463If this section exists, its contents is a list of null-terminated entries
24464specifying scripts to load. Each entry begins with a non-null prefix byte that
24465specifies the kind of entry, typically the extension language and whether the
24466script is in a file or inlined in @code{.debug_gdb_scripts}.
71b8c845 24467
9f050062
DE
24468The following entries are supported:
24469
24470@table @code
24471@item SECTION_SCRIPT_ID_PYTHON_FILE = 1
24472@item SECTION_SCRIPT_ID_SCHEME_FILE = 3
24473@item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
24474@item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
24475@end table
24476
24477@subsubsection Script File Entries
24478
24479If the entry specifies a file, @value{GDBN} will look for the file first
24480in the current directory and then along the source search path
71b8c845
DE
24481(@pxref{Source Path, ,Specifying Source Directories}),
24482except that @file{$cdir} is not searched, since the compilation
24483directory is not relevant to scripts.
24484
9f050062 24485File entries can be placed in section @code{.debug_gdb_scripts} with,
71b8c845
DE
24486for example, this GCC macro for Python scripts.
24487
24488@example
24489/* Note: The "MS" section flags are to remove duplicates. */
24490#define DEFINE_GDB_PY_SCRIPT(script_name) \
24491 asm("\
24492.pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
24493.byte 1 /* Python */\n\
24494.asciz \"" script_name "\"\n\
24495.popsection \n\
24496");
24497@end example
24498
24499@noindent
ed3ef339 24500For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
71b8c845
DE
24501Then one can reference the macro in a header or source file like this:
24502
24503@example
24504DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
24505@end example
24506
24507The script name may include directories if desired.
24508
24509Note that loading of this script file also requires accordingly configured
24510@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
24511
24512If the macro invocation is put in a header, any application or library
24513using this header will get a reference to the specified script,
24514and with the use of @code{"MS"} attributes on the section, the linker
24515will remove duplicates.
24516
9f050062
DE
24517@subsubsection Script Text Entries
24518
24519Script text entries allow to put the executable script in the entry
24520itself instead of loading it from a file.
24521The first line of the entry, everything after the prefix byte and up to
24522the first newline (@code{0xa}) character, is the script name, and must not
24523contain any kind of space character, e.g., spaces or tabs.
24524The rest of the entry, up to the trailing null byte, is the script to
24525execute in the specified language. The name needs to be unique among
24526all script names, as @value{GDBN} executes each script only once based
24527on its name.
24528
24529Here is an example from file @file{py-section-script.c} in the @value{GDBN}
24530testsuite.
24531
24532@example
24533#include "symcat.h"
24534#include "gdb/section-scripts.h"
24535asm(
24536".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
24537".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
24538".ascii \"gdb.inlined-script\\n\"\n"
24539".ascii \"class test_cmd (gdb.Command):\\n\"\n"
24540".ascii \" def __init__ (self):\\n\"\n"
24541".ascii \" super (test_cmd, self).__init__ ("
24542 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
24543".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
24544".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
24545".ascii \"test_cmd ()\\n\"\n"
24546".byte 0\n"
24547".popsection\n"
24548);
24549@end example
24550
24551Loading of inlined scripts requires a properly configured
24552@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
24553The path to specify in @code{auto-load safe-path} is the path of the file
24554containing the @code{.debug_gdb_scripts} section.
24555
71b8c845
DE
24556@node Which flavor to choose?
24557@subsection Which flavor to choose?
24558
24559Given the multiple ways of auto-loading extensions, it might not always
24560be clear which one to choose. This section provides some guidance.
24561
24562@noindent
24563Benefits of the @file{-gdb.@var{ext}} way:
24564
24565@itemize @bullet
24566@item
24567Can be used with file formats that don't support multiple sections.
24568
24569@item
24570Ease of finding scripts for public libraries.
24571
24572Scripts specified in the @code{.debug_gdb_scripts} section are searched for
24573in the source search path.
24574For publicly installed libraries, e.g., @file{libstdc++}, there typically
24575isn't a source directory in which to find the script.
24576
24577@item
24578Doesn't require source code additions.
24579@end itemize
24580
24581@noindent
24582Benefits of the @code{.debug_gdb_scripts} way:
24583
24584@itemize @bullet
24585@item
24586Works with static linking.
24587
24588Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
24589trigger their loading. When an application is statically linked the only
24590objfile available is the executable, and it is cumbersome to attach all the
24591scripts from all the input libraries to the executable's
24592@file{-gdb.@var{ext}} script.
24593
24594@item
24595Works with classes that are entirely inlined.
24596
24597Some classes can be entirely inlined, and thus there may not be an associated
24598shared library to attach a @file{-gdb.@var{ext}} script to.
24599
24600@item
24601Scripts needn't be copied out of the source tree.
24602
24603In some circumstances, apps can be built out of large collections of internal
24604libraries, and the build infrastructure necessary to install the
24605@file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
24606cumbersome. It may be easier to specify the scripts in the
24607@code{.debug_gdb_scripts} section as relative paths, and add a path to the
24608top of the source tree to the source search path.
24609@end itemize
24610
ed3ef339
DE
24611@node Multiple Extension Languages
24612@section Multiple Extension Languages
24613
24614The Guile and Python extension languages do not share any state,
24615and generally do not interfere with each other.
24616There are some things to be aware of, however.
24617
24618@subsection Python comes first
24619
24620Python was @value{GDBN}'s first extension language, and to avoid breaking
24621existing behaviour Python comes first. This is generally solved by the
24622``first one wins'' principle. @value{GDBN} maintains a list of enabled
24623extension languages, and when it makes a call to an extension language,
24624(say to pretty-print a value), it tries each in turn until an extension
24625language indicates it has performed the request (e.g., has returned the
24626pretty-printed form of a value).
24627This extends to errors while performing such requests: If an error happens
24628while, for example, trying to pretty-print an object then the error is
24629reported and any following extension languages are not tried.
24630
5a56e9c5
DE
24631@node Aliases
24632@section Creating new spellings of existing commands
24633@cindex aliases for commands
24634
24635It is often useful to define alternate spellings of existing commands.
24636For example, if a new @value{GDBN} command defined in Python has
24637a long name to type, it is handy to have an abbreviated version of it
24638that involves less typing.
24639
24640@value{GDBN} itself uses aliases. For example @samp{s} is an alias
24641of the @samp{step} command even though it is otherwise an ambiguous
24642abbreviation of other commands like @samp{set} and @samp{show}.
24643
24644Aliases are also used to provide shortened or more common versions
24645of multi-word commands. For example, @value{GDBN} provides the
24646@samp{tty} alias of the @samp{set inferior-tty} command.
24647
24648You can define a new alias with the @samp{alias} command.
24649
24650@table @code
24651
24652@kindex alias
24653@item alias [-a] [--] @var{ALIAS} = @var{COMMAND}
24654
24655@end table
24656
24657@var{ALIAS} specifies the name of the new alias.
24658Each word of @var{ALIAS} must consist of letters, numbers, dashes and
24659underscores.
24660
24661@var{COMMAND} specifies the name of an existing command
24662that is being aliased.
24663
24664The @samp{-a} option specifies that the new alias is an abbreviation
24665of the command. Abbreviations are not shown in command
24666lists displayed by the @samp{help} command.
24667
24668The @samp{--} option specifies the end of options,
24669and is useful when @var{ALIAS} begins with a dash.
24670
24671Here is a simple example showing how to make an abbreviation
24672of a command so that there is less to type.
24673Suppose you were tired of typing @samp{disas}, the current
24674shortest unambiguous abbreviation of the @samp{disassemble} command
24675and you wanted an even shorter version named @samp{di}.
24676The following will accomplish this.
24677
24678@smallexample
24679(gdb) alias -a di = disas
24680@end smallexample
24681
24682Note that aliases are different from user-defined commands.
24683With a user-defined command, you also need to write documentation
24684for it with the @samp{document} command.
24685An alias automatically picks up the documentation of the existing command.
24686
24687Here is an example where we make @samp{elms} an abbreviation of
24688@samp{elements} in the @samp{set print elements} command.
24689This is to show that you can make an abbreviation of any part
24690of a command.
24691
24692@smallexample
24693(gdb) alias -a set print elms = set print elements
24694(gdb) alias -a show print elms = show print elements
24695(gdb) set p elms 20
24696(gdb) show p elms
24697Limit on string chars or array elements to print is 200.
24698@end smallexample
24699
24700Note that if you are defining an alias of a @samp{set} command,
24701and you want to have an alias for the corresponding @samp{show}
24702command, then you need to define the latter separately.
24703
24704Unambiguously abbreviated commands are allowed in @var{COMMAND} and
24705@var{ALIAS}, just as they are normally.
24706
24707@smallexample
24708(gdb) alias -a set pr elms = set p ele
24709@end smallexample
24710
24711Finally, here is an example showing the creation of a one word
24712alias for a more complex command.
24713This creates alias @samp{spe} of the command @samp{set print elements}.
24714
24715@smallexample
24716(gdb) alias spe = set print elements
24717(gdb) spe 20
24718@end smallexample
24719
21c294e6
AC
24720@node Interpreters
24721@chapter Command Interpreters
24722@cindex command interpreters
24723
24724@value{GDBN} supports multiple command interpreters, and some command
24725infrastructure to allow users or user interface writers to switch
24726between interpreters or run commands in other interpreters.
24727
24728@value{GDBN} currently supports two command interpreters, the console
24729interpreter (sometimes called the command-line interpreter or @sc{cli})
24730and the machine interface interpreter (or @sc{gdb/mi}). This manual
24731describes both of these interfaces in great detail.
24732
24733By default, @value{GDBN} will start with the console interpreter.
24734However, the user may choose to start @value{GDBN} with another
24735interpreter by specifying the @option{-i} or @option{--interpreter}
24736startup options. Defined interpreters include:
24737
24738@table @code
24739@item console
24740@cindex console interpreter
24741The traditional console or command-line interpreter. This is the most often
24742used interpreter with @value{GDBN}. With no interpreter specified at runtime,
24743@value{GDBN} will use this interpreter.
24744
24745@item mi
24746@cindex mi interpreter
24747The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
24748by programs wishing to use @value{GDBN} as a backend for a debugger GUI
24749or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
24750Interface}.
24751
24752@item mi2
24753@cindex mi2 interpreter
24754The current @sc{gdb/mi} interface.
24755
24756@item mi1
24757@cindex mi1 interpreter
24758The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
24759
24760@end table
24761
24762@cindex invoke another interpreter
24763The interpreter being used by @value{GDBN} may not be dynamically
24764switched at runtime. Although possible, this could lead to a very
24765precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
24766enters the command "interpreter-set console" in a console view,
24767@value{GDBN} would switch to using the console interpreter, rendering
24768the IDE inoperable!
24769
24770@kindex interpreter-exec
24771Although you may only choose a single interpreter at startup, you may execute
24772commands in any interpreter from the current interpreter using the appropriate
24773command. If you are running the console interpreter, simply use the
24774@code{interpreter-exec} command:
24775
24776@smallexample
24777interpreter-exec mi "-data-list-register-names"
24778@end smallexample
24779
24780@sc{gdb/mi} has a similar command, although it is only available in versions of
24781@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
24782
8e04817f
AC
24783@node TUI
24784@chapter @value{GDBN} Text User Interface
24785@cindex TUI
d0d5df6f 24786@cindex Text User Interface
c906108c 24787
8e04817f
AC
24788@menu
24789* TUI Overview:: TUI overview
24790* TUI Keys:: TUI key bindings
7cf36c78 24791* TUI Single Key Mode:: TUI single key mode
db2e3e2e 24792* TUI Commands:: TUI-specific commands
8e04817f
AC
24793* TUI Configuration:: TUI configuration variables
24794@end menu
c906108c 24795
46ba6afa 24796The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
24797interface which uses the @code{curses} library to show the source
24798file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
24799commands in separate text windows. The TUI mode is supported only
24800on platforms where a suitable version of the @code{curses} library
24801is available.
d0d5df6f 24802
46ba6afa 24803The TUI mode is enabled by default when you invoke @value{GDBN} as
217bff3e 24804@samp{@value{GDBP} -tui}.
46ba6afa 24805You can also switch in and out of TUI mode while @value{GDBN} runs by
a4ea0946 24806using various TUI commands and key bindings, such as @command{tui
bcd8537c 24807enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
a4ea0946 24808@ref{TUI Keys, ,TUI Key Bindings}.
c906108c 24809
8e04817f 24810@node TUI Overview
79a6e687 24811@section TUI Overview
c906108c 24812
46ba6afa 24813In TUI mode, @value{GDBN} can display several text windows:
c906108c 24814
8e04817f
AC
24815@table @emph
24816@item command
24817This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
24818prompt and the @value{GDBN} output. The @value{GDBN} input is still
24819managed using readline.
c906108c 24820
8e04817f
AC
24821@item source
24822The source window shows the source file of the program. The current
46ba6afa 24823line and active breakpoints are displayed in this window.
c906108c 24824
8e04817f
AC
24825@item assembly
24826The assembly window shows the disassembly output of the program.
c906108c 24827
8e04817f 24828@item register
46ba6afa
BW
24829This window shows the processor registers. Registers are highlighted
24830when their values change.
c906108c
SS
24831@end table
24832
269c21fe 24833The source and assembly windows show the current program position
46ba6afa
BW
24834by highlighting the current line and marking it with a @samp{>} marker.
24835Breakpoints are indicated with two markers. The first marker
269c21fe
SC
24836indicates the breakpoint type:
24837
24838@table @code
24839@item B
24840Breakpoint which was hit at least once.
24841
24842@item b
24843Breakpoint which was never hit.
24844
24845@item H
24846Hardware breakpoint which was hit at least once.
24847
24848@item h
24849Hardware breakpoint which was never hit.
269c21fe
SC
24850@end table
24851
24852The second marker indicates whether the breakpoint is enabled or not:
24853
24854@table @code
24855@item +
24856Breakpoint is enabled.
24857
24858@item -
24859Breakpoint is disabled.
269c21fe
SC
24860@end table
24861
46ba6afa
BW
24862The source, assembly and register windows are updated when the current
24863thread changes, when the frame changes, or when the program counter
24864changes.
24865
24866These windows are not all visible at the same time. The command
24867window is always visible. The others can be arranged in several
24868layouts:
c906108c 24869
8e04817f
AC
24870@itemize @bullet
24871@item
46ba6afa 24872source only,
2df3850c 24873
8e04817f 24874@item
46ba6afa 24875assembly only,
8e04817f
AC
24876
24877@item
46ba6afa 24878source and assembly,
8e04817f
AC
24879
24880@item
46ba6afa 24881source and registers, or
c906108c 24882
8e04817f 24883@item
46ba6afa 24884assembly and registers.
8e04817f 24885@end itemize
c906108c 24886
46ba6afa 24887A status line above the command window shows the following information:
b7bb15bc
SC
24888
24889@table @emph
24890@item target
46ba6afa 24891Indicates the current @value{GDBN} target.
b7bb15bc
SC
24892(@pxref{Targets, ,Specifying a Debugging Target}).
24893
24894@item process
46ba6afa 24895Gives the current process or thread number.
b7bb15bc
SC
24896When no process is being debugged, this field is set to @code{No process}.
24897
24898@item function
24899Gives the current function name for the selected frame.
24900The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 24901When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
24902the string @code{??} is displayed.
24903
24904@item line
24905Indicates the current line number for the selected frame.
46ba6afa 24906When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
24907
24908@item pc
24909Indicates the current program counter address.
b7bb15bc
SC
24910@end table
24911
8e04817f
AC
24912@node TUI Keys
24913@section TUI Key Bindings
24914@cindex TUI key bindings
c906108c 24915
8e04817f 24916The TUI installs several key bindings in the readline keymaps
39037522
TT
24917@ifset SYSTEM_READLINE
24918(@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
24919@end ifset
24920@ifclear SYSTEM_READLINE
24921(@pxref{Command Line Editing}).
24922@end ifclear
24923The following key bindings are installed for both TUI mode and the
24924@value{GDBN} standard mode.
c906108c 24925
8e04817f
AC
24926@table @kbd
24927@kindex C-x C-a
24928@item C-x C-a
24929@kindex C-x a
24930@itemx C-x a
24931@kindex C-x A
24932@itemx C-x A
46ba6afa
BW
24933Enter or leave the TUI mode. When leaving the TUI mode,
24934the curses window management stops and @value{GDBN} operates using
24935its standard mode, writing on the terminal directly. When reentering
24936the TUI mode, control is given back to the curses windows.
8e04817f 24937The screen is then refreshed.
c906108c 24938
8e04817f
AC
24939@kindex C-x 1
24940@item C-x 1
24941Use a TUI layout with only one window. The layout will
24942either be @samp{source} or @samp{assembly}. When the TUI mode
24943is not active, it will switch to the TUI mode.
2df3850c 24944
8e04817f 24945Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 24946
8e04817f
AC
24947@kindex C-x 2
24948@item C-x 2
24949Use a TUI layout with at least two windows. When the current
46ba6afa 24950layout already has two windows, the next layout with two windows is used.
8e04817f
AC
24951When a new layout is chosen, one window will always be common to the
24952previous layout and the new one.
c906108c 24953
8e04817f 24954Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 24955
72ffddc9
SC
24956@kindex C-x o
24957@item C-x o
24958Change the active window. The TUI associates several key bindings
46ba6afa 24959(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
24960gives the focus to the next TUI window.
24961
24962Think of it as the Emacs @kbd{C-x o} binding.
24963
7cf36c78
SC
24964@kindex C-x s
24965@item C-x s
46ba6afa
BW
24966Switch in and out of the TUI SingleKey mode that binds single
24967keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c906108c
SS
24968@end table
24969
46ba6afa 24970The following key bindings only work in the TUI mode:
5d161b24 24971
46ba6afa 24972@table @asis
8e04817f 24973@kindex PgUp
46ba6afa 24974@item @key{PgUp}
8e04817f 24975Scroll the active window one page up.
c906108c 24976
8e04817f 24977@kindex PgDn
46ba6afa 24978@item @key{PgDn}
8e04817f 24979Scroll the active window one page down.
c906108c 24980
8e04817f 24981@kindex Up
46ba6afa 24982@item @key{Up}
8e04817f 24983Scroll the active window one line up.
c906108c 24984
8e04817f 24985@kindex Down
46ba6afa 24986@item @key{Down}
8e04817f 24987Scroll the active window one line down.
c906108c 24988
8e04817f 24989@kindex Left
46ba6afa 24990@item @key{Left}
8e04817f 24991Scroll the active window one column left.
c906108c 24992
8e04817f 24993@kindex Right
46ba6afa 24994@item @key{Right}
8e04817f 24995Scroll the active window one column right.
c906108c 24996
8e04817f 24997@kindex C-L
46ba6afa 24998@item @kbd{C-L}
8e04817f 24999Refresh the screen.
8e04817f 25000@end table
c906108c 25001
46ba6afa
BW
25002Because the arrow keys scroll the active window in the TUI mode, they
25003are not available for their normal use by readline unless the command
25004window has the focus. When another window is active, you must use
25005other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
25006and @kbd{C-f} to control the command window.
8e04817f 25007
7cf36c78
SC
25008@node TUI Single Key Mode
25009@section TUI Single Key Mode
25010@cindex TUI single key mode
25011
46ba6afa
BW
25012The TUI also provides a @dfn{SingleKey} mode, which binds several
25013frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
25014switch into this mode, where the following key bindings are used:
7cf36c78
SC
25015
25016@table @kbd
25017@kindex c @r{(SingleKey TUI key)}
25018@item c
25019continue
25020
25021@kindex d @r{(SingleKey TUI key)}
25022@item d
25023down
25024
25025@kindex f @r{(SingleKey TUI key)}
25026@item f
25027finish
25028
25029@kindex n @r{(SingleKey TUI key)}
25030@item n
25031next
25032
25033@kindex q @r{(SingleKey TUI key)}
25034@item q
46ba6afa 25035exit the SingleKey mode.
7cf36c78
SC
25036
25037@kindex r @r{(SingleKey TUI key)}
25038@item r
25039run
25040
25041@kindex s @r{(SingleKey TUI key)}
25042@item s
25043step
25044
25045@kindex u @r{(SingleKey TUI key)}
25046@item u
25047up
25048
25049@kindex v @r{(SingleKey TUI key)}
25050@item v
25051info locals
25052
25053@kindex w @r{(SingleKey TUI key)}
25054@item w
25055where
7cf36c78
SC
25056@end table
25057
25058Other keys temporarily switch to the @value{GDBN} command prompt.
25059The key that was pressed is inserted in the editing buffer so that
25060it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
25061with the TUI SingleKey mode. Once the command is entered the TUI
25062SingleKey mode is restored. The only way to permanently leave
7f9087cb 25063this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78
SC
25064
25065
8e04817f 25066@node TUI Commands
db2e3e2e 25067@section TUI-specific Commands
8e04817f
AC
25068@cindex TUI commands
25069
25070The TUI has specific commands to control the text windows.
46ba6afa
BW
25071These commands are always available, even when @value{GDBN} is not in
25072the TUI mode. When @value{GDBN} is in the standard mode, most
25073of these commands will automatically switch to the TUI mode.
c906108c 25074
ff12863f
PA
25075Note that if @value{GDBN}'s @code{stdout} is not connected to a
25076terminal, or @value{GDBN} has been started with the machine interface
25077interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
25078these commands will fail with an error, because it would not be
25079possible or desirable to enable curses window management.
25080
c906108c 25081@table @code
a4ea0946
AB
25082@item tui enable
25083@kindex tui enable
25084Activate TUI mode. The last active TUI window layout will be used if
25085TUI mode has prevsiouly been used in the current debugging session,
25086otherwise a default layout is used.
25087
25088@item tui disable
25089@kindex tui disable
25090Disable TUI mode, returning to the console interpreter.
25091
3d757584
SC
25092@item info win
25093@kindex info win
25094List and give the size of all displayed windows.
25095
6008fc5f 25096@item layout @var{name}
4644b6e3 25097@kindex layout
6008fc5f
AB
25098Changes which TUI windows are displayed. In each layout the command
25099window is always displayed, the @var{name} parameter controls which
25100additional windows are displayed, and can be any of the following:
25101
25102@table @code
25103@item next
8e04817f 25104Display the next layout.
2df3850c 25105
6008fc5f 25106@item prev
8e04817f 25107Display the previous layout.
c906108c 25108
6008fc5f
AB
25109@item src
25110Display the source and command windows.
c906108c 25111
6008fc5f
AB
25112@item asm
25113Display the assembly and command windows.
c906108c 25114
6008fc5f
AB
25115@item split
25116Display the source, assembly, and command windows.
c906108c 25117
6008fc5f
AB
25118@item regs
25119When in @code{src} layout display the register, source, and command
25120windows. When in @code{asm} or @code{split} layout display the
25121register, assembler, and command windows.
25122@end table
8e04817f 25123
6008fc5f 25124@item focus @var{name}
8e04817f 25125@kindex focus
6008fc5f
AB
25126Changes which TUI window is currently active for scrolling. The
25127@var{name} parameter can be any of the following:
25128
25129@table @code
25130@item next
46ba6afa
BW
25131Make the next window active for scrolling.
25132
6008fc5f 25133@item prev
46ba6afa
BW
25134Make the previous window active for scrolling.
25135
6008fc5f 25136@item src
46ba6afa
BW
25137Make the source window active for scrolling.
25138
6008fc5f 25139@item asm
46ba6afa
BW
25140Make the assembly window active for scrolling.
25141
6008fc5f 25142@item regs
46ba6afa
BW
25143Make the register window active for scrolling.
25144
6008fc5f 25145@item cmd
46ba6afa 25146Make the command window active for scrolling.
6008fc5f 25147@end table
c906108c 25148
8e04817f
AC
25149@item refresh
25150@kindex refresh
7f9087cb 25151Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 25152
51f0e40d 25153@item tui reg @var{group}
6a1b180d 25154@kindex tui reg
51f0e40d
AB
25155Changes the register group displayed in the tui register window to
25156@var{group}. If the register window is not currently displayed this
25157command will cause the register window to be displayed. The list of
25158register groups, as well as their order is target specific. The
25159following groups are available on most targets:
25160@table @code
25161@item next
25162Repeatedly selecting this group will cause the display to cycle
25163through all of the available register groups.
25164
25165@item prev
25166Repeatedly selecting this group will cause the display to cycle
25167through all of the available register groups in the reverse order to
25168@var{next}.
25169
25170@item general
25171Display the general registers.
25172@item float
25173Display the floating point registers.
25174@item system
25175Display the system registers.
25176@item vector
25177Display the vector registers.
25178@item all
25179Display all registers.
25180@end table
6a1b180d 25181
8e04817f
AC
25182@item update
25183@kindex update
25184Update the source window and the current execution point.
c906108c 25185
8e04817f
AC
25186@item winheight @var{name} +@var{count}
25187@itemx winheight @var{name} -@var{count}
25188@kindex winheight
25189Change the height of the window @var{name} by @var{count}
25190lines. Positive counts increase the height, while negative counts
bf555842
EZ
25191decrease it. The @var{name} parameter can be one of @code{src} (the
25192source window), @code{cmd} (the command window), @code{asm} (the
25193disassembly window), or @code{regs} (the register display window).
2df3850c 25194
46ba6afa
BW
25195@item tabset @var{nchars}
25196@kindex tabset
bf555842
EZ
25197Set the width of tab stops to be @var{nchars} characters. This
25198setting affects the display of TAB characters in the source and
25199assembly windows.
c906108c
SS
25200@end table
25201
8e04817f 25202@node TUI Configuration
79a6e687 25203@section TUI Configuration Variables
8e04817f 25204@cindex TUI configuration variables
c906108c 25205
46ba6afa 25206Several configuration variables control the appearance of TUI windows.
c906108c 25207
8e04817f
AC
25208@table @code
25209@item set tui border-kind @var{kind}
25210@kindex set tui border-kind
25211Select the border appearance for the source, assembly and register windows.
25212The possible values are the following:
25213@table @code
25214@item space
25215Use a space character to draw the border.
c906108c 25216
8e04817f 25217@item ascii
46ba6afa 25218Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 25219
8e04817f
AC
25220@item acs
25221Use the Alternate Character Set to draw the border. The border is
25222drawn using character line graphics if the terminal supports them.
8e04817f 25223@end table
c78b4128 25224
8e04817f
AC
25225@item set tui border-mode @var{mode}
25226@kindex set tui border-mode
46ba6afa
BW
25227@itemx set tui active-border-mode @var{mode}
25228@kindex set tui active-border-mode
25229Select the display attributes for the borders of the inactive windows
25230or the active window. The @var{mode} can be one of the following:
8e04817f
AC
25231@table @code
25232@item normal
25233Use normal attributes to display the border.
c906108c 25234
8e04817f
AC
25235@item standout
25236Use standout mode.
c906108c 25237
8e04817f
AC
25238@item reverse
25239Use reverse video mode.
c906108c 25240
8e04817f
AC
25241@item half
25242Use half bright mode.
c906108c 25243
8e04817f
AC
25244@item half-standout
25245Use half bright and standout mode.
c906108c 25246
8e04817f
AC
25247@item bold
25248Use extra bright or bold mode.
c78b4128 25249
8e04817f
AC
25250@item bold-standout
25251Use extra bright or bold and standout mode.
8e04817f 25252@end table
8e04817f 25253@end table
c78b4128 25254
8e04817f
AC
25255@node Emacs
25256@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 25257
8e04817f
AC
25258@cindex Emacs
25259@cindex @sc{gnu} Emacs
25260A special interface allows you to use @sc{gnu} Emacs to view (and
25261edit) the source files for the program you are debugging with
25262@value{GDBN}.
c906108c 25263
8e04817f
AC
25264To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
25265executable file you want to debug as an argument. This command starts
25266@value{GDBN} as a subprocess of Emacs, with input and output through a newly
25267created Emacs buffer.
25268@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 25269
5e252a2e 25270Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 25271things:
c906108c 25272
8e04817f
AC
25273@itemize @bullet
25274@item
5e252a2e
NR
25275All ``terminal'' input and output goes through an Emacs buffer, called
25276the GUD buffer.
c906108c 25277
8e04817f
AC
25278This applies both to @value{GDBN} commands and their output, and to the input
25279and output done by the program you are debugging.
bf0184be 25280
8e04817f
AC
25281This is useful because it means that you can copy the text of previous
25282commands and input them again; you can even use parts of the output
25283in this way.
bf0184be 25284
8e04817f
AC
25285All the facilities of Emacs' Shell mode are available for interacting
25286with your program. In particular, you can send signals the usual
25287way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
25288stop.
bf0184be
ND
25289
25290@item
8e04817f 25291@value{GDBN} displays source code through Emacs.
bf0184be 25292
8e04817f
AC
25293Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
25294source file for that frame and puts an arrow (@samp{=>}) at the
25295left margin of the current line. Emacs uses a separate buffer for
25296source display, and splits the screen to show both your @value{GDBN} session
25297and the source.
bf0184be 25298
8e04817f
AC
25299Explicit @value{GDBN} @code{list} or search commands still produce output as
25300usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
25301@end itemize
25302
25303We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
25304a graphical mode, enabled by default, which provides further buffers
25305that can control the execution and describe the state of your program.
25306@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 25307
64fabec2
AC
25308If you specify an absolute file name when prompted for the @kbd{M-x
25309gdb} argument, then Emacs sets your current working directory to where
25310your program resides. If you only specify the file name, then Emacs
7a9dd1b2 25311sets your current working directory to the directory associated
64fabec2
AC
25312with the previous buffer. In this case, @value{GDBN} may find your
25313program by searching your environment's @code{PATH} variable, but on
25314some operating systems it might not find the source. So, although the
25315@value{GDBN} input and output session proceeds normally, the auxiliary
25316buffer does not display the current source and line of execution.
25317
25318The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
25319line of the GUD buffer and this serves as a default for the commands
25320that specify files for @value{GDBN} to operate on. @xref{Files,
25321,Commands to Specify Files}.
64fabec2
AC
25322
25323By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
25324need to call @value{GDBN} by a different name (for example, if you
25325keep several configurations around, with different names) you can
25326customize the Emacs variable @code{gud-gdb-command-name} to run the
25327one you want.
8e04817f 25328
5e252a2e 25329In the GUD buffer, you can use these special Emacs commands in
8e04817f 25330addition to the standard Shell mode commands:
c906108c 25331
8e04817f
AC
25332@table @kbd
25333@item C-h m
5e252a2e 25334Describe the features of Emacs' GUD Mode.
c906108c 25335
64fabec2 25336@item C-c C-s
8e04817f
AC
25337Execute to another source line, like the @value{GDBN} @code{step} command; also
25338update the display window to show the current file and location.
c906108c 25339
64fabec2 25340@item C-c C-n
8e04817f
AC
25341Execute to next source line in this function, skipping all function
25342calls, like the @value{GDBN} @code{next} command. Then update the display window
25343to show the current file and location.
c906108c 25344
64fabec2 25345@item C-c C-i
8e04817f
AC
25346Execute one instruction, like the @value{GDBN} @code{stepi} command; update
25347display window accordingly.
c906108c 25348
8e04817f
AC
25349@item C-c C-f
25350Execute until exit from the selected stack frame, like the @value{GDBN}
25351@code{finish} command.
c906108c 25352
64fabec2 25353@item C-c C-r
8e04817f
AC
25354Continue execution of your program, like the @value{GDBN} @code{continue}
25355command.
b433d00b 25356
64fabec2 25357@item C-c <
8e04817f
AC
25358Go up the number of frames indicated by the numeric argument
25359(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
25360like the @value{GDBN} @code{up} command.
b433d00b 25361
64fabec2 25362@item C-c >
8e04817f
AC
25363Go down the number of frames indicated by the numeric argument, like the
25364@value{GDBN} @code{down} command.
8e04817f 25365@end table
c906108c 25366
7f9087cb 25367In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 25368tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 25369
5e252a2e
NR
25370In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
25371separate frame which shows a backtrace when the GUD buffer is current.
25372Move point to any frame in the stack and type @key{RET} to make it
25373become the current frame and display the associated source in the
25374source buffer. Alternatively, click @kbd{Mouse-2} to make the
25375selected frame become the current one. In graphical mode, the
25376speedbar displays watch expressions.
64fabec2 25377
8e04817f
AC
25378If you accidentally delete the source-display buffer, an easy way to get
25379it back is to type the command @code{f} in the @value{GDBN} buffer, to
25380request a frame display; when you run under Emacs, this recreates
25381the source buffer if necessary to show you the context of the current
25382frame.
c906108c 25383
8e04817f
AC
25384The source files displayed in Emacs are in ordinary Emacs buffers
25385which are visiting the source files in the usual way. You can edit
25386the files with these buffers if you wish; but keep in mind that @value{GDBN}
25387communicates with Emacs in terms of line numbers. If you add or
25388delete lines from the text, the line numbers that @value{GDBN} knows cease
25389to correspond properly with the code.
b383017d 25390
5e252a2e
NR
25391A more detailed description of Emacs' interaction with @value{GDBN} is
25392given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
25393Emacs Manual}).
c906108c 25394
922fbb7b
AC
25395@node GDB/MI
25396@chapter The @sc{gdb/mi} Interface
25397
25398@unnumberedsec Function and Purpose
25399
25400@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
25401@sc{gdb/mi} is a line based machine oriented text interface to
25402@value{GDBN} and is activated by specifying using the
25403@option{--interpreter} command line option (@pxref{Mode Options}). It
25404is specifically intended to support the development of systems which
25405use the debugger as just one small component of a larger system.
922fbb7b
AC
25406
25407This chapter is a specification of the @sc{gdb/mi} interface. It is written
25408in the form of a reference manual.
25409
25410Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
25411features described below are incomplete and subject to change
25412(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
25413
25414@unnumberedsec Notation and Terminology
25415
25416@cindex notational conventions, for @sc{gdb/mi}
25417This chapter uses the following notation:
25418
25419@itemize @bullet
25420@item
25421@code{|} separates two alternatives.
25422
25423@item
25424@code{[ @var{something} ]} indicates that @var{something} is optional:
25425it may or may not be given.
25426
25427@item
25428@code{( @var{group} )*} means that @var{group} inside the parentheses
25429may repeat zero or more times.
25430
25431@item
25432@code{( @var{group} )+} means that @var{group} inside the parentheses
25433may repeat one or more times.
25434
25435@item
25436@code{"@var{string}"} means a literal @var{string}.
25437@end itemize
25438
25439@ignore
25440@heading Dependencies
25441@end ignore
25442
922fbb7b 25443@menu
c3b108f7 25444* GDB/MI General Design::
922fbb7b
AC
25445* GDB/MI Command Syntax::
25446* GDB/MI Compatibility with CLI::
af6eff6f 25447* GDB/MI Development and Front Ends::
922fbb7b 25448* GDB/MI Output Records::
ef21caaf 25449* GDB/MI Simple Examples::
922fbb7b 25450* GDB/MI Command Description Format::
ef21caaf 25451* GDB/MI Breakpoint Commands::
3fa7bf06 25452* GDB/MI Catchpoint Commands::
a2c02241
NR
25453* GDB/MI Program Context::
25454* GDB/MI Thread Commands::
5d77fe44 25455* GDB/MI Ada Tasking Commands::
a2c02241
NR
25456* GDB/MI Program Execution::
25457* GDB/MI Stack Manipulation::
25458* GDB/MI Variable Objects::
922fbb7b 25459* GDB/MI Data Manipulation::
a2c02241
NR
25460* GDB/MI Tracepoint Commands::
25461* GDB/MI Symbol Query::
351ff01a 25462* GDB/MI File Commands::
922fbb7b
AC
25463@ignore
25464* GDB/MI Kod Commands::
25465* GDB/MI Memory Overlay Commands::
25466* GDB/MI Signal Handling Commands::
25467@end ignore
922fbb7b 25468* GDB/MI Target Manipulation::
a6b151f1 25469* GDB/MI File Transfer Commands::
58d06528 25470* GDB/MI Ada Exceptions Commands::
d192b373 25471* GDB/MI Support Commands::
ef21caaf 25472* GDB/MI Miscellaneous Commands::
922fbb7b
AC
25473@end menu
25474
c3b108f7
VP
25475@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25476@node GDB/MI General Design
25477@section @sc{gdb/mi} General Design
25478@cindex GDB/MI General Design
25479
25480Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
25481parts---commands sent to @value{GDBN}, responses to those commands
25482and notifications. Each command results in exactly one response,
25483indicating either successful completion of the command, or an error.
25484For the commands that do not resume the target, the response contains the
25485requested information. For the commands that resume the target, the
25486response only indicates whether the target was successfully resumed.
25487Notifications is the mechanism for reporting changes in the state of the
25488target, or in @value{GDBN} state, that cannot conveniently be associated with
25489a command and reported as part of that command response.
25490
25491The important examples of notifications are:
25492@itemize @bullet
25493
25494@item
25495Exec notifications. These are used to report changes in
25496target state---when a target is resumed, or stopped. It would not
25497be feasible to include this information in response of resuming
25498commands, because one resume commands can result in multiple events in
25499different threads. Also, quite some time may pass before any event
25500happens in the target, while a frontend needs to know whether the resuming
25501command itself was successfully executed.
25502
25503@item
25504Console output, and status notifications. Console output
25505notifications are used to report output of CLI commands, as well as
25506diagnostics for other commands. Status notifications are used to
25507report the progress of a long-running operation. Naturally, including
25508this information in command response would mean no output is produced
25509until the command is finished, which is undesirable.
25510
25511@item
25512General notifications. Commands may have various side effects on
25513the @value{GDBN} or target state beyond their official purpose. For example,
25514a command may change the selected thread. Although such changes can
25515be included in command response, using notification allows for more
25516orthogonal frontend design.
25517
25518@end itemize
25519
25520There's no guarantee that whenever an MI command reports an error,
25521@value{GDBN} or the target are in any specific state, and especially,
25522the state is not reverted to the state before the MI command was
25523processed. Therefore, whenever an MI command results in an error,
25524we recommend that the frontend refreshes all the information shown in
25525the user interface.
25526
508094de
NR
25527
25528@menu
25529* Context management::
25530* Asynchronous and non-stop modes::
25531* Thread groups::
25532@end menu
25533
25534@node Context management
c3b108f7
VP
25535@subsection Context management
25536
403cb6b1
JB
25537@subsubsection Threads and Frames
25538
c3b108f7
VP
25539In most cases when @value{GDBN} accesses the target, this access is
25540done in context of a specific thread and frame (@pxref{Frames}).
25541Often, even when accessing global data, the target requires that a thread
25542be specified. The CLI interface maintains the selected thread and frame,
25543and supplies them to target on each command. This is convenient,
25544because a command line user would not want to specify that information
25545explicitly on each command, and because user interacts with
25546@value{GDBN} via a single terminal, so no confusion is possible as
25547to what thread and frame are the current ones.
25548
25549In the case of MI, the concept of selected thread and frame is less
25550useful. First, a frontend can easily remember this information
25551itself. Second, a graphical frontend can have more than one window,
25552each one used for debugging a different thread, and the frontend might
25553want to access additional threads for internal purposes. This
25554increases the risk that by relying on implicitly selected thread, the
25555frontend may be operating on a wrong one. Therefore, each MI command
25556should explicitly specify which thread and frame to operate on. To
25557make it possible, each MI command accepts the @samp{--thread} and
5d5658a1
PA
25558@samp{--frame} options, the value to each is @value{GDBN} global
25559identifier for thread and frame to operate on.
c3b108f7
VP
25560
25561Usually, each top-level window in a frontend allows the user to select
25562a thread and a frame, and remembers the user selection for further
25563operations. However, in some cases @value{GDBN} may suggest that the
25564current thread be changed. For example, when stopping on a breakpoint
25565it is reasonable to switch to the thread where breakpoint is hit. For
25566another example, if the user issues the CLI @samp{thread} command via
25567the frontend, it is desirable to change the frontend's selected thread to the
25568one specified by user. @value{GDBN} communicates the suggestion to
25569change current thread using the @samp{=thread-selected} notification.
25570No such notification is available for the selected frame at the moment.
25571
25572Note that historically, MI shares the selected thread with CLI, so
25573frontends used the @code{-thread-select} to execute commands in the
25574right context. However, getting this to work right is cumbersome. The
25575simplest way is for frontend to emit @code{-thread-select} command
25576before every command. This doubles the number of commands that need
25577to be sent. The alternative approach is to suppress @code{-thread-select}
25578if the selected thread in @value{GDBN} is supposed to be identical to the
25579thread the frontend wants to operate on. However, getting this
25580optimization right can be tricky. In particular, if the frontend
25581sends several commands to @value{GDBN}, and one of the commands changes the
25582selected thread, then the behaviour of subsequent commands will
25583change. So, a frontend should either wait for response from such
25584problematic commands, or explicitly add @code{-thread-select} for
25585all subsequent commands. No frontend is known to do this exactly
25586right, so it is suggested to just always pass the @samp{--thread} and
25587@samp{--frame} options.
25588
403cb6b1
JB
25589@subsubsection Language
25590
25591The execution of several commands depends on which language is selected.
25592By default, the current language (@pxref{show language}) is used.
25593But for commands known to be language-sensitive, it is recommended
25594to use the @samp{--language} option. This option takes one argument,
25595which is the name of the language to use while executing the command.
25596For instance:
25597
25598@smallexample
25599-data-evaluate-expression --language c "sizeof (void*)"
25600^done,value="4"
25601(gdb)
25602@end smallexample
25603
25604The valid language names are the same names accepted by the
25605@samp{set language} command (@pxref{Manually}), excluding @samp{auto},
25606@samp{local} or @samp{unknown}.
25607
508094de 25608@node Asynchronous and non-stop modes
c3b108f7
VP
25609@subsection Asynchronous command execution and non-stop mode
25610
25611On some targets, @value{GDBN} is capable of processing MI commands
25612even while the target is running. This is called @dfn{asynchronous
25613command execution} (@pxref{Background Execution}). The frontend may
25614specify a preferrence for asynchronous execution using the
329ea579 25615@code{-gdb-set mi-async 1} command, which should be emitted before
c3b108f7
VP
25616either running the executable or attaching to the target. After the
25617frontend has started the executable or attached to the target, it can
25618find if asynchronous execution is enabled using the
25619@code{-list-target-features} command.
25620
329ea579
PA
25621@table @code
25622@item -gdb-set mi-async on
25623@item -gdb-set mi-async off
25624Set whether MI is in asynchronous mode.
25625
25626When @code{off}, which is the default, MI execution commands (e.g.,
25627@code{-exec-continue}) are foreground commands, and @value{GDBN} waits
25628for the program to stop before processing further commands.
25629
25630When @code{on}, MI execution commands are background execution
25631commands (e.g., @code{-exec-continue} becomes the equivalent of the
25632@code{c&} CLI command), and so @value{GDBN} is capable of processing
25633MI commands even while the target is running.
25634
25635@item -gdb-show mi-async
25636Show whether MI asynchronous mode is enabled.
25637@end table
25638
25639Note: In @value{GDBN} version 7.7 and earlier, this option was called
25640@code{target-async} instead of @code{mi-async}, and it had the effect
25641of both putting MI in asynchronous mode and making CLI background
25642commands possible. CLI background commands are now always possible
25643``out of the box'' if the target supports them. The old spelling is
25644kept as a deprecated alias for backwards compatibility.
25645
c3b108f7
VP
25646Even if @value{GDBN} can accept a command while target is running,
25647many commands that access the target do not work when the target is
25648running. Therefore, asynchronous command execution is most useful
25649when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
25650it is possible to examine the state of one thread, while other threads
25651are running.
25652
25653When a given thread is running, MI commands that try to access the
25654target in the context of that thread may not work, or may work only on
25655some targets. In particular, commands that try to operate on thread's
25656stack will not work, on any target. Commands that read memory, or
25657modify breakpoints, may work or not work, depending on the target. Note
25658that even commands that operate on global state, such as @code{print},
25659@code{set}, and breakpoint commands, still access the target in the
25660context of a specific thread, so frontend should try to find a
25661stopped thread and perform the operation on that thread (using the
25662@samp{--thread} option).
25663
25664Which commands will work in the context of a running thread is
25665highly target dependent. However, the two commands
25666@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
25667to find the state of a thread, will always work.
25668
508094de 25669@node Thread groups
c3b108f7
VP
25670@subsection Thread groups
25671@value{GDBN} may be used to debug several processes at the same time.
25672On some platfroms, @value{GDBN} may support debugging of several
25673hardware systems, each one having several cores with several different
25674processes running on each core. This section describes the MI
25675mechanism to support such debugging scenarios.
25676
25677The key observation is that regardless of the structure of the
25678target, MI can have a global list of threads, because most commands that
25679accept the @samp{--thread} option do not need to know what process that
25680thread belongs to. Therefore, it is not necessary to introduce
25681neither additional @samp{--process} option, nor an notion of the
25682current process in the MI interface. The only strictly new feature
25683that is required is the ability to find how the threads are grouped
25684into processes.
25685
25686To allow the user to discover such grouping, and to support arbitrary
25687hierarchy of machines/cores/processes, MI introduces the concept of a
25688@dfn{thread group}. Thread group is a collection of threads and other
25689thread groups. A thread group always has a string identifier, a type,
25690and may have additional attributes specific to the type. A new
25691command, @code{-list-thread-groups}, returns the list of top-level
25692thread groups, which correspond to processes that @value{GDBN} is
25693debugging at the moment. By passing an identifier of a thread group
25694to the @code{-list-thread-groups} command, it is possible to obtain
25695the members of specific thread group.
25696
25697To allow the user to easily discover processes, and other objects, he
25698wishes to debug, a concept of @dfn{available thread group} is
25699introduced. Available thread group is an thread group that
25700@value{GDBN} is not debugging, but that can be attached to, using the
25701@code{-target-attach} command. The list of available top-level thread
25702groups can be obtained using @samp{-list-thread-groups --available}.
25703In general, the content of a thread group may be only retrieved only
25704after attaching to that thread group.
25705
a79b8f6e
VP
25706Thread groups are related to inferiors (@pxref{Inferiors and
25707Programs}). Each inferior corresponds to a thread group of a special
25708type @samp{process}, and some additional operations are permitted on
25709such thread groups.
25710
922fbb7b
AC
25711@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25712@node GDB/MI Command Syntax
25713@section @sc{gdb/mi} Command Syntax
25714
25715@menu
25716* GDB/MI Input Syntax::
25717* GDB/MI Output Syntax::
922fbb7b
AC
25718@end menu
25719
25720@node GDB/MI Input Syntax
25721@subsection @sc{gdb/mi} Input Syntax
25722
25723@cindex input syntax for @sc{gdb/mi}
25724@cindex @sc{gdb/mi}, input syntax
25725@table @code
25726@item @var{command} @expansion{}
25727@code{@var{cli-command} | @var{mi-command}}
25728
25729@item @var{cli-command} @expansion{}
25730@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
25731@var{cli-command} is any existing @value{GDBN} CLI command.
25732
25733@item @var{mi-command} @expansion{}
25734@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
25735@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
25736
25737@item @var{token} @expansion{}
25738"any sequence of digits"
25739
25740@item @var{option} @expansion{}
25741@code{"-" @var{parameter} [ " " @var{parameter} ]}
25742
25743@item @var{parameter} @expansion{}
25744@code{@var{non-blank-sequence} | @var{c-string}}
25745
25746@item @var{operation} @expansion{}
25747@emph{any of the operations described in this chapter}
25748
25749@item @var{non-blank-sequence} @expansion{}
25750@emph{anything, provided it doesn't contain special characters such as
25751"-", @var{nl}, """ and of course " "}
25752
25753@item @var{c-string} @expansion{}
25754@code{""" @var{seven-bit-iso-c-string-content} """}
25755
25756@item @var{nl} @expansion{}
25757@code{CR | CR-LF}
25758@end table
25759
25760@noindent
25761Notes:
25762
25763@itemize @bullet
25764@item
25765The CLI commands are still handled by the @sc{mi} interpreter; their
25766output is described below.
25767
25768@item
25769The @code{@var{token}}, when present, is passed back when the command
25770finishes.
25771
25772@item
25773Some @sc{mi} commands accept optional arguments as part of the parameter
25774list. Each option is identified by a leading @samp{-} (dash) and may be
25775followed by an optional argument parameter. Options occur first in the
25776parameter list and can be delimited from normal parameters using
25777@samp{--} (this is useful when some parameters begin with a dash).
25778@end itemize
25779
25780Pragmatics:
25781
25782@itemize @bullet
25783@item
25784We want easy access to the existing CLI syntax (for debugging).
25785
25786@item
25787We want it to be easy to spot a @sc{mi} operation.
25788@end itemize
25789
25790@node GDB/MI Output Syntax
25791@subsection @sc{gdb/mi} Output Syntax
25792
25793@cindex output syntax of @sc{gdb/mi}
25794@cindex @sc{gdb/mi}, output syntax
25795The output from @sc{gdb/mi} consists of zero or more out-of-band records
25796followed, optionally, by a single result record. This result record
25797is for the most recent command. The sequence of output records is
594fe323 25798terminated by @samp{(gdb)}.
922fbb7b
AC
25799
25800If an input command was prefixed with a @code{@var{token}} then the
25801corresponding output for that command will also be prefixed by that same
25802@var{token}.
25803
25804@table @code
25805@item @var{output} @expansion{}
594fe323 25806@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
25807
25808@item @var{result-record} @expansion{}
25809@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
25810
25811@item @var{out-of-band-record} @expansion{}
25812@code{@var{async-record} | @var{stream-record}}
25813
25814@item @var{async-record} @expansion{}
25815@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
25816
25817@item @var{exec-async-output} @expansion{}
dcf106f3 25818@code{[ @var{token} ] "*" @var{async-output nl}}
922fbb7b
AC
25819
25820@item @var{status-async-output} @expansion{}
dcf106f3 25821@code{[ @var{token} ] "+" @var{async-output nl}}
922fbb7b
AC
25822
25823@item @var{notify-async-output} @expansion{}
dcf106f3 25824@code{[ @var{token} ] "=" @var{async-output nl}}
922fbb7b
AC
25825
25826@item @var{async-output} @expansion{}
dcf106f3 25827@code{@var{async-class} ( "," @var{result} )*}
922fbb7b
AC
25828
25829@item @var{result-class} @expansion{}
25830@code{"done" | "running" | "connected" | "error" | "exit"}
25831
25832@item @var{async-class} @expansion{}
25833@code{"stopped" | @var{others}} (where @var{others} will be added
25834depending on the needs---this is still in development).
25835
25836@item @var{result} @expansion{}
25837@code{ @var{variable} "=" @var{value}}
25838
25839@item @var{variable} @expansion{}
25840@code{ @var{string} }
25841
25842@item @var{value} @expansion{}
25843@code{ @var{const} | @var{tuple} | @var{list} }
25844
25845@item @var{const} @expansion{}
25846@code{@var{c-string}}
25847
25848@item @var{tuple} @expansion{}
25849@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
25850
25851@item @var{list} @expansion{}
25852@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
25853@var{result} ( "," @var{result} )* "]" }
25854
25855@item @var{stream-record} @expansion{}
25856@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
25857
25858@item @var{console-stream-output} @expansion{}
dcf106f3 25859@code{"~" @var{c-string nl}}
922fbb7b
AC
25860
25861@item @var{target-stream-output} @expansion{}
dcf106f3 25862@code{"@@" @var{c-string nl}}
922fbb7b
AC
25863
25864@item @var{log-stream-output} @expansion{}
dcf106f3 25865@code{"&" @var{c-string nl}}
922fbb7b
AC
25866
25867@item @var{nl} @expansion{}
25868@code{CR | CR-LF}
25869
25870@item @var{token} @expansion{}
25871@emph{any sequence of digits}.
25872@end table
25873
25874@noindent
25875Notes:
25876
25877@itemize @bullet
25878@item
25879All output sequences end in a single line containing a period.
25880
25881@item
721c02de
VP
25882The @code{@var{token}} is from the corresponding request. Note that
25883for all async output, while the token is allowed by the grammar and
25884may be output by future versions of @value{GDBN} for select async
25885output messages, it is generally omitted. Frontends should treat
25886all async output as reporting general changes in the state of the
25887target and there should be no need to associate async output to any
25888prior command.
922fbb7b
AC
25889
25890@item
25891@cindex status output in @sc{gdb/mi}
25892@var{status-async-output} contains on-going status information about the
25893progress of a slow operation. It can be discarded. All status output is
25894prefixed by @samp{+}.
25895
25896@item
25897@cindex async output in @sc{gdb/mi}
25898@var{exec-async-output} contains asynchronous state change on the target
25899(stopped, started, disappeared). All async output is prefixed by
25900@samp{*}.
25901
25902@item
25903@cindex notify output in @sc{gdb/mi}
25904@var{notify-async-output} contains supplementary information that the
25905client should handle (e.g., a new breakpoint information). All notify
25906output is prefixed by @samp{=}.
25907
25908@item
25909@cindex console output in @sc{gdb/mi}
25910@var{console-stream-output} is output that should be displayed as is in the
25911console. It is the textual response to a CLI command. All the console
25912output is prefixed by @samp{~}.
25913
25914@item
25915@cindex target output in @sc{gdb/mi}
25916@var{target-stream-output} is the output produced by the target program.
25917All the target output is prefixed by @samp{@@}.
25918
25919@item
25920@cindex log output in @sc{gdb/mi}
25921@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
25922instance messages that should be displayed as part of an error log. All
25923the log output is prefixed by @samp{&}.
25924
25925@item
25926@cindex list output in @sc{gdb/mi}
25927New @sc{gdb/mi} commands should only output @var{lists} containing
25928@var{values}.
25929
25930
25931@end itemize
25932
25933@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
25934details about the various output records.
25935
922fbb7b
AC
25936@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25937@node GDB/MI Compatibility with CLI
25938@section @sc{gdb/mi} Compatibility with CLI
25939
25940@cindex compatibility, @sc{gdb/mi} and CLI
25941@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 25942
a2c02241
NR
25943For the developers convenience CLI commands can be entered directly,
25944but there may be some unexpected behaviour. For example, commands
25945that query the user will behave as if the user replied yes, breakpoint
25946command lists are not executed and some CLI commands, such as
25947@code{if}, @code{when} and @code{define}, prompt for further input with
25948@samp{>}, which is not valid MI output.
ef21caaf
NR
25949
25950This feature may be removed at some stage in the future and it is
a2c02241
NR
25951recommended that front ends use the @code{-interpreter-exec} command
25952(@pxref{-interpreter-exec}).
922fbb7b 25953
af6eff6f
NR
25954@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25955@node GDB/MI Development and Front Ends
25956@section @sc{gdb/mi} Development and Front Ends
25957@cindex @sc{gdb/mi} development
25958
25959The application which takes the MI output and presents the state of the
25960program being debugged to the user is called a @dfn{front end}.
25961
25962Although @sc{gdb/mi} is still incomplete, it is currently being used
25963by a variety of front ends to @value{GDBN}. This makes it difficult
25964to introduce new functionality without breaking existing usage. This
25965section tries to minimize the problems by describing how the protocol
25966might change.
25967
25968Some changes in MI need not break a carefully designed front end, and
25969for these the MI version will remain unchanged. The following is a
25970list of changes that may occur within one level, so front ends should
25971parse MI output in a way that can handle them:
25972
25973@itemize @bullet
25974@item
25975New MI commands may be added.
25976
25977@item
25978New fields may be added to the output of any MI command.
25979
36ece8b3
NR
25980@item
25981The range of values for fields with specified values, e.g.,
9f708cb2 25982@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 25983
af6eff6f
NR
25984@c The format of field's content e.g type prefix, may change so parse it
25985@c at your own risk. Yes, in general?
25986
25987@c The order of fields may change? Shouldn't really matter but it might
25988@c resolve inconsistencies.
25989@end itemize
25990
25991If the changes are likely to break front ends, the MI version level
25992will be increased by one. This will allow the front end to parse the
25993output according to the MI version. Apart from mi0, new versions of
25994@value{GDBN} will not support old versions of MI and it will be the
25995responsibility of the front end to work with the new one.
25996
25997@c Starting with mi3, add a new command -mi-version that prints the MI
25998@c version?
25999
26000The best way to avoid unexpected changes in MI that might break your front
26001end is to make your project known to @value{GDBN} developers and
7a9a6b69 26002follow development on @email{gdb@@sourceware.org} and
fa0f268d 26003@email{gdb-patches@@sourceware.org}.
af6eff6f
NR
26004@cindex mailing lists
26005
922fbb7b
AC
26006@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26007@node GDB/MI Output Records
26008@section @sc{gdb/mi} Output Records
26009
26010@menu
26011* GDB/MI Result Records::
26012* GDB/MI Stream Records::
82f68b1c 26013* GDB/MI Async Records::
54516a0b 26014* GDB/MI Breakpoint Information::
c3b108f7 26015* GDB/MI Frame Information::
dc146f7c 26016* GDB/MI Thread Information::
4368ebeb 26017* GDB/MI Ada Exception Information::
922fbb7b
AC
26018@end menu
26019
26020@node GDB/MI Result Records
26021@subsection @sc{gdb/mi} Result Records
26022
26023@cindex result records in @sc{gdb/mi}
26024@cindex @sc{gdb/mi}, result records
26025In addition to a number of out-of-band notifications, the response to a
26026@sc{gdb/mi} command includes one of the following result indications:
26027
26028@table @code
26029@findex ^done
26030@item "^done" [ "," @var{results} ]
26031The synchronous operation was successful, @code{@var{results}} are the return
26032values.
26033
26034@item "^running"
26035@findex ^running
8e9c5e02
VP
26036This result record is equivalent to @samp{^done}. Historically, it
26037was output instead of @samp{^done} if the command has resumed the
26038target. This behaviour is maintained for backward compatibility, but
26039all frontends should treat @samp{^done} and @samp{^running}
26040identically and rely on the @samp{*running} output record to determine
26041which threads are resumed.
922fbb7b 26042
ef21caaf
NR
26043@item "^connected"
26044@findex ^connected
3f94c067 26045@value{GDBN} has connected to a remote target.
ef21caaf 26046
2ea126fa 26047@item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
922fbb7b 26048@findex ^error
2ea126fa
JB
26049The operation failed. The @code{msg=@var{c-string}} variable contains
26050the corresponding error message.
26051
26052If present, the @code{code=@var{c-string}} variable provides an error
26053code on which consumers can rely on to detect the corresponding
26054error condition. At present, only one error code is defined:
26055
26056@table @samp
26057@item "undefined-command"
26058Indicates that the command causing the error does not exist.
26059@end table
ef21caaf
NR
26060
26061@item "^exit"
26062@findex ^exit
3f94c067 26063@value{GDBN} has terminated.
ef21caaf 26064
922fbb7b
AC
26065@end table
26066
26067@node GDB/MI Stream Records
26068@subsection @sc{gdb/mi} Stream Records
26069
26070@cindex @sc{gdb/mi}, stream records
26071@cindex stream records in @sc{gdb/mi}
26072@value{GDBN} internally maintains a number of output streams: the console, the
26073target, and the log. The output intended for each of these streams is
26074funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
26075
26076Each stream record begins with a unique @dfn{prefix character} which
26077identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
26078Syntax}). In addition to the prefix, each stream record contains a
26079@code{@var{string-output}}. This is either raw text (with an implicit new
26080line) or a quoted C string (which does not contain an implicit newline).
26081
26082@table @code
26083@item "~" @var{string-output}
26084The console output stream contains text that should be displayed in the
26085CLI console window. It contains the textual responses to CLI commands.
26086
26087@item "@@" @var{string-output}
26088The target output stream contains any textual output from the running
ef21caaf
NR
26089target. This is only present when GDB's event loop is truly
26090asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
26091
26092@item "&" @var{string-output}
26093The log stream contains debugging messages being produced by @value{GDBN}'s
26094internals.
26095@end table
26096
82f68b1c
VP
26097@node GDB/MI Async Records
26098@subsection @sc{gdb/mi} Async Records
922fbb7b 26099
82f68b1c
VP
26100@cindex async records in @sc{gdb/mi}
26101@cindex @sc{gdb/mi}, async records
26102@dfn{Async} records are used to notify the @sc{gdb/mi} client of
922fbb7b 26103additional changes that have occurred. Those changes can either be a
82f68b1c 26104consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
922fbb7b
AC
26105target activity (e.g., target stopped).
26106
8eb41542 26107The following is the list of possible async records:
922fbb7b
AC
26108
26109@table @code
034dad6f 26110
e1ac3328 26111@item *running,thread-id="@var{thread}"
5d5658a1
PA
26112The target is now running. The @var{thread} field can be the global
26113thread ID of the the thread that is now running, and it can be
26114@samp{all} if all threads are running. The frontend should assume
26115that no interaction with a running thread is possible after this
26116notification is produced. The frontend should not assume that this
26117notification is output only once for any command. @value{GDBN} may
26118emit this notification several times, either for different threads,
26119because it cannot resume all threads together, or even for a single
26120thread, if the thread must be stepped though some code before letting
26121it run freely.
e1ac3328 26122
dc146f7c 26123@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
82f68b1c
VP
26124The target has stopped. The @var{reason} field can have one of the
26125following values:
034dad6f
BR
26126
26127@table @code
26128@item breakpoint-hit
26129A breakpoint was reached.
26130@item watchpoint-trigger
26131A watchpoint was triggered.
26132@item read-watchpoint-trigger
26133A read watchpoint was triggered.
26134@item access-watchpoint-trigger
26135An access watchpoint was triggered.
26136@item function-finished
26137An -exec-finish or similar CLI command was accomplished.
26138@item location-reached
26139An -exec-until or similar CLI command was accomplished.
26140@item watchpoint-scope
26141A watchpoint has gone out of scope.
26142@item end-stepping-range
26143An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
26144similar CLI command was accomplished.
26145@item exited-signalled
26146The inferior exited because of a signal.
26147@item exited
26148The inferior exited.
26149@item exited-normally
26150The inferior exited normally.
26151@item signal-received
26152A signal was received by the inferior.
36dfb11c
TT
26153@item solib-event
26154The inferior has stopped due to a library being loaded or unloaded.
edcc5120
TT
26155This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
26156set or when a @code{catch load} or @code{catch unload} catchpoint is
26157in use (@pxref{Set Catchpoints}).
36dfb11c
TT
26158@item fork
26159The inferior has forked. This is reported when @code{catch fork}
26160(@pxref{Set Catchpoints}) has been used.
26161@item vfork
26162The inferior has vforked. This is reported in when @code{catch vfork}
26163(@pxref{Set Catchpoints}) has been used.
26164@item syscall-entry
26165The inferior entered a system call. This is reported when @code{catch
26166syscall} (@pxref{Set Catchpoints}) has been used.
a64c9f7b 26167@item syscall-return
36dfb11c
TT
26168The inferior returned from a system call. This is reported when
26169@code{catch syscall} (@pxref{Set Catchpoints}) has been used.
26170@item exec
26171The inferior called @code{exec}. This is reported when @code{catch exec}
26172(@pxref{Set Catchpoints}) has been used.
922fbb7b
AC
26173@end table
26174
5d5658a1
PA
26175The @var{id} field identifies the global thread ID of the thread
26176that directly caused the stop -- for example by hitting a breakpoint.
26177Depending on whether all-stop
c3b108f7
VP
26178mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
26179stop all threads, or only the thread that directly triggered the stop.
26180If all threads are stopped, the @var{stopped} field will have the
26181value of @code{"all"}. Otherwise, the value of the @var{stopped}
26182field will be a list of thread identifiers. Presently, this list will
26183always include a single thread, but frontend should be prepared to see
dc146f7c
VP
26184several threads in the list. The @var{core} field reports the
26185processor core on which the stop event has happened. This field may be absent
26186if such information is not available.
c3b108f7 26187
a79b8f6e
VP
26188@item =thread-group-added,id="@var{id}"
26189@itemx =thread-group-removed,id="@var{id}"
26190A thread group was either added or removed. The @var{id} field
26191contains the @value{GDBN} identifier of the thread group. When a thread
26192group is added, it generally might not be associated with a running
26193process. When a thread group is removed, its id becomes invalid and
26194cannot be used in any way.
26195
26196@item =thread-group-started,id="@var{id}",pid="@var{pid}"
26197A thread group became associated with a running program,
26198either because the program was just started or the thread group
26199was attached to a program. The @var{id} field contains the
26200@value{GDBN} identifier of the thread group. The @var{pid} field
26201contains process identifier, specific to the operating system.
26202
8cf64490 26203@item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
a79b8f6e
VP
26204A thread group is no longer associated with a running program,
26205either because the program has exited, or because it was detached
c3b108f7 26206from. The @var{id} field contains the @value{GDBN} identifier of the
697aa1b7 26207thread group. The @var{code} field is the exit code of the inferior; it exists
8cf64490 26208only when the inferior exited with some code.
c3b108f7
VP
26209
26210@item =thread-created,id="@var{id}",group-id="@var{gid}"
26211@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
82f68b1c 26212A thread either was created, or has exited. The @var{id} field
5d5658a1 26213contains the global @value{GDBN} identifier of the thread. The @var{gid}
c3b108f7 26214field identifies the thread group this thread belongs to.
66bb093b
VP
26215
26216@item =thread-selected,id="@var{id}"
26217Informs that the selected thread was changed as result of the last
26218command. This notification is not emitted as result of @code{-thread-select}
26219command but is emitted whenever an MI command that is not documented
26220to change the selected thread actually changes it. In particular,
26221invoking, directly or indirectly (via user-defined command), the CLI
26222@code{thread} command, will generate this notification.
26223
26224We suggest that in response to this notification, front ends
26225highlight the selected thread and cause subsequent commands to apply to
26226that thread.
26227
c86cf029
VP
26228@item =library-loaded,...
26229Reports that a new library file was loaded by the program. This
26230notification has 4 fields---@var{id}, @var{target-name},
134eb42c 26231@var{host-name}, and @var{symbols-loaded}. The @var{id} field is an
c86cf029
VP
26232opaque identifier of the library. For remote debugging case,
26233@var{target-name} and @var{host-name} fields give the name of the
134eb42c
VP
26234library file on the target, and on the host respectively. For native
26235debugging, both those fields have the same value. The
f1cbe1d3
TT
26236@var{symbols-loaded} field is emitted only for backward compatibility
26237and should not be relied on to convey any useful information. The
26238@var{thread-group} field, if present, specifies the id of the thread
26239group in whose context the library was loaded. If the field is
26240absent, it means the library was loaded in the context of all present
26241thread groups.
c86cf029
VP
26242
26243@item =library-unloaded,...
134eb42c 26244Reports that a library was unloaded by the program. This notification
c86cf029 26245has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
a79b8f6e
VP
26246the same meaning as for the @code{=library-loaded} notification.
26247The @var{thread-group} field, if present, specifies the id of the
26248thread group in whose context the library was unloaded. If the field is
26249absent, it means the library was unloaded in the context of all present
26250thread groups.
c86cf029 26251
201b4506
YQ
26252@item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
26253@itemx =traceframe-changed,end
26254Reports that the trace frame was changed and its new number is
26255@var{tfnum}. The number of the tracepoint associated with this trace
26256frame is @var{tpnum}.
26257
134a2066 26258@item =tsv-created,name=@var{name},initial=@var{initial}
bb25a15c 26259Reports that the new trace state variable @var{name} is created with
134a2066 26260initial value @var{initial}.
bb25a15c
YQ
26261
26262@item =tsv-deleted,name=@var{name}
26263@itemx =tsv-deleted
26264Reports that the trace state variable @var{name} is deleted or all
26265trace state variables are deleted.
26266
134a2066
YQ
26267@item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
26268Reports that the trace state variable @var{name} is modified with
26269the initial value @var{initial}. The current value @var{current} of
26270trace state variable is optional and is reported if the current
26271value of trace state variable is known.
26272
8d3788bd
VP
26273@item =breakpoint-created,bkpt=@{...@}
26274@itemx =breakpoint-modified,bkpt=@{...@}
d9f08f52 26275@itemx =breakpoint-deleted,id=@var{number}
8d3788bd
VP
26276Reports that a breakpoint was created, modified, or deleted,
26277respectively. Only user-visible breakpoints are reported to the MI
26278user.
26279
26280The @var{bkpt} argument is of the same form as returned by the various
d9f08f52
YQ
26281breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
26282@var{number} is the ordinal number of the breakpoint.
8d3788bd
VP
26283
26284Note that if a breakpoint is emitted in the result record of a
26285command, then it will not also be emitted in an async record.
26286
82a90ccf
YQ
26287@item =record-started,thread-group="@var{id}"
26288@itemx =record-stopped,thread-group="@var{id}"
26289Execution log recording was either started or stopped on an
26290inferior. The @var{id} is the @value{GDBN} identifier of the thread
26291group corresponding to the affected inferior.
26292
5b9afe8a
YQ
26293@item =cmd-param-changed,param=@var{param},value=@var{value}
26294Reports that a parameter of the command @code{set @var{param}} is
26295changed to @var{value}. In the multi-word @code{set} command,
26296the @var{param} is the whole parameter list to @code{set} command.
26297For example, In command @code{set check type on}, @var{param}
26298is @code{check type} and @var{value} is @code{on}.
8de0566d
YQ
26299
26300@item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
26301Reports that bytes from @var{addr} to @var{data} + @var{len} were
26302written in an inferior. The @var{id} is the identifier of the
26303thread group corresponding to the affected inferior. The optional
26304@code{type="code"} part is reported if the memory written to holds
26305executable code.
82f68b1c
VP
26306@end table
26307
54516a0b
TT
26308@node GDB/MI Breakpoint Information
26309@subsection @sc{gdb/mi} Breakpoint Information
26310
26311When @value{GDBN} reports information about a breakpoint, a
26312tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
26313following fields:
26314
26315@table @code
26316@item number
26317The breakpoint number. For a breakpoint that represents one location
26318of a multi-location breakpoint, this will be a dotted pair, like
26319@samp{1.2}.
26320
26321@item type
26322The type of the breakpoint. For ordinary breakpoints this will be
26323@samp{breakpoint}, but many values are possible.
26324
8ac3646f
TT
26325@item catch-type
26326If the type of the breakpoint is @samp{catchpoint}, then this
26327indicates the exact type of catchpoint.
26328
54516a0b
TT
26329@item disp
26330This is the breakpoint disposition---either @samp{del}, meaning that
26331the breakpoint will be deleted at the next stop, or @samp{keep},
26332meaning that the breakpoint will not be deleted.
26333
26334@item enabled
26335This indicates whether the breakpoint is enabled, in which case the
26336value is @samp{y}, or disabled, in which case the value is @samp{n}.
26337Note that this is not the same as the field @code{enable}.
26338
26339@item addr
26340The address of the breakpoint. This may be a hexidecimal number,
26341giving the address; or the string @samp{<PENDING>}, for a pending
26342breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
26343multiple locations. This field will not be present if no address can
26344be determined. For example, a watchpoint does not have an address.
26345
26346@item func
26347If known, the function in which the breakpoint appears.
26348If not known, this field is not present.
26349
26350@item filename
26351The name of the source file which contains this function, if known.
26352If not known, this field is not present.
26353
26354@item fullname
26355The full file name of the source file which contains this function, if
26356known. If not known, this field is not present.
26357
26358@item line
26359The line number at which this breakpoint appears, if known.
26360If not known, this field is not present.
26361
26362@item at
26363If the source file is not known, this field may be provided. If
26364provided, this holds the address of the breakpoint, possibly followed
26365by a symbol name.
26366
26367@item pending
26368If this breakpoint is pending, this field is present and holds the
26369text used to set the breakpoint, as entered by the user.
26370
26371@item evaluated-by
26372Where this breakpoint's condition is evaluated, either @samp{host} or
26373@samp{target}.
26374
26375@item thread
26376If this is a thread-specific breakpoint, then this identifies the
26377thread in which the breakpoint can trigger.
26378
26379@item task
26380If this breakpoint is restricted to a particular Ada task, then this
26381field will hold the task identifier.
26382
26383@item cond
26384If the breakpoint is conditional, this is the condition expression.
26385
26386@item ignore
26387The ignore count of the breakpoint.
26388
26389@item enable
26390The enable count of the breakpoint.
26391
26392@item traceframe-usage
26393FIXME.
26394
26395@item static-tracepoint-marker-string-id
26396For a static tracepoint, the name of the static tracepoint marker.
26397
26398@item mask
26399For a masked watchpoint, this is the mask.
26400
26401@item pass
26402A tracepoint's pass count.
26403
26404@item original-location
26405The location of the breakpoint as originally specified by the user.
26406This field is optional.
26407
26408@item times
26409The number of times the breakpoint has been hit.
26410
26411@item installed
26412This field is only given for tracepoints. This is either @samp{y},
26413meaning that the tracepoint is installed, or @samp{n}, meaning that it
26414is not.
26415
26416@item what
26417Some extra data, the exact contents of which are type-dependent.
26418
26419@end table
26420
26421For example, here is what the output of @code{-break-insert}
26422(@pxref{GDB/MI Breakpoint Commands}) might be:
26423
26424@smallexample
26425-> -break-insert main
26426<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
26427 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
26428 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
26429 times="0"@}
54516a0b
TT
26430<- (gdb)
26431@end smallexample
26432
c3b108f7
VP
26433@node GDB/MI Frame Information
26434@subsection @sc{gdb/mi} Frame Information
26435
26436Response from many MI commands includes an information about stack
26437frame. This information is a tuple that may have the following
26438fields:
26439
26440@table @code
26441@item level
26442The level of the stack frame. The innermost frame has the level of
26443zero. This field is always present.
26444
26445@item func
26446The name of the function corresponding to the frame. This field may
26447be absent if @value{GDBN} is unable to determine the function name.
26448
26449@item addr
26450The code address for the frame. This field is always present.
26451
26452@item file
26453The name of the source files that correspond to the frame's code
26454address. This field may be absent.
26455
26456@item line
26457The source line corresponding to the frames' code address. This field
26458may be absent.
26459
26460@item from
26461The name of the binary file (either executable or shared library) the
26462corresponds to the frame's code address. This field may be absent.
26463
26464@end table
82f68b1c 26465
dc146f7c
VP
26466@node GDB/MI Thread Information
26467@subsection @sc{gdb/mi} Thread Information
26468
26469Whenever @value{GDBN} has to report an information about a thread, it
26470uses a tuple with the following fields:
26471
26472@table @code
26473@item id
5d5658a1 26474The global numeric id assigned to the thread by @value{GDBN}. This field is
dc146f7c
VP
26475always present.
26476
26477@item target-id
26478Target-specific string identifying the thread. This field is always present.
26479
26480@item details
26481Additional information about the thread provided by the target.
26482It is supposed to be human-readable and not interpreted by the
26483frontend. This field is optional.
26484
26485@item state
26486Either @samp{stopped} or @samp{running}, depending on whether the
26487thread is presently running. This field is always present.
26488
26489@item core
26490The value of this field is an integer number of the processor core the
26491thread was last seen on. This field is optional.
26492@end table
26493
956a9fb9
JB
26494@node GDB/MI Ada Exception Information
26495@subsection @sc{gdb/mi} Ada Exception Information
26496
26497Whenever a @code{*stopped} record is emitted because the program
26498stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
26499@value{GDBN} provides the name of the exception that was raised via
26500the @code{exception-name} field.
922fbb7b 26501
ef21caaf
NR
26502@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26503@node GDB/MI Simple Examples
26504@section Simple Examples of @sc{gdb/mi} Interaction
26505@cindex @sc{gdb/mi}, simple examples
26506
26507This subsection presents several simple examples of interaction using
26508the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
26509following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
26510the output received from @sc{gdb/mi}.
26511
d3e8051b 26512Note the line breaks shown in the examples are here only for
ef21caaf
NR
26513readability, they don't appear in the real output.
26514
79a6e687 26515@subheading Setting a Breakpoint
ef21caaf
NR
26516
26517Setting a breakpoint generates synchronous output which contains detailed
26518information of the breakpoint.
26519
26520@smallexample
26521-> -break-insert main
26522<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
26523 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
26524 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
26525 times="0"@}
ef21caaf
NR
26526<- (gdb)
26527@end smallexample
26528
26529@subheading Program Execution
26530
26531Program execution generates asynchronous records and MI gives the
26532reason that execution stopped.
26533
26534@smallexample
26535-> -exec-run
26536<- ^running
26537<- (gdb)
a47ec5fe 26538<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
ef21caaf
NR
26539 frame=@{addr="0x08048564",func="main",
26540 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
26541 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
26542<- (gdb)
26543-> -exec-continue
26544<- ^running
26545<- (gdb)
26546<- *stopped,reason="exited-normally"
26547<- (gdb)
26548@end smallexample
26549
3f94c067 26550@subheading Quitting @value{GDBN}
ef21caaf 26551
3f94c067 26552Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
26553
26554@smallexample
26555-> (gdb)
26556<- -gdb-exit
26557<- ^exit
26558@end smallexample
26559
a6b29f87
VP
26560Please note that @samp{^exit} is printed immediately, but it might
26561take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
26562performs necessary cleanups, including killing programs being debugged
26563or disconnecting from debug hardware, so the frontend should wait till
26564@value{GDBN} exits and should only forcibly kill @value{GDBN} if it
26565fails to exit in reasonable time.
26566
a2c02241 26567@subheading A Bad Command
ef21caaf
NR
26568
26569Here's what happens if you pass a non-existent command:
26570
26571@smallexample
26572-> -rubbish
26573<- ^error,msg="Undefined MI command: rubbish"
594fe323 26574<- (gdb)
ef21caaf
NR
26575@end smallexample
26576
26577
922fbb7b
AC
26578@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26579@node GDB/MI Command Description Format
26580@section @sc{gdb/mi} Command Description Format
26581
26582The remaining sections describe blocks of commands. Each block of
26583commands is laid out in a fashion similar to this section.
26584
922fbb7b
AC
26585@subheading Motivation
26586
26587The motivation for this collection of commands.
26588
26589@subheading Introduction
26590
26591A brief introduction to this collection of commands as a whole.
26592
26593@subheading Commands
26594
26595For each command in the block, the following is described:
26596
26597@subsubheading Synopsis
26598
26599@smallexample
26600 -command @var{args}@dots{}
26601@end smallexample
26602
922fbb7b
AC
26603@subsubheading Result
26604
265eeb58 26605@subsubheading @value{GDBN} Command
922fbb7b 26606
265eeb58 26607The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
26608
26609@subsubheading Example
26610
ef21caaf
NR
26611Example(s) formatted for readability. Some of the described commands have
26612not been implemented yet and these are labeled N.A.@: (not available).
26613
26614
922fbb7b 26615@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
26616@node GDB/MI Breakpoint Commands
26617@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
26618
26619@cindex breakpoint commands for @sc{gdb/mi}
26620@cindex @sc{gdb/mi}, breakpoint commands
26621This section documents @sc{gdb/mi} commands for manipulating
26622breakpoints.
26623
26624@subheading The @code{-break-after} Command
26625@findex -break-after
26626
26627@subsubheading Synopsis
26628
26629@smallexample
26630 -break-after @var{number} @var{count}
26631@end smallexample
26632
26633The breakpoint number @var{number} is not in effect until it has been
26634hit @var{count} times. To see how this is reflected in the output of
26635the @samp{-break-list} command, see the description of the
26636@samp{-break-list} command below.
26637
26638@subsubheading @value{GDBN} Command
26639
26640The corresponding @value{GDBN} command is @samp{ignore}.
26641
26642@subsubheading Example
26643
26644@smallexample
594fe323 26645(gdb)
922fbb7b 26646-break-insert main
a47ec5fe
AR
26647^done,bkpt=@{number="1",type="breakpoint",disp="keep",
26648enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
26649fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
26650times="0"@}
594fe323 26651(gdb)
922fbb7b
AC
26652-break-after 1 3
26653~
26654^done
594fe323 26655(gdb)
922fbb7b
AC
26656-break-list
26657^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
26658hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26659@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26660@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26661@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26662@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26663@{width="40",alignment="2",col_name="what",colhdr="What"@}],
26664body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 26665addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 26666line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 26667(gdb)
922fbb7b
AC
26668@end smallexample
26669
26670@ignore
26671@subheading The @code{-break-catch} Command
26672@findex -break-catch
48cb2d85 26673@end ignore
922fbb7b
AC
26674
26675@subheading The @code{-break-commands} Command
26676@findex -break-commands
922fbb7b 26677
48cb2d85
VP
26678@subsubheading Synopsis
26679
26680@smallexample
26681 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
26682@end smallexample
26683
26684Specifies the CLI commands that should be executed when breakpoint
26685@var{number} is hit. The parameters @var{command1} to @var{commandN}
26686are the commands. If no command is specified, any previously-set
26687commands are cleared. @xref{Break Commands}. Typical use of this
26688functionality is tracing a program, that is, printing of values of
26689some variables whenever breakpoint is hit and then continuing.
26690
26691@subsubheading @value{GDBN} Command
26692
26693The corresponding @value{GDBN} command is @samp{commands}.
26694
26695@subsubheading Example
26696
26697@smallexample
26698(gdb)
26699-break-insert main
26700^done,bkpt=@{number="1",type="breakpoint",disp="keep",
26701enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
26702fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
26703times="0"@}
48cb2d85
VP
26704(gdb)
26705-break-commands 1 "print v" "continue"
26706^done
26707(gdb)
26708@end smallexample
922fbb7b
AC
26709
26710@subheading The @code{-break-condition} Command
26711@findex -break-condition
26712
26713@subsubheading Synopsis
26714
26715@smallexample
26716 -break-condition @var{number} @var{expr}
26717@end smallexample
26718
26719Breakpoint @var{number} will stop the program only if the condition in
26720@var{expr} is true. The condition becomes part of the
26721@samp{-break-list} output (see the description of the @samp{-break-list}
26722command below).
26723
26724@subsubheading @value{GDBN} Command
26725
26726The corresponding @value{GDBN} command is @samp{condition}.
26727
26728@subsubheading Example
26729
26730@smallexample
594fe323 26731(gdb)
922fbb7b
AC
26732-break-condition 1 1
26733^done
594fe323 26734(gdb)
922fbb7b
AC
26735-break-list
26736^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
26737hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26738@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26739@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26740@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26741@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26742@{width="40",alignment="2",col_name="what",colhdr="What"@}],
26743body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 26744addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 26745line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 26746(gdb)
922fbb7b
AC
26747@end smallexample
26748
26749@subheading The @code{-break-delete} Command
26750@findex -break-delete
26751
26752@subsubheading Synopsis
26753
26754@smallexample
26755 -break-delete ( @var{breakpoint} )+
26756@end smallexample
26757
26758Delete the breakpoint(s) whose number(s) are specified in the argument
26759list. This is obviously reflected in the breakpoint list.
26760
79a6e687 26761@subsubheading @value{GDBN} Command
922fbb7b
AC
26762
26763The corresponding @value{GDBN} command is @samp{delete}.
26764
26765@subsubheading Example
26766
26767@smallexample
594fe323 26768(gdb)
922fbb7b
AC
26769-break-delete 1
26770^done
594fe323 26771(gdb)
922fbb7b
AC
26772-break-list
26773^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
26774hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26775@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26776@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26777@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26778@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26779@{width="40",alignment="2",col_name="what",colhdr="What"@}],
26780body=[]@}
594fe323 26781(gdb)
922fbb7b
AC
26782@end smallexample
26783
26784@subheading The @code{-break-disable} Command
26785@findex -break-disable
26786
26787@subsubheading Synopsis
26788
26789@smallexample
26790 -break-disable ( @var{breakpoint} )+
26791@end smallexample
26792
26793Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
26794break list is now set to @samp{n} for the named @var{breakpoint}(s).
26795
26796@subsubheading @value{GDBN} Command
26797
26798The corresponding @value{GDBN} command is @samp{disable}.
26799
26800@subsubheading Example
26801
26802@smallexample
594fe323 26803(gdb)
922fbb7b
AC
26804-break-disable 2
26805^done
594fe323 26806(gdb)
922fbb7b
AC
26807-break-list
26808^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
26809hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26810@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26811@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26812@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26813@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26814@{width="40",alignment="2",col_name="what",colhdr="What"@}],
26815body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102 26816addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 26817line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 26818(gdb)
922fbb7b
AC
26819@end smallexample
26820
26821@subheading The @code{-break-enable} Command
26822@findex -break-enable
26823
26824@subsubheading Synopsis
26825
26826@smallexample
26827 -break-enable ( @var{breakpoint} )+
26828@end smallexample
26829
26830Enable (previously disabled) @var{breakpoint}(s).
26831
26832@subsubheading @value{GDBN} Command
26833
26834The corresponding @value{GDBN} command is @samp{enable}.
26835
26836@subsubheading Example
26837
26838@smallexample
594fe323 26839(gdb)
922fbb7b
AC
26840-break-enable 2
26841^done
594fe323 26842(gdb)
922fbb7b
AC
26843-break-list
26844^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
26845hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26846@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26847@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26848@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26849@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26850@{width="40",alignment="2",col_name="what",colhdr="What"@}],
26851body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 26852addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 26853line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 26854(gdb)
922fbb7b
AC
26855@end smallexample
26856
26857@subheading The @code{-break-info} Command
26858@findex -break-info
26859
26860@subsubheading Synopsis
26861
26862@smallexample
26863 -break-info @var{breakpoint}
26864@end smallexample
26865
26866@c REDUNDANT???
26867Get information about a single breakpoint.
26868
54516a0b
TT
26869The result is a table of breakpoints. @xref{GDB/MI Breakpoint
26870Information}, for details on the format of each breakpoint in the
26871table.
26872
79a6e687 26873@subsubheading @value{GDBN} Command
922fbb7b
AC
26874
26875The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
26876
26877@subsubheading Example
26878N.A.
26879
26880@subheading The @code{-break-insert} Command
26881@findex -break-insert
629500fa 26882@anchor{-break-insert}
922fbb7b
AC
26883
26884@subsubheading Synopsis
26885
26886@smallexample
18148017 26887 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
922fbb7b 26888 [ -c @var{condition} ] [ -i @var{ignore-count} ]
472a2379 26889 [ -p @var{thread-id} ] [ @var{location} ]
922fbb7b
AC
26890@end smallexample
26891
26892@noindent
afe8ab22 26893If specified, @var{location}, can be one of:
922fbb7b 26894
629500fa
KS
26895@table @var
26896@item linespec location
26897A linespec location. @xref{Linespec Locations}.
26898
26899@item explicit location
26900An explicit location. @sc{gdb/mi} explicit locations are
26901analogous to the CLI's explicit locations using the option names
26902listed below. @xref{Explicit Locations}.
26903
26904@table @samp
26905@item --source @var{filename}
26906The source file name of the location. This option requires the use
26907of either @samp{--function} or @samp{--line}.
26908
26909@item --function @var{function}
26910The name of a function or method.
922fbb7b 26911
629500fa
KS
26912@item --label @var{label}
26913The name of a label.
26914
26915@item --line @var{lineoffset}
26916An absolute or relative line offset from the start of the location.
26917@end table
26918
26919@item address location
26920An address location, *@var{address}. @xref{Address Locations}.
26921@end table
26922
26923@noindent
922fbb7b
AC
26924The possible optional parameters of this command are:
26925
26926@table @samp
26927@item -t
948d5102 26928Insert a temporary breakpoint.
922fbb7b
AC
26929@item -h
26930Insert a hardware breakpoint.
afe8ab22
VP
26931@item -f
26932If @var{location} cannot be parsed (for example if it
26933refers to unknown files or functions), create a pending
26934breakpoint. Without this flag, @value{GDBN} will report
26935an error, and won't create a breakpoint, if @var{location}
26936cannot be parsed.
41447f92
VP
26937@item -d
26938Create a disabled breakpoint.
18148017
VP
26939@item -a
26940Create a tracepoint. @xref{Tracepoints}. When this parameter
26941is used together with @samp{-h}, a fast tracepoint is created.
472a2379
KS
26942@item -c @var{condition}
26943Make the breakpoint conditional on @var{condition}.
26944@item -i @var{ignore-count}
26945Initialize the @var{ignore-count}.
26946@item -p @var{thread-id}
5d5658a1
PA
26947Restrict the breakpoint to the thread with the specified global
26948@var{thread-id}.
922fbb7b
AC
26949@end table
26950
26951@subsubheading Result
26952
54516a0b
TT
26953@xref{GDB/MI Breakpoint Information}, for details on the format of the
26954resulting breakpoint.
922fbb7b
AC
26955
26956Note: this format is open to change.
26957@c An out-of-band breakpoint instead of part of the result?
26958
26959@subsubheading @value{GDBN} Command
26960
26961The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
496ee73e 26962@samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
922fbb7b
AC
26963
26964@subsubheading Example
26965
26966@smallexample
594fe323 26967(gdb)
922fbb7b 26968-break-insert main
948d5102 26969^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
998580f1
MK
26970fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
26971times="0"@}
594fe323 26972(gdb)
922fbb7b 26973-break-insert -t foo
948d5102 26974^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
998580f1
MK
26975fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
26976times="0"@}
594fe323 26977(gdb)
922fbb7b
AC
26978-break-list
26979^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
26980hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26981@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26982@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26983@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26984@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26985@{width="40",alignment="2",col_name="what",colhdr="What"@}],
26986body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 26987addr="0x0001072c", func="main",file="recursive2.c",
998580f1
MK
26988fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
26989times="0"@},
922fbb7b 26990bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102 26991addr="0x00010774",func="foo",file="recursive2.c",
998580f1
MK
26992fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
26993times="0"@}]@}
594fe323 26994(gdb)
496ee73e
KS
26995@c -break-insert -r foo.*
26996@c ~int foo(int, int);
26997@c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
998580f1
MK
26998@c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
26999@c times="0"@}
496ee73e 27000@c (gdb)
922fbb7b
AC
27001@end smallexample
27002
c5867ab6
HZ
27003@subheading The @code{-dprintf-insert} Command
27004@findex -dprintf-insert
27005
27006@subsubheading Synopsis
27007
27008@smallexample
27009 -dprintf-insert [ -t ] [ -f ] [ -d ]
27010 [ -c @var{condition} ] [ -i @var{ignore-count} ]
27011 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
27012 [ @var{argument} ]
27013@end smallexample
27014
27015@noindent
629500fa
KS
27016If supplied, @var{location} may be specified the same way as for
27017the @code{-break-insert} command. @xref{-break-insert}.
c5867ab6
HZ
27018
27019The possible optional parameters of this command are:
27020
27021@table @samp
27022@item -t
27023Insert a temporary breakpoint.
27024@item -f
27025If @var{location} cannot be parsed (for example, if it
27026refers to unknown files or functions), create a pending
27027breakpoint. Without this flag, @value{GDBN} will report
27028an error, and won't create a breakpoint, if @var{location}
27029cannot be parsed.
27030@item -d
27031Create a disabled breakpoint.
27032@item -c @var{condition}
27033Make the breakpoint conditional on @var{condition}.
27034@item -i @var{ignore-count}
27035Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
27036to @var{ignore-count}.
27037@item -p @var{thread-id}
5d5658a1
PA
27038Restrict the breakpoint to the thread with the specified global
27039@var{thread-id}.
c5867ab6
HZ
27040@end table
27041
27042@subsubheading Result
27043
27044@xref{GDB/MI Breakpoint Information}, for details on the format of the
27045resulting breakpoint.
27046
27047@c An out-of-band breakpoint instead of part of the result?
27048
27049@subsubheading @value{GDBN} Command
27050
27051The corresponding @value{GDBN} command is @samp{dprintf}.
27052
27053@subsubheading Example
27054
27055@smallexample
27056(gdb)
270574-dprintf-insert foo "At foo entry\n"
270584^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
27059addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
27060fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
27061times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
27062original-location="foo"@}
27063(gdb)
270645-dprintf-insert 26 "arg=%d, g=%d\n" arg g
270655^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
27066addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
27067fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
27068times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
27069original-location="mi-dprintf.c:26"@}
27070(gdb)
27071@end smallexample
27072
922fbb7b
AC
27073@subheading The @code{-break-list} Command
27074@findex -break-list
27075
27076@subsubheading Synopsis
27077
27078@smallexample
27079 -break-list
27080@end smallexample
27081
27082Displays the list of inserted breakpoints, showing the following fields:
27083
27084@table @samp
27085@item Number
27086number of the breakpoint
27087@item Type
27088type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
27089@item Disposition
27090should the breakpoint be deleted or disabled when it is hit: @samp{keep}
27091or @samp{nokeep}
27092@item Enabled
27093is the breakpoint enabled or no: @samp{y} or @samp{n}
27094@item Address
27095memory location at which the breakpoint is set
27096@item What
27097logical location of the breakpoint, expressed by function name, file
27098name, line number
998580f1
MK
27099@item Thread-groups
27100list of thread groups to which this breakpoint applies
922fbb7b
AC
27101@item Times
27102number of times the breakpoint has been hit
27103@end table
27104
27105If there are no breakpoints or watchpoints, the @code{BreakpointTable}
27106@code{body} field is an empty list.
27107
27108@subsubheading @value{GDBN} Command
27109
27110The corresponding @value{GDBN} command is @samp{info break}.
27111
27112@subsubheading Example
27113
27114@smallexample
594fe323 27115(gdb)
922fbb7b
AC
27116-break-list
27117^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
27118hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
27119@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
27120@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
27121@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
27122@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
27123@{width="40",alignment="2",col_name="what",colhdr="What"@}],
27124body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
998580f1
MK
27125addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
27126times="0"@},
922fbb7b 27127bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 27128addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
998580f1 27129line="13",thread-groups=["i1"],times="0"@}]@}
594fe323 27130(gdb)
922fbb7b
AC
27131@end smallexample
27132
27133Here's an example of the result when there are no breakpoints:
27134
27135@smallexample
594fe323 27136(gdb)
922fbb7b
AC
27137-break-list
27138^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
27139hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
27140@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
27141@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
27142@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
27143@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
27144@{width="40",alignment="2",col_name="what",colhdr="What"@}],
27145body=[]@}
594fe323 27146(gdb)
922fbb7b
AC
27147@end smallexample
27148
18148017
VP
27149@subheading The @code{-break-passcount} Command
27150@findex -break-passcount
27151
27152@subsubheading Synopsis
27153
27154@smallexample
27155 -break-passcount @var{tracepoint-number} @var{passcount}
27156@end smallexample
27157
27158Set the passcount for tracepoint @var{tracepoint-number} to
27159@var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
27160is not a tracepoint, error is emitted. This corresponds to CLI
27161command @samp{passcount}.
27162
922fbb7b
AC
27163@subheading The @code{-break-watch} Command
27164@findex -break-watch
27165
27166@subsubheading Synopsis
27167
27168@smallexample
27169 -break-watch [ -a | -r ]
27170@end smallexample
27171
27172Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 27173@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 27174read from or on a write to the memory location. With the @samp{-r}
d3e8051b 27175option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
27176trigger only when the memory location is accessed for reading. Without
27177either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 27178i.e., it will trigger when the memory location is accessed for writing.
79a6e687 27179@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
27180
27181Note that @samp{-break-list} will report a single list of watchpoints and
27182breakpoints inserted.
27183
27184@subsubheading @value{GDBN} Command
27185
27186The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
27187@samp{rwatch}.
27188
27189@subsubheading Example
27190
27191Setting a watchpoint on a variable in the @code{main} function:
27192
27193@smallexample
594fe323 27194(gdb)
922fbb7b
AC
27195-break-watch x
27196^done,wpt=@{number="2",exp="x"@}
594fe323 27197(gdb)
922fbb7b
AC
27198-exec-continue
27199^running
0869d01b
NR
27200(gdb)
27201*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 27202value=@{old="-268439212",new="55"@},
76ff342d 27203frame=@{func="main",args=[],file="recursive2.c",
948d5102 27204fullname="/home/foo/bar/recursive2.c",line="5"@}
594fe323 27205(gdb)
922fbb7b
AC
27206@end smallexample
27207
27208Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
27209the program execution twice: first for the variable changing value, then
27210for the watchpoint going out of scope.
27211
27212@smallexample
594fe323 27213(gdb)
922fbb7b
AC
27214-break-watch C
27215^done,wpt=@{number="5",exp="C"@}
594fe323 27216(gdb)
922fbb7b
AC
27217-exec-continue
27218^running
0869d01b
NR
27219(gdb)
27220*stopped,reason="watchpoint-trigger",
922fbb7b
AC
27221wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
27222frame=@{func="callee4",args=[],
76ff342d
DJ
27223file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27224fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 27225(gdb)
922fbb7b
AC
27226-exec-continue
27227^running
0869d01b
NR
27228(gdb)
27229*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
27230frame=@{func="callee3",args=[@{name="strarg",
27231value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
27232file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27233fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 27234(gdb)
922fbb7b
AC
27235@end smallexample
27236
27237Listing breakpoints and watchpoints, at different points in the program
27238execution. Note that once the watchpoint goes out of scope, it is
27239deleted.
27240
27241@smallexample
594fe323 27242(gdb)
922fbb7b
AC
27243-break-watch C
27244^done,wpt=@{number="2",exp="C"@}
594fe323 27245(gdb)
922fbb7b
AC
27246-break-list
27247^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
27248hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
27249@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
27250@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
27251@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
27252@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
27253@{width="40",alignment="2",col_name="what",colhdr="What"@}],
27254body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
27255addr="0x00010734",func="callee4",
948d5102 27256file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
27257fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
27258times="1"@},
922fbb7b 27259bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 27260enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
594fe323 27261(gdb)
922fbb7b
AC
27262-exec-continue
27263^running
0869d01b
NR
27264(gdb)
27265*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
27266value=@{old="-276895068",new="3"@},
27267frame=@{func="callee4",args=[],
76ff342d
DJ
27268file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27269fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 27270(gdb)
922fbb7b
AC
27271-break-list
27272^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
27273hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
27274@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
27275@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
27276@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
27277@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
27278@{width="40",alignment="2",col_name="what",colhdr="What"@}],
27279body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
27280addr="0x00010734",func="callee4",
948d5102 27281file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
27282fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
27283times="1"@},
922fbb7b 27284bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 27285enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
594fe323 27286(gdb)
922fbb7b
AC
27287-exec-continue
27288^running
27289^done,reason="watchpoint-scope",wpnum="2",
27290frame=@{func="callee3",args=[@{name="strarg",
27291value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
27292file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27293fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 27294(gdb)
922fbb7b
AC
27295-break-list
27296^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
27297hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
27298@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
27299@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
27300@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
27301@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
27302@{width="40",alignment="2",col_name="what",colhdr="What"@}],
27303body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
27304addr="0x00010734",func="callee4",
948d5102
NR
27305file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27306fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
998580f1 27307thread-groups=["i1"],times="1"@}]@}
594fe323 27308(gdb)
922fbb7b
AC
27309@end smallexample
27310
3fa7bf06
MG
27311
27312@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27313@node GDB/MI Catchpoint Commands
27314@section @sc{gdb/mi} Catchpoint Commands
27315
27316This section documents @sc{gdb/mi} commands for manipulating
27317catchpoints.
27318
40555925
JB
27319@menu
27320* Shared Library GDB/MI Catchpoint Commands::
27321* Ada Exception GDB/MI Catchpoint Commands::
27322@end menu
27323
27324@node Shared Library GDB/MI Catchpoint Commands
27325@subsection Shared Library @sc{gdb/mi} Catchpoints
27326
3fa7bf06
MG
27327@subheading The @code{-catch-load} Command
27328@findex -catch-load
27329
27330@subsubheading Synopsis
27331
27332@smallexample
27333 -catch-load [ -t ] [ -d ] @var{regexp}
27334@end smallexample
27335
27336Add a catchpoint for library load events. If the @samp{-t} option is used,
27337the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
27338Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
27339in a disabled state. The @samp{regexp} argument is a regular
27340expression used to match the name of the loaded library.
27341
27342
27343@subsubheading @value{GDBN} Command
27344
27345The corresponding @value{GDBN} command is @samp{catch load}.
27346
27347@subsubheading Example
27348
27349@smallexample
27350-catch-load -t foo.so
27351^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
8ac3646f 27352what="load of library matching foo.so",catch-type="load",times="0"@}
3fa7bf06
MG
27353(gdb)
27354@end smallexample
27355
27356
27357@subheading The @code{-catch-unload} Command
27358@findex -catch-unload
27359
27360@subsubheading Synopsis
27361
27362@smallexample
27363 -catch-unload [ -t ] [ -d ] @var{regexp}
27364@end smallexample
27365
27366Add a catchpoint for library unload events. If the @samp{-t} option is
27367used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
27368Breakpoints}). If the @samp{-d} option is used, the catchpoint is
27369created in a disabled state. The @samp{regexp} argument is a regular
27370expression used to match the name of the unloaded library.
27371
27372@subsubheading @value{GDBN} Command
27373
27374The corresponding @value{GDBN} command is @samp{catch unload}.
27375
27376@subsubheading Example
27377
27378@smallexample
27379-catch-unload -d bar.so
27380^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
8ac3646f 27381what="load of library matching bar.so",catch-type="unload",times="0"@}
3fa7bf06
MG
27382(gdb)
27383@end smallexample
27384
40555925
JB
27385@node Ada Exception GDB/MI Catchpoint Commands
27386@subsection Ada Exception @sc{gdb/mi} Catchpoints
27387
27388The following @sc{gdb/mi} commands can be used to create catchpoints
27389that stop the execution when Ada exceptions are being raised.
27390
27391@subheading The @code{-catch-assert} Command
27392@findex -catch-assert
27393
27394@subsubheading Synopsis
27395
27396@smallexample
27397 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
27398@end smallexample
27399
27400Add a catchpoint for failed Ada assertions.
27401
27402The possible optional parameters for this command are:
27403
27404@table @samp
27405@item -c @var{condition}
27406Make the catchpoint conditional on @var{condition}.
27407@item -d
27408Create a disabled catchpoint.
27409@item -t
27410Create a temporary catchpoint.
27411@end table
27412
27413@subsubheading @value{GDBN} Command
27414
27415The corresponding @value{GDBN} command is @samp{catch assert}.
27416
27417@subsubheading Example
27418
27419@smallexample
27420-catch-assert
27421^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
27422enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
27423thread-groups=["i1"],times="0",
27424original-location="__gnat_debug_raise_assert_failure"@}
27425(gdb)
27426@end smallexample
27427
27428@subheading The @code{-catch-exception} Command
27429@findex -catch-exception
27430
27431@subsubheading Synopsis
27432
27433@smallexample
27434 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
27435 [ -t ] [ -u ]
27436@end smallexample
27437
27438Add a catchpoint stopping when Ada exceptions are raised.
27439By default, the command stops the program when any Ada exception
27440gets raised. But it is also possible, by using some of the
27441optional parameters described below, to create more selective
27442catchpoints.
27443
27444The possible optional parameters for this command are:
27445
27446@table @samp
27447@item -c @var{condition}
27448Make the catchpoint conditional on @var{condition}.
27449@item -d
27450Create a disabled catchpoint.
27451@item -e @var{exception-name}
27452Only stop when @var{exception-name} is raised. This option cannot
27453be used combined with @samp{-u}.
27454@item -t
27455Create a temporary catchpoint.
27456@item -u
27457Stop only when an unhandled exception gets raised. This option
27458cannot be used combined with @samp{-e}.
27459@end table
27460
27461@subsubheading @value{GDBN} Command
27462
27463The corresponding @value{GDBN} commands are @samp{catch exception}
27464and @samp{catch exception unhandled}.
27465
27466@subsubheading Example
27467
27468@smallexample
27469-catch-exception -e Program_Error
27470^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
27471enabled="y",addr="0x0000000000404874",
27472what="`Program_Error' Ada exception", thread-groups=["i1"],
27473times="0",original-location="__gnat_debug_raise_exception"@}
27474(gdb)
27475@end smallexample
3fa7bf06 27476
922fbb7b 27477@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
27478@node GDB/MI Program Context
27479@section @sc{gdb/mi} Program Context
922fbb7b 27480
a2c02241
NR
27481@subheading The @code{-exec-arguments} Command
27482@findex -exec-arguments
922fbb7b 27483
922fbb7b
AC
27484
27485@subsubheading Synopsis
27486
27487@smallexample
a2c02241 27488 -exec-arguments @var{args}
922fbb7b
AC
27489@end smallexample
27490
a2c02241
NR
27491Set the inferior program arguments, to be used in the next
27492@samp{-exec-run}.
922fbb7b 27493
a2c02241 27494@subsubheading @value{GDBN} Command
922fbb7b 27495
a2c02241 27496The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 27497
a2c02241 27498@subsubheading Example
922fbb7b 27499
fbc5282e
MK
27500@smallexample
27501(gdb)
27502-exec-arguments -v word
27503^done
27504(gdb)
27505@end smallexample
922fbb7b 27506
a2c02241 27507
9901a55b 27508@ignore
a2c02241
NR
27509@subheading The @code{-exec-show-arguments} Command
27510@findex -exec-show-arguments
27511
27512@subsubheading Synopsis
27513
27514@smallexample
27515 -exec-show-arguments
27516@end smallexample
27517
27518Print the arguments of the program.
922fbb7b
AC
27519
27520@subsubheading @value{GDBN} Command
27521
a2c02241 27522The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
27523
27524@subsubheading Example
a2c02241 27525N.A.
9901a55b 27526@end ignore
922fbb7b 27527
922fbb7b 27528
a2c02241
NR
27529@subheading The @code{-environment-cd} Command
27530@findex -environment-cd
922fbb7b 27531
a2c02241 27532@subsubheading Synopsis
922fbb7b
AC
27533
27534@smallexample
a2c02241 27535 -environment-cd @var{pathdir}
922fbb7b
AC
27536@end smallexample
27537
a2c02241 27538Set @value{GDBN}'s working directory.
922fbb7b 27539
a2c02241 27540@subsubheading @value{GDBN} Command
922fbb7b 27541
a2c02241
NR
27542The corresponding @value{GDBN} command is @samp{cd}.
27543
27544@subsubheading Example
922fbb7b
AC
27545
27546@smallexample
594fe323 27547(gdb)
a2c02241
NR
27548-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
27549^done
594fe323 27550(gdb)
922fbb7b
AC
27551@end smallexample
27552
27553
a2c02241
NR
27554@subheading The @code{-environment-directory} Command
27555@findex -environment-directory
922fbb7b
AC
27556
27557@subsubheading Synopsis
27558
27559@smallexample
a2c02241 27560 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
27561@end smallexample
27562
a2c02241
NR
27563Add directories @var{pathdir} to beginning of search path for source files.
27564If the @samp{-r} option is used, the search path is reset to the default
27565search path. If directories @var{pathdir} are supplied in addition to the
27566@samp{-r} option, the search path is first reset and then addition
27567occurs as normal.
27568Multiple directories may be specified, separated by blanks. Specifying
27569multiple directories in a single command
27570results in the directories added to the beginning of the
27571search path in the same order they were presented in the command.
27572If blanks are needed as
27573part of a directory name, double-quotes should be used around
27574the name. In the command output, the path will show up separated
d3e8051b 27575by the system directory-separator character. The directory-separator
a2c02241
NR
27576character must not be used
27577in any directory name.
27578If no directories are specified, the current search path is displayed.
922fbb7b
AC
27579
27580@subsubheading @value{GDBN} Command
27581
a2c02241 27582The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
27583
27584@subsubheading Example
27585
922fbb7b 27586@smallexample
594fe323 27587(gdb)
a2c02241
NR
27588-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
27589^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 27590(gdb)
a2c02241
NR
27591-environment-directory ""
27592^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 27593(gdb)
a2c02241
NR
27594-environment-directory -r /home/jjohnstn/src/gdb /usr/src
27595^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 27596(gdb)
a2c02241
NR
27597-environment-directory -r
27598^done,source-path="$cdir:$cwd"
594fe323 27599(gdb)
922fbb7b
AC
27600@end smallexample
27601
27602
a2c02241
NR
27603@subheading The @code{-environment-path} Command
27604@findex -environment-path
922fbb7b
AC
27605
27606@subsubheading Synopsis
27607
27608@smallexample
a2c02241 27609 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
27610@end smallexample
27611
a2c02241
NR
27612Add directories @var{pathdir} to beginning of search path for object files.
27613If the @samp{-r} option is used, the search path is reset to the original
27614search path that existed at gdb start-up. If directories @var{pathdir} are
27615supplied in addition to the
27616@samp{-r} option, the search path is first reset and then addition
27617occurs as normal.
27618Multiple directories may be specified, separated by blanks. Specifying
27619multiple directories in a single command
27620results in the directories added to the beginning of the
27621search path in the same order they were presented in the command.
27622If blanks are needed as
27623part of a directory name, double-quotes should be used around
27624the name. In the command output, the path will show up separated
d3e8051b 27625by the system directory-separator character. The directory-separator
a2c02241
NR
27626character must not be used
27627in any directory name.
27628If no directories are specified, the current path is displayed.
27629
922fbb7b
AC
27630
27631@subsubheading @value{GDBN} Command
27632
a2c02241 27633The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
27634
27635@subsubheading Example
27636
922fbb7b 27637@smallexample
594fe323 27638(gdb)
a2c02241
NR
27639-environment-path
27640^done,path="/usr/bin"
594fe323 27641(gdb)
a2c02241
NR
27642-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
27643^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 27644(gdb)
a2c02241
NR
27645-environment-path -r /usr/local/bin
27646^done,path="/usr/local/bin:/usr/bin"
594fe323 27647(gdb)
922fbb7b
AC
27648@end smallexample
27649
27650
a2c02241
NR
27651@subheading The @code{-environment-pwd} Command
27652@findex -environment-pwd
922fbb7b
AC
27653
27654@subsubheading Synopsis
27655
27656@smallexample
a2c02241 27657 -environment-pwd
922fbb7b
AC
27658@end smallexample
27659
a2c02241 27660Show the current working directory.
922fbb7b 27661
79a6e687 27662@subsubheading @value{GDBN} Command
922fbb7b 27663
a2c02241 27664The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
27665
27666@subsubheading Example
27667
922fbb7b 27668@smallexample
594fe323 27669(gdb)
a2c02241
NR
27670-environment-pwd
27671^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 27672(gdb)
922fbb7b
AC
27673@end smallexample
27674
a2c02241
NR
27675@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27676@node GDB/MI Thread Commands
27677@section @sc{gdb/mi} Thread Commands
27678
27679
27680@subheading The @code{-thread-info} Command
27681@findex -thread-info
922fbb7b
AC
27682
27683@subsubheading Synopsis
27684
27685@smallexample
8e8901c5 27686 -thread-info [ @var{thread-id} ]
922fbb7b
AC
27687@end smallexample
27688
5d5658a1
PA
27689Reports information about either a specific thread, if the
27690@var{thread-id} parameter is present, or about all threads.
27691@var{thread-id} is the thread's global thread ID. When printing
27692information about all threads, also reports the global ID of the
27693current thread.
8e8901c5 27694
79a6e687 27695@subsubheading @value{GDBN} Command
922fbb7b 27696
8e8901c5
VP
27697The @samp{info thread} command prints the same information
27698about all threads.
922fbb7b 27699
4694da01 27700@subsubheading Result
922fbb7b 27701
4694da01
TT
27702The result is a list of threads. The following attributes are
27703defined for a given thread:
27704
27705@table @samp
27706@item current
27707This field exists only for the current thread. It has the value @samp{*}.
27708
27709@item id
5d5658a1 27710The global identifier that @value{GDBN} uses to refer to the thread.
4694da01
TT
27711
27712@item target-id
27713The identifier that the target uses to refer to the thread.
27714
27715@item details
27716Extra information about the thread, in a target-specific format. This
27717field is optional.
27718
27719@item name
27720The name of the thread. If the user specified a name using the
27721@code{thread name} command, then this name is given. Otherwise, if
27722@value{GDBN} can extract the thread name from the target, then that
27723name is given. If @value{GDBN} cannot find the thread name, then this
27724field is omitted.
27725
27726@item frame
27727The stack frame currently executing in the thread.
922fbb7b 27728
4694da01
TT
27729@item state
27730The thread's state. The @samp{state} field may have the following
27731values:
c3b108f7
VP
27732
27733@table @code
27734@item stopped
27735The thread is stopped. Frame information is available for stopped
27736threads.
27737
27738@item running
27739The thread is running. There's no frame information for running
27740threads.
27741
27742@end table
27743
4694da01
TT
27744@item core
27745If @value{GDBN} can find the CPU core on which this thread is running,
27746then this field is the core identifier. This field is optional.
27747
27748@end table
27749
27750@subsubheading Example
27751
27752@smallexample
27753-thread-info
27754^done,threads=[
27755@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
27756 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
27757 args=[]@},state="running"@},
27758@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
27759 frame=@{level="0",addr="0x0804891f",func="foo",
27760 args=[@{name="i",value="10"@}],
27761 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},
27762 state="running"@}],
27763current-thread-id="1"
27764(gdb)
27765@end smallexample
27766
a2c02241
NR
27767@subheading The @code{-thread-list-ids} Command
27768@findex -thread-list-ids
922fbb7b 27769
a2c02241 27770@subsubheading Synopsis
922fbb7b 27771
a2c02241
NR
27772@smallexample
27773 -thread-list-ids
27774@end smallexample
922fbb7b 27775
5d5658a1
PA
27776Produces a list of the currently known global @value{GDBN} thread ids.
27777At the end of the list it also prints the total number of such
27778threads.
922fbb7b 27779
c3b108f7
VP
27780This command is retained for historical reasons, the
27781@code{-thread-info} command should be used instead.
27782
922fbb7b
AC
27783@subsubheading @value{GDBN} Command
27784
a2c02241 27785Part of @samp{info threads} supplies the same information.
922fbb7b
AC
27786
27787@subsubheading Example
27788
922fbb7b 27789@smallexample
594fe323 27790(gdb)
a2c02241
NR
27791-thread-list-ids
27792^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
592375cd 27793current-thread-id="1",number-of-threads="3"
594fe323 27794(gdb)
922fbb7b
AC
27795@end smallexample
27796
a2c02241
NR
27797
27798@subheading The @code{-thread-select} Command
27799@findex -thread-select
922fbb7b
AC
27800
27801@subsubheading Synopsis
27802
27803@smallexample
5d5658a1 27804 -thread-select @var{thread-id}
922fbb7b
AC
27805@end smallexample
27806
5d5658a1
PA
27807Make thread with global thread number @var{thread-id} the current
27808thread. It prints the number of the new current thread, and the
27809topmost frame for that thread.
922fbb7b 27810
c3b108f7
VP
27811This command is deprecated in favor of explicitly using the
27812@samp{--thread} option to each command.
27813
922fbb7b
AC
27814@subsubheading @value{GDBN} Command
27815
a2c02241 27816The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
27817
27818@subsubheading Example
922fbb7b
AC
27819
27820@smallexample
594fe323 27821(gdb)
a2c02241
NR
27822-exec-next
27823^running
594fe323 27824(gdb)
a2c02241
NR
27825*stopped,reason="end-stepping-range",thread-id="2",line="187",
27826file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 27827(gdb)
a2c02241
NR
27828-thread-list-ids
27829^done,
27830thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
27831number-of-threads="3"
594fe323 27832(gdb)
a2c02241
NR
27833-thread-select 3
27834^done,new-thread-id="3",
27835frame=@{level="0",func="vprintf",
27836args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
27837@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
594fe323 27838(gdb)
922fbb7b
AC
27839@end smallexample
27840
5d77fe44
JB
27841@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27842@node GDB/MI Ada Tasking Commands
27843@section @sc{gdb/mi} Ada Tasking Commands
27844
27845@subheading The @code{-ada-task-info} Command
27846@findex -ada-task-info
27847
27848@subsubheading Synopsis
27849
27850@smallexample
27851 -ada-task-info [ @var{task-id} ]
27852@end smallexample
27853
27854Reports information about either a specific Ada task, if the
27855@var{task-id} parameter is present, or about all Ada tasks.
27856
27857@subsubheading @value{GDBN} Command
27858
27859The @samp{info tasks} command prints the same information
27860about all Ada tasks (@pxref{Ada Tasks}).
27861
27862@subsubheading Result
27863
27864The result is a table of Ada tasks. The following columns are
27865defined for each Ada task:
27866
27867@table @samp
27868@item current
27869This field exists only for the current thread. It has the value @samp{*}.
27870
27871@item id
27872The identifier that @value{GDBN} uses to refer to the Ada task.
27873
27874@item task-id
27875The identifier that the target uses to refer to the Ada task.
27876
27877@item thread-id
5d5658a1
PA
27878The global thread identifier of the thread corresponding to the Ada
27879task.
5d77fe44
JB
27880
27881This field should always exist, as Ada tasks are always implemented
27882on top of a thread. But if @value{GDBN} cannot find this corresponding
27883thread for any reason, the field is omitted.
27884
27885@item parent-id
27886This field exists only when the task was created by another task.
27887In this case, it provides the ID of the parent task.
27888
27889@item priority
27890The base priority of the task.
27891
27892@item state
27893The current state of the task. For a detailed description of the
27894possible states, see @ref{Ada Tasks}.
27895
27896@item name
27897The name of the task.
27898
27899@end table
27900
27901@subsubheading Example
27902
27903@smallexample
27904-ada-task-info
27905^done,tasks=@{nr_rows="3",nr_cols="8",
27906hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
27907@{width="3",alignment="1",col_name="id",colhdr="ID"@},
27908@{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
27909@{width="4",alignment="1",col_name="thread-id",colhdr=""@},
27910@{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
27911@{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
27912@{width="22",alignment="-1",col_name="state",colhdr="State"@},
27913@{width="1",alignment="2",col_name="name",colhdr="Name"@}],
27914body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
27915state="Child Termination Wait",name="main_task"@}]@}
27916(gdb)
27917@end smallexample
27918
a2c02241
NR
27919@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27920@node GDB/MI Program Execution
27921@section @sc{gdb/mi} Program Execution
922fbb7b 27922
ef21caaf 27923These are the asynchronous commands which generate the out-of-band
3f94c067 27924record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
27925asynchronously with remote targets and this interaction is mimicked in
27926other cases.
922fbb7b 27927
922fbb7b
AC
27928@subheading The @code{-exec-continue} Command
27929@findex -exec-continue
27930
27931@subsubheading Synopsis
27932
27933@smallexample
540aa8e7 27934 -exec-continue [--reverse] [--all|--thread-group N]
922fbb7b
AC
27935@end smallexample
27936
540aa8e7
MS
27937Resumes the execution of the inferior program, which will continue
27938to execute until it reaches a debugger stop event. If the
27939@samp{--reverse} option is specified, execution resumes in reverse until
27940it reaches a stop event. Stop events may include
27941@itemize @bullet
27942@item
27943breakpoints or watchpoints
27944@item
27945signals or exceptions
27946@item
27947the end of the process (or its beginning under @samp{--reverse})
27948@item
27949the end or beginning of a replay log if one is being used.
27950@end itemize
27951In all-stop mode (@pxref{All-Stop
27952Mode}), may resume only one thread, or all threads, depending on the
27953value of the @samp{scheduler-locking} variable. If @samp{--all} is
a79b8f6e 27954specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
540aa8e7
MS
27955ignored in all-stop mode. If the @samp{--thread-group} options is
27956specified, then all threads in that thread group are resumed.
922fbb7b
AC
27957
27958@subsubheading @value{GDBN} Command
27959
27960The corresponding @value{GDBN} corresponding is @samp{continue}.
27961
27962@subsubheading Example
27963
27964@smallexample
27965-exec-continue
27966^running
594fe323 27967(gdb)
922fbb7b 27968@@Hello world
a47ec5fe
AR
27969*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
27970func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
27971line="13"@}
594fe323 27972(gdb)
922fbb7b
AC
27973@end smallexample
27974
27975
27976@subheading The @code{-exec-finish} Command
27977@findex -exec-finish
27978
27979@subsubheading Synopsis
27980
27981@smallexample
540aa8e7 27982 -exec-finish [--reverse]
922fbb7b
AC
27983@end smallexample
27984
ef21caaf
NR
27985Resumes the execution of the inferior program until the current
27986function is exited. Displays the results returned by the function.
540aa8e7
MS
27987If the @samp{--reverse} option is specified, resumes the reverse
27988execution of the inferior program until the point where current
27989function was called.
922fbb7b
AC
27990
27991@subsubheading @value{GDBN} Command
27992
27993The corresponding @value{GDBN} command is @samp{finish}.
27994
27995@subsubheading Example
27996
27997Function returning @code{void}.
27998
27999@smallexample
28000-exec-finish
28001^running
594fe323 28002(gdb)
922fbb7b
AC
28003@@hello from foo
28004*stopped,reason="function-finished",frame=@{func="main",args=[],
948d5102 28005file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
594fe323 28006(gdb)
922fbb7b
AC
28007@end smallexample
28008
28009Function returning other than @code{void}. The name of the internal
28010@value{GDBN} variable storing the result is printed, together with the
28011value itself.
28012
28013@smallexample
28014-exec-finish
28015^running
594fe323 28016(gdb)
922fbb7b
AC
28017*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
28018args=[@{name="a",value="1"],@{name="b",value="9"@}@},
948d5102 28019file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
922fbb7b 28020gdb-result-var="$1",return-value="0"
594fe323 28021(gdb)
922fbb7b
AC
28022@end smallexample
28023
28024
28025@subheading The @code{-exec-interrupt} Command
28026@findex -exec-interrupt
28027
28028@subsubheading Synopsis
28029
28030@smallexample
c3b108f7 28031 -exec-interrupt [--all|--thread-group N]
922fbb7b
AC
28032@end smallexample
28033
ef21caaf
NR
28034Interrupts the background execution of the target. Note how the token
28035associated with the stop message is the one for the execution command
28036that has been interrupted. The token for the interrupt itself only
28037appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
28038interrupt a non-running program, an error message will be printed.
28039
c3b108f7
VP
28040Note that when asynchronous execution is enabled, this command is
28041asynchronous just like other execution commands. That is, first the
28042@samp{^done} response will be printed, and the target stop will be
28043reported after that using the @samp{*stopped} notification.
28044
28045In non-stop mode, only the context thread is interrupted by default.
a79b8f6e
VP
28046All threads (in all inferiors) will be interrupted if the
28047@samp{--all} option is specified. If the @samp{--thread-group}
28048option is specified, all threads in that group will be interrupted.
c3b108f7 28049
922fbb7b
AC
28050@subsubheading @value{GDBN} Command
28051
28052The corresponding @value{GDBN} command is @samp{interrupt}.
28053
28054@subsubheading Example
28055
28056@smallexample
594fe323 28057(gdb)
922fbb7b
AC
28058111-exec-continue
28059111^running
28060
594fe323 28061(gdb)
922fbb7b
AC
28062222-exec-interrupt
28063222^done
594fe323 28064(gdb)
922fbb7b 28065111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 28066frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
948d5102 28067fullname="/home/foo/bar/try.c",line="13"@}
594fe323 28068(gdb)
922fbb7b 28069
594fe323 28070(gdb)
922fbb7b
AC
28071-exec-interrupt
28072^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 28073(gdb)
922fbb7b
AC
28074@end smallexample
28075
83eba9b7
VP
28076@subheading The @code{-exec-jump} Command
28077@findex -exec-jump
28078
28079@subsubheading Synopsis
28080
28081@smallexample
28082 -exec-jump @var{location}
28083@end smallexample
28084
28085Resumes execution of the inferior program at the location specified by
28086parameter. @xref{Specify Location}, for a description of the
28087different forms of @var{location}.
28088
28089@subsubheading @value{GDBN} Command
28090
28091The corresponding @value{GDBN} command is @samp{jump}.
28092
28093@subsubheading Example
28094
28095@smallexample
28096-exec-jump foo.c:10
28097*running,thread-id="all"
28098^running
28099@end smallexample
28100
922fbb7b
AC
28101
28102@subheading The @code{-exec-next} Command
28103@findex -exec-next
28104
28105@subsubheading Synopsis
28106
28107@smallexample
540aa8e7 28108 -exec-next [--reverse]
922fbb7b
AC
28109@end smallexample
28110
ef21caaf
NR
28111Resumes execution of the inferior program, stopping when the beginning
28112of the next source line is reached.
922fbb7b 28113
540aa8e7
MS
28114If the @samp{--reverse} option is specified, resumes reverse execution
28115of the inferior program, stopping at the beginning of the previous
28116source line. If you issue this command on the first line of a
28117function, it will take you back to the caller of that function, to the
28118source line where the function was called.
28119
28120
922fbb7b
AC
28121@subsubheading @value{GDBN} Command
28122
28123The corresponding @value{GDBN} command is @samp{next}.
28124
28125@subsubheading Example
28126
28127@smallexample
28128-exec-next
28129^running
594fe323 28130(gdb)
922fbb7b 28131*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 28132(gdb)
922fbb7b
AC
28133@end smallexample
28134
28135
28136@subheading The @code{-exec-next-instruction} Command
28137@findex -exec-next-instruction
28138
28139@subsubheading Synopsis
28140
28141@smallexample
540aa8e7 28142 -exec-next-instruction [--reverse]
922fbb7b
AC
28143@end smallexample
28144
ef21caaf
NR
28145Executes one machine instruction. If the instruction is a function
28146call, continues until the function returns. If the program stops at an
28147instruction in the middle of a source line, the address will be
28148printed as well.
922fbb7b 28149
540aa8e7
MS
28150If the @samp{--reverse} option is specified, resumes reverse execution
28151of the inferior program, stopping at the previous instruction. If the
28152previously executed instruction was a return from another function,
28153it will continue to execute in reverse until the call to that function
28154(from the current stack frame) is reached.
28155
922fbb7b
AC
28156@subsubheading @value{GDBN} Command
28157
28158The corresponding @value{GDBN} command is @samp{nexti}.
28159
28160@subsubheading Example
28161
28162@smallexample
594fe323 28163(gdb)
922fbb7b
AC
28164-exec-next-instruction
28165^running
28166
594fe323 28167(gdb)
922fbb7b
AC
28168*stopped,reason="end-stepping-range",
28169addr="0x000100d4",line="5",file="hello.c"
594fe323 28170(gdb)
922fbb7b
AC
28171@end smallexample
28172
28173
28174@subheading The @code{-exec-return} Command
28175@findex -exec-return
28176
28177@subsubheading Synopsis
28178
28179@smallexample
28180 -exec-return
28181@end smallexample
28182
28183Makes current function return immediately. Doesn't execute the inferior.
28184Displays the new current frame.
28185
28186@subsubheading @value{GDBN} Command
28187
28188The corresponding @value{GDBN} command is @samp{return}.
28189
28190@subsubheading Example
28191
28192@smallexample
594fe323 28193(gdb)
922fbb7b
AC
28194200-break-insert callee4
28195200^done,bkpt=@{number="1",addr="0x00010734",
28196file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 28197(gdb)
922fbb7b
AC
28198000-exec-run
28199000^running
594fe323 28200(gdb)
a47ec5fe 28201000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
922fbb7b 28202frame=@{func="callee4",args=[],
76ff342d
DJ
28203file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28204fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 28205(gdb)
922fbb7b
AC
28206205-break-delete
28207205^done
594fe323 28208(gdb)
922fbb7b
AC
28209111-exec-return
28210111^done,frame=@{level="0",func="callee3",
28211args=[@{name="strarg",
28212value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
28213file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28214fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 28215(gdb)
922fbb7b
AC
28216@end smallexample
28217
28218
28219@subheading The @code{-exec-run} Command
28220@findex -exec-run
28221
28222@subsubheading Synopsis
28223
28224@smallexample
5713b9b5 28225 -exec-run [ --all | --thread-group N ] [ --start ]
922fbb7b
AC
28226@end smallexample
28227
ef21caaf
NR
28228Starts execution of the inferior from the beginning. The inferior
28229executes until either a breakpoint is encountered or the program
28230exits. In the latter case the output will include an exit code, if
28231the program has exited exceptionally.
922fbb7b 28232
5713b9b5
JB
28233When neither the @samp{--all} nor the @samp{--thread-group} option
28234is specified, the current inferior is started. If the
a79b8f6e
VP
28235@samp{--thread-group} option is specified, it should refer to a thread
28236group of type @samp{process}, and that thread group will be started.
28237If the @samp{--all} option is specified, then all inferiors will be started.
28238
5713b9b5
JB
28239Using the @samp{--start} option instructs the debugger to stop
28240the execution at the start of the inferior's main subprogram,
28241following the same behavior as the @code{start} command
28242(@pxref{Starting}).
28243
922fbb7b
AC
28244@subsubheading @value{GDBN} Command
28245
28246The corresponding @value{GDBN} command is @samp{run}.
28247
ef21caaf 28248@subsubheading Examples
922fbb7b
AC
28249
28250@smallexample
594fe323 28251(gdb)
922fbb7b
AC
28252-break-insert main
28253^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 28254(gdb)
922fbb7b
AC
28255-exec-run
28256^running
594fe323 28257(gdb)
a47ec5fe 28258*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
76ff342d 28259frame=@{func="main",args=[],file="recursive2.c",
948d5102 28260fullname="/home/foo/bar/recursive2.c",line="4"@}
594fe323 28261(gdb)
922fbb7b
AC
28262@end smallexample
28263
ef21caaf
NR
28264@noindent
28265Program exited normally:
28266
28267@smallexample
594fe323 28268(gdb)
ef21caaf
NR
28269-exec-run
28270^running
594fe323 28271(gdb)
ef21caaf
NR
28272x = 55
28273*stopped,reason="exited-normally"
594fe323 28274(gdb)
ef21caaf
NR
28275@end smallexample
28276
28277@noindent
28278Program exited exceptionally:
28279
28280@smallexample
594fe323 28281(gdb)
ef21caaf
NR
28282-exec-run
28283^running
594fe323 28284(gdb)
ef21caaf
NR
28285x = 55
28286*stopped,reason="exited",exit-code="01"
594fe323 28287(gdb)
ef21caaf
NR
28288@end smallexample
28289
28290Another way the program can terminate is if it receives a signal such as
28291@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
28292
28293@smallexample
594fe323 28294(gdb)
ef21caaf
NR
28295*stopped,reason="exited-signalled",signal-name="SIGINT",
28296signal-meaning="Interrupt"
28297@end smallexample
28298
922fbb7b 28299
a2c02241
NR
28300@c @subheading -exec-signal
28301
28302
28303@subheading The @code{-exec-step} Command
28304@findex -exec-step
922fbb7b
AC
28305
28306@subsubheading Synopsis
28307
28308@smallexample
540aa8e7 28309 -exec-step [--reverse]
922fbb7b
AC
28310@end smallexample
28311
a2c02241
NR
28312Resumes execution of the inferior program, stopping when the beginning
28313of the next source line is reached, if the next source line is not a
28314function call. If it is, stop at the first instruction of the called
540aa8e7
MS
28315function. If the @samp{--reverse} option is specified, resumes reverse
28316execution of the inferior program, stopping at the beginning of the
28317previously executed source line.
922fbb7b
AC
28318
28319@subsubheading @value{GDBN} Command
28320
a2c02241 28321The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
28322
28323@subsubheading Example
28324
28325Stepping into a function:
28326
28327@smallexample
28328-exec-step
28329^running
594fe323 28330(gdb)
922fbb7b
AC
28331*stopped,reason="end-stepping-range",
28332frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 28333@{name="b",value="0"@}],file="recursive2.c",
948d5102 28334fullname="/home/foo/bar/recursive2.c",line="11"@}
594fe323 28335(gdb)
922fbb7b
AC
28336@end smallexample
28337
28338Regular stepping:
28339
28340@smallexample
28341-exec-step
28342^running
594fe323 28343(gdb)
922fbb7b 28344*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 28345(gdb)
922fbb7b
AC
28346@end smallexample
28347
28348
28349@subheading The @code{-exec-step-instruction} Command
28350@findex -exec-step-instruction
28351
28352@subsubheading Synopsis
28353
28354@smallexample
540aa8e7 28355 -exec-step-instruction [--reverse]
922fbb7b
AC
28356@end smallexample
28357
540aa8e7
MS
28358Resumes the inferior which executes one machine instruction. If the
28359@samp{--reverse} option is specified, resumes reverse execution of the
28360inferior program, stopping at the previously executed instruction.
28361The output, once @value{GDBN} has stopped, will vary depending on
28362whether we have stopped in the middle of a source line or not. In the
28363former case, the address at which the program stopped will be printed
28364as well.
922fbb7b
AC
28365
28366@subsubheading @value{GDBN} Command
28367
28368The corresponding @value{GDBN} command is @samp{stepi}.
28369
28370@subsubheading Example
28371
28372@smallexample
594fe323 28373(gdb)
922fbb7b
AC
28374-exec-step-instruction
28375^running
28376
594fe323 28377(gdb)
922fbb7b 28378*stopped,reason="end-stepping-range",
76ff342d 28379frame=@{func="foo",args=[],file="try.c",
948d5102 28380fullname="/home/foo/bar/try.c",line="10"@}
594fe323 28381(gdb)
922fbb7b
AC
28382-exec-step-instruction
28383^running
28384
594fe323 28385(gdb)
922fbb7b 28386*stopped,reason="end-stepping-range",
76ff342d 28387frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
948d5102 28388fullname="/home/foo/bar/try.c",line="10"@}
594fe323 28389(gdb)
922fbb7b
AC
28390@end smallexample
28391
28392
28393@subheading The @code{-exec-until} Command
28394@findex -exec-until
28395
28396@subsubheading Synopsis
28397
28398@smallexample
28399 -exec-until [ @var{location} ]
28400@end smallexample
28401
ef21caaf
NR
28402Executes the inferior until the @var{location} specified in the
28403argument is reached. If there is no argument, the inferior executes
28404until a source line greater than the current one is reached. The
28405reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
28406
28407@subsubheading @value{GDBN} Command
28408
28409The corresponding @value{GDBN} command is @samp{until}.
28410
28411@subsubheading Example
28412
28413@smallexample
594fe323 28414(gdb)
922fbb7b
AC
28415-exec-until recursive2.c:6
28416^running
594fe323 28417(gdb)
922fbb7b
AC
28418x = 55
28419*stopped,reason="location-reached",frame=@{func="main",args=[],
948d5102 28420file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
594fe323 28421(gdb)
922fbb7b
AC
28422@end smallexample
28423
28424@ignore
28425@subheading -file-clear
28426Is this going away????
28427@end ignore
28428
351ff01a 28429@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
28430@node GDB/MI Stack Manipulation
28431@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 28432
1e611234
PM
28433@subheading The @code{-enable-frame-filters} Command
28434@findex -enable-frame-filters
28435
28436@smallexample
28437-enable-frame-filters
28438@end smallexample
28439
28440@value{GDBN} allows Python-based frame filters to affect the output of
28441the MI commands relating to stack traces. As there is no way to
28442implement this in a fully backward-compatible way, a front end must
28443request that this functionality be enabled.
28444
28445Once enabled, this feature cannot be disabled.
28446
28447Note that if Python support has not been compiled into @value{GDBN},
28448this command will still succeed (and do nothing).
922fbb7b 28449
a2c02241
NR
28450@subheading The @code{-stack-info-frame} Command
28451@findex -stack-info-frame
922fbb7b
AC
28452
28453@subsubheading Synopsis
28454
28455@smallexample
a2c02241 28456 -stack-info-frame
922fbb7b
AC
28457@end smallexample
28458
a2c02241 28459Get info on the selected frame.
922fbb7b
AC
28460
28461@subsubheading @value{GDBN} Command
28462
a2c02241
NR
28463The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
28464(without arguments).
922fbb7b
AC
28465
28466@subsubheading Example
28467
28468@smallexample
594fe323 28469(gdb)
a2c02241
NR
28470-stack-info-frame
28471^done,frame=@{level="1",addr="0x0001076c",func="callee3",
28472file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28473fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
594fe323 28474(gdb)
922fbb7b
AC
28475@end smallexample
28476
a2c02241
NR
28477@subheading The @code{-stack-info-depth} Command
28478@findex -stack-info-depth
922fbb7b
AC
28479
28480@subsubheading Synopsis
28481
28482@smallexample
a2c02241 28483 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
28484@end smallexample
28485
a2c02241
NR
28486Return the depth of the stack. If the integer argument @var{max-depth}
28487is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
28488
28489@subsubheading @value{GDBN} Command
28490
a2c02241 28491There's no equivalent @value{GDBN} command.
922fbb7b
AC
28492
28493@subsubheading Example
28494
a2c02241
NR
28495For a stack with frame levels 0 through 11:
28496
922fbb7b 28497@smallexample
594fe323 28498(gdb)
a2c02241
NR
28499-stack-info-depth
28500^done,depth="12"
594fe323 28501(gdb)
a2c02241
NR
28502-stack-info-depth 4
28503^done,depth="4"
594fe323 28504(gdb)
a2c02241
NR
28505-stack-info-depth 12
28506^done,depth="12"
594fe323 28507(gdb)
a2c02241
NR
28508-stack-info-depth 11
28509^done,depth="11"
594fe323 28510(gdb)
a2c02241
NR
28511-stack-info-depth 13
28512^done,depth="12"
594fe323 28513(gdb)
922fbb7b
AC
28514@end smallexample
28515
1e611234 28516@anchor{-stack-list-arguments}
a2c02241
NR
28517@subheading The @code{-stack-list-arguments} Command
28518@findex -stack-list-arguments
922fbb7b
AC
28519
28520@subsubheading Synopsis
28521
28522@smallexample
6211c335 28523 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
a2c02241 28524 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
28525@end smallexample
28526
a2c02241
NR
28527Display a list of the arguments for the frames between @var{low-frame}
28528and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
28529@var{high-frame} are not provided, list the arguments for the whole
28530call stack. If the two arguments are equal, show the single frame
28531at the corresponding level. It is an error if @var{low-frame} is
28532larger than the actual number of frames. On the other hand,
28533@var{high-frame} may be larger than the actual number of frames, in
28534which case only existing frames will be returned.
a2c02241 28535
3afae151
VP
28536If @var{print-values} is 0 or @code{--no-values}, print only the names of
28537the variables; if it is 1 or @code{--all-values}, print also their
28538values; and if it is 2 or @code{--simple-values}, print the name,
28539type and value for simple data types, and the name and type for arrays,
1e611234
PM
28540structures and unions. If the option @code{--no-frame-filters} is
28541supplied, then Python frame filters will not be executed.
28542
6211c335
YQ
28543If the @code{--skip-unavailable} option is specified, arguments that
28544are not available are not listed. Partially available arguments
28545are still displayed, however.
922fbb7b 28546
b3372f91
VP
28547Use of this command to obtain arguments in a single frame is
28548deprecated in favor of the @samp{-stack-list-variables} command.
28549
922fbb7b
AC
28550@subsubheading @value{GDBN} Command
28551
a2c02241
NR
28552@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
28553@samp{gdb_get_args} command which partially overlaps with the
28554functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
28555
28556@subsubheading Example
922fbb7b 28557
a2c02241 28558@smallexample
594fe323 28559(gdb)
a2c02241
NR
28560-stack-list-frames
28561^done,
28562stack=[
28563frame=@{level="0",addr="0x00010734",func="callee4",
28564file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28565fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
28566frame=@{level="1",addr="0x0001076c",func="callee3",
28567file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28568fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
28569frame=@{level="2",addr="0x0001078c",func="callee2",
28570file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28571fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
28572frame=@{level="3",addr="0x000107b4",func="callee1",
28573file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28574fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
28575frame=@{level="4",addr="0x000107e0",func="main",
28576file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28577fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
594fe323 28578(gdb)
a2c02241
NR
28579-stack-list-arguments 0
28580^done,
28581stack-args=[
28582frame=@{level="0",args=[]@},
28583frame=@{level="1",args=[name="strarg"]@},
28584frame=@{level="2",args=[name="intarg",name="strarg"]@},
28585frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
28586frame=@{level="4",args=[]@}]
594fe323 28587(gdb)
a2c02241
NR
28588-stack-list-arguments 1
28589^done,
28590stack-args=[
28591frame=@{level="0",args=[]@},
28592frame=@{level="1",
28593 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
28594frame=@{level="2",args=[
28595@{name="intarg",value="2"@},
28596@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
28597@{frame=@{level="3",args=[
28598@{name="intarg",value="2"@},
28599@{name="strarg",value="0x11940 \"A string argument.\""@},
28600@{name="fltarg",value="3.5"@}]@},
28601frame=@{level="4",args=[]@}]
594fe323 28602(gdb)
a2c02241
NR
28603-stack-list-arguments 0 2 2
28604^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 28605(gdb)
a2c02241
NR
28606-stack-list-arguments 1 2 2
28607^done,stack-args=[frame=@{level="2",
28608args=[@{name="intarg",value="2"@},
28609@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 28610(gdb)
a2c02241
NR
28611@end smallexample
28612
28613@c @subheading -stack-list-exception-handlers
922fbb7b 28614
a2c02241 28615
1e611234 28616@anchor{-stack-list-frames}
a2c02241
NR
28617@subheading The @code{-stack-list-frames} Command
28618@findex -stack-list-frames
1abaf70c
BR
28619
28620@subsubheading Synopsis
28621
28622@smallexample
1e611234 28623 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
1abaf70c
BR
28624@end smallexample
28625
a2c02241
NR
28626List the frames currently on the stack. For each frame it displays the
28627following info:
28628
28629@table @samp
28630@item @var{level}
d3e8051b 28631The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
28632@item @var{addr}
28633The @code{$pc} value for that frame.
28634@item @var{func}
28635Function name.
28636@item @var{file}
28637File name of the source file where the function lives.
7d288aaa
TT
28638@item @var{fullname}
28639The full file name of the source file where the function lives.
a2c02241
NR
28640@item @var{line}
28641Line number corresponding to the @code{$pc}.
7d288aaa
TT
28642@item @var{from}
28643The shared library where this function is defined. This is only given
28644if the frame's function is not known.
a2c02241
NR
28645@end table
28646
28647If invoked without arguments, this command prints a backtrace for the
28648whole stack. If given two integer arguments, it shows the frames whose
28649levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
28650are equal, it shows the single frame at the corresponding level. It is
28651an error if @var{low-frame} is larger than the actual number of
a5451f4e 28652frames. On the other hand, @var{high-frame} may be larger than the
1e611234
PM
28653actual number of frames, in which case only existing frames will be
28654returned. If the option @code{--no-frame-filters} is supplied, then
28655Python frame filters will not be executed.
1abaf70c
BR
28656
28657@subsubheading @value{GDBN} Command
28658
a2c02241 28659The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
28660
28661@subsubheading Example
28662
a2c02241
NR
28663Full stack backtrace:
28664
1abaf70c 28665@smallexample
594fe323 28666(gdb)
a2c02241
NR
28667-stack-list-frames
28668^done,stack=
28669[frame=@{level="0",addr="0x0001076c",func="foo",
28670 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
28671frame=@{level="1",addr="0x000107a4",func="foo",
28672 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28673frame=@{level="2",addr="0x000107a4",func="foo",
28674 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28675frame=@{level="3",addr="0x000107a4",func="foo",
28676 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28677frame=@{level="4",addr="0x000107a4",func="foo",
28678 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28679frame=@{level="5",addr="0x000107a4",func="foo",
28680 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28681frame=@{level="6",addr="0x000107a4",func="foo",
28682 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28683frame=@{level="7",addr="0x000107a4",func="foo",
28684 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28685frame=@{level="8",addr="0x000107a4",func="foo",
28686 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28687frame=@{level="9",addr="0x000107a4",func="foo",
28688 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28689frame=@{level="10",addr="0x000107a4",func="foo",
28690 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28691frame=@{level="11",addr="0x00010738",func="main",
28692 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
594fe323 28693(gdb)
1abaf70c
BR
28694@end smallexample
28695
a2c02241 28696Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 28697
a2c02241 28698@smallexample
594fe323 28699(gdb)
a2c02241
NR
28700-stack-list-frames 3 5
28701^done,stack=
28702[frame=@{level="3",addr="0x000107a4",func="foo",
28703 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28704frame=@{level="4",addr="0x000107a4",func="foo",
28705 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28706frame=@{level="5",addr="0x000107a4",func="foo",
28707 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 28708(gdb)
a2c02241 28709@end smallexample
922fbb7b 28710
a2c02241 28711Show a single frame:
922fbb7b
AC
28712
28713@smallexample
594fe323 28714(gdb)
a2c02241
NR
28715-stack-list-frames 3 3
28716^done,stack=
28717[frame=@{level="3",addr="0x000107a4",func="foo",
28718 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 28719(gdb)
922fbb7b
AC
28720@end smallexample
28721
922fbb7b 28722
a2c02241
NR
28723@subheading The @code{-stack-list-locals} Command
28724@findex -stack-list-locals
1e611234 28725@anchor{-stack-list-locals}
57c22c6c 28726
a2c02241 28727@subsubheading Synopsis
922fbb7b
AC
28728
28729@smallexample
6211c335 28730 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
922fbb7b
AC
28731@end smallexample
28732
a2c02241
NR
28733Display the local variable names for the selected frame. If
28734@var{print-values} is 0 or @code{--no-values}, print only the names of
28735the variables; if it is 1 or @code{--all-values}, print also their
28736values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 28737type and value for simple data types, and the name and type for arrays,
a2c02241
NR
28738structures and unions. In this last case, a frontend can immediately
28739display the value of simple data types and create variable objects for
d3e8051b 28740other data types when the user wishes to explore their values in
1e611234
PM
28741more detail. If the option @code{--no-frame-filters} is supplied, then
28742Python frame filters will not be executed.
922fbb7b 28743
6211c335
YQ
28744If the @code{--skip-unavailable} option is specified, local variables
28745that are not available are not listed. Partially available local
28746variables are still displayed, however.
28747
b3372f91
VP
28748This command is deprecated in favor of the
28749@samp{-stack-list-variables} command.
28750
922fbb7b
AC
28751@subsubheading @value{GDBN} Command
28752
a2c02241 28753@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
28754
28755@subsubheading Example
922fbb7b
AC
28756
28757@smallexample
594fe323 28758(gdb)
a2c02241
NR
28759-stack-list-locals 0
28760^done,locals=[name="A",name="B",name="C"]
594fe323 28761(gdb)
a2c02241
NR
28762-stack-list-locals --all-values
28763^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
28764 @{name="C",value="@{1, 2, 3@}"@}]
28765-stack-list-locals --simple-values
28766^done,locals=[@{name="A",type="int",value="1"@},
28767 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 28768(gdb)
922fbb7b
AC
28769@end smallexample
28770
1e611234 28771@anchor{-stack-list-variables}
b3372f91
VP
28772@subheading The @code{-stack-list-variables} Command
28773@findex -stack-list-variables
28774
28775@subsubheading Synopsis
28776
28777@smallexample
6211c335 28778 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
b3372f91
VP
28779@end smallexample
28780
28781Display the names of local variables and function arguments for the selected frame. If
28782@var{print-values} is 0 or @code{--no-values}, print only the names of
28783the variables; if it is 1 or @code{--all-values}, print also their
28784values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 28785type and value for simple data types, and the name and type for arrays,
1e611234
PM
28786structures and unions. If the option @code{--no-frame-filters} is
28787supplied, then Python frame filters will not be executed.
b3372f91 28788
6211c335
YQ
28789If the @code{--skip-unavailable} option is specified, local variables
28790and arguments that are not available are not listed. Partially
28791available arguments and local variables are still displayed, however.
28792
b3372f91
VP
28793@subsubheading Example
28794
28795@smallexample
28796(gdb)
28797-stack-list-variables --thread 1 --frame 0 --all-values
4f412fd0 28798^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
b3372f91
VP
28799(gdb)
28800@end smallexample
28801
922fbb7b 28802
a2c02241
NR
28803@subheading The @code{-stack-select-frame} Command
28804@findex -stack-select-frame
922fbb7b
AC
28805
28806@subsubheading Synopsis
28807
28808@smallexample
a2c02241 28809 -stack-select-frame @var{framenum}
922fbb7b
AC
28810@end smallexample
28811
a2c02241
NR
28812Change the selected frame. Select a different frame @var{framenum} on
28813the stack.
922fbb7b 28814
c3b108f7
VP
28815This command in deprecated in favor of passing the @samp{--frame}
28816option to every command.
28817
922fbb7b
AC
28818@subsubheading @value{GDBN} Command
28819
a2c02241
NR
28820The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
28821@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
28822
28823@subsubheading Example
28824
28825@smallexample
594fe323 28826(gdb)
a2c02241 28827-stack-select-frame 2
922fbb7b 28828^done
594fe323 28829(gdb)
922fbb7b
AC
28830@end smallexample
28831
28832@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
28833@node GDB/MI Variable Objects
28834@section @sc{gdb/mi} Variable Objects
922fbb7b 28835
a1b5960f 28836@ignore
922fbb7b 28837
a2c02241 28838@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 28839
a2c02241
NR
28840For the implementation of a variable debugger window (locals, watched
28841expressions, etc.), we are proposing the adaptation of the existing code
28842used by @code{Insight}.
922fbb7b 28843
a2c02241 28844The two main reasons for that are:
922fbb7b 28845
a2c02241
NR
28846@enumerate 1
28847@item
28848It has been proven in practice (it is already on its second generation).
922fbb7b 28849
a2c02241
NR
28850@item
28851It will shorten development time (needless to say how important it is
28852now).
28853@end enumerate
922fbb7b 28854
a2c02241
NR
28855The original interface was designed to be used by Tcl code, so it was
28856slightly changed so it could be used through @sc{gdb/mi}. This section
28857describes the @sc{gdb/mi} operations that will be available and gives some
28858hints about their use.
922fbb7b 28859
a2c02241
NR
28860@emph{Note}: In addition to the set of operations described here, we
28861expect the @sc{gui} implementation of a variable window to require, at
28862least, the following operations:
922fbb7b 28863
a2c02241
NR
28864@itemize @bullet
28865@item @code{-gdb-show} @code{output-radix}
28866@item @code{-stack-list-arguments}
28867@item @code{-stack-list-locals}
28868@item @code{-stack-select-frame}
28869@end itemize
922fbb7b 28870
a1b5960f
VP
28871@end ignore
28872
c8b2f53c 28873@subheading Introduction to Variable Objects
922fbb7b 28874
a2c02241 28875@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
28876
28877Variable objects are "object-oriented" MI interface for examining and
28878changing values of expressions. Unlike some other MI interfaces that
28879work with expressions, variable objects are specifically designed for
28880simple and efficient presentation in the frontend. A variable object
28881is identified by string name. When a variable object is created, the
28882frontend specifies the expression for that variable object. The
28883expression can be a simple variable, or it can be an arbitrary complex
28884expression, and can even involve CPU registers. After creating a
28885variable object, the frontend can invoke other variable object
28886operations---for example to obtain or change the value of a variable
28887object, or to change display format.
28888
28889Variable objects have hierarchical tree structure. Any variable object
28890that corresponds to a composite type, such as structure in C, has
28891a number of child variable objects, for example corresponding to each
28892element of a structure. A child variable object can itself have
28893children, recursively. Recursion ends when we reach
25d5ea92
VP
28894leaf variable objects, which always have built-in types. Child variable
28895objects are created only by explicit request, so if a frontend
28896is not interested in the children of a particular variable object, no
28897child will be created.
c8b2f53c
VP
28898
28899For a leaf variable object it is possible to obtain its value as a
28900string, or set the value from a string. String value can be also
28901obtained for a non-leaf variable object, but it's generally a string
28902that only indicates the type of the object, and does not list its
28903contents. Assignment to a non-leaf variable object is not allowed.
28904
28905A frontend does not need to read the values of all variable objects each time
28906the program stops. Instead, MI provides an update command that lists all
28907variable objects whose values has changed since the last update
28908operation. This considerably reduces the amount of data that must
25d5ea92
VP
28909be transferred to the frontend. As noted above, children variable
28910objects are created on demand, and only leaf variable objects have a
28911real value. As result, gdb will read target memory only for leaf
28912variables that frontend has created.
28913
28914The automatic update is not always desirable. For example, a frontend
28915might want to keep a value of some expression for future reference,
28916and never update it. For another example, fetching memory is
28917relatively slow for embedded targets, so a frontend might want
28918to disable automatic update for the variables that are either not
28919visible on the screen, or ``closed''. This is possible using so
28920called ``frozen variable objects''. Such variable objects are never
28921implicitly updated.
922fbb7b 28922
c3b108f7
VP
28923Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
28924fixed variable object, the expression is parsed when the variable
28925object is created, including associating identifiers to specific
28926variables. The meaning of expression never changes. For a floating
28927variable object the values of variables whose names appear in the
28928expressions are re-evaluated every time in the context of the current
28929frame. Consider this example:
28930
28931@smallexample
28932void do_work(...)
28933@{
28934 struct work_state state;
28935
28936 if (...)
28937 do_work(...);
28938@}
28939@end smallexample
28940
28941If a fixed variable object for the @code{state} variable is created in
7a9dd1b2 28942this function, and we enter the recursive call, the variable
c3b108f7
VP
28943object will report the value of @code{state} in the top-level
28944@code{do_work} invocation. On the other hand, a floating variable
28945object will report the value of @code{state} in the current frame.
28946
28947If an expression specified when creating a fixed variable object
28948refers to a local variable, the variable object becomes bound to the
28949thread and frame in which the variable object is created. When such
28950variable object is updated, @value{GDBN} makes sure that the
28951thread/frame combination the variable object is bound to still exists,
28952and re-evaluates the variable object in context of that thread/frame.
28953
a2c02241
NR
28954The following is the complete set of @sc{gdb/mi} operations defined to
28955access this functionality:
922fbb7b 28956
a2c02241
NR
28957@multitable @columnfractions .4 .6
28958@item @strong{Operation}
28959@tab @strong{Description}
922fbb7b 28960
0cc7d26f
TT
28961@item @code{-enable-pretty-printing}
28962@tab enable Python-based pretty-printing
a2c02241
NR
28963@item @code{-var-create}
28964@tab create a variable object
28965@item @code{-var-delete}
22d8a470 28966@tab delete the variable object and/or its children
a2c02241
NR
28967@item @code{-var-set-format}
28968@tab set the display format of this variable
28969@item @code{-var-show-format}
28970@tab show the display format of this variable
28971@item @code{-var-info-num-children}
28972@tab tells how many children this object has
28973@item @code{-var-list-children}
28974@tab return a list of the object's children
28975@item @code{-var-info-type}
28976@tab show the type of this variable object
28977@item @code{-var-info-expression}
02142340
VP
28978@tab print parent-relative expression that this variable object represents
28979@item @code{-var-info-path-expression}
28980@tab print full expression that this variable object represents
a2c02241
NR
28981@item @code{-var-show-attributes}
28982@tab is this variable editable? does it exist here?
28983@item @code{-var-evaluate-expression}
28984@tab get the value of this variable
28985@item @code{-var-assign}
28986@tab set the value of this variable
28987@item @code{-var-update}
28988@tab update the variable and its children
25d5ea92
VP
28989@item @code{-var-set-frozen}
28990@tab set frozeness attribute
0cc7d26f
TT
28991@item @code{-var-set-update-range}
28992@tab set range of children to display on update
a2c02241 28993@end multitable
922fbb7b 28994
a2c02241
NR
28995In the next subsection we describe each operation in detail and suggest
28996how it can be used.
922fbb7b 28997
a2c02241 28998@subheading Description And Use of Operations on Variable Objects
922fbb7b 28999
0cc7d26f
TT
29000@subheading The @code{-enable-pretty-printing} Command
29001@findex -enable-pretty-printing
29002
29003@smallexample
29004-enable-pretty-printing
29005@end smallexample
29006
29007@value{GDBN} allows Python-based visualizers to affect the output of the
29008MI variable object commands. However, because there was no way to
29009implement this in a fully backward-compatible way, a front end must
29010request that this functionality be enabled.
29011
29012Once enabled, this feature cannot be disabled.
29013
29014Note that if Python support has not been compiled into @value{GDBN},
29015this command will still succeed (and do nothing).
29016
f43030c4
TT
29017This feature is currently (as of @value{GDBN} 7.0) experimental, and
29018may work differently in future versions of @value{GDBN}.
29019
a2c02241
NR
29020@subheading The @code{-var-create} Command
29021@findex -var-create
ef21caaf 29022
a2c02241 29023@subsubheading Synopsis
ef21caaf 29024
a2c02241
NR
29025@smallexample
29026 -var-create @{@var{name} | "-"@}
c3b108f7 29027 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
a2c02241
NR
29028@end smallexample
29029
29030This operation creates a variable object, which allows the monitoring of
29031a variable, the result of an expression, a memory cell or a CPU
29032register.
ef21caaf 29033
a2c02241
NR
29034The @var{name} parameter is the string by which the object can be
29035referenced. It must be unique. If @samp{-} is specified, the varobj
29036system will generate a string ``varNNNNNN'' automatically. It will be
c3b108f7 29037unique provided that one does not specify @var{name} of that format.
a2c02241 29038The command fails if a duplicate name is found.
ef21caaf 29039
a2c02241
NR
29040The frame under which the expression should be evaluated can be
29041specified by @var{frame-addr}. A @samp{*} indicates that the current
c3b108f7
VP
29042frame should be used. A @samp{@@} indicates that a floating variable
29043object must be created.
922fbb7b 29044
a2c02241
NR
29045@var{expression} is any expression valid on the current language set (must not
29046begin with a @samp{*}), or one of the following:
922fbb7b 29047
a2c02241
NR
29048@itemize @bullet
29049@item
29050@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 29051
a2c02241
NR
29052@item
29053@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 29054
a2c02241
NR
29055@item
29056@samp{$@var{regname}} --- a CPU register name
29057@end itemize
922fbb7b 29058
0cc7d26f
TT
29059@cindex dynamic varobj
29060A varobj's contents may be provided by a Python-based pretty-printer. In this
29061case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
29062have slightly different semantics in some cases. If the
29063@code{-enable-pretty-printing} command is not sent, then @value{GDBN}
29064will never create a dynamic varobj. This ensures backward
29065compatibility for existing clients.
29066
a2c02241 29067@subsubheading Result
922fbb7b 29068
0cc7d26f
TT
29069This operation returns attributes of the newly-created varobj. These
29070are:
29071
29072@table @samp
29073@item name
29074The name of the varobj.
29075
29076@item numchild
29077The number of children of the varobj. This number is not necessarily
29078reliable for a dynamic varobj. Instead, you must examine the
29079@samp{has_more} attribute.
29080
29081@item value
29082The varobj's scalar value. For a varobj whose type is some sort of
29083aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
29084will not be interesting.
29085
29086@item type
29087The varobj's type. This is a string representation of the type, as
8264ba82
AG
29088would be printed by the @value{GDBN} CLI. If @samp{print object}
29089(@pxref{Print Settings, set print object}) is set to @code{on}, the
29090@emph{actual} (derived) type of the object is shown rather than the
29091@emph{declared} one.
0cc7d26f
TT
29092
29093@item thread-id
29094If a variable object is bound to a specific thread, then this is the
5d5658a1 29095thread's global identifier.
0cc7d26f
TT
29096
29097@item has_more
29098For a dynamic varobj, this indicates whether there appear to be any
29099children available. For a non-dynamic varobj, this will be 0.
29100
29101@item dynamic
29102This attribute will be present and have the value @samp{1} if the
29103varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
29104then this attribute will not be present.
29105
29106@item displayhint
29107A dynamic varobj can supply a display hint to the front end. The
29108value comes directly from the Python pretty-printer object's
4c374409 29109@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
29110@end table
29111
29112Typical output will look like this:
922fbb7b
AC
29113
29114@smallexample
0cc7d26f
TT
29115 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
29116 has_more="@var{has_more}"
dcaaae04
NR
29117@end smallexample
29118
a2c02241
NR
29119
29120@subheading The @code{-var-delete} Command
29121@findex -var-delete
922fbb7b
AC
29122
29123@subsubheading Synopsis
29124
29125@smallexample
22d8a470 29126 -var-delete [ -c ] @var{name}
922fbb7b
AC
29127@end smallexample
29128
a2c02241 29129Deletes a previously created variable object and all of its children.
22d8a470 29130With the @samp{-c} option, just deletes the children.
922fbb7b 29131
a2c02241 29132Returns an error if the object @var{name} is not found.
922fbb7b 29133
922fbb7b 29134
a2c02241
NR
29135@subheading The @code{-var-set-format} Command
29136@findex -var-set-format
922fbb7b 29137
a2c02241 29138@subsubheading Synopsis
922fbb7b
AC
29139
29140@smallexample
a2c02241 29141 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
29142@end smallexample
29143
a2c02241
NR
29144Sets the output format for the value of the object @var{name} to be
29145@var{format-spec}.
29146
de051565 29147@anchor{-var-set-format}
a2c02241
NR
29148The syntax for the @var{format-spec} is as follows:
29149
29150@smallexample
29151 @var{format-spec} @expansion{}
1c35a88f 29152 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
a2c02241
NR
29153@end smallexample
29154
c8b2f53c
VP
29155The natural format is the default format choosen automatically
29156based on the variable type (like decimal for an @code{int}, hex
29157for pointers, etc.).
29158
1c35a88f
LM
29159The zero-hexadecimal format has a representation similar to hexadecimal
29160but with padding zeroes to the left of the value. For example, a 32-bit
29161hexadecimal value of 0x1234 would be represented as 0x00001234 in the
29162zero-hexadecimal format.
29163
c8b2f53c
VP
29164For a variable with children, the format is set only on the
29165variable itself, and the children are not affected.
a2c02241
NR
29166
29167@subheading The @code{-var-show-format} Command
29168@findex -var-show-format
922fbb7b
AC
29169
29170@subsubheading Synopsis
29171
29172@smallexample
a2c02241 29173 -var-show-format @var{name}
922fbb7b
AC
29174@end smallexample
29175
a2c02241 29176Returns the format used to display the value of the object @var{name}.
922fbb7b 29177
a2c02241
NR
29178@smallexample
29179 @var{format} @expansion{}
29180 @var{format-spec}
29181@end smallexample
922fbb7b 29182
922fbb7b 29183
a2c02241
NR
29184@subheading The @code{-var-info-num-children} Command
29185@findex -var-info-num-children
29186
29187@subsubheading Synopsis
29188
29189@smallexample
29190 -var-info-num-children @var{name}
29191@end smallexample
29192
29193Returns the number of children of a variable object @var{name}:
29194
29195@smallexample
29196 numchild=@var{n}
29197@end smallexample
29198
0cc7d26f
TT
29199Note that this number is not completely reliable for a dynamic varobj.
29200It will return the current number of children, but more children may
29201be available.
29202
a2c02241
NR
29203
29204@subheading The @code{-var-list-children} Command
29205@findex -var-list-children
29206
29207@subsubheading Synopsis
29208
29209@smallexample
0cc7d26f 29210 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
a2c02241 29211@end smallexample
b569d230 29212@anchor{-var-list-children}
a2c02241
NR
29213
29214Return a list of the children of the specified variable object and
29215create variable objects for them, if they do not already exist. With
f5011d11 29216a single argument or if @var{print-values} has a value of 0 or
a2c02241
NR
29217@code{--no-values}, print only the names of the variables; if
29218@var{print-values} is 1 or @code{--all-values}, also print their
29219values; and if it is 2 or @code{--simple-values} print the name and
29220value for simple data types and just the name for arrays, structures
29221and unions.
922fbb7b 29222
0cc7d26f
TT
29223@var{from} and @var{to}, if specified, indicate the range of children
29224to report. If @var{from} or @var{to} is less than zero, the range is
29225reset and all children will be reported. Otherwise, children starting
29226at @var{from} (zero-based) and up to and excluding @var{to} will be
29227reported.
29228
29229If a child range is requested, it will only affect the current call to
29230@code{-var-list-children}, but not future calls to @code{-var-update}.
29231For this, you must instead use @code{-var-set-update-range}. The
29232intent of this approach is to enable a front end to implement any
29233update approach it likes; for example, scrolling a view may cause the
29234front end to request more children with @code{-var-list-children}, and
29235then the front end could call @code{-var-set-update-range} with a
29236different range to ensure that future updates are restricted to just
29237the visible items.
29238
b569d230
EZ
29239For each child the following results are returned:
29240
29241@table @var
29242
29243@item name
29244Name of the variable object created for this child.
29245
29246@item exp
29247The expression to be shown to the user by the front end to designate this child.
29248For example this may be the name of a structure member.
29249
0cc7d26f
TT
29250For a dynamic varobj, this value cannot be used to form an
29251expression. There is no way to do this at all with a dynamic varobj.
29252
b569d230
EZ
29253For C/C@t{++} structures there are several pseudo children returned to
29254designate access qualifiers. For these pseudo children @var{exp} is
29255@samp{public}, @samp{private}, or @samp{protected}. In this case the
29256type and value are not present.
29257
0cc7d26f
TT
29258A dynamic varobj will not report the access qualifying
29259pseudo-children, regardless of the language. This information is not
29260available at all with a dynamic varobj.
29261
b569d230 29262@item numchild
0cc7d26f
TT
29263Number of children this child has. For a dynamic varobj, this will be
292640.
b569d230
EZ
29265
29266@item type
8264ba82
AG
29267The type of the child. If @samp{print object}
29268(@pxref{Print Settings, set print object}) is set to @code{on}, the
29269@emph{actual} (derived) type of the object is shown rather than the
29270@emph{declared} one.
b569d230
EZ
29271
29272@item value
29273If values were requested, this is the value.
29274
29275@item thread-id
5d5658a1
PA
29276If this variable object is associated with a thread, this is the
29277thread's global thread id. Otherwise this result is not present.
b569d230
EZ
29278
29279@item frozen
29280If the variable object is frozen, this variable will be present with a value of 1.
c78feb39 29281
9df9dbe0
YQ
29282@item displayhint
29283A dynamic varobj can supply a display hint to the front end. The
29284value comes directly from the Python pretty-printer object's
29285@code{display_hint} method. @xref{Pretty Printing API}.
29286
c78feb39
YQ
29287@item dynamic
29288This attribute will be present and have the value @samp{1} if the
29289varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
29290then this attribute will not be present.
29291
b569d230
EZ
29292@end table
29293
0cc7d26f
TT
29294The result may have its own attributes:
29295
29296@table @samp
29297@item displayhint
29298A dynamic varobj can supply a display hint to the front end. The
29299value comes directly from the Python pretty-printer object's
4c374409 29300@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
29301
29302@item has_more
29303This is an integer attribute which is nonzero if there are children
29304remaining after the end of the selected range.
29305@end table
29306
922fbb7b
AC
29307@subsubheading Example
29308
29309@smallexample
594fe323 29310(gdb)
a2c02241 29311 -var-list-children n
b569d230 29312 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 29313 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 29314(gdb)
a2c02241 29315 -var-list-children --all-values n
b569d230 29316 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 29317 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
29318@end smallexample
29319
922fbb7b 29320
a2c02241
NR
29321@subheading The @code{-var-info-type} Command
29322@findex -var-info-type
922fbb7b 29323
a2c02241
NR
29324@subsubheading Synopsis
29325
29326@smallexample
29327 -var-info-type @var{name}
29328@end smallexample
29329
29330Returns the type of the specified variable @var{name}. The type is
29331returned as a string in the same format as it is output by the
29332@value{GDBN} CLI:
29333
29334@smallexample
29335 type=@var{typename}
29336@end smallexample
29337
29338
29339@subheading The @code{-var-info-expression} Command
29340@findex -var-info-expression
922fbb7b
AC
29341
29342@subsubheading Synopsis
29343
29344@smallexample
a2c02241 29345 -var-info-expression @var{name}
922fbb7b
AC
29346@end smallexample
29347
02142340
VP
29348Returns a string that is suitable for presenting this
29349variable object in user interface. The string is generally
29350not valid expression in the current language, and cannot be evaluated.
29351
29352For example, if @code{a} is an array, and variable object
29353@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 29354
a2c02241 29355@smallexample
02142340
VP
29356(gdb) -var-info-expression A.1
29357^done,lang="C",exp="1"
a2c02241 29358@end smallexample
922fbb7b 29359
a2c02241 29360@noindent
fa4d0c40
YQ
29361Here, the value of @code{lang} is the language name, which can be
29362found in @ref{Supported Languages}.
02142340
VP
29363
29364Note that the output of the @code{-var-list-children} command also
29365includes those expressions, so the @code{-var-info-expression} command
29366is of limited use.
29367
29368@subheading The @code{-var-info-path-expression} Command
29369@findex -var-info-path-expression
29370
29371@subsubheading Synopsis
29372
29373@smallexample
29374 -var-info-path-expression @var{name}
29375@end smallexample
29376
29377Returns an expression that can be evaluated in the current
29378context and will yield the same value that a variable object has.
29379Compare this with the @code{-var-info-expression} command, which
29380result can be used only for UI presentation. Typical use of
29381the @code{-var-info-path-expression} command is creating a
29382watchpoint from a variable object.
29383
0cc7d26f
TT
29384This command is currently not valid for children of a dynamic varobj,
29385and will give an error when invoked on one.
29386
02142340
VP
29387For example, suppose @code{C} is a C@t{++} class, derived from class
29388@code{Base}, and that the @code{Base} class has a member called
29389@code{m_size}. Assume a variable @code{c} is has the type of
29390@code{C} and a variable object @code{C} was created for variable
29391@code{c}. Then, we'll get this output:
29392@smallexample
29393(gdb) -var-info-path-expression C.Base.public.m_size
29394^done,path_expr=((Base)c).m_size)
29395@end smallexample
922fbb7b 29396
a2c02241
NR
29397@subheading The @code{-var-show-attributes} Command
29398@findex -var-show-attributes
922fbb7b 29399
a2c02241 29400@subsubheading Synopsis
922fbb7b 29401
a2c02241
NR
29402@smallexample
29403 -var-show-attributes @var{name}
29404@end smallexample
922fbb7b 29405
a2c02241 29406List attributes of the specified variable object @var{name}:
922fbb7b
AC
29407
29408@smallexample
a2c02241 29409 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
29410@end smallexample
29411
a2c02241
NR
29412@noindent
29413where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
29414
29415@subheading The @code{-var-evaluate-expression} Command
29416@findex -var-evaluate-expression
29417
29418@subsubheading Synopsis
29419
29420@smallexample
de051565 29421 -var-evaluate-expression [-f @var{format-spec}] @var{name}
a2c02241
NR
29422@end smallexample
29423
29424Evaluates the expression that is represented by the specified variable
de051565
MK
29425object and returns its value as a string. The format of the string
29426can be specified with the @samp{-f} option. The possible values of
29427this option are the same as for @code{-var-set-format}
29428(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
29429the current display format will be used. The current display format
29430can be changed using the @code{-var-set-format} command.
a2c02241
NR
29431
29432@smallexample
29433 value=@var{value}
29434@end smallexample
29435
29436Note that one must invoke @code{-var-list-children} for a variable
29437before the value of a child variable can be evaluated.
29438
29439@subheading The @code{-var-assign} Command
29440@findex -var-assign
29441
29442@subsubheading Synopsis
29443
29444@smallexample
29445 -var-assign @var{name} @var{expression}
29446@end smallexample
29447
29448Assigns the value of @var{expression} to the variable object specified
29449by @var{name}. The object must be @samp{editable}. If the variable's
29450value is altered by the assign, the variable will show up in any
29451subsequent @code{-var-update} list.
29452
29453@subsubheading Example
922fbb7b
AC
29454
29455@smallexample
594fe323 29456(gdb)
a2c02241
NR
29457-var-assign var1 3
29458^done,value="3"
594fe323 29459(gdb)
a2c02241
NR
29460-var-update *
29461^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 29462(gdb)
922fbb7b
AC
29463@end smallexample
29464
a2c02241
NR
29465@subheading The @code{-var-update} Command
29466@findex -var-update
29467
29468@subsubheading Synopsis
29469
29470@smallexample
29471 -var-update [@var{print-values}] @{@var{name} | "*"@}
29472@end smallexample
29473
c8b2f53c
VP
29474Reevaluate the expressions corresponding to the variable object
29475@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
29476list of variable objects whose values have changed; @var{name} must
29477be a root variable object. Here, ``changed'' means that the result of
29478@code{-var-evaluate-expression} before and after the
29479@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
29480object names, all existing variable objects are updated, except
29481for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3 29482@var{print-values} determines whether both names and values, or just
de051565 29483names are printed. The possible values of this option are the same
36ece8b3
NR
29484as for @code{-var-list-children} (@pxref{-var-list-children}). It is
29485recommended to use the @samp{--all-values} option, to reduce the
29486number of MI commands needed on each program stop.
c8b2f53c 29487
c3b108f7
VP
29488With the @samp{*} parameter, if a variable object is bound to a
29489currently running thread, it will not be updated, without any
29490diagnostic.
a2c02241 29491
0cc7d26f
TT
29492If @code{-var-set-update-range} was previously used on a varobj, then
29493only the selected range of children will be reported.
922fbb7b 29494
0cc7d26f
TT
29495@code{-var-update} reports all the changed varobjs in a tuple named
29496@samp{changelist}.
29497
29498Each item in the change list is itself a tuple holding:
29499
29500@table @samp
29501@item name
29502The name of the varobj.
29503
29504@item value
29505If values were requested for this update, then this field will be
29506present and will hold the value of the varobj.
922fbb7b 29507
0cc7d26f 29508@item in_scope
9f708cb2 29509@anchor{-var-update}
0cc7d26f 29510This field is a string which may take one of three values:
36ece8b3
NR
29511
29512@table @code
29513@item "true"
29514The variable object's current value is valid.
29515
29516@item "false"
29517The variable object does not currently hold a valid value but it may
29518hold one in the future if its associated expression comes back into
29519scope.
29520
29521@item "invalid"
29522The variable object no longer holds a valid value.
29523This can occur when the executable file being debugged has changed,
29524either through recompilation or by using the @value{GDBN} @code{file}
29525command. The front end should normally choose to delete these variable
29526objects.
29527@end table
29528
29529In the future new values may be added to this list so the front should
29530be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
29531
0cc7d26f
TT
29532@item type_changed
29533This is only present if the varobj is still valid. If the type
29534changed, then this will be the string @samp{true}; otherwise it will
29535be @samp{false}.
29536
7191c139
JB
29537When a varobj's type changes, its children are also likely to have
29538become incorrect. Therefore, the varobj's children are automatically
29539deleted when this attribute is @samp{true}. Also, the varobj's update
29540range, when set using the @code{-var-set-update-range} command, is
29541unset.
29542
0cc7d26f
TT
29543@item new_type
29544If the varobj's type changed, then this field will be present and will
29545hold the new type.
29546
29547@item new_num_children
29548For a dynamic varobj, if the number of children changed, or if the
29549type changed, this will be the new number of children.
29550
29551The @samp{numchild} field in other varobj responses is generally not
29552valid for a dynamic varobj -- it will show the number of children that
29553@value{GDBN} knows about, but because dynamic varobjs lazily
29554instantiate their children, this will not reflect the number of
29555children which may be available.
29556
29557The @samp{new_num_children} attribute only reports changes to the
29558number of children known by @value{GDBN}. This is the only way to
29559detect whether an update has removed children (which necessarily can
29560only happen at the end of the update range).
29561
29562@item displayhint
29563The display hint, if any.
29564
29565@item has_more
29566This is an integer value, which will be 1 if there are more children
29567available outside the varobj's update range.
29568
29569@item dynamic
29570This attribute will be present and have the value @samp{1} if the
29571varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
29572then this attribute will not be present.
29573
29574@item new_children
29575If new children were added to a dynamic varobj within the selected
29576update range (as set by @code{-var-set-update-range}), then they will
29577be listed in this attribute.
29578@end table
29579
29580@subsubheading Example
29581
29582@smallexample
29583(gdb)
29584-var-assign var1 3
29585^done,value="3"
29586(gdb)
29587-var-update --all-values var1
29588^done,changelist=[@{name="var1",value="3",in_scope="true",
29589type_changed="false"@}]
29590(gdb)
29591@end smallexample
29592
25d5ea92
VP
29593@subheading The @code{-var-set-frozen} Command
29594@findex -var-set-frozen
9f708cb2 29595@anchor{-var-set-frozen}
25d5ea92
VP
29596
29597@subsubheading Synopsis
29598
29599@smallexample
9f708cb2 29600 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
29601@end smallexample
29602
9f708cb2 29603Set the frozenness flag on the variable object @var{name}. The
25d5ea92 29604@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 29605frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 29606frozen, then neither itself, nor any of its children, are
9f708cb2 29607implicitly updated by @code{-var-update} of
25d5ea92
VP
29608a parent variable or by @code{-var-update *}. Only
29609@code{-var-update} of the variable itself will update its value and
29610values of its children. After a variable object is unfrozen, it is
29611implicitly updated by all subsequent @code{-var-update} operations.
29612Unfreezing a variable does not update it, only subsequent
29613@code{-var-update} does.
29614
29615@subsubheading Example
29616
29617@smallexample
29618(gdb)
29619-var-set-frozen V 1
29620^done
29621(gdb)
29622@end smallexample
29623
0cc7d26f
TT
29624@subheading The @code{-var-set-update-range} command
29625@findex -var-set-update-range
29626@anchor{-var-set-update-range}
29627
29628@subsubheading Synopsis
29629
29630@smallexample
29631 -var-set-update-range @var{name} @var{from} @var{to}
29632@end smallexample
29633
29634Set the range of children to be returned by future invocations of
29635@code{-var-update}.
29636
29637@var{from} and @var{to} indicate the range of children to report. If
29638@var{from} or @var{to} is less than zero, the range is reset and all
29639children will be reported. Otherwise, children starting at @var{from}
29640(zero-based) and up to and excluding @var{to} will be reported.
29641
29642@subsubheading Example
29643
29644@smallexample
29645(gdb)
29646-var-set-update-range V 1 2
29647^done
29648@end smallexample
29649
b6313243
TT
29650@subheading The @code{-var-set-visualizer} command
29651@findex -var-set-visualizer
29652@anchor{-var-set-visualizer}
29653
29654@subsubheading Synopsis
29655
29656@smallexample
29657 -var-set-visualizer @var{name} @var{visualizer}
29658@end smallexample
29659
29660Set a visualizer for the variable object @var{name}.
29661
29662@var{visualizer} is the visualizer to use. The special value
29663@samp{None} means to disable any visualizer in use.
29664
29665If not @samp{None}, @var{visualizer} must be a Python expression.
29666This expression must evaluate to a callable object which accepts a
29667single argument. @value{GDBN} will call this object with the value of
29668the varobj @var{name} as an argument (this is done so that the same
29669Python pretty-printing code can be used for both the CLI and MI).
29670When called, this object must return an object which conforms to the
4c374409 29671pretty-printing interface (@pxref{Pretty Printing API}).
b6313243
TT
29672
29673The pre-defined function @code{gdb.default_visualizer} may be used to
29674select a visualizer by following the built-in process
29675(@pxref{Selecting Pretty-Printers}). This is done automatically when
29676a varobj is created, and so ordinarily is not needed.
29677
29678This feature is only available if Python support is enabled. The MI
d192b373 29679command @code{-list-features} (@pxref{GDB/MI Support Commands})
b6313243
TT
29680can be used to check this.
29681
29682@subsubheading Example
29683
29684Resetting the visualizer:
29685
29686@smallexample
29687(gdb)
29688-var-set-visualizer V None
29689^done
29690@end smallexample
29691
29692Reselecting the default (type-based) visualizer:
29693
29694@smallexample
29695(gdb)
29696-var-set-visualizer V gdb.default_visualizer
29697^done
29698@end smallexample
29699
29700Suppose @code{SomeClass} is a visualizer class. A lambda expression
29701can be used to instantiate this class for a varobj:
29702
29703@smallexample
29704(gdb)
29705-var-set-visualizer V "lambda val: SomeClass()"
29706^done
29707@end smallexample
25d5ea92 29708
a2c02241
NR
29709@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29710@node GDB/MI Data Manipulation
29711@section @sc{gdb/mi} Data Manipulation
922fbb7b 29712
a2c02241
NR
29713@cindex data manipulation, in @sc{gdb/mi}
29714@cindex @sc{gdb/mi}, data manipulation
29715This section describes the @sc{gdb/mi} commands that manipulate data:
29716examine memory and registers, evaluate expressions, etc.
29717
a86c90e6
SM
29718For details about what an addressable memory unit is,
29719@pxref{addressable memory unit}.
29720
a2c02241
NR
29721@c REMOVED FROM THE INTERFACE.
29722@c @subheading -data-assign
29723@c Change the value of a program variable. Plenty of side effects.
79a6e687 29724@c @subsubheading GDB Command
a2c02241
NR
29725@c set variable
29726@c @subsubheading Example
29727@c N.A.
29728
29729@subheading The @code{-data-disassemble} Command
29730@findex -data-disassemble
922fbb7b
AC
29731
29732@subsubheading Synopsis
29733
29734@smallexample
a2c02241
NR
29735 -data-disassemble
29736 [ -s @var{start-addr} -e @var{end-addr} ]
29737 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
29738 -- @var{mode}
922fbb7b
AC
29739@end smallexample
29740
a2c02241
NR
29741@noindent
29742Where:
29743
29744@table @samp
29745@item @var{start-addr}
29746is the beginning address (or @code{$pc})
29747@item @var{end-addr}
29748is the end address
29749@item @var{filename}
29750is the name of the file to disassemble
29751@item @var{linenum}
29752is the line number to disassemble around
29753@item @var{lines}
d3e8051b 29754is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
29755the whole function will be disassembled, in case no @var{end-addr} is
29756specified. If @var{end-addr} is specified as a non-zero value, and
29757@var{lines} is lower than the number of disassembly lines between
29758@var{start-addr} and @var{end-addr}, only @var{lines} lines are
29759displayed; if @var{lines} is higher than the number of lines between
29760@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
29761are displayed.
29762@item @var{mode}
6ff0ba5f
DE
29763is one of:
29764@itemize @bullet
29765@item 0 disassembly only
29766@item 1 mixed source and disassembly (deprecated)
29767@item 2 disassembly with raw opcodes
29768@item 3 mixed source and disassembly with raw opcodes (deprecated)
29769@item 4 mixed source and disassembly
29770@item 5 mixed source and disassembly with raw opcodes
29771@end itemize
29772
29773Modes 1 and 3 are deprecated. The output is ``source centric''
29774which hasn't proved useful in practice.
29775@xref{Machine Code}, for a discussion of the difference between
29776@code{/m} and @code{/s} output of the @code{disassemble} command.
a2c02241
NR
29777@end table
29778
29779@subsubheading Result
29780
ed8a1c2d
AB
29781The result of the @code{-data-disassemble} command will be a list named
29782@samp{asm_insns}, the contents of this list depend on the @var{mode}
29783used with the @code{-data-disassemble} command.
a2c02241 29784
ed8a1c2d
AB
29785For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
29786following fields:
29787
29788@table @code
29789@item address
29790The address at which this instruction was disassembled.
29791
29792@item func-name
29793The name of the function this instruction is within.
29794
29795@item offset
29796The decimal offset in bytes from the start of @samp{func-name}.
29797
29798@item inst
29799The text disassembly for this @samp{address}.
29800
29801@item opcodes
6ff0ba5f 29802This field is only present for modes 2, 3 and 5. This contains the raw opcode
ed8a1c2d
AB
29803bytes for the @samp{inst} field.
29804
29805@end table
29806
6ff0ba5f 29807For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
ed8a1c2d 29808@samp{src_and_asm_line}, each of which has the following fields:
a2c02241 29809
ed8a1c2d
AB
29810@table @code
29811@item line
29812The line number within @samp{file}.
29813
29814@item file
29815The file name from the compilation unit. This might be an absolute
29816file name or a relative file name depending on the compile command
29817used.
29818
29819@item fullname
f35a17b5
JK
29820Absolute file name of @samp{file}. It is converted to a canonical form
29821using the source file search path
29822(@pxref{Source Path, ,Specifying Source Directories})
29823and after resolving all the symbolic links.
29824
29825If the source file is not found this field will contain the path as
29826present in the debug information.
ed8a1c2d
AB
29827
29828@item line_asm_insn
29829This is a list of tuples containing the disassembly for @samp{line} in
29830@samp{file}. The fields of each tuple are the same as for
29831@code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
29832@samp{func-name}, @samp{offset}, @samp{inst}, and optionally
29833@samp{opcodes}.
29834
29835@end table
29836
29837Note that whatever included in the @samp{inst} field, is not
29838manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
29839adjust its format.
922fbb7b
AC
29840
29841@subsubheading @value{GDBN} Command
29842
ed8a1c2d 29843The corresponding @value{GDBN} command is @samp{disassemble}.
922fbb7b
AC
29844
29845@subsubheading Example
29846
a2c02241
NR
29847Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
29848
922fbb7b 29849@smallexample
594fe323 29850(gdb)
a2c02241
NR
29851-data-disassemble -s $pc -e "$pc + 20" -- 0
29852^done,
29853asm_insns=[
29854@{address="0x000107c0",func-name="main",offset="4",
29855inst="mov 2, %o0"@},
29856@{address="0x000107c4",func-name="main",offset="8",
29857inst="sethi %hi(0x11800), %o2"@},
29858@{address="0x000107c8",func-name="main",offset="12",
29859inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
29860@{address="0x000107cc",func-name="main",offset="16",
29861inst="sethi %hi(0x11800), %o2"@},
29862@{address="0x000107d0",func-name="main",offset="20",
29863inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 29864(gdb)
a2c02241
NR
29865@end smallexample
29866
29867Disassemble the whole @code{main} function. Line 32 is part of
29868@code{main}.
29869
29870@smallexample
29871-data-disassemble -f basics.c -l 32 -- 0
29872^done,asm_insns=[
29873@{address="0x000107bc",func-name="main",offset="0",
29874inst="save %sp, -112, %sp"@},
29875@{address="0x000107c0",func-name="main",offset="4",
29876inst="mov 2, %o0"@},
29877@{address="0x000107c4",func-name="main",offset="8",
29878inst="sethi %hi(0x11800), %o2"@},
29879[@dots{}]
29880@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
29881@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 29882(gdb)
922fbb7b
AC
29883@end smallexample
29884
a2c02241 29885Disassemble 3 instructions from the start of @code{main}:
922fbb7b 29886
a2c02241 29887@smallexample
594fe323 29888(gdb)
a2c02241
NR
29889-data-disassemble -f basics.c -l 32 -n 3 -- 0
29890^done,asm_insns=[
29891@{address="0x000107bc",func-name="main",offset="0",
29892inst="save %sp, -112, %sp"@},
29893@{address="0x000107c0",func-name="main",offset="4",
29894inst="mov 2, %o0"@},
29895@{address="0x000107c4",func-name="main",offset="8",
29896inst="sethi %hi(0x11800), %o2"@}]
594fe323 29897(gdb)
a2c02241
NR
29898@end smallexample
29899
29900Disassemble 3 instructions from the start of @code{main} in mixed mode:
29901
29902@smallexample
594fe323 29903(gdb)
a2c02241
NR
29904-data-disassemble -f basics.c -l 32 -n 3 -- 1
29905^done,asm_insns=[
29906src_and_asm_line=@{line="31",
ed8a1c2d
AB
29907file="../../../src/gdb/testsuite/gdb.mi/basics.c",
29908fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
29909line_asm_insn=[@{address="0x000107bc",
29910func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
a2c02241 29911src_and_asm_line=@{line="32",
ed8a1c2d
AB
29912file="../../../src/gdb/testsuite/gdb.mi/basics.c",
29913fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
29914line_asm_insn=[@{address="0x000107c0",
29915func-name="main",offset="4",inst="mov 2, %o0"@},
a2c02241
NR
29916@{address="0x000107c4",func-name="main",offset="8",
29917inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 29918(gdb)
a2c02241
NR
29919@end smallexample
29920
29921
29922@subheading The @code{-data-evaluate-expression} Command
29923@findex -data-evaluate-expression
922fbb7b
AC
29924
29925@subsubheading Synopsis
29926
29927@smallexample
a2c02241 29928 -data-evaluate-expression @var{expr}
922fbb7b
AC
29929@end smallexample
29930
a2c02241
NR
29931Evaluate @var{expr} as an expression. The expression could contain an
29932inferior function call. The function call will execute synchronously.
29933If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
29934
29935@subsubheading @value{GDBN} Command
29936
a2c02241
NR
29937The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
29938@samp{call}. In @code{gdbtk} only, there's a corresponding
29939@samp{gdb_eval} command.
922fbb7b
AC
29940
29941@subsubheading Example
29942
a2c02241
NR
29943In the following example, the numbers that precede the commands are the
29944@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
29945Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
29946output.
29947
922fbb7b 29948@smallexample
a2c02241
NR
29949211-data-evaluate-expression A
29950211^done,value="1"
594fe323 29951(gdb)
a2c02241
NR
29952311-data-evaluate-expression &A
29953311^done,value="0xefffeb7c"
594fe323 29954(gdb)
a2c02241
NR
29955411-data-evaluate-expression A+3
29956411^done,value="4"
594fe323 29957(gdb)
a2c02241
NR
29958511-data-evaluate-expression "A + 3"
29959511^done,value="4"
594fe323 29960(gdb)
a2c02241 29961@end smallexample
922fbb7b
AC
29962
29963
a2c02241
NR
29964@subheading The @code{-data-list-changed-registers} Command
29965@findex -data-list-changed-registers
922fbb7b
AC
29966
29967@subsubheading Synopsis
29968
29969@smallexample
a2c02241 29970 -data-list-changed-registers
922fbb7b
AC
29971@end smallexample
29972
a2c02241 29973Display a list of the registers that have changed.
922fbb7b
AC
29974
29975@subsubheading @value{GDBN} Command
29976
a2c02241
NR
29977@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
29978has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
29979
29980@subsubheading Example
922fbb7b 29981
a2c02241 29982On a PPC MBX board:
922fbb7b
AC
29983
29984@smallexample
594fe323 29985(gdb)
a2c02241
NR
29986-exec-continue
29987^running
922fbb7b 29988
594fe323 29989(gdb)
a47ec5fe
AR
29990*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
29991func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
29992line="5"@}
594fe323 29993(gdb)
a2c02241
NR
29994-data-list-changed-registers
29995^done,changed-registers=["0","1","2","4","5","6","7","8","9",
29996"10","11","13","14","15","16","17","18","19","20","21","22","23",
29997"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 29998(gdb)
a2c02241 29999@end smallexample
922fbb7b
AC
30000
30001
a2c02241
NR
30002@subheading The @code{-data-list-register-names} Command
30003@findex -data-list-register-names
922fbb7b
AC
30004
30005@subsubheading Synopsis
30006
30007@smallexample
a2c02241 30008 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
30009@end smallexample
30010
a2c02241
NR
30011Show a list of register names for the current target. If no arguments
30012are given, it shows a list of the names of all the registers. If
30013integer numbers are given as arguments, it will print a list of the
30014names of the registers corresponding to the arguments. To ensure
30015consistency between a register name and its number, the output list may
30016include empty register names.
922fbb7b
AC
30017
30018@subsubheading @value{GDBN} Command
30019
a2c02241
NR
30020@value{GDBN} does not have a command which corresponds to
30021@samp{-data-list-register-names}. In @code{gdbtk} there is a
30022corresponding command @samp{gdb_regnames}.
922fbb7b
AC
30023
30024@subsubheading Example
922fbb7b 30025
a2c02241
NR
30026For the PPC MBX board:
30027@smallexample
594fe323 30028(gdb)
a2c02241
NR
30029-data-list-register-names
30030^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
30031"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
30032"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
30033"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
30034"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
30035"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
30036"", "pc","ps","cr","lr","ctr","xer"]
594fe323 30037(gdb)
a2c02241
NR
30038-data-list-register-names 1 2 3
30039^done,register-names=["r1","r2","r3"]
594fe323 30040(gdb)
a2c02241 30041@end smallexample
922fbb7b 30042
a2c02241
NR
30043@subheading The @code{-data-list-register-values} Command
30044@findex -data-list-register-values
922fbb7b
AC
30045
30046@subsubheading Synopsis
30047
30048@smallexample
c898adb7
YQ
30049 -data-list-register-values
30050 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
30051@end smallexample
30052
697aa1b7
EZ
30053Display the registers' contents. The format according to which the
30054registers' contents are to be returned is given by @var{fmt}, followed
30055by an optional list of numbers specifying the registers to display. A
30056missing list of numbers indicates that the contents of all the
30057registers must be returned. The @code{--skip-unavailable} option
30058indicates that only the available registers are to be returned.
a2c02241
NR
30059
30060Allowed formats for @var{fmt} are:
30061
30062@table @code
30063@item x
30064Hexadecimal
30065@item o
30066Octal
30067@item t
30068Binary
30069@item d
30070Decimal
30071@item r
30072Raw
30073@item N
30074Natural
30075@end table
922fbb7b
AC
30076
30077@subsubheading @value{GDBN} Command
30078
a2c02241
NR
30079The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
30080all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
30081
30082@subsubheading Example
922fbb7b 30083
a2c02241
NR
30084For a PPC MBX board (note: line breaks are for readability only, they
30085don't appear in the actual output):
30086
30087@smallexample
594fe323 30088(gdb)
a2c02241
NR
30089-data-list-register-values r 64 65
30090^done,register-values=[@{number="64",value="0xfe00a300"@},
30091@{number="65",value="0x00029002"@}]
594fe323 30092(gdb)
a2c02241
NR
30093-data-list-register-values x
30094^done,register-values=[@{number="0",value="0xfe0043c8"@},
30095@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
30096@{number="3",value="0x0"@},@{number="4",value="0xa"@},
30097@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
30098@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
30099@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
30100@{number="11",value="0x1"@},@{number="12",value="0x0"@},
30101@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
30102@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
30103@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
30104@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
30105@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
30106@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
30107@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
30108@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
30109@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
30110@{number="31",value="0x0"@},@{number="32",value="0x0"@},
30111@{number="33",value="0x0"@},@{number="34",value="0x0"@},
30112@{number="35",value="0x0"@},@{number="36",value="0x0"@},
30113@{number="37",value="0x0"@},@{number="38",value="0x0"@},
30114@{number="39",value="0x0"@},@{number="40",value="0x0"@},
30115@{number="41",value="0x0"@},@{number="42",value="0x0"@},
30116@{number="43",value="0x0"@},@{number="44",value="0x0"@},
30117@{number="45",value="0x0"@},@{number="46",value="0x0"@},
30118@{number="47",value="0x0"@},@{number="48",value="0x0"@},
30119@{number="49",value="0x0"@},@{number="50",value="0x0"@},
30120@{number="51",value="0x0"@},@{number="52",value="0x0"@},
30121@{number="53",value="0x0"@},@{number="54",value="0x0"@},
30122@{number="55",value="0x0"@},@{number="56",value="0x0"@},
30123@{number="57",value="0x0"@},@{number="58",value="0x0"@},
30124@{number="59",value="0x0"@},@{number="60",value="0x0"@},
30125@{number="61",value="0x0"@},@{number="62",value="0x0"@},
30126@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
30127@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
30128@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
30129@{number="69",value="0x20002b03"@}]
594fe323 30130(gdb)
a2c02241 30131@end smallexample
922fbb7b 30132
a2c02241
NR
30133
30134@subheading The @code{-data-read-memory} Command
30135@findex -data-read-memory
922fbb7b 30136
8dedea02
VP
30137This command is deprecated, use @code{-data-read-memory-bytes} instead.
30138
922fbb7b
AC
30139@subsubheading Synopsis
30140
30141@smallexample
a2c02241
NR
30142 -data-read-memory [ -o @var{byte-offset} ]
30143 @var{address} @var{word-format} @var{word-size}
30144 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
30145@end smallexample
30146
a2c02241
NR
30147@noindent
30148where:
922fbb7b 30149
a2c02241
NR
30150@table @samp
30151@item @var{address}
30152An expression specifying the address of the first memory word to be
30153read. Complex expressions containing embedded white space should be
30154quoted using the C convention.
922fbb7b 30155
a2c02241
NR
30156@item @var{word-format}
30157The format to be used to print the memory words. The notation is the
30158same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 30159,Output Formats}).
922fbb7b 30160
a2c02241
NR
30161@item @var{word-size}
30162The size of each memory word in bytes.
922fbb7b 30163
a2c02241
NR
30164@item @var{nr-rows}
30165The number of rows in the output table.
922fbb7b 30166
a2c02241
NR
30167@item @var{nr-cols}
30168The number of columns in the output table.
922fbb7b 30169
a2c02241
NR
30170@item @var{aschar}
30171If present, indicates that each row should include an @sc{ascii} dump. The
30172value of @var{aschar} is used as a padding character when a byte is not a
30173member of the printable @sc{ascii} character set (printable @sc{ascii}
30174characters are those whose code is between 32 and 126, inclusively).
922fbb7b 30175
a2c02241
NR
30176@item @var{byte-offset}
30177An offset to add to the @var{address} before fetching memory.
30178@end table
922fbb7b 30179
a2c02241
NR
30180This command displays memory contents as a table of @var{nr-rows} by
30181@var{nr-cols} words, each word being @var{word-size} bytes. In total,
30182@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
30183(returned as @samp{total-bytes}). Should less than the requested number
30184of bytes be returned by the target, the missing words are identified
30185using @samp{N/A}. The number of bytes read from the target is returned
30186in @samp{nr-bytes} and the starting address used to read memory in
30187@samp{addr}.
30188
30189The address of the next/previous row or page is available in
30190@samp{next-row} and @samp{prev-row}, @samp{next-page} and
30191@samp{prev-page}.
922fbb7b
AC
30192
30193@subsubheading @value{GDBN} Command
30194
a2c02241
NR
30195The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
30196@samp{gdb_get_mem} memory read command.
922fbb7b
AC
30197
30198@subsubheading Example
32e7087d 30199
a2c02241
NR
30200Read six bytes of memory starting at @code{bytes+6} but then offset by
30201@code{-6} bytes. Format as three rows of two columns. One byte per
30202word. Display each word in hex.
32e7087d
JB
30203
30204@smallexample
594fe323 30205(gdb)
a2c02241
NR
302069-data-read-memory -o -6 -- bytes+6 x 1 3 2
302079^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
30208next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
30209prev-page="0x0000138a",memory=[
30210@{addr="0x00001390",data=["0x00","0x01"]@},
30211@{addr="0x00001392",data=["0x02","0x03"]@},
30212@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 30213(gdb)
32e7087d
JB
30214@end smallexample
30215
a2c02241
NR
30216Read two bytes of memory starting at address @code{shorts + 64} and
30217display as a single word formatted in decimal.
32e7087d 30218
32e7087d 30219@smallexample
594fe323 30220(gdb)
a2c02241
NR
302215-data-read-memory shorts+64 d 2 1 1
302225^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
30223next-row="0x00001512",prev-row="0x0000150e",
30224next-page="0x00001512",prev-page="0x0000150e",memory=[
30225@{addr="0x00001510",data=["128"]@}]
594fe323 30226(gdb)
32e7087d
JB
30227@end smallexample
30228
a2c02241
NR
30229Read thirty two bytes of memory starting at @code{bytes+16} and format
30230as eight rows of four columns. Include a string encoding with @samp{x}
30231used as the non-printable character.
922fbb7b
AC
30232
30233@smallexample
594fe323 30234(gdb)
a2c02241
NR
302354-data-read-memory bytes+16 x 1 8 4 x
302364^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
30237next-row="0x000013c0",prev-row="0x0000139c",
30238next-page="0x000013c0",prev-page="0x00001380",memory=[
30239@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
30240@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
30241@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
30242@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
30243@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
30244@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
30245@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
30246@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 30247(gdb)
922fbb7b
AC
30248@end smallexample
30249
8dedea02
VP
30250@subheading The @code{-data-read-memory-bytes} Command
30251@findex -data-read-memory-bytes
30252
30253@subsubheading Synopsis
30254
30255@smallexample
a86c90e6 30256 -data-read-memory-bytes [ -o @var{offset} ]
8dedea02
VP
30257 @var{address} @var{count}
30258@end smallexample
30259
30260@noindent
30261where:
30262
30263@table @samp
30264@item @var{address}
a86c90e6
SM
30265An expression specifying the address of the first addressable memory unit
30266to be read. Complex expressions containing embedded white space should be
8dedea02
VP
30267quoted using the C convention.
30268
30269@item @var{count}
a86c90e6
SM
30270The number of addressable memory units to read. This should be an integer
30271literal.
8dedea02 30272
a86c90e6
SM
30273@item @var{offset}
30274The offset relative to @var{address} at which to start reading. This
30275should be an integer literal. This option is provided so that a frontend
30276is not required to first evaluate address and then perform address
30277arithmetics itself.
8dedea02
VP
30278
30279@end table
30280
30281This command attempts to read all accessible memory regions in the
30282specified range. First, all regions marked as unreadable in the memory
30283map (if one is defined) will be skipped. @xref{Memory Region
30284Attributes}. Second, @value{GDBN} will attempt to read the remaining
30285regions. For each one, if reading full region results in an errors,
30286@value{GDBN} will try to read a subset of the region.
30287
a86c90e6
SM
30288In general, every single memory unit in the region may be readable or not,
30289and the only way to read every readable unit is to try a read at
8dedea02 30290every address, which is not practical. Therefore, @value{GDBN} will
a86c90e6 30291attempt to read all accessible memory units at either beginning or the end
8dedea02
VP
30292of the region, using a binary division scheme. This heuristic works
30293well for reading accross a memory map boundary. Note that if a region
30294has a readable range that is neither at the beginning or the end,
30295@value{GDBN} will not read it.
30296
30297The result record (@pxref{GDB/MI Result Records}) that is output of
30298the command includes a field named @samp{memory} whose content is a
30299list of tuples. Each tuple represent a successfully read memory block
30300and has the following fields:
30301
30302@table @code
30303@item begin
30304The start address of the memory block, as hexadecimal literal.
30305
30306@item end
30307The end address of the memory block, as hexadecimal literal.
30308
30309@item offset
30310The offset of the memory block, as hexadecimal literal, relative to
30311the start address passed to @code{-data-read-memory-bytes}.
30312
30313@item contents
30314The contents of the memory block, in hex.
30315
30316@end table
30317
30318
30319
30320@subsubheading @value{GDBN} Command
30321
30322The corresponding @value{GDBN} command is @samp{x}.
30323
30324@subsubheading Example
30325
30326@smallexample
30327(gdb)
30328-data-read-memory-bytes &a 10
30329^done,memory=[@{begin="0xbffff154",offset="0x00000000",
30330 end="0xbffff15e",
30331 contents="01000000020000000300"@}]
30332(gdb)
30333@end smallexample
30334
30335
30336@subheading The @code{-data-write-memory-bytes} Command
30337@findex -data-write-memory-bytes
30338
30339@subsubheading Synopsis
30340
30341@smallexample
30342 -data-write-memory-bytes @var{address} @var{contents}
62747a60 30343 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
8dedea02
VP
30344@end smallexample
30345
30346@noindent
30347where:
30348
30349@table @samp
30350@item @var{address}
a86c90e6
SM
30351An expression specifying the address of the first addressable memory unit
30352to be written. Complex expressions containing embedded white space should
30353be quoted using the C convention.
8dedea02
VP
30354
30355@item @var{contents}
a86c90e6
SM
30356The hex-encoded data to write. It is an error if @var{contents} does
30357not represent an integral number of addressable memory units.
8dedea02 30358
62747a60 30359@item @var{count}
a86c90e6
SM
30360Optional argument indicating the number of addressable memory units to be
30361written. If @var{count} is greater than @var{contents}' length,
30362@value{GDBN} will repeatedly write @var{contents} until it fills
30363@var{count} memory units.
62747a60 30364
8dedea02
VP
30365@end table
30366
30367@subsubheading @value{GDBN} Command
30368
30369There's no corresponding @value{GDBN} command.
30370
30371@subsubheading Example
30372
30373@smallexample
30374(gdb)
30375-data-write-memory-bytes &a "aabbccdd"
30376^done
30377(gdb)
30378@end smallexample
30379
62747a60
TT
30380@smallexample
30381(gdb)
30382-data-write-memory-bytes &a "aabbccdd" 16e
30383^done
30384(gdb)
30385@end smallexample
8dedea02 30386
a2c02241
NR
30387@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30388@node GDB/MI Tracepoint Commands
30389@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 30390
18148017
VP
30391The commands defined in this section implement MI support for
30392tracepoints. For detailed introduction, see @ref{Tracepoints}.
30393
30394@subheading The @code{-trace-find} Command
30395@findex -trace-find
30396
30397@subsubheading Synopsis
30398
30399@smallexample
30400 -trace-find @var{mode} [@var{parameters}@dots{}]
30401@end smallexample
30402
30403Find a trace frame using criteria defined by @var{mode} and
30404@var{parameters}. The following table lists permissible
30405modes and their parameters. For details of operation, see @ref{tfind}.
30406
30407@table @samp
30408
30409@item none
30410No parameters are required. Stops examining trace frames.
30411
30412@item frame-number
30413An integer is required as parameter. Selects tracepoint frame with
30414that index.
30415
30416@item tracepoint-number
30417An integer is required as parameter. Finds next
30418trace frame that corresponds to tracepoint with the specified number.
30419
30420@item pc
30421An address is required as parameter. Finds
30422next trace frame that corresponds to any tracepoint at the specified
30423address.
30424
30425@item pc-inside-range
30426Two addresses are required as parameters. Finds next trace
30427frame that corresponds to a tracepoint at an address inside the
30428specified range. Both bounds are considered to be inside the range.
30429
30430@item pc-outside-range
30431Two addresses are required as parameters. Finds
30432next trace frame that corresponds to a tracepoint at an address outside
30433the specified range. Both bounds are considered to be inside the range.
30434
30435@item line
30436Line specification is required as parameter. @xref{Specify Location}.
30437Finds next trace frame that corresponds to a tracepoint at
30438the specified location.
30439
30440@end table
30441
30442If @samp{none} was passed as @var{mode}, the response does not
30443have fields. Otherwise, the response may have the following fields:
30444
30445@table @samp
30446@item found
30447This field has either @samp{0} or @samp{1} as the value, depending
30448on whether a matching tracepoint was found.
30449
30450@item traceframe
30451The index of the found traceframe. This field is present iff
30452the @samp{found} field has value of @samp{1}.
30453
30454@item tracepoint
30455The index of the found tracepoint. This field is present iff
30456the @samp{found} field has value of @samp{1}.
30457
30458@item frame
30459The information about the frame corresponding to the found trace
30460frame. This field is present only if a trace frame was found.
cd64ee31 30461@xref{GDB/MI Frame Information}, for description of this field.
18148017
VP
30462
30463@end table
30464
7d13fe92
SS
30465@subsubheading @value{GDBN} Command
30466
30467The corresponding @value{GDBN} command is @samp{tfind}.
30468
18148017
VP
30469@subheading -trace-define-variable
30470@findex -trace-define-variable
30471
30472@subsubheading Synopsis
30473
30474@smallexample
30475 -trace-define-variable @var{name} [ @var{value} ]
30476@end smallexample
30477
30478Create trace variable @var{name} if it does not exist. If
30479@var{value} is specified, sets the initial value of the specified
30480trace variable to that value. Note that the @var{name} should start
30481with the @samp{$} character.
30482
7d13fe92
SS
30483@subsubheading @value{GDBN} Command
30484
30485The corresponding @value{GDBN} command is @samp{tvariable}.
30486
dc673c81
YQ
30487@subheading The @code{-trace-frame-collected} Command
30488@findex -trace-frame-collected
30489
30490@subsubheading Synopsis
30491
30492@smallexample
30493 -trace-frame-collected
30494 [--var-print-values @var{var_pval}]
30495 [--comp-print-values @var{comp_pval}]
30496 [--registers-format @var{regformat}]
30497 [--memory-contents]
30498@end smallexample
30499
30500This command returns the set of collected objects, register names,
30501trace state variable names, memory ranges and computed expressions
30502that have been collected at a particular trace frame. The optional
30503parameters to the command affect the output format in different ways.
30504See the output description table below for more details.
30505
30506The reported names can be used in the normal manner to create
30507varobjs and inspect the objects themselves. The items returned by
30508this command are categorized so that it is clear which is a variable,
30509which is a register, which is a trace state variable, which is a
30510memory range and which is a computed expression.
30511
30512For instance, if the actions were
30513@smallexample
30514collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
30515collect *(int*)0xaf02bef0@@40
30516@end smallexample
30517
30518@noindent
30519the object collected in its entirety would be @code{myVar}. The
30520object @code{myArray} would be partially collected, because only the
30521element at index @code{myIndex} would be collected. The remaining
30522objects would be computed expressions.
30523
30524An example output would be:
30525
30526@smallexample
30527(gdb)
30528-trace-frame-collected
30529^done,
30530 explicit-variables=[@{name="myVar",value="1"@}],
30531 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
30532 @{name="myObj.field",value="0"@},
30533 @{name="myPtr->field",value="1"@},
30534 @{name="myCount + 2",value="3"@},
30535 @{name="$tvar1 + 1",value="43970027"@}],
30536 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
30537 @{number="1",value="0x0"@},
30538 @{number="2",value="0x4"@},
30539 ...
30540 @{number="125",value="0x0"@}],
30541 tvars=[@{name="$tvar1",current="43970026"@}],
30542 memory=[@{address="0x0000000000602264",length="4"@},
30543 @{address="0x0000000000615bc0",length="4"@}]
30544(gdb)
30545@end smallexample
30546
30547Where:
30548
30549@table @code
30550@item explicit-variables
30551The set of objects that have been collected in their entirety (as
30552opposed to collecting just a few elements of an array or a few struct
30553members). For each object, its name and value are printed.
30554The @code{--var-print-values} option affects how or whether the value
30555field is output. If @var{var_pval} is 0, then print only the names;
30556if it is 1, print also their values; and if it is 2, print the name,
30557type and value for simple data types, and the name and type for
30558arrays, structures and unions.
30559
30560@item computed-expressions
30561The set of computed expressions that have been collected at the
30562current trace frame. The @code{--comp-print-values} option affects
30563this set like the @code{--var-print-values} option affects the
30564@code{explicit-variables} set. See above.
30565
30566@item registers
30567The registers that have been collected at the current trace frame.
30568For each register collected, the name and current value are returned.
30569The value is formatted according to the @code{--registers-format}
30570option. See the @command{-data-list-register-values} command for a
30571list of the allowed formats. The default is @samp{x}.
30572
30573@item tvars
30574The trace state variables that have been collected at the current
30575trace frame. For each trace state variable collected, the name and
30576current value are returned.
30577
30578@item memory
30579The set of memory ranges that have been collected at the current trace
30580frame. Its content is a list of tuples. Each tuple represents a
30581collected memory range and has the following fields:
30582
30583@table @code
30584@item address
30585The start address of the memory range, as hexadecimal literal.
30586
30587@item length
30588The length of the memory range, as decimal literal.
30589
30590@item contents
30591The contents of the memory block, in hex. This field is only present
30592if the @code{--memory-contents} option is specified.
30593
30594@end table
30595
30596@end table
30597
30598@subsubheading @value{GDBN} Command
30599
30600There is no corresponding @value{GDBN} command.
30601
30602@subsubheading Example
30603
18148017
VP
30604@subheading -trace-list-variables
30605@findex -trace-list-variables
922fbb7b 30606
18148017 30607@subsubheading Synopsis
922fbb7b 30608
18148017
VP
30609@smallexample
30610 -trace-list-variables
30611@end smallexample
922fbb7b 30612
18148017
VP
30613Return a table of all defined trace variables. Each element of the
30614table has the following fields:
922fbb7b 30615
18148017
VP
30616@table @samp
30617@item name
30618The name of the trace variable. This field is always present.
922fbb7b 30619
18148017
VP
30620@item initial
30621The initial value. This is a 64-bit signed integer. This
30622field is always present.
922fbb7b 30623
18148017
VP
30624@item current
30625The value the trace variable has at the moment. This is a 64-bit
30626signed integer. This field is absent iff current value is
30627not defined, for example if the trace was never run, or is
30628presently running.
922fbb7b 30629
18148017 30630@end table
922fbb7b 30631
7d13fe92
SS
30632@subsubheading @value{GDBN} Command
30633
30634The corresponding @value{GDBN} command is @samp{tvariables}.
30635
18148017 30636@subsubheading Example
922fbb7b 30637
18148017
VP
30638@smallexample
30639(gdb)
30640-trace-list-variables
30641^done,trace-variables=@{nr_rows="1",nr_cols="3",
30642hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
30643 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
30644 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
30645body=[variable=@{name="$trace_timestamp",initial="0"@}
30646 variable=@{name="$foo",initial="10",current="15"@}]@}
30647(gdb)
30648@end smallexample
922fbb7b 30649
18148017
VP
30650@subheading -trace-save
30651@findex -trace-save
922fbb7b 30652
18148017
VP
30653@subsubheading Synopsis
30654
30655@smallexample
30656 -trace-save [-r ] @var{filename}
30657@end smallexample
30658
30659Saves the collected trace data to @var{filename}. Without the
30660@samp{-r} option, the data is downloaded from the target and saved
30661in a local file. With the @samp{-r} option the target is asked
30662to perform the save.
30663
7d13fe92
SS
30664@subsubheading @value{GDBN} Command
30665
30666The corresponding @value{GDBN} command is @samp{tsave}.
30667
18148017
VP
30668
30669@subheading -trace-start
30670@findex -trace-start
30671
30672@subsubheading Synopsis
30673
30674@smallexample
30675 -trace-start
30676@end smallexample
922fbb7b 30677
18148017
VP
30678Starts a tracing experiments. The result of this command does not
30679have any fields.
922fbb7b 30680
7d13fe92
SS
30681@subsubheading @value{GDBN} Command
30682
30683The corresponding @value{GDBN} command is @samp{tstart}.
30684
18148017
VP
30685@subheading -trace-status
30686@findex -trace-status
922fbb7b 30687
18148017
VP
30688@subsubheading Synopsis
30689
30690@smallexample
30691 -trace-status
30692@end smallexample
30693
a97153c7 30694Obtains the status of a tracing experiment. The result may include
18148017
VP
30695the following fields:
30696
30697@table @samp
30698
30699@item supported
30700May have a value of either @samp{0}, when no tracing operations are
30701supported, @samp{1}, when all tracing operations are supported, or
30702@samp{file} when examining trace file. In the latter case, examining
30703of trace frame is possible but new tracing experiement cannot be
30704started. This field is always present.
30705
30706@item running
30707May have a value of either @samp{0} or @samp{1} depending on whether
30708tracing experiement is in progress on target. This field is present
30709if @samp{supported} field is not @samp{0}.
30710
30711@item stop-reason
30712Report the reason why the tracing was stopped last time. This field
30713may be absent iff tracing was never stopped on target yet. The
30714value of @samp{request} means the tracing was stopped as result of
30715the @code{-trace-stop} command. The value of @samp{overflow} means
30716the tracing buffer is full. The value of @samp{disconnection} means
30717tracing was automatically stopped when @value{GDBN} has disconnected.
30718The value of @samp{passcount} means tracing was stopped when a
30719tracepoint was passed a maximal number of times for that tracepoint.
30720This field is present if @samp{supported} field is not @samp{0}.
30721
30722@item stopping-tracepoint
30723The number of tracepoint whose passcount as exceeded. This field is
30724present iff the @samp{stop-reason} field has the value of
30725@samp{passcount}.
30726
30727@item frames
87290684
SS
30728@itemx frames-created
30729The @samp{frames} field is a count of the total number of trace frames
30730in the trace buffer, while @samp{frames-created} is the total created
30731during the run, including ones that were discarded, such as when a
30732circular trace buffer filled up. Both fields are optional.
18148017
VP
30733
30734@item buffer-size
30735@itemx buffer-free
30736These fields tell the current size of the tracing buffer and the
87290684 30737remaining space. These fields are optional.
18148017 30738
a97153c7
PA
30739@item circular
30740The value of the circular trace buffer flag. @code{1} means that the
30741trace buffer is circular and old trace frames will be discarded if
30742necessary to make room, @code{0} means that the trace buffer is linear
30743and may fill up.
30744
30745@item disconnected
30746The value of the disconnected tracing flag. @code{1} means that
30747tracing will continue after @value{GDBN} disconnects, @code{0} means
30748that the trace run will stop.
30749
f5911ea1
HAQ
30750@item trace-file
30751The filename of the trace file being examined. This field is
30752optional, and only present when examining a trace file.
30753
18148017
VP
30754@end table
30755
7d13fe92
SS
30756@subsubheading @value{GDBN} Command
30757
30758The corresponding @value{GDBN} command is @samp{tstatus}.
30759
18148017
VP
30760@subheading -trace-stop
30761@findex -trace-stop
30762
30763@subsubheading Synopsis
30764
30765@smallexample
30766 -trace-stop
30767@end smallexample
922fbb7b 30768
18148017
VP
30769Stops a tracing experiment. The result of this command has the same
30770fields as @code{-trace-status}, except that the @samp{supported} and
30771@samp{running} fields are not output.
922fbb7b 30772
7d13fe92
SS
30773@subsubheading @value{GDBN} Command
30774
30775The corresponding @value{GDBN} command is @samp{tstop}.
30776
922fbb7b 30777
a2c02241
NR
30778@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30779@node GDB/MI Symbol Query
30780@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
30781
30782
9901a55b 30783@ignore
a2c02241
NR
30784@subheading The @code{-symbol-info-address} Command
30785@findex -symbol-info-address
922fbb7b
AC
30786
30787@subsubheading Synopsis
30788
30789@smallexample
a2c02241 30790 -symbol-info-address @var{symbol}
922fbb7b
AC
30791@end smallexample
30792
a2c02241 30793Describe where @var{symbol} is stored.
922fbb7b
AC
30794
30795@subsubheading @value{GDBN} Command
30796
a2c02241 30797The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
30798
30799@subsubheading Example
30800N.A.
30801
30802
a2c02241
NR
30803@subheading The @code{-symbol-info-file} Command
30804@findex -symbol-info-file
922fbb7b
AC
30805
30806@subsubheading Synopsis
30807
30808@smallexample
a2c02241 30809 -symbol-info-file
922fbb7b
AC
30810@end smallexample
30811
a2c02241 30812Show the file for the symbol.
922fbb7b 30813
a2c02241 30814@subsubheading @value{GDBN} Command
922fbb7b 30815
a2c02241
NR
30816There's no equivalent @value{GDBN} command. @code{gdbtk} has
30817@samp{gdb_find_file}.
922fbb7b
AC
30818
30819@subsubheading Example
30820N.A.
30821
30822
a2c02241
NR
30823@subheading The @code{-symbol-info-function} Command
30824@findex -symbol-info-function
922fbb7b
AC
30825
30826@subsubheading Synopsis
30827
30828@smallexample
a2c02241 30829 -symbol-info-function
922fbb7b
AC
30830@end smallexample
30831
a2c02241 30832Show which function the symbol lives in.
922fbb7b
AC
30833
30834@subsubheading @value{GDBN} Command
30835
a2c02241 30836@samp{gdb_get_function} in @code{gdbtk}.
922fbb7b
AC
30837
30838@subsubheading Example
30839N.A.
30840
30841
a2c02241
NR
30842@subheading The @code{-symbol-info-line} Command
30843@findex -symbol-info-line
922fbb7b
AC
30844
30845@subsubheading Synopsis
30846
30847@smallexample
a2c02241 30848 -symbol-info-line
922fbb7b
AC
30849@end smallexample
30850
a2c02241 30851Show the core addresses of the code for a source line.
922fbb7b 30852
a2c02241 30853@subsubheading @value{GDBN} Command
922fbb7b 30854
a2c02241
NR
30855The corresponding @value{GDBN} command is @samp{info line}.
30856@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
30857
30858@subsubheading Example
a2c02241 30859N.A.
922fbb7b
AC
30860
30861
a2c02241
NR
30862@subheading The @code{-symbol-info-symbol} Command
30863@findex -symbol-info-symbol
07f31aa6
DJ
30864
30865@subsubheading Synopsis
30866
a2c02241
NR
30867@smallexample
30868 -symbol-info-symbol @var{addr}
30869@end smallexample
07f31aa6 30870
a2c02241 30871Describe what symbol is at location @var{addr}.
07f31aa6 30872
a2c02241 30873@subsubheading @value{GDBN} Command
07f31aa6 30874
a2c02241 30875The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
30876
30877@subsubheading Example
a2c02241 30878N.A.
07f31aa6
DJ
30879
30880
a2c02241
NR
30881@subheading The @code{-symbol-list-functions} Command
30882@findex -symbol-list-functions
922fbb7b
AC
30883
30884@subsubheading Synopsis
30885
30886@smallexample
a2c02241 30887 -symbol-list-functions
922fbb7b
AC
30888@end smallexample
30889
a2c02241 30890List the functions in the executable.
922fbb7b
AC
30891
30892@subsubheading @value{GDBN} Command
30893
a2c02241
NR
30894@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
30895@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
30896
30897@subsubheading Example
a2c02241 30898N.A.
9901a55b 30899@end ignore
922fbb7b
AC
30900
30901
a2c02241
NR
30902@subheading The @code{-symbol-list-lines} Command
30903@findex -symbol-list-lines
922fbb7b
AC
30904
30905@subsubheading Synopsis
30906
30907@smallexample
a2c02241 30908 -symbol-list-lines @var{filename}
922fbb7b
AC
30909@end smallexample
30910
a2c02241
NR
30911Print the list of lines that contain code and their associated program
30912addresses for the given source filename. The entries are sorted in
30913ascending PC order.
922fbb7b
AC
30914
30915@subsubheading @value{GDBN} Command
30916
a2c02241 30917There is no corresponding @value{GDBN} command.
922fbb7b
AC
30918
30919@subsubheading Example
a2c02241 30920@smallexample
594fe323 30921(gdb)
a2c02241
NR
30922-symbol-list-lines basics.c
30923^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 30924(gdb)
a2c02241 30925@end smallexample
922fbb7b
AC
30926
30927
9901a55b 30928@ignore
a2c02241
NR
30929@subheading The @code{-symbol-list-types} Command
30930@findex -symbol-list-types
922fbb7b
AC
30931
30932@subsubheading Synopsis
30933
30934@smallexample
a2c02241 30935 -symbol-list-types
922fbb7b
AC
30936@end smallexample
30937
a2c02241 30938List all the type names.
922fbb7b
AC
30939
30940@subsubheading @value{GDBN} Command
30941
a2c02241
NR
30942The corresponding commands are @samp{info types} in @value{GDBN},
30943@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
30944
30945@subsubheading Example
30946N.A.
30947
30948
a2c02241
NR
30949@subheading The @code{-symbol-list-variables} Command
30950@findex -symbol-list-variables
922fbb7b
AC
30951
30952@subsubheading Synopsis
30953
30954@smallexample
a2c02241 30955 -symbol-list-variables
922fbb7b
AC
30956@end smallexample
30957
a2c02241 30958List all the global and static variable names.
922fbb7b
AC
30959
30960@subsubheading @value{GDBN} Command
30961
a2c02241 30962@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
30963
30964@subsubheading Example
30965N.A.
30966
30967
a2c02241
NR
30968@subheading The @code{-symbol-locate} Command
30969@findex -symbol-locate
922fbb7b
AC
30970
30971@subsubheading Synopsis
30972
30973@smallexample
a2c02241 30974 -symbol-locate
922fbb7b
AC
30975@end smallexample
30976
922fbb7b
AC
30977@subsubheading @value{GDBN} Command
30978
a2c02241 30979@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
30980
30981@subsubheading Example
30982N.A.
30983
30984
a2c02241
NR
30985@subheading The @code{-symbol-type} Command
30986@findex -symbol-type
922fbb7b
AC
30987
30988@subsubheading Synopsis
30989
30990@smallexample
a2c02241 30991 -symbol-type @var{variable}
922fbb7b
AC
30992@end smallexample
30993
a2c02241 30994Show type of @var{variable}.
922fbb7b 30995
a2c02241 30996@subsubheading @value{GDBN} Command
922fbb7b 30997
a2c02241
NR
30998The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
30999@samp{gdb_obj_variable}.
31000
31001@subsubheading Example
31002N.A.
9901a55b 31003@end ignore
a2c02241
NR
31004
31005
31006@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31007@node GDB/MI File Commands
31008@section @sc{gdb/mi} File Commands
31009
31010This section describes the GDB/MI commands to specify executable file names
31011and to read in and obtain symbol table information.
31012
31013@subheading The @code{-file-exec-and-symbols} Command
31014@findex -file-exec-and-symbols
31015
31016@subsubheading Synopsis
922fbb7b
AC
31017
31018@smallexample
a2c02241 31019 -file-exec-and-symbols @var{file}
922fbb7b
AC
31020@end smallexample
31021
a2c02241
NR
31022Specify the executable file to be debugged. This file is the one from
31023which the symbol table is also read. If no file is specified, the
31024command clears the executable and symbol information. If breakpoints
31025are set when using this command with no arguments, @value{GDBN} will produce
31026error messages. Otherwise, no output is produced, except a completion
31027notification.
31028
922fbb7b
AC
31029@subsubheading @value{GDBN} Command
31030
a2c02241 31031The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
31032
31033@subsubheading Example
31034
31035@smallexample
594fe323 31036(gdb)
a2c02241
NR
31037-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
31038^done
594fe323 31039(gdb)
922fbb7b
AC
31040@end smallexample
31041
922fbb7b 31042
a2c02241
NR
31043@subheading The @code{-file-exec-file} Command
31044@findex -file-exec-file
922fbb7b
AC
31045
31046@subsubheading Synopsis
31047
31048@smallexample
a2c02241 31049 -file-exec-file @var{file}
922fbb7b
AC
31050@end smallexample
31051
a2c02241
NR
31052Specify the executable file to be debugged. Unlike
31053@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
31054from this file. If used without argument, @value{GDBN} clears the information
31055about the executable file. No output is produced, except a completion
31056notification.
922fbb7b 31057
a2c02241
NR
31058@subsubheading @value{GDBN} Command
31059
31060The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
31061
31062@subsubheading Example
a2c02241
NR
31063
31064@smallexample
594fe323 31065(gdb)
a2c02241
NR
31066-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
31067^done
594fe323 31068(gdb)
a2c02241 31069@end smallexample
922fbb7b
AC
31070
31071
9901a55b 31072@ignore
a2c02241
NR
31073@subheading The @code{-file-list-exec-sections} Command
31074@findex -file-list-exec-sections
922fbb7b
AC
31075
31076@subsubheading Synopsis
31077
31078@smallexample
a2c02241 31079 -file-list-exec-sections
922fbb7b
AC
31080@end smallexample
31081
a2c02241
NR
31082List the sections of the current executable file.
31083
922fbb7b
AC
31084@subsubheading @value{GDBN} Command
31085
a2c02241
NR
31086The @value{GDBN} command @samp{info file} shows, among the rest, the same
31087information as this command. @code{gdbtk} has a corresponding command
31088@samp{gdb_load_info}.
922fbb7b
AC
31089
31090@subsubheading Example
31091N.A.
9901a55b 31092@end ignore
922fbb7b
AC
31093
31094
a2c02241
NR
31095@subheading The @code{-file-list-exec-source-file} Command
31096@findex -file-list-exec-source-file
922fbb7b
AC
31097
31098@subsubheading Synopsis
31099
31100@smallexample
a2c02241 31101 -file-list-exec-source-file
922fbb7b
AC
31102@end smallexample
31103
a2c02241 31104List the line number, the current source file, and the absolute path
44288b44
NR
31105to the current source file for the current executable. The macro
31106information field has a value of @samp{1} or @samp{0} depending on
31107whether or not the file includes preprocessor macro information.
922fbb7b
AC
31108
31109@subsubheading @value{GDBN} Command
31110
a2c02241 31111The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
31112
31113@subsubheading Example
31114
922fbb7b 31115@smallexample
594fe323 31116(gdb)
a2c02241 31117123-file-list-exec-source-file
44288b44 31118123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
594fe323 31119(gdb)
922fbb7b
AC
31120@end smallexample
31121
31122
a2c02241
NR
31123@subheading The @code{-file-list-exec-source-files} Command
31124@findex -file-list-exec-source-files
922fbb7b
AC
31125
31126@subsubheading Synopsis
31127
31128@smallexample
a2c02241 31129 -file-list-exec-source-files
922fbb7b
AC
31130@end smallexample
31131
a2c02241
NR
31132List the source files for the current executable.
31133
f35a17b5
JK
31134It will always output both the filename and fullname (absolute file
31135name) of a source file.
922fbb7b
AC
31136
31137@subsubheading @value{GDBN} Command
31138
a2c02241
NR
31139The @value{GDBN} equivalent is @samp{info sources}.
31140@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
31141
31142@subsubheading Example
922fbb7b 31143@smallexample
594fe323 31144(gdb)
a2c02241
NR
31145-file-list-exec-source-files
31146^done,files=[
31147@{file=foo.c,fullname=/home/foo.c@},
31148@{file=/home/bar.c,fullname=/home/bar.c@},
31149@{file=gdb_could_not_find_fullpath.c@}]
594fe323 31150(gdb)
922fbb7b
AC
31151@end smallexample
31152
9901a55b 31153@ignore
a2c02241
NR
31154@subheading The @code{-file-list-shared-libraries} Command
31155@findex -file-list-shared-libraries
922fbb7b 31156
a2c02241 31157@subsubheading Synopsis
922fbb7b 31158
a2c02241
NR
31159@smallexample
31160 -file-list-shared-libraries
31161@end smallexample
922fbb7b 31162
a2c02241 31163List the shared libraries in the program.
922fbb7b 31164
a2c02241 31165@subsubheading @value{GDBN} Command
922fbb7b 31166
a2c02241 31167The corresponding @value{GDBN} command is @samp{info shared}.
922fbb7b 31168
a2c02241
NR
31169@subsubheading Example
31170N.A.
922fbb7b
AC
31171
31172
a2c02241
NR
31173@subheading The @code{-file-list-symbol-files} Command
31174@findex -file-list-symbol-files
922fbb7b 31175
a2c02241 31176@subsubheading Synopsis
922fbb7b 31177
a2c02241
NR
31178@smallexample
31179 -file-list-symbol-files
31180@end smallexample
922fbb7b 31181
a2c02241 31182List symbol files.
922fbb7b 31183
a2c02241 31184@subsubheading @value{GDBN} Command
922fbb7b 31185
a2c02241 31186The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 31187
a2c02241
NR
31188@subsubheading Example
31189N.A.
9901a55b 31190@end ignore
922fbb7b 31191
922fbb7b 31192
a2c02241
NR
31193@subheading The @code{-file-symbol-file} Command
31194@findex -file-symbol-file
922fbb7b 31195
a2c02241 31196@subsubheading Synopsis
922fbb7b 31197
a2c02241
NR
31198@smallexample
31199 -file-symbol-file @var{file}
31200@end smallexample
922fbb7b 31201
a2c02241
NR
31202Read symbol table info from the specified @var{file} argument. When
31203used without arguments, clears @value{GDBN}'s symbol table info. No output is
31204produced, except for a completion notification.
922fbb7b 31205
a2c02241 31206@subsubheading @value{GDBN} Command
922fbb7b 31207
a2c02241 31208The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 31209
a2c02241 31210@subsubheading Example
922fbb7b 31211
a2c02241 31212@smallexample
594fe323 31213(gdb)
a2c02241
NR
31214-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
31215^done
594fe323 31216(gdb)
a2c02241 31217@end smallexample
922fbb7b 31218
a2c02241 31219@ignore
a2c02241
NR
31220@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31221@node GDB/MI Memory Overlay Commands
31222@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 31223
a2c02241 31224The memory overlay commands are not implemented.
922fbb7b 31225
a2c02241 31226@c @subheading -overlay-auto
922fbb7b 31227
a2c02241 31228@c @subheading -overlay-list-mapping-state
922fbb7b 31229
a2c02241 31230@c @subheading -overlay-list-overlays
922fbb7b 31231
a2c02241 31232@c @subheading -overlay-map
922fbb7b 31233
a2c02241 31234@c @subheading -overlay-off
922fbb7b 31235
a2c02241 31236@c @subheading -overlay-on
922fbb7b 31237
a2c02241 31238@c @subheading -overlay-unmap
922fbb7b 31239
a2c02241
NR
31240@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31241@node GDB/MI Signal Handling Commands
31242@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 31243
a2c02241 31244Signal handling commands are not implemented.
922fbb7b 31245
a2c02241 31246@c @subheading -signal-handle
922fbb7b 31247
a2c02241 31248@c @subheading -signal-list-handle-actions
922fbb7b 31249
a2c02241
NR
31250@c @subheading -signal-list-signal-types
31251@end ignore
922fbb7b 31252
922fbb7b 31253
a2c02241
NR
31254@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31255@node GDB/MI Target Manipulation
31256@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
31257
31258
a2c02241
NR
31259@subheading The @code{-target-attach} Command
31260@findex -target-attach
922fbb7b
AC
31261
31262@subsubheading Synopsis
31263
31264@smallexample
c3b108f7 31265 -target-attach @var{pid} | @var{gid} | @var{file}
922fbb7b
AC
31266@end smallexample
31267
c3b108f7
VP
31268Attach to a process @var{pid} or a file @var{file} outside of
31269@value{GDBN}, or a thread group @var{gid}. If attaching to a thread
31270group, the id previously returned by
31271@samp{-list-thread-groups --available} must be used.
922fbb7b 31272
79a6e687 31273@subsubheading @value{GDBN} Command
922fbb7b 31274
a2c02241 31275The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 31276
a2c02241 31277@subsubheading Example
b56e7235
VP
31278@smallexample
31279(gdb)
31280-target-attach 34
31281=thread-created,id="1"
5ae4183a 31282*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
b56e7235
VP
31283^done
31284(gdb)
31285@end smallexample
a2c02241 31286
9901a55b 31287@ignore
a2c02241
NR
31288@subheading The @code{-target-compare-sections} Command
31289@findex -target-compare-sections
922fbb7b
AC
31290
31291@subsubheading Synopsis
31292
31293@smallexample
a2c02241 31294 -target-compare-sections [ @var{section} ]
922fbb7b
AC
31295@end smallexample
31296
a2c02241
NR
31297Compare data of section @var{section} on target to the exec file.
31298Without the argument, all sections are compared.
922fbb7b 31299
a2c02241 31300@subsubheading @value{GDBN} Command
922fbb7b 31301
a2c02241 31302The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 31303
a2c02241
NR
31304@subsubheading Example
31305N.A.
9901a55b 31306@end ignore
a2c02241
NR
31307
31308
31309@subheading The @code{-target-detach} Command
31310@findex -target-detach
922fbb7b
AC
31311
31312@subsubheading Synopsis
31313
31314@smallexample
c3b108f7 31315 -target-detach [ @var{pid} | @var{gid} ]
922fbb7b
AC
31316@end smallexample
31317
a2c02241 31318Detach from the remote target which normally resumes its execution.
c3b108f7
VP
31319If either @var{pid} or @var{gid} is specified, detaches from either
31320the specified process, or specified thread group. There's no output.
a2c02241 31321
79a6e687 31322@subsubheading @value{GDBN} Command
a2c02241
NR
31323
31324The corresponding @value{GDBN} command is @samp{detach}.
31325
31326@subsubheading Example
922fbb7b
AC
31327
31328@smallexample
594fe323 31329(gdb)
a2c02241
NR
31330-target-detach
31331^done
594fe323 31332(gdb)
922fbb7b
AC
31333@end smallexample
31334
31335
a2c02241
NR
31336@subheading The @code{-target-disconnect} Command
31337@findex -target-disconnect
922fbb7b
AC
31338
31339@subsubheading Synopsis
31340
123dc839 31341@smallexample
a2c02241 31342 -target-disconnect
123dc839 31343@end smallexample
922fbb7b 31344
a2c02241
NR
31345Disconnect from the remote target. There's no output and the target is
31346generally not resumed.
31347
79a6e687 31348@subsubheading @value{GDBN} Command
a2c02241
NR
31349
31350The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
31351
31352@subsubheading Example
922fbb7b
AC
31353
31354@smallexample
594fe323 31355(gdb)
a2c02241
NR
31356-target-disconnect
31357^done
594fe323 31358(gdb)
922fbb7b
AC
31359@end smallexample
31360
31361
a2c02241
NR
31362@subheading The @code{-target-download} Command
31363@findex -target-download
922fbb7b
AC
31364
31365@subsubheading Synopsis
31366
31367@smallexample
a2c02241 31368 -target-download
922fbb7b
AC
31369@end smallexample
31370
a2c02241
NR
31371Loads the executable onto the remote target.
31372It prints out an update message every half second, which includes the fields:
31373
31374@table @samp
31375@item section
31376The name of the section.
31377@item section-sent
31378The size of what has been sent so far for that section.
31379@item section-size
31380The size of the section.
31381@item total-sent
31382The total size of what was sent so far (the current and the previous sections).
31383@item total-size
31384The size of the overall executable to download.
31385@end table
31386
31387@noindent
31388Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
31389@sc{gdb/mi} Output Syntax}).
31390
31391In addition, it prints the name and size of the sections, as they are
31392downloaded. These messages include the following fields:
31393
31394@table @samp
31395@item section
31396The name of the section.
31397@item section-size
31398The size of the section.
31399@item total-size
31400The size of the overall executable to download.
31401@end table
31402
31403@noindent
31404At the end, a summary is printed.
31405
31406@subsubheading @value{GDBN} Command
31407
31408The corresponding @value{GDBN} command is @samp{load}.
31409
31410@subsubheading Example
31411
31412Note: each status message appears on a single line. Here the messages
31413have been broken down so that they can fit onto a page.
922fbb7b
AC
31414
31415@smallexample
594fe323 31416(gdb)
a2c02241
NR
31417-target-download
31418+download,@{section=".text",section-size="6668",total-size="9880"@}
31419+download,@{section=".text",section-sent="512",section-size="6668",
31420total-sent="512",total-size="9880"@}
31421+download,@{section=".text",section-sent="1024",section-size="6668",
31422total-sent="1024",total-size="9880"@}
31423+download,@{section=".text",section-sent="1536",section-size="6668",
31424total-sent="1536",total-size="9880"@}
31425+download,@{section=".text",section-sent="2048",section-size="6668",
31426total-sent="2048",total-size="9880"@}
31427+download,@{section=".text",section-sent="2560",section-size="6668",
31428total-sent="2560",total-size="9880"@}
31429+download,@{section=".text",section-sent="3072",section-size="6668",
31430total-sent="3072",total-size="9880"@}
31431+download,@{section=".text",section-sent="3584",section-size="6668",
31432total-sent="3584",total-size="9880"@}
31433+download,@{section=".text",section-sent="4096",section-size="6668",
31434total-sent="4096",total-size="9880"@}
31435+download,@{section=".text",section-sent="4608",section-size="6668",
31436total-sent="4608",total-size="9880"@}
31437+download,@{section=".text",section-sent="5120",section-size="6668",
31438total-sent="5120",total-size="9880"@}
31439+download,@{section=".text",section-sent="5632",section-size="6668",
31440total-sent="5632",total-size="9880"@}
31441+download,@{section=".text",section-sent="6144",section-size="6668",
31442total-sent="6144",total-size="9880"@}
31443+download,@{section=".text",section-sent="6656",section-size="6668",
31444total-sent="6656",total-size="9880"@}
31445+download,@{section=".init",section-size="28",total-size="9880"@}
31446+download,@{section=".fini",section-size="28",total-size="9880"@}
31447+download,@{section=".data",section-size="3156",total-size="9880"@}
31448+download,@{section=".data",section-sent="512",section-size="3156",
31449total-sent="7236",total-size="9880"@}
31450+download,@{section=".data",section-sent="1024",section-size="3156",
31451total-sent="7748",total-size="9880"@}
31452+download,@{section=".data",section-sent="1536",section-size="3156",
31453total-sent="8260",total-size="9880"@}
31454+download,@{section=".data",section-sent="2048",section-size="3156",
31455total-sent="8772",total-size="9880"@}
31456+download,@{section=".data",section-sent="2560",section-size="3156",
31457total-sent="9284",total-size="9880"@}
31458+download,@{section=".data",section-sent="3072",section-size="3156",
31459total-sent="9796",total-size="9880"@}
31460^done,address="0x10004",load-size="9880",transfer-rate="6586",
31461write-rate="429"
594fe323 31462(gdb)
922fbb7b
AC
31463@end smallexample
31464
31465
9901a55b 31466@ignore
a2c02241
NR
31467@subheading The @code{-target-exec-status} Command
31468@findex -target-exec-status
922fbb7b
AC
31469
31470@subsubheading Synopsis
31471
31472@smallexample
a2c02241 31473 -target-exec-status
922fbb7b
AC
31474@end smallexample
31475
a2c02241
NR
31476Provide information on the state of the target (whether it is running or
31477not, for instance).
922fbb7b 31478
a2c02241 31479@subsubheading @value{GDBN} Command
922fbb7b 31480
a2c02241
NR
31481There's no equivalent @value{GDBN} command.
31482
31483@subsubheading Example
31484N.A.
922fbb7b 31485
a2c02241
NR
31486
31487@subheading The @code{-target-list-available-targets} Command
31488@findex -target-list-available-targets
922fbb7b
AC
31489
31490@subsubheading Synopsis
31491
31492@smallexample
a2c02241 31493 -target-list-available-targets
922fbb7b
AC
31494@end smallexample
31495
a2c02241 31496List the possible targets to connect to.
922fbb7b 31497
a2c02241 31498@subsubheading @value{GDBN} Command
922fbb7b 31499
a2c02241 31500The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 31501
a2c02241
NR
31502@subsubheading Example
31503N.A.
31504
31505
31506@subheading The @code{-target-list-current-targets} Command
31507@findex -target-list-current-targets
922fbb7b
AC
31508
31509@subsubheading Synopsis
31510
31511@smallexample
a2c02241 31512 -target-list-current-targets
922fbb7b
AC
31513@end smallexample
31514
a2c02241 31515Describe the current target.
922fbb7b 31516
a2c02241 31517@subsubheading @value{GDBN} Command
922fbb7b 31518
a2c02241
NR
31519The corresponding information is printed by @samp{info file} (among
31520other things).
922fbb7b 31521
a2c02241
NR
31522@subsubheading Example
31523N.A.
31524
31525
31526@subheading The @code{-target-list-parameters} Command
31527@findex -target-list-parameters
922fbb7b
AC
31528
31529@subsubheading Synopsis
31530
31531@smallexample
a2c02241 31532 -target-list-parameters
922fbb7b
AC
31533@end smallexample
31534
a2c02241 31535@c ????
9901a55b 31536@end ignore
a2c02241
NR
31537
31538@subsubheading @value{GDBN} Command
31539
31540No equivalent.
922fbb7b
AC
31541
31542@subsubheading Example
a2c02241
NR
31543N.A.
31544
31545
31546@subheading The @code{-target-select} Command
31547@findex -target-select
31548
31549@subsubheading Synopsis
922fbb7b
AC
31550
31551@smallexample
a2c02241 31552 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
31553@end smallexample
31554
a2c02241 31555Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 31556
a2c02241
NR
31557@table @samp
31558@item @var{type}
75c99385 31559The type of target, for instance @samp{remote}, etc.
a2c02241
NR
31560@item @var{parameters}
31561Device names, host names and the like. @xref{Target Commands, ,
79a6e687 31562Commands for Managing Targets}, for more details.
a2c02241
NR
31563@end table
31564
31565The output is a connection notification, followed by the address at
31566which the target program is, in the following form:
922fbb7b
AC
31567
31568@smallexample
a2c02241
NR
31569^connected,addr="@var{address}",func="@var{function name}",
31570 args=[@var{arg list}]
922fbb7b
AC
31571@end smallexample
31572
a2c02241
NR
31573@subsubheading @value{GDBN} Command
31574
31575The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
31576
31577@subsubheading Example
922fbb7b 31578
265eeb58 31579@smallexample
594fe323 31580(gdb)
75c99385 31581-target-select remote /dev/ttya
a2c02241 31582^connected,addr="0xfe00a300",func="??",args=[]
594fe323 31583(gdb)
265eeb58 31584@end smallexample
ef21caaf 31585
a6b151f1
DJ
31586@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31587@node GDB/MI File Transfer Commands
31588@section @sc{gdb/mi} File Transfer Commands
31589
31590
31591@subheading The @code{-target-file-put} Command
31592@findex -target-file-put
31593
31594@subsubheading Synopsis
31595
31596@smallexample
31597 -target-file-put @var{hostfile} @var{targetfile}
31598@end smallexample
31599
31600Copy file @var{hostfile} from the host system (the machine running
31601@value{GDBN}) to @var{targetfile} on the target system.
31602
31603@subsubheading @value{GDBN} Command
31604
31605The corresponding @value{GDBN} command is @samp{remote put}.
31606
31607@subsubheading Example
31608
31609@smallexample
31610(gdb)
31611-target-file-put localfile remotefile
31612^done
31613(gdb)
31614@end smallexample
31615
31616
1763a388 31617@subheading The @code{-target-file-get} Command
a6b151f1
DJ
31618@findex -target-file-get
31619
31620@subsubheading Synopsis
31621
31622@smallexample
31623 -target-file-get @var{targetfile} @var{hostfile}
31624@end smallexample
31625
31626Copy file @var{targetfile} from the target system to @var{hostfile}
31627on the host system.
31628
31629@subsubheading @value{GDBN} Command
31630
31631The corresponding @value{GDBN} command is @samp{remote get}.
31632
31633@subsubheading Example
31634
31635@smallexample
31636(gdb)
31637-target-file-get remotefile localfile
31638^done
31639(gdb)
31640@end smallexample
31641
31642
31643@subheading The @code{-target-file-delete} Command
31644@findex -target-file-delete
31645
31646@subsubheading Synopsis
31647
31648@smallexample
31649 -target-file-delete @var{targetfile}
31650@end smallexample
31651
31652Delete @var{targetfile} from the target system.
31653
31654@subsubheading @value{GDBN} Command
31655
31656The corresponding @value{GDBN} command is @samp{remote delete}.
31657
31658@subsubheading Example
31659
31660@smallexample
31661(gdb)
31662-target-file-delete remotefile
31663^done
31664(gdb)
31665@end smallexample
31666
31667
58d06528
JB
31668@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31669@node GDB/MI Ada Exceptions Commands
31670@section Ada Exceptions @sc{gdb/mi} Commands
31671
31672@subheading The @code{-info-ada-exceptions} Command
31673@findex -info-ada-exceptions
31674
31675@subsubheading Synopsis
31676
31677@smallexample
31678 -info-ada-exceptions [ @var{regexp}]
31679@end smallexample
31680
31681List all Ada exceptions defined within the program being debugged.
31682With a regular expression @var{regexp}, only those exceptions whose
31683names match @var{regexp} are listed.
31684
31685@subsubheading @value{GDBN} Command
31686
31687The corresponding @value{GDBN} command is @samp{info exceptions}.
31688
31689@subsubheading Result
31690
31691The result is a table of Ada exceptions. The following columns are
31692defined for each exception:
31693
31694@table @samp
31695@item name
31696The name of the exception.
31697
31698@item address
31699The address of the exception.
31700
31701@end table
31702
31703@subsubheading Example
31704
31705@smallexample
31706-info-ada-exceptions aint
31707^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
31708hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
31709@{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
31710body=[@{name="constraint_error",address="0x0000000000613da0"@},
31711@{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
31712@end smallexample
31713
31714@subheading Catching Ada Exceptions
31715
31716The commands describing how to ask @value{GDBN} to stop when a program
31717raises an exception are described at @ref{Ada Exception GDB/MI
31718Catchpoint Commands}.
31719
31720
ef21caaf 31721@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d192b373
JB
31722@node GDB/MI Support Commands
31723@section @sc{gdb/mi} Support Commands
ef21caaf 31724
d192b373
JB
31725Since new commands and features get regularly added to @sc{gdb/mi},
31726some commands are available to help front-ends query the debugger
31727about support for these capabilities. Similarly, it is also possible
31728to query @value{GDBN} about target support of certain features.
ef21caaf 31729
6b7cbff1
JB
31730@subheading The @code{-info-gdb-mi-command} Command
31731@cindex @code{-info-gdb-mi-command}
31732@findex -info-gdb-mi-command
31733
31734@subsubheading Synopsis
31735
31736@smallexample
31737 -info-gdb-mi-command @var{cmd_name}
31738@end smallexample
31739
31740Query support for the @sc{gdb/mi} command named @var{cmd_name}.
31741
31742Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
31743is technically not part of the command name (@pxref{GDB/MI Input
31744Syntax}), and thus should be omitted in @var{cmd_name}. However,
31745for ease of use, this command also accepts the form with the leading
31746dash.
31747
31748@subsubheading @value{GDBN} Command
31749
31750There is no corresponding @value{GDBN} command.
31751
31752@subsubheading Result
31753
31754The result is a tuple. There is currently only one field:
31755
31756@table @samp
31757@item exists
31758This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
31759@code{"false"} otherwise.
31760
31761@end table
31762
31763@subsubheading Example
31764
31765Here is an example where the @sc{gdb/mi} command does not exist:
31766
31767@smallexample
31768-info-gdb-mi-command unsupported-command
31769^done,command=@{exists="false"@}
31770@end smallexample
31771
31772@noindent
31773And here is an example where the @sc{gdb/mi} command is known
31774to the debugger:
31775
31776@smallexample
31777-info-gdb-mi-command symbol-list-lines
31778^done,command=@{exists="true"@}
31779@end smallexample
31780
084344da
VP
31781@subheading The @code{-list-features} Command
31782@findex -list-features
9b26f0fb 31783@cindex supported @sc{gdb/mi} features, list
084344da
VP
31784
31785Returns a list of particular features of the MI protocol that
31786this version of gdb implements. A feature can be a command,
31787or a new field in an output of some command, or even an
31788important bugfix. While a frontend can sometimes detect presence
31789of a feature at runtime, it is easier to perform detection at debugger
d192b373 31790startup.
084344da
VP
31791
31792The command returns a list of strings, with each string naming an
31793available feature. Each returned string is just a name, it does not
d192b373 31794have any internal structure. The list of possible feature names
084344da
VP
31795is given below.
31796
31797Example output:
31798
31799@smallexample
31800(gdb) -list-features
31801^done,result=["feature1","feature2"]
31802@end smallexample
31803
31804The current list of features is:
31805
edef6000 31806@ftable @samp
30e026bb 31807@item frozen-varobjs
a05336a1
JB
31808Indicates support for the @code{-var-set-frozen} command, as well
31809as possible presense of the @code{frozen} field in the output
30e026bb
VP
31810of @code{-varobj-create}.
31811@item pending-breakpoints
a05336a1
JB
31812Indicates support for the @option{-f} option to the @code{-break-insert}
31813command.
b6313243 31814@item python
a05336a1 31815Indicates Python scripting support, Python-based
b6313243
TT
31816pretty-printing commands, and possible presence of the
31817@samp{display_hint} field in the output of @code{-var-list-children}
30e026bb 31818@item thread-info
a05336a1 31819Indicates support for the @code{-thread-info} command.
8dedea02 31820@item data-read-memory-bytes
a05336a1 31821Indicates support for the @code{-data-read-memory-bytes} and the
8dedea02 31822@code{-data-write-memory-bytes} commands.
39c4d40a
TT
31823@item breakpoint-notifications
31824Indicates that changes to breakpoints and breakpoints created via the
31825CLI will be announced via async records.
5d77fe44 31826@item ada-task-info
6adcee18 31827Indicates support for the @code{-ada-task-info} command.
422ad5c2
JB
31828@item language-option
31829Indicates that all @sc{gdb/mi} commands accept the @option{--language}
31830option (@pxref{Context management}).
6b7cbff1
JB
31831@item info-gdb-mi-command
31832Indicates support for the @code{-info-gdb-mi-command} command.
2ea126fa
JB
31833@item undefined-command-error-code
31834Indicates support for the "undefined-command" error code in error result
31835records, produced when trying to execute an undefined @sc{gdb/mi} command
31836(@pxref{GDB/MI Result Records}).
72bfa06c
JB
31837@item exec-run-start-option
31838Indicates that the @code{-exec-run} command supports the @option{--start}
31839option (@pxref{GDB/MI Program Execution}).
edef6000 31840@end ftable
084344da 31841
c6ebd6cf
VP
31842@subheading The @code{-list-target-features} Command
31843@findex -list-target-features
31844
31845Returns a list of particular features that are supported by the
31846target. Those features affect the permitted MI commands, but
31847unlike the features reported by the @code{-list-features} command, the
31848features depend on which target GDB is using at the moment. Whenever
31849a target can change, due to commands such as @code{-target-select},
31850@code{-target-attach} or @code{-exec-run}, the list of target features
31851may change, and the frontend should obtain it again.
31852Example output:
31853
31854@smallexample
b3d3b4bd 31855(gdb) -list-target-features
c6ebd6cf
VP
31856^done,result=["async"]
31857@end smallexample
31858
31859The current list of features is:
31860
31861@table @samp
31862@item async
31863Indicates that the target is capable of asynchronous command
31864execution, which means that @value{GDBN} will accept further commands
31865while the target is running.
31866
f75d858b
MK
31867@item reverse
31868Indicates that the target is capable of reverse execution.
31869@xref{Reverse Execution}, for more information.
31870
c6ebd6cf
VP
31871@end table
31872
d192b373
JB
31873@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31874@node GDB/MI Miscellaneous Commands
31875@section Miscellaneous @sc{gdb/mi} Commands
31876
31877@c @subheading -gdb-complete
31878
31879@subheading The @code{-gdb-exit} Command
31880@findex -gdb-exit
31881
31882@subsubheading Synopsis
31883
31884@smallexample
31885 -gdb-exit
31886@end smallexample
31887
31888Exit @value{GDBN} immediately.
31889
31890@subsubheading @value{GDBN} Command
31891
31892Approximately corresponds to @samp{quit}.
31893
31894@subsubheading Example
31895
31896@smallexample
31897(gdb)
31898-gdb-exit
31899^exit
31900@end smallexample
31901
31902
31903@ignore
31904@subheading The @code{-exec-abort} Command
31905@findex -exec-abort
31906
31907@subsubheading Synopsis
31908
31909@smallexample
31910 -exec-abort
31911@end smallexample
31912
31913Kill the inferior running program.
31914
31915@subsubheading @value{GDBN} Command
31916
31917The corresponding @value{GDBN} command is @samp{kill}.
31918
31919@subsubheading Example
31920N.A.
31921@end ignore
31922
31923
31924@subheading The @code{-gdb-set} Command
31925@findex -gdb-set
31926
31927@subsubheading Synopsis
31928
31929@smallexample
31930 -gdb-set
31931@end smallexample
31932
31933Set an internal @value{GDBN} variable.
31934@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
31935
31936@subsubheading @value{GDBN} Command
31937
31938The corresponding @value{GDBN} command is @samp{set}.
31939
31940@subsubheading Example
31941
31942@smallexample
31943(gdb)
31944-gdb-set $foo=3
31945^done
31946(gdb)
31947@end smallexample
31948
31949
31950@subheading The @code{-gdb-show} Command
31951@findex -gdb-show
31952
31953@subsubheading Synopsis
31954
31955@smallexample
31956 -gdb-show
31957@end smallexample
31958
31959Show the current value of a @value{GDBN} variable.
31960
31961@subsubheading @value{GDBN} Command
31962
31963The corresponding @value{GDBN} command is @samp{show}.
31964
31965@subsubheading Example
31966
31967@smallexample
31968(gdb)
31969-gdb-show annotate
31970^done,value="0"
31971(gdb)
31972@end smallexample
31973
31974@c @subheading -gdb-source
31975
31976
31977@subheading The @code{-gdb-version} Command
31978@findex -gdb-version
31979
31980@subsubheading Synopsis
31981
31982@smallexample
31983 -gdb-version
31984@end smallexample
31985
31986Show version information for @value{GDBN}. Used mostly in testing.
31987
31988@subsubheading @value{GDBN} Command
31989
31990The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
31991default shows this information when you start an interactive session.
31992
31993@subsubheading Example
31994
31995@c This example modifies the actual output from GDB to avoid overfull
31996@c box in TeX.
31997@smallexample
31998(gdb)
31999-gdb-version
32000~GNU gdb 5.2.1
32001~Copyright 2000 Free Software Foundation, Inc.
32002~GDB is free software, covered by the GNU General Public License, and
32003~you are welcome to change it and/or distribute copies of it under
32004~ certain conditions.
32005~Type "show copying" to see the conditions.
32006~There is absolutely no warranty for GDB. Type "show warranty" for
32007~ details.
32008~This GDB was configured as
32009 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
32010^done
32011(gdb)
32012@end smallexample
32013
c3b108f7
VP
32014@subheading The @code{-list-thread-groups} Command
32015@findex -list-thread-groups
32016
32017@subheading Synopsis
32018
32019@smallexample
dc146f7c 32020-list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
c3b108f7
VP
32021@end smallexample
32022
dc146f7c
VP
32023Lists thread groups (@pxref{Thread groups}). When a single thread
32024group is passed as the argument, lists the children of that group.
32025When several thread group are passed, lists information about those
32026thread groups. Without any parameters, lists information about all
32027top-level thread groups.
32028
32029Normally, thread groups that are being debugged are reported.
32030With the @samp{--available} option, @value{GDBN} reports thread groups
32031available on the target.
32032
32033The output of this command may have either a @samp{threads} result or
32034a @samp{groups} result. The @samp{thread} result has a list of tuples
32035as value, with each tuple describing a thread (@pxref{GDB/MI Thread
32036Information}). The @samp{groups} result has a list of tuples as value,
32037each tuple describing a thread group. If top-level groups are
32038requested (that is, no parameter is passed), or when several groups
32039are passed, the output always has a @samp{groups} result. The format
32040of the @samp{group} result is described below.
32041
32042To reduce the number of roundtrips it's possible to list thread groups
32043together with their children, by passing the @samp{--recurse} option
32044and the recursion depth. Presently, only recursion depth of 1 is
32045permitted. If this option is present, then every reported thread group
32046will also include its children, either as @samp{group} or
32047@samp{threads} field.
32048
32049In general, any combination of option and parameters is permitted, with
32050the following caveats:
32051
32052@itemize @bullet
32053@item
32054When a single thread group is passed, the output will typically
32055be the @samp{threads} result. Because threads may not contain
32056anything, the @samp{recurse} option will be ignored.
32057
32058@item
32059When the @samp{--available} option is passed, limited information may
32060be available. In particular, the list of threads of a process might
32061be inaccessible. Further, specifying specific thread groups might
32062not give any performance advantage over listing all thread groups.
32063The frontend should assume that @samp{-list-thread-groups --available}
32064is always an expensive operation and cache the results.
32065
32066@end itemize
32067
32068The @samp{groups} result is a list of tuples, where each tuple may
32069have the following fields:
32070
32071@table @code
32072@item id
32073Identifier of the thread group. This field is always present.
a79b8f6e
VP
32074The identifier is an opaque string; frontends should not try to
32075convert it to an integer, even though it might look like one.
dc146f7c
VP
32076
32077@item type
32078The type of the thread group. At present, only @samp{process} is a
32079valid type.
32080
32081@item pid
32082The target-specific process identifier. This field is only present
a79b8f6e 32083for thread groups of type @samp{process} and only if the process exists.
c3b108f7 32084
2ddf4301
SM
32085@item exit-code
32086The exit code of this group's last exited thread, formatted in octal.
32087This field is only present for thread groups of type @samp{process} and
32088only if the process is not running.
32089
dc146f7c
VP
32090@item num_children
32091The number of children this thread group has. This field may be
32092absent for an available thread group.
32093
32094@item threads
32095This field has a list of tuples as value, each tuple describing a
32096thread. It may be present if the @samp{--recurse} option is
32097specified, and it's actually possible to obtain the threads.
32098
32099@item cores
32100This field is a list of integers, each identifying a core that one
32101thread of the group is running on. This field may be absent if
32102such information is not available.
32103
a79b8f6e
VP
32104@item executable
32105The name of the executable file that corresponds to this thread group.
32106The field is only present for thread groups of type @samp{process},
32107and only if there is a corresponding executable file.
32108
dc146f7c 32109@end table
c3b108f7
VP
32110
32111@subheading Example
32112
32113@smallexample
32114@value{GDBP}
32115-list-thread-groups
32116^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
32117-list-thread-groups 17
32118^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
32119 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
32120@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
32121 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
32122 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}]]
dc146f7c
VP
32123-list-thread-groups --available
32124^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
32125-list-thread-groups --available --recurse 1
32126 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
32127 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
32128 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
32129-list-thread-groups --available --recurse 1 17 18
32130^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
32131 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
32132 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
c3b108f7 32133@end smallexample
c6ebd6cf 32134
f3e0e960
SS
32135@subheading The @code{-info-os} Command
32136@findex -info-os
32137
32138@subsubheading Synopsis
32139
32140@smallexample
32141-info-os [ @var{type} ]
32142@end smallexample
32143
32144If no argument is supplied, the command returns a table of available
32145operating-system-specific information types. If one of these types is
32146supplied as an argument @var{type}, then the command returns a table
32147of data of that type.
32148
32149The types of information available depend on the target operating
32150system.
32151
32152@subsubheading @value{GDBN} Command
32153
32154The corresponding @value{GDBN} command is @samp{info os}.
32155
32156@subsubheading Example
32157
32158When run on a @sc{gnu}/Linux system, the output will look something
32159like this:
32160
32161@smallexample
32162@value{GDBP}
32163-info-os
d33279b3 32164^done,OSDataTable=@{nr_rows="10",nr_cols="3",
f3e0e960 32165hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
71caed83
SS
32166 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
32167 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
d33279b3
AT
32168body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
32169 col2="CPUs"@},
32170 item=@{col0="files",col1="Listing of all file descriptors",
32171 col2="File descriptors"@},
32172 item=@{col0="modules",col1="Listing of all loaded kernel modules",
32173 col2="Kernel modules"@},
32174 item=@{col0="msg",col1="Listing of all message queues",
32175 col2="Message queues"@},
32176 item=@{col0="processes",col1="Listing of all processes",
71caed83
SS
32177 col2="Processes"@},
32178 item=@{col0="procgroups",col1="Listing of all process groups",
32179 col2="Process groups"@},
71caed83
SS
32180 item=@{col0="semaphores",col1="Listing of all semaphores",
32181 col2="Semaphores"@},
d33279b3
AT
32182 item=@{col0="shm",col1="Listing of all shared-memory regions",
32183 col2="Shared-memory regions"@},
32184 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
32185 col2="Sockets"@},
32186 item=@{col0="threads",col1="Listing of all threads",
32187 col2="Threads"@}]
f3e0e960
SS
32188@value{GDBP}
32189-info-os processes
32190^done,OSDataTable=@{nr_rows="190",nr_cols="4",
32191hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
32192 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
32193 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
32194 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
32195body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
32196 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
32197 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
32198 ...
32199 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
32200 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
32201(gdb)
32202@end smallexample
a79b8f6e 32203
71caed83
SS
32204(Note that the MI output here includes a @code{"Title"} column that
32205does not appear in command-line @code{info os}; this column is useful
32206for MI clients that want to enumerate the types of data, such as in a
32207popup menu, but is needless clutter on the command line, and
32208@code{info os} omits it.)
32209
a79b8f6e
VP
32210@subheading The @code{-add-inferior} Command
32211@findex -add-inferior
32212
32213@subheading Synopsis
32214
32215@smallexample
32216-add-inferior
32217@end smallexample
32218
32219Creates a new inferior (@pxref{Inferiors and Programs}). The created
32220inferior is not associated with any executable. Such association may
32221be established with the @samp{-file-exec-and-symbols} command
32222(@pxref{GDB/MI File Commands}). The command response has a single
b7742092 32223field, @samp{inferior}, whose value is the identifier of the
a79b8f6e
VP
32224thread group corresponding to the new inferior.
32225
32226@subheading Example
32227
32228@smallexample
32229@value{GDBP}
32230-add-inferior
b7742092 32231^done,inferior="i3"
a79b8f6e
VP
32232@end smallexample
32233
ef21caaf
NR
32234@subheading The @code{-interpreter-exec} Command
32235@findex -interpreter-exec
32236
32237@subheading Synopsis
32238
32239@smallexample
32240-interpreter-exec @var{interpreter} @var{command}
32241@end smallexample
a2c02241 32242@anchor{-interpreter-exec}
ef21caaf
NR
32243
32244Execute the specified @var{command} in the given @var{interpreter}.
32245
32246@subheading @value{GDBN} Command
32247
32248The corresponding @value{GDBN} command is @samp{interpreter-exec}.
32249
32250@subheading Example
32251
32252@smallexample
594fe323 32253(gdb)
ef21caaf
NR
32254-interpreter-exec console "break main"
32255&"During symbol reading, couldn't parse type; debugger out of date?.\n"
32256&"During symbol reading, bad structure-type format.\n"
32257~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
32258^done
594fe323 32259(gdb)
ef21caaf
NR
32260@end smallexample
32261
32262@subheading The @code{-inferior-tty-set} Command
32263@findex -inferior-tty-set
32264
32265@subheading Synopsis
32266
32267@smallexample
32268-inferior-tty-set /dev/pts/1
32269@end smallexample
32270
32271Set terminal for future runs of the program being debugged.
32272
32273@subheading @value{GDBN} Command
32274
32275The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
32276
32277@subheading Example
32278
32279@smallexample
594fe323 32280(gdb)
ef21caaf
NR
32281-inferior-tty-set /dev/pts/1
32282^done
594fe323 32283(gdb)
ef21caaf
NR
32284@end smallexample
32285
32286@subheading The @code{-inferior-tty-show} Command
32287@findex -inferior-tty-show
32288
32289@subheading Synopsis
32290
32291@smallexample
32292-inferior-tty-show
32293@end smallexample
32294
32295Show terminal for future runs of program being debugged.
32296
32297@subheading @value{GDBN} Command
32298
32299The corresponding @value{GDBN} command is @samp{show inferior-tty}.
32300
32301@subheading Example
32302
32303@smallexample
594fe323 32304(gdb)
ef21caaf
NR
32305-inferior-tty-set /dev/pts/1
32306^done
594fe323 32307(gdb)
ef21caaf
NR
32308-inferior-tty-show
32309^done,inferior_tty_terminal="/dev/pts/1"
594fe323 32310(gdb)
ef21caaf 32311@end smallexample
922fbb7b 32312
a4eefcd8
NR
32313@subheading The @code{-enable-timings} Command
32314@findex -enable-timings
32315
32316@subheading Synopsis
32317
32318@smallexample
32319-enable-timings [yes | no]
32320@end smallexample
32321
32322Toggle the printing of the wallclock, user and system times for an MI
32323command as a field in its output. This command is to help frontend
32324developers optimize the performance of their code. No argument is
32325equivalent to @samp{yes}.
32326
32327@subheading @value{GDBN} Command
32328
32329No equivalent.
32330
32331@subheading Example
32332
32333@smallexample
32334(gdb)
32335-enable-timings
32336^done
32337(gdb)
32338-break-insert main
32339^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
32340addr="0x080484ed",func="main",file="myprog.c",
998580f1
MK
32341fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
32342times="0"@},
a4eefcd8
NR
32343time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
32344(gdb)
32345-enable-timings no
32346^done
32347(gdb)
32348-exec-run
32349^running
32350(gdb)
a47ec5fe 32351*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
a4eefcd8
NR
32352frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
32353@{name="argv",value="0xbfb60364"@}],file="myprog.c",
32354fullname="/home/nickrob/myprog.c",line="73"@}
32355(gdb)
32356@end smallexample
32357
922fbb7b
AC
32358@node Annotations
32359@chapter @value{GDBN} Annotations
32360
086432e2
AC
32361This chapter describes annotations in @value{GDBN}. Annotations were
32362designed to interface @value{GDBN} to graphical user interfaces or other
32363similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
32364relatively high level.
32365
d3e8051b 32366The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
32367(@pxref{GDB/MI}).
32368
922fbb7b
AC
32369@ignore
32370This is Edition @value{EDITION}, @value{DATE}.
32371@end ignore
32372
32373@menu
32374* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 32375* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
32376* Prompting:: Annotations marking @value{GDBN}'s need for input.
32377* Errors:: Annotations for error messages.
922fbb7b
AC
32378* Invalidation:: Some annotations describe things now invalid.
32379* Annotations for Running::
32380 Whether the program is running, how it stopped, etc.
32381* Source Annotations:: Annotations describing source code.
922fbb7b
AC
32382@end menu
32383
32384@node Annotations Overview
32385@section What is an Annotation?
32386@cindex annotations
32387
922fbb7b
AC
32388Annotations start with a newline character, two @samp{control-z}
32389characters, and the name of the annotation. If there is no additional
32390information associated with this annotation, the name of the annotation
32391is followed immediately by a newline. If there is additional
32392information, the name of the annotation is followed by a space, the
32393additional information, and a newline. The additional information
32394cannot contain newline characters.
32395
32396Any output not beginning with a newline and two @samp{control-z}
32397characters denotes literal output from @value{GDBN}. Currently there is
32398no need for @value{GDBN} to output a newline followed by two
32399@samp{control-z} characters, but if there was such a need, the
32400annotations could be extended with an @samp{escape} annotation which
32401means those three characters as output.
32402
086432e2
AC
32403The annotation @var{level}, which is specified using the
32404@option{--annotate} command line option (@pxref{Mode Options}), controls
32405how much information @value{GDBN} prints together with its prompt,
32406values of expressions, source lines, and other types of output. Level 0
d3e8051b 32407is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
32408subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
32409for programs that control @value{GDBN}, and level 2 annotations have
32410been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
32411Interface, annotate, GDB's Obsolete Annotations}).
32412
32413@table @code
32414@kindex set annotate
32415@item set annotate @var{level}
e09f16f9 32416The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 32417annotations to the specified @var{level}.
9c16f35a
EZ
32418
32419@item show annotate
32420@kindex show annotate
32421Show the current annotation level.
09d4efe1
EZ
32422@end table
32423
32424This chapter describes level 3 annotations.
086432e2 32425
922fbb7b
AC
32426A simple example of starting up @value{GDBN} with annotations is:
32427
32428@smallexample
086432e2
AC
32429$ @kbd{gdb --annotate=3}
32430GNU gdb 6.0
32431Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
32432GDB is free software, covered by the GNU General Public License,
32433and you are welcome to change it and/or distribute copies of it
32434under certain conditions.
32435Type "show copying" to see the conditions.
32436There is absolutely no warranty for GDB. Type "show warranty"
32437for details.
086432e2 32438This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
32439
32440^Z^Zpre-prompt
f7dc1244 32441(@value{GDBP})
922fbb7b 32442^Z^Zprompt
086432e2 32443@kbd{quit}
922fbb7b
AC
32444
32445^Z^Zpost-prompt
b383017d 32446$
922fbb7b
AC
32447@end smallexample
32448
32449Here @samp{quit} is input to @value{GDBN}; the rest is output from
32450@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
32451denotes a @samp{control-z} character) are annotations; the rest is
32452output from @value{GDBN}.
32453
9e6c4bd5
NR
32454@node Server Prefix
32455@section The Server Prefix
32456@cindex server prefix
32457
32458If you prefix a command with @samp{server } then it will not affect
32459the command history, nor will it affect @value{GDBN}'s notion of which
32460command to repeat if @key{RET} is pressed on a line by itself. This
32461means that commands can be run behind a user's back by a front-end in
32462a transparent manner.
32463
d837706a
NR
32464The @code{server } prefix does not affect the recording of values into
32465the value history; to print a value without recording it into the
32466value history, use the @code{output} command instead of the
32467@code{print} command.
32468
32469Using this prefix also disables confirmation requests
32470(@pxref{confirmation requests}).
9e6c4bd5 32471
922fbb7b
AC
32472@node Prompting
32473@section Annotation for @value{GDBN} Input
32474
32475@cindex annotations for prompts
32476When @value{GDBN} prompts for input, it annotates this fact so it is possible
32477to know when to send output, when the output from a given command is
32478over, etc.
32479
32480Different kinds of input each have a different @dfn{input type}. Each
32481input type has three annotations: a @code{pre-} annotation, which
32482denotes the beginning of any prompt which is being output, a plain
32483annotation, which denotes the end of the prompt, and then a @code{post-}
32484annotation which denotes the end of any echo which may (or may not) be
32485associated with the input. For example, the @code{prompt} input type
32486features the following annotations:
32487
32488@smallexample
32489^Z^Zpre-prompt
32490^Z^Zprompt
32491^Z^Zpost-prompt
32492@end smallexample
32493
32494The input types are
32495
32496@table @code
e5ac9b53
EZ
32497@findex pre-prompt annotation
32498@findex prompt annotation
32499@findex post-prompt annotation
922fbb7b
AC
32500@item prompt
32501When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
32502
e5ac9b53
EZ
32503@findex pre-commands annotation
32504@findex commands annotation
32505@findex post-commands annotation
922fbb7b
AC
32506@item commands
32507When @value{GDBN} prompts for a set of commands, like in the @code{commands}
32508command. The annotations are repeated for each command which is input.
32509
e5ac9b53
EZ
32510@findex pre-overload-choice annotation
32511@findex overload-choice annotation
32512@findex post-overload-choice annotation
922fbb7b
AC
32513@item overload-choice
32514When @value{GDBN} wants the user to select between various overloaded functions.
32515
e5ac9b53
EZ
32516@findex pre-query annotation
32517@findex query annotation
32518@findex post-query annotation
922fbb7b
AC
32519@item query
32520When @value{GDBN} wants the user to confirm a potentially dangerous operation.
32521
e5ac9b53
EZ
32522@findex pre-prompt-for-continue annotation
32523@findex prompt-for-continue annotation
32524@findex post-prompt-for-continue annotation
922fbb7b
AC
32525@item prompt-for-continue
32526When @value{GDBN} is asking the user to press return to continue. Note: Don't
32527expect this to work well; instead use @code{set height 0} to disable
32528prompting. This is because the counting of lines is buggy in the
32529presence of annotations.
32530@end table
32531
32532@node Errors
32533@section Errors
32534@cindex annotations for errors, warnings and interrupts
32535
e5ac9b53 32536@findex quit annotation
922fbb7b
AC
32537@smallexample
32538^Z^Zquit
32539@end smallexample
32540
32541This annotation occurs right before @value{GDBN} responds to an interrupt.
32542
e5ac9b53 32543@findex error annotation
922fbb7b
AC
32544@smallexample
32545^Z^Zerror
32546@end smallexample
32547
32548This annotation occurs right before @value{GDBN} responds to an error.
32549
32550Quit and error annotations indicate that any annotations which @value{GDBN} was
32551in the middle of may end abruptly. For example, if a
32552@code{value-history-begin} annotation is followed by a @code{error}, one
32553cannot expect to receive the matching @code{value-history-end}. One
32554cannot expect not to receive it either, however; an error annotation
32555does not necessarily mean that @value{GDBN} is immediately returning all the way
32556to the top level.
32557
e5ac9b53 32558@findex error-begin annotation
922fbb7b
AC
32559A quit or error annotation may be preceded by
32560
32561@smallexample
32562^Z^Zerror-begin
32563@end smallexample
32564
32565Any output between that and the quit or error annotation is the error
32566message.
32567
32568Warning messages are not yet annotated.
32569@c If we want to change that, need to fix warning(), type_error(),
32570@c range_error(), and possibly other places.
32571
922fbb7b
AC
32572@node Invalidation
32573@section Invalidation Notices
32574
32575@cindex annotations for invalidation messages
32576The following annotations say that certain pieces of state may have
32577changed.
32578
32579@table @code
e5ac9b53 32580@findex frames-invalid annotation
922fbb7b
AC
32581@item ^Z^Zframes-invalid
32582
32583The frames (for example, output from the @code{backtrace} command) may
32584have changed.
32585
e5ac9b53 32586@findex breakpoints-invalid annotation
922fbb7b
AC
32587@item ^Z^Zbreakpoints-invalid
32588
32589The breakpoints may have changed. For example, the user just added or
32590deleted a breakpoint.
32591@end table
32592
32593@node Annotations for Running
32594@section Running the Program
32595@cindex annotations for running programs
32596
e5ac9b53
EZ
32597@findex starting annotation
32598@findex stopping annotation
922fbb7b 32599When the program starts executing due to a @value{GDBN} command such as
b383017d 32600@code{step} or @code{continue},
922fbb7b
AC
32601
32602@smallexample
32603^Z^Zstarting
32604@end smallexample
32605
b383017d 32606is output. When the program stops,
922fbb7b
AC
32607
32608@smallexample
32609^Z^Zstopped
32610@end smallexample
32611
32612is output. Before the @code{stopped} annotation, a variety of
32613annotations describe how the program stopped.
32614
32615@table @code
e5ac9b53 32616@findex exited annotation
922fbb7b
AC
32617@item ^Z^Zexited @var{exit-status}
32618The program exited, and @var{exit-status} is the exit status (zero for
32619successful exit, otherwise nonzero).
32620
e5ac9b53
EZ
32621@findex signalled annotation
32622@findex signal-name annotation
32623@findex signal-name-end annotation
32624@findex signal-string annotation
32625@findex signal-string-end annotation
922fbb7b
AC
32626@item ^Z^Zsignalled
32627The program exited with a signal. After the @code{^Z^Zsignalled}, the
32628annotation continues:
32629
32630@smallexample
32631@var{intro-text}
32632^Z^Zsignal-name
32633@var{name}
32634^Z^Zsignal-name-end
32635@var{middle-text}
32636^Z^Zsignal-string
32637@var{string}
32638^Z^Zsignal-string-end
32639@var{end-text}
32640@end smallexample
32641
32642@noindent
32643where @var{name} is the name of the signal, such as @code{SIGILL} or
32644@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
697aa1b7 32645as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
922fbb7b
AC
32646@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
32647user's benefit and have no particular format.
32648
e5ac9b53 32649@findex signal annotation
922fbb7b
AC
32650@item ^Z^Zsignal
32651The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
32652just saying that the program received the signal, not that it was
32653terminated with it.
32654
e5ac9b53 32655@findex breakpoint annotation
922fbb7b
AC
32656@item ^Z^Zbreakpoint @var{number}
32657The program hit breakpoint number @var{number}.
32658
e5ac9b53 32659@findex watchpoint annotation
922fbb7b
AC
32660@item ^Z^Zwatchpoint @var{number}
32661The program hit watchpoint number @var{number}.
32662@end table
32663
32664@node Source Annotations
32665@section Displaying Source
32666@cindex annotations for source display
32667
e5ac9b53 32668@findex source annotation
922fbb7b
AC
32669The following annotation is used instead of displaying source code:
32670
32671@smallexample
32672^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
32673@end smallexample
32674
32675where @var{filename} is an absolute file name indicating which source
32676file, @var{line} is the line number within that file (where 1 is the
32677first line in the file), @var{character} is the character position
32678within the file (where 0 is the first character in the file) (for most
32679debug formats this will necessarily point to the beginning of a line),
32680@var{middle} is @samp{middle} if @var{addr} is in the middle of the
32681line, or @samp{beg} if @var{addr} is at the beginning of the line, and
32682@var{addr} is the address in the target program associated with the
697aa1b7 32683source which is being displayed. The @var{addr} is in the form @samp{0x}
922fbb7b
AC
32684followed by one or more lowercase hex digits (note that this does not
32685depend on the language).
32686
4efc6507
DE
32687@node JIT Interface
32688@chapter JIT Compilation Interface
32689@cindex just-in-time compilation
32690@cindex JIT compilation interface
32691
32692This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
32693interface. A JIT compiler is a program or library that generates native
32694executable code at runtime and executes it, usually in order to achieve good
32695performance while maintaining platform independence.
32696
32697Programs that use JIT compilation are normally difficult to debug because
32698portions of their code are generated at runtime, instead of being loaded from
32699object files, which is where @value{GDBN} normally finds the program's symbols
32700and debug information. In order to debug programs that use JIT compilation,
32701@value{GDBN} has an interface that allows the program to register in-memory
32702symbol files with @value{GDBN} at runtime.
32703
32704If you are using @value{GDBN} to debug a program that uses this interface, then
32705it should work transparently so long as you have not stripped the binary. If
32706you are developing a JIT compiler, then the interface is documented in the rest
32707of this chapter. At this time, the only known client of this interface is the
32708LLVM JIT.
32709
32710Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
32711JIT compiler communicates with @value{GDBN} by writing data into a global
32712variable and calling a fuction at a well-known symbol. When @value{GDBN}
32713attaches, it reads a linked list of symbol files from the global variable to
32714find existing code, and puts a breakpoint in the function so that it can find
32715out about additional code.
32716
32717@menu
32718* Declarations:: Relevant C struct declarations
32719* Registering Code:: Steps to register code
32720* Unregistering Code:: Steps to unregister code
f85b53f8 32721* Custom Debug Info:: Emit debug information in a custom format
4efc6507
DE
32722@end menu
32723
32724@node Declarations
32725@section JIT Declarations
32726
32727These are the relevant struct declarations that a C program should include to
32728implement the interface:
32729
32730@smallexample
32731typedef enum
32732@{
32733 JIT_NOACTION = 0,
32734 JIT_REGISTER_FN,
32735 JIT_UNREGISTER_FN
32736@} jit_actions_t;
32737
32738struct jit_code_entry
32739@{
32740 struct jit_code_entry *next_entry;
32741 struct jit_code_entry *prev_entry;
32742 const char *symfile_addr;
32743 uint64_t symfile_size;
32744@};
32745
32746struct jit_descriptor
32747@{
32748 uint32_t version;
32749 /* This type should be jit_actions_t, but we use uint32_t
32750 to be explicit about the bitwidth. */
32751 uint32_t action_flag;
32752 struct jit_code_entry *relevant_entry;
32753 struct jit_code_entry *first_entry;
32754@};
32755
32756/* GDB puts a breakpoint in this function. */
32757void __attribute__((noinline)) __jit_debug_register_code() @{ @};
32758
32759/* Make sure to specify the version statically, because the
32760 debugger may check the version before we can set it. */
32761struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
32762@end smallexample
32763
32764If the JIT is multi-threaded, then it is important that the JIT synchronize any
32765modifications to this global data properly, which can easily be done by putting
32766a global mutex around modifications to these structures.
32767
32768@node Registering Code
32769@section Registering Code
32770
32771To register code with @value{GDBN}, the JIT should follow this protocol:
32772
32773@itemize @bullet
32774@item
32775Generate an object file in memory with symbols and other desired debug
32776information. The file must include the virtual addresses of the sections.
32777
32778@item
32779Create a code entry for the file, which gives the start and size of the symbol
32780file.
32781
32782@item
32783Add it to the linked list in the JIT descriptor.
32784
32785@item
32786Point the relevant_entry field of the descriptor at the entry.
32787
32788@item
32789Set @code{action_flag} to @code{JIT_REGISTER} and call
32790@code{__jit_debug_register_code}.
32791@end itemize
32792
32793When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
32794@code{relevant_entry} pointer so it doesn't have to walk the list looking for
32795new code. However, the linked list must still be maintained in order to allow
32796@value{GDBN} to attach to a running process and still find the symbol files.
32797
32798@node Unregistering Code
32799@section Unregistering Code
32800
32801If code is freed, then the JIT should use the following protocol:
32802
32803@itemize @bullet
32804@item
32805Remove the code entry corresponding to the code from the linked list.
32806
32807@item
32808Point the @code{relevant_entry} field of the descriptor at the code entry.
32809
32810@item
32811Set @code{action_flag} to @code{JIT_UNREGISTER} and call
32812@code{__jit_debug_register_code}.
32813@end itemize
32814
32815If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
32816and the JIT will leak the memory used for the associated symbol files.
32817
f85b53f8
SD
32818@node Custom Debug Info
32819@section Custom Debug Info
32820@cindex custom JIT debug info
32821@cindex JIT debug info reader
32822
32823Generating debug information in platform-native file formats (like ELF
32824or COFF) may be an overkill for JIT compilers; especially if all the
32825debug info is used for is displaying a meaningful backtrace. The
32826issue can be resolved by having the JIT writers decide on a debug info
32827format and also provide a reader that parses the debug info generated
32828by the JIT compiler. This section gives a brief overview on writing
32829such a parser. More specific details can be found in the source file
32830@file{gdb/jit-reader.in}, which is also installed as a header at
32831@file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
32832
32833The reader is implemented as a shared object (so this functionality is
32834not available on platforms which don't allow loading shared objects at
32835runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
32836@code{jit-reader-unload} are provided, to be used to load and unload
32837the readers from a preconfigured directory. Once loaded, the shared
32838object is used the parse the debug information emitted by the JIT
32839compiler.
32840
32841@menu
32842* Using JIT Debug Info Readers:: How to use supplied readers correctly
32843* Writing JIT Debug Info Readers:: Creating a debug-info reader
32844@end menu
32845
32846@node Using JIT Debug Info Readers
32847@subsection Using JIT Debug Info Readers
32848@kindex jit-reader-load
32849@kindex jit-reader-unload
32850
32851Readers can be loaded and unloaded using the @code{jit-reader-load}
32852and @code{jit-reader-unload} commands.
32853
32854@table @code
c9fb1240 32855@item jit-reader-load @var{reader}
697aa1b7 32856Load the JIT reader named @var{reader}, which is a shared
c9fb1240
SD
32857object specified as either an absolute or a relative file name. In
32858the latter case, @value{GDBN} will try to load the reader from a
32859pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
32860system (here @var{libdir} is the system library directory, often
32861@file{/usr/local/lib}).
32862
32863Only one reader can be active at a time; trying to load a second
32864reader when one is already loaded will result in @value{GDBN}
32865reporting an error. A new JIT reader can be loaded by first unloading
32866the current one using @code{jit-reader-unload} and then invoking
32867@code{jit-reader-load}.
f85b53f8
SD
32868
32869@item jit-reader-unload
32870Unload the currently loaded JIT reader.
32871
32872@end table
32873
32874@node Writing JIT Debug Info Readers
32875@subsection Writing JIT Debug Info Readers
32876@cindex writing JIT debug info readers
32877
32878As mentioned, a reader is essentially a shared object conforming to a
32879certain ABI. This ABI is described in @file{jit-reader.h}.
32880
32881@file{jit-reader.h} defines the structures, macros and functions
32882required to write a reader. It is installed (along with
32883@value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
32884the system include directory.
32885
32886Readers need to be released under a GPL compatible license. A reader
32887can be declared as released under such a license by placing the macro
32888@code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
32889
32890The entry point for readers is the symbol @code{gdb_init_reader},
32891which is expected to be a function with the prototype
32892
32893@findex gdb_init_reader
32894@smallexample
32895extern struct gdb_reader_funcs *gdb_init_reader (void);
32896@end smallexample
32897
32898@cindex @code{struct gdb_reader_funcs}
32899
32900@code{struct gdb_reader_funcs} contains a set of pointers to callback
32901functions. These functions are executed to read the debug info
32902generated by the JIT compiler (@code{read}), to unwind stack frames
32903(@code{unwind}) and to create canonical frame IDs
32904(@code{get_Frame_id}). It also has a callback that is called when the
32905reader is being unloaded (@code{destroy}). The struct looks like this
32906
32907@smallexample
32908struct gdb_reader_funcs
32909@{
32910 /* Must be set to GDB_READER_INTERFACE_VERSION. */
32911 int reader_version;
32912
32913 /* For use by the reader. */
32914 void *priv_data;
32915
32916 gdb_read_debug_info *read;
32917 gdb_unwind_frame *unwind;
32918 gdb_get_frame_id *get_frame_id;
32919 gdb_destroy_reader *destroy;
32920@};
32921@end smallexample
32922
32923@cindex @code{struct gdb_symbol_callbacks}
32924@cindex @code{struct gdb_unwind_callbacks}
32925
32926The callbacks are provided with another set of callbacks by
32927@value{GDBN} to do their job. For @code{read}, these callbacks are
32928passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
32929and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
32930@code{struct gdb_symbol_callbacks} has callbacks to create new object
32931files and new symbol tables inside those object files. @code{struct
32932gdb_unwind_callbacks} has callbacks to read registers off the current
32933frame and to write out the values of the registers in the previous
32934frame. Both have a callback (@code{target_read}) to read bytes off the
32935target's address space.
32936
d1feda86
YQ
32937@node In-Process Agent
32938@chapter In-Process Agent
32939@cindex debugging agent
32940The traditional debugging model is conceptually low-speed, but works fine,
32941because most bugs can be reproduced in debugging-mode execution. However,
32942as multi-core or many-core processors are becoming mainstream, and
32943multi-threaded programs become more and more popular, there should be more
32944and more bugs that only manifest themselves at normal-mode execution, for
32945example, thread races, because debugger's interference with the program's
32946timing may conceal the bugs. On the other hand, in some applications,
32947it is not feasible for the debugger to interrupt the program's execution
32948long enough for the developer to learn anything helpful about its behavior.
32949If the program's correctness depends on its real-time behavior, delays
32950introduced by a debugger might cause the program to fail, even when the
32951code itself is correct. It is useful to be able to observe the program's
32952behavior without interrupting it.
32953
32954Therefore, traditional debugging model is too intrusive to reproduce
32955some bugs. In order to reduce the interference with the program, we can
32956reduce the number of operations performed by debugger. The
32957@dfn{In-Process Agent}, a shared library, is running within the same
32958process with inferior, and is able to perform some debugging operations
32959itself. As a result, debugger is only involved when necessary, and
32960performance of debugging can be improved accordingly. Note that
32961interference with program can be reduced but can't be removed completely,
32962because the in-process agent will still stop or slow down the program.
32963
32964The in-process agent can interpret and execute Agent Expressions
32965(@pxref{Agent Expressions}) during performing debugging operations. The
32966agent expressions can be used for different purposes, such as collecting
32967data in tracepoints, and condition evaluation in breakpoints.
32968
32969@anchor{Control Agent}
32970You can control whether the in-process agent is used as an aid for
32971debugging with the following commands:
32972
32973@table @code
32974@kindex set agent on
32975@item set agent on
32976Causes the in-process agent to perform some operations on behalf of the
32977debugger. Just which operations requested by the user will be done
32978by the in-process agent depends on the its capabilities. For example,
32979if you request to evaluate breakpoint conditions in the in-process agent,
32980and the in-process agent has such capability as well, then breakpoint
32981conditions will be evaluated in the in-process agent.
32982
32983@kindex set agent off
32984@item set agent off
32985Disables execution of debugging operations by the in-process agent. All
32986of the operations will be performed by @value{GDBN}.
32987
32988@kindex show agent
32989@item show agent
32990Display the current setting of execution of debugging operations by
32991the in-process agent.
32992@end table
32993
16bdd41f
YQ
32994@menu
32995* In-Process Agent Protocol::
32996@end menu
32997
32998@node In-Process Agent Protocol
32999@section In-Process Agent Protocol
33000@cindex in-process agent protocol
33001
33002The in-process agent is able to communicate with both @value{GDBN} and
33003GDBserver (@pxref{In-Process Agent}). This section documents the protocol
33004used for communications between @value{GDBN} or GDBserver and the IPA.
33005In general, @value{GDBN} or GDBserver sends commands
33006(@pxref{IPA Protocol Commands}) and data to in-process agent, and then
33007in-process agent replies back with the return result of the command, or
33008some other information. The data sent to in-process agent is composed
33009of primitive data types, such as 4-byte or 8-byte type, and composite
33010types, which are called objects (@pxref{IPA Protocol Objects}).
33011
33012@menu
33013* IPA Protocol Objects::
33014* IPA Protocol Commands::
33015@end menu
33016
33017@node IPA Protocol Objects
33018@subsection IPA Protocol Objects
33019@cindex ipa protocol objects
33020
33021The commands sent to and results received from agent may contain some
33022complex data types called @dfn{objects}.
33023
33024The in-process agent is running on the same machine with @value{GDBN}
33025or GDBserver, so it doesn't have to handle as much differences between
33026two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
33027However, there are still some differences of two ends in two processes:
33028
33029@enumerate
33030@item
33031word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
33032compiled as a 64-bit executable, while in-process agent is a 32-bit one.
33033@item
33034ABI. Some machines may have multiple types of ABI, @value{GDBN} or
33035GDBserver is compiled with one, and in-process agent is compiled with
33036the other one.
33037@end enumerate
33038
33039Here are the IPA Protocol Objects:
33040
33041@enumerate
33042@item
33043agent expression object. It represents an agent expression
33044(@pxref{Agent Expressions}).
33045@anchor{agent expression object}
33046@item
33047tracepoint action object. It represents a tracepoint action
33048(@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
33049memory, static trace data and to evaluate expression.
33050@anchor{tracepoint action object}
33051@item
33052tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
33053@anchor{tracepoint object}
33054
33055@end enumerate
33056
33057The following table describes important attributes of each IPA protocol
33058object:
33059
33060@multitable @columnfractions .30 .20 .50
33061@headitem Name @tab Size @tab Description
33062@item @emph{agent expression object} @tab @tab
33063@item length @tab 4 @tab length of bytes code
33064@item byte code @tab @var{length} @tab contents of byte code
33065@item @emph{tracepoint action for collecting memory} @tab @tab
33066@item 'M' @tab 1 @tab type of tracepoint action
33067@item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
33068address of the lowest byte to collect, otherwise @var{addr} is the offset
33069of @var{basereg} for memory collecting.
33070@item len @tab 8 @tab length of memory for collecting
33071@item basereg @tab 4 @tab the register number containing the starting
33072memory address for collecting.
33073@item @emph{tracepoint action for collecting registers} @tab @tab
33074@item 'R' @tab 1 @tab type of tracepoint action
33075@item @emph{tracepoint action for collecting static trace data} @tab @tab
33076@item 'L' @tab 1 @tab type of tracepoint action
33077@item @emph{tracepoint action for expression evaluation} @tab @tab
33078@item 'X' @tab 1 @tab type of tracepoint action
33079@item agent expression @tab length of @tab @ref{agent expression object}
33080@item @emph{tracepoint object} @tab @tab
33081@item number @tab 4 @tab number of tracepoint
33082@item address @tab 8 @tab address of tracepoint inserted on
33083@item type @tab 4 @tab type of tracepoint
33084@item enabled @tab 1 @tab enable or disable of tracepoint
33085@item step_count @tab 8 @tab step
33086@item pass_count @tab 8 @tab pass
33087@item numactions @tab 4 @tab number of tracepoint actions
33088@item hit count @tab 8 @tab hit count
33089@item trace frame usage @tab 8 @tab trace frame usage
33090@item compiled_cond @tab 8 @tab compiled condition
33091@item orig_size @tab 8 @tab orig size
33092@item condition @tab 4 if condition is NULL otherwise length of
33093@ref{agent expression object}
33094@tab zero if condition is NULL, otherwise is
33095@ref{agent expression object}
33096@item actions @tab variable
33097@tab numactions number of @ref{tracepoint action object}
33098@end multitable
33099
33100@node IPA Protocol Commands
33101@subsection IPA Protocol Commands
33102@cindex ipa protocol commands
33103
33104The spaces in each command are delimiters to ease reading this commands
33105specification. They don't exist in real commands.
33106
33107@table @samp
33108
33109@item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
33110Installs a new fast tracepoint described by @var{tracepoint_object}
697aa1b7 33111(@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
16bdd41f
YQ
33112head of @dfn{jumppad}, which is used to jump to data collection routine
33113in IPA finally.
33114
33115Replies:
33116@table @samp
33117@item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
33118@var{target_address} is address of tracepoint in the inferior.
697aa1b7 33119The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
16bdd41f 33120@var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
697aa1b7
EZ
33121The @var{fjump} contains a sequence of instructions jump to jumppad entry.
33122The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
16bdd41f
YQ
33123@item E @var{NN}
33124for an error
33125
33126@end table
33127
7255706c
YQ
33128@item close
33129Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
33130is about to kill inferiors.
33131
16bdd41f
YQ
33132@item qTfSTM
33133@xref{qTfSTM}.
33134@item qTsSTM
33135@xref{qTsSTM}.
33136@item qTSTMat
33137@xref{qTSTMat}.
33138@item probe_marker_at:@var{address}
33139Asks in-process agent to probe the marker at @var{address}.
33140
33141Replies:
33142@table @samp
33143@item E @var{NN}
33144for an error
33145@end table
33146@item unprobe_marker_at:@var{address}
33147Asks in-process agent to unprobe the marker at @var{address}.
33148@end table
33149
8e04817f
AC
33150@node GDB Bugs
33151@chapter Reporting Bugs in @value{GDBN}
33152@cindex bugs in @value{GDBN}
33153@cindex reporting bugs in @value{GDBN}
c906108c 33154
8e04817f 33155Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 33156
8e04817f
AC
33157Reporting a bug may help you by bringing a solution to your problem, or it
33158may not. But in any case the principal function of a bug report is to help
33159the entire community by making the next version of @value{GDBN} work better. Bug
33160reports are your contribution to the maintenance of @value{GDBN}.
c906108c 33161
8e04817f
AC
33162In order for a bug report to serve its purpose, you must include the
33163information that enables us to fix the bug.
c4555f82
SC
33164
33165@menu
8e04817f
AC
33166* Bug Criteria:: Have you found a bug?
33167* Bug Reporting:: How to report bugs
c4555f82
SC
33168@end menu
33169
8e04817f 33170@node Bug Criteria
79a6e687 33171@section Have You Found a Bug?
8e04817f 33172@cindex bug criteria
c4555f82 33173
8e04817f 33174If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
33175
33176@itemize @bullet
8e04817f
AC
33177@cindex fatal signal
33178@cindex debugger crash
33179@cindex crash of debugger
c4555f82 33180@item
8e04817f
AC
33181If the debugger gets a fatal signal, for any input whatever, that is a
33182@value{GDBN} bug. Reliable debuggers never crash.
33183
33184@cindex error on valid input
33185@item
33186If @value{GDBN} produces an error message for valid input, that is a
33187bug. (Note that if you're cross debugging, the problem may also be
33188somewhere in the connection to the target.)
c4555f82 33189
8e04817f 33190@cindex invalid input
c4555f82 33191@item
8e04817f
AC
33192If @value{GDBN} does not produce an error message for invalid input,
33193that is a bug. However, you should note that your idea of
33194``invalid input'' might be our idea of ``an extension'' or ``support
33195for traditional practice''.
33196
33197@item
33198If you are an experienced user of debugging tools, your suggestions
33199for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
33200@end itemize
33201
8e04817f 33202@node Bug Reporting
79a6e687 33203@section How to Report Bugs
8e04817f
AC
33204@cindex bug reports
33205@cindex @value{GDBN} bugs, reporting
33206
33207A number of companies and individuals offer support for @sc{gnu} products.
33208If you obtained @value{GDBN} from a support organization, we recommend you
33209contact that organization first.
33210
33211You can find contact information for many support companies and
33212individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
33213distribution.
33214@c should add a web page ref...
33215
c16158bc
JM
33216@ifset BUGURL
33217@ifset BUGURL_DEFAULT
129188f6 33218In any event, we also recommend that you submit bug reports for
d3e8051b 33219@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
33220@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
33221page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
33222be used.
8e04817f
AC
33223
33224@strong{Do not send bug reports to @samp{info-gdb}, or to
33225@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
33226not want to receive bug reports. Those that do have arranged to receive
33227@samp{bug-gdb}.
33228
33229The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
33230serves as a repeater. The mailing list and the newsgroup carry exactly
33231the same messages. Often people think of posting bug reports to the
33232newsgroup instead of mailing them. This appears to work, but it has one
33233problem which can be crucial: a newsgroup posting often lacks a mail
33234path back to the sender. Thus, if we need to ask for more information,
33235we may be unable to reach you. For this reason, it is better to send
33236bug reports to the mailing list.
c16158bc
JM
33237@end ifset
33238@ifclear BUGURL_DEFAULT
33239In any event, we also recommend that you submit bug reports for
33240@value{GDBN} to @value{BUGURL}.
33241@end ifclear
33242@end ifset
c4555f82 33243
8e04817f
AC
33244The fundamental principle of reporting bugs usefully is this:
33245@strong{report all the facts}. If you are not sure whether to state a
33246fact or leave it out, state it!
c4555f82 33247
8e04817f
AC
33248Often people omit facts because they think they know what causes the
33249problem and assume that some details do not matter. Thus, you might
33250assume that the name of the variable you use in an example does not matter.
33251Well, probably it does not, but one cannot be sure. Perhaps the bug is a
33252stray memory reference which happens to fetch from the location where that
33253name is stored in memory; perhaps, if the name were different, the contents
33254of that location would fool the debugger into doing the right thing despite
33255the bug. Play it safe and give a specific, complete example. That is the
33256easiest thing for you to do, and the most helpful.
c4555f82 33257
8e04817f
AC
33258Keep in mind that the purpose of a bug report is to enable us to fix the
33259bug. It may be that the bug has been reported previously, but neither
33260you nor we can know that unless your bug report is complete and
33261self-contained.
c4555f82 33262
8e04817f
AC
33263Sometimes people give a few sketchy facts and ask, ``Does this ring a
33264bell?'' Those bug reports are useless, and we urge everyone to
33265@emph{refuse to respond to them} except to chide the sender to report
33266bugs properly.
33267
33268To enable us to fix the bug, you should include all these things:
c4555f82
SC
33269
33270@itemize @bullet
33271@item
8e04817f
AC
33272The version of @value{GDBN}. @value{GDBN} announces it if you start
33273with no arguments; you can also print it at any time using @code{show
33274version}.
c4555f82 33275
8e04817f
AC
33276Without this, we will not know whether there is any point in looking for
33277the bug in the current version of @value{GDBN}.
c4555f82
SC
33278
33279@item
8e04817f
AC
33280The type of machine you are using, and the operating system name and
33281version number.
c4555f82 33282
6eaaf48b
EZ
33283@item
33284The details of the @value{GDBN} build-time configuration.
33285@value{GDBN} shows these details if you invoke it with the
33286@option{--configuration} command-line option, or if you type
33287@code{show configuration} at @value{GDBN}'s prompt.
33288
c4555f82 33289@item
c1468174 33290What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 33291``@value{GCC}--2.8.1''.
c4555f82
SC
33292
33293@item
8e04817f 33294What compiler (and its version) was used to compile the program you are
c1468174 33295debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
33296C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
33297to get this information; for other compilers, see the documentation for
33298those compilers.
c4555f82 33299
8e04817f
AC
33300@item
33301The command arguments you gave the compiler to compile your example and
33302observe the bug. For example, did you use @samp{-O}? To guarantee
33303you will not omit something important, list them all. A copy of the
33304Makefile (or the output from make) is sufficient.
c4555f82 33305
8e04817f
AC
33306If we were to try to guess the arguments, we would probably guess wrong
33307and then we might not encounter the bug.
c4555f82 33308
8e04817f
AC
33309@item
33310A complete input script, and all necessary source files, that will
33311reproduce the bug.
c4555f82 33312
8e04817f
AC
33313@item
33314A description of what behavior you observe that you believe is
33315incorrect. For example, ``It gets a fatal signal.''
c4555f82 33316
8e04817f
AC
33317Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
33318will certainly notice it. But if the bug is incorrect output, we might
33319not notice unless it is glaringly wrong. You might as well not give us
33320a chance to make a mistake.
c4555f82 33321
8e04817f
AC
33322Even if the problem you experience is a fatal signal, you should still
33323say so explicitly. Suppose something strange is going on, such as, your
33324copy of @value{GDBN} is out of synch, or you have encountered a bug in
33325the C library on your system. (This has happened!) Your copy might
33326crash and ours would not. If you told us to expect a crash, then when
33327ours fails to crash, we would know that the bug was not happening for
33328us. If you had not told us to expect a crash, then we would not be able
33329to draw any conclusion from our observations.
c4555f82 33330
e0c07bf0
MC
33331@pindex script
33332@cindex recording a session script
33333To collect all this information, you can use a session recording program
33334such as @command{script}, which is available on many Unix systems.
33335Just run your @value{GDBN} session inside @command{script} and then
33336include the @file{typescript} file with your bug report.
33337
33338Another way to record a @value{GDBN} session is to run @value{GDBN}
33339inside Emacs and then save the entire buffer to a file.
33340
8e04817f
AC
33341@item
33342If you wish to suggest changes to the @value{GDBN} source, send us context
33343diffs. If you even discuss something in the @value{GDBN} source, refer to
33344it by context, not by line number.
c4555f82 33345
8e04817f
AC
33346The line numbers in our development sources will not match those in your
33347sources. Your line numbers would convey no useful information to us.
c4555f82 33348
8e04817f 33349@end itemize
c4555f82 33350
8e04817f 33351Here are some things that are not necessary:
c4555f82 33352
8e04817f
AC
33353@itemize @bullet
33354@item
33355A description of the envelope of the bug.
c4555f82 33356
8e04817f
AC
33357Often people who encounter a bug spend a lot of time investigating
33358which changes to the input file will make the bug go away and which
33359changes will not affect it.
c4555f82 33360
8e04817f
AC
33361This is often time consuming and not very useful, because the way we
33362will find the bug is by running a single example under the debugger
33363with breakpoints, not by pure deduction from a series of examples.
33364We recommend that you save your time for something else.
c4555f82 33365
8e04817f
AC
33366Of course, if you can find a simpler example to report @emph{instead}
33367of the original one, that is a convenience for us. Errors in the
33368output will be easier to spot, running under the debugger will take
33369less time, and so on.
c4555f82 33370
8e04817f
AC
33371However, simplification is not vital; if you do not want to do this,
33372report the bug anyway and send us the entire test case you used.
c4555f82 33373
8e04817f
AC
33374@item
33375A patch for the bug.
c4555f82 33376
8e04817f
AC
33377A patch for the bug does help us if it is a good one. But do not omit
33378the necessary information, such as the test case, on the assumption that
33379a patch is all we need. We might see problems with your patch and decide
33380to fix the problem another way, or we might not understand it at all.
c4555f82 33381
8e04817f
AC
33382Sometimes with a program as complicated as @value{GDBN} it is very hard to
33383construct an example that will make the program follow a certain path
33384through the code. If you do not send us the example, we will not be able
33385to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 33386
8e04817f
AC
33387And if we cannot understand what bug you are trying to fix, or why your
33388patch should be an improvement, we will not install it. A test case will
33389help us to understand.
c4555f82 33390
8e04817f
AC
33391@item
33392A guess about what the bug is or what it depends on.
c4555f82 33393
8e04817f
AC
33394Such guesses are usually wrong. Even we cannot guess right about such
33395things without first using the debugger to find the facts.
33396@end itemize
c4555f82 33397
8e04817f
AC
33398@c The readline documentation is distributed with the readline code
33399@c and consists of the two following files:
cc88a640
JK
33400@c rluser.texi
33401@c hsuser.texi
8e04817f
AC
33402@c Use -I with makeinfo to point to the appropriate directory,
33403@c environment var TEXINPUTS with TeX.
39037522 33404@ifclear SYSTEM_READLINE
5bdf8622 33405@include rluser.texi
cc88a640 33406@include hsuser.texi
39037522 33407@end ifclear
c4555f82 33408
4ceed123
JB
33409@node In Memoriam
33410@appendix In Memoriam
33411
9ed350ad
JB
33412The @value{GDBN} project mourns the loss of the following long-time
33413contributors:
4ceed123
JB
33414
33415@table @code
33416@item Fred Fish
9ed350ad
JB
33417Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
33418to Free Software in general. Outside of @value{GDBN}, he was known in
33419the Amiga world for his series of Fish Disks, and the GeekGadget project.
4ceed123
JB
33420
33421@item Michael Snyder
9ed350ad
JB
33422Michael was one of the Global Maintainers of the @value{GDBN} project,
33423with contributions recorded as early as 1996, until 2011. In addition
33424to his day to day participation, he was a large driving force behind
33425adding Reverse Debugging to @value{GDBN}.
4ceed123
JB
33426@end table
33427
33428Beyond their technical contributions to the project, they were also
33429enjoyable members of the Free Software Community. We will miss them.
c4555f82 33430
8e04817f
AC
33431@node Formatting Documentation
33432@appendix Formatting Documentation
c4555f82 33433
8e04817f
AC
33434@cindex @value{GDBN} reference card
33435@cindex reference card
33436The @value{GDBN} 4 release includes an already-formatted reference card, ready
33437for printing with PostScript or Ghostscript, in the @file{gdb}
33438subdirectory of the main source directory@footnote{In
33439@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
33440release.}. If you can use PostScript or Ghostscript with your printer,
33441you can print the reference card immediately with @file{refcard.ps}.
c4555f82 33442
8e04817f
AC
33443The release also includes the source for the reference card. You
33444can format it, using @TeX{}, by typing:
c4555f82 33445
474c8240 33446@smallexample
8e04817f 33447make refcard.dvi
474c8240 33448@end smallexample
c4555f82 33449
8e04817f
AC
33450The @value{GDBN} reference card is designed to print in @dfn{landscape}
33451mode on US ``letter'' size paper;
33452that is, on a sheet 11 inches wide by 8.5 inches
33453high. You will need to specify this form of printing as an option to
33454your @sc{dvi} output program.
c4555f82 33455
8e04817f 33456@cindex documentation
c4555f82 33457
8e04817f
AC
33458All the documentation for @value{GDBN} comes as part of the machine-readable
33459distribution. The documentation is written in Texinfo format, which is
33460a documentation system that uses a single source file to produce both
33461on-line information and a printed manual. You can use one of the Info
33462formatting commands to create the on-line version of the documentation
33463and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 33464
8e04817f
AC
33465@value{GDBN} includes an already formatted copy of the on-line Info
33466version of this manual in the @file{gdb} subdirectory. The main Info
33467file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
33468subordinate files matching @samp{gdb.info*} in the same directory. If
33469necessary, you can print out these files, or read them with any editor;
33470but they are easier to read using the @code{info} subsystem in @sc{gnu}
33471Emacs or the standalone @code{info} program, available as part of the
33472@sc{gnu} Texinfo distribution.
c4555f82 33473
8e04817f
AC
33474If you want to format these Info files yourself, you need one of the
33475Info formatting programs, such as @code{texinfo-format-buffer} or
33476@code{makeinfo}.
c4555f82 33477
8e04817f
AC
33478If you have @code{makeinfo} installed, and are in the top level
33479@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
33480version @value{GDBVN}), you can make the Info file by typing:
c4555f82 33481
474c8240 33482@smallexample
8e04817f
AC
33483cd gdb
33484make gdb.info
474c8240 33485@end smallexample
c4555f82 33486
8e04817f
AC
33487If you want to typeset and print copies of this manual, you need @TeX{},
33488a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
33489Texinfo definitions file.
c4555f82 33490
8e04817f
AC
33491@TeX{} is a typesetting program; it does not print files directly, but
33492produces output files called @sc{dvi} files. To print a typeset
33493document, you need a program to print @sc{dvi} files. If your system
33494has @TeX{} installed, chances are it has such a program. The precise
33495command to use depends on your system; @kbd{lpr -d} is common; another
33496(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
33497require a file name without any extension or a @samp{.dvi} extension.
c4555f82 33498
8e04817f
AC
33499@TeX{} also requires a macro definitions file called
33500@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
33501written in Texinfo format. On its own, @TeX{} cannot either read or
33502typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
33503and is located in the @file{gdb-@var{version-number}/texinfo}
33504directory.
c4555f82 33505
8e04817f 33506If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 33507typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
33508subdirectory of the main source directory (for example, to
33509@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 33510
474c8240 33511@smallexample
8e04817f 33512make gdb.dvi
474c8240 33513@end smallexample
c4555f82 33514
8e04817f 33515Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 33516
8e04817f
AC
33517@node Installing GDB
33518@appendix Installing @value{GDBN}
8e04817f 33519@cindex installation
c4555f82 33520
7fa2210b
DJ
33521@menu
33522* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 33523* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
33524* Separate Objdir:: Compiling @value{GDBN} in another directory
33525* Config Names:: Specifying names for hosts and targets
33526* Configure Options:: Summary of options for configure
098b41a6 33527* System-wide configuration:: Having a system-wide init file
7fa2210b
DJ
33528@end menu
33529
33530@node Requirements
79a6e687 33531@section Requirements for Building @value{GDBN}
7fa2210b
DJ
33532@cindex building @value{GDBN}, requirements for
33533
33534Building @value{GDBN} requires various tools and packages to be available.
33535Other packages will be used only if they are found.
33536
79a6e687 33537@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b
DJ
33538@table @asis
33539@item ISO C90 compiler
33540@value{GDBN} is written in ISO C90. It should be buildable with any
33541working C90 compiler, e.g.@: GCC.
33542
33543@end table
33544
79a6e687 33545@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
33546@table @asis
33547@item Expat
123dc839 33548@anchor{Expat}
7fa2210b
DJ
33549@value{GDBN} can use the Expat XML parsing library. This library may be
33550included with your operating system distribution; if it is not, you
33551can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 33552The @file{configure} script will search for this library in several
7fa2210b
DJ
33553standard locations; if it is installed in an unusual path, you can
33554use the @option{--with-libexpat-prefix} option to specify its location.
33555
9cceb671
DJ
33556Expat is used for:
33557
33558@itemize @bullet
33559@item
33560Remote protocol memory maps (@pxref{Memory Map Format})
33561@item
33562Target descriptions (@pxref{Target Descriptions})
33563@item
2268b414
JK
33564Remote shared library lists (@xref{Library List Format},
33565or alternatively @pxref{Library List Format for SVR4 Targets})
9cceb671
DJ
33566@item
33567MS-Windows shared libraries (@pxref{Shared Libraries})
b3b9301e
PA
33568@item
33569Traceframe info (@pxref{Traceframe Info Format})
2ae8c8e7 33570@item
f4abbc16
MM
33571Branch trace (@pxref{Branch Trace Format},
33572@pxref{Branch Trace Configuration Format})
9cceb671 33573@end itemize
7fa2210b 33574
31fffb02
CS
33575@item zlib
33576@cindex compressed debug sections
33577@value{GDBN} will use the @samp{zlib} library, if available, to read
33578compressed debug sections. Some linkers, such as GNU gold, are capable
33579of producing binaries with compressed debug sections. If @value{GDBN}
33580is compiled with @samp{zlib}, it will be able to read the debug
33581information in such binaries.
33582
33583The @samp{zlib} library is likely included with your operating system
33584distribution; if it is not, you can get the latest version from
33585@url{http://zlib.net}.
33586
6c7a06a3
TT
33587@item iconv
33588@value{GDBN}'s features related to character sets (@pxref{Character
33589Sets}) require a functioning @code{iconv} implementation. If you are
33590on a GNU system, then this is provided by the GNU C Library. Some
33591other systems also provide a working @code{iconv}.
33592
478aac75
DE
33593If @value{GDBN} is using the @code{iconv} program which is installed
33594in a non-standard place, you will need to tell @value{GDBN} where to find it.
33595This is done with @option{--with-iconv-bin} which specifies the
33596directory that contains the @code{iconv} program.
33597
33598On systems without @code{iconv}, you can install GNU Libiconv. If you
6c7a06a3
TT
33599have previously installed Libiconv, you can use the
33600@option{--with-libiconv-prefix} option to configure.
33601
33602@value{GDBN}'s top-level @file{configure} and @file{Makefile} will
33603arrange to build Libiconv if a directory named @file{libiconv} appears
33604in the top-most source directory. If Libiconv is built this way, and
33605if the operating system does not provide a suitable @code{iconv}
33606implementation, then the just-built library will automatically be used
33607by @value{GDBN}. One easy way to set this up is to download GNU
33608Libiconv, unpack it, and then rename the directory holding the
33609Libiconv source code to @samp{libiconv}.
7fa2210b
DJ
33610@end table
33611
33612@node Running Configure
db2e3e2e 33613@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 33614@cindex configuring @value{GDBN}
db2e3e2e 33615@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
33616of preparing @value{GDBN} for installation; you can then use @code{make} to
33617build the @code{gdb} program.
33618@iftex
33619@c irrelevant in info file; it's as current as the code it lives with.
33620@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
33621look at the @file{README} file in the sources; we may have improved the
33622installation procedures since publishing this manual.}
33623@end iftex
c4555f82 33624
8e04817f
AC
33625The @value{GDBN} distribution includes all the source code you need for
33626@value{GDBN} in a single directory, whose name is usually composed by
33627appending the version number to @samp{gdb}.
c4555f82 33628
8e04817f
AC
33629For example, the @value{GDBN} version @value{GDBVN} distribution is in the
33630@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 33631
8e04817f
AC
33632@table @code
33633@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
33634script for configuring @value{GDBN} and all its supporting libraries
c4555f82 33635
8e04817f
AC
33636@item gdb-@value{GDBVN}/gdb
33637the source specific to @value{GDBN} itself
c4555f82 33638
8e04817f
AC
33639@item gdb-@value{GDBVN}/bfd
33640source for the Binary File Descriptor library
c906108c 33641
8e04817f
AC
33642@item gdb-@value{GDBVN}/include
33643@sc{gnu} include files
c906108c 33644
8e04817f
AC
33645@item gdb-@value{GDBVN}/libiberty
33646source for the @samp{-liberty} free software library
c906108c 33647
8e04817f
AC
33648@item gdb-@value{GDBVN}/opcodes
33649source for the library of opcode tables and disassemblers
c906108c 33650
8e04817f
AC
33651@item gdb-@value{GDBVN}/readline
33652source for the @sc{gnu} command-line interface
c906108c 33653
8e04817f
AC
33654@item gdb-@value{GDBVN}/glob
33655source for the @sc{gnu} filename pattern-matching subroutine
c906108c 33656
8e04817f
AC
33657@item gdb-@value{GDBVN}/mmalloc
33658source for the @sc{gnu} memory-mapped malloc package
33659@end table
c906108c 33660
db2e3e2e 33661The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
33662from the @file{gdb-@var{version-number}} source directory, which in
33663this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 33664
8e04817f 33665First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 33666if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
33667identifier for the platform on which @value{GDBN} will run as an
33668argument.
c906108c 33669
8e04817f 33670For example:
c906108c 33671
474c8240 33672@smallexample
8e04817f
AC
33673cd gdb-@value{GDBVN}
33674./configure @var{host}
33675make
474c8240 33676@end smallexample
c906108c 33677
8e04817f
AC
33678@noindent
33679where @var{host} is an identifier such as @samp{sun4} or
33680@samp{decstation}, that identifies the platform where @value{GDBN} will run.
db2e3e2e 33681(You can often leave off @var{host}; @file{configure} tries to guess the
8e04817f 33682correct value by examining your system.)
c906108c 33683
8e04817f
AC
33684Running @samp{configure @var{host}} and then running @code{make} builds the
33685@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
33686libraries, then @code{gdb} itself. The configured source files, and the
33687binaries, are left in the corresponding source directories.
c906108c 33688
8e04817f 33689@need 750
db2e3e2e 33690@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
33691system does not recognize this automatically when you run a different
33692shell, you may need to run @code{sh} on it explicitly:
c906108c 33693
474c8240 33694@smallexample
8e04817f 33695sh configure @var{host}
474c8240 33696@end smallexample
c906108c 33697
db2e3e2e 33698If you run @file{configure} from a directory that contains source
8e04817f 33699directories for multiple libraries or programs, such as the
db2e3e2e
BW
33700@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
33701@file{configure}
8e04817f
AC
33702creates configuration files for every directory level underneath (unless
33703you tell it not to, with the @samp{--norecursion} option).
33704
db2e3e2e 33705You should run the @file{configure} script from the top directory in the
94e91d6d 33706source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 33707@file{configure} from one of the subdirectories, you will configure only
94e91d6d 33708that subdirectory. That is usually not what you want. In particular,
db2e3e2e 33709if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
33710of the @file{gdb-@var{version-number}} directory, you will omit the
33711configuration of @file{bfd}, @file{readline}, and other sibling
33712directories of the @file{gdb} subdirectory. This leads to build errors
33713about missing include files such as @file{bfd/bfd.h}.
c906108c 33714
8e04817f
AC
33715You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
33716However, you should make sure that the shell on your path (named by
33717the @samp{SHELL} environment variable) is publicly readable. Remember
33718that @value{GDBN} uses the shell to start your program---some systems refuse to
33719let @value{GDBN} debug child processes whose programs are not readable.
c906108c 33720
8e04817f 33721@node Separate Objdir
79a6e687 33722@section Compiling @value{GDBN} in Another Directory
c906108c 33723
8e04817f
AC
33724If you want to run @value{GDBN} versions for several host or target machines,
33725you need a different @code{gdb} compiled for each combination of
db2e3e2e 33726host and target. @file{configure} is designed to make this easy by
8e04817f
AC
33727allowing you to generate each configuration in a separate subdirectory,
33728rather than in the source directory. If your @code{make} program
33729handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
33730@code{make} in each of these directories builds the @code{gdb}
33731program specified there.
c906108c 33732
db2e3e2e 33733To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 33734with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
33735(You also need to specify a path to find @file{configure}
33736itself from your working directory. If the path to @file{configure}
8e04817f
AC
33737would be the same as the argument to @samp{--srcdir}, you can leave out
33738the @samp{--srcdir} option; it is assumed.)
c906108c 33739
8e04817f
AC
33740For example, with version @value{GDBVN}, you can build @value{GDBN} in a
33741separate directory for a Sun 4 like this:
c906108c 33742
474c8240 33743@smallexample
8e04817f
AC
33744@group
33745cd gdb-@value{GDBVN}
33746mkdir ../gdb-sun4
33747cd ../gdb-sun4
33748../gdb-@value{GDBVN}/configure sun4
33749make
33750@end group
474c8240 33751@end smallexample
c906108c 33752
db2e3e2e 33753When @file{configure} builds a configuration using a remote source
8e04817f
AC
33754directory, it creates a tree for the binaries with the same structure
33755(and using the same names) as the tree under the source directory. In
33756the example, you'd find the Sun 4 library @file{libiberty.a} in the
33757directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
33758@file{gdb-sun4/gdb}.
c906108c 33759
94e91d6d
MC
33760Make sure that your path to the @file{configure} script has just one
33761instance of @file{gdb} in it. If your path to @file{configure} looks
33762like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
33763one subdirectory of @value{GDBN}, not the whole package. This leads to
33764build errors about missing include files such as @file{bfd/bfd.h}.
33765
8e04817f
AC
33766One popular reason to build several @value{GDBN} configurations in separate
33767directories is to configure @value{GDBN} for cross-compiling (where
33768@value{GDBN} runs on one machine---the @dfn{host}---while debugging
33769programs that run on another machine---the @dfn{target}).
33770You specify a cross-debugging target by
db2e3e2e 33771giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 33772
8e04817f
AC
33773When you run @code{make} to build a program or library, you must run
33774it in a configured directory---whatever directory you were in when you
db2e3e2e 33775called @file{configure} (or one of its subdirectories).
c906108c 33776
db2e3e2e 33777The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
33778directory also runs recursively. If you type @code{make} in a source
33779directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
33780directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
33781will build all the required libraries, and then build GDB.
c906108c 33782
8e04817f
AC
33783When you have multiple hosts or targets configured in separate
33784directories, you can run @code{make} on them in parallel (for example,
33785if they are NFS-mounted on each of the hosts); they will not interfere
33786with each other.
c906108c 33787
8e04817f 33788@node Config Names
79a6e687 33789@section Specifying Names for Hosts and Targets
c906108c 33790
db2e3e2e 33791The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
33792script are based on a three-part naming scheme, but some short predefined
33793aliases are also supported. The full naming scheme encodes three pieces
33794of information in the following pattern:
c906108c 33795
474c8240 33796@smallexample
8e04817f 33797@var{architecture}-@var{vendor}-@var{os}
474c8240 33798@end smallexample
c906108c 33799
8e04817f
AC
33800For example, you can use the alias @code{sun4} as a @var{host} argument,
33801or as the value for @var{target} in a @code{--target=@var{target}}
33802option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 33803
db2e3e2e 33804The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 33805any query facility to list all supported host and target names or
db2e3e2e 33806aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
33807@code{config.sub} to map abbreviations to full names; you can read the
33808script, if you wish, or you can use it to test your guesses on
33809abbreviations---for example:
c906108c 33810
8e04817f
AC
33811@smallexample
33812% sh config.sub i386-linux
33813i386-pc-linux-gnu
33814% sh config.sub alpha-linux
33815alpha-unknown-linux-gnu
33816% sh config.sub hp9k700
33817hppa1.1-hp-hpux
33818% sh config.sub sun4
33819sparc-sun-sunos4.1.1
33820% sh config.sub sun3
33821m68k-sun-sunos4.1.1
33822% sh config.sub i986v
33823Invalid configuration `i986v': machine `i986v' not recognized
33824@end smallexample
c906108c 33825
8e04817f
AC
33826@noindent
33827@code{config.sub} is also distributed in the @value{GDBN} source
33828directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 33829
8e04817f 33830@node Configure Options
db2e3e2e 33831@section @file{configure} Options
c906108c 33832
db2e3e2e
BW
33833Here is a summary of the @file{configure} options and arguments that
33834are most often useful for building @value{GDBN}. @file{configure} also has
8e04817f 33835several other options not listed here. @inforef{What Configure
db2e3e2e 33836Does,,configure.info}, for a full explanation of @file{configure}.
c906108c 33837
474c8240 33838@smallexample
8e04817f
AC
33839configure @r{[}--help@r{]}
33840 @r{[}--prefix=@var{dir}@r{]}
33841 @r{[}--exec-prefix=@var{dir}@r{]}
33842 @r{[}--srcdir=@var{dirname}@r{]}
33843 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
33844 @r{[}--target=@var{target}@r{]}
33845 @var{host}
474c8240 33846@end smallexample
c906108c 33847
8e04817f
AC
33848@noindent
33849You may introduce options with a single @samp{-} rather than
33850@samp{--} if you prefer; but you may abbreviate option names if you use
33851@samp{--}.
c906108c 33852
8e04817f
AC
33853@table @code
33854@item --help
db2e3e2e 33855Display a quick summary of how to invoke @file{configure}.
c906108c 33856
8e04817f
AC
33857@item --prefix=@var{dir}
33858Configure the source to install programs and files under directory
33859@file{@var{dir}}.
c906108c 33860
8e04817f
AC
33861@item --exec-prefix=@var{dir}
33862Configure the source to install programs under directory
33863@file{@var{dir}}.
c906108c 33864
8e04817f
AC
33865@c avoid splitting the warning from the explanation:
33866@need 2000
33867@item --srcdir=@var{dirname}
33868@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
33869@code{make} that implements the @code{VPATH} feature.}@*
33870Use this option to make configurations in directories separate from the
33871@value{GDBN} source directories. Among other things, you can use this to
33872build (or maintain) several configurations simultaneously, in separate
db2e3e2e 33873directories. @file{configure} writes configuration-specific files in
8e04817f 33874the current directory, but arranges for them to use the source in the
db2e3e2e 33875directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
33876the working directory in parallel to the source directories below
33877@var{dirname}.
c906108c 33878
8e04817f 33879@item --norecursion
db2e3e2e 33880Configure only the directory level where @file{configure} is executed; do not
8e04817f 33881propagate configuration to subdirectories.
c906108c 33882
8e04817f
AC
33883@item --target=@var{target}
33884Configure @value{GDBN} for cross-debugging programs running on the specified
33885@var{target}. Without this option, @value{GDBN} is configured to debug
33886programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 33887
8e04817f 33888There is no convenient way to generate a list of all available targets.
c906108c 33889
8e04817f
AC
33890@item @var{host} @dots{}
33891Configure @value{GDBN} to run on the specified @var{host}.
c906108c 33892
8e04817f
AC
33893There is no convenient way to generate a list of all available hosts.
33894@end table
c906108c 33895
8e04817f
AC
33896There are many other options available as well, but they are generally
33897needed for special purposes only.
c906108c 33898
098b41a6
JG
33899@node System-wide configuration
33900@section System-wide configuration and settings
33901@cindex system-wide init file
33902
33903@value{GDBN} can be configured to have a system-wide init file;
33904this file will be read and executed at startup (@pxref{Startup, , What
33905@value{GDBN} does during startup}).
33906
33907Here is the corresponding configure option:
33908
33909@table @code
33910@item --with-system-gdbinit=@var{file}
33911Specify that the default location of the system-wide init file is
33912@var{file}.
33913@end table
33914
33915If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
33916it may be subject to relocation. Two possible cases:
33917
33918@itemize @bullet
33919@item
33920If the default location of this init file contains @file{$prefix},
33921it will be subject to relocation. Suppose that the configure options
33922are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
33923if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
33924init file is looked for as @file{$install/etc/gdbinit} instead of
33925@file{$prefix/etc/gdbinit}.
33926
33927@item
33928By contrast, if the default location does not contain the prefix,
33929it will not be relocated. E.g.@: if @value{GDBN} has been configured with
33930@option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
33931then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
33932wherever @value{GDBN} is installed.
33933@end itemize
33934
e64e0392
DE
33935If the configured location of the system-wide init file (as given by the
33936@option{--with-system-gdbinit} option at configure time) is in the
33937data-directory (as specified by @option{--with-gdb-datadir} at configure
33938time) or in one of its subdirectories, then @value{GDBN} will look for the
33939system-wide init file in the directory specified by the
33940@option{--data-directory} command-line option.
33941Note that the system-wide init file is only read once, during @value{GDBN}
33942initialization. If the data-directory is changed after @value{GDBN} has
33943started with the @code{set data-directory} command, the file will not be
33944reread.
33945
5901af59
JB
33946@menu
33947* System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
33948@end menu
33949
33950@node System-wide Configuration Scripts
0201faac
JB
33951@subsection Installed System-wide Configuration Scripts
33952@cindex system-wide configuration scripts
33953
33954The @file{system-gdbinit} directory, located inside the data-directory
33955(as specified by @option{--with-gdb-datadir} at configure time) contains
33956a number of scripts which can be used as system-wide init files. To
33957automatically source those scripts at startup, @value{GDBN} should be
33958configured with @option{--with-system-gdbinit}. Otherwise, any user
33959should be able to source them by hand as needed.
33960
33961The following scripts are currently available:
33962@itemize @bullet
33963
33964@item @file{elinos.py}
33965@pindex elinos.py
33966@cindex ELinOS system-wide configuration script
33967This script is useful when debugging a program on an ELinOS target.
33968It takes advantage of the environment variables defined in a standard
33969ELinOS environment in order to determine the location of the system
33970shared libraries, and then sets the @samp{solib-absolute-prefix}
33971and @samp{solib-search-path} variables appropriately.
33972
33973@item @file{wrs-linux.py}
33974@pindex wrs-linux.py
33975@cindex Wind River Linux system-wide configuration script
33976This script is useful when debugging a program on a target running
33977Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
33978the host-side sysroot used by the target system.
33979
33980@end itemize
33981
8e04817f
AC
33982@node Maintenance Commands
33983@appendix Maintenance Commands
33984@cindex maintenance commands
33985@cindex internal commands
c906108c 33986
8e04817f 33987In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
33988includes a number of commands intended for @value{GDBN} developers,
33989that are not documented elsewhere in this manual. These commands are
da316a69
EZ
33990provided here for reference. (For commands that turn on debugging
33991messages, see @ref{Debugging Output}.)
c906108c 33992
8e04817f 33993@table @code
09d4efe1 33994@kindex maint agent
782b2b07 33995@kindex maint agent-eval
f77cc5f0
HZ
33996@item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
33997@itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
09d4efe1
EZ
33998Translate the given @var{expression} into remote agent bytecodes.
33999This command is useful for debugging the Agent Expression mechanism
782b2b07
SS
34000(@pxref{Agent Expressions}). The @samp{agent} version produces an
34001expression useful for data collection, such as by tracepoints, while
34002@samp{maint agent-eval} produces an expression that evaluates directly
34003to a result. For instance, a collection expression for @code{globa +
34004globb} will include bytecodes to record four bytes of memory at each
34005of the addresses of @code{globa} and @code{globb}, while discarding
34006the result of the addition, while an evaluation expression will do the
34007addition and return the sum.
f77cc5f0
HZ
34008If @code{-at} is given, generate remote agent bytecode for @var{location}.
34009If not, generate remote agent bytecode for current frame PC address.
09d4efe1 34010
d3ce09f5
SS
34011@kindex maint agent-printf
34012@item maint agent-printf @var{format},@var{expr},...
34013Translate the given format string and list of argument expressions
34014into remote agent bytecodes and display them as a disassembled list.
34015This command is useful for debugging the agent version of dynamic
6dd24dfa 34016printf (@pxref{Dynamic Printf}).
d3ce09f5 34017
8e04817f
AC
34018@kindex maint info breakpoints
34019@item @anchor{maint info breakpoints}maint info breakpoints
34020Using the same format as @samp{info breakpoints}, display both the
34021breakpoints you've set explicitly, and those @value{GDBN} is using for
34022internal purposes. Internal breakpoints are shown with negative
34023breakpoint numbers. The type column identifies what kind of breakpoint
34024is shown:
c906108c 34025
8e04817f
AC
34026@table @code
34027@item breakpoint
34028Normal, explicitly set breakpoint.
c906108c 34029
8e04817f
AC
34030@item watchpoint
34031Normal, explicitly set watchpoint.
c906108c 34032
8e04817f
AC
34033@item longjmp
34034Internal breakpoint, used to handle correctly stepping through
34035@code{longjmp} calls.
c906108c 34036
8e04817f
AC
34037@item longjmp resume
34038Internal breakpoint at the target of a @code{longjmp}.
c906108c 34039
8e04817f
AC
34040@item until
34041Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 34042
8e04817f
AC
34043@item finish
34044Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 34045
8e04817f
AC
34046@item shlib events
34047Shared library events.
c906108c 34048
8e04817f 34049@end table
c906108c 34050
b0627500
MM
34051@kindex maint info btrace
34052@item maint info btrace
34053Pint information about raw branch tracing data.
34054
34055@kindex maint btrace packet-history
34056@item maint btrace packet-history
34057Print the raw branch trace packets that are used to compute the
34058execution history for the @samp{record btrace} command. Both the
34059information and the format in which it is printed depend on the btrace
34060recording format.
34061
34062@table @code
34063@item bts
34064For the BTS recording format, print a list of blocks of sequential
34065code. For each block, the following information is printed:
34066
34067@table @asis
34068@item Block number
34069Newer blocks have higher numbers. The oldest block has number zero.
34070@item Lowest @samp{PC}
34071@item Highest @samp{PC}
34072@end table
34073
34074@item pt
bc504a31
PA
34075For the Intel Processor Trace recording format, print a list of
34076Intel Processor Trace packets. For each packet, the following
b0627500
MM
34077information is printed:
34078
34079@table @asis
34080@item Packet number
34081Newer packets have higher numbers. The oldest packet has number zero.
34082@item Trace offset
34083The packet's offset in the trace stream.
34084@item Packet opcode and payload
34085@end table
34086@end table
34087
34088@kindex maint btrace clear-packet-history
34089@item maint btrace clear-packet-history
34090Discards the cached packet history printed by the @samp{maint btrace
34091packet-history} command. The history will be computed again when
34092needed.
34093
34094@kindex maint btrace clear
34095@item maint btrace clear
34096Discard the branch trace data. The data will be fetched anew and the
34097branch trace will be recomputed when needed.
34098
34099This implicitly truncates the branch trace to a single branch trace
34100buffer. When updating branch trace incrementally, the branch trace
34101available to @value{GDBN} may be bigger than a single branch trace
34102buffer.
34103
34104@kindex maint set btrace pt skip-pad
34105@item maint set btrace pt skip-pad
34106@kindex maint show btrace pt skip-pad
34107@item maint show btrace pt skip-pad
34108Control whether @value{GDBN} will skip PAD packets when computing the
34109packet history.
34110
fff08868
HZ
34111@kindex set displaced-stepping
34112@kindex show displaced-stepping
237fc4c9
PA
34113@cindex displaced stepping support
34114@cindex out-of-line single-stepping
fff08868
HZ
34115@item set displaced-stepping
34116@itemx show displaced-stepping
237fc4c9 34117Control whether or not @value{GDBN} will do @dfn{displaced stepping}
fff08868
HZ
34118if the target supports it. Displaced stepping is a way to single-step
34119over breakpoints without removing them from the inferior, by executing
34120an out-of-line copy of the instruction that was originally at the
34121breakpoint location. It is also known as out-of-line single-stepping.
34122
34123@table @code
34124@item set displaced-stepping on
34125If the target architecture supports it, @value{GDBN} will use
34126displaced stepping to step over breakpoints.
34127
34128@item set displaced-stepping off
34129@value{GDBN} will not use displaced stepping to step over breakpoints,
34130even if such is supported by the target architecture.
34131
34132@cindex non-stop mode, and @samp{set displaced-stepping}
34133@item set displaced-stepping auto
34134This is the default mode. @value{GDBN} will use displaced stepping
34135only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
34136architecture supports displaced stepping.
34137@end table
237fc4c9 34138
7d0c9981
DE
34139@kindex maint check-psymtabs
34140@item maint check-psymtabs
34141Check the consistency of currently expanded psymtabs versus symtabs.
34142Use this to check, for example, whether a symbol is in one but not the other.
34143
09d4efe1
EZ
34144@kindex maint check-symtabs
34145@item maint check-symtabs
7d0c9981
DE
34146Check the consistency of currently expanded symtabs.
34147
34148@kindex maint expand-symtabs
34149@item maint expand-symtabs [@var{regexp}]
34150Expand symbol tables.
34151If @var{regexp} is specified, only expand symbol tables for file
34152names matching @var{regexp}.
09d4efe1 34153
992c7d70
GB
34154@kindex maint set catch-demangler-crashes
34155@kindex maint show catch-demangler-crashes
34156@cindex demangler crashes
34157@item maint set catch-demangler-crashes [on|off]
34158@itemx maint show catch-demangler-crashes
34159Control whether @value{GDBN} should attempt to catch crashes in the
34160symbol name demangler. The default is to attempt to catch crashes.
34161If enabled, the first time a crash is caught, a core file is created,
34162the offending symbol is displayed and the user is presented with the
34163option to terminate the current session.
34164
09d4efe1
EZ
34165@kindex maint cplus first_component
34166@item maint cplus first_component @var{name}
34167Print the first C@t{++} class/namespace component of @var{name}.
34168
34169@kindex maint cplus namespace
34170@item maint cplus namespace
34171Print the list of possible C@t{++} namespaces.
34172
09d4efe1
EZ
34173@kindex maint deprecate
34174@kindex maint undeprecate
34175@cindex deprecated commands
34176@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
34177@itemx maint undeprecate @var{command}
34178Deprecate or undeprecate the named @var{command}. Deprecated commands
34179cause @value{GDBN} to issue a warning when you use them. The optional
34180argument @var{replacement} says which newer command should be used in
34181favor of the deprecated one; if it is given, @value{GDBN} will mention
34182the replacement as part of the warning.
34183
34184@kindex maint dump-me
34185@item maint dump-me
721c2651 34186@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 34187Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
34188This is supported only on systems which support aborting a program
34189with the @code{SIGQUIT} signal.
09d4efe1 34190
8d30a00d
AC
34191@kindex maint internal-error
34192@kindex maint internal-warning
57fcfb1b
GB
34193@kindex maint demangler-warning
34194@cindex demangler crashes
09d4efe1
EZ
34195@item maint internal-error @r{[}@var{message-text}@r{]}
34196@itemx maint internal-warning @r{[}@var{message-text}@r{]}
57fcfb1b
GB
34197@itemx maint demangler-warning @r{[}@var{message-text}@r{]}
34198
34199Cause @value{GDBN} to call the internal function @code{internal_error},
34200@code{internal_warning} or @code{demangler_warning} and hence behave
7ee67ee4 34201as though an internal problem has been detected. In addition to
57fcfb1b
GB
34202reporting the internal problem, these functions give the user the
34203opportunity to either quit @value{GDBN} or (for @code{internal_error}
34204and @code{internal_warning}) create a core file of the current
8d30a00d
AC
34205@value{GDBN} session.
34206
09d4efe1
EZ
34207These commands take an optional parameter @var{message-text} that is
34208used as the text of the error or warning message.
34209
d3e8051b 34210Here's an example of using @code{internal-error}:
09d4efe1 34211
8d30a00d 34212@smallexample
f7dc1244 34213(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
34214@dots{}/maint.c:121: internal-error: testing, 1, 2
34215A problem internal to GDB has been detected. Further
34216debugging may prove unreliable.
34217Quit this debugging session? (y or n) @kbd{n}
34218Create a core file? (y or n) @kbd{n}
f7dc1244 34219(@value{GDBP})
8d30a00d
AC
34220@end smallexample
34221
3c16cced
PA
34222@cindex @value{GDBN} internal error
34223@cindex internal errors, control of @value{GDBN} behavior
57fcfb1b 34224@cindex demangler crashes
3c16cced
PA
34225
34226@kindex maint set internal-error
34227@kindex maint show internal-error
34228@kindex maint set internal-warning
34229@kindex maint show internal-warning
57fcfb1b
GB
34230@kindex maint set demangler-warning
34231@kindex maint show demangler-warning
3c16cced
PA
34232@item maint set internal-error @var{action} [ask|yes|no]
34233@itemx maint show internal-error @var{action}
34234@itemx maint set internal-warning @var{action} [ask|yes|no]
34235@itemx maint show internal-warning @var{action}
57fcfb1b
GB
34236@itemx maint set demangler-warning @var{action} [ask|yes|no]
34237@itemx maint show demangler-warning @var{action}
3c16cced
PA
34238When @value{GDBN} reports an internal problem (error or warning) it
34239gives the user the opportunity to both quit @value{GDBN} and create a
34240core file of the current @value{GDBN} session. These commands let you
34241override the default behaviour for each particular @var{action},
34242described in the table below.
34243
34244@table @samp
34245@item quit
34246You can specify that @value{GDBN} should always (yes) or never (no)
34247quit. The default is to ask the user what to do.
34248
34249@item corefile
34250You can specify that @value{GDBN} should always (yes) or never (no)
57fcfb1b
GB
34251create a core file. The default is to ask the user what to do. Note
34252that there is no @code{corefile} option for @code{demangler-warning}:
34253demangler warnings always create a core file and this cannot be
34254disabled.
3c16cced
PA
34255@end table
34256
09d4efe1
EZ
34257@kindex maint packet
34258@item maint packet @var{text}
34259If @value{GDBN} is talking to an inferior via the serial protocol,
34260then this command sends the string @var{text} to the inferior, and
34261displays the response packet. @value{GDBN} supplies the initial
34262@samp{$} character, the terminating @samp{#} character, and the
34263checksum.
34264
34265@kindex maint print architecture
34266@item maint print architecture @r{[}@var{file}@r{]}
34267Print the entire architecture configuration. The optional argument
34268@var{file} names the file where the output goes.
8d30a00d 34269
81adfced
DJ
34270@kindex maint print c-tdesc
34271@item maint print c-tdesc
34272Print the current target description (@pxref{Target Descriptions}) as
34273a C source file. The created source file can be used in @value{GDBN}
34274when an XML parser is not available to parse the description.
34275
00905d52
AC
34276@kindex maint print dummy-frames
34277@item maint print dummy-frames
00905d52
AC
34278Prints the contents of @value{GDBN}'s internal dummy-frame stack.
34279
34280@smallexample
f7dc1244 34281(@value{GDBP}) @kbd{b add}
00905d52 34282@dots{}
f7dc1244 34283(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
34284Breakpoint 2, add (a=2, b=3) at @dots{}
3428558 return (a + b);
34286The program being debugged stopped while in a function called from GDB.
34287@dots{}
f7dc1244 34288(@value{GDBP}) @kbd{maint print dummy-frames}
b67a2c6f 342890xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
f7dc1244 34290(@value{GDBP})
00905d52
AC
34291@end smallexample
34292
34293Takes an optional file parameter.
34294
0680b120
AC
34295@kindex maint print registers
34296@kindex maint print raw-registers
34297@kindex maint print cooked-registers
617073a9 34298@kindex maint print register-groups
c21236dc 34299@kindex maint print remote-registers
09d4efe1
EZ
34300@item maint print registers @r{[}@var{file}@r{]}
34301@itemx maint print raw-registers @r{[}@var{file}@r{]}
34302@itemx maint print cooked-registers @r{[}@var{file}@r{]}
34303@itemx maint print register-groups @r{[}@var{file}@r{]}
c21236dc 34304@itemx maint print remote-registers @r{[}@var{file}@r{]}
0680b120
AC
34305Print @value{GDBN}'s internal register data structures.
34306
617073a9 34307The command @code{maint print raw-registers} includes the contents of
c21236dc
PA
34308the raw register cache; the command @code{maint print
34309cooked-registers} includes the (cooked) value of all registers,
34310including registers which aren't available on the target nor visible
34311to user; the command @code{maint print register-groups} includes the
34312groups that each register is a member of; and the command @code{maint
34313print remote-registers} includes the remote target's register numbers
0a7cfe2c 34314and offsets in the `G' packets.
0680b120 34315
09d4efe1
EZ
34316These commands take an optional parameter, a file name to which to
34317write the information.
0680b120 34318
617073a9 34319@kindex maint print reggroups
09d4efe1
EZ
34320@item maint print reggroups @r{[}@var{file}@r{]}
34321Print @value{GDBN}'s internal register group data structures. The
34322optional argument @var{file} tells to what file to write the
34323information.
617073a9 34324
09d4efe1 34325The register groups info looks like this:
617073a9
AC
34326
34327@smallexample
f7dc1244 34328(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
34329 Group Type
34330 general user
34331 float user
34332 all user
34333 vector user
34334 system user
34335 save internal
34336 restore internal
617073a9
AC
34337@end smallexample
34338
09d4efe1
EZ
34339@kindex flushregs
34340@item flushregs
34341This command forces @value{GDBN} to flush its internal register cache.
34342
34343@kindex maint print objfiles
34344@cindex info for known object files
52e260a3
DE
34345@item maint print objfiles @r{[}@var{regexp}@r{]}
34346Print a dump of all known object files.
34347If @var{regexp} is specified, only print object files whose names
34348match @var{regexp}. For each object file, this command prints its name,
34349address in memory, and all of its psymtabs and symtabs.
09d4efe1 34350
f5b95c01
AA
34351@kindex maint print user-registers
34352@cindex user registers
34353@item maint print user-registers
34354List all currently available @dfn{user registers}. User registers
34355typically provide alternate names for actual hardware registers. They
34356include the four ``standard'' registers @code{$fp}, @code{$pc},
34357@code{$sp}, and @code{$ps}. @xref{standard registers}. User
34358registers can be used in expressions in the same way as the canonical
34359register names, but only the latter are listed by the @code{info
34360registers} and @code{maint print registers} commands.
34361
8a1ea21f
DE
34362@kindex maint print section-scripts
34363@cindex info for known .debug_gdb_scripts-loaded scripts
34364@item maint print section-scripts [@var{regexp}]
34365Print a dump of scripts specified in the @code{.debug_gdb_section} section.
34366If @var{regexp} is specified, only print scripts loaded by object files
34367matching @var{regexp}.
34368For each script, this command prints its name as specified in the objfile,
34369and the full path if known.
8e0583c8 34370@xref{dotdebug_gdb_scripts section}.
8a1ea21f 34371
09d4efe1
EZ
34372@kindex maint print statistics
34373@cindex bcache statistics
34374@item maint print statistics
34375This command prints, for each object file in the program, various data
34376about that object file followed by the byte cache (@dfn{bcache})
34377statistics for the object file. The objfile data includes the number
d3e8051b 34378of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
34379defined by the objfile, the number of as yet unexpanded psym tables,
34380the number of line tables and string tables, and the amount of memory
34381used by the various tables. The bcache statistics include the counts,
34382sizes, and counts of duplicates of all and unique objects, max,
34383average, and median entry size, total memory used and its overhead and
34384savings, and various measures of the hash table size and chain
34385lengths.
34386
c7ba131e
JB
34387@kindex maint print target-stack
34388@cindex target stack description
34389@item maint print target-stack
34390A @dfn{target} is an interface between the debugger and a particular
34391kind of file or process. Targets can be stacked in @dfn{strata},
34392so that more than one target can potentially respond to a request.
34393In particular, memory accesses will walk down the stack of targets
34394until they find a target that is interested in handling that particular
34395address.
34396
34397This command prints a short description of each layer that was pushed on
34398the @dfn{target stack}, starting from the top layer down to the bottom one.
34399
09d4efe1
EZ
34400@kindex maint print type
34401@cindex type chain of a data type
34402@item maint print type @var{expr}
34403Print the type chain for a type specified by @var{expr}. The argument
34404can be either a type name or a symbol. If it is a symbol, the type of
34405that symbol is described. The type chain produced by this command is
34406a recursive definition of the data type as stored in @value{GDBN}'s
34407data structures, including its flags and contained types.
34408
b4f54984
DE
34409@kindex maint set dwarf always-disassemble
34410@kindex maint show dwarf always-disassemble
34411@item maint set dwarf always-disassemble
34412@item maint show dwarf always-disassemble
9eae7c52
TT
34413Control the behavior of @code{info address} when using DWARF debugging
34414information.
34415
34416The default is @code{off}, which means that @value{GDBN} should try to
34417describe a variable's location in an easily readable format. When
34418@code{on}, @value{GDBN} will instead display the DWARF location
34419expression in an assembly-like format. Note that some locations are
34420too complex for @value{GDBN} to describe simply; in this case you will
34421always see the disassembly form.
34422
34423Here is an example of the resulting disassembly:
34424
34425@smallexample
34426(gdb) info addr argc
34427Symbol "argc" is a complex DWARF expression:
34428 1: DW_OP_fbreg 0
34429@end smallexample
34430
34431For more information on these expressions, see
34432@uref{http://www.dwarfstd.org/, the DWARF standard}.
34433
b4f54984
DE
34434@kindex maint set dwarf max-cache-age
34435@kindex maint show dwarf max-cache-age
34436@item maint set dwarf max-cache-age
34437@itemx maint show dwarf max-cache-age
34438Control the DWARF compilation unit cache.
09d4efe1 34439
b4f54984 34440@cindex DWARF compilation units cache
09d4efe1 34441In object files with inter-compilation-unit references, such as those
b4f54984 34442produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
09d4efe1
EZ
34443reader needs to frequently refer to previously read compilation units.
34444This setting controls how long a compilation unit will remain in the
34445cache if it is not referenced. A higher limit means that cached
34446compilation units will be stored in memory longer, and more total
34447memory will be used. Setting it to zero disables caching, which will
34448slow down @value{GDBN} startup, but reduce memory consumption.
34449
e7ba9c65
DJ
34450@kindex maint set profile
34451@kindex maint show profile
34452@cindex profiling GDB
34453@item maint set profile
34454@itemx maint show profile
34455Control profiling of @value{GDBN}.
34456
34457Profiling will be disabled until you use the @samp{maint set profile}
34458command to enable it. When you enable profiling, the system will begin
34459collecting timing and execution count data; when you disable profiling or
34460exit @value{GDBN}, the results will be written to a log file. Remember that
34461if you use profiling, @value{GDBN} will overwrite the profiling log file
34462(often called @file{gmon.out}). If you have a record of important profiling
34463data in a @file{gmon.out} file, be sure to move it to a safe location.
34464
34465Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 34466compiled with the @samp{-pg} compiler option.
e7ba9c65 34467
cbe54154
PA
34468@kindex maint set show-debug-regs
34469@kindex maint show show-debug-regs
eac35c4e 34470@cindex hardware debug registers
cbe54154
PA
34471@item maint set show-debug-regs
34472@itemx maint show show-debug-regs
eac35c4e 34473Control whether to show variables that mirror the hardware debug
6dd315ba 34474registers. Use @code{on} to enable, @code{off} to disable. If
3f94c067 34475enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
34476removes a hardware breakpoint or watchpoint, and when the inferior
34477triggers a hardware-assisted breakpoint or watchpoint.
34478
711e434b
PM
34479@kindex maint set show-all-tib
34480@kindex maint show show-all-tib
34481@item maint set show-all-tib
34482@itemx maint show show-all-tib
34483Control whether to show all non zero areas within a 1k block starting
34484at thread local base, when using the @samp{info w32 thread-information-block}
34485command.
34486
329ea579
PA
34487@kindex maint set target-async
34488@kindex maint show target-async
34489@item maint set target-async
34490@itemx maint show target-async
34491This controls whether @value{GDBN} targets operate in synchronous or
34492asynchronous mode (@pxref{Background Execution}). Normally the
34493default is asynchronous, if it is available; but this can be changed
34494to more easily debug problems occurring only in synchronous mode.
34495
fbea99ea
PA
34496@kindex maint set target-non-stop @var{mode} [on|off|auto]
34497@kindex maint show target-non-stop
34498@item maint set target-non-stop
34499@itemx maint show target-non-stop
34500
34501This controls whether @value{GDBN} targets always operate in non-stop
34502mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
34503Mode}). The default is @code{auto}, meaning non-stop mode is enabled
34504if supported by the target.
34505
34506@table @code
34507@item maint set target-non-stop auto
34508This is the default mode. @value{GDBN} controls the target in
34509non-stop mode if the target supports it.
34510
34511@item maint set target-non-stop on
34512@value{GDBN} controls the target in non-stop mode even if the target
34513does not indicate support.
34514
34515@item maint set target-non-stop off
34516@value{GDBN} does not control the target in non-stop mode even if the
34517target supports it.
34518@end table
34519
bd712aed
DE
34520@kindex maint set per-command
34521@kindex maint show per-command
34522@item maint set per-command
34523@itemx maint show per-command
34524@cindex resources used by commands
09d4efe1 34525
bd712aed
DE
34526@value{GDBN} can display the resources used by each command.
34527This is useful in debugging performance problems.
34528
34529@table @code
34530@item maint set per-command space [on|off]
34531@itemx maint show per-command space
34532Enable or disable the printing of the memory used by GDB for each command.
34533If enabled, @value{GDBN} will display how much memory each command
34534took, following the command's own output.
34535This can also be requested by invoking @value{GDBN} with the
34536@option{--statistics} command-line switch (@pxref{Mode Options}).
34537
34538@item maint set per-command time [on|off]
34539@itemx maint show per-command time
34540Enable or disable the printing of the execution time of @value{GDBN}
34541for each command.
34542If enabled, @value{GDBN} will display how much time it
09d4efe1 34543took to execute each command, following the command's own output.
0a1c4d10
DE
34544Both CPU time and wallclock time are printed.
34545Printing both is useful when trying to determine whether the cost is
bd712aed 34546CPU or, e.g., disk/network latency.
0a1c4d10
DE
34547Note that the CPU time printed is for @value{GDBN} only, it does not include
34548the execution time of the inferior because there's no mechanism currently
34549to compute how much time was spent by @value{GDBN} and how much time was
34550spent by the program been debugged.
09d4efe1
EZ
34551This can also be requested by invoking @value{GDBN} with the
34552@option{--statistics} command-line switch (@pxref{Mode Options}).
34553
bd712aed
DE
34554@item maint set per-command symtab [on|off]
34555@itemx maint show per-command symtab
34556Enable or disable the printing of basic symbol table statistics
34557for each command.
34558If enabled, @value{GDBN} will display the following information:
34559
215b9f98
EZ
34560@enumerate a
34561@item
34562number of symbol tables
34563@item
34564number of primary symbol tables
34565@item
34566number of blocks in the blockvector
34567@end enumerate
bd712aed
DE
34568@end table
34569
34570@kindex maint space
34571@cindex memory used by commands
34572@item maint space @var{value}
34573An alias for @code{maint set per-command space}.
34574A non-zero value enables it, zero disables it.
34575
34576@kindex maint time
34577@cindex time of command execution
34578@item maint time @var{value}
34579An alias for @code{maint set per-command time}.
34580A non-zero value enables it, zero disables it.
34581
09d4efe1
EZ
34582@kindex maint translate-address
34583@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
34584Find the symbol stored at the location specified by the address
34585@var{addr} and an optional section name @var{section}. If found,
34586@value{GDBN} prints the name of the closest symbol and an offset from
34587the symbol's location to the specified address. This is similar to
34588the @code{info address} command (@pxref{Symbols}), except that this
34589command also allows to find symbols in other sections.
ae038cb0 34590
c14c28ba
PP
34591If section was not specified, the section in which the symbol was found
34592is also printed. For dynamically linked executables, the name of
34593executable or shared library containing the symbol is printed as well.
34594
8e04817f 34595@end table
c906108c 34596
9c16f35a
EZ
34597The following command is useful for non-interactive invocations of
34598@value{GDBN}, such as in the test suite.
34599
34600@table @code
34601@item set watchdog @var{nsec}
34602@kindex set watchdog
34603@cindex watchdog timer
34604@cindex timeout for commands
34605Set the maximum number of seconds @value{GDBN} will wait for the
34606target operation to finish. If this time expires, @value{GDBN}
34607reports and error and the command is aborted.
34608
34609@item show watchdog
34610Show the current setting of the target wait timeout.
34611@end table
c906108c 34612
e0ce93ac 34613@node Remote Protocol
8e04817f 34614@appendix @value{GDBN} Remote Serial Protocol
c906108c 34615
ee2d5c50
AC
34616@menu
34617* Overview::
34618* Packets::
34619* Stop Reply Packets::
34620* General Query Packets::
a1dcb23a 34621* Architecture-Specific Protocol Details::
9d29849a 34622* Tracepoint Packets::
a6b151f1 34623* Host I/O Packets::
9a6253be 34624* Interrupts::
8b23ecc4
SL
34625* Notification Packets::
34626* Remote Non-Stop::
a6f3e723 34627* Packet Acknowledgment::
ee2d5c50 34628* Examples::
79a6e687 34629* File-I/O Remote Protocol Extension::
cfa9d6d9 34630* Library List Format::
2268b414 34631* Library List Format for SVR4 Targets::
79a6e687 34632* Memory Map Format::
dc146f7c 34633* Thread List Format::
b3b9301e 34634* Traceframe Info Format::
2ae8c8e7 34635* Branch Trace Format::
f4abbc16 34636* Branch Trace Configuration Format::
ee2d5c50
AC
34637@end menu
34638
34639@node Overview
34640@section Overview
34641
8e04817f
AC
34642There may be occasions when you need to know something about the
34643protocol---for example, if there is only one serial port to your target
34644machine, you might want your program to do something special if it
34645recognizes a packet meant for @value{GDBN}.
c906108c 34646
d2c6833e 34647In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 34648transmitted and received data, respectively.
c906108c 34649
8e04817f
AC
34650@cindex protocol, @value{GDBN} remote serial
34651@cindex serial protocol, @value{GDBN} remote
34652@cindex remote serial protocol
8b23ecc4
SL
34653All @value{GDBN} commands and responses (other than acknowledgments
34654and notifications, see @ref{Notification Packets}) are sent as a
34655@var{packet}. A @var{packet} is introduced with the character
8e04817f
AC
34656@samp{$}, the actual @var{packet-data}, and the terminating character
34657@samp{#} followed by a two-digit @var{checksum}:
c906108c 34658
474c8240 34659@smallexample
8e04817f 34660@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 34661@end smallexample
8e04817f 34662@noindent
c906108c 34663
8e04817f
AC
34664@cindex checksum, for @value{GDBN} remote
34665@noindent
34666The two-digit @var{checksum} is computed as the modulo 256 sum of all
34667characters between the leading @samp{$} and the trailing @samp{#} (an
34668eight bit unsigned checksum).
c906108c 34669
8e04817f
AC
34670Implementors should note that prior to @value{GDBN} 5.0 the protocol
34671specification also included an optional two-digit @var{sequence-id}:
c906108c 34672
474c8240 34673@smallexample
8e04817f 34674@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 34675@end smallexample
c906108c 34676
8e04817f
AC
34677@cindex sequence-id, for @value{GDBN} remote
34678@noindent
34679That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
34680has never output @var{sequence-id}s. Stubs that handle packets added
34681since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 34682
8e04817f
AC
34683When either the host or the target machine receives a packet, the first
34684response expected is an acknowledgment: either @samp{+} (to indicate
34685the package was received correctly) or @samp{-} (to request
34686retransmission):
c906108c 34687
474c8240 34688@smallexample
d2c6833e
AC
34689-> @code{$}@var{packet-data}@code{#}@var{checksum}
34690<- @code{+}
474c8240 34691@end smallexample
8e04817f 34692@noindent
53a5351d 34693
a6f3e723
SL
34694The @samp{+}/@samp{-} acknowledgments can be disabled
34695once a connection is established.
34696@xref{Packet Acknowledgment}, for details.
34697
8e04817f
AC
34698The host (@value{GDBN}) sends @var{command}s, and the target (the
34699debugging stub incorporated in your program) sends a @var{response}. In
34700the case of step and continue @var{command}s, the response is only sent
8b23ecc4
SL
34701when the operation has completed, and the target has again stopped all
34702threads in all attached processes. This is the default all-stop mode
34703behavior, but the remote protocol also supports @value{GDBN}'s non-stop
34704execution mode; see @ref{Remote Non-Stop}, for details.
c906108c 34705
8e04817f
AC
34706@var{packet-data} consists of a sequence of characters with the
34707exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
34708exceptions).
c906108c 34709
ee2d5c50 34710@cindex remote protocol, field separator
0876f84a 34711Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 34712@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 34713@sc{hex} with leading zeros suppressed.
c906108c 34714
8e04817f
AC
34715Implementors should note that prior to @value{GDBN} 5.0, the character
34716@samp{:} could not appear as the third character in a packet (as it
34717would potentially conflict with the @var{sequence-id}).
c906108c 34718
0876f84a
DJ
34719@cindex remote protocol, binary data
34720@anchor{Binary Data}
34721Binary data in most packets is encoded either as two hexadecimal
34722digits per byte of binary data. This allowed the traditional remote
34723protocol to work over connections which were only seven-bit clean.
34724Some packets designed more recently assume an eight-bit clean
34725connection, and use a more efficient encoding to send and receive
34726binary data.
34727
34728The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
34729as an escape character. Any escaped byte is transmitted as the escape
34730character followed by the original character XORed with @code{0x20}.
34731For example, the byte @code{0x7d} would be transmitted as the two
34732bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
34733@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
34734@samp{@}}) must always be escaped. Responses sent by the stub
34735must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
34736is not interpreted as the start of a run-length encoded sequence
34737(described next).
34738
1d3811f6
DJ
34739Response @var{data} can be run-length encoded to save space.
34740Run-length encoding replaces runs of identical characters with one
34741instance of the repeated character, followed by a @samp{*} and a
34742repeat count. The repeat count is itself sent encoded, to avoid
34743binary characters in @var{data}: a value of @var{n} is sent as
34744@code{@var{n}+29}. For a repeat count greater or equal to 3, this
34745produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
34746code 32) for a repeat count of 3. (This is because run-length
34747encoding starts to win for counts 3 or more.) Thus, for example,
34748@samp{0* } is a run-length encoding of ``0000'': the space character
34749after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
347503}} more times.
34751
34752The printable characters @samp{#} and @samp{$} or with a numeric value
34753greater than 126 must not be used. Runs of six repeats (@samp{#}) or
34754seven repeats (@samp{$}) can be expanded using a repeat count of only
34755five (@samp{"}). For example, @samp{00000000} can be encoded as
34756@samp{0*"00}.
c906108c 34757
8e04817f
AC
34758The error response returned for some packets includes a two character
34759error number. That number is not well defined.
c906108c 34760
f8da2bff 34761@cindex empty response, for unsupported packets
8e04817f
AC
34762For any @var{command} not supported by the stub, an empty response
34763(@samp{$#00}) should be returned. That way it is possible to extend the
34764protocol. A newer @value{GDBN} can tell if a packet is supported based
34765on that response.
c906108c 34766
393eab54
PA
34767At a minimum, a stub is required to support the @samp{g} and @samp{G}
34768commands for register access, and the @samp{m} and @samp{M} commands
34769for memory access. Stubs that only control single-threaded targets
34770can implement run control with the @samp{c} (continue), and @samp{s}
34771(step) commands. Stubs that support multi-threading targets should
34772support the @samp{vCont} command. All other commands are optional.
c906108c 34773
ee2d5c50
AC
34774@node Packets
34775@section Packets
34776
34777The following table provides a complete list of all currently defined
34778@var{command}s and their corresponding response @var{data}.
79a6e687 34779@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 34780I/O extension of the remote protocol.
ee2d5c50 34781
b8ff78ce
JB
34782Each packet's description has a template showing the packet's overall
34783syntax, followed by an explanation of the packet's meaning. We
34784include spaces in some of the templates for clarity; these are not
34785part of the packet's syntax. No @value{GDBN} packet uses spaces to
34786separate its components. For example, a template like @samp{foo
34787@var{bar} @var{baz}} describes a packet beginning with the three ASCII
34788bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 34789@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
34790@samp{foo} and the @var{bar}, or between the @var{bar} and the
34791@var{baz}.
34792
b90a069a
SL
34793@cindex @var{thread-id}, in remote protocol
34794@anchor{thread-id syntax}
34795Several packets and replies include a @var{thread-id} field to identify
34796a thread. Normally these are positive numbers with a target-specific
34797interpretation, formatted as big-endian hex strings. A @var{thread-id}
34798can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
34799pick any thread.
34800
34801In addition, the remote protocol supports a multiprocess feature in
34802which the @var{thread-id} syntax is extended to optionally include both
34803process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
34804The @var{pid} (process) and @var{tid} (thread) components each have the
34805format described above: a positive number with target-specific
34806interpretation formatted as a big-endian hex string, literal @samp{-1}
34807to indicate all processes or threads (respectively), or @samp{0} to
34808indicate an arbitrary process or thread. Specifying just a process, as
34809@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
34810error to specify all processes but a specific thread, such as
34811@samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
34812for those packets and replies explicitly documented to include a process
34813ID, rather than a @var{thread-id}.
34814
34815The multiprocess @var{thread-id} syntax extensions are only used if both
34816@value{GDBN} and the stub report support for the @samp{multiprocess}
34817feature using @samp{qSupported}. @xref{multiprocess extensions}, for
34818more information.
34819
8ffe2530
JB
34820Note that all packet forms beginning with an upper- or lower-case
34821letter, other than those described here, are reserved for future use.
34822
b8ff78ce 34823Here are the packet descriptions.
ee2d5c50 34824
b8ff78ce 34825@table @samp
ee2d5c50 34826
b8ff78ce
JB
34827@item !
34828@cindex @samp{!} packet
2d717e4f 34829@anchor{extended mode}
8e04817f
AC
34830Enable extended mode. In extended mode, the remote server is made
34831persistent. The @samp{R} packet is used to restart the program being
34832debugged.
ee2d5c50
AC
34833
34834Reply:
34835@table @samp
34836@item OK
8e04817f 34837The remote target both supports and has enabled extended mode.
ee2d5c50 34838@end table
c906108c 34839
b8ff78ce
JB
34840@item ?
34841@cindex @samp{?} packet
36cb1214 34842@anchor{? packet}
ee2d5c50 34843Indicate the reason the target halted. The reply is the same as for
8b23ecc4
SL
34844step and continue. This packet has a special interpretation when the
34845target is in non-stop mode; see @ref{Remote Non-Stop}.
c906108c 34846
ee2d5c50
AC
34847Reply:
34848@xref{Stop Reply Packets}, for the reply specifications.
34849
b8ff78ce
JB
34850@item A @var{arglen},@var{argnum},@var{arg},@dots{}
34851@cindex @samp{A} packet
34852Initialized @code{argv[]} array passed into program. @var{arglen}
34853specifies the number of bytes in the hex encoded byte stream
34854@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
34855
34856Reply:
34857@table @samp
34858@item OK
b8ff78ce
JB
34859The arguments were set.
34860@item E @var{NN}
34861An error occurred.
ee2d5c50
AC
34862@end table
34863
b8ff78ce
JB
34864@item b @var{baud}
34865@cindex @samp{b} packet
34866(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
34867Change the serial line speed to @var{baud}.
34868
34869JTC: @emph{When does the transport layer state change? When it's
34870received, or after the ACK is transmitted. In either case, there are
34871problems if the command or the acknowledgment packet is dropped.}
34872
34873Stan: @emph{If people really wanted to add something like this, and get
34874it working for the first time, they ought to modify ser-unix.c to send
34875some kind of out-of-band message to a specially-setup stub and have the
34876switch happen "in between" packets, so that from remote protocol's point
34877of view, nothing actually happened.}
34878
b8ff78ce
JB
34879@item B @var{addr},@var{mode}
34880@cindex @samp{B} packet
8e04817f 34881Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
34882breakpoint at @var{addr}.
34883
b8ff78ce 34884Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 34885(@pxref{insert breakpoint or watchpoint packet}).
c906108c 34886
bacec72f 34887@cindex @samp{bc} packet
0d772ac9
MS
34888@anchor{bc}
34889@item bc
bacec72f
MS
34890Backward continue. Execute the target system in reverse. No parameter.
34891@xref{Reverse Execution}, for more information.
34892
34893Reply:
34894@xref{Stop Reply Packets}, for the reply specifications.
34895
bacec72f 34896@cindex @samp{bs} packet
0d772ac9
MS
34897@anchor{bs}
34898@item bs
bacec72f
MS
34899Backward single step. Execute one instruction in reverse. No parameter.
34900@xref{Reverse Execution}, for more information.
34901
34902Reply:
34903@xref{Stop Reply Packets}, for the reply specifications.
34904
4f553f88 34905@item c @r{[}@var{addr}@r{]}
b8ff78ce 34906@cindex @samp{c} packet
697aa1b7
EZ
34907Continue at @var{addr}, which is the address to resume. If @var{addr}
34908is omitted, resume at current address.
c906108c 34909
393eab54
PA
34910This packet is deprecated for multi-threading support. @xref{vCont
34911packet}.
34912
ee2d5c50
AC
34913Reply:
34914@xref{Stop Reply Packets}, for the reply specifications.
34915
4f553f88 34916@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 34917@cindex @samp{C} packet
8e04817f 34918Continue with signal @var{sig} (hex signal number). If
b8ff78ce 34919@samp{;@var{addr}} is omitted, resume at same address.
c906108c 34920
393eab54
PA
34921This packet is deprecated for multi-threading support. @xref{vCont
34922packet}.
34923
ee2d5c50
AC
34924Reply:
34925@xref{Stop Reply Packets}, for the reply specifications.
c906108c 34926
b8ff78ce
JB
34927@item d
34928@cindex @samp{d} packet
ee2d5c50
AC
34929Toggle debug flag.
34930
b8ff78ce
JB
34931Don't use this packet; instead, define a general set packet
34932(@pxref{General Query Packets}).
ee2d5c50 34933
b8ff78ce 34934@item D
b90a069a 34935@itemx D;@var{pid}
b8ff78ce 34936@cindex @samp{D} packet
b90a069a
SL
34937The first form of the packet is used to detach @value{GDBN} from the
34938remote system. It is sent to the remote target
07f31aa6 34939before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50 34940
b90a069a
SL
34941The second form, including a process ID, is used when multiprocess
34942protocol extensions are enabled (@pxref{multiprocess extensions}), to
34943detach only a specific process. The @var{pid} is specified as a
34944big-endian hex string.
34945
ee2d5c50
AC
34946Reply:
34947@table @samp
10fac096
NW
34948@item OK
34949for success
b8ff78ce 34950@item E @var{NN}
10fac096 34951for an error
ee2d5c50 34952@end table
c906108c 34953
b8ff78ce
JB
34954@item F @var{RC},@var{EE},@var{CF};@var{XX}
34955@cindex @samp{F} packet
34956A reply from @value{GDBN} to an @samp{F} packet sent by the target.
34957This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 34958Remote Protocol Extension}, for the specification.
ee2d5c50 34959
b8ff78ce 34960@item g
ee2d5c50 34961@anchor{read registers packet}
b8ff78ce 34962@cindex @samp{g} packet
ee2d5c50
AC
34963Read general registers.
34964
34965Reply:
34966@table @samp
34967@item @var{XX@dots{}}
8e04817f
AC
34968Each byte of register data is described by two hex digits. The bytes
34969with the register are transmitted in target byte order. The size of
b8ff78ce 34970each register and their position within the @samp{g} packet are
4a9bb1df
UW
34971determined by the @value{GDBN} internal gdbarch functions
34972@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}. The
b8ff78ce 34973specification of several standard @samp{g} packets is specified below.
ad196637
PA
34974
34975When reading registers from a trace frame (@pxref{Analyze Collected
34976Data,,Using the Collected Data}), the stub may also return a string of
34977literal @samp{x}'s in place of the register data digits, to indicate
34978that the corresponding register has not been collected, thus its value
34979is unavailable. For example, for an architecture with 4 registers of
349804 bytes each, the following reply indicates to @value{GDBN} that
34981registers 0 and 2 have not been collected, while registers 1 and 3
34982have been collected, and both have zero value:
34983
34984@smallexample
34985-> @code{g}
34986<- @code{xxxxxxxx00000000xxxxxxxx00000000}
34987@end smallexample
34988
b8ff78ce 34989@item E @var{NN}
ee2d5c50
AC
34990for an error.
34991@end table
c906108c 34992
b8ff78ce
JB
34993@item G @var{XX@dots{}}
34994@cindex @samp{G} packet
34995Write general registers. @xref{read registers packet}, for a
34996description of the @var{XX@dots{}} data.
ee2d5c50
AC
34997
34998Reply:
34999@table @samp
35000@item OK
35001for success
b8ff78ce 35002@item E @var{NN}
ee2d5c50
AC
35003for an error
35004@end table
35005
393eab54 35006@item H @var{op} @var{thread-id}
b8ff78ce 35007@cindex @samp{H} packet
8e04817f 35008Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
697aa1b7
EZ
35009@samp{G}, et.al.). Depending on the operation to be performed, @var{op}
35010should be @samp{c} for step and continue operations (note that this
393eab54 35011is deprecated, supporting the @samp{vCont} command is a better
697aa1b7 35012option), and @samp{g} for other operations. The thread designator
393eab54
PA
35013@var{thread-id} has the format and interpretation described in
35014@ref{thread-id syntax}.
ee2d5c50
AC
35015
35016Reply:
35017@table @samp
35018@item OK
35019for success
b8ff78ce 35020@item E @var{NN}
ee2d5c50
AC
35021for an error
35022@end table
c906108c 35023
8e04817f
AC
35024@c FIXME: JTC:
35025@c 'H': How restrictive (or permissive) is the thread model. If a
35026@c thread is selected and stopped, are other threads allowed
35027@c to continue to execute? As I mentioned above, I think the
35028@c semantics of each command when a thread is selected must be
35029@c described. For example:
35030@c
35031@c 'g': If the stub supports threads and a specific thread is
35032@c selected, returns the register block from that thread;
35033@c otherwise returns current registers.
35034@c
35035@c 'G' If the stub supports threads and a specific thread is
35036@c selected, sets the registers of the register block of
35037@c that thread; otherwise sets current registers.
c906108c 35038
b8ff78ce 35039@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 35040@anchor{cycle step packet}
b8ff78ce
JB
35041@cindex @samp{i} packet
35042Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
35043present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
35044step starting at that address.
c906108c 35045
b8ff78ce
JB
35046@item I
35047@cindex @samp{I} packet
35048Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
35049step packet}.
ee2d5c50 35050
b8ff78ce
JB
35051@item k
35052@cindex @samp{k} packet
35053Kill request.
c906108c 35054
36cb1214
HZ
35055The exact effect of this packet is not specified.
35056
35057For a bare-metal target, it may power cycle or reset the target
35058system. For that reason, the @samp{k} packet has no reply.
35059
35060For a single-process target, it may kill that process if possible.
35061
35062A multiple-process target may choose to kill just one process, or all
35063that are under @value{GDBN}'s control. For more precise control, use
35064the vKill packet (@pxref{vKill packet}).
35065
35066If the target system immediately closes the connection in response to
35067@samp{k}, @value{GDBN} does not consider the lack of packet
35068acknowledgment to be an error, and assumes the kill was successful.
35069
35070If connected using @kbd{target extended-remote}, and the target does
35071not close the connection in response to a kill request, @value{GDBN}
35072probes the target state as if a new connection was opened
35073(@pxref{? packet}).
c906108c 35074
b8ff78ce
JB
35075@item m @var{addr},@var{length}
35076@cindex @samp{m} packet
a86c90e6
SM
35077Read @var{length} addressable memory units starting at address @var{addr}
35078(@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
35079any particular boundary.
fb031cdf
JB
35080
35081The stub need not use any particular size or alignment when gathering
35082data from memory for the response; even if @var{addr} is word-aligned
35083and @var{length} is a multiple of the word size, the stub is free to
35084use byte accesses, or not. For this reason, this packet may not be
35085suitable for accessing memory-mapped I/O devices.
c43c5473
JB
35086@cindex alignment of remote memory accesses
35087@cindex size of remote memory accesses
35088@cindex memory, alignment and size of remote accesses
c906108c 35089
ee2d5c50
AC
35090Reply:
35091@table @samp
35092@item @var{XX@dots{}}
a86c90e6
SM
35093Memory contents; each byte is transmitted as a two-digit hexadecimal number.
35094The reply may contain fewer addressable memory units than requested if the
b8ff78ce
JB
35095server was able to read only part of the region of memory.
35096@item E @var{NN}
ee2d5c50
AC
35097@var{NN} is errno
35098@end table
35099
b8ff78ce
JB
35100@item M @var{addr},@var{length}:@var{XX@dots{}}
35101@cindex @samp{M} packet
a86c90e6
SM
35102Write @var{length} addressable memory units starting at address @var{addr}
35103(@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
35104byte is transmitted as a two-digit hexadecimal number.
ee2d5c50
AC
35105
35106Reply:
35107@table @samp
35108@item OK
35109for success
b8ff78ce 35110@item E @var{NN}
8e04817f
AC
35111for an error (this includes the case where only part of the data was
35112written).
ee2d5c50 35113@end table
c906108c 35114
b8ff78ce
JB
35115@item p @var{n}
35116@cindex @samp{p} packet
35117Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
35118@xref{read registers packet}, for a description of how the returned
35119register value is encoded.
ee2d5c50
AC
35120
35121Reply:
35122@table @samp
2e868123
AC
35123@item @var{XX@dots{}}
35124the register's value
b8ff78ce 35125@item E @var{NN}
2e868123 35126for an error
d57350ea 35127@item @w{}
2e868123 35128Indicating an unrecognized @var{query}.
ee2d5c50
AC
35129@end table
35130
b8ff78ce 35131@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 35132@anchor{write register packet}
b8ff78ce
JB
35133@cindex @samp{P} packet
35134Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 35135number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 35136digits for each byte in the register (target byte order).
c906108c 35137
ee2d5c50
AC
35138Reply:
35139@table @samp
35140@item OK
35141for success
b8ff78ce 35142@item E @var{NN}
ee2d5c50
AC
35143for an error
35144@end table
35145
5f3bebba
JB
35146@item q @var{name} @var{params}@dots{}
35147@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 35148@cindex @samp{q} packet
b8ff78ce 35149@cindex @samp{Q} packet
5f3bebba
JB
35150General query (@samp{q}) and set (@samp{Q}). These packets are
35151described fully in @ref{General Query Packets}.
c906108c 35152
b8ff78ce
JB
35153@item r
35154@cindex @samp{r} packet
8e04817f 35155Reset the entire system.
c906108c 35156
b8ff78ce 35157Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 35158
b8ff78ce
JB
35159@item R @var{XX}
35160@cindex @samp{R} packet
697aa1b7 35161Restart the program being debugged. The @var{XX}, while needed, is ignored.
2d717e4f 35162This packet is only available in extended mode (@pxref{extended mode}).
ee2d5c50 35163
8e04817f 35164The @samp{R} packet has no reply.
ee2d5c50 35165
4f553f88 35166@item s @r{[}@var{addr}@r{]}
b8ff78ce 35167@cindex @samp{s} packet
697aa1b7 35168Single step, resuming at @var{addr}. If
b8ff78ce 35169@var{addr} is omitted, resume at same address.
c906108c 35170
393eab54
PA
35171This packet is deprecated for multi-threading support. @xref{vCont
35172packet}.
35173
ee2d5c50
AC
35174Reply:
35175@xref{Stop Reply Packets}, for the reply specifications.
35176
4f553f88 35177@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 35178@anchor{step with signal packet}
b8ff78ce
JB
35179@cindex @samp{S} packet
35180Step with signal. This is analogous to the @samp{C} packet, but
35181requests a single-step, rather than a normal resumption of execution.
c906108c 35182
393eab54
PA
35183This packet is deprecated for multi-threading support. @xref{vCont
35184packet}.
35185
ee2d5c50
AC
35186Reply:
35187@xref{Stop Reply Packets}, for the reply specifications.
35188
b8ff78ce
JB
35189@item t @var{addr}:@var{PP},@var{MM}
35190@cindex @samp{t} packet
8e04817f 35191Search backwards starting at address @var{addr} for a match with pattern
697aa1b7
EZ
35192@var{PP} and mask @var{MM}, both of which are are 4 byte long.
35193There must be at least 3 digits in @var{addr}.
c906108c 35194
b90a069a 35195@item T @var{thread-id}
b8ff78ce 35196@cindex @samp{T} packet
b90a069a 35197Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
c906108c 35198
ee2d5c50
AC
35199Reply:
35200@table @samp
35201@item OK
35202thread is still alive
b8ff78ce 35203@item E @var{NN}
ee2d5c50
AC
35204thread is dead
35205@end table
35206
b8ff78ce
JB
35207@item v
35208Packets starting with @samp{v} are identified by a multi-letter name,
35209up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 35210
2d717e4f
DJ
35211@item vAttach;@var{pid}
35212@cindex @samp{vAttach} packet
8b23ecc4
SL
35213Attach to a new process with the specified process ID @var{pid}.
35214The process ID is a
35215hexadecimal integer identifying the process. In all-stop mode, all
35216threads in the attached process are stopped; in non-stop mode, it may be
35217attached without being stopped if that is supported by the target.
35218
35219@c In non-stop mode, on a successful vAttach, the stub should set the
35220@c current thread to a thread of the newly-attached process. After
35221@c attaching, GDB queries for the attached process's thread ID with qC.
35222@c Also note that, from a user perspective, whether or not the
35223@c target is stopped on attach in non-stop mode depends on whether you
35224@c use the foreground or background version of the attach command, not
35225@c on what vAttach does; GDB does the right thing with respect to either
35226@c stopping or restarting threads.
2d717e4f
DJ
35227
35228This packet is only available in extended mode (@pxref{extended mode}).
35229
35230Reply:
35231@table @samp
35232@item E @var{nn}
35233for an error
35234@item @r{Any stop packet}
8b23ecc4
SL
35235for success in all-stop mode (@pxref{Stop Reply Packets})
35236@item OK
35237for success in non-stop mode (@pxref{Remote Non-Stop})
2d717e4f
DJ
35238@end table
35239
b90a069a 35240@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
b8ff78ce 35241@cindex @samp{vCont} packet
393eab54 35242@anchor{vCont packet}
b8ff78ce 35243Resume the inferior, specifying different actions for each thread.
b90a069a 35244If an action is specified with no @var{thread-id}, then it is applied to any
86d30acc 35245threads that don't have a specific action specified; if no default action is
8b23ecc4
SL
35246specified then other threads should remain stopped in all-stop mode and
35247in their current state in non-stop mode.
35248Specifying multiple
86d30acc 35249default actions is an error; specifying no actions is also an error.
b90a069a
SL
35250Thread IDs are specified using the syntax described in @ref{thread-id syntax}.
35251
35252Currently supported actions are:
86d30acc 35253
b8ff78ce 35254@table @samp
86d30acc
DJ
35255@item c
35256Continue.
b8ff78ce 35257@item C @var{sig}
8b23ecc4 35258Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
35259@item s
35260Step.
b8ff78ce 35261@item S @var{sig}
8b23ecc4
SL
35262Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
35263@item t
35264Stop.
c1e36e3e
PA
35265@item r @var{start},@var{end}
35266Step once, and then keep stepping as long as the thread stops at
35267addresses between @var{start} (inclusive) and @var{end} (exclusive).
35268The remote stub reports a stop reply when either the thread goes out
35269of the range or is stopped due to an unrelated reason, such as hitting
35270a breakpoint. @xref{range stepping}.
35271
35272If the range is empty (@var{start} == @var{end}), then the action
35273becomes equivalent to the @samp{s} action. In other words,
35274single-step once, and report the stop (even if the stepped instruction
35275jumps to @var{start}).
35276
35277(A stop reply may be sent at any point even if the PC is still within
35278the stepping range; for example, it is valid to implement this packet
35279in a degenerate way as a single instruction step operation.)
35280
86d30acc
DJ
35281@end table
35282
8b23ecc4
SL
35283The optional argument @var{addr} normally associated with the
35284@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
b8ff78ce 35285not supported in @samp{vCont}.
86d30acc 35286
08a0efd0
PA
35287The @samp{t} action is only relevant in non-stop mode
35288(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
8b23ecc4
SL
35289A stop reply should be generated for any affected thread not already stopped.
35290When a thread is stopped by means of a @samp{t} action,
35291the corresponding stop reply should indicate that the thread has stopped with
35292signal @samp{0}, regardless of whether the target uses some other signal
35293as an implementation detail.
35294
4220b2f8
TS
35295The stub must support @samp{vCont} if it reports support for
35296multiprocess extensions (@pxref{multiprocess extensions}). Note that in
35297this case @samp{vCont} actions can be specified to apply to all threads
35298in a process by using the @samp{p@var{pid}.-1} form of the
35299@var{thread-id}.
35300
86d30acc
DJ
35301Reply:
35302@xref{Stop Reply Packets}, for the reply specifications.
35303
b8ff78ce
JB
35304@item vCont?
35305@cindex @samp{vCont?} packet
d3e8051b 35306Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
35307
35308Reply:
35309@table @samp
b8ff78ce
JB
35310@item vCont@r{[};@var{action}@dots{}@r{]}
35311The @samp{vCont} packet is supported. Each @var{action} is a supported
35312command in the @samp{vCont} packet.
d57350ea 35313@item @w{}
b8ff78ce 35314The @samp{vCont} packet is not supported.
86d30acc 35315@end table
ee2d5c50 35316
de979965
PA
35317@anchor{vCtrlC packet}
35318@item vCtrlC
35319@cindex @samp{vCtrlC} packet
35320Interrupt remote target as if a control-C was pressed on the remote
35321terminal. This is the equivalent to reacting to the @code{^C}
35322(@samp{\003}, the control-C character) character in all-stop mode
35323while the target is running, except this works in non-stop mode.
35324@xref{interrupting remote targets}, for more info on the all-stop
35325variant.
35326
35327Reply:
35328@table @samp
35329@item E @var{nn}
35330for an error
35331@item OK
35332for success
35333@end table
35334
a6b151f1
DJ
35335@item vFile:@var{operation}:@var{parameter}@dots{}
35336@cindex @samp{vFile} packet
35337Perform a file operation on the target system. For details,
35338see @ref{Host I/O Packets}.
35339
68437a39
DJ
35340@item vFlashErase:@var{addr},@var{length}
35341@cindex @samp{vFlashErase} packet
35342Direct the stub to erase @var{length} bytes of flash starting at
35343@var{addr}. The region may enclose any number of flash blocks, but
35344its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
35345flash block size appearing in the memory map (@pxref{Memory Map
35346Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
35347together, and sends a @samp{vFlashDone} request after each group; the
35348stub is allowed to delay erase operation until the @samp{vFlashDone}
35349packet is received.
35350
35351Reply:
35352@table @samp
35353@item OK
35354for success
35355@item E @var{NN}
35356for an error
35357@end table
35358
35359@item vFlashWrite:@var{addr}:@var{XX@dots{}}
35360@cindex @samp{vFlashWrite} packet
35361Direct the stub to write data to flash address @var{addr}. The data
35362is passed in binary form using the same encoding as for the @samp{X}
35363packet (@pxref{Binary Data}). The memory ranges specified by
35364@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
35365not overlap, and must appear in order of increasing addresses
35366(although @samp{vFlashErase} packets for higher addresses may already
35367have been received; the ordering is guaranteed only between
35368@samp{vFlashWrite} packets). If a packet writes to an address that was
35369neither erased by a preceding @samp{vFlashErase} packet nor by some other
35370target-specific method, the results are unpredictable.
35371
35372
35373Reply:
35374@table @samp
35375@item OK
35376for success
35377@item E.memtype
35378for vFlashWrite addressing non-flash memory
35379@item E @var{NN}
35380for an error
35381@end table
35382
35383@item vFlashDone
35384@cindex @samp{vFlashDone} packet
35385Indicate to the stub that flash programming operation is finished.
35386The stub is permitted to delay or batch the effects of a group of
35387@samp{vFlashErase} and @samp{vFlashWrite} packets until a
35388@samp{vFlashDone} packet is received. The contents of the affected
35389regions of flash memory are unpredictable until the @samp{vFlashDone}
35390request is completed.
35391
b90a069a
SL
35392@item vKill;@var{pid}
35393@cindex @samp{vKill} packet
36cb1214 35394@anchor{vKill packet}
697aa1b7 35395Kill the process with the specified process ID @var{pid}, which is a
b90a069a
SL
35396hexadecimal integer identifying the process. This packet is used in
35397preference to @samp{k} when multiprocess protocol extensions are
35398supported; see @ref{multiprocess extensions}.
35399
35400Reply:
35401@table @samp
35402@item E @var{nn}
35403for an error
35404@item OK
35405for success
35406@end table
35407
2d717e4f
DJ
35408@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
35409@cindex @samp{vRun} packet
35410Run the program @var{filename}, passing it each @var{argument} on its
35411command line. The file and arguments are hex-encoded strings. If
35412@var{filename} is an empty string, the stub may use a default program
35413(e.g.@: the last program run). The program is created in the stopped
9b562ab8 35414state.
2d717e4f 35415
8b23ecc4
SL
35416@c FIXME: What about non-stop mode?
35417
2d717e4f
DJ
35418This packet is only available in extended mode (@pxref{extended mode}).
35419
35420Reply:
35421@table @samp
35422@item E @var{nn}
35423for an error
35424@item @r{Any stop packet}
35425for success (@pxref{Stop Reply Packets})
35426@end table
35427
8b23ecc4 35428@item vStopped
8b23ecc4 35429@cindex @samp{vStopped} packet
8dbe8ece 35430@xref{Notification Packets}.
8b23ecc4 35431
b8ff78ce 35432@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 35433@anchor{X packet}
b8ff78ce
JB
35434@cindex @samp{X} packet
35435Write data to memory, where the data is transmitted in binary.
a86c90e6
SM
35436Memory is specified by its address @var{addr} and number of addressable memory
35437units @var{length} (@pxref{addressable memory unit});
0876f84a 35438@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 35439
ee2d5c50
AC
35440Reply:
35441@table @samp
35442@item OK
35443for success
b8ff78ce 35444@item E @var{NN}
ee2d5c50
AC
35445for an error
35446@end table
35447
a1dcb23a
DJ
35448@item z @var{type},@var{addr},@var{kind}
35449@itemx Z @var{type},@var{addr},@var{kind}
2f870471 35450@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
35451@cindex @samp{z} packet
35452@cindex @samp{Z} packets
35453Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
a1dcb23a 35454watchpoint starting at address @var{address} of kind @var{kind}.
ee2d5c50 35455
2f870471
AC
35456Each breakpoint and watchpoint packet @var{type} is documented
35457separately.
35458
512217c7
AC
35459@emph{Implementation notes: A remote target shall return an empty string
35460for an unrecognized breakpoint or watchpoint packet @var{type}. A
35461remote target shall support either both or neither of a given
b8ff78ce 35462@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
35463avoid potential problems with duplicate packets, the operations should
35464be implemented in an idempotent way.}
35465
a1dcb23a 35466@item z0,@var{addr},@var{kind}
d3ce09f5 35467@itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
35468@cindex @samp{z0} packet
35469@cindex @samp{Z0} packet
35470Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
a1dcb23a 35471@var{addr} of type @var{kind}.
2f870471
AC
35472
35473A memory breakpoint is implemented by replacing the instruction at
35474@var{addr} with a software breakpoint or trap instruction. The
a1dcb23a
DJ
35475@var{kind} is target-specific and typically indicates the size of
35476the breakpoint in bytes that should be inserted. E.g., the @sc{arm}
35477and @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
35478architectures have additional meanings for @var{kind};
83364271
LM
35479@var{cond_list} is an optional list of conditional expressions in bytecode
35480form that should be evaluated on the target's side. These are the
35481conditions that should be taken into consideration when deciding if
35482the breakpoint trigger should be reported back to @var{GDBN}.
35483
f7e6eed5
PA
35484See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
35485for how to best report a memory breakpoint event to @value{GDBN}.
35486
83364271
LM
35487The @var{cond_list} parameter is comprised of a series of expressions,
35488concatenated without separators. Each expression has the following form:
35489
35490@table @samp
35491
35492@item X @var{len},@var{expr}
35493@var{len} is the length of the bytecode expression and @var{expr} is the
35494actual conditional expression in bytecode form.
35495
35496@end table
35497
d3ce09f5
SS
35498The optional @var{cmd_list} parameter introduces commands that may be
35499run on the target, rather than being reported back to @value{GDBN}.
35500The parameter starts with a numeric flag @var{persist}; if the flag is
35501nonzero, then the breakpoint may remain active and the commands
35502continue to be run even when @value{GDBN} disconnects from the target.
35503Following this flag is a series of expressions concatenated with no
35504separators. Each expression has the following form:
35505
35506@table @samp
35507
35508@item X @var{len},@var{expr}
35509@var{len} is the length of the bytecode expression and @var{expr} is the
35510actual conditional expression in bytecode form.
35511
35512@end table
35513
a1dcb23a 35514see @ref{Architecture-Specific Protocol Details}.
c906108c 35515
2f870471
AC
35516@emph{Implementation note: It is possible for a target to copy or move
35517code that contains memory breakpoints (e.g., when implementing
35518overlays). The behavior of this packet, in the presence of such a
35519target, is not defined.}
c906108c 35520
ee2d5c50
AC
35521Reply:
35522@table @samp
2f870471
AC
35523@item OK
35524success
d57350ea 35525@item @w{}
2f870471 35526not supported
b8ff78ce 35527@item E @var{NN}
ee2d5c50 35528for an error
2f870471
AC
35529@end table
35530
a1dcb23a 35531@item z1,@var{addr},@var{kind}
83364271 35532@itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}
b8ff78ce
JB
35533@cindex @samp{z1} packet
35534@cindex @samp{Z1} packet
35535Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
a1dcb23a 35536address @var{addr}.
2f870471
AC
35537
35538A hardware breakpoint is implemented using a mechanism that is not
697aa1b7 35539dependant on being able to modify the target's memory. The @var{kind}
83364271 35540and @var{cond_list} have the same meaning as in @samp{Z0} packets.
2f870471
AC
35541
35542@emph{Implementation note: A hardware breakpoint is not affected by code
35543movement.}
35544
35545Reply:
35546@table @samp
ee2d5c50 35547@item OK
2f870471 35548success
d57350ea 35549@item @w{}
2f870471 35550not supported
b8ff78ce 35551@item E @var{NN}
2f870471
AC
35552for an error
35553@end table
35554
a1dcb23a
DJ
35555@item z2,@var{addr},@var{kind}
35556@itemx Z2,@var{addr},@var{kind}
b8ff78ce
JB
35557@cindex @samp{z2} packet
35558@cindex @samp{Z2} packet
a1dcb23a 35559Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
697aa1b7 35560The number of bytes to watch is specified by @var{kind}.
2f870471
AC
35561
35562Reply:
35563@table @samp
35564@item OK
35565success
d57350ea 35566@item @w{}
2f870471 35567not supported
b8ff78ce 35568@item E @var{NN}
2f870471
AC
35569for an error
35570@end table
35571
a1dcb23a
DJ
35572@item z3,@var{addr},@var{kind}
35573@itemx Z3,@var{addr},@var{kind}
b8ff78ce
JB
35574@cindex @samp{z3} packet
35575@cindex @samp{Z3} packet
a1dcb23a 35576Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
697aa1b7 35577The number of bytes to watch is specified by @var{kind}.
2f870471
AC
35578
35579Reply:
35580@table @samp
35581@item OK
35582success
d57350ea 35583@item @w{}
2f870471 35584not supported
b8ff78ce 35585@item E @var{NN}
2f870471
AC
35586for an error
35587@end table
35588
a1dcb23a
DJ
35589@item z4,@var{addr},@var{kind}
35590@itemx Z4,@var{addr},@var{kind}
b8ff78ce
JB
35591@cindex @samp{z4} packet
35592@cindex @samp{Z4} packet
a1dcb23a 35593Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
697aa1b7 35594The number of bytes to watch is specified by @var{kind}.
2f870471
AC
35595
35596Reply:
35597@table @samp
35598@item OK
35599success
d57350ea 35600@item @w{}
2f870471 35601not supported
b8ff78ce 35602@item E @var{NN}
2f870471 35603for an error
ee2d5c50
AC
35604@end table
35605
35606@end table
c906108c 35607
ee2d5c50
AC
35608@node Stop Reply Packets
35609@section Stop Reply Packets
35610@cindex stop reply packets
c906108c 35611
8b23ecc4
SL
35612The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
35613@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
35614receive any of the below as a reply. Except for @samp{?}
35615and @samp{vStopped}, that reply is only returned
b8ff78ce 35616when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
35617number} is defined by the header @file{include/gdb/signals.h} in the
35618@value{GDBN} source code.
c906108c 35619
b8ff78ce
JB
35620As in the description of request packets, we include spaces in the
35621reply templates for clarity; these are not part of the reply packet's
35622syntax. No @value{GDBN} stop reply packet uses spaces to separate its
35623components.
c906108c 35624
b8ff78ce 35625@table @samp
ee2d5c50 35626
b8ff78ce 35627@item S @var{AA}
599b237a 35628The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
35629number). This is equivalent to a @samp{T} response with no
35630@var{n}:@var{r} pairs.
c906108c 35631
b8ff78ce
JB
35632@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
35633@cindex @samp{T} packet reply
599b237a 35634The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
35635number). This is equivalent to an @samp{S} response, except that the
35636@samp{@var{n}:@var{r}} pairs can carry values of important registers
35637and other information directly in the stop reply packet, reducing
35638round-trip latency. Single-step and breakpoint traps are reported
35639this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
35640
35641@itemize @bullet
b8ff78ce 35642@item
599b237a 35643If @var{n} is a hexadecimal number, it is a register number, and the
697aa1b7 35644corresponding @var{r} gives that register's value. The data @var{r} is a
b8ff78ce
JB
35645series of bytes in target byte order, with each byte given by a
35646two-digit hex number.
cfa9d6d9 35647
b8ff78ce 35648@item
b90a069a
SL
35649If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
35650the stopped thread, as specified in @ref{thread-id syntax}.
cfa9d6d9 35651
dc146f7c
VP
35652@item
35653If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
35654the core on which the stop event was detected.
35655
b8ff78ce 35656@item
cfa9d6d9
DJ
35657If @var{n} is a recognized @dfn{stop reason}, it describes a more
35658specific event that stopped the target. The currently defined stop
697aa1b7 35659reasons are listed below. The @var{aa} should be @samp{05}, the trap
cfa9d6d9
DJ
35660signal. At most one stop reason should be present.
35661
b8ff78ce
JB
35662@item
35663Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
35664and go on to the next; this allows us to extend the protocol in the
35665future.
cfa9d6d9
DJ
35666@end itemize
35667
35668The currently defined stop reasons are:
35669
35670@table @samp
35671@item watch
35672@itemx rwatch
35673@itemx awatch
35674The packet indicates a watchpoint hit, and @var{r} is the data address, in
35675hex.
35676
82075af2
JS
35677@item syscall_entry
35678@itemx syscall_return
35679The packet indicates a syscall entry or return, and @var{r} is the
35680syscall number, in hex.
35681
cfa9d6d9
DJ
35682@cindex shared library events, remote reply
35683@item library
35684The packet indicates that the loaded libraries have changed.
35685@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
697aa1b7 35686list of loaded libraries. The @var{r} part is ignored.
bacec72f
MS
35687
35688@cindex replay log events, remote reply
35689@item replaylog
35690The packet indicates that the target cannot continue replaying
35691logged execution events, because it has reached the end (or the
35692beginning when executing backward) of the log. The value of @var{r}
35693will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
35694for more information.
f7e6eed5
PA
35695
35696@item swbreak
35697@anchor{swbreak stop reason}
35698The packet indicates a memory breakpoint instruction was executed,
35699irrespective of whether it was @value{GDBN} that planted the
35700breakpoint or the breakpoint is hardcoded in the program. The @var{r}
35701part must be left empty.
35702
35703On some architectures, such as x86, at the architecture level, when a
35704breakpoint instruction executes the program counter points at the
35705breakpoint address plus an offset. On such targets, the stub is
35706responsible for adjusting the PC to point back at the breakpoint
35707address.
35708
35709This packet should not be sent by default; older @value{GDBN} versions
35710did not support it. @value{GDBN} requests it, by supplying an
35711appropriate @samp{qSupported} feature (@pxref{qSupported}). The
35712remote stub must also supply the appropriate @samp{qSupported} feature
35713indicating support.
35714
35715This packet is required for correct non-stop mode operation.
35716
35717@item hwbreak
35718The packet indicates the target stopped for a hardware breakpoint.
35719The @var{r} part must be left empty.
35720
35721The same remarks about @samp{qSupported} and non-stop mode above
35722apply.
0d71eef5
DB
35723
35724@cindex fork events, remote reply
35725@item fork
35726The packet indicates that @code{fork} was called, and @var{r}
35727is the thread ID of the new child process. Refer to
35728@ref{thread-id syntax} for the format of the @var{thread-id}
35729field. This packet is only applicable to targets that support
35730fork events.
35731
35732This packet should not be sent by default; older @value{GDBN} versions
35733did not support it. @value{GDBN} requests it, by supplying an
35734appropriate @samp{qSupported} feature (@pxref{qSupported}). The
35735remote stub must also supply the appropriate @samp{qSupported} feature
35736indicating support.
35737
35738@cindex vfork events, remote reply
35739@item vfork
35740The packet indicates that @code{vfork} was called, and @var{r}
35741is the thread ID of the new child process. Refer to
35742@ref{thread-id syntax} for the format of the @var{thread-id}
35743field. This packet is only applicable to targets that support
35744vfork events.
35745
35746This packet should not be sent by default; older @value{GDBN} versions
35747did not support it. @value{GDBN} requests it, by supplying an
35748appropriate @samp{qSupported} feature (@pxref{qSupported}). The
35749remote stub must also supply the appropriate @samp{qSupported} feature
35750indicating support.
35751
35752@cindex vforkdone events, remote reply
35753@item vforkdone
e68fa6f0
PA
35754The packet indicates that a child process created by a vfork
35755has either called @code{exec} or terminated, so that the
35756address spaces of the parent and child process are no longer
35757shared. The @var{r} part is ignored. This packet is only
35758applicable to targets that support vforkdone events.
0d71eef5
DB
35759
35760This packet should not be sent by default; older @value{GDBN} versions
35761did not support it. @value{GDBN} requests it, by supplying an
35762appropriate @samp{qSupported} feature (@pxref{qSupported}). The
35763remote stub must also supply the appropriate @samp{qSupported} feature
35764indicating support.
35765
b459a59b
DB
35766@cindex exec events, remote reply
35767@item exec
35768The packet indicates that @code{execve} was called, and @var{r}
35769is the absolute pathname of the file that was executed, in hex.
35770This packet is only applicable to targets that support exec events.
35771
35772This packet should not be sent by default; older @value{GDBN} versions
35773did not support it. @value{GDBN} requests it, by supplying an
35774appropriate @samp{qSupported} feature (@pxref{qSupported}). The
35775remote stub must also supply the appropriate @samp{qSupported} feature
35776indicating support.
35777
65706a29
PA
35778@cindex thread create event, remote reply
35779@anchor{thread create event}
35780@item create
35781The packet indicates that the thread was just created. The new thread
35782is stopped until @value{GDBN} sets it running with a resumption packet
35783(@pxref{vCont packet}). This packet should not be sent by default;
35784@value{GDBN} requests it with the @ref{QThreadEvents} packet. See
35785also the @samp{w} (@ref{thread exit event}) remote reply below.
35786
cfa9d6d9 35787@end table
ee2d5c50 35788
b8ff78ce 35789@item W @var{AA}
b90a069a 35790@itemx W @var{AA} ; process:@var{pid}
8e04817f 35791The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
35792applicable to certain targets.
35793
b90a069a
SL
35794The second form of the response, including the process ID of the exited
35795process, can be used only when @value{GDBN} has reported support for
35796multiprocess protocol extensions; see @ref{multiprocess extensions}.
35797The @var{pid} is formatted as a big-endian hex string.
35798
b8ff78ce 35799@item X @var{AA}
b90a069a 35800@itemx X @var{AA} ; process:@var{pid}
8e04817f 35801The process terminated with signal @var{AA}.
c906108c 35802
b90a069a
SL
35803The second form of the response, including the process ID of the
35804terminated process, can be used only when @value{GDBN} has reported
35805support for multiprocess protocol extensions; see @ref{multiprocess
35806extensions}. The @var{pid} is formatted as a big-endian hex string.
35807
65706a29
PA
35808@anchor{thread exit event}
35809@cindex thread exit event, remote reply
35810@item w @var{AA} ; @var{tid}
35811
35812The thread exited, and @var{AA} is the exit status. This response
35813should not be sent by default; @value{GDBN} requests it with the
35814@ref{QThreadEvents} packet. See also @ref{thread create event} above.
35815
f2faf941
PA
35816@item N
35817There are no resumed threads left in the target. In other words, even
35818though the process is alive, the last resumed thread has exited. For
35819example, say the target process has two threads: thread 1 and thread
358202. The client leaves thread 1 stopped, and resumes thread 2, which
35821subsequently exits. At this point, even though the process is still
35822alive, and thus no @samp{W} stop reply is sent, no thread is actually
35823executing either. The @samp{N} stop reply thus informs the client
35824that it can stop waiting for stop replies. This packet should not be
35825sent by default; older @value{GDBN} versions did not support it.
35826@value{GDBN} requests it, by supplying an appropriate
35827@samp{qSupported} feature (@pxref{qSupported}). The remote stub must
35828also supply the appropriate @samp{qSupported} feature indicating
35829support.
35830
b8ff78ce
JB
35831@item O @var{XX}@dots{}
35832@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
35833written as the program's console output. This can happen at any time
35834while the program is running and the debugger should continue to wait
8b23ecc4 35835for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
0ce1b118 35836
b8ff78ce 35837@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
35838@var{call-id} is the identifier which says which host system call should
35839be called. This is just the name of the function. Translation into the
35840correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 35841@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
35842system calls.
35843
b8ff78ce
JB
35844@samp{@var{parameter}@dots{}} is a list of parameters as defined for
35845this very system call.
0ce1b118 35846
b8ff78ce
JB
35847The target replies with this packet when it expects @value{GDBN} to
35848call a host system call on behalf of the target. @value{GDBN} replies
35849with an appropriate @samp{F} packet and keeps up waiting for the next
35850reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
35851or @samp{s} action is expected to be continued. @xref{File-I/O Remote
35852Protocol Extension}, for more details.
0ce1b118 35853
ee2d5c50
AC
35854@end table
35855
35856@node General Query Packets
35857@section General Query Packets
9c16f35a 35858@cindex remote query requests
c906108c 35859
5f3bebba
JB
35860Packets starting with @samp{q} are @dfn{general query packets};
35861packets starting with @samp{Q} are @dfn{general set packets}. General
35862query and set packets are a semi-unified form for retrieving and
35863sending information to and from the stub.
35864
35865The initial letter of a query or set packet is followed by a name
35866indicating what sort of thing the packet applies to. For example,
35867@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
35868definitions with the stub. These packet names follow some
35869conventions:
35870
35871@itemize @bullet
35872@item
35873The name must not contain commas, colons or semicolons.
35874@item
35875Most @value{GDBN} query and set packets have a leading upper case
35876letter.
35877@item
35878The names of custom vendor packets should use a company prefix, in
35879lower case, followed by a period. For example, packets designed at
35880the Acme Corporation might begin with @samp{qacme.foo} (for querying
35881foos) or @samp{Qacme.bar} (for setting bars).
35882@end itemize
35883
aa56d27a
JB
35884The name of a query or set packet should be separated from any
35885parameters by a @samp{:}; the parameters themselves should be
35886separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
35887full packet name, and check for a separator or the end of the packet,
35888in case two packet names share a common prefix. New packets should not begin
35889with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
35890packets predate these conventions, and have arguments without any terminator
35891for the packet name; we suspect they are in widespread use in places that
35892are difficult to upgrade. The @samp{qC} packet has no arguments, but some
35893existing stubs (e.g.@: RedBoot) are known to not check for the end of the
35894packet.}.
c906108c 35895
b8ff78ce
JB
35896Like the descriptions of the other packets, each description here
35897has a template showing the packet's overall syntax, followed by an
35898explanation of the packet's meaning. We include spaces in some of the
35899templates for clarity; these are not part of the packet's syntax. No
35900@value{GDBN} packet uses spaces to separate its components.
35901
5f3bebba
JB
35902Here are the currently defined query and set packets:
35903
b8ff78ce 35904@table @samp
c906108c 35905
d1feda86 35906@item QAgent:1
af4238e5 35907@itemx QAgent:0
d1feda86
YQ
35908Turn on or off the agent as a helper to perform some debugging operations
35909delegated from @value{GDBN} (@pxref{Control Agent}).
35910
d914c394
SS
35911@item QAllow:@var{op}:@var{val}@dots{}
35912@cindex @samp{QAllow} packet
35913Specify which operations @value{GDBN} expects to request of the
35914target, as a semicolon-separated list of operation name and value
35915pairs. Possible values for @var{op} include @samp{WriteReg},
35916@samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
35917@samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
35918indicating that @value{GDBN} will not request the operation, or 1,
35919indicating that it may. (The target can then use this to set up its
35920own internals optimally, for instance if the debugger never expects to
35921insert breakpoints, it may not need to install its own trap handler.)
35922
b8ff78ce 35923@item qC
9c16f35a 35924@cindex current thread, remote request
b8ff78ce 35925@cindex @samp{qC} packet
b90a069a 35926Return the current thread ID.
ee2d5c50
AC
35927
35928Reply:
35929@table @samp
b90a069a
SL
35930@item QC @var{thread-id}
35931Where @var{thread-id} is a thread ID as documented in
35932@ref{thread-id syntax}.
b8ff78ce 35933@item @r{(anything else)}
b90a069a 35934Any other reply implies the old thread ID.
ee2d5c50
AC
35935@end table
35936
b8ff78ce 35937@item qCRC:@var{addr},@var{length}
ff2587ec 35938@cindex CRC of memory block, remote request
b8ff78ce 35939@cindex @samp{qCRC} packet
936d2992 35940@anchor{qCRC packet}
99e008fe
EZ
35941Compute the CRC checksum of a block of memory using CRC-32 defined in
35942IEEE 802.3. The CRC is computed byte at a time, taking the most
35943significant bit of each byte first. The initial pattern code
35944@code{0xffffffff} is used to ensure leading zeros affect the CRC.
35945
35946@emph{Note:} This is the same CRC used in validating separate debug
35947files (@pxref{Separate Debug Files, , Debugging Information in Separate
35948Files}). However the algorithm is slightly different. When validating
35949separate debug files, the CRC is computed taking the @emph{least}
35950significant bit of each byte first, and the final result is inverted to
35951detect trailing zeros.
35952
ff2587ec
WZ
35953Reply:
35954@table @samp
b8ff78ce 35955@item E @var{NN}
ff2587ec 35956An error (such as memory fault)
b8ff78ce
JB
35957@item C @var{crc32}
35958The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
35959@end table
35960
03583c20
UW
35961@item QDisableRandomization:@var{value}
35962@cindex disable address space randomization, remote request
35963@cindex @samp{QDisableRandomization} packet
35964Some target operating systems will randomize the virtual address space
35965of the inferior process as a security feature, but provide a feature
35966to disable such randomization, e.g.@: to allow for a more deterministic
35967debugging experience. On such systems, this packet with a @var{value}
35968of 1 directs the target to disable address space randomization for
35969processes subsequently started via @samp{vRun} packets, while a packet
35970with a @var{value} of 0 tells the target to enable address space
35971randomization.
35972
35973This packet is only available in extended mode (@pxref{extended mode}).
35974
35975Reply:
35976@table @samp
35977@item OK
35978The request succeeded.
35979
35980@item E @var{nn}
697aa1b7 35981An error occurred. The error number @var{nn} is given as hex digits.
03583c20 35982
d57350ea 35983@item @w{}
03583c20
UW
35984An empty reply indicates that @samp{QDisableRandomization} is not supported
35985by the stub.
35986@end table
35987
35988This packet is not probed by default; the remote stub must request it,
35989by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35990This should only be done on targets that actually support disabling
35991address space randomization.
35992
b8ff78ce
JB
35993@item qfThreadInfo
35994@itemx qsThreadInfo
9c16f35a 35995@cindex list active threads, remote request
b8ff78ce
JB
35996@cindex @samp{qfThreadInfo} packet
35997@cindex @samp{qsThreadInfo} packet
b90a069a 35998Obtain a list of all active thread IDs from the target (OS). Since there
8e04817f
AC
35999may be too many active threads to fit into one reply packet, this query
36000works iteratively: it may require more than one query/reply sequence to
36001obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
36002be the @samp{qfThreadInfo} query; subsequent queries in the
36003sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 36004
b8ff78ce 36005NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
36006
36007Reply:
36008@table @samp
b90a069a
SL
36009@item m @var{thread-id}
36010A single thread ID
36011@item m @var{thread-id},@var{thread-id}@dots{}
36012a comma-separated list of thread IDs
b8ff78ce
JB
36013@item l
36014(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
36015@end table
36016
36017In response to each query, the target will reply with a list of one or
b90a069a 36018more thread IDs, separated by commas.
e1aac25b 36019@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce 36020ids (using the @samp{qs} form of the query), until the target responds
501994c0 36021with @samp{l} (lower-case ell, for @dfn{last}).
b90a069a
SL
36022Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
36023fields.
c906108c 36024
8dfcab11
DT
36025@emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
36026initial connection with the remote target, and the very first thread ID
36027mentioned in the reply will be stopped by @value{GDBN} in a subsequent
36028message. Therefore, the stub should ensure that the first thread ID in
36029the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
36030
b8ff78ce 36031@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 36032@cindex get thread-local storage address, remote request
b8ff78ce 36033@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
36034Fetch the address associated with thread local storage specified
36035by @var{thread-id}, @var{offset}, and @var{lm}.
36036
b90a069a
SL
36037@var{thread-id} is the thread ID associated with the
36038thread for which to fetch the TLS address. @xref{thread-id syntax}.
ff2587ec
WZ
36039
36040@var{offset} is the (big endian, hex encoded) offset associated with the
36041thread local variable. (This offset is obtained from the debug
36042information associated with the variable.)
36043
db2e3e2e 36044@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
7a9dd1b2 36045load module associated with the thread local storage. For example,
ff2587ec
WZ
36046a @sc{gnu}/Linux system will pass the link map address of the shared
36047object associated with the thread local storage under consideration.
36048Other operating environments may choose to represent the load module
36049differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
36050
36051Reply:
b8ff78ce
JB
36052@table @samp
36053@item @var{XX}@dots{}
ff2587ec
WZ
36054Hex encoded (big endian) bytes representing the address of the thread
36055local storage requested.
36056
b8ff78ce 36057@item E @var{nn}
697aa1b7 36058An error occurred. The error number @var{nn} is given as hex digits.
ff2587ec 36059
d57350ea 36060@item @w{}
b8ff78ce 36061An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
36062@end table
36063
711e434b
PM
36064@item qGetTIBAddr:@var{thread-id}
36065@cindex get thread information block address
36066@cindex @samp{qGetTIBAddr} packet
36067Fetch address of the Windows OS specific Thread Information Block.
36068
36069@var{thread-id} is the thread ID associated with the thread.
36070
36071Reply:
36072@table @samp
36073@item @var{XX}@dots{}
36074Hex encoded (big endian) bytes representing the linear address of the
36075thread information block.
36076
36077@item E @var{nn}
36078An error occured. This means that either the thread was not found, or the
36079address could not be retrieved.
36080
d57350ea 36081@item @w{}
711e434b
PM
36082An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
36083@end table
36084
b8ff78ce 36085@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
36086Obtain thread information from RTOS. Where: @var{startflag} (one hex
36087digit) is one to indicate the first query and zero to indicate a
36088subsequent query; @var{threadcount} (two hex digits) is the maximum
36089number of threads the response packet can contain; and @var{nextthread}
36090(eight hex digits), for subsequent queries (@var{startflag} is zero), is
36091returned in the response as @var{argthread}.
ee2d5c50 36092
b8ff78ce 36093Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
36094
36095Reply:
36096@table @samp
b8ff78ce 36097@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
36098Where: @var{count} (two hex digits) is the number of threads being
36099returned; @var{done} (one hex digit) is zero to indicate more threads
36100and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 36101digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
697aa1b7
EZ
36102is a sequence of thread IDs, @var{threadid} (eight hex
36103digits), from the target. See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 36104@end table
c906108c 36105
b8ff78ce 36106@item qOffsets
9c16f35a 36107@cindex section offsets, remote request
b8ff78ce 36108@cindex @samp{qOffsets} packet
31d99776
DJ
36109Get section offsets that the target used when relocating the downloaded
36110image.
c906108c 36111
ee2d5c50
AC
36112Reply:
36113@table @samp
31d99776
DJ
36114@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
36115Relocate the @code{Text} section by @var{xxx} from its original address.
36116Relocate the @code{Data} section by @var{yyy} from its original address.
36117If the object file format provides segment information (e.g.@: @sc{elf}
36118@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
36119segments by the supplied offsets.
36120
36121@emph{Note: while a @code{Bss} offset may be included in the response,
36122@value{GDBN} ignores this and instead applies the @code{Data} offset
36123to the @code{Bss} section.}
36124
36125@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
36126Relocate the first segment of the object file, which conventionally
36127contains program code, to a starting address of @var{xxx}. If
36128@samp{DataSeg} is specified, relocate the second segment, which
36129conventionally contains modifiable data, to a starting address of
36130@var{yyy}. @value{GDBN} will report an error if the object file
36131does not contain segment information, or does not contain at least
36132as many segments as mentioned in the reply. Extra segments are
36133kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
36134@end table
36135
b90a069a 36136@item qP @var{mode} @var{thread-id}
9c16f35a 36137@cindex thread information, remote request
b8ff78ce 36138@cindex @samp{qP} packet
b90a069a
SL
36139Returns information on @var{thread-id}. Where: @var{mode} is a hex
36140encoded 32 bit mode; @var{thread-id} is a thread ID
36141(@pxref{thread-id syntax}).
ee2d5c50 36142
aa56d27a
JB
36143Don't use this packet; use the @samp{qThreadExtraInfo} query instead
36144(see below).
36145
b8ff78ce 36146Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 36147
8b23ecc4 36148@item QNonStop:1
687e43a4 36149@itemx QNonStop:0
8b23ecc4
SL
36150@cindex non-stop mode, remote request
36151@cindex @samp{QNonStop} packet
36152@anchor{QNonStop}
36153Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
36154@xref{Remote Non-Stop}, for more information.
36155
36156Reply:
36157@table @samp
36158@item OK
36159The request succeeded.
36160
36161@item E @var{nn}
697aa1b7 36162An error occurred. The error number @var{nn} is given as hex digits.
8b23ecc4 36163
d57350ea 36164@item @w{}
8b23ecc4
SL
36165An empty reply indicates that @samp{QNonStop} is not supported by
36166the stub.
36167@end table
36168
36169This packet is not probed by default; the remote stub must request it,
36170by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
36171Use of this packet is controlled by the @code{set non-stop} command;
36172@pxref{Non-Stop Mode}.
36173
82075af2
JS
36174@item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
36175@itemx QCatchSyscalls:0
36176@cindex catch syscalls from inferior, remote request
36177@cindex @samp{QCatchSyscalls} packet
36178@anchor{QCatchSyscalls}
36179Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
36180catching syscalls from the inferior process.
36181
36182For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
36183in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
36184is listed, every system call should be reported.
36185
36186Note that if a syscall not in the list is reported, @value{GDBN} will
36187still filter the event according to its own list from all corresponding
36188@code{catch syscall} commands. However, it is more efficient to only
36189report the requested syscalls.
36190
36191Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
36192@samp{QCatchSyscalls:1} list is completely replaced by the new list.
36193
36194If the inferior process execs, the state of @samp{QCatchSyscalls} is
36195kept for the new process too. On targets where exec may affect syscall
36196numbers, for example with exec between 32 and 64-bit processes, the
36197client should send a new packet with the new syscall list.
36198
36199Reply:
36200@table @samp
36201@item OK
36202The request succeeded.
36203
36204@item E @var{nn}
36205An error occurred. @var{nn} are hex digits.
36206
36207@item @w{}
36208An empty reply indicates that @samp{QCatchSyscalls} is not supported by
36209the stub.
36210@end table
36211
36212Use of this packet is controlled by the @code{set remote catch-syscalls}
36213command (@pxref{Remote Configuration, set remote catch-syscalls}).
36214This packet is not probed by default; the remote stub must request it,
36215by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
36216
89be2091
DJ
36217@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
36218@cindex pass signals to inferior, remote request
36219@cindex @samp{QPassSignals} packet
23181151 36220@anchor{QPassSignals}
89be2091
DJ
36221Each listed @var{signal} should be passed directly to the inferior process.
36222Signals are numbered identically to continue packets and stop replies
36223(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
36224strictly greater than the previous item. These signals do not need to stop
36225the inferior, or be reported to @value{GDBN}. All other signals should be
36226reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
36227combine; any earlier @samp{QPassSignals} list is completely replaced by the
36228new list. This packet improves performance when using @samp{handle
36229@var{signal} nostop noprint pass}.
36230
36231Reply:
36232@table @samp
36233@item OK
36234The request succeeded.
36235
36236@item E @var{nn}
697aa1b7 36237An error occurred. The error number @var{nn} is given as hex digits.
89be2091 36238
d57350ea 36239@item @w{}
89be2091
DJ
36240An empty reply indicates that @samp{QPassSignals} is not supported by
36241the stub.
36242@end table
36243
36244Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 36245command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
36246This packet is not probed by default; the remote stub must request it,
36247by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
36248
9b224c5e
PA
36249@item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
36250@cindex signals the inferior may see, remote request
36251@cindex @samp{QProgramSignals} packet
36252@anchor{QProgramSignals}
36253Each listed @var{signal} may be delivered to the inferior process.
36254Others should be silently discarded.
36255
36256In some cases, the remote stub may need to decide whether to deliver a
36257signal to the program or not without @value{GDBN} involvement. One
36258example of that is while detaching --- the program's threads may have
36259stopped for signals that haven't yet had a chance of being reported to
36260@value{GDBN}, and so the remote stub can use the signal list specified
36261by this packet to know whether to deliver or ignore those pending
36262signals.
36263
36264This does not influence whether to deliver a signal as requested by a
36265resumption packet (@pxref{vCont packet}).
36266
36267Signals are numbered identically to continue packets and stop replies
36268(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
36269strictly greater than the previous item. Multiple
36270@samp{QProgramSignals} packets do not combine; any earlier
36271@samp{QProgramSignals} list is completely replaced by the new list.
36272
36273Reply:
36274@table @samp
36275@item OK
36276The request succeeded.
36277
36278@item E @var{nn}
697aa1b7 36279An error occurred. The error number @var{nn} is given as hex digits.
9b224c5e 36280
d57350ea 36281@item @w{}
9b224c5e
PA
36282An empty reply indicates that @samp{QProgramSignals} is not supported
36283by the stub.
36284@end table
36285
36286Use of this packet is controlled by the @code{set remote program-signals}
36287command (@pxref{Remote Configuration, set remote program-signals}).
36288This packet is not probed by default; the remote stub must request it,
36289by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
36290
65706a29
PA
36291@anchor{QThreadEvents}
36292@item QThreadEvents:1
36293@itemx QThreadEvents:0
36294@cindex thread create/exit events, remote request
36295@cindex @samp{QThreadEvents} packet
36296
36297Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
36298reporting of thread create and exit events. @xref{thread create
36299event}, for the reply specifications. For example, this is used in
36300non-stop mode when @value{GDBN} stops a set of threads and
36301synchronously waits for the their corresponding stop replies. Without
36302exit events, if one of the threads exits, @value{GDBN} would hang
36303forever not knowing that it should no longer expect a stop for that
36304same thread. @value{GDBN} does not enable this feature unless the
36305stub reports that it supports it by including @samp{QThreadEvents+} in
36306its @samp{qSupported} reply.
36307
36308Reply:
36309@table @samp
36310@item OK
36311The request succeeded.
36312
36313@item E @var{nn}
36314An error occurred. The error number @var{nn} is given as hex digits.
36315
36316@item @w{}
36317An empty reply indicates that @samp{QThreadEvents} is not supported by
36318the stub.
36319@end table
36320
36321Use of this packet is controlled by the @code{set remote thread-events}
36322command (@pxref{Remote Configuration, set remote thread-events}).
36323
b8ff78ce 36324@item qRcmd,@var{command}
ff2587ec 36325@cindex execute remote command, remote request
b8ff78ce 36326@cindex @samp{qRcmd} packet
ff2587ec 36327@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
36328execution. Invalid commands should be reported using the output
36329string. Before the final result packet, the target may also respond
36330with a number of intermediate @samp{O@var{output}} console output
36331packets. @emph{Implementors should note that providing access to a
36332stubs's interpreter may have security implications}.
fa93a9d8 36333
ff2587ec
WZ
36334Reply:
36335@table @samp
36336@item OK
36337A command response with no output.
36338@item @var{OUTPUT}
36339A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 36340@item E @var{NN}
ff2587ec 36341Indicate a badly formed request.
d57350ea 36342@item @w{}
b8ff78ce 36343An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 36344@end table
fa93a9d8 36345
aa56d27a
JB
36346(Note that the @code{qRcmd} packet's name is separated from the
36347command by a @samp{,}, not a @samp{:}, contrary to the naming
36348conventions above. Please don't use this packet as a model for new
36349packets.)
36350
08388c79
DE
36351@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
36352@cindex searching memory, in remote debugging
5c4808ca 36353@ifnotinfo
08388c79 36354@cindex @samp{qSearch:memory} packet
5c4808ca
EZ
36355@end ifnotinfo
36356@cindex @samp{qSearch memory} packet
08388c79
DE
36357@anchor{qSearch memory}
36358Search @var{length} bytes at @var{address} for @var{search-pattern}.
697aa1b7
EZ
36359Both @var{address} and @var{length} are encoded in hex;
36360@var{search-pattern} is a sequence of bytes, also hex encoded.
08388c79
DE
36361
36362Reply:
36363@table @samp
36364@item 0
36365The pattern was not found.
36366@item 1,address
36367The pattern was found at @var{address}.
36368@item E @var{NN}
36369A badly formed request or an error was encountered while searching memory.
d57350ea 36370@item @w{}
08388c79
DE
36371An empty reply indicates that @samp{qSearch:memory} is not recognized.
36372@end table
36373
a6f3e723
SL
36374@item QStartNoAckMode
36375@cindex @samp{QStartNoAckMode} packet
36376@anchor{QStartNoAckMode}
36377Request that the remote stub disable the normal @samp{+}/@samp{-}
36378protocol acknowledgments (@pxref{Packet Acknowledgment}).
36379
36380Reply:
36381@table @samp
36382@item OK
36383The stub has switched to no-acknowledgment mode.
36384@value{GDBN} acknowledges this reponse,
36385but neither the stub nor @value{GDBN} shall send or expect further
36386@samp{+}/@samp{-} acknowledgments in the current connection.
d57350ea 36387@item @w{}
a6f3e723
SL
36388An empty reply indicates that the stub does not support no-acknowledgment mode.
36389@end table
36390
be2a5f71
DJ
36391@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
36392@cindex supported packets, remote query
36393@cindex features of the remote protocol
36394@cindex @samp{qSupported} packet
0876f84a 36395@anchor{qSupported}
be2a5f71
DJ
36396Tell the remote stub about features supported by @value{GDBN}, and
36397query the stub for features it supports. This packet allows
36398@value{GDBN} and the remote stub to take advantage of each others'
36399features. @samp{qSupported} also consolidates multiple feature probes
36400at startup, to improve @value{GDBN} performance---a single larger
36401packet performs better than multiple smaller probe packets on
36402high-latency links. Some features may enable behavior which must not
36403be on by default, e.g.@: because it would confuse older clients or
36404stubs. Other features may describe packets which could be
36405automatically probed for, but are not. These features must be
36406reported before @value{GDBN} will use them. This ``default
36407unsupported'' behavior is not appropriate for all packets, but it
36408helps to keep the initial connection time under control with new
36409versions of @value{GDBN} which support increasing numbers of packets.
36410
36411Reply:
36412@table @samp
36413@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
36414The stub supports or does not support each returned @var{stubfeature},
36415depending on the form of each @var{stubfeature} (see below for the
36416possible forms).
d57350ea 36417@item @w{}
be2a5f71
DJ
36418An empty reply indicates that @samp{qSupported} is not recognized,
36419or that no features needed to be reported to @value{GDBN}.
36420@end table
36421
36422The allowed forms for each feature (either a @var{gdbfeature} in the
36423@samp{qSupported} packet, or a @var{stubfeature} in the response)
36424are:
36425
36426@table @samp
36427@item @var{name}=@var{value}
36428The remote protocol feature @var{name} is supported, and associated
36429with the specified @var{value}. The format of @var{value} depends
36430on the feature, but it must not include a semicolon.
36431@item @var{name}+
36432The remote protocol feature @var{name} is supported, and does not
36433need an associated value.
36434@item @var{name}-
36435The remote protocol feature @var{name} is not supported.
36436@item @var{name}?
36437The remote protocol feature @var{name} may be supported, and
36438@value{GDBN} should auto-detect support in some other way when it is
36439needed. This form will not be used for @var{gdbfeature} notifications,
36440but may be used for @var{stubfeature} responses.
36441@end table
36442
36443Whenever the stub receives a @samp{qSupported} request, the
36444supplied set of @value{GDBN} features should override any previous
36445request. This allows @value{GDBN} to put the stub in a known
36446state, even if the stub had previously been communicating with
36447a different version of @value{GDBN}.
36448
b90a069a
SL
36449The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
36450are defined:
36451
36452@table @samp
36453@item multiprocess
36454This feature indicates whether @value{GDBN} supports multiprocess
36455extensions to the remote protocol. @value{GDBN} does not use such
36456extensions unless the stub also reports that it supports them by
36457including @samp{multiprocess+} in its @samp{qSupported} reply.
36458@xref{multiprocess extensions}, for details.
c8d5aac9
L
36459
36460@item xmlRegisters
36461This feature indicates that @value{GDBN} supports the XML target
36462description. If the stub sees @samp{xmlRegisters=} with target
36463specific strings separated by a comma, it will report register
36464description.
dde08ee1
PA
36465
36466@item qRelocInsn
36467This feature indicates whether @value{GDBN} supports the
36468@samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
36469instruction reply packet}).
f7e6eed5
PA
36470
36471@item swbreak
36472This feature indicates whether @value{GDBN} supports the swbreak stop
36473reason in stop replies. @xref{swbreak stop reason}, for details.
36474
36475@item hwbreak
36476This feature indicates whether @value{GDBN} supports the hwbreak stop
36477reason in stop replies. @xref{swbreak stop reason}, for details.
0d71eef5
DB
36478
36479@item fork-events
36480This feature indicates whether @value{GDBN} supports fork event
36481extensions to the remote protocol. @value{GDBN} does not use such
36482extensions unless the stub also reports that it supports them by
36483including @samp{fork-events+} in its @samp{qSupported} reply.
36484
36485@item vfork-events
36486This feature indicates whether @value{GDBN} supports vfork event
36487extensions to the remote protocol. @value{GDBN} does not use such
36488extensions unless the stub also reports that it supports them by
36489including @samp{vfork-events+} in its @samp{qSupported} reply.
b459a59b
DB
36490
36491@item exec-events
36492This feature indicates whether @value{GDBN} supports exec event
36493extensions to the remote protocol. @value{GDBN} does not use such
36494extensions unless the stub also reports that it supports them by
36495including @samp{exec-events+} in its @samp{qSupported} reply.
750ce8d1
YQ
36496
36497@item vContSupported
36498This feature indicates whether @value{GDBN} wants to know the
36499supported actions in the reply to @samp{vCont?} packet.
b90a069a
SL
36500@end table
36501
36502Stubs should ignore any unknown values for
be2a5f71
DJ
36503@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
36504packet supports receiving packets of unlimited length (earlier
b90a069a 36505versions of @value{GDBN} may reject overly long responses). Additional values
be2a5f71
DJ
36506for @var{gdbfeature} may be defined in the future to let the stub take
36507advantage of new features in @value{GDBN}, e.g.@: incompatible
b90a069a
SL
36508improvements in the remote protocol---the @samp{multiprocess} feature is
36509an example of such a feature. The stub's reply should be independent
be2a5f71
DJ
36510of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
36511describes all the features it supports, and then the stub replies with
36512all the features it supports.
36513
36514Similarly, @value{GDBN} will silently ignore unrecognized stub feature
36515responses, as long as each response uses one of the standard forms.
36516
36517Some features are flags. A stub which supports a flag feature
36518should respond with a @samp{+} form response. Other features
36519require values, and the stub should respond with an @samp{=}
36520form response.
36521
36522Each feature has a default value, which @value{GDBN} will use if
36523@samp{qSupported} is not available or if the feature is not mentioned
36524in the @samp{qSupported} response. The default values are fixed; a
36525stub is free to omit any feature responses that match the defaults.
36526
36527Not all features can be probed, but for those which can, the probing
36528mechanism is useful: in some cases, a stub's internal
36529architecture may not allow the protocol layer to know some information
36530about the underlying target in advance. This is especially common in
36531stubs which may be configured for multiple targets.
36532
36533These are the currently defined stub features and their properties:
36534
cfa9d6d9 36535@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
36536@c NOTE: The first row should be @headitem, but we do not yet require
36537@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 36538@item Feature Name
be2a5f71
DJ
36539@tab Value Required
36540@tab Default
36541@tab Probe Allowed
36542
36543@item @samp{PacketSize}
36544@tab Yes
36545@tab @samp{-}
36546@tab No
36547
0876f84a
DJ
36548@item @samp{qXfer:auxv:read}
36549@tab No
36550@tab @samp{-}
36551@tab Yes
36552
2ae8c8e7
MM
36553@item @samp{qXfer:btrace:read}
36554@tab No
36555@tab @samp{-}
36556@tab Yes
36557
f4abbc16
MM
36558@item @samp{qXfer:btrace-conf:read}
36559@tab No
36560@tab @samp{-}
36561@tab Yes
36562
c78fa86a
GB
36563@item @samp{qXfer:exec-file:read}
36564@tab No
36565@tab @samp{-}
36566@tab Yes
36567
23181151
DJ
36568@item @samp{qXfer:features:read}
36569@tab No
36570@tab @samp{-}
36571@tab Yes
36572
cfa9d6d9
DJ
36573@item @samp{qXfer:libraries:read}
36574@tab No
36575@tab @samp{-}
36576@tab Yes
36577
85dc5a12
GB
36578@item @samp{qXfer:libraries-svr4:read}
36579@tab No
36580@tab @samp{-}
36581@tab Yes
36582
36583@item @samp{augmented-libraries-svr4-read}
36584@tab No
36585@tab @samp{-}
36586@tab No
36587
68437a39
DJ
36588@item @samp{qXfer:memory-map:read}
36589@tab No
36590@tab @samp{-}
36591@tab Yes
36592
0fb4aa4b
PA
36593@item @samp{qXfer:sdata:read}
36594@tab No
36595@tab @samp{-}
36596@tab Yes
36597
0e7f50da
UW
36598@item @samp{qXfer:spu:read}
36599@tab No
36600@tab @samp{-}
36601@tab Yes
36602
36603@item @samp{qXfer:spu:write}
36604@tab No
36605@tab @samp{-}
36606@tab Yes
36607
4aa995e1
PA
36608@item @samp{qXfer:siginfo:read}
36609@tab No
36610@tab @samp{-}
36611@tab Yes
36612
36613@item @samp{qXfer:siginfo:write}
36614@tab No
36615@tab @samp{-}
36616@tab Yes
36617
dc146f7c
VP
36618@item @samp{qXfer:threads:read}
36619@tab No
36620@tab @samp{-}
36621@tab Yes
36622
b3b9301e
PA
36623@item @samp{qXfer:traceframe-info:read}
36624@tab No
36625@tab @samp{-}
36626@tab Yes
36627
169081d0
TG
36628@item @samp{qXfer:uib:read}
36629@tab No
36630@tab @samp{-}
36631@tab Yes
36632
78d85199
YQ
36633@item @samp{qXfer:fdpic:read}
36634@tab No
36635@tab @samp{-}
36636@tab Yes
dc146f7c 36637
2ae8c8e7
MM
36638@item @samp{Qbtrace:off}
36639@tab Yes
36640@tab @samp{-}
36641@tab Yes
36642
36643@item @samp{Qbtrace:bts}
36644@tab Yes
36645@tab @samp{-}
36646@tab Yes
36647
b20a6524
MM
36648@item @samp{Qbtrace:pt}
36649@tab Yes
36650@tab @samp{-}
36651@tab Yes
36652
d33501a5
MM
36653@item @samp{Qbtrace-conf:bts:size}
36654@tab Yes
36655@tab @samp{-}
36656@tab Yes
36657
b20a6524
MM
36658@item @samp{Qbtrace-conf:pt:size}
36659@tab Yes
36660@tab @samp{-}
36661@tab Yes
36662
8b23ecc4
SL
36663@item @samp{QNonStop}
36664@tab No
36665@tab @samp{-}
36666@tab Yes
36667
82075af2
JS
36668@item @samp{QCatchSyscalls}
36669@tab No
36670@tab @samp{-}
36671@tab Yes
36672
89be2091
DJ
36673@item @samp{QPassSignals}
36674@tab No
36675@tab @samp{-}
36676@tab Yes
36677
a6f3e723
SL
36678@item @samp{QStartNoAckMode}
36679@tab No
36680@tab @samp{-}
36681@tab Yes
36682
b90a069a
SL
36683@item @samp{multiprocess}
36684@tab No
36685@tab @samp{-}
36686@tab No
36687
83364271
LM
36688@item @samp{ConditionalBreakpoints}
36689@tab No
36690@tab @samp{-}
36691@tab No
36692
782b2b07
SS
36693@item @samp{ConditionalTracepoints}
36694@tab No
36695@tab @samp{-}
36696@tab No
36697
0d772ac9
MS
36698@item @samp{ReverseContinue}
36699@tab No
2f8132f3 36700@tab @samp{-}
0d772ac9
MS
36701@tab No
36702
36703@item @samp{ReverseStep}
36704@tab No
2f8132f3 36705@tab @samp{-}
0d772ac9
MS
36706@tab No
36707
409873ef
SS
36708@item @samp{TracepointSource}
36709@tab No
36710@tab @samp{-}
36711@tab No
36712
d1feda86
YQ
36713@item @samp{QAgent}
36714@tab No
36715@tab @samp{-}
36716@tab No
36717
d914c394
SS
36718@item @samp{QAllow}
36719@tab No
36720@tab @samp{-}
36721@tab No
36722
03583c20
UW
36723@item @samp{QDisableRandomization}
36724@tab No
36725@tab @samp{-}
36726@tab No
36727
d248b706
KY
36728@item @samp{EnableDisableTracepoints}
36729@tab No
36730@tab @samp{-}
36731@tab No
36732
f6f899bf
HAQ
36733@item @samp{QTBuffer:size}
36734@tab No
36735@tab @samp{-}
36736@tab No
36737
3065dfb6
SS
36738@item @samp{tracenz}
36739@tab No
36740@tab @samp{-}
36741@tab No
36742
d3ce09f5
SS
36743@item @samp{BreakpointCommands}
36744@tab No
36745@tab @samp{-}
36746@tab No
36747
f7e6eed5
PA
36748@item @samp{swbreak}
36749@tab No
36750@tab @samp{-}
36751@tab No
36752
36753@item @samp{hwbreak}
36754@tab No
36755@tab @samp{-}
36756@tab No
36757
0d71eef5
DB
36758@item @samp{fork-events}
36759@tab No
36760@tab @samp{-}
36761@tab No
36762
36763@item @samp{vfork-events}
36764@tab No
36765@tab @samp{-}
36766@tab No
36767
b459a59b
DB
36768@item @samp{exec-events}
36769@tab No
36770@tab @samp{-}
36771@tab No
36772
65706a29
PA
36773@item @samp{QThreadEvents}
36774@tab No
36775@tab @samp{-}
36776@tab No
36777
f2faf941
PA
36778@item @samp{no-resumed}
36779@tab No
36780@tab @samp{-}
36781@tab No
36782
be2a5f71
DJ
36783@end multitable
36784
36785These are the currently defined stub features, in more detail:
36786
36787@table @samp
36788@cindex packet size, remote protocol
36789@item PacketSize=@var{bytes}
36790The remote stub can accept packets up to at least @var{bytes} in
36791length. @value{GDBN} will send packets up to this size for bulk
36792transfers, and will never send larger packets. This is a limit on the
36793data characters in the packet, including the frame and checksum.
36794There is no trailing NUL byte in a remote protocol packet; if the stub
36795stores packets in a NUL-terminated format, it should allow an extra
36796byte in its buffer for the NUL. If this stub feature is not supported,
36797@value{GDBN} guesses based on the size of the @samp{g} packet response.
36798
0876f84a
DJ
36799@item qXfer:auxv:read
36800The remote stub understands the @samp{qXfer:auxv:read} packet
36801(@pxref{qXfer auxiliary vector read}).
36802
2ae8c8e7
MM
36803@item qXfer:btrace:read
36804The remote stub understands the @samp{qXfer:btrace:read}
36805packet (@pxref{qXfer btrace read}).
36806
f4abbc16
MM
36807@item qXfer:btrace-conf:read
36808The remote stub understands the @samp{qXfer:btrace-conf:read}
36809packet (@pxref{qXfer btrace-conf read}).
36810
c78fa86a
GB
36811@item qXfer:exec-file:read
36812The remote stub understands the @samp{qXfer:exec-file:read} packet
36813(@pxref{qXfer executable filename read}).
36814
23181151
DJ
36815@item qXfer:features:read
36816The remote stub understands the @samp{qXfer:features:read} packet
36817(@pxref{qXfer target description read}).
36818
cfa9d6d9
DJ
36819@item qXfer:libraries:read
36820The remote stub understands the @samp{qXfer:libraries:read} packet
36821(@pxref{qXfer library list read}).
36822
2268b414
JK
36823@item qXfer:libraries-svr4:read
36824The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
36825(@pxref{qXfer svr4 library list read}).
36826
85dc5a12
GB
36827@item augmented-libraries-svr4-read
36828The remote stub understands the augmented form of the
36829@samp{qXfer:libraries-svr4:read} packet
36830(@pxref{qXfer svr4 library list read}).
36831
23181151
DJ
36832@item qXfer:memory-map:read
36833The remote stub understands the @samp{qXfer:memory-map:read} packet
36834(@pxref{qXfer memory map read}).
36835
0fb4aa4b
PA
36836@item qXfer:sdata:read
36837The remote stub understands the @samp{qXfer:sdata:read} packet
36838(@pxref{qXfer sdata read}).
36839
0e7f50da
UW
36840@item qXfer:spu:read
36841The remote stub understands the @samp{qXfer:spu:read} packet
36842(@pxref{qXfer spu read}).
36843
36844@item qXfer:spu:write
36845The remote stub understands the @samp{qXfer:spu:write} packet
36846(@pxref{qXfer spu write}).
36847
4aa995e1
PA
36848@item qXfer:siginfo:read
36849The remote stub understands the @samp{qXfer:siginfo:read} packet
36850(@pxref{qXfer siginfo read}).
36851
36852@item qXfer:siginfo:write
36853The remote stub understands the @samp{qXfer:siginfo:write} packet
36854(@pxref{qXfer siginfo write}).
36855
dc146f7c
VP
36856@item qXfer:threads:read
36857The remote stub understands the @samp{qXfer:threads:read} packet
36858(@pxref{qXfer threads read}).
36859
b3b9301e
PA
36860@item qXfer:traceframe-info:read
36861The remote stub understands the @samp{qXfer:traceframe-info:read}
36862packet (@pxref{qXfer traceframe info read}).
36863
169081d0
TG
36864@item qXfer:uib:read
36865The remote stub understands the @samp{qXfer:uib:read}
36866packet (@pxref{qXfer unwind info block}).
36867
78d85199
YQ
36868@item qXfer:fdpic:read
36869The remote stub understands the @samp{qXfer:fdpic:read}
36870packet (@pxref{qXfer fdpic loadmap read}).
36871
8b23ecc4
SL
36872@item QNonStop
36873The remote stub understands the @samp{QNonStop} packet
36874(@pxref{QNonStop}).
36875
82075af2
JS
36876@item QCatchSyscalls
36877The remote stub understands the @samp{QCatchSyscalls} packet
36878(@pxref{QCatchSyscalls}).
36879
23181151
DJ
36880@item QPassSignals
36881The remote stub understands the @samp{QPassSignals} packet
36882(@pxref{QPassSignals}).
36883
a6f3e723
SL
36884@item QStartNoAckMode
36885The remote stub understands the @samp{QStartNoAckMode} packet and
36886prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
36887
b90a069a
SL
36888@item multiprocess
36889@anchor{multiprocess extensions}
36890@cindex multiprocess extensions, in remote protocol
36891The remote stub understands the multiprocess extensions to the remote
36892protocol syntax. The multiprocess extensions affect the syntax of
36893thread IDs in both packets and replies (@pxref{thread-id syntax}), and
36894add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
36895replies. Note that reporting this feature indicates support for the
36896syntactic extensions only, not that the stub necessarily supports
36897debugging of more than one process at a time. The stub must not use
36898multiprocess extensions in packet replies unless @value{GDBN} has also
36899indicated it supports them in its @samp{qSupported} request.
36900
07e059b5
VP
36901@item qXfer:osdata:read
36902The remote stub understands the @samp{qXfer:osdata:read} packet
36903((@pxref{qXfer osdata read}).
36904
83364271
LM
36905@item ConditionalBreakpoints
36906The target accepts and implements evaluation of conditional expressions
36907defined for breakpoints. The target will only report breakpoint triggers
36908when such conditions are true (@pxref{Conditions, ,Break Conditions}).
36909
782b2b07
SS
36910@item ConditionalTracepoints
36911The remote stub accepts and implements conditional expressions defined
36912for tracepoints (@pxref{Tracepoint Conditions}).
36913
0d772ac9
MS
36914@item ReverseContinue
36915The remote stub accepts and implements the reverse continue packet
36916(@pxref{bc}).
36917
36918@item ReverseStep
36919The remote stub accepts and implements the reverse step packet
36920(@pxref{bs}).
36921
409873ef
SS
36922@item TracepointSource
36923The remote stub understands the @samp{QTDPsrc} packet that supplies
36924the source form of tracepoint definitions.
36925
d1feda86
YQ
36926@item QAgent
36927The remote stub understands the @samp{QAgent} packet.
36928
d914c394
SS
36929@item QAllow
36930The remote stub understands the @samp{QAllow} packet.
36931
03583c20
UW
36932@item QDisableRandomization
36933The remote stub understands the @samp{QDisableRandomization} packet.
36934
0fb4aa4b
PA
36935@item StaticTracepoint
36936@cindex static tracepoints, in remote protocol
36937The remote stub supports static tracepoints.
36938
1e4d1764
YQ
36939@item InstallInTrace
36940@anchor{install tracepoint in tracing}
36941The remote stub supports installing tracepoint in tracing.
36942
d248b706
KY
36943@item EnableDisableTracepoints
36944The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
36945@samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
36946to be enabled and disabled while a trace experiment is running.
36947
f6f899bf 36948@item QTBuffer:size
28abe188 36949The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
f6f899bf
HAQ
36950packet that allows to change the size of the trace buffer.
36951
3065dfb6
SS
36952@item tracenz
36953@cindex string tracing, in remote protocol
36954The remote stub supports the @samp{tracenz} bytecode for collecting strings.
36955See @ref{Bytecode Descriptions} for details about the bytecode.
36956
d3ce09f5
SS
36957@item BreakpointCommands
36958@cindex breakpoint commands, in remote protocol
36959The remote stub supports running a breakpoint's command list itself,
36960rather than reporting the hit to @value{GDBN}.
36961
2ae8c8e7
MM
36962@item Qbtrace:off
36963The remote stub understands the @samp{Qbtrace:off} packet.
36964
36965@item Qbtrace:bts
36966The remote stub understands the @samp{Qbtrace:bts} packet.
36967
b20a6524
MM
36968@item Qbtrace:pt
36969The remote stub understands the @samp{Qbtrace:pt} packet.
36970
d33501a5
MM
36971@item Qbtrace-conf:bts:size
36972The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
36973
b20a6524
MM
36974@item Qbtrace-conf:pt:size
36975The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
36976
f7e6eed5
PA
36977@item swbreak
36978The remote stub reports the @samp{swbreak} stop reason for memory
36979breakpoints.
36980
36981@item hwbreak
36982The remote stub reports the @samp{hwbreak} stop reason for hardware
36983breakpoints.
36984
0d71eef5
DB
36985@item fork-events
36986The remote stub reports the @samp{fork} stop reason for fork events.
36987
36988@item vfork-events
36989The remote stub reports the @samp{vfork} stop reason for vfork events
36990and vforkdone events.
36991
b459a59b
DB
36992@item exec-events
36993The remote stub reports the @samp{exec} stop reason for exec events.
36994
750ce8d1
YQ
36995@item vContSupported
36996The remote stub reports the supported actions in the reply to
36997@samp{vCont?} packet.
36998
65706a29
PA
36999@item QThreadEvents
37000The remote stub understands the @samp{QThreadEvents} packet.
37001
f2faf941
PA
37002@item no-resumed
37003The remote stub reports the @samp{N} stop reply.
37004
be2a5f71
DJ
37005@end table
37006
b8ff78ce 37007@item qSymbol::
ff2587ec 37008@cindex symbol lookup, remote request
b8ff78ce 37009@cindex @samp{qSymbol} packet
ff2587ec
WZ
37010Notify the target that @value{GDBN} is prepared to serve symbol lookup
37011requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
37012
37013Reply:
ff2587ec 37014@table @samp
b8ff78ce 37015@item OK
ff2587ec 37016The target does not need to look up any (more) symbols.
b8ff78ce 37017@item qSymbol:@var{sym_name}
ff2587ec
WZ
37018The target requests the value of symbol @var{sym_name} (hex encoded).
37019@value{GDBN} may provide the value by using the
b8ff78ce
JB
37020@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
37021below.
ff2587ec 37022@end table
83761cbd 37023
b8ff78ce 37024@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
37025Set the value of @var{sym_name} to @var{sym_value}.
37026
37027@var{sym_name} (hex encoded) is the name of a symbol whose value the
37028target has previously requested.
37029
37030@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
37031@value{GDBN} cannot supply a value for @var{sym_name}, then this field
37032will be empty.
37033
37034Reply:
37035@table @samp
b8ff78ce 37036@item OK
ff2587ec 37037The target does not need to look up any (more) symbols.
b8ff78ce 37038@item qSymbol:@var{sym_name}
ff2587ec
WZ
37039The target requests the value of a new symbol @var{sym_name} (hex
37040encoded). @value{GDBN} will continue to supply the values of symbols
37041(if available), until the target ceases to request them.
fa93a9d8 37042@end table
0abb7bc7 37043
00bf0b85 37044@item qTBuffer
687e43a4
TT
37045@itemx QTBuffer
37046@itemx QTDisconnected
d5551862 37047@itemx QTDP
409873ef 37048@itemx QTDPsrc
d5551862 37049@itemx QTDV
00bf0b85
SS
37050@itemx qTfP
37051@itemx qTfV
9d29849a 37052@itemx QTFrame
405f8e94
SS
37053@itemx qTMinFTPILen
37054
9d29849a
JB
37055@xref{Tracepoint Packets}.
37056
b90a069a 37057@item qThreadExtraInfo,@var{thread-id}
ff2587ec 37058@cindex thread attributes info, remote request
b8ff78ce 37059@cindex @samp{qThreadExtraInfo} packet
697aa1b7
EZ
37060Obtain from the target OS a printable string description of thread
37061attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
37062for the forms of @var{thread-id}. This
b8ff78ce
JB
37063string may contain anything that the target OS thinks is interesting
37064for @value{GDBN} to tell the user about the thread. The string is
37065displayed in @value{GDBN}'s @code{info threads} display. Some
37066examples of possible thread extra info strings are @samp{Runnable}, or
37067@samp{Blocked on Mutex}.
ff2587ec
WZ
37068
37069Reply:
37070@table @samp
b8ff78ce
JB
37071@item @var{XX}@dots{}
37072Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
37073comprising the printable string containing the extra information about
37074the thread's attributes.
ff2587ec 37075@end table
814e32d7 37076
aa56d27a
JB
37077(Note that the @code{qThreadExtraInfo} packet's name is separated from
37078the command by a @samp{,}, not a @samp{:}, contrary to the naming
37079conventions above. Please don't use this packet as a model for new
37080packets.)
37081
f196051f 37082@item QTNotes
687e43a4
TT
37083@itemx qTP
37084@itemx QTSave
37085@itemx qTsP
37086@itemx qTsV
d5551862 37087@itemx QTStart
9d29849a 37088@itemx QTStop
d248b706
KY
37089@itemx QTEnable
37090@itemx QTDisable
9d29849a
JB
37091@itemx QTinit
37092@itemx QTro
37093@itemx qTStatus
d5551862 37094@itemx qTV
0fb4aa4b
PA
37095@itemx qTfSTM
37096@itemx qTsSTM
37097@itemx qTSTMat
9d29849a
JB
37098@xref{Tracepoint Packets}.
37099
0876f84a
DJ
37100@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
37101@cindex read special object, remote request
37102@cindex @samp{qXfer} packet
68437a39 37103@anchor{qXfer read}
0876f84a
DJ
37104Read uninterpreted bytes from the target's special data area
37105identified by the keyword @var{object}. Request @var{length} bytes
37106starting at @var{offset} bytes into the data. The content and
0e7f50da 37107encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
37108additional details about what data to access.
37109
37110Here are the specific requests of this form defined so far. All
37111@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
37112formats, listed below.
37113
37114@table @samp
37115@item qXfer:auxv:read::@var{offset},@var{length}
37116@anchor{qXfer auxiliary vector read}
37117Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 37118auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
37119
37120This packet is not probed by default; the remote stub must request it,
89be2091 37121by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 37122
2ae8c8e7
MM
37123@item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
37124@anchor{qXfer btrace read}
37125
37126Return a description of the current branch trace.
37127@xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
37128packet may have one of the following values:
37129
37130@table @code
37131@item all
37132Returns all available branch trace.
37133
37134@item new
37135Returns all available branch trace if the branch trace changed since
37136the last read request.
969c39fb
MM
37137
37138@item delta
37139Returns the new branch trace since the last read request. Adds a new
37140block to the end of the trace that begins at zero and ends at the source
37141location of the first branch in the trace buffer. This extra block is
37142used to stitch traces together.
37143
37144If the trace buffer overflowed, returns an error indicating the overflow.
2ae8c8e7
MM
37145@end table
37146
37147This packet is not probed by default; the remote stub must request it
37148by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37149
f4abbc16
MM
37150@item qXfer:btrace-conf:read::@var{offset},@var{length}
37151@anchor{qXfer btrace-conf read}
37152
37153Return a description of the current branch trace configuration.
37154@xref{Branch Trace Configuration Format}.
37155
37156This packet is not probed by default; the remote stub must request it
37157by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
c78fa86a
GB
37158
37159@item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
37160@anchor{qXfer executable filename read}
37161Return the full absolute name of the file that was executed to create
37162a process running on the remote system. The annex specifies the
37163numeric process ID of the process to query, encoded as a hexadecimal
835205d0
GB
37164number. If the annex part is empty the remote stub should return the
37165filename corresponding to the currently executing process.
c78fa86a
GB
37166
37167This packet is not probed by default; the remote stub must request it,
37168by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
f4abbc16 37169
23181151
DJ
37170@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
37171@anchor{qXfer target description read}
37172Access the @dfn{target description}. @xref{Target Descriptions}. The
37173annex specifies which XML document to access. The main description is
37174always loaded from the @samp{target.xml} annex.
37175
37176This packet is not probed by default; the remote stub must request it,
37177by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37178
cfa9d6d9
DJ
37179@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
37180@anchor{qXfer library list read}
37181Access the target's list of loaded libraries. @xref{Library List Format}.
37182The annex part of the generic @samp{qXfer} packet must be empty
37183(@pxref{qXfer read}).
37184
37185Targets which maintain a list of libraries in the program's memory do
37186not need to implement this packet; it is designed for platforms where
37187the operating system manages the list of loaded libraries.
37188
37189This packet is not probed by default; the remote stub must request it,
37190by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37191
2268b414
JK
37192@item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
37193@anchor{qXfer svr4 library list read}
37194Access the target's list of loaded libraries when the target is an SVR4
37195platform. @xref{Library List Format for SVR4 Targets}. The annex part
85dc5a12
GB
37196of the generic @samp{qXfer} packet must be empty unless the remote
37197stub indicated it supports the augmented form of this packet
37198by supplying an appropriate @samp{qSupported} response
37199(@pxref{qXfer read}, @ref{qSupported}).
2268b414
JK
37200
37201This packet is optional for better performance on SVR4 targets.
37202@value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
37203
37204This packet is not probed by default; the remote stub must request it,
37205by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37206
85dc5a12
GB
37207If the remote stub indicates it supports the augmented form of this
37208packet then the annex part of the generic @samp{qXfer} packet may
37209contain a semicolon-separated list of @samp{@var{name}=@var{value}}
37210arguments. The currently supported arguments are:
37211
37212@table @code
37213@item start=@var{address}
37214A hexadecimal number specifying the address of the @samp{struct
37215link_map} to start reading the library list from. If unset or zero
37216then the first @samp{struct link_map} in the library list will be
37217chosen as the starting point.
37218
37219@item prev=@var{address}
37220A hexadecimal number specifying the address of the @samp{struct
37221link_map} immediately preceding the @samp{struct link_map}
37222specified by the @samp{start} argument. If unset or zero then
37223the remote stub will expect that no @samp{struct link_map}
37224exists prior to the starting point.
37225
37226@end table
37227
37228Arguments that are not understood by the remote stub will be silently
37229ignored.
37230
68437a39
DJ
37231@item qXfer:memory-map:read::@var{offset},@var{length}
37232@anchor{qXfer memory map read}
79a6e687 37233Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
37234annex part of the generic @samp{qXfer} packet must be empty
37235(@pxref{qXfer read}).
37236
0e7f50da
UW
37237This packet is not probed by default; the remote stub must request it,
37238by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37239
0fb4aa4b
PA
37240@item qXfer:sdata:read::@var{offset},@var{length}
37241@anchor{qXfer sdata read}
37242
37243Read contents of the extra collected static tracepoint marker
37244information. The annex part of the generic @samp{qXfer} packet must
37245be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
37246Action Lists}.
37247
37248This packet is not probed by default; the remote stub must request it,
37249by supplying an appropriate @samp{qSupported} response
37250(@pxref{qSupported}).
37251
4aa995e1
PA
37252@item qXfer:siginfo:read::@var{offset},@var{length}
37253@anchor{qXfer siginfo read}
37254Read contents of the extra signal information on the target
37255system. The annex part of the generic @samp{qXfer} packet must be
37256empty (@pxref{qXfer read}).
37257
37258This packet is not probed by default; the remote stub must request it,
37259by supplying an appropriate @samp{qSupported} response
37260(@pxref{qSupported}).
37261
0e7f50da
UW
37262@item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
37263@anchor{qXfer spu read}
37264Read contents of an @code{spufs} file on the target system. The
37265annex specifies which file to read; it must be of the form
37266@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
37267in the target process, and @var{name} identifes the @code{spufs} file
37268in that context to be accessed.
37269
68437a39 37270This packet is not probed by default; the remote stub must request it,
07e059b5
VP
37271by supplying an appropriate @samp{qSupported} response
37272(@pxref{qSupported}).
37273
dc146f7c
VP
37274@item qXfer:threads:read::@var{offset},@var{length}
37275@anchor{qXfer threads read}
37276Access the list of threads on target. @xref{Thread List Format}. The
37277annex part of the generic @samp{qXfer} packet must be empty
37278(@pxref{qXfer read}).
37279
37280This packet is not probed by default; the remote stub must request it,
37281by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37282
b3b9301e
PA
37283@item qXfer:traceframe-info:read::@var{offset},@var{length}
37284@anchor{qXfer traceframe info read}
37285
37286Return a description of the current traceframe's contents.
37287@xref{Traceframe Info Format}. The annex part of the generic
37288@samp{qXfer} packet must be empty (@pxref{qXfer read}).
37289
37290This packet is not probed by default; the remote stub must request it,
37291by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37292
169081d0
TG
37293@item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
37294@anchor{qXfer unwind info block}
37295
37296Return the unwind information block for @var{pc}. This packet is used
37297on OpenVMS/ia64 to ask the kernel unwind information.
37298
37299This packet is not probed by default.
37300
78d85199
YQ
37301@item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
37302@anchor{qXfer fdpic loadmap read}
37303Read contents of @code{loadmap}s on the target system. The
37304annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
37305executable @code{loadmap} or interpreter @code{loadmap} to read.
37306
37307This packet is not probed by default; the remote stub must request it,
37308by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37309
07e059b5
VP
37310@item qXfer:osdata:read::@var{offset},@var{length}
37311@anchor{qXfer osdata read}
697aa1b7 37312Access the target's @dfn{operating system information}.
07e059b5
VP
37313@xref{Operating System Information}.
37314
68437a39
DJ
37315@end table
37316
0876f84a
DJ
37317Reply:
37318@table @samp
37319@item m @var{data}
37320Data @var{data} (@pxref{Binary Data}) has been read from the
37321target. There may be more data at a higher address (although
37322it is permitted to return @samp{m} even for the last valid
37323block of data, as long as at least one byte of data was read).
697aa1b7 37324It is possible for @var{data} to have fewer bytes than the @var{length} in the
0876f84a
DJ
37325request.
37326
37327@item l @var{data}
37328Data @var{data} (@pxref{Binary Data}) has been read from the target.
697aa1b7
EZ
37329There is no more data to be read. It is possible for @var{data} to
37330have fewer bytes than the @var{length} in the request.
0876f84a
DJ
37331
37332@item l
37333The @var{offset} in the request is at the end of the data.
37334There is no more data to be read.
37335
37336@item E00
37337The request was malformed, or @var{annex} was invalid.
37338
37339@item E @var{nn}
37340The offset was invalid, or there was an error encountered reading the data.
697aa1b7 37341The @var{nn} part is a hex-encoded @code{errno} value.
0876f84a 37342
d57350ea 37343@item @w{}
0876f84a
DJ
37344An empty reply indicates the @var{object} string was not recognized by
37345the stub, or that the object does not support reading.
37346@end table
37347
37348@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
37349@cindex write data into object, remote request
4aa995e1 37350@anchor{qXfer write}
0876f84a
DJ
37351Write uninterpreted bytes into the target's special data area
37352identified by the keyword @var{object}, starting at @var{offset} bytes
697aa1b7
EZ
37353into the data. The binary-encoded data (@pxref{Binary Data}) to be
37354written is given by @var{data}@dots{}. The content and encoding of @var{annex}
0e7f50da 37355is specific to @var{object}; it can supply additional details about what data
0876f84a
DJ
37356to access.
37357
0e7f50da
UW
37358Here are the specific requests of this form defined so far. All
37359@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
37360formats, listed below.
37361
37362@table @samp
4aa995e1
PA
37363@item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
37364@anchor{qXfer siginfo write}
37365Write @var{data} to the extra signal information on the target system.
37366The annex part of the generic @samp{qXfer} packet must be
37367empty (@pxref{qXfer write}).
37368
37369This packet is not probed by default; the remote stub must request it,
37370by supplying an appropriate @samp{qSupported} response
37371(@pxref{qSupported}).
37372
84fcdf95 37373@item qXfer:spu:write:@var{annex}:@var{offset}:@var{data}@dots{}
0e7f50da
UW
37374@anchor{qXfer spu write}
37375Write @var{data} to an @code{spufs} file on the target system. The
37376annex specifies which file to write; it must be of the form
37377@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
37378in the target process, and @var{name} identifes the @code{spufs} file
37379in that context to be accessed.
37380
37381This packet is not probed by default; the remote stub must request it,
37382by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37383@end table
0876f84a
DJ
37384
37385Reply:
37386@table @samp
37387@item @var{nn}
37388@var{nn} (hex encoded) is the number of bytes written.
37389This may be fewer bytes than supplied in the request.
37390
37391@item E00
37392The request was malformed, or @var{annex} was invalid.
37393
37394@item E @var{nn}
37395The offset was invalid, or there was an error encountered writing the data.
697aa1b7 37396The @var{nn} part is a hex-encoded @code{errno} value.
0876f84a 37397
d57350ea 37398@item @w{}
0876f84a
DJ
37399An empty reply indicates the @var{object} string was not
37400recognized by the stub, or that the object does not support writing.
37401@end table
37402
37403@item qXfer:@var{object}:@var{operation}:@dots{}
37404Requests of this form may be added in the future. When a stub does
37405not recognize the @var{object} keyword, or its support for
37406@var{object} does not recognize the @var{operation} keyword, the stub
37407must respond with an empty packet.
37408
0b16c5cf
PA
37409@item qAttached:@var{pid}
37410@cindex query attached, remote request
37411@cindex @samp{qAttached} packet
37412Return an indication of whether the remote server attached to an
37413existing process or created a new process. When the multiprocess
37414protocol extensions are supported (@pxref{multiprocess extensions}),
37415@var{pid} is an integer in hexadecimal format identifying the target
37416process. Otherwise, @value{GDBN} will omit the @var{pid} field and
37417the query packet will be simplified as @samp{qAttached}.
37418
37419This query is used, for example, to know whether the remote process
37420should be detached or killed when a @value{GDBN} session is ended with
37421the @code{quit} command.
37422
37423Reply:
37424@table @samp
37425@item 1
37426The remote server attached to an existing process.
37427@item 0
37428The remote server created a new process.
37429@item E @var{NN}
37430A badly formed request or an error was encountered.
37431@end table
37432
2ae8c8e7 37433@item Qbtrace:bts
b20a6524
MM
37434Enable branch tracing for the current thread using Branch Trace Store.
37435
37436Reply:
37437@table @samp
37438@item OK
37439Branch tracing has been enabled.
37440@item E.errtext
37441A badly formed request or an error was encountered.
37442@end table
37443
37444@item Qbtrace:pt
bc504a31 37445Enable branch tracing for the current thread using Intel Processor Trace.
2ae8c8e7
MM
37446
37447Reply:
37448@table @samp
37449@item OK
37450Branch tracing has been enabled.
37451@item E.errtext
37452A badly formed request or an error was encountered.
37453@end table
37454
37455@item Qbtrace:off
37456Disable branch tracing for the current thread.
37457
37458Reply:
37459@table @samp
37460@item OK
37461Branch tracing has been disabled.
37462@item E.errtext
37463A badly formed request or an error was encountered.
37464@end table
37465
d33501a5
MM
37466@item Qbtrace-conf:bts:size=@var{value}
37467Set the requested ring buffer size for new threads that use the
37468btrace recording method in bts format.
37469
37470Reply:
37471@table @samp
37472@item OK
37473The ring buffer size has been set.
37474@item E.errtext
37475A badly formed request or an error was encountered.
37476@end table
37477
b20a6524
MM
37478@item Qbtrace-conf:pt:size=@var{value}
37479Set the requested ring buffer size for new threads that use the
37480btrace recording method in pt format.
37481
37482Reply:
37483@table @samp
37484@item OK
37485The ring buffer size has been set.
37486@item E.errtext
37487A badly formed request or an error was encountered.
37488@end table
37489
ee2d5c50
AC
37490@end table
37491
a1dcb23a
DJ
37492@node Architecture-Specific Protocol Details
37493@section Architecture-Specific Protocol Details
37494
37495This section describes how the remote protocol is applied to specific
37496target architectures. Also see @ref{Standard Target Features}, for
37497details of XML target descriptions for each architecture.
37498
02b67415
MR
37499@menu
37500* ARM-Specific Protocol Details::
37501* MIPS-Specific Protocol Details::
37502@end menu
37503
37504@node ARM-Specific Protocol Details
37505@subsection @acronym{ARM}-specific Protocol Details
37506
37507@menu
37508* ARM Breakpoint Kinds::
37509@end menu
a1dcb23a 37510
02b67415
MR
37511@node ARM Breakpoint Kinds
37512@subsubsection @acronym{ARM} Breakpoint Kinds
37513@cindex breakpoint kinds, @acronym{ARM}
a1dcb23a
DJ
37514
37515These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
37516
37517@table @r
37518
37519@item 2
3752016-bit Thumb mode breakpoint.
37521
37522@item 3
3752332-bit Thumb mode (Thumb-2) breakpoint.
37524
37525@item 4
02b67415 3752632-bit @acronym{ARM} mode breakpoint.
a1dcb23a
DJ
37527
37528@end table
37529
02b67415
MR
37530@node MIPS-Specific Protocol Details
37531@subsection @acronym{MIPS}-specific Protocol Details
37532
37533@menu
37534* MIPS Register packet Format::
4cc0665f 37535* MIPS Breakpoint Kinds::
02b67415 37536@end menu
a1dcb23a 37537
02b67415
MR
37538@node MIPS Register packet Format
37539@subsubsection @acronym{MIPS} Register Packet Format
eb17f351 37540@cindex register packet format, @acronym{MIPS}
eb12ee30 37541
b8ff78ce 37542The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
37543In the below, some thirty-two bit registers are transferred as
37544sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
37545to fill the space allocated. Register bytes are transferred in target
37546byte order. The two nibbles within a register byte are transferred
02b67415 37547most-significant -- least-significant.
eb12ee30 37548
ee2d5c50 37549@table @r
eb12ee30 37550
8e04817f 37551@item MIPS32
599b237a 37552All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
3755332 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
37554registers; fsr; fir; fp.
eb12ee30 37555
8e04817f 37556@item MIPS64
599b237a 37557All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
37558thirty-two bit registers such as @code{sr}). The ordering is the same
37559as @code{MIPS32}.
eb12ee30 37560
ee2d5c50
AC
37561@end table
37562
4cc0665f
MR
37563@node MIPS Breakpoint Kinds
37564@subsubsection @acronym{MIPS} Breakpoint Kinds
37565@cindex breakpoint kinds, @acronym{MIPS}
37566
37567These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
37568
37569@table @r
37570
37571@item 2
3757216-bit @acronym{MIPS16} mode breakpoint.
37573
37574@item 3
3757516-bit @acronym{microMIPS} mode breakpoint.
37576
37577@item 4
3757832-bit standard @acronym{MIPS} mode breakpoint.
37579
37580@item 5
3758132-bit @acronym{microMIPS} mode breakpoint.
37582
37583@end table
37584
9d29849a
JB
37585@node Tracepoint Packets
37586@section Tracepoint Packets
37587@cindex tracepoint packets
37588@cindex packets, tracepoint
37589
37590Here we describe the packets @value{GDBN} uses to implement
37591tracepoints (@pxref{Tracepoints}).
37592
37593@table @samp
37594
7a697b8d 37595@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
c614397c 37596@cindex @samp{QTDP} packet
9d29849a
JB
37597Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
37598is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
697aa1b7
EZ
37599the tracepoint is disabled. The @var{step} gives the tracepoint's step
37600count, and @var{pass} gives its pass count. If an @samp{F} is present,
7a697b8d
SS
37601then the tracepoint is to be a fast tracepoint, and the @var{flen} is
37602the number of bytes that the target should copy elsewhere to make room
37603for the tracepoint. If an @samp{X} is present, it introduces a
37604tracepoint condition, which consists of a hexadecimal length, followed
37605by a comma and hex-encoded bytes, in a manner similar to action
37606encodings as described below. If the trailing @samp{-} is present,
37607further @samp{QTDP} packets will follow to specify this tracepoint's
37608actions.
9d29849a
JB
37609
37610Replies:
37611@table @samp
37612@item OK
37613The packet was understood and carried out.
dde08ee1
PA
37614@item qRelocInsn
37615@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 37616@item @w{}
9d29849a
JB
37617The packet was not recognized.
37618@end table
37619
37620@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
697aa1b7 37621Define actions to be taken when a tracepoint is hit. The @var{n} and
9d29849a
JB
37622@var{addr} must be the same as in the initial @samp{QTDP} packet for
37623this tracepoint. This packet may only be sent immediately after
37624another @samp{QTDP} packet that ended with a @samp{-}. If the
37625trailing @samp{-} is present, further @samp{QTDP} packets will follow,
37626specifying more actions for this tracepoint.
37627
37628In the series of action packets for a given tracepoint, at most one
37629can have an @samp{S} before its first @var{action}. If such a packet
37630is sent, it and the following packets define ``while-stepping''
37631actions. Any prior packets define ordinary actions --- that is, those
37632taken when the tracepoint is first hit. If no action packet has an
37633@samp{S}, then all the packets in the series specify ordinary
37634tracepoint actions.
37635
37636The @samp{@var{action}@dots{}} portion of the packet is a series of
37637actions, concatenated without separators. Each action has one of the
37638following forms:
37639
37640@table @samp
37641
37642@item R @var{mask}
697aa1b7 37643Collect the registers whose bits are set in @var{mask},
599b237a 37644a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
37645@var{i} should be collected. (The least significant bit is numbered
37646zero.) Note that @var{mask} may be any number of digits long; it may
37647not fit in a 32-bit word.
37648
37649@item M @var{basereg},@var{offset},@var{len}
37650Collect @var{len} bytes of memory starting at the address in register
37651number @var{basereg}, plus @var{offset}. If @var{basereg} is
37652@samp{-1}, then the range has a fixed address: @var{offset} is the
37653address of the lowest byte to collect. The @var{basereg},
599b237a 37654@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
37655values (the @samp{-1} value for @var{basereg} is a special case).
37656
37657@item X @var{len},@var{expr}
37658Evaluate @var{expr}, whose length is @var{len}, and collect memory as
697aa1b7 37659it directs. The agent expression @var{expr} is as described in
9d29849a
JB
37660@ref{Agent Expressions}. Each byte of the expression is encoded as a
37661two-digit hex number in the packet; @var{len} is the number of bytes
37662in the expression (and thus one-half the number of hex digits in the
37663packet).
37664
37665@end table
37666
37667Any number of actions may be packed together in a single @samp{QTDP}
37668packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
37669length (400 bytes, for many stubs). There may be only one @samp{R}
37670action per tracepoint, and it must precede any @samp{M} or @samp{X}
37671actions. Any registers referred to by @samp{M} and @samp{X} actions
37672must be collected by a preceding @samp{R} action. (The
37673``while-stepping'' actions are treated as if they were attached to a
37674separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
37675
37676Replies:
37677@table @samp
37678@item OK
37679The packet was understood and carried out.
dde08ee1
PA
37680@item qRelocInsn
37681@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 37682@item @w{}
9d29849a
JB
37683The packet was not recognized.
37684@end table
37685
409873ef
SS
37686@item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
37687@cindex @samp{QTDPsrc} packet
37688Specify a source string of tracepoint @var{n} at address @var{addr}.
37689This is useful to get accurate reproduction of the tracepoints
697aa1b7 37690originally downloaded at the beginning of the trace run. The @var{type}
409873ef
SS
37691is the name of the tracepoint part, such as @samp{cond} for the
37692tracepoint's conditional expression (see below for a list of types), while
37693@var{bytes} is the string, encoded in hexadecimal.
37694
37695@var{start} is the offset of the @var{bytes} within the overall source
37696string, while @var{slen} is the total length of the source string.
37697This is intended for handling source strings that are longer than will
37698fit in a single packet.
37699@c Add detailed example when this info is moved into a dedicated
37700@c tracepoint descriptions section.
37701
37702The available string types are @samp{at} for the location,
37703@samp{cond} for the conditional, and @samp{cmd} for an action command.
37704@value{GDBN} sends a separate packet for each command in the action
37705list, in the same order in which the commands are stored in the list.
37706
37707The target does not need to do anything with source strings except
37708report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
37709query packets.
37710
37711Although this packet is optional, and @value{GDBN} will only send it
37712if the target replies with @samp{TracepointSource} @xref{General
37713Query Packets}, it makes both disconnected tracing and trace files
37714much easier to use. Otherwise the user must be careful that the
37715tracepoints in effect while looking at trace frames are identical to
37716the ones in effect during the trace run; even a small discrepancy
37717could cause @samp{tdump} not to work, or a particular trace frame not
37718be found.
37719
fa3f8d5a 37720@item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
f61e138d
SS
37721@cindex define trace state variable, remote request
37722@cindex @samp{QTDV} packet
37723Create a new trace state variable, number @var{n}, with an initial
37724value of @var{value}, which is a 64-bit signed integer. Both @var{n}
37725and @var{value} are encoded as hexadecimal values. @value{GDBN} has
37726the option of not using this packet for initial values of zero; the
37727target should simply create the trace state variables as they are
fa3f8d5a
DT
37728mentioned in expressions. The value @var{builtin} should be 1 (one)
37729if the trace state variable is builtin and 0 (zero) if it is not builtin.
37730@value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
37731@samp{qTsV} packet had it set. The contents of @var{name} is the
37732hex-encoded name (without the leading @samp{$}) of the trace state
37733variable.
f61e138d 37734
9d29849a 37735@item QTFrame:@var{n}
c614397c 37736@cindex @samp{QTFrame} packet
9d29849a
JB
37737Select the @var{n}'th tracepoint frame from the buffer, and use the
37738register and memory contents recorded there to answer subsequent
37739request packets from @value{GDBN}.
37740
37741A successful reply from the stub indicates that the stub has found the
37742requested frame. The response is a series of parts, concatenated
37743without separators, describing the frame we selected. Each part has
37744one of the following forms:
37745
37746@table @samp
37747@item F @var{f}
37748The selected frame is number @var{n} in the trace frame buffer;
599b237a 37749@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
37750was no frame matching the criteria in the request packet.
37751
37752@item T @var{t}
37753The selected trace frame records a hit of tracepoint number @var{t};
599b237a 37754@var{t} is a hexadecimal number.
9d29849a
JB
37755
37756@end table
37757
37758@item QTFrame:pc:@var{addr}
37759Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
37760currently selected frame whose PC is @var{addr};
599b237a 37761@var{addr} is a hexadecimal number.
9d29849a
JB
37762
37763@item QTFrame:tdp:@var{t}
37764Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
37765currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 37766is a hexadecimal number.
9d29849a
JB
37767
37768@item QTFrame:range:@var{start}:@var{end}
37769Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
37770currently selected frame whose PC is between @var{start} (inclusive)
081dfbf7 37771and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
37772numbers.
37773
37774@item QTFrame:outside:@var{start}:@var{end}
37775Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
081dfbf7 37776frame @emph{outside} the given range of addresses (exclusive).
9d29849a 37777
405f8e94 37778@item qTMinFTPILen
c614397c 37779@cindex @samp{qTMinFTPILen} packet
405f8e94
SS
37780This packet requests the minimum length of instruction at which a fast
37781tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
37782the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
37783it depends on the target system being able to create trampolines in
37784the first 64K of memory, which might or might not be possible for that
37785system. So the reply to this packet will be 4 if it is able to
37786arrange for that.
37787
37788Replies:
37789
37790@table @samp
37791@item 0
37792The minimum instruction length is currently unknown.
37793@item @var{length}
697aa1b7
EZ
37794The minimum instruction length is @var{length}, where @var{length}
37795is a hexadecimal number greater or equal to 1. A reply
37796of 1 means that a fast tracepoint may be placed on any instruction
37797regardless of size.
405f8e94
SS
37798@item E
37799An error has occurred.
d57350ea 37800@item @w{}
405f8e94
SS
37801An empty reply indicates that the request is not supported by the stub.
37802@end table
37803
9d29849a 37804@item QTStart
c614397c 37805@cindex @samp{QTStart} packet
dde08ee1
PA
37806Begin the tracepoint experiment. Begin collecting data from
37807tracepoint hits in the trace frame buffer. This packet supports the
37808@samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
37809instruction reply packet}).
9d29849a
JB
37810
37811@item QTStop
c614397c 37812@cindex @samp{QTStop} packet
9d29849a
JB
37813End the tracepoint experiment. Stop collecting trace frames.
37814
d248b706
KY
37815@item QTEnable:@var{n}:@var{addr}
37816@anchor{QTEnable}
c614397c 37817@cindex @samp{QTEnable} packet
d248b706
KY
37818Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
37819experiment. If the tracepoint was previously disabled, then collection
37820of data from it will resume.
37821
37822@item QTDisable:@var{n}:@var{addr}
37823@anchor{QTDisable}
c614397c 37824@cindex @samp{QTDisable} packet
d248b706
KY
37825Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
37826experiment. No more data will be collected from the tracepoint unless
37827@samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
37828
9d29849a 37829@item QTinit
c614397c 37830@cindex @samp{QTinit} packet
9d29849a
JB
37831Clear the table of tracepoints, and empty the trace frame buffer.
37832
37833@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
c614397c 37834@cindex @samp{QTro} packet
9d29849a
JB
37835Establish the given ranges of memory as ``transparent''. The stub
37836will answer requests for these ranges from memory's current contents,
37837if they were not collected as part of the tracepoint hit.
37838
37839@value{GDBN} uses this to mark read-only regions of memory, like those
37840containing program code. Since these areas never change, they should
37841still have the same contents they did when the tracepoint was hit, so
37842there's no reason for the stub to refuse to provide their contents.
37843
d5551862 37844@item QTDisconnected:@var{value}
c614397c 37845@cindex @samp{QTDisconnected} packet
d5551862
SS
37846Set the choice to what to do with the tracing run when @value{GDBN}
37847disconnects from the target. A @var{value} of 1 directs the target to
37848continue the tracing run, while 0 tells the target to stop tracing if
37849@value{GDBN} is no longer in the picture.
37850
9d29849a 37851@item qTStatus
c614397c 37852@cindex @samp{qTStatus} packet
9d29849a
JB
37853Ask the stub if there is a trace experiment running right now.
37854
4daf5ac0
SS
37855The reply has the form:
37856
37857@table @samp
37858
37859@item T@var{running}@r{[};@var{field}@r{]}@dots{}
37860@var{running} is a single digit @code{1} if the trace is presently
37861running, or @code{0} if not. It is followed by semicolon-separated
37862optional fields that an agent may use to report additional status.
37863
37864@end table
37865
37866If the trace is not running, the agent may report any of several
37867explanations as one of the optional fields:
37868
37869@table @samp
37870
37871@item tnotrun:0
37872No trace has been run yet.
37873
f196051f
SS
37874@item tstop[:@var{text}]:0
37875The trace was stopped by a user-originated stop command. The optional
37876@var{text} field is a user-supplied string supplied as part of the
37877stop command (for instance, an explanation of why the trace was
37878stopped manually). It is hex-encoded.
4daf5ac0
SS
37879
37880@item tfull:0
37881The trace stopped because the trace buffer filled up.
37882
37883@item tdisconnected:0
37884The trace stopped because @value{GDBN} disconnected from the target.
37885
37886@item tpasscount:@var{tpnum}
37887The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
37888
6c28cbf2
SS
37889@item terror:@var{text}:@var{tpnum}
37890The trace stopped because tracepoint @var{tpnum} had an error. The
37891string @var{text} is available to describe the nature of the error
697aa1b7
EZ
37892(for instance, a divide by zero in the condition expression); it
37893is hex encoded.
6c28cbf2 37894
4daf5ac0
SS
37895@item tunknown:0
37896The trace stopped for some other reason.
37897
37898@end table
37899
33da3f1c
SS
37900Additional optional fields supply statistical and other information.
37901Although not required, they are extremely useful for users monitoring
37902the progress of a trace run. If a trace has stopped, and these
37903numbers are reported, they must reflect the state of the just-stopped
37904trace.
4daf5ac0 37905
9d29849a 37906@table @samp
4daf5ac0
SS
37907
37908@item tframes:@var{n}
37909The number of trace frames in the buffer.
37910
37911@item tcreated:@var{n}
37912The total number of trace frames created during the run. This may
37913be larger than the trace frame count, if the buffer is circular.
37914
37915@item tsize:@var{n}
37916The total size of the trace buffer, in bytes.
37917
37918@item tfree:@var{n}
37919The number of bytes still unused in the buffer.
37920
33da3f1c
SS
37921@item circular:@var{n}
37922The value of the circular trace buffer flag. @code{1} means that the
37923trace buffer is circular and old trace frames will be discarded if
37924necessary to make room, @code{0} means that the trace buffer is linear
37925and may fill up.
37926
37927@item disconn:@var{n}
37928The value of the disconnected tracing flag. @code{1} means that
37929tracing will continue after @value{GDBN} disconnects, @code{0} means
37930that the trace run will stop.
37931
9d29849a
JB
37932@end table
37933
f196051f
SS
37934@item qTP:@var{tp}:@var{addr}
37935@cindex tracepoint status, remote request
37936@cindex @samp{qTP} packet
37937Ask the stub for the current state of tracepoint number @var{tp} at
37938address @var{addr}.
37939
37940Replies:
37941@table @samp
37942@item V@var{hits}:@var{usage}
37943The tracepoint has been hit @var{hits} times so far during the trace
37944run, and accounts for @var{usage} in the trace buffer. Note that
37945@code{while-stepping} steps are not counted as separate hits, but the
37946steps' space consumption is added into the usage number.
37947
37948@end table
37949
f61e138d
SS
37950@item qTV:@var{var}
37951@cindex trace state variable value, remote request
37952@cindex @samp{qTV} packet
37953Ask the stub for the value of the trace state variable number @var{var}.
37954
37955Replies:
37956@table @samp
37957@item V@var{value}
37958The value of the variable is @var{value}. This will be the current
37959value of the variable if the user is examining a running target, or a
37960saved value if the variable was collected in the trace frame that the
37961user is looking at. Note that multiple requests may result in
37962different reply values, such as when requesting values while the
37963program is running.
37964
37965@item U
37966The value of the variable is unknown. This would occur, for example,
37967if the user is examining a trace frame in which the requested variable
37968was not collected.
9d29849a
JB
37969@end table
37970
d5551862 37971@item qTfP
c614397c 37972@cindex @samp{qTfP} packet
d5551862 37973@itemx qTsP
c614397c 37974@cindex @samp{qTsP} packet
d5551862
SS
37975These packets request data about tracepoints that are being used by
37976the target. @value{GDBN} sends @code{qTfP} to get the first piece
37977of data, and multiple @code{qTsP} to get additional pieces. Replies
37978to these packets generally take the form of the @code{QTDP} packets
37979that define tracepoints. (FIXME add detailed syntax)
37980
00bf0b85 37981@item qTfV
c614397c 37982@cindex @samp{qTfV} packet
00bf0b85 37983@itemx qTsV
c614397c 37984@cindex @samp{qTsV} packet
00bf0b85
SS
37985These packets request data about trace state variables that are on the
37986target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
37987and multiple @code{qTsV} to get additional variables. Replies to
37988these packets follow the syntax of the @code{QTDV} packets that define
37989trace state variables.
37990
0fb4aa4b
PA
37991@item qTfSTM
37992@itemx qTsSTM
16bdd41f
YQ
37993@anchor{qTfSTM}
37994@anchor{qTsSTM}
c614397c
YQ
37995@cindex @samp{qTfSTM} packet
37996@cindex @samp{qTsSTM} packet
0fb4aa4b
PA
37997These packets request data about static tracepoint markers that exist
37998in the target program. @value{GDBN} sends @code{qTfSTM} to get the
37999first piece of data, and multiple @code{qTsSTM} to get additional
38000pieces. Replies to these packets take the following form:
38001
38002Reply:
38003@table @samp
38004@item m @var{address}:@var{id}:@var{extra}
38005A single marker
38006@item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
38007a comma-separated list of markers
38008@item l
38009(lower case letter @samp{L}) denotes end of list.
38010@item E @var{nn}
697aa1b7 38011An error occurred. The error number @var{nn} is given as hex digits.
d57350ea 38012@item @w{}
0fb4aa4b
PA
38013An empty reply indicates that the request is not supported by the
38014stub.
38015@end table
38016
697aa1b7 38017The @var{address} is encoded in hex;
0fb4aa4b
PA
38018@var{id} and @var{extra} are strings encoded in hex.
38019
38020In response to each query, the target will reply with a list of one or
38021more markers, separated by commas. @value{GDBN} will respond to each
38022reply with a request for more markers (using the @samp{qs} form of the
38023query), until the target responds with @samp{l} (lower-case ell, for
38024@dfn{last}).
38025
38026@item qTSTMat:@var{address}
16bdd41f 38027@anchor{qTSTMat}
c614397c 38028@cindex @samp{qTSTMat} packet
0fb4aa4b
PA
38029This packets requests data about static tracepoint markers in the
38030target program at @var{address}. Replies to this packet follow the
38031syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
38032tracepoint markers.
38033
00bf0b85 38034@item QTSave:@var{filename}
c614397c 38035@cindex @samp{QTSave} packet
00bf0b85 38036This packet directs the target to save trace data to the file name
697aa1b7 38037@var{filename} in the target's filesystem. The @var{filename} is encoded
00bf0b85
SS
38038as a hex string; the interpretation of the file name (relative vs
38039absolute, wild cards, etc) is up to the target.
38040
38041@item qTBuffer:@var{offset},@var{len}
c614397c 38042@cindex @samp{qTBuffer} packet
00bf0b85
SS
38043Return up to @var{len} bytes of the current contents of trace buffer,
38044starting at @var{offset}. The trace buffer is treated as if it were
38045a contiguous collection of traceframes, as per the trace file format.
38046The reply consists as many hex-encoded bytes as the target can deliver
38047in a packet; it is not an error to return fewer than were asked for.
38048A reply consisting of just @code{l} indicates that no bytes are
38049available.
38050
4daf5ac0
SS
38051@item QTBuffer:circular:@var{value}
38052This packet directs the target to use a circular trace buffer if
38053@var{value} is 1, or a linear buffer if the value is 0.
38054
f6f899bf 38055@item QTBuffer:size:@var{size}
28abe188
EZ
38056@anchor{QTBuffer-size}
38057@cindex @samp{QTBuffer size} packet
f6f899bf
HAQ
38058This packet directs the target to make the trace buffer be of size
38059@var{size} if possible. A value of @code{-1} tells the target to
38060use whatever size it prefers.
38061
f196051f 38062@item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
c614397c 38063@cindex @samp{QTNotes} packet
f196051f
SS
38064This packet adds optional textual notes to the trace run. Allowable
38065types include @code{user}, @code{notes}, and @code{tstop}, the
38066@var{text} fields are arbitrary strings, hex-encoded.
38067
f61e138d 38068@end table
9d29849a 38069
dde08ee1
PA
38070@subsection Relocate instruction reply packet
38071When installing fast tracepoints in memory, the target may need to
38072relocate the instruction currently at the tracepoint address to a
38073different address in memory. For most instructions, a simple copy is
38074enough, but, for example, call instructions that implicitly push the
38075return address on the stack, and relative branches or other
38076PC-relative instructions require offset adjustment, so that the effect
38077of executing the instruction at a different address is the same as if
38078it had executed in the original location.
38079
38080In response to several of the tracepoint packets, the target may also
38081respond with a number of intermediate @samp{qRelocInsn} request
38082packets before the final result packet, to have @value{GDBN} handle
38083this relocation operation. If a packet supports this mechanism, its
38084documentation will explicitly say so. See for example the above
38085descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
38086format of the request is:
38087
38088@table @samp
38089@item qRelocInsn:@var{from};@var{to}
38090
38091This requests @value{GDBN} to copy instruction at address @var{from}
38092to address @var{to}, possibly adjusted so that executing the
38093instruction at @var{to} has the same effect as executing it at
38094@var{from}. @value{GDBN} writes the adjusted instruction to target
38095memory starting at @var{to}.
38096@end table
38097
38098Replies:
38099@table @samp
38100@item qRelocInsn:@var{adjusted_size}
697aa1b7 38101Informs the stub the relocation is complete. The @var{adjusted_size} is
dde08ee1
PA
38102the length in bytes of resulting relocated instruction sequence.
38103@item E @var{NN}
38104A badly formed request was detected, or an error was encountered while
38105relocating the instruction.
38106@end table
38107
a6b151f1
DJ
38108@node Host I/O Packets
38109@section Host I/O Packets
38110@cindex Host I/O, remote protocol
38111@cindex file transfer, remote protocol
38112
38113The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
38114operations on the far side of a remote link. For example, Host I/O is
38115used to upload and download files to a remote target with its own
38116filesystem. Host I/O uses the same constant values and data structure
38117layout as the target-initiated File-I/O protocol. However, the
38118Host I/O packets are structured differently. The target-initiated
38119protocol relies on target memory to store parameters and buffers.
38120Host I/O requests are initiated by @value{GDBN}, and the
38121target's memory is not involved. @xref{File-I/O Remote Protocol
38122Extension}, for more details on the target-initiated protocol.
38123
38124The Host I/O request packets all encode a single operation along with
38125its arguments. They have this format:
38126
38127@table @samp
38128
38129@item vFile:@var{operation}: @var{parameter}@dots{}
38130@var{operation} is the name of the particular request; the target
38131should compare the entire packet name up to the second colon when checking
38132for a supported operation. The format of @var{parameter} depends on
38133the operation. Numbers are always passed in hexadecimal. Negative
38134numbers have an explicit minus sign (i.e.@: two's complement is not
38135used). Strings (e.g.@: filenames) are encoded as a series of
38136hexadecimal bytes. The last argument to a system call may be a
38137buffer of escaped binary data (@pxref{Binary Data}).
38138
38139@end table
38140
38141The valid responses to Host I/O packets are:
38142
38143@table @samp
38144
38145@item F @var{result} [, @var{errno}] [; @var{attachment}]
38146@var{result} is the integer value returned by this operation, usually
38147non-negative for success and -1 for errors. If an error has occured,
697aa1b7 38148@var{errno} will be included in the result specifying a
a6b151f1
DJ
38149value defined by the File-I/O protocol (@pxref{Errno Values}). For
38150operations which return data, @var{attachment} supplies the data as a
38151binary buffer. Binary buffers in response packets are escaped in the
38152normal way (@pxref{Binary Data}). See the individual packet
38153documentation for the interpretation of @var{result} and
38154@var{attachment}.
38155
d57350ea 38156@item @w{}
a6b151f1
DJ
38157An empty response indicates that this operation is not recognized.
38158
38159@end table
38160
38161These are the supported Host I/O operations:
38162
38163@table @samp
697aa1b7
EZ
38164@item vFile:open: @var{filename}, @var{flags}, @var{mode}
38165Open a file at @var{filename} and return a file descriptor for it, or
38166return -1 if an error occurs. The @var{filename} is a string,
a6b151f1
DJ
38167@var{flags} is an integer indicating a mask of open flags
38168(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
38169of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 38170@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
38171
38172@item vFile:close: @var{fd}
38173Close the open file corresponding to @var{fd} and return 0, or
38174-1 if an error occurs.
38175
38176@item vFile:pread: @var{fd}, @var{count}, @var{offset}
38177Read data from the open file corresponding to @var{fd}. Up to
38178@var{count} bytes will be read from the file, starting at @var{offset}
38179relative to the start of the file. The target may read fewer bytes;
38180common reasons include packet size limits and an end-of-file
38181condition. The number of bytes read is returned. Zero should only be
38182returned for a successful read at the end of the file, or if
38183@var{count} was zero.
38184
38185The data read should be returned as a binary attachment on success.
38186If zero bytes were read, the response should include an empty binary
38187attachment (i.e.@: a trailing semicolon). The return value is the
38188number of target bytes read; the binary attachment may be longer if
38189some characters were escaped.
38190
38191@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
38192Write @var{data} (a binary buffer) to the open file corresponding
38193to @var{fd}. Start the write at @var{offset} from the start of the
38194file. Unlike many @code{write} system calls, there is no
38195separate @var{count} argument; the length of @var{data} in the
38196packet is used. @samp{vFile:write} returns the number of bytes written,
38197which may be shorter than the length of @var{data}, or -1 if an
38198error occurred.
38199
0a93529c
GB
38200@item vFile:fstat: @var{fd}
38201Get information about the open file corresponding to @var{fd}.
38202On success the information is returned as a binary attachment
38203and the return value is the size of this attachment in bytes.
38204If an error occurs the return value is -1. The format of the
38205returned binary attachment is as described in @ref{struct stat}.
38206
697aa1b7
EZ
38207@item vFile:unlink: @var{filename}
38208Delete the file at @var{filename} on the target. Return 0,
38209or -1 if an error occurs. The @var{filename} is a string.
a6b151f1 38210
b9e7b9c3
UW
38211@item vFile:readlink: @var{filename}
38212Read value of symbolic link @var{filename} on the target. Return
38213the number of bytes read, or -1 if an error occurs.
38214
38215The data read should be returned as a binary attachment on success.
38216If zero bytes were read, the response should include an empty binary
38217attachment (i.e.@: a trailing semicolon). The return value is the
38218number of target bytes read; the binary attachment may be longer if
38219some characters were escaped.
38220
15a201c8
GB
38221@item vFile:setfs: @var{pid}
38222Select the filesystem on which @code{vFile} operations with
38223@var{filename} arguments will operate. This is required for
38224@value{GDBN} to be able to access files on remote targets where
38225the remote stub does not share a common filesystem with the
38226inferior(s).
38227
38228If @var{pid} is nonzero, select the filesystem as seen by process
38229@var{pid}. If @var{pid} is zero, select the filesystem as seen by
38230the remote stub. Return 0 on success, or -1 if an error occurs.
38231If @code{vFile:setfs:} indicates success, the selected filesystem
38232remains selected until the next successful @code{vFile:setfs:}
38233operation.
38234
a6b151f1
DJ
38235@end table
38236
9a6253be
KB
38237@node Interrupts
38238@section Interrupts
38239@cindex interrupts (remote protocol)
de979965 38240@anchor{interrupting remote targets}
9a6253be 38241
de979965
PA
38242In all-stop mode, when a program on the remote target is running,
38243@value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
38244@code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
38245is specified via @value{GDBN}'s @samp{interrupt-sequence}.
9a6253be
KB
38246
38247The precise meaning of @code{BREAK} is defined by the transport
8775bb90
MS
38248mechanism and may, in fact, be undefined. @value{GDBN} does not
38249currently define a @code{BREAK} mechanism for any of the network
38250interfaces except for TCP, in which case @value{GDBN} sends the
38251@code{telnet} BREAK sequence.
9a6253be
KB
38252
38253@samp{Ctrl-C}, on the other hand, is defined and implemented for all
38254transport mechanisms. It is represented by sending the single byte
38255@code{0x03} without any of the usual packet overhead described in
38256the Overview section (@pxref{Overview}). When a @code{0x03} byte is
38257transmitted as part of a packet, it is considered to be packet data
38258and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 38259(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
38260@code{0x03} as part of its packet.
38261
9a7071a8
JB
38262@code{BREAK} followed by @code{g} is also known as Magic SysRq g.
38263When Linux kernel receives this sequence from serial port,
38264it stops execution and connects to gdb.
38265
de979965
PA
38266In non-stop mode, because packet resumptions are asynchronous
38267(@pxref{vCont packet}), @value{GDBN} is always free to send a remote
38268command to the remote stub, even when the target is running. For that
38269reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
38270packet}) with the usual packet framing instead of the single byte
38271@code{0x03}.
38272
9a6253be
KB
38273Stubs are not required to recognize these interrupt mechanisms and the
38274precise meaning associated with receipt of the interrupt is
8b23ecc4
SL
38275implementation defined. If the target supports debugging of multiple
38276threads and/or processes, it should attempt to interrupt all
38277currently-executing threads and processes.
38278If the stub is successful at interrupting the
38279running program, it should send one of the stop
38280reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
38281of successfully stopping the program in all-stop mode, and a stop reply
38282for each stopped thread in non-stop mode.
38283Interrupts received while the
cde67b27
YQ
38284program is stopped are queued and the program will be interrupted when
38285it is resumed next time.
8b23ecc4
SL
38286
38287@node Notification Packets
38288@section Notification Packets
38289@cindex notification packets
38290@cindex packets, notification
38291
38292The @value{GDBN} remote serial protocol includes @dfn{notifications},
38293packets that require no acknowledgment. Both the GDB and the stub
38294may send notifications (although the only notifications defined at
38295present are sent by the stub). Notifications carry information
38296without incurring the round-trip latency of an acknowledgment, and so
38297are useful for low-impact communications where occasional packet loss
38298is not a problem.
38299
38300A notification packet has the form @samp{% @var{data} #
38301@var{checksum}}, where @var{data} is the content of the notification,
38302and @var{checksum} is a checksum of @var{data}, computed and formatted
38303as for ordinary @value{GDBN} packets. A notification's @var{data}
38304never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
38305receiving a notification, the recipient sends no @samp{+} or @samp{-}
38306to acknowledge the notification's receipt or to report its corruption.
38307
38308Every notification's @var{data} begins with a name, which contains no
38309colon characters, followed by a colon character.
38310
38311Recipients should silently ignore corrupted notifications and
38312notifications they do not understand. Recipients should restart
38313timeout periods on receipt of a well-formed notification, whether or
38314not they understand it.
38315
38316Senders should only send the notifications described here when this
38317protocol description specifies that they are permitted. In the
38318future, we may extend the protocol to permit existing notifications in
38319new contexts; this rule helps older senders avoid confusing newer
38320recipients.
38321
38322(Older versions of @value{GDBN} ignore bytes received until they see
38323the @samp{$} byte that begins an ordinary packet, so new stubs may
38324transmit notifications without fear of confusing older clients. There
38325are no notifications defined for @value{GDBN} to send at the moment, but we
38326assume that most older stubs would ignore them, as well.)
38327
8dbe8ece 38328Each notification is comprised of three parts:
8b23ecc4 38329@table @samp
8dbe8ece
YQ
38330@item @var{name}:@var{event}
38331The notification packet is sent by the side that initiates the
38332exchange (currently, only the stub does that), with @var{event}
697aa1b7
EZ
38333carrying the specific information about the notification, and
38334@var{name} specifying the name of the notification.
8dbe8ece
YQ
38335@item @var{ack}
38336The acknowledge sent by the other side, usually @value{GDBN}, to
38337acknowledge the exchange and request the event.
38338@end table
38339
38340The purpose of an asynchronous notification mechanism is to report to
38341@value{GDBN} that something interesting happened in the remote stub.
38342
38343The remote stub may send notification @var{name}:@var{event}
38344at any time, but @value{GDBN} acknowledges the notification when
38345appropriate. The notification event is pending before @value{GDBN}
38346acknowledges. Only one notification at a time may be pending; if
38347additional events occur before @value{GDBN} has acknowledged the
38348previous notification, they must be queued by the stub for later
38349synchronous transmission in response to @var{ack} packets from
38350@value{GDBN}. Because the notification mechanism is unreliable,
38351the stub is permitted to resend a notification if it believes
38352@value{GDBN} may not have received it.
38353
38354Specifically, notifications may appear when @value{GDBN} is not
38355otherwise reading input from the stub, or when @value{GDBN} is
38356expecting to read a normal synchronous response or a
38357@samp{+}/@samp{-} acknowledgment to a packet it has sent.
38358Notification packets are distinct from any other communication from
38359the stub so there is no ambiguity.
38360
38361After receiving a notification, @value{GDBN} shall acknowledge it by
38362sending a @var{ack} packet as a regular, synchronous request to the
38363stub. Such acknowledgment is not required to happen immediately, as
38364@value{GDBN} is permitted to send other, unrelated packets to the
38365stub first, which the stub should process normally.
38366
38367Upon receiving a @var{ack} packet, if the stub has other queued
38368events to report to @value{GDBN}, it shall respond by sending a
38369normal @var{event}. @value{GDBN} shall then send another @var{ack}
38370packet to solicit further responses; again, it is permitted to send
38371other, unrelated packets as well which the stub should process
38372normally.
38373
38374If the stub receives a @var{ack} packet and there are no additional
38375@var{event} to report, the stub shall return an @samp{OK} response.
38376At this point, @value{GDBN} has finished processing a notification
38377and the stub has completed sending any queued events. @value{GDBN}
38378won't accept any new notifications until the final @samp{OK} is
38379received . If further notification events occur, the stub shall send
38380a new notification, @value{GDBN} shall accept the notification, and
38381the process shall be repeated.
38382
38383The process of asynchronous notification can be illustrated by the
38384following example:
38385@smallexample
38386<- @code{%%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
38387@code{...}
38388-> @code{vStopped}
38389<- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
38390-> @code{vStopped}
38391<- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
38392-> @code{vStopped}
38393<- @code{OK}
38394@end smallexample
38395
38396The following notifications are defined:
38397@multitable @columnfractions 0.12 0.12 0.38 0.38
38398
38399@item Notification
38400@tab Ack
38401@tab Event
38402@tab Description
38403
38404@item Stop
38405@tab vStopped
38406@tab @var{reply}. The @var{reply} has the form of a stop reply, as
8b23ecc4
SL
38407described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
38408for information on how these notifications are acknowledged by
38409@value{GDBN}.
8dbe8ece
YQ
38410@tab Report an asynchronous stop event in non-stop mode.
38411
38412@end multitable
8b23ecc4
SL
38413
38414@node Remote Non-Stop
38415@section Remote Protocol Support for Non-Stop Mode
38416
38417@value{GDBN}'s remote protocol supports non-stop debugging of
38418multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
38419supports non-stop mode, it should report that to @value{GDBN} by including
38420@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
38421
38422@value{GDBN} typically sends a @samp{QNonStop} packet only when
38423establishing a new connection with the stub. Entering non-stop mode
38424does not alter the state of any currently-running threads, but targets
38425must stop all threads in any already-attached processes when entering
38426all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
38427probe the target state after a mode change.
38428
38429In non-stop mode, when an attached process encounters an event that
38430would otherwise be reported with a stop reply, it uses the
38431asynchronous notification mechanism (@pxref{Notification Packets}) to
38432inform @value{GDBN}. In contrast to all-stop mode, where all threads
38433in all processes are stopped when a stop reply is sent, in non-stop
38434mode only the thread reporting the stop event is stopped. That is,
38435when reporting a @samp{S} or @samp{T} response to indicate completion
38436of a step operation, hitting a breakpoint, or a fault, only the
38437affected thread is stopped; any other still-running threads continue
38438to run. When reporting a @samp{W} or @samp{X} response, all running
38439threads belonging to other attached processes continue to run.
38440
8b23ecc4
SL
38441In non-stop mode, the target shall respond to the @samp{?} packet as
38442follows. First, any incomplete stop reply notification/@samp{vStopped}
38443sequence in progress is abandoned. The target must begin a new
38444sequence reporting stop events for all stopped threads, whether or not
38445it has previously reported those events to @value{GDBN}. The first
38446stop reply is sent as a synchronous reply to the @samp{?} packet, and
38447subsequent stop replies are sent as responses to @samp{vStopped} packets
38448using the mechanism described above. The target must not send
38449asynchronous stop reply notifications until the sequence is complete.
38450If all threads are running when the target receives the @samp{?} packet,
38451or if the target is not attached to any process, it shall respond
38452@samp{OK}.
9a6253be 38453
f7e6eed5
PA
38454If the stub supports non-stop mode, it should also support the
38455@samp{swbreak} stop reason if software breakpoints are supported, and
38456the @samp{hwbreak} stop reason if hardware breakpoints are supported
38457(@pxref{swbreak stop reason}). This is because given the asynchronous
38458nature of non-stop mode, between the time a thread hits a breakpoint
38459and the time the event is finally processed by @value{GDBN}, the
38460breakpoint may have already been removed from the target. Due to
38461this, @value{GDBN} needs to be able to tell whether a trap stop was
38462caused by a delayed breakpoint event, which should be ignored, as
38463opposed to a random trap signal, which should be reported to the user.
38464Note the @samp{swbreak} feature implies that the target is responsible
38465for adjusting the PC when a software breakpoint triggers, if
38466necessary, such as on the x86 architecture.
38467
a6f3e723
SL
38468@node Packet Acknowledgment
38469@section Packet Acknowledgment
38470
38471@cindex acknowledgment, for @value{GDBN} remote
38472@cindex packet acknowledgment, for @value{GDBN} remote
38473By default, when either the host or the target machine receives a packet,
38474the first response expected is an acknowledgment: either @samp{+} (to indicate
38475the package was received correctly) or @samp{-} (to request retransmission).
38476This mechanism allows the @value{GDBN} remote protocol to operate over
38477unreliable transport mechanisms, such as a serial line.
38478
38479In cases where the transport mechanism is itself reliable (such as a pipe or
38480TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
38481It may be desirable to disable them in that case to reduce communication
38482overhead, or for other reasons. This can be accomplished by means of the
38483@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
38484
38485When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
38486expect @samp{+}/@samp{-} protocol acknowledgments. The packet
38487and response format still includes the normal checksum, as described in
38488@ref{Overview}, but the checksum may be ignored by the receiver.
38489
38490If the stub supports @samp{QStartNoAckMode} and prefers to operate in
38491no-acknowledgment mode, it should report that to @value{GDBN}
38492by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
38493@pxref{qSupported}.
38494If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
38495disabled via the @code{set remote noack-packet off} command
38496(@pxref{Remote Configuration}),
38497@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
38498Only then may the stub actually turn off packet acknowledgments.
38499@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
38500response, which can be safely ignored by the stub.
38501
38502Note that @code{set remote noack-packet} command only affects negotiation
38503between @value{GDBN} and the stub when subsequent connections are made;
38504it does not affect the protocol acknowledgment state for any current
38505connection.
38506Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
38507new connection is established,
38508there is also no protocol request to re-enable the acknowledgments
38509for the current connection, once disabled.
38510
ee2d5c50
AC
38511@node Examples
38512@section Examples
eb12ee30 38513
8e04817f
AC
38514Example sequence of a target being re-started. Notice how the restart
38515does not get any direct output:
eb12ee30 38516
474c8240 38517@smallexample
d2c6833e
AC
38518-> @code{R00}
38519<- @code{+}
8e04817f 38520@emph{target restarts}
d2c6833e 38521-> @code{?}
8e04817f 38522<- @code{+}
d2c6833e
AC
38523<- @code{T001:1234123412341234}
38524-> @code{+}
474c8240 38525@end smallexample
eb12ee30 38526
8e04817f 38527Example sequence of a target being stepped by a single instruction:
eb12ee30 38528
474c8240 38529@smallexample
d2c6833e 38530-> @code{G1445@dots{}}
8e04817f 38531<- @code{+}
d2c6833e
AC
38532-> @code{s}
38533<- @code{+}
38534@emph{time passes}
38535<- @code{T001:1234123412341234}
8e04817f 38536-> @code{+}
d2c6833e 38537-> @code{g}
8e04817f 38538<- @code{+}
d2c6833e
AC
38539<- @code{1455@dots{}}
38540-> @code{+}
474c8240 38541@end smallexample
eb12ee30 38542
79a6e687
BW
38543@node File-I/O Remote Protocol Extension
38544@section File-I/O Remote Protocol Extension
0ce1b118
CV
38545@cindex File-I/O remote protocol extension
38546
38547@menu
38548* File-I/O Overview::
79a6e687
BW
38549* Protocol Basics::
38550* The F Request Packet::
38551* The F Reply Packet::
38552* The Ctrl-C Message::
0ce1b118 38553* Console I/O::
79a6e687 38554* List of Supported Calls::
db2e3e2e 38555* Protocol-specific Representation of Datatypes::
0ce1b118
CV
38556* Constants::
38557* File-I/O Examples::
38558@end menu
38559
38560@node File-I/O Overview
38561@subsection File-I/O Overview
38562@cindex file-i/o overview
38563
9c16f35a 38564The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 38565target to use the host's file system and console I/O to perform various
0ce1b118 38566system calls. System calls on the target system are translated into a
fc320d37
SL
38567remote protocol packet to the host system, which then performs the needed
38568actions and returns a response packet to the target system.
0ce1b118
CV
38569This simulates file system operations even on targets that lack file systems.
38570
fc320d37
SL
38571The protocol is defined to be independent of both the host and target systems.
38572It uses its own internal representation of datatypes and values. Both
0ce1b118 38573@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
38574translating the system-dependent value representations into the internal
38575protocol representations when data is transmitted.
0ce1b118 38576
fc320d37
SL
38577The communication is synchronous. A system call is possible only when
38578@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
38579or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 38580the target is stopped to allow deterministic access to the target's
fc320d37
SL
38581memory. Therefore File-I/O is not interruptible by target signals. On
38582the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 38583(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
38584
38585The target's request to perform a host system call does not finish
38586the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
38587after finishing the system call, the target returns to continuing the
38588previous activity (continue, step). No additional continue or step
38589request from @value{GDBN} is required.
38590
38591@smallexample
f7dc1244 38592(@value{GDBP}) continue
0ce1b118
CV
38593 <- target requests 'system call X'
38594 target is stopped, @value{GDBN} executes system call
3f94c067
BW
38595 -> @value{GDBN} returns result
38596 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
38597 <- target hits breakpoint and sends a Txx packet
38598@end smallexample
38599
fc320d37
SL
38600The protocol only supports I/O on the console and to regular files on
38601the host file system. Character or block special devices, pipes,
38602named pipes, sockets or any other communication method on the host
0ce1b118
CV
38603system are not supported by this protocol.
38604
8b23ecc4
SL
38605File I/O is not supported in non-stop mode.
38606
79a6e687
BW
38607@node Protocol Basics
38608@subsection Protocol Basics
0ce1b118
CV
38609@cindex protocol basics, file-i/o
38610
fc320d37
SL
38611The File-I/O protocol uses the @code{F} packet as the request as well
38612as reply packet. Since a File-I/O system call can only occur when
38613@value{GDBN} is waiting for a response from the continuing or stepping target,
38614the File-I/O request is a reply that @value{GDBN} has to expect as a result
38615of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
38616This @code{F} packet contains all information needed to allow @value{GDBN}
38617to call the appropriate host system call:
38618
38619@itemize @bullet
b383017d 38620@item
0ce1b118
CV
38621A unique identifier for the requested system call.
38622
38623@item
38624All parameters to the system call. Pointers are given as addresses
38625in the target memory address space. Pointers to strings are given as
b383017d 38626pointer/length pair. Numerical values are given as they are.
db2e3e2e 38627Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
38628
38629@end itemize
38630
fc320d37 38631At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
38632
38633@itemize @bullet
b383017d 38634@item
fc320d37
SL
38635If the parameters include pointer values to data needed as input to a
38636system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
38637standard @code{m} packet request. This additional communication has to be
38638expected by the target implementation and is handled as any other @code{m}
38639packet.
38640
38641@item
38642@value{GDBN} translates all value from protocol representation to host
38643representation as needed. Datatypes are coerced into the host types.
38644
38645@item
fc320d37 38646@value{GDBN} calls the system call.
0ce1b118
CV
38647
38648@item
38649It then coerces datatypes back to protocol representation.
38650
38651@item
fc320d37
SL
38652If the system call is expected to return data in buffer space specified
38653by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
38654target using a @code{M} or @code{X} packet. This packet has to be expected
38655by the target implementation and is handled as any other @code{M} or @code{X}
38656packet.
38657
38658@end itemize
38659
38660Eventually @value{GDBN} replies with another @code{F} packet which contains all
38661necessary information for the target to continue. This at least contains
38662
38663@itemize @bullet
38664@item
38665Return value.
38666
38667@item
38668@code{errno}, if has been changed by the system call.
38669
38670@item
38671``Ctrl-C'' flag.
38672
38673@end itemize
38674
38675After having done the needed type and value coercion, the target continues
38676the latest continue or step action.
38677
79a6e687
BW
38678@node The F Request Packet
38679@subsection The @code{F} Request Packet
0ce1b118
CV
38680@cindex file-i/o request packet
38681@cindex @code{F} request packet
38682
38683The @code{F} request packet has the following format:
38684
38685@table @samp
fc320d37 38686@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
38687
38688@var{call-id} is the identifier to indicate the host system call to be called.
38689This is just the name of the function.
38690
fc320d37
SL
38691@var{parameter@dots{}} are the parameters to the system call.
38692Parameters are hexadecimal integer values, either the actual values in case
38693of scalar datatypes, pointers to target buffer space in case of compound
38694datatypes and unspecified memory areas, or pointer/length pairs in case
38695of string parameters. These are appended to the @var{call-id} as a
38696comma-delimited list. All values are transmitted in ASCII
38697string representation, pointer/length pairs separated by a slash.
0ce1b118 38698
b383017d 38699@end table
0ce1b118 38700
fc320d37 38701
0ce1b118 38702
79a6e687
BW
38703@node The F Reply Packet
38704@subsection The @code{F} Reply Packet
0ce1b118
CV
38705@cindex file-i/o reply packet
38706@cindex @code{F} reply packet
38707
38708The @code{F} reply packet has the following format:
38709
38710@table @samp
38711
d3bdde98 38712@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
38713
38714@var{retcode} is the return code of the system call as hexadecimal value.
38715
db2e3e2e
BW
38716@var{errno} is the @code{errno} set by the call, in protocol-specific
38717representation.
0ce1b118
CV
38718This parameter can be omitted if the call was successful.
38719
fc320d37
SL
38720@var{Ctrl-C flag} is only sent if the user requested a break. In this
38721case, @var{errno} must be sent as well, even if the call was successful.
38722The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
38723
38724@smallexample
38725F0,0,C
38726@end smallexample
38727
38728@noindent
fc320d37 38729or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
38730
38731@smallexample
38732F-1,4,C
38733@end smallexample
38734
38735@noindent
db2e3e2e 38736assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
38737
38738@end table
38739
0ce1b118 38740
79a6e687
BW
38741@node The Ctrl-C Message
38742@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
38743@cindex ctrl-c message, in file-i/o protocol
38744
c8aa23ab 38745If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 38746reply packet (@pxref{The F Reply Packet}),
fc320d37 38747the target should behave as if it had
0ce1b118 38748gotten a break message. The meaning for the target is ``system call
fc320d37 38749interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 38750(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 38751packet.
fc320d37
SL
38752
38753It's important for the target to know in which
38754state the system call was interrupted. There are two possible cases:
0ce1b118
CV
38755
38756@itemize @bullet
38757@item
38758The system call hasn't been performed on the host yet.
38759
38760@item
38761The system call on the host has been finished.
38762
38763@end itemize
38764
38765These two states can be distinguished by the target by the value of the
38766returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
38767call hasn't been performed. This is equivalent to the @code{EINTR} handling
38768on POSIX systems. In any other case, the target may presume that the
fc320d37 38769system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
38770as if the break message arrived right after the system call.
38771
fc320d37 38772@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
38773yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
38774@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
38775before the user requests a break, the full action must be finished by
38776@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
38777The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
38778or the full action has been completed.
38779
38780@node Console I/O
38781@subsection Console I/O
38782@cindex console i/o as part of file-i/o
38783
d3e8051b 38784By default and if not explicitly closed by the target system, the file
0ce1b118
CV
38785descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
38786on the @value{GDBN} console is handled as any other file output operation
38787(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
38788by @value{GDBN} so that after the target read request from file descriptor
387890 all following typing is buffered until either one of the following
38790conditions is met:
38791
38792@itemize @bullet
38793@item
c8aa23ab 38794The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
38795@code{read}
38796system call is treated as finished.
38797
38798@item
7f9087cb 38799The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 38800newline.
0ce1b118
CV
38801
38802@item
c8aa23ab
EZ
38803The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
38804character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
38805
38806@end itemize
38807
fc320d37
SL
38808If the user has typed more characters than fit in the buffer given to
38809the @code{read} call, the trailing characters are buffered in @value{GDBN} until
38810either another @code{read(0, @dots{})} is requested by the target, or debugging
38811is stopped at the user's request.
0ce1b118 38812
0ce1b118 38813
79a6e687
BW
38814@node List of Supported Calls
38815@subsection List of Supported Calls
0ce1b118
CV
38816@cindex list of supported file-i/o calls
38817
38818@menu
38819* open::
38820* close::
38821* read::
38822* write::
38823* lseek::
38824* rename::
38825* unlink::
38826* stat/fstat::
38827* gettimeofday::
38828* isatty::
38829* system::
38830@end menu
38831
38832@node open
38833@unnumberedsubsubsec open
38834@cindex open, file-i/o system call
38835
fc320d37
SL
38836@table @asis
38837@item Synopsis:
0ce1b118 38838@smallexample
0ce1b118
CV
38839int open(const char *pathname, int flags);
38840int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
38841@end smallexample
38842
fc320d37
SL
38843@item Request:
38844@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
38845
0ce1b118 38846@noindent
fc320d37 38847@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
38848
38849@table @code
b383017d 38850@item O_CREAT
0ce1b118
CV
38851If the file does not exist it will be created. The host
38852rules apply as far as file ownership and time stamps
38853are concerned.
38854
b383017d 38855@item O_EXCL
fc320d37 38856When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
38857an error and open() fails.
38858
b383017d 38859@item O_TRUNC
0ce1b118 38860If the file already exists and the open mode allows
fc320d37
SL
38861writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
38862truncated to zero length.
0ce1b118 38863
b383017d 38864@item O_APPEND
0ce1b118
CV
38865The file is opened in append mode.
38866
b383017d 38867@item O_RDONLY
0ce1b118
CV
38868The file is opened for reading only.
38869
b383017d 38870@item O_WRONLY
0ce1b118
CV
38871The file is opened for writing only.
38872
b383017d 38873@item O_RDWR
0ce1b118 38874The file is opened for reading and writing.
fc320d37 38875@end table
0ce1b118
CV
38876
38877@noindent
fc320d37 38878Other bits are silently ignored.
0ce1b118 38879
0ce1b118
CV
38880
38881@noindent
fc320d37 38882@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
38883
38884@table @code
b383017d 38885@item S_IRUSR
0ce1b118
CV
38886User has read permission.
38887
b383017d 38888@item S_IWUSR
0ce1b118
CV
38889User has write permission.
38890
b383017d 38891@item S_IRGRP
0ce1b118
CV
38892Group has read permission.
38893
b383017d 38894@item S_IWGRP
0ce1b118
CV
38895Group has write permission.
38896
b383017d 38897@item S_IROTH
0ce1b118
CV
38898Others have read permission.
38899
b383017d 38900@item S_IWOTH
0ce1b118 38901Others have write permission.
fc320d37 38902@end table
0ce1b118
CV
38903
38904@noindent
fc320d37 38905Other bits are silently ignored.
0ce1b118 38906
0ce1b118 38907
fc320d37
SL
38908@item Return value:
38909@code{open} returns the new file descriptor or -1 if an error
38910occurred.
0ce1b118 38911
fc320d37 38912@item Errors:
0ce1b118
CV
38913
38914@table @code
b383017d 38915@item EEXIST
fc320d37 38916@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 38917
b383017d 38918@item EISDIR
fc320d37 38919@var{pathname} refers to a directory.
0ce1b118 38920
b383017d 38921@item EACCES
0ce1b118
CV
38922The requested access is not allowed.
38923
38924@item ENAMETOOLONG
fc320d37 38925@var{pathname} was too long.
0ce1b118 38926
b383017d 38927@item ENOENT
fc320d37 38928A directory component in @var{pathname} does not exist.
0ce1b118 38929
b383017d 38930@item ENODEV
fc320d37 38931@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 38932
b383017d 38933@item EROFS
fc320d37 38934@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
38935write access was requested.
38936
b383017d 38937@item EFAULT
fc320d37 38938@var{pathname} is an invalid pointer value.
0ce1b118 38939
b383017d 38940@item ENOSPC
0ce1b118
CV
38941No space on device to create the file.
38942
b383017d 38943@item EMFILE
0ce1b118
CV
38944The process already has the maximum number of files open.
38945
b383017d 38946@item ENFILE
0ce1b118
CV
38947The limit on the total number of files open on the system
38948has been reached.
38949
b383017d 38950@item EINTR
0ce1b118
CV
38951The call was interrupted by the user.
38952@end table
38953
fc320d37
SL
38954@end table
38955
0ce1b118
CV
38956@node close
38957@unnumberedsubsubsec close
38958@cindex close, file-i/o system call
38959
fc320d37
SL
38960@table @asis
38961@item Synopsis:
0ce1b118 38962@smallexample
0ce1b118 38963int close(int fd);
fc320d37 38964@end smallexample
0ce1b118 38965
fc320d37
SL
38966@item Request:
38967@samp{Fclose,@var{fd}}
0ce1b118 38968
fc320d37
SL
38969@item Return value:
38970@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 38971
fc320d37 38972@item Errors:
0ce1b118
CV
38973
38974@table @code
b383017d 38975@item EBADF
fc320d37 38976@var{fd} isn't a valid open file descriptor.
0ce1b118 38977
b383017d 38978@item EINTR
0ce1b118
CV
38979The call was interrupted by the user.
38980@end table
38981
fc320d37
SL
38982@end table
38983
0ce1b118
CV
38984@node read
38985@unnumberedsubsubsec read
38986@cindex read, file-i/o system call
38987
fc320d37
SL
38988@table @asis
38989@item Synopsis:
0ce1b118 38990@smallexample
0ce1b118 38991int read(int fd, void *buf, unsigned int count);
fc320d37 38992@end smallexample
0ce1b118 38993
fc320d37
SL
38994@item Request:
38995@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 38996
fc320d37 38997@item Return value:
0ce1b118
CV
38998On success, the number of bytes read is returned.
38999Zero indicates end of file. If count is zero, read
b383017d 39000returns zero as well. On error, -1 is returned.
0ce1b118 39001
fc320d37 39002@item Errors:
0ce1b118
CV
39003
39004@table @code
b383017d 39005@item EBADF
fc320d37 39006@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
39007reading.
39008
b383017d 39009@item EFAULT
fc320d37 39010@var{bufptr} is an invalid pointer value.
0ce1b118 39011
b383017d 39012@item EINTR
0ce1b118
CV
39013The call was interrupted by the user.
39014@end table
39015
fc320d37
SL
39016@end table
39017
0ce1b118
CV
39018@node write
39019@unnumberedsubsubsec write
39020@cindex write, file-i/o system call
39021
fc320d37
SL
39022@table @asis
39023@item Synopsis:
0ce1b118 39024@smallexample
0ce1b118 39025int write(int fd, const void *buf, unsigned int count);
fc320d37 39026@end smallexample
0ce1b118 39027
fc320d37
SL
39028@item Request:
39029@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 39030
fc320d37 39031@item Return value:
0ce1b118
CV
39032On success, the number of bytes written are returned.
39033Zero indicates nothing was written. On error, -1
39034is returned.
39035
fc320d37 39036@item Errors:
0ce1b118
CV
39037
39038@table @code
b383017d 39039@item EBADF
fc320d37 39040@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
39041writing.
39042
b383017d 39043@item EFAULT
fc320d37 39044@var{bufptr} is an invalid pointer value.
0ce1b118 39045
b383017d 39046@item EFBIG
0ce1b118 39047An attempt was made to write a file that exceeds the
db2e3e2e 39048host-specific maximum file size allowed.
0ce1b118 39049
b383017d 39050@item ENOSPC
0ce1b118
CV
39051No space on device to write the data.
39052
b383017d 39053@item EINTR
0ce1b118
CV
39054The call was interrupted by the user.
39055@end table
39056
fc320d37
SL
39057@end table
39058
0ce1b118
CV
39059@node lseek
39060@unnumberedsubsubsec lseek
39061@cindex lseek, file-i/o system call
39062
fc320d37
SL
39063@table @asis
39064@item Synopsis:
0ce1b118 39065@smallexample
0ce1b118 39066long lseek (int fd, long offset, int flag);
0ce1b118
CV
39067@end smallexample
39068
fc320d37
SL
39069@item Request:
39070@samp{Flseek,@var{fd},@var{offset},@var{flag}}
39071
39072@var{flag} is one of:
0ce1b118
CV
39073
39074@table @code
b383017d 39075@item SEEK_SET
fc320d37 39076The offset is set to @var{offset} bytes.
0ce1b118 39077
b383017d 39078@item SEEK_CUR
fc320d37 39079The offset is set to its current location plus @var{offset}
0ce1b118
CV
39080bytes.
39081
b383017d 39082@item SEEK_END
fc320d37 39083The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
39084bytes.
39085@end table
39086
fc320d37 39087@item Return value:
0ce1b118
CV
39088On success, the resulting unsigned offset in bytes from
39089the beginning of the file is returned. Otherwise, a
39090value of -1 is returned.
39091
fc320d37 39092@item Errors:
0ce1b118
CV
39093
39094@table @code
b383017d 39095@item EBADF
fc320d37 39096@var{fd} is not a valid open file descriptor.
0ce1b118 39097
b383017d 39098@item ESPIPE
fc320d37 39099@var{fd} is associated with the @value{GDBN} console.
0ce1b118 39100
b383017d 39101@item EINVAL
fc320d37 39102@var{flag} is not a proper value.
0ce1b118 39103
b383017d 39104@item EINTR
0ce1b118
CV
39105The call was interrupted by the user.
39106@end table
39107
fc320d37
SL
39108@end table
39109
0ce1b118
CV
39110@node rename
39111@unnumberedsubsubsec rename
39112@cindex rename, file-i/o system call
39113
fc320d37
SL
39114@table @asis
39115@item Synopsis:
0ce1b118 39116@smallexample
0ce1b118 39117int rename(const char *oldpath, const char *newpath);
fc320d37 39118@end smallexample
0ce1b118 39119
fc320d37
SL
39120@item Request:
39121@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 39122
fc320d37 39123@item Return value:
0ce1b118
CV
39124On success, zero is returned. On error, -1 is returned.
39125
fc320d37 39126@item Errors:
0ce1b118
CV
39127
39128@table @code
b383017d 39129@item EISDIR
fc320d37 39130@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
39131directory.
39132
b383017d 39133@item EEXIST
fc320d37 39134@var{newpath} is a non-empty directory.
0ce1b118 39135
b383017d 39136@item EBUSY
fc320d37 39137@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
39138process.
39139
b383017d 39140@item EINVAL
0ce1b118
CV
39141An attempt was made to make a directory a subdirectory
39142of itself.
39143
b383017d 39144@item ENOTDIR
fc320d37
SL
39145A component used as a directory in @var{oldpath} or new
39146path is not a directory. Or @var{oldpath} is a directory
39147and @var{newpath} exists but is not a directory.
0ce1b118 39148
b383017d 39149@item EFAULT
fc320d37 39150@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 39151
b383017d 39152@item EACCES
0ce1b118
CV
39153No access to the file or the path of the file.
39154
39155@item ENAMETOOLONG
b383017d 39156
fc320d37 39157@var{oldpath} or @var{newpath} was too long.
0ce1b118 39158
b383017d 39159@item ENOENT
fc320d37 39160A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 39161
b383017d 39162@item EROFS
0ce1b118
CV
39163The file is on a read-only filesystem.
39164
b383017d 39165@item ENOSPC
0ce1b118
CV
39166The device containing the file has no room for the new
39167directory entry.
39168
b383017d 39169@item EINTR
0ce1b118
CV
39170The call was interrupted by the user.
39171@end table
39172
fc320d37
SL
39173@end table
39174
0ce1b118
CV
39175@node unlink
39176@unnumberedsubsubsec unlink
39177@cindex unlink, file-i/o system call
39178
fc320d37
SL
39179@table @asis
39180@item Synopsis:
0ce1b118 39181@smallexample
0ce1b118 39182int unlink(const char *pathname);
fc320d37 39183@end smallexample
0ce1b118 39184
fc320d37
SL
39185@item Request:
39186@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 39187
fc320d37 39188@item Return value:
0ce1b118
CV
39189On success, zero is returned. On error, -1 is returned.
39190
fc320d37 39191@item Errors:
0ce1b118
CV
39192
39193@table @code
b383017d 39194@item EACCES
0ce1b118
CV
39195No access to the file or the path of the file.
39196
b383017d 39197@item EPERM
0ce1b118
CV
39198The system does not allow unlinking of directories.
39199
b383017d 39200@item EBUSY
fc320d37 39201The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
39202being used by another process.
39203
b383017d 39204@item EFAULT
fc320d37 39205@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
39206
39207@item ENAMETOOLONG
fc320d37 39208@var{pathname} was too long.
0ce1b118 39209
b383017d 39210@item ENOENT
fc320d37 39211A directory component in @var{pathname} does not exist.
0ce1b118 39212
b383017d 39213@item ENOTDIR
0ce1b118
CV
39214A component of the path is not a directory.
39215
b383017d 39216@item EROFS
0ce1b118
CV
39217The file is on a read-only filesystem.
39218
b383017d 39219@item EINTR
0ce1b118
CV
39220The call was interrupted by the user.
39221@end table
39222
fc320d37
SL
39223@end table
39224
0ce1b118
CV
39225@node stat/fstat
39226@unnumberedsubsubsec stat/fstat
39227@cindex fstat, file-i/o system call
39228@cindex stat, file-i/o system call
39229
fc320d37
SL
39230@table @asis
39231@item Synopsis:
0ce1b118 39232@smallexample
0ce1b118
CV
39233int stat(const char *pathname, struct stat *buf);
39234int fstat(int fd, struct stat *buf);
fc320d37 39235@end smallexample
0ce1b118 39236
fc320d37
SL
39237@item Request:
39238@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
39239@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 39240
fc320d37 39241@item Return value:
0ce1b118
CV
39242On success, zero is returned. On error, -1 is returned.
39243
fc320d37 39244@item Errors:
0ce1b118
CV
39245
39246@table @code
b383017d 39247@item EBADF
fc320d37 39248@var{fd} is not a valid open file.
0ce1b118 39249
b383017d 39250@item ENOENT
fc320d37 39251A directory component in @var{pathname} does not exist or the
0ce1b118
CV
39252path is an empty string.
39253
b383017d 39254@item ENOTDIR
0ce1b118
CV
39255A component of the path is not a directory.
39256
b383017d 39257@item EFAULT
fc320d37 39258@var{pathnameptr} is an invalid pointer value.
0ce1b118 39259
b383017d 39260@item EACCES
0ce1b118
CV
39261No access to the file or the path of the file.
39262
39263@item ENAMETOOLONG
fc320d37 39264@var{pathname} was too long.
0ce1b118 39265
b383017d 39266@item EINTR
0ce1b118
CV
39267The call was interrupted by the user.
39268@end table
39269
fc320d37
SL
39270@end table
39271
0ce1b118
CV
39272@node gettimeofday
39273@unnumberedsubsubsec gettimeofday
39274@cindex gettimeofday, file-i/o system call
39275
fc320d37
SL
39276@table @asis
39277@item Synopsis:
0ce1b118 39278@smallexample
0ce1b118 39279int gettimeofday(struct timeval *tv, void *tz);
fc320d37 39280@end smallexample
0ce1b118 39281
fc320d37
SL
39282@item Request:
39283@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 39284
fc320d37 39285@item Return value:
0ce1b118
CV
39286On success, 0 is returned, -1 otherwise.
39287
fc320d37 39288@item Errors:
0ce1b118
CV
39289
39290@table @code
b383017d 39291@item EINVAL
fc320d37 39292@var{tz} is a non-NULL pointer.
0ce1b118 39293
b383017d 39294@item EFAULT
fc320d37
SL
39295@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
39296@end table
39297
0ce1b118
CV
39298@end table
39299
39300@node isatty
39301@unnumberedsubsubsec isatty
39302@cindex isatty, file-i/o system call
39303
fc320d37
SL
39304@table @asis
39305@item Synopsis:
0ce1b118 39306@smallexample
0ce1b118 39307int isatty(int fd);
fc320d37 39308@end smallexample
0ce1b118 39309
fc320d37
SL
39310@item Request:
39311@samp{Fisatty,@var{fd}}
0ce1b118 39312
fc320d37
SL
39313@item Return value:
39314Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 39315
fc320d37 39316@item Errors:
0ce1b118
CV
39317
39318@table @code
b383017d 39319@item EINTR
0ce1b118
CV
39320The call was interrupted by the user.
39321@end table
39322
fc320d37
SL
39323@end table
39324
39325Note that the @code{isatty} call is treated as a special case: it returns
393261 to the target if the file descriptor is attached
39327to the @value{GDBN} console, 0 otherwise. Implementing through system calls
39328would require implementing @code{ioctl} and would be more complex than
39329needed.
39330
39331
0ce1b118
CV
39332@node system
39333@unnumberedsubsubsec system
39334@cindex system, file-i/o system call
39335
fc320d37
SL
39336@table @asis
39337@item Synopsis:
0ce1b118 39338@smallexample
0ce1b118 39339int system(const char *command);
fc320d37 39340@end smallexample
0ce1b118 39341
fc320d37
SL
39342@item Request:
39343@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 39344
fc320d37 39345@item Return value:
5600ea19
NS
39346If @var{len} is zero, the return value indicates whether a shell is
39347available. A zero return value indicates a shell is not available.
39348For non-zero @var{len}, the value returned is -1 on error and the
39349return status of the command otherwise. Only the exit status of the
39350command is returned, which is extracted from the host's @code{system}
39351return value by calling @code{WEXITSTATUS(retval)}. In case
39352@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 39353
fc320d37 39354@item Errors:
0ce1b118
CV
39355
39356@table @code
b383017d 39357@item EINTR
0ce1b118
CV
39358The call was interrupted by the user.
39359@end table
39360
fc320d37
SL
39361@end table
39362
39363@value{GDBN} takes over the full task of calling the necessary host calls
39364to perform the @code{system} call. The return value of @code{system} on
39365the host is simplified before it's returned
39366to the target. Any termination signal information from the child process
39367is discarded, and the return value consists
39368entirely of the exit status of the called command.
39369
39370Due to security concerns, the @code{system} call is by default refused
39371by @value{GDBN}. The user has to allow this call explicitly with the
39372@code{set remote system-call-allowed 1} command.
39373
39374@table @code
39375@item set remote system-call-allowed
39376@kindex set remote system-call-allowed
39377Control whether to allow the @code{system} calls in the File I/O
39378protocol for the remote target. The default is zero (disabled).
39379
39380@item show remote system-call-allowed
39381@kindex show remote system-call-allowed
39382Show whether the @code{system} calls are allowed in the File I/O
39383protocol.
39384@end table
39385
db2e3e2e
BW
39386@node Protocol-specific Representation of Datatypes
39387@subsection Protocol-specific Representation of Datatypes
39388@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
39389
39390@menu
79a6e687
BW
39391* Integral Datatypes::
39392* Pointer Values::
39393* Memory Transfer::
0ce1b118
CV
39394* struct stat::
39395* struct timeval::
39396@end menu
39397
79a6e687
BW
39398@node Integral Datatypes
39399@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
39400@cindex integral datatypes, in file-i/o protocol
39401
fc320d37
SL
39402The integral datatypes used in the system calls are @code{int},
39403@code{unsigned int}, @code{long}, @code{unsigned long},
39404@code{mode_t}, and @code{time_t}.
0ce1b118 39405
fc320d37 39406@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
39407implemented as 32 bit values in this protocol.
39408
fc320d37 39409@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 39410
0ce1b118
CV
39411@xref{Limits}, for corresponding MIN and MAX values (similar to those
39412in @file{limits.h}) to allow range checking on host and target.
39413
39414@code{time_t} datatypes are defined as seconds since the Epoch.
39415
39416All integral datatypes transferred as part of a memory read or write of a
39417structured datatype e.g.@: a @code{struct stat} have to be given in big endian
39418byte order.
39419
79a6e687
BW
39420@node Pointer Values
39421@unnumberedsubsubsec Pointer Values
0ce1b118
CV
39422@cindex pointer values, in file-i/o protocol
39423
39424Pointers to target data are transmitted as they are. An exception
39425is made for pointers to buffers for which the length isn't
39426transmitted as part of the function call, namely strings. Strings
39427are transmitted as a pointer/length pair, both as hex values, e.g.@:
39428
39429@smallexample
39430@code{1aaf/12}
39431@end smallexample
39432
39433@noindent
39434which is a pointer to data of length 18 bytes at position 0x1aaf.
39435The length is defined as the full string length in bytes, including
fc320d37
SL
39436the trailing null byte. For example, the string @code{"hello world"}
39437at address 0x123456 is transmitted as
0ce1b118
CV
39438
39439@smallexample
fc320d37 39440@code{123456/d}
0ce1b118
CV
39441@end smallexample
39442
79a6e687
BW
39443@node Memory Transfer
39444@unnumberedsubsubsec Memory Transfer
fc320d37
SL
39445@cindex memory transfer, in file-i/o protocol
39446
39447Structured data which is transferred using a memory read or write (for
db2e3e2e 39448example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
39449with all scalar multibyte datatypes being big endian. Translation to
39450this representation needs to be done both by the target before the @code{F}
39451packet is sent, and by @value{GDBN} before
39452it transfers memory to the target. Transferred pointers to structured
39453data should point to the already-coerced data at any time.
0ce1b118 39454
0ce1b118
CV
39455
39456@node struct stat
39457@unnumberedsubsubsec struct stat
39458@cindex struct stat, in file-i/o protocol
39459
fc320d37
SL
39460The buffer of type @code{struct stat} used by the target and @value{GDBN}
39461is defined as follows:
0ce1b118
CV
39462
39463@smallexample
39464struct stat @{
39465 unsigned int st_dev; /* device */
39466 unsigned int st_ino; /* inode */
39467 mode_t st_mode; /* protection */
39468 unsigned int st_nlink; /* number of hard links */
39469 unsigned int st_uid; /* user ID of owner */
39470 unsigned int st_gid; /* group ID of owner */
39471 unsigned int st_rdev; /* device type (if inode device) */
39472 unsigned long st_size; /* total size, in bytes */
39473 unsigned long st_blksize; /* blocksize for filesystem I/O */
39474 unsigned long st_blocks; /* number of blocks allocated */
39475 time_t st_atime; /* time of last access */
39476 time_t st_mtime; /* time of last modification */
39477 time_t st_ctime; /* time of last change */
39478@};
39479@end smallexample
39480
fc320d37 39481The integral datatypes conform to the definitions given in the
79a6e687 39482appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
39483structure is of size 64 bytes.
39484
39485The values of several fields have a restricted meaning and/or
39486range of values.
39487
fc320d37 39488@table @code
0ce1b118 39489
fc320d37
SL
39490@item st_dev
39491A value of 0 represents a file, 1 the console.
0ce1b118 39492
fc320d37
SL
39493@item st_ino
39494No valid meaning for the target. Transmitted unchanged.
0ce1b118 39495
fc320d37
SL
39496@item st_mode
39497Valid mode bits are described in @ref{Constants}. Any other
39498bits have currently no meaning for the target.
0ce1b118 39499
fc320d37
SL
39500@item st_uid
39501@itemx st_gid
39502@itemx st_rdev
39503No valid meaning for the target. Transmitted unchanged.
0ce1b118 39504
fc320d37
SL
39505@item st_atime
39506@itemx st_mtime
39507@itemx st_ctime
39508These values have a host and file system dependent
39509accuracy. Especially on Windows hosts, the file system may not
39510support exact timing values.
39511@end table
0ce1b118 39512
fc320d37
SL
39513The target gets a @code{struct stat} of the above representation and is
39514responsible for coercing it to the target representation before
0ce1b118
CV
39515continuing.
39516
fc320d37
SL
39517Note that due to size differences between the host, target, and protocol
39518representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
39519get truncated on the target.
39520
39521@node struct timeval
39522@unnumberedsubsubsec struct timeval
39523@cindex struct timeval, in file-i/o protocol
39524
fc320d37 39525The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
39526is defined as follows:
39527
39528@smallexample
b383017d 39529struct timeval @{
0ce1b118
CV
39530 time_t tv_sec; /* second */
39531 long tv_usec; /* microsecond */
39532@};
39533@end smallexample
39534
fc320d37 39535The integral datatypes conform to the definitions given in the
79a6e687 39536appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
39537structure is of size 8 bytes.
39538
39539@node Constants
39540@subsection Constants
39541@cindex constants, in file-i/o protocol
39542
39543The following values are used for the constants inside of the
fc320d37 39544protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
39545values before and after the call as needed.
39546
39547@menu
79a6e687
BW
39548* Open Flags::
39549* mode_t Values::
39550* Errno Values::
39551* Lseek Flags::
0ce1b118
CV
39552* Limits::
39553@end menu
39554
79a6e687
BW
39555@node Open Flags
39556@unnumberedsubsubsec Open Flags
0ce1b118
CV
39557@cindex open flags, in file-i/o protocol
39558
39559All values are given in hexadecimal representation.
39560
39561@smallexample
39562 O_RDONLY 0x0
39563 O_WRONLY 0x1
39564 O_RDWR 0x2
39565 O_APPEND 0x8
39566 O_CREAT 0x200
39567 O_TRUNC 0x400
39568 O_EXCL 0x800
39569@end smallexample
39570
79a6e687
BW
39571@node mode_t Values
39572@unnumberedsubsubsec mode_t Values
0ce1b118
CV
39573@cindex mode_t values, in file-i/o protocol
39574
39575All values are given in octal representation.
39576
39577@smallexample
39578 S_IFREG 0100000
39579 S_IFDIR 040000
39580 S_IRUSR 0400
39581 S_IWUSR 0200
39582 S_IXUSR 0100
39583 S_IRGRP 040
39584 S_IWGRP 020
39585 S_IXGRP 010
39586 S_IROTH 04
39587 S_IWOTH 02
39588 S_IXOTH 01
39589@end smallexample
39590
79a6e687
BW
39591@node Errno Values
39592@unnumberedsubsubsec Errno Values
0ce1b118
CV
39593@cindex errno values, in file-i/o protocol
39594
39595All values are given in decimal representation.
39596
39597@smallexample
39598 EPERM 1
39599 ENOENT 2
39600 EINTR 4
39601 EBADF 9
39602 EACCES 13
39603 EFAULT 14
39604 EBUSY 16
39605 EEXIST 17
39606 ENODEV 19
39607 ENOTDIR 20
39608 EISDIR 21
39609 EINVAL 22
39610 ENFILE 23
39611 EMFILE 24
39612 EFBIG 27
39613 ENOSPC 28
39614 ESPIPE 29
39615 EROFS 30
39616 ENAMETOOLONG 91
39617 EUNKNOWN 9999
39618@end smallexample
39619
fc320d37 39620 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
39621 any error value not in the list of supported error numbers.
39622
79a6e687
BW
39623@node Lseek Flags
39624@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
39625@cindex lseek flags, in file-i/o protocol
39626
39627@smallexample
39628 SEEK_SET 0
39629 SEEK_CUR 1
39630 SEEK_END 2
39631@end smallexample
39632
39633@node Limits
39634@unnumberedsubsubsec Limits
39635@cindex limits, in file-i/o protocol
39636
39637All values are given in decimal representation.
39638
39639@smallexample
39640 INT_MIN -2147483648
39641 INT_MAX 2147483647
39642 UINT_MAX 4294967295
39643 LONG_MIN -9223372036854775808
39644 LONG_MAX 9223372036854775807
39645 ULONG_MAX 18446744073709551615
39646@end smallexample
39647
39648@node File-I/O Examples
39649@subsection File-I/O Examples
39650@cindex file-i/o examples
39651
39652Example sequence of a write call, file descriptor 3, buffer is at target
39653address 0x1234, 6 bytes should be written:
39654
39655@smallexample
39656<- @code{Fwrite,3,1234,6}
39657@emph{request memory read from target}
39658-> @code{m1234,6}
39659<- XXXXXX
39660@emph{return "6 bytes written"}
39661-> @code{F6}
39662@end smallexample
39663
39664Example sequence of a read call, file descriptor 3, buffer is at target
39665address 0x1234, 6 bytes should be read:
39666
39667@smallexample
39668<- @code{Fread,3,1234,6}
39669@emph{request memory write to target}
39670-> @code{X1234,6:XXXXXX}
39671@emph{return "6 bytes read"}
39672-> @code{F6}
39673@end smallexample
39674
39675Example sequence of a read call, call fails on the host due to invalid
fc320d37 39676file descriptor (@code{EBADF}):
0ce1b118
CV
39677
39678@smallexample
39679<- @code{Fread,3,1234,6}
39680-> @code{F-1,9}
39681@end smallexample
39682
c8aa23ab 39683Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
39684host is called:
39685
39686@smallexample
39687<- @code{Fread,3,1234,6}
39688-> @code{F-1,4,C}
39689<- @code{T02}
39690@end smallexample
39691
c8aa23ab 39692Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
39693host is called:
39694
39695@smallexample
39696<- @code{Fread,3,1234,6}
39697-> @code{X1234,6:XXXXXX}
39698<- @code{T02}
39699@end smallexample
39700
cfa9d6d9
DJ
39701@node Library List Format
39702@section Library List Format
39703@cindex library list format, remote protocol
39704
39705On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
39706same process as your application to manage libraries. In this case,
39707@value{GDBN} can use the loader's symbol table and normal memory
39708operations to maintain a list of shared libraries. On other
39709platforms, the operating system manages loaded libraries.
39710@value{GDBN} can not retrieve the list of currently loaded libraries
39711through memory operations, so it uses the @samp{qXfer:libraries:read}
39712packet (@pxref{qXfer library list read}) instead. The remote stub
39713queries the target's operating system and reports which libraries
39714are loaded.
39715
39716The @samp{qXfer:libraries:read} packet returns an XML document which
39717lists loaded libraries and their offsets. Each library has an
1fddbabb
PA
39718associated name and one or more segment or section base addresses,
39719which report where the library was loaded in memory.
39720
39721For the common case of libraries that are fully linked binaries, the
39722library should have a list of segments. If the target supports
39723dynamic linking of a relocatable object file, its library XML element
39724should instead include a list of allocated sections. The segment or
39725section bases are start addresses, not relocation offsets; they do not
39726depend on the library's link-time base addresses.
cfa9d6d9 39727
9cceb671
DJ
39728@value{GDBN} must be linked with the Expat library to support XML
39729library lists. @xref{Expat}.
39730
cfa9d6d9
DJ
39731A simple memory map, with one loaded library relocated by a single
39732offset, looks like this:
39733
39734@smallexample
39735<library-list>
39736 <library name="/lib/libc.so.6">
39737 <segment address="0x10000000"/>
39738 </library>
39739</library-list>
39740@end smallexample
39741
1fddbabb
PA
39742Another simple memory map, with one loaded library with three
39743allocated sections (.text, .data, .bss), looks like this:
39744
39745@smallexample
39746<library-list>
39747 <library name="sharedlib.o">
39748 <section address="0x10000000"/>
39749 <section address="0x20000000"/>
39750 <section address="0x30000000"/>
39751 </library>
39752</library-list>
39753@end smallexample
39754
cfa9d6d9
DJ
39755The format of a library list is described by this DTD:
39756
39757@smallexample
39758<!-- library-list: Root element with versioning -->
39759<!ELEMENT library-list (library)*>
39760<!ATTLIST library-list version CDATA #FIXED "1.0">
1fddbabb 39761<!ELEMENT library (segment*, section*)>
cfa9d6d9
DJ
39762<!ATTLIST library name CDATA #REQUIRED>
39763<!ELEMENT segment EMPTY>
39764<!ATTLIST segment address CDATA #REQUIRED>
1fddbabb
PA
39765<!ELEMENT section EMPTY>
39766<!ATTLIST section address CDATA #REQUIRED>
cfa9d6d9
DJ
39767@end smallexample
39768
1fddbabb
PA
39769In addition, segments and section descriptors cannot be mixed within a
39770single library element, and you must supply at least one segment or
39771section for each library.
39772
2268b414
JK
39773@node Library List Format for SVR4 Targets
39774@section Library List Format for SVR4 Targets
39775@cindex library list format, remote protocol
39776
39777On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
39778(e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
39779shared libraries. Still a special library list provided by this packet is
39780more efficient for the @value{GDBN} remote protocol.
39781
39782The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
39783loaded libraries and their SVR4 linker parameters. For each library on SVR4
39784target, the following parameters are reported:
39785
39786@itemize @minus
39787@item
39788@code{name}, the absolute file name from the @code{l_name} field of
39789@code{struct link_map}.
39790@item
39791@code{lm} with address of @code{struct link_map} used for TLS
39792(Thread Local Storage) access.
39793@item
39794@code{l_addr}, the displacement as read from the field @code{l_addr} of
39795@code{struct link_map}. For prelinked libraries this is not an absolute
39796memory address. It is a displacement of absolute memory address against
39797address the file was prelinked to during the library load.
39798@item
39799@code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
39800@end itemize
39801
39802Additionally the single @code{main-lm} attribute specifies address of
39803@code{struct link_map} used for the main executable. This parameter is used
39804for TLS access and its presence is optional.
39805
39806@value{GDBN} must be linked with the Expat library to support XML
39807SVR4 library lists. @xref{Expat}.
39808
39809A simple memory map, with two loaded libraries (which do not use prelink),
39810looks like this:
39811
39812@smallexample
39813<library-list-svr4 version="1.0" main-lm="0xe4f8f8">
39814 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
39815 l_ld="0xe4eefc"/>
39816 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
db1ff28b 39817 l_ld="0x152350"/>
2268b414
JK
39818</library-list-svr>
39819@end smallexample
39820
39821The format of an SVR4 library list is described by this DTD:
39822
39823@smallexample
39824<!-- library-list-svr4: Root element with versioning -->
39825<!ELEMENT library-list-svr4 (library)*>
db1ff28b
JK
39826<!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
39827<!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
2268b414 39828<!ELEMENT library EMPTY>
db1ff28b
JK
39829<!ATTLIST library name CDATA #REQUIRED>
39830<!ATTLIST library lm CDATA #REQUIRED>
39831<!ATTLIST library l_addr CDATA #REQUIRED>
39832<!ATTLIST library l_ld CDATA #REQUIRED>
2268b414
JK
39833@end smallexample
39834
79a6e687
BW
39835@node Memory Map Format
39836@section Memory Map Format
68437a39
DJ
39837@cindex memory map format
39838
39839To be able to write into flash memory, @value{GDBN} needs to obtain a
39840memory map from the target. This section describes the format of the
39841memory map.
39842
39843The memory map is obtained using the @samp{qXfer:memory-map:read}
39844(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
39845lists memory regions.
39846
39847@value{GDBN} must be linked with the Expat library to support XML
39848memory maps. @xref{Expat}.
39849
39850The top-level structure of the document is shown below:
68437a39
DJ
39851
39852@smallexample
39853<?xml version="1.0"?>
39854<!DOCTYPE memory-map
39855 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
39856 "http://sourceware.org/gdb/gdb-memory-map.dtd">
39857<memory-map>
39858 region...
39859</memory-map>
39860@end smallexample
39861
39862Each region can be either:
39863
39864@itemize
39865
39866@item
39867A region of RAM starting at @var{addr} and extending for @var{length}
39868bytes from there:
39869
39870@smallexample
39871<memory type="ram" start="@var{addr}" length="@var{length}"/>
39872@end smallexample
39873
39874
39875@item
39876A region of read-only memory:
39877
39878@smallexample
39879<memory type="rom" start="@var{addr}" length="@var{length}"/>
39880@end smallexample
39881
39882
39883@item
39884A region of flash memory, with erasure blocks @var{blocksize}
39885bytes in length:
39886
39887@smallexample
39888<memory type="flash" start="@var{addr}" length="@var{length}">
39889 <property name="blocksize">@var{blocksize}</property>
39890</memory>
39891@end smallexample
39892
39893@end itemize
39894
39895Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
39896by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
39897packets to write to addresses in such ranges.
39898
39899The formal DTD for memory map format is given below:
39900
39901@smallexample
39902<!-- ................................................... -->
39903<!-- Memory Map XML DTD ................................ -->
39904<!-- File: memory-map.dtd .............................. -->
39905<!-- .................................... .............. -->
39906<!-- memory-map.dtd -->
39907<!-- memory-map: Root element with versioning -->
39908<!ELEMENT memory-map (memory | property)>
39909<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
39910<!ELEMENT memory (property)>
39911<!-- memory: Specifies a memory region,
39912 and its type, or device. -->
39913<!ATTLIST memory type CDATA #REQUIRED
39914 start CDATA #REQUIRED
39915 length CDATA #REQUIRED
39916 device CDATA #IMPLIED>
39917<!-- property: Generic attribute tag -->
39918<!ELEMENT property (#PCDATA | property)*>
39919<!ATTLIST property name CDATA #REQUIRED>
39920@end smallexample
39921
dc146f7c
VP
39922@node Thread List Format
39923@section Thread List Format
39924@cindex thread list format
39925
39926To efficiently update the list of threads and their attributes,
39927@value{GDBN} issues the @samp{qXfer:threads:read} packet
39928(@pxref{qXfer threads read}) and obtains the XML document with
39929the following structure:
39930
39931@smallexample
39932<?xml version="1.0"?>
39933<threads>
79efa585 39934 <thread id="id" core="0" name="name">
dc146f7c
VP
39935 ... description ...
39936 </thread>
39937</threads>
39938@end smallexample
39939
39940Each @samp{thread} element must have the @samp{id} attribute that
39941identifies the thread (@pxref{thread-id syntax}). The
39942@samp{core} attribute, if present, specifies which processor core
79efa585
SM
39943the thread was last executing on. The @samp{name} attribute, if
39944present, specifies the human-readable name of the thread. The content
39945of the of @samp{thread} element is interpreted as human-readable
39946auxiliary information.
dc146f7c 39947
b3b9301e
PA
39948@node Traceframe Info Format
39949@section Traceframe Info Format
39950@cindex traceframe info format
39951
39952To be able to know which objects in the inferior can be examined when
39953inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
39954memory ranges, registers and trace state variables that have been
39955collected in a traceframe.
39956
39957This list is obtained using the @samp{qXfer:traceframe-info:read}
39958(@pxref{qXfer traceframe info read}) packet and is an XML document.
39959
39960@value{GDBN} must be linked with the Expat library to support XML
39961traceframe info discovery. @xref{Expat}.
39962
39963The top-level structure of the document is shown below:
39964
39965@smallexample
39966<?xml version="1.0"?>
39967<!DOCTYPE traceframe-info
39968 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
39969 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
39970<traceframe-info>
39971 block...
39972</traceframe-info>
39973@end smallexample
39974
39975Each traceframe block can be either:
39976
39977@itemize
39978
39979@item
39980A region of collected memory starting at @var{addr} and extending for
39981@var{length} bytes from there:
39982
39983@smallexample
39984<memory start="@var{addr}" length="@var{length}"/>
39985@end smallexample
39986
28a93511
YQ
39987@item
39988A block indicating trace state variable numbered @var{number} has been
39989collected:
39990
39991@smallexample
39992<tvar id="@var{number}"/>
39993@end smallexample
39994
b3b9301e
PA
39995@end itemize
39996
39997The formal DTD for the traceframe info format is given below:
39998
39999@smallexample
28a93511 40000<!ELEMENT traceframe-info (memory | tvar)* >
b3b9301e
PA
40001<!ATTLIST traceframe-info version CDATA #FIXED "1.0">
40002
40003<!ELEMENT memory EMPTY>
40004<!ATTLIST memory start CDATA #REQUIRED
40005 length CDATA #REQUIRED>
28a93511
YQ
40006<!ELEMENT tvar>
40007<!ATTLIST tvar id CDATA #REQUIRED>
b3b9301e
PA
40008@end smallexample
40009
2ae8c8e7
MM
40010@node Branch Trace Format
40011@section Branch Trace Format
40012@cindex branch trace format
40013
40014In order to display the branch trace of an inferior thread,
40015@value{GDBN} needs to obtain the list of branches. This list is
40016represented as list of sequential code blocks that are connected via
40017branches. The code in each block has been executed sequentially.
40018
40019This list is obtained using the @samp{qXfer:btrace:read}
40020(@pxref{qXfer btrace read}) packet and is an XML document.
40021
40022@value{GDBN} must be linked with the Expat library to support XML
40023traceframe info discovery. @xref{Expat}.
40024
40025The top-level structure of the document is shown below:
40026
40027@smallexample
40028<?xml version="1.0"?>
40029<!DOCTYPE btrace
40030 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
40031 "http://sourceware.org/gdb/gdb-btrace.dtd">
40032<btrace>
40033 block...
40034</btrace>
40035@end smallexample
40036
40037@itemize
40038
40039@item
40040A block of sequentially executed instructions starting at @var{begin}
40041and ending at @var{end}:
40042
40043@smallexample
40044<block begin="@var{begin}" end="@var{end}"/>
40045@end smallexample
40046
40047@end itemize
40048
40049The formal DTD for the branch trace format is given below:
40050
40051@smallexample
b20a6524 40052<!ELEMENT btrace (block* | pt) >
2ae8c8e7
MM
40053<!ATTLIST btrace version CDATA #FIXED "1.0">
40054
40055<!ELEMENT block EMPTY>
40056<!ATTLIST block begin CDATA #REQUIRED
40057 end CDATA #REQUIRED>
b20a6524
MM
40058
40059<!ELEMENT pt (pt-config?, raw?)>
40060
40061<!ELEMENT pt-config (cpu?)>
40062
40063<!ELEMENT cpu EMPTY>
40064<!ATTLIST cpu vendor CDATA #REQUIRED
40065 family CDATA #REQUIRED
40066 model CDATA #REQUIRED
40067 stepping CDATA #REQUIRED>
40068
40069<!ELEMENT raw (#PCDATA)>
2ae8c8e7
MM
40070@end smallexample
40071
f4abbc16
MM
40072@node Branch Trace Configuration Format
40073@section Branch Trace Configuration Format
40074@cindex branch trace configuration format
40075
40076For each inferior thread, @value{GDBN} can obtain the branch trace
40077configuration using the @samp{qXfer:btrace-conf:read}
40078(@pxref{qXfer btrace-conf read}) packet.
40079
40080The configuration describes the branch trace format and configuration
d33501a5
MM
40081settings for that format. The following information is described:
40082
40083@table @code
40084@item bts
40085This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
40086@table @code
40087@item size
40088The size of the @acronym{BTS} ring buffer in bytes.
40089@end table
b20a6524 40090@item pt
bc504a31 40091This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
b20a6524
MM
40092PT}) format.
40093@table @code
40094@item size
bc504a31 40095The size of the @acronym{Intel PT} ring buffer in bytes.
b20a6524 40096@end table
d33501a5 40097@end table
f4abbc16
MM
40098
40099@value{GDBN} must be linked with the Expat library to support XML
40100branch trace configuration discovery. @xref{Expat}.
40101
40102The formal DTD for the branch trace configuration format is given below:
40103
40104@smallexample
b20a6524 40105<!ELEMENT btrace-conf (bts?, pt?)>
f4abbc16
MM
40106<!ATTLIST btrace-conf version CDATA #FIXED "1.0">
40107
40108<!ELEMENT bts EMPTY>
d33501a5 40109<!ATTLIST bts size CDATA #IMPLIED>
b20a6524
MM
40110
40111<!ELEMENT pt EMPTY>
40112<!ATTLIST pt size CDATA #IMPLIED>
f4abbc16
MM
40113@end smallexample
40114
f418dd93
DJ
40115@include agentexpr.texi
40116
23181151
DJ
40117@node Target Descriptions
40118@appendix Target Descriptions
40119@cindex target descriptions
40120
23181151
DJ
40121One of the challenges of using @value{GDBN} to debug embedded systems
40122is that there are so many minor variants of each processor
40123architecture in use. It is common practice for vendors to start with
eb17f351 40124a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
23181151
DJ
40125and then make changes to adapt it to a particular market niche. Some
40126architectures have hundreds of variants, available from dozens of
40127vendors. This leads to a number of problems:
40128
40129@itemize @bullet
40130@item
40131With so many different customized processors, it is difficult for
40132the @value{GDBN} maintainers to keep up with the changes.
40133@item
40134Since individual variants may have short lifetimes or limited
40135audiences, it may not be worthwhile to carry information about every
40136variant in the @value{GDBN} source tree.
40137@item
40138When @value{GDBN} does support the architecture of the embedded system
40139at hand, the task of finding the correct architecture name to give the
40140@command{set architecture} command can be error-prone.
40141@end itemize
40142
40143To address these problems, the @value{GDBN} remote protocol allows a
40144target system to not only identify itself to @value{GDBN}, but to
40145actually describe its own features. This lets @value{GDBN} support
40146processor variants it has never seen before --- to the extent that the
40147descriptions are accurate, and that @value{GDBN} understands them.
40148
9cceb671
DJ
40149@value{GDBN} must be linked with the Expat library to support XML
40150target descriptions. @xref{Expat}.
123dc839 40151
23181151
DJ
40152@menu
40153* Retrieving Descriptions:: How descriptions are fetched from a target.
40154* Target Description Format:: The contents of a target description.
123dc839
DJ
40155* Predefined Target Types:: Standard types available for target
40156 descriptions.
40157* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
40158@end menu
40159
40160@node Retrieving Descriptions
40161@section Retrieving Descriptions
40162
40163Target descriptions can be read from the target automatically, or
40164specified by the user manually. The default behavior is to read the
40165description from the target. @value{GDBN} retrieves it via the remote
40166protocol using @samp{qXfer} requests (@pxref{General Query Packets,
40167qXfer}). The @var{annex} in the @samp{qXfer} packet will be
40168@samp{target.xml}. The contents of the @samp{target.xml} annex are an
40169XML document, of the form described in @ref{Target Description
40170Format}.
40171
40172Alternatively, you can specify a file to read for the target description.
40173If a file is set, the target will not be queried. The commands to
40174specify a file are:
40175
40176@table @code
40177@cindex set tdesc filename
40178@item set tdesc filename @var{path}
40179Read the target description from @var{path}.
40180
40181@cindex unset tdesc filename
40182@item unset tdesc filename
40183Do not read the XML target description from a file. @value{GDBN}
40184will use the description supplied by the current target.
40185
40186@cindex show tdesc filename
40187@item show tdesc filename
40188Show the filename to read for a target description, if any.
40189@end table
40190
40191
40192@node Target Description Format
40193@section Target Description Format
40194@cindex target descriptions, XML format
40195
40196A target description annex is an @uref{http://www.w3.org/XML/, XML}
40197document which complies with the Document Type Definition provided in
40198the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
40199means you can use generally available tools like @command{xmllint} to
40200check that your feature descriptions are well-formed and valid.
40201However, to help people unfamiliar with XML write descriptions for
40202their targets, we also describe the grammar here.
40203
123dc839
DJ
40204Target descriptions can identify the architecture of the remote target
40205and (for some architectures) provide information about custom register
08d16641
PA
40206sets. They can also identify the OS ABI of the remote target.
40207@value{GDBN} can use this information to autoconfigure for your
123dc839 40208target, or to warn you if you connect to an unsupported target.
23181151
DJ
40209
40210Here is a simple target description:
40211
123dc839 40212@smallexample
1780a0ed 40213<target version="1.0">
23181151
DJ
40214 <architecture>i386:x86-64</architecture>
40215</target>
123dc839 40216@end smallexample
23181151
DJ
40217
40218@noindent
40219This minimal description only says that the target uses
40220the x86-64 architecture.
40221
123dc839
DJ
40222A target description has the following overall form, with [ ] marking
40223optional elements and @dots{} marking repeatable elements. The elements
40224are explained further below.
23181151 40225
123dc839 40226@smallexample
23181151
DJ
40227<?xml version="1.0"?>
40228<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 40229<target version="1.0">
123dc839 40230 @r{[}@var{architecture}@r{]}
08d16641 40231 @r{[}@var{osabi}@r{]}
e35359c5 40232 @r{[}@var{compatible}@r{]}
123dc839 40233 @r{[}@var{feature}@dots{}@r{]}
23181151 40234</target>
123dc839 40235@end smallexample
23181151
DJ
40236
40237@noindent
40238The description is generally insensitive to whitespace and line
40239breaks, under the usual common-sense rules. The XML version
40240declaration and document type declaration can generally be omitted
40241(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
40242useful for XML validation tools. The @samp{version} attribute for
40243@samp{<target>} may also be omitted, but we recommend
40244including it; if future versions of @value{GDBN} use an incompatible
40245revision of @file{gdb-target.dtd}, they will detect and report
40246the version mismatch.
23181151 40247
108546a0
DJ
40248@subsection Inclusion
40249@cindex target descriptions, inclusion
40250@cindex XInclude
40251@ifnotinfo
40252@cindex <xi:include>
40253@end ifnotinfo
40254
40255It can sometimes be valuable to split a target description up into
40256several different annexes, either for organizational purposes, or to
40257share files between different possible target descriptions. You can
40258divide a description into multiple files by replacing any element of
40259the target description with an inclusion directive of the form:
40260
123dc839 40261@smallexample
108546a0 40262<xi:include href="@var{document}"/>
123dc839 40263@end smallexample
108546a0
DJ
40264
40265@noindent
40266When @value{GDBN} encounters an element of this form, it will retrieve
40267the named XML @var{document}, and replace the inclusion directive with
40268the contents of that document. If the current description was read
40269using @samp{qXfer}, then so will be the included document;
40270@var{document} will be interpreted as the name of an annex. If the
40271current description was read from a file, @value{GDBN} will look for
40272@var{document} as a file in the same directory where it found the
40273original description.
40274
123dc839
DJ
40275@subsection Architecture
40276@cindex <architecture>
40277
40278An @samp{<architecture>} element has this form:
40279
40280@smallexample
40281 <architecture>@var{arch}</architecture>
40282@end smallexample
40283
e35359c5
UW
40284@var{arch} is one of the architectures from the set accepted by
40285@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
123dc839 40286
08d16641
PA
40287@subsection OS ABI
40288@cindex @code{<osabi>}
40289
40290This optional field was introduced in @value{GDBN} version 7.0.
40291Previous versions of @value{GDBN} ignore it.
40292
40293An @samp{<osabi>} element has this form:
40294
40295@smallexample
40296 <osabi>@var{abi-name}</osabi>
40297@end smallexample
40298
40299@var{abi-name} is an OS ABI name from the same selection accepted by
40300@w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
40301
e35359c5
UW
40302@subsection Compatible Architecture
40303@cindex @code{<compatible>}
40304
40305This optional field was introduced in @value{GDBN} version 7.0.
40306Previous versions of @value{GDBN} ignore it.
40307
40308A @samp{<compatible>} element has this form:
40309
40310@smallexample
40311 <compatible>@var{arch}</compatible>
40312@end smallexample
40313
40314@var{arch} is one of the architectures from the set accepted by
40315@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
40316
40317A @samp{<compatible>} element is used to specify that the target
40318is able to run binaries in some other than the main target architecture
40319given by the @samp{<architecture>} element. For example, on the
40320Cell Broadband Engine, the main architecture is @code{powerpc:common}
40321or @code{powerpc:common64}, but the system is able to run binaries
40322in the @code{spu} architecture as well. The way to describe this
40323capability with @samp{<compatible>} is as follows:
40324
40325@smallexample
40326 <architecture>powerpc:common</architecture>
40327 <compatible>spu</compatible>
40328@end smallexample
40329
123dc839
DJ
40330@subsection Features
40331@cindex <feature>
40332
40333Each @samp{<feature>} describes some logical portion of the target
40334system. Features are currently used to describe available CPU
40335registers and the types of their contents. A @samp{<feature>} element
40336has this form:
40337
40338@smallexample
40339<feature name="@var{name}">
40340 @r{[}@var{type}@dots{}@r{]}
40341 @var{reg}@dots{}
40342</feature>
40343@end smallexample
40344
40345@noindent
40346Each feature's name should be unique within the description. The name
40347of a feature does not matter unless @value{GDBN} has some special
40348knowledge of the contents of that feature; if it does, the feature
40349should have its standard name. @xref{Standard Target Features}.
40350
40351@subsection Types
40352
40353Any register's value is a collection of bits which @value{GDBN} must
40354interpret. The default interpretation is a two's complement integer,
40355but other types can be requested by name in the register description.
40356Some predefined types are provided by @value{GDBN} (@pxref{Predefined
40357Target Types}), and the description can define additional composite types.
40358
40359Each type element must have an @samp{id} attribute, which gives
40360a unique (within the containing @samp{<feature>}) name to the type.
40361Types must be defined before they are used.
40362
40363@cindex <vector>
40364Some targets offer vector registers, which can be treated as arrays
40365of scalar elements. These types are written as @samp{<vector>} elements,
40366specifying the array element type, @var{type}, and the number of elements,
40367@var{count}:
40368
40369@smallexample
40370<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
40371@end smallexample
40372
40373@cindex <union>
40374If a register's value is usefully viewed in multiple ways, define it
40375with a union type containing the useful representations. The
40376@samp{<union>} element contains one or more @samp{<field>} elements,
40377each of which has a @var{name} and a @var{type}:
40378
40379@smallexample
40380<union id="@var{id}">
40381 <field name="@var{name}" type="@var{type}"/>
40382 @dots{}
40383</union>
40384@end smallexample
40385
f5dff777
DJ
40386@cindex <struct>
40387If a register's value is composed from several separate values, define
40388it with a structure type. There are two forms of the @samp{<struct>}
40389element; a @samp{<struct>} element must either contain only bitfields
40390or contain no bitfields. If the structure contains only bitfields,
40391its total size in bytes must be specified, each bitfield must have an
40392explicit start and end, and bitfields are automatically assigned an
40393integer type. The field's @var{start} should be less than or
40394equal to its @var{end}, and zero represents the least significant bit.
40395
40396@smallexample
40397<struct id="@var{id}" size="@var{size}">
40398 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
40399 @dots{}
40400</struct>
40401@end smallexample
40402
40403If the structure contains no bitfields, then each field has an
40404explicit type, and no implicit padding is added.
40405
40406@smallexample
40407<struct id="@var{id}">
40408 <field name="@var{name}" type="@var{type}"/>
40409 @dots{}
40410</struct>
40411@end smallexample
40412
40413@cindex <flags>
40414If a register's value is a series of single-bit flags, define it with
40415a flags type. The @samp{<flags>} element has an explicit @var{size}
40416and contains one or more @samp{<field>} elements. Each field has a
40417@var{name}, a @var{start}, and an @var{end}. Only single-bit flags
40418are supported.
40419
40420@smallexample
40421<flags id="@var{id}" size="@var{size}">
40422 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
40423 @dots{}
40424</flags>
40425@end smallexample
40426
123dc839
DJ
40427@subsection Registers
40428@cindex <reg>
40429
40430Each register is represented as an element with this form:
40431
40432@smallexample
40433<reg name="@var{name}"
40434 bitsize="@var{size}"
40435 @r{[}regnum="@var{num}"@r{]}
40436 @r{[}save-restore="@var{save-restore}"@r{]}
40437 @r{[}type="@var{type}"@r{]}
40438 @r{[}group="@var{group}"@r{]}/>
40439@end smallexample
40440
40441@noindent
40442The components are as follows:
40443
40444@table @var
40445
40446@item name
40447The register's name; it must be unique within the target description.
40448
40449@item bitsize
40450The register's size, in bits.
40451
40452@item regnum
40453The register's number. If omitted, a register's number is one greater
40454than that of the previous register (either in the current feature or in
177b42fe 40455a preceding feature); the first register in the target description
123dc839
DJ
40456defaults to zero. This register number is used to read or write
40457the register; e.g.@: it is used in the remote @code{p} and @code{P}
40458packets, and registers appear in the @code{g} and @code{G} packets
40459in order of increasing register number.
40460
40461@item save-restore
40462Whether the register should be preserved across inferior function
40463calls; this must be either @code{yes} or @code{no}. The default is
40464@code{yes}, which is appropriate for most registers except for
40465some system control registers; this is not related to the target's
40466ABI.
40467
40468@item type
697aa1b7 40469The type of the register. It may be a predefined type, a type
123dc839
DJ
40470defined in the current feature, or one of the special types @code{int}
40471and @code{float}. @code{int} is an integer type of the correct size
40472for @var{bitsize}, and @code{float} is a floating point type (in the
40473architecture's normal floating point format) of the correct size for
40474@var{bitsize}. The default is @code{int}.
40475
40476@item group
697aa1b7 40477The register group to which this register belongs. It must
123dc839
DJ
40478be either @code{general}, @code{float}, or @code{vector}. If no
40479@var{group} is specified, @value{GDBN} will not display the register
40480in @code{info registers}.
40481
40482@end table
40483
40484@node Predefined Target Types
40485@section Predefined Target Types
40486@cindex target descriptions, predefined types
40487
40488Type definitions in the self-description can build up composite types
40489from basic building blocks, but can not define fundamental types. Instead,
40490standard identifiers are provided by @value{GDBN} for the fundamental
40491types. The currently supported types are:
40492
40493@table @code
40494
40495@item int8
40496@itemx int16
40497@itemx int32
40498@itemx int64
7cc46491 40499@itemx int128
123dc839
DJ
40500Signed integer types holding the specified number of bits.
40501
40502@item uint8
40503@itemx uint16
40504@itemx uint32
40505@itemx uint64
7cc46491 40506@itemx uint128
123dc839
DJ
40507Unsigned integer types holding the specified number of bits.
40508
40509@item code_ptr
40510@itemx data_ptr
40511Pointers to unspecified code and data. The program counter and
40512any dedicated return address register may be marked as code
40513pointers; printing a code pointer converts it into a symbolic
40514address. The stack pointer and any dedicated address registers
40515may be marked as data pointers.
40516
6e3bbd1a
PB
40517@item ieee_single
40518Single precision IEEE floating point.
40519
40520@item ieee_double
40521Double precision IEEE floating point.
40522
123dc839
DJ
40523@item arm_fpa_ext
40524The 12-byte extended precision format used by ARM FPA registers.
40525
075b51b7
L
40526@item i387_ext
40527The 10-byte extended precision format used by x87 registers.
40528
40529@item i386_eflags
4053032bit @sc{eflags} register used by x86.
40531
40532@item i386_mxcsr
4053332bit @sc{mxcsr} register used by x86.
40534
123dc839
DJ
40535@end table
40536
40537@node Standard Target Features
40538@section Standard Target Features
40539@cindex target descriptions, standard features
40540
40541A target description must contain either no registers or all the
40542target's registers. If the description contains no registers, then
40543@value{GDBN} will assume a default register layout, selected based on
40544the architecture. If the description contains any registers, the
40545default layout will not be used; the standard registers must be
40546described in the target description, in such a way that @value{GDBN}
40547can recognize them.
40548
40549This is accomplished by giving specific names to feature elements
40550which contain standard registers. @value{GDBN} will look for features
40551with those names and verify that they contain the expected registers;
40552if any known feature is missing required registers, or if any required
40553feature is missing, @value{GDBN} will reject the target
40554description. You can add additional registers to any of the
40555standard features --- @value{GDBN} will display them just as if
40556they were added to an unrecognized feature.
40557
40558This section lists the known features and their expected contents.
40559Sample XML documents for these features are included in the
40560@value{GDBN} source tree, in the directory @file{gdb/features}.
40561
40562Names recognized by @value{GDBN} should include the name of the
40563company or organization which selected the name, and the overall
40564architecture to which the feature applies; so e.g.@: the feature
40565containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
40566
ff6f572f
DJ
40567The names of registers are not case sensitive for the purpose
40568of recognizing standard features, but @value{GDBN} will only display
40569registers using the capitalization used in the description.
40570
e9c17194 40571@menu
430ed3f0 40572* AArch64 Features::
e9c17194 40573* ARM Features::
3bb8d5c3 40574* i386 Features::
164224e9 40575* MicroBlaze Features::
1e26b4f8 40576* MIPS Features::
e9c17194 40577* M68K Features::
a1217d97 40578* Nios II Features::
1e26b4f8 40579* PowerPC Features::
4ac33720 40580* S/390 and System z Features::
224bbe49 40581* TIC6x Features::
e9c17194
VP
40582@end menu
40583
40584
430ed3f0
MS
40585@node AArch64 Features
40586@subsection AArch64 Features
40587@cindex target descriptions, AArch64 features
40588
40589The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
40590targets. It should contain registers @samp{x0} through @samp{x30},
40591@samp{sp}, @samp{pc}, and @samp{cpsr}.
40592
40593The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
40594it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
40595and @samp{fpcr}.
40596
e9c17194 40597@node ARM Features
123dc839
DJ
40598@subsection ARM Features
40599@cindex target descriptions, ARM features
40600
9779414d
DJ
40601The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
40602ARM targets.
123dc839
DJ
40603It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
40604@samp{lr}, @samp{pc}, and @samp{cpsr}.
40605
9779414d
DJ
40606For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
40607feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
40608registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
40609and @samp{xpsr}.
40610
123dc839
DJ
40611The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
40612should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
40613
ff6f572f
DJ
40614The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
40615it should contain at least registers @samp{wR0} through @samp{wR15} and
40616@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
40617@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 40618
58d6951d
DJ
40619The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
40620should contain at least registers @samp{d0} through @samp{d15}. If
40621they are present, @samp{d16} through @samp{d31} should also be included.
40622@value{GDBN} will synthesize the single-precision registers from
40623halves of the double-precision registers.
40624
40625The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
40626need to contain registers; it instructs @value{GDBN} to display the
40627VFP double-precision registers as vectors and to synthesize the
40628quad-precision registers from pairs of double-precision registers.
40629If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
40630be present and include 32 double-precision registers.
40631
3bb8d5c3
L
40632@node i386 Features
40633@subsection i386 Features
40634@cindex target descriptions, i386 features
40635
40636The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
40637targets. It should describe the following registers:
40638
40639@itemize @minus
40640@item
40641@samp{eax} through @samp{edi} plus @samp{eip} for i386
40642@item
40643@samp{rax} through @samp{r15} plus @samp{rip} for amd64
40644@item
40645@samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
40646@samp{fs}, @samp{gs}
40647@item
40648@samp{st0} through @samp{st7}
40649@item
40650@samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
40651@samp{foseg}, @samp{fooff} and @samp{fop}
40652@end itemize
40653
40654The register sets may be different, depending on the target.
40655
3a13a53b 40656The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
3bb8d5c3
L
40657describe registers:
40658
40659@itemize @minus
40660@item
40661@samp{xmm0} through @samp{xmm7} for i386
40662@item
40663@samp{xmm0} through @samp{xmm15} for amd64
40664@item
40665@samp{mxcsr}
40666@end itemize
40667
3a13a53b
L
40668The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
40669@samp{org.gnu.gdb.i386.sse} feature. It should
f68eb612
L
40670describe the upper 128 bits of @sc{ymm} registers:
40671
40672@itemize @minus
40673@item
40674@samp{ymm0h} through @samp{ymm7h} for i386
40675@item
40676@samp{ymm0h} through @samp{ymm15h} for amd64
f68eb612
L
40677@end itemize
40678
bc504a31 40679The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
ca8941bb
WT
40680Memory Protection Extension (MPX). It should describe the following registers:
40681
40682@itemize @minus
40683@item
40684@samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
40685@item
40686@samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
40687@end itemize
40688
3bb8d5c3
L
40689The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
40690describe a single register, @samp{orig_eax}.
40691
01f9f808
MS
40692The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
40693@samp{org.gnu.gdb.i386.avx} feature. It should
40694describe additional @sc{xmm} registers:
40695
40696@itemize @minus
40697@item
40698@samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
40699@end itemize
40700
40701It should describe the upper 128 bits of additional @sc{ymm} registers:
40702
40703@itemize @minus
40704@item
40705@samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
40706@end itemize
40707
40708It should
40709describe the upper 256 bits of @sc{zmm} registers:
40710
40711@itemize @minus
40712@item
40713@samp{zmm0h} through @samp{zmm7h} for i386.
40714@item
40715@samp{zmm0h} through @samp{zmm15h} for amd64.
40716@end itemize
40717
40718It should
40719describe the additional @sc{zmm} registers:
40720
40721@itemize @minus
40722@item
40723@samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
40724@end itemize
40725
164224e9
ME
40726@node MicroBlaze Features
40727@subsection MicroBlaze Features
40728@cindex target descriptions, MicroBlaze features
40729
40730The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
40731targets. It should contain registers @samp{r0} through @samp{r31},
40732@samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
40733@samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
40734@samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
40735
40736The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
40737If present, it should contain registers @samp{rshr} and @samp{rslr}
40738
1e26b4f8 40739@node MIPS Features
eb17f351
EZ
40740@subsection @acronym{MIPS} Features
40741@cindex target descriptions, @acronym{MIPS} features
f8b73d13 40742
eb17f351 40743The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
f8b73d13
DJ
40744It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
40745@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
40746on the target.
40747
40748The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
40749contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
40750registers. They may be 32-bit or 64-bit depending on the target.
40751
40752The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
40753it may be optional in a future version of @value{GDBN}. It should
40754contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
40755@samp{fir}. They may be 32-bit or 64-bit depending on the target.
40756
1faeff08
MR
40757The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
40758contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
40759@samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
40760be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
40761
822b6570
DJ
40762The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
40763contain a single register, @samp{restart}, which is used by the
40764Linux kernel to control restartable syscalls.
40765
e9c17194
VP
40766@node M68K Features
40767@subsection M68K Features
40768@cindex target descriptions, M68K features
40769
40770@table @code
40771@item @samp{org.gnu.gdb.m68k.core}
40772@itemx @samp{org.gnu.gdb.coldfire.core}
40773@itemx @samp{org.gnu.gdb.fido.core}
40774One of those features must be always present.
249e1128 40775The feature that is present determines which flavor of m68k is
e9c17194
VP
40776used. The feature that is present should contain registers
40777@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
40778@samp{sp}, @samp{ps} and @samp{pc}.
40779
40780@item @samp{org.gnu.gdb.coldfire.fp}
40781This feature is optional. If present, it should contain registers
40782@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
40783@samp{fpiaddr}.
40784@end table
40785
a1217d97
SL
40786@node Nios II Features
40787@subsection Nios II Features
40788@cindex target descriptions, Nios II features
40789
40790The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
40791targets. It should contain the 32 core registers (@samp{zero},
40792@samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
40793@samp{pc}, and the 16 control registers (@samp{status} through
40794@samp{mpuacc}).
40795
1e26b4f8 40796@node PowerPC Features
7cc46491
DJ
40797@subsection PowerPC Features
40798@cindex target descriptions, PowerPC features
40799
40800The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
40801targets. It should contain registers @samp{r0} through @samp{r31},
40802@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
40803@samp{xer}. They may be 32-bit or 64-bit depending on the target.
40804
40805The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
40806contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
40807
40808The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
40809contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
40810and @samp{vrsave}.
40811
677c5bb1
LM
40812The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
40813contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN}
40814will combine these registers with the floating point registers
40815(@samp{f0} through @samp{f31}) and the altivec registers (@samp{vr0}
aeac0ff9 40816through @samp{vr31}) to present the 128-bit wide registers @samp{vs0}
677c5bb1
LM
40817through @samp{vs63}, the set of vector registers for POWER7.
40818
7cc46491
DJ
40819The @samp{org.gnu.gdb.power.spe} feature is optional. It should
40820contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
40821@samp{spefscr}. SPE targets should provide 32-bit registers in
40822@samp{org.gnu.gdb.power.core} and provide the upper halves in
40823@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
40824these to present registers @samp{ev0} through @samp{ev31} to the
40825user.
40826
4ac33720
UW
40827@node S/390 and System z Features
40828@subsection S/390 and System z Features
40829@cindex target descriptions, S/390 features
40830@cindex target descriptions, System z features
40831
40832The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
40833System z targets. It should contain the PSW and the 16 general
40834registers. In particular, System z targets should provide the 64-bit
40835registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
40836S/390 targets should provide the 32-bit versions of these registers.
40837A System z target that runs in 31-bit addressing mode should provide
4083832-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
40839register's upper halves @samp{r0h} through @samp{r15h}, and their
40840lower halves @samp{r0l} through @samp{r15l}.
40841
40842The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
40843contain the 64-bit registers @samp{f0} through @samp{f15}, and
40844@samp{fpc}.
40845
40846The @samp{org.gnu.gdb.s390.acr} feature is required. It should
40847contain the 32-bit registers @samp{acr0} through @samp{acr15}.
40848
40849The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
40850contain the register @samp{orig_r2}, which is 64-bit wide on System z
40851targets and 32-bit otherwise. In addition, the feature may contain
40852the @samp{last_break} register, whose width depends on the addressing
40853mode, as well as the @samp{system_call} register, which is always
4085432-bit wide.
40855
40856The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
40857contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
40858@samp{atia}, and @samp{tr0} through @samp{tr15}.
40859
446899e4
AA
40860The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
4086164-bit wide registers @samp{v0l} through @samp{v15l}, which will be
40862combined by @value{GDBN} with the floating point registers @samp{f0}
40863through @samp{f15} to present the 128-bit wide vector registers
40864@samp{v0} through @samp{v15}. In addition, this feature should
40865contain the 128-bit wide vector registers @samp{v16} through
40866@samp{v31}.
40867
224bbe49
YQ
40868@node TIC6x Features
40869@subsection TMS320C6x Features
40870@cindex target descriptions, TIC6x features
40871@cindex target descriptions, TMS320C6x features
40872The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
40873targets. It should contain registers @samp{A0} through @samp{A15},
40874registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
40875
40876The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
40877contain registers @samp{A16} through @samp{A31} and @samp{B16}
40878through @samp{B31}.
40879
40880The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
40881contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
40882
07e059b5
VP
40883@node Operating System Information
40884@appendix Operating System Information
40885@cindex operating system information
40886
40887@menu
40888* Process list::
40889@end menu
40890
40891Users of @value{GDBN} often wish to obtain information about the state of
40892the operating system running on the target---for example the list of
40893processes, or the list of open files. This section describes the
40894mechanism that makes it possible. This mechanism is similar to the
40895target features mechanism (@pxref{Target Descriptions}), but focuses
40896on a different aspect of target.
40897
40898Operating system information is retrived from the target via the
40899remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
40900read}). The object name in the request should be @samp{osdata}, and
40901the @var{annex} identifies the data to be fetched.
40902
40903@node Process list
40904@appendixsection Process list
40905@cindex operating system information, process list
40906
40907When requesting the process list, the @var{annex} field in the
40908@samp{qXfer} request should be @samp{processes}. The returned data is
40909an XML document. The formal syntax of this document is defined in
40910@file{gdb/features/osdata.dtd}.
40911
40912An example document is:
40913
40914@smallexample
40915<?xml version="1.0"?>
40916<!DOCTYPE target SYSTEM "osdata.dtd">
40917<osdata type="processes">
40918 <item>
40919 <column name="pid">1</column>
40920 <column name="user">root</column>
40921 <column name="command">/sbin/init</column>
dc146f7c 40922 <column name="cores">1,2,3</column>
07e059b5
VP
40923 </item>
40924</osdata>
40925@end smallexample
40926
40927Each item should include a column whose name is @samp{pid}. The value
40928of that column should identify the process on the target. The
40929@samp{user} and @samp{command} columns are optional, and will be
dc146f7c
VP
40930displayed by @value{GDBN}. The @samp{cores} column, if present,
40931should contain a comma-separated list of cores that this process
40932is running on. Target may provide additional columns,
07e059b5
VP
40933which @value{GDBN} currently ignores.
40934
05c8c3f5
TT
40935@node Trace File Format
40936@appendix Trace File Format
40937@cindex trace file format
40938
40939The trace file comes in three parts: a header, a textual description
40940section, and a trace frame section with binary data.
40941
40942The header has the form @code{\x7fTRACE0\n}. The first byte is
40943@code{0x7f} so as to indicate that the file contains binary data,
40944while the @code{0} is a version number that may have different values
40945in the future.
40946
40947The description section consists of multiple lines of @sc{ascii} text
40948separated by newline characters (@code{0xa}). The lines may include a
40949variety of optional descriptive or context-setting information, such
40950as tracepoint definitions or register set size. @value{GDBN} will
40951ignore any line that it does not recognize. An empty line marks the end
40952of this section.
40953
40954@c FIXME add some specific types of data
40955
40956The trace frame section consists of a number of consecutive frames.
40957Each frame begins with a two-byte tracepoint number, followed by a
40958four-byte size giving the amount of data in the frame. The data in
40959the frame consists of a number of blocks, each introduced by a
40960character indicating its type (at least register, memory, and trace
40961state variable). The data in this section is raw binary, not a
40962hexadecimal or other encoding; its endianness matches the target's
40963endianness.
40964
40965@c FIXME bi-arch may require endianness/arch info in description section
40966
40967@table @code
40968@item R @var{bytes}
40969Register block. The number and ordering of bytes matches that of a
40970@code{g} packet in the remote protocol. Note that these are the
40971actual bytes, in target order and @value{GDBN} register order, not a
40972hexadecimal encoding.
40973
40974@item M @var{address} @var{length} @var{bytes}...
40975Memory block. This is a contiguous block of memory, at the 8-byte
40976address @var{address}, with a 2-byte length @var{length}, followed by
40977@var{length} bytes.
40978
40979@item V @var{number} @var{value}
40980Trace state variable block. This records the 8-byte signed value
40981@var{value} of trace state variable numbered @var{number}.
40982
40983@end table
40984
40985Future enhancements of the trace file format may include additional types
40986of blocks.
40987
90476074
TT
40988@node Index Section Format
40989@appendix @code{.gdb_index} section format
40990@cindex .gdb_index section format
40991@cindex index section format
40992
40993This section documents the index section that is created by @code{save
40994gdb-index} (@pxref{Index Files}). The index section is
40995DWARF-specific; some knowledge of DWARF is assumed in this
40996description.
40997
40998The mapped index file format is designed to be directly
40999@code{mmap}able on any architecture. In most cases, a datum is
41000represented using a little-endian 32-bit integer value, called an
41001@code{offset_type}. Big endian machines must byte-swap the values
41002before using them. Exceptions to this rule are noted. The data is
41003laid out such that alignment is always respected.
41004
41005A mapped index consists of several areas, laid out in order.
41006
41007@enumerate
41008@item
41009The file header. This is a sequence of values, of @code{offset_type}
41010unless otherwise noted:
41011
41012@enumerate
41013@item
796a7ff8 41014The version number, currently 8. Versions 1, 2 and 3 are obsolete.
481860b3 41015Version 4 uses a different hashing function from versions 5 and 6.
b6ba681c
TT
41016Version 6 includes symbols for inlined functions, whereas versions 4
41017and 5 do not. Version 7 adds attributes to the CU indices in the
796a7ff8
DE
41018symbol table. Version 8 specifies that symbols from DWARF type units
41019(@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
41020compilation unit (@samp{DW_TAG_comp_unit}) using the type.
41021
41022@value{GDBN} will only read version 4, 5, or 6 indices
e615022a 41023by specifying @code{set use-deprecated-index-sections on}.
796a7ff8
DE
41024GDB has a workaround for potentially broken version 7 indices so it is
41025currently not flagged as deprecated.
90476074
TT
41026
41027@item
41028The offset, from the start of the file, of the CU list.
41029
41030@item
41031The offset, from the start of the file, of the types CU list. Note
41032that this area can be empty, in which case this offset will be equal
41033to the next offset.
41034
41035@item
41036The offset, from the start of the file, of the address area.
41037
41038@item
41039The offset, from the start of the file, of the symbol table.
41040
41041@item
41042The offset, from the start of the file, of the constant pool.
41043@end enumerate
41044
41045@item
41046The CU list. This is a sequence of pairs of 64-bit little-endian
41047values, sorted by the CU offset. The first element in each pair is
41048the offset of a CU in the @code{.debug_info} section. The second
41049element in each pair is the length of that CU. References to a CU
41050elsewhere in the map are done using a CU index, which is just the
410510-based index into this table. Note that if there are type CUs, then
41052conceptually CUs and type CUs form a single list for the purposes of
41053CU indices.
41054
41055@item
41056The types CU list. This is a sequence of triplets of 64-bit
41057little-endian values. In a triplet, the first value is the CU offset,
41058the second value is the type offset in the CU, and the third value is
41059the type signature. The types CU list is not sorted.
41060
41061@item
41062The address area. The address area consists of a sequence of address
41063entries. Each address entry has three elements:
41064
41065@enumerate
41066@item
41067The low address. This is a 64-bit little-endian value.
41068
41069@item
41070The high address. This is a 64-bit little-endian value. Like
41071@code{DW_AT_high_pc}, the value is one byte beyond the end.
41072
41073@item
41074The CU index. This is an @code{offset_type} value.
41075@end enumerate
41076
41077@item
41078The symbol table. This is an open-addressed hash table. The size of
41079the hash table is always a power of 2.
41080
41081Each slot in the hash table consists of a pair of @code{offset_type}
41082values. The first value is the offset of the symbol's name in the
41083constant pool. The second value is the offset of the CU vector in the
41084constant pool.
41085
41086If both values are 0, then this slot in the hash table is empty. This
41087is ok because while 0 is a valid constant pool index, it cannot be a
41088valid index for both a string and a CU vector.
41089
41090The hash value for a table entry is computed by applying an
41091iterative hash function to the symbol's name. Starting with an
41092initial value of @code{r = 0}, each (unsigned) character @samp{c} in
559a7a62
JK
41093the string is incorporated into the hash using the formula depending on the
41094index version:
41095
41096@table @asis
41097@item Version 4
41098The formula is @code{r = r * 67 + c - 113}.
41099
156942c7 41100@item Versions 5 to 7
559a7a62
JK
41101The formula is @code{r = r * 67 + tolower (c) - 113}.
41102@end table
41103
41104The terminating @samp{\0} is not incorporated into the hash.
90476074
TT
41105
41106The step size used in the hash table is computed via
41107@code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
41108value, and @samp{size} is the size of the hash table. The step size
41109is used to find the next candidate slot when handling a hash
41110collision.
41111
41112The names of C@t{++} symbols in the hash table are canonicalized. We
41113don't currently have a simple description of the canonicalization
41114algorithm; if you intend to create new index sections, you must read
41115the code.
41116
41117@item
41118The constant pool. This is simply a bunch of bytes. It is organized
41119so that alignment is correct: CU vectors are stored first, followed by
41120strings.
41121
41122A CU vector in the constant pool is a sequence of @code{offset_type}
41123values. The first value is the number of CU indices in the vector.
156942c7
DE
41124Each subsequent value is the index and symbol attributes of a CU in
41125the CU list. This element in the hash table is used to indicate which
41126CUs define the symbol and how the symbol is used.
41127See below for the format of each CU index+attributes entry.
90476074
TT
41128
41129A string in the constant pool is zero-terminated.
41130@end enumerate
41131
156942c7
DE
41132Attributes were added to CU index values in @code{.gdb_index} version 7.
41133If a symbol has multiple uses within a CU then there is one
41134CU index+attributes value for each use.
41135
41136The format of each CU index+attributes entry is as follows
41137(bit 0 = LSB):
41138
41139@table @asis
41140
41141@item Bits 0-23
41142This is the index of the CU in the CU list.
41143@item Bits 24-27
41144These bits are reserved for future purposes and must be zero.
41145@item Bits 28-30
41146The kind of the symbol in the CU.
41147
41148@table @asis
41149@item 0
41150This value is reserved and should not be used.
41151By reserving zero the full @code{offset_type} value is backwards compatible
41152with previous versions of the index.
41153@item 1
41154The symbol is a type.
41155@item 2
41156The symbol is a variable or an enum value.
41157@item 3
41158The symbol is a function.
41159@item 4
41160Any other kind of symbol.
41161@item 5,6,7
41162These values are reserved.
41163@end table
41164
41165@item Bit 31
41166This bit is zero if the value is global and one if it is static.
41167
41168The determination of whether a symbol is global or static is complicated.
41169The authorative reference is the file @file{dwarf2read.c} in
41170@value{GDBN} sources.
41171
41172@end table
41173
41174This pseudo-code describes the computation of a symbol's kind and
41175global/static attributes in the index.
41176
41177@smallexample
41178is_external = get_attribute (die, DW_AT_external);
41179language = get_attribute (cu_die, DW_AT_language);
41180switch (die->tag)
41181 @{
41182 case DW_TAG_typedef:
41183 case DW_TAG_base_type:
41184 case DW_TAG_subrange_type:
41185 kind = TYPE;
41186 is_static = 1;
41187 break;
41188 case DW_TAG_enumerator:
41189 kind = VARIABLE;
41190 is_static = (language != CPLUS && language != JAVA);
41191 break;
41192 case DW_TAG_subprogram:
41193 kind = FUNCTION;
41194 is_static = ! (is_external || language == ADA);
41195 break;
41196 case DW_TAG_constant:
41197 kind = VARIABLE;
41198 is_static = ! is_external;
41199 break;
41200 case DW_TAG_variable:
41201 kind = VARIABLE;
41202 is_static = ! is_external;
41203 break;
41204 case DW_TAG_namespace:
41205 kind = TYPE;
41206 is_static = 0;
41207 break;
41208 case DW_TAG_class_type:
41209 case DW_TAG_interface_type:
41210 case DW_TAG_structure_type:
41211 case DW_TAG_union_type:
41212 case DW_TAG_enumeration_type:
41213 kind = TYPE;
41214 is_static = (language != CPLUS && language != JAVA);
41215 break;
41216 default:
41217 assert (0);
41218 @}
41219@end smallexample
41220
43662968
JK
41221@node Man Pages
41222@appendix Manual pages
41223@cindex Man pages
41224
41225@menu
41226* gdb man:: The GNU Debugger man page
41227* gdbserver man:: Remote Server for the GNU Debugger man page
b292c783 41228* gcore man:: Generate a core file of a running program
43662968
JK
41229* gdbinit man:: gdbinit scripts
41230@end menu
41231
41232@node gdb man
41233@heading gdb man
41234
41235@c man title gdb The GNU Debugger
41236
41237@c man begin SYNOPSIS gdb
41238gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
41239[@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
41240[@option{-b}@w{ }@var{bps}]
41241 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
41242[@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
906ccdf0
JK
41243[@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
41244 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
41245[@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
43662968
JK
41246@c man end
41247
41248@c man begin DESCRIPTION gdb
41249The purpose of a debugger such as @value{GDBN} is to allow you to see what is
41250going on ``inside'' another program while it executes -- or what another
41251program was doing at the moment it crashed.
41252
41253@value{GDBN} can do four main kinds of things (plus other things in support of
41254these) to help you catch bugs in the act:
41255
41256@itemize @bullet
41257@item
41258Start your program, specifying anything that might affect its behavior.
41259
41260@item
41261Make your program stop on specified conditions.
41262
41263@item
41264Examine what has happened, when your program has stopped.
41265
41266@item
41267Change things in your program, so you can experiment with correcting the
41268effects of one bug and go on to learn about another.
41269@end itemize
41270
906ccdf0
JK
41271You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
41272Modula-2.
43662968
JK
41273
41274@value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
41275commands from the terminal until you tell it to exit with the @value{GDBN}
41276command @code{quit}. You can get online help from @value{GDBN} itself
41277by using the command @code{help}.
41278
41279You can run @code{gdb} with no arguments or options; but the most
41280usual way to start @value{GDBN} is with one argument or two, specifying an
41281executable program as the argument:
41282
41283@smallexample
41284gdb program
41285@end smallexample
41286
41287You can also start with both an executable program and a core file specified:
41288
41289@smallexample
41290gdb program core
41291@end smallexample
41292
41293You can, instead, specify a process ID as a second argument, if you want
41294to debug a running process:
41295
41296@smallexample
41297gdb program 1234
906ccdf0 41298gdb -p 1234
43662968
JK
41299@end smallexample
41300
41301@noindent
41302would attach @value{GDBN} to process @code{1234} (unless you also have a file
41303named @file{1234}; @value{GDBN} does check for a core file first).
906ccdf0 41304With option @option{-p} you can omit the @var{program} filename.
43662968
JK
41305
41306Here are some of the most frequently needed @value{GDBN} commands:
41307
41308@c pod2man highlights the right hand side of the @item lines.
41309@table @env
41310@item break [@var{file}:]@var{functiop}
41311Set a breakpoint at @var{function} (in @var{file}).
41312
41313@item run [@var{arglist}]
41314Start your program (with @var{arglist}, if specified).
41315
41316@item bt
41317Backtrace: display the program stack.
41318
41319@item print @var{expr}
41320Display the value of an expression.
41321
41322@item c
41323Continue running your program (after stopping, e.g. at a breakpoint).
41324
41325@item next
41326Execute next program line (after stopping); step @emph{over} any
41327function calls in the line.
41328
41329@item edit [@var{file}:]@var{function}
41330look at the program line where it is presently stopped.
41331
41332@item list [@var{file}:]@var{function}
41333type the text of the program in the vicinity of where it is presently stopped.
41334
41335@item step
41336Execute next program line (after stopping); step @emph{into} any
41337function calls in the line.
41338
41339@item help [@var{name}]
41340Show information about @value{GDBN} command @var{name}, or general information
41341about using @value{GDBN}.
41342
41343@item quit
41344Exit from @value{GDBN}.
41345@end table
41346
41347@ifset man
41348For full details on @value{GDBN},
41349see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
41350by Richard M. Stallman and Roland H. Pesch. The same text is available online
41351as the @code{gdb} entry in the @code{info} program.
41352@end ifset
41353@c man end
41354
41355@c man begin OPTIONS gdb
41356Any arguments other than options specify an executable
41357file and core file (or process ID); that is, the first argument
41358encountered with no
41359associated option flag is equivalent to a @option{-se} option, and the second,
41360if any, is equivalent to a @option{-c} option if it's the name of a file.
41361Many options have
41362both long and short forms; both are shown here. The long forms are also
41363recognized if you truncate them, so long as enough of the option is
41364present to be unambiguous. (If you prefer, you can flag option
41365arguments with @option{+} rather than @option{-}, though we illustrate the
41366more usual convention.)
41367
41368All the options and command line arguments you give are processed
41369in sequential order. The order makes a difference when the @option{-x}
41370option is used.
41371
41372@table @env
41373@item -help
41374@itemx -h
41375List all options, with brief explanations.
41376
41377@item -symbols=@var{file}
41378@itemx -s @var{file}
41379Read symbol table from file @var{file}.
41380
41381@item -write
41382Enable writing into executable and core files.
41383
41384@item -exec=@var{file}
41385@itemx -e @var{file}
41386Use file @var{file} as the executable file to execute when
41387appropriate, and for examining pure data in conjunction with a core
41388dump.
41389
41390@item -se=@var{file}
41391Read symbol table from file @var{file} and use it as the executable
41392file.
41393
41394@item -core=@var{file}
41395@itemx -c @var{file}
41396Use file @var{file} as a core dump to examine.
41397
41398@item -command=@var{file}
41399@itemx -x @var{file}
41400Execute @value{GDBN} commands from file @var{file}.
41401
41402@item -ex @var{command}
41403Execute given @value{GDBN} @var{command}.
41404
41405@item -directory=@var{directory}
41406@itemx -d @var{directory}
41407Add @var{directory} to the path to search for source files.
41408
41409@item -nh
41410Do not execute commands from @file{~/.gdbinit}.
41411
41412@item -nx
41413@itemx -n
41414Do not execute commands from any @file{.gdbinit} initialization files.
41415
41416@item -quiet
41417@itemx -q
41418``Quiet''. Do not print the introductory and copyright messages. These
41419messages are also suppressed in batch mode.
41420
41421@item -batch
41422Run in batch mode. Exit with status @code{0} after processing all the command
41423files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
41424Exit with nonzero status if an error occurs in executing the @value{GDBN}
41425commands in the command files.
41426
41427Batch mode may be useful for running @value{GDBN} as a filter, for example to
41428download and run a program on another computer; in order to make this
41429more useful, the message
41430
41431@smallexample
41432Program exited normally.
41433@end smallexample
41434
41435@noindent
41436(which is ordinarily issued whenever a program running under @value{GDBN} control
41437terminates) is not issued when running in batch mode.
41438
41439@item -cd=@var{directory}
41440Run @value{GDBN} using @var{directory} as its working directory,
41441instead of the current directory.
41442
41443@item -fullname
41444@itemx -f
41445Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
41446@value{GDBN} to output the full file name and line number in a standard,
41447recognizable fashion each time a stack frame is displayed (which
41448includes each time the program stops). This recognizable format looks
41449like two @samp{\032} characters, followed by the file name, line number
41450and character position separated by colons, and a newline. The
41451Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
41452characters as a signal to display the source code for the frame.
41453
41454@item -b @var{bps}
41455Set the line speed (baud rate or bits per second) of any serial
41456interface used by @value{GDBN} for remote debugging.
41457
41458@item -tty=@var{device}
41459Run using @var{device} for your program's standard input and output.
41460@end table
41461@c man end
41462
41463@c man begin SEEALSO gdb
41464@ifset man
41465The full documentation for @value{GDBN} is maintained as a Texinfo manual.
41466If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
41467documentation are properly installed at your site, the command
41468
41469@smallexample
41470info gdb
41471@end smallexample
41472
41473@noindent
41474should give you access to the complete manual.
41475
41476@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
41477Richard M. Stallman and Roland H. Pesch, July 1991.
41478@end ifset
41479@c man end
41480
41481@node gdbserver man
41482@heading gdbserver man
41483
41484@c man title gdbserver Remote Server for the GNU Debugger
41485@format
41486@c man begin SYNOPSIS gdbserver
5b8b6385 41487gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
43662968 41488
5b8b6385
JK
41489gdbserver --attach @var{comm} @var{pid}
41490
41491gdbserver --multi @var{comm}
43662968
JK
41492@c man end
41493@end format
41494
41495@c man begin DESCRIPTION gdbserver
41496@command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
41497than the one which is running the program being debugged.
41498
41499@ifclear man
41500@subheading Usage (server (target) side)
41501@end ifclear
41502@ifset man
41503Usage (server (target) side):
41504@end ifset
41505
41506First, you need to have a copy of the program you want to debug put onto
41507the target system. The program can be stripped to save space if needed, as
41508@command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
41509the @value{GDBN} running on the host system.
41510
41511To use the server, you log on to the target system, and run the @command{gdbserver}
41512program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
41513your program, and (c) its arguments. The general syntax is:
41514
41515@smallexample
41516target> gdbserver @var{comm} @var{program} [@var{args} ...]
41517@end smallexample
41518
41519For example, using a serial port, you might say:
41520
41521@smallexample
41522@ifset man
41523@c @file would wrap it as F</dev/com1>.
41524target> gdbserver /dev/com1 emacs foo.txt
41525@end ifset
41526@ifclear man
41527target> gdbserver @file{/dev/com1} emacs foo.txt
41528@end ifclear
41529@end smallexample
41530
41531This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
41532to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
41533waits patiently for the host @value{GDBN} to communicate with it.
41534
41535To use a TCP connection, you could say:
41536
41537@smallexample
41538target> gdbserver host:2345 emacs foo.txt
41539@end smallexample
41540
41541This says pretty much the same thing as the last example, except that we are
41542going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
41543that we are expecting to see a TCP connection from @code{host} to local TCP port
415442345. (Currently, the @code{host} part is ignored.) You can choose any number you
41545want for the port number as long as it does not conflict with any existing TCP
41546ports on the target system. This same port number must be used in the host
41547@value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
41548you chose a port number that conflicts with another service, @command{gdbserver} will
41549print an error message and exit.
41550
5b8b6385 41551@command{gdbserver} can also attach to running programs.
43662968
JK
41552This is accomplished via the @option{--attach} argument. The syntax is:
41553
41554@smallexample
5b8b6385 41555target> gdbserver --attach @var{comm} @var{pid}
43662968
JK
41556@end smallexample
41557
41558@var{pid} is the process ID of a currently running process. It isn't
41559necessary to point @command{gdbserver} at a binary for the running process.
41560
5b8b6385
JK
41561To start @code{gdbserver} without supplying an initial command to run
41562or process ID to attach, use the @option{--multi} command line option.
41563In such case you should connect using @kbd{target extended-remote} to start
41564the program you want to debug.
41565
41566@smallexample
41567target> gdbserver --multi @var{comm}
41568@end smallexample
41569
43662968
JK
41570@ifclear man
41571@subheading Usage (host side)
41572@end ifclear
41573@ifset man
41574Usage (host side):
41575@end ifset
41576
41577You need an unstripped copy of the target program on your host system, since
41578@value{GDBN} needs to examine it's symbol tables and such. Start up @value{GDBN} as you normally
41579would, with the target program as the first argument. (You may need to use the
41580@option{--baud} option if the serial line is running at anything except 9600 baud.)
41581That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
5b8b6385
JK
41582new command you need to know about is @code{target remote}
41583(or @code{target extended-remote}). Its argument is either
43662968
JK
41584a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
41585descriptor. For example:
41586
41587@smallexample
41588@ifset man
41589@c @file would wrap it as F</dev/ttyb>.
41590(gdb) target remote /dev/ttyb
41591@end ifset
41592@ifclear man
41593(gdb) target remote @file{/dev/ttyb}
41594@end ifclear
41595@end smallexample
41596
41597@noindent
41598communicates with the server via serial line @file{/dev/ttyb}, and:
41599
41600@smallexample
41601(gdb) target remote the-target:2345
41602@end smallexample
41603
41604@noindent
41605communicates via a TCP connection to port 2345 on host `the-target', where
41606you previously started up @command{gdbserver} with the same port number. Note that for
41607TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
41608command, otherwise you may get an error that looks something like
41609`Connection refused'.
5b8b6385
JK
41610
41611@command{gdbserver} can also debug multiple inferiors at once,
41612described in
41613@ifset man
41614the @value{GDBN} manual in node @code{Inferiors and Programs}
41615-- shell command @code{info -f gdb -n 'Inferiors and Programs'}.
41616@end ifset
41617@ifclear man
41618@ref{Inferiors and Programs}.
41619@end ifclear
41620In such case use the @code{extended-remote} @value{GDBN} command variant:
41621
41622@smallexample
41623(gdb) target extended-remote the-target:2345
41624@end smallexample
41625
41626The @command{gdbserver} option @option{--multi} may or may not be used in such
41627case.
43662968
JK
41628@c man end
41629
41630@c man begin OPTIONS gdbserver
5b8b6385
JK
41631There are three different modes for invoking @command{gdbserver}:
41632
41633@itemize @bullet
41634
41635@item
41636Debug a specific program specified by its program name:
41637
41638@smallexample
41639gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
41640@end smallexample
41641
41642The @var{comm} parameter specifies how should the server communicate
41643with @value{GDBN}; it is either a device name (to use a serial line),
41644a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
41645stdin/stdout of @code{gdbserver}. Specify the name of the program to
41646debug in @var{prog}. Any remaining arguments will be passed to the
41647program verbatim. When the program exits, @value{GDBN} will close the
41648connection, and @code{gdbserver} will exit.
41649
41650@item
41651Debug a specific program by specifying the process ID of a running
41652program:
41653
41654@smallexample
41655gdbserver --attach @var{comm} @var{pid}
41656@end smallexample
41657
41658The @var{comm} parameter is as described above. Supply the process ID
41659of a running program in @var{pid}; @value{GDBN} will do everything
41660else. Like with the previous mode, when the process @var{pid} exits,
41661@value{GDBN} will close the connection, and @code{gdbserver} will exit.
41662
41663@item
41664Multi-process mode -- debug more than one program/process:
41665
41666@smallexample
41667gdbserver --multi @var{comm}
41668@end smallexample
41669
41670In this mode, @value{GDBN} can instruct @command{gdbserver} which
41671command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
41672close the connection when a process being debugged exits, so you can
41673debug several processes in the same session.
41674@end itemize
41675
41676In each of the modes you may specify these options:
41677
41678@table @env
41679
41680@item --help
41681List all options, with brief explanations.
41682
41683@item --version
41684This option causes @command{gdbserver} to print its version number and exit.
41685
41686@item --attach
41687@command{gdbserver} will attach to a running program. The syntax is:
41688
41689@smallexample
41690target> gdbserver --attach @var{comm} @var{pid}
41691@end smallexample
41692
41693@var{pid} is the process ID of a currently running process. It isn't
41694necessary to point @command{gdbserver} at a binary for the running process.
41695
41696@item --multi
41697To start @code{gdbserver} without supplying an initial command to run
41698or process ID to attach, use this command line option.
41699Then you can connect using @kbd{target extended-remote} and start
41700the program you want to debug. The syntax is:
41701
41702@smallexample
41703target> gdbserver --multi @var{comm}
41704@end smallexample
41705
41706@item --debug
41707Instruct @code{gdbserver} to display extra status information about the debugging
41708process.
41709This option is intended for @code{gdbserver} development and for bug reports to
41710the developers.
41711
41712@item --remote-debug
41713Instruct @code{gdbserver} to display remote protocol debug output.
41714This option is intended for @code{gdbserver} development and for bug reports to
41715the developers.
41716
87ce2a04
DE
41717@item --debug-format=option1@r{[},option2,...@r{]}
41718Instruct @code{gdbserver} to include extra information in each line
41719of debugging output.
41720@xref{Other Command-Line Arguments for gdbserver}.
41721
5b8b6385
JK
41722@item --wrapper
41723Specify a wrapper to launch programs
41724for debugging. The option should be followed by the name of the
41725wrapper, then any command-line arguments to pass to the wrapper, then
41726@kbd{--} indicating the end of the wrapper arguments.
41727
41728@item --once
41729By default, @command{gdbserver} keeps the listening TCP port open, so that
41730additional connections are possible. However, if you start @code{gdbserver}
41731with the @option{--once} option, it will stop listening for any further
41732connection attempts after connecting to the first @value{GDBN} session.
41733
41734@c --disable-packet is not documented for users.
41735
41736@c --disable-randomization and --no-disable-randomization are superseded by
41737@c QDisableRandomization.
41738
41739@end table
43662968
JK
41740@c man end
41741
41742@c man begin SEEALSO gdbserver
41743@ifset man
41744The full documentation for @value{GDBN} is maintained as a Texinfo manual.
41745If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
41746documentation are properly installed at your site, the command
41747
41748@smallexample
41749info gdb
41750@end smallexample
41751
41752should give you access to the complete manual.
41753
41754@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
41755Richard M. Stallman and Roland H. Pesch, July 1991.
41756@end ifset
41757@c man end
41758
b292c783
JK
41759@node gcore man
41760@heading gcore
41761
41762@c man title gcore Generate a core file of a running program
41763
41764@format
41765@c man begin SYNOPSIS gcore
41766gcore [-o @var{filename}] @var{pid}
41767@c man end
41768@end format
41769
41770@c man begin DESCRIPTION gcore
41771Generate a core dump of a running program with process ID @var{pid}.
41772Produced file is equivalent to a kernel produced core file as if the process
41773crashed (and if @kbd{ulimit -c} were used to set up an appropriate core dump
41774limit). Unlike after a crash, after @command{gcore} the program remains
41775running without any change.
41776@c man end
41777
41778@c man begin OPTIONS gcore
41779@table @env
41780@item -o @var{filename}
41781The optional argument
41782@var{filename} specifies the file name where to put the core dump.
41783If not specified, the file name defaults to @file{core.@var{pid}},
41784where @var{pid} is the running program process ID.
41785@end table
41786@c man end
41787
41788@c man begin SEEALSO gcore
41789@ifset man
41790The full documentation for @value{GDBN} is maintained as a Texinfo manual.
41791If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
41792documentation are properly installed at your site, the command
41793
41794@smallexample
41795info gdb
41796@end smallexample
41797
41798@noindent
41799should give you access to the complete manual.
41800
41801@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
41802Richard M. Stallman and Roland H. Pesch, July 1991.
41803@end ifset
41804@c man end
41805
43662968
JK
41806@node gdbinit man
41807@heading gdbinit
41808
41809@c man title gdbinit GDB initialization scripts
41810
41811@format
41812@c man begin SYNOPSIS gdbinit
41813@ifset SYSTEM_GDBINIT
41814@value{SYSTEM_GDBINIT}
41815@end ifset
41816
41817~/.gdbinit
41818
41819./.gdbinit
41820@c man end
41821@end format
41822
41823@c man begin DESCRIPTION gdbinit
41824These files contain @value{GDBN} commands to automatically execute during
41825@value{GDBN} startup. The lines of contents are canned sequences of commands,
41826described in
41827@ifset man
41828the @value{GDBN} manual in node @code{Sequences}
41829-- shell command @code{info -f gdb -n Sequences}.
41830@end ifset
41831@ifclear man
41832@ref{Sequences}.
41833@end ifclear
41834
41835Please read more in
41836@ifset man
41837the @value{GDBN} manual in node @code{Startup}
41838-- shell command @code{info -f gdb -n Startup}.
41839@end ifset
41840@ifclear man
41841@ref{Startup}.
41842@end ifclear
41843
41844@table @env
41845@ifset SYSTEM_GDBINIT
41846@item @value{SYSTEM_GDBINIT}
41847@end ifset
41848@ifclear SYSTEM_GDBINIT
41849@item (not enabled with @code{--with-system-gdbinit} during compilation)
41850@end ifclear
41851System-wide initialization file. It is executed unless user specified
41852@value{GDBN} option @code{-nx} or @code{-n}.
41853See more in
41854@ifset man
41855the @value{GDBN} manual in node @code{System-wide configuration}
41856-- shell command @code{info -f gdb -n 'System-wide configuration'}.
41857@end ifset
41858@ifclear man
41859@ref{System-wide configuration}.
41860@end ifclear
41861
41862@item ~/.gdbinit
41863User initialization file. It is executed unless user specified
41864@value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
41865
41866@item ./.gdbinit
41867Initialization file for current directory. It may need to be enabled with
41868@value{GDBN} security command @code{set auto-load local-gdbinit}.
41869See more in
41870@ifset man
41871the @value{GDBN} manual in node @code{Init File in the Current Directory}
41872-- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
41873@end ifset
41874@ifclear man
41875@ref{Init File in the Current Directory}.
41876@end ifclear
41877@end table
41878@c man end
41879
41880@c man begin SEEALSO gdbinit
41881@ifset man
41882gdb(1), @code{info -f gdb -n Startup}
41883
41884The full documentation for @value{GDBN} is maintained as a Texinfo manual.
41885If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
41886documentation are properly installed at your site, the command
41887
41888@smallexample
41889info gdb
41890@end smallexample
41891
41892should give you access to the complete manual.
41893
41894@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
41895Richard M. Stallman and Roland H. Pesch, July 1991.
41896@end ifset
41897@c man end
41898
aab4e0ec 41899@include gpl.texi
eb12ee30 41900
e4c0cfae
SS
41901@node GNU Free Documentation License
41902@appendix GNU Free Documentation License
6826cf00
EZ
41903@include fdl.texi
41904
00595b5e
EZ
41905@node Concept Index
41906@unnumbered Concept Index
c906108c
SS
41907
41908@printindex cp
41909
00595b5e
EZ
41910@node Command and Variable Index
41911@unnumbered Command, Variable, and Function Index
41912
41913@printindex fn
41914
c906108c 41915@tex
984359d2 41916% I think something like @@colophon should be in texinfo. In the
c906108c
SS
41917% meantime:
41918\long\def\colophon{\hbox to0pt{}\vfill
41919\centerline{The body of this manual is set in}
41920\centerline{\fontname\tenrm,}
41921\centerline{with headings in {\bf\fontname\tenbf}}
41922\centerline{and examples in {\tt\fontname\tentt}.}
41923\centerline{{\it\fontname\tenit\/},}
41924\centerline{{\bf\fontname\tenbf}, and}
41925\centerline{{\sl\fontname\tensl\/}}
41926\centerline{are used for emphasis.}\vfill}
41927\page\colophon
984359d2 41928% Blame: doc@@cygnus.com, 1991.
c906108c
SS
41929@end tex
41930
c906108c 41931@bye
This page took 8.532267 seconds and 4 git commands to generate.