btrace: control memory access during replay
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
ecd75fc8 2@c Copyright (C) 1988-2014 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
ecd75fc8 53Copyright @copyright{} 1988-2014 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
ecd75fc8 123Copyright (C) 1988-2014 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
c906108c
SS
888@value{GDBN}'s non-warranty, by specifying @code{-silent}:
889
890@smallexample
891@value{GDBP} -silent
892@end smallexample
893
894@noindent
895You can further control how @value{GDBN} starts up by using command-line
896options. @value{GDBN} itself can remind you of the options available.
897
898@noindent
899Type
900
474c8240 901@smallexample
c906108c 902@value{GDBP} -help
474c8240 903@end smallexample
c906108c
SS
904
905@noindent
906to display all available options and briefly describe their use
907(@samp{@value{GDBP} -h} is a shorter equivalent).
908
909All options and command line arguments you give are processed
910in sequential order. The order makes a difference when the
911@samp{-x} option is used.
912
913
914@menu
c906108c
SS
915* File Options:: Choosing files
916* Mode Options:: Choosing modes
6fc08d32 917* Startup:: What @value{GDBN} does during startup
c906108c
SS
918@end menu
919
6d2ebf8b 920@node File Options
79a6e687 921@subsection Choosing Files
c906108c 922
2df3850c 923When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
924specifying an executable file and core file (or process ID). This is
925the same as if the arguments were specified by the @samp{-se} and
d52fb0e9 926@samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
19837790
MS
927first argument that does not have an associated option flag as
928equivalent to the @samp{-se} option followed by that argument; and the
929second argument that does not have an associated option flag, if any, as
930equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
931If the second argument begins with a decimal digit, @value{GDBN} will
932first attempt to attach to it as a process, and if that fails, attempt
933to open it as a corefile. If you have a corefile whose name begins with
b383017d 934a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 935prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
936
937If @value{GDBN} has not been configured to included core file support,
938such as for most embedded targets, then it will complain about a second
939argument and ignore it.
c906108c
SS
940
941Many options have both long and short forms; both are shown in the
942following list. @value{GDBN} also recognizes the long forms if you truncate
943them, so long as enough of the option is present to be unambiguous.
944(If you prefer, you can flag option arguments with @samp{--} rather
945than @samp{-}, though we illustrate the more usual convention.)
946
d700128c
EZ
947@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
948@c way, both those who look for -foo and --foo in the index, will find
949@c it.
950
c906108c
SS
951@table @code
952@item -symbols @var{file}
953@itemx -s @var{file}
d700128c
EZ
954@cindex @code{--symbols}
955@cindex @code{-s}
c906108c
SS
956Read symbol table from file @var{file}.
957
958@item -exec @var{file}
959@itemx -e @var{file}
d700128c
EZ
960@cindex @code{--exec}
961@cindex @code{-e}
7a292a7a
SS
962Use file @var{file} as the executable file to execute when appropriate,
963and for examining pure data in conjunction with a core dump.
c906108c
SS
964
965@item -se @var{file}
d700128c 966@cindex @code{--se}
c906108c
SS
967Read symbol table from file @var{file} and use it as the executable
968file.
969
c906108c
SS
970@item -core @var{file}
971@itemx -c @var{file}
d700128c
EZ
972@cindex @code{--core}
973@cindex @code{-c}
b383017d 974Use file @var{file} as a core dump to examine.
c906108c 975
19837790
MS
976@item -pid @var{number}
977@itemx -p @var{number}
978@cindex @code{--pid}
979@cindex @code{-p}
980Connect to process ID @var{number}, as with the @code{attach} command.
c906108c
SS
981
982@item -command @var{file}
983@itemx -x @var{file}
d700128c
EZ
984@cindex @code{--command}
985@cindex @code{-x}
95433b34
JB
986Execute commands from file @var{file}. The contents of this file is
987evaluated exactly as the @code{source} command would.
8150ff9c 988@xref{Command Files,, Command files}.
c906108c 989
8a5a3c82
AS
990@item -eval-command @var{command}
991@itemx -ex @var{command}
992@cindex @code{--eval-command}
993@cindex @code{-ex}
994Execute a single @value{GDBN} command.
995
996This option may be used multiple times to call multiple commands. It may
997also be interleaved with @samp{-command} as required.
998
999@smallexample
1000@value{GDBP} -ex 'target sim' -ex 'load' \
1001 -x setbreakpoints -ex 'run' a.out
1002@end smallexample
1003
8320cc4f
JK
1004@item -init-command @var{file}
1005@itemx -ix @var{file}
1006@cindex @code{--init-command}
1007@cindex @code{-ix}
2d7b58e8
JK
1008Execute commands from file @var{file} before loading the inferior (but
1009after loading gdbinit files).
8320cc4f
JK
1010@xref{Startup}.
1011
1012@item -init-eval-command @var{command}
1013@itemx -iex @var{command}
1014@cindex @code{--init-eval-command}
1015@cindex @code{-iex}
2d7b58e8
JK
1016Execute a single @value{GDBN} command before loading the inferior (but
1017after loading gdbinit files).
8320cc4f
JK
1018@xref{Startup}.
1019
c906108c
SS
1020@item -directory @var{directory}
1021@itemx -d @var{directory}
d700128c
EZ
1022@cindex @code{--directory}
1023@cindex @code{-d}
4b505b12 1024Add @var{directory} to the path to search for source and script files.
c906108c 1025
c906108c
SS
1026@item -r
1027@itemx -readnow
d700128c
EZ
1028@cindex @code{--readnow}
1029@cindex @code{-r}
c906108c
SS
1030Read each symbol file's entire symbol table immediately, rather than
1031the default, which is to read it incrementally as it is needed.
1032This makes startup slower, but makes future operations faster.
53a5351d 1033
c906108c
SS
1034@end table
1035
6d2ebf8b 1036@node Mode Options
79a6e687 1037@subsection Choosing Modes
c906108c
SS
1038
1039You can run @value{GDBN} in various alternative modes---for example, in
1040batch mode or quiet mode.
1041
1042@table @code
bf88dd68 1043@anchor{-nx}
c906108c
SS
1044@item -nx
1045@itemx -n
d700128c
EZ
1046@cindex @code{--nx}
1047@cindex @code{-n}
07540c15
DE
1048Do not execute commands found in any initialization file.
1049There are three init files, loaded in the following order:
1050
1051@table @code
1052@item @file{system.gdbinit}
1053This is the system-wide init file.
1054Its location is specified with the @code{--with-system-gdbinit}
1055configure option (@pxref{System-wide configuration}).
1056It is loaded first when @value{GDBN} starts, before command line options
1057have been processed.
1058@item @file{~/.gdbinit}
1059This is the init file in your home directory.
1060It is loaded next, after @file{system.gdbinit}, and before
1061command options have been processed.
1062@item @file{./.gdbinit}
1063This is the init file in the current directory.
1064It is loaded last, after command line options other than @code{-x} and
1065@code{-ex} have been processed. Command line options @code{-x} and
1066@code{-ex} are processed last, after @file{./.gdbinit} has been loaded.
1067@end table
1068
1069For further documentation on startup processing, @xref{Startup}.
1070For documentation on how to write command files,
1071@xref{Command Files,,Command Files}.
1072
1073@anchor{-nh}
1074@item -nh
1075@cindex @code{--nh}
1076Do not execute commands found in @file{~/.gdbinit}, the init file
1077in your home directory.
1078@xref{Startup}.
c906108c
SS
1079
1080@item -quiet
d700128c 1081@itemx -silent
c906108c 1082@itemx -q
d700128c
EZ
1083@cindex @code{--quiet}
1084@cindex @code{--silent}
1085@cindex @code{-q}
c906108c
SS
1086``Quiet''. Do not print the introductory and copyright messages. These
1087messages are also suppressed in batch mode.
1088
1089@item -batch
d700128c 1090@cindex @code{--batch}
c906108c
SS
1091Run in batch mode. Exit with status @code{0} after processing all the
1092command files specified with @samp{-x} (and all commands from
1093initialization files, if not inhibited with @samp{-n}). Exit with
1094nonzero status if an error occurs in executing the @value{GDBN} commands
5da1313b
JK
1095in the command files. Batch mode also disables pagination, sets unlimited
1096terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1097off} were in effect (@pxref{Messages/Warnings}).
c906108c 1098
2df3850c
JM
1099Batch mode may be useful for running @value{GDBN} as a filter, for
1100example to download and run a program on another computer; in order to
1101make this more useful, the message
c906108c 1102
474c8240 1103@smallexample
c906108c 1104Program exited normally.
474c8240 1105@end smallexample
c906108c
SS
1106
1107@noindent
2df3850c
JM
1108(which is ordinarily issued whenever a program running under
1109@value{GDBN} control terminates) is not issued when running in batch
1110mode.
1111
1a088d06
AS
1112@item -batch-silent
1113@cindex @code{--batch-silent}
1114Run in batch mode exactly like @samp{-batch}, but totally silently. All
1115@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1116unaffected). This is much quieter than @samp{-silent} and would be useless
1117for an interactive session.
1118
1119This is particularly useful when using targets that give @samp{Loading section}
1120messages, for example.
1121
1122Note that targets that give their output via @value{GDBN}, as opposed to
1123writing directly to @code{stdout}, will also be made silent.
1124
4b0ad762
AS
1125@item -return-child-result
1126@cindex @code{--return-child-result}
1127The return code from @value{GDBN} will be the return code from the child
1128process (the process being debugged), with the following exceptions:
1129
1130@itemize @bullet
1131@item
1132@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1133internal error. In this case the exit code is the same as it would have been
1134without @samp{-return-child-result}.
1135@item
1136The user quits with an explicit value. E.g., @samp{quit 1}.
1137@item
1138The child process never runs, or is not allowed to terminate, in which case
1139the exit code will be -1.
1140@end itemize
1141
1142This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1143when @value{GDBN} is being used as a remote program loader or simulator
1144interface.
1145
2df3850c
JM
1146@item -nowindows
1147@itemx -nw
d700128c
EZ
1148@cindex @code{--nowindows}
1149@cindex @code{-nw}
2df3850c 1150``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1151(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1152interface. If no GUI is available, this option has no effect.
1153
1154@item -windows
1155@itemx -w
d700128c
EZ
1156@cindex @code{--windows}
1157@cindex @code{-w}
2df3850c
JM
1158If @value{GDBN} includes a GUI, then this option requires it to be
1159used if possible.
c906108c
SS
1160
1161@item -cd @var{directory}
d700128c 1162@cindex @code{--cd}
c906108c
SS
1163Run @value{GDBN} using @var{directory} as its working directory,
1164instead of the current directory.
1165
aae1c79a 1166@item -data-directory @var{directory}
8d551b02 1167@itemx -D @var{directory}
aae1c79a 1168@cindex @code{--data-directory}
8d551b02 1169@cindex @code{-D}
aae1c79a
DE
1170Run @value{GDBN} using @var{directory} as its data directory.
1171The data directory is where @value{GDBN} searches for its
1172auxiliary files. @xref{Data Files}.
1173
c906108c
SS
1174@item -fullname
1175@itemx -f
d700128c
EZ
1176@cindex @code{--fullname}
1177@cindex @code{-f}
7a292a7a
SS
1178@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1179subprocess. It tells @value{GDBN} to output the full file name and line
1180number in a standard, recognizable fashion each time a stack frame is
1181displayed (which includes each time your program stops). This
1182recognizable format looks like two @samp{\032} characters, followed by
1183the file name, line number and character position separated by colons,
1184and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1185@samp{\032} characters as a signal to display the source code for the
1186frame.
c906108c 1187
d700128c
EZ
1188@item -annotate @var{level}
1189@cindex @code{--annotate}
1190This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1191effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1192(@pxref{Annotations}). The annotation @var{level} controls how much
1193information @value{GDBN} prints together with its prompt, values of
1194expressions, source lines, and other types of output. Level 0 is the
1195normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1196@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1197that control @value{GDBN}, and level 2 has been deprecated.
1198
265eeb58 1199The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1200(@pxref{GDB/MI}).
d700128c 1201
aa26fa3a
TT
1202@item --args
1203@cindex @code{--args}
1204Change interpretation of command line so that arguments following the
1205executable file are passed as command line arguments to the inferior.
1206This option stops option processing.
1207
2df3850c
JM
1208@item -baud @var{bps}
1209@itemx -b @var{bps}
d700128c
EZ
1210@cindex @code{--baud}
1211@cindex @code{-b}
c906108c
SS
1212Set the line speed (baud rate or bits per second) of any serial
1213interface used by @value{GDBN} for remote debugging.
c906108c 1214
f47b1503
AS
1215@item -l @var{timeout}
1216@cindex @code{-l}
1217Set the timeout (in seconds) of any communication used by @value{GDBN}
1218for remote debugging.
1219
c906108c 1220@item -tty @var{device}
d700128c
EZ
1221@itemx -t @var{device}
1222@cindex @code{--tty}
1223@cindex @code{-t}
c906108c
SS
1224Run using @var{device} for your program's standard input and output.
1225@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1226
53a5351d 1227@c resolve the situation of these eventually
c4555f82
SC
1228@item -tui
1229@cindex @code{--tui}
d0d5df6f
AC
1230Activate the @dfn{Text User Interface} when starting. The Text User
1231Interface manages several text windows on the terminal, showing
1232source, assembly, registers and @value{GDBN} command outputs
217bff3e
JK
1233(@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1234option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1235Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1236
1237@c @item -xdb
d700128c 1238@c @cindex @code{--xdb}
53a5351d
JM
1239@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1240@c For information, see the file @file{xdb_trans.html}, which is usually
1241@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1242@c systems.
1243
d700128c
EZ
1244@item -interpreter @var{interp}
1245@cindex @code{--interpreter}
1246Use the interpreter @var{interp} for interface with the controlling
1247program or device. This option is meant to be set by programs which
94bbb2c0 1248communicate with @value{GDBN} using it as a back end.
21c294e6 1249@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1250
da0f9dcd 1251@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1252@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1253The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1254previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1255selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1256@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1257
1258@item -write
1259@cindex @code{--write}
1260Open the executable and core files for both reading and writing. This
1261is equivalent to the @samp{set write on} command inside @value{GDBN}
1262(@pxref{Patching}).
1263
1264@item -statistics
1265@cindex @code{--statistics}
1266This option causes @value{GDBN} to print statistics about time and
1267memory usage after it completes each command and returns to the prompt.
1268
1269@item -version
1270@cindex @code{--version}
1271This option causes @value{GDBN} to print its version number and
1272no-warranty blurb, and exit.
1273
6eaaf48b
EZ
1274@item -configuration
1275@cindex @code{--configuration}
1276This option causes @value{GDBN} to print details about its build-time
1277configuration parameters, and then exit. These details can be
1278important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1279
c906108c
SS
1280@end table
1281
6fc08d32 1282@node Startup
79a6e687 1283@subsection What @value{GDBN} Does During Startup
6fc08d32
EZ
1284@cindex @value{GDBN} startup
1285
1286Here's the description of what @value{GDBN} does during session startup:
1287
1288@enumerate
1289@item
1290Sets up the command interpreter as specified by the command line
1291(@pxref{Mode Options, interpreter}).
1292
1293@item
1294@cindex init file
098b41a6
JG
1295Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1296used when building @value{GDBN}; @pxref{System-wide configuration,
1297 ,System-wide configuration and settings}) and executes all the commands in
1298that file.
1299
bf88dd68 1300@anchor{Home Directory Init File}
098b41a6
JG
1301@item
1302Reads the init file (if any) in your home directory@footnote{On
6fc08d32
EZ
1303DOS/Windows systems, the home directory is the one pointed to by the
1304@code{HOME} environment variable.} and executes all the commands in
1305that file.
1306
2d7b58e8
JK
1307@anchor{Option -init-eval-command}
1308@item
1309Executes commands and command files specified by the @samp{-iex} and
1310@samp{-ix} options in their specified order. Usually you should use the
1311@samp{-ex} and @samp{-x} options instead, but this way you can apply
1312settings before @value{GDBN} init files get executed and before inferior
1313gets loaded.
1314
6fc08d32
EZ
1315@item
1316Processes command line options and operands.
1317
bf88dd68 1318@anchor{Init File in the Current Directory during Startup}
6fc08d32
EZ
1319@item
1320Reads and executes the commands from init file (if any) in the current
bf88dd68
JK
1321working directory as long as @samp{set auto-load local-gdbinit} is set to
1322@samp{on} (@pxref{Init File in the Current Directory}).
1323This is only done if the current directory is
119b882a
EZ
1324different from your home directory. Thus, you can have more than one
1325init file, one generic in your home directory, and another, specific
1326to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1327@value{GDBN}.
1328
a86caf66
DE
1329@item
1330If the command line specified a program to debug, or a process to
1331attach to, or a core file, @value{GDBN} loads any auto-loaded
1332scripts provided for the program or for its loaded shared libraries.
1333@xref{Auto-loading}.
1334
1335If you wish to disable the auto-loading during startup,
1336you must do something like the following:
1337
1338@smallexample
bf88dd68 1339$ gdb -iex "set auto-load python-scripts off" myprogram
a86caf66
DE
1340@end smallexample
1341
8320cc4f
JK
1342Option @samp{-ex} does not work because the auto-loading is then turned
1343off too late.
a86caf66 1344
6fc08d32 1345@item
6fe37d23
JK
1346Executes commands and command files specified by the @samp{-ex} and
1347@samp{-x} options in their specified order. @xref{Command Files}, for
1348more details about @value{GDBN} command files.
6fc08d32
EZ
1349
1350@item
1351Reads the command history recorded in the @dfn{history file}.
d620b259 1352@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1353files where @value{GDBN} records it.
1354@end enumerate
1355
1356Init files use the same syntax as @dfn{command files} (@pxref{Command
1357Files}) and are processed by @value{GDBN} in the same way. The init
1358file in your home directory can set options (such as @samp{set
1359complaints}) that affect subsequent processing of command line options
1360and operands. Init files are not executed if you use the @samp{-nx}
79a6e687 1361option (@pxref{Mode Options, ,Choosing Modes}).
6fc08d32 1362
098b41a6
JG
1363To display the list of init files loaded by gdb at startup, you
1364can use @kbd{gdb --help}.
1365
6fc08d32
EZ
1366@cindex init file name
1367@cindex @file{.gdbinit}
119b882a 1368@cindex @file{gdb.ini}
8807d78b 1369The @value{GDBN} init files are normally called @file{.gdbinit}.
119b882a
EZ
1370The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1371the limitations of file names imposed by DOS filesystems. The Windows
4d3f93a2
JB
1372port of @value{GDBN} uses the standard name, but if it finds a
1373@file{gdb.ini} file in your home directory, it warns you about that
1374and suggests to rename the file to the standard name.
119b882a 1375
6fc08d32 1376
6d2ebf8b 1377@node Quitting GDB
c906108c
SS
1378@section Quitting @value{GDBN}
1379@cindex exiting @value{GDBN}
1380@cindex leaving @value{GDBN}
1381
1382@table @code
1383@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1384@kindex q @r{(@code{quit})}
96a2c332
SS
1385@item quit @r{[}@var{expression}@r{]}
1386@itemx q
1387To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1388@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1389do not supply @var{expression}, @value{GDBN} will terminate normally;
1390otherwise it will terminate using the result of @var{expression} as the
1391error code.
c906108c
SS
1392@end table
1393
1394@cindex interrupt
c8aa23ab 1395An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1396terminates the action of any @value{GDBN} command that is in progress and
1397returns to @value{GDBN} command level. It is safe to type the interrupt
1398character at any time because @value{GDBN} does not allow it to take effect
1399until a time when it is safe.
1400
c906108c
SS
1401If you have been using @value{GDBN} to control an attached process or
1402device, you can release it with the @code{detach} command
79a6e687 1403(@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 1404
6d2ebf8b 1405@node Shell Commands
79a6e687 1406@section Shell Commands
c906108c
SS
1407
1408If you need to execute occasional shell commands during your
1409debugging session, there is no need to leave or suspend @value{GDBN}; you can
1410just use the @code{shell} command.
1411
1412@table @code
1413@kindex shell
ed59ded5 1414@kindex !
c906108c 1415@cindex shell escape
ed59ded5
DE
1416@item shell @var{command-string}
1417@itemx !@var{command-string}
1418Invoke a standard shell to execute @var{command-string}.
1419Note that no space is needed between @code{!} and @var{command-string}.
c906108c 1420If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1421shell to run. Otherwise @value{GDBN} uses the default shell
1422(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1423@end table
1424
1425The utility @code{make} is often needed in development environments.
1426You do not have to use the @code{shell} command for this purpose in
1427@value{GDBN}:
1428
1429@table @code
1430@kindex make
1431@cindex calling make
1432@item make @var{make-args}
1433Execute the @code{make} program with the specified
1434arguments. This is equivalent to @samp{shell make @var{make-args}}.
1435@end table
1436
79a6e687
BW
1437@node Logging Output
1438@section Logging Output
0fac0b41 1439@cindex logging @value{GDBN} output
9c16f35a 1440@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1441
1442You may want to save the output of @value{GDBN} commands to a file.
1443There are several commands to control @value{GDBN}'s logging.
1444
1445@table @code
1446@kindex set logging
1447@item set logging on
1448Enable logging.
1449@item set logging off
1450Disable logging.
9c16f35a 1451@cindex logging file name
0fac0b41
DJ
1452@item set logging file @var{file}
1453Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1454@item set logging overwrite [on|off]
1455By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1456you want @code{set logging on} to overwrite the logfile instead.
1457@item set logging redirect [on|off]
1458By default, @value{GDBN} output will go to both the terminal and the logfile.
1459Set @code{redirect} if you want output to go only to the log file.
1460@kindex show logging
1461@item show logging
1462Show the current values of the logging settings.
1463@end table
1464
6d2ebf8b 1465@node Commands
c906108c
SS
1466@chapter @value{GDBN} Commands
1467
1468You can abbreviate a @value{GDBN} command to the first few letters of the command
1469name, if that abbreviation is unambiguous; and you can repeat certain
1470@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1471key to get @value{GDBN} to fill out the rest of a word in a command (or to
1472show you the alternatives available, if there is more than one possibility).
1473
1474@menu
1475* Command Syntax:: How to give commands to @value{GDBN}
1476* Completion:: Command completion
1477* Help:: How to ask @value{GDBN} for help
1478@end menu
1479
6d2ebf8b 1480@node Command Syntax
79a6e687 1481@section Command Syntax
c906108c
SS
1482
1483A @value{GDBN} command is a single line of input. There is no limit on
1484how long it can be. It starts with a command name, which is followed by
1485arguments whose meaning depends on the command name. For example, the
1486command @code{step} accepts an argument which is the number of times to
1487step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1488with no arguments. Some commands do not allow any arguments.
c906108c
SS
1489
1490@cindex abbreviation
1491@value{GDBN} command names may always be truncated if that abbreviation is
1492unambiguous. Other possible command abbreviations are listed in the
1493documentation for individual commands. In some cases, even ambiguous
1494abbreviations are allowed; for example, @code{s} is specially defined as
1495equivalent to @code{step} even though there are other commands whose
1496names start with @code{s}. You can test abbreviations by using them as
1497arguments to the @code{help} command.
1498
1499@cindex repeating commands
41afff9a 1500@kindex RET @r{(repeat last command)}
c906108c 1501A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1502repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1503will not repeat this way; these are commands whose unintentional
1504repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1505repeat. User-defined commands can disable this feature; see
1506@ref{Define, dont-repeat}.
c906108c
SS
1507
1508The @code{list} and @code{x} commands, when you repeat them with
1509@key{RET}, construct new arguments rather than repeating
1510exactly as typed. This permits easy scanning of source or memory.
1511
1512@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1513output, in a way similar to the common utility @code{more}
79a6e687 1514(@pxref{Screen Size,,Screen Size}). Since it is easy to press one
c906108c
SS
1515@key{RET} too many in this situation, @value{GDBN} disables command
1516repetition after any command that generates this sort of display.
1517
41afff9a 1518@kindex # @r{(a comment)}
c906108c
SS
1519@cindex comment
1520Any text from a @kbd{#} to the end of the line is a comment; it does
1521nothing. This is useful mainly in command files (@pxref{Command
79a6e687 1522Files,,Command Files}).
c906108c 1523
88118b3a 1524@cindex repeating command sequences
c8aa23ab
EZ
1525@kindex Ctrl-o @r{(operate-and-get-next)}
1526The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1527commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1528then fetches the next line relative to the current line from the history
1529for editing.
1530
6d2ebf8b 1531@node Completion
79a6e687 1532@section Command Completion
c906108c
SS
1533
1534@cindex completion
1535@cindex word completion
1536@value{GDBN} can fill in the rest of a word in a command for you, if there is
1537only one possibility; it can also show you what the valid possibilities
1538are for the next word in a command, at any time. This works for @value{GDBN}
1539commands, @value{GDBN} subcommands, and the names of symbols in your program.
1540
1541Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1542of a word. If there is only one possibility, @value{GDBN} fills in the
1543word, and waits for you to finish the command (or press @key{RET} to
1544enter it). For example, if you type
1545
1546@c FIXME "@key" does not distinguish its argument sufficiently to permit
1547@c complete accuracy in these examples; space introduced for clarity.
1548@c If texinfo enhancements make it unnecessary, it would be nice to
1549@c replace " @key" by "@key" in the following...
474c8240 1550@smallexample
c906108c 1551(@value{GDBP}) info bre @key{TAB}
474c8240 1552@end smallexample
c906108c
SS
1553
1554@noindent
1555@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1556the only @code{info} subcommand beginning with @samp{bre}:
1557
474c8240 1558@smallexample
c906108c 1559(@value{GDBP}) info breakpoints
474c8240 1560@end smallexample
c906108c
SS
1561
1562@noindent
1563You can either press @key{RET} at this point, to run the @code{info
1564breakpoints} command, or backspace and enter something else, if
1565@samp{breakpoints} does not look like the command you expected. (If you
1566were sure you wanted @code{info breakpoints} in the first place, you
1567might as well just type @key{RET} immediately after @samp{info bre},
1568to exploit command abbreviations rather than command completion).
1569
1570If there is more than one possibility for the next word when you press
1571@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1572characters and try again, or just press @key{TAB} a second time;
1573@value{GDBN} displays all the possible completions for that word. For
1574example, you might want to set a breakpoint on a subroutine whose name
1575begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1576just sounds the bell. Typing @key{TAB} again displays all the
1577function names in your program that begin with those characters, for
1578example:
1579
474c8240 1580@smallexample
c906108c
SS
1581(@value{GDBP}) b make_ @key{TAB}
1582@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1583make_a_section_from_file make_environ
1584make_abs_section make_function_type
1585make_blockvector make_pointer_type
1586make_cleanup make_reference_type
c906108c
SS
1587make_command make_symbol_completion_list
1588(@value{GDBP}) b make_
474c8240 1589@end smallexample
c906108c
SS
1590
1591@noindent
1592After displaying the available possibilities, @value{GDBN} copies your
1593partial input (@samp{b make_} in the example) so you can finish the
1594command.
1595
1596If you just want to see the list of alternatives in the first place, you
b37052ae 1597can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1598means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1599key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1600one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1601
1602@cindex quotes in commands
1603@cindex completion of quoted strings
1604Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1605parentheses or other characters that @value{GDBN} normally excludes from
1606its notion of a word. To permit word completion to work in this
1607situation, you may enclose words in @code{'} (single quote marks) in
1608@value{GDBN} commands.
c906108c 1609
c906108c 1610The most likely situation where you might need this is in typing the
b37052ae
EZ
1611name of a C@t{++} function. This is because C@t{++} allows function
1612overloading (multiple definitions of the same function, distinguished
1613by argument type). For example, when you want to set a breakpoint you
1614may need to distinguish whether you mean the version of @code{name}
1615that takes an @code{int} parameter, @code{name(int)}, or the version
1616that takes a @code{float} parameter, @code{name(float)}. To use the
1617word-completion facilities in this situation, type a single quote
1618@code{'} at the beginning of the function name. This alerts
1619@value{GDBN} that it may need to consider more information than usual
1620when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1621
474c8240 1622@smallexample
96a2c332 1623(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1624bubble(double,double) bubble(int,int)
1625(@value{GDBP}) b 'bubble(
474c8240 1626@end smallexample
c906108c
SS
1627
1628In some cases, @value{GDBN} can tell that completing a name requires using
1629quotes. When this happens, @value{GDBN} inserts the quote for you (while
1630completing as much as it can) if you do not type the quote in the first
1631place:
1632
474c8240 1633@smallexample
c906108c
SS
1634(@value{GDBP}) b bub @key{TAB}
1635@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1636(@value{GDBP}) b 'bubble(
474c8240 1637@end smallexample
c906108c
SS
1638
1639@noindent
1640In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1641you have not yet started typing the argument list when you ask for
1642completion on an overloaded symbol.
1643
79a6e687
BW
1644For more information about overloaded functions, see @ref{C Plus Plus
1645Expressions, ,C@t{++} Expressions}. You can use the command @code{set
c906108c 1646overload-resolution off} to disable overload resolution;
79a6e687 1647see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
c906108c 1648
65d12d83
TT
1649@cindex completion of structure field names
1650@cindex structure field name completion
1651@cindex completion of union field names
1652@cindex union field name completion
1653When completing in an expression which looks up a field in a
1654structure, @value{GDBN} also tries@footnote{The completer can be
1655confused by certain kinds of invalid expressions. Also, it only
1656examines the static type of the expression, not the dynamic type.} to
1657limit completions to the field names available in the type of the
1658left-hand-side:
1659
1660@smallexample
1661(@value{GDBP}) p gdb_stdout.@kbd{M-?}
01124a23
DE
1662magic to_fputs to_rewind
1663to_data to_isatty to_write
1664to_delete to_put to_write_async_safe
1665to_flush to_read
65d12d83
TT
1666@end smallexample
1667
1668@noindent
1669This is because the @code{gdb_stdout} is a variable of the type
1670@code{struct ui_file} that is defined in @value{GDBN} sources as
1671follows:
1672
1673@smallexample
1674struct ui_file
1675@{
1676 int *magic;
1677 ui_file_flush_ftype *to_flush;
1678 ui_file_write_ftype *to_write;
01124a23 1679 ui_file_write_async_safe_ftype *to_write_async_safe;
65d12d83
TT
1680 ui_file_fputs_ftype *to_fputs;
1681 ui_file_read_ftype *to_read;
1682 ui_file_delete_ftype *to_delete;
1683 ui_file_isatty_ftype *to_isatty;
1684 ui_file_rewind_ftype *to_rewind;
1685 ui_file_put_ftype *to_put;
1686 void *to_data;
1687@}
1688@end smallexample
1689
c906108c 1690
6d2ebf8b 1691@node Help
79a6e687 1692@section Getting Help
c906108c
SS
1693@cindex online documentation
1694@kindex help
1695
5d161b24 1696You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1697using the command @code{help}.
1698
1699@table @code
41afff9a 1700@kindex h @r{(@code{help})}
c906108c
SS
1701@item help
1702@itemx h
1703You can use @code{help} (abbreviated @code{h}) with no arguments to
1704display a short list of named classes of commands:
1705
1706@smallexample
1707(@value{GDBP}) help
1708List of classes of commands:
1709
2df3850c 1710aliases -- Aliases of other commands
c906108c 1711breakpoints -- Making program stop at certain points
2df3850c 1712data -- Examining data
c906108c 1713files -- Specifying and examining files
2df3850c
JM
1714internals -- Maintenance commands
1715obscure -- Obscure features
1716running -- Running the program
1717stack -- Examining the stack
c906108c
SS
1718status -- Status inquiries
1719support -- Support facilities
12c27660 1720tracepoints -- Tracing of program execution without
96a2c332 1721 stopping the program
c906108c 1722user-defined -- User-defined commands
c906108c 1723
5d161b24 1724Type "help" followed by a class name for a list of
c906108c 1725commands in that class.
5d161b24 1726Type "help" followed by command name for full
c906108c
SS
1727documentation.
1728Command name abbreviations are allowed if unambiguous.
1729(@value{GDBP})
1730@end smallexample
96a2c332 1731@c the above line break eliminates huge line overfull...
c906108c
SS
1732
1733@item help @var{class}
1734Using one of the general help classes as an argument, you can get a
1735list of the individual commands in that class. For example, here is the
1736help display for the class @code{status}:
1737
1738@smallexample
1739(@value{GDBP}) help status
1740Status inquiries.
1741
1742List of commands:
1743
1744@c Line break in "show" line falsifies real output, but needed
1745@c to fit in smallbook page size.
2df3850c 1746info -- Generic command for showing things
12c27660 1747 about the program being debugged
2df3850c 1748show -- Generic command for showing things
12c27660 1749 about the debugger
c906108c 1750
5d161b24 1751Type "help" followed by command name for full
c906108c
SS
1752documentation.
1753Command name abbreviations are allowed if unambiguous.
1754(@value{GDBP})
1755@end smallexample
1756
1757@item help @var{command}
1758With a command name as @code{help} argument, @value{GDBN} displays a
1759short paragraph on how to use that command.
1760
6837a0a2
DB
1761@kindex apropos
1762@item apropos @var{args}
09d4efe1 1763The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2 1764commands, and their documentation, for the regular expression specified in
99e008fe 1765@var{args}. It prints out all matches found. For example:
6837a0a2
DB
1766
1767@smallexample
16899756 1768apropos alias
6837a0a2
DB
1769@end smallexample
1770
b37052ae
EZ
1771@noindent
1772results in:
6837a0a2
DB
1773
1774@smallexample
6d2ebf8b 1775@c @group
16899756
DE
1776alias -- Define a new command that is an alias of an existing command
1777aliases -- Aliases of other commands
1778d -- Delete some breakpoints or auto-display expressions
1779del -- Delete some breakpoints or auto-display expressions
1780delete -- Delete some breakpoints or auto-display expressions
6d2ebf8b 1781@c @end group
6837a0a2
DB
1782@end smallexample
1783
c906108c
SS
1784@kindex complete
1785@item complete @var{args}
1786The @code{complete @var{args}} command lists all the possible completions
1787for the beginning of a command. Use @var{args} to specify the beginning of the
1788command you want completed. For example:
1789
1790@smallexample
1791complete i
1792@end smallexample
1793
1794@noindent results in:
1795
1796@smallexample
1797@group
2df3850c
JM
1798if
1799ignore
c906108c
SS
1800info
1801inspect
c906108c
SS
1802@end group
1803@end smallexample
1804
1805@noindent This is intended for use by @sc{gnu} Emacs.
1806@end table
1807
1808In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1809and @code{show} to inquire about the state of your program, or the state
1810of @value{GDBN} itself. Each command supports many topics of inquiry; this
1811manual introduces each of them in the appropriate context. The listings
00595b5e
EZ
1812under @code{info} and under @code{show} in the Command, Variable, and
1813Function Index point to all the sub-commands. @xref{Command and Variable
1814Index}.
c906108c
SS
1815
1816@c @group
1817@table @code
1818@kindex info
41afff9a 1819@kindex i @r{(@code{info})}
c906108c
SS
1820@item info
1821This command (abbreviated @code{i}) is for describing the state of your
cda4ce5a 1822program. For example, you can show the arguments passed to a function
c906108c
SS
1823with @code{info args}, list the registers currently in use with @code{info
1824registers}, or list the breakpoints you have set with @code{info breakpoints}.
1825You can get a complete list of the @code{info} sub-commands with
1826@w{@code{help info}}.
1827
1828@kindex set
1829@item set
5d161b24 1830You can assign the result of an expression to an environment variable with
c906108c
SS
1831@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1832@code{set prompt $}.
1833
1834@kindex show
1835@item show
5d161b24 1836In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1837@value{GDBN} itself.
1838You can change most of the things you can @code{show}, by using the
1839related command @code{set}; for example, you can control what number
1840system is used for displays with @code{set radix}, or simply inquire
1841which is currently in use with @code{show radix}.
1842
1843@kindex info set
1844To display all the settable parameters and their current
1845values, you can use @code{show} with no arguments; you may also use
1846@code{info set}. Both commands produce the same display.
1847@c FIXME: "info set" violates the rule that "info" is for state of
1848@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1849@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1850@end table
1851@c @end group
1852
6eaaf48b 1853Here are several miscellaneous @code{show} subcommands, all of which are
c906108c
SS
1854exceptional in lacking corresponding @code{set} commands:
1855
1856@table @code
1857@kindex show version
9c16f35a 1858@cindex @value{GDBN} version number
c906108c
SS
1859@item show version
1860Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1861information in @value{GDBN} bug-reports. If multiple versions of
1862@value{GDBN} are in use at your site, you may need to determine which
1863version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1864commands are introduced, and old ones may wither away. Also, many
1865system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1866variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1867The version number is the same as the one announced when you start
1868@value{GDBN}.
c906108c
SS
1869
1870@kindex show copying
09d4efe1 1871@kindex info copying
9c16f35a 1872@cindex display @value{GDBN} copyright
c906108c 1873@item show copying
09d4efe1 1874@itemx info copying
c906108c
SS
1875Display information about permission for copying @value{GDBN}.
1876
1877@kindex show warranty
09d4efe1 1878@kindex info warranty
c906108c 1879@item show warranty
09d4efe1 1880@itemx info warranty
2df3850c 1881Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1882if your version of @value{GDBN} comes with one.
2df3850c 1883
6eaaf48b
EZ
1884@kindex show configuration
1885@item show configuration
1886Display detailed information about the way @value{GDBN} was configured
1887when it was built. This displays the optional arguments passed to the
1888@file{configure} script and also configuration parameters detected
1889automatically by @command{configure}. When reporting a @value{GDBN}
1890bug (@pxref{GDB Bugs}), it is important to include this information in
1891your report.
1892
c906108c
SS
1893@end table
1894
6d2ebf8b 1895@node Running
c906108c
SS
1896@chapter Running Programs Under @value{GDBN}
1897
1898When you run a program under @value{GDBN}, you must first generate
1899debugging information when you compile it.
7a292a7a
SS
1900
1901You may start @value{GDBN} with its arguments, if any, in an environment
1902of your choice. If you are doing native debugging, you may redirect
1903your program's input and output, debug an already running process, or
1904kill a child process.
c906108c
SS
1905
1906@menu
1907* Compilation:: Compiling for debugging
1908* Starting:: Starting your program
c906108c
SS
1909* Arguments:: Your program's arguments
1910* Environment:: Your program's environment
c906108c
SS
1911
1912* Working Directory:: Your program's working directory
1913* Input/Output:: Your program's input and output
1914* Attach:: Debugging an already-running process
1915* Kill Process:: Killing the child process
c906108c 1916
6c95b8df 1917* Inferiors and Programs:: Debugging multiple inferiors and programs
c906108c 1918* Threads:: Debugging programs with multiple threads
6c95b8df 1919* Forks:: Debugging forks
5c95884b 1920* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
1921@end menu
1922
6d2ebf8b 1923@node Compilation
79a6e687 1924@section Compiling for Debugging
c906108c
SS
1925
1926In order to debug a program effectively, you need to generate
1927debugging information when you compile it. This debugging information
1928is stored in the object file; it describes the data type of each
1929variable or function and the correspondence between source line numbers
1930and addresses in the executable code.
1931
1932To request debugging information, specify the @samp{-g} option when you run
1933the compiler.
1934
514c4d71 1935Programs that are to be shipped to your customers are compiled with
edb3359d 1936optimizations, using the @samp{-O} compiler option. However, some
514c4d71
EZ
1937compilers are unable to handle the @samp{-g} and @samp{-O} options
1938together. Using those compilers, you cannot generate optimized
c906108c
SS
1939executables containing debugging information.
1940
514c4d71 1941@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1942without @samp{-O}, making it possible to debug optimized code. We
1943recommend that you @emph{always} use @samp{-g} whenever you compile a
1944program. You may think your program is correct, but there is no sense
edb3359d 1945in pushing your luck. For more information, see @ref{Optimized Code}.
c906108c
SS
1946
1947Older versions of the @sc{gnu} C compiler permitted a variant option
1948@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1949format; if your @sc{gnu} C compiler has this option, do not use it.
1950
514c4d71
EZ
1951@value{GDBN} knows about preprocessor macros and can show you their
1952expansion (@pxref{Macros}). Most compilers do not include information
1953about preprocessor macros in the debugging information if you specify
e0f8f636
TT
1954the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
1955the @sc{gnu} C compiler, provides macro information if you are using
1956the DWARF debugging format, and specify the option @option{-g3}.
1957
1958@xref{Debugging Options,,Options for Debugging Your Program or GCC,
1959gcc.info, Using the @sc{gnu} Compiler Collection (GCC)}, for more
1960information on @value{NGCC} options affecting debug information.
1961
1962You will have the best debugging experience if you use the latest
1963version of the DWARF debugging format that your compiler supports.
1964DWARF is currently the most expressive and best supported debugging
1965format in @value{GDBN}.
514c4d71 1966
c906108c 1967@need 2000
6d2ebf8b 1968@node Starting
79a6e687 1969@section Starting your Program
c906108c
SS
1970@cindex starting
1971@cindex running
1972
1973@table @code
1974@kindex run
41afff9a 1975@kindex r @r{(@code{run})}
c906108c
SS
1976@item run
1977@itemx r
7a292a7a
SS
1978Use the @code{run} command to start your program under @value{GDBN}.
1979You must first specify the program name (except on VxWorks) with an
1980argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1981@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
79a6e687 1982(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
1983
1984@end table
1985
c906108c
SS
1986If you are running your program in an execution environment that
1987supports processes, @code{run} creates an inferior process and makes
8edfe269
DJ
1988that process run your program. In some environments without processes,
1989@code{run} jumps to the start of your program. Other targets,
1990like @samp{remote}, are always running. If you get an error
1991message like this one:
1992
1993@smallexample
1994The "remote" target does not support "run".
1995Try "help target" or "continue".
1996@end smallexample
1997
1998@noindent
1999then use @code{continue} to run your program. You may need @code{load}
2000first (@pxref{load}).
c906108c
SS
2001
2002The execution of a program is affected by certain information it
2003receives from its superior. @value{GDBN} provides ways to specify this
2004information, which you must do @emph{before} starting your program. (You
2005can change it after starting your program, but such changes only affect
2006your program the next time you start it.) This information may be
2007divided into four categories:
2008
2009@table @asis
2010@item The @emph{arguments.}
2011Specify the arguments to give your program as the arguments of the
2012@code{run} command. If a shell is available on your target, the shell
2013is used to pass the arguments, so that you may use normal conventions
2014(such as wildcard expansion or variable substitution) in describing
2015the arguments.
2016In Unix systems, you can control which shell is used with the
98882a26
PA
2017@code{SHELL} environment variable. If you do not define @code{SHELL},
2018@value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2019use of any shell with the @code{set startup-with-shell} command (see
2020below for details).
c906108c
SS
2021
2022@item The @emph{environment.}
2023Your program normally inherits its environment from @value{GDBN}, but you can
2024use the @value{GDBN} commands @code{set environment} and @code{unset
2025environment} to change parts of the environment that affect
79a6e687 2026your program. @xref{Environment, ,Your Program's Environment}.
c906108c
SS
2027
2028@item The @emph{working directory.}
2029Your program inherits its working directory from @value{GDBN}. You can set
2030the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
79a6e687 2031@xref{Working Directory, ,Your Program's Working Directory}.
c906108c
SS
2032
2033@item The @emph{standard input and output.}
2034Your program normally uses the same device for standard input and
2035standard output as @value{GDBN} is using. You can redirect input and output
2036in the @code{run} command line, or you can use the @code{tty} command to
2037set a different device for your program.
79a6e687 2038@xref{Input/Output, ,Your Program's Input and Output}.
c906108c
SS
2039
2040@cindex pipes
2041@emph{Warning:} While input and output redirection work, you cannot use
2042pipes to pass the output of the program you are debugging to another
2043program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2044wrong program.
2045@end table
c906108c
SS
2046
2047When you issue the @code{run} command, your program begins to execute
79a6e687 2048immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
c906108c
SS
2049of how to arrange for your program to stop. Once your program has
2050stopped, you may call functions in your program, using the @code{print}
2051or @code{call} commands. @xref{Data, ,Examining Data}.
2052
2053If the modification time of your symbol file has changed since the last
2054time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2055table, and reads it again. When it does this, @value{GDBN} tries to retain
2056your current breakpoints.
2057
4e8b0763
JB
2058@table @code
2059@kindex start
2060@item start
2061@cindex run to main procedure
2062The name of the main procedure can vary from language to language.
2063With C or C@t{++}, the main procedure name is always @code{main}, but
2064other languages such as Ada do not require a specific name for their
2065main procedure. The debugger provides a convenient way to start the
2066execution of the program and to stop at the beginning of the main
2067procedure, depending on the language used.
2068
2069The @samp{start} command does the equivalent of setting a temporary
2070breakpoint at the beginning of the main procedure and then invoking
2071the @samp{run} command.
2072
f018e82f
EZ
2073@cindex elaboration phase
2074Some programs contain an @dfn{elaboration} phase where some startup code is
2075executed before the main procedure is called. This depends on the
2076languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
2077constructors for static and global objects are executed before
2078@code{main} is called. It is therefore possible that the debugger stops
2079before reaching the main procedure. However, the temporary breakpoint
2080will remain to halt execution.
2081
2082Specify the arguments to give to your program as arguments to the
2083@samp{start} command. These arguments will be given verbatim to the
2084underlying @samp{run} command. Note that the same arguments will be
2085reused if no argument is provided during subsequent calls to
2086@samp{start} or @samp{run}.
2087
2088It is sometimes necessary to debug the program during elaboration. In
2089these cases, using the @code{start} command would stop the execution of
2090your program too late, as the program would have already completed the
2091elaboration phase. Under these circumstances, insert breakpoints in your
2092elaboration code before running your program.
ccd213ac 2093
41ef2965 2094@anchor{set exec-wrapper}
ccd213ac
DJ
2095@kindex set exec-wrapper
2096@item set exec-wrapper @var{wrapper}
2097@itemx show exec-wrapper
2098@itemx unset exec-wrapper
2099When @samp{exec-wrapper} is set, the specified wrapper is used to
2100launch programs for debugging. @value{GDBN} starts your program
2101with a shell command of the form @kbd{exec @var{wrapper}
2102@var{program}}. Quoting is added to @var{program} and its
2103arguments, but not to @var{wrapper}, so you should add quotes if
2104appropriate for your shell. The wrapper runs until it executes
2105your program, and then @value{GDBN} takes control.
2106
2107You can use any program that eventually calls @code{execve} with
2108its arguments as a wrapper. Several standard Unix utilities do
2109this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2110with @code{exec "$@@"} will also work.
2111
2112For example, you can use @code{env} to pass an environment variable to
2113the debugged program, without setting the variable in your shell's
2114environment:
2115
2116@smallexample
2117(@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2118(@value{GDBP}) run
2119@end smallexample
2120
2121This command is available when debugging locally on most targets, excluding
2122@sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2123
98882a26
PA
2124@kindex set startup-with-shell
2125@item set startup-with-shell
2126@itemx set startup-with-shell on
2127@itemx set startup-with-shell off
2128@itemx show set startup-with-shell
2129On Unix systems, by default, if a shell is available on your target,
2130@value{GDBN}) uses it to start your program. Arguments of the
2131@code{run} command are passed to the shell, which does variable
2132substitution, expands wildcard characters and performs redirection of
2133I/O. In some circumstances, it may be useful to disable such use of a
2134shell, for example, when debugging the shell itself or diagnosing
2135startup failures such as:
2136
2137@smallexample
2138(@value{GDBP}) run
2139Starting program: ./a.out
2140During startup program terminated with signal SIGSEGV, Segmentation fault.
2141@end smallexample
2142
2143@noindent
2144which indicates the shell or the wrapper specified with
2145@samp{exec-wrapper} crashed, not your program. Most often, this is
afa332ce
PA
2146caused by something odd in your shell's non-interactive mode
2147initialization file---such as @file{.cshrc} for C-shell,
2148$@file{.zshenv} for the Z shell, or the file specified in the
2149@samp{BASH_ENV} environment variable for BASH.
98882a26 2150
6a3cb8e8
PA
2151@anchor{set auto-connect-native-target}
2152@kindex set auto-connect-native-target
2153@item set auto-connect-native-target
2154@itemx set auto-connect-native-target on
2155@itemx set auto-connect-native-target off
2156@itemx show auto-connect-native-target
2157
2158By default, if not connected to any target yet (e.g., with
2159@code{target remote}), the @code{run} command starts your program as a
2160native process under @value{GDBN}, on your local machine. If you're
2161sure you don't want to debug programs on your local machine, you can
2162tell @value{GDBN} to not connect to the native target automatically
2163with the @code{set auto-connect-native-target off} command.
2164
2165If @code{on}, which is the default, and if @value{GDBN} is not
2166connected to a target already, the @code{run} command automaticaly
2167connects to the native target, if one is available.
2168
2169If @code{off}, and if @value{GDBN} is not connected to a target
2170already, the @code{run} command fails with an error:
2171
2172@smallexample
2173(@value{GDBP}) run
2174Don't know how to run. Try "help target".
2175@end smallexample
2176
2177If @value{GDBN} is already connected to a target, @value{GDBN} always
2178uses it with the @code{run} command.
2179
2180In any case, you can explicitly connect to the native target with the
2181@code{target native} command. For example,
2182
2183@smallexample
2184(@value{GDBP}) set auto-connect-native-target off
2185(@value{GDBP}) run
2186Don't know how to run. Try "help target".
2187(@value{GDBP}) target native
2188(@value{GDBP}) run
2189Starting program: ./a.out
2190[Inferior 1 (process 10421) exited normally]
2191@end smallexample
2192
2193In case you connected explicitly to the @code{native} target,
2194@value{GDBN} remains connected even if all inferiors exit, ready for
2195the next @code{run} command. Use the @code{disconnect} command to
2196disconnect.
2197
2198Examples of other commands that likewise respect the
2199@code{auto-connect-native-target} setting: @code{attach}, @code{info
2200proc}, @code{info os}.
2201
10568435
JK
2202@kindex set disable-randomization
2203@item set disable-randomization
2204@itemx set disable-randomization on
2205This option (enabled by default in @value{GDBN}) will turn off the native
2206randomization of the virtual address space of the started program. This option
2207is useful for multiple debugging sessions to make the execution better
2208reproducible and memory addresses reusable across debugging sessions.
2209
03583c20
UW
2210This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2211On @sc{gnu}/Linux you can get the same behavior using
10568435
JK
2212
2213@smallexample
2214(@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2215@end smallexample
2216
2217@item set disable-randomization off
2218Leave the behavior of the started executable unchanged. Some bugs rear their
2219ugly heads only when the program is loaded at certain addresses. If your bug
2220disappears when you run the program under @value{GDBN}, that might be because
2221@value{GDBN} by default disables the address randomization on platforms, such
2222as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2223disable-randomization off} to try to reproduce such elusive bugs.
2224
03583c20
UW
2225On targets where it is available, virtual address space randomization
2226protects the programs against certain kinds of security attacks. In these
10568435
JK
2227cases the attacker needs to know the exact location of a concrete executable
2228code. Randomizing its location makes it impossible to inject jumps misusing
2229a code at its expected addresses.
2230
2231Prelinking shared libraries provides a startup performance advantage but it
2232makes addresses in these libraries predictable for privileged processes by
2233having just unprivileged access at the target system. Reading the shared
2234library binary gives enough information for assembling the malicious code
2235misusing it. Still even a prelinked shared library can get loaded at a new
2236random address just requiring the regular relocation process during the
2237startup. Shared libraries not already prelinked are always loaded at
2238a randomly chosen address.
2239
2240Position independent executables (PIE) contain position independent code
2241similar to the shared libraries and therefore such executables get loaded at
2242a randomly chosen address upon startup. PIE executables always load even
2243already prelinked shared libraries at a random address. You can build such
2244executable using @command{gcc -fPIE -pie}.
2245
2246Heap (malloc storage), stack and custom mmap areas are always placed randomly
2247(as long as the randomization is enabled).
2248
2249@item show disable-randomization
2250Show the current setting of the explicit disable of the native randomization of
2251the virtual address space of the started program.
2252
4e8b0763
JB
2253@end table
2254
6d2ebf8b 2255@node Arguments
79a6e687 2256@section Your Program's Arguments
c906108c
SS
2257
2258@cindex arguments (to your program)
2259The arguments to your program can be specified by the arguments of the
5d161b24 2260@code{run} command.
c906108c
SS
2261They are passed to a shell, which expands wildcard characters and
2262performs redirection of I/O, and thence to your program. Your
2263@code{SHELL} environment variable (if it exists) specifies what shell
2264@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
2265the default shell (@file{/bin/sh} on Unix).
2266
2267On non-Unix systems, the program is usually invoked directly by
2268@value{GDBN}, which emulates I/O redirection via the appropriate system
2269calls, and the wildcard characters are expanded by the startup code of
2270the program, not by the shell.
c906108c
SS
2271
2272@code{run} with no arguments uses the same arguments used by the previous
2273@code{run}, or those set by the @code{set args} command.
2274
c906108c 2275@table @code
41afff9a 2276@kindex set args
c906108c
SS
2277@item set args
2278Specify the arguments to be used the next time your program is run. If
2279@code{set args} has no arguments, @code{run} executes your program
2280with no arguments. Once you have run your program with arguments,
2281using @code{set args} before the next @code{run} is the only way to run
2282it again without arguments.
2283
2284@kindex show args
2285@item show args
2286Show the arguments to give your program when it is started.
2287@end table
2288
6d2ebf8b 2289@node Environment
79a6e687 2290@section Your Program's Environment
c906108c
SS
2291
2292@cindex environment (of your program)
2293The @dfn{environment} consists of a set of environment variables and
2294their values. Environment variables conventionally record such things as
2295your user name, your home directory, your terminal type, and your search
2296path for programs to run. Usually you set up environment variables with
2297the shell and they are inherited by all the other programs you run. When
2298debugging, it can be useful to try running your program with a modified
2299environment without having to start @value{GDBN} over again.
2300
2301@table @code
2302@kindex path
2303@item path @var{directory}
2304Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
2305(the search path for executables) that will be passed to your program.
2306The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
2307You may specify several directory names, separated by whitespace or by a
2308system-dependent separator character (@samp{:} on Unix, @samp{;} on
2309MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2310is moved to the front, so it is searched sooner.
c906108c
SS
2311
2312You can use the string @samp{$cwd} to refer to whatever is the current
2313working directory at the time @value{GDBN} searches the path. If you
2314use @samp{.} instead, it refers to the directory where you executed the
2315@code{path} command. @value{GDBN} replaces @samp{.} in the
2316@var{directory} argument (with the current path) before adding
2317@var{directory} to the search path.
2318@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2319@c document that, since repeating it would be a no-op.
2320
2321@kindex show paths
2322@item show paths
2323Display the list of search paths for executables (the @code{PATH}
2324environment variable).
2325
2326@kindex show environment
2327@item show environment @r{[}@var{varname}@r{]}
2328Print the value of environment variable @var{varname} to be given to
2329your program when it starts. If you do not supply @var{varname},
2330print the names and values of all environment variables to be given to
2331your program. You can abbreviate @code{environment} as @code{env}.
2332
2333@kindex set environment
53a5351d 2334@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c 2335Set environment variable @var{varname} to @var{value}. The value
41ef2965
PA
2336changes for your program (and the shell @value{GDBN} uses to launch
2337it), not for @value{GDBN} itself. @var{value} may be any string; the
2338values of environment variables are just strings, and any
2339interpretation is supplied by your program itself. The @var{value}
c906108c
SS
2340parameter is optional; if it is eliminated, the variable is set to a
2341null value.
2342@c "any string" here does not include leading, trailing
2343@c blanks. Gnu asks: does anyone care?
2344
2345For example, this command:
2346
474c8240 2347@smallexample
c906108c 2348set env USER = foo
474c8240 2349@end smallexample
c906108c
SS
2350
2351@noindent
d4f3574e 2352tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2353@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2354are not actually required.)
2355
41ef2965
PA
2356Note that on Unix systems, @value{GDBN} runs your program via a shell,
2357which also inherits the environment set with @code{set environment}.
2358If necessary, you can avoid that by using the @samp{env} program as a
2359wrapper instead of using @code{set environment}. @xref{set
2360exec-wrapper}, for an example doing just that.
2361
c906108c
SS
2362@kindex unset environment
2363@item unset environment @var{varname}
2364Remove variable @var{varname} from the environment to be passed to your
2365program. This is different from @samp{set env @var{varname} =};
2366@code{unset environment} removes the variable from the environment,
2367rather than assigning it an empty value.
2368@end table
2369
d4f3574e 2370@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
afa332ce
PA
2371the shell indicated by your @code{SHELL} environment variable if it
2372exists (or @code{/bin/sh} if not). If your @code{SHELL} variable
2373names a shell that runs an initialization file when started
2374non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2375for the Z shell, or the file specified in the @samp{BASH_ENV}
2376environment variable for BASH---any variables you set in that file
2377affect your program. You may wish to move setting of environment
2378variables to files that are only run when you sign on, such as
2379@file{.login} or @file{.profile}.
c906108c 2380
6d2ebf8b 2381@node Working Directory
79a6e687 2382@section Your Program's Working Directory
c906108c
SS
2383
2384@cindex working directory (of your program)
2385Each time you start your program with @code{run}, it inherits its
2386working directory from the current working directory of @value{GDBN}.
2387The @value{GDBN} working directory is initially whatever it inherited
2388from its parent process (typically the shell), but you can specify a new
2389working directory in @value{GDBN} with the @code{cd} command.
2390
2391The @value{GDBN} working directory also serves as a default for the commands
2392that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
79a6e687 2393Specify Files}.
c906108c
SS
2394
2395@table @code
2396@kindex cd
721c2651 2397@cindex change working directory
f3c8a52a
JK
2398@item cd @r{[}@var{directory}@r{]}
2399Set the @value{GDBN} working directory to @var{directory}. If not
2400given, @var{directory} uses @file{'~'}.
c906108c
SS
2401
2402@kindex pwd
2403@item pwd
2404Print the @value{GDBN} working directory.
2405@end table
2406
60bf7e09
EZ
2407It is generally impossible to find the current working directory of
2408the process being debugged (since a program can change its directory
2409during its run). If you work on a system where @value{GDBN} is
2410configured with the @file{/proc} support, you can use the @code{info
2411proc} command (@pxref{SVR4 Process Information}) to find out the
2412current working directory of the debuggee.
2413
6d2ebf8b 2414@node Input/Output
79a6e687 2415@section Your Program's Input and Output
c906108c
SS
2416
2417@cindex redirection
2418@cindex i/o
2419@cindex terminal
2420By default, the program you run under @value{GDBN} does input and output to
5d161b24 2421the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2422to its own terminal modes to interact with you, but it records the terminal
2423modes your program was using and switches back to them when you continue
2424running your program.
2425
2426@table @code
2427@kindex info terminal
2428@item info terminal
2429Displays information recorded by @value{GDBN} about the terminal modes your
2430program is using.
2431@end table
2432
2433You can redirect your program's input and/or output using shell
2434redirection with the @code{run} command. For example,
2435
474c8240 2436@smallexample
c906108c 2437run > outfile
474c8240 2438@end smallexample
c906108c
SS
2439
2440@noindent
2441starts your program, diverting its output to the file @file{outfile}.
2442
2443@kindex tty
2444@cindex controlling terminal
2445Another way to specify where your program should do input and output is
2446with the @code{tty} command. This command accepts a file name as
2447argument, and causes this file to be the default for future @code{run}
2448commands. It also resets the controlling terminal for the child
2449process, for future @code{run} commands. For example,
2450
474c8240 2451@smallexample
c906108c 2452tty /dev/ttyb
474c8240 2453@end smallexample
c906108c
SS
2454
2455@noindent
2456directs that processes started with subsequent @code{run} commands
2457default to do input and output on the terminal @file{/dev/ttyb} and have
2458that as their controlling terminal.
2459
2460An explicit redirection in @code{run} overrides the @code{tty} command's
2461effect on the input/output device, but not its effect on the controlling
2462terminal.
2463
2464When you use the @code{tty} command or redirect input in the @code{run}
2465command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2466for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2467for @code{set inferior-tty}.
2468
2469@cindex inferior tty
2470@cindex set inferior controlling terminal
2471You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2472display the name of the terminal that will be used for future runs of your
2473program.
2474
2475@table @code
2476@item set inferior-tty /dev/ttyb
2477@kindex set inferior-tty
2478Set the tty for the program being debugged to /dev/ttyb.
2479
2480@item show inferior-tty
2481@kindex show inferior-tty
2482Show the current tty for the program being debugged.
2483@end table
c906108c 2484
6d2ebf8b 2485@node Attach
79a6e687 2486@section Debugging an Already-running Process
c906108c
SS
2487@kindex attach
2488@cindex attach
2489
2490@table @code
2491@item attach @var{process-id}
2492This command attaches to a running process---one that was started
2493outside @value{GDBN}. (@code{info files} shows your active
2494targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2495find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2496or with the @samp{jobs -l} shell command.
2497
2498@code{attach} does not repeat if you press @key{RET} a second time after
2499executing the command.
2500@end table
2501
2502To use @code{attach}, your program must be running in an environment
2503which supports processes; for example, @code{attach} does not work for
2504programs on bare-board targets that lack an operating system. You must
2505also have permission to send the process a signal.
2506
2507When you use @code{attach}, the debugger finds the program running in
2508the process first by looking in the current working directory, then (if
2509the program is not found) by using the source file search path
79a6e687 2510(@pxref{Source Path, ,Specifying Source Directories}). You can also use
c906108c
SS
2511the @code{file} command to load the program. @xref{Files, ,Commands to
2512Specify Files}.
2513
2514The first thing @value{GDBN} does after arranging to debug the specified
2515process is to stop it. You can examine and modify an attached process
53a5351d
JM
2516with all the @value{GDBN} commands that are ordinarily available when
2517you start processes with @code{run}. You can insert breakpoints; you
2518can step and continue; you can modify storage. If you would rather the
2519process continue running, you may use the @code{continue} command after
c906108c
SS
2520attaching @value{GDBN} to the process.
2521
2522@table @code
2523@kindex detach
2524@item detach
2525When you have finished debugging the attached process, you can use the
2526@code{detach} command to release it from @value{GDBN} control. Detaching
2527the process continues its execution. After the @code{detach} command,
2528that process and @value{GDBN} become completely independent once more, and you
2529are ready to @code{attach} another process or start one with @code{run}.
2530@code{detach} does not repeat if you press @key{RET} again after
2531executing the command.
2532@end table
2533
159fcc13
JK
2534If you exit @value{GDBN} while you have an attached process, you detach
2535that process. If you use the @code{run} command, you kill that process.
2536By default, @value{GDBN} asks for confirmation if you try to do either of these
2537things; you can control whether or not you need to confirm by using the
2538@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
79a6e687 2539Messages}).
c906108c 2540
6d2ebf8b 2541@node Kill Process
79a6e687 2542@section Killing the Child Process
c906108c
SS
2543
2544@table @code
2545@kindex kill
2546@item kill
2547Kill the child process in which your program is running under @value{GDBN}.
2548@end table
2549
2550This command is useful if you wish to debug a core dump instead of a
2551running process. @value{GDBN} ignores any core dump file while your program
2552is running.
2553
2554On some operating systems, a program cannot be executed outside @value{GDBN}
2555while you have breakpoints set on it inside @value{GDBN}. You can use the
2556@code{kill} command in this situation to permit running your program
2557outside the debugger.
2558
2559The @code{kill} command is also useful if you wish to recompile and
2560relink your program, since on many systems it is impossible to modify an
2561executable file while it is running in a process. In this case, when you
2562next type @code{run}, @value{GDBN} notices that the file has changed, and
2563reads the symbol table again (while trying to preserve your current
2564breakpoint settings).
2565
6c95b8df
PA
2566@node Inferiors and Programs
2567@section Debugging Multiple Inferiors and Programs
b77209e0 2568
6c95b8df
PA
2569@value{GDBN} lets you run and debug multiple programs in a single
2570session. In addition, @value{GDBN} on some systems may let you run
2571several programs simultaneously (otherwise you have to exit from one
2572before starting another). In the most general case, you can have
2573multiple threads of execution in each of multiple processes, launched
2574from multiple executables.
b77209e0
PA
2575
2576@cindex inferior
2577@value{GDBN} represents the state of each program execution with an
2578object called an @dfn{inferior}. An inferior typically corresponds to
2579a process, but is more general and applies also to targets that do not
2580have processes. Inferiors may be created before a process runs, and
6c95b8df
PA
2581may be retained after a process exits. Inferiors have unique
2582identifiers that are different from process ids. Usually each
2583inferior will also have its own distinct address space, although some
2584embedded targets may have several inferiors running in different parts
2585of a single address space. Each inferior may in turn have multiple
2586threads running in it.
b77209e0 2587
6c95b8df
PA
2588To find out what inferiors exist at any moment, use @w{@code{info
2589inferiors}}:
b77209e0
PA
2590
2591@table @code
2592@kindex info inferiors
2593@item info inferiors
2594Print a list of all inferiors currently being managed by @value{GDBN}.
3a1ff0b6
PA
2595
2596@value{GDBN} displays for each inferior (in this order):
2597
2598@enumerate
2599@item
2600the inferior number assigned by @value{GDBN}
2601
2602@item
2603the target system's inferior identifier
6c95b8df
PA
2604
2605@item
2606the name of the executable the inferior is running.
2607
3a1ff0b6
PA
2608@end enumerate
2609
2610@noindent
2611An asterisk @samp{*} preceding the @value{GDBN} inferior number
2612indicates the current inferior.
2613
2614For example,
2277426b 2615@end table
3a1ff0b6
PA
2616@c end table here to get a little more width for example
2617
2618@smallexample
2619(@value{GDBP}) info inferiors
6c95b8df
PA
2620 Num Description Executable
2621 2 process 2307 hello
2622* 1 process 3401 goodbye
3a1ff0b6 2623@end smallexample
2277426b
PA
2624
2625To switch focus between inferiors, use the @code{inferior} command:
2626
2627@table @code
3a1ff0b6
PA
2628@kindex inferior @var{infno}
2629@item inferior @var{infno}
2630Make inferior number @var{infno} the current inferior. The argument
2631@var{infno} is the inferior number assigned by @value{GDBN}, as shown
2632in the first field of the @samp{info inferiors} display.
2277426b
PA
2633@end table
2634
6c95b8df
PA
2635
2636You can get multiple executables into a debugging session via the
2637@code{add-inferior} and @w{@code{clone-inferior}} commands. On some
2638systems @value{GDBN} can add inferiors to the debug session
2639automatically by following calls to @code{fork} and @code{exec}. To
2640remove inferiors from the debugging session use the
af624141 2641@w{@code{remove-inferiors}} command.
6c95b8df
PA
2642
2643@table @code
2644@kindex add-inferior
2645@item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ]
2646Adds @var{n} inferiors to be run using @var{executable} as the
2647executable. @var{n} defaults to 1. If no executable is specified,
2648the inferiors begins empty, with no program. You can still assign or
2649change the program assigned to the inferior at any time by using the
2650@code{file} command with the executable name as its argument.
2651
2652@kindex clone-inferior
2653@item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
2654Adds @var{n} inferiors ready to execute the same program as inferior
2655@var{infno}. @var{n} defaults to 1. @var{infno} defaults to the
2656number of the current inferior. This is a convenient command when you
2657want to run another instance of the inferior you are debugging.
2658
2659@smallexample
2660(@value{GDBP}) info inferiors
2661 Num Description Executable
2662* 1 process 29964 helloworld
2663(@value{GDBP}) clone-inferior
2664Added inferior 2.
26651 inferiors added.
2666(@value{GDBP}) info inferiors
2667 Num Description Executable
2668 2 <null> helloworld
2669* 1 process 29964 helloworld
2670@end smallexample
2671
2672You can now simply switch focus to inferior 2 and run it.
2673
af624141
MS
2674@kindex remove-inferiors
2675@item remove-inferiors @var{infno}@dots{}
2676Removes the inferior or inferiors @var{infno}@dots{}. It is not
2677possible to remove an inferior that is running with this command. For
2678those, use the @code{kill} or @code{detach} command first.
6c95b8df
PA
2679
2680@end table
2681
2682To quit debugging one of the running inferiors that is not the current
2683inferior, you can either detach from it by using the @w{@code{detach
2684inferior}} command (allowing it to run independently), or kill it
af624141 2685using the @w{@code{kill inferiors}} command:
2277426b
PA
2686
2687@table @code
af624141
MS
2688@kindex detach inferiors @var{infno}@dots{}
2689@item detach inferior @var{infno}@dots{}
2690Detach from the inferior or inferiors identified by @value{GDBN}
5e30da2c 2691inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
af624141
MS
2692still stays on the list of inferiors shown by @code{info inferiors},
2693but its Description will show @samp{<null>}.
2694
2695@kindex kill inferiors @var{infno}@dots{}
2696@item kill inferiors @var{infno}@dots{}
2697Kill the inferior or inferiors identified by @value{GDBN} inferior
2698number(s) @var{infno}@dots{}. Note that the inferior's entry still
2699stays on the list of inferiors shown by @code{info inferiors}, but its
2700Description will show @samp{<null>}.
2277426b
PA
2701@end table
2702
6c95b8df 2703After the successful completion of a command such as @code{detach},
af624141 2704@code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
6c95b8df
PA
2705a normal process exit, the inferior is still valid and listed with
2706@code{info inferiors}, ready to be restarted.
2707
2708
2277426b
PA
2709To be notified when inferiors are started or exit under @value{GDBN}'s
2710control use @w{@code{set print inferior-events}}:
b77209e0 2711
2277426b 2712@table @code
b77209e0
PA
2713@kindex set print inferior-events
2714@cindex print messages on inferior start and exit
2715@item set print inferior-events
2716@itemx set print inferior-events on
2717@itemx set print inferior-events off
2718The @code{set print inferior-events} command allows you to enable or
2719disable printing of messages when @value{GDBN} notices that new
2720inferiors have started or that inferiors have exited or have been
2721detached. By default, these messages will not be printed.
2722
2723@kindex show print inferior-events
2724@item show print inferior-events
2725Show whether messages will be printed when @value{GDBN} detects that
2726inferiors have started, exited or have been detached.
2727@end table
2728
6c95b8df
PA
2729Many commands will work the same with multiple programs as with a
2730single program: e.g., @code{print myglobal} will simply display the
2731value of @code{myglobal} in the current inferior.
2732
2733
2734Occasionaly, when debugging @value{GDBN} itself, it may be useful to
2735get more info about the relationship of inferiors, programs, address
2736spaces in a debug session. You can do that with the @w{@code{maint
2737info program-spaces}} command.
2738
2739@table @code
2740@kindex maint info program-spaces
2741@item maint info program-spaces
2742Print a list of all program spaces currently being managed by
2743@value{GDBN}.
2744
2745@value{GDBN} displays for each program space (in this order):
2746
2747@enumerate
2748@item
2749the program space number assigned by @value{GDBN}
2750
2751@item
2752the name of the executable loaded into the program space, with e.g.,
2753the @code{file} command.
2754
2755@end enumerate
2756
2757@noindent
2758An asterisk @samp{*} preceding the @value{GDBN} program space number
2759indicates the current program space.
2760
2761In addition, below each program space line, @value{GDBN} prints extra
2762information that isn't suitable to display in tabular form. For
2763example, the list of inferiors bound to the program space.
2764
2765@smallexample
2766(@value{GDBP}) maint info program-spaces
2767 Id Executable
2768 2 goodbye
2769 Bound inferiors: ID 1 (process 21561)
2770* 1 hello
2771@end smallexample
2772
2773Here we can see that no inferior is running the program @code{hello},
2774while @code{process 21561} is running the program @code{goodbye}. On
2775some targets, it is possible that multiple inferiors are bound to the
2776same program space. The most common example is that of debugging both
2777the parent and child processes of a @code{vfork} call. For example,
2778
2779@smallexample
2780(@value{GDBP}) maint info program-spaces
2781 Id Executable
2782* 1 vfork-test
2783 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
2784@end smallexample
2785
2786Here, both inferior 2 and inferior 1 are running in the same program
2787space as a result of inferior 1 having executed a @code{vfork} call.
2788@end table
2789
6d2ebf8b 2790@node Threads
79a6e687 2791@section Debugging Programs with Multiple Threads
c906108c
SS
2792
2793@cindex threads of execution
2794@cindex multiple threads
2795@cindex switching threads
2796In some operating systems, such as HP-UX and Solaris, a single program
2797may have more than one @dfn{thread} of execution. The precise semantics
2798of threads differ from one operating system to another, but in general
2799the threads of a single program are akin to multiple processes---except
2800that they share one address space (that is, they can all examine and
2801modify the same variables). On the other hand, each thread has its own
2802registers and execution stack, and perhaps private memory.
2803
2804@value{GDBN} provides these facilities for debugging multi-thread
2805programs:
2806
2807@itemize @bullet
2808@item automatic notification of new threads
2809@item @samp{thread @var{threadno}}, a command to switch among threads
2810@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2811@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2812a command to apply a command to a list of threads
2813@item thread-specific breakpoints
93815fbf
VP
2814@item @samp{set print thread-events}, which controls printing of
2815messages on thread start and exit.
17a37d48
PP
2816@item @samp{set libthread-db-search-path @var{path}}, which lets
2817the user specify which @code{libthread_db} to use if the default choice
2818isn't compatible with the program.
c906108c
SS
2819@end itemize
2820
c906108c
SS
2821@quotation
2822@emph{Warning:} These facilities are not yet available on every
2823@value{GDBN} configuration where the operating system supports threads.
2824If your @value{GDBN} does not support threads, these commands have no
2825effect. For example, a system without thread support shows no output
2826from @samp{info threads}, and always rejects the @code{thread} command,
2827like this:
2828
2829@smallexample
2830(@value{GDBP}) info threads
2831(@value{GDBP}) thread 1
2832Thread ID 1 not known. Use the "info threads" command to
2833see the IDs of currently known threads.
2834@end smallexample
2835@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2836@c doesn't support threads"?
2837@end quotation
c906108c
SS
2838
2839@cindex focus of debugging
2840@cindex current thread
2841The @value{GDBN} thread debugging facility allows you to observe all
2842threads while your program runs---but whenever @value{GDBN} takes
2843control, one thread in particular is always the focus of debugging.
2844This thread is called the @dfn{current thread}. Debugging commands show
2845program information from the perspective of the current thread.
2846
41afff9a 2847@cindex @code{New} @var{systag} message
c906108c
SS
2848@cindex thread identifier (system)
2849@c FIXME-implementors!! It would be more helpful if the [New...] message
2850@c included GDB's numeric thread handle, so you could just go to that
2851@c thread without first checking `info threads'.
2852Whenever @value{GDBN} detects a new thread in your program, it displays
2853the target system's identification for the thread with a message in the
2854form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2855whose form varies depending on the particular system. For example, on
8807d78b 2856@sc{gnu}/Linux, you might see
c906108c 2857
474c8240 2858@smallexample
08e796bc 2859[New Thread 0x41e02940 (LWP 25582)]
474c8240 2860@end smallexample
c906108c
SS
2861
2862@noindent
2863when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2864the @var{systag} is simply something like @samp{process 368}, with no
2865further qualifier.
2866
2867@c FIXME!! (1) Does the [New...] message appear even for the very first
2868@c thread of a program, or does it only appear for the
6ca652b0 2869@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2870@c program?
2871@c (2) *Is* there necessarily a first thread always? Or do some
2872@c multithread systems permit starting a program with multiple
5d161b24 2873@c threads ab initio?
c906108c
SS
2874
2875@cindex thread number
2876@cindex thread identifier (GDB)
2877For debugging purposes, @value{GDBN} associates its own thread
2878number---always a single integer---with each thread in your program.
2879
2880@table @code
2881@kindex info threads
60f98dde
MS
2882@item info threads @r{[}@var{id}@dots{}@r{]}
2883Display a summary of all threads currently in your program. Optional
2884argument @var{id}@dots{} is one or more thread ids separated by spaces, and
2885means to print information only about the specified thread or threads.
2886@value{GDBN} displays for each thread (in this order):
c906108c
SS
2887
2888@enumerate
09d4efe1
EZ
2889@item
2890the thread number assigned by @value{GDBN}
c906108c 2891
09d4efe1
EZ
2892@item
2893the target system's thread identifier (@var{systag})
c906108c 2894
4694da01
TT
2895@item
2896the thread's name, if one is known. A thread can either be named by
2897the user (see @code{thread name}, below), or, in some cases, by the
2898program itself.
2899
09d4efe1
EZ
2900@item
2901the current stack frame summary for that thread
c906108c
SS
2902@end enumerate
2903
2904@noindent
2905An asterisk @samp{*} to the left of the @value{GDBN} thread number
2906indicates the current thread.
2907
5d161b24 2908For example,
c906108c
SS
2909@end table
2910@c end table here to get a little more width for example
2911
2912@smallexample
2913(@value{GDBP}) info threads
13fd8b81
TT
2914 Id Target Id Frame
2915 3 process 35 thread 27 0x34e5 in sigpause ()
2916 2 process 35 thread 23 0x34e5 in sigpause ()
2917* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
c906108c
SS
2918 at threadtest.c:68
2919@end smallexample
53a5351d 2920
c45da7e6
EZ
2921On Solaris, you can display more information about user threads with a
2922Solaris-specific command:
2923
2924@table @code
2925@item maint info sol-threads
2926@kindex maint info sol-threads
2927@cindex thread info (Solaris)
2928Display info on Solaris user threads.
2929@end table
2930
c906108c
SS
2931@table @code
2932@kindex thread @var{threadno}
2933@item thread @var{threadno}
2934Make thread number @var{threadno} the current thread. The command
2935argument @var{threadno} is the internal @value{GDBN} thread number, as
2936shown in the first field of the @samp{info threads} display.
2937@value{GDBN} responds by displaying the system identifier of the thread
2938you selected, and its current stack frame summary:
2939
2940@smallexample
c906108c 2941(@value{GDBP}) thread 2
13fd8b81
TT
2942[Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
2943#0 some_function (ignore=0x0) at example.c:8
29448 printf ("hello\n");
c906108c
SS
2945@end smallexample
2946
2947@noindent
2948As with the @samp{[New @dots{}]} message, the form of the text after
2949@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2950threads.
c906108c 2951
6aed2dbc
SS
2952@vindex $_thread@r{, convenience variable}
2953The debugger convenience variable @samp{$_thread} contains the number
2954of the current thread. You may find this useful in writing breakpoint
2955conditional expressions, command scripts, and so forth. See
2956@xref{Convenience Vars,, Convenience Variables}, for general
2957information on convenience variables.
2958
9c16f35a 2959@kindex thread apply
638ac427 2960@cindex apply command to several threads
13fd8b81 2961@item thread apply [@var{threadno} | all] @var{command}
839c27b7
EZ
2962The @code{thread apply} command allows you to apply the named
2963@var{command} to one or more threads. Specify the numbers of the
2964threads that you want affected with the command argument
2965@var{threadno}. It can be a single thread number, one of the numbers
2966shown in the first field of the @samp{info threads} display; or it
2967could be a range of thread numbers, as in @code{2-4}. To apply a
2968command to all threads, type @kbd{thread apply all @var{command}}.
93815fbf 2969
4694da01
TT
2970@kindex thread name
2971@cindex name a thread
2972@item thread name [@var{name}]
2973This command assigns a name to the current thread. If no argument is
2974given, any existing user-specified name is removed. The thread name
2975appears in the @samp{info threads} display.
2976
2977On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
2978determine the name of the thread as given by the OS. On these
2979systems, a name specified with @samp{thread name} will override the
2980system-give name, and removing the user-specified name will cause
2981@value{GDBN} to once again display the system-specified name.
2982
60f98dde
MS
2983@kindex thread find
2984@cindex search for a thread
2985@item thread find [@var{regexp}]
2986Search for and display thread ids whose name or @var{systag}
2987matches the supplied regular expression.
2988
2989As well as being the complement to the @samp{thread name} command,
2990this command also allows you to identify a thread by its target
2991@var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
2992is the LWP id.
2993
2994@smallexample
2995(@value{GDBN}) thread find 26688
2996Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
2997(@value{GDBN}) info thread 4
2998 Id Target Id Frame
2999 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3000@end smallexample
3001
93815fbf
VP
3002@kindex set print thread-events
3003@cindex print messages on thread start and exit
3004@item set print thread-events
3005@itemx set print thread-events on
3006@itemx set print thread-events off
3007The @code{set print thread-events} command allows you to enable or
3008disable printing of messages when @value{GDBN} notices that new threads have
3009started or that threads have exited. By default, these messages will
3010be printed if detection of these events is supported by the target.
3011Note that these messages cannot be disabled on all targets.
3012
3013@kindex show print thread-events
3014@item show print thread-events
3015Show whether messages will be printed when @value{GDBN} detects that threads
3016have started and exited.
c906108c
SS
3017@end table
3018
79a6e687 3019@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
c906108c
SS
3020more information about how @value{GDBN} behaves when you stop and start
3021programs with multiple threads.
3022
79a6e687 3023@xref{Set Watchpoints,,Setting Watchpoints}, for information about
c906108c 3024watchpoints in programs with multiple threads.
c906108c 3025
bf88dd68 3026@anchor{set libthread-db-search-path}
17a37d48
PP
3027@table @code
3028@kindex set libthread-db-search-path
3029@cindex search path for @code{libthread_db}
3030@item set libthread-db-search-path @r{[}@var{path}@r{]}
3031If this variable is set, @var{path} is a colon-separated list of
3032directories @value{GDBN} will use to search for @code{libthread_db}.
3033If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
98a5dd13 3034its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
7e0396aa
DE
3035Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3036macro.
17a37d48
PP
3037
3038On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3039@code{libthread_db} library to obtain information about threads in the
3040inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
bf88dd68
JK
3041to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3042specific thread debugging library loading is enabled
3043by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3044
3045A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3046refers to the default system directories that are
bf88dd68
JK
3047normally searched for loading shared libraries. The @samp{$sdir} entry
3048is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3049(@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3050
3051A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3052refers to the directory from which @code{libpthread}
3053was loaded in the inferior process.
17a37d48
PP
3054
3055For any @code{libthread_db} library @value{GDBN} finds in above directories,
3056@value{GDBN} attempts to initialize it with the current inferior process.
3057If this initialization fails (which could happen because of a version
3058mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3059will unload @code{libthread_db}, and continue with the next directory.
3060If none of @code{libthread_db} libraries initialize successfully,
3061@value{GDBN} will issue a warning and thread debugging will be disabled.
3062
3063Setting @code{libthread-db-search-path} is currently implemented
3064only on some platforms.
3065
3066@kindex show libthread-db-search-path
3067@item show libthread-db-search-path
3068Display current libthread_db search path.
02d868e8
PP
3069
3070@kindex set debug libthread-db
3071@kindex show debug libthread-db
3072@cindex debugging @code{libthread_db}
3073@item set debug libthread-db
3074@itemx show debug libthread-db
3075Turns on or off display of @code{libthread_db}-related events.
3076Use @code{1} to enable, @code{0} to disable.
17a37d48
PP
3077@end table
3078
6c95b8df
PA
3079@node Forks
3080@section Debugging Forks
c906108c
SS
3081
3082@cindex fork, debugging programs which call
3083@cindex multiple processes
3084@cindex processes, multiple
53a5351d
JM
3085On most systems, @value{GDBN} has no special support for debugging
3086programs which create additional processes using the @code{fork}
3087function. When a program forks, @value{GDBN} will continue to debug the
3088parent process and the child process will run unimpeded. If you have
3089set a breakpoint in any code which the child then executes, the child
3090will get a @code{SIGTRAP} signal which (unless it catches the signal)
3091will cause it to terminate.
c906108c
SS
3092
3093However, if you want to debug the child process there is a workaround
3094which isn't too painful. Put a call to @code{sleep} in the code which
3095the child process executes after the fork. It may be useful to sleep
3096only if a certain environment variable is set, or a certain file exists,
3097so that the delay need not occur when you don't want to run @value{GDBN}
3098on the child. While the child is sleeping, use the @code{ps} program to
3099get its process ID. Then tell @value{GDBN} (a new invocation of
3100@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 3101the child process (@pxref{Attach}). From that point on you can debug
c906108c 3102the child process just like any other process which you attached to.
c906108c 3103
b51970ac
DJ
3104On some systems, @value{GDBN} provides support for debugging programs that
3105create additional processes using the @code{fork} or @code{vfork} functions.
3106Currently, the only platforms with this feature are HP-UX (11.x and later
a6b151f1 3107only?) and @sc{gnu}/Linux (kernel version 2.5.60 and later).
c906108c
SS
3108
3109By default, when a program forks, @value{GDBN} will continue to debug
3110the parent process and the child process will run unimpeded.
3111
3112If you want to follow the child process instead of the parent process,
3113use the command @w{@code{set follow-fork-mode}}.
3114
3115@table @code
3116@kindex set follow-fork-mode
3117@item set follow-fork-mode @var{mode}
3118Set the debugger response to a program call of @code{fork} or
3119@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 3120process. The @var{mode} argument can be:
c906108c
SS
3121
3122@table @code
3123@item parent
3124The original process is debugged after a fork. The child process runs
2df3850c 3125unimpeded. This is the default.
c906108c
SS
3126
3127@item child
3128The new process is debugged after a fork. The parent process runs
3129unimpeded.
3130
c906108c
SS
3131@end table
3132
9c16f35a 3133@kindex show follow-fork-mode
c906108c 3134@item show follow-fork-mode
2df3850c 3135Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
3136@end table
3137
5c95884b
MS
3138@cindex debugging multiple processes
3139On Linux, if you want to debug both the parent and child processes, use the
3140command @w{@code{set detach-on-fork}}.
3141
3142@table @code
3143@kindex set detach-on-fork
3144@item set detach-on-fork @var{mode}
3145Tells gdb whether to detach one of the processes after a fork, or
3146retain debugger control over them both.
3147
3148@table @code
3149@item on
3150The child process (or parent process, depending on the value of
3151@code{follow-fork-mode}) will be detached and allowed to run
3152independently. This is the default.
3153
3154@item off
3155Both processes will be held under the control of @value{GDBN}.
3156One process (child or parent, depending on the value of
3157@code{follow-fork-mode}) is debugged as usual, while the other
3158is held suspended.
3159
3160@end table
3161
11310833
NR
3162@kindex show detach-on-fork
3163@item show detach-on-fork
3164Show whether detach-on-fork mode is on/off.
5c95884b
MS
3165@end table
3166
2277426b
PA
3167If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3168will retain control of all forked processes (including nested forks).
3169You can list the forked processes under the control of @value{GDBN} by
3170using the @w{@code{info inferiors}} command, and switch from one fork
6c95b8df
PA
3171to another by using the @code{inferior} command (@pxref{Inferiors and
3172Programs, ,Debugging Multiple Inferiors and Programs}).
5c95884b
MS
3173
3174To quit debugging one of the forked processes, you can either detach
af624141
MS
3175from it by using the @w{@code{detach inferiors}} command (allowing it
3176to run independently), or kill it using the @w{@code{kill inferiors}}
6c95b8df
PA
3177command. @xref{Inferiors and Programs, ,Debugging Multiple Inferiors
3178and Programs}.
5c95884b 3179
c906108c
SS
3180If you ask to debug a child process and a @code{vfork} is followed by an
3181@code{exec}, @value{GDBN} executes the new target up to the first
3182breakpoint in the new target. If you have a breakpoint set on
3183@code{main} in your original program, the breakpoint will also be set on
3184the child process's @code{main}.
3185
2277426b
PA
3186On some systems, when a child process is spawned by @code{vfork}, you
3187cannot debug the child or parent until an @code{exec} call completes.
c906108c
SS
3188
3189If you issue a @code{run} command to @value{GDBN} after an @code{exec}
6c95b8df
PA
3190call executes, the new target restarts. To restart the parent
3191process, use the @code{file} command with the parent executable name
3192as its argument. By default, after an @code{exec} call executes,
3193@value{GDBN} discards the symbols of the previous executable image.
3194You can change this behaviour with the @w{@code{set follow-exec-mode}}
3195command.
3196
3197@table @code
3198@kindex set follow-exec-mode
3199@item set follow-exec-mode @var{mode}
3200
3201Set debugger response to a program call of @code{exec}. An
3202@code{exec} call replaces the program image of a process.
3203
3204@code{follow-exec-mode} can be:
3205
3206@table @code
3207@item new
3208@value{GDBN} creates a new inferior and rebinds the process to this
3209new inferior. The program the process was running before the
3210@code{exec} call can be restarted afterwards by restarting the
3211original inferior.
3212
3213For example:
3214
3215@smallexample
3216(@value{GDBP}) info inferiors
3217(gdb) info inferior
3218 Id Description Executable
3219* 1 <null> prog1
3220(@value{GDBP}) run
3221process 12020 is executing new program: prog2
3222Program exited normally.
3223(@value{GDBP}) info inferiors
3224 Id Description Executable
3225* 2 <null> prog2
3226 1 <null> prog1
3227@end smallexample
3228
3229@item same
3230@value{GDBN} keeps the process bound to the same inferior. The new
3231executable image replaces the previous executable loaded in the
3232inferior. Restarting the inferior after the @code{exec} call, with
3233e.g., the @code{run} command, restarts the executable the process was
3234running after the @code{exec} call. This is the default mode.
3235
3236For example:
3237
3238@smallexample
3239(@value{GDBP}) info inferiors
3240 Id Description Executable
3241* 1 <null> prog1
3242(@value{GDBP}) run
3243process 12020 is executing new program: prog2
3244Program exited normally.
3245(@value{GDBP}) info inferiors
3246 Id Description Executable
3247* 1 <null> prog2
3248@end smallexample
3249
3250@end table
3251@end table
c906108c
SS
3252
3253You can use the @code{catch} command to make @value{GDBN} stop whenever
3254a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
79a6e687 3255Catchpoints, ,Setting Catchpoints}.
c906108c 3256
5c95884b 3257@node Checkpoint/Restart
79a6e687 3258@section Setting a @emph{Bookmark} to Return to Later
5c95884b
MS
3259
3260@cindex checkpoint
3261@cindex restart
3262@cindex bookmark
3263@cindex snapshot of a process
3264@cindex rewind program state
3265
3266On certain operating systems@footnote{Currently, only
3267@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3268program's state, called a @dfn{checkpoint}, and come back to it
3269later.
3270
3271Returning to a checkpoint effectively undoes everything that has
3272happened in the program since the @code{checkpoint} was saved. This
3273includes changes in memory, registers, and even (within some limits)
3274system state. Effectively, it is like going back in time to the
3275moment when the checkpoint was saved.
3276
3277Thus, if you're stepping thru a program and you think you're
3278getting close to the point where things go wrong, you can save
3279a checkpoint. Then, if you accidentally go too far and miss
3280the critical statement, instead of having to restart your program
3281from the beginning, you can just go back to the checkpoint and
3282start again from there.
3283
3284This can be especially useful if it takes a lot of time or
3285steps to reach the point where you think the bug occurs.
3286
3287To use the @code{checkpoint}/@code{restart} method of debugging:
3288
3289@table @code
3290@kindex checkpoint
3291@item checkpoint
3292Save a snapshot of the debugged program's current execution state.
3293The @code{checkpoint} command takes no arguments, but each checkpoint
3294is assigned a small integer id, similar to a breakpoint id.
3295
3296@kindex info checkpoints
3297@item info checkpoints
3298List the checkpoints that have been saved in the current debugging
3299session. For each checkpoint, the following information will be
3300listed:
3301
3302@table @code
3303@item Checkpoint ID
3304@item Process ID
3305@item Code Address
3306@item Source line, or label
3307@end table
3308
3309@kindex restart @var{checkpoint-id}
3310@item restart @var{checkpoint-id}
3311Restore the program state that was saved as checkpoint number
3312@var{checkpoint-id}. All program variables, registers, stack frames
3313etc.@: will be returned to the values that they had when the checkpoint
3314was saved. In essence, gdb will ``wind back the clock'' to the point
3315in time when the checkpoint was saved.
3316
3317Note that breakpoints, @value{GDBN} variables, command history etc.
3318are not affected by restoring a checkpoint. In general, a checkpoint
3319only restores things that reside in the program being debugged, not in
3320the debugger.
3321
b8db102d
MS
3322@kindex delete checkpoint @var{checkpoint-id}
3323@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
3324Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
3325
3326@end table
3327
3328Returning to a previously saved checkpoint will restore the user state
3329of the program being debugged, plus a significant subset of the system
3330(OS) state, including file pointers. It won't ``un-write'' data from
3331a file, but it will rewind the file pointer to the previous location,
3332so that the previously written data can be overwritten. For files
3333opened in read mode, the pointer will also be restored so that the
3334previously read data can be read again.
3335
3336Of course, characters that have been sent to a printer (or other
3337external device) cannot be ``snatched back'', and characters received
3338from eg.@: a serial device can be removed from internal program buffers,
3339but they cannot be ``pushed back'' into the serial pipeline, ready to
3340be received again. Similarly, the actual contents of files that have
3341been changed cannot be restored (at this time).
3342
3343However, within those constraints, you actually can ``rewind'' your
3344program to a previously saved point in time, and begin debugging it
3345again --- and you can change the course of events so as to debug a
3346different execution path this time.
3347
3348@cindex checkpoints and process id
3349Finally, there is one bit of internal program state that will be
3350different when you return to a checkpoint --- the program's process
3351id. Each checkpoint will have a unique process id (or @var{pid}),
3352and each will be different from the program's original @var{pid}.
3353If your program has saved a local copy of its process id, this could
3354potentially pose a problem.
3355
79a6e687 3356@subsection A Non-obvious Benefit of Using Checkpoints
5c95884b
MS
3357
3358On some systems such as @sc{gnu}/Linux, address space randomization
3359is performed on new processes for security reasons. This makes it
3360difficult or impossible to set a breakpoint, or watchpoint, on an
3361absolute address if you have to restart the program, since the
3362absolute location of a symbol will change from one execution to the
3363next.
3364
3365A checkpoint, however, is an @emph{identical} copy of a process.
3366Therefore if you create a checkpoint at (eg.@:) the start of main,
3367and simply return to that checkpoint instead of restarting the
3368process, you can avoid the effects of address randomization and
3369your symbols will all stay in the same place.
3370
6d2ebf8b 3371@node Stopping
c906108c
SS
3372@chapter Stopping and Continuing
3373
3374The principal purposes of using a debugger are so that you can stop your
3375program before it terminates; or so that, if your program runs into
3376trouble, you can investigate and find out why.
3377
7a292a7a
SS
3378Inside @value{GDBN}, your program may stop for any of several reasons,
3379such as a signal, a breakpoint, or reaching a new line after a
3380@value{GDBN} command such as @code{step}. You may then examine and
3381change variables, set new breakpoints or remove old ones, and then
3382continue execution. Usually, the messages shown by @value{GDBN} provide
3383ample explanation of the status of your program---but you can also
3384explicitly request this information at any time.
c906108c
SS
3385
3386@table @code
3387@kindex info program
3388@item info program
3389Display information about the status of your program: whether it is
7a292a7a 3390running or not, what process it is, and why it stopped.
c906108c
SS
3391@end table
3392
3393@menu
3394* Breakpoints:: Breakpoints, watchpoints, and catchpoints
3395* Continuing and Stepping:: Resuming execution
aad1c02c
TT
3396* Skipping Over Functions and Files::
3397 Skipping over functions and files
c906108c 3398* Signals:: Signals
c906108c 3399* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
3400@end menu
3401
6d2ebf8b 3402@node Breakpoints
79a6e687 3403@section Breakpoints, Watchpoints, and Catchpoints
c906108c
SS
3404
3405@cindex breakpoints
3406A @dfn{breakpoint} makes your program stop whenever a certain point in
3407the program is reached. For each breakpoint, you can add conditions to
3408control in finer detail whether your program stops. You can set
3409breakpoints with the @code{break} command and its variants (@pxref{Set
79a6e687 3410Breaks, ,Setting Breakpoints}), to specify the place where your program
c906108c
SS
3411should stop by line number, function name or exact address in the
3412program.
3413
09d4efe1
EZ
3414On some systems, you can set breakpoints in shared libraries before
3415the executable is run. There is a minor limitation on HP-UX systems:
3416you must wait until the executable is run in order to set breakpoints
3417in shared library routines that are not called directly by the program
3418(for example, routines that are arguments in a @code{pthread_create}
3419call).
c906108c
SS
3420
3421@cindex watchpoints
fd60e0df 3422@cindex data breakpoints
c906108c
SS
3423@cindex memory tracing
3424@cindex breakpoint on memory address
3425@cindex breakpoint on variable modification
3426A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 3427when the value of an expression changes. The expression may be a value
0ced0c34 3428of a variable, or it could involve values of one or more variables
fd60e0df
EZ
3429combined by operators, such as @samp{a + b}. This is sometimes called
3430@dfn{data breakpoints}. You must use a different command to set
79a6e687 3431watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
fd60e0df
EZ
3432from that, you can manage a watchpoint like any other breakpoint: you
3433enable, disable, and delete both breakpoints and watchpoints using the
3434same commands.
c906108c
SS
3435
3436You can arrange to have values from your program displayed automatically
3437whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
79a6e687 3438Automatic Display}.
c906108c
SS
3439
3440@cindex catchpoints
3441@cindex breakpoint on events
3442A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 3443when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
3444exception or the loading of a library. As with watchpoints, you use a
3445different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
79a6e687 3446Catchpoints}), but aside from that, you can manage a catchpoint like any
c906108c 3447other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 3448@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
3449
3450@cindex breakpoint numbers
3451@cindex numbers for breakpoints
3452@value{GDBN} assigns a number to each breakpoint, watchpoint, or
3453catchpoint when you create it; these numbers are successive integers
3454starting with one. In many of the commands for controlling various
3455features of breakpoints you use the breakpoint number to say which
3456breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
3457@dfn{disabled}; if disabled, it has no effect on your program until you
3458enable it again.
3459
c5394b80
JM
3460@cindex breakpoint ranges
3461@cindex ranges of breakpoints
3462Some @value{GDBN} commands accept a range of breakpoints on which to
3463operate. A breakpoint range is either a single breakpoint number, like
3464@samp{5}, or two such numbers, in increasing order, separated by a
3465hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
d52fb0e9 3466all breakpoints in that range are operated on.
c5394b80 3467
c906108c
SS
3468@menu
3469* Set Breaks:: Setting breakpoints
3470* Set Watchpoints:: Setting watchpoints
3471* Set Catchpoints:: Setting catchpoints
3472* Delete Breaks:: Deleting breakpoints
3473* Disabling:: Disabling breakpoints
3474* Conditions:: Break conditions
3475* Break Commands:: Breakpoint command lists
e7e0cddf 3476* Dynamic Printf:: Dynamic printf
6149aea9 3477* Save Breakpoints:: How to save breakpoints in a file
62e5f89c 3478* Static Probe Points:: Listing static probe points
d4f3574e 3479* Error in Breakpoints:: ``Cannot insert breakpoints''
79a6e687 3480* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
c906108c
SS
3481@end menu
3482
6d2ebf8b 3483@node Set Breaks
79a6e687 3484@subsection Setting Breakpoints
c906108c 3485
5d161b24 3486@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
3487@c consider in particular declaration with/without initialization.
3488@c
3489@c FIXME 2 is there stuff on this already? break at fun start, already init?
3490
3491@kindex break
41afff9a
EZ
3492@kindex b @r{(@code{break})}
3493@vindex $bpnum@r{, convenience variable}
c906108c
SS
3494@cindex latest breakpoint
3495Breakpoints are set with the @code{break} command (abbreviated
5d161b24 3496@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 3497number of the breakpoint you've set most recently; see @ref{Convenience
79a6e687 3498Vars,, Convenience Variables}, for a discussion of what you can do with
c906108c
SS
3499convenience variables.
3500
c906108c 3501@table @code
2a25a5ba
EZ
3502@item break @var{location}
3503Set a breakpoint at the given @var{location}, which can specify a
3504function name, a line number, or an address of an instruction.
3505(@xref{Specify Location}, for a list of all the possible ways to
3506specify a @var{location}.) The breakpoint will stop your program just
3507before it executes any of the code in the specified @var{location}.
3508
c906108c 3509When using source languages that permit overloading of symbols, such as
2a25a5ba 3510C@t{++}, a function name may refer to more than one possible place to break.
6ba66d6a
JB
3511@xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
3512that situation.
c906108c 3513
45ac276d 3514It is also possible to insert a breakpoint that will stop the program
2c88c651
JB
3515only if a specific thread (@pxref{Thread-Specific Breakpoints})
3516or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
45ac276d 3517
c906108c
SS
3518@item break
3519When called without any arguments, @code{break} sets a breakpoint at
3520the next instruction to be executed in the selected stack frame
3521(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
3522innermost, this makes your program stop as soon as control
3523returns to that frame. This is similar to the effect of a
3524@code{finish} command in the frame inside the selected frame---except
3525that @code{finish} does not leave an active breakpoint. If you use
3526@code{break} without an argument in the innermost frame, @value{GDBN} stops
3527the next time it reaches the current location; this may be useful
3528inside loops.
3529
3530@value{GDBN} normally ignores breakpoints when it resumes execution, until at
3531least one instruction has been executed. If it did not do this, you
3532would be unable to proceed past a breakpoint without first disabling the
3533breakpoint. This rule applies whether or not the breakpoint already
3534existed when your program stopped.
3535
3536@item break @dots{} if @var{cond}
3537Set a breakpoint with condition @var{cond}; evaluate the expression
3538@var{cond} each time the breakpoint is reached, and stop only if the
3539value is nonzero---that is, if @var{cond} evaluates as true.
3540@samp{@dots{}} stands for one of the possible arguments described
3541above (or no argument) specifying where to break. @xref{Conditions,
79a6e687 3542,Break Conditions}, for more information on breakpoint conditions.
c906108c
SS
3543
3544@kindex tbreak
3545@item tbreak @var{args}
3546Set a breakpoint enabled only for one stop. @var{args} are the
3547same as for the @code{break} command, and the breakpoint is set in the same
3548way, but the breakpoint is automatically deleted after the first time your
79a6e687 3549program stops there. @xref{Disabling, ,Disabling Breakpoints}.
c906108c 3550
c906108c 3551@kindex hbreak
ba04e063 3552@cindex hardware breakpoints
c906108c 3553@item hbreak @var{args}
d4f3574e
SS
3554Set a hardware-assisted breakpoint. @var{args} are the same as for the
3555@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
3556breakpoint requires hardware support and some target hardware may not
3557have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
3558debugging, so you can set a breakpoint at an instruction without
3559changing the instruction. This can be used with the new trap-generation
09d4efe1 3560provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
3561will generate traps when a program accesses some data or instruction
3562address that is assigned to the debug registers. However the hardware
3563breakpoint registers can take a limited number of breakpoints. For
3564example, on the DSU, only two data breakpoints can be set at a time, and
3565@value{GDBN} will reject this command if more than two are used. Delete
3566or disable unused hardware breakpoints before setting new ones
79a6e687
BW
3567(@pxref{Disabling, ,Disabling Breakpoints}).
3568@xref{Conditions, ,Break Conditions}.
9c16f35a
EZ
3569For remote targets, you can restrict the number of hardware
3570breakpoints @value{GDBN} will use, see @ref{set remote
3571hardware-breakpoint-limit}.
501eef12 3572
c906108c
SS
3573@kindex thbreak
3574@item thbreak @var{args}
3575Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
3576are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 3577the same way. However, like the @code{tbreak} command,
c906108c
SS
3578the breakpoint is automatically deleted after the
3579first time your program stops there. Also, like the @code{hbreak}
5d161b24 3580command, the breakpoint requires hardware support and some target hardware
79a6e687
BW
3581may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
3582See also @ref{Conditions, ,Break Conditions}.
c906108c
SS
3583
3584@kindex rbreak
3585@cindex regular expression
8bd10a10 3586@cindex breakpoints at functions matching a regexp
c45da7e6 3587@cindex set breakpoints in many functions
c906108c 3588@item rbreak @var{regex}
c906108c 3589Set breakpoints on all functions matching the regular expression
11cf8741
JM
3590@var{regex}. This command sets an unconditional breakpoint on all
3591matches, printing a list of all breakpoints it set. Once these
3592breakpoints are set, they are treated just like the breakpoints set with
3593the @code{break} command. You can delete them, disable them, or make
3594them conditional the same way as any other breakpoint.
3595
3596The syntax of the regular expression is the standard one used with tools
3597like @file{grep}. Note that this is different from the syntax used by
3598shells, so for instance @code{foo*} matches all functions that include
3599an @code{fo} followed by zero or more @code{o}s. There is an implicit
3600@code{.*} leading and trailing the regular expression you supply, so to
3601match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 3602
f7dc1244 3603@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 3604When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
3605breakpoints on overloaded functions that are not members of any special
3606classes.
c906108c 3607
f7dc1244
EZ
3608@cindex set breakpoints on all functions
3609The @code{rbreak} command can be used to set breakpoints in
3610@strong{all} the functions in a program, like this:
3611
3612@smallexample
3613(@value{GDBP}) rbreak .
3614@end smallexample
3615
8bd10a10
CM
3616@item rbreak @var{file}:@var{regex}
3617If @code{rbreak} is called with a filename qualification, it limits
3618the search for functions matching the given regular expression to the
3619specified @var{file}. This can be used, for example, to set breakpoints on
3620every function in a given file:
3621
3622@smallexample
3623(@value{GDBP}) rbreak file.c:.
3624@end smallexample
3625
3626The colon separating the filename qualifier from the regex may
3627optionally be surrounded by spaces.
3628
c906108c
SS
3629@kindex info breakpoints
3630@cindex @code{$_} and @code{info breakpoints}
e5a67952
MS
3631@item info breakpoints @r{[}@var{n}@dots{}@r{]}
3632@itemx info break @r{[}@var{n}@dots{}@r{]}
c906108c 3633Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734 3634not deleted. Optional argument @var{n} means print information only
e5a67952
MS
3635about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
3636For each breakpoint, following columns are printed:
c906108c
SS
3637
3638@table @emph
3639@item Breakpoint Numbers
3640@item Type
3641Breakpoint, watchpoint, or catchpoint.
3642@item Disposition
3643Whether the breakpoint is marked to be disabled or deleted when hit.
3644@item Enabled or Disabled
3645Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
b3db7447 3646that are not enabled.
c906108c 3647@item Address
fe6fbf8b 3648Where the breakpoint is in your program, as a memory address. For a
b3db7447
NR
3649pending breakpoint whose address is not yet known, this field will
3650contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
3651library that has the symbol or line referred by breakpoint is loaded.
3652See below for details. A breakpoint with several locations will
3b784c4f 3653have @samp{<MULTIPLE>} in this field---see below for details.
c906108c
SS
3654@item What
3655Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
3656line number. For a pending breakpoint, the original string passed to
3657the breakpoint command will be listed as it cannot be resolved until
3658the appropriate shared library is loaded in the future.
c906108c
SS
3659@end table
3660
3661@noindent
83364271
LM
3662If a breakpoint is conditional, there are two evaluation modes: ``host'' and
3663``target''. If mode is ``host'', breakpoint condition evaluation is done by
3664@value{GDBN} on the host's side. If it is ``target'', then the condition
3665is evaluated by the target. The @code{info break} command shows
3666the condition on the line following the affected breakpoint, together with
3667its condition evaluation mode in between parentheses.
3668
3669Breakpoint commands, if any, are listed after that. A pending breakpoint is
3670allowed to have a condition specified for it. The condition is not parsed for
3671validity until a shared library is loaded that allows the pending
3672breakpoint to resolve to a valid location.
c906108c
SS
3673
3674@noindent
3675@code{info break} with a breakpoint
3676number @var{n} as argument lists only that breakpoint. The
3677convenience variable @code{$_} and the default examining-address for
3678the @code{x} command are set to the address of the last breakpoint
79a6e687 3679listed (@pxref{Memory, ,Examining Memory}).
c906108c
SS
3680
3681@noindent
3682@code{info break} displays a count of the number of times the breakpoint
3683has been hit. This is especially useful in conjunction with the
3684@code{ignore} command. You can ignore a large number of breakpoint
3685hits, look at the breakpoint info to see how many times the breakpoint
3686was hit, and then run again, ignoring one less than that number. This
3687will get you quickly to the last hit of that breakpoint.
816338b5
SS
3688
3689@noindent
3690For a breakpoints with an enable count (xref) greater than 1,
3691@code{info break} also displays that count.
3692
c906108c
SS
3693@end table
3694
3695@value{GDBN} allows you to set any number of breakpoints at the same place in
3696your program. There is nothing silly or meaningless about this. When
3697the breakpoints are conditional, this is even useful
79a6e687 3698(@pxref{Conditions, ,Break Conditions}).
c906108c 3699
2e9132cc
EZ
3700@cindex multiple locations, breakpoints
3701@cindex breakpoints, multiple locations
fcda367b 3702It is possible that a breakpoint corresponds to several locations
fe6fbf8b
VP
3703in your program. Examples of this situation are:
3704
3705@itemize @bullet
f8eba3c6
TT
3706@item
3707Multiple functions in the program may have the same name.
3708
fe6fbf8b
VP
3709@item
3710For a C@t{++} constructor, the @value{NGCC} compiler generates several
3711instances of the function body, used in different cases.
3712
3713@item
3714For a C@t{++} template function, a given line in the function can
3715correspond to any number of instantiations.
3716
3717@item
3718For an inlined function, a given source line can correspond to
3719several places where that function is inlined.
fe6fbf8b
VP
3720@end itemize
3721
3722In all those cases, @value{GDBN} will insert a breakpoint at all
f8eba3c6 3723the relevant locations.
fe6fbf8b 3724
3b784c4f
EZ
3725A breakpoint with multiple locations is displayed in the breakpoint
3726table using several rows---one header row, followed by one row for
3727each breakpoint location. The header row has @samp{<MULTIPLE>} in the
3728address column. The rows for individual locations contain the actual
3729addresses for locations, and show the functions to which those
3730locations belong. The number column for a location is of the form
fe6fbf8b
VP
3731@var{breakpoint-number}.@var{location-number}.
3732
3733For example:
3b784c4f 3734
fe6fbf8b
VP
3735@smallexample
3736Num Type Disp Enb Address What
37371 breakpoint keep y <MULTIPLE>
3738 stop only if i==1
3739 breakpoint already hit 1 time
37401.1 y 0x080486a2 in void foo<int>() at t.cc:8
37411.2 y 0x080486ca in void foo<double>() at t.cc:8
3742@end smallexample
3743
3744Each location can be individually enabled or disabled by passing
3745@var{breakpoint-number}.@var{location-number} as argument to the
3b784c4f
EZ
3746@code{enable} and @code{disable} commands. Note that you cannot
3747delete the individual locations from the list, you can only delete the
16bfc218 3748entire list of locations that belong to their parent breakpoint (with
3b784c4f
EZ
3749the @kbd{delete @var{num}} command, where @var{num} is the number of
3750the parent breakpoint, 1 in the above example). Disabling or enabling
3751the parent breakpoint (@pxref{Disabling}) affects all of the locations
3752that belong to that breakpoint.
fe6fbf8b 3753
2650777c 3754@cindex pending breakpoints
fe6fbf8b 3755It's quite common to have a breakpoint inside a shared library.
3b784c4f 3756Shared libraries can be loaded and unloaded explicitly,
fe6fbf8b
VP
3757and possibly repeatedly, as the program is executed. To support
3758this use case, @value{GDBN} updates breakpoint locations whenever
3759any shared library is loaded or unloaded. Typically, you would
fcda367b 3760set a breakpoint in a shared library at the beginning of your
fe6fbf8b
VP
3761debugging session, when the library is not loaded, and when the
3762symbols from the library are not available. When you try to set
3763breakpoint, @value{GDBN} will ask you if you want to set
3b784c4f 3764a so called @dfn{pending breakpoint}---breakpoint whose address
fe6fbf8b
VP
3765is not yet resolved.
3766
3767After the program is run, whenever a new shared library is loaded,
3768@value{GDBN} reevaluates all the breakpoints. When a newly loaded
3769shared library contains the symbol or line referred to by some
3770pending breakpoint, that breakpoint is resolved and becomes an
3771ordinary breakpoint. When a library is unloaded, all breakpoints
3772that refer to its symbols or source lines become pending again.
3773
3774This logic works for breakpoints with multiple locations, too. For
3775example, if you have a breakpoint in a C@t{++} template function, and
3776a newly loaded shared library has an instantiation of that template,
3777a new location is added to the list of locations for the breakpoint.
3778
3779Except for having unresolved address, pending breakpoints do not
3780differ from regular breakpoints. You can set conditions or commands,
3781enable and disable them and perform other breakpoint operations.
3782
3783@value{GDBN} provides some additional commands for controlling what
3784happens when the @samp{break} command cannot resolve breakpoint
3785address specification to an address:
dd79a6cf
JJ
3786
3787@kindex set breakpoint pending
3788@kindex show breakpoint pending
3789@table @code
3790@item set breakpoint pending auto
3791This is the default behavior. When @value{GDBN} cannot find the breakpoint
3792location, it queries you whether a pending breakpoint should be created.
3793
3794@item set breakpoint pending on
3795This indicates that an unrecognized breakpoint location should automatically
3796result in a pending breakpoint being created.
3797
3798@item set breakpoint pending off
3799This indicates that pending breakpoints are not to be created. Any
3800unrecognized breakpoint location results in an error. This setting does
3801not affect any pending breakpoints previously created.
3802
3803@item show breakpoint pending
3804Show the current behavior setting for creating pending breakpoints.
3805@end table
2650777c 3806
fe6fbf8b
VP
3807The settings above only affect the @code{break} command and its
3808variants. Once breakpoint is set, it will be automatically updated
3809as shared libraries are loaded and unloaded.
2650777c 3810
765dc015
VP
3811@cindex automatic hardware breakpoints
3812For some targets, @value{GDBN} can automatically decide if hardware or
3813software breakpoints should be used, depending on whether the
3814breakpoint address is read-only or read-write. This applies to
3815breakpoints set with the @code{break} command as well as to internal
3816breakpoints set by commands like @code{next} and @code{finish}. For
fcda367b 3817breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
765dc015
VP
3818breakpoints.
3819
3820You can control this automatic behaviour with the following commands::
3821
3822@kindex set breakpoint auto-hw
3823@kindex show breakpoint auto-hw
3824@table @code
3825@item set breakpoint auto-hw on
3826This is the default behavior. When @value{GDBN} sets a breakpoint, it
3827will try to use the target memory map to decide if software or hardware
3828breakpoint must be used.
3829
3830@item set breakpoint auto-hw off
3831This indicates @value{GDBN} should not automatically select breakpoint
3832type. If the target provides a memory map, @value{GDBN} will warn when
3833trying to set software breakpoint at a read-only address.
3834@end table
3835
74960c60
VP
3836@value{GDBN} normally implements breakpoints by replacing the program code
3837at the breakpoint address with a special instruction, which, when
3838executed, given control to the debugger. By default, the program
3839code is so modified only when the program is resumed. As soon as
3840the program stops, @value{GDBN} restores the original instructions. This
3841behaviour guards against leaving breakpoints inserted in the
3842target should gdb abrubptly disconnect. However, with slow remote
3843targets, inserting and removing breakpoint can reduce the performance.
3844This behavior can be controlled with the following commands::
3845
3846@kindex set breakpoint always-inserted
3847@kindex show breakpoint always-inserted
3848@table @code
3849@item set breakpoint always-inserted off
33e5cbd6
PA
3850All breakpoints, including newly added by the user, are inserted in
3851the target only when the target is resumed. All breakpoints are
3852removed from the target when it stops.
74960c60
VP
3853
3854@item set breakpoint always-inserted on
3855Causes all breakpoints to be inserted in the target at all times. If
3856the user adds a new breakpoint, or changes an existing breakpoint, the
3857breakpoints in the target are updated immediately. A breakpoint is
3858removed from the target only when breakpoint itself is removed.
33e5cbd6
PA
3859
3860@cindex non-stop mode, and @code{breakpoint always-inserted}
3861@item set breakpoint always-inserted auto
3862This is the default mode. If @value{GDBN} is controlling the inferior
3863in non-stop mode (@pxref{Non-Stop Mode}), gdb behaves as if
3864@code{breakpoint always-inserted} mode is on. If @value{GDBN} is
3865controlling the inferior in all-stop mode, @value{GDBN} behaves as if
3866@code{breakpoint always-inserted} mode is off.
74960c60 3867@end table
765dc015 3868
83364271
LM
3869@value{GDBN} handles conditional breakpoints by evaluating these conditions
3870when a breakpoint breaks. If the condition is true, then the process being
3871debugged stops, otherwise the process is resumed.
3872
3873If the target supports evaluating conditions on its end, @value{GDBN} may
3874download the breakpoint, together with its conditions, to it.
3875
3876This feature can be controlled via the following commands:
3877
3878@kindex set breakpoint condition-evaluation
3879@kindex show breakpoint condition-evaluation
3880@table @code
3881@item set breakpoint condition-evaluation host
3882This option commands @value{GDBN} to evaluate the breakpoint
3883conditions on the host's side. Unconditional breakpoints are sent to
3884the target which in turn receives the triggers and reports them back to GDB
3885for condition evaluation. This is the standard evaluation mode.
3886
3887@item set breakpoint condition-evaluation target
3888This option commands @value{GDBN} to download breakpoint conditions
3889to the target at the moment of their insertion. The target
3890is responsible for evaluating the conditional expression and reporting
3891breakpoint stop events back to @value{GDBN} whenever the condition
3892is true. Due to limitations of target-side evaluation, some conditions
3893cannot be evaluated there, e.g., conditions that depend on local data
3894that is only known to the host. Examples include
3895conditional expressions involving convenience variables, complex types
3896that cannot be handled by the agent expression parser and expressions
3897that are too long to be sent over to the target, specially when the
3898target is a remote system. In these cases, the conditions will be
3899evaluated by @value{GDBN}.
3900
3901@item set breakpoint condition-evaluation auto
3902This is the default mode. If the target supports evaluating breakpoint
3903conditions on its end, @value{GDBN} will download breakpoint conditions to
3904the target (limitations mentioned previously apply). If the target does
3905not support breakpoint condition evaluation, then @value{GDBN} will fallback
3906to evaluating all these conditions on the host's side.
3907@end table
3908
3909
c906108c
SS
3910@cindex negative breakpoint numbers
3911@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
3912@value{GDBN} itself sometimes sets breakpoints in your program for
3913special purposes, such as proper handling of @code{longjmp} (in C
3914programs). These internal breakpoints are assigned negative numbers,
3915starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 3916You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 3917@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
3918
3919
6d2ebf8b 3920@node Set Watchpoints
79a6e687 3921@subsection Setting Watchpoints
c906108c
SS
3922
3923@cindex setting watchpoints
c906108c
SS
3924You can use a watchpoint to stop execution whenever the value of an
3925expression changes, without having to predict a particular place where
fd60e0df
EZ
3926this may happen. (This is sometimes called a @dfn{data breakpoint}.)
3927The expression may be as simple as the value of a single variable, or
3928as complex as many variables combined by operators. Examples include:
3929
3930@itemize @bullet
3931@item
3932A reference to the value of a single variable.
3933
3934@item
3935An address cast to an appropriate data type. For example,
3936@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
3937address (assuming an @code{int} occupies 4 bytes).
3938
3939@item
3940An arbitrarily complex expression, such as @samp{a*b + c/d}. The
3941expression can use any operators valid in the program's native
3942language (@pxref{Languages}).
3943@end itemize
c906108c 3944
fa4727a6
DJ
3945You can set a watchpoint on an expression even if the expression can
3946not be evaluated yet. For instance, you can set a watchpoint on
3947@samp{*global_ptr} before @samp{global_ptr} is initialized.
3948@value{GDBN} will stop when your program sets @samp{global_ptr} and
3949the expression produces a valid value. If the expression becomes
3950valid in some other way than changing a variable (e.g.@: if the memory
3951pointed to by @samp{*global_ptr} becomes readable as the result of a
3952@code{malloc} call), @value{GDBN} may not stop until the next time
3953the expression changes.
3954
82f2d802
EZ
3955@cindex software watchpoints
3956@cindex hardware watchpoints
c906108c 3957Depending on your system, watchpoints may be implemented in software or
2df3850c 3958hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
3959program and testing the variable's value each time, which is hundreds of
3960times slower than normal execution. (But this may still be worth it, to
3961catch errors where you have no clue what part of your program is the
3962culprit.)
3963
37e4754d 3964On some systems, such as HP-UX, PowerPC, @sc{gnu}/Linux and most other
82f2d802
EZ
3965x86-based targets, @value{GDBN} includes support for hardware
3966watchpoints, which do not slow down the running of your program.
c906108c
SS
3967
3968@table @code
3969@kindex watch
9c06b0b4 3970@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
fd60e0df
EZ
3971Set a watchpoint for an expression. @value{GDBN} will break when the
3972expression @var{expr} is written into by the program and its value
3973changes. The simplest (and the most popular) use of this command is
3974to watch the value of a single variable:
3975
3976@smallexample
3977(@value{GDBP}) watch foo
3978@end smallexample
c906108c 3979
d8b2a693 3980If the command includes a @code{@r{[}thread @var{threadnum}@r{]}}
9c06b0b4 3981argument, @value{GDBN} breaks only when the thread identified by
d8b2a693
JB
3982@var{threadnum} changes the value of @var{expr}. If any other threads
3983change the value of @var{expr}, @value{GDBN} will not break. Note
3984that watchpoints restricted to a single thread in this way only work
3985with Hardware Watchpoints.
3986
06a64a0b
TT
3987Ordinarily a watchpoint respects the scope of variables in @var{expr}
3988(see below). The @code{-location} argument tells @value{GDBN} to
3989instead watch the memory referred to by @var{expr}. In this case,
3990@value{GDBN} will evaluate @var{expr}, take the address of the result,
3991and watch the memory at that address. The type of the result is used
3992to determine the size of the watched memory. If the expression's
3993result does not have an address, then @value{GDBN} will print an
3994error.
3995
9c06b0b4
TJB
3996The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
3997of masked watchpoints, if the current architecture supports this
3998feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
3999Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4000to an address to watch. The mask specifies that some bits of an address
4001(the bits which are reset in the mask) should be ignored when matching
4002the address accessed by the inferior against the watchpoint address.
4003Thus, a masked watchpoint watches many addresses simultaneously---those
4004addresses whose unmasked bits are identical to the unmasked bits in the
4005watchpoint address. The @code{mask} argument implies @code{-location}.
4006Examples:
4007
4008@smallexample
4009(@value{GDBP}) watch foo mask 0xffff00ff
4010(@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4011@end smallexample
4012
c906108c 4013@kindex rwatch
9c06b0b4 4014@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4015Set a watchpoint that will break when the value of @var{expr} is read
4016by the program.
c906108c
SS
4017
4018@kindex awatch
9c06b0b4 4019@item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4020Set a watchpoint that will break when @var{expr} is either read from
4021or written into by the program.
c906108c 4022
e5a67952
MS
4023@kindex info watchpoints @r{[}@var{n}@dots{}@r{]}
4024@item info watchpoints @r{[}@var{n}@dots{}@r{]}
d77f58be
SS
4025This command prints a list of watchpoints, using the same format as
4026@code{info break} (@pxref{Set Breaks}).
c906108c
SS
4027@end table
4028
65d79d4b
SDJ
4029If you watch for a change in a numerically entered address you need to
4030dereference it, as the address itself is just a constant number which will
4031never change. @value{GDBN} refuses to create a watchpoint that watches
4032a never-changing value:
4033
4034@smallexample
4035(@value{GDBP}) watch 0x600850
4036Cannot watch constant value 0x600850.
4037(@value{GDBP}) watch *(int *) 0x600850
4038Watchpoint 1: *(int *) 6293584
4039@end smallexample
4040
c906108c
SS
4041@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4042watchpoints execute very quickly, and the debugger reports a change in
4043value at the exact instruction where the change occurs. If @value{GDBN}
4044cannot set a hardware watchpoint, it sets a software watchpoint, which
4045executes more slowly and reports the change in value at the next
82f2d802
EZ
4046@emph{statement}, not the instruction, after the change occurs.
4047
82f2d802
EZ
4048@cindex use only software watchpoints
4049You can force @value{GDBN} to use only software watchpoints with the
4050@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4051zero, @value{GDBN} will never try to use hardware watchpoints, even if
4052the underlying system supports them. (Note that hardware-assisted
4053watchpoints that were set @emph{before} setting
4054@code{can-use-hw-watchpoints} to zero will still use the hardware
d3e8051b 4055mechanism of watching expression values.)
c906108c 4056
9c16f35a
EZ
4057@table @code
4058@item set can-use-hw-watchpoints
4059@kindex set can-use-hw-watchpoints
4060Set whether or not to use hardware watchpoints.
4061
4062@item show can-use-hw-watchpoints
4063@kindex show can-use-hw-watchpoints
4064Show the current mode of using hardware watchpoints.
4065@end table
4066
4067For remote targets, you can restrict the number of hardware
4068watchpoints @value{GDBN} will use, see @ref{set remote
4069hardware-breakpoint-limit}.
4070
c906108c
SS
4071When you issue the @code{watch} command, @value{GDBN} reports
4072
474c8240 4073@smallexample
c906108c 4074Hardware watchpoint @var{num}: @var{expr}
474c8240 4075@end smallexample
c906108c
SS
4076
4077@noindent
4078if it was able to set a hardware watchpoint.
4079
7be570e7
JM
4080Currently, the @code{awatch} and @code{rwatch} commands can only set
4081hardware watchpoints, because accesses to data that don't change the
4082value of the watched expression cannot be detected without examining
4083every instruction as it is being executed, and @value{GDBN} does not do
4084that currently. If @value{GDBN} finds that it is unable to set a
4085hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4086will print a message like this:
4087
4088@smallexample
4089Expression cannot be implemented with read/access watchpoint.
4090@end smallexample
4091
4092Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4093data type of the watched expression is wider than what a hardware
4094watchpoint on the target machine can handle. For example, some systems
4095can only watch regions that are up to 4 bytes wide; on such systems you
4096cannot set hardware watchpoints for an expression that yields a
4097double-precision floating-point number (which is typically 8 bytes
4098wide). As a work-around, it might be possible to break the large region
4099into a series of smaller ones and watch them with separate watchpoints.
4100
4101If you set too many hardware watchpoints, @value{GDBN} might be unable
4102to insert all of them when you resume the execution of your program.
4103Since the precise number of active watchpoints is unknown until such
4104time as the program is about to be resumed, @value{GDBN} might not be
4105able to warn you about this when you set the watchpoints, and the
4106warning will be printed only when the program is resumed:
4107
4108@smallexample
4109Hardware watchpoint @var{num}: Could not insert watchpoint
4110@end smallexample
4111
4112@noindent
4113If this happens, delete or disable some of the watchpoints.
4114
fd60e0df
EZ
4115Watching complex expressions that reference many variables can also
4116exhaust the resources available for hardware-assisted watchpoints.
4117That's because @value{GDBN} needs to watch every variable in the
4118expression with separately allocated resources.
4119
c906108c 4120If you call a function interactively using @code{print} or @code{call},
2df3850c 4121any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
4122kind of breakpoint or the call completes.
4123
7be570e7
JM
4124@value{GDBN} automatically deletes watchpoints that watch local
4125(automatic) variables, or expressions that involve such variables, when
4126they go out of scope, that is, when the execution leaves the block in
4127which these variables were defined. In particular, when the program
4128being debugged terminates, @emph{all} local variables go out of scope,
4129and so only watchpoints that watch global variables remain set. If you
4130rerun the program, you will need to set all such watchpoints again. One
4131way of doing that would be to set a code breakpoint at the entry to the
4132@code{main} function and when it breaks, set all the watchpoints.
4133
c906108c
SS
4134@cindex watchpoints and threads
4135@cindex threads and watchpoints
d983da9c
DJ
4136In multi-threaded programs, watchpoints will detect changes to the
4137watched expression from every thread.
4138
4139@quotation
4140@emph{Warning:} In multi-threaded programs, software watchpoints
53a5351d
JM
4141have only limited usefulness. If @value{GDBN} creates a software
4142watchpoint, it can only watch the value of an expression @emph{in a
4143single thread}. If you are confident that the expression can only
4144change due to the current thread's activity (and if you are also
4145confident that no other thread can become current), then you can use
4146software watchpoints as usual. However, @value{GDBN} may not notice
4147when a non-current thread's activity changes the expression. (Hardware
4148watchpoints, in contrast, watch an expression in all threads.)
c906108c 4149@end quotation
c906108c 4150
501eef12
AC
4151@xref{set remote hardware-watchpoint-limit}.
4152
6d2ebf8b 4153@node Set Catchpoints
79a6e687 4154@subsection Setting Catchpoints
d4f3574e 4155@cindex catchpoints, setting
c906108c
SS
4156@cindex exception handlers
4157@cindex event handling
4158
4159You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 4160kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
4161shared library. Use the @code{catch} command to set a catchpoint.
4162
4163@table @code
4164@kindex catch
4165@item catch @var{event}
4166Stop when @var{event} occurs. @var{event} can be any of the following:
591f19e8 4167
c906108c 4168@table @code
cc16e6c9
TT
4169@item throw @r{[}@var{regexp}@r{]}
4170@itemx rethrow @r{[}@var{regexp}@r{]}
4171@itemx catch @r{[}@var{regexp}@r{]}
1a4f73eb
TT
4172@kindex catch throw
4173@kindex catch rethrow
4174@kindex catch catch
4644b6e3 4175@cindex stop on C@t{++} exceptions
591f19e8
TT
4176The throwing, re-throwing, or catching of a C@t{++} exception.
4177
cc16e6c9
TT
4178If @var{regexp} is given, then only exceptions whose type matches the
4179regular expression will be caught.
4180
72f1fe8a
TT
4181@vindex $_exception@r{, convenience variable}
4182The convenience variable @code{$_exception} is available at an
4183exception-related catchpoint, on some systems. This holds the
4184exception being thrown.
4185
591f19e8
TT
4186There are currently some limitations to C@t{++} exception handling in
4187@value{GDBN}:
c906108c 4188
591f19e8
TT
4189@itemize @bullet
4190@item
4191The support for these commands is system-dependent. Currently, only
4192systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
4193supported.
4194
72f1fe8a 4195@item
cc16e6c9
TT
4196The regular expression feature and the @code{$_exception} convenience
4197variable rely on the presence of some SDT probes in @code{libstdc++}.
4198If these probes are not present, then these features cannot be used.
dee368d3
TT
4199These probes were first available in the GCC 4.8 release, but whether
4200or not they are available in your GCC also depends on how it was
4201built.
72f1fe8a
TT
4202
4203@item
4204The @code{$_exception} convenience variable is only valid at the
4205instruction at which an exception-related catchpoint is set.
4206
591f19e8
TT
4207@item
4208When an exception-related catchpoint is hit, @value{GDBN} stops at a
4209location in the system library which implements runtime exception
4210support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
4211(@pxref{Selection}) to get to your code.
4212
4213@item
4214If you call a function interactively, @value{GDBN} normally returns
4215control to you when the function has finished executing. If the call
4216raises an exception, however, the call may bypass the mechanism that
4217returns control to you and cause your program either to abort or to
4218simply continue running until it hits a breakpoint, catches a signal
4219that @value{GDBN} is listening for, or exits. This is the case even if
4220you set a catchpoint for the exception; catchpoints on exceptions are
4221disabled within interactive calls. @xref{Calling}, for information on
4222controlling this with @code{set unwind-on-terminating-exception}.
4223
4224@item
4225You cannot raise an exception interactively.
4226
4227@item
4228You cannot install an exception handler interactively.
4229@end itemize
c906108c 4230
8936fcda 4231@item exception
1a4f73eb 4232@kindex catch exception
8936fcda
JB
4233@cindex Ada exception catching
4234@cindex catch Ada exceptions
4235An Ada exception being raised. If an exception name is specified
4236at the end of the command (eg @code{catch exception Program_Error}),
4237the debugger will stop only when this specific exception is raised.
4238Otherwise, the debugger stops execution when any Ada exception is raised.
4239
87f67dba
JB
4240When inserting an exception catchpoint on a user-defined exception whose
4241name is identical to one of the exceptions defined by the language, the
4242fully qualified name must be used as the exception name. Otherwise,
4243@value{GDBN} will assume that it should stop on the pre-defined exception
4244rather than the user-defined one. For instance, assuming an exception
4245called @code{Constraint_Error} is defined in package @code{Pck}, then
4246the command to use to catch such exceptions is @kbd{catch exception
4247Pck.Constraint_Error}.
4248
8936fcda 4249@item exception unhandled
1a4f73eb 4250@kindex catch exception unhandled
8936fcda
JB
4251An exception that was raised but is not handled by the program.
4252
4253@item assert
1a4f73eb 4254@kindex catch assert
8936fcda
JB
4255A failed Ada assertion.
4256
c906108c 4257@item exec
1a4f73eb 4258@kindex catch exec
4644b6e3 4259@cindex break on fork/exec
5ee187d7
DJ
4260A call to @code{exec}. This is currently only available for HP-UX
4261and @sc{gnu}/Linux.
c906108c 4262
a96d9b2e 4263@item syscall
ee8e71d4 4264@itemx syscall @r{[}@var{name} @r{|} @var{number}@r{]} @dots{}
1a4f73eb 4265@kindex catch syscall
a96d9b2e
SDJ
4266@cindex break on a system call.
4267A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
4268syscall is a mechanism for application programs to request a service
4269from the operating system (OS) or one of the OS system services.
4270@value{GDBN} can catch some or all of the syscalls issued by the
4271debuggee, and show the related information for each syscall. If no
4272argument is specified, calls to and returns from all system calls
4273will be caught.
4274
4275@var{name} can be any system call name that is valid for the
4276underlying OS. Just what syscalls are valid depends on the OS. On
4277GNU and Unix systems, you can find the full list of valid syscall
4278names on @file{/usr/include/asm/unistd.h}.
4279
4280@c For MS-Windows, the syscall names and the corresponding numbers
4281@c can be found, e.g., on this URL:
4282@c http://www.metasploit.com/users/opcode/syscalls.html
4283@c but we don't support Windows syscalls yet.
4284
4285Normally, @value{GDBN} knows in advance which syscalls are valid for
4286each OS, so you can use the @value{GDBN} command-line completion
4287facilities (@pxref{Completion,, command completion}) to list the
4288available choices.
4289
4290You may also specify the system call numerically. A syscall's
4291number is the value passed to the OS's syscall dispatcher to
4292identify the requested service. When you specify the syscall by its
4293name, @value{GDBN} uses its database of syscalls to convert the name
4294into the corresponding numeric code, but using the number directly
4295may be useful if @value{GDBN}'s database does not have the complete
4296list of syscalls on your system (e.g., because @value{GDBN} lags
4297behind the OS upgrades).
4298
4299The example below illustrates how this command works if you don't provide
4300arguments to it:
4301
4302@smallexample
4303(@value{GDBP}) catch syscall
4304Catchpoint 1 (syscall)
4305(@value{GDBP}) r
4306Starting program: /tmp/catch-syscall
4307
4308Catchpoint 1 (call to syscall 'close'), \
4309 0xffffe424 in __kernel_vsyscall ()
4310(@value{GDBP}) c
4311Continuing.
4312
4313Catchpoint 1 (returned from syscall 'close'), \
4314 0xffffe424 in __kernel_vsyscall ()
4315(@value{GDBP})
4316@end smallexample
4317
4318Here is an example of catching a system call by name:
4319
4320@smallexample
4321(@value{GDBP}) catch syscall chroot
4322Catchpoint 1 (syscall 'chroot' [61])
4323(@value{GDBP}) r
4324Starting program: /tmp/catch-syscall
4325
4326Catchpoint 1 (call to syscall 'chroot'), \
4327 0xffffe424 in __kernel_vsyscall ()
4328(@value{GDBP}) c
4329Continuing.
4330
4331Catchpoint 1 (returned from syscall 'chroot'), \
4332 0xffffe424 in __kernel_vsyscall ()
4333(@value{GDBP})
4334@end smallexample
4335
4336An example of specifying a system call numerically. In the case
4337below, the syscall number has a corresponding entry in the XML
4338file, so @value{GDBN} finds its name and prints it:
4339
4340@smallexample
4341(@value{GDBP}) catch syscall 252
4342Catchpoint 1 (syscall(s) 'exit_group')
4343(@value{GDBP}) r
4344Starting program: /tmp/catch-syscall
4345
4346Catchpoint 1 (call to syscall 'exit_group'), \
4347 0xffffe424 in __kernel_vsyscall ()
4348(@value{GDBP}) c
4349Continuing.
4350
4351Program exited normally.
4352(@value{GDBP})
4353@end smallexample
4354
4355However, there can be situations when there is no corresponding name
4356in XML file for that syscall number. In this case, @value{GDBN} prints
4357a warning message saying that it was not able to find the syscall name,
4358but the catchpoint will be set anyway. See the example below:
4359
4360@smallexample
4361(@value{GDBP}) catch syscall 764
4362warning: The number '764' does not represent a known syscall.
4363Catchpoint 2 (syscall 764)
4364(@value{GDBP})
4365@end smallexample
4366
4367If you configure @value{GDBN} using the @samp{--without-expat} option,
4368it will not be able to display syscall names. Also, if your
4369architecture does not have an XML file describing its system calls,
4370you will not be able to see the syscall names. It is important to
4371notice that these two features are used for accessing the syscall
4372name database. In either case, you will see a warning like this:
4373
4374@smallexample
4375(@value{GDBP}) catch syscall
4376warning: Could not open "syscalls/i386-linux.xml"
4377warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
4378GDB will not be able to display syscall names.
4379Catchpoint 1 (syscall)
4380(@value{GDBP})
4381@end smallexample
4382
4383Of course, the file name will change depending on your architecture and system.
4384
4385Still using the example above, you can also try to catch a syscall by its
4386number. In this case, you would see something like:
4387
4388@smallexample
4389(@value{GDBP}) catch syscall 252
4390Catchpoint 1 (syscall(s) 252)
4391@end smallexample
4392
4393Again, in this case @value{GDBN} would not be able to display syscall's names.
4394
c906108c 4395@item fork
1a4f73eb 4396@kindex catch fork
5ee187d7
DJ
4397A call to @code{fork}. This is currently only available for HP-UX
4398and @sc{gnu}/Linux.
c906108c
SS
4399
4400@item vfork
1a4f73eb 4401@kindex catch vfork
5ee187d7
DJ
4402A call to @code{vfork}. This is currently only available for HP-UX
4403and @sc{gnu}/Linux.
c906108c 4404
edcc5120
TT
4405@item load @r{[}regexp@r{]}
4406@itemx unload @r{[}regexp@r{]}
1a4f73eb
TT
4407@kindex catch load
4408@kindex catch unload
edcc5120
TT
4409The loading or unloading of a shared library. If @var{regexp} is
4410given, then the catchpoint will stop only if the regular expression
4411matches one of the affected libraries.
4412
ab04a2af 4413@item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
1a4f73eb 4414@kindex catch signal
ab04a2af
TT
4415The delivery of a signal.
4416
4417With no arguments, this catchpoint will catch any signal that is not
4418used internally by @value{GDBN}, specifically, all signals except
4419@samp{SIGTRAP} and @samp{SIGINT}.
4420
4421With the argument @samp{all}, all signals, including those used by
4422@value{GDBN}, will be caught. This argument cannot be used with other
4423signal names.
4424
4425Otherwise, the arguments are a list of signal names as given to
4426@code{handle} (@pxref{Signals}). Only signals specified in this list
4427will be caught.
4428
4429One reason that @code{catch signal} can be more useful than
4430@code{handle} is that you can attach commands and conditions to the
4431catchpoint.
4432
4433When a signal is caught by a catchpoint, the signal's @code{stop} and
4434@code{print} settings, as specified by @code{handle}, are ignored.
4435However, whether the signal is still delivered to the inferior depends
4436on the @code{pass} setting; this can be changed in the catchpoint's
4437commands.
4438
c906108c
SS
4439@end table
4440
4441@item tcatch @var{event}
1a4f73eb 4442@kindex tcatch
c906108c
SS
4443Set a catchpoint that is enabled only for one stop. The catchpoint is
4444automatically deleted after the first time the event is caught.
4445
4446@end table
4447
4448Use the @code{info break} command to list the current catchpoints.
4449
c906108c 4450
6d2ebf8b 4451@node Delete Breaks
79a6e687 4452@subsection Deleting Breakpoints
c906108c
SS
4453
4454@cindex clearing breakpoints, watchpoints, catchpoints
4455@cindex deleting breakpoints, watchpoints, catchpoints
4456It is often necessary to eliminate a breakpoint, watchpoint, or
4457catchpoint once it has done its job and you no longer want your program
4458to stop there. This is called @dfn{deleting} the breakpoint. A
4459breakpoint that has been deleted no longer exists; it is forgotten.
4460
4461With the @code{clear} command you can delete breakpoints according to
4462where they are in your program. With the @code{delete} command you can
4463delete individual breakpoints, watchpoints, or catchpoints by specifying
4464their breakpoint numbers.
4465
4466It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
4467automatically ignores breakpoints on the first instruction to be executed
4468when you continue execution without changing the execution address.
4469
4470@table @code
4471@kindex clear
4472@item clear
4473Delete any breakpoints at the next instruction to be executed in the
79a6e687 4474selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
c906108c
SS
4475the innermost frame is selected, this is a good way to delete a
4476breakpoint where your program just stopped.
4477
2a25a5ba
EZ
4478@item clear @var{location}
4479Delete any breakpoints set at the specified @var{location}.
4480@xref{Specify Location}, for the various forms of @var{location}; the
4481most useful ones are listed below:
4482
4483@table @code
c906108c
SS
4484@item clear @var{function}
4485@itemx clear @var{filename}:@var{function}
09d4efe1 4486Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
4487
4488@item clear @var{linenum}
4489@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
4490Delete any breakpoints set at or within the code of the specified
4491@var{linenum} of the specified @var{filename}.
2a25a5ba 4492@end table
c906108c
SS
4493
4494@cindex delete breakpoints
4495@kindex delete
41afff9a 4496@kindex d @r{(@code{delete})}
c5394b80
JM
4497@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4498Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
4499ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
4500breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
4501confirm off}). You can abbreviate this command as @code{d}.
4502@end table
4503
6d2ebf8b 4504@node Disabling
79a6e687 4505@subsection Disabling Breakpoints
c906108c 4506
4644b6e3 4507@cindex enable/disable a breakpoint
c906108c
SS
4508Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
4509prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
4510it had been deleted, but remembers the information on the breakpoint so
4511that you can @dfn{enable} it again later.
4512
4513You disable and enable breakpoints, watchpoints, and catchpoints with
d77f58be
SS
4514the @code{enable} and @code{disable} commands, optionally specifying
4515one or more breakpoint numbers as arguments. Use @code{info break} to
4516print a list of all breakpoints, watchpoints, and catchpoints if you
4517do not know which numbers to use.
c906108c 4518
3b784c4f
EZ
4519Disabling and enabling a breakpoint that has multiple locations
4520affects all of its locations.
4521
816338b5
SS
4522A breakpoint, watchpoint, or catchpoint can have any of several
4523different states of enablement:
c906108c
SS
4524
4525@itemize @bullet
4526@item
4527Enabled. The breakpoint stops your program. A breakpoint set
4528with the @code{break} command starts out in this state.
4529@item
4530Disabled. The breakpoint has no effect on your program.
4531@item
4532Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 4533disabled.
c906108c 4534@item
816338b5
SS
4535Enabled for a count. The breakpoint stops your program for the next
4536N times, then becomes disabled.
4537@item
c906108c 4538Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
4539immediately after it does so it is deleted permanently. A breakpoint
4540set with the @code{tbreak} command starts out in this state.
c906108c
SS
4541@end itemize
4542
4543You can use the following commands to enable or disable breakpoints,
4544watchpoints, and catchpoints:
4545
4546@table @code
c906108c 4547@kindex disable
41afff9a 4548@kindex dis @r{(@code{disable})}
c5394b80 4549@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4550Disable the specified breakpoints---or all breakpoints, if none are
4551listed. A disabled breakpoint has no effect but is not forgotten. All
4552options such as ignore-counts, conditions and commands are remembered in
4553case the breakpoint is enabled again later. You may abbreviate
4554@code{disable} as @code{dis}.
4555
c906108c 4556@kindex enable
c5394b80 4557@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4558Enable the specified breakpoints (or all defined breakpoints). They
4559become effective once again in stopping your program.
4560
c5394b80 4561@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
4562Enable the specified breakpoints temporarily. @value{GDBN} disables any
4563of these breakpoints immediately after stopping your program.
4564
816338b5
SS
4565@item enable @r{[}breakpoints@r{]} count @var{count} @var{range}@dots{}
4566Enable the specified breakpoints temporarily. @value{GDBN} records
4567@var{count} with each of the specified breakpoints, and decrements a
4568breakpoint's count when it is hit. When any count reaches 0,
4569@value{GDBN} disables that breakpoint. If a breakpoint has an ignore
4570count (@pxref{Conditions, ,Break Conditions}), that will be
4571decremented to 0 before @var{count} is affected.
4572
c5394b80 4573@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
4574Enable the specified breakpoints to work once, then die. @value{GDBN}
4575deletes any of these breakpoints as soon as your program stops there.
09d4efe1 4576Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
4577@end table
4578
d4f3574e
SS
4579@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
4580@c confusing: tbreak is also initially enabled.
c906108c 4581Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
79a6e687 4582,Setting Breakpoints}), breakpoints that you set are initially enabled;
c906108c
SS
4583subsequently, they become disabled or enabled only when you use one of
4584the commands above. (The command @code{until} can set and delete a
4585breakpoint of its own, but it does not change the state of your other
4586breakpoints; see @ref{Continuing and Stepping, ,Continuing and
79a6e687 4587Stepping}.)
c906108c 4588
6d2ebf8b 4589@node Conditions
79a6e687 4590@subsection Break Conditions
c906108c
SS
4591@cindex conditional breakpoints
4592@cindex breakpoint conditions
4593
4594@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 4595@c in particular for a watchpoint?
c906108c
SS
4596The simplest sort of breakpoint breaks every time your program reaches a
4597specified place. You can also specify a @dfn{condition} for a
4598breakpoint. A condition is just a Boolean expression in your
4599programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
4600a condition evaluates the expression each time your program reaches it,
4601and your program stops only if the condition is @emph{true}.
4602
4603This is the converse of using assertions for program validation; in that
4604situation, you want to stop when the assertion is violated---that is,
4605when the condition is false. In C, if you want to test an assertion expressed
4606by the condition @var{assert}, you should set the condition
4607@samp{! @var{assert}} on the appropriate breakpoint.
4608
4609Conditions are also accepted for watchpoints; you may not need them,
4610since a watchpoint is inspecting the value of an expression anyhow---but
4611it might be simpler, say, to just set a watchpoint on a variable name,
4612and specify a condition that tests whether the new value is an interesting
4613one.
4614
4615Break conditions can have side effects, and may even call functions in
4616your program. This can be useful, for example, to activate functions
4617that log program progress, or to use your own print functions to
99e008fe 4618format special data structures. The effects are completely predictable
c906108c
SS
4619unless there is another enabled breakpoint at the same address. (In
4620that case, @value{GDBN} might see the other breakpoint first and stop your
4621program without checking the condition of this one.) Note that
d4f3574e
SS
4622breakpoint commands are usually more convenient and flexible than break
4623conditions for the
c906108c 4624purpose of performing side effects when a breakpoint is reached
79a6e687 4625(@pxref{Break Commands, ,Breakpoint Command Lists}).
c906108c 4626
83364271
LM
4627Breakpoint conditions can also be evaluated on the target's side if
4628the target supports it. Instead of evaluating the conditions locally,
4629@value{GDBN} encodes the expression into an agent expression
4630(@pxref{Agent Expressions}) suitable for execution on the target,
4631independently of @value{GDBN}. Global variables become raw memory
4632locations, locals become stack accesses, and so forth.
4633
4634In this case, @value{GDBN} will only be notified of a breakpoint trigger
4635when its condition evaluates to true. This mechanism may provide faster
4636response times depending on the performance characteristics of the target
4637since it does not need to keep @value{GDBN} informed about
4638every breakpoint trigger, even those with false conditions.
4639
c906108c
SS
4640Break conditions can be specified when a breakpoint is set, by using
4641@samp{if} in the arguments to the @code{break} command. @xref{Set
79a6e687 4642Breaks, ,Setting Breakpoints}. They can also be changed at any time
c906108c 4643with the @code{condition} command.
53a5351d 4644
c906108c
SS
4645You can also use the @code{if} keyword with the @code{watch} command.
4646The @code{catch} command does not recognize the @code{if} keyword;
4647@code{condition} is the only way to impose a further condition on a
4648catchpoint.
c906108c
SS
4649
4650@table @code
4651@kindex condition
4652@item condition @var{bnum} @var{expression}
4653Specify @var{expression} as the break condition for breakpoint,
4654watchpoint, or catchpoint number @var{bnum}. After you set a condition,
4655breakpoint @var{bnum} stops your program only if the value of
4656@var{expression} is true (nonzero, in C). When you use
4657@code{condition}, @value{GDBN} checks @var{expression} immediately for
4658syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
4659referents in the context of your breakpoint. If @var{expression} uses
4660symbols not referenced in the context of the breakpoint, @value{GDBN}
4661prints an error message:
4662
474c8240 4663@smallexample
d4f3574e 4664No symbol "foo" in current context.
474c8240 4665@end smallexample
d4f3574e
SS
4666
4667@noindent
c906108c
SS
4668@value{GDBN} does
4669not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
4670command (or a command that sets a breakpoint with a condition, like
4671@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
4672
4673@item condition @var{bnum}
4674Remove the condition from breakpoint number @var{bnum}. It becomes
4675an ordinary unconditional breakpoint.
4676@end table
4677
4678@cindex ignore count (of breakpoint)
4679A special case of a breakpoint condition is to stop only when the
4680breakpoint has been reached a certain number of times. This is so
4681useful that there is a special way to do it, using the @dfn{ignore
4682count} of the breakpoint. Every breakpoint has an ignore count, which
4683is an integer. Most of the time, the ignore count is zero, and
4684therefore has no effect. But if your program reaches a breakpoint whose
4685ignore count is positive, then instead of stopping, it just decrements
4686the ignore count by one and continues. As a result, if the ignore count
4687value is @var{n}, the breakpoint does not stop the next @var{n} times
4688your program reaches it.
4689
4690@table @code
4691@kindex ignore
4692@item ignore @var{bnum} @var{count}
4693Set the ignore count of breakpoint number @var{bnum} to @var{count}.
4694The next @var{count} times the breakpoint is reached, your program's
4695execution does not stop; other than to decrement the ignore count, @value{GDBN}
4696takes no action.
4697
4698To make the breakpoint stop the next time it is reached, specify
4699a count of zero.
4700
4701When you use @code{continue} to resume execution of your program from a
4702breakpoint, you can specify an ignore count directly as an argument to
4703@code{continue}, rather than using @code{ignore}. @xref{Continuing and
79a6e687 4704Stepping,,Continuing and Stepping}.
c906108c
SS
4705
4706If a breakpoint has a positive ignore count and a condition, the
4707condition is not checked. Once the ignore count reaches zero,
4708@value{GDBN} resumes checking the condition.
4709
4710You could achieve the effect of the ignore count with a condition such
4711as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
4712is decremented each time. @xref{Convenience Vars, ,Convenience
79a6e687 4713Variables}.
c906108c
SS
4714@end table
4715
4716Ignore counts apply to breakpoints, watchpoints, and catchpoints.
4717
4718
6d2ebf8b 4719@node Break Commands
79a6e687 4720@subsection Breakpoint Command Lists
c906108c
SS
4721
4722@cindex breakpoint commands
4723You can give any breakpoint (or watchpoint or catchpoint) a series of
4724commands to execute when your program stops due to that breakpoint. For
4725example, you might want to print the values of certain expressions, or
4726enable other breakpoints.
4727
4728@table @code
4729@kindex commands
ca91424e 4730@kindex end@r{ (breakpoint commands)}
95a42b64 4731@item commands @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4732@itemx @dots{} @var{command-list} @dots{}
4733@itemx end
95a42b64 4734Specify a list of commands for the given breakpoints. The commands
c906108c
SS
4735themselves appear on the following lines. Type a line containing just
4736@code{end} to terminate the commands.
4737
4738To remove all commands from a breakpoint, type @code{commands} and
4739follow it immediately with @code{end}; that is, give no commands.
4740
95a42b64
TT
4741With no argument, @code{commands} refers to the last breakpoint,
4742watchpoint, or catchpoint set (not to the breakpoint most recently
4743encountered). If the most recent breakpoints were set with a single
4744command, then the @code{commands} will apply to all the breakpoints
4745set by that command. This applies to breakpoints set by
86b17b60
PA
4746@code{rbreak}, and also applies when a single @code{break} command
4747creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
4748Expressions}).
c906108c
SS
4749@end table
4750
4751Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
4752disabled within a @var{command-list}.
4753
4754You can use breakpoint commands to start your program up again. Simply
4755use the @code{continue} command, or @code{step}, or any other command
4756that resumes execution.
4757
4758Any other commands in the command list, after a command that resumes
4759execution, are ignored. This is because any time you resume execution
4760(even with a simple @code{next} or @code{step}), you may encounter
4761another breakpoint---which could have its own command list, leading to
4762ambiguities about which list to execute.
4763
4764@kindex silent
4765If the first command you specify in a command list is @code{silent}, the
4766usual message about stopping at a breakpoint is not printed. This may
4767be desirable for breakpoints that are to print a specific message and
4768then continue. If none of the remaining commands print anything, you
4769see no sign that the breakpoint was reached. @code{silent} is
4770meaningful only at the beginning of a breakpoint command list.
4771
4772The commands @code{echo}, @code{output}, and @code{printf} allow you to
4773print precisely controlled output, and are often useful in silent
79a6e687 4774breakpoints. @xref{Output, ,Commands for Controlled Output}.
c906108c
SS
4775
4776For example, here is how you could use breakpoint commands to print the
4777value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
4778
474c8240 4779@smallexample
c906108c
SS
4780break foo if x>0
4781commands
4782silent
4783printf "x is %d\n",x
4784cont
4785end
474c8240 4786@end smallexample
c906108c
SS
4787
4788One application for breakpoint commands is to compensate for one bug so
4789you can test for another. Put a breakpoint just after the erroneous line
4790of code, give it a condition to detect the case in which something
4791erroneous has been done, and give it commands to assign correct values
4792to any variables that need them. End with the @code{continue} command
4793so that your program does not stop, and start with the @code{silent}
4794command so that no output is produced. Here is an example:
4795
474c8240 4796@smallexample
c906108c
SS
4797break 403
4798commands
4799silent
4800set x = y + 4
4801cont
4802end
474c8240 4803@end smallexample
c906108c 4804
e7e0cddf
SS
4805@node Dynamic Printf
4806@subsection Dynamic Printf
4807
4808@cindex dynamic printf
4809@cindex dprintf
4810The dynamic printf command @code{dprintf} combines a breakpoint with
4811formatted printing of your program's data to give you the effect of
4812inserting @code{printf} calls into your program on-the-fly, without
4813having to recompile it.
4814
4815In its most basic form, the output goes to the GDB console. However,
4816you can set the variable @code{dprintf-style} for alternate handling.
4817For instance, you can ask to format the output by calling your
4818program's @code{printf} function. This has the advantage that the
4819characters go to the program's output device, so they can recorded in
4820redirects to files and so forth.
4821
d3ce09f5
SS
4822If you are doing remote debugging with a stub or agent, you can also
4823ask to have the printf handled by the remote agent. In addition to
4824ensuring that the output goes to the remote program's device along
4825with any other output the program might produce, you can also ask that
4826the dprintf remain active even after disconnecting from the remote
4827target. Using the stub/agent is also more efficient, as it can do
4828everything without needing to communicate with @value{GDBN}.
4829
e7e0cddf
SS
4830@table @code
4831@kindex dprintf
4832@item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
4833Whenever execution reaches @var{location}, print the values of one or
4834more @var{expressions} under the control of the string @var{template}.
4835To print several values, separate them with commas.
4836
4837@item set dprintf-style @var{style}
4838Set the dprintf output to be handled in one of several different
4839styles enumerated below. A change of style affects all existing
4840dynamic printfs immediately. (If you need individual control over the
4841print commands, simply define normal breakpoints with
4842explicitly-supplied command lists.)
4843
4844@item gdb
4845@kindex dprintf-style gdb
4846Handle the output using the @value{GDBN} @code{printf} command.
4847
4848@item call
4849@kindex dprintf-style call
4850Handle the output by calling a function in your program (normally
4851@code{printf}).
4852
d3ce09f5
SS
4853@item agent
4854@kindex dprintf-style agent
4855Have the remote debugging agent (such as @code{gdbserver}) handle
4856the output itself. This style is only available for agents that
4857support running commands on the target.
4858
e7e0cddf
SS
4859@item set dprintf-function @var{function}
4860Set the function to call if the dprintf style is @code{call}. By
4861default its value is @code{printf}. You may set it to any expression.
4862that @value{GDBN} can evaluate to a function, as per the @code{call}
4863command.
4864
4865@item set dprintf-channel @var{channel}
4866Set a ``channel'' for dprintf. If set to a non-empty value,
4867@value{GDBN} will evaluate it as an expression and pass the result as
4868a first argument to the @code{dprintf-function}, in the manner of
4869@code{fprintf} and similar functions. Otherwise, the dprintf format
4870string will be the first argument, in the manner of @code{printf}.
4871
4872As an example, if you wanted @code{dprintf} output to go to a logfile
4873that is a standard I/O stream assigned to the variable @code{mylog},
4874you could do the following:
4875
4876@example
4877(gdb) set dprintf-style call
4878(gdb) set dprintf-function fprintf
4879(gdb) set dprintf-channel mylog
4880(gdb) dprintf 25,"at line 25, glob=%d\n",glob
4881Dprintf 1 at 0x123456: file main.c, line 25.
4882(gdb) info break
48831 dprintf keep y 0x00123456 in main at main.c:25
4884 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
4885 continue
4886(gdb)
4887@end example
4888
4889Note that the @code{info break} displays the dynamic printf commands
4890as normal breakpoint commands; you can thus easily see the effect of
4891the variable settings.
4892
d3ce09f5
SS
4893@item set disconnected-dprintf on
4894@itemx set disconnected-dprintf off
4895@kindex set disconnected-dprintf
4896Choose whether @code{dprintf} commands should continue to run if
4897@value{GDBN} has disconnected from the target. This only applies
4898if the @code{dprintf-style} is @code{agent}.
4899
4900@item show disconnected-dprintf off
4901@kindex show disconnected-dprintf
4902Show the current choice for disconnected @code{dprintf}.
4903
e7e0cddf
SS
4904@end table
4905
4906@value{GDBN} does not check the validity of function and channel,
4907relying on you to supply values that are meaningful for the contexts
4908in which they are being used. For instance, the function and channel
4909may be the values of local variables, but if that is the case, then
4910all enabled dynamic prints must be at locations within the scope of
4911those locals. If evaluation fails, @value{GDBN} will report an error.
4912
6149aea9
PA
4913@node Save Breakpoints
4914@subsection How to save breakpoints to a file
4915
4916To save breakpoint definitions to a file use the @w{@code{save
4917breakpoints}} command.
4918
4919@table @code
4920@kindex save breakpoints
4921@cindex save breakpoints to a file for future sessions
4922@item save breakpoints [@var{filename}]
4923This command saves all current breakpoint definitions together with
4924their commands and ignore counts, into a file @file{@var{filename}}
4925suitable for use in a later debugging session. This includes all
4926types of breakpoints (breakpoints, watchpoints, catchpoints,
4927tracepoints). To read the saved breakpoint definitions, use the
4928@code{source} command (@pxref{Command Files}). Note that watchpoints
4929with expressions involving local variables may fail to be recreated
4930because it may not be possible to access the context where the
4931watchpoint is valid anymore. Because the saved breakpoint definitions
4932are simply a sequence of @value{GDBN} commands that recreate the
4933breakpoints, you can edit the file in your favorite editing program,
4934and remove the breakpoint definitions you're not interested in, or
4935that can no longer be recreated.
4936@end table
4937
62e5f89c
SDJ
4938@node Static Probe Points
4939@subsection Static Probe Points
4940
4941@cindex static probe point, SystemTap
4942@value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
4943for Statically Defined Tracing, and the probes are designed to have a tiny
4944runtime code and data footprint, and no dynamic relocations. They are
4945usable from assembly, C and C@t{++} languages. See
4946@uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
4947for a good reference on how the @acronym{SDT} probes are implemented.
4948
4949Currently, @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
4950@acronym{SDT} probes are supported on ELF-compatible systems. See
4951@uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
4952for more information on how to add @code{SystemTap} @acronym{SDT} probes
4953in your applications.
4954
4955@cindex semaphores on static probe points
4956Some probes have an associated semaphore variable; for instance, this
4957happens automatically if you defined your probe using a DTrace-style
4958@file{.d} file. If your probe has a semaphore, @value{GDBN} will
4959automatically enable it when you specify a breakpoint using the
4960@samp{-probe-stap} notation. But, if you put a breakpoint at a probe's
4961location by some other method (e.g., @code{break file:line}), then
4962@value{GDBN} will not automatically set the semaphore.
4963
4964You can examine the available static static probes using @code{info
4965probes}, with optional arguments:
4966
4967@table @code
4968@kindex info probes
4969@item info probes stap @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
4970If given, @var{provider} is a regular expression used to match against provider
4971names when selecting which probes to list. If omitted, probes by all
4972probes from all providers are listed.
4973
4974If given, @var{name} is a regular expression to match against probe names
4975when selecting which probes to list. If omitted, probe names are not
4976considered when deciding whether to display them.
4977
4978If given, @var{objfile} is a regular expression used to select which
4979object files (executable or shared libraries) to examine. If not
4980given, all object files are considered.
4981
4982@item info probes all
4983List the available static probes, from all types.
4984@end table
4985
4986@vindex $_probe_arg@r{, convenience variable}
4987A probe may specify up to twelve arguments. These are available at the
4988point at which the probe is defined---that is, when the current PC is
4989at the probe's location. The arguments are available using the
4990convenience variables (@pxref{Convenience Vars})
4991@code{$_probe_arg0}@dots{}@code{$_probe_arg11}. Each probe argument is
4992an integer of the appropriate size; types are not preserved. The
4993convenience variable @code{$_probe_argc} holds the number of arguments
4994at the current probe point.
4995
4996These variables are always available, but attempts to access them at
4997any location other than a probe point will cause @value{GDBN} to give
4998an error message.
4999
5000
c906108c 5001@c @ifclear BARETARGET
6d2ebf8b 5002@node Error in Breakpoints
d4f3574e 5003@subsection ``Cannot insert breakpoints''
c906108c 5004
fa3a767f
PA
5005If you request too many active hardware-assisted breakpoints and
5006watchpoints, you will see this error message:
d4f3574e
SS
5007
5008@c FIXME: the precise wording of this message may change; the relevant
5009@c source change is not committed yet (Sep 3, 1999).
5010@smallexample
5011Stopped; cannot insert breakpoints.
5012You may have requested too many hardware breakpoints and watchpoints.
5013@end smallexample
5014
5015@noindent
5016This message is printed when you attempt to resume the program, since
5017only then @value{GDBN} knows exactly how many hardware breakpoints and
5018watchpoints it needs to insert.
5019
5020When this message is printed, you need to disable or remove some of the
5021hardware-assisted breakpoints and watchpoints, and then continue.
5022
79a6e687 5023@node Breakpoint-related Warnings
1485d690
KB
5024@subsection ``Breakpoint address adjusted...''
5025@cindex breakpoint address adjusted
5026
5027Some processor architectures place constraints on the addresses at
5028which breakpoints may be placed. For architectures thus constrained,
5029@value{GDBN} will attempt to adjust the breakpoint's address to comply
5030with the constraints dictated by the architecture.
5031
5032One example of such an architecture is the Fujitsu FR-V. The FR-V is
5033a VLIW architecture in which a number of RISC-like instructions may be
5034bundled together for parallel execution. The FR-V architecture
5035constrains the location of a breakpoint instruction within such a
5036bundle to the instruction with the lowest address. @value{GDBN}
5037honors this constraint by adjusting a breakpoint's address to the
5038first in the bundle.
5039
5040It is not uncommon for optimized code to have bundles which contain
5041instructions from different source statements, thus it may happen that
5042a breakpoint's address will be adjusted from one source statement to
5043another. Since this adjustment may significantly alter @value{GDBN}'s
5044breakpoint related behavior from what the user expects, a warning is
5045printed when the breakpoint is first set and also when the breakpoint
5046is hit.
5047
5048A warning like the one below is printed when setting a breakpoint
5049that's been subject to address adjustment:
5050
5051@smallexample
5052warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
5053@end smallexample
5054
5055Such warnings are printed both for user settable and @value{GDBN}'s
5056internal breakpoints. If you see one of these warnings, you should
5057verify that a breakpoint set at the adjusted address will have the
5058desired affect. If not, the breakpoint in question may be removed and
b383017d 5059other breakpoints may be set which will have the desired behavior.
1485d690
KB
5060E.g., it may be sufficient to place the breakpoint at a later
5061instruction. A conditional breakpoint may also be useful in some
5062cases to prevent the breakpoint from triggering too often.
5063
5064@value{GDBN} will also issue a warning when stopping at one of these
5065adjusted breakpoints:
5066
5067@smallexample
5068warning: Breakpoint 1 address previously adjusted from 0x00010414
5069to 0x00010410.
5070@end smallexample
5071
5072When this warning is encountered, it may be too late to take remedial
5073action except in cases where the breakpoint is hit earlier or more
5074frequently than expected.
d4f3574e 5075
6d2ebf8b 5076@node Continuing and Stepping
79a6e687 5077@section Continuing and Stepping
c906108c
SS
5078
5079@cindex stepping
5080@cindex continuing
5081@cindex resuming execution
5082@dfn{Continuing} means resuming program execution until your program
5083completes normally. In contrast, @dfn{stepping} means executing just
5084one more ``step'' of your program, where ``step'' may mean either one
5085line of source code, or one machine instruction (depending on what
7a292a7a
SS
5086particular command you use). Either when continuing or when stepping,
5087your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
5088it stops due to a signal, you may want to use @code{handle}, or use
5089@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
5090
5091@table @code
5092@kindex continue
41afff9a
EZ
5093@kindex c @r{(@code{continue})}
5094@kindex fg @r{(resume foreground execution)}
c906108c
SS
5095@item continue @r{[}@var{ignore-count}@r{]}
5096@itemx c @r{[}@var{ignore-count}@r{]}
5097@itemx fg @r{[}@var{ignore-count}@r{]}
5098Resume program execution, at the address where your program last stopped;
5099any breakpoints set at that address are bypassed. The optional argument
5100@var{ignore-count} allows you to specify a further number of times to
5101ignore a breakpoint at this location; its effect is like that of
79a6e687 5102@code{ignore} (@pxref{Conditions, ,Break Conditions}).
c906108c
SS
5103
5104The argument @var{ignore-count} is meaningful only when your program
5105stopped due to a breakpoint. At other times, the argument to
5106@code{continue} is ignored.
5107
d4f3574e
SS
5108The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
5109debugged program is deemed to be the foreground program) are provided
5110purely for convenience, and have exactly the same behavior as
5111@code{continue}.
c906108c
SS
5112@end table
5113
5114To resume execution at a different place, you can use @code{return}
79a6e687 5115(@pxref{Returning, ,Returning from a Function}) to go back to the
c906108c 5116calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
79a6e687 5117Different Address}) to go to an arbitrary location in your program.
c906108c
SS
5118
5119A typical technique for using stepping is to set a breakpoint
79a6e687 5120(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
c906108c
SS
5121beginning of the function or the section of your program where a problem
5122is believed to lie, run your program until it stops at that breakpoint,
5123and then step through the suspect area, examining the variables that are
5124interesting, until you see the problem happen.
5125
5126@table @code
5127@kindex step
41afff9a 5128@kindex s @r{(@code{step})}
c906108c
SS
5129@item step
5130Continue running your program until control reaches a different source
5131line, then stop it and return control to @value{GDBN}. This command is
5132abbreviated @code{s}.
5133
5134@quotation
5135@c "without debugging information" is imprecise; actually "without line
5136@c numbers in the debugging information". (gcc -g1 has debugging info but
5137@c not line numbers). But it seems complex to try to make that
5138@c distinction here.
5139@emph{Warning:} If you use the @code{step} command while control is
5140within a function that was compiled without debugging information,
5141execution proceeds until control reaches a function that does have
5142debugging information. Likewise, it will not step into a function which
5143is compiled without debugging information. To step through functions
5144without debugging information, use the @code{stepi} command, described
5145below.
5146@end quotation
5147
4a92d011
EZ
5148The @code{step} command only stops at the first instruction of a source
5149line. This prevents the multiple stops that could otherwise occur in
5150@code{switch} statements, @code{for} loops, etc. @code{step} continues
5151to stop if a function that has debugging information is called within
5152the line. In other words, @code{step} @emph{steps inside} any functions
5153called within the line.
c906108c 5154
d4f3574e
SS
5155Also, the @code{step} command only enters a function if there is line
5156number information for the function. Otherwise it acts like the
5d161b24 5157@code{next} command. This avoids problems when using @code{cc -gl}
eb17f351 5158on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5d161b24 5159was any debugging information about the routine.
c906108c
SS
5160
5161@item step @var{count}
5162Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
5163breakpoint is reached, or a signal not related to stepping occurs before
5164@var{count} steps, stepping stops right away.
c906108c
SS
5165
5166@kindex next
41afff9a 5167@kindex n @r{(@code{next})}
c906108c
SS
5168@item next @r{[}@var{count}@r{]}
5169Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
5170This is similar to @code{step}, but function calls that appear within
5171the line of code are executed without stopping. Execution stops when
5172control reaches a different line of code at the original stack level
5173that was executing when you gave the @code{next} command. This command
5174is abbreviated @code{n}.
c906108c
SS
5175
5176An argument @var{count} is a repeat count, as for @code{step}.
5177
5178
5179@c FIX ME!! Do we delete this, or is there a way it fits in with
5180@c the following paragraph? --- Vctoria
5181@c
5182@c @code{next} within a function that lacks debugging information acts like
5183@c @code{step}, but any function calls appearing within the code of the
5184@c function are executed without stopping.
5185
d4f3574e
SS
5186The @code{next} command only stops at the first instruction of a
5187source line. This prevents multiple stops that could otherwise occur in
4a92d011 5188@code{switch} statements, @code{for} loops, etc.
c906108c 5189
b90a5f51
CF
5190@kindex set step-mode
5191@item set step-mode
5192@cindex functions without line info, and stepping
5193@cindex stepping into functions with no line info
5194@itemx set step-mode on
4a92d011 5195The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
5196stop at the first instruction of a function which contains no debug line
5197information rather than stepping over it.
5198
4a92d011
EZ
5199This is useful in cases where you may be interested in inspecting the
5200machine instructions of a function which has no symbolic info and do not
5201want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
5202
5203@item set step-mode off
4a92d011 5204Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
5205debug information. This is the default.
5206
9c16f35a
EZ
5207@item show step-mode
5208Show whether @value{GDBN} will stop in or step over functions without
5209source line debug information.
5210
c906108c 5211@kindex finish
8dfa32fc 5212@kindex fin @r{(@code{finish})}
c906108c
SS
5213@item finish
5214Continue running until just after function in the selected stack frame
8dfa32fc
JB
5215returns. Print the returned value (if any). This command can be
5216abbreviated as @code{fin}.
c906108c
SS
5217
5218Contrast this with the @code{return} command (@pxref{Returning,
79a6e687 5219,Returning from a Function}).
c906108c
SS
5220
5221@kindex until
41afff9a 5222@kindex u @r{(@code{until})}
09d4efe1 5223@cindex run until specified location
c906108c
SS
5224@item until
5225@itemx u
5226Continue running until a source line past the current line, in the
5227current stack frame, is reached. This command is used to avoid single
5228stepping through a loop more than once. It is like the @code{next}
5229command, except that when @code{until} encounters a jump, it
5230automatically continues execution until the program counter is greater
5231than the address of the jump.
5232
5233This means that when you reach the end of a loop after single stepping
5234though it, @code{until} makes your program continue execution until it
5235exits the loop. In contrast, a @code{next} command at the end of a loop
5236simply steps back to the beginning of the loop, which forces you to step
5237through the next iteration.
5238
5239@code{until} always stops your program if it attempts to exit the current
5240stack frame.
5241
5242@code{until} may produce somewhat counterintuitive results if the order
5243of machine code does not match the order of the source lines. For
5244example, in the following excerpt from a debugging session, the @code{f}
5245(@code{frame}) command shows that execution is stopped at line
5246@code{206}; yet when we use @code{until}, we get to line @code{195}:
5247
474c8240 5248@smallexample
c906108c
SS
5249(@value{GDBP}) f
5250#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
5251206 expand_input();
5252(@value{GDBP}) until
5253195 for ( ; argc > 0; NEXTARG) @{
474c8240 5254@end smallexample
c906108c
SS
5255
5256This happened because, for execution efficiency, the compiler had
5257generated code for the loop closure test at the end, rather than the
5258start, of the loop---even though the test in a C @code{for}-loop is
5259written before the body of the loop. The @code{until} command appeared
5260to step back to the beginning of the loop when it advanced to this
5261expression; however, it has not really gone to an earlier
5262statement---not in terms of the actual machine code.
5263
5264@code{until} with no argument works by means of single
5265instruction stepping, and hence is slower than @code{until} with an
5266argument.
5267
5268@item until @var{location}
5269@itemx u @var{location}
5270Continue running your program until either the specified location is
5271reached, or the current stack frame returns. @var{location} is any of
2a25a5ba
EZ
5272the forms described in @ref{Specify Location}.
5273This form of the command uses temporary breakpoints, and
c60eb6f1
EZ
5274hence is quicker than @code{until} without an argument. The specified
5275location is actually reached only if it is in the current frame. This
5276implies that @code{until} can be used to skip over recursive function
5277invocations. For instance in the code below, if the current location is
5278line @code{96}, issuing @code{until 99} will execute the program up to
db2e3e2e 5279line @code{99} in the same invocation of factorial, i.e., after the inner
c60eb6f1
EZ
5280invocations have returned.
5281
5282@smallexample
528394 int factorial (int value)
528495 @{
528596 if (value > 1) @{
528697 value *= factorial (value - 1);
528798 @}
528899 return (value);
5289100 @}
5290@end smallexample
5291
5292
5293@kindex advance @var{location}
984359d2 5294@item advance @var{location}
09d4efe1 5295Continue running the program up to the given @var{location}. An argument is
2a25a5ba
EZ
5296required, which should be of one of the forms described in
5297@ref{Specify Location}.
5298Execution will also stop upon exit from the current stack
c60eb6f1
EZ
5299frame. This command is similar to @code{until}, but @code{advance} will
5300not skip over recursive function calls, and the target location doesn't
5301have to be in the same frame as the current one.
5302
c906108c
SS
5303
5304@kindex stepi
41afff9a 5305@kindex si @r{(@code{stepi})}
c906108c 5306@item stepi
96a2c332 5307@itemx stepi @var{arg}
c906108c
SS
5308@itemx si
5309Execute one machine instruction, then stop and return to the debugger.
5310
5311It is often useful to do @samp{display/i $pc} when stepping by machine
5312instructions. This makes @value{GDBN} automatically display the next
5313instruction to be executed, each time your program stops. @xref{Auto
79a6e687 5314Display,, Automatic Display}.
c906108c
SS
5315
5316An argument is a repeat count, as in @code{step}.
5317
5318@need 750
5319@kindex nexti
41afff9a 5320@kindex ni @r{(@code{nexti})}
c906108c 5321@item nexti
96a2c332 5322@itemx nexti @var{arg}
c906108c
SS
5323@itemx ni
5324Execute one machine instruction, but if it is a function call,
5325proceed until the function returns.
5326
5327An argument is a repeat count, as in @code{next}.
c1e36e3e
PA
5328
5329@end table
5330
5331@anchor{range stepping}
5332@cindex range stepping
5333@cindex target-assisted range stepping
5334By default, and if available, @value{GDBN} makes use of
5335target-assisted @dfn{range stepping}. In other words, whenever you
5336use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
5337tells the target to step the corresponding range of instruction
5338addresses instead of issuing multiple single-steps. This speeds up
5339line stepping, particularly for remote targets. Ideally, there should
5340be no reason you would want to turn range stepping off. However, it's
5341possible that a bug in the debug info, a bug in the remote stub (for
5342remote targets), or even a bug in @value{GDBN} could make line
5343stepping behave incorrectly when target-assisted range stepping is
5344enabled. You can use the following command to turn off range stepping
5345if necessary:
5346
5347@table @code
5348@kindex set range-stepping
5349@kindex show range-stepping
5350@item set range-stepping
5351@itemx show range-stepping
5352Control whether range stepping is enabled.
5353
5354If @code{on}, and the target supports it, @value{GDBN} tells the
5355target to step a range of addresses itself, instead of issuing
5356multiple single-steps. If @code{off}, @value{GDBN} always issues
5357single-steps, even if range stepping is supported by the target. The
5358default is @code{on}.
5359
c906108c
SS
5360@end table
5361
aad1c02c
TT
5362@node Skipping Over Functions and Files
5363@section Skipping Over Functions and Files
1bfeeb0f
JL
5364@cindex skipping over functions and files
5365
5366The program you are debugging may contain some functions which are
5367uninteresting to debug. The @code{skip} comand lets you tell @value{GDBN} to
5368skip a function or all functions in a file when stepping.
5369
5370For example, consider the following C function:
5371
5372@smallexample
5373101 int func()
5374102 @{
5375103 foo(boring());
5376104 bar(boring());
5377105 @}
5378@end smallexample
5379
5380@noindent
5381Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
5382are not interested in stepping through @code{boring}. If you run @code{step}
5383at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
5384step over both @code{foo} and @code{boring}!
5385
5386One solution is to @code{step} into @code{boring} and use the @code{finish}
5387command to immediately exit it. But this can become tedious if @code{boring}
5388is called from many places.
5389
5390A more flexible solution is to execute @kbd{skip boring}. This instructs
5391@value{GDBN} never to step into @code{boring}. Now when you execute
5392@code{step} at line 103, you'll step over @code{boring} and directly into
5393@code{foo}.
5394
5395You can also instruct @value{GDBN} to skip all functions in a file, with, for
5396example, @code{skip file boring.c}.
5397
5398@table @code
5399@kindex skip function
5400@item skip @r{[}@var{linespec}@r{]}
5401@itemx skip function @r{[}@var{linespec}@r{]}
5402After running this command, the function named by @var{linespec} or the
5403function containing the line named by @var{linespec} will be skipped over when
983fb131 5404stepping. @xref{Specify Location}.
1bfeeb0f
JL
5405
5406If you do not specify @var{linespec}, the function you're currently debugging
5407will be skipped.
5408
5409(If you have a function called @code{file} that you want to skip, use
5410@kbd{skip function file}.)
5411
5412@kindex skip file
5413@item skip file @r{[}@var{filename}@r{]}
5414After running this command, any function whose source lives in @var{filename}
5415will be skipped over when stepping.
5416
5417If you do not specify @var{filename}, functions whose source lives in the file
5418you're currently debugging will be skipped.
5419@end table
5420
5421Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
5422These are the commands for managing your list of skips:
5423
5424@table @code
5425@kindex info skip
5426@item info skip @r{[}@var{range}@r{]}
5427Print details about the specified skip(s). If @var{range} is not specified,
5428print a table with details about all functions and files marked for skipping.
5429@code{info skip} prints the following information about each skip:
5430
5431@table @emph
5432@item Identifier
5433A number identifying this skip.
5434@item Type
5435The type of this skip, either @samp{function} or @samp{file}.
5436@item Enabled or Disabled
5437Enabled skips are marked with @samp{y}. Disabled skips are marked with @samp{n}.
5438@item Address
5439For function skips, this column indicates the address in memory of the function
5440being skipped. If you've set a function skip on a function which has not yet
5441been loaded, this field will contain @samp{<PENDING>}. Once a shared library
5442which has the function is loaded, @code{info skip} will show the function's
5443address here.
5444@item What
5445For file skips, this field contains the filename being skipped. For functions
5446skips, this field contains the function name and its line number in the file
5447where it is defined.
5448@end table
5449
5450@kindex skip delete
5451@item skip delete @r{[}@var{range}@r{]}
5452Delete the specified skip(s). If @var{range} is not specified, delete all
5453skips.
5454
5455@kindex skip enable
5456@item skip enable @r{[}@var{range}@r{]}
5457Enable the specified skip(s). If @var{range} is not specified, enable all
5458skips.
5459
5460@kindex skip disable
5461@item skip disable @r{[}@var{range}@r{]}
5462Disable the specified skip(s). If @var{range} is not specified, disable all
5463skips.
5464
5465@end table
5466
6d2ebf8b 5467@node Signals
c906108c
SS
5468@section Signals
5469@cindex signals
5470
5471A signal is an asynchronous event that can happen in a program. The
5472operating system defines the possible kinds of signals, and gives each
5473kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 5474signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
5475@code{SIGSEGV} is the signal a program gets from referencing a place in
5476memory far away from all the areas in use; @code{SIGALRM} occurs when
5477the alarm clock timer goes off (which happens only if your program has
5478requested an alarm).
5479
5480@cindex fatal signals
5481Some signals, including @code{SIGALRM}, are a normal part of the
5482functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 5483errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
5484program has not specified in advance some other way to handle the signal.
5485@code{SIGINT} does not indicate an error in your program, but it is normally
5486fatal so it can carry out the purpose of the interrupt: to kill the program.
5487
5488@value{GDBN} has the ability to detect any occurrence of a signal in your
5489program. You can tell @value{GDBN} in advance what to do for each kind of
5490signal.
5491
5492@cindex handling signals
24f93129
EZ
5493Normally, @value{GDBN} is set up to let the non-erroneous signals like
5494@code{SIGALRM} be silently passed to your program
5495(so as not to interfere with their role in the program's functioning)
c906108c
SS
5496but to stop your program immediately whenever an error signal happens.
5497You can change these settings with the @code{handle} command.
5498
5499@table @code
5500@kindex info signals
09d4efe1 5501@kindex info handle
c906108c 5502@item info signals
96a2c332 5503@itemx info handle
c906108c
SS
5504Print a table of all the kinds of signals and how @value{GDBN} has been told to
5505handle each one. You can use this to see the signal numbers of all
5506the defined types of signals.
5507
45ac1734
EZ
5508@item info signals @var{sig}
5509Similar, but print information only about the specified signal number.
5510
d4f3574e 5511@code{info handle} is an alias for @code{info signals}.
c906108c 5512
ab04a2af
TT
5513@item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
5514Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
5515for details about this command.
5516
c906108c 5517@kindex handle
45ac1734 5518@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
5ece1a18
EZ
5519Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
5520can be the number of a signal or its name (with or without the
24f93129 5521@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 5522@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
5523known signals. Optional arguments @var{keywords}, described below,
5524say what change to make.
c906108c
SS
5525@end table
5526
5527@c @group
5528The keywords allowed by the @code{handle} command can be abbreviated.
5529Their full names are:
5530
5531@table @code
5532@item nostop
5533@value{GDBN} should not stop your program when this signal happens. It may
5534still print a message telling you that the signal has come in.
5535
5536@item stop
5537@value{GDBN} should stop your program when this signal happens. This implies
5538the @code{print} keyword as well.
5539
5540@item print
5541@value{GDBN} should print a message when this signal happens.
5542
5543@item noprint
5544@value{GDBN} should not mention the occurrence of the signal at all. This
5545implies the @code{nostop} keyword as well.
5546
5547@item pass
5ece1a18 5548@itemx noignore
c906108c
SS
5549@value{GDBN} should allow your program to see this signal; your program
5550can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 5551and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
5552
5553@item nopass
5ece1a18 5554@itemx ignore
c906108c 5555@value{GDBN} should not allow your program to see this signal.
5ece1a18 5556@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
5557@end table
5558@c @end group
5559
d4f3574e
SS
5560When a signal stops your program, the signal is not visible to the
5561program until you
c906108c
SS
5562continue. Your program sees the signal then, if @code{pass} is in
5563effect for the signal in question @emph{at that time}. In other words,
5564after @value{GDBN} reports a signal, you can use the @code{handle}
5565command with @code{pass} or @code{nopass} to control whether your
5566program sees that signal when you continue.
5567
24f93129
EZ
5568The default is set to @code{nostop}, @code{noprint}, @code{pass} for
5569non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
5570@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
5571erroneous signals.
5572
c906108c
SS
5573You can also use the @code{signal} command to prevent your program from
5574seeing a signal, or cause it to see a signal it normally would not see,
5575or to give it any signal at any time. For example, if your program stopped
5576due to some sort of memory reference error, you might store correct
5577values into the erroneous variables and continue, hoping to see more
5578execution; but your program would probably terminate immediately as
5579a result of the fatal signal once it saw the signal. To prevent this,
5580you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
79a6e687 5581Program a Signal}.
c906108c 5582
4aa995e1
PA
5583@cindex extra signal information
5584@anchor{extra signal information}
5585
5586On some targets, @value{GDBN} can inspect extra signal information
5587associated with the intercepted signal, before it is actually
5588delivered to the program being debugged. This information is exported
5589by the convenience variable @code{$_siginfo}, and consists of data
5590that is passed by the kernel to the signal handler at the time of the
5591receipt of a signal. The data type of the information itself is
5592target dependent. You can see the data type using the @code{ptype
5593$_siginfo} command. On Unix systems, it typically corresponds to the
5594standard @code{siginfo_t} type, as defined in the @file{signal.h}
5595system header.
5596
5597Here's an example, on a @sc{gnu}/Linux system, printing the stray
5598referenced address that raised a segmentation fault.
5599
5600@smallexample
5601@group
5602(@value{GDBP}) continue
5603Program received signal SIGSEGV, Segmentation fault.
56040x0000000000400766 in main ()
560569 *(int *)p = 0;
5606(@value{GDBP}) ptype $_siginfo
5607type = struct @{
5608 int si_signo;
5609 int si_errno;
5610 int si_code;
5611 union @{
5612 int _pad[28];
5613 struct @{...@} _kill;
5614 struct @{...@} _timer;
5615 struct @{...@} _rt;
5616 struct @{...@} _sigchld;
5617 struct @{...@} _sigfault;
5618 struct @{...@} _sigpoll;
5619 @} _sifields;
5620@}
5621(@value{GDBP}) ptype $_siginfo._sifields._sigfault
5622type = struct @{
5623 void *si_addr;
5624@}
5625(@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
5626$1 = (void *) 0x7ffff7ff7000
5627@end group
5628@end smallexample
5629
5630Depending on target support, @code{$_siginfo} may also be writable.
5631
6d2ebf8b 5632@node Thread Stops
79a6e687 5633@section Stopping and Starting Multi-thread Programs
c906108c 5634
0606b73b
SL
5635@cindex stopped threads
5636@cindex threads, stopped
5637
5638@cindex continuing threads
5639@cindex threads, continuing
5640
5641@value{GDBN} supports debugging programs with multiple threads
5642(@pxref{Threads,, Debugging Programs with Multiple Threads}). There
5643are two modes of controlling execution of your program within the
5644debugger. In the default mode, referred to as @dfn{all-stop mode},
5645when any thread in your program stops (for example, at a breakpoint
5646or while being stepped), all other threads in the program are also stopped by
5647@value{GDBN}. On some targets, @value{GDBN} also supports
5648@dfn{non-stop mode}, in which other threads can continue to run freely while
5649you examine the stopped thread in the debugger.
5650
5651@menu
5652* All-Stop Mode:: All threads stop when GDB takes control
5653* Non-Stop Mode:: Other threads continue to execute
5654* Background Execution:: Running your program asynchronously
5655* Thread-Specific Breakpoints:: Controlling breakpoints
5656* Interrupted System Calls:: GDB may interfere with system calls
d914c394 5657* Observer Mode:: GDB does not alter program behavior
0606b73b
SL
5658@end menu
5659
5660@node All-Stop Mode
5661@subsection All-Stop Mode
5662
5663@cindex all-stop mode
5664
5665In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
5666@emph{all} threads of execution stop, not just the current thread. This
5667allows you to examine the overall state of the program, including
5668switching between threads, without worrying that things may change
5669underfoot.
5670
5671Conversely, whenever you restart the program, @emph{all} threads start
5672executing. @emph{This is true even when single-stepping} with commands
5673like @code{step} or @code{next}.
5674
5675In particular, @value{GDBN} cannot single-step all threads in lockstep.
5676Since thread scheduling is up to your debugging target's operating
5677system (not controlled by @value{GDBN}), other threads may
5678execute more than one statement while the current thread completes a
5679single step. Moreover, in general other threads stop in the middle of a
5680statement, rather than at a clean statement boundary, when the program
5681stops.
5682
5683You might even find your program stopped in another thread after
5684continuing or even single-stepping. This happens whenever some other
5685thread runs into a breakpoint, a signal, or an exception before the
5686first thread completes whatever you requested.
5687
5688@cindex automatic thread selection
5689@cindex switching threads automatically
5690@cindex threads, automatic switching
5691Whenever @value{GDBN} stops your program, due to a breakpoint or a
5692signal, it automatically selects the thread where that breakpoint or
5693signal happened. @value{GDBN} alerts you to the context switch with a
5694message such as @samp{[Switching to Thread @var{n}]} to identify the
5695thread.
5696
5697On some OSes, you can modify @value{GDBN}'s default behavior by
5698locking the OS scheduler to allow only a single thread to run.
5699
5700@table @code
5701@item set scheduler-locking @var{mode}
5702@cindex scheduler locking mode
5703@cindex lock scheduler
5704Set the scheduler locking mode. If it is @code{off}, then there is no
5705locking and any thread may run at any time. If @code{on}, then only the
5706current thread may run when the inferior is resumed. The @code{step}
5707mode optimizes for single-stepping; it prevents other threads
5708from preempting the current thread while you are stepping, so that
5709the focus of debugging does not change unexpectedly.
5710Other threads only rarely (or never) get a chance to run
5711when you step. They are more likely to run when you @samp{next} over a
5712function call, and they are completely free to run when you use commands
5713like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
5714thread hits a breakpoint during its timeslice, @value{GDBN} does not change
5715the current thread away from the thread that you are debugging.
5716
5717@item show scheduler-locking
5718Display the current scheduler locking mode.
5719@end table
5720
d4db2f36
PA
5721@cindex resume threads of multiple processes simultaneously
5722By default, when you issue one of the execution commands such as
5723@code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
5724threads of the current inferior to run. For example, if @value{GDBN}
5725is attached to two inferiors, each with two threads, the
5726@code{continue} command resumes only the two threads of the current
5727inferior. This is useful, for example, when you debug a program that
5728forks and you want to hold the parent stopped (so that, for instance,
5729it doesn't run to exit), while you debug the child. In other
5730situations, you may not be interested in inspecting the current state
5731of any of the processes @value{GDBN} is attached to, and you may want
5732to resume them all until some breakpoint is hit. In the latter case,
5733you can instruct @value{GDBN} to allow all threads of all the
5734inferiors to run with the @w{@code{set schedule-multiple}} command.
5735
5736@table @code
5737@kindex set schedule-multiple
5738@item set schedule-multiple
5739Set the mode for allowing threads of multiple processes to be resumed
5740when an execution command is issued. When @code{on}, all threads of
5741all processes are allowed to run. When @code{off}, only the threads
5742of the current process are resumed. The default is @code{off}. The
5743@code{scheduler-locking} mode takes precedence when set to @code{on},
5744or while you are stepping and set to @code{step}.
5745
5746@item show schedule-multiple
5747Display the current mode for resuming the execution of threads of
5748multiple processes.
5749@end table
5750
0606b73b
SL
5751@node Non-Stop Mode
5752@subsection Non-Stop Mode
5753
5754@cindex non-stop mode
5755
5756@c This section is really only a place-holder, and needs to be expanded
97d8f0ee 5757@c with more details.
0606b73b
SL
5758
5759For some multi-threaded targets, @value{GDBN} supports an optional
5760mode of operation in which you can examine stopped program threads in
5761the debugger while other threads continue to execute freely. This
97d8f0ee
DE
5762minimizes intrusion when debugging live systems, such as programs
5763where some threads have real-time constraints or must continue to
0606b73b
SL
5764respond to external events. This is referred to as @dfn{non-stop} mode.
5765
5766In non-stop mode, when a thread stops to report a debugging event,
5767@emph{only} that thread is stopped; @value{GDBN} does not stop other
5768threads as well, in contrast to the all-stop mode behavior. Additionally,
5769execution commands such as @code{continue} and @code{step} apply by default
5770only to the current thread in non-stop mode, rather than all threads as
5771in all-stop mode. This allows you to control threads explicitly in
97d8f0ee 5772ways that are not possible in all-stop mode --- for example, stepping
0606b73b 5773one thread while allowing others to run freely, stepping
97d8f0ee 5774one thread while holding all others stopped, or stepping several threads
0606b73b
SL
5775independently and simultaneously.
5776
5777To enter non-stop mode, use this sequence of commands before you run
5778or attach to your program:
5779
0606b73b 5780@smallexample
97d8f0ee 5781# Enable the async interface.
c6ebd6cf 5782set target-async 1
0606b73b 5783
0606b73b
SL
5784# If using the CLI, pagination breaks non-stop.
5785set pagination off
5786
5787# Finally, turn it on!
5788set non-stop on
5789@end smallexample
5790
5791You can use these commands to manipulate the non-stop mode setting:
5792
5793@table @code
5794@kindex set non-stop
5795@item set non-stop on
5796Enable selection of non-stop mode.
5797@item set non-stop off
5798Disable selection of non-stop mode.
5799@kindex show non-stop
5800@item show non-stop
5801Show the current non-stop enablement setting.
5802@end table
5803
5804Note these commands only reflect whether non-stop mode is enabled,
97d8f0ee 5805not whether the currently-executing program is being run in non-stop mode.
0606b73b 5806In particular, the @code{set non-stop} preference is only consulted when
97d8f0ee 5807@value{GDBN} starts or connects to the target program, and it is generally
0606b73b
SL
5808not possible to switch modes once debugging has started. Furthermore,
5809since not all targets support non-stop mode, even when you have enabled
5810non-stop mode, @value{GDBN} may still fall back to all-stop operation by
5811default.
5812
5813In non-stop mode, all execution commands apply only to the current thread
97d8f0ee 5814by default. That is, @code{continue} only continues one thread.
0606b73b
SL
5815To continue all threads, issue @code{continue -a} or @code{c -a}.
5816
97d8f0ee 5817You can use @value{GDBN}'s background execution commands
0606b73b 5818(@pxref{Background Execution}) to run some threads in the background
97d8f0ee 5819while you continue to examine or step others from @value{GDBN}.
0606b73b
SL
5820The MI execution commands (@pxref{GDB/MI Program Execution}) are
5821always executed asynchronously in non-stop mode.
5822
5823Suspending execution is done with the @code{interrupt} command when
97d8f0ee
DE
5824running in the background, or @kbd{Ctrl-c} during foreground execution.
5825In all-stop mode, this stops the whole process;
5826but in non-stop mode the interrupt applies only to the current thread.
0606b73b
SL
5827To stop the whole program, use @code{interrupt -a}.
5828
5829Other execution commands do not currently support the @code{-a} option.
5830
5831In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
5832that thread current, as it does in all-stop mode. This is because the
97d8f0ee 5833thread stop notifications are asynchronous with respect to @value{GDBN}'s
0606b73b
SL
5834command interpreter, and it would be confusing if @value{GDBN} unexpectedly
5835changed to a different thread just as you entered a command to operate on the
5836previously current thread.
5837
5838@node Background Execution
5839@subsection Background Execution
5840
5841@cindex foreground execution
5842@cindex background execution
5843@cindex asynchronous execution
5844@cindex execution, foreground, background and asynchronous
5845
5846@value{GDBN}'s execution commands have two variants: the normal
5847foreground (synchronous) behavior, and a background
97d8f0ee 5848(asynchronous) behavior. In foreground execution, @value{GDBN} waits for
0606b73b
SL
5849the program to report that some thread has stopped before prompting for
5850another command. In background execution, @value{GDBN} immediately gives
5851a command prompt so that you can issue other commands while your program runs.
5852
32fc0df9
PA
5853You need to explicitly enable asynchronous mode before you can use
5854background execution commands. You can use these commands to
5855manipulate the asynchronous mode setting:
5856
5857@table @code
5858@kindex set target-async
5859@item set target-async on
5860Enable asynchronous mode.
5861@item set target-async off
5862Disable asynchronous mode.
5863@kindex show target-async
5864@item show target-async
5865Show the current target-async setting.
5866@end table
5867
5868If the target doesn't support async mode, @value{GDBN} issues an error
5869message if you attempt to use the background execution commands.
5870
0606b73b
SL
5871To specify background execution, add a @code{&} to the command. For example,
5872the background form of the @code{continue} command is @code{continue&}, or
5873just @code{c&}. The execution commands that accept background execution
5874are:
5875
5876@table @code
5877@kindex run&
5878@item run
5879@xref{Starting, , Starting your Program}.
5880
5881@item attach
5882@kindex attach&
5883@xref{Attach, , Debugging an Already-running Process}.
5884
5885@item step
5886@kindex step&
5887@xref{Continuing and Stepping, step}.
5888
5889@item stepi
5890@kindex stepi&
5891@xref{Continuing and Stepping, stepi}.
5892
5893@item next
5894@kindex next&
5895@xref{Continuing and Stepping, next}.
5896
7ce58dd2
DE
5897@item nexti
5898@kindex nexti&
5899@xref{Continuing and Stepping, nexti}.
5900
0606b73b
SL
5901@item continue
5902@kindex continue&
5903@xref{Continuing and Stepping, continue}.
5904
5905@item finish
5906@kindex finish&
5907@xref{Continuing and Stepping, finish}.
5908
5909@item until
5910@kindex until&
5911@xref{Continuing and Stepping, until}.
5912
5913@end table
5914
5915Background execution is especially useful in conjunction with non-stop
5916mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
5917However, you can also use these commands in the normal all-stop mode with
5918the restriction that you cannot issue another execution command until the
5919previous one finishes. Examples of commands that are valid in all-stop
5920mode while the program is running include @code{help} and @code{info break}.
5921
5922You can interrupt your program while it is running in the background by
5923using the @code{interrupt} command.
5924
5925@table @code
5926@kindex interrupt
5927@item interrupt
5928@itemx interrupt -a
5929
97d8f0ee 5930Suspend execution of the running program. In all-stop mode,
0606b73b 5931@code{interrupt} stops the whole process, but in non-stop mode, it stops
97d8f0ee 5932only the current thread. To stop the whole program in non-stop mode,
0606b73b
SL
5933use @code{interrupt -a}.
5934@end table
5935
0606b73b
SL
5936@node Thread-Specific Breakpoints
5937@subsection Thread-Specific Breakpoints
5938
c906108c 5939When your program has multiple threads (@pxref{Threads,, Debugging
79a6e687 5940Programs with Multiple Threads}), you can choose whether to set
c906108c
SS
5941breakpoints on all threads, or on a particular thread.
5942
5943@table @code
5944@cindex breakpoints and threads
5945@cindex thread breakpoints
5946@kindex break @dots{} thread @var{threadno}
5947@item break @var{linespec} thread @var{threadno}
5948@itemx break @var{linespec} thread @var{threadno} if @dots{}
5949@var{linespec} specifies source lines; there are several ways of
2a25a5ba
EZ
5950writing them (@pxref{Specify Location}), but the effect is always to
5951specify some source line.
c906108c
SS
5952
5953Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
5954to specify that you only want @value{GDBN} to stop the program when a
5955particular thread reaches this breakpoint. @var{threadno} is one of the
5956numeric thread identifiers assigned by @value{GDBN}, shown in the first
5957column of the @samp{info threads} display.
5958
5959If you do not specify @samp{thread @var{threadno}} when you set a
5960breakpoint, the breakpoint applies to @emph{all} threads of your
5961program.
5962
5963You can use the @code{thread} qualifier on conditional breakpoints as
b6199126
DJ
5964well; in this case, place @samp{thread @var{threadno}} before or
5965after the breakpoint condition, like this:
c906108c
SS
5966
5967@smallexample
2df3850c 5968(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
5969@end smallexample
5970
5971@end table
5972
f4fb82a1
PA
5973Thread-specific breakpoints are automatically deleted when
5974@value{GDBN} detects the corresponding thread is no longer in the
5975thread list. For example:
5976
5977@smallexample
5978(@value{GDBP}) c
5979Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
5980@end smallexample
5981
5982There are several ways for a thread to disappear, such as a regular
5983thread exit, but also when you detach from the process with the
5984@code{detach} command (@pxref{Attach, ,Debugging an Already-running
5985Process}), or if @value{GDBN} loses the remote connection
5986(@pxref{Remote Debugging}), etc. Note that with some targets,
5987@value{GDBN} is only able to detect a thread has exited when the user
5988explictly asks for the thread list with the @code{info threads}
5989command.
5990
0606b73b
SL
5991@node Interrupted System Calls
5992@subsection Interrupted System Calls
c906108c 5993
36d86913
MC
5994@cindex thread breakpoints and system calls
5995@cindex system calls and thread breakpoints
5996@cindex premature return from system calls
0606b73b
SL
5997There is an unfortunate side effect when using @value{GDBN} to debug
5998multi-threaded programs. If one thread stops for a
36d86913
MC
5999breakpoint, or for some other reason, and another thread is blocked in a
6000system call, then the system call may return prematurely. This is a
6001consequence of the interaction between multiple threads and the signals
6002that @value{GDBN} uses to implement breakpoints and other events that
6003stop execution.
6004
6005To handle this problem, your program should check the return value of
6006each system call and react appropriately. This is good programming
6007style anyways.
6008
6009For example, do not write code like this:
6010
6011@smallexample
6012 sleep (10);
6013@end smallexample
6014
6015The call to @code{sleep} will return early if a different thread stops
6016at a breakpoint or for some other reason.
6017
6018Instead, write this:
6019
6020@smallexample
6021 int unslept = 10;
6022 while (unslept > 0)
6023 unslept = sleep (unslept);
6024@end smallexample
6025
6026A system call is allowed to return early, so the system is still
6027conforming to its specification. But @value{GDBN} does cause your
6028multi-threaded program to behave differently than it would without
6029@value{GDBN}.
6030
6031Also, @value{GDBN} uses internal breakpoints in the thread library to
6032monitor certain events such as thread creation and thread destruction.
6033When such an event happens, a system call in another thread may return
6034prematurely, even though your program does not appear to stop.
6035
d914c394
SS
6036@node Observer Mode
6037@subsection Observer Mode
6038
6039If you want to build on non-stop mode and observe program behavior
6040without any chance of disruption by @value{GDBN}, you can set
6041variables to disable all of the debugger's attempts to modify state,
6042whether by writing memory, inserting breakpoints, etc. These operate
6043at a low level, intercepting operations from all commands.
6044
6045When all of these are set to @code{off}, then @value{GDBN} is said to
6046be @dfn{observer mode}. As a convenience, the variable
6047@code{observer} can be set to disable these, plus enable non-stop
6048mode.
6049
6050Note that @value{GDBN} will not prevent you from making nonsensical
6051combinations of these settings. For instance, if you have enabled
6052@code{may-insert-breakpoints} but disabled @code{may-write-memory},
6053then breakpoints that work by writing trap instructions into the code
6054stream will still not be able to be placed.
6055
6056@table @code
6057
6058@kindex observer
6059@item set observer on
6060@itemx set observer off
6061When set to @code{on}, this disables all the permission variables
6062below (except for @code{insert-fast-tracepoints}), plus enables
6063non-stop debugging. Setting this to @code{off} switches back to
6064normal debugging, though remaining in non-stop mode.
6065
6066@item show observer
6067Show whether observer mode is on or off.
6068
6069@kindex may-write-registers
6070@item set may-write-registers on
6071@itemx set may-write-registers off
6072This controls whether @value{GDBN} will attempt to alter the values of
6073registers, such as with assignment expressions in @code{print}, or the
6074@code{jump} command. It defaults to @code{on}.
6075
6076@item show may-write-registers
6077Show the current permission to write registers.
6078
6079@kindex may-write-memory
6080@item set may-write-memory on
6081@itemx set may-write-memory off
6082This controls whether @value{GDBN} will attempt to alter the contents
6083of memory, such as with assignment expressions in @code{print}. It
6084defaults to @code{on}.
6085
6086@item show may-write-memory
6087Show the current permission to write memory.
6088
6089@kindex may-insert-breakpoints
6090@item set may-insert-breakpoints on
6091@itemx set may-insert-breakpoints off
6092This controls whether @value{GDBN} will attempt to insert breakpoints.
6093This affects all breakpoints, including internal breakpoints defined
6094by @value{GDBN}. It defaults to @code{on}.
6095
6096@item show may-insert-breakpoints
6097Show the current permission to insert breakpoints.
6098
6099@kindex may-insert-tracepoints
6100@item set may-insert-tracepoints on
6101@itemx set may-insert-tracepoints off
6102This controls whether @value{GDBN} will attempt to insert (regular)
6103tracepoints at the beginning of a tracing experiment. It affects only
6104non-fast tracepoints, fast tracepoints being under the control of
6105@code{may-insert-fast-tracepoints}. It defaults to @code{on}.
6106
6107@item show may-insert-tracepoints
6108Show the current permission to insert tracepoints.
6109
6110@kindex may-insert-fast-tracepoints
6111@item set may-insert-fast-tracepoints on
6112@itemx set may-insert-fast-tracepoints off
6113This controls whether @value{GDBN} will attempt to insert fast
6114tracepoints at the beginning of a tracing experiment. It affects only
6115fast tracepoints, regular (non-fast) tracepoints being under the
6116control of @code{may-insert-tracepoints}. It defaults to @code{on}.
6117
6118@item show may-insert-fast-tracepoints
6119Show the current permission to insert fast tracepoints.
6120
6121@kindex may-interrupt
6122@item set may-interrupt on
6123@itemx set may-interrupt off
6124This controls whether @value{GDBN} will attempt to interrupt or stop
6125program execution. When this variable is @code{off}, the
6126@code{interrupt} command will have no effect, nor will
6127@kbd{Ctrl-c}. It defaults to @code{on}.
6128
6129@item show may-interrupt
6130Show the current permission to interrupt or stop the program.
6131
6132@end table
c906108c 6133
bacec72f
MS
6134@node Reverse Execution
6135@chapter Running programs backward
6136@cindex reverse execution
6137@cindex running programs backward
6138
6139When you are debugging a program, it is not unusual to realize that
6140you have gone too far, and some event of interest has already happened.
6141If the target environment supports it, @value{GDBN} can allow you to
6142``rewind'' the program by running it backward.
6143
6144A target environment that supports reverse execution should be able
6145to ``undo'' the changes in machine state that have taken place as the
6146program was executing normally. Variables, registers etc.@: should
6147revert to their previous values. Obviously this requires a great
6148deal of sophistication on the part of the target environment; not
6149all target environments can support reverse execution.
6150
6151When a program is executed in reverse, the instructions that
6152have most recently been executed are ``un-executed'', in reverse
6153order. The program counter runs backward, following the previous
6154thread of execution in reverse. As each instruction is ``un-executed'',
6155the values of memory and/or registers that were changed by that
6156instruction are reverted to their previous states. After executing
6157a piece of source code in reverse, all side effects of that code
6158should be ``undone'', and all variables should be returned to their
6159prior values@footnote{
6160Note that some side effects are easier to undo than others. For instance,
6161memory and registers are relatively easy, but device I/O is hard. Some
6162targets may be able undo things like device I/O, and some may not.
6163
6164The contract between @value{GDBN} and the reverse executing target
6165requires only that the target do something reasonable when
6166@value{GDBN} tells it to execute backwards, and then report the
6167results back to @value{GDBN}. Whatever the target reports back to
6168@value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
6169assumes that the memory and registers that the target reports are in a
6170consistant state, but @value{GDBN} accepts whatever it is given.
6171}.
6172
6173If you are debugging in a target environment that supports
6174reverse execution, @value{GDBN} provides the following commands.
6175
6176@table @code
6177@kindex reverse-continue
6178@kindex rc @r{(@code{reverse-continue})}
6179@item reverse-continue @r{[}@var{ignore-count}@r{]}
6180@itemx rc @r{[}@var{ignore-count}@r{]}
6181Beginning at the point where your program last stopped, start executing
6182in reverse. Reverse execution will stop for breakpoints and synchronous
6183exceptions (signals), just like normal execution. Behavior of
6184asynchronous signals depends on the target environment.
6185
6186@kindex reverse-step
6187@kindex rs @r{(@code{step})}
6188@item reverse-step @r{[}@var{count}@r{]}
6189Run the program backward until control reaches the start of a
6190different source line; then stop it, and return control to @value{GDBN}.
6191
6192Like the @code{step} command, @code{reverse-step} will only stop
6193at the beginning of a source line. It ``un-executes'' the previously
6194executed source line. If the previous source line included calls to
6195debuggable functions, @code{reverse-step} will step (backward) into
6196the called function, stopping at the beginning of the @emph{last}
6197statement in the called function (typically a return statement).
6198
6199Also, as with the @code{step} command, if non-debuggable functions are
6200called, @code{reverse-step} will run thru them backward without stopping.
6201
6202@kindex reverse-stepi
6203@kindex rsi @r{(@code{reverse-stepi})}
6204@item reverse-stepi @r{[}@var{count}@r{]}
6205Reverse-execute one machine instruction. Note that the instruction
6206to be reverse-executed is @emph{not} the one pointed to by the program
6207counter, but the instruction executed prior to that one. For instance,
6208if the last instruction was a jump, @code{reverse-stepi} will take you
6209back from the destination of the jump to the jump instruction itself.
6210
6211@kindex reverse-next
6212@kindex rn @r{(@code{reverse-next})}
6213@item reverse-next @r{[}@var{count}@r{]}
6214Run backward to the beginning of the previous line executed in
6215the current (innermost) stack frame. If the line contains function
6216calls, they will be ``un-executed'' without stopping. Starting from
6217the first line of a function, @code{reverse-next} will take you back
6218to the caller of that function, @emph{before} the function was called,
6219just as the normal @code{next} command would take you from the last
6220line of a function back to its return to its caller
16af530a 6221@footnote{Unless the code is too heavily optimized.}.
bacec72f
MS
6222
6223@kindex reverse-nexti
6224@kindex rni @r{(@code{reverse-nexti})}
6225@item reverse-nexti @r{[}@var{count}@r{]}
6226Like @code{nexti}, @code{reverse-nexti} executes a single instruction
6227in reverse, except that called functions are ``un-executed'' atomically.
6228That is, if the previously executed instruction was a return from
540aa8e7 6229another function, @code{reverse-nexti} will continue to execute
bacec72f
MS
6230in reverse until the call to that function (from the current stack
6231frame) is reached.
6232
6233@kindex reverse-finish
6234@item reverse-finish
6235Just as the @code{finish} command takes you to the point where the
6236current function returns, @code{reverse-finish} takes you to the point
6237where it was called. Instead of ending up at the end of the current
6238function invocation, you end up at the beginning.
6239
6240@kindex set exec-direction
6241@item set exec-direction
6242Set the direction of target execution.
984359d2 6243@item set exec-direction reverse
bacec72f
MS
6244@cindex execute forward or backward in time
6245@value{GDBN} will perform all execution commands in reverse, until the
6246exec-direction mode is changed to ``forward''. Affected commands include
6247@code{step, stepi, next, nexti, continue, and finish}. The @code{return}
6248command cannot be used in reverse mode.
6249@item set exec-direction forward
6250@value{GDBN} will perform all execution commands in the normal fashion.
6251This is the default.
6252@end table
6253
c906108c 6254
a2311334
EZ
6255@node Process Record and Replay
6256@chapter Recording Inferior's Execution and Replaying It
53cc454a
HZ
6257@cindex process record and replay
6258@cindex recording inferior's execution and replaying it
6259
8e05493c
EZ
6260On some platforms, @value{GDBN} provides a special @dfn{process record
6261and replay} target that can record a log of the process execution, and
6262replay it later with both forward and reverse execution commands.
a2311334
EZ
6263
6264@cindex replay mode
6265When this target is in use, if the execution log includes the record
6266for the next instruction, @value{GDBN} will debug in @dfn{replay
6267mode}. In the replay mode, the inferior does not really execute code
6268instructions. Instead, all the events that normally happen during
6269code execution are taken from the execution log. While code is not
6270really executed in replay mode, the values of registers (including the
6271program counter register) and the memory of the inferior are still
8e05493c
EZ
6272changed as they normally would. Their contents are taken from the
6273execution log.
a2311334
EZ
6274
6275@cindex record mode
6276If the record for the next instruction is not in the execution log,
6277@value{GDBN} will debug in @dfn{record mode}. In this mode, the
6278inferior executes normally, and @value{GDBN} records the execution log
6279for future replay.
6280
8e05493c
EZ
6281The process record and replay target supports reverse execution
6282(@pxref{Reverse Execution}), even if the platform on which the
6283inferior runs does not. However, the reverse execution is limited in
6284this case by the range of the instructions recorded in the execution
6285log. In other words, reverse execution on platforms that don't
6286support it directly can only be done in the replay mode.
6287
6288When debugging in the reverse direction, @value{GDBN} will work in
6289replay mode as long as the execution log includes the record for the
6290previous instruction; otherwise, it will work in record mode, if the
6291platform supports reverse execution, or stop if not.
6292
a2311334
EZ
6293For architecture environments that support process record and replay,
6294@value{GDBN} provides the following commands:
53cc454a
HZ
6295
6296@table @code
6297@kindex target record
59ea5688
MM
6298@kindex target record-full
6299@kindex target record-btrace
53cc454a 6300@kindex record
59ea5688
MM
6301@kindex record full
6302@kindex record btrace
53cc454a 6303@kindex rec
59ea5688
MM
6304@kindex rec full
6305@kindex rec btrace
6306@item record @var{method}
6307This command starts the process record and replay target. The
6308recording method can be specified as parameter. Without a parameter
6309the command uses the @code{full} recording method. The following
6310recording methods are available:
a2311334 6311
59ea5688
MM
6312@table @code
6313@item full
6314Full record/replay recording using @value{GDBN}'s software record and
6315replay implementation. This method allows replaying and reverse
6316execution.
6317
6318@item btrace
52834460
MM
6319Hardware-supported instruction recording. This method does not record
6320data. Further, the data is collected in a ring buffer so old data will
6321be overwritten when the buffer is full. It allows limited replay and
6322reverse execution.
59ea5688
MM
6323
6324This recording method may not be available on all processors.
6325@end table
6326
6327The process record and replay target can only debug a process that is
6328already running. Therefore, you need first to start the process with
6329the @kbd{run} or @kbd{start} commands, and then start the recording
6330with the @kbd{record @var{method}} command.
6331
6332Both @code{record @var{method}} and @code{rec @var{method}} are
6333aliases of @code{target record-@var{method}}.
a2311334
EZ
6334
6335@cindex displaced stepping, and process record and replay
6336Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
6337will be automatically disabled when process record and replay target
6338is started. That's because the process record and replay target
6339doesn't support displaced stepping.
6340
6341@cindex non-stop mode, and process record and replay
6342@cindex asynchronous execution, and process record and replay
6343If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
59ea5688
MM
6344the asynchronous execution mode (@pxref{Background Execution}), not
6345all recording methods are available. The @code{full} recording method
6346does not support these two modes.
53cc454a
HZ
6347
6348@kindex record stop
6349@kindex rec s
6350@item record stop
a2311334
EZ
6351Stop the process record and replay target. When process record and
6352replay target stops, the entire execution log will be deleted and the
6353inferior will either be terminated, or will remain in its final state.
53cc454a 6354
a2311334
EZ
6355When you stop the process record and replay target in record mode (at
6356the end of the execution log), the inferior will be stopped at the
6357next instruction that would have been recorded. In other words, if
6358you record for a while and then stop recording, the inferior process
6359will be left in the same state as if the recording never happened.
53cc454a 6360
a2311334
EZ
6361On the other hand, if the process record and replay target is stopped
6362while in replay mode (that is, not at the end of the execution log,
6363but at some earlier point), the inferior process will become ``live''
6364at that earlier state, and it will then be possible to continue the
6365usual ``live'' debugging of the process from that state.
53cc454a 6366
a2311334
EZ
6367When the inferior process exits, or @value{GDBN} detaches from it,
6368process record and replay target will automatically stop itself.
53cc454a 6369
742ce053
MM
6370@kindex record goto
6371@item record goto
6372Go to a specific location in the execution log. There are several
6373ways to specify the location to go to:
6374
6375@table @code
6376@item record goto begin
6377@itemx record goto start
6378Go to the beginning of the execution log.
6379
6380@item record goto end
6381Go to the end of the execution log.
6382
6383@item record goto @var{n}
6384Go to instruction number @var{n} in the execution log.
6385@end table
6386
24e933df
HZ
6387@kindex record save
6388@item record save @var{filename}
6389Save the execution log to a file @file{@var{filename}}.
6390Default filename is @file{gdb_record.@var{process_id}}, where
6391@var{process_id} is the process ID of the inferior.
6392
59ea5688
MM
6393This command may not be available for all recording methods.
6394
24e933df
HZ
6395@kindex record restore
6396@item record restore @var{filename}
6397Restore the execution log from a file @file{@var{filename}}.
6398File must have been created with @code{record save}.
6399
59ea5688
MM
6400@kindex set record full
6401@item set record full insn-number-max @var{limit}
f81d1120 6402@itemx set record full insn-number-max unlimited
59ea5688
MM
6403Set the limit of instructions to be recorded for the @code{full}
6404recording method. Default value is 200000.
53cc454a 6405
a2311334
EZ
6406If @var{limit} is a positive number, then @value{GDBN} will start
6407deleting instructions from the log once the number of the record
6408instructions becomes greater than @var{limit}. For every new recorded
6409instruction, @value{GDBN} will delete the earliest recorded
6410instruction to keep the number of recorded instructions at the limit.
6411(Since deleting recorded instructions loses information, @value{GDBN}
6412lets you control what happens when the limit is reached, by means of
6413the @code{stop-at-limit} option, described below.)
53cc454a 6414
f81d1120
PA
6415If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
6416delete recorded instructions from the execution log. The number of
6417recorded instructions is limited only by the available memory.
53cc454a 6418
59ea5688
MM
6419@kindex show record full
6420@item show record full insn-number-max
6421Show the limit of instructions to be recorded with the @code{full}
6422recording method.
53cc454a 6423
59ea5688
MM
6424@item set record full stop-at-limit
6425Control the behavior of the @code{full} recording method when the
6426number of recorded instructions reaches the limit. If ON (the
6427default), @value{GDBN} will stop when the limit is reached for the
6428first time and ask you whether you want to stop the inferior or
6429continue running it and recording the execution log. If you decide
6430to continue recording, each new recorded instruction will cause the
6431oldest one to be deleted.
53cc454a 6432
a2311334
EZ
6433If this option is OFF, @value{GDBN} will automatically delete the
6434oldest record to make room for each new one, without asking.
53cc454a 6435
59ea5688 6436@item show record full stop-at-limit
a2311334 6437Show the current setting of @code{stop-at-limit}.
53cc454a 6438
59ea5688 6439@item set record full memory-query
bb08c432 6440Control the behavior when @value{GDBN} is unable to record memory
59ea5688
MM
6441changes caused by an instruction for the @code{full} recording method.
6442If ON, @value{GDBN} will query whether to stop the inferior in that
6443case.
bb08c432
HZ
6444
6445If this option is OFF (the default), @value{GDBN} will automatically
6446ignore the effect of such instructions on memory. Later, when
6447@value{GDBN} replays this execution log, it will mark the log of this
6448instruction as not accessible, and it will not affect the replay
6449results.
6450
59ea5688 6451@item show record full memory-query
bb08c432
HZ
6452Show the current setting of @code{memory-query}.
6453
67b5c0c1
MM
6454@kindex set record btrace
6455The @code{btrace} record target does not trace data. As a
6456convenience, when replaying, @value{GDBN} reads read-only memory off
6457the live program directly, assuming that the addresses of the
6458read-only areas don't change. This for example makes it possible to
6459disassemble code while replaying, but not to print variables.
6460In some cases, being able to inspect variables might be useful.
6461You can use the following command for that:
6462
6463@item set record btrace replay-memory-access
6464Control the behavior of the @code{btrace} recording method when
6465accessing memory during replay. If @code{read-only} (the default),
6466@value{GDBN} will only allow accesses to read-only memory.
6467If @code{read-write}, @value{GDBN} will allow accesses to read-only
6468and to read-write memory. Beware that the accessed memory corresponds
6469to the live target and not necessarily to the current replay
6470position.
6471
6472@kindex show record btrace
6473@item show record btrace replay-memory-access
6474Show the current setting of @code{replay-memory-access}.
6475
29153c24
MS
6476@kindex info record
6477@item info record
59ea5688
MM
6478Show various statistics about the recording depending on the recording
6479method:
6480
6481@table @code
6482@item full
6483For the @code{full} recording method, it shows the state of process
6484record and its in-memory execution log buffer, including:
29153c24
MS
6485
6486@itemize @bullet
6487@item
6488Whether in record mode or replay mode.
6489@item
6490Lowest recorded instruction number (counting from when the current execution log started recording instructions).
6491@item
6492Highest recorded instruction number.
6493@item
6494Current instruction about to be replayed (if in replay mode).
6495@item
6496Number of instructions contained in the execution log.
6497@item
6498Maximum number of instructions that may be contained in the execution log.
6499@end itemize
53cc454a 6500
59ea5688
MM
6501@item btrace
6502For the @code{btrace} recording method, it shows the number of
6503instructions that have been recorded and the number of blocks of
6504sequential control-flow that is formed by the recorded instructions.
6505@end table
6506
53cc454a
HZ
6507@kindex record delete
6508@kindex rec del
6509@item record delete
a2311334 6510When record target runs in replay mode (``in the past''), delete the
53cc454a 6511subsequent execution log and begin to record a new execution log starting
a2311334 6512from the current address. This means you will abandon the previously
53cc454a 6513recorded ``future'' and begin recording a new ``future''.
59ea5688
MM
6514
6515@kindex record instruction-history
6516@kindex rec instruction-history
6517@item record instruction-history
6518Disassembles instructions from the recorded execution log. By
6519default, ten instructions are disassembled. This can be changed using
6520the @code{set record instruction-history-size} command. Instructions
6521are printed in execution order. There are several ways to specify
6522what part of the execution log to disassemble:
6523
6524@table @code
6525@item record instruction-history @var{insn}
6526Disassembles ten instructions starting from instruction number
6527@var{insn}.
6528
6529@item record instruction-history @var{insn}, +/-@var{n}
6530Disassembles @var{n} instructions around instruction number
6531@var{insn}. If @var{n} is preceded with @code{+}, disassembles
6532@var{n} instructions after instruction number @var{insn}. If
6533@var{n} is preceded with @code{-}, disassembles @var{n}
6534instructions before instruction number @var{insn}.
6535
6536@item record instruction-history
6537Disassembles ten more instructions after the last disassembly.
6538
6539@item record instruction-history -
6540Disassembles ten more instructions before the last disassembly.
6541
6542@item record instruction-history @var{begin} @var{end}
6543Disassembles instructions beginning with instruction number
6544@var{begin} until instruction number @var{end}. The instruction
0688d04e 6545number @var{end} is included.
59ea5688
MM
6546@end table
6547
6548This command may not be available for all recording methods.
6549
6550@kindex set record
f81d1120
PA
6551@item set record instruction-history-size @var{size}
6552@itemx set record instruction-history-size unlimited
59ea5688
MM
6553Define how many instructions to disassemble in the @code{record
6554instruction-history} command. The default value is 10.
f81d1120 6555A @var{size} of @code{unlimited} means unlimited instructions.
59ea5688
MM
6556
6557@kindex show record
6558@item show record instruction-history-size
6559Show how many instructions to disassemble in the @code{record
6560instruction-history} command.
6561
6562@kindex record function-call-history
6563@kindex rec function-call-history
6564@item record function-call-history
6565Prints the execution history at function granularity. It prints one
6566line for each sequence of instructions that belong to the same
6567function giving the name of that function, the source lines
6568for this instruction sequence (if the @code{/l} modifier is
6569specified), and the instructions numbers that form the sequence (if
8710b709
MM
6570the @code{/i} modifier is specified). The function names are indented
6571to reflect the call stack depth if the @code{/c} modifier is
6572specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be
6573given together.
59ea5688
MM
6574
6575@smallexample
6576(@value{GDBP}) @b{list 1, 10}
65771 void foo (void)
65782 @{
65793 @}
65804
65815 void bar (void)
65826 @{
65837 ...
65848 foo ();
65859 ...
658610 @}
8710b709
MM
6587(@value{GDBP}) @b{record function-call-history /ilc}
65881 bar inst 1,4 at foo.c:6,8
65892 foo inst 5,10 at foo.c:2,3
65903 bar inst 11,13 at foo.c:9,10
59ea5688
MM
6591@end smallexample
6592
6593By default, ten lines are printed. This can be changed using the
6594@code{set record function-call-history-size} command. Functions are
6595printed in execution order. There are several ways to specify what
6596to print:
6597
6598@table @code
6599@item record function-call-history @var{func}
6600Prints ten functions starting from function number @var{func}.
6601
6602@item record function-call-history @var{func}, +/-@var{n}
6603Prints @var{n} functions around function number @var{func}. If
6604@var{n} is preceded with @code{+}, prints @var{n} functions after
6605function number @var{func}. If @var{n} is preceded with @code{-},
6606prints @var{n} functions before function number @var{func}.
6607
6608@item record function-call-history
6609Prints ten more functions after the last ten-line print.
6610
6611@item record function-call-history -
6612Prints ten more functions before the last ten-line print.
6613
6614@item record function-call-history @var{begin} @var{end}
6615Prints functions beginning with function number @var{begin} until
0688d04e 6616function number @var{end}. The function number @var{end} is included.
59ea5688
MM
6617@end table
6618
6619This command may not be available for all recording methods.
6620
f81d1120
PA
6621@item set record function-call-history-size @var{size}
6622@itemx set record function-call-history-size unlimited
59ea5688
MM
6623Define how many lines to print in the
6624@code{record function-call-history} command. The default value is 10.
f81d1120 6625A size of @code{unlimited} means unlimited lines.
59ea5688
MM
6626
6627@item show record function-call-history-size
6628Show how many lines to print in the
6629@code{record function-call-history} command.
53cc454a
HZ
6630@end table
6631
6632
6d2ebf8b 6633@node Stack
c906108c
SS
6634@chapter Examining the Stack
6635
6636When your program has stopped, the first thing you need to know is where it
6637stopped and how it got there.
6638
6639@cindex call stack
5d161b24
DB
6640Each time your program performs a function call, information about the call
6641is generated.
6642That information includes the location of the call in your program,
6643the arguments of the call,
c906108c 6644and the local variables of the function being called.
5d161b24 6645The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
6646The stack frames are allocated in a region of memory called the @dfn{call
6647stack}.
6648
6649When your program stops, the @value{GDBN} commands for examining the
6650stack allow you to see all of this information.
6651
6652@cindex selected frame
6653One of the stack frames is @dfn{selected} by @value{GDBN} and many
6654@value{GDBN} commands refer implicitly to the selected frame. In
6655particular, whenever you ask @value{GDBN} for the value of a variable in
6656your program, the value is found in the selected frame. There are
6657special @value{GDBN} commands to select whichever frame you are
79a6e687 6658interested in. @xref{Selection, ,Selecting a Frame}.
c906108c
SS
6659
6660When your program stops, @value{GDBN} automatically selects the
5d161b24 6661currently executing frame and describes it briefly, similar to the
79a6e687 6662@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
c906108c
SS
6663
6664@menu
6665* Frames:: Stack frames
6666* Backtrace:: Backtraces
1e611234 6667* Frame Filter Management:: Managing frame filters
c906108c
SS
6668* Selection:: Selecting a frame
6669* Frame Info:: Information on a frame
c906108c
SS
6670
6671@end menu
6672
6d2ebf8b 6673@node Frames
79a6e687 6674@section Stack Frames
c906108c 6675
d4f3574e 6676@cindex frame, definition
c906108c
SS
6677@cindex stack frame
6678The call stack is divided up into contiguous pieces called @dfn{stack
6679frames}, or @dfn{frames} for short; each frame is the data associated
6680with one call to one function. The frame contains the arguments given
6681to the function, the function's local variables, and the address at
6682which the function is executing.
6683
6684@cindex initial frame
6685@cindex outermost frame
6686@cindex innermost frame
6687When your program is started, the stack has only one frame, that of the
6688function @code{main}. This is called the @dfn{initial} frame or the
6689@dfn{outermost} frame. Each time a function is called, a new frame is
6690made. Each time a function returns, the frame for that function invocation
6691is eliminated. If a function is recursive, there can be many frames for
6692the same function. The frame for the function in which execution is
6693actually occurring is called the @dfn{innermost} frame. This is the most
6694recently created of all the stack frames that still exist.
6695
6696@cindex frame pointer
6697Inside your program, stack frames are identified by their addresses. A
6698stack frame consists of many bytes, each of which has its own address; each
6699kind of computer has a convention for choosing one byte whose
6700address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
6701in a register called the @dfn{frame pointer register}
6702(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
6703
6704@cindex frame number
6705@value{GDBN} assigns numbers to all existing stack frames, starting with
6706zero for the innermost frame, one for the frame that called it,
6707and so on upward. These numbers do not really exist in your program;
6708they are assigned by @value{GDBN} to give you a way of designating stack
6709frames in @value{GDBN} commands.
6710
6d2ebf8b
SS
6711@c The -fomit-frame-pointer below perennially causes hbox overflow
6712@c underflow problems.
c906108c
SS
6713@cindex frameless execution
6714Some compilers provide a way to compile functions so that they operate
e22ea452 6715without stack frames. (For example, the @value{NGCC} option
474c8240 6716@smallexample
6d2ebf8b 6717@samp{-fomit-frame-pointer}
474c8240 6718@end smallexample
6d2ebf8b 6719generates functions without a frame.)
c906108c
SS
6720This is occasionally done with heavily used library functions to save
6721the frame setup time. @value{GDBN} has limited facilities for dealing
6722with these function invocations. If the innermost function invocation
6723has no stack frame, @value{GDBN} nevertheless regards it as though
6724it had a separate frame, which is numbered zero as usual, allowing
6725correct tracing of the function call chain. However, @value{GDBN} has
6726no provision for frameless functions elsewhere in the stack.
6727
6728@table @code
d4f3574e 6729@kindex frame@r{, command}
41afff9a 6730@cindex current stack frame
c906108c 6731@item frame @var{args}
5d161b24 6732The @code{frame} command allows you to move from one stack frame to another,
c906108c 6733and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
6734address of the frame or the stack frame number. Without an argument,
6735@code{frame} prints the current stack frame.
c906108c
SS
6736
6737@kindex select-frame
41afff9a 6738@cindex selecting frame silently
c906108c
SS
6739@item select-frame
6740The @code{select-frame} command allows you to move from one stack frame
6741to another without printing the frame. This is the silent version of
6742@code{frame}.
6743@end table
6744
6d2ebf8b 6745@node Backtrace
c906108c
SS
6746@section Backtraces
6747
09d4efe1
EZ
6748@cindex traceback
6749@cindex call stack traces
c906108c
SS
6750A backtrace is a summary of how your program got where it is. It shows one
6751line per frame, for many frames, starting with the currently executing
6752frame (frame zero), followed by its caller (frame one), and on up the
6753stack.
6754
1e611234 6755@anchor{backtrace-command}
c906108c
SS
6756@table @code
6757@kindex backtrace
41afff9a 6758@kindex bt @r{(@code{backtrace})}
c906108c
SS
6759@item backtrace
6760@itemx bt
6761Print a backtrace of the entire stack: one line per frame for all
6762frames in the stack.
6763
6764You can stop the backtrace at any time by typing the system interrupt
c8aa23ab 6765character, normally @kbd{Ctrl-c}.
c906108c
SS
6766
6767@item backtrace @var{n}
6768@itemx bt @var{n}
6769Similar, but print only the innermost @var{n} frames.
6770
6771@item backtrace -@var{n}
6772@itemx bt -@var{n}
6773Similar, but print only the outermost @var{n} frames.
0f061b69
NR
6774
6775@item backtrace full
0f061b69 6776@itemx bt full
dd74f6ae
NR
6777@itemx bt full @var{n}
6778@itemx bt full -@var{n}
e7109c7e 6779Print the values of the local variables also. @var{n} specifies the
286ba84d 6780number of frames to print, as described above.
1e611234
PM
6781
6782@item backtrace no-filters
6783@itemx bt no-filters
6784@itemx bt no-filters @var{n}
6785@itemx bt no-filters -@var{n}
6786@itemx bt no-filters full
6787@itemx bt no-filters full @var{n}
6788@itemx bt no-filters full -@var{n}
6789Do not run Python frame filters on this backtrace. @xref{Frame
6790Filter API}, for more information. Additionally use @ref{disable
6791frame-filter all} to turn off all frame filters. This is only
6792relevant when @value{GDBN} has been configured with @code{Python}
6793support.
c906108c
SS
6794@end table
6795
6796@kindex where
6797@kindex info stack
c906108c
SS
6798The names @code{where} and @code{info stack} (abbreviated @code{info s})
6799are additional aliases for @code{backtrace}.
6800
839c27b7
EZ
6801@cindex multiple threads, backtrace
6802In a multi-threaded program, @value{GDBN} by default shows the
6803backtrace only for the current thread. To display the backtrace for
6804several or all of the threads, use the command @code{thread apply}
6805(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
6806apply all backtrace}, @value{GDBN} will display the backtrace for all
6807the threads; this is handy when you debug a core dump of a
6808multi-threaded program.
6809
c906108c
SS
6810Each line in the backtrace shows the frame number and the function name.
6811The program counter value is also shown---unless you use @code{set
6812print address off}. The backtrace also shows the source file name and
6813line number, as well as the arguments to the function. The program
6814counter value is omitted if it is at the beginning of the code for that
6815line number.
6816
6817Here is an example of a backtrace. It was made with the command
6818@samp{bt 3}, so it shows the innermost three frames.
6819
6820@smallexample
6821@group
5d161b24 6822#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c 6823 at builtin.c:993
4f5376b2 6824#1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
c906108c
SS
6825#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
6826 at macro.c:71
6827(More stack frames follow...)
6828@end group
6829@end smallexample
6830
6831@noindent
6832The display for frame zero does not begin with a program counter
6833value, indicating that your program has stopped at the beginning of the
6834code for line @code{993} of @code{builtin.c}.
6835
4f5376b2
JB
6836@noindent
6837The value of parameter @code{data} in frame 1 has been replaced by
6838@code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
6839only if it is a scalar (integer, pointer, enumeration, etc). See command
6840@kbd{set print frame-arguments} in @ref{Print Settings} for more details
6841on how to configure the way function parameter values are printed.
6842
585fdaa1 6843@cindex optimized out, in backtrace
18999be5
EZ
6844@cindex function call arguments, optimized out
6845If your program was compiled with optimizations, some compilers will
6846optimize away arguments passed to functions if those arguments are
6847never used after the call. Such optimizations generate code that
6848passes arguments through registers, but doesn't store those arguments
6849in the stack frame. @value{GDBN} has no way of displaying such
6850arguments in stack frames other than the innermost one. Here's what
6851such a backtrace might look like:
6852
6853@smallexample
6854@group
6855#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
6856 at builtin.c:993
585fdaa1
PA
6857#1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
6858#2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
18999be5
EZ
6859 at macro.c:71
6860(More stack frames follow...)
6861@end group
6862@end smallexample
6863
6864@noindent
6865The values of arguments that were not saved in their stack frames are
585fdaa1 6866shown as @samp{<optimized out>}.
18999be5
EZ
6867
6868If you need to display the values of such optimized-out arguments,
6869either deduce that from other variables whose values depend on the one
6870you are interested in, or recompile without optimizations.
6871
a8f24a35
EZ
6872@cindex backtrace beyond @code{main} function
6873@cindex program entry point
6874@cindex startup code, and backtrace
25d29d70
AC
6875Most programs have a standard user entry point---a place where system
6876libraries and startup code transition into user code. For C this is
d416eeec
EZ
6877@code{main}@footnote{
6878Note that embedded programs (the so-called ``free-standing''
6879environment) are not required to have a @code{main} function as the
6880entry point. They could even have multiple entry points.}.
6881When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
6882it will terminate the backtrace, to avoid tracing into highly
6883system-specific (and generally uninteresting) code.
6884
6885If you need to examine the startup code, or limit the number of levels
6886in a backtrace, you can change this behavior:
95f90d25
DJ
6887
6888@table @code
25d29d70
AC
6889@item set backtrace past-main
6890@itemx set backtrace past-main on
4644b6e3 6891@kindex set backtrace
25d29d70
AC
6892Backtraces will continue past the user entry point.
6893
6894@item set backtrace past-main off
95f90d25
DJ
6895Backtraces will stop when they encounter the user entry point. This is the
6896default.
6897
25d29d70 6898@item show backtrace past-main
4644b6e3 6899@kindex show backtrace
25d29d70
AC
6900Display the current user entry point backtrace policy.
6901
2315ffec
RC
6902@item set backtrace past-entry
6903@itemx set backtrace past-entry on
a8f24a35 6904Backtraces will continue past the internal entry point of an application.
2315ffec
RC
6905This entry point is encoded by the linker when the application is built,
6906and is likely before the user entry point @code{main} (or equivalent) is called.
6907
6908@item set backtrace past-entry off
d3e8051b 6909Backtraces will stop when they encounter the internal entry point of an
2315ffec
RC
6910application. This is the default.
6911
6912@item show backtrace past-entry
6913Display the current internal entry point backtrace policy.
6914
25d29d70
AC
6915@item set backtrace limit @var{n}
6916@itemx set backtrace limit 0
f81d1120 6917@itemx set backtrace limit unlimited
25d29d70 6918@cindex backtrace limit
f81d1120
PA
6919Limit the backtrace to @var{n} levels. A value of @code{unlimited}
6920or zero means unlimited levels.
95f90d25 6921
25d29d70
AC
6922@item show backtrace limit
6923Display the current limit on backtrace levels.
95f90d25
DJ
6924@end table
6925
1b56eb55
JK
6926You can control how file names are displayed.
6927
6928@table @code
6929@item set filename-display
6930@itemx set filename-display relative
6931@cindex filename-display
6932Display file names relative to the compilation directory. This is the default.
6933
6934@item set filename-display basename
6935Display only basename of a filename.
6936
6937@item set filename-display absolute
6938Display an absolute filename.
6939
6940@item show filename-display
6941Show the current way to display filenames.
6942@end table
6943
1e611234
PM
6944@node Frame Filter Management
6945@section Management of Frame Filters.
6946@cindex managing frame filters
6947
6948Frame filters are Python based utilities to manage and decorate the
6949output of frames. @xref{Frame Filter API}, for further information.
6950
6951Managing frame filters is performed by several commands available
6952within @value{GDBN}, detailed here.
6953
6954@table @code
6955@kindex info frame-filter
6956@item info frame-filter
6957Print a list of installed frame filters from all dictionaries, showing
6958their name, priority and enabled status.
6959
6960@kindex disable frame-filter
6961@anchor{disable frame-filter all}
6962@item disable frame-filter @var{filter-dictionary} @var{filter-name}
6963Disable a frame filter in the dictionary matching
6964@var{filter-dictionary}, or @code{all}, and @var{filter-name}.
6965@var{filter-dictionary} may be @code{all}, @code{global},
6966@code{progspace} or the name of the object file where the frame filter
6967dictionary resides. When @code{all} is specified, all frame filters
6968across all dictionaries are disabled. @var{filter-name} is the name
6969of the frame filter and is used when @code{all} is not the option for
6970@var{filter-dictionary}. A disabled frame-filter is not deleted, it
6971may be enabled again later.
6972
6973@kindex enable frame-filter
6974@item enable frame-filter @var{filter-dictionary} @var{filter-name}
6975Enable a frame filter in the dictionary matching
6976@var{filter-dictionary}, or @code{all}, and @var{filter-name}.
6977@var{filter-dictionary} may be @code{all}, @code{global},
6978@code{progspace} or the name of the object file where the frame filter
6979dictionary resides. When @code{all} is specified, all frame filters across
6980all dictionaries are enabled. @var{filter-name} is the name of the frame
6981filter and is used when @code{all} is not the option for
6982@var{filter-dictionary}.
6983
6984Example:
6985
6986@smallexample
6987(gdb) info frame-filter
6988
6989global frame-filters:
6990 Priority Enabled Name
6991 1000 No PrimaryFunctionFilter
6992 100 Yes Reverse
6993
6994progspace /build/test frame-filters:
6995 Priority Enabled Name
6996 100 Yes ProgspaceFilter
6997
6998objfile /build/test frame-filters:
6999 Priority Enabled Name
7000 999 Yes BuildProgra Filter
7001
7002(gdb) disable frame-filter /build/test BuildProgramFilter
7003(gdb) info frame-filter
7004
7005global frame-filters:
7006 Priority Enabled Name
7007 1000 No PrimaryFunctionFilter
7008 100 Yes Reverse
7009
7010progspace /build/test frame-filters:
7011 Priority Enabled Name
7012 100 Yes ProgspaceFilter
7013
7014objfile /build/test frame-filters:
7015 Priority Enabled Name
7016 999 No BuildProgramFilter
7017
7018(gdb) enable frame-filter global PrimaryFunctionFilter
7019(gdb) info frame-filter
7020
7021global frame-filters:
7022 Priority Enabled Name
7023 1000 Yes PrimaryFunctionFilter
7024 100 Yes Reverse
7025
7026progspace /build/test frame-filters:
7027 Priority Enabled Name
7028 100 Yes ProgspaceFilter
7029
7030objfile /build/test frame-filters:
7031 Priority Enabled Name
7032 999 No BuildProgramFilter
7033@end smallexample
7034
7035@kindex set frame-filter priority
7036@item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
7037Set the @var{priority} of a frame filter in the dictionary matching
7038@var{filter-dictionary}, and the frame filter name matching
7039@var{filter-name}. @var{filter-dictionary} may be @code{global},
7040@code{progspace} or the name of the object file where the frame filter
7041dictionary resides. @var{priority} is an integer.
7042
7043@kindex show frame-filter priority
7044@item show frame-filter priority @var{filter-dictionary} @var{filter-name}
7045Show the @var{priority} of a frame filter in the dictionary matching
7046@var{filter-dictionary}, and the frame filter name matching
7047@var{filter-name}. @var{filter-dictionary} may be @code{global},
7048@code{progspace} or the name of the object file where the frame filter
7049dictionary resides.
7050
7051Example:
7052
7053@smallexample
7054(gdb) info frame-filter
7055
7056global frame-filters:
7057 Priority Enabled Name
7058 1000 Yes PrimaryFunctionFilter
7059 100 Yes Reverse
7060
7061progspace /build/test frame-filters:
7062 Priority Enabled Name
7063 100 Yes ProgspaceFilter
7064
7065objfile /build/test frame-filters:
7066 Priority Enabled Name
7067 999 No BuildProgramFilter
7068
7069(gdb) set frame-filter priority global Reverse 50
7070(gdb) info frame-filter
7071
7072global frame-filters:
7073 Priority Enabled Name
7074 1000 Yes PrimaryFunctionFilter
7075 50 Yes Reverse
7076
7077progspace /build/test frame-filters:
7078 Priority Enabled Name
7079 100 Yes ProgspaceFilter
7080
7081objfile /build/test frame-filters:
7082 Priority Enabled Name
7083 999 No BuildProgramFilter
7084@end smallexample
7085@end table
7086
6d2ebf8b 7087@node Selection
79a6e687 7088@section Selecting a Frame
c906108c
SS
7089
7090Most commands for examining the stack and other data in your program work on
7091whichever stack frame is selected at the moment. Here are the commands for
7092selecting a stack frame; all of them finish by printing a brief description
7093of the stack frame just selected.
7094
7095@table @code
d4f3574e 7096@kindex frame@r{, selecting}
41afff9a 7097@kindex f @r{(@code{frame})}
c906108c
SS
7098@item frame @var{n}
7099@itemx f @var{n}
7100Select frame number @var{n}. Recall that frame zero is the innermost
7101(currently executing) frame, frame one is the frame that called the
7102innermost one, and so on. The highest-numbered frame is the one for
7103@code{main}.
7104
7105@item frame @var{addr}
7106@itemx f @var{addr}
7107Select the frame at address @var{addr}. This is useful mainly if the
7108chaining of stack frames has been damaged by a bug, making it
7109impossible for @value{GDBN} to assign numbers properly to all frames. In
7110addition, this can be useful when your program has multiple stacks and
7111switches between them.
7112
c906108c
SS
7113On the SPARC architecture, @code{frame} needs two addresses to
7114select an arbitrary frame: a frame pointer and a stack pointer.
7115
eb17f351 7116On the @acronym{MIPS} and Alpha architecture, it needs two addresses: a stack
c906108c
SS
7117pointer and a program counter.
7118
7119On the 29k architecture, it needs three addresses: a register stack
7120pointer, a program counter, and a memory stack pointer.
c906108c
SS
7121
7122@kindex up
7123@item up @var{n}
7124Move @var{n} frames up the stack. For positive numbers @var{n}, this
7125advances toward the outermost frame, to higher frame numbers, to frames
7126that have existed longer. @var{n} defaults to one.
7127
7128@kindex down
41afff9a 7129@kindex do @r{(@code{down})}
c906108c
SS
7130@item down @var{n}
7131Move @var{n} frames down the stack. For positive numbers @var{n}, this
7132advances toward the innermost frame, to lower frame numbers, to frames
7133that were created more recently. @var{n} defaults to one. You may
7134abbreviate @code{down} as @code{do}.
7135@end table
7136
7137All of these commands end by printing two lines of output describing the
7138frame. The first line shows the frame number, the function name, the
7139arguments, and the source file and line number of execution in that
5d161b24 7140frame. The second line shows the text of that source line.
c906108c
SS
7141
7142@need 1000
7143For example:
7144
7145@smallexample
7146@group
7147(@value{GDBP}) up
7148#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
7149 at env.c:10
715010 read_input_file (argv[i]);
7151@end group
7152@end smallexample
7153
7154After such a printout, the @code{list} command with no arguments
7155prints ten lines centered on the point of execution in the frame.
87885426
FN
7156You can also edit the program at the point of execution with your favorite
7157editing program by typing @code{edit}.
79a6e687 7158@xref{List, ,Printing Source Lines},
87885426 7159for details.
c906108c
SS
7160
7161@table @code
7162@kindex down-silently
7163@kindex up-silently
7164@item up-silently @var{n}
7165@itemx down-silently @var{n}
7166These two commands are variants of @code{up} and @code{down},
7167respectively; they differ in that they do their work silently, without
7168causing display of the new frame. They are intended primarily for use
7169in @value{GDBN} command scripts, where the output might be unnecessary and
7170distracting.
7171@end table
7172
6d2ebf8b 7173@node Frame Info
79a6e687 7174@section Information About a Frame
c906108c
SS
7175
7176There are several other commands to print information about the selected
7177stack frame.
7178
7179@table @code
7180@item frame
7181@itemx f
7182When used without any argument, this command does not change which
7183frame is selected, but prints a brief description of the currently
7184selected stack frame. It can be abbreviated @code{f}. With an
7185argument, this command is used to select a stack frame.
79a6e687 7186@xref{Selection, ,Selecting a Frame}.
c906108c
SS
7187
7188@kindex info frame
41afff9a 7189@kindex info f @r{(@code{info frame})}
c906108c
SS
7190@item info frame
7191@itemx info f
7192This command prints a verbose description of the selected stack frame,
7193including:
7194
7195@itemize @bullet
5d161b24
DB
7196@item
7197the address of the frame
c906108c
SS
7198@item
7199the address of the next frame down (called by this frame)
7200@item
7201the address of the next frame up (caller of this frame)
7202@item
7203the language in which the source code corresponding to this frame is written
7204@item
7205the address of the frame's arguments
7206@item
d4f3574e
SS
7207the address of the frame's local variables
7208@item
c906108c
SS
7209the program counter saved in it (the address of execution in the caller frame)
7210@item
7211which registers were saved in the frame
7212@end itemize
7213
7214@noindent The verbose description is useful when
7215something has gone wrong that has made the stack format fail to fit
7216the usual conventions.
7217
7218@item info frame @var{addr}
7219@itemx info f @var{addr}
7220Print a verbose description of the frame at address @var{addr}, without
7221selecting that frame. The selected frame remains unchanged by this
7222command. This requires the same kind of address (more than one for some
7223architectures) that you specify in the @code{frame} command.
79a6e687 7224@xref{Selection, ,Selecting a Frame}.
c906108c
SS
7225
7226@kindex info args
7227@item info args
7228Print the arguments of the selected frame, each on a separate line.
7229
7230@item info locals
7231@kindex info locals
7232Print the local variables of the selected frame, each on a separate
7233line. These are all variables (declared either static or automatic)
7234accessible at the point of execution of the selected frame.
7235
c906108c
SS
7236@end table
7237
c906108c 7238
6d2ebf8b 7239@node Source
c906108c
SS
7240@chapter Examining Source Files
7241
7242@value{GDBN} can print parts of your program's source, since the debugging
7243information recorded in the program tells @value{GDBN} what source files were
7244used to build it. When your program stops, @value{GDBN} spontaneously prints
7245the line where it stopped. Likewise, when you select a stack frame
79a6e687 7246(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
c906108c
SS
7247execution in that frame has stopped. You can print other portions of
7248source files by explicit command.
7249
7a292a7a 7250If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 7251prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 7252@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
7253
7254@menu
7255* List:: Printing source lines
2a25a5ba 7256* Specify Location:: How to specify code locations
87885426 7257* Edit:: Editing source files
c906108c 7258* Search:: Searching source files
c906108c
SS
7259* Source Path:: Specifying source directories
7260* Machine Code:: Source and machine code
7261@end menu
7262
6d2ebf8b 7263@node List
79a6e687 7264@section Printing Source Lines
c906108c
SS
7265
7266@kindex list
41afff9a 7267@kindex l @r{(@code{list})}
c906108c 7268To print lines from a source file, use the @code{list} command
5d161b24 7269(abbreviated @code{l}). By default, ten lines are printed.
2a25a5ba
EZ
7270There are several ways to specify what part of the file you want to
7271print; see @ref{Specify Location}, for the full list.
c906108c
SS
7272
7273Here are the forms of the @code{list} command most commonly used:
7274
7275@table @code
7276@item list @var{linenum}
7277Print lines centered around line number @var{linenum} in the
7278current source file.
7279
7280@item list @var{function}
7281Print lines centered around the beginning of function
7282@var{function}.
7283
7284@item list
7285Print more lines. If the last lines printed were printed with a
7286@code{list} command, this prints lines following the last lines
7287printed; however, if the last line printed was a solitary line printed
7288as part of displaying a stack frame (@pxref{Stack, ,Examining the
7289Stack}), this prints lines centered around that line.
7290
7291@item list -
7292Print lines just before the lines last printed.
7293@end table
7294
9c16f35a 7295@cindex @code{list}, how many lines to display
c906108c
SS
7296By default, @value{GDBN} prints ten source lines with any of these forms of
7297the @code{list} command. You can change this using @code{set listsize}:
7298
7299@table @code
7300@kindex set listsize
7301@item set listsize @var{count}
f81d1120 7302@itemx set listsize unlimited
c906108c
SS
7303Make the @code{list} command display @var{count} source lines (unless
7304the @code{list} argument explicitly specifies some other number).
f81d1120 7305Setting @var{count} to @code{unlimited} or 0 means there's no limit.
c906108c
SS
7306
7307@kindex show listsize
7308@item show listsize
7309Display the number of lines that @code{list} prints.
7310@end table
7311
7312Repeating a @code{list} command with @key{RET} discards the argument,
7313so it is equivalent to typing just @code{list}. This is more useful
7314than listing the same lines again. An exception is made for an
7315argument of @samp{-}; that argument is preserved in repetition so that
7316each repetition moves up in the source file.
7317
c906108c
SS
7318In general, the @code{list} command expects you to supply zero, one or two
7319@dfn{linespecs}. Linespecs specify source lines; there are several ways
2a25a5ba
EZ
7320of writing them (@pxref{Specify Location}), but the effect is always
7321to specify some source line.
7322
c906108c
SS
7323Here is a complete description of the possible arguments for @code{list}:
7324
7325@table @code
7326@item list @var{linespec}
7327Print lines centered around the line specified by @var{linespec}.
7328
7329@item list @var{first},@var{last}
7330Print lines from @var{first} to @var{last}. Both arguments are
2a25a5ba
EZ
7331linespecs. When a @code{list} command has two linespecs, and the
7332source file of the second linespec is omitted, this refers to
7333the same source file as the first linespec.
c906108c
SS
7334
7335@item list ,@var{last}
7336Print lines ending with @var{last}.
7337
7338@item list @var{first},
7339Print lines starting with @var{first}.
7340
7341@item list +
7342Print lines just after the lines last printed.
7343
7344@item list -
7345Print lines just before the lines last printed.
7346
7347@item list
7348As described in the preceding table.
7349@end table
7350
2a25a5ba
EZ
7351@node Specify Location
7352@section Specifying a Location
7353@cindex specifying location
7354@cindex linespec
c906108c 7355
2a25a5ba
EZ
7356Several @value{GDBN} commands accept arguments that specify a location
7357of your program's code. Since @value{GDBN} is a source-level
7358debugger, a location usually specifies some line in the source code;
7359for that reason, locations are also known as @dfn{linespecs}.
c906108c 7360
2a25a5ba
EZ
7361Here are all the different ways of specifying a code location that
7362@value{GDBN} understands:
c906108c 7363
2a25a5ba
EZ
7364@table @code
7365@item @var{linenum}
7366Specifies the line number @var{linenum} of the current source file.
c906108c 7367
2a25a5ba
EZ
7368@item -@var{offset}
7369@itemx +@var{offset}
7370Specifies the line @var{offset} lines before or after the @dfn{current
7371line}. For the @code{list} command, the current line is the last one
7372printed; for the breakpoint commands, this is the line at which
7373execution stopped in the currently selected @dfn{stack frame}
7374(@pxref{Frames, ,Frames}, for a description of stack frames.) When
7375used as the second of the two linespecs in a @code{list} command,
7376this specifies the line @var{offset} lines up or down from the first
7377linespec.
7378
7379@item @var{filename}:@var{linenum}
7380Specifies the line @var{linenum} in the source file @var{filename}.
4aac40c8
TT
7381If @var{filename} is a relative file name, then it will match any
7382source file name with the same trailing components. For example, if
7383@var{filename} is @samp{gcc/expr.c}, then it will match source file
7384name of @file{/build/trunk/gcc/expr.c}, but not
7385@file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
c906108c
SS
7386
7387@item @var{function}
7388Specifies the line that begins the body of the function @var{function}.
2a25a5ba 7389For example, in C, this is the line with the open brace.
c906108c 7390
9ef07c8c
TT
7391@item @var{function}:@var{label}
7392Specifies the line where @var{label} appears in @var{function}.
7393
c906108c 7394@item @var{filename}:@var{function}
2a25a5ba
EZ
7395Specifies the line that begins the body of the function @var{function}
7396in the file @var{filename}. You only need the file name with a
7397function name to avoid ambiguity when there are identically named
7398functions in different source files.
c906108c 7399
0f5238ed
TT
7400@item @var{label}
7401Specifies the line at which the label named @var{label} appears.
7402@value{GDBN} searches for the label in the function corresponding to
7403the currently selected stack frame. If there is no current selected
7404stack frame (for instance, if the inferior is not running), then
7405@value{GDBN} will not search for a label.
7406
c906108c 7407@item *@var{address}
2a25a5ba
EZ
7408Specifies the program address @var{address}. For line-oriented
7409commands, such as @code{list} and @code{edit}, this specifies a source
7410line that contains @var{address}. For @code{break} and other
7411breakpoint oriented commands, this can be used to set breakpoints in
7412parts of your program which do not have debugging information or
7413source files.
7414
7415Here @var{address} may be any expression valid in the current working
7416language (@pxref{Languages, working language}) that specifies a code
5fa54e5d
EZ
7417address. In addition, as a convenience, @value{GDBN} extends the
7418semantics of expressions used in locations to cover the situations
7419that frequently happen during debugging. Here are the various forms
7420of @var{address}:
2a25a5ba
EZ
7421
7422@table @code
7423@item @var{expression}
7424Any expression valid in the current working language.
7425
7426@item @var{funcaddr}
7427An address of a function or procedure derived from its name. In C,
7428C@t{++}, Java, Objective-C, Fortran, minimal, and assembly, this is
7429simply the function's name @var{function} (and actually a special case
7430of a valid expression). In Pascal and Modula-2, this is
7431@code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
7432(although the Pascal form also works).
7433
7434This form specifies the address of the function's first instruction,
7435before the stack frame and arguments have been set up.
7436
7437@item '@var{filename}'::@var{funcaddr}
7438Like @var{funcaddr} above, but also specifies the name of the source
7439file explicitly. This is useful if the name of the function does not
7440specify the function unambiguously, e.g., if there are several
7441functions with identical names in different source files.
c906108c
SS
7442@end table
7443
62e5f89c
SDJ
7444@cindex breakpoint at static probe point
7445@item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
7446The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
7447applications to embed static probes. @xref{Static Probe Points}, for more
7448information on finding and using static probes. This form of linespec
7449specifies the location of such a static probe.
7450
7451If @var{objfile} is given, only probes coming from that shared library
7452or executable matching @var{objfile} as a regular expression are considered.
7453If @var{provider} is given, then only probes from that provider are considered.
7454If several probes match the spec, @value{GDBN} will insert a breakpoint at
7455each one of those probes.
7456
2a25a5ba
EZ
7457@end table
7458
7459
87885426 7460@node Edit
79a6e687 7461@section Editing Source Files
87885426
FN
7462@cindex editing source files
7463
7464@kindex edit
7465@kindex e @r{(@code{edit})}
7466To edit the lines in a source file, use the @code{edit} command.
7467The editing program of your choice
7468is invoked with the current line set to
7469the active line in the program.
7470Alternatively, there are several ways to specify what part of the file you
2a25a5ba 7471want to print if you want to see other parts of the program:
87885426
FN
7472
7473@table @code
2a25a5ba
EZ
7474@item edit @var{location}
7475Edit the source file specified by @code{location}. Editing starts at
7476that @var{location}, e.g., at the specified source line of the
7477specified file. @xref{Specify Location}, for all the possible forms
7478of the @var{location} argument; here are the forms of the @code{edit}
7479command most commonly used:
87885426 7480
2a25a5ba 7481@table @code
87885426
FN
7482@item edit @var{number}
7483Edit the current source file with @var{number} as the active line number.
7484
7485@item edit @var{function}
7486Edit the file containing @var{function} at the beginning of its definition.
2a25a5ba 7487@end table
87885426 7488
87885426
FN
7489@end table
7490
79a6e687 7491@subsection Choosing your Editor
87885426
FN
7492You can customize @value{GDBN} to use any editor you want
7493@footnote{
7494The only restriction is that your editor (say @code{ex}), recognizes the
7495following command-line syntax:
10998722 7496@smallexample
87885426 7497ex +@var{number} file
10998722 7498@end smallexample
15387254
EZ
7499The optional numeric value +@var{number} specifies the number of the line in
7500the file where to start editing.}.
7501By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
7502by setting the environment variable @code{EDITOR} before using
7503@value{GDBN}. For example, to configure @value{GDBN} to use the
7504@code{vi} editor, you could use these commands with the @code{sh} shell:
7505@smallexample
87885426
FN
7506EDITOR=/usr/bin/vi
7507export EDITOR
15387254 7508gdb @dots{}
10998722 7509@end smallexample
87885426 7510or in the @code{csh} shell,
10998722 7511@smallexample
87885426 7512setenv EDITOR /usr/bin/vi
15387254 7513gdb @dots{}
10998722 7514@end smallexample
87885426 7515
6d2ebf8b 7516@node Search
79a6e687 7517@section Searching Source Files
15387254 7518@cindex searching source files
c906108c
SS
7519
7520There are two commands for searching through the current source file for a
7521regular expression.
7522
7523@table @code
7524@kindex search
7525@kindex forward-search
1e96de83 7526@kindex fo @r{(@code{forward-search})}
c906108c
SS
7527@item forward-search @var{regexp}
7528@itemx search @var{regexp}
7529The command @samp{forward-search @var{regexp}} checks each line,
7530starting with the one following the last line listed, for a match for
5d161b24 7531@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
7532synonym @samp{search @var{regexp}} or abbreviate the command name as
7533@code{fo}.
7534
09d4efe1 7535@kindex reverse-search
c906108c
SS
7536@item reverse-search @var{regexp}
7537The command @samp{reverse-search @var{regexp}} checks each line, starting
7538with the one before the last line listed and going backward, for a match
7539for @var{regexp}. It lists the line that is found. You can abbreviate
7540this command as @code{rev}.
7541@end table
c906108c 7542
6d2ebf8b 7543@node Source Path
79a6e687 7544@section Specifying Source Directories
c906108c
SS
7545
7546@cindex source path
7547@cindex directories for source files
7548Executable programs sometimes do not record the directories of the source
7549files from which they were compiled, just the names. Even when they do,
7550the directories could be moved between the compilation and your debugging
7551session. @value{GDBN} has a list of directories to search for source files;
7552this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
7553it tries all the directories in the list, in the order they are present
0b66e38c
EZ
7554in the list, until it finds a file with the desired name.
7555
7556For example, suppose an executable references the file
7557@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
7558@file{/mnt/cross}. The file is first looked up literally; if this
7559fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
7560fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
7561message is printed. @value{GDBN} does not look up the parts of the
7562source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
7563Likewise, the subdirectories of the source path are not searched: if
7564the source path is @file{/mnt/cross}, and the binary refers to
7565@file{foo.c}, @value{GDBN} would not find it under
7566@file{/mnt/cross/usr/src/foo-1.0/lib}.
7567
7568Plain file names, relative file names with leading directories, file
7569names containing dots, etc.@: are all treated as described above; for
7570instance, if the source path is @file{/mnt/cross}, and the source file
7571is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
7572@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
7573that---@file{/mnt/cross/foo.c}.
7574
7575Note that the executable search path is @emph{not} used to locate the
cd852561 7576source files.
c906108c
SS
7577
7578Whenever you reset or rearrange the source path, @value{GDBN} clears out
7579any information it has cached about where source files are found and where
7580each line is in the file.
7581
7582@kindex directory
7583@kindex dir
d4f3574e
SS
7584When you start @value{GDBN}, its source path includes only @samp{cdir}
7585and @samp{cwd}, in that order.
c906108c
SS
7586To add other directories, use the @code{directory} command.
7587
4b505b12
AS
7588The search path is used to find both program source files and @value{GDBN}
7589script files (read using the @samp{-command} option and @samp{source} command).
7590
30daae6c
JB
7591In addition to the source path, @value{GDBN} provides a set of commands
7592that manage a list of source path substitution rules. A @dfn{substitution
7593rule} specifies how to rewrite source directories stored in the program's
7594debug information in case the sources were moved to a different
7595directory between compilation and debugging. A rule is made of
7596two strings, the first specifying what needs to be rewritten in
7597the path, and the second specifying how it should be rewritten.
7598In @ref{set substitute-path}, we name these two parts @var{from} and
7599@var{to} respectively. @value{GDBN} does a simple string replacement
7600of @var{from} with @var{to} at the start of the directory part of the
7601source file name, and uses that result instead of the original file
7602name to look up the sources.
7603
7604Using the previous example, suppose the @file{foo-1.0} tree has been
7605moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
3f94c067 7606@value{GDBN} to replace @file{/usr/src} in all source path names with
30daae6c
JB
7607@file{/mnt/cross}. The first lookup will then be
7608@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
7609of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
7610substitution rule, use the @code{set substitute-path} command
7611(@pxref{set substitute-path}).
7612
7613To avoid unexpected substitution results, a rule is applied only if the
7614@var{from} part of the directory name ends at a directory separator.
7615For instance, a rule substituting @file{/usr/source} into
7616@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
7617not to @file{/usr/sourceware/foo-2.0}. And because the substitution
d3e8051b 7618is applied only at the beginning of the directory name, this rule will
30daae6c
JB
7619not be applied to @file{/root/usr/source/baz.c} either.
7620
7621In many cases, you can achieve the same result using the @code{directory}
7622command. However, @code{set substitute-path} can be more efficient in
7623the case where the sources are organized in a complex tree with multiple
7624subdirectories. With the @code{directory} command, you need to add each
7625subdirectory of your project. If you moved the entire tree while
7626preserving its internal organization, then @code{set substitute-path}
7627allows you to direct the debugger to all the sources with one single
7628command.
7629
7630@code{set substitute-path} is also more than just a shortcut command.
7631The source path is only used if the file at the original location no
7632longer exists. On the other hand, @code{set substitute-path} modifies
7633the debugger behavior to look at the rewritten location instead. So, if
7634for any reason a source file that is not relevant to your executable is
7635located at the original location, a substitution rule is the only
3f94c067 7636method available to point @value{GDBN} at the new location.
30daae6c 7637
29b0e8a2
JM
7638@cindex @samp{--with-relocated-sources}
7639@cindex default source path substitution
7640You can configure a default source path substitution rule by
7641configuring @value{GDBN} with the
7642@samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
7643should be the name of a directory under @value{GDBN}'s configured
7644prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
7645directory names in debug information under @var{dir} will be adjusted
7646automatically if the installed @value{GDBN} is moved to a new
7647location. This is useful if @value{GDBN}, libraries or executables
7648with debug information and corresponding source code are being moved
7649together.
7650
c906108c
SS
7651@table @code
7652@item directory @var{dirname} @dots{}
7653@item dir @var{dirname} @dots{}
7654Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
7655directory names may be given to this command, separated by @samp{:}
7656(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
7657part of absolute file names) or
c906108c
SS
7658whitespace. You may specify a directory that is already in the source
7659path; this moves it forward, so @value{GDBN} searches it sooner.
7660
7661@kindex cdir
7662@kindex cwd
41afff9a 7663@vindex $cdir@r{, convenience variable}
d3e8051b 7664@vindex $cwd@r{, convenience variable}
c906108c
SS
7665@cindex compilation directory
7666@cindex current directory
7667@cindex working directory
7668@cindex directory, current
7669@cindex directory, compilation
7670You can use the string @samp{$cdir} to refer to the compilation
7671directory (if one is recorded), and @samp{$cwd} to refer to the current
7672working directory. @samp{$cwd} is not the same as @samp{.}---the former
7673tracks the current working directory as it changes during your @value{GDBN}
7674session, while the latter is immediately expanded to the current
7675directory at the time you add an entry to the source path.
7676
7677@item directory
cd852561 7678Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
7679
7680@c RET-repeat for @code{directory} is explicitly disabled, but since
7681@c repeating it would be a no-op we do not say that. (thanks to RMS)
7682
99e7ae30
DE
7683@item set directories @var{path-list}
7684@kindex set directories
7685Set the source path to @var{path-list}.
7686@samp{$cdir:$cwd} are added if missing.
7687
c906108c
SS
7688@item show directories
7689@kindex show directories
7690Print the source path: show which directories it contains.
30daae6c
JB
7691
7692@anchor{set substitute-path}
7693@item set substitute-path @var{from} @var{to}
7694@kindex set substitute-path
7695Define a source path substitution rule, and add it at the end of the
7696current list of existing substitution rules. If a rule with the same
7697@var{from} was already defined, then the old rule is also deleted.
7698
7699For example, if the file @file{/foo/bar/baz.c} was moved to
7700@file{/mnt/cross/baz.c}, then the command
7701
7702@smallexample
7703(@value{GDBP}) set substitute-path /usr/src /mnt/cross
7704@end smallexample
7705
7706@noindent
7707will tell @value{GDBN} to replace @samp{/usr/src} with
7708@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
7709@file{baz.c} even though it was moved.
7710
7711In the case when more than one substitution rule have been defined,
7712the rules are evaluated one by one in the order where they have been
7713defined. The first one matching, if any, is selected to perform
7714the substitution.
7715
7716For instance, if we had entered the following commands:
7717
7718@smallexample
7719(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
7720(@value{GDBP}) set substitute-path /usr/src /mnt/src
7721@end smallexample
7722
7723@noindent
7724@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
7725@file{/mnt/include/defs.h} by using the first rule. However, it would
7726use the second rule to rewrite @file{/usr/src/lib/foo.c} into
7727@file{/mnt/src/lib/foo.c}.
7728
7729
7730@item unset substitute-path [path]
7731@kindex unset substitute-path
7732If a path is specified, search the current list of substitution rules
7733for a rule that would rewrite that path. Delete that rule if found.
7734A warning is emitted by the debugger if no rule could be found.
7735
7736If no path is specified, then all substitution rules are deleted.
7737
7738@item show substitute-path [path]
7739@kindex show substitute-path
7740If a path is specified, then print the source path substitution rule
7741which would rewrite that path, if any.
7742
7743If no path is specified, then print all existing source path substitution
7744rules.
7745
c906108c
SS
7746@end table
7747
7748If your source path is cluttered with directories that are no longer of
7749interest, @value{GDBN} may sometimes cause confusion by finding the wrong
7750versions of source. You can correct the situation as follows:
7751
7752@enumerate
7753@item
cd852561 7754Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
7755
7756@item
7757Use @code{directory} with suitable arguments to reinstall the
7758directories you want in the source path. You can add all the
7759directories in one command.
7760@end enumerate
7761
6d2ebf8b 7762@node Machine Code
79a6e687 7763@section Source and Machine Code
15387254 7764@cindex source line and its code address
c906108c
SS
7765
7766You can use the command @code{info line} to map source lines to program
7767addresses (and vice versa), and the command @code{disassemble} to display
91440f57
HZ
7768a range of addresses as machine instructions. You can use the command
7769@code{set disassemble-next-line} to set whether to disassemble next
7770source line when execution stops. When run under @sc{gnu} Emacs
d4f3574e 7771mode, the @code{info line} command causes the arrow to point to the
5d161b24 7772line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
7773well as hex.
7774
7775@table @code
7776@kindex info line
7777@item info line @var{linespec}
7778Print the starting and ending addresses of the compiled code for
7779source line @var{linespec}. You can specify source lines in any of
2a25a5ba 7780the ways documented in @ref{Specify Location}.
c906108c
SS
7781@end table
7782
7783For example, we can use @code{info line} to discover the location of
7784the object code for the first line of function
7785@code{m4_changequote}:
7786
d4f3574e
SS
7787@c FIXME: I think this example should also show the addresses in
7788@c symbolic form, as they usually would be displayed.
c906108c 7789@smallexample
96a2c332 7790(@value{GDBP}) info line m4_changequote
c906108c
SS
7791Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
7792@end smallexample
7793
7794@noindent
15387254 7795@cindex code address and its source line
c906108c
SS
7796We can also inquire (using @code{*@var{addr}} as the form for
7797@var{linespec}) what source line covers a particular address:
7798@smallexample
7799(@value{GDBP}) info line *0x63ff
7800Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
7801@end smallexample
7802
7803@cindex @code{$_} and @code{info line}
15387254 7804@cindex @code{x} command, default address
41afff9a 7805@kindex x@r{(examine), and} info line
c906108c
SS
7806After @code{info line}, the default address for the @code{x} command
7807is changed to the starting address of the line, so that @samp{x/i} is
7808sufficient to begin examining the machine code (@pxref{Memory,
79a6e687 7809,Examining Memory}). Also, this address is saved as the value of the
c906108c 7810convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
79a6e687 7811Variables}).
c906108c
SS
7812
7813@table @code
7814@kindex disassemble
7815@cindex assembly instructions
7816@cindex instructions, assembly
7817@cindex machine instructions
7818@cindex listing machine instructions
7819@item disassemble
d14508fe 7820@itemx disassemble /m
9b117ef3 7821@itemx disassemble /r
c906108c 7822This specialized command dumps a range of memory as machine
d14508fe 7823instructions. It can also print mixed source+disassembly by specifying
9b117ef3
HZ
7824the @code{/m} modifier and print the raw instructions in hex as well as
7825in symbolic form by specifying the @code{/r}.
d14508fe 7826The default memory range is the function surrounding the
c906108c
SS
7827program counter of the selected frame. A single argument to this
7828command is a program counter value; @value{GDBN} dumps the function
21a0512e
PP
7829surrounding this value. When two arguments are given, they should
7830be separated by a comma, possibly surrounded by whitespace. The
53a71c06
CR
7831arguments specify a range of addresses to dump, in one of two forms:
7832
7833@table @code
7834@item @var{start},@var{end}
7835the addresses from @var{start} (inclusive) to @var{end} (exclusive)
7836@item @var{start},+@var{length}
7837the addresses from @var{start} (inclusive) to
7838@code{@var{start}+@var{length}} (exclusive).
7839@end table
7840
7841@noindent
7842When 2 arguments are specified, the name of the function is also
7843printed (since there could be several functions in the given range).
21a0512e
PP
7844
7845The argument(s) can be any expression yielding a numeric value, such as
7846@samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
2b28d209
PP
7847
7848If the range of memory being disassembled contains current program counter,
7849the instruction at that location is shown with a @code{=>} marker.
c906108c
SS
7850@end table
7851
c906108c
SS
7852The following example shows the disassembly of a range of addresses of
7853HP PA-RISC 2.0 code:
7854
7855@smallexample
21a0512e 7856(@value{GDBP}) disas 0x32c4, 0x32e4
c906108c 7857Dump of assembler code from 0x32c4 to 0x32e4:
2b28d209
PP
7858 0x32c4 <main+204>: addil 0,dp
7859 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
7860 0x32cc <main+212>: ldil 0x3000,r31
7861 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
7862 0x32d4 <main+220>: ldo 0(r31),rp
7863 0x32d8 <main+224>: addil -0x800,dp
7864 0x32dc <main+228>: ldo 0x588(r1),r26
7865 0x32e0 <main+232>: ldil 0x3000,r31
c906108c
SS
7866End of assembler dump.
7867@end smallexample
c906108c 7868
2b28d209
PP
7869Here is an example showing mixed source+assembly for Intel x86, when the
7870program is stopped just after function prologue:
d14508fe
DE
7871
7872@smallexample
7873(@value{GDBP}) disas /m main
7874Dump of assembler code for function main:
78755 @{
9c419145
PP
7876 0x08048330 <+0>: push %ebp
7877 0x08048331 <+1>: mov %esp,%ebp
7878 0x08048333 <+3>: sub $0x8,%esp
7879 0x08048336 <+6>: and $0xfffffff0,%esp
7880 0x08048339 <+9>: sub $0x10,%esp
d14508fe
DE
7881
78826 printf ("Hello.\n");
9c419145
PP
7883=> 0x0804833c <+12>: movl $0x8048440,(%esp)
7884 0x08048343 <+19>: call 0x8048284 <puts@@plt>
d14508fe
DE
7885
78867 return 0;
78878 @}
9c419145
PP
7888 0x08048348 <+24>: mov $0x0,%eax
7889 0x0804834d <+29>: leave
7890 0x0804834e <+30>: ret
d14508fe
DE
7891
7892End of assembler dump.
7893@end smallexample
7894
53a71c06
CR
7895Here is another example showing raw instructions in hex for AMD x86-64,
7896
7897@smallexample
7898(gdb) disas /r 0x400281,+10
7899Dump of assembler code from 0x400281 to 0x40028b:
7900 0x0000000000400281: 38 36 cmp %dh,(%rsi)
7901 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
7902 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
7903 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
7904End of assembler dump.
7905@end smallexample
7906
7e1e0340
DE
7907Addresses cannot be specified as a linespec (@pxref{Specify Location}).
7908So, for example, if you want to disassemble function @code{bar}
7909in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
7910and not @samp{disassemble foo.c:bar}.
7911
c906108c
SS
7912Some architectures have more than one commonly-used set of instruction
7913mnemonics or other syntax.
7914
76d17f34
EZ
7915For programs that were dynamically linked and use shared libraries,
7916instructions that call functions or branch to locations in the shared
7917libraries might show a seemingly bogus location---it's actually a
7918location of the relocation table. On some architectures, @value{GDBN}
7919might be able to resolve these to actual function names.
7920
c906108c 7921@table @code
d4f3574e 7922@kindex set disassembly-flavor
d4f3574e
SS
7923@cindex Intel disassembly flavor
7924@cindex AT&T disassembly flavor
7925@item set disassembly-flavor @var{instruction-set}
c906108c
SS
7926Select the instruction set to use when disassembling the
7927program via the @code{disassemble} or @code{x/i} commands.
7928
7929Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
7930can set @var{instruction-set} to either @code{intel} or @code{att}.
7931The default is @code{att}, the AT&T flavor used by default by Unix
7932assemblers for x86-based targets.
9c16f35a
EZ
7933
7934@kindex show disassembly-flavor
7935@item show disassembly-flavor
7936Show the current setting of the disassembly flavor.
c906108c
SS
7937@end table
7938
91440f57
HZ
7939@table @code
7940@kindex set disassemble-next-line
7941@kindex show disassemble-next-line
7942@item set disassemble-next-line
7943@itemx show disassemble-next-line
32ae1842
EZ
7944Control whether or not @value{GDBN} will disassemble the next source
7945line or instruction when execution stops. If ON, @value{GDBN} will
7946display disassembly of the next source line when execution of the
7947program being debugged stops. This is @emph{in addition} to
7948displaying the source line itself, which @value{GDBN} always does if
7949possible. If the next source line cannot be displayed for some reason
7950(e.g., if @value{GDBN} cannot find the source file, or there's no line
7951info in the debug info), @value{GDBN} will display disassembly of the
7952next @emph{instruction} instead of showing the next source line. If
7953AUTO, @value{GDBN} will display disassembly of next instruction only
7954if the source line cannot be displayed. This setting causes
7955@value{GDBN} to display some feedback when you step through a function
7956with no line info or whose source file is unavailable. The default is
7957OFF, which means never display the disassembly of the next line or
7958instruction.
91440f57
HZ
7959@end table
7960
c906108c 7961
6d2ebf8b 7962@node Data
c906108c
SS
7963@chapter Examining Data
7964
7965@cindex printing data
7966@cindex examining data
7967@kindex print
7968@kindex inspect
c906108c 7969The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
7970command (abbreviated @code{p}), or its synonym @code{inspect}. It
7971evaluates and prints the value of an expression of the language your
7972program is written in (@pxref{Languages, ,Using @value{GDBN} with
78e2826b
TT
7973Different Languages}). It may also print the expression using a
7974Python-based pretty-printer (@pxref{Pretty Printing}).
c906108c
SS
7975
7976@table @code
d4f3574e
SS
7977@item print @var{expr}
7978@itemx print /@var{f} @var{expr}
7979@var{expr} is an expression (in the source language). By default the
7980value of @var{expr} is printed in a format appropriate to its data type;
c906108c 7981you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 7982@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
79a6e687 7983Formats}.
c906108c
SS
7984
7985@item print
7986@itemx print /@var{f}
15387254 7987@cindex reprint the last value
d4f3574e 7988If you omit @var{expr}, @value{GDBN} displays the last value again (from the
79a6e687 7989@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
c906108c
SS
7990conveniently inspect the same value in an alternative format.
7991@end table
7992
7993A more low-level way of examining data is with the @code{x} command.
7994It examines data in memory at a specified address and prints it in a
79a6e687 7995specified format. @xref{Memory, ,Examining Memory}.
c906108c 7996
7a292a7a 7997If you are interested in information about types, or about how the
d4f3574e
SS
7998fields of a struct or a class are declared, use the @code{ptype @var{exp}}
7999command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 8000Table}.
c906108c 8001
06fc020f
SCR
8002@cindex exploring hierarchical data structures
8003@kindex explore
8004Another way of examining values of expressions and type information is
8005through the Python extension command @code{explore} (available only if
8006the @value{GDBN} build is configured with @code{--with-python}). It
8007offers an interactive way to start at the highest level (or, the most
8008abstract level) of the data type of an expression (or, the data type
8009itself) and explore all the way down to leaf scalar values/fields
8010embedded in the higher level data types.
8011
8012@table @code
8013@item explore @var{arg}
8014@var{arg} is either an expression (in the source language), or a type
8015visible in the current context of the program being debugged.
8016@end table
8017
8018The working of the @code{explore} command can be illustrated with an
8019example. If a data type @code{struct ComplexStruct} is defined in your
8020C program as
8021
8022@smallexample
8023struct SimpleStruct
8024@{
8025 int i;
8026 double d;
8027@};
8028
8029struct ComplexStruct
8030@{
8031 struct SimpleStruct *ss_p;
8032 int arr[10];
8033@};
8034@end smallexample
8035
8036@noindent
8037followed by variable declarations as
8038
8039@smallexample
8040struct SimpleStruct ss = @{ 10, 1.11 @};
8041struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
8042@end smallexample
8043
8044@noindent
8045then, the value of the variable @code{cs} can be explored using the
8046@code{explore} command as follows.
8047
8048@smallexample
8049(gdb) explore cs
8050The value of `cs' is a struct/class of type `struct ComplexStruct' with
8051the following fields:
8052
8053 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
8054 arr = <Enter 1 to explore this field of type `int [10]'>
8055
8056Enter the field number of choice:
8057@end smallexample
8058
8059@noindent
8060Since the fields of @code{cs} are not scalar values, you are being
8061prompted to chose the field you want to explore. Let's say you choose
8062the field @code{ss_p} by entering @code{0}. Then, since this field is a
8063pointer, you will be asked if it is pointing to a single value. From
8064the declaration of @code{cs} above, it is indeed pointing to a single
8065value, hence you enter @code{y}. If you enter @code{n}, then you will
8066be asked if it were pointing to an array of values, in which case this
8067field will be explored as if it were an array.
8068
8069@smallexample
8070`cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
8071Continue exploring it as a pointer to a single value [y/n]: y
8072The value of `*(cs.ss_p)' is a struct/class of type `struct
8073SimpleStruct' with the following fields:
8074
8075 i = 10 .. (Value of type `int')
8076 d = 1.1100000000000001 .. (Value of type `double')
8077
8078Press enter to return to parent value:
8079@end smallexample
8080
8081@noindent
8082If the field @code{arr} of @code{cs} was chosen for exploration by
8083entering @code{1} earlier, then since it is as array, you will be
8084prompted to enter the index of the element in the array that you want
8085to explore.
8086
8087@smallexample
8088`cs.arr' is an array of `int'.
8089Enter the index of the element you want to explore in `cs.arr': 5
8090
8091`(cs.arr)[5]' is a scalar value of type `int'.
8092
8093(cs.arr)[5] = 4
8094
8095Press enter to return to parent value:
8096@end smallexample
8097
8098In general, at any stage of exploration, you can go deeper towards the
8099leaf values by responding to the prompts appropriately, or hit the
8100return key to return to the enclosing data structure (the @i{higher}
8101level data structure).
8102
8103Similar to exploring values, you can use the @code{explore} command to
8104explore types. Instead of specifying a value (which is typically a
8105variable name or an expression valid in the current context of the
8106program being debugged), you specify a type name. If you consider the
8107same example as above, your can explore the type
8108@code{struct ComplexStruct} by passing the argument
8109@code{struct ComplexStruct} to the @code{explore} command.
8110
8111@smallexample
8112(gdb) explore struct ComplexStruct
8113@end smallexample
8114
8115@noindent
8116By responding to the prompts appropriately in the subsequent interactive
8117session, you can explore the type @code{struct ComplexStruct} in a
8118manner similar to how the value @code{cs} was explored in the above
8119example.
8120
8121The @code{explore} command also has two sub-commands,
8122@code{explore value} and @code{explore type}. The former sub-command is
8123a way to explicitly specify that value exploration of the argument is
8124being invoked, while the latter is a way to explicitly specify that type
8125exploration of the argument is being invoked.
8126
8127@table @code
8128@item explore value @var{expr}
8129@cindex explore value
8130This sub-command of @code{explore} explores the value of the
8131expression @var{expr} (if @var{expr} is an expression valid in the
8132current context of the program being debugged). The behavior of this
8133command is identical to that of the behavior of the @code{explore}
8134command being passed the argument @var{expr}.
8135
8136@item explore type @var{arg}
8137@cindex explore type
8138This sub-command of @code{explore} explores the type of @var{arg} (if
8139@var{arg} is a type visible in the current context of program being
8140debugged), or the type of the value/expression @var{arg} (if @var{arg}
8141is an expression valid in the current context of the program being
8142debugged). If @var{arg} is a type, then the behavior of this command is
8143identical to that of the @code{explore} command being passed the
8144argument @var{arg}. If @var{arg} is an expression, then the behavior of
8145this command will be identical to that of the @code{explore} command
8146being passed the type of @var{arg} as the argument.
8147@end table
8148
c906108c
SS
8149@menu
8150* Expressions:: Expressions
6ba66d6a 8151* Ambiguous Expressions:: Ambiguous Expressions
c906108c
SS
8152* Variables:: Program variables
8153* Arrays:: Artificial arrays
8154* Output Formats:: Output formats
8155* Memory:: Examining memory
8156* Auto Display:: Automatic display
8157* Print Settings:: Print settings
4c374409 8158* Pretty Printing:: Python pretty printing
c906108c
SS
8159* Value History:: Value history
8160* Convenience Vars:: Convenience variables
a72c3253 8161* Convenience Funs:: Convenience functions
c906108c 8162* Registers:: Registers
c906108c 8163* Floating Point Hardware:: Floating point hardware
53c69bd7 8164* Vector Unit:: Vector Unit
721c2651 8165* OS Information:: Auxiliary data provided by operating system
29e57380 8166* Memory Region Attributes:: Memory region attributes
16d9dec6 8167* Dump/Restore Files:: Copy between memory and a file
384ee23f 8168* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
8169* Character Sets:: Debugging programs that use a different
8170 character set than GDB does
b12039c6 8171* Caching Target Data:: Data caching for targets
08388c79 8172* Searching Memory:: Searching memory for a sequence of bytes
c906108c
SS
8173@end menu
8174
6d2ebf8b 8175@node Expressions
c906108c
SS
8176@section Expressions
8177
8178@cindex expressions
8179@code{print} and many other @value{GDBN} commands accept an expression and
8180compute its value. Any kind of constant, variable or operator defined
8181by the programming language you are using is valid in an expression in
e2e0bcd1
JB
8182@value{GDBN}. This includes conditional expressions, function calls,
8183casts, and string constants. It also includes preprocessor macros, if
8184you compiled your program to include this information; see
8185@ref{Compilation}.
c906108c 8186
15387254 8187@cindex arrays in expressions
d4f3574e
SS
8188@value{GDBN} supports array constants in expressions input by
8189the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
63092375
DJ
8190you can use the command @code{print @{1, 2, 3@}} to create an array
8191of three integers. If you pass an array to a function or assign it
8192to a program variable, @value{GDBN} copies the array to memory that
8193is @code{malloc}ed in the target program.
c906108c 8194
c906108c
SS
8195Because C is so widespread, most of the expressions shown in examples in
8196this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
8197Languages}, for information on how to use expressions in other
8198languages.
8199
8200In this section, we discuss operators that you can use in @value{GDBN}
8201expressions regardless of your programming language.
8202
15387254 8203@cindex casts, in expressions
c906108c
SS
8204Casts are supported in all languages, not just in C, because it is so
8205useful to cast a number into a pointer in order to examine a structure
8206at that address in memory.
8207@c FIXME: casts supported---Mod2 true?
c906108c
SS
8208
8209@value{GDBN} supports these operators, in addition to those common
8210to programming languages:
8211
8212@table @code
8213@item @@
8214@samp{@@} is a binary operator for treating parts of memory as arrays.
79a6e687 8215@xref{Arrays, ,Artificial Arrays}, for more information.
c906108c
SS
8216
8217@item ::
8218@samp{::} allows you to specify a variable in terms of the file or
79a6e687 8219function where it is defined. @xref{Variables, ,Program Variables}.
c906108c
SS
8220
8221@cindex @{@var{type}@}
8222@cindex type casting memory
8223@cindex memory, viewing as typed object
8224@cindex casts, to view memory
8225@item @{@var{type}@} @var{addr}
8226Refers to an object of type @var{type} stored at address @var{addr} in
8227memory. @var{addr} may be any expression whose value is an integer or
8228pointer (but parentheses are required around binary operators, just as in
8229a cast). This construct is allowed regardless of what kind of data is
8230normally supposed to reside at @var{addr}.
8231@end table
8232
6ba66d6a
JB
8233@node Ambiguous Expressions
8234@section Ambiguous Expressions
8235@cindex ambiguous expressions
8236
8237Expressions can sometimes contain some ambiguous elements. For instance,
8238some programming languages (notably Ada, C@t{++} and Objective-C) permit
8239a single function name to be defined several times, for application in
8240different contexts. This is called @dfn{overloading}. Another example
8241involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
8242templates and is typically instantiated several times, resulting in
8243the same function name being defined in different contexts.
8244
8245In some cases and depending on the language, it is possible to adjust
8246the expression to remove the ambiguity. For instance in C@t{++}, you
8247can specify the signature of the function you want to break on, as in
8248@kbd{break @var{function}(@var{types})}. In Ada, using the fully
8249qualified name of your function often makes the expression unambiguous
8250as well.
8251
8252When an ambiguity that needs to be resolved is detected, the debugger
8253has the capability to display a menu of numbered choices for each
8254possibility, and then waits for the selection with the prompt @samp{>}.
8255The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
8256aborts the current command. If the command in which the expression was
8257used allows more than one choice to be selected, the next option in the
8258menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
8259choices.
8260
8261For example, the following session excerpt shows an attempt to set a
8262breakpoint at the overloaded symbol @code{String::after}.
8263We choose three particular definitions of that function name:
8264
8265@c FIXME! This is likely to change to show arg type lists, at least
8266@smallexample
8267@group
8268(@value{GDBP}) b String::after
8269[0] cancel
8270[1] all
8271[2] file:String.cc; line number:867
8272[3] file:String.cc; line number:860
8273[4] file:String.cc; line number:875
8274[5] file:String.cc; line number:853
8275[6] file:String.cc; line number:846
8276[7] file:String.cc; line number:735
8277> 2 4 6
8278Breakpoint 1 at 0xb26c: file String.cc, line 867.
8279Breakpoint 2 at 0xb344: file String.cc, line 875.
8280Breakpoint 3 at 0xafcc: file String.cc, line 846.
8281Multiple breakpoints were set.
8282Use the "delete" command to delete unwanted
8283 breakpoints.
8284(@value{GDBP})
8285@end group
8286@end smallexample
8287
8288@table @code
8289@kindex set multiple-symbols
8290@item set multiple-symbols @var{mode}
8291@cindex multiple-symbols menu
8292
8293This option allows you to adjust the debugger behavior when an expression
8294is ambiguous.
8295
8296By default, @var{mode} is set to @code{all}. If the command with which
8297the expression is used allows more than one choice, then @value{GDBN}
8298automatically selects all possible choices. For instance, inserting
8299a breakpoint on a function using an ambiguous name results in a breakpoint
8300inserted on each possible match. However, if a unique choice must be made,
8301then @value{GDBN} uses the menu to help you disambiguate the expression.
8302For instance, printing the address of an overloaded function will result
8303in the use of the menu.
8304
8305When @var{mode} is set to @code{ask}, the debugger always uses the menu
8306when an ambiguity is detected.
8307
8308Finally, when @var{mode} is set to @code{cancel}, the debugger reports
8309an error due to the ambiguity and the command is aborted.
8310
8311@kindex show multiple-symbols
8312@item show multiple-symbols
8313Show the current value of the @code{multiple-symbols} setting.
8314@end table
8315
6d2ebf8b 8316@node Variables
79a6e687 8317@section Program Variables
c906108c
SS
8318
8319The most common kind of expression to use is the name of a variable
8320in your program.
8321
8322Variables in expressions are understood in the selected stack frame
79a6e687 8323(@pxref{Selection, ,Selecting a Frame}); they must be either:
c906108c
SS
8324
8325@itemize @bullet
8326@item
8327global (or file-static)
8328@end itemize
8329
5d161b24 8330@noindent or
c906108c
SS
8331
8332@itemize @bullet
8333@item
8334visible according to the scope rules of the
8335programming language from the point of execution in that frame
5d161b24 8336@end itemize
c906108c
SS
8337
8338@noindent This means that in the function
8339
474c8240 8340@smallexample
c906108c
SS
8341foo (a)
8342 int a;
8343@{
8344 bar (a);
8345 @{
8346 int b = test ();
8347 bar (b);
8348 @}
8349@}
474c8240 8350@end smallexample
c906108c
SS
8351
8352@noindent
8353you can examine and use the variable @code{a} whenever your program is
8354executing within the function @code{foo}, but you can only use or
8355examine the variable @code{b} while your program is executing inside
8356the block where @code{b} is declared.
8357
8358@cindex variable name conflict
8359There is an exception: you can refer to a variable or function whose
8360scope is a single source file even if the current execution point is not
8361in this file. But it is possible to have more than one such variable or
8362function with the same name (in different source files). If that
8363happens, referring to that name has unpredictable effects. If you wish,
72384ba3 8364you can specify a static variable in a particular function or file by
15387254 8365using the colon-colon (@code{::}) notation:
c906108c 8366
d4f3574e 8367@cindex colon-colon, context for variables/functions
12c27660 8368@ifnotinfo
c906108c 8369@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 8370@cindex @code{::}, context for variables/functions
12c27660 8371@end ifnotinfo
474c8240 8372@smallexample
c906108c
SS
8373@var{file}::@var{variable}
8374@var{function}::@var{variable}
474c8240 8375@end smallexample
c906108c
SS
8376
8377@noindent
8378Here @var{file} or @var{function} is the name of the context for the
8379static @var{variable}. In the case of file names, you can use quotes to
8380make sure @value{GDBN} parses the file name as a single word---for example,
8381to print a global value of @code{x} defined in @file{f2.c}:
8382
474c8240 8383@smallexample
c906108c 8384(@value{GDBP}) p 'f2.c'::x
474c8240 8385@end smallexample
c906108c 8386
72384ba3
PH
8387The @code{::} notation is normally used for referring to
8388static variables, since you typically disambiguate uses of local variables
8389in functions by selecting the appropriate frame and using the
8390simple name of the variable. However, you may also use this notation
8391to refer to local variables in frames enclosing the selected frame:
8392
8393@smallexample
8394void
8395foo (int a)
8396@{
8397 if (a < 10)
8398 bar (a);
8399 else
8400 process (a); /* Stop here */
8401@}
8402
8403int
8404bar (int a)
8405@{
8406 foo (a + 5);
8407@}
8408@end smallexample
8409
8410@noindent
8411For example, if there is a breakpoint at the commented line,
8412here is what you might see
8413when the program stops after executing the call @code{bar(0)}:
8414
8415@smallexample
8416(@value{GDBP}) p a
8417$1 = 10
8418(@value{GDBP}) p bar::a
8419$2 = 5
8420(@value{GDBP}) up 2
8421#2 0x080483d0 in foo (a=5) at foobar.c:12
8422(@value{GDBP}) p a
8423$3 = 5
8424(@value{GDBP}) p bar::a
8425$4 = 0
8426@end smallexample
8427
b37052ae 8428@cindex C@t{++} scope resolution
805e1f19
TT
8429These uses of @samp{::} are very rarely in conflict with the very
8430similar use of the same notation in C@t{++}. When they are in
8431conflict, the C@t{++} meaning takes precedence; however, this can be
8432overridden by quoting the file or function name with single quotes.
8433
8434For example, suppose the program is stopped in a method of a class
8435that has a field named @code{includefile}, and there is also an
8436include file named @file{includefile} that defines a variable,
8437@code{some_global}.
8438
8439@smallexample
8440(@value{GDBP}) p includefile
8441$1 = 23
8442(@value{GDBP}) p includefile::some_global
8443A syntax error in expression, near `'.
8444(@value{GDBP}) p 'includefile'::some_global
8445$2 = 27
8446@end smallexample
c906108c
SS
8447
8448@cindex wrong values
8449@cindex variable values, wrong
15387254
EZ
8450@cindex function entry/exit, wrong values of variables
8451@cindex optimized code, wrong values of variables
c906108c
SS
8452@quotation
8453@emph{Warning:} Occasionally, a local variable may appear to have the
8454wrong value at certain points in a function---just after entry to a new
8455scope, and just before exit.
8456@end quotation
8457You may see this problem when you are stepping by machine instructions.
8458This is because, on most machines, it takes more than one instruction to
8459set up a stack frame (including local variable definitions); if you are
8460stepping by machine instructions, variables may appear to have the wrong
8461values until the stack frame is completely built. On exit, it usually
8462also takes more than one machine instruction to destroy a stack frame;
8463after you begin stepping through that group of instructions, local
8464variable definitions may be gone.
8465
8466This may also happen when the compiler does significant optimizations.
8467To be sure of always seeing accurate values, turn off all optimization
8468when compiling.
8469
d4f3574e
SS
8470@cindex ``No symbol "foo" in current context''
8471Another possible effect of compiler optimizations is to optimize
8472unused variables out of existence, or assign variables to registers (as
8473opposed to memory addresses). Depending on the support for such cases
8474offered by the debug info format used by the compiler, @value{GDBN}
8475might not be able to display values for such local variables. If that
8476happens, @value{GDBN} will print a message like this:
8477
474c8240 8478@smallexample
d4f3574e 8479No symbol "foo" in current context.
474c8240 8480@end smallexample
d4f3574e
SS
8481
8482To solve such problems, either recompile without optimizations, or use a
8483different debug info format, if the compiler supports several such
e0f8f636
TT
8484formats. @xref{Compilation}, for more information on choosing compiler
8485options. @xref{C, ,C and C@t{++}}, for more information about debug
8486info formats that are best suited to C@t{++} programs.
d4f3574e 8487
ab1adacd
EZ
8488If you ask to print an object whose contents are unknown to
8489@value{GDBN}, e.g., because its data type is not completely specified
8490by the debug information, @value{GDBN} will say @samp{<incomplete
8491type>}. @xref{Symbols, incomplete type}, for more about this.
8492
36b11add
JK
8493If you append @kbd{@@entry} string to a function parameter name you get its
8494value at the time the function got called. If the value is not available an
8495error message is printed. Entry values are available only with some compilers.
8496Entry values are normally also printed at the function parameter list according
8497to @ref{set print entry-values}.
8498
8499@smallexample
8500Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
850129 i++;
8502(gdb) next
850330 e (i);
8504(gdb) print i
8505$1 = 31
8506(gdb) print i@@entry
8507$2 = 30
8508@end smallexample
8509
3a60f64e
JK
8510Strings are identified as arrays of @code{char} values without specified
8511signedness. Arrays of either @code{signed char} or @code{unsigned char} get
8512printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
8513@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
8514defines literal string type @code{"char"} as @code{char} without a sign.
8515For program code
8516
8517@smallexample
8518char var0[] = "A";
8519signed char var1[] = "A";
8520@end smallexample
8521
8522You get during debugging
8523@smallexample
8524(gdb) print var0
8525$1 = "A"
8526(gdb) print var1
8527$2 = @{65 'A', 0 '\0'@}
8528@end smallexample
8529
6d2ebf8b 8530@node Arrays
79a6e687 8531@section Artificial Arrays
c906108c
SS
8532
8533@cindex artificial array
15387254 8534@cindex arrays
41afff9a 8535@kindex @@@r{, referencing memory as an array}
c906108c
SS
8536It is often useful to print out several successive objects of the
8537same type in memory; a section of an array, or an array of
8538dynamically determined size for which only a pointer exists in the
8539program.
8540
8541You can do this by referring to a contiguous span of memory as an
8542@dfn{artificial array}, using the binary operator @samp{@@}. The left
8543operand of @samp{@@} should be the first element of the desired array
8544and be an individual object. The right operand should be the desired length
8545of the array. The result is an array value whose elements are all of
8546the type of the left argument. The first element is actually the left
8547argument; the second element comes from bytes of memory immediately
8548following those that hold the first element, and so on. Here is an
8549example. If a program says
8550
474c8240 8551@smallexample
c906108c 8552int *array = (int *) malloc (len * sizeof (int));
474c8240 8553@end smallexample
c906108c
SS
8554
8555@noindent
8556you can print the contents of @code{array} with
8557
474c8240 8558@smallexample
c906108c 8559p *array@@len
474c8240 8560@end smallexample
c906108c
SS
8561
8562The left operand of @samp{@@} must reside in memory. Array values made
8563with @samp{@@} in this way behave just like other arrays in terms of
8564subscripting, and are coerced to pointers when used in expressions.
8565Artificial arrays most often appear in expressions via the value history
79a6e687 8566(@pxref{Value History, ,Value History}), after printing one out.
c906108c
SS
8567
8568Another way to create an artificial array is to use a cast.
8569This re-interprets a value as if it were an array.
8570The value need not be in memory:
474c8240 8571@smallexample
c906108c
SS
8572(@value{GDBP}) p/x (short[2])0x12345678
8573$1 = @{0x1234, 0x5678@}
474c8240 8574@end smallexample
c906108c
SS
8575
8576As a convenience, if you leave the array length out (as in
c3f6f71d 8577@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 8578the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 8579@smallexample
c906108c
SS
8580(@value{GDBP}) p/x (short[])0x12345678
8581$2 = @{0x1234, 0x5678@}
474c8240 8582@end smallexample
c906108c
SS
8583
8584Sometimes the artificial array mechanism is not quite enough; in
8585moderately complex data structures, the elements of interest may not
8586actually be adjacent---for example, if you are interested in the values
8587of pointers in an array. One useful work-around in this situation is
8588to use a convenience variable (@pxref{Convenience Vars, ,Convenience
79a6e687 8589Variables}) as a counter in an expression that prints the first
c906108c
SS
8590interesting value, and then repeat that expression via @key{RET}. For
8591instance, suppose you have an array @code{dtab} of pointers to
8592structures, and you are interested in the values of a field @code{fv}
8593in each structure. Here is an example of what you might type:
8594
474c8240 8595@smallexample
c906108c
SS
8596set $i = 0
8597p dtab[$i++]->fv
8598@key{RET}
8599@key{RET}
8600@dots{}
474c8240 8601@end smallexample
c906108c 8602
6d2ebf8b 8603@node Output Formats
79a6e687 8604@section Output Formats
c906108c
SS
8605
8606@cindex formatted output
8607@cindex output formats
8608By default, @value{GDBN} prints a value according to its data type. Sometimes
8609this is not what you want. For example, you might want to print a number
8610in hex, or a pointer in decimal. Or you might want to view data in memory
8611at a certain address as a character string or as an instruction. To do
8612these things, specify an @dfn{output format} when you print a value.
8613
8614The simplest use of output formats is to say how to print a value
8615already computed. This is done by starting the arguments of the
8616@code{print} command with a slash and a format letter. The format
8617letters supported are:
8618
8619@table @code
8620@item x
8621Regard the bits of the value as an integer, and print the integer in
8622hexadecimal.
8623
8624@item d
8625Print as integer in signed decimal.
8626
8627@item u
8628Print as integer in unsigned decimal.
8629
8630@item o
8631Print as integer in octal.
8632
8633@item t
8634Print as integer in binary. The letter @samp{t} stands for ``two''.
8635@footnote{@samp{b} cannot be used because these format letters are also
8636used with the @code{x} command, where @samp{b} stands for ``byte'';
79a6e687 8637see @ref{Memory,,Examining Memory}.}
c906108c
SS
8638
8639@item a
8640@cindex unknown address, locating
3d67e040 8641@cindex locate address
c906108c
SS
8642Print as an address, both absolute in hexadecimal and as an offset from
8643the nearest preceding symbol. You can use this format used to discover
8644where (in what function) an unknown address is located:
8645
474c8240 8646@smallexample
c906108c
SS
8647(@value{GDBP}) p/a 0x54320
8648$3 = 0x54320 <_initialize_vx+396>
474c8240 8649@end smallexample
c906108c 8650
3d67e040
EZ
8651@noindent
8652The command @code{info symbol 0x54320} yields similar results.
8653@xref{Symbols, info symbol}.
8654
c906108c 8655@item c
51274035
EZ
8656Regard as an integer and print it as a character constant. This
8657prints both the numerical value and its character representation. The
8658character representation is replaced with the octal escape @samp{\nnn}
8659for characters outside the 7-bit @sc{ascii} range.
c906108c 8660
ea37ba09
DJ
8661Without this format, @value{GDBN} displays @code{char},
8662@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
8663constants. Single-byte members of vectors are displayed as integer
8664data.
8665
c906108c
SS
8666@item f
8667Regard the bits of the value as a floating point number and print
8668using typical floating point syntax.
ea37ba09
DJ
8669
8670@item s
8671@cindex printing strings
8672@cindex printing byte arrays
8673Regard as a string, if possible. With this format, pointers to single-byte
8674data are displayed as null-terminated strings and arrays of single-byte data
8675are displayed as fixed-length strings. Other values are displayed in their
8676natural types.
8677
8678Without this format, @value{GDBN} displays pointers to and arrays of
8679@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
8680strings. Single-byte members of a vector are displayed as an integer
8681array.
a6bac58e 8682
6fbe845e
AB
8683@item z
8684Like @samp{x} formatting, the value is treated as an integer and
8685printed as hexadecimal, but leading zeros are printed to pad the value
8686to the size of the integer type.
8687
a6bac58e
TT
8688@item r
8689@cindex raw printing
8690Print using the @samp{raw} formatting. By default, @value{GDBN} will
78e2826b
TT
8691use a Python-based pretty-printer, if one is available (@pxref{Pretty
8692Printing}). This typically results in a higher-level display of the
8693value's contents. The @samp{r} format bypasses any Python
8694pretty-printer which might exist.
c906108c
SS
8695@end table
8696
8697For example, to print the program counter in hex (@pxref{Registers}), type
8698
474c8240 8699@smallexample
c906108c 8700p/x $pc
474c8240 8701@end smallexample
c906108c
SS
8702
8703@noindent
8704Note that no space is required before the slash; this is because command
8705names in @value{GDBN} cannot contain a slash.
8706
8707To reprint the last value in the value history with a different format,
8708you can use the @code{print} command with just a format and no
8709expression. For example, @samp{p/x} reprints the last value in hex.
8710
6d2ebf8b 8711@node Memory
79a6e687 8712@section Examining Memory
c906108c
SS
8713
8714You can use the command @code{x} (for ``examine'') to examine memory in
8715any of several formats, independently of your program's data types.
8716
8717@cindex examining memory
8718@table @code
41afff9a 8719@kindex x @r{(examine memory)}
c906108c
SS
8720@item x/@var{nfu} @var{addr}
8721@itemx x @var{addr}
8722@itemx x
8723Use the @code{x} command to examine memory.
8724@end table
8725
8726@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
8727much memory to display and how to format it; @var{addr} is an
8728expression giving the address where you want to start displaying memory.
8729If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
8730Several commands set convenient defaults for @var{addr}.
8731
8732@table @r
8733@item @var{n}, the repeat count
8734The repeat count is a decimal integer; the default is 1. It specifies
8735how much memory (counting by units @var{u}) to display.
8736@c This really is **decimal**; unaffected by 'set radix' as of GDB
8737@c 4.1.2.
8738
8739@item @var{f}, the display format
51274035
EZ
8740The display format is one of the formats used by @code{print}
8741(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
ea37ba09
DJ
8742@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
8743The default is @samp{x} (hexadecimal) initially. The default changes
8744each time you use either @code{x} or @code{print}.
c906108c
SS
8745
8746@item @var{u}, the unit size
8747The unit size is any of
8748
8749@table @code
8750@item b
8751Bytes.
8752@item h
8753Halfwords (two bytes).
8754@item w
8755Words (four bytes). This is the initial default.
8756@item g
8757Giant words (eight bytes).
8758@end table
8759
8760Each time you specify a unit size with @code{x}, that size becomes the
9a22f0d0
PM
8761default unit the next time you use @code{x}. For the @samp{i} format,
8762the unit size is ignored and is normally not written. For the @samp{s} format,
8763the unit size defaults to @samp{b}, unless it is explicitly given.
8764Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
876532-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
8766Note that the results depend on the programming language of the
8767current compilation unit. If the language is C, the @samp{s}
8768modifier will use the UTF-16 encoding while @samp{w} will use
8769UTF-32. The encoding is set by the programming language and cannot
8770be altered.
c906108c
SS
8771
8772@item @var{addr}, starting display address
8773@var{addr} is the address where you want @value{GDBN} to begin displaying
8774memory. The expression need not have a pointer value (though it may);
8775it is always interpreted as an integer address of a byte of memory.
8776@xref{Expressions, ,Expressions}, for more information on expressions. The default for
8777@var{addr} is usually just after the last address examined---but several
8778other commands also set the default address: @code{info breakpoints} (to
8779the address of the last breakpoint listed), @code{info line} (to the
8780starting address of a line), and @code{print} (if you use it to display
8781a value from memory).
8782@end table
8783
8784For example, @samp{x/3uh 0x54320} is a request to display three halfwords
8785(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
8786starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
8787words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 8788@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
8789
8790Since the letters indicating unit sizes are all distinct from the
8791letters specifying output formats, you do not have to remember whether
8792unit size or format comes first; either order works. The output
8793specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
8794(However, the count @var{n} must come first; @samp{wx4} does not work.)
8795
8796Even though the unit size @var{u} is ignored for the formats @samp{s}
8797and @samp{i}, you might still want to use a count @var{n}; for example,
8798@samp{3i} specifies that you want to see three machine instructions,
a4642986
MR
8799including any operands. For convenience, especially when used with
8800the @code{display} command, the @samp{i} format also prints branch delay
8801slot instructions, if any, beyond the count specified, which immediately
8802follow the last instruction that is within the count. The command
8803@code{disassemble} gives an alternative way of inspecting machine
8804instructions; see @ref{Machine Code,,Source and Machine Code}.
c906108c
SS
8805
8806All the defaults for the arguments to @code{x} are designed to make it
8807easy to continue scanning memory with minimal specifications each time
8808you use @code{x}. For example, after you have inspected three machine
8809instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
8810with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
8811the repeat count @var{n} is used again; the other arguments default as
8812for successive uses of @code{x}.
8813
2b28d209
PP
8814When examining machine instructions, the instruction at current program
8815counter is shown with a @code{=>} marker. For example:
8816
8817@smallexample
8818(@value{GDBP}) x/5i $pc-6
8819 0x804837f <main+11>: mov %esp,%ebp
8820 0x8048381 <main+13>: push %ecx
8821 0x8048382 <main+14>: sub $0x4,%esp
8822=> 0x8048385 <main+17>: movl $0x8048460,(%esp)
8823 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
8824@end smallexample
8825
c906108c
SS
8826@cindex @code{$_}, @code{$__}, and value history
8827The addresses and contents printed by the @code{x} command are not saved
8828in the value history because there is often too much of them and they
8829would get in the way. Instead, @value{GDBN} makes these values available for
8830subsequent use in expressions as values of the convenience variables
8831@code{$_} and @code{$__}. After an @code{x} command, the last address
8832examined is available for use in expressions in the convenience variable
8833@code{$_}. The contents of that address, as examined, are available in
8834the convenience variable @code{$__}.
8835
8836If the @code{x} command has a repeat count, the address and contents saved
8837are from the last memory unit printed; this is not the same as the last
8838address printed if several units were printed on the last line of output.
8839
09d4efe1 8840@cindex remote memory comparison
936d2992 8841@cindex target memory comparison
09d4efe1 8842@cindex verify remote memory image
936d2992 8843@cindex verify target memory image
09d4efe1 8844When you are debugging a program running on a remote target machine
936d2992
PA
8845(@pxref{Remote Debugging}), you may wish to verify the program's image
8846in the remote machine's memory against the executable file you
8847downloaded to the target. Or, on any target, you may want to check
8848whether the program has corrupted its own read-only sections. The
8849@code{compare-sections} command is provided for such situations.
09d4efe1
EZ
8850
8851@table @code
8852@kindex compare-sections
95cf3b38 8853@item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
09d4efe1
EZ
8854Compare the data of a loadable section @var{section-name} in the
8855executable file of the program being debugged with the same section in
936d2992 8856the target machine's memory, and report any mismatches. With no
95cf3b38 8857arguments, compares all loadable sections. With an argument of
936d2992
PA
8858@code{-r}, compares all loadable read-only sections.
8859
8860Note: for remote targets, this command can be accelerated if the
8861target supports computing the CRC checksum of a block of memory
8862(@pxref{qCRC packet}).
09d4efe1
EZ
8863@end table
8864
6d2ebf8b 8865@node Auto Display
79a6e687 8866@section Automatic Display
c906108c
SS
8867@cindex automatic display
8868@cindex display of expressions
8869
8870If you find that you want to print the value of an expression frequently
8871(to see how it changes), you might want to add it to the @dfn{automatic
8872display list} so that @value{GDBN} prints its value each time your program stops.
8873Each expression added to the list is given a number to identify it;
8874to remove an expression from the list, you specify that number.
8875The automatic display looks like this:
8876
474c8240 8877@smallexample
c906108c
SS
88782: foo = 38
88793: bar[5] = (struct hack *) 0x3804
474c8240 8880@end smallexample
c906108c
SS
8881
8882@noindent
8883This display shows item numbers, expressions and their current values. As with
8884displays you request manually using @code{x} or @code{print}, you can
8885specify the output format you prefer; in fact, @code{display} decides
ea37ba09
DJ
8886whether to use @code{print} or @code{x} depending your format
8887specification---it uses @code{x} if you specify either the @samp{i}
8888or @samp{s} format, or a unit size; otherwise it uses @code{print}.
c906108c
SS
8889
8890@table @code
8891@kindex display
d4f3574e
SS
8892@item display @var{expr}
8893Add the expression @var{expr} to the list of expressions to display
c906108c
SS
8894each time your program stops. @xref{Expressions, ,Expressions}.
8895
8896@code{display} does not repeat if you press @key{RET} again after using it.
8897
d4f3574e 8898@item display/@var{fmt} @var{expr}
c906108c 8899For @var{fmt} specifying only a display format and not a size or
d4f3574e 8900count, add the expression @var{expr} to the auto-display list but
c906108c 8901arrange to display it each time in the specified format @var{fmt}.
79a6e687 8902@xref{Output Formats,,Output Formats}.
c906108c
SS
8903
8904@item display/@var{fmt} @var{addr}
8905For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
8906number of units, add the expression @var{addr} as a memory address to
8907be examined each time your program stops. Examining means in effect
79a6e687 8908doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
c906108c
SS
8909@end table
8910
8911For example, @samp{display/i $pc} can be helpful, to see the machine
8912instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 8913is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
8914
8915@table @code
8916@kindex delete display
8917@kindex undisplay
8918@item undisplay @var{dnums}@dots{}
8919@itemx delete display @var{dnums}@dots{}
c9174737
PA
8920Remove items from the list of expressions to display. Specify the
8921numbers of the displays that you want affected with the command
8922argument @var{dnums}. It can be a single display number, one of the
8923numbers shown in the first field of the @samp{info display} display;
8924or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
8925
8926@code{undisplay} does not repeat if you press @key{RET} after using it.
8927(Otherwise you would just get the error @samp{No display number @dots{}}.)
8928
8929@kindex disable display
8930@item disable display @var{dnums}@dots{}
8931Disable the display of item numbers @var{dnums}. A disabled display
8932item is not printed automatically, but is not forgotten. It may be
c9174737
PA
8933enabled again later. Specify the numbers of the displays that you
8934want affected with the command argument @var{dnums}. It can be a
8935single display number, one of the numbers shown in the first field of
8936the @samp{info display} display; or it could be a range of display
8937numbers, as in @code{2-4}.
c906108c
SS
8938
8939@kindex enable display
8940@item enable display @var{dnums}@dots{}
8941Enable display of item numbers @var{dnums}. It becomes effective once
8942again in auto display of its expression, until you specify otherwise.
c9174737
PA
8943Specify the numbers of the displays that you want affected with the
8944command argument @var{dnums}. It can be a single display number, one
8945of the numbers shown in the first field of the @samp{info display}
8946display; or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
8947
8948@item display
8949Display the current values of the expressions on the list, just as is
8950done when your program stops.
8951
8952@kindex info display
8953@item info display
8954Print the list of expressions previously set up to display
8955automatically, each one with its item number, but without showing the
8956values. This includes disabled expressions, which are marked as such.
8957It also includes expressions which would not be displayed right now
8958because they refer to automatic variables not currently available.
8959@end table
8960
15387254 8961@cindex display disabled out of scope
c906108c
SS
8962If a display expression refers to local variables, then it does not make
8963sense outside the lexical context for which it was set up. Such an
8964expression is disabled when execution enters a context where one of its
8965variables is not defined. For example, if you give the command
8966@code{display last_char} while inside a function with an argument
8967@code{last_char}, @value{GDBN} displays this argument while your program
8968continues to stop inside that function. When it stops elsewhere---where
8969there is no variable @code{last_char}---the display is disabled
8970automatically. The next time your program stops where @code{last_char}
8971is meaningful, you can enable the display expression once again.
8972
6d2ebf8b 8973@node Print Settings
79a6e687 8974@section Print Settings
c906108c
SS
8975
8976@cindex format options
8977@cindex print settings
8978@value{GDBN} provides the following ways to control how arrays, structures,
8979and symbols are printed.
8980
8981@noindent
8982These settings are useful for debugging programs in any language:
8983
8984@table @code
4644b6e3 8985@kindex set print
c906108c
SS
8986@item set print address
8987@itemx set print address on
4644b6e3 8988@cindex print/don't print memory addresses
c906108c
SS
8989@value{GDBN} prints memory addresses showing the location of stack
8990traces, structure values, pointer values, breakpoints, and so forth,
8991even when it also displays the contents of those addresses. The default
8992is @code{on}. For example, this is what a stack frame display looks like with
8993@code{set print address on}:
8994
8995@smallexample
8996@group
8997(@value{GDBP}) f
8998#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
8999 at input.c:530
9000530 if (lquote != def_lquote)
9001@end group
9002@end smallexample
9003
9004@item set print address off
9005Do not print addresses when displaying their contents. For example,
9006this is the same stack frame displayed with @code{set print address off}:
9007
9008@smallexample
9009@group
9010(@value{GDBP}) set print addr off
9011(@value{GDBP}) f
9012#0 set_quotes (lq="<<", rq=">>") at input.c:530
9013530 if (lquote != def_lquote)
9014@end group
9015@end smallexample
9016
9017You can use @samp{set print address off} to eliminate all machine
9018dependent displays from the @value{GDBN} interface. For example, with
9019@code{print address off}, you should get the same text for backtraces on
9020all machines---whether or not they involve pointer arguments.
9021
4644b6e3 9022@kindex show print
c906108c
SS
9023@item show print address
9024Show whether or not addresses are to be printed.
9025@end table
9026
9027When @value{GDBN} prints a symbolic address, it normally prints the
9028closest earlier symbol plus an offset. If that symbol does not uniquely
9029identify the address (for example, it is a name whose scope is a single
9030source file), you may need to clarify. One way to do this is with
9031@code{info line}, for example @samp{info line *0x4537}. Alternately,
9032you can set @value{GDBN} to print the source file and line number when
9033it prints a symbolic address:
9034
9035@table @code
c906108c 9036@item set print symbol-filename on
9c16f35a
EZ
9037@cindex source file and line of a symbol
9038@cindex symbol, source file and line
c906108c
SS
9039Tell @value{GDBN} to print the source file name and line number of a
9040symbol in the symbolic form of an address.
9041
9042@item set print symbol-filename off
9043Do not print source file name and line number of a symbol. This is the
9044default.
9045
c906108c
SS
9046@item show print symbol-filename
9047Show whether or not @value{GDBN} will print the source file name and
9048line number of a symbol in the symbolic form of an address.
9049@end table
9050
9051Another situation where it is helpful to show symbol filenames and line
9052numbers is when disassembling code; @value{GDBN} shows you the line
9053number and source file that corresponds to each instruction.
9054
9055Also, you may wish to see the symbolic form only if the address being
9056printed is reasonably close to the closest earlier symbol:
9057
9058@table @code
c906108c 9059@item set print max-symbolic-offset @var{max-offset}
f81d1120 9060@itemx set print max-symbolic-offset unlimited
4644b6e3 9061@cindex maximum value for offset of closest symbol
c906108c
SS
9062Tell @value{GDBN} to only display the symbolic form of an address if the
9063offset between the closest earlier symbol and the address is less than
f81d1120
PA
9064@var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
9065to always print the symbolic form of an address if any symbol precedes
9066it. Zero is equivalent to @code{unlimited}.
c906108c 9067
c906108c
SS
9068@item show print max-symbolic-offset
9069Ask how large the maximum offset is that @value{GDBN} prints in a
9070symbolic address.
9071@end table
9072
9073@cindex wild pointer, interpreting
9074@cindex pointer, finding referent
9075If you have a pointer and you are not sure where it points, try
9076@samp{set print symbol-filename on}. Then you can determine the name
9077and source file location of the variable where it points, using
9078@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
9079For example, here @value{GDBN} shows that a variable @code{ptt} points
9080at another variable @code{t}, defined in @file{hi2.c}:
9081
474c8240 9082@smallexample
c906108c
SS
9083(@value{GDBP}) set print symbol-filename on
9084(@value{GDBP}) p/a ptt
9085$4 = 0xe008 <t in hi2.c>
474c8240 9086@end smallexample
c906108c
SS
9087
9088@quotation
9089@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
9090does not show the symbol name and filename of the referent, even with
9091the appropriate @code{set print} options turned on.
9092@end quotation
9093
9cb709b6
TT
9094You can also enable @samp{/a}-like formatting all the time using
9095@samp{set print symbol on}:
9096
9097@table @code
9098@item set print symbol on
9099Tell @value{GDBN} to print the symbol corresponding to an address, if
9100one exists.
9101
9102@item set print symbol off
9103Tell @value{GDBN} not to print the symbol corresponding to an
9104address. In this mode, @value{GDBN} will still print the symbol
9105corresponding to pointers to functions. This is the default.
9106
9107@item show print symbol
9108Show whether @value{GDBN} will display the symbol corresponding to an
9109address.
9110@end table
9111
c906108c
SS
9112Other settings control how different kinds of objects are printed:
9113
9114@table @code
c906108c
SS
9115@item set print array
9116@itemx set print array on
4644b6e3 9117@cindex pretty print arrays
c906108c
SS
9118Pretty print arrays. This format is more convenient to read,
9119but uses more space. The default is off.
9120
9121@item set print array off
9122Return to compressed format for arrays.
9123
c906108c
SS
9124@item show print array
9125Show whether compressed or pretty format is selected for displaying
9126arrays.
9127
3c9c013a
JB
9128@cindex print array indexes
9129@item set print array-indexes
9130@itemx set print array-indexes on
9131Print the index of each element when displaying arrays. May be more
9132convenient to locate a given element in the array or quickly find the
9133index of a given element in that printed array. The default is off.
9134
9135@item set print array-indexes off
9136Stop printing element indexes when displaying arrays.
9137
9138@item show print array-indexes
9139Show whether the index of each element is printed when displaying
9140arrays.
9141
c906108c 9142@item set print elements @var{number-of-elements}
f81d1120 9143@itemx set print elements unlimited
4644b6e3 9144@cindex number of array elements to print
9c16f35a 9145@cindex limit on number of printed array elements
c906108c
SS
9146Set a limit on how many elements of an array @value{GDBN} will print.
9147If @value{GDBN} is printing a large array, it stops printing after it has
9148printed the number of elements set by the @code{set print elements} command.
9149This limit also applies to the display of strings.
d4f3574e 9150When @value{GDBN} starts, this limit is set to 200.
f81d1120
PA
9151Setting @var{number-of-elements} to @code{unlimited} or zero means
9152that the number of elements to print is unlimited.
c906108c 9153
c906108c
SS
9154@item show print elements
9155Display the number of elements of a large array that @value{GDBN} will print.
9156If the number is 0, then the printing is unlimited.
9157
b4740add 9158@item set print frame-arguments @var{value}
a0381d3a 9159@kindex set print frame-arguments
b4740add
JB
9160@cindex printing frame argument values
9161@cindex print all frame argument values
9162@cindex print frame argument values for scalars only
9163@cindex do not print frame argument values
9164This command allows to control how the values of arguments are printed
9165when the debugger prints a frame (@pxref{Frames}). The possible
9166values are:
9167
9168@table @code
9169@item all
4f5376b2 9170The values of all arguments are printed.
b4740add
JB
9171
9172@item scalars
9173Print the value of an argument only if it is a scalar. The value of more
9174complex arguments such as arrays, structures, unions, etc, is replaced
4f5376b2
JB
9175by @code{@dots{}}. This is the default. Here is an example where
9176only scalar arguments are shown:
b4740add
JB
9177
9178@smallexample
9179#1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
9180 at frame-args.c:23
9181@end smallexample
9182
9183@item none
9184None of the argument values are printed. Instead, the value of each argument
9185is replaced by @code{@dots{}}. In this case, the example above now becomes:
9186
9187@smallexample
9188#1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
9189 at frame-args.c:23
9190@end smallexample
9191@end table
9192
4f5376b2
JB
9193By default, only scalar arguments are printed. This command can be used
9194to configure the debugger to print the value of all arguments, regardless
9195of their type. However, it is often advantageous to not print the value
9196of more complex parameters. For instance, it reduces the amount of
9197information printed in each frame, making the backtrace more readable.
9198Also, it improves performance when displaying Ada frames, because
9199the computation of large arguments can sometimes be CPU-intensive,
9200especially in large applications. Setting @code{print frame-arguments}
9201to @code{scalars} (the default) or @code{none} avoids this computation,
9202thus speeding up the display of each Ada frame.
b4740add
JB
9203
9204@item show print frame-arguments
9205Show how the value of arguments should be displayed when printing a frame.
9206
e7045703
DE
9207@item set print raw frame-arguments on
9208Print frame arguments in raw, non pretty-printed, form.
9209
9210@item set print raw frame-arguments off
9211Print frame arguments in pretty-printed form, if there is a pretty-printer
9212for the value (@pxref{Pretty Printing}),
9213otherwise print the value in raw form.
9214This is the default.
9215
9216@item show print raw frame-arguments
9217Show whether to print frame arguments in raw form.
9218
36b11add 9219@anchor{set print entry-values}
e18b2753
JK
9220@item set print entry-values @var{value}
9221@kindex set print entry-values
9222Set printing of frame argument values at function entry. In some cases
9223@value{GDBN} can determine the value of function argument which was passed by
9224the function caller, even if the value was modified inside the called function
9225and therefore is different. With optimized code, the current value could be
9226unavailable, but the entry value may still be known.
9227
9228The default value is @code{default} (see below for its description). Older
9229@value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
9230this feature will behave in the @code{default} setting the same way as with the
9231@code{no} setting.
9232
9233This functionality is currently supported only by DWARF 2 debugging format and
9234the compiler has to produce @samp{DW_TAG_GNU_call_site} tags. With
9235@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
9236this information.
9237
9238The @var{value} parameter can be one of the following:
9239
9240@table @code
9241@item no
9242Print only actual parameter values, never print values from function entry
9243point.
9244@smallexample
9245#0 equal (val=5)
9246#0 different (val=6)
9247#0 lost (val=<optimized out>)
9248#0 born (val=10)
9249#0 invalid (val=<optimized out>)
9250@end smallexample
9251
9252@item only
9253Print only parameter values from function entry point. The actual parameter
9254values are never printed.
9255@smallexample
9256#0 equal (val@@entry=5)
9257#0 different (val@@entry=5)
9258#0 lost (val@@entry=5)
9259#0 born (val@@entry=<optimized out>)
9260#0 invalid (val@@entry=<optimized out>)
9261@end smallexample
9262
9263@item preferred
9264Print only parameter values from function entry point. If value from function
9265entry point is not known while the actual value is known, print the actual
9266value for such parameter.
9267@smallexample
9268#0 equal (val@@entry=5)
9269#0 different (val@@entry=5)
9270#0 lost (val@@entry=5)
9271#0 born (val=10)
9272#0 invalid (val@@entry=<optimized out>)
9273@end smallexample
9274
9275@item if-needed
9276Print actual parameter values. If actual parameter value is not known while
9277value from function entry point is known, print the entry point value for such
9278parameter.
9279@smallexample
9280#0 equal (val=5)
9281#0 different (val=6)
9282#0 lost (val@@entry=5)
9283#0 born (val=10)
9284#0 invalid (val=<optimized out>)
9285@end smallexample
9286
9287@item both
9288Always print both the actual parameter value and its value from function entry
9289point, even if values of one or both are not available due to compiler
9290optimizations.
9291@smallexample
9292#0 equal (val=5, val@@entry=5)
9293#0 different (val=6, val@@entry=5)
9294#0 lost (val=<optimized out>, val@@entry=5)
9295#0 born (val=10, val@@entry=<optimized out>)
9296#0 invalid (val=<optimized out>, val@@entry=<optimized out>)
9297@end smallexample
9298
9299@item compact
9300Print the actual parameter value if it is known and also its value from
9301function entry point if it is known. If neither is known, print for the actual
9302value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
9303values are known and identical, print the shortened
9304@code{param=param@@entry=VALUE} notation.
9305@smallexample
9306#0 equal (val=val@@entry=5)
9307#0 different (val=6, val@@entry=5)
9308#0 lost (val@@entry=5)
9309#0 born (val=10)
9310#0 invalid (val=<optimized out>)
9311@end smallexample
9312
9313@item default
9314Always print the actual parameter value. Print also its value from function
9315entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
9316if both values are known and identical, print the shortened
9317@code{param=param@@entry=VALUE} notation.
9318@smallexample
9319#0 equal (val=val@@entry=5)
9320#0 different (val=6, val@@entry=5)
9321#0 lost (val=<optimized out>, val@@entry=5)
9322#0 born (val=10)
9323#0 invalid (val=<optimized out>)
9324@end smallexample
9325@end table
9326
9327For analysis messages on possible failures of frame argument values at function
9328entry resolution see @ref{set debug entry-values}.
9329
9330@item show print entry-values
9331Show the method being used for printing of frame argument values at function
9332entry.
9333
f81d1120
PA
9334@item set print repeats @var{number-of-repeats}
9335@itemx set print repeats unlimited
9c16f35a
EZ
9336@cindex repeated array elements
9337Set the threshold for suppressing display of repeated array
d3e8051b 9338elements. When the number of consecutive identical elements of an
9c16f35a
EZ
9339array exceeds the threshold, @value{GDBN} prints the string
9340@code{"<repeats @var{n} times>"}, where @var{n} is the number of
9341identical repetitions, instead of displaying the identical elements
f81d1120
PA
9342themselves. Setting the threshold to @code{unlimited} or zero will
9343cause all elements to be individually printed. The default threshold
9344is 10.
9c16f35a
EZ
9345
9346@item show print repeats
9347Display the current threshold for printing repeated identical
9348elements.
9349
c906108c 9350@item set print null-stop
4644b6e3 9351@cindex @sc{null} elements in arrays
c906108c 9352Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 9353@sc{null} is encountered. This is useful when large arrays actually
c906108c 9354contain only short strings.
d4f3574e 9355The default is off.
c906108c 9356
9c16f35a
EZ
9357@item show print null-stop
9358Show whether @value{GDBN} stops printing an array on the first
9359@sc{null} character.
9360
c906108c 9361@item set print pretty on
9c16f35a
EZ
9362@cindex print structures in indented form
9363@cindex indentation in structure display
5d161b24 9364Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
9365per line, like this:
9366
9367@smallexample
9368@group
9369$1 = @{
9370 next = 0x0,
9371 flags = @{
9372 sweet = 1,
9373 sour = 1
9374 @},
9375 meat = 0x54 "Pork"
9376@}
9377@end group
9378@end smallexample
9379
9380@item set print pretty off
9381Cause @value{GDBN} to print structures in a compact format, like this:
9382
9383@smallexample
9384@group
9385$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
9386meat = 0x54 "Pork"@}
9387@end group
9388@end smallexample
9389
9390@noindent
9391This is the default format.
9392
c906108c
SS
9393@item show print pretty
9394Show which format @value{GDBN} is using to print structures.
9395
c906108c 9396@item set print sevenbit-strings on
4644b6e3
EZ
9397@cindex eight-bit characters in strings
9398@cindex octal escapes in strings
c906108c
SS
9399Print using only seven-bit characters; if this option is set,
9400@value{GDBN} displays any eight-bit characters (in strings or
9401character values) using the notation @code{\}@var{nnn}. This setting is
9402best if you are working in English (@sc{ascii}) and you use the
9403high-order bit of characters as a marker or ``meta'' bit.
9404
9405@item set print sevenbit-strings off
9406Print full eight-bit characters. This allows the use of more
9407international character sets, and is the default.
9408
c906108c
SS
9409@item show print sevenbit-strings
9410Show whether or not @value{GDBN} is printing only seven-bit characters.
9411
c906108c 9412@item set print union on
4644b6e3 9413@cindex unions in structures, printing
9c16f35a
EZ
9414Tell @value{GDBN} to print unions which are contained in structures
9415and other unions. This is the default setting.
c906108c
SS
9416
9417@item set print union off
9c16f35a
EZ
9418Tell @value{GDBN} not to print unions which are contained in
9419structures and other unions. @value{GDBN} will print @code{"@{...@}"}
9420instead.
c906108c 9421
c906108c
SS
9422@item show print union
9423Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 9424structures and other unions.
c906108c
SS
9425
9426For example, given the declarations
9427
9428@smallexample
9429typedef enum @{Tree, Bug@} Species;
9430typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 9431typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
9432 Bug_forms;
9433
9434struct thing @{
9435 Species it;
9436 union @{
9437 Tree_forms tree;
9438 Bug_forms bug;
9439 @} form;
9440@};
9441
9442struct thing foo = @{Tree, @{Acorn@}@};
9443@end smallexample
9444
9445@noindent
9446with @code{set print union on} in effect @samp{p foo} would print
9447
9448@smallexample
9449$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
9450@end smallexample
9451
9452@noindent
9453and with @code{set print union off} in effect it would print
9454
9455@smallexample
9456$1 = @{it = Tree, form = @{...@}@}
9457@end smallexample
9c16f35a
EZ
9458
9459@noindent
9460@code{set print union} affects programs written in C-like languages
9461and in Pascal.
c906108c
SS
9462@end table
9463
c906108c
SS
9464@need 1000
9465@noindent
b37052ae 9466These settings are of interest when debugging C@t{++} programs:
c906108c
SS
9467
9468@table @code
4644b6e3 9469@cindex demangling C@t{++} names
c906108c
SS
9470@item set print demangle
9471@itemx set print demangle on
b37052ae 9472Print C@t{++} names in their source form rather than in the encoded
c906108c 9473(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 9474linkage. The default is on.
c906108c 9475
c906108c 9476@item show print demangle
b37052ae 9477Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 9478
c906108c
SS
9479@item set print asm-demangle
9480@itemx set print asm-demangle on
b37052ae 9481Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
9482in assembler code printouts such as instruction disassemblies.
9483The default is off.
9484
c906108c 9485@item show print asm-demangle
b37052ae 9486Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
9487or demangled form.
9488
b37052ae
EZ
9489@cindex C@t{++} symbol decoding style
9490@cindex symbol decoding style, C@t{++}
a8f24a35 9491@kindex set demangle-style
c906108c
SS
9492@item set demangle-style @var{style}
9493Choose among several encoding schemes used by different compilers to
b37052ae 9494represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
9495
9496@table @code
9497@item auto
9498Allow @value{GDBN} to choose a decoding style by inspecting your program.
891df0ea 9499This is the default.
c906108c
SS
9500
9501@item gnu
b37052ae 9502Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c
SS
9503
9504@item hp
b37052ae 9505Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
9506
9507@item lucid
b37052ae 9508Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
9509
9510@item arm
b37052ae 9511Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
9512@strong{Warning:} this setting alone is not sufficient to allow
9513debugging @code{cfront}-generated executables. @value{GDBN} would
9514require further enhancement to permit that.
9515
9516@end table
9517If you omit @var{style}, you will see a list of possible formats.
9518
c906108c 9519@item show demangle-style
b37052ae 9520Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 9521
c906108c
SS
9522@item set print object
9523@itemx set print object on
4644b6e3 9524@cindex derived type of an object, printing
9c16f35a 9525@cindex display derived types
c906108c
SS
9526When displaying a pointer to an object, identify the @emph{actual}
9527(derived) type of the object rather than the @emph{declared} type, using
625c0d47
TT
9528the virtual function table. Note that the virtual function table is
9529required---this feature can only work for objects that have run-time
9530type identification; a single virtual method in the object's declared
8264ba82
AG
9531type is sufficient. Note that this setting is also taken into account when
9532working with variable objects via MI (@pxref{GDB/MI}).
c906108c
SS
9533
9534@item set print object off
9535Display only the declared type of objects, without reference to the
9536virtual function table. This is the default setting.
9537
c906108c
SS
9538@item show print object
9539Show whether actual, or declared, object types are displayed.
9540
c906108c
SS
9541@item set print static-members
9542@itemx set print static-members on
4644b6e3 9543@cindex static members of C@t{++} objects
b37052ae 9544Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
9545
9546@item set print static-members off
b37052ae 9547Do not print static members when displaying a C@t{++} object.
c906108c 9548
c906108c 9549@item show print static-members
9c16f35a
EZ
9550Show whether C@t{++} static members are printed or not.
9551
9552@item set print pascal_static-members
9553@itemx set print pascal_static-members on
d3e8051b
EZ
9554@cindex static members of Pascal objects
9555@cindex Pascal objects, static members display
9c16f35a
EZ
9556Print static members when displaying a Pascal object. The default is on.
9557
9558@item set print pascal_static-members off
9559Do not print static members when displaying a Pascal object.
9560
9561@item show print pascal_static-members
9562Show whether Pascal static members are printed or not.
c906108c
SS
9563
9564@c These don't work with HP ANSI C++ yet.
c906108c
SS
9565@item set print vtbl
9566@itemx set print vtbl on
4644b6e3 9567@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
9568@cindex virtual functions (C@t{++}) display
9569@cindex VTBL display
b37052ae 9570Pretty print C@t{++} virtual function tables. The default is off.
c906108c 9571(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 9572ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
9573
9574@item set print vtbl off
b37052ae 9575Do not pretty print C@t{++} virtual function tables.
c906108c 9576
c906108c 9577@item show print vtbl
b37052ae 9578Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 9579@end table
c906108c 9580
4c374409
JK
9581@node Pretty Printing
9582@section Pretty Printing
9583
9584@value{GDBN} provides a mechanism to allow pretty-printing of values using
9585Python code. It greatly simplifies the display of complex objects. This
9586mechanism works for both MI and the CLI.
9587
7b51bc51
DE
9588@menu
9589* Pretty-Printer Introduction:: Introduction to pretty-printers
9590* Pretty-Printer Example:: An example pretty-printer
9591* Pretty-Printer Commands:: Pretty-printer commands
9592@end menu
9593
9594@node Pretty-Printer Introduction
9595@subsection Pretty-Printer Introduction
9596
9597When @value{GDBN} prints a value, it first sees if there is a pretty-printer
9598registered for the value. If there is then @value{GDBN} invokes the
9599pretty-printer to print the value. Otherwise the value is printed normally.
9600
9601Pretty-printers are normally named. This makes them easy to manage.
9602The @samp{info pretty-printer} command will list all the installed
9603pretty-printers with their names.
9604If a pretty-printer can handle multiple data types, then its
9605@dfn{subprinters} are the printers for the individual data types.
9606Each such subprinter has its own name.
4e04c971 9607The format of the name is @var{printer-name};@var{subprinter-name}.
7b51bc51
DE
9608
9609Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
9610Typically they are automatically loaded and registered when the corresponding
9611debug information is loaded, thus making them available without having to
9612do anything special.
9613
9614There are three places where a pretty-printer can be registered.
9615
9616@itemize @bullet
9617@item
9618Pretty-printers registered globally are available when debugging
9619all inferiors.
9620
9621@item
9622Pretty-printers registered with a program space are available only
9623when debugging that program.
9624@xref{Progspaces In Python}, for more details on program spaces in Python.
9625
9626@item
9627Pretty-printers registered with an objfile are loaded and unloaded
9628with the corresponding objfile (e.g., shared library).
9629@xref{Objfiles In Python}, for more details on objfiles in Python.
9630@end itemize
9631
9632@xref{Selecting Pretty-Printers}, for further information on how
9633pretty-printers are selected,
9634
9635@xref{Writing a Pretty-Printer}, for implementing pretty printers
9636for new types.
9637
9638@node Pretty-Printer Example
9639@subsection Pretty-Printer Example
9640
9641Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
4c374409
JK
9642
9643@smallexample
9644(@value{GDBP}) print s
9645$1 = @{
9646 static npos = 4294967295,
9647 _M_dataplus = @{
9648 <std::allocator<char>> = @{
9649 <__gnu_cxx::new_allocator<char>> = @{
9650 <No data fields>@}, <No data fields>
9651 @},
9652 members of std::basic_string<char, std::char_traits<char>,
9653 std::allocator<char> >::_Alloc_hider:
9654 _M_p = 0x804a014 "abcd"
9655 @}
9656@}
9657@end smallexample
9658
9659With a pretty-printer for @code{std::string} only the contents are printed:
9660
9661@smallexample
9662(@value{GDBP}) print s
9663$2 = "abcd"
9664@end smallexample
9665
7b51bc51
DE
9666@node Pretty-Printer Commands
9667@subsection Pretty-Printer Commands
9668@cindex pretty-printer commands
9669
9670@table @code
9671@kindex info pretty-printer
9672@item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9673Print the list of installed pretty-printers.
9674This includes disabled pretty-printers, which are marked as such.
9675
9676@var{object-regexp} is a regular expression matching the objects
9677whose pretty-printers to list.
9678Objects can be @code{global}, the program space's file
9679(@pxref{Progspaces In Python}),
9680and the object files within that program space (@pxref{Objfiles In Python}).
9681@xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
9682looks up a printer from these three objects.
9683
9684@var{name-regexp} is a regular expression matching the name of the printers
9685to list.
9686
9687@kindex disable pretty-printer
9688@item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9689Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
9690A disabled pretty-printer is not forgotten, it may be enabled again later.
9691
9692@kindex enable pretty-printer
9693@item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9694Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
9695@end table
9696
9697Example:
9698
9699Suppose we have three pretty-printers installed: one from library1.so
9700named @code{foo} that prints objects of type @code{foo}, and
9701another from library2.so named @code{bar} that prints two types of objects,
9702@code{bar1} and @code{bar2}.
9703
9704@smallexample
9705(gdb) info pretty-printer
9706library1.so:
9707 foo
9708library2.so:
9709 bar
9710 bar1
9711 bar2
9712(gdb) info pretty-printer library2
9713library2.so:
9714 bar
9715 bar1
9716 bar2
9717(gdb) disable pretty-printer library1
97181 printer disabled
97192 of 3 printers enabled
9720(gdb) info pretty-printer
9721library1.so:
9722 foo [disabled]
9723library2.so:
9724 bar
9725 bar1
9726 bar2
9727(gdb) disable pretty-printer library2 bar:bar1
97281 printer disabled
97291 of 3 printers enabled
9730(gdb) info pretty-printer library2
9731library1.so:
9732 foo [disabled]
9733library2.so:
9734 bar
9735 bar1 [disabled]
9736 bar2
9737(gdb) disable pretty-printer library2 bar
97381 printer disabled
97390 of 3 printers enabled
9740(gdb) info pretty-printer library2
9741library1.so:
9742 foo [disabled]
9743library2.so:
9744 bar [disabled]
9745 bar1 [disabled]
9746 bar2
9747@end smallexample
9748
9749Note that for @code{bar} the entire printer can be disabled,
9750as can each individual subprinter.
4c374409 9751
6d2ebf8b 9752@node Value History
79a6e687 9753@section Value History
c906108c
SS
9754
9755@cindex value history
9c16f35a 9756@cindex history of values printed by @value{GDBN}
5d161b24
DB
9757Values printed by the @code{print} command are saved in the @value{GDBN}
9758@dfn{value history}. This allows you to refer to them in other expressions.
9759Values are kept until the symbol table is re-read or discarded
9760(for example with the @code{file} or @code{symbol-file} commands).
9761When the symbol table changes, the value history is discarded,
9762since the values may contain pointers back to the types defined in the
c906108c
SS
9763symbol table.
9764
9765@cindex @code{$}
9766@cindex @code{$$}
9767@cindex history number
9768The values printed are given @dfn{history numbers} by which you can
9769refer to them. These are successive integers starting with one.
9770@code{print} shows you the history number assigned to a value by
9771printing @samp{$@var{num} = } before the value; here @var{num} is the
9772history number.
9773
9774To refer to any previous value, use @samp{$} followed by the value's
9775history number. The way @code{print} labels its output is designed to
9776remind you of this. Just @code{$} refers to the most recent value in
9777the history, and @code{$$} refers to the value before that.
9778@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
9779is the value just prior to @code{$$}, @code{$$1} is equivalent to
9780@code{$$}, and @code{$$0} is equivalent to @code{$}.
9781
9782For example, suppose you have just printed a pointer to a structure and
9783want to see the contents of the structure. It suffices to type
9784
474c8240 9785@smallexample
c906108c 9786p *$
474c8240 9787@end smallexample
c906108c
SS
9788
9789If you have a chain of structures where the component @code{next} points
9790to the next one, you can print the contents of the next one with this:
9791
474c8240 9792@smallexample
c906108c 9793p *$.next
474c8240 9794@end smallexample
c906108c
SS
9795
9796@noindent
9797You can print successive links in the chain by repeating this
9798command---which you can do by just typing @key{RET}.
9799
9800Note that the history records values, not expressions. If the value of
9801@code{x} is 4 and you type these commands:
9802
474c8240 9803@smallexample
c906108c
SS
9804print x
9805set x=5
474c8240 9806@end smallexample
c906108c
SS
9807
9808@noindent
9809then the value recorded in the value history by the @code{print} command
9810remains 4 even though the value of @code{x} has changed.
9811
9812@table @code
9813@kindex show values
9814@item show values
9815Print the last ten values in the value history, with their item numbers.
9816This is like @samp{p@ $$9} repeated ten times, except that @code{show
9817values} does not change the history.
9818
9819@item show values @var{n}
9820Print ten history values centered on history item number @var{n}.
9821
9822@item show values +
9823Print ten history values just after the values last printed. If no more
9824values are available, @code{show values +} produces no display.
9825@end table
9826
9827Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
9828same effect as @samp{show values +}.
9829
6d2ebf8b 9830@node Convenience Vars
79a6e687 9831@section Convenience Variables
c906108c
SS
9832
9833@cindex convenience variables
9c16f35a 9834@cindex user-defined variables
c906108c
SS
9835@value{GDBN} provides @dfn{convenience variables} that you can use within
9836@value{GDBN} to hold on to a value and refer to it later. These variables
9837exist entirely within @value{GDBN}; they are not part of your program, and
9838setting a convenience variable has no direct effect on further execution
9839of your program. That is why you can use them freely.
9840
9841Convenience variables are prefixed with @samp{$}. Any name preceded by
9842@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 9843the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c 9844(Value history references, in contrast, are @emph{numbers} preceded
79a6e687 9845by @samp{$}. @xref{Value History, ,Value History}.)
c906108c
SS
9846
9847You can save a value in a convenience variable with an assignment
9848expression, just as you would set a variable in your program.
9849For example:
9850
474c8240 9851@smallexample
c906108c 9852set $foo = *object_ptr
474c8240 9853@end smallexample
c906108c
SS
9854
9855@noindent
9856would save in @code{$foo} the value contained in the object pointed to by
9857@code{object_ptr}.
9858
9859Using a convenience variable for the first time creates it, but its
9860value is @code{void} until you assign a new value. You can alter the
9861value with another assignment at any time.
9862
9863Convenience variables have no fixed types. You can assign a convenience
9864variable any type of value, including structures and arrays, even if
9865that variable already has a value of a different type. The convenience
9866variable, when used as an expression, has the type of its current value.
9867
9868@table @code
9869@kindex show convenience
f47f77df 9870@cindex show all user variables and functions
c906108c 9871@item show convenience
f47f77df
DE
9872Print a list of convenience variables used so far, and their values,
9873as well as a list of the convenience functions.
d4f3574e 9874Abbreviated @code{show conv}.
53e5f3cf
AS
9875
9876@kindex init-if-undefined
9877@cindex convenience variables, initializing
9878@item init-if-undefined $@var{variable} = @var{expression}
9879Set a convenience variable if it has not already been set. This is useful
9880for user-defined commands that keep some state. It is similar, in concept,
9881to using local static variables with initializers in C (except that
9882convenience variables are global). It can also be used to allow users to
9883override default values used in a command script.
9884
9885If the variable is already defined then the expression is not evaluated so
9886any side-effects do not occur.
c906108c
SS
9887@end table
9888
9889One of the ways to use a convenience variable is as a counter to be
9890incremented or a pointer to be advanced. For example, to print
9891a field from successive elements of an array of structures:
9892
474c8240 9893@smallexample
c906108c
SS
9894set $i = 0
9895print bar[$i++]->contents
474c8240 9896@end smallexample
c906108c 9897
d4f3574e
SS
9898@noindent
9899Repeat that command by typing @key{RET}.
c906108c
SS
9900
9901Some convenience variables are created automatically by @value{GDBN} and given
9902values likely to be useful.
9903
9904@table @code
41afff9a 9905@vindex $_@r{, convenience variable}
c906108c
SS
9906@item $_
9907The variable @code{$_} is automatically set by the @code{x} command to
79a6e687 9908the last address examined (@pxref{Memory, ,Examining Memory}). Other
c906108c
SS
9909commands which provide a default address for @code{x} to examine also
9910set @code{$_} to that address; these commands include @code{info line}
9911and @code{info breakpoint}. The type of @code{$_} is @code{void *}
9912except when set by the @code{x} command, in which case it is a pointer
9913to the type of @code{$__}.
9914
41afff9a 9915@vindex $__@r{, convenience variable}
c906108c
SS
9916@item $__
9917The variable @code{$__} is automatically set by the @code{x} command
9918to the value found in the last address examined. Its type is chosen
9919to match the format in which the data was printed.
9920
9921@item $_exitcode
41afff9a 9922@vindex $_exitcode@r{, convenience variable}
0c557179
SDJ
9923When the program being debugged terminates normally, @value{GDBN}
9924automatically sets this variable to the exit code of the program, and
9925resets @code{$_exitsignal} to @code{void}.
9926
9927@item $_exitsignal
9928@vindex $_exitsignal@r{, convenience variable}
9929When the program being debugged dies due to an uncaught signal,
9930@value{GDBN} automatically sets this variable to that signal's number,
9931and resets @code{$_exitcode} to @code{void}.
9932
9933To distinguish between whether the program being debugged has exited
9934(i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
9935@code{$_exitsignal} is not @code{void}), the convenience function
9936@code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
9937Functions}). For example, considering the following source code:
9938
9939@smallexample
9940#include <signal.h>
9941
9942int
9943main (int argc, char *argv[])
9944@{
9945 raise (SIGALRM);
9946 return 0;
9947@}
9948@end smallexample
9949
9950A valid way of telling whether the program being debugged has exited
9951or signalled would be:
9952
9953@smallexample
9954(@value{GDBP}) define has_exited_or_signalled
9955Type commands for definition of ``has_exited_or_signalled''.
9956End with a line saying just ``end''.
9957>if $_isvoid ($_exitsignal)
9958 >echo The program has exited\n
9959 >else
9960 >echo The program has signalled\n
9961 >end
9962>end
9963(@value{GDBP}) run
9964Starting program:
9965
9966Program terminated with signal SIGALRM, Alarm clock.
9967The program no longer exists.
9968(@value{GDBP}) has_exited_or_signalled
9969The program has signalled
9970@end smallexample
9971
9972As can be seen, @value{GDBN} correctly informs that the program being
9973debugged has signalled, since it calls @code{raise} and raises a
9974@code{SIGALRM} signal. If the program being debugged had not called
9975@code{raise}, then @value{GDBN} would report a normal exit:
9976
9977@smallexample
9978(@value{GDBP}) has_exited_or_signalled
9979The program has exited
9980@end smallexample
4aa995e1 9981
72f1fe8a
TT
9982@item $_exception
9983The variable @code{$_exception} is set to the exception object being
9984thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
9985
62e5f89c
SDJ
9986@item $_probe_argc
9987@itemx $_probe_arg0@dots{}$_probe_arg11
9988Arguments to a static probe. @xref{Static Probe Points}.
9989
0fb4aa4b
PA
9990@item $_sdata
9991@vindex $_sdata@r{, inspect, convenience variable}
9992The variable @code{$_sdata} contains extra collected static tracepoint
9993data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
9994@code{$_sdata} could be empty, if not inspecting a trace buffer, or
9995if extra static tracepoint data has not been collected.
9996
4aa995e1
PA
9997@item $_siginfo
9998@vindex $_siginfo@r{, convenience variable}
ec7e75e7
PP
9999The variable @code{$_siginfo} contains extra signal information
10000(@pxref{extra signal information}). Note that @code{$_siginfo}
10001could be empty, if the application has not yet received any signals.
10002For example, it will be empty before you execute the @code{run} command.
711e434b
PM
10003
10004@item $_tlb
10005@vindex $_tlb@r{, convenience variable}
10006The variable @code{$_tlb} is automatically set when debugging
10007applications running on MS-Windows in native mode or connected to
10008gdbserver that supports the @code{qGetTIBAddr} request.
10009@xref{General Query Packets}.
10010This variable contains the address of the thread information block.
10011
c906108c
SS
10012@end table
10013
53a5351d
JM
10014On HP-UX systems, if you refer to a function or variable name that
10015begins with a dollar sign, @value{GDBN} searches for a user or system
10016name first, before it searches for a convenience variable.
c906108c 10017
a72c3253
DE
10018@node Convenience Funs
10019@section Convenience Functions
10020
bc3b79fd
TJB
10021@cindex convenience functions
10022@value{GDBN} also supplies some @dfn{convenience functions}. These
10023have a syntax similar to convenience variables. A convenience
10024function can be used in an expression just like an ordinary function;
10025however, a convenience function is implemented internally to
10026@value{GDBN}.
10027
a280dbd1
SDJ
10028These functions do not require @value{GDBN} to be configured with
10029@code{Python} support, which means that they are always available.
10030
10031@table @code
10032
10033@item $_isvoid (@var{expr})
10034@findex $_isvoid@r{, convenience function}
10035Return one if the expression @var{expr} is @code{void}. Otherwise it
10036returns zero.
10037
10038A @code{void} expression is an expression where the type of the result
10039is @code{void}. For example, you can examine a convenience variable
10040(see @ref{Convenience Vars,, Convenience Variables}) to check whether
10041it is @code{void}:
10042
10043@smallexample
10044(@value{GDBP}) print $_exitcode
10045$1 = void
10046(@value{GDBP}) print $_isvoid ($_exitcode)
10047$2 = 1
10048(@value{GDBP}) run
10049Starting program: ./a.out
10050[Inferior 1 (process 29572) exited normally]
10051(@value{GDBP}) print $_exitcode
10052$3 = 0
10053(@value{GDBP}) print $_isvoid ($_exitcode)
10054$4 = 0
10055@end smallexample
10056
10057In the example above, we used @code{$_isvoid} to check whether
10058@code{$_exitcode} is @code{void} before and after the execution of the
10059program being debugged. Before the execution there is no exit code to
10060be examined, therefore @code{$_exitcode} is @code{void}. After the
10061execution the program being debugged returned zero, therefore
10062@code{$_exitcode} is zero, which means that it is not @code{void}
10063anymore.
10064
10065The @code{void} expression can also be a call of a function from the
10066program being debugged. For example, given the following function:
10067
10068@smallexample
10069void
10070foo (void)
10071@{
10072@}
10073@end smallexample
10074
10075The result of calling it inside @value{GDBN} is @code{void}:
10076
10077@smallexample
10078(@value{GDBP}) print foo ()
10079$1 = void
10080(@value{GDBP}) print $_isvoid (foo ())
10081$2 = 1
10082(@value{GDBP}) set $v = foo ()
10083(@value{GDBP}) print $v
10084$3 = void
10085(@value{GDBP}) print $_isvoid ($v)
10086$4 = 1
10087@end smallexample
10088
10089@end table
10090
a72c3253
DE
10091These functions require @value{GDBN} to be configured with
10092@code{Python} support.
10093
10094@table @code
10095
10096@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
10097@findex $_memeq@r{, convenience function}
10098Returns one if the @var{length} bytes at the addresses given by
10099@var{buf1} and @var{buf2} are equal.
10100Otherwise it returns zero.
10101
10102@item $_regex(@var{str}, @var{regex})
10103@findex $_regex@r{, convenience function}
10104Returns one if the string @var{str} matches the regular expression
10105@var{regex}. Otherwise it returns zero.
10106The syntax of the regular expression is that specified by @code{Python}'s
10107regular expression support.
10108
10109@item $_streq(@var{str1}, @var{str2})
10110@findex $_streq@r{, convenience function}
10111Returns one if the strings @var{str1} and @var{str2} are equal.
10112Otherwise it returns zero.
10113
10114@item $_strlen(@var{str})
10115@findex $_strlen@r{, convenience function}
10116Returns the length of string @var{str}.
10117
10118@end table
10119
10120@value{GDBN} provides the ability to list and get help on
10121convenience functions.
10122
bc3b79fd
TJB
10123@table @code
10124@item help function
10125@kindex help function
10126@cindex show all convenience functions
10127Print a list of all convenience functions.
10128@end table
10129
6d2ebf8b 10130@node Registers
c906108c
SS
10131@section Registers
10132
10133@cindex registers
10134You can refer to machine register contents, in expressions, as variables
10135with names starting with @samp{$}. The names of registers are different
10136for each machine; use @code{info registers} to see the names used on
10137your machine.
10138
10139@table @code
10140@kindex info registers
10141@item info registers
10142Print the names and values of all registers except floating-point
c85508ee 10143and vector registers (in the selected stack frame).
c906108c
SS
10144
10145@kindex info all-registers
10146@cindex floating point registers
10147@item info all-registers
10148Print the names and values of all registers, including floating-point
c85508ee 10149and vector registers (in the selected stack frame).
c906108c
SS
10150
10151@item info registers @var{regname} @dots{}
10152Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
10153As discussed in detail below, register values are normally relative to
10154the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
10155the machine you are using, with or without the initial @samp{$}.
10156@end table
10157
e09f16f9
EZ
10158@cindex stack pointer register
10159@cindex program counter register
10160@cindex process status register
10161@cindex frame pointer register
10162@cindex standard registers
c906108c
SS
10163@value{GDBN} has four ``standard'' register names that are available (in
10164expressions) on most machines---whenever they do not conflict with an
10165architecture's canonical mnemonics for registers. The register names
10166@code{$pc} and @code{$sp} are used for the program counter register and
10167the stack pointer. @code{$fp} is used for a register that contains a
10168pointer to the current stack frame, and @code{$ps} is used for a
10169register that contains the processor status. For example,
10170you could print the program counter in hex with
10171
474c8240 10172@smallexample
c906108c 10173p/x $pc
474c8240 10174@end smallexample
c906108c
SS
10175
10176@noindent
10177or print the instruction to be executed next with
10178
474c8240 10179@smallexample
c906108c 10180x/i $pc
474c8240 10181@end smallexample
c906108c
SS
10182
10183@noindent
10184or add four to the stack pointer@footnote{This is a way of removing
10185one word from the stack, on machines where stacks grow downward in
10186memory (most machines, nowadays). This assumes that the innermost
10187stack frame is selected; setting @code{$sp} is not allowed when other
10188stack frames are selected. To pop entire frames off the stack,
10189regardless of machine architecture, use @code{return};
79a6e687 10190see @ref{Returning, ,Returning from a Function}.} with
c906108c 10191
474c8240 10192@smallexample
c906108c 10193set $sp += 4
474c8240 10194@end smallexample
c906108c
SS
10195
10196Whenever possible, these four standard register names are available on
10197your machine even though the machine has different canonical mnemonics,
10198so long as there is no conflict. The @code{info registers} command
10199shows the canonical names. For example, on the SPARC, @code{info
10200registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
10201can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
10202is an alias for the @sc{eflags} register.
c906108c
SS
10203
10204@value{GDBN} always considers the contents of an ordinary register as an
10205integer when the register is examined in this way. Some machines have
10206special registers which can hold nothing but floating point; these
10207registers are considered to have floating point values. There is no way
10208to refer to the contents of an ordinary register as floating point value
10209(although you can @emph{print} it as a floating point value with
10210@samp{print/f $@var{regname}}).
10211
10212Some registers have distinct ``raw'' and ``virtual'' data formats. This
10213means that the data format in which the register contents are saved by
10214the operating system is not the same one that your program normally
10215sees. For example, the registers of the 68881 floating point
10216coprocessor are always saved in ``extended'' (raw) format, but all C
10217programs expect to work with ``double'' (virtual) format. In such
5d161b24 10218cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
10219that makes sense for your program), but the @code{info registers} command
10220prints the data in both formats.
10221
36b80e65
EZ
10222@cindex SSE registers (x86)
10223@cindex MMX registers (x86)
10224Some machines have special registers whose contents can be interpreted
10225in several different ways. For example, modern x86-based machines
10226have SSE and MMX registers that can hold several values packed
10227together in several different formats. @value{GDBN} refers to such
10228registers in @code{struct} notation:
10229
10230@smallexample
10231(@value{GDBP}) print $xmm1
10232$1 = @{
10233 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
10234 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
10235 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
10236 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
10237 v4_int32 = @{0, 20657912, 11, 13@},
10238 v2_int64 = @{88725056443645952, 55834574859@},
10239 uint128 = 0x0000000d0000000b013b36f800000000
10240@}
10241@end smallexample
10242
10243@noindent
10244To set values of such registers, you need to tell @value{GDBN} which
10245view of the register you wish to change, as if you were assigning
10246value to a @code{struct} member:
10247
10248@smallexample
10249 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
10250@end smallexample
10251
c906108c 10252Normally, register values are relative to the selected stack frame
79a6e687 10253(@pxref{Selection, ,Selecting a Frame}). This means that you get the
c906108c
SS
10254value that the register would contain if all stack frames farther in
10255were exited and their saved registers restored. In order to see the
10256true contents of hardware registers, you must select the innermost
10257frame (with @samp{frame 0}).
10258
901461f8
PA
10259@cindex caller-saved registers
10260@cindex call-clobbered registers
10261@cindex volatile registers
10262@cindex <not saved> values
10263Usually ABIs reserve some registers as not needed to be saved by the
10264callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
10265registers). It may therefore not be possible for @value{GDBN} to know
10266the value a register had before the call (in other words, in the outer
10267frame), if the register value has since been changed by the callee.
10268@value{GDBN} tries to deduce where the inner frame saved
10269(``callee-saved'') registers, from the debug info, unwind info, or the
10270machine code generated by your compiler. If some register is not
10271saved, and @value{GDBN} knows the register is ``caller-saved'' (via
10272its own knowledge of the ABI, or because the debug/unwind info
10273explicitly says the register's value is undefined), @value{GDBN}
10274displays @w{@samp{<not saved>}} as the register's value. With targets
10275that @value{GDBN} has no knowledge of the register saving convention,
10276if a register was not saved by the callee, then its value and location
10277in the outer frame are assumed to be the same of the inner frame.
10278This is usually harmless, because if the register is call-clobbered,
10279the caller either does not care what is in the register after the
10280call, or has code to restore the value that it does care about. Note,
10281however, that if you change such a register in the outer frame, you
10282may also be affecting the inner frame. Also, the more ``outer'' the
10283frame is you're looking at, the more likely a call-clobbered
10284register's value is to be wrong, in the sense that it doesn't actually
10285represent the value the register had just before the call.
c906108c 10286
6d2ebf8b 10287@node Floating Point Hardware
79a6e687 10288@section Floating Point Hardware
c906108c
SS
10289@cindex floating point
10290
10291Depending on the configuration, @value{GDBN} may be able to give
10292you more information about the status of the floating point hardware.
10293
10294@table @code
10295@kindex info float
10296@item info float
10297Display hardware-dependent information about the floating
10298point unit. The exact contents and layout vary depending on the
10299floating point chip. Currently, @samp{info float} is supported on
10300the ARM and x86 machines.
10301@end table
c906108c 10302
e76f1f2e
AC
10303@node Vector Unit
10304@section Vector Unit
10305@cindex vector unit
10306
10307Depending on the configuration, @value{GDBN} may be able to give you
10308more information about the status of the vector unit.
10309
10310@table @code
10311@kindex info vector
10312@item info vector
10313Display information about the vector unit. The exact contents and
10314layout vary depending on the hardware.
10315@end table
10316
721c2651 10317@node OS Information
79a6e687 10318@section Operating System Auxiliary Information
721c2651
EZ
10319@cindex OS information
10320
10321@value{GDBN} provides interfaces to useful OS facilities that can help
10322you debug your program.
10323
b383017d
RM
10324@cindex auxiliary vector
10325@cindex vector, auxiliary
b383017d
RM
10326Some operating systems supply an @dfn{auxiliary vector} to programs at
10327startup. This is akin to the arguments and environment that you
10328specify for a program, but contains a system-dependent variety of
10329binary values that tell system libraries important details about the
10330hardware, operating system, and process. Each value's purpose is
10331identified by an integer tag; the meanings are well-known but system-specific.
10332Depending on the configuration and operating system facilities,
9c16f35a
EZ
10333@value{GDBN} may be able to show you this information. For remote
10334targets, this functionality may further depend on the remote stub's
427c3a89
DJ
10335support of the @samp{qXfer:auxv:read} packet, see
10336@ref{qXfer auxiliary vector read}.
b383017d
RM
10337
10338@table @code
10339@kindex info auxv
10340@item info auxv
10341Display the auxiliary vector of the inferior, which can be either a
e4937fc1 10342live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
10343numerically, and also shows names and text descriptions for recognized
10344tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 10345pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
10346most appropriate form for a recognized tag, and in hexadecimal for
10347an unrecognized tag.
10348@end table
10349
85d4a676
SS
10350On some targets, @value{GDBN} can access operating system-specific
10351information and show it to you. The types of information available
10352will differ depending on the type of operating system running on the
10353target. The mechanism used to fetch the data is described in
10354@ref{Operating System Information}. For remote targets, this
10355functionality depends on the remote stub's support of the
07e059b5
VP
10356@samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
10357
10358@table @code
a61408f8 10359@kindex info os
85d4a676
SS
10360@item info os @var{infotype}
10361
10362Display OS information of the requested type.
a61408f8 10363
85d4a676
SS
10364On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
10365
10366@anchor{linux info os infotypes}
10367@table @code
07e059b5 10368@kindex info os processes
85d4a676 10369@item processes
07e059b5 10370Display the list of processes on the target. For each process,
85d4a676
SS
10371@value{GDBN} prints the process identifier, the name of the user, the
10372command corresponding to the process, and the list of processor cores
10373that the process is currently running on. (To understand what these
10374properties mean, for this and the following info types, please consult
10375the general @sc{gnu}/Linux documentation.)
10376
10377@kindex info os procgroups
10378@item procgroups
10379Display the list of process groups on the target. For each process,
10380@value{GDBN} prints the identifier of the process group that it belongs
10381to, the command corresponding to the process group leader, the process
10382identifier, and the command line of the process. The list is sorted
10383first by the process group identifier, then by the process identifier,
10384so that processes belonging to the same process group are grouped together
10385and the process group leader is listed first.
10386
10387@kindex info os threads
10388@item threads
10389Display the list of threads running on the target. For each thread,
10390@value{GDBN} prints the identifier of the process that the thread
10391belongs to, the command of the process, the thread identifier, and the
10392processor core that it is currently running on. The main thread of a
10393process is not listed.
10394
10395@kindex info os files
10396@item files
10397Display the list of open file descriptors on the target. For each
10398file descriptor, @value{GDBN} prints the identifier of the process
10399owning the descriptor, the command of the owning process, the value
10400of the descriptor, and the target of the descriptor.
10401
10402@kindex info os sockets
10403@item sockets
10404Display the list of Internet-domain sockets on the target. For each
10405socket, @value{GDBN} prints the address and port of the local and
10406remote endpoints, the current state of the connection, the creator of
10407the socket, the IP address family of the socket, and the type of the
10408connection.
10409
10410@kindex info os shm
10411@item shm
10412Display the list of all System V shared-memory regions on the target.
10413For each shared-memory region, @value{GDBN} prints the region key,
10414the shared-memory identifier, the access permissions, the size of the
10415region, the process that created the region, the process that last
10416attached to or detached from the region, the current number of live
10417attaches to the region, and the times at which the region was last
10418attached to, detach from, and changed.
10419
10420@kindex info os semaphores
10421@item semaphores
10422Display the list of all System V semaphore sets on the target. For each
10423semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
10424set identifier, the access permissions, the number of semaphores in the
10425set, the user and group of the owner and creator of the semaphore set,
10426and the times at which the semaphore set was operated upon and changed.
10427
10428@kindex info os msg
10429@item msg
10430Display the list of all System V message queues on the target. For each
10431message queue, @value{GDBN} prints the message queue key, the message
10432queue identifier, the access permissions, the current number of bytes
10433on the queue, the current number of messages on the queue, the processes
10434that last sent and received a message on the queue, the user and group
10435of the owner and creator of the message queue, the times at which a
10436message was last sent and received on the queue, and the time at which
10437the message queue was last changed.
10438
10439@kindex info os modules
10440@item modules
10441Display the list of all loaded kernel modules on the target. For each
10442module, @value{GDBN} prints the module name, the size of the module in
10443bytes, the number of times the module is used, the dependencies of the
10444module, the status of the module, and the address of the loaded module
10445in memory.
10446@end table
10447
10448@item info os
10449If @var{infotype} is omitted, then list the possible values for
10450@var{infotype} and the kind of OS information available for each
10451@var{infotype}. If the target does not return a list of possible
10452types, this command will report an error.
07e059b5 10453@end table
721c2651 10454
29e57380 10455@node Memory Region Attributes
79a6e687 10456@section Memory Region Attributes
29e57380
C
10457@cindex memory region attributes
10458
b383017d 10459@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
10460required by regions of your target's memory. @value{GDBN} uses
10461attributes to determine whether to allow certain types of memory
10462accesses; whether to use specific width accesses; and whether to cache
10463target memory. By default the description of memory regions is
10464fetched from the target (if the current target supports this), but the
10465user can override the fetched regions.
29e57380
C
10466
10467Defined memory regions can be individually enabled and disabled. When a
10468memory region is disabled, @value{GDBN} uses the default attributes when
10469accessing memory in that region. Similarly, if no memory regions have
10470been defined, @value{GDBN} uses the default attributes when accessing
10471all memory.
10472
b383017d 10473When a memory region is defined, it is given a number to identify it;
29e57380
C
10474to enable, disable, or remove a memory region, you specify that number.
10475
10476@table @code
10477@kindex mem
bfac230e 10478@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
10479Define a memory region bounded by @var{lower} and @var{upper} with
10480attributes @var{attributes}@dots{}, and add it to the list of regions
10481monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
d3e8051b 10482case: it is treated as the target's maximum memory address.
bfac230e 10483(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 10484
fd79ecee
DJ
10485@item mem auto
10486Discard any user changes to the memory regions and use target-supplied
10487regions, if available, or no regions if the target does not support.
10488
29e57380
C
10489@kindex delete mem
10490@item delete mem @var{nums}@dots{}
09d4efe1
EZ
10491Remove memory regions @var{nums}@dots{} from the list of regions
10492monitored by @value{GDBN}.
29e57380
C
10493
10494@kindex disable mem
10495@item disable mem @var{nums}@dots{}
09d4efe1 10496Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 10497A disabled memory region is not forgotten.
29e57380
C
10498It may be enabled again later.
10499
10500@kindex enable mem
10501@item enable mem @var{nums}@dots{}
09d4efe1 10502Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
10503
10504@kindex info mem
10505@item info mem
10506Print a table of all defined memory regions, with the following columns
09d4efe1 10507for each region:
29e57380
C
10508
10509@table @emph
10510@item Memory Region Number
10511@item Enabled or Disabled.
b383017d 10512Enabled memory regions are marked with @samp{y}.
29e57380
C
10513Disabled memory regions are marked with @samp{n}.
10514
10515@item Lo Address
10516The address defining the inclusive lower bound of the memory region.
10517
10518@item Hi Address
10519The address defining the exclusive upper bound of the memory region.
10520
10521@item Attributes
10522The list of attributes set for this memory region.
10523@end table
10524@end table
10525
10526
10527@subsection Attributes
10528
b383017d 10529@subsubsection Memory Access Mode
29e57380
C
10530The access mode attributes set whether @value{GDBN} may make read or
10531write accesses to a memory region.
10532
10533While these attributes prevent @value{GDBN} from performing invalid
10534memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 10535etc.@: from accessing memory.
29e57380
C
10536
10537@table @code
10538@item ro
10539Memory is read only.
10540@item wo
10541Memory is write only.
10542@item rw
6ca652b0 10543Memory is read/write. This is the default.
29e57380
C
10544@end table
10545
10546@subsubsection Memory Access Size
d3e8051b 10547The access size attribute tells @value{GDBN} to use specific sized
29e57380
C
10548accesses in the memory region. Often memory mapped device registers
10549require specific sized accesses. If no access size attribute is
10550specified, @value{GDBN} may use accesses of any size.
10551
10552@table @code
10553@item 8
10554Use 8 bit memory accesses.
10555@item 16
10556Use 16 bit memory accesses.
10557@item 32
10558Use 32 bit memory accesses.
10559@item 64
10560Use 64 bit memory accesses.
10561@end table
10562
10563@c @subsubsection Hardware/Software Breakpoints
10564@c The hardware/software breakpoint attributes set whether @value{GDBN}
10565@c will use hardware or software breakpoints for the internal breakpoints
10566@c used by the step, next, finish, until, etc. commands.
10567@c
10568@c @table @code
10569@c @item hwbreak
b383017d 10570@c Always use hardware breakpoints
29e57380
C
10571@c @item swbreak (default)
10572@c @end table
10573
10574@subsubsection Data Cache
10575The data cache attributes set whether @value{GDBN} will cache target
10576memory. While this generally improves performance by reducing debug
10577protocol overhead, it can lead to incorrect results because @value{GDBN}
10578does not know about volatile variables or memory mapped device
10579registers.
10580
10581@table @code
10582@item cache
b383017d 10583Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
10584@item nocache
10585Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
10586@end table
10587
4b5752d0
VP
10588@subsection Memory Access Checking
10589@value{GDBN} can be instructed to refuse accesses to memory that is
10590not explicitly described. This can be useful if accessing such
10591regions has undesired effects for a specific target, or to provide
10592better error checking. The following commands control this behaviour.
10593
10594@table @code
10595@kindex set mem inaccessible-by-default
10596@item set mem inaccessible-by-default [on|off]
10597If @code{on} is specified, make @value{GDBN} treat memory not
10598explicitly described by the memory ranges as non-existent and refuse accesses
10599to such memory. The checks are only performed if there's at least one
10600memory range defined. If @code{off} is specified, make @value{GDBN}
10601treat the memory not explicitly described by the memory ranges as RAM.
56cf5405 10602The default value is @code{on}.
4b5752d0
VP
10603@kindex show mem inaccessible-by-default
10604@item show mem inaccessible-by-default
10605Show the current handling of accesses to unknown memory.
10606@end table
10607
10608
29e57380 10609@c @subsubsection Memory Write Verification
b383017d 10610@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
10611@c will re-reads data after each write to verify the write was successful.
10612@c
10613@c @table @code
10614@c @item verify
10615@c @item noverify (default)
10616@c @end table
10617
16d9dec6 10618@node Dump/Restore Files
79a6e687 10619@section Copy Between Memory and a File
16d9dec6
MS
10620@cindex dump/restore files
10621@cindex append data to a file
10622@cindex dump data to a file
10623@cindex restore data from a file
16d9dec6 10624
df5215a6
JB
10625You can use the commands @code{dump}, @code{append}, and
10626@code{restore} to copy data between target memory and a file. The
10627@code{dump} and @code{append} commands write data to a file, and the
10628@code{restore} command reads data from a file back into the inferior's
10629memory. Files may be in binary, Motorola S-record, Intel hex, or
10630Tektronix Hex format; however, @value{GDBN} can only append to binary
10631files.
10632
10633@table @code
10634
10635@kindex dump
10636@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
10637@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
10638Dump the contents of memory from @var{start_addr} to @var{end_addr},
10639or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 10640
df5215a6 10641The @var{format} parameter may be any one of:
16d9dec6 10642@table @code
df5215a6
JB
10643@item binary
10644Raw binary form.
10645@item ihex
10646Intel hex format.
10647@item srec
10648Motorola S-record format.
10649@item tekhex
10650Tektronix Hex format.
10651@end table
10652
10653@value{GDBN} uses the same definitions of these formats as the
10654@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
10655@var{format} is omitted, @value{GDBN} dumps the data in raw binary
10656form.
10657
10658@kindex append
10659@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
10660@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
10661Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 10662or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
10663(@value{GDBN} can only append data to files in raw binary form.)
10664
10665@kindex restore
10666@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
10667Restore the contents of file @var{filename} into memory. The
10668@code{restore} command can automatically recognize any known @sc{bfd}
10669file format, except for raw binary. To restore a raw binary file you
10670must specify the optional keyword @code{binary} after the filename.
16d9dec6 10671
b383017d 10672If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
10673contained in the file. Binary files always start at address zero, so
10674they will be restored at address @var{bias}. Other bfd files have
10675a built-in location; they will be restored at offset @var{bias}
10676from that location.
10677
10678If @var{start} and/or @var{end} are non-zero, then only data between
10679file offset @var{start} and file offset @var{end} will be restored.
b383017d 10680These offsets are relative to the addresses in the file, before
16d9dec6
MS
10681the @var{bias} argument is applied.
10682
10683@end table
10684
384ee23f
EZ
10685@node Core File Generation
10686@section How to Produce a Core File from Your Program
10687@cindex dump core from inferior
10688
10689A @dfn{core file} or @dfn{core dump} is a file that records the memory
10690image of a running process and its process status (register values
10691etc.). Its primary use is post-mortem debugging of a program that
10692crashed while it ran outside a debugger. A program that crashes
10693automatically produces a core file, unless this feature is disabled by
10694the user. @xref{Files}, for information on invoking @value{GDBN} in
10695the post-mortem debugging mode.
10696
10697Occasionally, you may wish to produce a core file of the program you
10698are debugging in order to preserve a snapshot of its state.
10699@value{GDBN} has a special command for that.
10700
10701@table @code
10702@kindex gcore
10703@kindex generate-core-file
10704@item generate-core-file [@var{file}]
10705@itemx gcore [@var{file}]
10706Produce a core dump of the inferior process. The optional argument
10707@var{file} specifies the file name where to put the core dump. If not
10708specified, the file name defaults to @file{core.@var{pid}}, where
10709@var{pid} is the inferior process ID.
10710
10711Note that this command is implemented only for some systems (as of
05b4bd79 10712this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
384ee23f
EZ
10713@end table
10714
a0eb71c5
KB
10715@node Character Sets
10716@section Character Sets
10717@cindex character sets
10718@cindex charset
10719@cindex translating between character sets
10720@cindex host character set
10721@cindex target character set
10722
10723If the program you are debugging uses a different character set to
10724represent characters and strings than the one @value{GDBN} uses itself,
10725@value{GDBN} can automatically translate between the character sets for
10726you. The character set @value{GDBN} uses we call the @dfn{host
10727character set}; the one the inferior program uses we call the
10728@dfn{target character set}.
10729
10730For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
10731uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
ea35711c 10732remote protocol (@pxref{Remote Debugging}) to debug a program
a0eb71c5
KB
10733running on an IBM mainframe, which uses the @sc{ebcdic} character set,
10734then the host character set is Latin-1, and the target character set is
10735@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 10736target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
10737@sc{ebcdic} and Latin 1 as you print character or string values, or use
10738character and string literals in expressions.
10739
10740@value{GDBN} has no way to automatically recognize which character set
10741the inferior program uses; you must tell it, using the @code{set
10742target-charset} command, described below.
10743
10744Here are the commands for controlling @value{GDBN}'s character set
10745support:
10746
10747@table @code
10748@item set target-charset @var{charset}
10749@kindex set target-charset
10af6951
EZ
10750Set the current target character set to @var{charset}. To display the
10751list of supported target character sets, type
10752@kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
a0eb71c5 10753
a0eb71c5
KB
10754@item set host-charset @var{charset}
10755@kindex set host-charset
10756Set the current host character set to @var{charset}.
10757
10758By default, @value{GDBN} uses a host character set appropriate to the
10759system it is running on; you can override that default using the
732f6a93
TT
10760@code{set host-charset} command. On some systems, @value{GDBN} cannot
10761automatically determine the appropriate host character set. In this
10762case, @value{GDBN} uses @samp{UTF-8}.
a0eb71c5
KB
10763
10764@value{GDBN} can only use certain character sets as its host character
c1b6b909 10765set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
10af6951 10766@value{GDBN} will list the host character sets it supports.
a0eb71c5
KB
10767
10768@item set charset @var{charset}
10769@kindex set charset
e33d66ec 10770Set the current host and target character sets to @var{charset}. As
10af6951
EZ
10771above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
10772@value{GDBN} will list the names of the character sets that can be used
e33d66ec
EZ
10773for both host and target.
10774
a0eb71c5 10775@item show charset
a0eb71c5 10776@kindex show charset
10af6951 10777Show the names of the current host and target character sets.
e33d66ec 10778
10af6951 10779@item show host-charset
a0eb71c5 10780@kindex show host-charset
10af6951 10781Show the name of the current host character set.
e33d66ec 10782
10af6951 10783@item show target-charset
a0eb71c5 10784@kindex show target-charset
10af6951 10785Show the name of the current target character set.
a0eb71c5 10786
10af6951
EZ
10787@item set target-wide-charset @var{charset}
10788@kindex set target-wide-charset
10789Set the current target's wide character set to @var{charset}. This is
10790the character set used by the target's @code{wchar_t} type. To
10791display the list of supported wide character sets, type
10792@kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
10793
10794@item show target-wide-charset
10795@kindex show target-wide-charset
10796Show the name of the current target's wide character set.
a0eb71c5
KB
10797@end table
10798
a0eb71c5
KB
10799Here is an example of @value{GDBN}'s character set support in action.
10800Assume that the following source code has been placed in the file
10801@file{charset-test.c}:
10802
10803@smallexample
10804#include <stdio.h>
10805
10806char ascii_hello[]
10807 = @{72, 101, 108, 108, 111, 44, 32, 119,
10808 111, 114, 108, 100, 33, 10, 0@};
10809char ibm1047_hello[]
10810 = @{200, 133, 147, 147, 150, 107, 64, 166,
10811 150, 153, 147, 132, 90, 37, 0@};
10812
10813main ()
10814@{
10815 printf ("Hello, world!\n");
10816@}
10998722 10817@end smallexample
a0eb71c5
KB
10818
10819In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
10820containing the string @samp{Hello, world!} followed by a newline,
10821encoded in the @sc{ascii} and @sc{ibm1047} character sets.
10822
10823We compile the program, and invoke the debugger on it:
10824
10825@smallexample
10826$ gcc -g charset-test.c -o charset-test
10827$ gdb -nw charset-test
10828GNU gdb 2001-12-19-cvs
10829Copyright 2001 Free Software Foundation, Inc.
10830@dots{}
f7dc1244 10831(@value{GDBP})
10998722 10832@end smallexample
a0eb71c5
KB
10833
10834We can use the @code{show charset} command to see what character sets
10835@value{GDBN} is currently using to interpret and display characters and
10836strings:
10837
10838@smallexample
f7dc1244 10839(@value{GDBP}) show charset
e33d66ec 10840The current host and target character set is `ISO-8859-1'.
f7dc1244 10841(@value{GDBP})
10998722 10842@end smallexample
a0eb71c5
KB
10843
10844For the sake of printing this manual, let's use @sc{ascii} as our
10845initial character set:
10846@smallexample
f7dc1244
EZ
10847(@value{GDBP}) set charset ASCII
10848(@value{GDBP}) show charset
e33d66ec 10849The current host and target character set is `ASCII'.
f7dc1244 10850(@value{GDBP})
10998722 10851@end smallexample
a0eb71c5
KB
10852
10853Let's assume that @sc{ascii} is indeed the correct character set for our
10854host system --- in other words, let's assume that if @value{GDBN} prints
10855characters using the @sc{ascii} character set, our terminal will display
10856them properly. Since our current target character set is also
10857@sc{ascii}, the contents of @code{ascii_hello} print legibly:
10858
10859@smallexample
f7dc1244 10860(@value{GDBP}) print ascii_hello
a0eb71c5 10861$1 = 0x401698 "Hello, world!\n"
f7dc1244 10862(@value{GDBP}) print ascii_hello[0]
a0eb71c5 10863$2 = 72 'H'
f7dc1244 10864(@value{GDBP})
10998722 10865@end smallexample
a0eb71c5
KB
10866
10867@value{GDBN} uses the target character set for character and string
10868literals you use in expressions:
10869
10870@smallexample
f7dc1244 10871(@value{GDBP}) print '+'
a0eb71c5 10872$3 = 43 '+'
f7dc1244 10873(@value{GDBP})
10998722 10874@end smallexample
a0eb71c5
KB
10875
10876The @sc{ascii} character set uses the number 43 to encode the @samp{+}
10877character.
10878
10879@value{GDBN} relies on the user to tell it which character set the
10880target program uses. If we print @code{ibm1047_hello} while our target
10881character set is still @sc{ascii}, we get jibberish:
10882
10883@smallexample
f7dc1244 10884(@value{GDBP}) print ibm1047_hello
a0eb71c5 10885$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 10886(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 10887$5 = 200 '\310'
f7dc1244 10888(@value{GDBP})
10998722 10889@end smallexample
a0eb71c5 10890
e33d66ec 10891If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
10892@value{GDBN} tells us the character sets it supports:
10893
10894@smallexample
f7dc1244 10895(@value{GDBP}) set target-charset
b383017d 10896ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 10897(@value{GDBP}) set target-charset
10998722 10898@end smallexample
a0eb71c5
KB
10899
10900We can select @sc{ibm1047} as our target character set, and examine the
10901program's strings again. Now the @sc{ascii} string is wrong, but
10902@value{GDBN} translates the contents of @code{ibm1047_hello} from the
10903target character set, @sc{ibm1047}, to the host character set,
10904@sc{ascii}, and they display correctly:
10905
10906@smallexample
f7dc1244
EZ
10907(@value{GDBP}) set target-charset IBM1047
10908(@value{GDBP}) show charset
e33d66ec
EZ
10909The current host character set is `ASCII'.
10910The current target character set is `IBM1047'.
f7dc1244 10911(@value{GDBP}) print ascii_hello
a0eb71c5 10912$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 10913(@value{GDBP}) print ascii_hello[0]
a0eb71c5 10914$7 = 72 '\110'
f7dc1244 10915(@value{GDBP}) print ibm1047_hello
a0eb71c5 10916$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 10917(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 10918$9 = 200 'H'
f7dc1244 10919(@value{GDBP})
10998722 10920@end smallexample
a0eb71c5
KB
10921
10922As above, @value{GDBN} uses the target character set for character and
10923string literals you use in expressions:
10924
10925@smallexample
f7dc1244 10926(@value{GDBP}) print '+'
a0eb71c5 10927$10 = 78 '+'
f7dc1244 10928(@value{GDBP})
10998722 10929@end smallexample
a0eb71c5 10930
e33d66ec 10931The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
10932character.
10933
b12039c6
YQ
10934@node Caching Target Data
10935@section Caching Data of Targets
10936@cindex caching data of targets
10937
10938@value{GDBN} caches data exchanged between the debugger and a target.
b26dfc9a
YQ
10939Each cache is associated with the address space of the inferior.
10940@xref{Inferiors and Programs}, about inferior and address space.
b12039c6
YQ
10941Such caching generally improves performance in remote debugging
10942(@pxref{Remote Debugging}), because it reduces the overhead of the
10943remote protocol by bundling memory reads and writes into large chunks.
10944Unfortunately, simply caching everything would lead to incorrect results,
10945since @value{GDBN} does not necessarily know anything about volatile
10946values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
10947(@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
10948is executing.
29b090c0
DE
10949Therefore, by default, @value{GDBN} only caches data
10950known to be on the stack@footnote{In non-stop mode, it is moderately
10951rare for a running thread to modify the stack of a stopped thread
10952in a way that would interfere with a backtrace, and caching of
29453a14
YQ
10953stack reads provides a significant speed up of remote backtraces.} or
10954in the code segment.
29b090c0 10955Other regions of memory can be explicitly marked as
27b81af3 10956cacheable; @pxref{Memory Region Attributes}.
09d4efe1
EZ
10957
10958@table @code
10959@kindex set remotecache
10960@item set remotecache on
10961@itemx set remotecache off
4e5d721f
DE
10962This option no longer does anything; it exists for compatibility
10963with old scripts.
09d4efe1
EZ
10964
10965@kindex show remotecache
10966@item show remotecache
4e5d721f
DE
10967Show the current state of the obsolete remotecache flag.
10968
10969@kindex set stack-cache
10970@item set stack-cache on
10971@itemx set stack-cache off
6dd315ba
YQ
10972Enable or disable caching of stack accesses. When @code{on}, use
10973caching. By default, this option is @code{on}.
4e5d721f
DE
10974
10975@kindex show stack-cache
10976@item show stack-cache
10977Show the current state of data caching for memory accesses.
09d4efe1 10978
29453a14
YQ
10979@kindex set code-cache
10980@item set code-cache on
10981@itemx set code-cache off
10982Enable or disable caching of code segment accesses. When @code{on},
10983use caching. By default, this option is @code{on}. This improves
10984performance of disassembly in remote debugging.
10985
10986@kindex show code-cache
10987@item show code-cache
10988Show the current state of target memory cache for code segment
10989accesses.
10990
09d4efe1 10991@kindex info dcache
4e5d721f 10992@item info dcache @r{[}line@r{]}
b26dfc9a
YQ
10993Print the information about the performance of data cache of the
10994current inferior's address space. The information displayed
10995includes the dcache width and depth, and for each cache line, its
10996number, address, and how many times it was referenced. This
10997command is useful for debugging the data cache operation.
4e5d721f
DE
10998
10999If a line number is specified, the contents of that line will be
11000printed in hex.
1a532630
PP
11001
11002@item set dcache size @var{size}
11003@cindex dcache size
11004@kindex set dcache size
11005Set maximum number of entries in dcache (dcache depth above).
11006
11007@item set dcache line-size @var{line-size}
11008@cindex dcache line-size
11009@kindex set dcache line-size
11010Set number of bytes each dcache entry caches (dcache width above).
11011Must be a power of 2.
11012
11013@item show dcache size
11014@kindex show dcache size
b12039c6 11015Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
1a532630
PP
11016
11017@item show dcache line-size
11018@kindex show dcache line-size
b12039c6 11019Show default size of dcache lines.
1a532630 11020
09d4efe1
EZ
11021@end table
11022
08388c79
DE
11023@node Searching Memory
11024@section Search Memory
11025@cindex searching memory
11026
11027Memory can be searched for a particular sequence of bytes with the
11028@code{find} command.
11029
11030@table @code
11031@kindex find
11032@item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
11033@itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
11034Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
11035etc. The search begins at address @var{start_addr} and continues for either
11036@var{len} bytes or through to @var{end_addr} inclusive.
11037@end table
11038
11039@var{s} and @var{n} are optional parameters.
11040They may be specified in either order, apart or together.
11041
11042@table @r
11043@item @var{s}, search query size
11044The size of each search query value.
11045
11046@table @code
11047@item b
11048bytes
11049@item h
11050halfwords (two bytes)
11051@item w
11052words (four bytes)
11053@item g
11054giant words (eight bytes)
11055@end table
11056
11057All values are interpreted in the current language.
11058This means, for example, that if the current source language is C/C@t{++}
11059then searching for the string ``hello'' includes the trailing '\0'.
11060
11061If the value size is not specified, it is taken from the
11062value's type in the current language.
11063This is useful when one wants to specify the search
11064pattern as a mixture of types.
11065Note that this means, for example, that in the case of C-like languages
11066a search for an untyped 0x42 will search for @samp{(int) 0x42}
11067which is typically four bytes.
11068
11069@item @var{n}, maximum number of finds
11070The maximum number of matches to print. The default is to print all finds.
11071@end table
11072
11073You can use strings as search values. Quote them with double-quotes
11074 (@code{"}).
11075The string value is copied into the search pattern byte by byte,
11076regardless of the endianness of the target and the size specification.
11077
11078The address of each match found is printed as well as a count of the
11079number of matches found.
11080
11081The address of the last value found is stored in convenience variable
11082@samp{$_}.
11083A count of the number of matches is stored in @samp{$numfound}.
11084
11085For example, if stopped at the @code{printf} in this function:
11086
11087@smallexample
11088void
11089hello ()
11090@{
11091 static char hello[] = "hello-hello";
11092 static struct @{ char c; short s; int i; @}
11093 __attribute__ ((packed)) mixed
11094 = @{ 'c', 0x1234, 0x87654321 @};
11095 printf ("%s\n", hello);
11096@}
11097@end smallexample
11098
11099@noindent
11100you get during debugging:
11101
11102@smallexample
11103(gdb) find &hello[0], +sizeof(hello), "hello"
111040x804956d <hello.1620+6>
111051 pattern found
11106(gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
111070x8049567 <hello.1620>
111080x804956d <hello.1620+6>
111092 patterns found
11110(gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
111110x8049567 <hello.1620>
111121 pattern found
11113(gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
111140x8049560 <mixed.1625>
111151 pattern found
11116(gdb) print $numfound
11117$1 = 1
11118(gdb) print $_
11119$2 = (void *) 0x8049560
11120@end smallexample
a0eb71c5 11121
edb3359d
DJ
11122@node Optimized Code
11123@chapter Debugging Optimized Code
11124@cindex optimized code, debugging
11125@cindex debugging optimized code
11126
11127Almost all compilers support optimization. With optimization
11128disabled, the compiler generates assembly code that corresponds
11129directly to your source code, in a simplistic way. As the compiler
11130applies more powerful optimizations, the generated assembly code
11131diverges from your original source code. With help from debugging
11132information generated by the compiler, @value{GDBN} can map from
11133the running program back to constructs from your original source.
11134
11135@value{GDBN} is more accurate with optimization disabled. If you
11136can recompile without optimization, it is easier to follow the
11137progress of your program during debugging. But, there are many cases
11138where you may need to debug an optimized version.
11139
11140When you debug a program compiled with @samp{-g -O}, remember that the
11141optimizer has rearranged your code; the debugger shows you what is
11142really there. Do not be too surprised when the execution path does not
11143exactly match your source file! An extreme example: if you define a
11144variable, but never use it, @value{GDBN} never sees that
11145variable---because the compiler optimizes it out of existence.
11146
11147Some things do not work as well with @samp{-g -O} as with just
11148@samp{-g}, particularly on machines with instruction scheduling. If in
11149doubt, recompile with @samp{-g} alone, and if this fixes the problem,
11150please report it to us as a bug (including a test case!).
11151@xref{Variables}, for more information about debugging optimized code.
11152
11153@menu
11154* Inline Functions:: How @value{GDBN} presents inlining
111c6489 11155* Tail Call Frames:: @value{GDBN} analysis of jumps to functions
edb3359d
DJ
11156@end menu
11157
11158@node Inline Functions
11159@section Inline Functions
11160@cindex inline functions, debugging
11161
11162@dfn{Inlining} is an optimization that inserts a copy of the function
11163body directly at each call site, instead of jumping to a shared
11164routine. @value{GDBN} displays inlined functions just like
11165non-inlined functions. They appear in backtraces. You can view their
11166arguments and local variables, step into them with @code{step}, skip
11167them with @code{next}, and escape from them with @code{finish}.
11168You can check whether a function was inlined by using the
11169@code{info frame} command.
11170
11171For @value{GDBN} to support inlined functions, the compiler must
11172record information about inlining in the debug information ---
11173@value{NGCC} using the @sc{dwarf 2} format does this, and several
11174other compilers do also. @value{GDBN} only supports inlined functions
11175when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
11176do not emit two required attributes (@samp{DW_AT_call_file} and
11177@samp{DW_AT_call_line}); @value{GDBN} does not display inlined
11178function calls with earlier versions of @value{NGCC}. It instead
11179displays the arguments and local variables of inlined functions as
11180local variables in the caller.
11181
11182The body of an inlined function is directly included at its call site;
11183unlike a non-inlined function, there are no instructions devoted to
11184the call. @value{GDBN} still pretends that the call site and the
11185start of the inlined function are different instructions. Stepping to
11186the call site shows the call site, and then stepping again shows
11187the first line of the inlined function, even though no additional
11188instructions are executed.
11189
11190This makes source-level debugging much clearer; you can see both the
11191context of the call and then the effect of the call. Only stepping by
11192a single instruction using @code{stepi} or @code{nexti} does not do
11193this; single instruction steps always show the inlined body.
11194
11195There are some ways that @value{GDBN} does not pretend that inlined
11196function calls are the same as normal calls:
11197
11198@itemize @bullet
edb3359d
DJ
11199@item
11200Setting breakpoints at the call site of an inlined function may not
11201work, because the call site does not contain any code. @value{GDBN}
11202may incorrectly move the breakpoint to the next line of the enclosing
11203function, after the call. This limitation will be removed in a future
11204version of @value{GDBN}; until then, set a breakpoint on an earlier line
11205or inside the inlined function instead.
11206
11207@item
11208@value{GDBN} cannot locate the return value of inlined calls after
11209using the @code{finish} command. This is a limitation of compiler-generated
11210debugging information; after @code{finish}, you can step to the next line
11211and print a variable where your program stored the return value.
11212
11213@end itemize
11214
111c6489
JK
11215@node Tail Call Frames
11216@section Tail Call Frames
11217@cindex tail call frames, debugging
11218
11219Function @code{B} can call function @code{C} in its very last statement. In
11220unoptimized compilation the call of @code{C} is immediately followed by return
11221instruction at the end of @code{B} code. Optimizing compiler may replace the
11222call and return in function @code{B} into one jump to function @code{C}
11223instead. Such use of a jump instruction is called @dfn{tail call}.
11224
11225During execution of function @code{C}, there will be no indication in the
11226function call stack frames that it was tail-called from @code{B}. If function
11227@code{A} regularly calls function @code{B} which tail-calls function @code{C},
11228then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
11229some cases @value{GDBN} can determine that @code{C} was tail-called from
11230@code{B}, and it will then create fictitious call frame for that, with the
11231return address set up as if @code{B} called @code{C} normally.
11232
11233This functionality is currently supported only by DWARF 2 debugging format and
11234the compiler has to produce @samp{DW_TAG_GNU_call_site} tags. With
11235@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11236this information.
11237
11238@kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
11239kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
11240
11241@smallexample
11242(gdb) x/i $pc - 2
11243 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
11244(gdb) info frame
11245Stack level 1, frame at 0x7fffffffda30:
11246 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
11247 tail call frame, caller of frame at 0x7fffffffda30
11248 source language c++.
11249 Arglist at unknown address.
11250 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
11251@end smallexample
11252
11253The detection of all the possible code path executions can find them ambiguous.
11254There is no execution history stored (possible @ref{Reverse Execution} is never
11255used for this purpose) and the last known caller could have reached the known
11256callee by multiple different jump sequences. In such case @value{GDBN} still
11257tries to show at least all the unambiguous top tail callers and all the
11258unambiguous bottom tail calees, if any.
11259
11260@table @code
e18b2753 11261@anchor{set debug entry-values}
111c6489
JK
11262@item set debug entry-values
11263@kindex set debug entry-values
11264When set to on, enables printing of analysis messages for both frame argument
11265values at function entry and tail calls. It will show all the possible valid
11266tail calls code paths it has considered. It will also print the intersection
11267of them with the final unambiguous (possibly partial or even empty) code path
11268result.
11269
11270@item show debug entry-values
11271@kindex show debug entry-values
11272Show the current state of analysis messages printing for both frame argument
11273values at function entry and tail calls.
11274@end table
11275
11276The analysis messages for tail calls can for example show why the virtual tail
11277call frame for function @code{c} has not been recognized (due to the indirect
11278reference by variable @code{x}):
11279
11280@smallexample
11281static void __attribute__((noinline, noclone)) c (void);
11282void (*x) (void) = c;
11283static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
11284static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
11285int main (void) @{ x (); return 0; @}
11286
11287Breakpoint 1, DW_OP_GNU_entry_value resolving cannot find
11288DW_TAG_GNU_call_site 0x40039a in main
11289a () at t.c:3
112903 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
11291(gdb) bt
11292#0 a () at t.c:3
11293#1 0x000000000040039a in main () at t.c:5
11294@end smallexample
11295
11296Another possibility is an ambiguous virtual tail call frames resolution:
11297
11298@smallexample
11299int i;
11300static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
11301static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
11302static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
11303static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
11304static void __attribute__((noinline, noclone)) b (void)
11305@{ if (i) c (); else e (); @}
11306static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
11307int main (void) @{ a (); return 0; @}
11308
11309tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
11310tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
11311tailcall: reduced: 0x4004d2(a) |
11312(gdb) bt
11313#0 f () at t.c:2
11314#1 0x00000000004004d2 in a () at t.c:8
11315#2 0x0000000000400395 in main () at t.c:9
11316@end smallexample
11317
5048e516
JK
11318@set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
11319@set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
11320
11321@c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
11322@ifset HAVE_MAKEINFO_CLICK
11323@set ARROW @click{}
11324@set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
11325@set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
11326@end ifset
11327@ifclear HAVE_MAKEINFO_CLICK
11328@set ARROW ->
11329@set CALLSEQ1B @value{CALLSEQ1A}
11330@set CALLSEQ2B @value{CALLSEQ2A}
11331@end ifclear
11332
11333Frames #0 and #2 are real, #1 is a virtual tail call frame.
11334The code can have possible execution paths @value{CALLSEQ1B} or
11335@value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
111c6489
JK
11336
11337@code{initial:} state shows some random possible calling sequence @value{GDBN}
11338has found. It then finds another possible calling sequcen - that one is
11339prefixed by @code{compare:}. The non-ambiguous intersection of these two is
11340printed as the @code{reduced:} calling sequence. That one could have many
11341futher @code{compare:} and @code{reduced:} statements as long as there remain
11342any non-ambiguous sequence entries.
11343
11344For the frame of function @code{b} in both cases there are different possible
11345@code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
11346also ambigous. The only non-ambiguous frame is the one for function @code{a},
11347therefore this one is displayed to the user while the ambiguous frames are
11348omitted.
edb3359d 11349
e18b2753
JK
11350There can be also reasons why printing of frame argument values at function
11351entry may fail:
11352
11353@smallexample
11354int v;
11355static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
11356static void __attribute__((noinline, noclone)) a (int i);
11357static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
11358static void __attribute__((noinline, noclone)) a (int i)
11359@{ if (i) b (i - 1); else c (0); @}
11360int main (void) @{ a (5); return 0; @}
11361
11362(gdb) bt
11363#0 c (i=i@@entry=0) at t.c:2
11364#1 0x0000000000400428 in a (DW_OP_GNU_entry_value resolving has found
11365function "a" at 0x400420 can call itself via tail calls
11366i=<optimized out>) at t.c:6
11367#2 0x000000000040036e in main () at t.c:7
11368@end smallexample
11369
11370@value{GDBN} cannot find out from the inferior state if and how many times did
11371function @code{a} call itself (via function @code{b}) as these calls would be
11372tail calls. Such tail calls would modify thue @code{i} variable, therefore
11373@value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
11374prints @code{<optimized out>} instead.
11375
e2e0bcd1
JB
11376@node Macros
11377@chapter C Preprocessor Macros
11378
49efadf5 11379Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
11380``preprocessor macros'' which expand into strings of tokens.
11381@value{GDBN} can evaluate expressions containing macro invocations, show
11382the result of macro expansion, and show a macro's definition, including
11383where it was defined.
11384
11385You may need to compile your program specially to provide @value{GDBN}
11386with information about preprocessor macros. Most compilers do not
11387include macros in their debugging information, even when you compile
11388with the @option{-g} flag. @xref{Compilation}.
11389
11390A program may define a macro at one point, remove that definition later,
11391and then provide a different definition after that. Thus, at different
11392points in the program, a macro may have different definitions, or have
11393no definition at all. If there is a current stack frame, @value{GDBN}
11394uses the macros in scope at that frame's source code line. Otherwise,
11395@value{GDBN} uses the macros in scope at the current listing location;
11396see @ref{List}.
11397
e2e0bcd1
JB
11398Whenever @value{GDBN} evaluates an expression, it always expands any
11399macro invocations present in the expression. @value{GDBN} also provides
11400the following commands for working with macros explicitly.
11401
11402@table @code
11403
11404@kindex macro expand
11405@cindex macro expansion, showing the results of preprocessor
11406@cindex preprocessor macro expansion, showing the results of
11407@cindex expanding preprocessor macros
11408@item macro expand @var{expression}
11409@itemx macro exp @var{expression}
11410Show the results of expanding all preprocessor macro invocations in
11411@var{expression}. Since @value{GDBN} simply expands macros, but does
11412not parse the result, @var{expression} need not be a valid expression;
11413it can be any string of tokens.
11414
09d4efe1 11415@kindex macro exp1
e2e0bcd1
JB
11416@item macro expand-once @var{expression}
11417@itemx macro exp1 @var{expression}
4644b6e3 11418@cindex expand macro once
e2e0bcd1
JB
11419@i{(This command is not yet implemented.)} Show the results of
11420expanding those preprocessor macro invocations that appear explicitly in
11421@var{expression}. Macro invocations appearing in that expansion are
11422left unchanged. This command allows you to see the effect of a
11423particular macro more clearly, without being confused by further
11424expansions. Since @value{GDBN} simply expands macros, but does not
11425parse the result, @var{expression} need not be a valid expression; it
11426can be any string of tokens.
11427
475b0867 11428@kindex info macro
e2e0bcd1 11429@cindex macro definition, showing
9b158ba0 11430@cindex definition of a macro, showing
11431@cindex macros, from debug info
71eba9c2 11432@item info macro [-a|-all] [--] @var{macro}
11433Show the current definition or all definitions of the named @var{macro},
11434and describe the source location or compiler command-line where that
11435definition was established. The optional double dash is to signify the end of
11436argument processing and the beginning of @var{macro} for non C-like macros where
11437the macro may begin with a hyphen.
e2e0bcd1 11438
9b158ba0 11439@kindex info macros
11440@item info macros @var{linespec}
11441Show all macro definitions that are in effect at the location specified
11442by @var{linespec}, and describe the source location or compiler
11443command-line where those definitions were established.
11444
e2e0bcd1
JB
11445@kindex macro define
11446@cindex user-defined macros
11447@cindex defining macros interactively
11448@cindex macros, user-defined
11449@item macro define @var{macro} @var{replacement-list}
11450@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
d7d9f01e
TT
11451Introduce a definition for a preprocessor macro named @var{macro},
11452invocations of which are replaced by the tokens given in
11453@var{replacement-list}. The first form of this command defines an
11454``object-like'' macro, which takes no arguments; the second form
11455defines a ``function-like'' macro, which takes the arguments given in
11456@var{arglist}.
11457
11458A definition introduced by this command is in scope in every
11459expression evaluated in @value{GDBN}, until it is removed with the
11460@code{macro undef} command, described below. The definition overrides
11461all definitions for @var{macro} present in the program being debugged,
11462as well as any previous user-supplied definition.
e2e0bcd1
JB
11463
11464@kindex macro undef
11465@item macro undef @var{macro}
d7d9f01e
TT
11466Remove any user-supplied definition for the macro named @var{macro}.
11467This command only affects definitions provided with the @code{macro
11468define} command, described above; it cannot remove definitions present
11469in the program being debugged.
e2e0bcd1 11470
09d4efe1
EZ
11471@kindex macro list
11472@item macro list
d7d9f01e 11473List all the macros defined using the @code{macro define} command.
e2e0bcd1
JB
11474@end table
11475
11476@cindex macros, example of debugging with
11477Here is a transcript showing the above commands in action. First, we
11478show our source files:
11479
11480@smallexample
11481$ cat sample.c
11482#include <stdio.h>
11483#include "sample.h"
11484
11485#define M 42
11486#define ADD(x) (M + x)
11487
11488main ()
11489@{
11490#define N 28
11491 printf ("Hello, world!\n");
11492#undef N
11493 printf ("We're so creative.\n");
11494#define N 1729
11495 printf ("Goodbye, world!\n");
11496@}
11497$ cat sample.h
11498#define Q <
11499$
11500@end smallexample
11501
e0f8f636
TT
11502Now, we compile the program using the @sc{gnu} C compiler,
11503@value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
11504minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
11505and @option{-gdwarf-4}; we recommend always choosing the most recent
11506version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
11507includes information about preprocessor macros in the debugging
e2e0bcd1
JB
11508information.
11509
11510@smallexample
11511$ gcc -gdwarf-2 -g3 sample.c -o sample
11512$
11513@end smallexample
11514
11515Now, we start @value{GDBN} on our sample program:
11516
11517@smallexample
11518$ gdb -nw sample
11519GNU gdb 2002-05-06-cvs
11520Copyright 2002 Free Software Foundation, Inc.
11521GDB is free software, @dots{}
f7dc1244 11522(@value{GDBP})
e2e0bcd1
JB
11523@end smallexample
11524
11525We can expand macros and examine their definitions, even when the
11526program is not running. @value{GDBN} uses the current listing position
11527to decide which macro definitions are in scope:
11528
11529@smallexample
f7dc1244 11530(@value{GDBP}) list main
e2e0bcd1
JB
115313
115324 #define M 42
115335 #define ADD(x) (M + x)
115346
115357 main ()
115368 @{
115379 #define N 28
1153810 printf ("Hello, world!\n");
1153911 #undef N
1154012 printf ("We're so creative.\n");
f7dc1244 11541(@value{GDBP}) info macro ADD
e2e0bcd1
JB
11542Defined at /home/jimb/gdb/macros/play/sample.c:5
11543#define ADD(x) (M + x)
f7dc1244 11544(@value{GDBP}) info macro Q
e2e0bcd1
JB
11545Defined at /home/jimb/gdb/macros/play/sample.h:1
11546 included at /home/jimb/gdb/macros/play/sample.c:2
11547#define Q <
f7dc1244 11548(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 11549expands to: (42 + 1)
f7dc1244 11550(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 11551expands to: once (M + 1)
f7dc1244 11552(@value{GDBP})
e2e0bcd1
JB
11553@end smallexample
11554
d7d9f01e 11555In the example above, note that @code{macro expand-once} expands only
e2e0bcd1
JB
11556the macro invocation explicit in the original text --- the invocation of
11557@code{ADD} --- but does not expand the invocation of the macro @code{M},
11558which was introduced by @code{ADD}.
11559
3f94c067
BW
11560Once the program is running, @value{GDBN} uses the macro definitions in
11561force at the source line of the current stack frame:
e2e0bcd1
JB
11562
11563@smallexample
f7dc1244 11564(@value{GDBP}) break main
e2e0bcd1 11565Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 11566(@value{GDBP}) run
b383017d 11567Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
11568
11569Breakpoint 1, main () at sample.c:10
1157010 printf ("Hello, world!\n");
f7dc1244 11571(@value{GDBP})
e2e0bcd1
JB
11572@end smallexample
11573
11574At line 10, the definition of the macro @code{N} at line 9 is in force:
11575
11576@smallexample
f7dc1244 11577(@value{GDBP}) info macro N
e2e0bcd1
JB
11578Defined at /home/jimb/gdb/macros/play/sample.c:9
11579#define N 28
f7dc1244 11580(@value{GDBP}) macro expand N Q M
e2e0bcd1 11581expands to: 28 < 42
f7dc1244 11582(@value{GDBP}) print N Q M
e2e0bcd1 11583$1 = 1
f7dc1244 11584(@value{GDBP})
e2e0bcd1
JB
11585@end smallexample
11586
11587As we step over directives that remove @code{N}'s definition, and then
11588give it a new definition, @value{GDBN} finds the definition (or lack
11589thereof) in force at each point:
11590
11591@smallexample
f7dc1244 11592(@value{GDBP}) next
e2e0bcd1
JB
11593Hello, world!
1159412 printf ("We're so creative.\n");
f7dc1244 11595(@value{GDBP}) info macro N
e2e0bcd1
JB
11596The symbol `N' has no definition as a C/C++ preprocessor macro
11597at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 11598(@value{GDBP}) next
e2e0bcd1
JB
11599We're so creative.
1160014 printf ("Goodbye, world!\n");
f7dc1244 11601(@value{GDBP}) info macro N
e2e0bcd1
JB
11602Defined at /home/jimb/gdb/macros/play/sample.c:13
11603#define N 1729
f7dc1244 11604(@value{GDBP}) macro expand N Q M
e2e0bcd1 11605expands to: 1729 < 42
f7dc1244 11606(@value{GDBP}) print N Q M
e2e0bcd1 11607$2 = 0
f7dc1244 11608(@value{GDBP})
e2e0bcd1
JB
11609@end smallexample
11610
484086b7
JK
11611In addition to source files, macros can be defined on the compilation command
11612line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
11613such a way, @value{GDBN} displays the location of their definition as line zero
11614of the source file submitted to the compiler.
11615
11616@smallexample
11617(@value{GDBP}) info macro __STDC__
11618Defined at /home/jimb/gdb/macros/play/sample.c:0
11619-D__STDC__=1
11620(@value{GDBP})
11621@end smallexample
11622
e2e0bcd1 11623
b37052ae
EZ
11624@node Tracepoints
11625@chapter Tracepoints
11626@c This chapter is based on the documentation written by Michael
11627@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
11628
11629@cindex tracepoints
11630In some applications, it is not feasible for the debugger to interrupt
11631the program's execution long enough for the developer to learn
11632anything helpful about its behavior. If the program's correctness
11633depends on its real-time behavior, delays introduced by a debugger
11634might cause the program to change its behavior drastically, or perhaps
11635fail, even when the code itself is correct. It is useful to be able
11636to observe the program's behavior without interrupting it.
11637
11638Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
11639specify locations in the program, called @dfn{tracepoints}, and
11640arbitrary expressions to evaluate when those tracepoints are reached.
11641Later, using the @code{tfind} command, you can examine the values
11642those expressions had when the program hit the tracepoints. The
11643expressions may also denote objects in memory---structures or arrays,
11644for example---whose values @value{GDBN} should record; while visiting
11645a particular tracepoint, you may inspect those objects as if they were
11646in memory at that moment. However, because @value{GDBN} records these
11647values without interacting with you, it can do so quickly and
11648unobtrusively, hopefully not disturbing the program's behavior.
11649
11650The tracepoint facility is currently available only for remote
9d29849a
JB
11651targets. @xref{Targets}. In addition, your remote target must know
11652how to collect trace data. This functionality is implemented in the
11653remote stub; however, none of the stubs distributed with @value{GDBN}
11654support tracepoints as of this writing. The format of the remote
11655packets used to implement tracepoints are described in @ref{Tracepoint
11656Packets}.
b37052ae 11657
00bf0b85
SS
11658It is also possible to get trace data from a file, in a manner reminiscent
11659of corefiles; you specify the filename, and use @code{tfind} to search
11660through the file. @xref{Trace Files}, for more details.
11661
b37052ae
EZ
11662This chapter describes the tracepoint commands and features.
11663
11664@menu
b383017d
RM
11665* Set Tracepoints::
11666* Analyze Collected Data::
11667* Tracepoint Variables::
00bf0b85 11668* Trace Files::
b37052ae
EZ
11669@end menu
11670
11671@node Set Tracepoints
11672@section Commands to Set Tracepoints
11673
11674Before running such a @dfn{trace experiment}, an arbitrary number of
1042e4c0
SS
11675tracepoints can be set. A tracepoint is actually a special type of
11676breakpoint (@pxref{Set Breaks}), so you can manipulate it using
11677standard breakpoint commands. For instance, as with breakpoints,
11678tracepoint numbers are successive integers starting from one, and many
11679of the commands associated with tracepoints take the tracepoint number
11680as their argument, to identify which tracepoint to work on.
b37052ae
EZ
11681
11682For each tracepoint, you can specify, in advance, some arbitrary set
11683of data that you want the target to collect in the trace buffer when
11684it hits that tracepoint. The collected data can include registers,
11685local variables, or global data. Later, you can use @value{GDBN}
11686commands to examine the values these data had at the time the
11687tracepoint was hit.
11688
7d13fe92
SS
11689Tracepoints do not support every breakpoint feature. Ignore counts on
11690tracepoints have no effect, and tracepoints cannot run @value{GDBN}
11691commands when they are hit. Tracepoints may not be thread-specific
11692either.
1042e4c0 11693
7a697b8d
SS
11694@cindex fast tracepoints
11695Some targets may support @dfn{fast tracepoints}, which are inserted in
11696a different way (such as with a jump instead of a trap), that is
11697faster but possibly restricted in where they may be installed.
11698
0fb4aa4b
PA
11699@cindex static tracepoints
11700@cindex markers, static tracepoints
11701@cindex probing markers, static tracepoints
11702Regular and fast tracepoints are dynamic tracing facilities, meaning
11703that they can be used to insert tracepoints at (almost) any location
11704in the target. Some targets may also support controlling @dfn{static
11705tracepoints} from @value{GDBN}. With static tracing, a set of
11706instrumentation points, also known as @dfn{markers}, are embedded in
11707the target program, and can be activated or deactivated by name or
11708address. These are usually placed at locations which facilitate
11709investigating what the target is actually doing. @value{GDBN}'s
11710support for static tracing includes being able to list instrumentation
11711points, and attach them with @value{GDBN} defined high level
11712tracepoints that expose the whole range of convenience of
8786b2bd 11713@value{GDBN}'s tracepoints support. Namely, support for collecting
0fb4aa4b
PA
11714registers values and values of global or local (to the instrumentation
11715point) variables; tracepoint conditions and trace state variables.
11716The act of installing a @value{GDBN} static tracepoint on an
11717instrumentation point, or marker, is referred to as @dfn{probing} a
11718static tracepoint marker.
11719
fa593d66
PA
11720@code{gdbserver} supports tracepoints on some target systems.
11721@xref{Server,,Tracepoints support in @code{gdbserver}}.
11722
b37052ae
EZ
11723This section describes commands to set tracepoints and associated
11724conditions and actions.
11725
11726@menu
b383017d
RM
11727* Create and Delete Tracepoints::
11728* Enable and Disable Tracepoints::
11729* Tracepoint Passcounts::
782b2b07 11730* Tracepoint Conditions::
f61e138d 11731* Trace State Variables::
b383017d
RM
11732* Tracepoint Actions::
11733* Listing Tracepoints::
0fb4aa4b 11734* Listing Static Tracepoint Markers::
79a6e687 11735* Starting and Stopping Trace Experiments::
c9429232 11736* Tracepoint Restrictions::
b37052ae
EZ
11737@end menu
11738
11739@node Create and Delete Tracepoints
11740@subsection Create and Delete Tracepoints
11741
11742@table @code
11743@cindex set tracepoint
11744@kindex trace
1042e4c0 11745@item trace @var{location}
b37052ae 11746The @code{trace} command is very similar to the @code{break} command.
1042e4c0
SS
11747Its argument @var{location} can be a source line, a function name, or
11748an address in the target program. @xref{Specify Location}. The
11749@code{trace} command defines a tracepoint, which is a point in the
11750target program where the debugger will briefly stop, collect some
11751data, and then allow the program to continue. Setting a tracepoint or
1e4d1764
YQ
11752changing its actions takes effect immediately if the remote stub
11753supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
11754in tracing}).
11755If remote stub doesn't support the @samp{InstallInTrace} feature, all
11756these changes don't take effect until the next @code{tstart}
1042e4c0 11757command, and once a trace experiment is running, further changes will
bfccc43c
YQ
11758not have any effect until the next trace experiment starts. In addition,
11759@value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
11760address is not yet resolved. (This is similar to pending breakpoints.)
11761Pending tracepoints are not downloaded to the target and not installed
11762until they are resolved. The resolution of pending tracepoints requires
11763@value{GDBN} support---when debugging with the remote target, and
11764@value{GDBN} disconnects from the remote stub (@pxref{disconnected
11765tracing}), pending tracepoints can not be resolved (and downloaded to
11766the remote stub) while @value{GDBN} is disconnected.
b37052ae
EZ
11767
11768Here are some examples of using the @code{trace} command:
11769
11770@smallexample
11771(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
11772
11773(@value{GDBP}) @b{trace +2} // 2 lines forward
11774
11775(@value{GDBP}) @b{trace my_function} // first source line of function
11776
11777(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
11778
11779(@value{GDBP}) @b{trace *0x2117c4} // an address
11780@end smallexample
11781
11782@noindent
11783You can abbreviate @code{trace} as @code{tr}.
11784
782b2b07
SS
11785@item trace @var{location} if @var{cond}
11786Set a tracepoint with condition @var{cond}; evaluate the expression
11787@var{cond} each time the tracepoint is reached, and collect data only
11788if the value is nonzero---that is, if @var{cond} evaluates as true.
11789@xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
11790information on tracepoint conditions.
11791
7a697b8d
SS
11792@item ftrace @var{location} [ if @var{cond} ]
11793@cindex set fast tracepoint
74c761c1 11794@cindex fast tracepoints, setting
7a697b8d
SS
11795@kindex ftrace
11796The @code{ftrace} command sets a fast tracepoint. For targets that
11797support them, fast tracepoints will use a more efficient but possibly
11798less general technique to trigger data collection, such as a jump
11799instruction instead of a trap, or some sort of hardware support. It
11800may not be possible to create a fast tracepoint at the desired
11801location, in which case the command will exit with an explanatory
11802message.
11803
11804@value{GDBN} handles arguments to @code{ftrace} exactly as for
11805@code{trace}.
11806
405f8e94
SS
11807On 32-bit x86-architecture systems, fast tracepoints normally need to
11808be placed at an instruction that is 5 bytes or longer, but can be
11809placed at 4-byte instructions if the low 64K of memory of the target
11810program is available to install trampolines. Some Unix-type systems,
11811such as @sc{gnu}/Linux, exclude low addresses from the program's
11812address space; but for instance with the Linux kernel it is possible
11813to let @value{GDBN} use this area by doing a @command{sysctl} command
11814to set the @code{mmap_min_addr} kernel parameter, as in
11815
11816@example
11817sudo sysctl -w vm.mmap_min_addr=32768
11818@end example
11819
11820@noindent
11821which sets the low address to 32K, which leaves plenty of room for
11822trampolines. The minimum address should be set to a page boundary.
11823
0fb4aa4b 11824@item strace @var{location} [ if @var{cond} ]
74c761c1
PA
11825@cindex set static tracepoint
11826@cindex static tracepoints, setting
11827@cindex probe static tracepoint marker
0fb4aa4b
PA
11828@kindex strace
11829The @code{strace} command sets a static tracepoint. For targets that
11830support it, setting a static tracepoint probes a static
11831instrumentation point, or marker, found at @var{location}. It may not
11832be possible to set a static tracepoint at the desired location, in
11833which case the command will exit with an explanatory message.
11834
11835@value{GDBN} handles arguments to @code{strace} exactly as for
11836@code{trace}, with the addition that the user can also specify
11837@code{-m @var{marker}} as @var{location}. This probes the marker
11838identified by the @var{marker} string identifier. This identifier
11839depends on the static tracepoint backend library your program is
11840using. You can find all the marker identifiers in the @samp{ID} field
11841of the @code{info static-tracepoint-markers} command output.
11842@xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
11843Markers}. For example, in the following small program using the UST
11844tracing engine:
11845
11846@smallexample
11847main ()
11848@{
11849 trace_mark(ust, bar33, "str %s", "FOOBAZ");
11850@}
11851@end smallexample
11852
11853@noindent
11854the marker id is composed of joining the first two arguments to the
11855@code{trace_mark} call with a slash, which translates to:
11856
11857@smallexample
11858(@value{GDBP}) info static-tracepoint-markers
11859Cnt Enb ID Address What
118601 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
11861 Data: "str %s"
11862[etc...]
11863@end smallexample
11864
11865@noindent
11866so you may probe the marker above with:
11867
11868@smallexample
11869(@value{GDBP}) strace -m ust/bar33
11870@end smallexample
11871
11872Static tracepoints accept an extra collect action --- @code{collect
11873$_sdata}. This collects arbitrary user data passed in the probe point
11874call to the tracing library. In the UST example above, you'll see
11875that the third argument to @code{trace_mark} is a printf-like format
11876string. The user data is then the result of running that formating
11877string against the following arguments. Note that @code{info
11878static-tracepoint-markers} command output lists that format string in
11879the @samp{Data:} field.
11880
11881You can inspect this data when analyzing the trace buffer, by printing
11882the $_sdata variable like any other variable available to
11883@value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
11884
b37052ae
EZ
11885@vindex $tpnum
11886@cindex last tracepoint number
11887@cindex recent tracepoint number
11888@cindex tracepoint number
11889The convenience variable @code{$tpnum} records the tracepoint number
11890of the most recently set tracepoint.
11891
11892@kindex delete tracepoint
11893@cindex tracepoint deletion
11894@item delete tracepoint @r{[}@var{num}@r{]}
11895Permanently delete one or more tracepoints. With no argument, the
1042e4c0
SS
11896default is to delete all tracepoints. Note that the regular
11897@code{delete} command can remove tracepoints also.
b37052ae
EZ
11898
11899Examples:
11900
11901@smallexample
11902(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
11903
11904(@value{GDBP}) @b{delete trace} // remove all tracepoints
11905@end smallexample
11906
11907@noindent
11908You can abbreviate this command as @code{del tr}.
11909@end table
11910
11911@node Enable and Disable Tracepoints
11912@subsection Enable and Disable Tracepoints
11913
1042e4c0
SS
11914These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
11915
b37052ae
EZ
11916@table @code
11917@kindex disable tracepoint
11918@item disable tracepoint @r{[}@var{num}@r{]}
11919Disable tracepoint @var{num}, or all tracepoints if no argument
11920@var{num} is given. A disabled tracepoint will have no effect during
d248b706 11921a trace experiment, but it is not forgotten. You can re-enable
b37052ae 11922a disabled tracepoint using the @code{enable tracepoint} command.
d248b706
KY
11923If the command is issued during a trace experiment and the debug target
11924has support for disabling tracepoints during a trace experiment, then the
11925change will be effective immediately. Otherwise, it will be applied to the
11926next trace experiment.
b37052ae
EZ
11927
11928@kindex enable tracepoint
11929@item enable tracepoint @r{[}@var{num}@r{]}
d248b706
KY
11930Enable tracepoint @var{num}, or all tracepoints. If this command is
11931issued during a trace experiment and the debug target supports enabling
11932tracepoints during a trace experiment, then the enabled tracepoints will
11933become effective immediately. Otherwise, they will become effective the
11934next time a trace experiment is run.
b37052ae
EZ
11935@end table
11936
11937@node Tracepoint Passcounts
11938@subsection Tracepoint Passcounts
11939
11940@table @code
11941@kindex passcount
11942@cindex tracepoint pass count
11943@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
11944Set the @dfn{passcount} of a tracepoint. The passcount is a way to
11945automatically stop a trace experiment. If a tracepoint's passcount is
11946@var{n}, then the trace experiment will be automatically stopped on
11947the @var{n}'th time that tracepoint is hit. If the tracepoint number
11948@var{num} is not specified, the @code{passcount} command sets the
11949passcount of the most recently defined tracepoint. If no passcount is
11950given, the trace experiment will run until stopped explicitly by the
11951user.
11952
11953Examples:
11954
11955@smallexample
b383017d 11956(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 11957@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
11958
11959(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 11960@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
11961(@value{GDBP}) @b{trace foo}
11962(@value{GDBP}) @b{pass 3}
11963(@value{GDBP}) @b{trace bar}
11964(@value{GDBP}) @b{pass 2}
11965(@value{GDBP}) @b{trace baz}
11966(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
11967@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
11968@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
11969@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
11970@end smallexample
11971@end table
11972
782b2b07
SS
11973@node Tracepoint Conditions
11974@subsection Tracepoint Conditions
11975@cindex conditional tracepoints
11976@cindex tracepoint conditions
11977
11978The simplest sort of tracepoint collects data every time your program
11979reaches a specified place. You can also specify a @dfn{condition} for
11980a tracepoint. A condition is just a Boolean expression in your
11981programming language (@pxref{Expressions, ,Expressions}). A
11982tracepoint with a condition evaluates the expression each time your
11983program reaches it, and data collection happens only if the condition
11984is true.
11985
11986Tracepoint conditions can be specified when a tracepoint is set, by
11987using @samp{if} in the arguments to the @code{trace} command.
11988@xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
11989also be set or changed at any time with the @code{condition} command,
11990just as with breakpoints.
11991
11992Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
11993the conditional expression itself. Instead, @value{GDBN} encodes the
6dcd5565 11994expression into an agent expression (@pxref{Agent Expressions})
782b2b07
SS
11995suitable for execution on the target, independently of @value{GDBN}.
11996Global variables become raw memory locations, locals become stack
11997accesses, and so forth.
11998
11999For instance, suppose you have a function that is usually called
12000frequently, but should not be called after an error has occurred. You
12001could use the following tracepoint command to collect data about calls
12002of that function that happen while the error code is propagating
12003through the program; an unconditional tracepoint could end up
12004collecting thousands of useless trace frames that you would have to
12005search through.
12006
12007@smallexample
12008(@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
12009@end smallexample
12010
f61e138d
SS
12011@node Trace State Variables
12012@subsection Trace State Variables
12013@cindex trace state variables
12014
12015A @dfn{trace state variable} is a special type of variable that is
12016created and managed by target-side code. The syntax is the same as
12017that for GDB's convenience variables (a string prefixed with ``$''),
12018but they are stored on the target. They must be created explicitly,
12019using a @code{tvariable} command. They are always 64-bit signed
12020integers.
12021
12022Trace state variables are remembered by @value{GDBN}, and downloaded
12023to the target along with tracepoint information when the trace
12024experiment starts. There are no intrinsic limits on the number of
12025trace state variables, beyond memory limitations of the target.
12026
12027@cindex convenience variables, and trace state variables
12028Although trace state variables are managed by the target, you can use
12029them in print commands and expressions as if they were convenience
12030variables; @value{GDBN} will get the current value from the target
12031while the trace experiment is running. Trace state variables share
12032the same namespace as other ``$'' variables, which means that you
12033cannot have trace state variables with names like @code{$23} or
12034@code{$pc}, nor can you have a trace state variable and a convenience
12035variable with the same name.
12036
12037@table @code
12038
12039@item tvariable $@var{name} [ = @var{expression} ]
12040@kindex tvariable
12041The @code{tvariable} command creates a new trace state variable named
12042@code{$@var{name}}, and optionally gives it an initial value of
12043@var{expression}. @var{expression} is evaluated when this command is
12044entered; the result will be converted to an integer if possible,
12045otherwise @value{GDBN} will report an error. A subsequent
12046@code{tvariable} command specifying the same name does not create a
12047variable, but instead assigns the supplied initial value to the
12048existing variable of that name, overwriting any previous initial
12049value. The default initial value is 0.
12050
12051@item info tvariables
12052@kindex info tvariables
12053List all the trace state variables along with their initial values.
12054Their current values may also be displayed, if the trace experiment is
12055currently running.
12056
12057@item delete tvariable @r{[} $@var{name} @dots{} @r{]}
12058@kindex delete tvariable
12059Delete the given trace state variables, or all of them if no arguments
12060are specified.
12061
12062@end table
12063
b37052ae
EZ
12064@node Tracepoint Actions
12065@subsection Tracepoint Action Lists
12066
12067@table @code
12068@kindex actions
12069@cindex tracepoint actions
12070@item actions @r{[}@var{num}@r{]}
12071This command will prompt for a list of actions to be taken when the
12072tracepoint is hit. If the tracepoint number @var{num} is not
12073specified, this command sets the actions for the one that was most
12074recently defined (so that you can define a tracepoint and then say
12075@code{actions} without bothering about its number). You specify the
12076actions themselves on the following lines, one action at a time, and
12077terminate the actions list with a line containing just @code{end}. So
7d13fe92 12078far, the only defined actions are @code{collect}, @code{teval}, and
b37052ae
EZ
12079@code{while-stepping}.
12080
5a9351ae
SS
12081@code{actions} is actually equivalent to @code{commands} (@pxref{Break
12082Commands, ,Breakpoint Command Lists}), except that only the defined
12083actions are allowed; any other @value{GDBN} command is rejected.
12084
b37052ae
EZ
12085@cindex remove actions from a tracepoint
12086To remove all actions from a tracepoint, type @samp{actions @var{num}}
12087and follow it immediately with @samp{end}.
12088
12089@smallexample
12090(@value{GDBP}) @b{collect @var{data}} // collect some data
12091
6826cf00 12092(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 12093
6826cf00 12094(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
12095@end smallexample
12096
12097In the following example, the action list begins with @code{collect}
12098commands indicating the things to be collected when the tracepoint is
12099hit. Then, in order to single-step and collect additional data
12100following the tracepoint, a @code{while-stepping} command is used,
7d13fe92
SS
12101followed by the list of things to be collected after each step in a
12102sequence of single steps. The @code{while-stepping} command is
12103terminated by its own separate @code{end} command. Lastly, the action
12104list is terminated by an @code{end} command.
b37052ae
EZ
12105
12106@smallexample
12107(@value{GDBP}) @b{trace foo}
12108(@value{GDBP}) @b{actions}
12109Enter actions for tracepoint 1, one per line:
12110> collect bar,baz
12111> collect $regs
12112> while-stepping 12
5a9351ae 12113 > collect $pc, arr[i]
b37052ae
EZ
12114 > end
12115end
12116@end smallexample
12117
12118@kindex collect @r{(tracepoints)}
3065dfb6 12119@item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
b37052ae
EZ
12120Collect values of the given expressions when the tracepoint is hit.
12121This command accepts a comma-separated list of any valid expressions.
12122In addition to global, static, or local variables, the following
12123special arguments are supported:
12124
12125@table @code
12126@item $regs
0fb4aa4b 12127Collect all registers.
b37052ae
EZ
12128
12129@item $args
0fb4aa4b 12130Collect all function arguments.
b37052ae
EZ
12131
12132@item $locals
0fb4aa4b
PA
12133Collect all local variables.
12134
6710bf39
SS
12135@item $_ret
12136Collect the return address. This is helpful if you want to see more
12137of a backtrace.
12138
62e5f89c
SDJ
12139@item $_probe_argc
12140Collects the number of arguments from the static probe at which the
12141tracepoint is located.
12142@xref{Static Probe Points}.
12143
12144@item $_probe_arg@var{n}
12145@var{n} is an integer between 0 and 11. Collects the @var{n}th argument
12146from the static probe at which the tracepoint is located.
12147@xref{Static Probe Points}.
12148
0fb4aa4b
PA
12149@item $_sdata
12150@vindex $_sdata@r{, collect}
12151Collect static tracepoint marker specific data. Only available for
12152static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
12153Lists}. On the UST static tracepoints library backend, an
12154instrumentation point resembles a @code{printf} function call. The
12155tracing library is able to collect user specified data formatted to a
12156character string using the format provided by the programmer that
12157instrumented the program. Other backends have similar mechanisms.
12158Here's an example of a UST marker call:
12159
12160@smallexample
12161 const char master_name[] = "$your_name";
12162 trace_mark(channel1, marker1, "hello %s", master_name)
12163@end smallexample
12164
12165In this case, collecting @code{$_sdata} collects the string
12166@samp{hello $yourname}. When analyzing the trace buffer, you can
12167inspect @samp{$_sdata} like any other variable available to
12168@value{GDBN}.
b37052ae
EZ
12169@end table
12170
12171You can give several consecutive @code{collect} commands, each one
12172with a single argument, or one @code{collect} command with several
5a9351ae 12173arguments separated by commas; the effect is the same.
b37052ae 12174
3065dfb6
SS
12175The optional @var{mods} changes the usual handling of the arguments.
12176@code{s} requests that pointers to chars be handled as strings, in
12177particular collecting the contents of the memory being pointed at, up
12178to the first zero. The upper bound is by default the value of the
12179@code{print elements} variable; if @code{s} is followed by a decimal
12180number, that is the upper bound instead. So for instance
12181@samp{collect/s25 mystr} collects as many as 25 characters at
12182@samp{mystr}.
12183
f5c37c66
EZ
12184The command @code{info scope} (@pxref{Symbols, info scope}) is
12185particularly useful for figuring out what data to collect.
12186
6da95a67
SS
12187@kindex teval @r{(tracepoints)}
12188@item teval @var{expr1}, @var{expr2}, @dots{}
12189Evaluate the given expressions when the tracepoint is hit. This
12190command accepts a comma-separated list of expressions. The results
12191are discarded, so this is mainly useful for assigning values to trace
12192state variables (@pxref{Trace State Variables}) without adding those
12193values to the trace buffer, as would be the case if the @code{collect}
12194action were used.
12195
b37052ae
EZ
12196@kindex while-stepping @r{(tracepoints)}
12197@item while-stepping @var{n}
c9429232 12198Perform @var{n} single-step instruction traces after the tracepoint,
7d13fe92 12199collecting new data after each step. The @code{while-stepping}
c9429232
SS
12200command is followed by the list of what to collect while stepping
12201(followed by its own @code{end} command):
b37052ae
EZ
12202
12203@smallexample
12204> while-stepping 12
12205 > collect $regs, myglobal
12206 > end
12207>
12208@end smallexample
12209
12210@noindent
7d13fe92
SS
12211Note that @code{$pc} is not automatically collected by
12212@code{while-stepping}; you need to explicitly collect that register if
12213you need it. You may abbreviate @code{while-stepping} as @code{ws} or
b37052ae 12214@code{stepping}.
236f1d4d
SS
12215
12216@item set default-collect @var{expr1}, @var{expr2}, @dots{}
12217@kindex set default-collect
12218@cindex default collection action
12219This variable is a list of expressions to collect at each tracepoint
12220hit. It is effectively an additional @code{collect} action prepended
12221to every tracepoint action list. The expressions are parsed
12222individually for each tracepoint, so for instance a variable named
12223@code{xyz} may be interpreted as a global for one tracepoint, and a
12224local for another, as appropriate to the tracepoint's location.
12225
12226@item show default-collect
12227@kindex show default-collect
12228Show the list of expressions that are collected by default at each
12229tracepoint hit.
12230
b37052ae
EZ
12231@end table
12232
12233@node Listing Tracepoints
12234@subsection Listing Tracepoints
12235
12236@table @code
e5a67952
MS
12237@kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
12238@kindex info tp @r{[}@var{n}@dots{}@r{]}
b37052ae 12239@cindex information about tracepoints
e5a67952 12240@item info tracepoints @r{[}@var{num}@dots{}@r{]}
1042e4c0
SS
12241Display information about the tracepoint @var{num}. If you don't
12242specify a tracepoint number, displays information about all the
12243tracepoints defined so far. The format is similar to that used for
12244@code{info breakpoints}; in fact, @code{info tracepoints} is the same
12245command, simply restricting itself to tracepoints.
12246
12247A tracepoint's listing may include additional information specific to
12248tracing:
b37052ae
EZ
12249
12250@itemize @bullet
12251@item
b37052ae 12252its passcount as given by the @code{passcount @var{n}} command
f2a8bc8a
YQ
12253
12254@item
12255the state about installed on target of each location
b37052ae
EZ
12256@end itemize
12257
12258@smallexample
12259(@value{GDBP}) @b{info trace}
1042e4c0
SS
12260Num Type Disp Enb Address What
122611 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
5a9351ae
SS
12262 while-stepping 20
12263 collect globfoo, $regs
12264 end
12265 collect globfoo2
12266 end
1042e4c0 12267 pass count 1200
f2a8bc8a
YQ
122682 tracepoint keep y <MULTIPLE>
12269 collect $eip
122702.1 y 0x0804859c in func4 at change-loc.h:35
12271 installed on target
122722.2 y 0xb7ffc480 in func4 at change-loc.h:35
12273 installed on target
122742.3 y <PENDING> set_tracepoint
122753 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
12276 not installed on target
b37052ae
EZ
12277(@value{GDBP})
12278@end smallexample
12279
12280@noindent
12281This command can be abbreviated @code{info tp}.
12282@end table
12283
0fb4aa4b
PA
12284@node Listing Static Tracepoint Markers
12285@subsection Listing Static Tracepoint Markers
12286
12287@table @code
12288@kindex info static-tracepoint-markers
12289@cindex information about static tracepoint markers
12290@item info static-tracepoint-markers
12291Display information about all static tracepoint markers defined in the
12292program.
12293
12294For each marker, the following columns are printed:
12295
12296@table @emph
12297@item Count
12298An incrementing counter, output to help readability. This is not a
12299stable identifier.
12300@item ID
12301The marker ID, as reported by the target.
12302@item Enabled or Disabled
12303Probed markers are tagged with @samp{y}. @samp{n} identifies marks
12304that are not enabled.
12305@item Address
12306Where the marker is in your program, as a memory address.
12307@item What
12308Where the marker is in the source for your program, as a file and line
12309number. If the debug information included in the program does not
12310allow @value{GDBN} to locate the source of the marker, this column
12311will be left blank.
12312@end table
12313
12314@noindent
12315In addition, the following information may be printed for each marker:
12316
12317@table @emph
12318@item Data
12319User data passed to the tracing library by the marker call. In the
12320UST backend, this is the format string passed as argument to the
12321marker call.
12322@item Static tracepoints probing the marker
12323The list of static tracepoints attached to the marker.
12324@end table
12325
12326@smallexample
12327(@value{GDBP}) info static-tracepoint-markers
12328Cnt ID Enb Address What
123291 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
12330 Data: number1 %d number2 %d
12331 Probed by static tracepoints: #2
123322 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
12333 Data: str %s
12334(@value{GDBP})
12335@end smallexample
12336@end table
12337
79a6e687
BW
12338@node Starting and Stopping Trace Experiments
12339@subsection Starting and Stopping Trace Experiments
b37052ae
EZ
12340
12341@table @code
f196051f 12342@kindex tstart [ @var{notes} ]
b37052ae
EZ
12343@cindex start a new trace experiment
12344@cindex collected data discarded
12345@item tstart
f196051f
SS
12346This command starts the trace experiment, and begins collecting data.
12347It has the side effect of discarding all the data collected in the
12348trace buffer during the previous trace experiment. If any arguments
12349are supplied, they are taken as a note and stored with the trace
12350experiment's state. The notes may be arbitrary text, and are
12351especially useful with disconnected tracing in a multi-user context;
12352the notes can explain what the trace is doing, supply user contact
12353information, and so forth.
12354
12355@kindex tstop [ @var{notes} ]
b37052ae
EZ
12356@cindex stop a running trace experiment
12357@item tstop
f196051f
SS
12358This command stops the trace experiment. If any arguments are
12359supplied, they are recorded with the experiment as a note. This is
12360useful if you are stopping a trace started by someone else, for
12361instance if the trace is interfering with the system's behavior and
12362needs to be stopped quickly.
b37052ae 12363
68c71a2e 12364@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
12365automatically if any tracepoint's passcount is reached
12366(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
12367
12368@kindex tstatus
12369@cindex status of trace data collection
12370@cindex trace experiment, status of
12371@item tstatus
12372This command displays the status of the current trace data
12373collection.
12374@end table
12375
12376Here is an example of the commands we described so far:
12377
12378@smallexample
12379(@value{GDBP}) @b{trace gdb_c_test}
12380(@value{GDBP}) @b{actions}
12381Enter actions for tracepoint #1, one per line.
12382> collect $regs,$locals,$args
12383> while-stepping 11
12384 > collect $regs
12385 > end
12386> end
12387(@value{GDBP}) @b{tstart}
12388 [time passes @dots{}]
12389(@value{GDBP}) @b{tstop}
12390@end smallexample
12391
03f2bd59 12392@anchor{disconnected tracing}
d5551862
SS
12393@cindex disconnected tracing
12394You can choose to continue running the trace experiment even if
12395@value{GDBN} disconnects from the target, voluntarily or
12396involuntarily. For commands such as @code{detach}, the debugger will
12397ask what you want to do with the trace. But for unexpected
12398terminations (@value{GDBN} crash, network outage), it would be
12399unfortunate to lose hard-won trace data, so the variable
12400@code{disconnected-tracing} lets you decide whether the trace should
12401continue running without @value{GDBN}.
12402
12403@table @code
12404@item set disconnected-tracing on
12405@itemx set disconnected-tracing off
12406@kindex set disconnected-tracing
12407Choose whether a tracing run should continue to run if @value{GDBN}
12408has disconnected from the target. Note that @code{detach} or
12409@code{quit} will ask you directly what to do about a running trace no
12410matter what this variable's setting, so the variable is mainly useful
12411for handling unexpected situations, such as loss of the network.
12412
12413@item show disconnected-tracing
12414@kindex show disconnected-tracing
12415Show the current choice for disconnected tracing.
12416
12417@end table
12418
12419When you reconnect to the target, the trace experiment may or may not
12420still be running; it might have filled the trace buffer in the
12421meantime, or stopped for one of the other reasons. If it is running,
12422it will continue after reconnection.
12423
12424Upon reconnection, the target will upload information about the
12425tracepoints in effect. @value{GDBN} will then compare that
12426information to the set of tracepoints currently defined, and attempt
12427to match them up, allowing for the possibility that the numbers may
12428have changed due to creation and deletion in the meantime. If one of
12429the target's tracepoints does not match any in @value{GDBN}, the
12430debugger will create a new tracepoint, so that you have a number with
12431which to specify that tracepoint. This matching-up process is
12432necessarily heuristic, and it may result in useless tracepoints being
12433created; you may simply delete them if they are of no use.
b37052ae 12434
4daf5ac0
SS
12435@cindex circular trace buffer
12436If your target agent supports a @dfn{circular trace buffer}, then you
12437can run a trace experiment indefinitely without filling the trace
12438buffer; when space runs out, the agent deletes already-collected trace
12439frames, oldest first, until there is enough room to continue
12440collecting. This is especially useful if your tracepoints are being
12441hit too often, and your trace gets terminated prematurely because the
12442buffer is full. To ask for a circular trace buffer, simply set
81896e36 12443@samp{circular-trace-buffer} to on. You can set this at any time,
4daf5ac0
SS
12444including during tracing; if the agent can do it, it will change
12445buffer handling on the fly, otherwise it will not take effect until
12446the next run.
12447
12448@table @code
12449@item set circular-trace-buffer on
12450@itemx set circular-trace-buffer off
12451@kindex set circular-trace-buffer
12452Choose whether a tracing run should use a linear or circular buffer
12453for trace data. A linear buffer will not lose any trace data, but may
12454fill up prematurely, while a circular buffer will discard old trace
12455data, but it will have always room for the latest tracepoint hits.
12456
12457@item show circular-trace-buffer
12458@kindex show circular-trace-buffer
12459Show the current choice for the trace buffer. Note that this may not
12460match the agent's current buffer handling, nor is it guaranteed to
12461match the setting that might have been in effect during a past run,
12462for instance if you are looking at frames from a trace file.
12463
12464@end table
12465
f6f899bf
HAQ
12466@table @code
12467@item set trace-buffer-size @var{n}
f81d1120 12468@itemx set trace-buffer-size unlimited
f6f899bf
HAQ
12469@kindex set trace-buffer-size
12470Request that the target use a trace buffer of @var{n} bytes. Not all
12471targets will honor the request; they may have a compiled-in size for
12472the trace buffer, or some other limitation. Set to a value of
f81d1120
PA
12473@code{unlimited} or @code{-1} to let the target use whatever size it
12474likes. This is also the default.
f6f899bf
HAQ
12475
12476@item show trace-buffer-size
12477@kindex show trace-buffer-size
12478Show the current requested size for the trace buffer. Note that this
12479will only match the actual size if the target supports size-setting,
12480and was able to handle the requested size. For instance, if the
12481target can only change buffer size between runs, this variable will
12482not reflect the change until the next run starts. Use @code{tstatus}
12483to get a report of the actual buffer size.
12484@end table
12485
f196051f
SS
12486@table @code
12487@item set trace-user @var{text}
12488@kindex set trace-user
12489
12490@item show trace-user
12491@kindex show trace-user
12492
12493@item set trace-notes @var{text}
12494@kindex set trace-notes
12495Set the trace run's notes.
12496
12497@item show trace-notes
12498@kindex show trace-notes
12499Show the trace run's notes.
12500
12501@item set trace-stop-notes @var{text}
12502@kindex set trace-stop-notes
12503Set the trace run's stop notes. The handling of the note is as for
12504@code{tstop} arguments; the set command is convenient way to fix a
12505stop note that is mistaken or incomplete.
12506
12507@item show trace-stop-notes
12508@kindex show trace-stop-notes
12509Show the trace run's stop notes.
12510
12511@end table
12512
c9429232
SS
12513@node Tracepoint Restrictions
12514@subsection Tracepoint Restrictions
12515
12516@cindex tracepoint restrictions
12517There are a number of restrictions on the use of tracepoints. As
12518described above, tracepoint data gathering occurs on the target
12519without interaction from @value{GDBN}. Thus the full capabilities of
12520the debugger are not available during data gathering, and then at data
12521examination time, you will be limited by only having what was
12522collected. The following items describe some common problems, but it
12523is not exhaustive, and you may run into additional difficulties not
12524mentioned here.
12525
12526@itemize @bullet
12527
12528@item
12529Tracepoint expressions are intended to gather objects (lvalues). Thus
12530the full flexibility of GDB's expression evaluator is not available.
12531You cannot call functions, cast objects to aggregate types, access
12532convenience variables or modify values (except by assignment to trace
12533state variables). Some language features may implicitly call
12534functions (for instance Objective-C fields with accessors), and therefore
12535cannot be collected either.
12536
12537@item
12538Collection of local variables, either individually or in bulk with
12539@code{$locals} or @code{$args}, during @code{while-stepping} may
12540behave erratically. The stepping action may enter a new scope (for
12541instance by stepping into a function), or the location of the variable
12542may change (for instance it is loaded into a register). The
12543tracepoint data recorded uses the location information for the
12544variables that is correct for the tracepoint location. When the
12545tracepoint is created, it is not possible, in general, to determine
12546where the steps of a @code{while-stepping} sequence will advance the
12547program---particularly if a conditional branch is stepped.
12548
12549@item
12550Collection of an incompletely-initialized or partially-destroyed object
12551may result in something that @value{GDBN} cannot display, or displays
12552in a misleading way.
12553
12554@item
12555When @value{GDBN} displays a pointer to character it automatically
12556dereferences the pointer to also display characters of the string
12557being pointed to. However, collecting the pointer during tracing does
12558not automatically collect the string. You need to explicitly
12559dereference the pointer and provide size information if you want to
12560collect not only the pointer, but the memory pointed to. For example,
12561@code{*ptr@@50} can be used to collect the 50 element array pointed to
12562by @code{ptr}.
12563
12564@item
12565It is not possible to collect a complete stack backtrace at a
12566tracepoint. Instead, you may collect the registers and a few hundred
d99f7e48 12567bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
c9429232
SS
12568(adjust to use the name of the actual stack pointer register on your
12569target architecture, and the amount of stack you wish to capture).
12570Then the @code{backtrace} command will show a partial backtrace when
12571using a trace frame. The number of stack frames that can be examined
12572depends on the sizes of the frames in the collected stack. Note that
12573if you ask for a block so large that it goes past the bottom of the
12574stack, the target agent may report an error trying to read from an
12575invalid address.
12576
af54718e
SS
12577@item
12578If you do not collect registers at a tracepoint, @value{GDBN} can
12579infer that the value of @code{$pc} must be the same as the address of
12580the tracepoint and use that when you are looking at a trace frame
12581for that tracepoint. However, this cannot work if the tracepoint has
12582multiple locations (for instance if it was set in a function that was
12583inlined), or if it has a @code{while-stepping} loop. In those cases
12584@value{GDBN} will warn you that it can't infer @code{$pc}, and default
12585it to zero.
12586
c9429232
SS
12587@end itemize
12588
b37052ae 12589@node Analyze Collected Data
79a6e687 12590@section Using the Collected Data
b37052ae
EZ
12591
12592After the tracepoint experiment ends, you use @value{GDBN} commands
12593for examining the trace data. The basic idea is that each tracepoint
12594collects a trace @dfn{snapshot} every time it is hit and another
12595snapshot every time it single-steps. All these snapshots are
12596consecutively numbered from zero and go into a buffer, and you can
12597examine them later. The way you examine them is to @dfn{focus} on a
12598specific trace snapshot. When the remote stub is focused on a trace
12599snapshot, it will respond to all @value{GDBN} requests for memory and
12600registers by reading from the buffer which belongs to that snapshot,
12601rather than from @emph{real} memory or registers of the program being
12602debugged. This means that @strong{all} @value{GDBN} commands
12603(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
12604behave as if we were currently debugging the program state as it was
12605when the tracepoint occurred. Any requests for data that are not in
12606the buffer will fail.
12607
12608@menu
12609* tfind:: How to select a trace snapshot
12610* tdump:: How to display all data for a snapshot
6149aea9 12611* save tracepoints:: How to save tracepoints for a future run
b37052ae
EZ
12612@end menu
12613
12614@node tfind
12615@subsection @code{tfind @var{n}}
12616
12617@kindex tfind
12618@cindex select trace snapshot
12619@cindex find trace snapshot
12620The basic command for selecting a trace snapshot from the buffer is
12621@code{tfind @var{n}}, which finds trace snapshot number @var{n},
12622counting from zero. If no argument @var{n} is given, the next
12623snapshot is selected.
12624
12625Here are the various forms of using the @code{tfind} command.
12626
12627@table @code
12628@item tfind start
12629Find the first snapshot in the buffer. This is a synonym for
12630@code{tfind 0} (since 0 is the number of the first snapshot).
12631
12632@item tfind none
12633Stop debugging trace snapshots, resume @emph{live} debugging.
12634
12635@item tfind end
12636Same as @samp{tfind none}.
12637
12638@item tfind
12639No argument means find the next trace snapshot.
12640
12641@item tfind -
12642Find the previous trace snapshot before the current one. This permits
12643retracing earlier steps.
12644
12645@item tfind tracepoint @var{num}
12646Find the next snapshot associated with tracepoint @var{num}. Search
12647proceeds forward from the last examined trace snapshot. If no
12648argument @var{num} is given, it means find the next snapshot collected
12649for the same tracepoint as the current snapshot.
12650
12651@item tfind pc @var{addr}
12652Find the next snapshot associated with the value @var{addr} of the
12653program counter. Search proceeds forward from the last examined trace
12654snapshot. If no argument @var{addr} is given, it means find the next
12655snapshot with the same value of PC as the current snapshot.
12656
12657@item tfind outside @var{addr1}, @var{addr2}
12658Find the next snapshot whose PC is outside the given range of
081dfbf7 12659addresses (exclusive).
b37052ae
EZ
12660
12661@item tfind range @var{addr1}, @var{addr2}
12662Find the next snapshot whose PC is between @var{addr1} and
081dfbf7 12663@var{addr2} (inclusive).
b37052ae
EZ
12664
12665@item tfind line @r{[}@var{file}:@r{]}@var{n}
12666Find the next snapshot associated with the source line @var{n}. If
12667the optional argument @var{file} is given, refer to line @var{n} in
12668that source file. Search proceeds forward from the last examined
12669trace snapshot. If no argument @var{n} is given, it means find the
12670next line other than the one currently being examined; thus saying
12671@code{tfind line} repeatedly can appear to have the same effect as
12672stepping from line to line in a @emph{live} debugging session.
12673@end table
12674
12675The default arguments for the @code{tfind} commands are specifically
12676designed to make it easy to scan through the trace buffer. For
12677instance, @code{tfind} with no argument selects the next trace
12678snapshot, and @code{tfind -} with no argument selects the previous
12679trace snapshot. So, by giving one @code{tfind} command, and then
12680simply hitting @key{RET} repeatedly you can examine all the trace
12681snapshots in order. Or, by saying @code{tfind -} and then hitting
12682@key{RET} repeatedly you can examine the snapshots in reverse order.
12683The @code{tfind line} command with no argument selects the snapshot
12684for the next source line executed. The @code{tfind pc} command with
12685no argument selects the next snapshot with the same program counter
12686(PC) as the current frame. The @code{tfind tracepoint} command with
12687no argument selects the next trace snapshot collected by the same
12688tracepoint as the current one.
12689
12690In addition to letting you scan through the trace buffer manually,
12691these commands make it easy to construct @value{GDBN} scripts that
12692scan through the trace buffer and print out whatever collected data
12693you are interested in. Thus, if we want to examine the PC, FP, and SP
12694registers from each trace frame in the buffer, we can say this:
12695
12696@smallexample
12697(@value{GDBP}) @b{tfind start}
12698(@value{GDBP}) @b{while ($trace_frame != -1)}
12699> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
12700 $trace_frame, $pc, $sp, $fp
12701> tfind
12702> end
12703
12704Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
12705Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
12706Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
12707Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
12708Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
12709Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
12710Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
12711Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
12712Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
12713Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
12714Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
12715@end smallexample
12716
12717Or, if we want to examine the variable @code{X} at each source line in
12718the buffer:
12719
12720@smallexample
12721(@value{GDBP}) @b{tfind start}
12722(@value{GDBP}) @b{while ($trace_frame != -1)}
12723> printf "Frame %d, X == %d\n", $trace_frame, X
12724> tfind line
12725> end
12726
12727Frame 0, X = 1
12728Frame 7, X = 2
12729Frame 13, X = 255
12730@end smallexample
12731
12732@node tdump
12733@subsection @code{tdump}
12734@kindex tdump
12735@cindex dump all data collected at tracepoint
12736@cindex tracepoint data, display
12737
12738This command takes no arguments. It prints all the data collected at
12739the current trace snapshot.
12740
12741@smallexample
12742(@value{GDBP}) @b{trace 444}
12743(@value{GDBP}) @b{actions}
12744Enter actions for tracepoint #2, one per line:
12745> collect $regs, $locals, $args, gdb_long_test
12746> end
12747
12748(@value{GDBP}) @b{tstart}
12749
12750(@value{GDBP}) @b{tfind line 444}
12751#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
12752at gdb_test.c:444
12753444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
12754
12755(@value{GDBP}) @b{tdump}
12756Data collected at tracepoint 2, trace frame 1:
12757d0 0xc4aa0085 -995491707
12758d1 0x18 24
12759d2 0x80 128
12760d3 0x33 51
12761d4 0x71aea3d 119204413
12762d5 0x22 34
12763d6 0xe0 224
12764d7 0x380035 3670069
12765a0 0x19e24a 1696330
12766a1 0x3000668 50333288
12767a2 0x100 256
12768a3 0x322000 3284992
12769a4 0x3000698 50333336
12770a5 0x1ad3cc 1758156
12771fp 0x30bf3c 0x30bf3c
12772sp 0x30bf34 0x30bf34
12773ps 0x0 0
12774pc 0x20b2c8 0x20b2c8
12775fpcontrol 0x0 0
12776fpstatus 0x0 0
12777fpiaddr 0x0 0
12778p = 0x20e5b4 "gdb-test"
12779p1 = (void *) 0x11
12780p2 = (void *) 0x22
12781p3 = (void *) 0x33
12782p4 = (void *) 0x44
12783p5 = (void *) 0x55
12784p6 = (void *) 0x66
12785gdb_long_test = 17 '\021'
12786
12787(@value{GDBP})
12788@end smallexample
12789
af54718e
SS
12790@code{tdump} works by scanning the tracepoint's current collection
12791actions and printing the value of each expression listed. So
12792@code{tdump} can fail, if after a run, you change the tracepoint's
12793actions to mention variables that were not collected during the run.
12794
12795Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
12796uses the collected value of @code{$pc} to distinguish between trace
12797frames that were collected at the tracepoint hit, and frames that were
12798collected while stepping. This allows it to correctly choose whether
12799to display the basic list of collections, or the collections from the
12800body of the while-stepping loop. However, if @code{$pc} was not collected,
12801then @code{tdump} will always attempt to dump using the basic collection
12802list, and may fail if a while-stepping frame does not include all the
12803same data that is collected at the tracepoint hit.
12804@c This is getting pretty arcane, example would be good.
12805
6149aea9
PA
12806@node save tracepoints
12807@subsection @code{save tracepoints @var{filename}}
12808@kindex save tracepoints
b37052ae
EZ
12809@kindex save-tracepoints
12810@cindex save tracepoints for future sessions
12811
12812This command saves all current tracepoint definitions together with
12813their actions and passcounts, into a file @file{@var{filename}}
12814suitable for use in a later debugging session. To read the saved
12815tracepoint definitions, use the @code{source} command (@pxref{Command
6149aea9
PA
12816Files}). The @w{@code{save-tracepoints}} command is a deprecated
12817alias for @w{@code{save tracepoints}}
b37052ae
EZ
12818
12819@node Tracepoint Variables
12820@section Convenience Variables for Tracepoints
12821@cindex tracepoint variables
12822@cindex convenience variables for tracepoints
12823
12824@table @code
12825@vindex $trace_frame
12826@item (int) $trace_frame
12827The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
12828snapshot is selected.
12829
12830@vindex $tracepoint
12831@item (int) $tracepoint
12832The tracepoint for the current trace snapshot.
12833
12834@vindex $trace_line
12835@item (int) $trace_line
12836The line number for the current trace snapshot.
12837
12838@vindex $trace_file
12839@item (char []) $trace_file
12840The source file for the current trace snapshot.
12841
12842@vindex $trace_func
12843@item (char []) $trace_func
12844The name of the function containing @code{$tracepoint}.
12845@end table
12846
12847Note: @code{$trace_file} is not suitable for use in @code{printf},
12848use @code{output} instead.
12849
12850Here's a simple example of using these convenience variables for
12851stepping through all the trace snapshots and printing some of their
f61e138d
SS
12852data. Note that these are not the same as trace state variables,
12853which are managed by the target.
b37052ae
EZ
12854
12855@smallexample
12856(@value{GDBP}) @b{tfind start}
12857
12858(@value{GDBP}) @b{while $trace_frame != -1}
12859> output $trace_file
12860> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
12861> tfind
12862> end
12863@end smallexample
12864
00bf0b85
SS
12865@node Trace Files
12866@section Using Trace Files
12867@cindex trace files
12868
12869In some situations, the target running a trace experiment may no
12870longer be available; perhaps it crashed, or the hardware was needed
12871for a different activity. To handle these cases, you can arrange to
12872dump the trace data into a file, and later use that file as a source
12873of trace data, via the @code{target tfile} command.
12874
12875@table @code
12876
12877@kindex tsave
12878@item tsave [ -r ] @var{filename}
d0353e76 12879@itemx tsave [-ctf] @var{dirname}
00bf0b85
SS
12880Save the trace data to @var{filename}. By default, this command
12881assumes that @var{filename} refers to the host filesystem, so if
12882necessary @value{GDBN} will copy raw trace data up from the target and
12883then save it. If the target supports it, you can also supply the
12884optional argument @code{-r} (``remote'') to direct the target to save
12885the data directly into @var{filename} in its own filesystem, which may be
12886more efficient if the trace buffer is very large. (Note, however, that
12887@code{target tfile} can only read from files accessible to the host.)
d0353e76
YQ
12888By default, this command will save trace frame in tfile format.
12889You can supply the optional argument @code{-ctf} to save date in CTF
12890format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
12891that can be shared by multiple debugging and tracing tools. Please go to
12892@indicateurl{http://www.efficios.com/ctf} to get more information.
00bf0b85
SS
12893
12894@kindex target tfile
12895@kindex tfile
393fd4c3
YQ
12896@kindex target ctf
12897@kindex ctf
00bf0b85 12898@item target tfile @var{filename}
393fd4c3
YQ
12899@itemx target ctf @var{dirname}
12900Use the file named @var{filename} or directory named @var{dirname} as
12901a source of trace data. Commands that examine data work as they do with
12902a live target, but it is not possible to run any new trace experiments.
12903@code{tstatus} will report the state of the trace run at the moment
12904the data was saved, as well as the current trace frame you are examining.
12905@var{filename} or @var{dirname} must be on a filesystem accessible to
12906the host.
12907
12908@smallexample
12909(@value{GDBP}) target ctf ctf.ctf
12910(@value{GDBP}) tfind
12911Found trace frame 0, tracepoint 2
1291239 ++a; /* set tracepoint 1 here */
12913(@value{GDBP}) tdump
12914Data collected at tracepoint 2, trace frame 0:
12915i = 0
12916a = 0
12917b = 1 '\001'
12918c = @{"123", "456", "789", "123", "456", "789"@}
12919d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
12920(@value{GDBP}) p b
12921$1 = 1
12922@end smallexample
00bf0b85
SS
12923
12924@end table
12925
df0cd8c5
JB
12926@node Overlays
12927@chapter Debugging Programs That Use Overlays
12928@cindex overlays
12929
12930If your program is too large to fit completely in your target system's
12931memory, you can sometimes use @dfn{overlays} to work around this
12932problem. @value{GDBN} provides some support for debugging programs that
12933use overlays.
12934
12935@menu
12936* How Overlays Work:: A general explanation of overlays.
12937* Overlay Commands:: Managing overlays in @value{GDBN}.
12938* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
12939 mapped by asking the inferior.
12940* Overlay Sample Program:: A sample program using overlays.
12941@end menu
12942
12943@node How Overlays Work
12944@section How Overlays Work
12945@cindex mapped overlays
12946@cindex unmapped overlays
12947@cindex load address, overlay's
12948@cindex mapped address
12949@cindex overlay area
12950
12951Suppose you have a computer whose instruction address space is only 64
12952kilobytes long, but which has much more memory which can be accessed by
12953other means: special instructions, segment registers, or memory
12954management hardware, for example. Suppose further that you want to
12955adapt a program which is larger than 64 kilobytes to run on this system.
12956
12957One solution is to identify modules of your program which are relatively
12958independent, and need not call each other directly; call these modules
12959@dfn{overlays}. Separate the overlays from the main program, and place
12960their machine code in the larger memory. Place your main program in
12961instruction memory, but leave at least enough space there to hold the
12962largest overlay as well.
12963
12964Now, to call a function located in an overlay, you must first copy that
12965overlay's machine code from the large memory into the space set aside
12966for it in the instruction memory, and then jump to its entry point
12967there.
12968
c928edc0
AC
12969@c NB: In the below the mapped area's size is greater or equal to the
12970@c size of all overlays. This is intentional to remind the developer
12971@c that overlays don't necessarily need to be the same size.
12972
474c8240 12973@smallexample
df0cd8c5 12974@group
c928edc0
AC
12975 Data Instruction Larger
12976Address Space Address Space Address Space
12977+-----------+ +-----------+ +-----------+
12978| | | | | |
12979+-----------+ +-----------+ +-----------+<-- overlay 1
12980| program | | main | .----| overlay 1 | load address
12981| variables | | program | | +-----------+
12982| and heap | | | | | |
12983+-----------+ | | | +-----------+<-- overlay 2
12984| | +-----------+ | | | load address
12985+-----------+ | | | .-| overlay 2 |
12986 | | | | | |
12987 mapped --->+-----------+ | | +-----------+
12988 address | | | | | |
12989 | overlay | <-' | | |
12990 | area | <---' +-----------+<-- overlay 3
12991 | | <---. | | load address
12992 +-----------+ `--| overlay 3 |
12993 | | | |
12994 +-----------+ | |
12995 +-----------+
12996 | |
12997 +-----------+
12998
12999 @anchor{A code overlay}A code overlay
df0cd8c5 13000@end group
474c8240 13001@end smallexample
df0cd8c5 13002
c928edc0
AC
13003The diagram (@pxref{A code overlay}) shows a system with separate data
13004and instruction address spaces. To map an overlay, the program copies
13005its code from the larger address space to the instruction address space.
13006Since the overlays shown here all use the same mapped address, only one
13007may be mapped at a time. For a system with a single address space for
13008data and instructions, the diagram would be similar, except that the
13009program variables and heap would share an address space with the main
13010program and the overlay area.
df0cd8c5
JB
13011
13012An overlay loaded into instruction memory and ready for use is called a
13013@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
13014instruction memory. An overlay not present (or only partially present)
13015in instruction memory is called @dfn{unmapped}; its @dfn{load address}
13016is its address in the larger memory. The mapped address is also called
13017the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
13018called the @dfn{load memory address}, or @dfn{LMA}.
13019
13020Unfortunately, overlays are not a completely transparent way to adapt a
13021program to limited instruction memory. They introduce a new set of
13022global constraints you must keep in mind as you design your program:
13023
13024@itemize @bullet
13025
13026@item
13027Before calling or returning to a function in an overlay, your program
13028must make sure that overlay is actually mapped. Otherwise, the call or
13029return will transfer control to the right address, but in the wrong
13030overlay, and your program will probably crash.
13031
13032@item
13033If the process of mapping an overlay is expensive on your system, you
13034will need to choose your overlays carefully to minimize their effect on
13035your program's performance.
13036
13037@item
13038The executable file you load onto your system must contain each
13039overlay's instructions, appearing at the overlay's load address, not its
13040mapped address. However, each overlay's instructions must be relocated
13041and its symbols defined as if the overlay were at its mapped address.
13042You can use GNU linker scripts to specify different load and relocation
13043addresses for pieces of your program; see @ref{Overlay Description,,,
13044ld.info, Using ld: the GNU linker}.
13045
13046@item
13047The procedure for loading executable files onto your system must be able
13048to load their contents into the larger address space as well as the
13049instruction and data spaces.
13050
13051@end itemize
13052
13053The overlay system described above is rather simple, and could be
13054improved in many ways:
13055
13056@itemize @bullet
13057
13058@item
13059If your system has suitable bank switch registers or memory management
13060hardware, you could use those facilities to make an overlay's load area
13061contents simply appear at their mapped address in instruction space.
13062This would probably be faster than copying the overlay to its mapped
13063area in the usual way.
13064
13065@item
13066If your overlays are small enough, you could set aside more than one
13067overlay area, and have more than one overlay mapped at a time.
13068
13069@item
13070You can use overlays to manage data, as well as instructions. In
13071general, data overlays are even less transparent to your design than
13072code overlays: whereas code overlays only require care when you call or
13073return to functions, data overlays require care every time you access
13074the data. Also, if you change the contents of a data overlay, you
13075must copy its contents back out to its load address before you can copy a
13076different data overlay into the same mapped area.
13077
13078@end itemize
13079
13080
13081@node Overlay Commands
13082@section Overlay Commands
13083
13084To use @value{GDBN}'s overlay support, each overlay in your program must
13085correspond to a separate section of the executable file. The section's
13086virtual memory address and load memory address must be the overlay's
13087mapped and load addresses. Identifying overlays with sections allows
13088@value{GDBN} to determine the appropriate address of a function or
13089variable, depending on whether the overlay is mapped or not.
13090
13091@value{GDBN}'s overlay commands all start with the word @code{overlay};
13092you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
13093
13094@table @code
13095@item overlay off
4644b6e3 13096@kindex overlay
df0cd8c5
JB
13097Disable @value{GDBN}'s overlay support. When overlay support is
13098disabled, @value{GDBN} assumes that all functions and variables are
13099always present at their mapped addresses. By default, @value{GDBN}'s
13100overlay support is disabled.
13101
13102@item overlay manual
df0cd8c5
JB
13103@cindex manual overlay debugging
13104Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
13105relies on you to tell it which overlays are mapped, and which are not,
13106using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
13107commands described below.
13108
13109@item overlay map-overlay @var{overlay}
13110@itemx overlay map @var{overlay}
df0cd8c5
JB
13111@cindex map an overlay
13112Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
13113be the name of the object file section containing the overlay. When an
13114overlay is mapped, @value{GDBN} assumes it can find the overlay's
13115functions and variables at their mapped addresses. @value{GDBN} assumes
13116that any other overlays whose mapped ranges overlap that of
13117@var{overlay} are now unmapped.
13118
13119@item overlay unmap-overlay @var{overlay}
13120@itemx overlay unmap @var{overlay}
df0cd8c5
JB
13121@cindex unmap an overlay
13122Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
13123must be the name of the object file section containing the overlay.
13124When an overlay is unmapped, @value{GDBN} assumes it can find the
13125overlay's functions and variables at their load addresses.
13126
13127@item overlay auto
df0cd8c5
JB
13128Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
13129consults a data structure the overlay manager maintains in the inferior
13130to see which overlays are mapped. For details, see @ref{Automatic
13131Overlay Debugging}.
13132
13133@item overlay load-target
13134@itemx overlay load
df0cd8c5
JB
13135@cindex reloading the overlay table
13136Re-read the overlay table from the inferior. Normally, @value{GDBN}
13137re-reads the table @value{GDBN} automatically each time the inferior
13138stops, so this command should only be necessary if you have changed the
13139overlay mapping yourself using @value{GDBN}. This command is only
13140useful when using automatic overlay debugging.
13141
13142@item overlay list-overlays
13143@itemx overlay list
13144@cindex listing mapped overlays
13145Display a list of the overlays currently mapped, along with their mapped
13146addresses, load addresses, and sizes.
13147
13148@end table
13149
13150Normally, when @value{GDBN} prints a code address, it includes the name
13151of the function the address falls in:
13152
474c8240 13153@smallexample
f7dc1244 13154(@value{GDBP}) print main
df0cd8c5 13155$3 = @{int ()@} 0x11a0 <main>
474c8240 13156@end smallexample
df0cd8c5
JB
13157@noindent
13158When overlay debugging is enabled, @value{GDBN} recognizes code in
13159unmapped overlays, and prints the names of unmapped functions with
13160asterisks around them. For example, if @code{foo} is a function in an
13161unmapped overlay, @value{GDBN} prints it this way:
13162
474c8240 13163@smallexample
f7dc1244 13164(@value{GDBP}) overlay list
df0cd8c5 13165No sections are mapped.
f7dc1244 13166(@value{GDBP}) print foo
df0cd8c5 13167$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 13168@end smallexample
df0cd8c5
JB
13169@noindent
13170When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
13171name normally:
13172
474c8240 13173@smallexample
f7dc1244 13174(@value{GDBP}) overlay list
b383017d 13175Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 13176 mapped at 0x1016 - 0x104a
f7dc1244 13177(@value{GDBP}) print foo
df0cd8c5 13178$6 = @{int (int)@} 0x1016 <foo>
474c8240 13179@end smallexample
df0cd8c5
JB
13180
13181When overlay debugging is enabled, @value{GDBN} can find the correct
13182address for functions and variables in an overlay, whether or not the
13183overlay is mapped. This allows most @value{GDBN} commands, like
13184@code{break} and @code{disassemble}, to work normally, even on unmapped
13185code. However, @value{GDBN}'s breakpoint support has some limitations:
13186
13187@itemize @bullet
13188@item
13189@cindex breakpoints in overlays
13190@cindex overlays, setting breakpoints in
13191You can set breakpoints in functions in unmapped overlays, as long as
13192@value{GDBN} can write to the overlay at its load address.
13193@item
13194@value{GDBN} can not set hardware or simulator-based breakpoints in
13195unmapped overlays. However, if you set a breakpoint at the end of your
13196overlay manager (and tell @value{GDBN} which overlays are now mapped, if
13197you are using manual overlay management), @value{GDBN} will re-set its
13198breakpoints properly.
13199@end itemize
13200
13201
13202@node Automatic Overlay Debugging
13203@section Automatic Overlay Debugging
13204@cindex automatic overlay debugging
13205
13206@value{GDBN} can automatically track which overlays are mapped and which
13207are not, given some simple co-operation from the overlay manager in the
13208inferior. If you enable automatic overlay debugging with the
13209@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
13210looks in the inferior's memory for certain variables describing the
13211current state of the overlays.
13212
13213Here are the variables your overlay manager must define to support
13214@value{GDBN}'s automatic overlay debugging:
13215
13216@table @asis
13217
13218@item @code{_ovly_table}:
13219This variable must be an array of the following structures:
13220
474c8240 13221@smallexample
df0cd8c5
JB
13222struct
13223@{
13224 /* The overlay's mapped address. */
13225 unsigned long vma;
13226
13227 /* The size of the overlay, in bytes. */
13228 unsigned long size;
13229
13230 /* The overlay's load address. */
13231 unsigned long lma;
13232
13233 /* Non-zero if the overlay is currently mapped;
13234 zero otherwise. */
13235 unsigned long mapped;
13236@}
474c8240 13237@end smallexample
df0cd8c5
JB
13238
13239@item @code{_novlys}:
13240This variable must be a four-byte signed integer, holding the total
13241number of elements in @code{_ovly_table}.
13242
13243@end table
13244
13245To decide whether a particular overlay is mapped or not, @value{GDBN}
13246looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
13247@code{lma} members equal the VMA and LMA of the overlay's section in the
13248executable file. When @value{GDBN} finds a matching entry, it consults
13249the entry's @code{mapped} member to determine whether the overlay is
13250currently mapped.
13251
81d46470 13252In addition, your overlay manager may define a function called
def71bfa 13253@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
13254will silently set a breakpoint there. If the overlay manager then
13255calls this function whenever it has changed the overlay table, this
13256will enable @value{GDBN} to accurately keep track of which overlays
13257are in program memory, and update any breakpoints that may be set
b383017d 13258in overlays. This will allow breakpoints to work even if the
81d46470
MS
13259overlays are kept in ROM or other non-writable memory while they
13260are not being executed.
df0cd8c5
JB
13261
13262@node Overlay Sample Program
13263@section Overlay Sample Program
13264@cindex overlay example program
13265
13266When linking a program which uses overlays, you must place the overlays
13267at their load addresses, while relocating them to run at their mapped
13268addresses. To do this, you must write a linker script (@pxref{Overlay
13269Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
13270since linker scripts are specific to a particular host system, target
13271architecture, and target memory layout, this manual cannot provide
13272portable sample code demonstrating @value{GDBN}'s overlay support.
13273
13274However, the @value{GDBN} source distribution does contain an overlaid
13275program, with linker scripts for a few systems, as part of its test
13276suite. The program consists of the following files from
13277@file{gdb/testsuite/gdb.base}:
13278
13279@table @file
13280@item overlays.c
13281The main program file.
13282@item ovlymgr.c
13283A simple overlay manager, used by @file{overlays.c}.
13284@item foo.c
13285@itemx bar.c
13286@itemx baz.c
13287@itemx grbx.c
13288Overlay modules, loaded and used by @file{overlays.c}.
13289@item d10v.ld
13290@itemx m32r.ld
13291Linker scripts for linking the test program on the @code{d10v-elf}
13292and @code{m32r-elf} targets.
13293@end table
13294
13295You can build the test program using the @code{d10v-elf} GCC
13296cross-compiler like this:
13297
474c8240 13298@smallexample
df0cd8c5
JB
13299$ d10v-elf-gcc -g -c overlays.c
13300$ d10v-elf-gcc -g -c ovlymgr.c
13301$ d10v-elf-gcc -g -c foo.c
13302$ d10v-elf-gcc -g -c bar.c
13303$ d10v-elf-gcc -g -c baz.c
13304$ d10v-elf-gcc -g -c grbx.c
13305$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
13306 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 13307@end smallexample
df0cd8c5
JB
13308
13309The build process is identical for any other architecture, except that
13310you must substitute the appropriate compiler and linker script for the
13311target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
13312
13313
6d2ebf8b 13314@node Languages
c906108c
SS
13315@chapter Using @value{GDBN} with Different Languages
13316@cindex languages
13317
c906108c
SS
13318Although programming languages generally have common aspects, they are
13319rarely expressed in the same manner. For instance, in ANSI C,
13320dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
13321Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 13322represented (and displayed) differently. Hex numbers in C appear as
c906108c 13323@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
13324
13325@cindex working language
13326Language-specific information is built into @value{GDBN} for some languages,
13327allowing you to express operations like the above in your program's
13328native language, and allowing @value{GDBN} to output values in a manner
13329consistent with the syntax of your program's native language. The
13330language you use to build expressions is called the @dfn{working
13331language}.
13332
13333@menu
13334* Setting:: Switching between source languages
13335* Show:: Displaying the language
c906108c 13336* Checks:: Type and range checks
79a6e687
BW
13337* Supported Languages:: Supported languages
13338* Unsupported Languages:: Unsupported languages
c906108c
SS
13339@end menu
13340
6d2ebf8b 13341@node Setting
79a6e687 13342@section Switching Between Source Languages
c906108c
SS
13343
13344There are two ways to control the working language---either have @value{GDBN}
13345set it automatically, or select it manually yourself. You can use the
13346@code{set language} command for either purpose. On startup, @value{GDBN}
13347defaults to setting the language automatically. The working language is
13348used to determine how expressions you type are interpreted, how values
13349are printed, etc.
13350
13351In addition to the working language, every source file that
13352@value{GDBN} knows about has its own working language. For some object
13353file formats, the compiler might indicate which language a particular
13354source file is in. However, most of the time @value{GDBN} infers the
13355language from the name of the file. The language of a source file
b37052ae 13356controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 13357show each frame appropriately for its own language. There is no way to
d4f3574e
SS
13358set the language of a source file from within @value{GDBN}, but you can
13359set the language associated with a filename extension. @xref{Show, ,
79a6e687 13360Displaying the Language}.
c906108c
SS
13361
13362This is most commonly a problem when you use a program, such
5d161b24 13363as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
13364another language. In that case, make the
13365program use @code{#line} directives in its C output; that way
13366@value{GDBN} will know the correct language of the source code of the original
13367program, and will display that source code, not the generated C code.
13368
13369@menu
13370* Filenames:: Filename extensions and languages.
13371* Manually:: Setting the working language manually
13372* Automatically:: Having @value{GDBN} infer the source language
13373@end menu
13374
6d2ebf8b 13375@node Filenames
79a6e687 13376@subsection List of Filename Extensions and Languages
c906108c
SS
13377
13378If a source file name ends in one of the following extensions, then
13379@value{GDBN} infers that its language is the one indicated.
13380
13381@table @file
e07c999f
PH
13382@item .ada
13383@itemx .ads
13384@itemx .adb
13385@itemx .a
13386Ada source file.
c906108c
SS
13387
13388@item .c
13389C source file
13390
13391@item .C
13392@itemx .cc
13393@itemx .cp
13394@itemx .cpp
13395@itemx .cxx
13396@itemx .c++
b37052ae 13397C@t{++} source file
c906108c 13398
6aecb9c2
JB
13399@item .d
13400D source file
13401
b37303ee
AF
13402@item .m
13403Objective-C source file
13404
c906108c
SS
13405@item .f
13406@itemx .F
13407Fortran source file
13408
c906108c
SS
13409@item .mod
13410Modula-2 source file
c906108c
SS
13411
13412@item .s
13413@itemx .S
13414Assembler source file. This actually behaves almost like C, but
13415@value{GDBN} does not skip over function prologues when stepping.
13416@end table
13417
13418In addition, you may set the language associated with a filename
79a6e687 13419extension. @xref{Show, , Displaying the Language}.
c906108c 13420
6d2ebf8b 13421@node Manually
79a6e687 13422@subsection Setting the Working Language
c906108c
SS
13423
13424If you allow @value{GDBN} to set the language automatically,
13425expressions are interpreted the same way in your debugging session and
13426your program.
13427
13428@kindex set language
13429If you wish, you may set the language manually. To do this, issue the
13430command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 13431a language, such as
c906108c 13432@code{c} or @code{modula-2}.
c906108c
SS
13433For a list of the supported languages, type @samp{set language}.
13434
c906108c
SS
13435Setting the language manually prevents @value{GDBN} from updating the working
13436language automatically. This can lead to confusion if you try
13437to debug a program when the working language is not the same as the
13438source language, when an expression is acceptable to both
13439languages---but means different things. For instance, if the current
13440source file were written in C, and @value{GDBN} was parsing Modula-2, a
13441command such as:
13442
474c8240 13443@smallexample
c906108c 13444print a = b + c
474c8240 13445@end smallexample
c906108c
SS
13446
13447@noindent
13448might not have the effect you intended. In C, this means to add
13449@code{b} and @code{c} and place the result in @code{a}. The result
13450printed would be the value of @code{a}. In Modula-2, this means to compare
13451@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 13452
6d2ebf8b 13453@node Automatically
79a6e687 13454@subsection Having @value{GDBN} Infer the Source Language
c906108c
SS
13455
13456To have @value{GDBN} set the working language automatically, use
13457@samp{set language local} or @samp{set language auto}. @value{GDBN}
13458then infers the working language. That is, when your program stops in a
13459frame (usually by encountering a breakpoint), @value{GDBN} sets the
13460working language to the language recorded for the function in that
13461frame. If the language for a frame is unknown (that is, if the function
13462or block corresponding to the frame was defined in a source file that
13463does not have a recognized extension), the current working language is
13464not changed, and @value{GDBN} issues a warning.
13465
13466This may not seem necessary for most programs, which are written
13467entirely in one source language. However, program modules and libraries
13468written in one source language can be used by a main program written in
13469a different source language. Using @samp{set language auto} in this
13470case frees you from having to set the working language manually.
13471
6d2ebf8b 13472@node Show
79a6e687 13473@section Displaying the Language
c906108c
SS
13474
13475The following commands help you find out which language is the
13476working language, and also what language source files were written in.
13477
c906108c
SS
13478@table @code
13479@item show language
403cb6b1 13480@anchor{show language}
9c16f35a 13481@kindex show language
c906108c
SS
13482Display the current working language. This is the
13483language you can use with commands such as @code{print} to
13484build and compute expressions that may involve variables in your program.
13485
13486@item info frame
4644b6e3 13487@kindex info frame@r{, show the source language}
5d161b24 13488Display the source language for this frame. This language becomes the
c906108c 13489working language if you use an identifier from this frame.
79a6e687 13490@xref{Frame Info, ,Information about a Frame}, to identify the other
c906108c
SS
13491information listed here.
13492
13493@item info source
4644b6e3 13494@kindex info source@r{, show the source language}
c906108c 13495Display the source language of this source file.
5d161b24 13496@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
13497information listed here.
13498@end table
13499
13500In unusual circumstances, you may have source files with extensions
13501not in the standard list. You can then set the extension associated
13502with a language explicitly:
13503
c906108c 13504@table @code
09d4efe1 13505@item set extension-language @var{ext} @var{language}
9c16f35a 13506@kindex set extension-language
09d4efe1
EZ
13507Tell @value{GDBN} that source files with extension @var{ext} are to be
13508assumed as written in the source language @var{language}.
c906108c
SS
13509
13510@item info extensions
9c16f35a 13511@kindex info extensions
c906108c
SS
13512List all the filename extensions and the associated languages.
13513@end table
13514
6d2ebf8b 13515@node Checks
79a6e687 13516@section Type and Range Checking
c906108c 13517
c906108c
SS
13518Some languages are designed to guard you against making seemingly common
13519errors through a series of compile- and run-time checks. These include
a451cb65 13520checking the type of arguments to functions and operators and making
c906108c
SS
13521sure mathematical overflows are caught at run time. Checks such as
13522these help to ensure a program's correctness once it has been compiled
a451cb65 13523by eliminating type mismatches and providing active checks for range
c906108c
SS
13524errors when your program is running.
13525
a451cb65
KS
13526By default @value{GDBN} checks for these errors according to the
13527rules of the current source language. Although @value{GDBN} does not check
13528the statements in your program, it can check expressions entered directly
13529into @value{GDBN} for evaluation via the @code{print} command, for example.
c906108c
SS
13530
13531@menu
13532* Type Checking:: An overview of type checking
13533* Range Checking:: An overview of range checking
13534@end menu
13535
13536@cindex type checking
13537@cindex checks, type
6d2ebf8b 13538@node Type Checking
79a6e687 13539@subsection An Overview of Type Checking
c906108c 13540
a451cb65 13541Some languages, such as C and C@t{++}, are strongly typed, meaning that the
c906108c
SS
13542arguments to operators and functions have to be of the correct type,
13543otherwise an error occurs. These checks prevent type mismatch
13544errors from ever causing any run-time problems. For example,
13545
13546@smallexample
a451cb65
KS
13547int klass::my_method(char *b) @{ return b ? 1 : 2; @}
13548
13549(@value{GDBP}) print obj.my_method (0)
13550$1 = 2
c906108c 13551@exdent but
a451cb65
KS
13552(@value{GDBP}) print obj.my_method (0x1234)
13553Cannot resolve method klass::my_method to any overloaded instance
c906108c
SS
13554@end smallexample
13555
a451cb65
KS
13556The second example fails because in C@t{++} the integer constant
13557@samp{0x1234} is not type-compatible with the pointer parameter type.
c906108c 13558
a451cb65
KS
13559For the expressions you use in @value{GDBN} commands, you can tell
13560@value{GDBN} to not enforce strict type checking or
5d161b24 13561to treat any mismatches as errors and abandon the expression;
a451cb65
KS
13562When type checking is disabled, @value{GDBN} successfully evaluates
13563expressions like the second example above.
c906108c 13564
a451cb65 13565Even if type checking is off, there may be other reasons
5d161b24
DB
13566related to type that prevent @value{GDBN} from evaluating an expression.
13567For instance, @value{GDBN} does not know how to add an @code{int} and
13568a @code{struct foo}. These particular type errors have nothing to do
a451cb65
KS
13569with the language in use and usually arise from expressions which make
13570little sense to evaluate anyway.
c906108c 13571
a451cb65 13572@value{GDBN} provides some additional commands for controlling type checking:
c906108c 13573
c906108c
SS
13574@kindex set check type
13575@kindex show check type
13576@table @code
c906108c
SS
13577@item set check type on
13578@itemx set check type off
a451cb65 13579Set strict type checking on or off. If any type mismatches occur in
d4f3574e 13580evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
13581message and aborts evaluation of the expression.
13582
a451cb65
KS
13583@item show check type
13584Show the current setting of type checking and whether @value{GDBN}
13585is enforcing strict type checking rules.
c906108c
SS
13586@end table
13587
13588@cindex range checking
13589@cindex checks, range
6d2ebf8b 13590@node Range Checking
79a6e687 13591@subsection An Overview of Range Checking
c906108c
SS
13592
13593In some languages (such as Modula-2), it is an error to exceed the
13594bounds of a type; this is enforced with run-time checks. Such range
13595checking is meant to ensure program correctness by making sure
13596computations do not overflow, or indices on an array element access do
13597not exceed the bounds of the array.
13598
13599For expressions you use in @value{GDBN} commands, you can tell
13600@value{GDBN} to treat range errors in one of three ways: ignore them,
13601always treat them as errors and abandon the expression, or issue
13602warnings but evaluate the expression anyway.
13603
13604A range error can result from numerical overflow, from exceeding an
13605array index bound, or when you type a constant that is not a member
13606of any type. Some languages, however, do not treat overflows as an
13607error. In many implementations of C, mathematical overflow causes the
13608result to ``wrap around'' to lower values---for example, if @var{m} is
13609the largest integer value, and @var{s} is the smallest, then
13610
474c8240 13611@smallexample
c906108c 13612@var{m} + 1 @result{} @var{s}
474c8240 13613@end smallexample
c906108c
SS
13614
13615This, too, is specific to individual languages, and in some cases
79a6e687
BW
13616specific to individual compilers or machines. @xref{Supported Languages, ,
13617Supported Languages}, for further details on specific languages.
c906108c
SS
13618
13619@value{GDBN} provides some additional commands for controlling the range checker:
13620
c906108c
SS
13621@kindex set check range
13622@kindex show check range
13623@table @code
13624@item set check range auto
13625Set range checking on or off based on the current working language.
79a6e687 13626@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
13627each language.
13628
13629@item set check range on
13630@itemx set check range off
13631Set range checking on or off, overriding the default setting for the
13632current working language. A warning is issued if the setting does not
c3f6f71d
JM
13633match the language default. If a range error occurs and range checking is on,
13634then a message is printed and evaluation of the expression is aborted.
c906108c
SS
13635
13636@item set check range warn
13637Output messages when the @value{GDBN} range checker detects a range error,
13638but attempt to evaluate the expression anyway. Evaluating the
13639expression may still be impossible for other reasons, such as accessing
13640memory that the process does not own (a typical example from many Unix
13641systems).
13642
13643@item show range
13644Show the current setting of the range checker, and whether or not it is
13645being set automatically by @value{GDBN}.
13646@end table
c906108c 13647
79a6e687
BW
13648@node Supported Languages
13649@section Supported Languages
c906108c 13650
a766d390
DE
13651@value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran, Java,
13652OpenCL C, Pascal, assembly, Modula-2, and Ada.
cce74817 13653@c This is false ...
c906108c
SS
13654Some @value{GDBN} features may be used in expressions regardless of the
13655language you use: the @value{GDBN} @code{@@} and @code{::} operators,
13656and the @samp{@{type@}addr} construct (@pxref{Expressions,
13657,Expressions}) can be used with the constructs of any supported
13658language.
13659
13660The following sections detail to what degree each source language is
13661supported by @value{GDBN}. These sections are not meant to be language
13662tutorials or references, but serve only as a reference guide to what the
13663@value{GDBN} expression parser accepts, and what input and output
13664formats should look like for different languages. There are many good
13665books written on each of these languages; please look to these for a
13666language reference or tutorial.
13667
c906108c 13668@menu
b37303ee 13669* C:: C and C@t{++}
6aecb9c2 13670* D:: D
a766d390 13671* Go:: Go
b383017d 13672* Objective-C:: Objective-C
f4b8a18d 13673* OpenCL C:: OpenCL C
09d4efe1 13674* Fortran:: Fortran
9c16f35a 13675* Pascal:: Pascal
b37303ee 13676* Modula-2:: Modula-2
e07c999f 13677* Ada:: Ada
c906108c
SS
13678@end menu
13679
6d2ebf8b 13680@node C
b37052ae 13681@subsection C and C@t{++}
7a292a7a 13682
b37052ae
EZ
13683@cindex C and C@t{++}
13684@cindex expressions in C or C@t{++}
c906108c 13685
b37052ae 13686Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
13687to both languages. Whenever this is the case, we discuss those languages
13688together.
13689
41afff9a
EZ
13690@cindex C@t{++}
13691@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
13692@cindex @sc{gnu} C@t{++}
13693The C@t{++} debugging facilities are jointly implemented by the C@t{++}
13694compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
13695effectively, you must compile your C@t{++} programs with a supported
13696C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
13697compiler (@code{aCC}).
13698
c906108c 13699@menu
b37052ae
EZ
13700* C Operators:: C and C@t{++} operators
13701* C Constants:: C and C@t{++} constants
79a6e687 13702* C Plus Plus Expressions:: C@t{++} expressions
b37052ae
EZ
13703* C Defaults:: Default settings for C and C@t{++}
13704* C Checks:: C and C@t{++} type and range checks
c906108c 13705* Debugging C:: @value{GDBN} and C
79a6e687 13706* Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
febe4383 13707* Decimal Floating Point:: Numbers in Decimal Floating Point format
c906108c 13708@end menu
c906108c 13709
6d2ebf8b 13710@node C Operators
79a6e687 13711@subsubsection C and C@t{++} Operators
7a292a7a 13712
b37052ae 13713@cindex C and C@t{++} operators
c906108c
SS
13714
13715Operators must be defined on values of specific types. For instance,
13716@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 13717often defined on groups of types.
c906108c 13718
b37052ae 13719For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
13720
13721@itemize @bullet
53a5351d 13722
c906108c 13723@item
c906108c 13724@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 13725specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
13726
13727@item
d4f3574e
SS
13728@emph{Floating-point types} include @code{float}, @code{double}, and
13729@code{long double} (if supported by the target platform).
c906108c
SS
13730
13731@item
53a5351d 13732@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
13733
13734@item
13735@emph{Scalar types} include all of the above.
53a5351d 13736
c906108c
SS
13737@end itemize
13738
13739@noindent
13740The following operators are supported. They are listed here
13741in order of increasing precedence:
13742
13743@table @code
13744@item ,
13745The comma or sequencing operator. Expressions in a comma-separated list
13746are evaluated from left to right, with the result of the entire
13747expression being the last expression evaluated.
13748
13749@item =
13750Assignment. The value of an assignment expression is the value
13751assigned. Defined on scalar types.
13752
13753@item @var{op}=
13754Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
13755and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 13756@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
13757@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
13758@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
13759
13760@item ?:
13761The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
13762of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
13763integral type.
13764
13765@item ||
13766Logical @sc{or}. Defined on integral types.
13767
13768@item &&
13769Logical @sc{and}. Defined on integral types.
13770
13771@item |
13772Bitwise @sc{or}. Defined on integral types.
13773
13774@item ^
13775Bitwise exclusive-@sc{or}. Defined on integral types.
13776
13777@item &
13778Bitwise @sc{and}. Defined on integral types.
13779
13780@item ==@r{, }!=
13781Equality and inequality. Defined on scalar types. The value of these
13782expressions is 0 for false and non-zero for true.
13783
13784@item <@r{, }>@r{, }<=@r{, }>=
13785Less than, greater than, less than or equal, greater than or equal.
13786Defined on scalar types. The value of these expressions is 0 for false
13787and non-zero for true.
13788
13789@item <<@r{, }>>
13790left shift, and right shift. Defined on integral types.
13791
13792@item @@
13793The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
13794
13795@item +@r{, }-
13796Addition and subtraction. Defined on integral types, floating-point types and
13797pointer types.
13798
13799@item *@r{, }/@r{, }%
13800Multiplication, division, and modulus. Multiplication and division are
13801defined on integral and floating-point types. Modulus is defined on
13802integral types.
13803
13804@item ++@r{, }--
13805Increment and decrement. When appearing before a variable, the
13806operation is performed before the variable is used in an expression;
13807when appearing after it, the variable's value is used before the
13808operation takes place.
13809
13810@item *
13811Pointer dereferencing. Defined on pointer types. Same precedence as
13812@code{++}.
13813
13814@item &
13815Address operator. Defined on variables. Same precedence as @code{++}.
13816
b37052ae
EZ
13817For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
13818allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
b17828ca 13819to examine the address
b37052ae 13820where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 13821stored.
c906108c
SS
13822
13823@item -
13824Negative. Defined on integral and floating-point types. Same
13825precedence as @code{++}.
13826
13827@item !
13828Logical negation. Defined on integral types. Same precedence as
13829@code{++}.
13830
13831@item ~
13832Bitwise complement operator. Defined on integral types. Same precedence as
13833@code{++}.
13834
13835
13836@item .@r{, }->
13837Structure member, and pointer-to-structure member. For convenience,
13838@value{GDBN} regards the two as equivalent, choosing whether to dereference a
13839pointer based on the stored type information.
13840Defined on @code{struct} and @code{union} data.
13841
c906108c
SS
13842@item .*@r{, }->*
13843Dereferences of pointers to members.
c906108c
SS
13844
13845@item []
13846Array indexing. @code{@var{a}[@var{i}]} is defined as
13847@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
13848
13849@item ()
13850Function parameter list. Same precedence as @code{->}.
13851
c906108c 13852@item ::
b37052ae 13853C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 13854and @code{class} types.
c906108c
SS
13855
13856@item ::
7a292a7a
SS
13857Doubled colons also represent the @value{GDBN} scope operator
13858(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
13859above.
c906108c
SS
13860@end table
13861
c906108c
SS
13862If an operator is redefined in the user code, @value{GDBN} usually
13863attempts to invoke the redefined version instead of using the operator's
13864predefined meaning.
c906108c 13865
6d2ebf8b 13866@node C Constants
79a6e687 13867@subsubsection C and C@t{++} Constants
c906108c 13868
b37052ae 13869@cindex C and C@t{++} constants
c906108c 13870
b37052ae 13871@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 13872following ways:
c906108c
SS
13873
13874@itemize @bullet
13875@item
13876Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
13877specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
13878by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
13879@samp{l}, specifying that the constant should be treated as a
13880@code{long} value.
13881
13882@item
13883Floating point constants are a sequence of digits, followed by a decimal
13884point, followed by a sequence of digits, and optionally followed by an
13885exponent. An exponent is of the form:
13886@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
13887sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
13888A floating-point constant may also end with a letter @samp{f} or
13889@samp{F}, specifying that the constant should be treated as being of
13890the @code{float} (as opposed to the default @code{double}) type; or with
13891a letter @samp{l} or @samp{L}, which specifies a @code{long double}
13892constant.
c906108c
SS
13893
13894@item
13895Enumerated constants consist of enumerated identifiers, or their
13896integral equivalents.
13897
13898@item
13899Character constants are a single character surrounded by single quotes
13900(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 13901(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
13902be represented by a letter or by @dfn{escape sequences}, which are of
13903the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
13904of the character's ordinal value; or of the form @samp{\@var{x}}, where
13905@samp{@var{x}} is a predefined special character---for example,
13906@samp{\n} for newline.
13907
e0f8f636
TT
13908Wide character constants can be written by prefixing a character
13909constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
13910form of @samp{x}. The target wide character set is used when
13911computing the value of this constant (@pxref{Character Sets}).
13912
c906108c 13913@item
96a2c332
SS
13914String constants are a sequence of character constants surrounded by
13915double quotes (@code{"}). Any valid character constant (as described
13916above) may appear. Double quotes within the string must be preceded by
13917a backslash, so for instance @samp{"a\"b'c"} is a string of five
13918characters.
c906108c 13919
e0f8f636
TT
13920Wide string constants can be written by prefixing a string constant
13921with @samp{L}, as in C. The target wide character set is used when
13922computing the value of this constant (@pxref{Character Sets}).
13923
c906108c
SS
13924@item
13925Pointer constants are an integral value. You can also write pointers
13926to constants using the C operator @samp{&}.
13927
13928@item
13929Array constants are comma-separated lists surrounded by braces @samp{@{}
13930and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
13931integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
13932and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
13933@end itemize
13934
79a6e687
BW
13935@node C Plus Plus Expressions
13936@subsubsection C@t{++} Expressions
b37052ae
EZ
13937
13938@cindex expressions in C@t{++}
13939@value{GDBN} expression handling can interpret most C@t{++} expressions.
13940
0179ffac
DC
13941@cindex debugging C@t{++} programs
13942@cindex C@t{++} compilers
13943@cindex debug formats and C@t{++}
13944@cindex @value{NGCC} and C@t{++}
c906108c 13945@quotation
e0f8f636
TT
13946@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
13947the proper compiler and the proper debug format. Currently,
13948@value{GDBN} works best when debugging C@t{++} code that is compiled
13949with the most recent version of @value{NGCC} possible. The DWARF
13950debugging format is preferred; @value{NGCC} defaults to this on most
13951popular platforms. Other compilers and/or debug formats are likely to
13952work badly or not at all when using @value{GDBN} to debug C@t{++}
13953code. @xref{Compilation}.
c906108c 13954@end quotation
c906108c
SS
13955
13956@enumerate
13957
13958@cindex member functions
13959@item
13960Member function calls are allowed; you can use expressions like
13961
474c8240 13962@smallexample
c906108c 13963count = aml->GetOriginal(x, y)
474c8240 13964@end smallexample
c906108c 13965
41afff9a 13966@vindex this@r{, inside C@t{++} member functions}
b37052ae 13967@cindex namespace in C@t{++}
c906108c
SS
13968@item
13969While a member function is active (in the selected stack frame), your
13970expressions have the same namespace available as the member function;
13971that is, @value{GDBN} allows implicit references to the class instance
e0f8f636
TT
13972pointer @code{this} following the same rules as C@t{++}. @code{using}
13973declarations in the current scope are also respected by @value{GDBN}.
c906108c 13974
c906108c 13975@cindex call overloaded functions
d4f3574e 13976@cindex overloaded functions, calling
b37052ae 13977@cindex type conversions in C@t{++}
c906108c
SS
13978@item
13979You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 13980call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
13981perform overload resolution involving user-defined type conversions,
13982calls to constructors, or instantiations of templates that do not exist
13983in the program. It also cannot handle ellipsis argument lists or
13984default arguments.
13985
13986It does perform integral conversions and promotions, floating-point
13987promotions, arithmetic conversions, pointer conversions, conversions of
13988class objects to base classes, and standard conversions such as those of
13989functions or arrays to pointers; it requires an exact match on the
13990number of function arguments.
13991
13992Overload resolution is always performed, unless you have specified
79a6e687
BW
13993@code{set overload-resolution off}. @xref{Debugging C Plus Plus,
13994,@value{GDBN} Features for C@t{++}}.
c906108c 13995
d4f3574e 13996You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
13997explicit function signature to call an overloaded function, as in
13998@smallexample
13999p 'foo(char,int)'('x', 13)
14000@end smallexample
d4f3574e 14001
c906108c 14002The @value{GDBN} command-completion facility can simplify this;
79a6e687 14003see @ref{Completion, ,Command Completion}.
c906108c 14004
c906108c
SS
14005@cindex reference declarations
14006@item
b37052ae
EZ
14007@value{GDBN} understands variables declared as C@t{++} references; you can use
14008them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
14009dereferenced.
14010
14011In the parameter list shown when @value{GDBN} displays a frame, the values of
14012reference variables are not displayed (unlike other variables); this
14013avoids clutter, since references are often used for large structures.
14014The @emph{address} of a reference variable is always shown, unless
14015you have specified @samp{set print address off}.
14016
14017@item
b37052ae 14018@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
14019expressions can use it just as expressions in your program do. Since
14020one scope may be defined in another, you can use @code{::} repeatedly if
14021necessary, for example in an expression like
14022@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 14023resolving name scope by reference to source files, in both C and C@t{++}
79a6e687 14024debugging (@pxref{Variables, ,Program Variables}).
c906108c 14025
e0f8f636
TT
14026@item
14027@value{GDBN} performs argument-dependent lookup, following the C@t{++}
14028specification.
14029@end enumerate
c906108c 14030
6d2ebf8b 14031@node C Defaults
79a6e687 14032@subsubsection C and C@t{++} Defaults
7a292a7a 14033
b37052ae 14034@cindex C and C@t{++} defaults
c906108c 14035
a451cb65
KS
14036If you allow @value{GDBN} to set range checking automatically, it
14037defaults to @code{off} whenever the working language changes to
b37052ae 14038C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 14039selects the working language.
c906108c
SS
14040
14041If you allow @value{GDBN} to set the language automatically, it
14042recognizes source files whose names end with @file{.c}, @file{.C}, or
14043@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 14044these files, it sets the working language to C or C@t{++}.
79a6e687 14045@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
c906108c
SS
14046for further details.
14047
6d2ebf8b 14048@node C Checks
79a6e687 14049@subsubsection C and C@t{++} Type and Range Checks
7a292a7a 14050
b37052ae 14051@cindex C and C@t{++} checks
c906108c 14052
a451cb65
KS
14053By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
14054checking is used. However, if you turn type checking off, @value{GDBN}
14055will allow certain non-standard conversions, such as promoting integer
14056constants to pointers.
c906108c
SS
14057
14058Range checking, if turned on, is done on mathematical operations. Array
14059indices are not checked, since they are often used to index a pointer
14060that is not itself an array.
c906108c 14061
6d2ebf8b 14062@node Debugging C
c906108c 14063@subsubsection @value{GDBN} and C
c906108c
SS
14064
14065The @code{set print union} and @code{show print union} commands apply to
14066the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
14067inside a @code{struct} or @code{class} is also printed. Otherwise, it
14068appears as @samp{@{...@}}.
c906108c
SS
14069
14070The @code{@@} operator aids in the debugging of dynamic arrays, formed
14071with pointers and a memory allocation function. @xref{Expressions,
14072,Expressions}.
14073
79a6e687
BW
14074@node Debugging C Plus Plus
14075@subsubsection @value{GDBN} Features for C@t{++}
c906108c 14076
b37052ae 14077@cindex commands for C@t{++}
7a292a7a 14078
b37052ae
EZ
14079Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
14080designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
14081
14082@table @code
14083@cindex break in overloaded functions
14084@item @r{breakpoint menus}
14085When you want a breakpoint in a function whose name is overloaded,
6ba66d6a
JB
14086@value{GDBN} has the capability to display a menu of possible breakpoint
14087locations to help you specify which function definition you want.
14088@xref{Ambiguous Expressions,,Ambiguous Expressions}.
c906108c 14089
b37052ae 14090@cindex overloading in C@t{++}
c906108c
SS
14091@item rbreak @var{regex}
14092Setting breakpoints using regular expressions is helpful for setting
14093breakpoints on overloaded functions that are not members of any special
14094classes.
79a6e687 14095@xref{Set Breaks, ,Setting Breakpoints}.
c906108c 14096
b37052ae 14097@cindex C@t{++} exception handling
c906108c 14098@item catch throw
591f19e8 14099@itemx catch rethrow
c906108c 14100@itemx catch catch
b37052ae 14101Debug C@t{++} exception handling using these commands. @xref{Set
79a6e687 14102Catchpoints, , Setting Catchpoints}.
c906108c
SS
14103
14104@cindex inheritance
14105@item ptype @var{typename}
14106Print inheritance relationships as well as other information for type
14107@var{typename}.
14108@xref{Symbols, ,Examining the Symbol Table}.
14109
c4aeac85
TT
14110@item info vtbl @var{expression}.
14111The @code{info vtbl} command can be used to display the virtual
14112method tables of the object computed by @var{expression}. This shows
14113one entry per virtual table; there may be multiple virtual tables when
14114multiple inheritance is in use.
14115
b37052ae 14116@cindex C@t{++} symbol display
c906108c
SS
14117@item set print demangle
14118@itemx show print demangle
14119@itemx set print asm-demangle
14120@itemx show print asm-demangle
b37052ae
EZ
14121Control whether C@t{++} symbols display in their source form, both when
14122displaying code as C@t{++} source and when displaying disassemblies.
79a6e687 14123@xref{Print Settings, ,Print Settings}.
c906108c
SS
14124
14125@item set print object
14126@itemx show print object
14127Choose whether to print derived (actual) or declared types of objects.
79a6e687 14128@xref{Print Settings, ,Print Settings}.
c906108c
SS
14129
14130@item set print vtbl
14131@itemx show print vtbl
14132Control the format for printing virtual function tables.
79a6e687 14133@xref{Print Settings, ,Print Settings}.
c906108c 14134(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 14135ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
14136
14137@kindex set overload-resolution
d4f3574e 14138@cindex overloaded functions, overload resolution
c906108c 14139@item set overload-resolution on
b37052ae 14140Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
14141is on. For overloaded functions, @value{GDBN} evaluates the arguments
14142and searches for a function whose signature matches the argument types,
79a6e687
BW
14143using the standard C@t{++} conversion rules (see @ref{C Plus Plus
14144Expressions, ,C@t{++} Expressions}, for details).
14145If it cannot find a match, it emits a message.
c906108c
SS
14146
14147@item set overload-resolution off
b37052ae 14148Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
14149overloaded functions that are not class member functions, @value{GDBN}
14150chooses the first function of the specified name that it finds in the
14151symbol table, whether or not its arguments are of the correct type. For
14152overloaded functions that are class member functions, @value{GDBN}
14153searches for a function whose signature @emph{exactly} matches the
14154argument types.
c906108c 14155
9c16f35a
EZ
14156@kindex show overload-resolution
14157@item show overload-resolution
14158Show the current setting of overload resolution.
14159
c906108c
SS
14160@item @r{Overloaded symbol names}
14161You can specify a particular definition of an overloaded symbol, using
b37052ae 14162the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
14163@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
14164also use the @value{GDBN} command-line word completion facilities to list the
14165available choices, or to finish the type list for you.
79a6e687 14166@xref{Completion,, Command Completion}, for details on how to do this.
c906108c 14167@end table
c906108c 14168
febe4383
TJB
14169@node Decimal Floating Point
14170@subsubsection Decimal Floating Point format
14171@cindex decimal floating point format
14172
14173@value{GDBN} can examine, set and perform computations with numbers in
14174decimal floating point format, which in the C language correspond to the
14175@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
14176specified by the extension to support decimal floating-point arithmetic.
14177
14178There are two encodings in use, depending on the architecture: BID (Binary
14179Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
4ac33720
UW
14180PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
14181configured target.
febe4383
TJB
14182
14183Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
14184to manipulate decimal floating point numbers, it is not possible to convert
14185(using a cast, for example) integers wider than 32-bit to decimal float.
14186
14187In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
14188point computations, error checking in decimal float operations ignores
14189underflow, overflow and divide by zero exceptions.
14190
4acd40f3 14191In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
99e008fe
EZ
14192to inspect @code{_Decimal128} values stored in floating point registers.
14193See @ref{PowerPC,,PowerPC} for more details.
4acd40f3 14194
6aecb9c2
JB
14195@node D
14196@subsection D
14197
14198@cindex D
14199@value{GDBN} can be used to debug programs written in D and compiled with
14200GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
14201specific feature --- dynamic arrays.
14202
a766d390
DE
14203@node Go
14204@subsection Go
14205
14206@cindex Go (programming language)
14207@value{GDBN} can be used to debug programs written in Go and compiled with
14208@file{gccgo} or @file{6g} compilers.
14209
14210Here is a summary of the Go-specific features and restrictions:
14211
14212@table @code
14213@cindex current Go package
14214@item The current Go package
14215The name of the current package does not need to be specified when
14216specifying global variables and functions.
14217
14218For example, given the program:
14219
14220@example
14221package main
14222var myglob = "Shall we?"
14223func main () @{
14224 // ...
14225@}
14226@end example
14227
14228When stopped inside @code{main} either of these work:
14229
14230@example
14231(gdb) p myglob
14232(gdb) p main.myglob
14233@end example
14234
14235@cindex builtin Go types
14236@item Builtin Go types
14237The @code{string} type is recognized by @value{GDBN} and is printed
14238as a string.
14239
14240@cindex builtin Go functions
14241@item Builtin Go functions
14242The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
14243function and handles it internally.
a766d390
DE
14244
14245@cindex restrictions on Go expressions
14246@item Restrictions on Go expressions
14247All Go operators are supported except @code{&^}.
14248The Go @code{_} ``blank identifier'' is not supported.
14249Automatic dereferencing of pointers is not supported.
50f042b9 14250@end table
a766d390 14251
b37303ee
AF
14252@node Objective-C
14253@subsection Objective-C
14254
14255@cindex Objective-C
14256This section provides information about some commands and command
721c2651
EZ
14257options that are useful for debugging Objective-C code. See also
14258@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
14259few more commands specific to Objective-C support.
b37303ee
AF
14260
14261@menu
b383017d
RM
14262* Method Names in Commands::
14263* The Print Command with Objective-C::
b37303ee
AF
14264@end menu
14265
c8f4133a 14266@node Method Names in Commands
b37303ee
AF
14267@subsubsection Method Names in Commands
14268
14269The following commands have been extended to accept Objective-C method
14270names as line specifications:
14271
14272@kindex clear@r{, and Objective-C}
14273@kindex break@r{, and Objective-C}
14274@kindex info line@r{, and Objective-C}
14275@kindex jump@r{, and Objective-C}
14276@kindex list@r{, and Objective-C}
14277@itemize
14278@item @code{clear}
14279@item @code{break}
14280@item @code{info line}
14281@item @code{jump}
14282@item @code{list}
14283@end itemize
14284
14285A fully qualified Objective-C method name is specified as
14286
14287@smallexample
14288-[@var{Class} @var{methodName}]
14289@end smallexample
14290
c552b3bb
JM
14291where the minus sign is used to indicate an instance method and a
14292plus sign (not shown) is used to indicate a class method. The class
14293name @var{Class} and method name @var{methodName} are enclosed in
14294brackets, similar to the way messages are specified in Objective-C
14295source code. For example, to set a breakpoint at the @code{create}
14296instance method of class @code{Fruit} in the program currently being
14297debugged, enter:
b37303ee
AF
14298
14299@smallexample
14300break -[Fruit create]
14301@end smallexample
14302
14303To list ten program lines around the @code{initialize} class method,
14304enter:
14305
14306@smallexample
14307list +[NSText initialize]
14308@end smallexample
14309
c552b3bb
JM
14310In the current version of @value{GDBN}, the plus or minus sign is
14311required. In future versions of @value{GDBN}, the plus or minus
14312sign will be optional, but you can use it to narrow the search. It
14313is also possible to specify just a method name:
b37303ee
AF
14314
14315@smallexample
14316break create
14317@end smallexample
14318
14319You must specify the complete method name, including any colons. If
14320your program's source files contain more than one @code{create} method,
14321you'll be presented with a numbered list of classes that implement that
14322method. Indicate your choice by number, or type @samp{0} to exit if
14323none apply.
14324
14325As another example, to clear a breakpoint established at the
14326@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
14327
14328@smallexample
14329clear -[NSWindow makeKeyAndOrderFront:]
14330@end smallexample
14331
14332@node The Print Command with Objective-C
14333@subsubsection The Print Command With Objective-C
721c2651 14334@cindex Objective-C, print objects
c552b3bb
JM
14335@kindex print-object
14336@kindex po @r{(@code{print-object})}
b37303ee 14337
c552b3bb 14338The print command has also been extended to accept methods. For example:
b37303ee
AF
14339
14340@smallexample
c552b3bb 14341print -[@var{object} hash]
b37303ee
AF
14342@end smallexample
14343
14344@cindex print an Objective-C object description
c552b3bb
JM
14345@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
14346@noindent
14347will tell @value{GDBN} to send the @code{hash} message to @var{object}
14348and print the result. Also, an additional command has been added,
14349@code{print-object} or @code{po} for short, which is meant to print
14350the description of an object. However, this command may only work
14351with certain Objective-C libraries that have a particular hook
14352function, @code{_NSPrintForDebugger}, defined.
b37303ee 14353
f4b8a18d
KW
14354@node OpenCL C
14355@subsection OpenCL C
14356
14357@cindex OpenCL C
14358This section provides information about @value{GDBN}s OpenCL C support.
14359
14360@menu
14361* OpenCL C Datatypes::
14362* OpenCL C Expressions::
14363* OpenCL C Operators::
14364@end menu
14365
14366@node OpenCL C Datatypes
14367@subsubsection OpenCL C Datatypes
14368
14369@cindex OpenCL C Datatypes
14370@value{GDBN} supports the builtin scalar and vector datatypes specified
14371by OpenCL 1.1. In addition the half- and double-precision floating point
14372data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
14373extensions are also known to @value{GDBN}.
14374
14375@node OpenCL C Expressions
14376@subsubsection OpenCL C Expressions
14377
14378@cindex OpenCL C Expressions
14379@value{GDBN} supports accesses to vector components including the access as
14380lvalue where possible. Since OpenCL C is based on C99 most C expressions
14381supported by @value{GDBN} can be used as well.
14382
14383@node OpenCL C Operators
14384@subsubsection OpenCL C Operators
14385
14386@cindex OpenCL C Operators
14387@value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
14388vector data types.
14389
09d4efe1
EZ
14390@node Fortran
14391@subsection Fortran
14392@cindex Fortran-specific support in @value{GDBN}
14393
814e32d7
WZ
14394@value{GDBN} can be used to debug programs written in Fortran, but it
14395currently supports only the features of Fortran 77 language.
14396
14397@cindex trailing underscore, in Fortran symbols
14398Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
14399among them) append an underscore to the names of variables and
14400functions. When you debug programs compiled by those compilers, you
14401will need to refer to variables and functions with a trailing
14402underscore.
14403
14404@menu
14405* Fortran Operators:: Fortran operators and expressions
14406* Fortran Defaults:: Default settings for Fortran
79a6e687 14407* Special Fortran Commands:: Special @value{GDBN} commands for Fortran
814e32d7
WZ
14408@end menu
14409
14410@node Fortran Operators
79a6e687 14411@subsubsection Fortran Operators and Expressions
814e32d7
WZ
14412
14413@cindex Fortran operators and expressions
14414
14415Operators must be defined on values of specific types. For instance,
14416@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 14417arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
14418
14419@table @code
14420@item **
99e008fe 14421The exponentiation operator. It raises the first operand to the power
814e32d7
WZ
14422of the second one.
14423
14424@item :
14425The range operator. Normally used in the form of array(low:high) to
14426represent a section of array.
68837c9d
MD
14427
14428@item %
14429The access component operator. Normally used to access elements in derived
14430types. Also suitable for unions. As unions aren't part of regular Fortran,
14431this can only happen when accessing a register that uses a gdbarch-defined
14432union type.
814e32d7
WZ
14433@end table
14434
14435@node Fortran Defaults
14436@subsubsection Fortran Defaults
14437
14438@cindex Fortran Defaults
14439
14440Fortran symbols are usually case-insensitive, so @value{GDBN} by
14441default uses case-insensitive matches for Fortran symbols. You can
14442change that with the @samp{set case-insensitive} command, see
14443@ref{Symbols}, for the details.
14444
79a6e687
BW
14445@node Special Fortran Commands
14446@subsubsection Special Fortran Commands
814e32d7
WZ
14447
14448@cindex Special Fortran commands
14449
db2e3e2e
BW
14450@value{GDBN} has some commands to support Fortran-specific features,
14451such as displaying common blocks.
814e32d7 14452
09d4efe1
EZ
14453@table @code
14454@cindex @code{COMMON} blocks, Fortran
14455@kindex info common
14456@item info common @r{[}@var{common-name}@r{]}
14457This command prints the values contained in the Fortran @code{COMMON}
14458block whose name is @var{common-name}. With no argument, the names of
d52fb0e9 14459all @code{COMMON} blocks visible at the current program location are
09d4efe1
EZ
14460printed.
14461@end table
14462
9c16f35a
EZ
14463@node Pascal
14464@subsection Pascal
14465
14466@cindex Pascal support in @value{GDBN}, limitations
14467Debugging Pascal programs which use sets, subranges, file variables, or
14468nested functions does not currently work. @value{GDBN} does not support
14469entering expressions, printing values, or similar features using Pascal
14470syntax.
14471
14472The Pascal-specific command @code{set print pascal_static-members}
14473controls whether static members of Pascal objects are displayed.
14474@xref{Print Settings, pascal_static-members}.
14475
09d4efe1 14476@node Modula-2
c906108c 14477@subsection Modula-2
7a292a7a 14478
d4f3574e 14479@cindex Modula-2, @value{GDBN} support
c906108c
SS
14480
14481The extensions made to @value{GDBN} to support Modula-2 only support
14482output from the @sc{gnu} Modula-2 compiler (which is currently being
14483developed). Other Modula-2 compilers are not currently supported, and
14484attempting to debug executables produced by them is most likely
14485to give an error as @value{GDBN} reads in the executable's symbol
14486table.
14487
14488@cindex expressions in Modula-2
14489@menu
14490* M2 Operators:: Built-in operators
14491* Built-In Func/Proc:: Built-in functions and procedures
14492* M2 Constants:: Modula-2 constants
72019c9c 14493* M2 Types:: Modula-2 types
c906108c
SS
14494* M2 Defaults:: Default settings for Modula-2
14495* Deviations:: Deviations from standard Modula-2
14496* M2 Checks:: Modula-2 type and range checks
14497* M2 Scope:: The scope operators @code{::} and @code{.}
14498* GDB/M2:: @value{GDBN} and Modula-2
14499@end menu
14500
6d2ebf8b 14501@node M2 Operators
c906108c
SS
14502@subsubsection Operators
14503@cindex Modula-2 operators
14504
14505Operators must be defined on values of specific types. For instance,
14506@code{+} is defined on numbers, but not on structures. Operators are
14507often defined on groups of types. For the purposes of Modula-2, the
14508following definitions hold:
14509
14510@itemize @bullet
14511
14512@item
14513@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
14514their subranges.
14515
14516@item
14517@emph{Character types} consist of @code{CHAR} and its subranges.
14518
14519@item
14520@emph{Floating-point types} consist of @code{REAL}.
14521
14522@item
14523@emph{Pointer types} consist of anything declared as @code{POINTER TO
14524@var{type}}.
14525
14526@item
14527@emph{Scalar types} consist of all of the above.
14528
14529@item
14530@emph{Set types} consist of @code{SET} and @code{BITSET} types.
14531
14532@item
14533@emph{Boolean types} consist of @code{BOOLEAN}.
14534@end itemize
14535
14536@noindent
14537The following operators are supported, and appear in order of
14538increasing precedence:
14539
14540@table @code
14541@item ,
14542Function argument or array index separator.
14543
14544@item :=
14545Assignment. The value of @var{var} @code{:=} @var{value} is
14546@var{value}.
14547
14548@item <@r{, }>
14549Less than, greater than on integral, floating-point, or enumerated
14550types.
14551
14552@item <=@r{, }>=
96a2c332 14553Less than or equal to, greater than or equal to
c906108c
SS
14554on integral, floating-point and enumerated types, or set inclusion on
14555set types. Same precedence as @code{<}.
14556
14557@item =@r{, }<>@r{, }#
14558Equality and two ways of expressing inequality, valid on scalar types.
14559Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
14560available for inequality, since @code{#} conflicts with the script
14561comment character.
14562
14563@item IN
14564Set membership. Defined on set types and the types of their members.
14565Same precedence as @code{<}.
14566
14567@item OR
14568Boolean disjunction. Defined on boolean types.
14569
14570@item AND@r{, }&
d4f3574e 14571Boolean conjunction. Defined on boolean types.
c906108c
SS
14572
14573@item @@
14574The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
14575
14576@item +@r{, }-
14577Addition and subtraction on integral and floating-point types, or union
14578and difference on set types.
14579
14580@item *
14581Multiplication on integral and floating-point types, or set intersection
14582on set types.
14583
14584@item /
14585Division on floating-point types, or symmetric set difference on set
14586types. Same precedence as @code{*}.
14587
14588@item DIV@r{, }MOD
14589Integer division and remainder. Defined on integral types. Same
14590precedence as @code{*}.
14591
14592@item -
99e008fe 14593Negative. Defined on @code{INTEGER} and @code{REAL} data.
c906108c
SS
14594
14595@item ^
14596Pointer dereferencing. Defined on pointer types.
14597
14598@item NOT
14599Boolean negation. Defined on boolean types. Same precedence as
14600@code{^}.
14601
14602@item .
14603@code{RECORD} field selector. Defined on @code{RECORD} data. Same
14604precedence as @code{^}.
14605
14606@item []
14607Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
14608
14609@item ()
14610Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
14611as @code{^}.
14612
14613@item ::@r{, }.
14614@value{GDBN} and Modula-2 scope operators.
14615@end table
14616
14617@quotation
72019c9c 14618@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
14619treats the use of the operator @code{IN}, or the use of operators
14620@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
14621@code{<=}, and @code{>=} on sets as an error.
14622@end quotation
14623
cb51c4e0 14624
6d2ebf8b 14625@node Built-In Func/Proc
79a6e687 14626@subsubsection Built-in Functions and Procedures
cb51c4e0 14627@cindex Modula-2 built-ins
c906108c
SS
14628
14629Modula-2 also makes available several built-in procedures and functions.
14630In describing these, the following metavariables are used:
14631
14632@table @var
14633
14634@item a
14635represents an @code{ARRAY} variable.
14636
14637@item c
14638represents a @code{CHAR} constant or variable.
14639
14640@item i
14641represents a variable or constant of integral type.
14642
14643@item m
14644represents an identifier that belongs to a set. Generally used in the
14645same function with the metavariable @var{s}. The type of @var{s} should
14646be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
14647
14648@item n
14649represents a variable or constant of integral or floating-point type.
14650
14651@item r
14652represents a variable or constant of floating-point type.
14653
14654@item t
14655represents a type.
14656
14657@item v
14658represents a variable.
14659
14660@item x
14661represents a variable or constant of one of many types. See the
14662explanation of the function for details.
14663@end table
14664
14665All Modula-2 built-in procedures also return a result, described below.
14666
14667@table @code
14668@item ABS(@var{n})
14669Returns the absolute value of @var{n}.
14670
14671@item CAP(@var{c})
14672If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 14673equivalent, otherwise it returns its argument.
c906108c
SS
14674
14675@item CHR(@var{i})
14676Returns the character whose ordinal value is @var{i}.
14677
14678@item DEC(@var{v})
c3f6f71d 14679Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
14680
14681@item DEC(@var{v},@var{i})
14682Decrements the value in the variable @var{v} by @var{i}. Returns the
14683new value.
14684
14685@item EXCL(@var{m},@var{s})
14686Removes the element @var{m} from the set @var{s}. Returns the new
14687set.
14688
14689@item FLOAT(@var{i})
14690Returns the floating point equivalent of the integer @var{i}.
14691
14692@item HIGH(@var{a})
14693Returns the index of the last member of @var{a}.
14694
14695@item INC(@var{v})
c3f6f71d 14696Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
14697
14698@item INC(@var{v},@var{i})
14699Increments the value in the variable @var{v} by @var{i}. Returns the
14700new value.
14701
14702@item INCL(@var{m},@var{s})
14703Adds the element @var{m} to the set @var{s} if it is not already
14704there. Returns the new set.
14705
14706@item MAX(@var{t})
14707Returns the maximum value of the type @var{t}.
14708
14709@item MIN(@var{t})
14710Returns the minimum value of the type @var{t}.
14711
14712@item ODD(@var{i})
14713Returns boolean TRUE if @var{i} is an odd number.
14714
14715@item ORD(@var{x})
14716Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
14717value of a character is its @sc{ascii} value (on machines supporting the
14718@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
14719integral, character and enumerated types.
14720
14721@item SIZE(@var{x})
14722Returns the size of its argument. @var{x} can be a variable or a type.
14723
14724@item TRUNC(@var{r})
14725Returns the integral part of @var{r}.
14726
844781a1
GM
14727@item TSIZE(@var{x})
14728Returns the size of its argument. @var{x} can be a variable or a type.
14729
c906108c
SS
14730@item VAL(@var{t},@var{i})
14731Returns the member of the type @var{t} whose ordinal value is @var{i}.
14732@end table
14733
14734@quotation
14735@emph{Warning:} Sets and their operations are not yet supported, so
14736@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
14737an error.
14738@end quotation
14739
14740@cindex Modula-2 constants
6d2ebf8b 14741@node M2 Constants
c906108c
SS
14742@subsubsection Constants
14743
14744@value{GDBN} allows you to express the constants of Modula-2 in the following
14745ways:
14746
14747@itemize @bullet
14748
14749@item
14750Integer constants are simply a sequence of digits. When used in an
14751expression, a constant is interpreted to be type-compatible with the
14752rest of the expression. Hexadecimal integers are specified by a
14753trailing @samp{H}, and octal integers by a trailing @samp{B}.
14754
14755@item
14756Floating point constants appear as a sequence of digits, followed by a
14757decimal point and another sequence of digits. An optional exponent can
14758then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
14759@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
14760digits of the floating point constant must be valid decimal (base 10)
14761digits.
14762
14763@item
14764Character constants consist of a single character enclosed by a pair of
14765like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 14766also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
14767followed by a @samp{C}.
14768
14769@item
14770String constants consist of a sequence of characters enclosed by a
14771pair of like quotes, either single (@code{'}) or double (@code{"}).
14772Escape sequences in the style of C are also allowed. @xref{C
79a6e687 14773Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
c906108c
SS
14774sequences.
14775
14776@item
14777Enumerated constants consist of an enumerated identifier.
14778
14779@item
14780Boolean constants consist of the identifiers @code{TRUE} and
14781@code{FALSE}.
14782
14783@item
14784Pointer constants consist of integral values only.
14785
14786@item
14787Set constants are not yet supported.
14788@end itemize
14789
72019c9c
GM
14790@node M2 Types
14791@subsubsection Modula-2 Types
14792@cindex Modula-2 types
14793
14794Currently @value{GDBN} can print the following data types in Modula-2
14795syntax: array types, record types, set types, pointer types, procedure
14796types, enumerated types, subrange types and base types. You can also
14797print the contents of variables declared using these type.
14798This section gives a number of simple source code examples together with
14799sample @value{GDBN} sessions.
14800
14801The first example contains the following section of code:
14802
14803@smallexample
14804VAR
14805 s: SET OF CHAR ;
14806 r: [20..40] ;
14807@end smallexample
14808
14809@noindent
14810and you can request @value{GDBN} to interrogate the type and value of
14811@code{r} and @code{s}.
14812
14813@smallexample
14814(@value{GDBP}) print s
14815@{'A'..'C', 'Z'@}
14816(@value{GDBP}) ptype s
14817SET OF CHAR
14818(@value{GDBP}) print r
1481921
14820(@value{GDBP}) ptype r
14821[20..40]
14822@end smallexample
14823
14824@noindent
14825Likewise if your source code declares @code{s} as:
14826
14827@smallexample
14828VAR
14829 s: SET ['A'..'Z'] ;
14830@end smallexample
14831
14832@noindent
14833then you may query the type of @code{s} by:
14834
14835@smallexample
14836(@value{GDBP}) ptype s
14837type = SET ['A'..'Z']
14838@end smallexample
14839
14840@noindent
14841Note that at present you cannot interactively manipulate set
14842expressions using the debugger.
14843
14844The following example shows how you might declare an array in Modula-2
14845and how you can interact with @value{GDBN} to print its type and contents:
14846
14847@smallexample
14848VAR
14849 s: ARRAY [-10..10] OF CHAR ;
14850@end smallexample
14851
14852@smallexample
14853(@value{GDBP}) ptype s
14854ARRAY [-10..10] OF CHAR
14855@end smallexample
14856
14857Note that the array handling is not yet complete and although the type
14858is printed correctly, expression handling still assumes that all
14859arrays have a lower bound of zero and not @code{-10} as in the example
844781a1 14860above.
72019c9c
GM
14861
14862Here are some more type related Modula-2 examples:
14863
14864@smallexample
14865TYPE
14866 colour = (blue, red, yellow, green) ;
14867 t = [blue..yellow] ;
14868VAR
14869 s: t ;
14870BEGIN
14871 s := blue ;
14872@end smallexample
14873
14874@noindent
14875The @value{GDBN} interaction shows how you can query the data type
14876and value of a variable.
14877
14878@smallexample
14879(@value{GDBP}) print s
14880$1 = blue
14881(@value{GDBP}) ptype t
14882type = [blue..yellow]
14883@end smallexample
14884
14885@noindent
14886In this example a Modula-2 array is declared and its contents
14887displayed. Observe that the contents are written in the same way as
14888their @code{C} counterparts.
14889
14890@smallexample
14891VAR
14892 s: ARRAY [1..5] OF CARDINAL ;
14893BEGIN
14894 s[1] := 1 ;
14895@end smallexample
14896
14897@smallexample
14898(@value{GDBP}) print s
14899$1 = @{1, 0, 0, 0, 0@}
14900(@value{GDBP}) ptype s
14901type = ARRAY [1..5] OF CARDINAL
14902@end smallexample
14903
14904The Modula-2 language interface to @value{GDBN} also understands
14905pointer types as shown in this example:
14906
14907@smallexample
14908VAR
14909 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
14910BEGIN
14911 NEW(s) ;
14912 s^[1] := 1 ;
14913@end smallexample
14914
14915@noindent
14916and you can request that @value{GDBN} describes the type of @code{s}.
14917
14918@smallexample
14919(@value{GDBP}) ptype s
14920type = POINTER TO ARRAY [1..5] OF CARDINAL
14921@end smallexample
14922
14923@value{GDBN} handles compound types as we can see in this example.
14924Here we combine array types, record types, pointer types and subrange
14925types:
14926
14927@smallexample
14928TYPE
14929 foo = RECORD
14930 f1: CARDINAL ;
14931 f2: CHAR ;
14932 f3: myarray ;
14933 END ;
14934
14935 myarray = ARRAY myrange OF CARDINAL ;
14936 myrange = [-2..2] ;
14937VAR
14938 s: POINTER TO ARRAY myrange OF foo ;
14939@end smallexample
14940
14941@noindent
14942and you can ask @value{GDBN} to describe the type of @code{s} as shown
14943below.
14944
14945@smallexample
14946(@value{GDBP}) ptype s
14947type = POINTER TO ARRAY [-2..2] OF foo = RECORD
14948 f1 : CARDINAL;
14949 f2 : CHAR;
14950 f3 : ARRAY [-2..2] OF CARDINAL;
14951END
14952@end smallexample
14953
6d2ebf8b 14954@node M2 Defaults
79a6e687 14955@subsubsection Modula-2 Defaults
c906108c
SS
14956@cindex Modula-2 defaults
14957
14958If type and range checking are set automatically by @value{GDBN}, they
14959both default to @code{on} whenever the working language changes to
d4f3574e 14960Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
14961selected the working language.
14962
14963If you allow @value{GDBN} to set the language automatically, then entering
14964code compiled from a file whose name ends with @file{.mod} sets the
79a6e687
BW
14965working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
14966Infer the Source Language}, for further details.
c906108c 14967
6d2ebf8b 14968@node Deviations
79a6e687 14969@subsubsection Deviations from Standard Modula-2
c906108c
SS
14970@cindex Modula-2, deviations from
14971
14972A few changes have been made to make Modula-2 programs easier to debug.
14973This is done primarily via loosening its type strictness:
14974
14975@itemize @bullet
14976@item
14977Unlike in standard Modula-2, pointer constants can be formed by
14978integers. This allows you to modify pointer variables during
14979debugging. (In standard Modula-2, the actual address contained in a
14980pointer variable is hidden from you; it can only be modified
14981through direct assignment to another pointer variable or expression that
14982returned a pointer.)
14983
14984@item
14985C escape sequences can be used in strings and characters to represent
14986non-printable characters. @value{GDBN} prints out strings with these
14987escape sequences embedded. Single non-printable characters are
14988printed using the @samp{CHR(@var{nnn})} format.
14989
14990@item
14991The assignment operator (@code{:=}) returns the value of its right-hand
14992argument.
14993
14994@item
14995All built-in procedures both modify @emph{and} return their argument.
14996@end itemize
14997
6d2ebf8b 14998@node M2 Checks
79a6e687 14999@subsubsection Modula-2 Type and Range Checks
c906108c
SS
15000@cindex Modula-2 checks
15001
15002@quotation
15003@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
15004range checking.
15005@end quotation
15006@c FIXME remove warning when type/range checks added
15007
15008@value{GDBN} considers two Modula-2 variables type equivalent if:
15009
15010@itemize @bullet
15011@item
15012They are of types that have been declared equivalent via a @code{TYPE
15013@var{t1} = @var{t2}} statement
15014
15015@item
15016They have been declared on the same line. (Note: This is true of the
15017@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
15018@end itemize
15019
15020As long as type checking is enabled, any attempt to combine variables
15021whose types are not equivalent is an error.
15022
15023Range checking is done on all mathematical operations, assignment, array
15024index bounds, and all built-in functions and procedures.
15025
6d2ebf8b 15026@node M2 Scope
79a6e687 15027@subsubsection The Scope Operators @code{::} and @code{.}
c906108c 15028@cindex scope
41afff9a 15029@cindex @code{.}, Modula-2 scope operator
c906108c
SS
15030@cindex colon, doubled as scope operator
15031@ifinfo
41afff9a 15032@vindex colon-colon@r{, in Modula-2}
c906108c
SS
15033@c Info cannot handle :: but TeX can.
15034@end ifinfo
a67ec3f4 15035@ifnotinfo
41afff9a 15036@vindex ::@r{, in Modula-2}
a67ec3f4 15037@end ifnotinfo
c906108c
SS
15038
15039There are a few subtle differences between the Modula-2 scope operator
15040(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
15041similar syntax:
15042
474c8240 15043@smallexample
c906108c
SS
15044
15045@var{module} . @var{id}
15046@var{scope} :: @var{id}
474c8240 15047@end smallexample
c906108c
SS
15048
15049@noindent
15050where @var{scope} is the name of a module or a procedure,
15051@var{module} the name of a module, and @var{id} is any declared
15052identifier within your program, except another module.
15053
15054Using the @code{::} operator makes @value{GDBN} search the scope
15055specified by @var{scope} for the identifier @var{id}. If it is not
15056found in the specified scope, then @value{GDBN} searches all scopes
15057enclosing the one specified by @var{scope}.
15058
15059Using the @code{.} operator makes @value{GDBN} search the current scope for
15060the identifier specified by @var{id} that was imported from the
15061definition module specified by @var{module}. With this operator, it is
15062an error if the identifier @var{id} was not imported from definition
15063module @var{module}, or if @var{id} is not an identifier in
15064@var{module}.
15065
6d2ebf8b 15066@node GDB/M2
c906108c
SS
15067@subsubsection @value{GDBN} and Modula-2
15068
15069Some @value{GDBN} commands have little use when debugging Modula-2 programs.
15070Five subcommands of @code{set print} and @code{show print} apply
b37052ae 15071specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 15072@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 15073apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
15074analogue in Modula-2.
15075
15076The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 15077with any language, is not useful with Modula-2. Its
c906108c 15078intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 15079created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 15080address can be specified by an integral constant, the construct
d4f3574e 15081@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
15082
15083@cindex @code{#} in Modula-2
15084In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
15085interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 15086
e07c999f
PH
15087@node Ada
15088@subsection Ada
15089@cindex Ada
15090
15091The extensions made to @value{GDBN} for Ada only support
15092output from the @sc{gnu} Ada (GNAT) compiler.
15093Other Ada compilers are not currently supported, and
15094attempting to debug executables produced by them is most likely
15095to be difficult.
15096
15097
15098@cindex expressions in Ada
15099@menu
15100* Ada Mode Intro:: General remarks on the Ada syntax
15101 and semantics supported by Ada mode
15102 in @value{GDBN}.
15103* Omissions from Ada:: Restrictions on the Ada expression syntax.
15104* Additions to Ada:: Extensions of the Ada expression syntax.
15105* Stopping Before Main Program:: Debugging the program during elaboration.
58d06528 15106* Ada Exceptions:: Ada Exceptions
20924a55
JB
15107* Ada Tasks:: Listing and setting breakpoints in tasks.
15108* Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
6e1bb179
JB
15109* Ravenscar Profile:: Tasking Support when using the Ravenscar
15110 Profile
e07c999f
PH
15111* Ada Glitches:: Known peculiarities of Ada mode.
15112@end menu
15113
15114@node Ada Mode Intro
15115@subsubsection Introduction
15116@cindex Ada mode, general
15117
15118The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
15119syntax, with some extensions.
15120The philosophy behind the design of this subset is
15121
15122@itemize @bullet
15123@item
15124That @value{GDBN} should provide basic literals and access to operations for
15125arithmetic, dereferencing, field selection, indexing, and subprogram calls,
15126leaving more sophisticated computations to subprograms written into the
15127program (which therefore may be called from @value{GDBN}).
15128
15129@item
15130That type safety and strict adherence to Ada language restrictions
15131are not particularly important to the @value{GDBN} user.
15132
15133@item
15134That brevity is important to the @value{GDBN} user.
15135@end itemize
15136
f3a2dd1a
JB
15137Thus, for brevity, the debugger acts as if all names declared in
15138user-written packages are directly visible, even if they are not visible
15139according to Ada rules, thus making it unnecessary to fully qualify most
15140names with their packages, regardless of context. Where this causes
15141ambiguity, @value{GDBN} asks the user's intent.
e07c999f
PH
15142
15143The debugger will start in Ada mode if it detects an Ada main program.
15144As for other languages, it will enter Ada mode when stopped in a program that
15145was translated from an Ada source file.
15146
15147While in Ada mode, you may use `@t{--}' for comments. This is useful
15148mostly for documenting command files. The standard @value{GDBN} comment
15149(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
15150middle (to allow based literals).
15151
15152The debugger supports limited overloading. Given a subprogram call in which
15153the function symbol has multiple definitions, it will use the number of
15154actual parameters and some information about their types to attempt to narrow
15155the set of definitions. It also makes very limited use of context, preferring
15156procedures to functions in the context of the @code{call} command, and
15157functions to procedures elsewhere.
15158
15159@node Omissions from Ada
15160@subsubsection Omissions from Ada
15161@cindex Ada, omissions from
15162
15163Here are the notable omissions from the subset:
15164
15165@itemize @bullet
15166@item
15167Only a subset of the attributes are supported:
15168
15169@itemize @minus
15170@item
15171@t{'First}, @t{'Last}, and @t{'Length}
15172 on array objects (not on types and subtypes).
15173
15174@item
15175@t{'Min} and @t{'Max}.
15176
15177@item
15178@t{'Pos} and @t{'Val}.
15179
15180@item
15181@t{'Tag}.
15182
15183@item
15184@t{'Range} on array objects (not subtypes), but only as the right
15185operand of the membership (@code{in}) operator.
15186
15187@item
15188@t{'Access}, @t{'Unchecked_Access}, and
15189@t{'Unrestricted_Access} (a GNAT extension).
15190
15191@item
15192@t{'Address}.
15193@end itemize
15194
15195@item
15196The names in
15197@code{Characters.Latin_1} are not available and
15198concatenation is not implemented. Thus, escape characters in strings are
15199not currently available.
15200
15201@item
15202Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
15203equality of representations. They will generally work correctly
15204for strings and arrays whose elements have integer or enumeration types.
15205They may not work correctly for arrays whose element
15206types have user-defined equality, for arrays of real values
15207(in particular, IEEE-conformant floating point, because of negative
15208zeroes and NaNs), and for arrays whose elements contain unused bits with
15209indeterminate values.
15210
15211@item
15212The other component-by-component array operations (@code{and}, @code{or},
15213@code{xor}, @code{not}, and relational tests other than equality)
15214are not implemented.
15215
15216@item
860701dc
PH
15217@cindex array aggregates (Ada)
15218@cindex record aggregates (Ada)
15219@cindex aggregates (Ada)
15220There is limited support for array and record aggregates. They are
15221permitted only on the right sides of assignments, as in these examples:
15222
15223@smallexample
077e0a52
JB
15224(@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
15225(@value{GDBP}) set An_Array := (1, others => 0)
15226(@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
15227(@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
15228(@value{GDBP}) set A_Record := (1, "Peter", True);
15229(@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
860701dc
PH
15230@end smallexample
15231
15232Changing a
15233discriminant's value by assigning an aggregate has an
15234undefined effect if that discriminant is used within the record.
15235However, you can first modify discriminants by directly assigning to
15236them (which normally would not be allowed in Ada), and then performing an
15237aggregate assignment. For example, given a variable @code{A_Rec}
15238declared to have a type such as:
15239
15240@smallexample
15241type Rec (Len : Small_Integer := 0) is record
15242 Id : Integer;
15243 Vals : IntArray (1 .. Len);
15244end record;
15245@end smallexample
15246
15247you can assign a value with a different size of @code{Vals} with two
15248assignments:
15249
15250@smallexample
077e0a52
JB
15251(@value{GDBP}) set A_Rec.Len := 4
15252(@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
860701dc
PH
15253@end smallexample
15254
15255As this example also illustrates, @value{GDBN} is very loose about the usual
15256rules concerning aggregates. You may leave out some of the
15257components of an array or record aggregate (such as the @code{Len}
15258component in the assignment to @code{A_Rec} above); they will retain their
15259original values upon assignment. You may freely use dynamic values as
15260indices in component associations. You may even use overlapping or
15261redundant component associations, although which component values are
15262assigned in such cases is not defined.
e07c999f
PH
15263
15264@item
15265Calls to dispatching subprograms are not implemented.
15266
15267@item
15268The overloading algorithm is much more limited (i.e., less selective)
ae21e955
BW
15269than that of real Ada. It makes only limited use of the context in
15270which a subexpression appears to resolve its meaning, and it is much
15271looser in its rules for allowing type matches. As a result, some
15272function calls will be ambiguous, and the user will be asked to choose
15273the proper resolution.
e07c999f
PH
15274
15275@item
15276The @code{new} operator is not implemented.
15277
15278@item
15279Entry calls are not implemented.
15280
15281@item
15282Aside from printing, arithmetic operations on the native VAX floating-point
15283formats are not supported.
15284
15285@item
15286It is not possible to slice a packed array.
158c7665
PH
15287
15288@item
15289The names @code{True} and @code{False}, when not part of a qualified name,
15290are interpreted as if implicitly prefixed by @code{Standard}, regardless of
15291context.
15292Should your program
15293redefine these names in a package or procedure (at best a dubious practice),
15294you will have to use fully qualified names to access their new definitions.
e07c999f
PH
15295@end itemize
15296
15297@node Additions to Ada
15298@subsubsection Additions to Ada
15299@cindex Ada, deviations from
15300
15301As it does for other languages, @value{GDBN} makes certain generic
15302extensions to Ada (@pxref{Expressions}):
15303
15304@itemize @bullet
15305@item
ae21e955
BW
15306If the expression @var{E} is a variable residing in memory (typically
15307a local variable or array element) and @var{N} is a positive integer,
15308then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
15309@var{N}-1 adjacent variables following it in memory as an array. In
15310Ada, this operator is generally not necessary, since its prime use is
15311in displaying parts of an array, and slicing will usually do this in
15312Ada. However, there are occasional uses when debugging programs in
15313which certain debugging information has been optimized away.
e07c999f
PH
15314
15315@item
ae21e955
BW
15316@code{@var{B}::@var{var}} means ``the variable named @var{var} that
15317appears in function or file @var{B}.'' When @var{B} is a file name,
15318you must typically surround it in single quotes.
e07c999f
PH
15319
15320@item
15321The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
15322@var{type} that appears at address @var{addr}.''
15323
15324@item
15325A name starting with @samp{$} is a convenience variable
15326(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
15327@end itemize
15328
ae21e955
BW
15329In addition, @value{GDBN} provides a few other shortcuts and outright
15330additions specific to Ada:
e07c999f
PH
15331
15332@itemize @bullet
15333@item
15334The assignment statement is allowed as an expression, returning
15335its right-hand operand as its value. Thus, you may enter
15336
15337@smallexample
077e0a52
JB
15338(@value{GDBP}) set x := y + 3
15339(@value{GDBP}) print A(tmp := y + 1)
e07c999f
PH
15340@end smallexample
15341
15342@item
15343The semicolon is allowed as an ``operator,'' returning as its value
15344the value of its right-hand operand.
15345This allows, for example,
15346complex conditional breaks:
15347
15348@smallexample
077e0a52
JB
15349(@value{GDBP}) break f
15350(@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
e07c999f
PH
15351@end smallexample
15352
15353@item
15354Rather than use catenation and symbolic character names to introduce special
15355characters into strings, one may instead use a special bracket notation,
15356which is also used to print strings. A sequence of characters of the form
15357@samp{["@var{XX}"]} within a string or character literal denotes the
15358(single) character whose numeric encoding is @var{XX} in hexadecimal. The
15359sequence of characters @samp{["""]} also denotes a single quotation mark
15360in strings. For example,
15361@smallexample
15362 "One line.["0a"]Next line.["0a"]"
15363@end smallexample
15364@noindent
ae21e955
BW
15365contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
15366after each period.
e07c999f
PH
15367
15368@item
15369The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
15370@t{'Max} is optional (and is ignored in any case). For example, it is valid
15371to write
15372
15373@smallexample
077e0a52 15374(@value{GDBP}) print 'max(x, y)
e07c999f
PH
15375@end smallexample
15376
15377@item
15378When printing arrays, @value{GDBN} uses positional notation when the
15379array has a lower bound of 1, and uses a modified named notation otherwise.
ae21e955
BW
15380For example, a one-dimensional array of three integers with a lower bound
15381of 3 might print as
e07c999f
PH
15382
15383@smallexample
15384(3 => 10, 17, 1)
15385@end smallexample
15386
15387@noindent
15388That is, in contrast to valid Ada, only the first component has a @code{=>}
15389clause.
15390
15391@item
15392You may abbreviate attributes in expressions with any unique,
15393multi-character subsequence of
15394their names (an exact match gets preference).
15395For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
15396in place of @t{a'length}.
15397
15398@item
15399@cindex quoting Ada internal identifiers
15400Since Ada is case-insensitive, the debugger normally maps identifiers you type
15401to lower case. The GNAT compiler uses upper-case characters for
15402some of its internal identifiers, which are normally of no interest to users.
15403For the rare occasions when you actually have to look at them,
15404enclose them in angle brackets to avoid the lower-case mapping.
15405For example,
15406@smallexample
077e0a52 15407(@value{GDBP}) print <JMPBUF_SAVE>[0]
e07c999f
PH
15408@end smallexample
15409
15410@item
15411Printing an object of class-wide type or dereferencing an
15412access-to-class-wide value will display all the components of the object's
15413specific type (as indicated by its run-time tag). Likewise, component
15414selection on such a value will operate on the specific type of the
15415object.
15416
15417@end itemize
15418
15419@node Stopping Before Main Program
15420@subsubsection Stopping at the Very Beginning
15421
15422@cindex breakpointing Ada elaboration code
15423It is sometimes necessary to debug the program during elaboration, and
15424before reaching the main procedure.
15425As defined in the Ada Reference
15426Manual, the elaboration code is invoked from a procedure called
15427@code{adainit}. To run your program up to the beginning of
15428elaboration, simply use the following two commands:
15429@code{tbreak adainit} and @code{run}.
15430
58d06528
JB
15431@node Ada Exceptions
15432@subsubsection Ada Exceptions
15433
15434A command is provided to list all Ada exceptions:
15435
15436@table @code
15437@kindex info exceptions
15438@item info exceptions
15439@itemx info exceptions @var{regexp}
15440The @code{info exceptions} command allows you to list all Ada exceptions
15441defined within the program being debugged, as well as their addresses.
15442With a regular expression, @var{regexp}, as argument, only those exceptions
15443whose names match @var{regexp} are listed.
15444@end table
15445
15446Below is a small example, showing how the command can be used, first
15447without argument, and next with a regular expression passed as an
15448argument.
15449
15450@smallexample
15451(@value{GDBP}) info exceptions
15452All defined Ada exceptions:
15453constraint_error: 0x613da0
15454program_error: 0x613d20
15455storage_error: 0x613ce0
15456tasking_error: 0x613ca0
15457const.aint_global_e: 0x613b00
15458(@value{GDBP}) info exceptions const.aint
15459All Ada exceptions matching regular expression "const.aint":
15460constraint_error: 0x613da0
15461const.aint_global_e: 0x613b00
15462@end smallexample
15463
15464It is also possible to ask @value{GDBN} to stop your program's execution
15465when an exception is raised. For more details, see @ref{Set Catchpoints}.
15466
20924a55
JB
15467@node Ada Tasks
15468@subsubsection Extensions for Ada Tasks
15469@cindex Ada, tasking
15470
15471Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
15472@value{GDBN} provides the following task-related commands:
15473
15474@table @code
15475@kindex info tasks
15476@item info tasks
15477This command shows a list of current Ada tasks, as in the following example:
15478
15479
15480@smallexample
15481@iftex
15482@leftskip=0.5cm
15483@end iftex
15484(@value{GDBP}) info tasks
15485 ID TID P-ID Pri State Name
15486 1 8088000 0 15 Child Activation Wait main_task
15487 2 80a4000 1 15 Accept Statement b
15488 3 809a800 1 15 Child Activation Wait a
32cd1edc 15489* 4 80ae800 3 15 Runnable c
20924a55
JB
15490
15491@end smallexample
15492
15493@noindent
15494In this listing, the asterisk before the last task indicates it to be the
15495task currently being inspected.
15496
15497@table @asis
15498@item ID
15499Represents @value{GDBN}'s internal task number.
15500
15501@item TID
15502The Ada task ID.
15503
15504@item P-ID
15505The parent's task ID (@value{GDBN}'s internal task number).
15506
15507@item Pri
15508The base priority of the task.
15509
15510@item State
15511Current state of the task.
15512
15513@table @code
15514@item Unactivated
15515The task has been created but has not been activated. It cannot be
15516executing.
15517
20924a55
JB
15518@item Runnable
15519The task is not blocked for any reason known to Ada. (It may be waiting
15520for a mutex, though.) It is conceptually "executing" in normal mode.
15521
15522@item Terminated
15523The task is terminated, in the sense of ARM 9.3 (5). Any dependents
15524that were waiting on terminate alternatives have been awakened and have
15525terminated themselves.
15526
15527@item Child Activation Wait
15528The task is waiting for created tasks to complete activation.
15529
15530@item Accept Statement
15531The task is waiting on an accept or selective wait statement.
15532
15533@item Waiting on entry call
15534The task is waiting on an entry call.
15535
15536@item Async Select Wait
15537The task is waiting to start the abortable part of an asynchronous
15538select statement.
15539
15540@item Delay Sleep
15541The task is waiting on a select statement with only a delay
15542alternative open.
15543
15544@item Child Termination Wait
15545The task is sleeping having completed a master within itself, and is
15546waiting for the tasks dependent on that master to become terminated or
15547waiting on a terminate Phase.
15548
15549@item Wait Child in Term Alt
15550The task is sleeping waiting for tasks on terminate alternatives to
15551finish terminating.
15552
15553@item Accepting RV with @var{taskno}
15554The task is accepting a rendez-vous with the task @var{taskno}.
15555@end table
15556
15557@item Name
15558Name of the task in the program.
15559
15560@end table
15561
15562@kindex info task @var{taskno}
15563@item info task @var{taskno}
15564This command shows detailled informations on the specified task, as in
15565the following example:
15566@smallexample
15567@iftex
15568@leftskip=0.5cm
15569@end iftex
15570(@value{GDBP}) info tasks
15571 ID TID P-ID Pri State Name
15572 1 8077880 0 15 Child Activation Wait main_task
32cd1edc 15573* 2 807c468 1 15 Runnable task_1
20924a55
JB
15574(@value{GDBP}) info task 2
15575Ada Task: 0x807c468
15576Name: task_1
15577Thread: 0x807f378
15578Parent: 1 (main_task)
15579Base Priority: 15
15580State: Runnable
15581@end smallexample
15582
15583@item task
15584@kindex task@r{ (Ada)}
15585@cindex current Ada task ID
15586This command prints the ID of the current task.
15587
15588@smallexample
15589@iftex
15590@leftskip=0.5cm
15591@end iftex
15592(@value{GDBP}) info tasks
15593 ID TID P-ID Pri State Name
15594 1 8077870 0 15 Child Activation Wait main_task
32cd1edc 15595* 2 807c458 1 15 Runnable t
20924a55
JB
15596(@value{GDBP}) task
15597[Current task is 2]
15598@end smallexample
15599
15600@item task @var{taskno}
15601@cindex Ada task switching
15602This command is like the @code{thread @var{threadno}}
15603command (@pxref{Threads}). It switches the context of debugging
15604from the current task to the given task.
15605
15606@smallexample
15607@iftex
15608@leftskip=0.5cm
15609@end iftex
15610(@value{GDBP}) info tasks
15611 ID TID P-ID Pri State Name
15612 1 8077870 0 15 Child Activation Wait main_task
32cd1edc 15613* 2 807c458 1 15 Runnable t
20924a55
JB
15614(@value{GDBP}) task 1
15615[Switching to task 1]
15616#0 0x8067726 in pthread_cond_wait ()
15617(@value{GDBP}) bt
15618#0 0x8067726 in pthread_cond_wait ()
15619#1 0x8056714 in system.os_interface.pthread_cond_wait ()
15620#2 0x805cb63 in system.task_primitives.operations.sleep ()
15621#3 0x806153e in system.tasking.stages.activate_tasks ()
15622#4 0x804aacc in un () at un.adb:5
15623@end smallexample
15624
45ac276d
JB
15625@item break @var{linespec} task @var{taskno}
15626@itemx break @var{linespec} task @var{taskno} if @dots{}
15627@cindex breakpoints and tasks, in Ada
15628@cindex task breakpoints, in Ada
15629@kindex break @dots{} task @var{taskno}@r{ (Ada)}
15630These commands are like the @code{break @dots{} thread @dots{}}
15631command (@pxref{Thread Stops}).
15632@var{linespec} specifies source lines, as described
15633in @ref{Specify Location}.
15634
15635Use the qualifier @samp{task @var{taskno}} with a breakpoint command
15636to specify that you only want @value{GDBN} to stop the program when a
15637particular Ada task reaches this breakpoint. @var{taskno} is one of the
15638numeric task identifiers assigned by @value{GDBN}, shown in the first
15639column of the @samp{info tasks} display.
15640
15641If you do not specify @samp{task @var{taskno}} when you set a
15642breakpoint, the breakpoint applies to @emph{all} tasks of your
15643program.
15644
15645You can use the @code{task} qualifier on conditional breakpoints as
15646well; in this case, place @samp{task @var{taskno}} before the
15647breakpoint condition (before the @code{if}).
15648
15649For example,
15650
15651@smallexample
15652@iftex
15653@leftskip=0.5cm
15654@end iftex
15655(@value{GDBP}) info tasks
15656 ID TID P-ID Pri State Name
15657 1 140022020 0 15 Child Activation Wait main_task
15658 2 140045060 1 15 Accept/Select Wait t2
15659 3 140044840 1 15 Runnable t1
15660* 4 140056040 1 15 Runnable t3
15661(@value{GDBP}) b 15 task 2
15662Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
15663(@value{GDBP}) cont
15664Continuing.
15665task # 1 running
15666task # 2 running
15667
15668Breakpoint 5, test_task_debug () at test_task_debug.adb:15
1566915 flush;
15670(@value{GDBP}) info tasks
15671 ID TID P-ID Pri State Name
15672 1 140022020 0 15 Child Activation Wait main_task
15673* 2 140045060 1 15 Runnable t2
15674 3 140044840 1 15 Runnable t1
15675 4 140056040 1 15 Delay Sleep t3
15676@end smallexample
20924a55
JB
15677@end table
15678
15679@node Ada Tasks and Core Files
15680@subsubsection Tasking Support when Debugging Core Files
15681@cindex Ada tasking and core file debugging
15682
15683When inspecting a core file, as opposed to debugging a live program,
15684tasking support may be limited or even unavailable, depending on
15685the platform being used.
15686For instance, on x86-linux, the list of tasks is available, but task
15687switching is not supported. On Tru64, however, task switching will work
15688as usual.
15689
15690On certain platforms, including Tru64, the debugger needs to perform some
15691memory writes in order to provide Ada tasking support. When inspecting
15692a core file, this means that the core file must be opened with read-write
15693privileges, using the command @samp{"set write on"} (@pxref{Patching}).
15694Under these circumstances, you should make a backup copy of the core
15695file before inspecting it with @value{GDBN}.
15696
6e1bb179
JB
15697@node Ravenscar Profile
15698@subsubsection Tasking Support when using the Ravenscar Profile
15699@cindex Ravenscar Profile
15700
15701The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
15702specifically designed for systems with safety-critical real-time
15703requirements.
15704
15705@table @code
15706@kindex set ravenscar task-switching on
15707@cindex task switching with program using Ravenscar Profile
15708@item set ravenscar task-switching on
15709Allows task switching when debugging a program that uses the Ravenscar
15710Profile. This is the default.
15711
15712@kindex set ravenscar task-switching off
15713@item set ravenscar task-switching off
15714Turn off task switching when debugging a program that uses the Ravenscar
15715Profile. This is mostly intended to disable the code that adds support
15716for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
15717the Ravenscar runtime is preventing @value{GDBN} from working properly.
15718To be effective, this command should be run before the program is started.
15719
15720@kindex show ravenscar task-switching
15721@item show ravenscar task-switching
15722Show whether it is possible to switch from task to task in a program
15723using the Ravenscar Profile.
15724
15725@end table
15726
e07c999f
PH
15727@node Ada Glitches
15728@subsubsection Known Peculiarities of Ada Mode
15729@cindex Ada, problems
15730
15731Besides the omissions listed previously (@pxref{Omissions from Ada}),
15732we know of several problems with and limitations of Ada mode in
15733@value{GDBN},
15734some of which will be fixed with planned future releases of the debugger
15735and the GNU Ada compiler.
15736
15737@itemize @bullet
e07c999f
PH
15738@item
15739Static constants that the compiler chooses not to materialize as objects in
15740storage are invisible to the debugger.
15741
15742@item
15743Named parameter associations in function argument lists are ignored (the
15744argument lists are treated as positional).
15745
15746@item
15747Many useful library packages are currently invisible to the debugger.
15748
15749@item
15750Fixed-point arithmetic, conversions, input, and output is carried out using
15751floating-point arithmetic, and may give results that only approximate those on
15752the host machine.
15753
e07c999f
PH
15754@item
15755The GNAT compiler never generates the prefix @code{Standard} for any of
15756the standard symbols defined by the Ada language. @value{GDBN} knows about
15757this: it will strip the prefix from names when you use it, and will never
15758look for a name you have so qualified among local symbols, nor match against
15759symbols in other packages or subprograms. If you have
15760defined entities anywhere in your program other than parameters and
15761local variables whose simple names match names in @code{Standard},
15762GNAT's lack of qualification here can cause confusion. When this happens,
15763you can usually resolve the confusion
15764by qualifying the problematic names with package
15765@code{Standard} explicitly.
15766@end itemize
15767
95433b34
JB
15768Older versions of the compiler sometimes generate erroneous debugging
15769information, resulting in the debugger incorrectly printing the value
15770of affected entities. In some cases, the debugger is able to work
15771around an issue automatically. In other cases, the debugger is able
15772to work around the issue, but the work-around has to be specifically
15773enabled.
15774
15775@kindex set ada trust-PAD-over-XVS
15776@kindex show ada trust-PAD-over-XVS
15777@table @code
15778
15779@item set ada trust-PAD-over-XVS on
15780Configure GDB to strictly follow the GNAT encoding when computing the
15781value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
15782types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
15783a complete description of the encoding used by the GNAT compiler).
15784This is the default.
15785
15786@item set ada trust-PAD-over-XVS off
15787This is related to the encoding using by the GNAT compiler. If @value{GDBN}
15788sometimes prints the wrong value for certain entities, changing @code{ada
15789trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
15790the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
15791@code{off}, but this incurs a slight performance penalty, so it is
15792recommended to leave this setting to @code{on} unless necessary.
15793
15794@end table
15795
c6044dd1
JB
15796@cindex GNAT descriptive types
15797@cindex GNAT encoding
15798Internally, the debugger also relies on the compiler following a number
15799of conventions known as the @samp{GNAT Encoding}, all documented in
15800@file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
15801how the debugging information should be generated for certain types.
15802In particular, this convention makes use of @dfn{descriptive types},
15803which are artificial types generated purely to help the debugger.
15804
15805These encodings were defined at a time when the debugging information
15806format used was not powerful enough to describe some of the more complex
15807types available in Ada. Since DWARF allows us to express nearly all
15808Ada features, the long-term goal is to slowly replace these descriptive
15809types by their pure DWARF equivalent. To facilitate that transition,
15810a new maintenance option is available to force the debugger to ignore
15811those descriptive types. It allows the user to quickly evaluate how
15812well @value{GDBN} works without them.
15813
15814@table @code
15815
15816@kindex maint ada set ignore-descriptive-types
15817@item maintenance ada set ignore-descriptive-types [on|off]
15818Control whether the debugger should ignore descriptive types.
15819The default is not to ignore descriptives types (@code{off}).
15820
15821@kindex maint ada show ignore-descriptive-types
15822@item maintenance ada show ignore-descriptive-types
15823Show if descriptive types are ignored by @value{GDBN}.
15824
15825@end table
15826
79a6e687
BW
15827@node Unsupported Languages
15828@section Unsupported Languages
4e562065
JB
15829
15830@cindex unsupported languages
15831@cindex minimal language
15832In addition to the other fully-supported programming languages,
15833@value{GDBN} also provides a pseudo-language, called @code{minimal}.
15834It does not represent a real programming language, but provides a set
15835of capabilities close to what the C or assembly languages provide.
15836This should allow most simple operations to be performed while debugging
15837an application that uses a language currently not supported by @value{GDBN}.
15838
15839If the language is set to @code{auto}, @value{GDBN} will automatically
15840select this language if the current frame corresponds to an unsupported
15841language.
15842
6d2ebf8b 15843@node Symbols
c906108c
SS
15844@chapter Examining the Symbol Table
15845
d4f3574e 15846The commands described in this chapter allow you to inquire about the
c906108c
SS
15847symbols (names of variables, functions and types) defined in your
15848program. This information is inherent in the text of your program and
15849does not change as your program executes. @value{GDBN} finds it in your
15850program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
15851(@pxref{File Options, ,Choosing Files}), or by one of the
15852file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
15853
15854@cindex symbol names
15855@cindex names of symbols
15856@cindex quoting names
15857Occasionally, you may need to refer to symbols that contain unusual
15858characters, which @value{GDBN} ordinarily treats as word delimiters. The
15859most frequent case is in referring to static variables in other
79a6e687 15860source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
15861are recorded in object files as debugging symbols, but @value{GDBN} would
15862ordinarily parse a typical file name, like @file{foo.c}, as the three words
15863@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
15864@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
15865
474c8240 15866@smallexample
c906108c 15867p 'foo.c'::x
474c8240 15868@end smallexample
c906108c
SS
15869
15870@noindent
15871looks up the value of @code{x} in the scope of the file @file{foo.c}.
15872
15873@table @code
a8f24a35
EZ
15874@cindex case-insensitive symbol names
15875@cindex case sensitivity in symbol names
15876@kindex set case-sensitive
15877@item set case-sensitive on
15878@itemx set case-sensitive off
15879@itemx set case-sensitive auto
15880Normally, when @value{GDBN} looks up symbols, it matches their names
15881with case sensitivity determined by the current source language.
15882Occasionally, you may wish to control that. The command @code{set
15883case-sensitive} lets you do that by specifying @code{on} for
15884case-sensitive matches or @code{off} for case-insensitive ones. If
15885you specify @code{auto}, case sensitivity is reset to the default
15886suitable for the source language. The default is case-sensitive
15887matches for all languages except for Fortran, for which the default is
15888case-insensitive matches.
15889
9c16f35a
EZ
15890@kindex show case-sensitive
15891@item show case-sensitive
a8f24a35
EZ
15892This command shows the current setting of case sensitivity for symbols
15893lookups.
15894
53342f27
TT
15895@kindex set print type methods
15896@item set print type methods
15897@itemx set print type methods on
15898@itemx set print type methods off
15899Normally, when @value{GDBN} prints a class, it displays any methods
15900declared in that class. You can control this behavior either by
15901passing the appropriate flag to @code{ptype}, or using @command{set
15902print type methods}. Specifying @code{on} will cause @value{GDBN} to
15903display the methods; this is the default. Specifying @code{off} will
15904cause @value{GDBN} to omit the methods.
15905
15906@kindex show print type methods
15907@item show print type methods
15908This command shows the current setting of method display when printing
15909classes.
15910
15911@kindex set print type typedefs
15912@item set print type typedefs
15913@itemx set print type typedefs on
15914@itemx set print type typedefs off
15915
15916Normally, when @value{GDBN} prints a class, it displays any typedefs
15917defined in that class. You can control this behavior either by
15918passing the appropriate flag to @code{ptype}, or using @command{set
15919print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
15920display the typedef definitions; this is the default. Specifying
15921@code{off} will cause @value{GDBN} to omit the typedef definitions.
15922Note that this controls whether the typedef definition itself is
15923printed, not whether typedef names are substituted when printing other
15924types.
15925
15926@kindex show print type typedefs
15927@item show print type typedefs
15928This command shows the current setting of typedef display when
15929printing classes.
15930
c906108c 15931@kindex info address
b37052ae 15932@cindex address of a symbol
c906108c
SS
15933@item info address @var{symbol}
15934Describe where the data for @var{symbol} is stored. For a register
15935variable, this says which register it is kept in. For a non-register
15936local variable, this prints the stack-frame offset at which the variable
15937is always stored.
15938
15939Note the contrast with @samp{print &@var{symbol}}, which does not work
15940at all for a register variable, and for a stack local variable prints
15941the exact address of the current instantiation of the variable.
15942
3d67e040 15943@kindex info symbol
b37052ae 15944@cindex symbol from address
9c16f35a 15945@cindex closest symbol and offset for an address
3d67e040
EZ
15946@item info symbol @var{addr}
15947Print the name of a symbol which is stored at the address @var{addr}.
15948If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
15949nearest symbol and an offset from it:
15950
474c8240 15951@smallexample
3d67e040
EZ
15952(@value{GDBP}) info symbol 0x54320
15953_initialize_vx + 396 in section .text
474c8240 15954@end smallexample
3d67e040
EZ
15955
15956@noindent
15957This is the opposite of the @code{info address} command. You can use
15958it to find out the name of a variable or a function given its address.
15959
c14c28ba
PP
15960For dynamically linked executables, the name of executable or shared
15961library containing the symbol is also printed:
15962
15963@smallexample
15964(@value{GDBP}) info symbol 0x400225
15965_start + 5 in section .text of /tmp/a.out
15966(@value{GDBP}) info symbol 0x2aaaac2811cf
15967__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
15968@end smallexample
15969
c906108c 15970@kindex whatis
53342f27 15971@item whatis[/@var{flags}] [@var{arg}]
177bc839
JK
15972Print the data type of @var{arg}, which can be either an expression
15973or a name of a data type. With no argument, print the data type of
15974@code{$}, the last value in the value history.
15975
15976If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
15977is not actually evaluated, and any side-effecting operations (such as
15978assignments or function calls) inside it do not take place.
15979
15980If @var{arg} is a variable or an expression, @code{whatis} prints its
15981literal type as it is used in the source code. If the type was
15982defined using a @code{typedef}, @code{whatis} will @emph{not} print
15983the data type underlying the @code{typedef}. If the type of the
15984variable or the expression is a compound data type, such as
15985@code{struct} or @code{class}, @code{whatis} never prints their
15986fields or methods. It just prints the @code{struct}/@code{class}
15987name (a.k.a.@: its @dfn{tag}). If you want to see the members of
15988such a compound data type, use @code{ptype}.
15989
15990If @var{arg} is a type name that was defined using @code{typedef},
15991@code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
15992Unrolling means that @code{whatis} will show the underlying type used
15993in the @code{typedef} declaration of @var{arg}. However, if that
15994underlying type is also a @code{typedef}, @code{whatis} will not
15995unroll it.
15996
15997For C code, the type names may also have the form @samp{class
15998@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
15999@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 16000
53342f27
TT
16001@var{flags} can be used to modify how the type is displayed.
16002Available flags are:
16003
16004@table @code
16005@item r
16006Display in ``raw'' form. Normally, @value{GDBN} substitutes template
16007parameters and typedefs defined in a class when printing the class'
16008members. The @code{/r} flag disables this.
16009
16010@item m
16011Do not print methods defined in the class.
16012
16013@item M
16014Print methods defined in the class. This is the default, but the flag
16015exists in case you change the default with @command{set print type methods}.
16016
16017@item t
16018Do not print typedefs defined in the class. Note that this controls
16019whether the typedef definition itself is printed, not whether typedef
16020names are substituted when printing other types.
16021
16022@item T
16023Print typedefs defined in the class. This is the default, but the flag
16024exists in case you change the default with @command{set print type typedefs}.
16025@end table
16026
c906108c 16027@kindex ptype
53342f27 16028@item ptype[/@var{flags}] [@var{arg}]
62f3a2ba
FF
16029@code{ptype} accepts the same arguments as @code{whatis}, but prints a
16030detailed description of the type, instead of just the name of the type.
16031@xref{Expressions, ,Expressions}.
c906108c 16032
177bc839
JK
16033Contrary to @code{whatis}, @code{ptype} always unrolls any
16034@code{typedef}s in its argument declaration, whether the argument is
16035a variable, expression, or a data type. This means that @code{ptype}
16036of a variable or an expression will not print literally its type as
16037present in the source code---use @code{whatis} for that. @code{typedef}s at
16038the pointer or reference targets are also unrolled. Only @code{typedef}s of
16039fields, methods and inner @code{class typedef}s of @code{struct}s,
16040@code{class}es and @code{union}s are not unrolled even with @code{ptype}.
16041
c906108c
SS
16042For example, for this variable declaration:
16043
474c8240 16044@smallexample
177bc839
JK
16045typedef double real_t;
16046struct complex @{ real_t real; double imag; @};
16047typedef struct complex complex_t;
16048complex_t var;
16049real_t *real_pointer_var;
474c8240 16050@end smallexample
c906108c
SS
16051
16052@noindent
16053the two commands give this output:
16054
474c8240 16055@smallexample
c906108c 16056@group
177bc839
JK
16057(@value{GDBP}) whatis var
16058type = complex_t
16059(@value{GDBP}) ptype var
16060type = struct complex @{
16061 real_t real;
16062 double imag;
16063@}
16064(@value{GDBP}) whatis complex_t
16065type = struct complex
16066(@value{GDBP}) whatis struct complex
c906108c 16067type = struct complex
177bc839 16068(@value{GDBP}) ptype struct complex
c906108c 16069type = struct complex @{
177bc839 16070 real_t real;
c906108c
SS
16071 double imag;
16072@}
177bc839
JK
16073(@value{GDBP}) whatis real_pointer_var
16074type = real_t *
16075(@value{GDBP}) ptype real_pointer_var
16076type = double *
c906108c 16077@end group
474c8240 16078@end smallexample
c906108c
SS
16079
16080@noindent
16081As with @code{whatis}, using @code{ptype} without an argument refers to
16082the type of @code{$}, the last value in the value history.
16083
ab1adacd
EZ
16084@cindex incomplete type
16085Sometimes, programs use opaque data types or incomplete specifications
16086of complex data structure. If the debug information included in the
16087program does not allow @value{GDBN} to display a full declaration of
16088the data type, it will say @samp{<incomplete type>}. For example,
16089given these declarations:
16090
16091@smallexample
16092 struct foo;
16093 struct foo *fooptr;
16094@end smallexample
16095
16096@noindent
16097but no definition for @code{struct foo} itself, @value{GDBN} will say:
16098
16099@smallexample
ddb50cd7 16100 (@value{GDBP}) ptype foo
ab1adacd
EZ
16101 $1 = <incomplete type>
16102@end smallexample
16103
16104@noindent
16105``Incomplete type'' is C terminology for data types that are not
16106completely specified.
16107
c906108c
SS
16108@kindex info types
16109@item info types @var{regexp}
16110@itemx info types
09d4efe1
EZ
16111Print a brief description of all types whose names match the regular
16112expression @var{regexp} (or all types in your program, if you supply
16113no argument). Each complete typename is matched as though it were a
16114complete line; thus, @samp{i type value} gives information on all
16115types in your program whose names include the string @code{value}, but
16116@samp{i type ^value$} gives information only on types whose complete
16117name is @code{value}.
c906108c
SS
16118
16119This command differs from @code{ptype} in two ways: first, like
16120@code{whatis}, it does not print a detailed description; second, it
16121lists all source files where a type is defined.
16122
18a9fc12
TT
16123@kindex info type-printers
16124@item info type-printers
16125Versions of @value{GDBN} that ship with Python scripting enabled may
16126have ``type printers'' available. When using @command{ptype} or
16127@command{whatis}, these printers are consulted when the name of a type
16128is needed. @xref{Type Printing API}, for more information on writing
16129type printers.
16130
16131@code{info type-printers} displays all the available type printers.
16132
16133@kindex enable type-printer
16134@kindex disable type-printer
16135@item enable type-printer @var{name}@dots{}
16136@item disable type-printer @var{name}@dots{}
16137These commands can be used to enable or disable type printers.
16138
b37052ae
EZ
16139@kindex info scope
16140@cindex local variables
09d4efe1 16141@item info scope @var{location}
b37052ae 16142List all the variables local to a particular scope. This command
09d4efe1
EZ
16143accepts a @var{location} argument---a function name, a source line, or
16144an address preceded by a @samp{*}, and prints all the variables local
2a25a5ba
EZ
16145to the scope defined by that location. (@xref{Specify Location}, for
16146details about supported forms of @var{location}.) For example:
b37052ae
EZ
16147
16148@smallexample
16149(@value{GDBP}) @b{info scope command_line_handler}
16150Scope for command_line_handler:
16151Symbol rl is an argument at stack/frame offset 8, length 4.
16152Symbol linebuffer is in static storage at address 0x150a18, length 4.
16153Symbol linelength is in static storage at address 0x150a1c, length 4.
16154Symbol p is a local variable in register $esi, length 4.
16155Symbol p1 is a local variable in register $ebx, length 4.
16156Symbol nline is a local variable in register $edx, length 4.
16157Symbol repeat is a local variable at frame offset -8, length 4.
16158@end smallexample
16159
f5c37c66
EZ
16160@noindent
16161This command is especially useful for determining what data to collect
16162during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
16163collect}.
16164
c906108c
SS
16165@kindex info source
16166@item info source
919d772c
JB
16167Show information about the current source file---that is, the source file for
16168the function containing the current point of execution:
16169@itemize @bullet
16170@item
16171the name of the source file, and the directory containing it,
16172@item
16173the directory it was compiled in,
16174@item
16175its length, in lines,
16176@item
16177which programming language it is written in,
16178@item
16179whether the executable includes debugging information for that file, and
16180if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
16181@item
16182whether the debugging information includes information about
16183preprocessor macros.
16184@end itemize
16185
c906108c
SS
16186
16187@kindex info sources
16188@item info sources
16189Print the names of all source files in your program for which there is
16190debugging information, organized into two lists: files whose symbols
16191have already been read, and files whose symbols will be read when needed.
16192
16193@kindex info functions
16194@item info functions
16195Print the names and data types of all defined functions.
16196
16197@item info functions @var{regexp}
16198Print the names and data types of all defined functions
16199whose names contain a match for regular expression @var{regexp}.
16200Thus, @samp{info fun step} finds all functions whose names
16201include @code{step}; @samp{info fun ^step} finds those whose names
b383017d 16202start with @code{step}. If a function name contains characters
c1468174 16203that conflict with the regular expression language (e.g.@:
1c5dfdad 16204@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
16205
16206@kindex info variables
16207@item info variables
0fe7935b 16208Print the names and data types of all variables that are defined
6ca652b0 16209outside of functions (i.e.@: excluding local variables).
c906108c
SS
16210
16211@item info variables @var{regexp}
16212Print the names and data types of all variables (except for local
16213variables) whose names contain a match for regular expression
16214@var{regexp}.
16215
b37303ee 16216@kindex info classes
721c2651 16217@cindex Objective-C, classes and selectors
b37303ee
AF
16218@item info classes
16219@itemx info classes @var{regexp}
16220Display all Objective-C classes in your program, or
16221(with the @var{regexp} argument) all those matching a particular regular
16222expression.
16223
16224@kindex info selectors
16225@item info selectors
16226@itemx info selectors @var{regexp}
16227Display all Objective-C selectors in your program, or
16228(with the @var{regexp} argument) all those matching a particular regular
16229expression.
16230
c906108c
SS
16231@ignore
16232This was never implemented.
16233@kindex info methods
16234@item info methods
16235@itemx info methods @var{regexp}
16236The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
16237methods within C@t{++} program, or (with the @var{regexp} argument) a
16238specific set of methods found in the various C@t{++} classes. Many
16239C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
16240from the @code{ptype} command can be overwhelming and hard to use. The
16241@code{info-methods} command filters the methods, printing only those
16242which match the regular-expression @var{regexp}.
16243@end ignore
16244
9c16f35a 16245@cindex opaque data types
c906108c
SS
16246@kindex set opaque-type-resolution
16247@item set opaque-type-resolution on
16248Tell @value{GDBN} to resolve opaque types. An opaque type is a type
16249declared as a pointer to a @code{struct}, @code{class}, or
16250@code{union}---for example, @code{struct MyType *}---that is used in one
16251source file although the full declaration of @code{struct MyType} is in
16252another source file. The default is on.
16253
16254A change in the setting of this subcommand will not take effect until
16255the next time symbols for a file are loaded.
16256
16257@item set opaque-type-resolution off
16258Tell @value{GDBN} not to resolve opaque types. In this case, the type
16259is printed as follows:
16260@smallexample
16261@{<no data fields>@}
16262@end smallexample
16263
16264@kindex show opaque-type-resolution
16265@item show opaque-type-resolution
16266Show whether opaque types are resolved or not.
c906108c 16267
770e7fc7
DE
16268@kindex set print symbol-loading
16269@cindex print messages when symbols are loaded
16270@item set print symbol-loading
16271@itemx set print symbol-loading full
16272@itemx set print symbol-loading brief
16273@itemx set print symbol-loading off
16274The @code{set print symbol-loading} command allows you to control the
16275printing of messages when @value{GDBN} loads symbol information.
16276By default a message is printed for the executable and one for each
16277shared library, and normally this is what you want. However, when
16278debugging apps with large numbers of shared libraries these messages
16279can be annoying.
16280When set to @code{brief} a message is printed for each executable,
16281and when @value{GDBN} loads a collection of shared libraries at once
16282it will only print one message regardless of the number of shared
16283libraries. When set to @code{off} no messages are printed.
16284
16285@kindex show print symbol-loading
16286@item show print symbol-loading
16287Show whether messages will be printed when a @value{GDBN} command
16288entered from the keyboard causes symbol information to be loaded.
16289
c906108c
SS
16290@kindex maint print symbols
16291@cindex symbol dump
16292@kindex maint print psymbols
16293@cindex partial symbol dump
7c57fa1e
YQ
16294@kindex maint print msymbols
16295@cindex minimal symbol dump
c906108c
SS
16296@item maint print symbols @var{filename}
16297@itemx maint print psymbols @var{filename}
16298@itemx maint print msymbols @var{filename}
16299Write a dump of debugging symbol data into the file @var{filename}.
16300These commands are used to debug the @value{GDBN} symbol-reading code. Only
16301symbols with debugging data are included. If you use @samp{maint print
16302symbols}, @value{GDBN} includes all the symbols for which it has already
16303collected full details: that is, @var{filename} reflects symbols for
16304only those files whose symbols @value{GDBN} has read. You can use the
16305command @code{info sources} to find out which files these are. If you
16306use @samp{maint print psymbols} instead, the dump shows information about
16307symbols that @value{GDBN} only knows partially---that is, symbols defined in
16308files that @value{GDBN} has skimmed, but not yet read completely. Finally,
16309@samp{maint print msymbols} dumps just the minimal symbol information
16310required for each object file from which @value{GDBN} has read some symbols.
79a6e687 16311@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 16312@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 16313
5e7b2f39
JB
16314@kindex maint info symtabs
16315@kindex maint info psymtabs
44ea7b70
JB
16316@cindex listing @value{GDBN}'s internal symbol tables
16317@cindex symbol tables, listing @value{GDBN}'s internal
16318@cindex full symbol tables, listing @value{GDBN}'s internal
16319@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
16320@item maint info symtabs @r{[} @var{regexp} @r{]}
16321@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
16322
16323List the @code{struct symtab} or @code{struct partial_symtab}
16324structures whose names match @var{regexp}. If @var{regexp} is not
16325given, list them all. The output includes expressions which you can
16326copy into a @value{GDBN} debugging this one to examine a particular
16327structure in more detail. For example:
16328
16329@smallexample
5e7b2f39 16330(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
16331@{ objfile /home/gnu/build/gdb/gdb
16332 ((struct objfile *) 0x82e69d0)
b383017d 16333 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
16334 ((struct partial_symtab *) 0x8474b10)
16335 readin no
16336 fullname (null)
16337 text addresses 0x814d3c8 -- 0x8158074
16338 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
16339 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
16340 dependencies (none)
16341 @}
16342@}
5e7b2f39 16343(@value{GDBP}) maint info symtabs
44ea7b70
JB
16344(@value{GDBP})
16345@end smallexample
16346@noindent
16347We see that there is one partial symbol table whose filename contains
16348the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
16349and we see that @value{GDBN} has not read in any symtabs yet at all.
16350If we set a breakpoint on a function, that will cause @value{GDBN} to
16351read the symtab for the compilation unit containing that function:
16352
16353@smallexample
16354(@value{GDBP}) break dwarf2_psymtab_to_symtab
16355Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
16356line 1574.
5e7b2f39 16357(@value{GDBP}) maint info symtabs
b383017d 16358@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 16359 ((struct objfile *) 0x82e69d0)
b383017d 16360 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
16361 ((struct symtab *) 0x86c1f38)
16362 dirname (null)
16363 fullname (null)
16364 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 16365 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
16366 debugformat DWARF 2
16367 @}
16368@}
b383017d 16369(@value{GDBP})
44ea7b70 16370@end smallexample
c906108c
SS
16371@end table
16372
44ea7b70 16373
6d2ebf8b 16374@node Altering
c906108c
SS
16375@chapter Altering Execution
16376
16377Once you think you have found an error in your program, you might want to
16378find out for certain whether correcting the apparent error would lead to
16379correct results in the rest of the run. You can find the answer by
16380experiment, using the @value{GDBN} features for altering execution of the
16381program.
16382
16383For example, you can store new values into variables or memory
7a292a7a
SS
16384locations, give your program a signal, restart it at a different
16385address, or even return prematurely from a function.
c906108c
SS
16386
16387@menu
16388* Assignment:: Assignment to variables
16389* Jumping:: Continuing at a different address
c906108c 16390* Signaling:: Giving your program a signal
c906108c
SS
16391* Returning:: Returning from a function
16392* Calling:: Calling your program's functions
16393* Patching:: Patching your program
16394@end menu
16395
6d2ebf8b 16396@node Assignment
79a6e687 16397@section Assignment to Variables
c906108c
SS
16398
16399@cindex assignment
16400@cindex setting variables
16401To alter the value of a variable, evaluate an assignment expression.
16402@xref{Expressions, ,Expressions}. For example,
16403
474c8240 16404@smallexample
c906108c 16405print x=4
474c8240 16406@end smallexample
c906108c
SS
16407
16408@noindent
16409stores the value 4 into the variable @code{x}, and then prints the
5d161b24 16410value of the assignment expression (which is 4).
c906108c
SS
16411@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
16412information on operators in supported languages.
c906108c
SS
16413
16414@kindex set variable
16415@cindex variables, setting
16416If you are not interested in seeing the value of the assignment, use the
16417@code{set} command instead of the @code{print} command. @code{set} is
16418really the same as @code{print} except that the expression's value is
16419not printed and is not put in the value history (@pxref{Value History,
79a6e687 16420,Value History}). The expression is evaluated only for its effects.
c906108c 16421
c906108c
SS
16422If the beginning of the argument string of the @code{set} command
16423appears identical to a @code{set} subcommand, use the @code{set
16424variable} command instead of just @code{set}. This command is identical
16425to @code{set} except for its lack of subcommands. For example, if your
16426program has a variable @code{width}, you get an error if you try to set
16427a new value with just @samp{set width=13}, because @value{GDBN} has the
16428command @code{set width}:
16429
474c8240 16430@smallexample
c906108c
SS
16431(@value{GDBP}) whatis width
16432type = double
16433(@value{GDBP}) p width
16434$4 = 13
16435(@value{GDBP}) set width=47
16436Invalid syntax in expression.
474c8240 16437@end smallexample
c906108c
SS
16438
16439@noindent
16440The invalid expression, of course, is @samp{=47}. In
16441order to actually set the program's variable @code{width}, use
16442
474c8240 16443@smallexample
c906108c 16444(@value{GDBP}) set var width=47
474c8240 16445@end smallexample
53a5351d 16446
c906108c
SS
16447Because the @code{set} command has many subcommands that can conflict
16448with the names of program variables, it is a good idea to use the
16449@code{set variable} command instead of just @code{set}. For example, if
16450your program has a variable @code{g}, you run into problems if you try
16451to set a new value with just @samp{set g=4}, because @value{GDBN} has
16452the command @code{set gnutarget}, abbreviated @code{set g}:
16453
474c8240 16454@smallexample
c906108c
SS
16455@group
16456(@value{GDBP}) whatis g
16457type = double
16458(@value{GDBP}) p g
16459$1 = 1
16460(@value{GDBP}) set g=4
2df3850c 16461(@value{GDBP}) p g
c906108c
SS
16462$2 = 1
16463(@value{GDBP}) r
16464The program being debugged has been started already.
16465Start it from the beginning? (y or n) y
16466Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
16467"/home/smith/cc_progs/a.out": can't open to read symbols:
16468 Invalid bfd target.
c906108c
SS
16469(@value{GDBP}) show g
16470The current BFD target is "=4".
16471@end group
474c8240 16472@end smallexample
c906108c
SS
16473
16474@noindent
16475The program variable @code{g} did not change, and you silently set the
16476@code{gnutarget} to an invalid value. In order to set the variable
16477@code{g}, use
16478
474c8240 16479@smallexample
c906108c 16480(@value{GDBP}) set var g=4
474c8240 16481@end smallexample
c906108c
SS
16482
16483@value{GDBN} allows more implicit conversions in assignments than C; you can
16484freely store an integer value into a pointer variable or vice versa,
16485and you can convert any structure to any other structure that is the
16486same length or shorter.
16487@comment FIXME: how do structs align/pad in these conversions?
16488@comment /doc@cygnus.com 18dec1990
16489
16490To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
16491construct to generate a value of specified type at a specified address
16492(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
16493to memory location @code{0x83040} as an integer (which implies a certain size
16494and representation in memory), and
16495
474c8240 16496@smallexample
c906108c 16497set @{int@}0x83040 = 4
474c8240 16498@end smallexample
c906108c
SS
16499
16500@noindent
16501stores the value 4 into that memory location.
16502
6d2ebf8b 16503@node Jumping
79a6e687 16504@section Continuing at a Different Address
c906108c
SS
16505
16506Ordinarily, when you continue your program, you do so at the place where
16507it stopped, with the @code{continue} command. You can instead continue at
16508an address of your own choosing, with the following commands:
16509
16510@table @code
16511@kindex jump
c1d780c2 16512@kindex j @r{(@code{jump})}
c906108c 16513@item jump @var{linespec}
c1d780c2 16514@itemx j @var{linespec}
2a25a5ba 16515@itemx jump @var{location}
c1d780c2 16516@itemx j @var{location}
2a25a5ba
EZ
16517Resume execution at line @var{linespec} or at address given by
16518@var{location}. Execution stops again immediately if there is a
16519breakpoint there. @xref{Specify Location}, for a description of the
16520different forms of @var{linespec} and @var{location}. It is common
16521practice to use the @code{tbreak} command in conjunction with
16522@code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
c906108c
SS
16523
16524The @code{jump} command does not change the current stack frame, or
16525the stack pointer, or the contents of any memory location or any
16526register other than the program counter. If line @var{linespec} is in
16527a different function from the one currently executing, the results may
16528be bizarre if the two functions expect different patterns of arguments or
16529of local variables. For this reason, the @code{jump} command requests
16530confirmation if the specified line is not in the function currently
16531executing. However, even bizarre results are predictable if you are
16532well acquainted with the machine-language code of your program.
c906108c
SS
16533@end table
16534
c906108c 16535@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
16536On many systems, you can get much the same effect as the @code{jump}
16537command by storing a new value into the register @code{$pc}. The
16538difference is that this does not start your program running; it only
16539changes the address of where it @emph{will} run when you continue. For
16540example,
c906108c 16541
474c8240 16542@smallexample
c906108c 16543set $pc = 0x485
474c8240 16544@end smallexample
c906108c
SS
16545
16546@noindent
16547makes the next @code{continue} command or stepping command execute at
16548address @code{0x485}, rather than at the address where your program stopped.
79a6e687 16549@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
16550
16551The most common occasion to use the @code{jump} command is to back
16552up---perhaps with more breakpoints set---over a portion of a program
16553that has already executed, in order to examine its execution in more
16554detail.
16555
c906108c 16556@c @group
6d2ebf8b 16557@node Signaling
79a6e687 16558@section Giving your Program a Signal
9c16f35a 16559@cindex deliver a signal to a program
c906108c
SS
16560
16561@table @code
16562@kindex signal
16563@item signal @var{signal}
16564Resume execution where your program stopped, but immediately give it the
16565signal @var{signal}. @var{signal} can be the name or the number of a
16566signal. For example, on many systems @code{signal 2} and @code{signal
16567SIGINT} are both ways of sending an interrupt signal.
16568
16569Alternatively, if @var{signal} is zero, continue execution without
16570giving a signal. This is useful when your program stopped on account of
ae606bee 16571a signal and would ordinarily see the signal when resumed with the
c906108c
SS
16572@code{continue} command; @samp{signal 0} causes it to resume without a
16573signal.
16574
16575@code{signal} does not repeat when you press @key{RET} a second time
16576after executing the command.
16577@end table
16578@c @end group
16579
16580Invoking the @code{signal} command is not the same as invoking the
16581@code{kill} utility from the shell. Sending a signal with @code{kill}
16582causes @value{GDBN} to decide what to do with the signal depending on
16583the signal handling tables (@pxref{Signals}). The @code{signal} command
16584passes the signal directly to your program.
16585
c906108c 16586
6d2ebf8b 16587@node Returning
79a6e687 16588@section Returning from a Function
c906108c
SS
16589
16590@table @code
16591@cindex returning from a function
16592@kindex return
16593@item return
16594@itemx return @var{expression}
16595You can cancel execution of a function call with the @code{return}
16596command. If you give an
16597@var{expression} argument, its value is used as the function's return
16598value.
16599@end table
16600
16601When you use @code{return}, @value{GDBN} discards the selected stack frame
16602(and all frames within it). You can think of this as making the
16603discarded frame return prematurely. If you wish to specify a value to
16604be returned, give that value as the argument to @code{return}.
16605
16606This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 16607Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
16608innermost remaining frame. That frame becomes selected. The
16609specified value is stored in the registers used for returning values
16610of functions.
16611
16612The @code{return} command does not resume execution; it leaves the
16613program stopped in the state that would exist if the function had just
16614returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 16615and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
16616selected stack frame returns naturally.
16617
61ff14c6
JK
16618@value{GDBN} needs to know how the @var{expression} argument should be set for
16619the inferior. The concrete registers assignment depends on the OS ABI and the
16620type being returned by the selected stack frame. For example it is common for
16621OS ABI to return floating point values in FPU registers while integer values in
16622CPU registers. Still some ABIs return even floating point values in CPU
16623registers. Larger integer widths (such as @code{long long int}) also have
16624specific placement rules. @value{GDBN} already knows the OS ABI from its
16625current target so it needs to find out also the type being returned to make the
16626assignment into the right register(s).
16627
16628Normally, the selected stack frame has debug info. @value{GDBN} will always
16629use the debug info instead of the implicit type of @var{expression} when the
16630debug info is available. For example, if you type @kbd{return -1}, and the
16631function in the current stack frame is declared to return a @code{long long
16632int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
16633into a @code{long long int}:
16634
16635@smallexample
16636Breakpoint 1, func () at gdb.base/return-nodebug.c:29
1663729 return 31;
16638(@value{GDBP}) return -1
16639Make func return now? (y or n) y
16640#0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
1664143 printf ("result=%lld\n", func ());
16642(@value{GDBP})
16643@end smallexample
16644
16645However, if the selected stack frame does not have a debug info, e.g., if the
16646function was compiled without debug info, @value{GDBN} has to find out the type
16647to return from user. Specifying a different type by mistake may set the value
16648in different inferior registers than the caller code expects. For example,
16649typing @kbd{return -1} with its implicit type @code{int} would set only a part
16650of a @code{long long int} result for a debug info less function (on 32-bit
16651architectures). Therefore the user is required to specify the return type by
16652an appropriate cast explicitly:
16653
16654@smallexample
16655Breakpoint 2, 0x0040050b in func ()
16656(@value{GDBP}) return -1
16657Return value type not available for selected stack frame.
16658Please use an explicit cast of the value to return.
16659(@value{GDBP}) return (long long int) -1
16660Make selected stack frame return now? (y or n) y
16661#0 0x00400526 in main ()
16662(@value{GDBP})
16663@end smallexample
16664
6d2ebf8b 16665@node Calling
79a6e687 16666@section Calling Program Functions
c906108c 16667
f8568604 16668@table @code
c906108c 16669@cindex calling functions
f8568604
EZ
16670@cindex inferior functions, calling
16671@item print @var{expr}
d3e8051b 16672Evaluate the expression @var{expr} and display the resulting value.
f8568604
EZ
16673@var{expr} may include calls to functions in the program being
16674debugged.
16675
c906108c 16676@kindex call
c906108c
SS
16677@item call @var{expr}
16678Evaluate the expression @var{expr} without displaying @code{void}
16679returned values.
c906108c
SS
16680
16681You can use this variant of the @code{print} command if you want to
f8568604
EZ
16682execute a function from your program that does not return anything
16683(a.k.a.@: @dfn{a void function}), but without cluttering the output
16684with @code{void} returned values that @value{GDBN} will otherwise
16685print. If the result is not void, it is printed and saved in the
16686value history.
16687@end table
16688
9c16f35a
EZ
16689It is possible for the function you call via the @code{print} or
16690@code{call} command to generate a signal (e.g., if there's a bug in
16691the function, or if you passed it incorrect arguments). What happens
16692in that case is controlled by the @code{set unwindonsignal} command.
16693
7cd1089b
PM
16694Similarly, with a C@t{++} program it is possible for the function you
16695call via the @code{print} or @code{call} command to generate an
16696exception that is not handled due to the constraints of the dummy
16697frame. In this case, any exception that is raised in the frame, but has
16698an out-of-frame exception handler will not be found. GDB builds a
16699dummy-frame for the inferior function call, and the unwinder cannot
16700seek for exception handlers outside of this dummy-frame. What happens
16701in that case is controlled by the
16702@code{set unwind-on-terminating-exception} command.
16703
9c16f35a
EZ
16704@table @code
16705@item set unwindonsignal
16706@kindex set unwindonsignal
16707@cindex unwind stack in called functions
16708@cindex call dummy stack unwinding
16709Set unwinding of the stack if a signal is received while in a function
16710that @value{GDBN} called in the program being debugged. If set to on,
16711@value{GDBN} unwinds the stack it created for the call and restores
16712the context to what it was before the call. If set to off (the
16713default), @value{GDBN} stops in the frame where the signal was
16714received.
16715
16716@item show unwindonsignal
16717@kindex show unwindonsignal
16718Show the current setting of stack unwinding in the functions called by
16719@value{GDBN}.
7cd1089b
PM
16720
16721@item set unwind-on-terminating-exception
16722@kindex set unwind-on-terminating-exception
16723@cindex unwind stack in called functions with unhandled exceptions
16724@cindex call dummy stack unwinding on unhandled exception.
16725Set unwinding of the stack if a C@t{++} exception is raised, but left
16726unhandled while in a function that @value{GDBN} called in the program being
16727debugged. If set to on (the default), @value{GDBN} unwinds the stack
16728it created for the call and restores the context to what it was before
16729the call. If set to off, @value{GDBN} the exception is delivered to
16730the default C@t{++} exception handler and the inferior terminated.
16731
16732@item show unwind-on-terminating-exception
16733@kindex show unwind-on-terminating-exception
16734Show the current setting of stack unwinding in the functions called by
16735@value{GDBN}.
16736
9c16f35a
EZ
16737@end table
16738
f8568604
EZ
16739@cindex weak alias functions
16740Sometimes, a function you wish to call is actually a @dfn{weak alias}
16741for another function. In such case, @value{GDBN} might not pick up
16742the type information, including the types of the function arguments,
16743which causes @value{GDBN} to call the inferior function incorrectly.
16744As a result, the called function will function erroneously and may
16745even crash. A solution to that is to use the name of the aliased
16746function instead.
c906108c 16747
6d2ebf8b 16748@node Patching
79a6e687 16749@section Patching Programs
7a292a7a 16750
c906108c
SS
16751@cindex patching binaries
16752@cindex writing into executables
c906108c 16753@cindex writing into corefiles
c906108c 16754
7a292a7a
SS
16755By default, @value{GDBN} opens the file containing your program's
16756executable code (or the corefile) read-only. This prevents accidental
16757alterations to machine code; but it also prevents you from intentionally
16758patching your program's binary.
c906108c
SS
16759
16760If you'd like to be able to patch the binary, you can specify that
16761explicitly with the @code{set write} command. For example, you might
16762want to turn on internal debugging flags, or even to make emergency
16763repairs.
16764
16765@table @code
16766@kindex set write
16767@item set write on
16768@itemx set write off
7a292a7a 16769If you specify @samp{set write on}, @value{GDBN} opens executable and
20924a55 16770core files for both reading and writing; if you specify @kbd{set write
c906108c
SS
16771off} (the default), @value{GDBN} opens them read-only.
16772
16773If you have already loaded a file, you must load it again (using the
7a292a7a
SS
16774@code{exec-file} or @code{core-file} command) after changing @code{set
16775write}, for your new setting to take effect.
c906108c
SS
16776
16777@item show write
16778@kindex show write
7a292a7a
SS
16779Display whether executable files and core files are opened for writing
16780as well as reading.
c906108c
SS
16781@end table
16782
6d2ebf8b 16783@node GDB Files
c906108c
SS
16784@chapter @value{GDBN} Files
16785
7a292a7a
SS
16786@value{GDBN} needs to know the file name of the program to be debugged,
16787both in order to read its symbol table and in order to start your
16788program. To debug a core dump of a previous run, you must also tell
16789@value{GDBN} the name of the core dump file.
c906108c
SS
16790
16791@menu
16792* Files:: Commands to specify files
5b5d99cf 16793* Separate Debug Files:: Debugging information in separate files
608e2dbb 16794* MiniDebugInfo:: Debugging information in a special section
9291a0cd 16795* Index Files:: Index files speed up GDB
c906108c 16796* Symbol Errors:: Errors reading symbol files
b14b1491 16797* Data Files:: GDB data files
c906108c
SS
16798@end menu
16799
6d2ebf8b 16800@node Files
79a6e687 16801@section Commands to Specify Files
c906108c 16802
7a292a7a 16803@cindex symbol table
c906108c 16804@cindex core dump file
7a292a7a
SS
16805
16806You may want to specify executable and core dump file names. The usual
16807way to do this is at start-up time, using the arguments to
16808@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
16809Out of @value{GDBN}}).
c906108c
SS
16810
16811Occasionally it is necessary to change to a different file during a
397ca115
EZ
16812@value{GDBN} session. Or you may run @value{GDBN} and forget to
16813specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
16814via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
16815Program}). In these situations the @value{GDBN} commands to specify
0869d01b 16816new files are useful.
c906108c
SS
16817
16818@table @code
16819@cindex executable file
16820@kindex file
16821@item file @var{filename}
16822Use @var{filename} as the program to be debugged. It is read for its
16823symbols and for the contents of pure memory. It is also the program
16824executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
16825directory and the file is not found in the @value{GDBN} working directory,
16826@value{GDBN} uses the environment variable @code{PATH} as a list of
16827directories to search, just as the shell does when looking for a program
16828to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
16829and your program, using the @code{path} command.
16830
fc8be69e
EZ
16831@cindex unlinked object files
16832@cindex patching object files
16833You can load unlinked object @file{.o} files into @value{GDBN} using
16834the @code{file} command. You will not be able to ``run'' an object
16835file, but you can disassemble functions and inspect variables. Also,
16836if the underlying BFD functionality supports it, you could use
16837@kbd{gdb -write} to patch object files using this technique. Note
16838that @value{GDBN} can neither interpret nor modify relocations in this
16839case, so branches and some initialized variables will appear to go to
16840the wrong place. But this feature is still handy from time to time.
16841
c906108c
SS
16842@item file
16843@code{file} with no argument makes @value{GDBN} discard any information it
16844has on both executable file and the symbol table.
16845
16846@kindex exec-file
16847@item exec-file @r{[} @var{filename} @r{]}
16848Specify that the program to be run (but not the symbol table) is found
16849in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
16850if necessary to locate your program. Omitting @var{filename} means to
16851discard information on the executable file.
16852
16853@kindex symbol-file
16854@item symbol-file @r{[} @var{filename} @r{]}
16855Read symbol table information from file @var{filename}. @code{PATH} is
16856searched when necessary. Use the @code{file} command to get both symbol
16857table and program to run from the same file.
16858
16859@code{symbol-file} with no argument clears out @value{GDBN} information on your
16860program's symbol table.
16861
ae5a43e0
DJ
16862The @code{symbol-file} command causes @value{GDBN} to forget the contents of
16863some breakpoints and auto-display expressions. This is because they may
16864contain pointers to the internal data recording symbols and data types,
16865which are part of the old symbol table data being discarded inside
16866@value{GDBN}.
c906108c
SS
16867
16868@code{symbol-file} does not repeat if you press @key{RET} again after
16869executing it once.
16870
16871When @value{GDBN} is configured for a particular environment, it
16872understands debugging information in whatever format is the standard
16873generated for that environment; you may use either a @sc{gnu} compiler, or
16874other compilers that adhere to the local conventions.
c906108c 16875Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 16876using @code{@value{NGCC}} you can generate debugging information for
c906108c 16877optimized code.
c906108c
SS
16878
16879For most kinds of object files, with the exception of old SVR3 systems
16880using COFF, the @code{symbol-file} command does not normally read the
16881symbol table in full right away. Instead, it scans the symbol table
16882quickly to find which source files and which symbols are present. The
16883details are read later, one source file at a time, as they are needed.
16884
16885The purpose of this two-stage reading strategy is to make @value{GDBN}
16886start up faster. For the most part, it is invisible except for
16887occasional pauses while the symbol table details for a particular source
16888file are being read. (The @code{set verbose} command can turn these
16889pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 16890Warnings and Messages}.)
c906108c 16891
c906108c
SS
16892We have not implemented the two-stage strategy for COFF yet. When the
16893symbol table is stored in COFF format, @code{symbol-file} reads the
16894symbol table data in full right away. Note that ``stabs-in-COFF''
16895still does the two-stage strategy, since the debug info is actually
16896in stabs format.
16897
16898@kindex readnow
16899@cindex reading symbols immediately
16900@cindex symbols, reading immediately
6ac33a4e
TT
16901@item symbol-file @r{[} -readnow @r{]} @var{filename}
16902@itemx file @r{[} -readnow @r{]} @var{filename}
c906108c
SS
16903You can override the @value{GDBN} two-stage strategy for reading symbol
16904tables by using the @samp{-readnow} option with any of the commands that
16905load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 16906entire symbol table available.
c906108c 16907
c906108c
SS
16908@c FIXME: for now no mention of directories, since this seems to be in
16909@c flux. 13mar1992 status is that in theory GDB would look either in
16910@c current dir or in same dir as myprog; but issues like competing
16911@c GDB's, or clutter in system dirs, mean that in practice right now
16912@c only current dir is used. FFish says maybe a special GDB hierarchy
16913@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
16914@c files.
16915
c906108c 16916@kindex core-file
09d4efe1 16917@item core-file @r{[}@var{filename}@r{]}
4644b6e3 16918@itemx core
c906108c
SS
16919Specify the whereabouts of a core dump file to be used as the ``contents
16920of memory''. Traditionally, core files contain only some parts of the
16921address space of the process that generated them; @value{GDBN} can access the
16922executable file itself for other parts.
16923
16924@code{core-file} with no argument specifies that no core file is
16925to be used.
16926
16927Note that the core file is ignored when your program is actually running
7a292a7a
SS
16928under @value{GDBN}. So, if you have been running your program and you
16929wish to debug a core file instead, you must kill the subprocess in which
16930the program is running. To do this, use the @code{kill} command
79a6e687 16931(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 16932
c906108c
SS
16933@kindex add-symbol-file
16934@cindex dynamic linking
16935@item add-symbol-file @var{filename} @var{address}
a94ab193 16936@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
24bdad53 16937@itemx add-symbol-file @var{filename} @var{address} -s @var{section} @var{address} @dots{}
96a2c332
SS
16938The @code{add-symbol-file} command reads additional symbol table
16939information from the file @var{filename}. You would use this command
16940when @var{filename} has been dynamically loaded (by some other means)
16941into the program that is running. @var{address} should be the memory
16942address at which the file has been loaded; @value{GDBN} cannot figure
d167840f 16943this out for itself. You can additionally specify an arbitrary number
24bdad53 16944of @samp{-s @var{section} @var{address}} pairs, to give an explicit
d167840f
EZ
16945section name and base address for that section. You can specify any
16946@var{address} as an expression.
c906108c
SS
16947
16948The symbol table of the file @var{filename} is added to the symbol table
16949originally read with the @code{symbol-file} command. You can use the
96a2c332 16950@code{add-symbol-file} command any number of times; the new symbol data
98297bf6
NB
16951thus read is kept in addition to the old.
16952
16953Changes can be reverted using the command @code{remove-symbol-file}.
c906108c 16954
17d9d558
JB
16955@cindex relocatable object files, reading symbols from
16956@cindex object files, relocatable, reading symbols from
16957@cindex reading symbols from relocatable object files
16958@cindex symbols, reading from relocatable object files
16959@cindex @file{.o} files, reading symbols from
16960Although @var{filename} is typically a shared library file, an
16961executable file, or some other object file which has been fully
16962relocated for loading into a process, you can also load symbolic
16963information from relocatable @file{.o} files, as long as:
16964
16965@itemize @bullet
16966@item
16967the file's symbolic information refers only to linker symbols defined in
16968that file, not to symbols defined by other object files,
16969@item
16970every section the file's symbolic information refers to has actually
16971been loaded into the inferior, as it appears in the file, and
16972@item
16973you can determine the address at which every section was loaded, and
16974provide these to the @code{add-symbol-file} command.
16975@end itemize
16976
16977@noindent
16978Some embedded operating systems, like Sun Chorus and VxWorks, can load
16979relocatable files into an already running program; such systems
16980typically make the requirements above easy to meet. However, it's
16981important to recognize that many native systems use complex link
49efadf5 16982procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
16983assembly, for example) that make the requirements difficult to meet. In
16984general, one cannot assume that using @code{add-symbol-file} to read a
16985relocatable object file's symbolic information will have the same effect
16986as linking the relocatable object file into the program in the normal
16987way.
16988
c906108c
SS
16989@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
16990
98297bf6
NB
16991@kindex remove-symbol-file
16992@item remove-symbol-file @var{filename}
16993@item remove-symbol-file -a @var{address}
16994Remove a symbol file added via the @code{add-symbol-file} command. The
16995file to remove can be identified by its @var{filename} or by an @var{address}
16996that lies within the boundaries of this symbol file in memory. Example:
16997
16998@smallexample
16999(gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
17000add symbol table from file "/home/user/gdb/mylib.so" at
17001 .text_addr = 0x7ffff7ff9480
17002(y or n) y
17003Reading symbols from /home/user/gdb/mylib.so...done.
17004(gdb) remove-symbol-file -a 0x7ffff7ff9480
17005Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
17006(gdb)
17007@end smallexample
17008
17009
17010@code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
17011
c45da7e6
EZ
17012@kindex add-symbol-file-from-memory
17013@cindex @code{syscall DSO}
17014@cindex load symbols from memory
17015@item add-symbol-file-from-memory @var{address}
17016Load symbols from the given @var{address} in a dynamically loaded
17017object file whose image is mapped directly into the inferior's memory.
17018For example, the Linux kernel maps a @code{syscall DSO} into each
17019process's address space; this DSO provides kernel-specific code for
17020some system calls. The argument can be any expression whose
17021evaluation yields the address of the file's shared object file header.
17022For this command to work, you must have used @code{symbol-file} or
17023@code{exec-file} commands in advance.
17024
09d4efe1
EZ
17025@kindex add-shared-symbol-files
17026@kindex assf
17027@item add-shared-symbol-files @var{library-file}
17028@itemx assf @var{library-file}
95060284
JB
17029This command is deprecated and will be removed in future versions
17030of @value{GDBN}. Use the @code{sharedlibrary} command instead.
17031
09d4efe1
EZ
17032The @code{add-shared-symbol-files} command can currently be used only
17033in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
17034alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
17035@value{GDBN} automatically looks for shared libraries, however if
17036@value{GDBN} does not find yours, you can invoke
17037@code{add-shared-symbol-files}. It takes one argument: the shared
17038library's file name. @code{assf} is a shorthand alias for
17039@code{add-shared-symbol-files}.
c906108c 17040
c906108c 17041@kindex section
09d4efe1
EZ
17042@item section @var{section} @var{addr}
17043The @code{section} command changes the base address of the named
17044@var{section} of the exec file to @var{addr}. This can be used if the
17045exec file does not contain section addresses, (such as in the
17046@code{a.out} format), or when the addresses specified in the file
17047itself are wrong. Each section must be changed separately. The
17048@code{info files} command, described below, lists all the sections and
17049their addresses.
c906108c
SS
17050
17051@kindex info files
17052@kindex info target
17053@item info files
17054@itemx info target
7a292a7a
SS
17055@code{info files} and @code{info target} are synonymous; both print the
17056current target (@pxref{Targets, ,Specifying a Debugging Target}),
17057including the names of the executable and core dump files currently in
17058use by @value{GDBN}, and the files from which symbols were loaded. The
17059command @code{help target} lists all possible targets rather than
17060current ones.
17061
fe95c787
MS
17062@kindex maint info sections
17063@item maint info sections
17064Another command that can give you extra information about program sections
17065is @code{maint info sections}. In addition to the section information
17066displayed by @code{info files}, this command displays the flags and file
17067offset of each section in the executable and core dump files. In addition,
17068@code{maint info sections} provides the following command options (which
17069may be arbitrarily combined):
17070
17071@table @code
17072@item ALLOBJ
17073Display sections for all loaded object files, including shared libraries.
17074@item @var{sections}
6600abed 17075Display info only for named @var{sections}.
fe95c787
MS
17076@item @var{section-flags}
17077Display info only for sections for which @var{section-flags} are true.
17078The section flags that @value{GDBN} currently knows about are:
17079@table @code
17080@item ALLOC
17081Section will have space allocated in the process when loaded.
17082Set for all sections except those containing debug information.
17083@item LOAD
17084Section will be loaded from the file into the child process memory.
17085Set for pre-initialized code and data, clear for @code{.bss} sections.
17086@item RELOC
17087Section needs to be relocated before loading.
17088@item READONLY
17089Section cannot be modified by the child process.
17090@item CODE
17091Section contains executable code only.
6600abed 17092@item DATA
fe95c787
MS
17093Section contains data only (no executable code).
17094@item ROM
17095Section will reside in ROM.
17096@item CONSTRUCTOR
17097Section contains data for constructor/destructor lists.
17098@item HAS_CONTENTS
17099Section is not empty.
17100@item NEVER_LOAD
17101An instruction to the linker to not output the section.
17102@item COFF_SHARED_LIBRARY
17103A notification to the linker that the section contains
17104COFF shared library information.
17105@item IS_COMMON
17106Section contains common symbols.
17107@end table
17108@end table
6763aef9 17109@kindex set trust-readonly-sections
9c16f35a 17110@cindex read-only sections
6763aef9
MS
17111@item set trust-readonly-sections on
17112Tell @value{GDBN} that readonly sections in your object file
6ca652b0 17113really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
17114In that case, @value{GDBN} can fetch values from these sections
17115out of the object file, rather than from the target program.
17116For some targets (notably embedded ones), this can be a significant
17117enhancement to debugging performance.
17118
17119The default is off.
17120
17121@item set trust-readonly-sections off
15110bc3 17122Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
17123the contents of the section might change while the program is running,
17124and must therefore be fetched from the target when needed.
9c16f35a
EZ
17125
17126@item show trust-readonly-sections
17127Show the current setting of trusting readonly sections.
c906108c
SS
17128@end table
17129
17130All file-specifying commands allow both absolute and relative file names
17131as arguments. @value{GDBN} always converts the file name to an absolute file
17132name and remembers it that way.
17133
c906108c 17134@cindex shared libraries
9cceb671
DJ
17135@anchor{Shared Libraries}
17136@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
9c16f35a 17137and IBM RS/6000 AIX shared libraries.
53a5351d 17138
9cceb671
DJ
17139On MS-Windows @value{GDBN} must be linked with the Expat library to support
17140shared libraries. @xref{Expat}.
17141
c906108c
SS
17142@value{GDBN} automatically loads symbol definitions from shared libraries
17143when you use the @code{run} command, or when you examine a core file.
17144(Before you issue the @code{run} command, @value{GDBN} does not understand
17145references to a function in a shared library, however---unless you are
17146debugging a core file).
53a5351d
JM
17147
17148On HP-UX, if the program loads a library explicitly, @value{GDBN}
17149automatically loads the symbols at the time of the @code{shl_load} call.
17150
c906108c
SS
17151@c FIXME: some @value{GDBN} release may permit some refs to undef
17152@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
17153@c FIXME...lib; check this from time to time when updating manual
17154
b7209cb4
FF
17155There are times, however, when you may wish to not automatically load
17156symbol definitions from shared libraries, such as when they are
17157particularly large or there are many of them.
17158
17159To control the automatic loading of shared library symbols, use the
17160commands:
17161
17162@table @code
17163@kindex set auto-solib-add
17164@item set auto-solib-add @var{mode}
17165If @var{mode} is @code{on}, symbols from all shared object libraries
17166will be loaded automatically when the inferior begins execution, you
17167attach to an independently started inferior, or when the dynamic linker
17168informs @value{GDBN} that a new library has been loaded. If @var{mode}
17169is @code{off}, symbols must be loaded manually, using the
17170@code{sharedlibrary} command. The default value is @code{on}.
17171
dcaf7c2c
EZ
17172@cindex memory used for symbol tables
17173If your program uses lots of shared libraries with debug info that
17174takes large amounts of memory, you can decrease the @value{GDBN}
17175memory footprint by preventing it from automatically loading the
17176symbols from shared libraries. To that end, type @kbd{set
17177auto-solib-add off} before running the inferior, then load each
17178library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 17179@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
17180the libraries whose symbols you want to be loaded.
17181
b7209cb4
FF
17182@kindex show auto-solib-add
17183@item show auto-solib-add
17184Display the current autoloading mode.
17185@end table
17186
c45da7e6 17187@cindex load shared library
b7209cb4
FF
17188To explicitly load shared library symbols, use the @code{sharedlibrary}
17189command:
17190
c906108c
SS
17191@table @code
17192@kindex info sharedlibrary
17193@kindex info share
55333a84
DE
17194@item info share @var{regex}
17195@itemx info sharedlibrary @var{regex}
17196Print the names of the shared libraries which are currently loaded
17197that match @var{regex}. If @var{regex} is omitted then print
17198all shared libraries that are loaded.
c906108c
SS
17199
17200@kindex sharedlibrary
17201@kindex share
17202@item sharedlibrary @var{regex}
17203@itemx share @var{regex}
c906108c
SS
17204Load shared object library symbols for files matching a
17205Unix regular expression.
17206As with files loaded automatically, it only loads shared libraries
17207required by your program for a core file or after typing @code{run}. If
17208@var{regex} is omitted all shared libraries required by your program are
17209loaded.
c45da7e6
EZ
17210
17211@item nosharedlibrary
17212@kindex nosharedlibrary
17213@cindex unload symbols from shared libraries
17214Unload all shared object library symbols. This discards all symbols
17215that have been loaded from all shared libraries. Symbols from shared
17216libraries that were loaded by explicit user requests are not
17217discarded.
c906108c
SS
17218@end table
17219
721c2651 17220Sometimes you may wish that @value{GDBN} stops and gives you control
edcc5120
TT
17221when any of shared library events happen. The best way to do this is
17222to use @code{catch load} and @code{catch unload} (@pxref{Set
17223Catchpoints}).
17224
17225@value{GDBN} also supports the the @code{set stop-on-solib-events}
17226command for this. This command exists for historical reasons. It is
17227less useful than setting a catchpoint, because it does not allow for
17228conditions or commands as a catchpoint does.
721c2651
EZ
17229
17230@table @code
17231@item set stop-on-solib-events
17232@kindex set stop-on-solib-events
17233This command controls whether @value{GDBN} should give you control
17234when the dynamic linker notifies it about some shared library event.
17235The most common event of interest is loading or unloading of a new
17236shared library.
17237
17238@item show stop-on-solib-events
17239@kindex show stop-on-solib-events
17240Show whether @value{GDBN} stops and gives you control when shared
17241library events happen.
17242@end table
17243
f5ebfba0 17244Shared libraries are also supported in many cross or remote debugging
f1838a98
UW
17245configurations. @value{GDBN} needs to have access to the target's libraries;
17246this can be accomplished either by providing copies of the libraries
17247on the host system, or by asking @value{GDBN} to automatically retrieve the
17248libraries from the target. If copies of the target libraries are
17249provided, they need to be the same as the target libraries, although the
f5ebfba0
DJ
17250copies on the target can be stripped as long as the copies on the host are
17251not.
17252
59b7b46f
EZ
17253@cindex where to look for shared libraries
17254For remote debugging, you need to tell @value{GDBN} where the target
17255libraries are, so that it can load the correct copies---otherwise, it
17256may try to load the host's libraries. @value{GDBN} has two variables
17257to specify the search directories for target libraries.
f5ebfba0
DJ
17258
17259@table @code
59b7b46f 17260@cindex prefix for shared library file names
f822c95b 17261@cindex system root, alternate
f5ebfba0 17262@kindex set solib-absolute-prefix
f822c95b
DJ
17263@kindex set sysroot
17264@item set sysroot @var{path}
17265Use @var{path} as the system root for the program being debugged. Any
17266absolute shared library paths will be prefixed with @var{path}; many
17267runtime loaders store the absolute paths to the shared library in the
17268target program's memory. If you use @code{set sysroot} to find shared
17269libraries, they need to be laid out in the same way that they are on
17270the target, with e.g.@: a @file{/lib} and @file{/usr/lib} hierarchy
17271under @var{path}.
17272
f1838a98
UW
17273If @var{path} starts with the sequence @file{remote:}, @value{GDBN} will
17274retrieve the target libraries from the remote system. This is only
17275supported when using a remote target that supports the @code{remote get}
17276command (@pxref{File Transfer,,Sending files to a remote system}).
17277The part of @var{path} following the initial @file{remote:}
17278(if present) is used as system root prefix on the remote file system.
17279@footnote{If you want to specify a local system root using a directory
17280that happens to be named @file{remote:}, you need to use some equivalent
17281variant of the name like @file{./remote:}.}
17282
ab38a727
PA
17283For targets with an MS-DOS based filesystem, such as MS-Windows and
17284SymbianOS, @value{GDBN} tries prefixing a few variants of the target
17285absolute file name with @var{path}. But first, on Unix hosts,
17286@value{GDBN} converts all backslash directory separators into forward
17287slashes, because the backslash is not a directory separator on Unix:
17288
17289@smallexample
17290 c:\foo\bar.dll @result{} c:/foo/bar.dll
17291@end smallexample
17292
17293Then, @value{GDBN} attempts prefixing the target file name with
17294@var{path}, and looks for the resulting file name in the host file
17295system:
17296
17297@smallexample
17298 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
17299@end smallexample
17300
17301If that does not find the shared library, @value{GDBN} tries removing
17302the @samp{:} character from the drive spec, both for convenience, and,
17303for the case of the host file system not supporting file names with
17304colons:
17305
17306@smallexample
17307 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
17308@end smallexample
17309
17310This makes it possible to have a system root that mirrors a target
17311with more than one drive. E.g., you may want to setup your local
17312copies of the target system shared libraries like so (note @samp{c} vs
17313@samp{z}):
17314
17315@smallexample
17316 @file{/path/to/sysroot/c/sys/bin/foo.dll}
17317 @file{/path/to/sysroot/c/sys/bin/bar.dll}
17318 @file{/path/to/sysroot/z/sys/bin/bar.dll}
17319@end smallexample
17320
17321@noindent
17322and point the system root at @file{/path/to/sysroot}, so that
17323@value{GDBN} can find the correct copies of both
17324@file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
17325
17326If that still does not find the shared library, @value{GDBN} tries
17327removing the whole drive spec from the target file name:
17328
17329@smallexample
17330 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
17331@end smallexample
17332
17333This last lookup makes it possible to not care about the drive name,
17334if you don't want or need to.
17335
f822c95b
DJ
17336The @code{set solib-absolute-prefix} command is an alias for @code{set
17337sysroot}.
17338
17339@cindex default system root
59b7b46f 17340@cindex @samp{--with-sysroot}
f822c95b
DJ
17341You can set the default system root by using the configure-time
17342@samp{--with-sysroot} option. If the system root is inside
17343@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
17344@samp{--exec-prefix}), then the default system root will be updated
17345automatically if the installed @value{GDBN} is moved to a new
17346location.
17347
17348@kindex show sysroot
17349@item show sysroot
f5ebfba0
DJ
17350Display the current shared library prefix.
17351
17352@kindex set solib-search-path
17353@item set solib-search-path @var{path}
f822c95b
DJ
17354If this variable is set, @var{path} is a colon-separated list of
17355directories to search for shared libraries. @samp{solib-search-path}
17356is used after @samp{sysroot} fails to locate the library, or if the
17357path to the library is relative instead of absolute. If you want to
17358use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 17359@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 17360finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 17361it to a nonexistent directory may interfere with automatic loading
f822c95b 17362of shared library symbols.
f5ebfba0
DJ
17363
17364@kindex show solib-search-path
17365@item show solib-search-path
17366Display the current shared library search path.
ab38a727
PA
17367
17368@cindex DOS file-name semantics of file names.
17369@kindex set target-file-system-kind (unix|dos-based|auto)
17370@kindex show target-file-system-kind
17371@item set target-file-system-kind @var{kind}
17372Set assumed file system kind for target reported file names.
17373
17374Shared library file names as reported by the target system may not
17375make sense as is on the system @value{GDBN} is running on. For
17376example, when remote debugging a target that has MS-DOS based file
17377system semantics, from a Unix host, the target may be reporting to
17378@value{GDBN} a list of loaded shared libraries with file names such as
17379@file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
17380drive letters, so the @samp{c:\} prefix is not normally understood as
17381indicating an absolute file name, and neither is the backslash
17382normally considered a directory separator character. In that case,
17383the native file system would interpret this whole absolute file name
17384as a relative file name with no directory components. This would make
17385it impossible to point @value{GDBN} at a copy of the remote target's
17386shared libraries on the host using @code{set sysroot}, and impractical
17387with @code{set solib-search-path}. Setting
17388@code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
17389to interpret such file names similarly to how the target would, and to
17390map them to file names valid on @value{GDBN}'s native file system
17391semantics. The value of @var{kind} can be @code{"auto"}, in addition
17392to one of the supported file system kinds. In that case, @value{GDBN}
17393tries to determine the appropriate file system variant based on the
17394current target's operating system (@pxref{ABI, ,Configuring the
17395Current ABI}). The supported file system settings are:
17396
17397@table @code
17398@item unix
17399Instruct @value{GDBN} to assume the target file system is of Unix
17400kind. Only file names starting the forward slash (@samp{/}) character
17401are considered absolute, and the directory separator character is also
17402the forward slash.
17403
17404@item dos-based
17405Instruct @value{GDBN} to assume the target file system is DOS based.
17406File names starting with either a forward slash, or a drive letter
17407followed by a colon (e.g., @samp{c:}), are considered absolute, and
17408both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
17409considered directory separators.
17410
17411@item auto
17412Instruct @value{GDBN} to use the file system kind associated with the
17413target operating system (@pxref{ABI, ,Configuring the Current ABI}).
17414This is the default.
17415@end table
f5ebfba0
DJ
17416@end table
17417
c011a4f4
DE
17418@cindex file name canonicalization
17419@cindex base name differences
17420When processing file names provided by the user, @value{GDBN}
17421frequently needs to compare them to the file names recorded in the
17422program's debug info. Normally, @value{GDBN} compares just the
17423@dfn{base names} of the files as strings, which is reasonably fast
17424even for very large programs. (The base name of a file is the last
17425portion of its name, after stripping all the leading directories.)
17426This shortcut in comparison is based upon the assumption that files
17427cannot have more than one base name. This is usually true, but
17428references to files that use symlinks or similar filesystem
17429facilities violate that assumption. If your program records files
17430using such facilities, or if you provide file names to @value{GDBN}
17431using symlinks etc., you can set @code{basenames-may-differ} to
17432@code{true} to instruct @value{GDBN} to completely canonicalize each
17433pair of file names it needs to compare. This will make file-name
17434comparisons accurate, but at a price of a significant slowdown.
17435
17436@table @code
17437@item set basenames-may-differ
17438@kindex set basenames-may-differ
17439Set whether a source file may have multiple base names.
17440
17441@item show basenames-may-differ
17442@kindex show basenames-may-differ
17443Show whether a source file may have multiple base names.
17444@end table
5b5d99cf
JB
17445
17446@node Separate Debug Files
17447@section Debugging Information in Separate Files
17448@cindex separate debugging information files
17449@cindex debugging information in separate files
17450@cindex @file{.debug} subdirectories
17451@cindex debugging information directory, global
f307c045 17452@cindex global debugging information directories
c7e83d54
EZ
17453@cindex build ID, and separate debugging files
17454@cindex @file{.build-id} directory
5b5d99cf
JB
17455
17456@value{GDBN} allows you to put a program's debugging information in a
17457file separate from the executable itself, in a way that allows
17458@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
17459Since debugging information can be very large---sometimes larger
17460than the executable code itself---some systems distribute debugging
5b5d99cf
JB
17461information for their executables in separate files, which users can
17462install only when they need to debug a problem.
17463
c7e83d54
EZ
17464@value{GDBN} supports two ways of specifying the separate debug info
17465file:
5b5d99cf
JB
17466
17467@itemize @bullet
17468@item
c7e83d54
EZ
17469The executable contains a @dfn{debug link} that specifies the name of
17470the separate debug info file. The separate debug file's name is
17471usually @file{@var{executable}.debug}, where @var{executable} is the
17472name of the corresponding executable file without leading directories
17473(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
99e008fe
EZ
17474debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
17475checksum for the debug file, which @value{GDBN} uses to validate that
17476the executable and the debug file came from the same build.
c7e83d54
EZ
17477
17478@item
7e27a47a 17479The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 17480also present in the corresponding debug info file. (This is supported
7e27a47a
EZ
17481only on some operating systems, notably those which use the ELF format
17482for binary files and the @sc{gnu} Binutils.) For more details about
17483this feature, see the description of the @option{--build-id}
17484command-line option in @ref{Options, , Command Line Options, ld.info,
17485The GNU Linker}. The debug info file's name is not specified
17486explicitly by the build ID, but can be computed from the build ID, see
17487below.
d3750b24
JK
17488@end itemize
17489
c7e83d54
EZ
17490Depending on the way the debug info file is specified, @value{GDBN}
17491uses two different methods of looking for the debug file:
d3750b24
JK
17492
17493@itemize @bullet
17494@item
c7e83d54
EZ
17495For the ``debug link'' method, @value{GDBN} looks up the named file in
17496the directory of the executable file, then in a subdirectory of that
f307c045
JK
17497directory named @file{.debug}, and finally under each one of the global debug
17498directories, in a subdirectory whose name is identical to the leading
c7e83d54
EZ
17499directories of the executable's absolute file name.
17500
17501@item
83f83d7f 17502For the ``build ID'' method, @value{GDBN} looks in the
f307c045
JK
17503@file{.build-id} subdirectory of each one of the global debug directories for
17504a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
17505first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
17506are the rest of the bit string. (Real build ID strings are 32 or more
17507hex characters, not 10.)
c7e83d54
EZ
17508@end itemize
17509
17510So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
17511@file{/usr/bin/ls}, which has a debug link that specifies the
17512file @file{ls.debug}, and a build ID whose value in hex is
f307c045 17513@code{abcdef1234}. If the list of the global debug directories includes
c7e83d54
EZ
17514@file{/usr/lib/debug}, then @value{GDBN} will look for the following
17515debug information files, in the indicated order:
17516
17517@itemize @minus
17518@item
17519@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 17520@item
c7e83d54 17521@file{/usr/bin/ls.debug}
5b5d99cf 17522@item
c7e83d54 17523@file{/usr/bin/.debug/ls.debug}
5b5d99cf 17524@item
c7e83d54 17525@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 17526@end itemize
5b5d99cf 17527
1564a261
JK
17528@anchor{debug-file-directory}
17529Global debugging info directories default to what is set by @value{GDBN}
17530configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
17531you can also set the global debugging info directories, and view the list
17532@value{GDBN} is currently using.
5b5d99cf
JB
17533
17534@table @code
17535
17536@kindex set debug-file-directory
24ddea62
JK
17537@item set debug-file-directory @var{directories}
17538Set the directories which @value{GDBN} searches for separate debugging
d9242c17
JK
17539information files to @var{directory}. Multiple path components can be set
17540concatenating them by a path separator.
5b5d99cf
JB
17541
17542@kindex show debug-file-directory
17543@item show debug-file-directory
24ddea62 17544Show the directories @value{GDBN} searches for separate debugging
5b5d99cf
JB
17545information files.
17546
17547@end table
17548
17549@cindex @code{.gnu_debuglink} sections
c7e83d54 17550@cindex debug link sections
5b5d99cf
JB
17551A debug link is a special section of the executable file named
17552@code{.gnu_debuglink}. The section must contain:
17553
17554@itemize
17555@item
17556A filename, with any leading directory components removed, followed by
17557a zero byte,
17558@item
17559zero to three bytes of padding, as needed to reach the next four-byte
17560boundary within the section, and
17561@item
17562a four-byte CRC checksum, stored in the same endianness used for the
17563executable file itself. The checksum is computed on the debugging
17564information file's full contents by the function given below, passing
17565zero as the @var{crc} argument.
17566@end itemize
17567
17568Any executable file format can carry a debug link, as long as it can
17569contain a section named @code{.gnu_debuglink} with the contents
17570described above.
17571
d3750b24 17572@cindex @code{.note.gnu.build-id} sections
c7e83d54 17573@cindex build ID sections
7e27a47a
EZ
17574The build ID is a special section in the executable file (and in other
17575ELF binary files that @value{GDBN} may consider). This section is
17576often named @code{.note.gnu.build-id}, but that name is not mandatory.
17577It contains unique identification for the built files---the ID remains
17578the same across multiple builds of the same build tree. The default
17579algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
17580content for the build ID string. The same section with an identical
17581value is present in the original built binary with symbols, in its
17582stripped variant, and in the separate debugging information file.
d3750b24 17583
5b5d99cf
JB
17584The debugging information file itself should be an ordinary
17585executable, containing a full set of linker symbols, sections, and
17586debugging information. The sections of the debugging information file
c7e83d54
EZ
17587should have the same names, addresses, and sizes as the original file,
17588but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
17589in an ordinary executable.
17590
7e27a47a 17591The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
17592@samp{objcopy} utility that can produce
17593the separated executable / debugging information file pairs using the
17594following commands:
17595
17596@smallexample
17597@kbd{objcopy --only-keep-debug foo foo.debug}
17598@kbd{strip -g foo}
c7e83d54
EZ
17599@end smallexample
17600
17601@noindent
17602These commands remove the debugging
83f83d7f
JK
17603information from the executable file @file{foo} and place it in the file
17604@file{foo.debug}. You can use the first, second or both methods to link the
17605two files:
17606
17607@itemize @bullet
17608@item
17609The debug link method needs the following additional command to also leave
17610behind a debug link in @file{foo}:
17611
17612@smallexample
17613@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
17614@end smallexample
17615
17616Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 17617a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
17618foo.debug} has the same functionality as the two @code{objcopy} commands and
17619the @code{ln -s} command above, together.
17620
17621@item
17622Build ID gets embedded into the main executable using @code{ld --build-id} or
17623the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
17624compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 17625utilities (Binutils) package since version 2.18.
83f83d7f
JK
17626@end itemize
17627
17628@noindent
d3750b24 17629
99e008fe
EZ
17630@cindex CRC algorithm definition
17631The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
17632IEEE 802.3 using the polynomial:
17633
17634@c TexInfo requires naked braces for multi-digit exponents for Tex
17635@c output, but this causes HTML output to barf. HTML has to be set using
17636@c raw commands. So we end up having to specify this equation in 2
17637@c different ways!
17638@ifhtml
17639@display
17640@html
17641 <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>
17642 + <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
17643@end html
17644@end display
17645@end ifhtml
17646@ifnothtml
17647@display
17648 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
17649 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
17650@end display
17651@end ifnothtml
17652
17653The function is computed byte at a time, taking the least
17654significant bit of each byte first. The initial pattern
17655@code{0xffffffff} is used, to ensure leading zeros affect the CRC and
17656the final result is inverted to ensure trailing zeros also affect the
17657CRC.
17658
17659@emph{Note:} This is the same CRC polynomial as used in handling the
936d2992
PA
17660@dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
17661However in the case of the Remote Serial Protocol, the CRC is computed
17662@emph{most} significant bit first, and the result is not inverted, so
17663trailing zeros have no effect on the CRC value.
99e008fe
EZ
17664
17665To complete the description, we show below the code of the function
17666which produces the CRC used in @code{.gnu_debuglink}. Inverting the
17667initially supplied @code{crc} argument means that an initial call to
17668this function passing in zero will start computing the CRC using
17669@code{0xffffffff}.
5b5d99cf 17670
4644b6e3 17671@kindex gnu_debuglink_crc32
5b5d99cf
JB
17672@smallexample
17673unsigned long
17674gnu_debuglink_crc32 (unsigned long crc,
17675 unsigned char *buf, size_t len)
17676@{
17677 static const unsigned long crc32_table[256] =
17678 @{
17679 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
17680 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
17681 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
17682 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
17683 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
17684 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
17685 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
17686 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
17687 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
17688 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
17689 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
17690 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
17691 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
17692 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
17693 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
17694 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
17695 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
17696 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
17697 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
17698 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
17699 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
17700 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
17701 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
17702 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
17703 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
17704 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
17705 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
17706 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
17707 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
17708 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
17709 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
17710 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
17711 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
17712 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
17713 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
17714 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
17715 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
17716 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
17717 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
17718 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
17719 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
17720 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
17721 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
17722 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
17723 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
17724 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
17725 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
17726 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
17727 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
17728 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
17729 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
17730 0x2d02ef8d
17731 @};
17732 unsigned char *end;
17733
17734 crc = ~crc & 0xffffffff;
17735 for (end = buf + len; buf < end; ++buf)
17736 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 17737 return ~crc & 0xffffffff;
5b5d99cf
JB
17738@}
17739@end smallexample
17740
c7e83d54
EZ
17741@noindent
17742This computation does not apply to the ``build ID'' method.
17743
608e2dbb
TT
17744@node MiniDebugInfo
17745@section Debugging information in a special section
17746@cindex separate debug sections
17747@cindex @samp{.gnu_debugdata} section
17748
17749Some systems ship pre-built executables and libraries that have a
17750special @samp{.gnu_debugdata} section. This feature is called
17751@dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
17752is used to supply extra symbols for backtraces.
17753
17754The intent of this section is to provide extra minimal debugging
17755information for use in simple backtraces. It is not intended to be a
17756replacement for full separate debugging information (@pxref{Separate
17757Debug Files}). The example below shows the intended use; however,
17758@value{GDBN} does not currently put restrictions on what sort of
17759debugging information might be included in the section.
17760
17761@value{GDBN} has support for this extension. If the section exists,
17762then it is used provided that no other source of debugging information
17763can be found, and that @value{GDBN} was configured with LZMA support.
17764
17765This section can be easily created using @command{objcopy} and other
17766standard utilities:
17767
17768@smallexample
17769# Extract the dynamic symbols from the main binary, there is no need
5423b017 17770# to also have these in the normal symbol table.
608e2dbb
TT
17771nm -D @var{binary} --format=posix --defined-only \
17772 | awk '@{ print $1 @}' | sort > dynsyms
17773
5423b017 17774# Extract all the text (i.e. function) symbols from the debuginfo.
1d236d23
JK
17775# (Note that we actually also accept "D" symbols, for the benefit
17776# of platforms like PowerPC64 that use function descriptors.)
608e2dbb 17777nm @var{binary} --format=posix --defined-only \
1d236d23 17778 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
608e2dbb
TT
17779 | sort > funcsyms
17780
17781# Keep all the function symbols not already in the dynamic symbol
17782# table.
17783comm -13 dynsyms funcsyms > keep_symbols
17784
edf9f00c
JK
17785# Separate full debug info into debug binary.
17786objcopy --only-keep-debug @var{binary} debug
17787
608e2dbb
TT
17788# Copy the full debuginfo, keeping only a minimal set of symbols and
17789# removing some unnecessary sections.
17790objcopy -S --remove-section .gdb_index --remove-section .comment \
edf9f00c
JK
17791 --keep-symbols=keep_symbols debug mini_debuginfo
17792
17793# Drop the full debug info from the original binary.
17794strip --strip-all -R .comment @var{binary}
608e2dbb
TT
17795
17796# Inject the compressed data into the .gnu_debugdata section of the
17797# original binary.
17798xz mini_debuginfo
17799objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
17800@end smallexample
5b5d99cf 17801
9291a0cd
TT
17802@node Index Files
17803@section Index Files Speed Up @value{GDBN}
17804@cindex index files
17805@cindex @samp{.gdb_index} section
17806
17807When @value{GDBN} finds a symbol file, it scans the symbols in the
17808file in order to construct an internal symbol table. This lets most
17809@value{GDBN} operations work quickly---at the cost of a delay early
17810on. For large programs, this delay can be quite lengthy, so
17811@value{GDBN} provides a way to build an index, which speeds up
17812startup.
17813
17814The index is stored as a section in the symbol file. @value{GDBN} can
17815write the index to a file, then you can put it into the symbol file
17816using @command{objcopy}.
17817
17818To create an index file, use the @code{save gdb-index} command:
17819
17820@table @code
17821@item save gdb-index @var{directory}
17822@kindex save gdb-index
17823Create an index file for each symbol file currently known by
17824@value{GDBN}. Each file is named after its corresponding symbol file,
17825with @samp{.gdb-index} appended, and is written into the given
17826@var{directory}.
17827@end table
17828
17829Once you have created an index file you can merge it into your symbol
17830file, here named @file{symfile}, using @command{objcopy}:
17831
17832@smallexample
17833$ objcopy --add-section .gdb_index=symfile.gdb-index \
17834 --set-section-flags .gdb_index=readonly symfile symfile
17835@end smallexample
17836
e615022a
DE
17837@value{GDBN} will normally ignore older versions of @file{.gdb_index}
17838sections that have been deprecated. Usually they are deprecated because
17839they are missing a new feature or have performance issues.
17840To tell @value{GDBN} to use a deprecated index section anyway
17841specify @code{set use-deprecated-index-sections on}.
17842The default is @code{off}.
17843This can speed up startup, but may result in some functionality being lost.
17844@xref{Index Section Format}.
17845
17846@emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
17847must be done before gdb reads the file. The following will not work:
17848
17849@smallexample
17850$ gdb -ex "set use-deprecated-index-sections on" <program>
17851@end smallexample
17852
17853Instead you must do, for example,
17854
17855@smallexample
17856$ gdb -iex "set use-deprecated-index-sections on" <program>
17857@end smallexample
17858
9291a0cd
TT
17859There are currently some limitation on indices. They only work when
17860for DWARF debugging information, not stabs. And, they do not
17861currently work for programs using Ada.
17862
6d2ebf8b 17863@node Symbol Errors
79a6e687 17864@section Errors Reading Symbol Files
c906108c
SS
17865
17866While reading a symbol file, @value{GDBN} occasionally encounters problems,
17867such as symbol types it does not recognize, or known bugs in compiler
17868output. By default, @value{GDBN} does not notify you of such problems, since
17869they are relatively common and primarily of interest to people
17870debugging compilers. If you are interested in seeing information
17871about ill-constructed symbol tables, you can either ask @value{GDBN} to print
17872only one message about each such type of problem, no matter how many
17873times the problem occurs; or you can ask @value{GDBN} to print more messages,
17874to see how many times the problems occur, with the @code{set
79a6e687
BW
17875complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
17876Messages}).
c906108c
SS
17877
17878The messages currently printed, and their meanings, include:
17879
17880@table @code
17881@item inner block not inside outer block in @var{symbol}
17882
17883The symbol information shows where symbol scopes begin and end
17884(such as at the start of a function or a block of statements). This
17885error indicates that an inner scope block is not fully contained
17886in its outer scope blocks.
17887
17888@value{GDBN} circumvents the problem by treating the inner block as if it had
17889the same scope as the outer block. In the error message, @var{symbol}
17890may be shown as ``@code{(don't know)}'' if the outer block is not a
17891function.
17892
17893@item block at @var{address} out of order
17894
17895The symbol information for symbol scope blocks should occur in
17896order of increasing addresses. This error indicates that it does not
17897do so.
17898
17899@value{GDBN} does not circumvent this problem, and has trouble
17900locating symbols in the source file whose symbols it is reading. (You
17901can often determine what source file is affected by specifying
79a6e687
BW
17902@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
17903Messages}.)
c906108c
SS
17904
17905@item bad block start address patched
17906
17907The symbol information for a symbol scope block has a start address
17908smaller than the address of the preceding source line. This is known
17909to occur in the SunOS 4.1.1 (and earlier) C compiler.
17910
17911@value{GDBN} circumvents the problem by treating the symbol scope block as
17912starting on the previous source line.
17913
17914@item bad string table offset in symbol @var{n}
17915
17916@cindex foo
17917Symbol number @var{n} contains a pointer into the string table which is
17918larger than the size of the string table.
17919
17920@value{GDBN} circumvents the problem by considering the symbol to have the
17921name @code{foo}, which may cause other problems if many symbols end up
17922with this name.
17923
17924@item unknown symbol type @code{0x@var{nn}}
17925
7a292a7a
SS
17926The symbol information contains new data types that @value{GDBN} does
17927not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 17928uncomprehended information, in hexadecimal.
c906108c 17929
7a292a7a
SS
17930@value{GDBN} circumvents the error by ignoring this symbol information.
17931This usually allows you to debug your program, though certain symbols
c906108c 17932are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
17933debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
17934on @code{complain}, then go up to the function @code{read_dbx_symtab}
17935and examine @code{*bufp} to see the symbol.
c906108c
SS
17936
17937@item stub type has NULL name
c906108c 17938
7a292a7a 17939@value{GDBN} could not find the full definition for a struct or class.
c906108c 17940
7a292a7a 17941@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 17942The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
17943information that recent versions of the compiler should have output for
17944it.
c906108c
SS
17945
17946@item info mismatch between compiler and debugger
17947
17948@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 17949
c906108c
SS
17950@end table
17951
b14b1491
TT
17952@node Data Files
17953@section GDB Data Files
17954
17955@cindex prefix for data files
17956@value{GDBN} will sometimes read an auxiliary data file. These files
17957are kept in a directory known as the @dfn{data directory}.
17958
17959You can set the data directory's name, and view the name @value{GDBN}
17960is currently using.
17961
17962@table @code
17963@kindex set data-directory
17964@item set data-directory @var{directory}
17965Set the directory which @value{GDBN} searches for auxiliary data files
17966to @var{directory}.
17967
17968@kindex show data-directory
17969@item show data-directory
17970Show the directory @value{GDBN} searches for auxiliary data files.
17971@end table
17972
17973@cindex default data directory
17974@cindex @samp{--with-gdb-datadir}
17975You can set the default data directory by using the configure-time
17976@samp{--with-gdb-datadir} option. If the data directory is inside
17977@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
17978@samp{--exec-prefix}), then the default data directory will be updated
17979automatically if the installed @value{GDBN} is moved to a new
17980location.
17981
aae1c79a
DE
17982The data directory may also be specified with the
17983@code{--data-directory} command line option.
17984@xref{Mode Options}.
17985
6d2ebf8b 17986@node Targets
c906108c 17987@chapter Specifying a Debugging Target
7a292a7a 17988
c906108c 17989@cindex debugging target
c906108c 17990A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
17991
17992Often, @value{GDBN} runs in the same host environment as your program;
17993in that case, the debugging target is specified as a side effect when
17994you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
17995flexibility---for example, running @value{GDBN} on a physically separate
17996host, or controlling a standalone system over a serial port or a
53a5351d
JM
17997realtime system over a TCP/IP connection---you can use the @code{target}
17998command to specify one of the target types configured for @value{GDBN}
79a6e687 17999(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 18000
a8f24a35
EZ
18001@cindex target architecture
18002It is possible to build @value{GDBN} for several different @dfn{target
18003architectures}. When @value{GDBN} is built like that, you can choose
18004one of the available architectures with the @kbd{set architecture}
18005command.
18006
18007@table @code
18008@kindex set architecture
18009@kindex show architecture
18010@item set architecture @var{arch}
18011This command sets the current target architecture to @var{arch}. The
18012value of @var{arch} can be @code{"auto"}, in addition to one of the
18013supported architectures.
18014
18015@item show architecture
18016Show the current target architecture.
9c16f35a
EZ
18017
18018@item set processor
18019@itemx processor
18020@kindex set processor
18021@kindex show processor
18022These are alias commands for, respectively, @code{set architecture}
18023and @code{show architecture}.
a8f24a35
EZ
18024@end table
18025
c906108c
SS
18026@menu
18027* Active Targets:: Active targets
18028* Target Commands:: Commands for managing targets
c906108c 18029* Byte Order:: Choosing target byte order
c906108c
SS
18030@end menu
18031
6d2ebf8b 18032@node Active Targets
79a6e687 18033@section Active Targets
7a292a7a 18034
c906108c
SS
18035@cindex stacking targets
18036@cindex active targets
18037@cindex multiple targets
18038
8ea5bce5 18039There are multiple classes of targets such as: processes, executable files or
c0edd9ed
JK
18040recording sessions. Core files belong to the process class, making core file
18041and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
18042on multiple active targets, one in each class. This allows you to (for
18043example) start a process and inspect its activity, while still having access to
18044the executable file after the process finishes. Or if you start process
18045recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
18046presented a virtual layer of the recording target, while the process target
18047remains stopped at the chronologically last point of the process execution.
18048
18049Use the @code{core-file} and @code{exec-file} commands to select a new core
18050file or executable target (@pxref{Files, ,Commands to Specify Files}). To
18051specify as a target a process that is already running, use the @code{attach}
18052command (@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 18053
6d2ebf8b 18054@node Target Commands
79a6e687 18055@section Commands for Managing Targets
c906108c
SS
18056
18057@table @code
18058@item target @var{type} @var{parameters}
7a292a7a
SS
18059Connects the @value{GDBN} host environment to a target machine or
18060process. A target is typically a protocol for talking to debugging
18061facilities. You use the argument @var{type} to specify the type or
18062protocol of the target machine.
c906108c
SS
18063
18064Further @var{parameters} are interpreted by the target protocol, but
18065typically include things like device names or host names to connect
18066with, process numbers, and baud rates.
c906108c
SS
18067
18068The @code{target} command does not repeat if you press @key{RET} again
18069after executing the command.
18070
18071@kindex help target
18072@item help target
18073Displays the names of all targets available. To display targets
18074currently selected, use either @code{info target} or @code{info files}
79a6e687 18075(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
18076
18077@item help target @var{name}
18078Describe a particular target, including any parameters necessary to
18079select it.
18080
18081@kindex set gnutarget
18082@item set gnutarget @var{args}
5d161b24 18083@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 18084knows whether it is reading an @dfn{executable},
5d161b24
DB
18085a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
18086with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
18087with @code{gnutarget} the @code{target} refers to a program, not a machine.
18088
d4f3574e 18089@quotation
c906108c
SS
18090@emph{Warning:} To specify a file format with @code{set gnutarget},
18091you must know the actual BFD name.
d4f3574e 18092@end quotation
c906108c 18093
d4f3574e 18094@noindent
79a6e687 18095@xref{Files, , Commands to Specify Files}.
c906108c 18096
5d161b24 18097@kindex show gnutarget
c906108c
SS
18098@item show gnutarget
18099Use the @code{show gnutarget} command to display what file format
18100@code{gnutarget} is set to read. If you have not set @code{gnutarget},
18101@value{GDBN} will determine the file format for each file automatically,
c4957902 18102and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
c906108c
SS
18103@end table
18104
4644b6e3 18105@cindex common targets
c906108c
SS
18106Here are some common targets (available, or not, depending on the GDB
18107configuration):
c906108c
SS
18108
18109@table @code
4644b6e3 18110@kindex target
c906108c 18111@item target exec @var{program}
4644b6e3 18112@cindex executable file target
c906108c
SS
18113An executable file. @samp{target exec @var{program}} is the same as
18114@samp{exec-file @var{program}}.
18115
c906108c 18116@item target core @var{filename}
4644b6e3 18117@cindex core dump file target
c906108c
SS
18118A core dump file. @samp{target core @var{filename}} is the same as
18119@samp{core-file @var{filename}}.
c906108c 18120
1a10341b 18121@item target remote @var{medium}
4644b6e3 18122@cindex remote target
1a10341b
JB
18123A remote system connected to @value{GDBN} via a serial line or network
18124connection. This command tells @value{GDBN} to use its own remote
18125protocol over @var{medium} for debugging. @xref{Remote Debugging}.
18126
18127For example, if you have a board connected to @file{/dev/ttya} on the
18128machine running @value{GDBN}, you could say:
18129
18130@smallexample
18131target remote /dev/ttya
18132@end smallexample
18133
18134@code{target remote} supports the @code{load} command. This is only
18135useful if you have some other way of getting the stub to the target
18136system, and you can put it somewhere in memory where it won't get
18137clobbered by the download.
c906108c 18138
ee8e71d4 18139@item target sim @r{[}@var{simargs}@r{]} @dots{}
4644b6e3 18140@cindex built-in simulator target
2df3850c 18141Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 18142In general,
474c8240 18143@smallexample
104c1213
JM
18144 target sim
18145 load
18146 run
474c8240 18147@end smallexample
d4f3574e 18148@noindent
104c1213 18149works; however, you cannot assume that a specific memory map, device
d4f3574e 18150drivers, or even basic I/O is available, although some simulators do
104c1213
JM
18151provide these. For info about any processor-specific simulator details,
18152see the appropriate section in @ref{Embedded Processors, ,Embedded
18153Processors}.
18154
6a3cb8e8
PA
18155@item target native
18156@cindex native target
18157Setup for local/native process debugging. Useful to make the
18158@code{run} command spawn native processes (likewise @code{attach},
18159etc.@:) even when @code{set auto-connect-native-target} is @code{off}
18160(@pxref{set auto-connect-native-target}).
18161
c906108c
SS
18162@end table
18163
5d161b24 18164Different targets are available on different configurations of @value{GDBN};
c906108c 18165your configuration may have more or fewer targets.
c906108c 18166
721c2651
EZ
18167Many remote targets require you to download the executable's code once
18168you've successfully established a connection. You may wish to control
3d00d119
DJ
18169various aspects of this process.
18170
18171@table @code
721c2651
EZ
18172
18173@item set hash
18174@kindex set hash@r{, for remote monitors}
18175@cindex hash mark while downloading
18176This command controls whether a hash mark @samp{#} is displayed while
18177downloading a file to the remote monitor. If on, a hash mark is
18178displayed after each S-record is successfully downloaded to the
18179monitor.
18180
18181@item show hash
18182@kindex show hash@r{, for remote monitors}
18183Show the current status of displaying the hash mark.
18184
18185@item set debug monitor
18186@kindex set debug monitor
18187@cindex display remote monitor communications
18188Enable or disable display of communications messages between
18189@value{GDBN} and the remote monitor.
18190
18191@item show debug monitor
18192@kindex show debug monitor
18193Show the current status of displaying communications between
18194@value{GDBN} and the remote monitor.
a8f24a35 18195@end table
c906108c
SS
18196
18197@table @code
18198
18199@kindex load @var{filename}
18200@item load @var{filename}
8edfe269 18201@anchor{load}
c906108c
SS
18202Depending on what remote debugging facilities are configured into
18203@value{GDBN}, the @code{load} command may be available. Where it exists, it
18204is meant to make @var{filename} (an executable) available for debugging
18205on the remote system---by downloading, or dynamic linking, for example.
18206@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
18207the @code{add-symbol-file} command.
18208
18209If your @value{GDBN} does not have a @code{load} command, attempting to
18210execute it gets the error message ``@code{You can't do that when your
18211target is @dots{}}''
c906108c
SS
18212
18213The file is loaded at whatever address is specified in the executable.
18214For some object file formats, you can specify the load address when you
18215link the program; for other formats, like a.out, the object file format
18216specifies a fixed address.
18217@c FIXME! This would be a good place for an xref to the GNU linker doc.
18218
68437a39
DJ
18219Depending on the remote side capabilities, @value{GDBN} may be able to
18220load programs into flash memory.
18221
c906108c
SS
18222@code{load} does not repeat if you press @key{RET} again after using it.
18223@end table
18224
6d2ebf8b 18225@node Byte Order
79a6e687 18226@section Choosing Target Byte Order
7a292a7a 18227
c906108c
SS
18228@cindex choosing target byte order
18229@cindex target byte order
c906108c 18230
eb17f351 18231Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
c906108c
SS
18232offer the ability to run either big-endian or little-endian byte
18233orders. Usually the executable or symbol will include a bit to
18234designate the endian-ness, and you will not need to worry about
18235which to use. However, you may still find it useful to adjust
d4f3574e 18236@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
18237
18238@table @code
4644b6e3 18239@kindex set endian
c906108c
SS
18240@item set endian big
18241Instruct @value{GDBN} to assume the target is big-endian.
18242
c906108c
SS
18243@item set endian little
18244Instruct @value{GDBN} to assume the target is little-endian.
18245
c906108c
SS
18246@item set endian auto
18247Instruct @value{GDBN} to use the byte order associated with the
18248executable.
18249
18250@item show endian
18251Display @value{GDBN}'s current idea of the target byte order.
18252
18253@end table
18254
18255Note that these commands merely adjust interpretation of symbolic
18256data on the host, and that they have absolutely no effect on the
18257target system.
18258
ea35711c
DJ
18259
18260@node Remote Debugging
18261@chapter Debugging Remote Programs
c906108c
SS
18262@cindex remote debugging
18263
18264If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
18265@value{GDBN} in the usual way, it is often useful to use remote debugging.
18266For example, you might use remote debugging on an operating system kernel,
c906108c
SS
18267or on a small system which does not have a general purpose operating system
18268powerful enough to run a full-featured debugger.
18269
18270Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
18271to make this work with particular debugging targets. In addition,
5d161b24 18272@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
18273but not specific to any particular target system) which you can use if you
18274write the remote stubs---the code that runs on the remote system to
18275communicate with @value{GDBN}.
18276
18277Other remote targets may be available in your
18278configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 18279
6b2f586d 18280@menu
07f31aa6 18281* Connecting:: Connecting to a remote target
a6b151f1 18282* File Transfer:: Sending files to a remote system
6b2f586d 18283* Server:: Using the gdbserver program
79a6e687
BW
18284* Remote Configuration:: Remote configuration
18285* Remote Stub:: Implementing a remote stub
6b2f586d
AC
18286@end menu
18287
07f31aa6 18288@node Connecting
79a6e687 18289@section Connecting to a Remote Target
07f31aa6
DJ
18290
18291On the @value{GDBN} host machine, you will need an unstripped copy of
d3e8051b 18292your program, since @value{GDBN} needs symbol and debugging information.
07f31aa6
DJ
18293Start up @value{GDBN} as usual, using the name of the local copy of your
18294program as the first argument.
18295
86941c27
JB
18296@cindex @code{target remote}
18297@value{GDBN} can communicate with the target over a serial line, or
18298over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
18299each case, @value{GDBN} uses the same protocol for debugging your
18300program; only the medium carrying the debugging packets varies. The
18301@code{target remote} command establishes a connection to the target.
18302Its arguments indicate which medium to use:
18303
18304@table @code
18305
18306@item target remote @var{serial-device}
07f31aa6 18307@cindex serial line, @code{target remote}
86941c27
JB
18308Use @var{serial-device} to communicate with the target. For example,
18309to use a serial line connected to the device named @file{/dev/ttyb}:
18310
18311@smallexample
18312target remote /dev/ttyb
18313@end smallexample
18314
07f31aa6 18315If you're using a serial line, you may want to give @value{GDBN} the
2446f5ea 18316@samp{--baud} option, or use the @code{set serial baud} command
0d12017b 18317(@pxref{Remote Configuration, set serial baud}) before the
9c16f35a 18318@code{target} command.
07f31aa6 18319
86941c27
JB
18320@item target remote @code{@var{host}:@var{port}}
18321@itemx target remote @code{tcp:@var{host}:@var{port}}
18322@cindex @acronym{TCP} port, @code{target remote}
18323Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
18324The @var{host} may be either a host name or a numeric @acronym{IP}
18325address; @var{port} must be a decimal number. The @var{host} could be
18326the target machine itself, if it is directly connected to the net, or
18327it might be a terminal server which in turn has a serial line to the
18328target.
07f31aa6 18329
86941c27
JB
18330For example, to connect to port 2828 on a terminal server named
18331@code{manyfarms}:
07f31aa6
DJ
18332
18333@smallexample
18334target remote manyfarms:2828
18335@end smallexample
18336
86941c27
JB
18337If your remote target is actually running on the same machine as your
18338debugger session (e.g.@: a simulator for your target running on the
18339same host), you can omit the hostname. For example, to connect to
18340port 1234 on your local machine:
07f31aa6
DJ
18341
18342@smallexample
18343target remote :1234
18344@end smallexample
18345@noindent
18346
18347Note that the colon is still required here.
18348
86941c27
JB
18349@item target remote @code{udp:@var{host}:@var{port}}
18350@cindex @acronym{UDP} port, @code{target remote}
18351Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
18352connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
18353
18354@smallexample
18355target remote udp:manyfarms:2828
18356@end smallexample
18357
86941c27
JB
18358When using a @acronym{UDP} connection for remote debugging, you should
18359keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
18360can silently drop packets on busy or unreliable networks, which will
18361cause havoc with your debugging session.
18362
66b8c7f6
JB
18363@item target remote | @var{command}
18364@cindex pipe, @code{target remote} to
18365Run @var{command} in the background and communicate with it using a
18366pipe. The @var{command} is a shell command, to be parsed and expanded
18367by the system's command shell, @code{/bin/sh}; it should expect remote
18368protocol packets on its standard input, and send replies on its
18369standard output. You could use this to run a stand-alone simulator
18370that speaks the remote debugging protocol, to make net connections
18371using programs like @code{ssh}, or for other similar tricks.
18372
18373If @var{command} closes its standard output (perhaps by exiting),
18374@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
18375program has already exited, this will have no effect.)
18376
86941c27 18377@end table
07f31aa6 18378
86941c27 18379Once the connection has been established, you can use all the usual
8edfe269
DJ
18380commands to examine and change data. The remote program is already
18381running; you can use @kbd{step} and @kbd{continue}, and you do not
18382need to use @kbd{run}.
07f31aa6
DJ
18383
18384@cindex interrupting remote programs
18385@cindex remote programs, interrupting
18386Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 18387interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
18388program. This may or may not succeed, depending in part on the hardware
18389and the serial drivers the remote system uses. If you type the
18390interrupt character once again, @value{GDBN} displays this prompt:
18391
18392@smallexample
18393Interrupted while waiting for the program.
18394Give up (and stop debugging it)? (y or n)
18395@end smallexample
18396
18397If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
18398(If you decide you want to try again later, you can use @samp{target
18399remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
18400goes back to waiting.
18401
18402@table @code
18403@kindex detach (remote)
18404@item detach
18405When you have finished debugging the remote program, you can use the
18406@code{detach} command to release it from @value{GDBN} control.
18407Detaching from the target normally resumes its execution, but the results
18408will depend on your particular remote stub. After the @code{detach}
18409command, @value{GDBN} is free to connect to another target.
18410
18411@kindex disconnect
18412@item disconnect
18413The @code{disconnect} command behaves like @code{detach}, except that
18414the target is generally not resumed. It will wait for @value{GDBN}
18415(this instance or another one) to connect and continue debugging. After
18416the @code{disconnect} command, @value{GDBN} is again free to connect to
18417another target.
09d4efe1
EZ
18418
18419@cindex send command to remote monitor
fad38dfa
EZ
18420@cindex extend @value{GDBN} for remote targets
18421@cindex add new commands for external monitor
09d4efe1
EZ
18422@kindex monitor
18423@item monitor @var{cmd}
fad38dfa
EZ
18424This command allows you to send arbitrary commands directly to the
18425remote monitor. Since @value{GDBN} doesn't care about the commands it
18426sends like this, this command is the way to extend @value{GDBN}---you
18427can add new commands that only the external monitor will understand
18428and implement.
07f31aa6
DJ
18429@end table
18430
a6b151f1
DJ
18431@node File Transfer
18432@section Sending files to a remote system
18433@cindex remote target, file transfer
18434@cindex file transfer
18435@cindex sending files to remote systems
18436
18437Some remote targets offer the ability to transfer files over the same
18438connection used to communicate with @value{GDBN}. This is convenient
18439for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
18440running @code{gdbserver} over a network interface. For other targets,
18441e.g.@: embedded devices with only a single serial port, this may be
18442the only way to upload or download files.
18443
18444Not all remote targets support these commands.
18445
18446@table @code
18447@kindex remote put
18448@item remote put @var{hostfile} @var{targetfile}
18449Copy file @var{hostfile} from the host system (the machine running
18450@value{GDBN}) to @var{targetfile} on the target system.
18451
18452@kindex remote get
18453@item remote get @var{targetfile} @var{hostfile}
18454Copy file @var{targetfile} from the target system to @var{hostfile}
18455on the host system.
18456
18457@kindex remote delete
18458@item remote delete @var{targetfile}
18459Delete @var{targetfile} from the target system.
18460
18461@end table
18462
6f05cf9f 18463@node Server
79a6e687 18464@section Using the @code{gdbserver} Program
6f05cf9f
AC
18465
18466@kindex gdbserver
18467@cindex remote connection without stubs
18468@code{gdbserver} is a control program for Unix-like systems, which
18469allows you to connect your program with a remote @value{GDBN} via
18470@code{target remote}---but without linking in the usual debugging stub.
18471
18472@code{gdbserver} is not a complete replacement for the debugging stubs,
18473because it requires essentially the same operating-system facilities
18474that @value{GDBN} itself does. In fact, a system that can run
18475@code{gdbserver} to connect to a remote @value{GDBN} could also run
18476@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
18477because it is a much smaller program than @value{GDBN} itself. It is
18478also easier to port than all of @value{GDBN}, so you may be able to get
18479started more quickly on a new system by using @code{gdbserver}.
18480Finally, if you develop code for real-time systems, you may find that
18481the tradeoffs involved in real-time operation make it more convenient to
18482do as much development work as possible on another system, for example
18483by cross-compiling. You can use @code{gdbserver} to make a similar
18484choice for debugging.
18485
18486@value{GDBN} and @code{gdbserver} communicate via either a serial line
18487or a TCP connection, using the standard @value{GDBN} remote serial
18488protocol.
18489
2d717e4f
DJ
18490@quotation
18491@emph{Warning:} @code{gdbserver} does not have any built-in security.
18492Do not run @code{gdbserver} connected to any public network; a
18493@value{GDBN} connection to @code{gdbserver} provides access to the
18494target system with the same privileges as the user running
18495@code{gdbserver}.
18496@end quotation
18497
18498@subsection Running @code{gdbserver}
18499@cindex arguments, to @code{gdbserver}
d9b1a651 18500@cindex @code{gdbserver}, command-line arguments
2d717e4f
DJ
18501
18502Run @code{gdbserver} on the target system. You need a copy of the
18503program you want to debug, including any libraries it requires.
6f05cf9f
AC
18504@code{gdbserver} does not need your program's symbol table, so you can
18505strip the program if necessary to save space. @value{GDBN} on the host
18506system does all the symbol handling.
18507
18508To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 18509the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
18510syntax is:
18511
18512@smallexample
18513target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
18514@end smallexample
18515
e0f9f062
DE
18516@var{comm} is either a device name (to use a serial line), or a TCP
18517hostname and portnumber, or @code{-} or @code{stdio} to use
18518stdin/stdout of @code{gdbserver}.
18519For example, to debug Emacs with the argument
6f05cf9f
AC
18520@samp{foo.txt} and communicate with @value{GDBN} over the serial port
18521@file{/dev/com1}:
18522
18523@smallexample
18524target> gdbserver /dev/com1 emacs foo.txt
18525@end smallexample
18526
18527@code{gdbserver} waits passively for the host @value{GDBN} to communicate
18528with it.
18529
18530To use a TCP connection instead of a serial line:
18531
18532@smallexample
18533target> gdbserver host:2345 emacs foo.txt
18534@end smallexample
18535
18536The only difference from the previous example is the first argument,
18537specifying that you are communicating with the host @value{GDBN} via
18538TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
18539expect a TCP connection from machine @samp{host} to local TCP port 2345.
18540(Currently, the @samp{host} part is ignored.) You can choose any number
18541you want for the port number as long as it does not conflict with any
18542TCP ports already in use on the target system (for example, @code{23} is
18543reserved for @code{telnet}).@footnote{If you choose a port number that
18544conflicts with another service, @code{gdbserver} prints an error message
18545and exits.} You must use the same port number with the host @value{GDBN}
18546@code{target remote} command.
18547
e0f9f062
DE
18548The @code{stdio} connection is useful when starting @code{gdbserver}
18549with ssh:
18550
18551@smallexample
18552(gdb) target remote | ssh -T hostname gdbserver - hello
18553@end smallexample
18554
18555The @samp{-T} option to ssh is provided because we don't need a remote pty,
18556and we don't want escape-character handling. Ssh does this by default when
18557a command is provided, the flag is provided to make it explicit.
18558You could elide it if you want to.
18559
18560Programs started with stdio-connected gdbserver have @file{/dev/null} for
18561@code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
18562display through a pipe connected to gdbserver.
18563Both @code{stdout} and @code{stderr} use the same pipe.
18564
2d717e4f 18565@subsubsection Attaching to a Running Program
d9b1a651
EZ
18566@cindex attach to a program, @code{gdbserver}
18567@cindex @option{--attach}, @code{gdbserver} option
2d717e4f 18568
56460a61
DJ
18569On some targets, @code{gdbserver} can also attach to running programs.
18570This is accomplished via the @code{--attach} argument. The syntax is:
18571
18572@smallexample
2d717e4f 18573target> gdbserver --attach @var{comm} @var{pid}
56460a61
DJ
18574@end smallexample
18575
18576@var{pid} is the process ID of a currently running process. It isn't necessary
18577to point @code{gdbserver} at a binary for the running process.
18578
b1fe9455 18579@pindex pidof
b1fe9455
DJ
18580You can debug processes by name instead of process ID if your target has the
18581@code{pidof} utility:
18582
18583@smallexample
2d717e4f 18584target> gdbserver --attach @var{comm} `pidof @var{program}`
b1fe9455
DJ
18585@end smallexample
18586
f822c95b 18587In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
18588has multiple threads, most versions of @code{pidof} support the
18589@code{-s} option to only return the first process ID.
18590
2d717e4f 18591@subsubsection Multi-Process Mode for @code{gdbserver}
d9b1a651
EZ
18592@cindex @code{gdbserver}, multiple processes
18593@cindex multiple processes with @code{gdbserver}
2d717e4f
DJ
18594
18595When you connect to @code{gdbserver} using @code{target remote},
18596@code{gdbserver} debugs the specified program only once. When the
18597program exits, or you detach from it, @value{GDBN} closes the connection
18598and @code{gdbserver} exits.
18599
6e6c6f50 18600If you connect using @kbd{target extended-remote}, @code{gdbserver}
2d717e4f
DJ
18601enters multi-process mode. When the debugged program exits, or you
18602detach from it, @value{GDBN} stays connected to @code{gdbserver} even
18603though no program is running. The @code{run} and @code{attach}
18604commands instruct @code{gdbserver} to run or attach to a new program.
18605The @code{run} command uses @code{set remote exec-file} (@pxref{set
18606remote exec-file}) to select the program to run. Command line
18607arguments are supported, except for wildcard expansion and I/O
18608redirection (@pxref{Arguments}).
18609
d9b1a651 18610@cindex @option{--multi}, @code{gdbserver} option
2d717e4f
DJ
18611To start @code{gdbserver} without supplying an initial command to run
18612or process ID to attach, use the @option{--multi} command line option.
6e6c6f50 18613Then you can connect using @kbd{target extended-remote} and start
2d717e4f
DJ
18614the program you want to debug.
18615
03f2bd59
JK
18616In multi-process mode @code{gdbserver} does not automatically exit unless you
18617use the option @option{--once}. You can terminate it by using
18618@code{monitor exit} (@pxref{Monitor Commands for gdbserver}). Note that the
18619conditions under which @code{gdbserver} terminates depend on how @value{GDBN}
18620connects to it (@kbd{target remote} or @kbd{target extended-remote}). The
18621@option{--multi} option to @code{gdbserver} has no influence on that.
18622
18623@subsubsection TCP port allocation lifecycle of @code{gdbserver}
18624
18625This section applies only when @code{gdbserver} is run to listen on a TCP port.
18626
18627@code{gdbserver} normally terminates after all of its debugged processes have
18628terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
18629extended-remote}, @code{gdbserver} stays running even with no processes left.
18630@value{GDBN} normally terminates the spawned debugged process on its exit,
18631which normally also terminates @code{gdbserver} in the @kbd{target remote}
18632mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
18633cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
18634stays running even in the @kbd{target remote} mode.
18635
18636When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
18637Such reconnecting is useful for features like @ref{disconnected tracing}. For
18638completeness, at most one @value{GDBN} can be connected at a time.
18639
18640@cindex @option{--once}, @code{gdbserver} option
18641By default, @code{gdbserver} keeps the listening TCP port open, so that
6e8c5661 18642subsequent connections are possible. However, if you start @code{gdbserver}
03f2bd59
JK
18643with the @option{--once} option, it will stop listening for any further
18644connection attempts after connecting to the first @value{GDBN} session. This
18645means no further connections to @code{gdbserver} will be possible after the
18646first one. It also means @code{gdbserver} will terminate after the first
18647connection with remote @value{GDBN} has closed, even for unexpectedly closed
18648connections and even in the @kbd{target extended-remote} mode. The
18649@option{--once} option allows reusing the same port number for connecting to
18650multiple instances of @code{gdbserver} running on the same host, since each
18651instance closes its port after the first connection.
2d717e4f 18652
87ce2a04 18653@anchor{Other Command-Line Arguments for gdbserver}
2d717e4f
DJ
18654@subsubsection Other Command-Line Arguments for @code{gdbserver}
18655
d9b1a651 18656@cindex @option{--debug}, @code{gdbserver} option
62709adf 18657The @option{--debug} option tells @code{gdbserver} to display extra
d9b1a651
EZ
18658status information about the debugging process.
18659@cindex @option{--remote-debug}, @code{gdbserver} option
18660The @option{--remote-debug} option tells @code{gdbserver} to display
62709adf
PA
18661remote protocol debug output. These options are intended for
18662@code{gdbserver} development and for bug reports to the developers.
2d717e4f 18663
87ce2a04
DE
18664@cindex @option{--debug-format}, @code{gdbserver} option
18665The @option{--debug-format=option1[,option2,...]} option tells
18666@code{gdbserver} to include additional information in each output.
18667Possible options are:
18668
18669@table @code
18670@item none
18671Turn off all extra information in debugging output.
18672@item all
18673Turn on all extra information in debugging output.
18674@item timestamps
18675Include a timestamp in each line of debugging output.
18676@end table
18677
18678Options are processed in order. Thus, for example, if @option{none}
18679appears last then no additional information is added to debugging output.
18680
d9b1a651 18681@cindex @option{--wrapper}, @code{gdbserver} option
ccd213ac
DJ
18682The @option{--wrapper} option specifies a wrapper to launch programs
18683for debugging. The option should be followed by the name of the
18684wrapper, then any command-line arguments to pass to the wrapper, then
18685@kbd{--} indicating the end of the wrapper arguments.
18686
18687@code{gdbserver} runs the specified wrapper program with a combined
18688command line including the wrapper arguments, then the name of the
18689program to debug, then any arguments to the program. The wrapper
18690runs until it executes your program, and then @value{GDBN} gains control.
18691
18692You can use any program that eventually calls @code{execve} with
18693its arguments as a wrapper. Several standard Unix utilities do
18694this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
18695with @code{exec "$@@"} will also work.
18696
18697For example, you can use @code{env} to pass an environment variable to
18698the debugged program, without setting the variable in @code{gdbserver}'s
18699environment:
18700
18701@smallexample
18702$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
18703@end smallexample
18704
2d717e4f
DJ
18705@subsection Connecting to @code{gdbserver}
18706
18707Run @value{GDBN} on the host system.
18708
18709First make sure you have the necessary symbol files. Load symbols for
f822c95b
DJ
18710your application using the @code{file} command before you connect. Use
18711@code{set sysroot} to locate target libraries (unless your @value{GDBN}
2d717e4f 18712was compiled with the correct sysroot using @code{--with-sysroot}).
f822c95b
DJ
18713
18714The symbol file and target libraries must exactly match the executable
18715and libraries on the target, with one exception: the files on the host
18716system should not be stripped, even if the files on the target system
18717are. Mismatched or missing files will lead to confusing results
18718during debugging. On @sc{gnu}/Linux targets, mismatched or missing
18719files may also prevent @code{gdbserver} from debugging multi-threaded
18720programs.
18721
79a6e687 18722Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f
AC
18723For TCP connections, you must start up @code{gdbserver} prior to using
18724the @code{target remote} command. Otherwise you may get an error whose
18725text depends on the host system, but which usually looks something like
2d717e4f 18726@samp{Connection refused}. Don't use the @code{load}
397ca115 18727command in @value{GDBN} when using @code{gdbserver}, since the program is
f822c95b 18728already on the target.
07f31aa6 18729
79a6e687 18730@subsection Monitor Commands for @code{gdbserver}
c74d0ad8 18731@cindex monitor commands, for @code{gdbserver}
2d717e4f 18732@anchor{Monitor Commands for gdbserver}
c74d0ad8
DJ
18733
18734During a @value{GDBN} session using @code{gdbserver}, you can use the
18735@code{monitor} command to send special requests to @code{gdbserver}.
2d717e4f 18736Here are the available commands.
c74d0ad8
DJ
18737
18738@table @code
18739@item monitor help
18740List the available monitor commands.
18741
18742@item monitor set debug 0
18743@itemx monitor set debug 1
18744Disable or enable general debugging messages.
18745
18746@item monitor set remote-debug 0
18747@itemx monitor set remote-debug 1
18748Disable or enable specific debugging messages associated with the remote
18749protocol (@pxref{Remote Protocol}).
18750
87ce2a04
DE
18751@item monitor set debug-format option1@r{[},option2,...@r{]}
18752Specify additional text to add to debugging messages.
18753Possible options are:
18754
18755@table @code
18756@item none
18757Turn off all extra information in debugging output.
18758@item all
18759Turn on all extra information in debugging output.
18760@item timestamps
18761Include a timestamp in each line of debugging output.
18762@end table
18763
18764Options are processed in order. Thus, for example, if @option{none}
18765appears last then no additional information is added to debugging output.
18766
cdbfd419
PP
18767@item monitor set libthread-db-search-path [PATH]
18768@cindex gdbserver, search path for @code{libthread_db}
18769When this command is issued, @var{path} is a colon-separated list of
18770directories to search for @code{libthread_db} (@pxref{Threads,,set
18771libthread-db-search-path}). If you omit @var{path},
84e578fb 18772@samp{libthread-db-search-path} will be reset to its default value.
cdbfd419 18773
98a5dd13
DE
18774The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
18775not supported in @code{gdbserver}.
18776
2d717e4f
DJ
18777@item monitor exit
18778Tell gdbserver to exit immediately. This command should be followed by
18779@code{disconnect} to close the debugging session. @code{gdbserver} will
18780detach from any attached processes and kill any processes it created.
18781Use @code{monitor exit} to terminate @code{gdbserver} at the end
18782of a multi-process mode debug session.
18783
c74d0ad8
DJ
18784@end table
18785
fa593d66
PA
18786@subsection Tracepoints support in @code{gdbserver}
18787@cindex tracepoints support in @code{gdbserver}
18788
0fb4aa4b
PA
18789On some targets, @code{gdbserver} supports tracepoints, fast
18790tracepoints and static tracepoints.
fa593d66 18791
0fb4aa4b 18792For fast or static tracepoints to work, a special library called the
fa593d66
PA
18793@dfn{in-process agent} (IPA), must be loaded in the inferior process.
18794This library is built and distributed as an integral part of
0fb4aa4b
PA
18795@code{gdbserver}. In addition, support for static tracepoints
18796requires building the in-process agent library with static tracepoints
18797support. At present, the UST (LTTng Userspace Tracer,
18798@url{http://lttng.org/ust}) tracing engine is supported. This support
18799is automatically available if UST development headers are found in the
18800standard include path when @code{gdbserver} is built, or if
18801@code{gdbserver} was explicitly configured using @option{--with-ust}
18802to point at such headers. You can explicitly disable the support
18803using @option{--with-ust=no}.
fa593d66
PA
18804
18805There are several ways to load the in-process agent in your program:
18806
18807@table @code
18808@item Specifying it as dependency at link time
18809
18810You can link your program dynamically with the in-process agent
18811library. On most systems, this is accomplished by adding
18812@code{-linproctrace} to the link command.
18813
18814@item Using the system's preloading mechanisms
18815
18816You can force loading the in-process agent at startup time by using
18817your system's support for preloading shared libraries. Many Unixes
18818support the concept of preloading user defined libraries. In most
18819cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
18820in the environment. See also the description of @code{gdbserver}'s
18821@option{--wrapper} command line option.
18822
18823@item Using @value{GDBN} to force loading the agent at run time
18824
18825On some systems, you can force the inferior to load a shared library,
18826by calling a dynamic loader function in the inferior that takes care
18827of dynamically looking up and loading a shared library. On most Unix
18828systems, the function is @code{dlopen}. You'll use the @code{call}
18829command for that. For example:
18830
18831@smallexample
18832(@value{GDBP}) call dlopen ("libinproctrace.so", ...)
18833@end smallexample
18834
18835Note that on most Unix systems, for the @code{dlopen} function to be
18836available, the program needs to be linked with @code{-ldl}.
18837@end table
18838
18839On systems that have a userspace dynamic loader, like most Unix
18840systems, when you connect to @code{gdbserver} using @code{target
18841remote}, you'll find that the program is stopped at the dynamic
18842loader's entry point, and no shared library has been loaded in the
18843program's address space yet, including the in-process agent. In that
0fb4aa4b
PA
18844case, before being able to use any of the fast or static tracepoints
18845features, you need to let the loader run and load the shared
18846libraries. The simplest way to do that is to run the program to the
18847main procedure. E.g., if debugging a C or C@t{++} program, start
fa593d66
PA
18848@code{gdbserver} like so:
18849
18850@smallexample
18851$ gdbserver :9999 myprogram
18852@end smallexample
18853
18854Start GDB and connect to @code{gdbserver} like so, and run to main:
18855
18856@smallexample
18857$ gdb myprogram
18858(@value{GDBP}) target remote myhost:9999
188590x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
18860(@value{GDBP}) b main
18861(@value{GDBP}) continue
18862@end smallexample
18863
18864The in-process tracing agent library should now be loaded into the
18865process; you can confirm it with the @code{info sharedlibrary}
18866command, which will list @file{libinproctrace.so} as loaded in the
0fb4aa4b
PA
18867process. You are now ready to install fast tracepoints, list static
18868tracepoint markers, probe static tracepoints markers, and start
fa593d66
PA
18869tracing.
18870
79a6e687
BW
18871@node Remote Configuration
18872@section Remote Configuration
501eef12 18873
9c16f35a
EZ
18874@kindex set remote
18875@kindex show remote
18876This section documents the configuration options available when
18877debugging remote programs. For the options related to the File I/O
fc320d37 18878extensions of the remote protocol, see @ref{system,
9c16f35a 18879system-call-allowed}.
501eef12
AC
18880
18881@table @code
9c16f35a 18882@item set remoteaddresssize @var{bits}
d3e8051b 18883@cindex address size for remote targets
9c16f35a
EZ
18884@cindex bits in remote address
18885Set the maximum size of address in a memory packet to the specified
18886number of bits. @value{GDBN} will mask off the address bits above
18887that number, when it passes addresses to the remote target. The
18888default value is the number of bits in the target's address.
18889
18890@item show remoteaddresssize
18891Show the current value of remote address size in bits.
18892
0d12017b 18893@item set serial baud @var{n}
9c16f35a
EZ
18894@cindex baud rate for remote targets
18895Set the baud rate for the remote serial I/O to @var{n} baud. The
18896value is used to set the speed of the serial port used for debugging
18897remote targets.
18898
0d12017b 18899@item show serial baud
9c16f35a
EZ
18900Show the current speed of the remote connection.
18901
18902@item set remotebreak
18903@cindex interrupt remote programs
18904@cindex BREAK signal instead of Ctrl-C
9a6253be 18905@anchor{set remotebreak}
9c16f35a 18906If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 18907when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 18908on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
18909character instead. The default is off, since most remote systems
18910expect to see @samp{Ctrl-C} as the interrupt signal.
18911
18912@item show remotebreak
18913Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
18914interrupt the remote program.
18915
23776285
MR
18916@item set remoteflow on
18917@itemx set remoteflow off
18918@kindex set remoteflow
18919Enable or disable hardware flow control (@code{RTS}/@code{CTS})
18920on the serial port used to communicate to the remote target.
18921
18922@item show remoteflow
18923@kindex show remoteflow
18924Show the current setting of hardware flow control.
18925
9c16f35a
EZ
18926@item set remotelogbase @var{base}
18927Set the base (a.k.a.@: radix) of logging serial protocol
18928communications to @var{base}. Supported values of @var{base} are:
18929@code{ascii}, @code{octal}, and @code{hex}. The default is
18930@code{ascii}.
18931
18932@item show remotelogbase
18933Show the current setting of the radix for logging remote serial
18934protocol.
18935
18936@item set remotelogfile @var{file}
18937@cindex record serial communications on file
18938Record remote serial communications on the named @var{file}. The
18939default is not to record at all.
18940
18941@item show remotelogfile.
18942Show the current setting of the file name on which to record the
18943serial communications.
18944
18945@item set remotetimeout @var{num}
18946@cindex timeout for serial communications
18947@cindex remote timeout
18948Set the timeout limit to wait for the remote target to respond to
18949@var{num} seconds. The default is 2 seconds.
18950
18951@item show remotetimeout
18952Show the current number of seconds to wait for the remote target
18953responses.
18954
18955@cindex limit hardware breakpoints and watchpoints
18956@cindex remote target, limit break- and watchpoints
501eef12
AC
18957@anchor{set remote hardware-watchpoint-limit}
18958@anchor{set remote hardware-breakpoint-limit}
18959@item set remote hardware-watchpoint-limit @var{limit}
18960@itemx set remote hardware-breakpoint-limit @var{limit}
18961Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
18962watchpoints. A limit of -1, the default, is treated as unlimited.
2d717e4f 18963
480a3f21
PW
18964@cindex limit hardware watchpoints length
18965@cindex remote target, limit watchpoints length
18966@anchor{set remote hardware-watchpoint-length-limit}
18967@item set remote hardware-watchpoint-length-limit @var{limit}
18968Restrict @value{GDBN} to using @var{limit} bytes for the maximum length of
18969a remote hardware watchpoint. A limit of -1, the default, is treated
18970as unlimited.
18971
18972@item show remote hardware-watchpoint-length-limit
18973Show the current limit (in bytes) of the maximum length of
18974a remote hardware watchpoint.
18975
2d717e4f
DJ
18976@item set remote exec-file @var{filename}
18977@itemx show remote exec-file
18978@anchor{set remote exec-file}
18979@cindex executable file, for remote target
18980Select the file used for @code{run} with @code{target
18981extended-remote}. This should be set to a filename valid on the
18982target system. If it is not set, the target will use a default
18983filename (e.g.@: the last program run).
84603566 18984
9a7071a8
JB
18985@item set remote interrupt-sequence
18986@cindex interrupt remote programs
18987@cindex select Ctrl-C, BREAK or BREAK-g
18988Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
18989@samp{BREAK-g} as the
18990sequence to the remote target in order to interrupt the execution.
18991@samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
18992is high level of serial line for some certain time.
18993Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
18994It is @code{BREAK} signal followed by character @code{g}.
18995
18996@item show interrupt-sequence
18997Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
18998is sent by @value{GDBN} to interrupt the remote program.
18999@code{BREAK-g} is BREAK signal followed by @code{g} and
19000also known as Magic SysRq g.
19001
19002@item set remote interrupt-on-connect
19003@cindex send interrupt-sequence on start
19004Specify whether interrupt-sequence is sent to remote target when
19005@value{GDBN} connects to it. This is mostly needed when you debug
19006Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
19007which is known as Magic SysRq g in order to connect @value{GDBN}.
19008
19009@item show interrupt-on-connect
19010Show whether interrupt-sequence is sent
19011to remote target when @value{GDBN} connects to it.
19012
84603566
SL
19013@kindex set tcp
19014@kindex show tcp
19015@item set tcp auto-retry on
19016@cindex auto-retry, for remote TCP target
19017Enable auto-retry for remote TCP connections. This is useful if the remote
19018debugging agent is launched in parallel with @value{GDBN}; there is a race
19019condition because the agent may not become ready to accept the connection
19020before @value{GDBN} attempts to connect. When auto-retry is
19021enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
19022to establish the connection using the timeout specified by
19023@code{set tcp connect-timeout}.
19024
19025@item set tcp auto-retry off
19026Do not auto-retry failed TCP connections.
19027
19028@item show tcp auto-retry
19029Show the current auto-retry setting.
19030
19031@item set tcp connect-timeout @var{seconds}
f81d1120 19032@itemx set tcp connect-timeout unlimited
84603566
SL
19033@cindex connection timeout, for remote TCP target
19034@cindex timeout, for remote target connection
19035Set the timeout for establishing a TCP connection to the remote target to
19036@var{seconds}. The timeout affects both polling to retry failed connections
19037(enabled by @code{set tcp auto-retry on}) and waiting for connections
19038that are merely slow to complete, and represents an approximate cumulative
f81d1120
PA
19039value. If @var{seconds} is @code{unlimited}, there is no timeout and
19040@value{GDBN} will keep attempting to establish a connection forever,
19041unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
84603566
SL
19042
19043@item show tcp connect-timeout
19044Show the current connection timeout setting.
501eef12
AC
19045@end table
19046
427c3a89
DJ
19047@cindex remote packets, enabling and disabling
19048The @value{GDBN} remote protocol autodetects the packets supported by
19049your debugging stub. If you need to override the autodetection, you
19050can use these commands to enable or disable individual packets. Each
19051packet can be set to @samp{on} (the remote target supports this
19052packet), @samp{off} (the remote target does not support this packet),
19053or @samp{auto} (detect remote target support for this packet). They
19054all default to @samp{auto}. For more information about each packet,
19055see @ref{Remote Protocol}.
19056
19057During normal use, you should not have to use any of these commands.
19058If you do, that may be a bug in your remote debugging stub, or a bug
19059in @value{GDBN}. You may want to report the problem to the
19060@value{GDBN} developers.
19061
cfa9d6d9
DJ
19062For each packet @var{name}, the command to enable or disable the
19063packet is @code{set remote @var{name}-packet}. The available settings
19064are:
427c3a89 19065
cfa9d6d9 19066@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
19067@item Command Name
19068@tab Remote Packet
19069@tab Related Features
19070
cfa9d6d9 19071@item @code{fetch-register}
427c3a89
DJ
19072@tab @code{p}
19073@tab @code{info registers}
19074
cfa9d6d9 19075@item @code{set-register}
427c3a89
DJ
19076@tab @code{P}
19077@tab @code{set}
19078
cfa9d6d9 19079@item @code{binary-download}
427c3a89
DJ
19080@tab @code{X}
19081@tab @code{load}, @code{set}
19082
cfa9d6d9 19083@item @code{read-aux-vector}
427c3a89
DJ
19084@tab @code{qXfer:auxv:read}
19085@tab @code{info auxv}
19086
cfa9d6d9 19087@item @code{symbol-lookup}
427c3a89
DJ
19088@tab @code{qSymbol}
19089@tab Detecting multiple threads
19090
2d717e4f
DJ
19091@item @code{attach}
19092@tab @code{vAttach}
19093@tab @code{attach}
19094
cfa9d6d9 19095@item @code{verbose-resume}
427c3a89
DJ
19096@tab @code{vCont}
19097@tab Stepping or resuming multiple threads
19098
2d717e4f
DJ
19099@item @code{run}
19100@tab @code{vRun}
19101@tab @code{run}
19102
cfa9d6d9 19103@item @code{software-breakpoint}
427c3a89
DJ
19104@tab @code{Z0}
19105@tab @code{break}
19106
cfa9d6d9 19107@item @code{hardware-breakpoint}
427c3a89
DJ
19108@tab @code{Z1}
19109@tab @code{hbreak}
19110
cfa9d6d9 19111@item @code{write-watchpoint}
427c3a89
DJ
19112@tab @code{Z2}
19113@tab @code{watch}
19114
cfa9d6d9 19115@item @code{read-watchpoint}
427c3a89
DJ
19116@tab @code{Z3}
19117@tab @code{rwatch}
19118
cfa9d6d9 19119@item @code{access-watchpoint}
427c3a89
DJ
19120@tab @code{Z4}
19121@tab @code{awatch}
19122
cfa9d6d9
DJ
19123@item @code{target-features}
19124@tab @code{qXfer:features:read}
19125@tab @code{set architecture}
19126
19127@item @code{library-info}
19128@tab @code{qXfer:libraries:read}
19129@tab @code{info sharedlibrary}
19130
19131@item @code{memory-map}
19132@tab @code{qXfer:memory-map:read}
19133@tab @code{info mem}
19134
0fb4aa4b
PA
19135@item @code{read-sdata-object}
19136@tab @code{qXfer:sdata:read}
19137@tab @code{print $_sdata}
19138
cfa9d6d9
DJ
19139@item @code{read-spu-object}
19140@tab @code{qXfer:spu:read}
19141@tab @code{info spu}
19142
19143@item @code{write-spu-object}
19144@tab @code{qXfer:spu:write}
19145@tab @code{info spu}
19146
4aa995e1
PA
19147@item @code{read-siginfo-object}
19148@tab @code{qXfer:siginfo:read}
19149@tab @code{print $_siginfo}
19150
19151@item @code{write-siginfo-object}
19152@tab @code{qXfer:siginfo:write}
19153@tab @code{set $_siginfo}
19154
dc146f7c
VP
19155@item @code{threads}
19156@tab @code{qXfer:threads:read}
19157@tab @code{info threads}
19158
cfa9d6d9 19159@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
19160@tab @code{qGetTLSAddr}
19161@tab Displaying @code{__thread} variables
19162
711e434b
PM
19163@item @code{get-thread-information-block-address}
19164@tab @code{qGetTIBAddr}
19165@tab Display MS-Windows Thread Information Block.
19166
08388c79
DE
19167@item @code{search-memory}
19168@tab @code{qSearch:memory}
19169@tab @code{find}
19170
427c3a89
DJ
19171@item @code{supported-packets}
19172@tab @code{qSupported}
19173@tab Remote communications parameters
19174
cfa9d6d9 19175@item @code{pass-signals}
89be2091
DJ
19176@tab @code{QPassSignals}
19177@tab @code{handle @var{signal}}
19178
9b224c5e
PA
19179@item @code{program-signals}
19180@tab @code{QProgramSignals}
19181@tab @code{handle @var{signal}}
19182
a6b151f1
DJ
19183@item @code{hostio-close-packet}
19184@tab @code{vFile:close}
19185@tab @code{remote get}, @code{remote put}
19186
19187@item @code{hostio-open-packet}
19188@tab @code{vFile:open}
19189@tab @code{remote get}, @code{remote put}
19190
19191@item @code{hostio-pread-packet}
19192@tab @code{vFile:pread}
19193@tab @code{remote get}, @code{remote put}
19194
19195@item @code{hostio-pwrite-packet}
19196@tab @code{vFile:pwrite}
19197@tab @code{remote get}, @code{remote put}
19198
19199@item @code{hostio-unlink-packet}
19200@tab @code{vFile:unlink}
19201@tab @code{remote delete}
a6f3e723 19202
b9e7b9c3
UW
19203@item @code{hostio-readlink-packet}
19204@tab @code{vFile:readlink}
19205@tab Host I/O
19206
a6f3e723
SL
19207@item @code{noack-packet}
19208@tab @code{QStartNoAckMode}
19209@tab Packet acknowledgment
07e059b5
VP
19210
19211@item @code{osdata}
19212@tab @code{qXfer:osdata:read}
19213@tab @code{info os}
0b16c5cf
PA
19214
19215@item @code{query-attached}
19216@tab @code{qAttached}
19217@tab Querying remote process attach state.
b3b9301e 19218
a46c1e42
PA
19219@item @code{trace-buffer-size}
19220@tab @code{QTBuffer:size}
19221@tab @code{set trace-buffer-size}
19222
bd3eecc3
PA
19223@item @code{trace-status}
19224@tab @code{qTStatus}
19225@tab @code{tstatus}
19226
b3b9301e
PA
19227@item @code{traceframe-info}
19228@tab @code{qXfer:traceframe-info:read}
19229@tab Traceframe info
03583c20 19230
1e4d1764
YQ
19231@item @code{install-in-trace}
19232@tab @code{InstallInTrace}
19233@tab Install tracepoint in tracing
19234
03583c20
UW
19235@item @code{disable-randomization}
19236@tab @code{QDisableRandomization}
19237@tab @code{set disable-randomization}
83364271
LM
19238
19239@item @code{conditional-breakpoints-packet}
19240@tab @code{Z0 and Z1}
19241@tab @code{Support for target-side breakpoint condition evaluation}
427c3a89
DJ
19242@end multitable
19243
79a6e687
BW
19244@node Remote Stub
19245@section Implementing a Remote Stub
7a292a7a 19246
8e04817f
AC
19247@cindex debugging stub, example
19248@cindex remote stub, example
19249@cindex stub example, remote debugging
19250The stub files provided with @value{GDBN} implement the target side of the
19251communication protocol, and the @value{GDBN} side is implemented in the
19252@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
19253these subroutines to communicate, and ignore the details. (If you're
19254implementing your own stub file, you can still ignore the details: start
19255with one of the existing stub files. @file{sparc-stub.c} is the best
19256organized, and therefore the easiest to read.)
19257
104c1213
JM
19258@cindex remote serial debugging, overview
19259To debug a program running on another machine (the debugging
19260@dfn{target} machine), you must first arrange for all the usual
19261prerequisites for the program to run by itself. For example, for a C
19262program, you need:
c906108c 19263
104c1213
JM
19264@enumerate
19265@item
19266A startup routine to set up the C runtime environment; these usually
19267have a name like @file{crt0}. The startup routine may be supplied by
19268your hardware supplier, or you may have to write your own.
96baa820 19269
5d161b24 19270@item
d4f3574e 19271A C subroutine library to support your program's
104c1213 19272subroutine calls, notably managing input and output.
96baa820 19273
104c1213
JM
19274@item
19275A way of getting your program to the other machine---for example, a
19276download program. These are often supplied by the hardware
19277manufacturer, but you may have to write your own from hardware
19278documentation.
19279@end enumerate
96baa820 19280
104c1213
JM
19281The next step is to arrange for your program to use a serial port to
19282communicate with the machine where @value{GDBN} is running (the @dfn{host}
19283machine). In general terms, the scheme looks like this:
96baa820 19284
104c1213
JM
19285@table @emph
19286@item On the host,
19287@value{GDBN} already understands how to use this protocol; when everything
19288else is set up, you can simply use the @samp{target remote} command
19289(@pxref{Targets,,Specifying a Debugging Target}).
19290
19291@item On the target,
19292you must link with your program a few special-purpose subroutines that
19293implement the @value{GDBN} remote serial protocol. The file containing these
19294subroutines is called a @dfn{debugging stub}.
19295
19296On certain remote targets, you can use an auxiliary program
19297@code{gdbserver} instead of linking a stub into your program.
79a6e687 19298@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 19299@end table
96baa820 19300
104c1213
JM
19301The debugging stub is specific to the architecture of the remote
19302machine; for example, use @file{sparc-stub.c} to debug programs on
19303@sc{sparc} boards.
96baa820 19304
104c1213
JM
19305@cindex remote serial stub list
19306These working remote stubs are distributed with @value{GDBN}:
96baa820 19307
104c1213
JM
19308@table @code
19309
19310@item i386-stub.c
41afff9a 19311@cindex @file{i386-stub.c}
104c1213
JM
19312@cindex Intel
19313@cindex i386
19314For Intel 386 and compatible architectures.
19315
19316@item m68k-stub.c
41afff9a 19317@cindex @file{m68k-stub.c}
104c1213
JM
19318@cindex Motorola 680x0
19319@cindex m680x0
19320For Motorola 680x0 architectures.
19321
19322@item sh-stub.c
41afff9a 19323@cindex @file{sh-stub.c}
172c2a43 19324@cindex Renesas
104c1213 19325@cindex SH
172c2a43 19326For Renesas SH architectures.
104c1213
JM
19327
19328@item sparc-stub.c
41afff9a 19329@cindex @file{sparc-stub.c}
104c1213
JM
19330@cindex Sparc
19331For @sc{sparc} architectures.
19332
19333@item sparcl-stub.c
41afff9a 19334@cindex @file{sparcl-stub.c}
104c1213
JM
19335@cindex Fujitsu
19336@cindex SparcLite
19337For Fujitsu @sc{sparclite} architectures.
19338
19339@end table
19340
19341The @file{README} file in the @value{GDBN} distribution may list other
19342recently added stubs.
19343
19344@menu
19345* Stub Contents:: What the stub can do for you
19346* Bootstrapping:: What you must do for the stub
19347* Debug Session:: Putting it all together
104c1213
JM
19348@end menu
19349
6d2ebf8b 19350@node Stub Contents
79a6e687 19351@subsection What the Stub Can Do for You
104c1213
JM
19352
19353@cindex remote serial stub
19354The debugging stub for your architecture supplies these three
19355subroutines:
19356
19357@table @code
19358@item set_debug_traps
4644b6e3 19359@findex set_debug_traps
104c1213
JM
19360@cindex remote serial stub, initialization
19361This routine arranges for @code{handle_exception} to run when your
2fb860fc
PA
19362program stops. You must call this subroutine explicitly in your
19363program's startup code.
104c1213
JM
19364
19365@item handle_exception
4644b6e3 19366@findex handle_exception
104c1213
JM
19367@cindex remote serial stub, main routine
19368This is the central workhorse, but your program never calls it
19369explicitly---the setup code arranges for @code{handle_exception} to
19370run when a trap is triggered.
19371
19372@code{handle_exception} takes control when your program stops during
19373execution (for example, on a breakpoint), and mediates communications
19374with @value{GDBN} on the host machine. This is where the communications
19375protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 19376representative on the target machine. It begins by sending summary
104c1213
JM
19377information on the state of your program, then continues to execute,
19378retrieving and transmitting any information @value{GDBN} needs, until you
19379execute a @value{GDBN} command that makes your program resume; at that point,
19380@code{handle_exception} returns control to your own code on the target
5d161b24 19381machine.
104c1213
JM
19382
19383@item breakpoint
19384@cindex @code{breakpoint} subroutine, remote
19385Use this auxiliary subroutine to make your program contain a
19386breakpoint. Depending on the particular situation, this may be the only
19387way for @value{GDBN} to get control. For instance, if your target
19388machine has some sort of interrupt button, you won't need to call this;
19389pressing the interrupt button transfers control to
19390@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
19391simply receiving characters on the serial port may also trigger a trap;
19392again, in that situation, you don't need to call @code{breakpoint} from
19393your own program---simply running @samp{target remote} from the host
5d161b24 19394@value{GDBN} session gets control.
104c1213
JM
19395
19396Call @code{breakpoint} if none of these is true, or if you simply want
19397to make certain your program stops at a predetermined point for the
19398start of your debugging session.
19399@end table
19400
6d2ebf8b 19401@node Bootstrapping
79a6e687 19402@subsection What You Must Do for the Stub
104c1213
JM
19403
19404@cindex remote stub, support routines
19405The debugging stubs that come with @value{GDBN} are set up for a particular
19406chip architecture, but they have no information about the rest of your
19407debugging target machine.
19408
19409First of all you need to tell the stub how to communicate with the
19410serial port.
19411
19412@table @code
19413@item int getDebugChar()
4644b6e3 19414@findex getDebugChar
104c1213
JM
19415Write this subroutine to read a single character from the serial port.
19416It may be identical to @code{getchar} for your target system; a
19417different name is used to allow you to distinguish the two if you wish.
19418
19419@item void putDebugChar(int)
4644b6e3 19420@findex putDebugChar
104c1213 19421Write this subroutine to write a single character to the serial port.
5d161b24 19422It may be identical to @code{putchar} for your target system; a
104c1213
JM
19423different name is used to allow you to distinguish the two if you wish.
19424@end table
19425
19426@cindex control C, and remote debugging
19427@cindex interrupting remote targets
19428If you want @value{GDBN} to be able to stop your program while it is
19429running, you need to use an interrupt-driven serial driver, and arrange
19430for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
19431character). That is the character which @value{GDBN} uses to tell the
19432remote system to stop.
19433
19434Getting the debugging target to return the proper status to @value{GDBN}
19435probably requires changes to the standard stub; one quick and dirty way
19436is to just execute a breakpoint instruction (the ``dirty'' part is that
19437@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
19438
19439Other routines you need to supply are:
19440
19441@table @code
19442@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 19443@findex exceptionHandler
104c1213
JM
19444Write this function to install @var{exception_address} in the exception
19445handling tables. You need to do this because the stub does not have any
19446way of knowing what the exception handling tables on your target system
19447are like (for example, the processor's table might be in @sc{rom},
19448containing entries which point to a table in @sc{ram}).
19449@var{exception_number} is the exception number which should be changed;
19450its meaning is architecture-dependent (for example, different numbers
19451might represent divide by zero, misaligned access, etc). When this
19452exception occurs, control should be transferred directly to
19453@var{exception_address}, and the processor state (stack, registers,
19454and so on) should be just as it is when a processor exception occurs. So if
19455you want to use a jump instruction to reach @var{exception_address}, it
19456should be a simple jump, not a jump to subroutine.
19457
19458For the 386, @var{exception_address} should be installed as an interrupt
19459gate so that interrupts are masked while the handler runs. The gate
19460should be at privilege level 0 (the most privileged level). The
19461@sc{sparc} and 68k stubs are able to mask interrupts themselves without
19462help from @code{exceptionHandler}.
19463
19464@item void flush_i_cache()
4644b6e3 19465@findex flush_i_cache
d4f3574e 19466On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
19467instruction cache, if any, on your target machine. If there is no
19468instruction cache, this subroutine may be a no-op.
19469
19470On target machines that have instruction caches, @value{GDBN} requires this
19471function to make certain that the state of your program is stable.
19472@end table
19473
19474@noindent
19475You must also make sure this library routine is available:
19476
19477@table @code
19478@item void *memset(void *, int, int)
4644b6e3 19479@findex memset
104c1213
JM
19480This is the standard library function @code{memset} that sets an area of
19481memory to a known value. If you have one of the free versions of
19482@code{libc.a}, @code{memset} can be found there; otherwise, you must
19483either obtain it from your hardware manufacturer, or write your own.
19484@end table
19485
19486If you do not use the GNU C compiler, you may need other standard
19487library subroutines as well; this varies from one stub to another,
19488but in general the stubs are likely to use any of the common library
e22ea452 19489subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
19490
19491
6d2ebf8b 19492@node Debug Session
79a6e687 19493@subsection Putting it All Together
104c1213
JM
19494
19495@cindex remote serial debugging summary
19496In summary, when your program is ready to debug, you must follow these
19497steps.
19498
19499@enumerate
19500@item
6d2ebf8b 19501Make sure you have defined the supporting low-level routines
79a6e687 19502(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
19503@display
19504@code{getDebugChar}, @code{putDebugChar},
19505@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
19506@end display
19507
19508@item
2fb860fc
PA
19509Insert these lines in your program's startup code, before the main
19510procedure is called:
104c1213 19511
474c8240 19512@smallexample
104c1213
JM
19513set_debug_traps();
19514breakpoint();
474c8240 19515@end smallexample
104c1213 19516
2fb860fc
PA
19517On some machines, when a breakpoint trap is raised, the hardware
19518automatically makes the PC point to the instruction after the
19519breakpoint. If your machine doesn't do that, you may need to adjust
19520@code{handle_exception} to arrange for it to return to the instruction
19521after the breakpoint on this first invocation, so that your program
19522doesn't keep hitting the initial breakpoint instead of making
19523progress.
19524
104c1213
JM
19525@item
19526For the 680x0 stub only, you need to provide a variable called
19527@code{exceptionHook}. Normally you just use:
19528
474c8240 19529@smallexample
104c1213 19530void (*exceptionHook)() = 0;
474c8240 19531@end smallexample
104c1213 19532
d4f3574e 19533@noindent
104c1213 19534but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 19535function in your program, that function is called when
104c1213
JM
19536@code{@value{GDBN}} continues after stopping on a trap (for example, bus
19537error). The function indicated by @code{exceptionHook} is called with
19538one parameter: an @code{int} which is the exception number.
19539
19540@item
19541Compile and link together: your program, the @value{GDBN} debugging stub for
19542your target architecture, and the supporting subroutines.
19543
19544@item
19545Make sure you have a serial connection between your target machine and
19546the @value{GDBN} host, and identify the serial port on the host.
19547
19548@item
19549@c The "remote" target now provides a `load' command, so we should
19550@c document that. FIXME.
19551Download your program to your target machine (or get it there by
19552whatever means the manufacturer provides), and start it.
19553
19554@item
07f31aa6 19555Start @value{GDBN} on the host, and connect to the target
79a6e687 19556(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 19557
104c1213
JM
19558@end enumerate
19559
8e04817f
AC
19560@node Configurations
19561@chapter Configuration-Specific Information
104c1213 19562
8e04817f
AC
19563While nearly all @value{GDBN} commands are available for all native and
19564cross versions of the debugger, there are some exceptions. This chapter
19565describes things that are only available in certain configurations.
104c1213 19566
8e04817f
AC
19567There are three major categories of configurations: native
19568configurations, where the host and target are the same, embedded
19569operating system configurations, which are usually the same for several
19570different processor architectures, and bare embedded processors, which
19571are quite different from each other.
104c1213 19572
8e04817f
AC
19573@menu
19574* Native::
19575* Embedded OS::
19576* Embedded Processors::
19577* Architectures::
19578@end menu
104c1213 19579
8e04817f
AC
19580@node Native
19581@section Native
104c1213 19582
8e04817f
AC
19583This section describes details specific to particular native
19584configurations.
6cf7e474 19585
8e04817f
AC
19586@menu
19587* HP-UX:: HP-UX
7561d450 19588* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
19589* SVR4 Process Information:: SVR4 process information
19590* DJGPP Native:: Features specific to the DJGPP port
78c47bea 19591* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 19592* Hurd Native:: Features specific to @sc{gnu} Hurd
a80b95ba 19593* Darwin:: Features specific to Darwin
8e04817f 19594@end menu
6cf7e474 19595
8e04817f
AC
19596@node HP-UX
19597@subsection HP-UX
104c1213 19598
8e04817f
AC
19599On HP-UX systems, if you refer to a function or variable name that
19600begins with a dollar sign, @value{GDBN} searches for a user or system
19601name first, before it searches for a convenience variable.
104c1213 19602
9c16f35a 19603
7561d450
MK
19604@node BSD libkvm Interface
19605@subsection BSD libkvm Interface
19606
19607@cindex libkvm
19608@cindex kernel memory image
19609@cindex kernel crash dump
19610
19611BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
19612interface that provides a uniform interface for accessing kernel virtual
19613memory images, including live systems and crash dumps. @value{GDBN}
19614uses this interface to allow you to debug live kernels and kernel crash
19615dumps on many native BSD configurations. This is implemented as a
19616special @code{kvm} debugging target. For debugging a live system, load
19617the currently running kernel into @value{GDBN} and connect to the
19618@code{kvm} target:
19619
19620@smallexample
19621(@value{GDBP}) @b{target kvm}
19622@end smallexample
19623
19624For debugging crash dumps, provide the file name of the crash dump as an
19625argument:
19626
19627@smallexample
19628(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
19629@end smallexample
19630
19631Once connected to the @code{kvm} target, the following commands are
19632available:
19633
19634@table @code
19635@kindex kvm
19636@item kvm pcb
721c2651 19637Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
19638
19639@item kvm proc
19640Set current context from proc address. This command isn't available on
19641modern FreeBSD systems.
19642@end table
19643
8e04817f 19644@node SVR4 Process Information
79a6e687 19645@subsection SVR4 Process Information
60bf7e09
EZ
19646@cindex /proc
19647@cindex examine process image
19648@cindex process info via @file{/proc}
104c1213 19649
60bf7e09
EZ
19650Many versions of SVR4 and compatible systems provide a facility called
19651@samp{/proc} that can be used to examine the image of a running
451b7c33
TT
19652process using file-system subroutines.
19653
19654If @value{GDBN} is configured for an operating system with this
19655facility, the command @code{info proc} is available to report
19656information about the process running your program, or about any
19657process running on your system. This includes, as of this writing,
19658@sc{gnu}/Linux, OSF/1 (Digital Unix), Solaris, and Irix, but
19659not HP-UX, for example.
19660
19661This command may also work on core files that were created on a system
19662that has the @samp{/proc} facility.
104c1213 19663
8e04817f
AC
19664@table @code
19665@kindex info proc
60bf7e09 19666@cindex process ID
8e04817f 19667@item info proc
60bf7e09
EZ
19668@itemx info proc @var{process-id}
19669Summarize available information about any running process. If a
19670process ID is specified by @var{process-id}, display information about
19671that process; otherwise display information about the program being
19672debugged. The summary includes the debugged process ID, the command
19673line used to invoke it, its current working directory, and its
19674executable file's absolute file name.
19675
19676On some systems, @var{process-id} can be of the form
19677@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
19678within a process. If the optional @var{pid} part is missing, it means
19679a thread from the process being debugged (the leading @samp{/} still
19680needs to be present, or else @value{GDBN} will interpret the number as
19681a process ID rather than a thread ID).
6cf7e474 19682
0c631110
TT
19683@item info proc cmdline
19684@cindex info proc cmdline
19685Show the original command line of the process. This command is
19686specific to @sc{gnu}/Linux.
19687
19688@item info proc cwd
19689@cindex info proc cwd
19690Show the current working directory of the process. This command is
19691specific to @sc{gnu}/Linux.
19692
19693@item info proc exe
19694@cindex info proc exe
19695Show the name of executable of the process. This command is specific
19696to @sc{gnu}/Linux.
19697
8e04817f 19698@item info proc mappings
60bf7e09
EZ
19699@cindex memory address space mappings
19700Report the memory address space ranges accessible in the program, with
19701information on whether the process has read, write, or execute access
19702rights to each range. On @sc{gnu}/Linux systems, each memory range
19703includes the object file which is mapped to that range, instead of the
19704memory access rights to that range.
19705
19706@item info proc stat
19707@itemx info proc status
19708@cindex process detailed status information
19709These subcommands are specific to @sc{gnu}/Linux systems. They show
19710the process-related information, including the user ID and group ID;
19711how many threads are there in the process; its virtual memory usage;
19712the signals that are pending, blocked, and ignored; its TTY; its
19713consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 19714value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
19715(type @kbd{man 5 proc} from your shell prompt).
19716
19717@item info proc all
19718Show all the information about the process described under all of the
19719above @code{info proc} subcommands.
19720
8e04817f
AC
19721@ignore
19722@comment These sub-options of 'info proc' were not included when
19723@comment procfs.c was re-written. Keep their descriptions around
19724@comment against the day when someone finds the time to put them back in.
19725@kindex info proc times
19726@item info proc times
19727Starting time, user CPU time, and system CPU time for your program and
19728its children.
6cf7e474 19729
8e04817f
AC
19730@kindex info proc id
19731@item info proc id
19732Report on the process IDs related to your program: its own process ID,
19733the ID of its parent, the process group ID, and the session ID.
8e04817f 19734@end ignore
721c2651
EZ
19735
19736@item set procfs-trace
19737@kindex set procfs-trace
19738@cindex @code{procfs} API calls
19739This command enables and disables tracing of @code{procfs} API calls.
19740
19741@item show procfs-trace
19742@kindex show procfs-trace
19743Show the current state of @code{procfs} API call tracing.
19744
19745@item set procfs-file @var{file}
19746@kindex set procfs-file
19747Tell @value{GDBN} to write @code{procfs} API trace to the named
19748@var{file}. @value{GDBN} appends the trace info to the previous
19749contents of the file. The default is to display the trace on the
19750standard output.
19751
19752@item show procfs-file
19753@kindex show procfs-file
19754Show the file to which @code{procfs} API trace is written.
19755
19756@item proc-trace-entry
19757@itemx proc-trace-exit
19758@itemx proc-untrace-entry
19759@itemx proc-untrace-exit
19760@kindex proc-trace-entry
19761@kindex proc-trace-exit
19762@kindex proc-untrace-entry
19763@kindex proc-untrace-exit
19764These commands enable and disable tracing of entries into and exits
19765from the @code{syscall} interface.
19766
19767@item info pidlist
19768@kindex info pidlist
19769@cindex process list, QNX Neutrino
19770For QNX Neutrino only, this command displays the list of all the
19771processes and all the threads within each process.
19772
19773@item info meminfo
19774@kindex info meminfo
19775@cindex mapinfo list, QNX Neutrino
19776For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 19777@end table
104c1213 19778
8e04817f
AC
19779@node DJGPP Native
19780@subsection Features for Debugging @sc{djgpp} Programs
19781@cindex @sc{djgpp} debugging
19782@cindex native @sc{djgpp} debugging
19783@cindex MS-DOS-specific commands
104c1213 19784
514c4d71
EZ
19785@cindex DPMI
19786@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
19787MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
19788that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
19789top of real-mode DOS systems and their emulations.
104c1213 19790
8e04817f
AC
19791@value{GDBN} supports native debugging of @sc{djgpp} programs, and
19792defines a few commands specific to the @sc{djgpp} port. This
19793subsection describes those commands.
104c1213 19794
8e04817f
AC
19795@table @code
19796@kindex info dos
19797@item info dos
19798This is a prefix of @sc{djgpp}-specific commands which print
19799information about the target system and important OS structures.
f1251bdd 19800
8e04817f
AC
19801@kindex sysinfo
19802@cindex MS-DOS system info
19803@cindex free memory information (MS-DOS)
19804@item info dos sysinfo
19805This command displays assorted information about the underlying
19806platform: the CPU type and features, the OS version and flavor, the
19807DPMI version, and the available conventional and DPMI memory.
104c1213 19808
8e04817f
AC
19809@cindex GDT
19810@cindex LDT
19811@cindex IDT
19812@cindex segment descriptor tables
19813@cindex descriptor tables display
19814@item info dos gdt
19815@itemx info dos ldt
19816@itemx info dos idt
19817These 3 commands display entries from, respectively, Global, Local,
19818and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
19819tables are data structures which store a descriptor for each segment
19820that is currently in use. The segment's selector is an index into a
19821descriptor table; the table entry for that index holds the
19822descriptor's base address and limit, and its attributes and access
19823rights.
104c1213 19824
8e04817f
AC
19825A typical @sc{djgpp} program uses 3 segments: a code segment, a data
19826segment (used for both data and the stack), and a DOS segment (which
19827allows access to DOS/BIOS data structures and absolute addresses in
19828conventional memory). However, the DPMI host will usually define
19829additional segments in order to support the DPMI environment.
d4f3574e 19830
8e04817f
AC
19831@cindex garbled pointers
19832These commands allow to display entries from the descriptor tables.
19833Without an argument, all entries from the specified table are
19834displayed. An argument, which should be an integer expression, means
19835display a single entry whose index is given by the argument. For
19836example, here's a convenient way to display information about the
19837debugged program's data segment:
104c1213 19838
8e04817f
AC
19839@smallexample
19840@exdent @code{(@value{GDBP}) info dos ldt $ds}
19841@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
19842@end smallexample
104c1213 19843
8e04817f
AC
19844@noindent
19845This comes in handy when you want to see whether a pointer is outside
19846the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 19847
8e04817f
AC
19848@cindex page tables display (MS-DOS)
19849@item info dos pde
19850@itemx info dos pte
19851These two commands display entries from, respectively, the Page
19852Directory and the Page Tables. Page Directories and Page Tables are
19853data structures which control how virtual memory addresses are mapped
19854into physical addresses. A Page Table includes an entry for every
19855page of memory that is mapped into the program's address space; there
19856may be several Page Tables, each one holding up to 4096 entries. A
19857Page Directory has up to 4096 entries, one each for every Page Table
19858that is currently in use.
104c1213 19859
8e04817f
AC
19860Without an argument, @kbd{info dos pde} displays the entire Page
19861Directory, and @kbd{info dos pte} displays all the entries in all of
19862the Page Tables. An argument, an integer expression, given to the
19863@kbd{info dos pde} command means display only that entry from the Page
19864Directory table. An argument given to the @kbd{info dos pte} command
19865means display entries from a single Page Table, the one pointed to by
19866the specified entry in the Page Directory.
104c1213 19867
8e04817f
AC
19868@cindex direct memory access (DMA) on MS-DOS
19869These commands are useful when your program uses @dfn{DMA} (Direct
19870Memory Access), which needs physical addresses to program the DMA
19871controller.
104c1213 19872
8e04817f 19873These commands are supported only with some DPMI servers.
104c1213 19874
8e04817f
AC
19875@cindex physical address from linear address
19876@item info dos address-pte @var{addr}
19877This command displays the Page Table entry for a specified linear
514c4d71
EZ
19878address. The argument @var{addr} is a linear address which should
19879already have the appropriate segment's base address added to it,
19880because this command accepts addresses which may belong to @emph{any}
19881segment. For example, here's how to display the Page Table entry for
19882the page where a variable @code{i} is stored:
104c1213 19883
b383017d 19884@smallexample
8e04817f
AC
19885@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
19886@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 19887@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 19888@end smallexample
104c1213 19889
8e04817f
AC
19890@noindent
19891This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 19892whose physical base address is @code{0x02698000}, and shows all the
8e04817f 19893attributes of that page.
104c1213 19894
8e04817f
AC
19895Note that you must cast the addresses of variables to a @code{char *},
19896since otherwise the value of @code{__djgpp_base_address}, the base
19897address of all variables and functions in a @sc{djgpp} program, will
19898be added using the rules of C pointer arithmetics: if @code{i} is
19899declared an @code{int}, @value{GDBN} will add 4 times the value of
19900@code{__djgpp_base_address} to the address of @code{i}.
104c1213 19901
8e04817f
AC
19902Here's another example, it displays the Page Table entry for the
19903transfer buffer:
104c1213 19904
8e04817f
AC
19905@smallexample
19906@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
19907@exdent @code{Page Table entry for address 0x29110:}
19908@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
19909@end smallexample
104c1213 19910
8e04817f
AC
19911@noindent
19912(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
199133rd member of the @code{_go32_info_block} structure.) The output
19914clearly shows that this DPMI server maps the addresses in conventional
19915memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
19916linear (@code{0x29110}) addresses are identical.
104c1213 19917
8e04817f
AC
19918This command is supported only with some DPMI servers.
19919@end table
104c1213 19920
c45da7e6 19921@cindex DOS serial data link, remote debugging
a8f24a35
EZ
19922In addition to native debugging, the DJGPP port supports remote
19923debugging via a serial data link. The following commands are specific
19924to remote serial debugging in the DJGPP port of @value{GDBN}.
19925
19926@table @code
19927@kindex set com1base
19928@kindex set com1irq
19929@kindex set com2base
19930@kindex set com2irq
19931@kindex set com3base
19932@kindex set com3irq
19933@kindex set com4base
19934@kindex set com4irq
19935@item set com1base @var{addr}
19936This command sets the base I/O port address of the @file{COM1} serial
19937port.
19938
19939@item set com1irq @var{irq}
19940This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
19941for the @file{COM1} serial port.
19942
19943There are similar commands @samp{set com2base}, @samp{set com3irq},
19944etc.@: for setting the port address and the @code{IRQ} lines for the
19945other 3 COM ports.
19946
19947@kindex show com1base
19948@kindex show com1irq
19949@kindex show com2base
19950@kindex show com2irq
19951@kindex show com3base
19952@kindex show com3irq
19953@kindex show com4base
19954@kindex show com4irq
19955The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
19956display the current settings of the base address and the @code{IRQ}
19957lines used by the COM ports.
c45da7e6
EZ
19958
19959@item info serial
19960@kindex info serial
19961@cindex DOS serial port status
19962This command prints the status of the 4 DOS serial ports. For each
19963port, it prints whether it's active or not, its I/O base address and
19964IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
19965counts of various errors encountered so far.
a8f24a35
EZ
19966@end table
19967
19968
78c47bea 19969@node Cygwin Native
79a6e687 19970@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
19971@cindex MS Windows debugging
19972@cindex native Cygwin debugging
19973@cindex Cygwin-specific commands
19974
be448670 19975@value{GDBN} supports native debugging of MS Windows programs, including
cbb8f428
EZ
19976DLLs with and without symbolic debugging information.
19977
19978@cindex Ctrl-BREAK, MS-Windows
19979@cindex interrupt debuggee on MS-Windows
19980MS-Windows programs that call @code{SetConsoleMode} to switch off the
19981special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
19982by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
19983supports @kbd{C-@key{BREAK}} as an alternative interrupt key
19984sequence, which can be used to interrupt the debuggee even if it
19985ignores @kbd{C-c}.
19986
19987There are various additional Cygwin-specific commands, described in
19988this section. Working with DLLs that have no debugging symbols is
19989described in @ref{Non-debug DLL Symbols}.
78c47bea
PM
19990
19991@table @code
19992@kindex info w32
19993@item info w32
db2e3e2e 19994This is a prefix of MS Windows-specific commands which print
78c47bea
PM
19995information about the target system and important OS structures.
19996
19997@item info w32 selector
19998This command displays information returned by
19999the Win32 API @code{GetThreadSelectorEntry} function.
20000It takes an optional argument that is evaluated to
20001a long value to give the information about this given selector.
20002Without argument, this command displays information
d3e8051b 20003about the six segment registers.
78c47bea 20004
711e434b
PM
20005@item info w32 thread-information-block
20006This command displays thread specific information stored in the
20007Thread Information Block (readable on the X86 CPU family using @code{$fs}
20008selector for 32-bit programs and @code{$gs} for 64-bit programs).
20009
78c47bea
PM
20010@kindex info dll
20011@item info dll
db2e3e2e 20012This is a Cygwin-specific alias of @code{info shared}.
78c47bea
PM
20013
20014@kindex dll-symbols
20015@item dll-symbols
95060284
JB
20016This command is deprecated and will be removed in future versions
20017of @value{GDBN}. Use the @code{sharedlibrary} command instead.
20018
78c47bea
PM
20019This command loads symbols from a dll similarly to
20020add-sym command but without the need to specify a base address.
20021
be90c084 20022@kindex set cygwin-exceptions
e16b02ee
EZ
20023@cindex debugging the Cygwin DLL
20024@cindex Cygwin DLL, debugging
be90c084 20025@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
20026If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
20027happen inside the Cygwin DLL. If @var{mode} is @code{off},
20028@value{GDBN} will delay recognition of exceptions, and may ignore some
20029exceptions which seem to be caused by internal Cygwin DLL
20030``bookkeeping''. This option is meant primarily for debugging the
20031Cygwin DLL itself; the default value is @code{off} to avoid annoying
20032@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
20033
20034@kindex show cygwin-exceptions
20035@item show cygwin-exceptions
e16b02ee
EZ
20036Displays whether @value{GDBN} will break on exceptions that happen
20037inside the Cygwin DLL itself.
be90c084 20038
b383017d 20039@kindex set new-console
78c47bea 20040@item set new-console @var{mode}
b383017d 20041If @var{mode} is @code{on} the debuggee will
78c47bea 20042be started in a new console on next start.
e03e5e7b 20043If @var{mode} is @code{off}, the debuggee will
78c47bea
PM
20044be started in the same console as the debugger.
20045
20046@kindex show new-console
20047@item show new-console
20048Displays whether a new console is used
20049when the debuggee is started.
20050
20051@kindex set new-group
20052@item set new-group @var{mode}
20053This boolean value controls whether the debuggee should
20054start a new group or stay in the same group as the debugger.
20055This affects the way the Windows OS handles
c8aa23ab 20056@samp{Ctrl-C}.
78c47bea
PM
20057
20058@kindex show new-group
20059@item show new-group
20060Displays current value of new-group boolean.
20061
20062@kindex set debugevents
20063@item set debugevents
219eec71
EZ
20064This boolean value adds debug output concerning kernel events related
20065to the debuggee seen by the debugger. This includes events that
20066signal thread and process creation and exit, DLL loading and
20067unloading, console interrupts, and debugging messages produced by the
20068Windows @code{OutputDebugString} API call.
78c47bea
PM
20069
20070@kindex set debugexec
20071@item set debugexec
b383017d 20072This boolean value adds debug output concerning execute events
219eec71 20073(such as resume thread) seen by the debugger.
78c47bea
PM
20074
20075@kindex set debugexceptions
20076@item set debugexceptions
219eec71
EZ
20077This boolean value adds debug output concerning exceptions in the
20078debuggee seen by the debugger.
78c47bea
PM
20079
20080@kindex set debugmemory
20081@item set debugmemory
219eec71
EZ
20082This boolean value adds debug output concerning debuggee memory reads
20083and writes by the debugger.
78c47bea
PM
20084
20085@kindex set shell
20086@item set shell
20087This boolean values specifies whether the debuggee is called
20088via a shell or directly (default value is on).
20089
20090@kindex show shell
20091@item show shell
20092Displays if the debuggee will be started with a shell.
20093
20094@end table
20095
be448670 20096@menu
79a6e687 20097* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
20098@end menu
20099
79a6e687
BW
20100@node Non-debug DLL Symbols
20101@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
20102@cindex DLLs with no debugging symbols
20103@cindex Minimal symbols and DLLs
20104
20105Very often on windows, some of the DLLs that your program relies on do
20106not include symbolic debugging information (for example,
db2e3e2e 20107@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 20108symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 20109information contained in the DLL's export table. This section
be448670
CF
20110describes working with such symbols, known internally to @value{GDBN} as
20111``minimal symbols''.
20112
20113Note that before the debugged program has started execution, no DLLs
db2e3e2e 20114will have been loaded. The easiest way around this problem is simply to
be448670 20115start the program --- either by setting a breakpoint or letting the
95060284 20116program run once to completion.
be448670 20117
79a6e687 20118@subsubsection DLL Name Prefixes
be448670
CF
20119
20120In keeping with the naming conventions used by the Microsoft debugging
20121tools, DLL export symbols are made available with a prefix based on the
20122DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
20123also entered into the symbol table, so @code{CreateFileA} is often
99e008fe 20124sufficient. In some cases there will be name clashes within a program
be448670
CF
20125(particularly if the executable itself includes full debugging symbols)
20126necessitating the use of the fully qualified name when referring to the
99e008fe 20127contents of the DLL. Use single-quotes around the name to avoid the
be448670
CF
20128exclamation mark (``!'') being interpreted as a language operator.
20129
20130Note that the internal name of the DLL may be all upper-case, even
99e008fe 20131though the file name of the DLL is lower-case, or vice-versa. Since
be448670
CF
20132symbols within @value{GDBN} are @emph{case-sensitive} this may cause
20133some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
20134@code{info variables} commands or even @code{maint print msymbols}
20135(@pxref{Symbols}). Here's an example:
be448670
CF
20136
20137@smallexample
f7dc1244 20138(@value{GDBP}) info function CreateFileA
be448670
CF
20139All functions matching regular expression "CreateFileA":
20140
20141Non-debugging symbols:
201420x77e885f4 CreateFileA
201430x77e885f4 KERNEL32!CreateFileA
20144@end smallexample
20145
20146@smallexample
f7dc1244 20147(@value{GDBP}) info function !
be448670
CF
20148All functions matching regular expression "!":
20149
20150Non-debugging symbols:
201510x6100114c cygwin1!__assert
201520x61004034 cygwin1!_dll_crt0@@0
201530x61004240 cygwin1!dll_crt0(per_process *)
20154[etc...]
20155@end smallexample
20156
79a6e687 20157@subsubsection Working with Minimal Symbols
be448670
CF
20158
20159Symbols extracted from a DLL's export table do not contain very much
20160type information. All that @value{GDBN} can do is guess whether a symbol
20161refers to a function or variable depending on the linker section that
20162contains the symbol. Also note that the actual contents of the memory
20163contained in a DLL are not available unless the program is running. This
20164means that you cannot examine the contents of a variable or disassemble
20165a function within a DLL without a running program.
20166
20167Variables are generally treated as pointers and dereferenced
20168automatically. For this reason, it is often necessary to prefix a
20169variable name with the address-of operator (``&'') and provide explicit
20170type information in the command. Here's an example of the type of
20171problem:
20172
20173@smallexample
f7dc1244 20174(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
20175$1 = 268572168
20176@end smallexample
20177
20178@smallexample
f7dc1244 20179(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
201800x10021610: "\230y\""
20181@end smallexample
20182
20183And two possible solutions:
20184
20185@smallexample
f7dc1244 20186(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
20187$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
20188@end smallexample
20189
20190@smallexample
f7dc1244 20191(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 201920x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 20193(@value{GDBP}) x/x 0x10021608
be448670 201940x10021608: 0x0022fd98
f7dc1244 20195(@value{GDBP}) x/s 0x0022fd98
be448670
CF
201960x22fd98: "/cygdrive/c/mydirectory/myprogram"
20197@end smallexample
20198
20199Setting a break point within a DLL is possible even before the program
20200starts execution. However, under these circumstances, @value{GDBN} can't
20201examine the initial instructions of the function in order to skip the
20202function's frame set-up code. You can work around this by using ``*&''
20203to set the breakpoint at a raw memory address:
20204
20205@smallexample
f7dc1244 20206(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
20207Breakpoint 1 at 0x1e04eff0
20208@end smallexample
20209
20210The author of these extensions is not entirely convinced that setting a
20211break point within a shared DLL like @file{kernel32.dll} is completely
20212safe.
20213
14d6dd68 20214@node Hurd Native
79a6e687 20215@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
20216@cindex @sc{gnu} Hurd debugging
20217
20218This subsection describes @value{GDBN} commands specific to the
20219@sc{gnu} Hurd native debugging.
20220
20221@table @code
20222@item set signals
20223@itemx set sigs
20224@kindex set signals@r{, Hurd command}
20225@kindex set sigs@r{, Hurd command}
20226This command toggles the state of inferior signal interception by
20227@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
20228affected by this command. @code{sigs} is a shorthand alias for
20229@code{signals}.
20230
20231@item show signals
20232@itemx show sigs
20233@kindex show signals@r{, Hurd command}
20234@kindex show sigs@r{, Hurd command}
20235Show the current state of intercepting inferior's signals.
20236
20237@item set signal-thread
20238@itemx set sigthread
20239@kindex set signal-thread
20240@kindex set sigthread
20241This command tells @value{GDBN} which thread is the @code{libc} signal
20242thread. That thread is run when a signal is delivered to a running
20243process. @code{set sigthread} is the shorthand alias of @code{set
20244signal-thread}.
20245
20246@item show signal-thread
20247@itemx show sigthread
20248@kindex show signal-thread
20249@kindex show sigthread
20250These two commands show which thread will run when the inferior is
20251delivered a signal.
20252
20253@item set stopped
20254@kindex set stopped@r{, Hurd command}
20255This commands tells @value{GDBN} that the inferior process is stopped,
20256as with the @code{SIGSTOP} signal. The stopped process can be
20257continued by delivering a signal to it.
20258
20259@item show stopped
20260@kindex show stopped@r{, Hurd command}
20261This command shows whether @value{GDBN} thinks the debuggee is
20262stopped.
20263
20264@item set exceptions
20265@kindex set exceptions@r{, Hurd command}
20266Use this command to turn off trapping of exceptions in the inferior.
20267When exception trapping is off, neither breakpoints nor
20268single-stepping will work. To restore the default, set exception
20269trapping on.
20270
20271@item show exceptions
20272@kindex show exceptions@r{, Hurd command}
20273Show the current state of trapping exceptions in the inferior.
20274
20275@item set task pause
20276@kindex set task@r{, Hurd commands}
20277@cindex task attributes (@sc{gnu} Hurd)
20278@cindex pause current task (@sc{gnu} Hurd)
20279This command toggles task suspension when @value{GDBN} has control.
20280Setting it to on takes effect immediately, and the task is suspended
20281whenever @value{GDBN} gets control. Setting it to off will take
20282effect the next time the inferior is continued. If this option is set
20283to off, you can use @code{set thread default pause on} or @code{set
20284thread pause on} (see below) to pause individual threads.
20285
20286@item show task pause
20287@kindex show task@r{, Hurd commands}
20288Show the current state of task suspension.
20289
20290@item set task detach-suspend-count
20291@cindex task suspend count
20292@cindex detach from task, @sc{gnu} Hurd
20293This command sets the suspend count the task will be left with when
20294@value{GDBN} detaches from it.
20295
20296@item show task detach-suspend-count
20297Show the suspend count the task will be left with when detaching.
20298
20299@item set task exception-port
20300@itemx set task excp
20301@cindex task exception port, @sc{gnu} Hurd
20302This command sets the task exception port to which @value{GDBN} will
20303forward exceptions. The argument should be the value of the @dfn{send
20304rights} of the task. @code{set task excp} is a shorthand alias.
20305
20306@item set noninvasive
20307@cindex noninvasive task options
20308This command switches @value{GDBN} to a mode that is the least
20309invasive as far as interfering with the inferior is concerned. This
20310is the same as using @code{set task pause}, @code{set exceptions}, and
20311@code{set signals} to values opposite to the defaults.
20312
20313@item info send-rights
20314@itemx info receive-rights
20315@itemx info port-rights
20316@itemx info port-sets
20317@itemx info dead-names
20318@itemx info ports
20319@itemx info psets
20320@cindex send rights, @sc{gnu} Hurd
20321@cindex receive rights, @sc{gnu} Hurd
20322@cindex port rights, @sc{gnu} Hurd
20323@cindex port sets, @sc{gnu} Hurd
20324@cindex dead names, @sc{gnu} Hurd
20325These commands display information about, respectively, send rights,
20326receive rights, port rights, port sets, and dead names of a task.
20327There are also shorthand aliases: @code{info ports} for @code{info
20328port-rights} and @code{info psets} for @code{info port-sets}.
20329
20330@item set thread pause
20331@kindex set thread@r{, Hurd command}
20332@cindex thread properties, @sc{gnu} Hurd
20333@cindex pause current thread (@sc{gnu} Hurd)
20334This command toggles current thread suspension when @value{GDBN} has
20335control. Setting it to on takes effect immediately, and the current
20336thread is suspended whenever @value{GDBN} gets control. Setting it to
20337off will take effect the next time the inferior is continued.
20338Normally, this command has no effect, since when @value{GDBN} has
20339control, the whole task is suspended. However, if you used @code{set
20340task pause off} (see above), this command comes in handy to suspend
20341only the current thread.
20342
20343@item show thread pause
20344@kindex show thread@r{, Hurd command}
20345This command shows the state of current thread suspension.
20346
20347@item set thread run
d3e8051b 20348This command sets whether the current thread is allowed to run.
14d6dd68
EZ
20349
20350@item show thread run
20351Show whether the current thread is allowed to run.
20352
20353@item set thread detach-suspend-count
20354@cindex thread suspend count, @sc{gnu} Hurd
20355@cindex detach from thread, @sc{gnu} Hurd
20356This command sets the suspend count @value{GDBN} will leave on a
20357thread when detaching. This number is relative to the suspend count
20358found by @value{GDBN} when it notices the thread; use @code{set thread
20359takeover-suspend-count} to force it to an absolute value.
20360
20361@item show thread detach-suspend-count
20362Show the suspend count @value{GDBN} will leave on the thread when
20363detaching.
20364
20365@item set thread exception-port
20366@itemx set thread excp
20367Set the thread exception port to which to forward exceptions. This
20368overrides the port set by @code{set task exception-port} (see above).
20369@code{set thread excp} is the shorthand alias.
20370
20371@item set thread takeover-suspend-count
20372Normally, @value{GDBN}'s thread suspend counts are relative to the
20373value @value{GDBN} finds when it notices each thread. This command
20374changes the suspend counts to be absolute instead.
20375
20376@item set thread default
20377@itemx show thread default
20378@cindex thread default settings, @sc{gnu} Hurd
20379Each of the above @code{set thread} commands has a @code{set thread
20380default} counterpart (e.g., @code{set thread default pause}, @code{set
20381thread default exception-port}, etc.). The @code{thread default}
20382variety of commands sets the default thread properties for all
20383threads; you can then change the properties of individual threads with
20384the non-default commands.
20385@end table
20386
a80b95ba
TG
20387@node Darwin
20388@subsection Darwin
20389@cindex Darwin
20390
20391@value{GDBN} provides the following commands specific to the Darwin target:
20392
20393@table @code
20394@item set debug darwin @var{num}
20395@kindex set debug darwin
20396When set to a non zero value, enables debugging messages specific to
20397the Darwin support. Higher values produce more verbose output.
20398
20399@item show debug darwin
20400@kindex show debug darwin
20401Show the current state of Darwin messages.
20402
20403@item set debug mach-o @var{num}
20404@kindex set debug mach-o
20405When set to a non zero value, enables debugging messages while
20406@value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
20407file format used on Darwin for object and executable files.) Higher
20408values produce more verbose output. This is a command to diagnose
20409problems internal to @value{GDBN} and should not be needed in normal
20410usage.
20411
20412@item show debug mach-o
20413@kindex show debug mach-o
20414Show the current state of Mach-O file messages.
20415
20416@item set mach-exceptions on
20417@itemx set mach-exceptions off
20418@kindex set mach-exceptions
20419On Darwin, faults are first reported as a Mach exception and are then
20420mapped to a Posix signal. Use this command to turn on trapping of
20421Mach exceptions in the inferior. This might be sometimes useful to
20422better understand the cause of a fault. The default is off.
20423
20424@item show mach-exceptions
20425@kindex show mach-exceptions
20426Show the current state of exceptions trapping.
20427@end table
20428
a64548ea 20429
8e04817f
AC
20430@node Embedded OS
20431@section Embedded Operating Systems
104c1213 20432
8e04817f
AC
20433This section describes configurations involving the debugging of
20434embedded operating systems that are available for several different
20435architectures.
d4f3574e 20436
8e04817f
AC
20437@menu
20438* VxWorks:: Using @value{GDBN} with VxWorks
20439@end menu
104c1213 20440
8e04817f
AC
20441@value{GDBN} includes the ability to debug programs running on
20442various real-time operating systems.
104c1213 20443
8e04817f
AC
20444@node VxWorks
20445@subsection Using @value{GDBN} with VxWorks
104c1213 20446
8e04817f 20447@cindex VxWorks
104c1213 20448
8e04817f 20449@table @code
104c1213 20450
8e04817f
AC
20451@kindex target vxworks
20452@item target vxworks @var{machinename}
20453A VxWorks system, attached via TCP/IP. The argument @var{machinename}
20454is the target system's machine name or IP address.
104c1213 20455
8e04817f 20456@end table
104c1213 20457
8e04817f
AC
20458On VxWorks, @code{load} links @var{filename} dynamically on the
20459current target system as well as adding its symbols in @value{GDBN}.
104c1213 20460
8e04817f
AC
20461@value{GDBN} enables developers to spawn and debug tasks running on networked
20462VxWorks targets from a Unix host. Already-running tasks spawned from
20463the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
20464both the Unix host and on the VxWorks target. The program
20465@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
20466installed with the name @code{vxgdb}, to distinguish it from a
20467@value{GDBN} for debugging programs on the host itself.)
104c1213 20468
8e04817f
AC
20469@table @code
20470@item VxWorks-timeout @var{args}
20471@kindex vxworks-timeout
20472All VxWorks-based targets now support the option @code{vxworks-timeout}.
20473This option is set by the user, and @var{args} represents the number of
20474seconds @value{GDBN} waits for responses to rpc's. You might use this if
20475your VxWorks target is a slow software simulator or is on the far side
20476of a thin network line.
20477@end table
104c1213 20478
8e04817f
AC
20479The following information on connecting to VxWorks was current when
20480this manual was produced; newer releases of VxWorks may use revised
20481procedures.
104c1213 20482
4644b6e3 20483@findex INCLUDE_RDB
8e04817f
AC
20484To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
20485to include the remote debugging interface routines in the VxWorks
20486library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
20487VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
20488kernel. The resulting kernel contains @file{rdb.a}, and spawns the
20489source debugging task @code{tRdbTask} when VxWorks is booted. For more
20490information on configuring and remaking VxWorks, see the manufacturer's
20491manual.
20492@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 20493
8e04817f
AC
20494Once you have included @file{rdb.a} in your VxWorks system image and set
20495your Unix execution search path to find @value{GDBN}, you are ready to
20496run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
20497@code{vxgdb}, depending on your installation).
104c1213 20498
8e04817f 20499@value{GDBN} comes up showing the prompt:
104c1213 20500
474c8240 20501@smallexample
8e04817f 20502(vxgdb)
474c8240 20503@end smallexample
104c1213 20504
8e04817f
AC
20505@menu
20506* VxWorks Connection:: Connecting to VxWorks
20507* VxWorks Download:: VxWorks download
20508* VxWorks Attach:: Running tasks
20509@end menu
104c1213 20510
8e04817f
AC
20511@node VxWorks Connection
20512@subsubsection Connecting to VxWorks
104c1213 20513
8e04817f
AC
20514The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
20515network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 20516
474c8240 20517@smallexample
8e04817f 20518(vxgdb) target vxworks tt
474c8240 20519@end smallexample
104c1213 20520
8e04817f
AC
20521@need 750
20522@value{GDBN} displays messages like these:
104c1213 20523
8e04817f
AC
20524@smallexample
20525Attaching remote machine across net...
20526Connected to tt.
20527@end smallexample
104c1213 20528
8e04817f
AC
20529@need 1000
20530@value{GDBN} then attempts to read the symbol tables of any object modules
20531loaded into the VxWorks target since it was last booted. @value{GDBN} locates
20532these files by searching the directories listed in the command search
79a6e687 20533path (@pxref{Environment, ,Your Program's Environment}); if it fails
8e04817f 20534to find an object file, it displays a message such as:
5d161b24 20535
474c8240 20536@smallexample
8e04817f 20537prog.o: No such file or directory.
474c8240 20538@end smallexample
104c1213 20539
8e04817f
AC
20540When this happens, add the appropriate directory to the search path with
20541the @value{GDBN} command @code{path}, and execute the @code{target}
20542command again.
104c1213 20543
8e04817f 20544@node VxWorks Download
79a6e687 20545@subsubsection VxWorks Download
104c1213 20546
8e04817f
AC
20547@cindex download to VxWorks
20548If you have connected to the VxWorks target and you want to debug an
20549object that has not yet been loaded, you can use the @value{GDBN}
20550@code{load} command to download a file from Unix to VxWorks
20551incrementally. The object file given as an argument to the @code{load}
20552command is actually opened twice: first by the VxWorks target in order
20553to download the code, then by @value{GDBN} in order to read the symbol
20554table. This can lead to problems if the current working directories on
20555the two systems differ. If both systems have NFS mounted the same
20556filesystems, you can avoid these problems by using absolute paths.
20557Otherwise, it is simplest to set the working directory on both systems
20558to the directory in which the object file resides, and then to reference
20559the file by its name, without any path. For instance, a program
20560@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
20561and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
20562program, type this on VxWorks:
104c1213 20563
474c8240 20564@smallexample
8e04817f 20565-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 20566@end smallexample
104c1213 20567
8e04817f
AC
20568@noindent
20569Then, in @value{GDBN}, type:
104c1213 20570
474c8240 20571@smallexample
8e04817f
AC
20572(vxgdb) cd @var{hostpath}/vw/demo/rdb
20573(vxgdb) load prog.o
474c8240 20574@end smallexample
104c1213 20575
8e04817f 20576@value{GDBN} displays a response similar to this:
104c1213 20577
8e04817f
AC
20578@smallexample
20579Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
20580@end smallexample
104c1213 20581
8e04817f
AC
20582You can also use the @code{load} command to reload an object module
20583after editing and recompiling the corresponding source file. Note that
20584this makes @value{GDBN} delete all currently-defined breakpoints,
20585auto-displays, and convenience variables, and to clear the value
20586history. (This is necessary in order to preserve the integrity of
20587debugger's data structures that reference the target system's symbol
20588table.)
104c1213 20589
8e04817f 20590@node VxWorks Attach
79a6e687 20591@subsubsection Running Tasks
104c1213
JM
20592
20593@cindex running VxWorks tasks
20594You can also attach to an existing task using the @code{attach} command as
20595follows:
20596
474c8240 20597@smallexample
104c1213 20598(vxgdb) attach @var{task}
474c8240 20599@end smallexample
104c1213
JM
20600
20601@noindent
20602where @var{task} is the VxWorks hexadecimal task ID. The task can be running
20603or suspended when you attach to it. Running tasks are suspended at
20604the time of attachment.
20605
6d2ebf8b 20606@node Embedded Processors
104c1213
JM
20607@section Embedded Processors
20608
20609This section goes into details specific to particular embedded
20610configurations.
20611
c45da7e6
EZ
20612@cindex send command to simulator
20613Whenever a specific embedded processor has a simulator, @value{GDBN}
20614allows to send an arbitrary command to the simulator.
20615
20616@table @code
20617@item sim @var{command}
20618@kindex sim@r{, a command}
20619Send an arbitrary @var{command} string to the simulator. Consult the
20620documentation for the specific simulator in use for information about
20621acceptable commands.
20622@end table
20623
7d86b5d5 20624
104c1213 20625@menu
c45da7e6 20626* ARM:: ARM RDI
172c2a43 20627* M32R/D:: Renesas M32R/D
104c1213 20628* M68K:: Motorola M68K
08be9d71 20629* MicroBlaze:: Xilinx MicroBlaze
104c1213 20630* MIPS Embedded:: MIPS Embedded
4acd40f3 20631* PowerPC Embedded:: PowerPC Embedded
984359d2 20632* PA:: HP PA Embedded
104c1213
JM
20633* Sparclet:: Tsqware Sparclet
20634* Sparclite:: Fujitsu Sparclite
104c1213 20635* Z8000:: Zilog Z8000
a64548ea
EZ
20636* AVR:: Atmel AVR
20637* CRIS:: CRIS
20638* Super-H:: Renesas Super-H
104c1213
JM
20639@end menu
20640
6d2ebf8b 20641@node ARM
104c1213 20642@subsection ARM
c45da7e6 20643@cindex ARM RDI
104c1213
JM
20644
20645@table @code
8e04817f
AC
20646@kindex target rdi
20647@item target rdi @var{dev}
20648ARM Angel monitor, via RDI library interface to ADP protocol. You may
20649use this target to communicate with both boards running the Angel
20650monitor, or with the EmbeddedICE JTAG debug device.
20651
20652@kindex target rdp
20653@item target rdp @var{dev}
20654ARM Demon monitor.
20655
20656@end table
20657
e2f4edfd
EZ
20658@value{GDBN} provides the following ARM-specific commands:
20659
20660@table @code
20661@item set arm disassembler
20662@kindex set arm
20663This commands selects from a list of disassembly styles. The
20664@code{"std"} style is the standard style.
20665
20666@item show arm disassembler
20667@kindex show arm
20668Show the current disassembly style.
20669
20670@item set arm apcs32
20671@cindex ARM 32-bit mode
20672This command toggles ARM operation mode between 32-bit and 26-bit.
20673
20674@item show arm apcs32
20675Display the current usage of the ARM 32-bit mode.
20676
20677@item set arm fpu @var{fputype}
20678This command sets the ARM floating-point unit (FPU) type. The
20679argument @var{fputype} can be one of these:
20680
20681@table @code
20682@item auto
20683Determine the FPU type by querying the OS ABI.
20684@item softfpa
20685Software FPU, with mixed-endian doubles on little-endian ARM
20686processors.
20687@item fpa
20688GCC-compiled FPA co-processor.
20689@item softvfp
20690Software FPU with pure-endian doubles.
20691@item vfp
20692VFP co-processor.
20693@end table
20694
20695@item show arm fpu
20696Show the current type of the FPU.
20697
20698@item set arm abi
20699This command forces @value{GDBN} to use the specified ABI.
20700
20701@item show arm abi
20702Show the currently used ABI.
20703
0428b8f5
DJ
20704@item set arm fallback-mode (arm|thumb|auto)
20705@value{GDBN} uses the symbol table, when available, to determine
20706whether instructions are ARM or Thumb. This command controls
20707@value{GDBN}'s default behavior when the symbol table is not
20708available. The default is @samp{auto}, which causes @value{GDBN} to
20709use the current execution mode (from the @code{T} bit in the @code{CPSR}
20710register).
20711
20712@item show arm fallback-mode
20713Show the current fallback instruction mode.
20714
20715@item set arm force-mode (arm|thumb|auto)
20716This command overrides use of the symbol table to determine whether
20717instructions are ARM or Thumb. The default is @samp{auto}, which
20718causes @value{GDBN} to use the symbol table and then the setting
20719of @samp{set arm fallback-mode}.
20720
20721@item show arm force-mode
20722Show the current forced instruction mode.
20723
e2f4edfd
EZ
20724@item set debug arm
20725Toggle whether to display ARM-specific debugging messages from the ARM
20726target support subsystem.
20727
20728@item show debug arm
20729Show whether ARM-specific debugging messages are enabled.
20730@end table
20731
c45da7e6
EZ
20732The following commands are available when an ARM target is debugged
20733using the RDI interface:
20734
20735@table @code
20736@item rdilogfile @r{[}@var{file}@r{]}
20737@kindex rdilogfile
20738@cindex ADP (Angel Debugger Protocol) logging
20739Set the filename for the ADP (Angel Debugger Protocol) packet log.
20740With an argument, sets the log file to the specified @var{file}. With
20741no argument, show the current log file name. The default log file is
20742@file{rdi.log}.
20743
20744@item rdilogenable @r{[}@var{arg}@r{]}
20745@kindex rdilogenable
20746Control logging of ADP packets. With an argument of 1 or @code{"yes"}
20747enables logging, with an argument 0 or @code{"no"} disables it. With
20748no arguments displays the current setting. When logging is enabled,
20749ADP packets exchanged between @value{GDBN} and the RDI target device
20750are logged to a file.
20751
20752@item set rdiromatzero
20753@kindex set rdiromatzero
20754@cindex ROM at zero address, RDI
20755Tell @value{GDBN} whether the target has ROM at address 0. If on,
20756vector catching is disabled, so that zero address can be used. If off
20757(the default), vector catching is enabled. For this command to take
20758effect, it needs to be invoked prior to the @code{target rdi} command.
20759
20760@item show rdiromatzero
20761@kindex show rdiromatzero
20762Show the current setting of ROM at zero address.
20763
20764@item set rdiheartbeat
20765@kindex set rdiheartbeat
20766@cindex RDI heartbeat
20767Enable or disable RDI heartbeat packets. It is not recommended to
20768turn on this option, since it confuses ARM and EPI JTAG interface, as
20769well as the Angel monitor.
20770
20771@item show rdiheartbeat
20772@kindex show rdiheartbeat
20773Show the setting of RDI heartbeat packets.
20774@end table
20775
ee8e71d4
EZ
20776@table @code
20777@item target sim @r{[}@var{simargs}@r{]} @dots{}
20778The @value{GDBN} ARM simulator accepts the following optional arguments.
20779
20780@table @code
20781@item --swi-support=@var{type}
20782Tell the simulator which SWI interfaces to support.
20783@var{type} may be a comma separated list of the following values.
20784The default value is @code{all}.
20785
20786@table @code
20787@item none
20788@item demon
20789@item angel
20790@item redboot
20791@item all
20792@end table
20793@end table
20794@end table
e2f4edfd 20795
8e04817f 20796@node M32R/D
ba04e063 20797@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
20798
20799@table @code
8e04817f
AC
20800@kindex target m32r
20801@item target m32r @var{dev}
172c2a43 20802Renesas M32R/D ROM monitor.
8e04817f 20803
fb3e19c0
KI
20804@kindex target m32rsdi
20805@item target m32rsdi @var{dev}
20806Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
20807@end table
20808
20809The following @value{GDBN} commands are specific to the M32R monitor:
20810
20811@table @code
20812@item set download-path @var{path}
20813@kindex set download-path
20814@cindex find downloadable @sc{srec} files (M32R)
d3e8051b 20815Set the default path for finding downloadable @sc{srec} files.
721c2651
EZ
20816
20817@item show download-path
20818@kindex show download-path
20819Show the default path for downloadable @sc{srec} files.
fb3e19c0 20820
721c2651
EZ
20821@item set board-address @var{addr}
20822@kindex set board-address
20823@cindex M32-EVA target board address
20824Set the IP address for the M32R-EVA target board.
20825
20826@item show board-address
20827@kindex show board-address
20828Show the current IP address of the target board.
20829
20830@item set server-address @var{addr}
20831@kindex set server-address
20832@cindex download server address (M32R)
20833Set the IP address for the download server, which is the @value{GDBN}'s
20834host machine.
20835
20836@item show server-address
20837@kindex show server-address
20838Display the IP address of the download server.
20839
20840@item upload @r{[}@var{file}@r{]}
20841@kindex upload@r{, M32R}
20842Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
20843upload capability. If no @var{file} argument is given, the current
20844executable file is uploaded.
20845
20846@item tload @r{[}@var{file}@r{]}
20847@kindex tload@r{, M32R}
20848Test the @code{upload} command.
8e04817f
AC
20849@end table
20850
ba04e063
EZ
20851The following commands are available for M32R/SDI:
20852
20853@table @code
20854@item sdireset
20855@kindex sdireset
20856@cindex reset SDI connection, M32R
20857This command resets the SDI connection.
20858
20859@item sdistatus
20860@kindex sdistatus
20861This command shows the SDI connection status.
20862
20863@item debug_chaos
20864@kindex debug_chaos
20865@cindex M32R/Chaos debugging
20866Instructs the remote that M32R/Chaos debugging is to be used.
20867
20868@item use_debug_dma
20869@kindex use_debug_dma
20870Instructs the remote to use the DEBUG_DMA method of accessing memory.
20871
20872@item use_mon_code
20873@kindex use_mon_code
20874Instructs the remote to use the MON_CODE method of accessing memory.
20875
20876@item use_ib_break
20877@kindex use_ib_break
20878Instructs the remote to set breakpoints by IB break.
20879
20880@item use_dbt_break
20881@kindex use_dbt_break
20882Instructs the remote to set breakpoints by DBT.
20883@end table
20884
8e04817f
AC
20885@node M68K
20886@subsection M68k
20887
7ce59000
DJ
20888The Motorola m68k configuration includes ColdFire support, and a
20889target command for the following ROM monitor.
8e04817f
AC
20890
20891@table @code
20892
8e04817f
AC
20893@kindex target dbug
20894@item target dbug @var{dev}
20895dBUG ROM monitor for Motorola ColdFire.
20896
8e04817f
AC
20897@end table
20898
08be9d71
ME
20899@node MicroBlaze
20900@subsection MicroBlaze
20901@cindex Xilinx MicroBlaze
20902@cindex XMD, Xilinx Microprocessor Debugger
20903
20904The MicroBlaze is a soft-core processor supported on various Xilinx
20905FPGAs, such as Spartan or Virtex series. Boards with these processors
20906usually have JTAG ports which connect to a host system running the Xilinx
20907Embedded Development Kit (EDK) or Software Development Kit (SDK).
20908This host system is used to download the configuration bitstream to
20909the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
20910communicates with the target board using the JTAG interface and
20911presents a @code{gdbserver} interface to the board. By default
20912@code{xmd} uses port @code{1234}. (While it is possible to change
20913this default port, it requires the use of undocumented @code{xmd}
20914commands. Contact Xilinx support if you need to do this.)
20915
20916Use these GDB commands to connect to the MicroBlaze target processor.
20917
20918@table @code
20919@item target remote :1234
20920Use this command to connect to the target if you are running @value{GDBN}
20921on the same system as @code{xmd}.
20922
20923@item target remote @var{xmd-host}:1234
20924Use this command to connect to the target if it is connected to @code{xmd}
20925running on a different system named @var{xmd-host}.
20926
20927@item load
20928Use this command to download a program to the MicroBlaze target.
20929
20930@item set debug microblaze @var{n}
20931Enable MicroBlaze-specific debugging messages if non-zero.
20932
20933@item show debug microblaze @var{n}
20934Show MicroBlaze-specific debugging level.
20935@end table
20936
8e04817f 20937@node MIPS Embedded
eb17f351 20938@subsection @acronym{MIPS} Embedded
8e04817f 20939
eb17f351
EZ
20940@cindex @acronym{MIPS} boards
20941@value{GDBN} can use the @acronym{MIPS} remote debugging protocol to talk to a
20942@acronym{MIPS} board attached to a serial line. This is available when
cc30c4bd 20943you configure @value{GDBN} with @samp{--target=mips-elf}.
104c1213 20944
8e04817f
AC
20945@need 1000
20946Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 20947
8e04817f
AC
20948@table @code
20949@item target mips @var{port}
20950@kindex target mips @var{port}
20951To run a program on the board, start up @code{@value{GDBP}} with the
20952name of your program as the argument. To connect to the board, use the
20953command @samp{target mips @var{port}}, where @var{port} is the name of
20954the serial port connected to the board. If the program has not already
20955been downloaded to the board, you may use the @code{load} command to
20956download it. You can then use all the usual @value{GDBN} commands.
104c1213 20957
8e04817f
AC
20958For example, this sequence connects to the target board through a serial
20959port, and loads and runs a program called @var{prog} through the
20960debugger:
104c1213 20961
474c8240 20962@smallexample
8e04817f
AC
20963host$ @value{GDBP} @var{prog}
20964@value{GDBN} is free software and @dots{}
20965(@value{GDBP}) target mips /dev/ttyb
20966(@value{GDBP}) load @var{prog}
20967(@value{GDBP}) run
474c8240 20968@end smallexample
104c1213 20969
8e04817f
AC
20970@item target mips @var{hostname}:@var{portnumber}
20971On some @value{GDBN} host configurations, you can specify a TCP
20972connection (for instance, to a serial line managed by a terminal
20973concentrator) instead of a serial port, using the syntax
20974@samp{@var{hostname}:@var{portnumber}}.
104c1213 20975
8e04817f
AC
20976@item target pmon @var{port}
20977@kindex target pmon @var{port}
20978PMON ROM monitor.
104c1213 20979
8e04817f
AC
20980@item target ddb @var{port}
20981@kindex target ddb @var{port}
20982NEC's DDB variant of PMON for Vr4300.
104c1213 20983
8e04817f
AC
20984@item target lsi @var{port}
20985@kindex target lsi @var{port}
20986LSI variant of PMON.
104c1213 20987
8e04817f
AC
20988@kindex target r3900
20989@item target r3900 @var{dev}
20990Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 20991
8e04817f
AC
20992@kindex target array
20993@item target array @var{dev}
20994Array Tech LSI33K RAID controller board.
104c1213 20995
8e04817f 20996@end table
104c1213 20997
104c1213 20998
8e04817f 20999@noindent
eb17f351 21000@value{GDBN} also supports these special commands for @acronym{MIPS} targets:
104c1213 21001
8e04817f 21002@table @code
8e04817f
AC
21003@item set mipsfpu double
21004@itemx set mipsfpu single
21005@itemx set mipsfpu none
a64548ea 21006@itemx set mipsfpu auto
8e04817f
AC
21007@itemx show mipsfpu
21008@kindex set mipsfpu
21009@kindex show mipsfpu
eb17f351
EZ
21010@cindex @acronym{MIPS} remote floating point
21011@cindex floating point, @acronym{MIPS} remote
21012If your target board does not support the @acronym{MIPS} floating point
8e04817f
AC
21013coprocessor, you should use the command @samp{set mipsfpu none} (if you
21014need this, you may wish to put the command in your @value{GDBN} init
21015file). This tells @value{GDBN} how to find the return value of
21016functions which return floating point values. It also allows
21017@value{GDBN} to avoid saving the floating point registers when calling
21018functions on the board. If you are using a floating point coprocessor
21019with only single precision floating point support, as on the @sc{r4650}
21020processor, use the command @samp{set mipsfpu single}. The default
21021double precision floating point coprocessor may be selected using
21022@samp{set mipsfpu double}.
104c1213 21023
8e04817f
AC
21024In previous versions the only choices were double precision or no
21025floating point, so @samp{set mipsfpu on} will select double precision
21026and @samp{set mipsfpu off} will select no floating point.
104c1213 21027
8e04817f
AC
21028As usual, you can inquire about the @code{mipsfpu} variable with
21029@samp{show mipsfpu}.
104c1213 21030
8e04817f
AC
21031@item set timeout @var{seconds}
21032@itemx set retransmit-timeout @var{seconds}
21033@itemx show timeout
21034@itemx show retransmit-timeout
eb17f351
EZ
21035@cindex @code{timeout}, @acronym{MIPS} protocol
21036@cindex @code{retransmit-timeout}, @acronym{MIPS} protocol
8e04817f
AC
21037@kindex set timeout
21038@kindex show timeout
21039@kindex set retransmit-timeout
21040@kindex show retransmit-timeout
eb17f351 21041You can control the timeout used while waiting for a packet, in the @acronym{MIPS}
8e04817f
AC
21042remote protocol, with the @code{set timeout @var{seconds}} command. The
21043default is 5 seconds. Similarly, you can control the timeout used while
a6f3e723 21044waiting for an acknowledgment of a packet with the @code{set
8e04817f
AC
21045retransmit-timeout @var{seconds}} command. The default is 3 seconds.
21046You can inspect both values with @code{show timeout} and @code{show
21047retransmit-timeout}. (These commands are @emph{only} available when
cc30c4bd 21048@value{GDBN} is configured for @samp{--target=mips-elf}.)
104c1213 21049
8e04817f
AC
21050The timeout set by @code{set timeout} does not apply when @value{GDBN}
21051is waiting for your program to stop. In that case, @value{GDBN} waits
21052forever because it has no way of knowing how long the program is going
21053to run before stopping.
ba04e063
EZ
21054
21055@item set syn-garbage-limit @var{num}
eb17f351
EZ
21056@kindex set syn-garbage-limit@r{, @acronym{MIPS} remote}
21057@cindex synchronize with remote @acronym{MIPS} target
ba04e063
EZ
21058Limit the maximum number of characters @value{GDBN} should ignore when
21059it tries to synchronize with the remote target. The default is 10
21060characters. Setting the limit to -1 means there's no limit.
21061
21062@item show syn-garbage-limit
eb17f351 21063@kindex show syn-garbage-limit@r{, @acronym{MIPS} remote}
ba04e063
EZ
21064Show the current limit on the number of characters to ignore when
21065trying to synchronize with the remote system.
21066
21067@item set monitor-prompt @var{prompt}
eb17f351 21068@kindex set monitor-prompt@r{, @acronym{MIPS} remote}
ba04e063
EZ
21069@cindex remote monitor prompt
21070Tell @value{GDBN} to expect the specified @var{prompt} string from the
21071remote monitor. The default depends on the target:
21072@table @asis
21073@item pmon target
21074@samp{PMON}
21075@item ddb target
21076@samp{NEC010}
21077@item lsi target
21078@samp{PMON>}
21079@end table
21080
21081@item show monitor-prompt
eb17f351 21082@kindex show monitor-prompt@r{, @acronym{MIPS} remote}
ba04e063
EZ
21083Show the current strings @value{GDBN} expects as the prompt from the
21084remote monitor.
21085
21086@item set monitor-warnings
eb17f351 21087@kindex set monitor-warnings@r{, @acronym{MIPS} remote}
ba04e063
EZ
21088Enable or disable monitor warnings about hardware breakpoints. This
21089has effect only for the @code{lsi} target. When on, @value{GDBN} will
21090display warning messages whose codes are returned by the @code{lsi}
21091PMON monitor for breakpoint commands.
21092
21093@item show monitor-warnings
eb17f351 21094@kindex show monitor-warnings@r{, @acronym{MIPS} remote}
ba04e063
EZ
21095Show the current setting of printing monitor warnings.
21096
21097@item pmon @var{command}
eb17f351 21098@kindex pmon@r{, @acronym{MIPS} remote}
ba04e063
EZ
21099@cindex send PMON command
21100This command allows sending an arbitrary @var{command} string to the
21101monitor. The monitor must be in debug mode for this to work.
8e04817f 21102@end table
104c1213 21103
4acd40f3
TJB
21104@node PowerPC Embedded
21105@subsection PowerPC Embedded
104c1213 21106
66b73624
TJB
21107@cindex DVC register
21108@value{GDBN} supports using the DVC (Data Value Compare) register to
21109implement in hardware simple hardware watchpoint conditions of the form:
21110
21111@smallexample
21112(@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
21113 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
21114@end smallexample
21115
e09342b5
TJB
21116The DVC register will be automatically used when @value{GDBN} detects
21117such pattern in a condition expression, and the created watchpoint uses one
21118debug register (either the @code{exact-watchpoints} option is on and the
21119variable is scalar, or the variable has a length of one byte). This feature
21120is available in native @value{GDBN} running on a Linux kernel version 2.6.34
21121or newer.
21122
21123When running on PowerPC embedded processors, @value{GDBN} automatically uses
21124ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
21125in which case watchpoints using only one debug register are created when
21126watching variables of scalar types.
21127
21128You can create an artificial array to watch an arbitrary memory
21129region using one of the following commands (@pxref{Expressions}):
21130
21131@smallexample
21132(@value{GDBP}) watch *((char *) @var{address})@@@var{length}
21133(@value{GDBP}) watch @{char[@var{length}]@} @var{address}
21134@end smallexample
66b73624 21135
9c06b0b4
TJB
21136PowerPC embedded processors support masked watchpoints. See the discussion
21137about the @code{mask} argument in @ref{Set Watchpoints}.
21138
f1310107
TJB
21139@cindex ranged breakpoint
21140PowerPC embedded processors support hardware accelerated
21141@dfn{ranged breakpoints}. A ranged breakpoint stops execution of
21142the inferior whenever it executes an instruction at any address within
21143the range it specifies. To set a ranged breakpoint in @value{GDBN},
21144use the @code{break-range} command.
21145
55eddb0f
DJ
21146@value{GDBN} provides the following PowerPC-specific commands:
21147
104c1213 21148@table @code
f1310107
TJB
21149@kindex break-range
21150@item break-range @var{start-location}, @var{end-location}
21151Set a breakpoint for an address range.
21152@var{start-location} and @var{end-location} can specify a function name,
21153a line number, an offset of lines from the current line or from the start
21154location, or an address of an instruction (see @ref{Specify Location},
21155for a list of all the possible ways to specify a @var{location}.)
21156The breakpoint will stop execution of the inferior whenever it
21157executes an instruction at any address within the specified range,
21158(including @var{start-location} and @var{end-location}.)
21159
55eddb0f
DJ
21160@kindex set powerpc
21161@item set powerpc soft-float
21162@itemx show powerpc soft-float
21163Force @value{GDBN} to use (or not use) a software floating point calling
21164convention. By default, @value{GDBN} selects the calling convention based
21165on the selected architecture and the provided executable file.
21166
21167@item set powerpc vector-abi
21168@itemx show powerpc vector-abi
21169Force @value{GDBN} to use the specified calling convention for vector
21170arguments and return values. The valid options are @samp{auto};
21171@samp{generic}, to avoid vector registers even if they are present;
21172@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
21173registers. By default, @value{GDBN} selects the calling convention
21174based on the selected architecture and the provided executable file.
21175
e09342b5
TJB
21176@item set powerpc exact-watchpoints
21177@itemx show powerpc exact-watchpoints
21178Allow @value{GDBN} to use only one debug register when watching a variable
21179of scalar type, thus assuming that the variable is accessed through the
21180address of its first byte.
21181
8e04817f
AC
21182@kindex target dink32
21183@item target dink32 @var{dev}
21184DINK32 ROM monitor.
104c1213 21185
8e04817f
AC
21186@kindex target ppcbug
21187@item target ppcbug @var{dev}
21188@kindex target ppcbug1
21189@item target ppcbug1 @var{dev}
21190PPCBUG ROM monitor for PowerPC.
104c1213 21191
8e04817f
AC
21192@kindex target sds
21193@item target sds @var{dev}
21194SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 21195@end table
8e04817f 21196
c45da7e6 21197@cindex SDS protocol
d52fb0e9 21198The following commands specific to the SDS protocol are supported
55eddb0f 21199by @value{GDBN}:
c45da7e6
EZ
21200
21201@table @code
21202@item set sdstimeout @var{nsec}
21203@kindex set sdstimeout
21204Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
21205default is 2 seconds.
21206
21207@item show sdstimeout
21208@kindex show sdstimeout
21209Show the current value of the SDS timeout.
21210
21211@item sds @var{command}
21212@kindex sds@r{, a command}
21213Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
21214@end table
21215
c45da7e6 21216
8e04817f
AC
21217@node PA
21218@subsection HP PA Embedded
104c1213
JM
21219
21220@table @code
21221
8e04817f
AC
21222@kindex target op50n
21223@item target op50n @var{dev}
21224OP50N monitor, running on an OKI HPPA board.
21225
21226@kindex target w89k
21227@item target w89k @var{dev}
21228W89K monitor, running on a Winbond HPPA board.
104c1213
JM
21229
21230@end table
21231
8e04817f
AC
21232@node Sparclet
21233@subsection Tsqware Sparclet
104c1213 21234
8e04817f
AC
21235@cindex Sparclet
21236
21237@value{GDBN} enables developers to debug tasks running on
21238Sparclet targets from a Unix host.
21239@value{GDBN} uses code that runs on
21240both the Unix host and on the Sparclet target. The program
21241@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 21242
8e04817f
AC
21243@table @code
21244@item remotetimeout @var{args}
21245@kindex remotetimeout
21246@value{GDBN} supports the option @code{remotetimeout}.
21247This option is set by the user, and @var{args} represents the number of
21248seconds @value{GDBN} waits for responses.
104c1213
JM
21249@end table
21250
8e04817f
AC
21251@cindex compiling, on Sparclet
21252When compiling for debugging, include the options @samp{-g} to get debug
21253information and @samp{-Ttext} to relocate the program to where you wish to
21254load it on the target. You may also want to add the options @samp{-n} or
21255@samp{-N} in order to reduce the size of the sections. Example:
104c1213 21256
474c8240 21257@smallexample
8e04817f 21258sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 21259@end smallexample
104c1213 21260
8e04817f 21261You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 21262
474c8240 21263@smallexample
8e04817f 21264sparclet-aout-objdump --headers --syms prog
474c8240 21265@end smallexample
104c1213 21266
8e04817f
AC
21267@cindex running, on Sparclet
21268Once you have set
21269your Unix execution search path to find @value{GDBN}, you are ready to
21270run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
21271(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 21272
8e04817f
AC
21273@value{GDBN} comes up showing the prompt:
21274
474c8240 21275@smallexample
8e04817f 21276(gdbslet)
474c8240 21277@end smallexample
104c1213
JM
21278
21279@menu
8e04817f
AC
21280* Sparclet File:: Setting the file to debug
21281* Sparclet Connection:: Connecting to Sparclet
21282* Sparclet Download:: Sparclet download
21283* Sparclet Execution:: Running and debugging
104c1213
JM
21284@end menu
21285
8e04817f 21286@node Sparclet File
79a6e687 21287@subsubsection Setting File to Debug
104c1213 21288
8e04817f 21289The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 21290
474c8240 21291@smallexample
8e04817f 21292(gdbslet) file prog
474c8240 21293@end smallexample
104c1213 21294
8e04817f
AC
21295@need 1000
21296@value{GDBN} then attempts to read the symbol table of @file{prog}.
21297@value{GDBN} locates
21298the file by searching the directories listed in the command search
21299path.
12c27660 21300If the file was compiled with debug information (option @samp{-g}), source
8e04817f
AC
21301files will be searched as well.
21302@value{GDBN} locates
21303the source files by searching the directories listed in the directory search
79a6e687 21304path (@pxref{Environment, ,Your Program's Environment}).
8e04817f
AC
21305If it fails
21306to find a file, it displays a message such as:
104c1213 21307
474c8240 21308@smallexample
8e04817f 21309prog: No such file or directory.
474c8240 21310@end smallexample
104c1213 21311
8e04817f
AC
21312When this happens, add the appropriate directories to the search paths with
21313the @value{GDBN} commands @code{path} and @code{dir}, and execute the
21314@code{target} command again.
104c1213 21315
8e04817f
AC
21316@node Sparclet Connection
21317@subsubsection Connecting to Sparclet
104c1213 21318
8e04817f
AC
21319The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
21320To connect to a target on serial port ``@code{ttya}'', type:
104c1213 21321
474c8240 21322@smallexample
8e04817f
AC
21323(gdbslet) target sparclet /dev/ttya
21324Remote target sparclet connected to /dev/ttya
21325main () at ../prog.c:3
474c8240 21326@end smallexample
104c1213 21327
8e04817f
AC
21328@need 750
21329@value{GDBN} displays messages like these:
104c1213 21330
474c8240 21331@smallexample
8e04817f 21332Connected to ttya.
474c8240 21333@end smallexample
104c1213 21334
8e04817f 21335@node Sparclet Download
79a6e687 21336@subsubsection Sparclet Download
104c1213 21337
8e04817f
AC
21338@cindex download to Sparclet
21339Once connected to the Sparclet target,
21340you can use the @value{GDBN}
21341@code{load} command to download the file from the host to the target.
21342The file name and load offset should be given as arguments to the @code{load}
21343command.
21344Since the file format is aout, the program must be loaded to the starting
21345address. You can use @code{objdump} to find out what this value is. The load
21346offset is an offset which is added to the VMA (virtual memory address)
21347of each of the file's sections.
21348For instance, if the program
21349@file{prog} was linked to text address 0x1201000, with data at 0x12010160
21350and bss at 0x12010170, in @value{GDBN}, type:
104c1213 21351
474c8240 21352@smallexample
8e04817f
AC
21353(gdbslet) load prog 0x12010000
21354Loading section .text, size 0xdb0 vma 0x12010000
474c8240 21355@end smallexample
104c1213 21356
8e04817f
AC
21357If the code is loaded at a different address then what the program was linked
21358to, you may need to use the @code{section} and @code{add-symbol-file} commands
21359to tell @value{GDBN} where to map the symbol table.
21360
21361@node Sparclet Execution
79a6e687 21362@subsubsection Running and Debugging
8e04817f
AC
21363
21364@cindex running and debugging Sparclet programs
21365You can now begin debugging the task using @value{GDBN}'s execution control
21366commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
21367manual for the list of commands.
21368
474c8240 21369@smallexample
8e04817f
AC
21370(gdbslet) b main
21371Breakpoint 1 at 0x12010000: file prog.c, line 3.
21372(gdbslet) run
21373Starting program: prog
21374Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
213753 char *symarg = 0;
21376(gdbslet) step
213774 char *execarg = "hello!";
21378(gdbslet)
474c8240 21379@end smallexample
8e04817f
AC
21380
21381@node Sparclite
21382@subsection Fujitsu Sparclite
104c1213
JM
21383
21384@table @code
21385
8e04817f
AC
21386@kindex target sparclite
21387@item target sparclite @var{dev}
21388Fujitsu sparclite boards, used only for the purpose of loading.
21389You must use an additional command to debug the program.
21390For example: target remote @var{dev} using @value{GDBN} standard
21391remote protocol.
104c1213
JM
21392
21393@end table
21394
8e04817f
AC
21395@node Z8000
21396@subsection Zilog Z8000
104c1213 21397
8e04817f
AC
21398@cindex Z8000
21399@cindex simulator, Z8000
21400@cindex Zilog Z8000 simulator
104c1213 21401
8e04817f
AC
21402When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
21403a Z8000 simulator.
21404
21405For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
21406unsegmented variant of the Z8000 architecture) or the Z8001 (the
21407segmented variant). The simulator recognizes which architecture is
21408appropriate by inspecting the object code.
104c1213 21409
8e04817f
AC
21410@table @code
21411@item target sim @var{args}
21412@kindex sim
21413@kindex target sim@r{, with Z8000}
21414Debug programs on a simulated CPU. If the simulator supports setup
21415options, specify them via @var{args}.
104c1213
JM
21416@end table
21417
8e04817f
AC
21418@noindent
21419After specifying this target, you can debug programs for the simulated
21420CPU in the same style as programs for your host computer; use the
21421@code{file} command to load a new program image, the @code{run} command
21422to run your program, and so on.
21423
21424As well as making available all the usual machine registers
21425(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
21426additional items of information as specially named registers:
104c1213
JM
21427
21428@table @code
21429
8e04817f
AC
21430@item cycles
21431Counts clock-ticks in the simulator.
104c1213 21432
8e04817f
AC
21433@item insts
21434Counts instructions run in the simulator.
104c1213 21435
8e04817f
AC
21436@item time
21437Execution time in 60ths of a second.
104c1213 21438
8e04817f 21439@end table
104c1213 21440
8e04817f
AC
21441You can refer to these values in @value{GDBN} expressions with the usual
21442conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
21443conditional breakpoint that suspends only after at least 5000
21444simulated clock ticks.
104c1213 21445
a64548ea
EZ
21446@node AVR
21447@subsection Atmel AVR
21448@cindex AVR
21449
21450When configured for debugging the Atmel AVR, @value{GDBN} supports the
21451following AVR-specific commands:
21452
21453@table @code
21454@item info io_registers
21455@kindex info io_registers@r{, AVR}
21456@cindex I/O registers (Atmel AVR)
21457This command displays information about the AVR I/O registers. For
21458each register, @value{GDBN} prints its number and value.
21459@end table
21460
21461@node CRIS
21462@subsection CRIS
21463@cindex CRIS
21464
21465When configured for debugging CRIS, @value{GDBN} provides the
21466following CRIS-specific commands:
21467
21468@table @code
21469@item set cris-version @var{ver}
21470@cindex CRIS version
e22e55c9
OF
21471Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
21472The CRIS version affects register names and sizes. This command is useful in
21473case autodetection of the CRIS version fails.
a64548ea
EZ
21474
21475@item show cris-version
21476Show the current CRIS version.
21477
21478@item set cris-dwarf2-cfi
21479@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
21480Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
21481Change to @samp{off} when using @code{gcc-cris} whose version is below
21482@code{R59}.
a64548ea
EZ
21483
21484@item show cris-dwarf2-cfi
21485Show the current state of using DWARF-2 CFI.
e22e55c9
OF
21486
21487@item set cris-mode @var{mode}
21488@cindex CRIS mode
21489Set the current CRIS mode to @var{mode}. It should only be changed when
21490debugging in guru mode, in which case it should be set to
21491@samp{guru} (the default is @samp{normal}).
21492
21493@item show cris-mode
21494Show the current CRIS mode.
a64548ea
EZ
21495@end table
21496
21497@node Super-H
21498@subsection Renesas Super-H
21499@cindex Super-H
21500
21501For the Renesas Super-H processor, @value{GDBN} provides these
21502commands:
21503
21504@table @code
c055b101
CV
21505@item set sh calling-convention @var{convention}
21506@kindex set sh calling-convention
21507Set the calling-convention used when calling functions from @value{GDBN}.
21508Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
21509With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
21510convention. If the DWARF-2 information of the called function specifies
21511that the function follows the Renesas calling convention, the function
21512is called using the Renesas calling convention. If the calling convention
21513is set to @samp{renesas}, the Renesas calling convention is always used,
21514regardless of the DWARF-2 information. This can be used to override the
21515default of @samp{gcc} if debug information is missing, or the compiler
21516does not emit the DWARF-2 calling convention entry for a function.
21517
21518@item show sh calling-convention
21519@kindex show sh calling-convention
21520Show the current calling convention setting.
21521
a64548ea
EZ
21522@end table
21523
21524
8e04817f
AC
21525@node Architectures
21526@section Architectures
104c1213 21527
8e04817f
AC
21528This section describes characteristics of architectures that affect
21529all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 21530
8e04817f 21531@menu
430ed3f0 21532* AArch64::
9c16f35a 21533* i386::
8e04817f
AC
21534* Alpha::
21535* MIPS::
a64548ea 21536* HPPA:: HP PA architecture
23d964e7 21537* SPU:: Cell Broadband Engine SPU architecture
4acd40f3 21538* PowerPC::
a1217d97 21539* Nios II::
8e04817f 21540@end menu
104c1213 21541
430ed3f0
MS
21542@node AArch64
21543@subsection AArch64
21544@cindex AArch64 support
21545
21546When @value{GDBN} is debugging the AArch64 architecture, it provides the
21547following special commands:
21548
21549@table @code
21550@item set debug aarch64
21551@kindex set debug aarch64
21552This command determines whether AArch64 architecture-specific debugging
21553messages are to be displayed.
21554
21555@item show debug aarch64
21556Show whether AArch64 debugging messages are displayed.
21557
21558@end table
21559
9c16f35a 21560@node i386
db2e3e2e 21561@subsection x86 Architecture-specific Issues
9c16f35a
EZ
21562
21563@table @code
21564@item set struct-convention @var{mode}
21565@kindex set struct-convention
21566@cindex struct return convention
21567@cindex struct/union returned in registers
21568Set the convention used by the inferior to return @code{struct}s and
21569@code{union}s from functions to @var{mode}. Possible values of
21570@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
21571default). @code{"default"} or @code{"pcc"} means that @code{struct}s
21572are returned on the stack, while @code{"reg"} means that a
21573@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
21574be returned in a register.
21575
21576@item show struct-convention
21577@kindex show struct-convention
21578Show the current setting of the convention to return @code{struct}s
21579from functions.
3ea8680f 21580@end table
ca8941bb 21581
ca8941bb 21582@subsubsection Intel(R) @dfn{Memory Protection Extensions} (MPX).
22f25c9d 21583@cindex Intel(R) Memory Protection Extensions (MPX).
ca8941bb 21584
ca8941bb
WT
21585Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
21586@footnote{The register named with capital letters represent the architecture
21587registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
21588which are the lower bound and upper bound. Bounds are effective addresses or
21589memory locations. The upper bounds are architecturally represented in 1's
21590complement form. A bound having lower bound = 0, and upper bound = 0
21591(1's complement of all bits set) will allow access to the entire address space.
21592
21593@samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
21594through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
21595display the upper bound performing the complement of one operation on the
21596upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
21597@value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
21598can also be noted that the upper bounds are inclusive.
21599
21600As an example, assume that the register BND0 holds bounds for a pointer having
21601access allowed for the range between 0x32 and 0x71. The values present on
21602bnd0raw and bnd registers are presented as follows:
21603
21604@smallexample
21605 bnd0raw = @{0x32, 0xffffffff8e@}
21606 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
21607@end smallexample
21608
22f25c9d
EZ
21609This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
21610change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
21611counterpart. When the bnd0@dots{}bnd3 registers are displayed via
21612Python, the display includes the memory size, in bits, accessible to
21613the pointer.
9c16f35a 21614
8e04817f
AC
21615@node Alpha
21616@subsection Alpha
104c1213 21617
8e04817f 21618See the following section.
104c1213 21619
8e04817f 21620@node MIPS
eb17f351 21621@subsection @acronym{MIPS}
104c1213 21622
8e04817f 21623@cindex stack on Alpha
eb17f351 21624@cindex stack on @acronym{MIPS}
8e04817f 21625@cindex Alpha stack
eb17f351
EZ
21626@cindex @acronym{MIPS} stack
21627Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
8e04817f
AC
21628sometimes requires @value{GDBN} to search backward in the object code to
21629find the beginning of a function.
104c1213 21630
eb17f351 21631@cindex response time, @acronym{MIPS} debugging
8e04817f
AC
21632To improve response time (especially for embedded applications, where
21633@value{GDBN} may be restricted to a slow serial line for this search)
21634you may want to limit the size of this search, using one of these
21635commands:
104c1213 21636
8e04817f 21637@table @code
eb17f351 21638@cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
8e04817f
AC
21639@item set heuristic-fence-post @var{limit}
21640Restrict @value{GDBN} to examining at most @var{limit} bytes in its
21641search for the beginning of a function. A value of @var{0} (the
21642default) means there is no limit. However, except for @var{0}, the
21643larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
21644and therefore the longer it takes to run. You should only need to use
21645this command when debugging a stripped executable.
104c1213 21646
8e04817f
AC
21647@item show heuristic-fence-post
21648Display the current limit.
21649@end table
104c1213
JM
21650
21651@noindent
8e04817f 21652These commands are available @emph{only} when @value{GDBN} is configured
eb17f351 21653for debugging programs on Alpha or @acronym{MIPS} processors.
104c1213 21654
eb17f351 21655Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
a64548ea
EZ
21656programs:
21657
21658@table @code
a64548ea
EZ
21659@item set mips abi @var{arg}
21660@kindex set mips abi
eb17f351
EZ
21661@cindex set ABI for @acronym{MIPS}
21662Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
a64548ea
EZ
21663values of @var{arg} are:
21664
21665@table @samp
21666@item auto
21667The default ABI associated with the current binary (this is the
21668default).
21669@item o32
21670@item o64
21671@item n32
21672@item n64
21673@item eabi32
21674@item eabi64
a64548ea
EZ
21675@end table
21676
21677@item show mips abi
21678@kindex show mips abi
eb17f351 21679Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
a64548ea 21680
4cc0665f
MR
21681@item set mips compression @var{arg}
21682@kindex set mips compression
21683@cindex code compression, @acronym{MIPS}
21684Tell @value{GDBN} which @acronym{MIPS} compressed
21685@acronym{ISA, Instruction Set Architecture} encoding is used by the
21686inferior. @value{GDBN} uses this for code disassembly and other
21687internal interpretation purposes. This setting is only referred to
21688when no executable has been associated with the debugging session or
21689the executable does not provide information about the encoding it uses.
21690Otherwise this setting is automatically updated from information
21691provided by the executable.
21692
21693Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
21694The default compressed @acronym{ISA} encoding is @samp{mips16}, as
21695executables containing @acronym{MIPS16} code frequently are not
21696identified as such.
21697
21698This setting is ``sticky''; that is, it retains its value across
21699debugging sessions until reset either explicitly with this command or
21700implicitly from an executable.
21701
21702The compiler and/or assembler typically add symbol table annotations to
21703identify functions compiled for the @acronym{MIPS16} or
21704@acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
21705are present, @value{GDBN} uses them in preference to the global
21706compressed @acronym{ISA} encoding setting.
21707
21708@item show mips compression
21709@kindex show mips compression
21710Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
21711@value{GDBN} to debug the inferior.
21712
a64548ea
EZ
21713@item set mipsfpu
21714@itemx show mipsfpu
21715@xref{MIPS Embedded, set mipsfpu}.
21716
21717@item set mips mask-address @var{arg}
21718@kindex set mips mask-address
eb17f351 21719@cindex @acronym{MIPS} addresses, masking
a64548ea 21720This command determines whether the most-significant 32 bits of 64-bit
eb17f351 21721@acronym{MIPS} addresses are masked off. The argument @var{arg} can be
a64548ea
EZ
21722@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
21723setting, which lets @value{GDBN} determine the correct value.
21724
21725@item show mips mask-address
21726@kindex show mips mask-address
eb17f351 21727Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
a64548ea
EZ
21728not.
21729
21730@item set remote-mips64-transfers-32bit-regs
21731@kindex set remote-mips64-transfers-32bit-regs
eb17f351
EZ
21732This command controls compatibility with 64-bit @acronym{MIPS} targets that
21733transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
a64548ea
EZ
21734that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
21735and 64 bits for other registers, set this option to @samp{on}.
21736
21737@item show remote-mips64-transfers-32bit-regs
21738@kindex show remote-mips64-transfers-32bit-regs
eb17f351 21739Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
a64548ea
EZ
21740
21741@item set debug mips
21742@kindex set debug mips
eb17f351 21743This command turns on and off debugging messages for the @acronym{MIPS}-specific
a64548ea
EZ
21744target code in @value{GDBN}.
21745
21746@item show debug mips
21747@kindex show debug mips
eb17f351 21748Show the current setting of @acronym{MIPS} debugging messages.
a64548ea
EZ
21749@end table
21750
21751
21752@node HPPA
21753@subsection HPPA
21754@cindex HPPA support
21755
d3e8051b 21756When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
21757following special commands:
21758
21759@table @code
21760@item set debug hppa
21761@kindex set debug hppa
db2e3e2e 21762This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
21763messages are to be displayed.
21764
21765@item show debug hppa
21766Show whether HPPA debugging messages are displayed.
21767
21768@item maint print unwind @var{address}
21769@kindex maint print unwind@r{, HPPA}
21770This command displays the contents of the unwind table entry at the
21771given @var{address}.
21772
21773@end table
21774
104c1213 21775
23d964e7
UW
21776@node SPU
21777@subsection Cell Broadband Engine SPU architecture
21778@cindex Cell Broadband Engine
21779@cindex SPU
21780
21781When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
21782it provides the following special commands:
21783
21784@table @code
21785@item info spu event
21786@kindex info spu
21787Display SPU event facility status. Shows current event mask
21788and pending event status.
21789
21790@item info spu signal
21791Display SPU signal notification facility status. Shows pending
21792signal-control word and signal notification mode of both signal
21793notification channels.
21794
21795@item info spu mailbox
21796Display SPU mailbox facility status. Shows all pending entries,
21797in order of processing, in each of the SPU Write Outbound,
21798SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
21799
21800@item info spu dma
21801Display MFC DMA status. Shows all pending commands in the MFC
21802DMA queue. For each entry, opcode, tag, class IDs, effective
21803and local store addresses and transfer size are shown.
21804
21805@item info spu proxydma
21806Display MFC Proxy-DMA status. Shows all pending commands in the MFC
21807Proxy-DMA queue. For each entry, opcode, tag, class IDs, effective
21808and local store addresses and transfer size are shown.
21809
21810@end table
21811
3285f3fe
UW
21812When @value{GDBN} is debugging a combined PowerPC/SPU application
21813on the Cell Broadband Engine, it provides in addition the following
21814special commands:
21815
21816@table @code
21817@item set spu stop-on-load @var{arg}
21818@kindex set spu
21819Set whether to stop for new SPE threads. When set to @code{on}, @value{GDBN}
21820will give control to the user when a new SPE thread enters its @code{main}
21821function. The default is @code{off}.
21822
21823@item show spu stop-on-load
21824@kindex show spu
21825Show whether to stop for new SPE threads.
21826
ff1a52c6
UW
21827@item set spu auto-flush-cache @var{arg}
21828Set whether to automatically flush the software-managed cache. When set to
21829@code{on}, @value{GDBN} will automatically cause the SPE software-managed
21830cache to be flushed whenever SPE execution stops. This provides a consistent
21831view of PowerPC memory that is accessed via the cache. If an application
21832does not use the software-managed cache, this option has no effect.
21833
21834@item show spu auto-flush-cache
21835Show whether to automatically flush the software-managed cache.
21836
3285f3fe
UW
21837@end table
21838
4acd40f3
TJB
21839@node PowerPC
21840@subsection PowerPC
21841@cindex PowerPC architecture
21842
21843When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
21844pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
21845numbers stored in the floating point registers. These values must be stored
21846in two consecutive registers, always starting at an even register like
21847@code{f0} or @code{f2}.
21848
21849The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
21850by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
21851@code{f2} and @code{f3} for @code{$dl1} and so on.
21852
aeac0ff9 21853For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
677c5bb1
LM
21854wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
21855
a1217d97
SL
21856@node Nios II
21857@subsection Nios II
21858@cindex Nios II architecture
21859
21860When @value{GDBN} is debugging the Nios II architecture,
21861it provides the following special commands:
21862
21863@table @code
21864
21865@item set debug nios2
21866@kindex set debug nios2
21867This command turns on and off debugging messages for the Nios II
21868target code in @value{GDBN}.
21869
21870@item show debug nios2
21871@kindex show debug nios2
21872Show the current setting of Nios II debugging messages.
21873@end table
23d964e7 21874
8e04817f
AC
21875@node Controlling GDB
21876@chapter Controlling @value{GDBN}
21877
21878You can alter the way @value{GDBN} interacts with you by using the
21879@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 21880data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
21881described here.
21882
21883@menu
21884* Prompt:: Prompt
21885* Editing:: Command editing
d620b259 21886* Command History:: Command history
8e04817f
AC
21887* Screen Size:: Screen size
21888* Numbers:: Numbers
1e698235 21889* ABI:: Configuring the current ABI
bf88dd68 21890* Auto-loading:: Automatically loading associated files
8e04817f
AC
21891* Messages/Warnings:: Optional warnings and messages
21892* Debugging Output:: Optional messages about internal happenings
14fb1bac 21893* Other Misc Settings:: Other Miscellaneous Settings
8e04817f
AC
21894@end menu
21895
21896@node Prompt
21897@section Prompt
104c1213 21898
8e04817f 21899@cindex prompt
104c1213 21900
8e04817f
AC
21901@value{GDBN} indicates its readiness to read a command by printing a string
21902called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
21903can change the prompt string with the @code{set prompt} command. For
21904instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
21905the prompt in one of the @value{GDBN} sessions so that you can always tell
21906which one you are talking to.
104c1213 21907
8e04817f
AC
21908@emph{Note:} @code{set prompt} does not add a space for you after the
21909prompt you set. This allows you to set a prompt which ends in a space
21910or a prompt that does not.
104c1213 21911
8e04817f
AC
21912@table @code
21913@kindex set prompt
21914@item set prompt @var{newprompt}
21915Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 21916
8e04817f
AC
21917@kindex show prompt
21918@item show prompt
21919Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
21920@end table
21921
fa3a4f15
PM
21922Versions of @value{GDBN} that ship with Python scripting enabled have
21923prompt extensions. The commands for interacting with these extensions
21924are:
21925
21926@table @code
21927@kindex set extended-prompt
21928@item set extended-prompt @var{prompt}
21929Set an extended prompt that allows for substitutions.
21930@xref{gdb.prompt}, for a list of escape sequences that can be used for
21931substitution. Any escape sequences specified as part of the prompt
21932string are replaced with the corresponding strings each time the prompt
21933is displayed.
21934
21935For example:
21936
21937@smallexample
21938set extended-prompt Current working directory: \w (gdb)
21939@end smallexample
21940
21941Note that when an extended-prompt is set, it takes control of the
21942@var{prompt_hook} hook. @xref{prompt_hook}, for further information.
21943
21944@kindex show extended-prompt
21945@item show extended-prompt
21946Prints the extended prompt. Any escape sequences specified as part of
21947the prompt string with @code{set extended-prompt}, are replaced with the
21948corresponding strings each time the prompt is displayed.
21949@end table
21950
8e04817f 21951@node Editing
79a6e687 21952@section Command Editing
8e04817f
AC
21953@cindex readline
21954@cindex command line editing
104c1213 21955
703663ab 21956@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
21957@sc{gnu} library provides consistent behavior for programs which provide a
21958command line interface to the user. Advantages are @sc{gnu} Emacs-style
21959or @dfn{vi}-style inline editing of commands, @code{csh}-like history
21960substitution, and a storage and recall of command history across
21961debugging sessions.
104c1213 21962
8e04817f
AC
21963You may control the behavior of command line editing in @value{GDBN} with the
21964command @code{set}.
104c1213 21965
8e04817f
AC
21966@table @code
21967@kindex set editing
21968@cindex editing
21969@item set editing
21970@itemx set editing on
21971Enable command line editing (enabled by default).
104c1213 21972
8e04817f
AC
21973@item set editing off
21974Disable command line editing.
104c1213 21975
8e04817f
AC
21976@kindex show editing
21977@item show editing
21978Show whether command line editing is enabled.
104c1213
JM
21979@end table
21980
39037522
TT
21981@ifset SYSTEM_READLINE
21982@xref{Command Line Editing, , , rluserman, GNU Readline Library},
21983@end ifset
21984@ifclear SYSTEM_READLINE
21985@xref{Command Line Editing},
21986@end ifclear
21987for more details about the Readline
703663ab
EZ
21988interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
21989encouraged to read that chapter.
21990
d620b259 21991@node Command History
79a6e687 21992@section Command History
703663ab 21993@cindex command history
8e04817f
AC
21994
21995@value{GDBN} can keep track of the commands you type during your
21996debugging sessions, so that you can be certain of precisely what
21997happened. Use these commands to manage the @value{GDBN} command
21998history facility.
104c1213 21999
703663ab 22000@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
39037522
TT
22001package, to provide the history facility.
22002@ifset SYSTEM_READLINE
22003@xref{Using History Interactively, , , history, GNU History Library},
22004@end ifset
22005@ifclear SYSTEM_READLINE
22006@xref{Using History Interactively},
22007@end ifclear
22008for the detailed description of the History library.
703663ab 22009
d620b259 22010To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
22011the state which is seen by users, prefix it with @samp{server }
22012(@pxref{Server Prefix}). This
d620b259
NR
22013means that this command will not affect the command history, nor will it
22014affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
22015pressed on a line by itself.
22016
22017@cindex @code{server}, command prefix
22018The server prefix does not affect the recording of values into the value
22019history; to print a value without recording it into the value history,
22020use the @code{output} command instead of the @code{print} command.
22021
703663ab
EZ
22022Here is the description of @value{GDBN} commands related to command
22023history.
22024
104c1213 22025@table @code
8e04817f
AC
22026@cindex history substitution
22027@cindex history file
22028@kindex set history filename
4644b6e3 22029@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
22030@item set history filename @var{fname}
22031Set the name of the @value{GDBN} command history file to @var{fname}.
22032This is the file where @value{GDBN} reads an initial command history
22033list, and where it writes the command history from this session when it
22034exits. You can access this list through history expansion or through
22035the history command editing characters listed below. This file defaults
22036to the value of the environment variable @code{GDBHISTFILE}, or to
22037@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
22038is not set.
104c1213 22039
9c16f35a
EZ
22040@cindex save command history
22041@kindex set history save
8e04817f
AC
22042@item set history save
22043@itemx set history save on
22044Record command history in a file, whose name may be specified with the
22045@code{set history filename} command. By default, this option is disabled.
104c1213 22046
8e04817f
AC
22047@item set history save off
22048Stop recording command history in a file.
104c1213 22049
8e04817f 22050@cindex history size
9c16f35a 22051@kindex set history size
6fc08d32 22052@cindex @env{HISTSIZE}, environment variable
8e04817f 22053@item set history size @var{size}
f81d1120 22054@itemx set history size unlimited
8e04817f
AC
22055Set the number of commands which @value{GDBN} keeps in its history list.
22056This defaults to the value of the environment variable
f81d1120
PA
22057@code{HISTSIZE}, or to 256 if this variable is not set. If @var{size}
22058is @code{unlimited}, the number of commands @value{GDBN} keeps in the
22059history list is unlimited.
104c1213
JM
22060@end table
22061
8e04817f 22062History expansion assigns special meaning to the character @kbd{!}.
39037522
TT
22063@ifset SYSTEM_READLINE
22064@xref{Event Designators, , , history, GNU History Library},
22065@end ifset
22066@ifclear SYSTEM_READLINE
22067@xref{Event Designators},
22068@end ifclear
22069for more details.
8e04817f 22070
703663ab 22071@cindex history expansion, turn on/off
8e04817f
AC
22072Since @kbd{!} is also the logical not operator in C, history expansion
22073is off by default. If you decide to enable history expansion with the
22074@code{set history expansion on} command, you may sometimes need to
22075follow @kbd{!} (when it is used as logical not, in an expression) with
22076a space or a tab to prevent it from being expanded. The readline
22077history facilities do not attempt substitution on the strings
22078@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
22079
22080The commands to control history expansion are:
104c1213
JM
22081
22082@table @code
8e04817f
AC
22083@item set history expansion on
22084@itemx set history expansion
703663ab 22085@kindex set history expansion
8e04817f 22086Enable history expansion. History expansion is off by default.
104c1213 22087
8e04817f
AC
22088@item set history expansion off
22089Disable history expansion.
104c1213 22090
8e04817f
AC
22091@c @group
22092@kindex show history
22093@item show history
22094@itemx show history filename
22095@itemx show history save
22096@itemx show history size
22097@itemx show history expansion
22098These commands display the state of the @value{GDBN} history parameters.
22099@code{show history} by itself displays all four states.
22100@c @end group
22101@end table
22102
22103@table @code
9c16f35a
EZ
22104@kindex show commands
22105@cindex show last commands
22106@cindex display command history
8e04817f
AC
22107@item show commands
22108Display the last ten commands in the command history.
104c1213 22109
8e04817f
AC
22110@item show commands @var{n}
22111Print ten commands centered on command number @var{n}.
22112
22113@item show commands +
22114Print ten commands just after the commands last printed.
104c1213
JM
22115@end table
22116
8e04817f 22117@node Screen Size
79a6e687 22118@section Screen Size
8e04817f
AC
22119@cindex size of screen
22120@cindex pauses in output
104c1213 22121
8e04817f
AC
22122Certain commands to @value{GDBN} may produce large amounts of
22123information output to the screen. To help you read all of it,
22124@value{GDBN} pauses and asks you for input at the end of each page of
22125output. Type @key{RET} when you want to continue the output, or @kbd{q}
22126to discard the remaining output. Also, the screen width setting
22127determines when to wrap lines of output. Depending on what is being
22128printed, @value{GDBN} tries to break the line at a readable place,
22129rather than simply letting it overflow onto the following line.
22130
22131Normally @value{GDBN} knows the size of the screen from the terminal
22132driver software. For example, on Unix @value{GDBN} uses the termcap data base
22133together with the value of the @code{TERM} environment variable and the
22134@code{stty rows} and @code{stty cols} settings. If this is not correct,
22135you can override it with the @code{set height} and @code{set
22136width} commands:
22137
22138@table @code
22139@kindex set height
22140@kindex set width
22141@kindex show width
22142@kindex show height
22143@item set height @var{lpp}
f81d1120 22144@itemx set height unlimited
8e04817f
AC
22145@itemx show height
22146@itemx set width @var{cpl}
f81d1120 22147@itemx set width unlimited
8e04817f
AC
22148@itemx show width
22149These @code{set} commands specify a screen height of @var{lpp} lines and
22150a screen width of @var{cpl} characters. The associated @code{show}
22151commands display the current settings.
104c1213 22152
f81d1120
PA
22153If you specify a height of either @code{unlimited} or zero lines,
22154@value{GDBN} does not pause during output no matter how long the
22155output is. This is useful if output is to a file or to an editor
22156buffer.
104c1213 22157
f81d1120
PA
22158Likewise, you can specify @samp{set width unlimited} or @samp{set
22159width 0} to prevent @value{GDBN} from wrapping its output.
9c16f35a
EZ
22160
22161@item set pagination on
22162@itemx set pagination off
22163@kindex set pagination
22164Turn the output pagination on or off; the default is on. Turning
f81d1120 22165pagination off is the alternative to @code{set height unlimited}. Note that
7c953934
TT
22166running @value{GDBN} with the @option{--batch} option (@pxref{Mode
22167Options, -batch}) also automatically disables pagination.
9c16f35a
EZ
22168
22169@item show pagination
22170@kindex show pagination
22171Show the current pagination mode.
104c1213
JM
22172@end table
22173
8e04817f
AC
22174@node Numbers
22175@section Numbers
22176@cindex number representation
22177@cindex entering numbers
104c1213 22178
8e04817f
AC
22179You can always enter numbers in octal, decimal, or hexadecimal in
22180@value{GDBN} by the usual conventions: octal numbers begin with
22181@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
22182begin with @samp{0x}. Numbers that neither begin with @samp{0} or
22183@samp{0x}, nor end with a @samp{.} are, by default, entered in base
2218410; likewise, the default display for numbers---when no particular
22185format is specified---is base 10. You can change the default base for
22186both input and output with the commands described below.
104c1213 22187
8e04817f
AC
22188@table @code
22189@kindex set input-radix
22190@item set input-radix @var{base}
22191Set the default base for numeric input. Supported choices
22192for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 22193specified either unambiguously or using the current input radix; for
8e04817f 22194example, any of
104c1213 22195
8e04817f 22196@smallexample
9c16f35a
EZ
22197set input-radix 012
22198set input-radix 10.
22199set input-radix 0xa
8e04817f 22200@end smallexample
104c1213 22201
8e04817f 22202@noindent
9c16f35a 22203sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
22204leaves the input radix unchanged, no matter what it was, since
22205@samp{10}, being without any leading or trailing signs of its base, is
22206interpreted in the current radix. Thus, if the current radix is 16,
22207@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
22208change the radix.
104c1213 22209
8e04817f
AC
22210@kindex set output-radix
22211@item set output-radix @var{base}
22212Set the default base for numeric display. Supported choices
22213for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 22214specified either unambiguously or using the current input radix.
104c1213 22215
8e04817f
AC
22216@kindex show input-radix
22217@item show input-radix
22218Display the current default base for numeric input.
104c1213 22219
8e04817f
AC
22220@kindex show output-radix
22221@item show output-radix
22222Display the current default base for numeric display.
9c16f35a
EZ
22223
22224@item set radix @r{[}@var{base}@r{]}
22225@itemx show radix
22226@kindex set radix
22227@kindex show radix
22228These commands set and show the default base for both input and output
22229of numbers. @code{set radix} sets the radix of input and output to
22230the same base; without an argument, it resets the radix back to its
22231default value of 10.
22232
8e04817f 22233@end table
104c1213 22234
1e698235 22235@node ABI
79a6e687 22236@section Configuring the Current ABI
1e698235
DJ
22237
22238@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
22239application automatically. However, sometimes you need to override its
22240conclusions. Use these commands to manage @value{GDBN}'s view of the
22241current ABI.
22242
98b45e30
DJ
22243@cindex OS ABI
22244@kindex set osabi
b4e9345d 22245@kindex show osabi
430ed3f0 22246@cindex Newlib OS ABI and its influence on the longjmp handling
98b45e30
DJ
22247
22248One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 22249system targets, either via remote debugging or native emulation.
98b45e30
DJ
22250@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
22251but you can override its conclusion using the @code{set osabi} command.
22252One example where this is useful is in debugging of binaries which use
22253an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
22254not have the same identifying marks that the standard C library for your
22255platform provides.
22256
430ed3f0
MS
22257When @value{GDBN} is debugging the AArch64 architecture, it provides a
22258``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
22259@code{longjmp} when debugging binaries that use the @sc{newlib} C library.
22260The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
22261
98b45e30
DJ
22262@table @code
22263@item show osabi
22264Show the OS ABI currently in use.
22265
22266@item set osabi
22267With no argument, show the list of registered available OS ABI's.
22268
22269@item set osabi @var{abi}
22270Set the current OS ABI to @var{abi}.
22271@end table
22272
1e698235 22273@cindex float promotion
1e698235
DJ
22274
22275Generally, the way that an argument of type @code{float} is passed to a
22276function depends on whether the function is prototyped. For a prototyped
22277(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
22278according to the architecture's convention for @code{float}. For unprototyped
22279(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
22280@code{double} and then passed.
22281
22282Unfortunately, some forms of debug information do not reliably indicate whether
22283a function is prototyped. If @value{GDBN} calls a function that is not marked
22284as prototyped, it consults @kbd{set coerce-float-to-double}.
22285
22286@table @code
a8f24a35 22287@kindex set coerce-float-to-double
1e698235
DJ
22288@item set coerce-float-to-double
22289@itemx set coerce-float-to-double on
22290Arguments of type @code{float} will be promoted to @code{double} when passed
22291to an unprototyped function. This is the default setting.
22292
22293@item set coerce-float-to-double off
22294Arguments of type @code{float} will be passed directly to unprototyped
22295functions.
9c16f35a
EZ
22296
22297@kindex show coerce-float-to-double
22298@item show coerce-float-to-double
22299Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
22300@end table
22301
f1212245
DJ
22302@kindex set cp-abi
22303@kindex show cp-abi
22304@value{GDBN} needs to know the ABI used for your program's C@t{++}
22305objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
22306used to build your application. @value{GDBN} only fully supports
22307programs with a single C@t{++} ABI; if your program contains code using
22308multiple C@t{++} ABI's or if @value{GDBN} can not identify your
22309program's ABI correctly, you can tell @value{GDBN} which ABI to use.
22310Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
22311before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
22312``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
22313use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
22314``auto''.
22315
22316@table @code
22317@item show cp-abi
22318Show the C@t{++} ABI currently in use.
22319
22320@item set cp-abi
22321With no argument, show the list of supported C@t{++} ABI's.
22322
22323@item set cp-abi @var{abi}
22324@itemx set cp-abi auto
22325Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
22326@end table
22327
bf88dd68
JK
22328@node Auto-loading
22329@section Automatically loading associated files
22330@cindex auto-loading
22331
22332@value{GDBN} sometimes reads files with commands and settings automatically,
22333without being explicitly told so by the user. We call this feature
22334@dfn{auto-loading}. While auto-loading is useful for automatically adapting
22335@value{GDBN} to the needs of your project, it can sometimes produce unexpected
22336results or introduce security risks (e.g., if the file comes from untrusted
22337sources).
22338
71b8c845
DE
22339@menu
22340* Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
22341* libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
22342
22343* Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
22344* Auto-loading verbose mode:: @samp{set/show debug auto-load}
22345@end menu
22346
22347There are various kinds of files @value{GDBN} can automatically load.
22348In addition to these files, @value{GDBN} supports auto-loading code written
22349in various extension languages. @xref{Auto-loading extensions}.
22350
c1668e4e
JK
22351Note that loading of these associated files (including the local @file{.gdbinit}
22352file) requires accordingly configured @code{auto-load safe-path}
22353(@pxref{Auto-loading safe path}).
22354
bf88dd68
JK
22355For these reasons, @value{GDBN} includes commands and options to let you
22356control when to auto-load files and which files should be auto-loaded.
22357
22358@table @code
22359@anchor{set auto-load off}
22360@kindex set auto-load off
22361@item set auto-load off
22362Globally disable loading of all auto-loaded files.
22363You may want to use this command with the @samp{-iex} option
22364(@pxref{Option -init-eval-command}) such as:
22365@smallexample
22366$ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
22367@end smallexample
22368
22369Be aware that system init file (@pxref{System-wide configuration})
22370and init files from your home directory (@pxref{Home Directory Init File})
22371still get read (as they come from generally trusted directories).
22372To prevent @value{GDBN} from auto-loading even those init files, use the
22373@option{-nx} option (@pxref{Mode Options}), in addition to
22374@code{set auto-load no}.
22375
22376@anchor{show auto-load}
22377@kindex show auto-load
22378@item show auto-load
22379Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
22380or disabled.
22381
22382@smallexample
22383(gdb) show auto-load
22384gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
22385libthread-db: Auto-loading of inferior specific libthread_db is on.
1ccacbcd
JK
22386local-gdbinit: Auto-loading of .gdbinit script from current directory
22387 is on.
bf88dd68 22388python-scripts: Auto-loading of Python scripts is on.
bccbefd2 22389safe-path: List of directories from which it is safe to auto-load files
1564a261 22390 is $debugdir:$datadir/auto-load.
7349ff92 22391scripts-directory: List of directories from which to load auto-loaded scripts
1564a261 22392 is $debugdir:$datadir/auto-load.
bf88dd68
JK
22393@end smallexample
22394
22395@anchor{info auto-load}
22396@kindex info auto-load
22397@item info auto-load
22398Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
22399not.
22400
22401@smallexample
22402(gdb) info auto-load
22403gdb-scripts:
22404Loaded Script
22405Yes /home/user/gdb/gdb-gdb.gdb
22406libthread-db: No auto-loaded libthread-db.
1ccacbcd
JK
22407local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
22408 loaded.
bf88dd68
JK
22409python-scripts:
22410Loaded Script
22411Yes /home/user/gdb/gdb-gdb.py
22412@end smallexample
22413@end table
22414
bf88dd68
JK
22415These are @value{GDBN} control commands for the auto-loading:
22416
22417@multitable @columnfractions .5 .5
22418@item @xref{set auto-load off}.
22419@tab Disable auto-loading globally.
22420@item @xref{show auto-load}.
22421@tab Show setting of all kinds of files.
22422@item @xref{info auto-load}.
22423@tab Show state of all kinds of files.
22424@item @xref{set auto-load gdb-scripts}.
22425@tab Control for @value{GDBN} command scripts.
22426@item @xref{show auto-load gdb-scripts}.
22427@tab Show setting of @value{GDBN} command scripts.
22428@item @xref{info auto-load gdb-scripts}.
22429@tab Show state of @value{GDBN} command scripts.
22430@item @xref{set auto-load python-scripts}.
22431@tab Control for @value{GDBN} Python scripts.
22432@item @xref{show auto-load python-scripts}.
22433@tab Show setting of @value{GDBN} Python scripts.
22434@item @xref{info auto-load python-scripts}.
22435@tab Show state of @value{GDBN} Python scripts.
ed3ef339
DE
22436@item @xref{set auto-load guile-scripts}.
22437@tab Control for @value{GDBN} Guile scripts.
22438@item @xref{show auto-load guile-scripts}.
22439@tab Show setting of @value{GDBN} Guile scripts.
22440@item @xref{info auto-load guile-scripts}.
22441@tab Show state of @value{GDBN} Guile scripts.
7349ff92
JK
22442@item @xref{set auto-load scripts-directory}.
22443@tab Control for @value{GDBN} auto-loaded scripts location.
22444@item @xref{show auto-load scripts-directory}.
22445@tab Show @value{GDBN} auto-loaded scripts location.
bf88dd68
JK
22446@item @xref{set auto-load local-gdbinit}.
22447@tab Control for init file in the current directory.
22448@item @xref{show auto-load local-gdbinit}.
22449@tab Show setting of init file in the current directory.
22450@item @xref{info auto-load local-gdbinit}.
22451@tab Show state of init file in the current directory.
22452@item @xref{set auto-load libthread-db}.
22453@tab Control for thread debugging library.
22454@item @xref{show auto-load libthread-db}.
22455@tab Show setting of thread debugging library.
22456@item @xref{info auto-load libthread-db}.
22457@tab Show state of thread debugging library.
bccbefd2
JK
22458@item @xref{set auto-load safe-path}.
22459@tab Control directories trusted for automatic loading.
22460@item @xref{show auto-load safe-path}.
22461@tab Show directories trusted for automatic loading.
22462@item @xref{add-auto-load-safe-path}.
22463@tab Add directory trusted for automatic loading.
bf88dd68
JK
22464@end multitable
22465
bf88dd68
JK
22466@node Init File in the Current Directory
22467@subsection Automatically loading init file in the current directory
22468@cindex auto-loading init file in the current directory
22469
22470By default, @value{GDBN} reads and executes the canned sequences of commands
22471from init file (if any) in the current working directory,
22472see @ref{Init File in the Current Directory during Startup}.
22473
c1668e4e
JK
22474Note that loading of this local @file{.gdbinit} file also requires accordingly
22475configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
22476
bf88dd68
JK
22477@table @code
22478@anchor{set auto-load local-gdbinit}
22479@kindex set auto-load local-gdbinit
22480@item set auto-load local-gdbinit [on|off]
22481Enable or disable the auto-loading of canned sequences of commands
22482(@pxref{Sequences}) found in init file in the current directory.
22483
22484@anchor{show auto-load local-gdbinit}
22485@kindex show auto-load local-gdbinit
22486@item show auto-load local-gdbinit
22487Show whether auto-loading of canned sequences of commands from init file in the
22488current directory is enabled or disabled.
22489
22490@anchor{info auto-load local-gdbinit}
22491@kindex info auto-load local-gdbinit
22492@item info auto-load local-gdbinit
22493Print whether canned sequences of commands from init file in the
22494current directory have been auto-loaded.
22495@end table
22496
22497@node libthread_db.so.1 file
22498@subsection Automatically loading thread debugging library
22499@cindex auto-loading libthread_db.so.1
22500
22501This feature is currently present only on @sc{gnu}/Linux native hosts.
22502
22503@value{GDBN} reads in some cases thread debugging library from places specific
22504to the inferior (@pxref{set libthread-db-search-path}).
22505
22506The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
22507without checking this @samp{set auto-load libthread-db} switch as system
22508libraries have to be trusted in general. In all other cases of
22509@samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
22510auto-load libthread-db} is enabled before trying to open such thread debugging
22511library.
22512
c1668e4e
JK
22513Note that loading of this debugging library also requires accordingly configured
22514@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
22515
bf88dd68
JK
22516@table @code
22517@anchor{set auto-load libthread-db}
22518@kindex set auto-load libthread-db
22519@item set auto-load libthread-db [on|off]
22520Enable or disable the auto-loading of inferior specific thread debugging library.
22521
22522@anchor{show auto-load libthread-db}
22523@kindex show auto-load libthread-db
22524@item show auto-load libthread-db
22525Show whether auto-loading of inferior specific thread debugging library is
22526enabled or disabled.
22527
22528@anchor{info auto-load libthread-db}
22529@kindex info auto-load libthread-db
22530@item info auto-load libthread-db
22531Print the list of all loaded inferior specific thread debugging libraries and
22532for each such library print list of inferior @var{pid}s using it.
22533@end table
22534
bccbefd2
JK
22535@node Auto-loading safe path
22536@subsection Security restriction for auto-loading
22537@cindex auto-loading safe-path
22538
22539As the files of inferior can come from untrusted source (such as submitted by
22540an application user) @value{GDBN} does not always load any files automatically.
22541@value{GDBN} provides the @samp{set auto-load safe-path} setting to list
22542directories trusted for loading files not explicitly requested by user.
202cbf1c 22543Each directory can also be a shell wildcard pattern.
bccbefd2
JK
22544
22545If the path is not set properly you will see a warning and the file will not
22546get loaded:
22547
22548@smallexample
22549$ ./gdb -q ./gdb
22550Reading symbols from /home/user/gdb/gdb...done.
22551warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
1564a261
JK
22552 declined by your `auto-load safe-path' set
22553 to "$debugdir:$datadir/auto-load".
bccbefd2 22554warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
1564a261
JK
22555 declined by your `auto-load safe-path' set
22556 to "$debugdir:$datadir/auto-load".
bccbefd2
JK
22557@end smallexample
22558
2c91021c
JK
22559@noindent
22560To instruct @value{GDBN} to go ahead and use the init files anyway,
22561invoke @value{GDBN} like this:
22562
22563@smallexample
22564$ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
22565@end smallexample
22566
bccbefd2
JK
22567The list of trusted directories is controlled by the following commands:
22568
22569@table @code
22570@anchor{set auto-load safe-path}
22571@kindex set auto-load safe-path
af2c1515 22572@item set auto-load safe-path @r{[}@var{directories}@r{]}
bccbefd2
JK
22573Set the list of directories (and their subdirectories) trusted for automatic
22574loading and execution of scripts. You can also enter a specific trusted file.
202cbf1c
JK
22575Each directory can also be a shell wildcard pattern; wildcards do not match
22576directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
22577(@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
af2c1515
JK
22578If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
22579its default value as specified during @value{GDBN} compilation.
22580
d9242c17 22581The list of directories uses path separator (@samp{:} on GNU and Unix
bccbefd2
JK
22582systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
22583to the @env{PATH} environment variable.
22584
22585@anchor{show auto-load safe-path}
22586@kindex show auto-load safe-path
22587@item show auto-load safe-path
22588Show the list of directories trusted for automatic loading and execution of
22589scripts.
22590
22591@anchor{add-auto-load-safe-path}
22592@kindex add-auto-load-safe-path
22593@item add-auto-load-safe-path
22594Add an entry (or list of entries) the list of directories trusted for automatic
22595loading and execution of scripts. Multiple entries may be delimited by the
d9242c17 22596host platform path separator in use.
bccbefd2
JK
22597@end table
22598
7349ff92 22599This variable defaults to what @code{--with-auto-load-dir} has been configured
1564a261
JK
22600to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
22601substitution applies the same as for @ref{set auto-load scripts-directory}.
22602The default @code{set auto-load safe-path} value can be also overriden by
22603@value{GDBN} configuration option @option{--with-auto-load-safe-path}.
6dea1fbd 22604
6dea1fbd
JK
22605Setting this variable to @file{/} disables this security protection,
22606corresponding @value{GDBN} configuration option is
22607@option{--without-auto-load-safe-path}.
bccbefd2
JK
22608This variable is supposed to be set to the system directories writable by the
22609system superuser only. Users can add their source directories in init files in
22610their home directories (@pxref{Home Directory Init File}). See also deprecated
22611init file in the current directory
22612(@pxref{Init File in the Current Directory during Startup}).
22613
22614To force @value{GDBN} to load the files it declined to load in the previous
22615example, you could use one of the following ways:
22616
0511cc75
JK
22617@table @asis
22618@item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
bccbefd2
JK
22619Specify this trusted directory (or a file) as additional component of the list.
22620You have to specify also any existing directories displayed by
22621by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
22622
174bb630 22623@item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
bccbefd2
JK
22624Specify this directory as in the previous case but just for a single
22625@value{GDBN} session.
22626
af2c1515 22627@item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
bccbefd2
JK
22628Disable auto-loading safety for a single @value{GDBN} session.
22629This assumes all the files you debug during this @value{GDBN} session will come
22630from trusted sources.
22631
22632@item @kbd{./configure --without-auto-load-safe-path}
22633During compilation of @value{GDBN} you may disable any auto-loading safety.
22634This assumes all the files you will ever debug with this @value{GDBN} come from
22635trusted sources.
0511cc75 22636@end table
bccbefd2
JK
22637
22638On the other hand you can also explicitly forbid automatic files loading which
22639also suppresses any such warning messages:
22640
0511cc75 22641@table @asis
174bb630 22642@item @kbd{gdb -iex "set auto-load no" @dots{}}
bccbefd2
JK
22643You can use @value{GDBN} command-line option for a single @value{GDBN} session.
22644
0511cc75 22645@item @file{~/.gdbinit}: @samp{set auto-load no}
bccbefd2
JK
22646Disable auto-loading globally for the user
22647(@pxref{Home Directory Init File}). While it is improbable, you could also
22648use system init file instead (@pxref{System-wide configuration}).
0511cc75 22649@end table
bccbefd2
JK
22650
22651This setting applies to the file names as entered by user. If no entry matches
22652@value{GDBN} tries as a last resort to also resolve all the file names into
22653their canonical form (typically resolving symbolic links) and compare the
22654entries again. @value{GDBN} already canonicalizes most of the filenames on its
22655own before starting the comparison so a canonical form of directories is
22656recommended to be entered.
22657
4dc84fd1
JK
22658@node Auto-loading verbose mode
22659@subsection Displaying files tried for auto-load
22660@cindex auto-loading verbose mode
22661
22662For better visibility of all the file locations where you can place scripts to
22663be auto-loaded with inferior --- or to protect yourself against accidental
22664execution of untrusted scripts --- @value{GDBN} provides a feature for printing
22665all the files attempted to be loaded. Both existing and non-existing files may
22666be printed.
22667
22668For example the list of directories from which it is safe to auto-load files
22669(@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
22670may not be too obvious while setting it up.
22671
22672@smallexample
0070f25a 22673(gdb) set debug auto-load on
4dc84fd1
JK
22674(gdb) file ~/src/t/true
22675auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
22676 for objfile "/tmp/true".
22677auto-load: Updating directories of "/usr:/opt".
22678auto-load: Using directory "/usr".
22679auto-load: Using directory "/opt".
22680warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
22681 by your `auto-load safe-path' set to "/usr:/opt".
22682@end smallexample
22683
22684@table @code
22685@anchor{set debug auto-load}
22686@kindex set debug auto-load
22687@item set debug auto-load [on|off]
22688Set whether to print the filenames attempted to be auto-loaded.
22689
22690@anchor{show debug auto-load}
22691@kindex show debug auto-load
22692@item show debug auto-load
22693Show whether printing of the filenames attempted to be auto-loaded is turned
22694on or off.
22695@end table
22696
8e04817f 22697@node Messages/Warnings
79a6e687 22698@section Optional Warnings and Messages
104c1213 22699
9c16f35a
EZ
22700@cindex verbose operation
22701@cindex optional warnings
8e04817f
AC
22702By default, @value{GDBN} is silent about its inner workings. If you are
22703running on a slow machine, you may want to use the @code{set verbose}
22704command. This makes @value{GDBN} tell you when it does a lengthy
22705internal operation, so you will not think it has crashed.
104c1213 22706
8e04817f
AC
22707Currently, the messages controlled by @code{set verbose} are those
22708which announce that the symbol table for a source file is being read;
79a6e687 22709see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 22710
8e04817f
AC
22711@table @code
22712@kindex set verbose
22713@item set verbose on
22714Enables @value{GDBN} output of certain informational messages.
104c1213 22715
8e04817f
AC
22716@item set verbose off
22717Disables @value{GDBN} output of certain informational messages.
104c1213 22718
8e04817f
AC
22719@kindex show verbose
22720@item show verbose
22721Displays whether @code{set verbose} is on or off.
22722@end table
104c1213 22723
8e04817f
AC
22724By default, if @value{GDBN} encounters bugs in the symbol table of an
22725object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
22726find this information useful (@pxref{Symbol Errors, ,Errors Reading
22727Symbol Files}).
104c1213 22728
8e04817f 22729@table @code
104c1213 22730
8e04817f
AC
22731@kindex set complaints
22732@item set complaints @var{limit}
22733Permits @value{GDBN} to output @var{limit} complaints about each type of
22734unusual symbols before becoming silent about the problem. Set
22735@var{limit} to zero to suppress all complaints; set it to a large number
22736to prevent complaints from being suppressed.
104c1213 22737
8e04817f
AC
22738@kindex show complaints
22739@item show complaints
22740Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 22741
8e04817f 22742@end table
104c1213 22743
d837706a 22744@anchor{confirmation requests}
8e04817f
AC
22745By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
22746lot of stupid questions to confirm certain commands. For example, if
22747you try to run a program which is already running:
104c1213 22748
474c8240 22749@smallexample
8e04817f
AC
22750(@value{GDBP}) run
22751The program being debugged has been started already.
22752Start it from the beginning? (y or n)
474c8240 22753@end smallexample
104c1213 22754
8e04817f
AC
22755If you are willing to unflinchingly face the consequences of your own
22756commands, you can disable this ``feature'':
104c1213 22757
8e04817f 22758@table @code
104c1213 22759
8e04817f
AC
22760@kindex set confirm
22761@cindex flinching
22762@cindex confirmation
22763@cindex stupid questions
22764@item set confirm off
7c953934
TT
22765Disables confirmation requests. Note that running @value{GDBN} with
22766the @option{--batch} option (@pxref{Mode Options, -batch}) also
22767automatically disables confirmation requests.
104c1213 22768
8e04817f
AC
22769@item set confirm on
22770Enables confirmation requests (the default).
104c1213 22771
8e04817f
AC
22772@kindex show confirm
22773@item show confirm
22774Displays state of confirmation requests.
22775
22776@end table
104c1213 22777
16026cd7
AS
22778@cindex command tracing
22779If you need to debug user-defined commands or sourced files you may find it
22780useful to enable @dfn{command tracing}. In this mode each command will be
22781printed as it is executed, prefixed with one or more @samp{+} symbols, the
22782quantity denoting the call depth of each command.
22783
22784@table @code
22785@kindex set trace-commands
22786@cindex command scripts, debugging
22787@item set trace-commands on
22788Enable command tracing.
22789@item set trace-commands off
22790Disable command tracing.
22791@item show trace-commands
22792Display the current state of command tracing.
22793@end table
22794
8e04817f 22795@node Debugging Output
79a6e687 22796@section Optional Messages about Internal Happenings
4644b6e3
EZ
22797@cindex optional debugging messages
22798
da316a69
EZ
22799@value{GDBN} has commands that enable optional debugging messages from
22800various @value{GDBN} subsystems; normally these commands are of
22801interest to @value{GDBN} maintainers, or when reporting a bug. This
22802section documents those commands.
22803
104c1213 22804@table @code
a8f24a35
EZ
22805@kindex set exec-done-display
22806@item set exec-done-display
22807Turns on or off the notification of asynchronous commands'
22808completion. When on, @value{GDBN} will print a message when an
22809asynchronous command finishes its execution. The default is off.
22810@kindex show exec-done-display
22811@item show exec-done-display
22812Displays the current setting of asynchronous command completion
22813notification.
4644b6e3 22814@kindex set debug
be9a8770
PA
22815@cindex ARM AArch64
22816@item set debug aarch64
22817Turns on or off display of debugging messages related to ARM AArch64.
22818The default is off.
22819@kindex show debug
22820@item show debug aarch64
22821Displays the current state of displaying debugging messages related to
22822ARM AArch64.
4644b6e3 22823@cindex gdbarch debugging info
a8f24a35 22824@cindex architecture debugging info
8e04817f 22825@item set debug arch
a8f24a35 22826Turns on or off display of gdbarch debugging info. The default is off
8e04817f
AC
22827@item show debug arch
22828Displays the current state of displaying gdbarch debugging info.
9a005eb9
JB
22829@item set debug aix-solib
22830@cindex AIX shared library debugging
22831Control display of debugging messages from the AIX shared library
22832support module. The default is off.
22833@item show debug aix-thread
22834Show the current state of displaying AIX shared library debugging messages.
721c2651
EZ
22835@item set debug aix-thread
22836@cindex AIX threads
22837Display debugging messages about inner workings of the AIX thread
22838module.
22839@item show debug aix-thread
22840Show the current state of AIX thread debugging info display.
900e11f9
JK
22841@item set debug check-physname
22842@cindex physname
22843Check the results of the ``physname'' computation. When reading DWARF
22844debugging information for C@t{++}, @value{GDBN} attempts to compute
22845each entity's name. @value{GDBN} can do this computation in two
22846different ways, depending on exactly what information is present.
22847When enabled, this setting causes @value{GDBN} to compute the names
22848both ways and display any discrepancies.
22849@item show debug check-physname
22850Show the current state of ``physname'' checking.
be9a8770
PA
22851@item set debug coff-pe-read
22852@cindex COFF/PE exported symbols
22853Control display of debugging messages related to reading of COFF/PE
22854exported symbols. The default is off.
22855@item show debug coff-pe-read
22856Displays the current state of displaying debugging messages related to
22857reading of COFF/PE exported symbols.
d97bc12b
DE
22858@item set debug dwarf2-die
22859@cindex DWARF2 DIEs
22860Dump DWARF2 DIEs after they are read in.
22861The value is the number of nesting levels to print.
22862A value of zero turns off the display.
22863@item show debug dwarf2-die
22864Show the current state of DWARF2 DIE debugging.
45cfd468
DE
22865@item set debug dwarf2-read
22866@cindex DWARF2 Reading
22867Turns on or off display of debugging messages related to reading
73be47f5
DE
22868DWARF debug info. The default is 0 (off).
22869A value of 1 provides basic information.
22870A value greater than 1 provides more verbose information.
45cfd468
DE
22871@item show debug dwarf2-read
22872Show the current state of DWARF2 reader debugging.
237fc4c9
PA
22873@item set debug displaced
22874@cindex displaced stepping debugging info
22875Turns on or off display of @value{GDBN} debugging info for the
22876displaced stepping support. The default is off.
22877@item show debug displaced
22878Displays the current state of displaying @value{GDBN} debugging info
22879related to displaced stepping.
8e04817f 22880@item set debug event
4644b6e3 22881@cindex event debugging info
a8f24a35 22882Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 22883default is off.
8e04817f
AC
22884@item show debug event
22885Displays the current state of displaying @value{GDBN} event debugging
22886info.
8e04817f 22887@item set debug expression
4644b6e3 22888@cindex expression debugging info
721c2651
EZ
22889Turns on or off display of debugging info about @value{GDBN}
22890expression parsing. The default is off.
8e04817f 22891@item show debug expression
721c2651
EZ
22892Displays the current state of displaying debugging info about
22893@value{GDBN} expression parsing.
7453dc06 22894@item set debug frame
4644b6e3 22895@cindex frame debugging info
7453dc06
AC
22896Turns on or off display of @value{GDBN} frame debugging info. The
22897default is off.
7453dc06
AC
22898@item show debug frame
22899Displays the current state of displaying @value{GDBN} frame debugging
22900info.
cbe54154
PA
22901@item set debug gnu-nat
22902@cindex @sc{gnu}/Hurd debug messages
22903Turns on or off debugging messages from the @sc{gnu}/Hurd debug support.
22904@item show debug gnu-nat
22905Show the current state of @sc{gnu}/Hurd debugging messages.
30e91e0b
RC
22906@item set debug infrun
22907@cindex inferior debugging info
22908Turns on or off display of @value{GDBN} debugging info for running the inferior.
22909The default is off. @file{infrun.c} contains GDB's runtime state machine used
22910for implementing operations such as single-stepping the inferior.
22911@item show debug infrun
22912Displays the current state of @value{GDBN} inferior debugging.
a255712f
PP
22913@item set debug jit
22914@cindex just-in-time compilation, debugging messages
22915Turns on or off debugging messages from JIT debug support.
22916@item show debug jit
22917Displays the current state of @value{GDBN} JIT debugging.
da316a69
EZ
22918@item set debug lin-lwp
22919@cindex @sc{gnu}/Linux LWP debug messages
22920@cindex Linux lightweight processes
721c2651 22921Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
22922@item show debug lin-lwp
22923Show the current state of Linux LWP debugging messages.
be9a8770
PA
22924@item set debug mach-o
22925@cindex Mach-O symbols processing
22926Control display of debugging messages related to Mach-O symbols
22927processing. The default is off.
22928@item show debug mach-o
22929Displays the current state of displaying debugging messages related to
22930reading of COFF/PE exported symbols.
c9b6281a
YQ
22931@item set debug notification
22932@cindex remote async notification debugging info
22933Turns on or off debugging messages about remote async notification.
22934The default is off.
22935@item show debug notification
22936Displays the current state of remote async notification debugging messages.
2b4855ab 22937@item set debug observer
4644b6e3 22938@cindex observer debugging info
2b4855ab
AC
22939Turns on or off display of @value{GDBN} observer debugging. This
22940includes info such as the notification of observable events.
2b4855ab
AC
22941@item show debug observer
22942Displays the current state of observer debugging.
8e04817f 22943@item set debug overload
4644b6e3 22944@cindex C@t{++} overload debugging info
8e04817f 22945Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 22946info. This includes info such as ranking of functions, etc. The default
8e04817f 22947is off.
8e04817f
AC
22948@item show debug overload
22949Displays the current state of displaying @value{GDBN} C@t{++} overload
22950debugging info.
92981e24
TT
22951@cindex expression parser, debugging info
22952@cindex debug expression parser
22953@item set debug parser
22954Turns on or off the display of expression parser debugging output.
22955Internally, this sets the @code{yydebug} variable in the expression
22956parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
22957details. The default is off.
22958@item show debug parser
22959Show the current state of expression parser debugging.
8e04817f
AC
22960@cindex packets, reporting on stdout
22961@cindex serial connections, debugging
605a56cb
DJ
22962@cindex debug remote protocol
22963@cindex remote protocol debugging
22964@cindex display remote packets
8e04817f
AC
22965@item set debug remote
22966Turns on or off display of reports on all packets sent back and forth across
22967the serial line to the remote machine. The info is printed on the
22968@value{GDBN} standard output stream. The default is off.
8e04817f
AC
22969@item show debug remote
22970Displays the state of display of remote packets.
8e04817f
AC
22971@item set debug serial
22972Turns on or off display of @value{GDBN} serial debugging info. The
22973default is off.
8e04817f
AC
22974@item show debug serial
22975Displays the current state of displaying @value{GDBN} serial debugging
22976info.
c45da7e6
EZ
22977@item set debug solib-frv
22978@cindex FR-V shared-library debugging
22979Turns on or off debugging messages for FR-V shared-library code.
22980@item show debug solib-frv
22981Display the current state of FR-V shared-library code debugging
22982messages.
8fb8eb5c
DE
22983@item set debug symfile
22984@cindex symbol file functions
22985Turns on or off display of debugging messages related to symbol file functions.
22986The default is off. @xref{Files}.
22987@item show debug symfile
22988Show the current state of symbol file debugging messages.
45cfd468
DE
22989@item set debug symtab-create
22990@cindex symbol table creation
22991Turns on or off display of debugging messages related to symbol table creation.
db0fec5c
DE
22992The default is 0 (off).
22993A value of 1 provides basic information.
22994A value greater than 1 provides more verbose information.
45cfd468
DE
22995@item show debug symtab-create
22996Show the current state of symbol table creation debugging.
8e04817f 22997@item set debug target
4644b6e3 22998@cindex target debugging info
8e04817f
AC
22999Turns on or off display of @value{GDBN} target debugging info. This info
23000includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
23001default is 0. Set it to 1 to track events, and to 2 to also track the
23002value of large memory transfers. Changes to this flag do not take effect
23003until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
23004@item show debug target
23005Displays the current state of displaying @value{GDBN} target debugging
23006info.
75feb17d
DJ
23007@item set debug timestamp
23008@cindex timestampping debugging info
23009Turns on or off display of timestamps with @value{GDBN} debugging info.
23010When enabled, seconds and microseconds are displayed before each debugging
23011message.
23012@item show debug timestamp
23013Displays the current state of displaying timestamps with @value{GDBN}
23014debugging info.
f989a1c8 23015@item set debug varobj
4644b6e3 23016@cindex variable object debugging info
8e04817f
AC
23017Turns on or off display of @value{GDBN} variable object debugging
23018info. The default is off.
f989a1c8 23019@item show debug varobj
8e04817f
AC
23020Displays the current state of displaying @value{GDBN} variable object
23021debugging info.
e776119f
DJ
23022@item set debug xml
23023@cindex XML parser debugging
23024Turns on or off debugging messages for built-in XML parsers.
23025@item show debug xml
23026Displays the current state of XML debugging messages.
8e04817f 23027@end table
104c1213 23028
14fb1bac
JB
23029@node Other Misc Settings
23030@section Other Miscellaneous Settings
23031@cindex miscellaneous settings
23032
23033@table @code
23034@kindex set interactive-mode
23035@item set interactive-mode
7bfc9434
JB
23036If @code{on}, forces @value{GDBN} to assume that GDB was started
23037in a terminal. In practice, this means that @value{GDBN} should wait
23038for the user to answer queries generated by commands entered at
23039the command prompt. If @code{off}, forces @value{GDBN} to operate
23040in the opposite mode, and it uses the default answers to all queries.
23041If @code{auto} (the default), @value{GDBN} tries to determine whether
23042its standard input is a terminal, and works in interactive-mode if it
23043is, non-interactively otherwise.
14fb1bac
JB
23044
23045In the vast majority of cases, the debugger should be able to guess
23046correctly which mode should be used. But this setting can be useful
23047in certain specific cases, such as running a MinGW @value{GDBN}
23048inside a cygwin window.
23049
23050@kindex show interactive-mode
23051@item show interactive-mode
23052Displays whether the debugger is operating in interactive mode or not.
23053@end table
23054
d57a3c85
TJB
23055@node Extending GDB
23056@chapter Extending @value{GDBN}
23057@cindex extending GDB
23058
71b8c845
DE
23059@value{GDBN} provides several mechanisms for extension.
23060@value{GDBN} also provides the ability to automatically load
23061extensions when it reads a file for debugging. This allows the
23062user to automatically customize @value{GDBN} for the program
23063being debugged.
d57a3c85 23064
71b8c845
DE
23065@menu
23066* Sequences:: Canned Sequences of @value{GDBN} Commands
23067* Python:: Extending @value{GDBN} using Python
ed3ef339 23068* Guile:: Extending @value{GDBN} using Guile
71b8c845 23069* Auto-loading extensions:: Automatically loading extensions
ed3ef339 23070* Multiple Extension Languages:: Working with multiple extension languages
71b8c845
DE
23071* Aliases:: Creating new spellings of existing commands
23072@end menu
23073
23074To facilitate the use of extension languages, @value{GDBN} is capable
95433b34 23075of evaluating the contents of a file. When doing so, @value{GDBN}
71b8c845 23076can recognize which extension language is being used by looking at
95433b34
JB
23077the filename extension. Files with an unrecognized filename extension
23078are always treated as a @value{GDBN} Command Files.
23079@xref{Command Files,, Command files}.
23080
23081You can control how @value{GDBN} evaluates these files with the following
23082setting:
23083
23084@table @code
23085@kindex set script-extension
23086@kindex show script-extension
23087@item set script-extension off
23088All scripts are always evaluated as @value{GDBN} Command Files.
23089
23090@item set script-extension soft
23091The debugger determines the scripting language based on filename
23092extension. If this scripting language is supported, @value{GDBN}
23093evaluates the script using that language. Otherwise, it evaluates
23094the file as a @value{GDBN} Command File.
23095
23096@item set script-extension strict
23097The debugger determines the scripting language based on filename
23098extension, and evaluates the script using that language. If the
23099language is not supported, then the evaluation fails.
23100
23101@item show script-extension
23102Display the current value of the @code{script-extension} option.
23103
23104@end table
23105
8e04817f 23106@node Sequences
d57a3c85 23107@section Canned Sequences of Commands
104c1213 23108
8e04817f 23109Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 23110Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
23111commands for execution as a unit: user-defined commands and command
23112files.
104c1213 23113
8e04817f 23114@menu
fcc73fe3
EZ
23115* Define:: How to define your own commands
23116* Hooks:: Hooks for user-defined commands
23117* Command Files:: How to write scripts of commands to be stored in a file
23118* Output:: Commands for controlled output
71b8c845 23119* Auto-loading sequences:: Controlling auto-loaded command files
8e04817f 23120@end menu
104c1213 23121
8e04817f 23122@node Define
d57a3c85 23123@subsection User-defined Commands
104c1213 23124
8e04817f 23125@cindex user-defined command
fcc73fe3 23126@cindex arguments, to user-defined commands
8e04817f
AC
23127A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
23128which you assign a new name as a command. This is done with the
23129@code{define} command. User commands may accept up to 10 arguments
23130separated by whitespace. Arguments are accessed within the user command
c03c782f 23131via @code{$arg0@dots{}$arg9}. A trivial example:
104c1213 23132
8e04817f
AC
23133@smallexample
23134define adder
23135 print $arg0 + $arg1 + $arg2
c03c782f 23136end
8e04817f 23137@end smallexample
104c1213
JM
23138
23139@noindent
8e04817f 23140To execute the command use:
104c1213 23141
8e04817f
AC
23142@smallexample
23143adder 1 2 3
23144@end smallexample
104c1213 23145
8e04817f
AC
23146@noindent
23147This defines the command @code{adder}, which prints the sum of
23148its three arguments. Note the arguments are text substitutions, so they may
23149reference variables, use complex expressions, or even perform inferior
23150functions calls.
104c1213 23151
fcc73fe3
EZ
23152@cindex argument count in user-defined commands
23153@cindex how many arguments (user-defined commands)
c03c782f
AS
23154In addition, @code{$argc} may be used to find out how many arguments have
23155been passed. This expands to a number in the range 0@dots{}10.
23156
23157@smallexample
23158define adder
23159 if $argc == 2
23160 print $arg0 + $arg1
23161 end
23162 if $argc == 3
23163 print $arg0 + $arg1 + $arg2
23164 end
23165end
23166@end smallexample
23167
104c1213 23168@table @code
104c1213 23169
8e04817f
AC
23170@kindex define
23171@item define @var{commandname}
23172Define a command named @var{commandname}. If there is already a command
23173by that name, you are asked to confirm that you want to redefine it.
adb483fe
DJ
23174@var{commandname} may be a bare command name consisting of letters,
23175numbers, dashes, and underscores. It may also start with any predefined
23176prefix command. For example, @samp{define target my-target} creates
23177a user-defined @samp{target my-target} command.
104c1213 23178
8e04817f
AC
23179The definition of the command is made up of other @value{GDBN} command lines,
23180which are given following the @code{define} command. The end of these
23181commands is marked by a line containing @code{end}.
104c1213 23182
8e04817f 23183@kindex document
ca91424e 23184@kindex end@r{ (user-defined commands)}
8e04817f
AC
23185@item document @var{commandname}
23186Document the user-defined command @var{commandname}, so that it can be
23187accessed by @code{help}. The command @var{commandname} must already be
23188defined. This command reads lines of documentation just as @code{define}
23189reads the lines of the command definition, ending with @code{end}.
23190After the @code{document} command is finished, @code{help} on command
23191@var{commandname} displays the documentation you have written.
104c1213 23192
8e04817f
AC
23193You may use the @code{document} command again to change the
23194documentation of a command. Redefining the command with @code{define}
23195does not change the documentation.
104c1213 23196
c45da7e6
EZ
23197@kindex dont-repeat
23198@cindex don't repeat command
23199@item dont-repeat
23200Used inside a user-defined command, this tells @value{GDBN} that this
23201command should not be repeated when the user hits @key{RET}
23202(@pxref{Command Syntax, repeat last command}).
23203
8e04817f
AC
23204@kindex help user-defined
23205@item help user-defined
7d74f244
DE
23206List all user-defined commands and all python commands defined in class
23207COMAND_USER. The first line of the documentation or docstring is
23208included (if any).
104c1213 23209
8e04817f
AC
23210@kindex show user
23211@item show user
23212@itemx show user @var{commandname}
23213Display the @value{GDBN} commands used to define @var{commandname} (but
23214not its documentation). If no @var{commandname} is given, display the
23215definitions for all user-defined commands.
7d74f244 23216This does not work for user-defined python commands.
104c1213 23217
fcc73fe3 23218@cindex infinite recursion in user-defined commands
20f01a46
DH
23219@kindex show max-user-call-depth
23220@kindex set max-user-call-depth
23221@item show max-user-call-depth
5ca0cb28
DH
23222@itemx set max-user-call-depth
23223The value of @code{max-user-call-depth} controls how many recursion
3f94c067 23224levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 23225infinite recursion and aborts the command.
7d74f244 23226This does not apply to user-defined python commands.
104c1213
JM
23227@end table
23228
fcc73fe3
EZ
23229In addition to the above commands, user-defined commands frequently
23230use control flow commands, described in @ref{Command Files}.
23231
8e04817f
AC
23232When user-defined commands are executed, the
23233commands of the definition are not printed. An error in any command
23234stops execution of the user-defined command.
104c1213 23235
8e04817f
AC
23236If used interactively, commands that would ask for confirmation proceed
23237without asking when used inside a user-defined command. Many @value{GDBN}
23238commands that normally print messages to say what they are doing omit the
23239messages when used in a user-defined command.
104c1213 23240
8e04817f 23241@node Hooks
d57a3c85 23242@subsection User-defined Command Hooks
8e04817f
AC
23243@cindex command hooks
23244@cindex hooks, for commands
23245@cindex hooks, pre-command
104c1213 23246
8e04817f 23247@kindex hook
8e04817f
AC
23248You may define @dfn{hooks}, which are a special kind of user-defined
23249command. Whenever you run the command @samp{foo}, if the user-defined
23250command @samp{hook-foo} exists, it is executed (with no arguments)
23251before that command.
104c1213 23252
8e04817f
AC
23253@cindex hooks, post-command
23254@kindex hookpost
8e04817f
AC
23255A hook may also be defined which is run after the command you executed.
23256Whenever you run the command @samp{foo}, if the user-defined command
23257@samp{hookpost-foo} exists, it is executed (with no arguments) after
23258that command. Post-execution hooks may exist simultaneously with
23259pre-execution hooks, for the same command.
104c1213 23260
8e04817f 23261It is valid for a hook to call the command which it hooks. If this
9f1c6395 23262occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 23263
8e04817f
AC
23264@c It would be nice if hookpost could be passed a parameter indicating
23265@c if the command it hooks executed properly or not. FIXME!
104c1213 23266
8e04817f
AC
23267@kindex stop@r{, a pseudo-command}
23268In addition, a pseudo-command, @samp{stop} exists. Defining
23269(@samp{hook-stop}) makes the associated commands execute every time
23270execution stops in your program: before breakpoint commands are run,
23271displays are printed, or the stack frame is printed.
104c1213 23272
8e04817f
AC
23273For example, to ignore @code{SIGALRM} signals while
23274single-stepping, but treat them normally during normal execution,
23275you could define:
104c1213 23276
474c8240 23277@smallexample
8e04817f
AC
23278define hook-stop
23279handle SIGALRM nopass
23280end
104c1213 23281
8e04817f
AC
23282define hook-run
23283handle SIGALRM pass
23284end
104c1213 23285
8e04817f 23286define hook-continue
d3e8051b 23287handle SIGALRM pass
8e04817f 23288end
474c8240 23289@end smallexample
104c1213 23290
d3e8051b 23291As a further example, to hook at the beginning and end of the @code{echo}
b383017d 23292command, and to add extra text to the beginning and end of the message,
8e04817f 23293you could define:
104c1213 23294
474c8240 23295@smallexample
8e04817f
AC
23296define hook-echo
23297echo <<<---
23298end
104c1213 23299
8e04817f
AC
23300define hookpost-echo
23301echo --->>>\n
23302end
104c1213 23303
8e04817f
AC
23304(@value{GDBP}) echo Hello World
23305<<<---Hello World--->>>
23306(@value{GDBP})
104c1213 23307
474c8240 23308@end smallexample
104c1213 23309
8e04817f
AC
23310You can define a hook for any single-word command in @value{GDBN}, but
23311not for command aliases; you should define a hook for the basic command
c1468174 23312name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
23313@c FIXME! So how does Joe User discover whether a command is an alias
23314@c or not?
adb483fe
DJ
23315You can hook a multi-word command by adding @code{hook-} or
23316@code{hookpost-} to the last word of the command, e.g.@:
23317@samp{define target hook-remote} to add a hook to @samp{target remote}.
23318
8e04817f
AC
23319If an error occurs during the execution of your hook, execution of
23320@value{GDBN} commands stops and @value{GDBN} issues a prompt
23321(before the command that you actually typed had a chance to run).
104c1213 23322
8e04817f
AC
23323If you try to define a hook which does not match any known command, you
23324get a warning from the @code{define} command.
c906108c 23325
8e04817f 23326@node Command Files
d57a3c85 23327@subsection Command Files
c906108c 23328
8e04817f 23329@cindex command files
fcc73fe3 23330@cindex scripting commands
6fc08d32
EZ
23331A command file for @value{GDBN} is a text file made of lines that are
23332@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
23333also be included. An empty line in a command file does nothing; it
23334does not mean to repeat the last command, as it would from the
23335terminal.
c906108c 23336
6fc08d32 23337You can request the execution of a command file with the @code{source}
95433b34
JB
23338command. Note that the @code{source} command is also used to evaluate
23339scripts that are not Command Files. The exact behavior can be configured
23340using the @code{script-extension} setting.
23341@xref{Extending GDB,, Extending GDB}.
c906108c 23342
8e04817f
AC
23343@table @code
23344@kindex source
ca91424e 23345@cindex execute commands from a file
3f7b2faa 23346@item source [-s] [-v] @var{filename}
8e04817f 23347Execute the command file @var{filename}.
c906108c
SS
23348@end table
23349
fcc73fe3
EZ
23350The lines in a command file are generally executed sequentially,
23351unless the order of execution is changed by one of the
23352@emph{flow-control commands} described below. The commands are not
a71ec265
DH
23353printed as they are executed. An error in any command terminates
23354execution of the command file and control is returned to the console.
c906108c 23355
08001717
DE
23356@value{GDBN} first searches for @var{filename} in the current directory.
23357If the file is not found there, and @var{filename} does not specify a
23358directory, then @value{GDBN} also looks for the file on the source search path
23359(specified with the @samp{directory} command);
23360except that @file{$cdir} is not searched because the compilation directory
23361is not relevant to scripts.
4b505b12 23362
3f7b2faa
DE
23363If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
23364on the search path even if @var{filename} specifies a directory.
23365The search is done by appending @var{filename} to each element of the
23366search path. So, for example, if @var{filename} is @file{mylib/myscript}
23367and the search path contains @file{/home/user} then @value{GDBN} will
23368look for the script @file{/home/user/mylib/myscript}.
23369The search is also done if @var{filename} is an absolute path.
23370For example, if @var{filename} is @file{/tmp/myscript} and
23371the search path contains @file{/home/user} then @value{GDBN} will
23372look for the script @file{/home/user/tmp/myscript}.
23373For DOS-like systems, if @var{filename} contains a drive specification,
23374it is stripped before concatenation. For example, if @var{filename} is
23375@file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
23376will look for the script @file{c:/tmp/myscript}.
23377
16026cd7
AS
23378If @code{-v}, for verbose mode, is given then @value{GDBN} displays
23379each command as it is executed. The option must be given before
23380@var{filename}, and is interpreted as part of the filename anywhere else.
23381
8e04817f
AC
23382Commands that would ask for confirmation if used interactively proceed
23383without asking when used in a command file. Many @value{GDBN} commands that
23384normally print messages to say what they are doing omit the messages
23385when called from command files.
c906108c 23386
8e04817f
AC
23387@value{GDBN} also accepts command input from standard input. In this
23388mode, normal output goes to standard output and error output goes to
23389standard error. Errors in a command file supplied on standard input do
6fc08d32 23390not terminate execution of the command file---execution continues with
8e04817f 23391the next command.
c906108c 23392
474c8240 23393@smallexample
8e04817f 23394gdb < cmds > log 2>&1
474c8240 23395@end smallexample
c906108c 23396
8e04817f
AC
23397(The syntax above will vary depending on the shell used.) This example
23398will execute commands from the file @file{cmds}. All output and errors
23399would be directed to @file{log}.
c906108c 23400
fcc73fe3
EZ
23401Since commands stored on command files tend to be more general than
23402commands typed interactively, they frequently need to deal with
23403complicated situations, such as different or unexpected values of
23404variables and symbols, changes in how the program being debugged is
23405built, etc. @value{GDBN} provides a set of flow-control commands to
23406deal with these complexities. Using these commands, you can write
23407complex scripts that loop over data structures, execute commands
23408conditionally, etc.
23409
23410@table @code
23411@kindex if
23412@kindex else
23413@item if
23414@itemx else
23415This command allows to include in your script conditionally executed
23416commands. The @code{if} command takes a single argument, which is an
23417expression to evaluate. It is followed by a series of commands that
23418are executed only if the expression is true (its value is nonzero).
23419There can then optionally be an @code{else} line, followed by a series
23420of commands that are only executed if the expression was false. The
23421end of the list is marked by a line containing @code{end}.
23422
23423@kindex while
23424@item while
23425This command allows to write loops. Its syntax is similar to
23426@code{if}: the command takes a single argument, which is an expression
23427to evaluate, and must be followed by the commands to execute, one per
23428line, terminated by an @code{end}. These commands are called the
23429@dfn{body} of the loop. The commands in the body of @code{while} are
23430executed repeatedly as long as the expression evaluates to true.
23431
23432@kindex loop_break
23433@item loop_break
23434This command exits the @code{while} loop in whose body it is included.
23435Execution of the script continues after that @code{while}s @code{end}
23436line.
23437
23438@kindex loop_continue
23439@item loop_continue
23440This command skips the execution of the rest of the body of commands
23441in the @code{while} loop in whose body it is included. Execution
23442branches to the beginning of the @code{while} loop, where it evaluates
23443the controlling expression.
ca91424e
EZ
23444
23445@kindex end@r{ (if/else/while commands)}
23446@item end
23447Terminate the block of commands that are the body of @code{if},
23448@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
23449@end table
23450
23451
8e04817f 23452@node Output
d57a3c85 23453@subsection Commands for Controlled Output
c906108c 23454
8e04817f
AC
23455During the execution of a command file or a user-defined command, normal
23456@value{GDBN} output is suppressed; the only output that appears is what is
23457explicitly printed by the commands in the definition. This section
23458describes three commands useful for generating exactly the output you
23459want.
c906108c
SS
23460
23461@table @code
8e04817f
AC
23462@kindex echo
23463@item echo @var{text}
23464@c I do not consider backslash-space a standard C escape sequence
23465@c because it is not in ANSI.
23466Print @var{text}. Nonprinting characters can be included in
23467@var{text} using C escape sequences, such as @samp{\n} to print a
23468newline. @strong{No newline is printed unless you specify one.}
23469In addition to the standard C escape sequences, a backslash followed
23470by a space stands for a space. This is useful for displaying a
23471string with spaces at the beginning or the end, since leading and
23472trailing spaces are otherwise trimmed from all arguments.
23473To print @samp{@w{ }and foo =@w{ }}, use the command
23474@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 23475
8e04817f
AC
23476A backslash at the end of @var{text} can be used, as in C, to continue
23477the command onto subsequent lines. For example,
c906108c 23478
474c8240 23479@smallexample
8e04817f
AC
23480echo This is some text\n\
23481which is continued\n\
23482onto several lines.\n
474c8240 23483@end smallexample
c906108c 23484
8e04817f 23485produces the same output as
c906108c 23486
474c8240 23487@smallexample
8e04817f
AC
23488echo This is some text\n
23489echo which is continued\n
23490echo onto several lines.\n
474c8240 23491@end smallexample
c906108c 23492
8e04817f
AC
23493@kindex output
23494@item output @var{expression}
23495Print the value of @var{expression} and nothing but that value: no
23496newlines, no @samp{$@var{nn} = }. The value is not entered in the
23497value history either. @xref{Expressions, ,Expressions}, for more information
23498on expressions.
c906108c 23499
8e04817f
AC
23500@item output/@var{fmt} @var{expression}
23501Print the value of @var{expression} in format @var{fmt}. You can use
23502the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 23503Formats}, for more information.
c906108c 23504
8e04817f 23505@kindex printf
82160952
EZ
23506@item printf @var{template}, @var{expressions}@dots{}
23507Print the values of one or more @var{expressions} under the control of
23508the string @var{template}. To print several values, make
23509@var{expressions} be a comma-separated list of individual expressions,
23510which may be either numbers or pointers. Their values are printed as
23511specified by @var{template}, exactly as a C program would do by
23512executing the code below:
c906108c 23513
474c8240 23514@smallexample
82160952 23515printf (@var{template}, @var{expressions}@dots{});
474c8240 23516@end smallexample
c906108c 23517
82160952
EZ
23518As in @code{C} @code{printf}, ordinary characters in @var{template}
23519are printed verbatim, while @dfn{conversion specification} introduced
23520by the @samp{%} character cause subsequent @var{expressions} to be
23521evaluated, their values converted and formatted according to type and
23522style information encoded in the conversion specifications, and then
23523printed.
23524
8e04817f 23525For example, you can print two values in hex like this:
c906108c 23526
8e04817f
AC
23527@smallexample
23528printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
23529@end smallexample
c906108c 23530
82160952
EZ
23531@code{printf} supports all the standard @code{C} conversion
23532specifications, including the flags and modifiers between the @samp{%}
23533character and the conversion letter, with the following exceptions:
23534
23535@itemize @bullet
23536@item
23537The argument-ordering modifiers, such as @samp{2$}, are not supported.
23538
23539@item
23540The modifier @samp{*} is not supported for specifying precision or
23541width.
23542
23543@item
23544The @samp{'} flag (for separation of digits into groups according to
23545@code{LC_NUMERIC'}) is not supported.
23546
23547@item
23548The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
23549supported.
23550
23551@item
23552The conversion letter @samp{n} (as in @samp{%n}) is not supported.
23553
23554@item
23555The conversion letters @samp{a} and @samp{A} are not supported.
23556@end itemize
23557
23558@noindent
23559Note that the @samp{ll} type modifier is supported only if the
23560underlying @code{C} implementation used to build @value{GDBN} supports
23561the @code{long long int} type, and the @samp{L} type modifier is
23562supported only if @code{long double} type is available.
23563
23564As in @code{C}, @code{printf} supports simple backslash-escape
23565sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
23566@samp{\a}, and @samp{\f}, that consist of backslash followed by a
23567single character. Octal and hexadecimal escape sequences are not
23568supported.
1a619819
LM
23569
23570Additionally, @code{printf} supports conversion specifications for DFP
0aea4bf3
LM
23571(@dfn{Decimal Floating Point}) types using the following length modifiers
23572together with a floating point specifier.
1a619819
LM
23573letters:
23574
23575@itemize @bullet
23576@item
23577@samp{H} for printing @code{Decimal32} types.
23578
23579@item
23580@samp{D} for printing @code{Decimal64} types.
23581
23582@item
23583@samp{DD} for printing @code{Decimal128} types.
23584@end itemize
23585
23586If the underlying @code{C} implementation used to build @value{GDBN} has
0aea4bf3 23587support for the three length modifiers for DFP types, other modifiers
3b784c4f 23588such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
23589
23590In case there is no such @code{C} support, no additional modifiers will be
23591available and the value will be printed in the standard way.
23592
23593Here's an example of printing DFP types using the above conversion letters:
23594@smallexample
0aea4bf3 23595printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
1a619819
LM
23596@end smallexample
23597
f1421989
HZ
23598@kindex eval
23599@item eval @var{template}, @var{expressions}@dots{}
23600Convert the values of one or more @var{expressions} under the control of
23601the string @var{template} to a command line, and call it.
23602
c906108c
SS
23603@end table
23604
71b8c845
DE
23605@node Auto-loading sequences
23606@subsection Controlling auto-loading native @value{GDBN} scripts
23607@cindex native script auto-loading
23608
23609When a new object file is read (for example, due to the @code{file}
23610command, or because the inferior has loaded a shared library),
23611@value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
23612@xref{Auto-loading extensions}.
23613
23614Auto-loading can be enabled or disabled,
23615and the list of auto-loaded scripts can be printed.
23616
23617@table @code
23618@anchor{set auto-load gdb-scripts}
23619@kindex set auto-load gdb-scripts
23620@item set auto-load gdb-scripts [on|off]
23621Enable or disable the auto-loading of canned sequences of commands scripts.
23622
23623@anchor{show auto-load gdb-scripts}
23624@kindex show auto-load gdb-scripts
23625@item show auto-load gdb-scripts
23626Show whether auto-loading of canned sequences of commands scripts is enabled or
23627disabled.
23628
23629@anchor{info auto-load gdb-scripts}
23630@kindex info auto-load gdb-scripts
23631@cindex print list of auto-loaded canned sequences of commands scripts
23632@item info auto-load gdb-scripts [@var{regexp}]
23633Print the list of all canned sequences of commands scripts that @value{GDBN}
23634auto-loaded.
23635@end table
23636
23637If @var{regexp} is supplied only canned sequences of commands scripts with
23638matching names are printed.
23639
329baa95
DE
23640@c Python docs live in a separate file.
23641@include python.texi
0e3509db 23642
ed3ef339
DE
23643@c Guile docs live in a separate file.
23644@include guile.texi
23645
71b8c845
DE
23646@node Auto-loading extensions
23647@section Auto-loading extensions
23648@cindex auto-loading extensions
23649
23650@value{GDBN} provides two mechanisms for automatically loading extensions
23651when a new object file is read (for example, due to the @code{file}
23652command, or because the inferior has loaded a shared library):
23653@file{@var{objfile}-gdb.@var{ext}} and the @code{.debug_gdb_scripts}
23654section of modern file formats like ELF.
23655
23656@menu
23657* objfile-gdb.ext file: objfile-gdbdotext file. The @file{@var{objfile}-gdb.@var{ext}} file
23658* .debug_gdb_scripts section: dotdebug_gdb_scripts section. The @code{.debug_gdb_scripts} section
23659* Which flavor to choose?::
23660@end menu
23661
23662The auto-loading feature is useful for supplying application-specific
23663debugging commands and features.
23664
23665Auto-loading can be enabled or disabled,
23666and the list of auto-loaded scripts can be printed.
23667See the @samp{auto-loading} section of each extension language
23668for more information.
23669For @value{GDBN} command files see @ref{Auto-loading sequences}.
23670For Python files see @ref{Python Auto-loading}.
23671
23672Note that loading of this script file also requires accordingly configured
23673@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
23674
23675@node objfile-gdbdotext file
23676@subsection The @file{@var{objfile}-gdb.@var{ext}} file
23677@cindex @file{@var{objfile}-gdb.gdb}
23678@cindex @file{@var{objfile}-gdb.py}
23679@cindex @file{@var{objfile}-gdb.scm}
23680
23681When a new object file is read, @value{GDBN} looks for a file named
23682@file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
23683where @var{objfile} is the object file's name and
23684where @var{ext} is the file extension for the extension language:
23685
23686@table @code
23687@item @file{@var{objfile}-gdb.gdb}
23688GDB's own command language
23689@item @file{@var{objfile}-gdb.py}
23690Python
ed3ef339
DE
23691@item @file{@var{objfile}-gdb.scm}
23692Guile
71b8c845
DE
23693@end table
23694
23695@var{script-name} is formed by ensuring that the file name of @var{objfile}
23696is absolute, following all symlinks, and resolving @code{.} and @code{..}
23697components, and appending the @file{-gdb.@var{ext}} suffix.
23698If this file exists and is readable, @value{GDBN} will evaluate it as a
23699script in the specified extension language.
23700
23701If this file does not exist, then @value{GDBN} will look for
23702@var{script-name} file in all of the directories as specified below.
23703
23704Note that loading of these files requires an accordingly configured
23705@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
23706
23707For object files using @file{.exe} suffix @value{GDBN} tries to load first the
23708scripts normally according to its @file{.exe} filename. But if no scripts are
23709found @value{GDBN} also tries script filenames matching the object file without
23710its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
23711is attempted on any platform. This makes the script filenames compatible
23712between Unix and MS-Windows hosts.
23713
23714@table @code
23715@anchor{set auto-load scripts-directory}
23716@kindex set auto-load scripts-directory
23717@item set auto-load scripts-directory @r{[}@var{directories}@r{]}
23718Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
23719may be delimited by the host platform path separator in use
23720(@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
23721
23722Each entry here needs to be covered also by the security setting
23723@code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
23724
23725@anchor{with-auto-load-dir}
23726This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
23727@code{set auto-load safe-path} value can be also overriden by @value{GDBN}
23728configuration option @option{--with-auto-load-dir}.
23729
23730Any reference to @file{$debugdir} will get replaced by
23731@var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
23732reference to @file{$datadir} will get replaced by @var{data-directory} which is
23733determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
23734@file{$datadir} must be placed as a directory component --- either alone or
23735delimited by @file{/} or @file{\} directory separators, depending on the host
23736platform.
23737
23738The list of directories uses path separator (@samp{:} on GNU and Unix
23739systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
23740to the @env{PATH} environment variable.
23741
23742@anchor{show auto-load scripts-directory}
23743@kindex show auto-load scripts-directory
23744@item show auto-load scripts-directory
23745Show @value{GDBN} auto-loaded scripts location.
23746@end table
23747
23748@value{GDBN} does not track which files it has already auto-loaded this way.
23749@value{GDBN} will load the associated script every time the corresponding
23750@var{objfile} is opened.
23751So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
23752is evaluated more than once.
23753
23754@node dotdebug_gdb_scripts section
23755@subsection The @code{.debug_gdb_scripts} section
23756@cindex @code{.debug_gdb_scripts} section
23757
23758For systems using file formats like ELF and COFF,
23759when @value{GDBN} loads a new object file
23760it will look for a special section named @code{.debug_gdb_scripts}.
23761If this section exists, its contents is a list of NUL-terminated names
23762of scripts to load. Each entry begins with a non-NULL prefix byte that
23763specifies the kind of entry, typically the extension language.
23764
23765@value{GDBN} will look for each specified script file first in the
23766current directory and then along the source search path
23767(@pxref{Source Path, ,Specifying Source Directories}),
23768except that @file{$cdir} is not searched, since the compilation
23769directory is not relevant to scripts.
23770
23771Entries can be placed in section @code{.debug_gdb_scripts} with,
23772for example, this GCC macro for Python scripts.
23773
23774@example
23775/* Note: The "MS" section flags are to remove duplicates. */
23776#define DEFINE_GDB_PY_SCRIPT(script_name) \
23777 asm("\
23778.pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
23779.byte 1 /* Python */\n\
23780.asciz \"" script_name "\"\n\
23781.popsection \n\
23782");
23783@end example
23784
23785@noindent
ed3ef339 23786For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
71b8c845
DE
23787Then one can reference the macro in a header or source file like this:
23788
23789@example
23790DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
23791@end example
23792
23793The script name may include directories if desired.
23794
23795Note that loading of this script file also requires accordingly configured
23796@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
23797
23798If the macro invocation is put in a header, any application or library
23799using this header will get a reference to the specified script,
23800and with the use of @code{"MS"} attributes on the section, the linker
23801will remove duplicates.
23802
23803@node Which flavor to choose?
23804@subsection Which flavor to choose?
23805
23806Given the multiple ways of auto-loading extensions, it might not always
23807be clear which one to choose. This section provides some guidance.
23808
23809@noindent
23810Benefits of the @file{-gdb.@var{ext}} way:
23811
23812@itemize @bullet
23813@item
23814Can be used with file formats that don't support multiple sections.
23815
23816@item
23817Ease of finding scripts for public libraries.
23818
23819Scripts specified in the @code{.debug_gdb_scripts} section are searched for
23820in the source search path.
23821For publicly installed libraries, e.g., @file{libstdc++}, there typically
23822isn't a source directory in which to find the script.
23823
23824@item
23825Doesn't require source code additions.
23826@end itemize
23827
23828@noindent
23829Benefits of the @code{.debug_gdb_scripts} way:
23830
23831@itemize @bullet
23832@item
23833Works with static linking.
23834
23835Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
23836trigger their loading. When an application is statically linked the only
23837objfile available is the executable, and it is cumbersome to attach all the
23838scripts from all the input libraries to the executable's
23839@file{-gdb.@var{ext}} script.
23840
23841@item
23842Works with classes that are entirely inlined.
23843
23844Some classes can be entirely inlined, and thus there may not be an associated
23845shared library to attach a @file{-gdb.@var{ext}} script to.
23846
23847@item
23848Scripts needn't be copied out of the source tree.
23849
23850In some circumstances, apps can be built out of large collections of internal
23851libraries, and the build infrastructure necessary to install the
23852@file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
23853cumbersome. It may be easier to specify the scripts in the
23854@code{.debug_gdb_scripts} section as relative paths, and add a path to the
23855top of the source tree to the source search path.
23856@end itemize
23857
ed3ef339
DE
23858@node Multiple Extension Languages
23859@section Multiple Extension Languages
23860
23861The Guile and Python extension languages do not share any state,
23862and generally do not interfere with each other.
23863There are some things to be aware of, however.
23864
23865@subsection Python comes first
23866
23867Python was @value{GDBN}'s first extension language, and to avoid breaking
23868existing behaviour Python comes first. This is generally solved by the
23869``first one wins'' principle. @value{GDBN} maintains a list of enabled
23870extension languages, and when it makes a call to an extension language,
23871(say to pretty-print a value), it tries each in turn until an extension
23872language indicates it has performed the request (e.g., has returned the
23873pretty-printed form of a value).
23874This extends to errors while performing such requests: If an error happens
23875while, for example, trying to pretty-print an object then the error is
23876reported and any following extension languages are not tried.
23877
5a56e9c5
DE
23878@node Aliases
23879@section Creating new spellings of existing commands
23880@cindex aliases for commands
23881
23882It is often useful to define alternate spellings of existing commands.
23883For example, if a new @value{GDBN} command defined in Python has
23884a long name to type, it is handy to have an abbreviated version of it
23885that involves less typing.
23886
23887@value{GDBN} itself uses aliases. For example @samp{s} is an alias
23888of the @samp{step} command even though it is otherwise an ambiguous
23889abbreviation of other commands like @samp{set} and @samp{show}.
23890
23891Aliases are also used to provide shortened or more common versions
23892of multi-word commands. For example, @value{GDBN} provides the
23893@samp{tty} alias of the @samp{set inferior-tty} command.
23894
23895You can define a new alias with the @samp{alias} command.
23896
23897@table @code
23898
23899@kindex alias
23900@item alias [-a] [--] @var{ALIAS} = @var{COMMAND}
23901
23902@end table
23903
23904@var{ALIAS} specifies the name of the new alias.
23905Each word of @var{ALIAS} must consist of letters, numbers, dashes and
23906underscores.
23907
23908@var{COMMAND} specifies the name of an existing command
23909that is being aliased.
23910
23911The @samp{-a} option specifies that the new alias is an abbreviation
23912of the command. Abbreviations are not shown in command
23913lists displayed by the @samp{help} command.
23914
23915The @samp{--} option specifies the end of options,
23916and is useful when @var{ALIAS} begins with a dash.
23917
23918Here is a simple example showing how to make an abbreviation
23919of a command so that there is less to type.
23920Suppose you were tired of typing @samp{disas}, the current
23921shortest unambiguous abbreviation of the @samp{disassemble} command
23922and you wanted an even shorter version named @samp{di}.
23923The following will accomplish this.
23924
23925@smallexample
23926(gdb) alias -a di = disas
23927@end smallexample
23928
23929Note that aliases are different from user-defined commands.
23930With a user-defined command, you also need to write documentation
23931for it with the @samp{document} command.
23932An alias automatically picks up the documentation of the existing command.
23933
23934Here is an example where we make @samp{elms} an abbreviation of
23935@samp{elements} in the @samp{set print elements} command.
23936This is to show that you can make an abbreviation of any part
23937of a command.
23938
23939@smallexample
23940(gdb) alias -a set print elms = set print elements
23941(gdb) alias -a show print elms = show print elements
23942(gdb) set p elms 20
23943(gdb) show p elms
23944Limit on string chars or array elements to print is 200.
23945@end smallexample
23946
23947Note that if you are defining an alias of a @samp{set} command,
23948and you want to have an alias for the corresponding @samp{show}
23949command, then you need to define the latter separately.
23950
23951Unambiguously abbreviated commands are allowed in @var{COMMAND} and
23952@var{ALIAS}, just as they are normally.
23953
23954@smallexample
23955(gdb) alias -a set pr elms = set p ele
23956@end smallexample
23957
23958Finally, here is an example showing the creation of a one word
23959alias for a more complex command.
23960This creates alias @samp{spe} of the command @samp{set print elements}.
23961
23962@smallexample
23963(gdb) alias spe = set print elements
23964(gdb) spe 20
23965@end smallexample
23966
21c294e6
AC
23967@node Interpreters
23968@chapter Command Interpreters
23969@cindex command interpreters
23970
23971@value{GDBN} supports multiple command interpreters, and some command
23972infrastructure to allow users or user interface writers to switch
23973between interpreters or run commands in other interpreters.
23974
23975@value{GDBN} currently supports two command interpreters, the console
23976interpreter (sometimes called the command-line interpreter or @sc{cli})
23977and the machine interface interpreter (or @sc{gdb/mi}). This manual
23978describes both of these interfaces in great detail.
23979
23980By default, @value{GDBN} will start with the console interpreter.
23981However, the user may choose to start @value{GDBN} with another
23982interpreter by specifying the @option{-i} or @option{--interpreter}
23983startup options. Defined interpreters include:
23984
23985@table @code
23986@item console
23987@cindex console interpreter
23988The traditional console or command-line interpreter. This is the most often
23989used interpreter with @value{GDBN}. With no interpreter specified at runtime,
23990@value{GDBN} will use this interpreter.
23991
23992@item mi
23993@cindex mi interpreter
23994The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
23995by programs wishing to use @value{GDBN} as a backend for a debugger GUI
23996or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
23997Interface}.
23998
23999@item mi2
24000@cindex mi2 interpreter
24001The current @sc{gdb/mi} interface.
24002
24003@item mi1
24004@cindex mi1 interpreter
24005The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
24006
24007@end table
24008
24009@cindex invoke another interpreter
24010The interpreter being used by @value{GDBN} may not be dynamically
24011switched at runtime. Although possible, this could lead to a very
24012precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
24013enters the command "interpreter-set console" in a console view,
24014@value{GDBN} would switch to using the console interpreter, rendering
24015the IDE inoperable!
24016
24017@kindex interpreter-exec
24018Although you may only choose a single interpreter at startup, you may execute
24019commands in any interpreter from the current interpreter using the appropriate
24020command. If you are running the console interpreter, simply use the
24021@code{interpreter-exec} command:
24022
24023@smallexample
24024interpreter-exec mi "-data-list-register-names"
24025@end smallexample
24026
24027@sc{gdb/mi} has a similar command, although it is only available in versions of
24028@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
24029
8e04817f
AC
24030@node TUI
24031@chapter @value{GDBN} Text User Interface
24032@cindex TUI
d0d5df6f 24033@cindex Text User Interface
c906108c 24034
8e04817f
AC
24035@menu
24036* TUI Overview:: TUI overview
24037* TUI Keys:: TUI key bindings
7cf36c78 24038* TUI Single Key Mode:: TUI single key mode
db2e3e2e 24039* TUI Commands:: TUI-specific commands
8e04817f
AC
24040* TUI Configuration:: TUI configuration variables
24041@end menu
c906108c 24042
46ba6afa 24043The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
24044interface which uses the @code{curses} library to show the source
24045file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
24046commands in separate text windows. The TUI mode is supported only
24047on platforms where a suitable version of the @code{curses} library
24048is available.
d0d5df6f 24049
46ba6afa 24050The TUI mode is enabled by default when you invoke @value{GDBN} as
217bff3e 24051@samp{@value{GDBP} -tui}.
46ba6afa
BW
24052You can also switch in and out of TUI mode while @value{GDBN} runs by
24053using various TUI commands and key bindings, such as @kbd{C-x C-a}.
24054@xref{TUI Keys, ,TUI Key Bindings}.
c906108c 24055
8e04817f 24056@node TUI Overview
79a6e687 24057@section TUI Overview
c906108c 24058
46ba6afa 24059In TUI mode, @value{GDBN} can display several text windows:
c906108c 24060
8e04817f
AC
24061@table @emph
24062@item command
24063This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
24064prompt and the @value{GDBN} output. The @value{GDBN} input is still
24065managed using readline.
c906108c 24066
8e04817f
AC
24067@item source
24068The source window shows the source file of the program. The current
46ba6afa 24069line and active breakpoints are displayed in this window.
c906108c 24070
8e04817f
AC
24071@item assembly
24072The assembly window shows the disassembly output of the program.
c906108c 24073
8e04817f 24074@item register
46ba6afa
BW
24075This window shows the processor registers. Registers are highlighted
24076when their values change.
c906108c
SS
24077@end table
24078
269c21fe 24079The source and assembly windows show the current program position
46ba6afa
BW
24080by highlighting the current line and marking it with a @samp{>} marker.
24081Breakpoints are indicated with two markers. The first marker
269c21fe
SC
24082indicates the breakpoint type:
24083
24084@table @code
24085@item B
24086Breakpoint which was hit at least once.
24087
24088@item b
24089Breakpoint which was never hit.
24090
24091@item H
24092Hardware breakpoint which was hit at least once.
24093
24094@item h
24095Hardware breakpoint which was never hit.
269c21fe
SC
24096@end table
24097
24098The second marker indicates whether the breakpoint is enabled or not:
24099
24100@table @code
24101@item +
24102Breakpoint is enabled.
24103
24104@item -
24105Breakpoint is disabled.
269c21fe
SC
24106@end table
24107
46ba6afa
BW
24108The source, assembly and register windows are updated when the current
24109thread changes, when the frame changes, or when the program counter
24110changes.
24111
24112These windows are not all visible at the same time. The command
24113window is always visible. The others can be arranged in several
24114layouts:
c906108c 24115
8e04817f
AC
24116@itemize @bullet
24117@item
46ba6afa 24118source only,
2df3850c 24119
8e04817f 24120@item
46ba6afa 24121assembly only,
8e04817f
AC
24122
24123@item
46ba6afa 24124source and assembly,
8e04817f
AC
24125
24126@item
46ba6afa 24127source and registers, or
c906108c 24128
8e04817f 24129@item
46ba6afa 24130assembly and registers.
8e04817f 24131@end itemize
c906108c 24132
46ba6afa 24133A status line above the command window shows the following information:
b7bb15bc
SC
24134
24135@table @emph
24136@item target
46ba6afa 24137Indicates the current @value{GDBN} target.
b7bb15bc
SC
24138(@pxref{Targets, ,Specifying a Debugging Target}).
24139
24140@item process
46ba6afa 24141Gives the current process or thread number.
b7bb15bc
SC
24142When no process is being debugged, this field is set to @code{No process}.
24143
24144@item function
24145Gives the current function name for the selected frame.
24146The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 24147When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
24148the string @code{??} is displayed.
24149
24150@item line
24151Indicates the current line number for the selected frame.
46ba6afa 24152When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
24153
24154@item pc
24155Indicates the current program counter address.
b7bb15bc
SC
24156@end table
24157
8e04817f
AC
24158@node TUI Keys
24159@section TUI Key Bindings
24160@cindex TUI key bindings
c906108c 24161
8e04817f 24162The TUI installs several key bindings in the readline keymaps
39037522
TT
24163@ifset SYSTEM_READLINE
24164(@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
24165@end ifset
24166@ifclear SYSTEM_READLINE
24167(@pxref{Command Line Editing}).
24168@end ifclear
24169The following key bindings are installed for both TUI mode and the
24170@value{GDBN} standard mode.
c906108c 24171
8e04817f
AC
24172@table @kbd
24173@kindex C-x C-a
24174@item C-x C-a
24175@kindex C-x a
24176@itemx C-x a
24177@kindex C-x A
24178@itemx C-x A
46ba6afa
BW
24179Enter or leave the TUI mode. When leaving the TUI mode,
24180the curses window management stops and @value{GDBN} operates using
24181its standard mode, writing on the terminal directly. When reentering
24182the TUI mode, control is given back to the curses windows.
8e04817f 24183The screen is then refreshed.
c906108c 24184
8e04817f
AC
24185@kindex C-x 1
24186@item C-x 1
24187Use a TUI layout with only one window. The layout will
24188either be @samp{source} or @samp{assembly}. When the TUI mode
24189is not active, it will switch to the TUI mode.
2df3850c 24190
8e04817f 24191Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 24192
8e04817f
AC
24193@kindex C-x 2
24194@item C-x 2
24195Use a TUI layout with at least two windows. When the current
46ba6afa 24196layout already has two windows, the next layout with two windows is used.
8e04817f
AC
24197When a new layout is chosen, one window will always be common to the
24198previous layout and the new one.
c906108c 24199
8e04817f 24200Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 24201
72ffddc9
SC
24202@kindex C-x o
24203@item C-x o
24204Change the active window. The TUI associates several key bindings
46ba6afa 24205(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
24206gives the focus to the next TUI window.
24207
24208Think of it as the Emacs @kbd{C-x o} binding.
24209
7cf36c78
SC
24210@kindex C-x s
24211@item C-x s
46ba6afa
BW
24212Switch in and out of the TUI SingleKey mode that binds single
24213keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c906108c
SS
24214@end table
24215
46ba6afa 24216The following key bindings only work in the TUI mode:
5d161b24 24217
46ba6afa 24218@table @asis
8e04817f 24219@kindex PgUp
46ba6afa 24220@item @key{PgUp}
8e04817f 24221Scroll the active window one page up.
c906108c 24222
8e04817f 24223@kindex PgDn
46ba6afa 24224@item @key{PgDn}
8e04817f 24225Scroll the active window one page down.
c906108c 24226
8e04817f 24227@kindex Up
46ba6afa 24228@item @key{Up}
8e04817f 24229Scroll the active window one line up.
c906108c 24230
8e04817f 24231@kindex Down
46ba6afa 24232@item @key{Down}
8e04817f 24233Scroll the active window one line down.
c906108c 24234
8e04817f 24235@kindex Left
46ba6afa 24236@item @key{Left}
8e04817f 24237Scroll the active window one column left.
c906108c 24238
8e04817f 24239@kindex Right
46ba6afa 24240@item @key{Right}
8e04817f 24241Scroll the active window one column right.
c906108c 24242
8e04817f 24243@kindex C-L
46ba6afa 24244@item @kbd{C-L}
8e04817f 24245Refresh the screen.
8e04817f 24246@end table
c906108c 24247
46ba6afa
BW
24248Because the arrow keys scroll the active window in the TUI mode, they
24249are not available for their normal use by readline unless the command
24250window has the focus. When another window is active, you must use
24251other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
24252and @kbd{C-f} to control the command window.
8e04817f 24253
7cf36c78
SC
24254@node TUI Single Key Mode
24255@section TUI Single Key Mode
24256@cindex TUI single key mode
24257
46ba6afa
BW
24258The TUI also provides a @dfn{SingleKey} mode, which binds several
24259frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
24260switch into this mode, where the following key bindings are used:
7cf36c78
SC
24261
24262@table @kbd
24263@kindex c @r{(SingleKey TUI key)}
24264@item c
24265continue
24266
24267@kindex d @r{(SingleKey TUI key)}
24268@item d
24269down
24270
24271@kindex f @r{(SingleKey TUI key)}
24272@item f
24273finish
24274
24275@kindex n @r{(SingleKey TUI key)}
24276@item n
24277next
24278
24279@kindex q @r{(SingleKey TUI key)}
24280@item q
46ba6afa 24281exit the SingleKey mode.
7cf36c78
SC
24282
24283@kindex r @r{(SingleKey TUI key)}
24284@item r
24285run
24286
24287@kindex s @r{(SingleKey TUI key)}
24288@item s
24289step
24290
24291@kindex u @r{(SingleKey TUI key)}
24292@item u
24293up
24294
24295@kindex v @r{(SingleKey TUI key)}
24296@item v
24297info locals
24298
24299@kindex w @r{(SingleKey TUI key)}
24300@item w
24301where
7cf36c78
SC
24302@end table
24303
24304Other keys temporarily switch to the @value{GDBN} command prompt.
24305The key that was pressed is inserted in the editing buffer so that
24306it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
24307with the TUI SingleKey mode. Once the command is entered the TUI
24308SingleKey mode is restored. The only way to permanently leave
7f9087cb 24309this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78
SC
24310
24311
8e04817f 24312@node TUI Commands
db2e3e2e 24313@section TUI-specific Commands
8e04817f
AC
24314@cindex TUI commands
24315
24316The TUI has specific commands to control the text windows.
46ba6afa
BW
24317These commands are always available, even when @value{GDBN} is not in
24318the TUI mode. When @value{GDBN} is in the standard mode, most
24319of these commands will automatically switch to the TUI mode.
c906108c 24320
ff12863f
PA
24321Note that if @value{GDBN}'s @code{stdout} is not connected to a
24322terminal, or @value{GDBN} has been started with the machine interface
24323interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
24324these commands will fail with an error, because it would not be
24325possible or desirable to enable curses window management.
24326
c906108c 24327@table @code
3d757584
SC
24328@item info win
24329@kindex info win
24330List and give the size of all displayed windows.
24331
8e04817f 24332@item layout next
4644b6e3 24333@kindex layout
8e04817f 24334Display the next layout.
2df3850c 24335
8e04817f 24336@item layout prev
8e04817f 24337Display the previous layout.
c906108c 24338
8e04817f 24339@item layout src
8e04817f 24340Display the source window only.
c906108c 24341
8e04817f 24342@item layout asm
8e04817f 24343Display the assembly window only.
c906108c 24344
8e04817f 24345@item layout split
8e04817f 24346Display the source and assembly window.
c906108c 24347
8e04817f 24348@item layout regs
8e04817f
AC
24349Display the register window together with the source or assembly window.
24350
46ba6afa 24351@item focus next
8e04817f 24352@kindex focus
46ba6afa
BW
24353Make the next window active for scrolling.
24354
24355@item focus prev
24356Make the previous window active for scrolling.
24357
24358@item focus src
24359Make the source window active for scrolling.
24360
24361@item focus asm
24362Make the assembly window active for scrolling.
24363
24364@item focus regs
24365Make the register window active for scrolling.
24366
24367@item focus cmd
24368Make the command window active for scrolling.
c906108c 24369
8e04817f
AC
24370@item refresh
24371@kindex refresh
7f9087cb 24372Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 24373
6a1b180d
SC
24374@item tui reg float
24375@kindex tui reg
24376Show the floating point registers in the register window.
24377
24378@item tui reg general
24379Show the general registers in the register window.
24380
24381@item tui reg next
24382Show the next register group. The list of register groups as well as
24383their order is target specific. The predefined register groups are the
24384following: @code{general}, @code{float}, @code{system}, @code{vector},
24385@code{all}, @code{save}, @code{restore}.
24386
24387@item tui reg system
24388Show the system registers in the register window.
24389
8e04817f
AC
24390@item update
24391@kindex update
24392Update the source window and the current execution point.
c906108c 24393
8e04817f
AC
24394@item winheight @var{name} +@var{count}
24395@itemx winheight @var{name} -@var{count}
24396@kindex winheight
24397Change the height of the window @var{name} by @var{count}
24398lines. Positive counts increase the height, while negative counts
24399decrease it.
2df3850c 24400
46ba6afa
BW
24401@item tabset @var{nchars}
24402@kindex tabset
c45da7e6 24403Set the width of tab stops to be @var{nchars} characters.
c906108c
SS
24404@end table
24405
8e04817f 24406@node TUI Configuration
79a6e687 24407@section TUI Configuration Variables
8e04817f 24408@cindex TUI configuration variables
c906108c 24409
46ba6afa 24410Several configuration variables control the appearance of TUI windows.
c906108c 24411
8e04817f
AC
24412@table @code
24413@item set tui border-kind @var{kind}
24414@kindex set tui border-kind
24415Select the border appearance for the source, assembly and register windows.
24416The possible values are the following:
24417@table @code
24418@item space
24419Use a space character to draw the border.
c906108c 24420
8e04817f 24421@item ascii
46ba6afa 24422Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 24423
8e04817f
AC
24424@item acs
24425Use the Alternate Character Set to draw the border. The border is
24426drawn using character line graphics if the terminal supports them.
8e04817f 24427@end table
c78b4128 24428
8e04817f
AC
24429@item set tui border-mode @var{mode}
24430@kindex set tui border-mode
46ba6afa
BW
24431@itemx set tui active-border-mode @var{mode}
24432@kindex set tui active-border-mode
24433Select the display attributes for the borders of the inactive windows
24434or the active window. The @var{mode} can be one of the following:
8e04817f
AC
24435@table @code
24436@item normal
24437Use normal attributes to display the border.
c906108c 24438
8e04817f
AC
24439@item standout
24440Use standout mode.
c906108c 24441
8e04817f
AC
24442@item reverse
24443Use reverse video mode.
c906108c 24444
8e04817f
AC
24445@item half
24446Use half bright mode.
c906108c 24447
8e04817f
AC
24448@item half-standout
24449Use half bright and standout mode.
c906108c 24450
8e04817f
AC
24451@item bold
24452Use extra bright or bold mode.
c78b4128 24453
8e04817f
AC
24454@item bold-standout
24455Use extra bright or bold and standout mode.
8e04817f 24456@end table
8e04817f 24457@end table
c78b4128 24458
8e04817f
AC
24459@node Emacs
24460@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 24461
8e04817f
AC
24462@cindex Emacs
24463@cindex @sc{gnu} Emacs
24464A special interface allows you to use @sc{gnu} Emacs to view (and
24465edit) the source files for the program you are debugging with
24466@value{GDBN}.
c906108c 24467
8e04817f
AC
24468To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
24469executable file you want to debug as an argument. This command starts
24470@value{GDBN} as a subprocess of Emacs, with input and output through a newly
24471created Emacs buffer.
24472@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 24473
5e252a2e 24474Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 24475things:
c906108c 24476
8e04817f
AC
24477@itemize @bullet
24478@item
5e252a2e
NR
24479All ``terminal'' input and output goes through an Emacs buffer, called
24480the GUD buffer.
c906108c 24481
8e04817f
AC
24482This applies both to @value{GDBN} commands and their output, and to the input
24483and output done by the program you are debugging.
bf0184be 24484
8e04817f
AC
24485This is useful because it means that you can copy the text of previous
24486commands and input them again; you can even use parts of the output
24487in this way.
bf0184be 24488
8e04817f
AC
24489All the facilities of Emacs' Shell mode are available for interacting
24490with your program. In particular, you can send signals the usual
24491way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
24492stop.
bf0184be
ND
24493
24494@item
8e04817f 24495@value{GDBN} displays source code through Emacs.
bf0184be 24496
8e04817f
AC
24497Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
24498source file for that frame and puts an arrow (@samp{=>}) at the
24499left margin of the current line. Emacs uses a separate buffer for
24500source display, and splits the screen to show both your @value{GDBN} session
24501and the source.
bf0184be 24502
8e04817f
AC
24503Explicit @value{GDBN} @code{list} or search commands still produce output as
24504usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
24505@end itemize
24506
24507We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
24508a graphical mode, enabled by default, which provides further buffers
24509that can control the execution and describe the state of your program.
24510@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 24511
64fabec2
AC
24512If you specify an absolute file name when prompted for the @kbd{M-x
24513gdb} argument, then Emacs sets your current working directory to where
24514your program resides. If you only specify the file name, then Emacs
7a9dd1b2 24515sets your current working directory to the directory associated
64fabec2
AC
24516with the previous buffer. In this case, @value{GDBN} may find your
24517program by searching your environment's @code{PATH} variable, but on
24518some operating systems it might not find the source. So, although the
24519@value{GDBN} input and output session proceeds normally, the auxiliary
24520buffer does not display the current source and line of execution.
24521
24522The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
24523line of the GUD buffer and this serves as a default for the commands
24524that specify files for @value{GDBN} to operate on. @xref{Files,
24525,Commands to Specify Files}.
64fabec2
AC
24526
24527By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
24528need to call @value{GDBN} by a different name (for example, if you
24529keep several configurations around, with different names) you can
24530customize the Emacs variable @code{gud-gdb-command-name} to run the
24531one you want.
8e04817f 24532
5e252a2e 24533In the GUD buffer, you can use these special Emacs commands in
8e04817f 24534addition to the standard Shell mode commands:
c906108c 24535
8e04817f
AC
24536@table @kbd
24537@item C-h m
5e252a2e 24538Describe the features of Emacs' GUD Mode.
c906108c 24539
64fabec2 24540@item C-c C-s
8e04817f
AC
24541Execute to another source line, like the @value{GDBN} @code{step} command; also
24542update the display window to show the current file and location.
c906108c 24543
64fabec2 24544@item C-c C-n
8e04817f
AC
24545Execute to next source line in this function, skipping all function
24546calls, like the @value{GDBN} @code{next} command. Then update the display window
24547to show the current file and location.
c906108c 24548
64fabec2 24549@item C-c C-i
8e04817f
AC
24550Execute one instruction, like the @value{GDBN} @code{stepi} command; update
24551display window accordingly.
c906108c 24552
8e04817f
AC
24553@item C-c C-f
24554Execute until exit from the selected stack frame, like the @value{GDBN}
24555@code{finish} command.
c906108c 24556
64fabec2 24557@item C-c C-r
8e04817f
AC
24558Continue execution of your program, like the @value{GDBN} @code{continue}
24559command.
b433d00b 24560
64fabec2 24561@item C-c <
8e04817f
AC
24562Go up the number of frames indicated by the numeric argument
24563(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
24564like the @value{GDBN} @code{up} command.
b433d00b 24565
64fabec2 24566@item C-c >
8e04817f
AC
24567Go down the number of frames indicated by the numeric argument, like the
24568@value{GDBN} @code{down} command.
8e04817f 24569@end table
c906108c 24570
7f9087cb 24571In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 24572tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 24573
5e252a2e
NR
24574In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
24575separate frame which shows a backtrace when the GUD buffer is current.
24576Move point to any frame in the stack and type @key{RET} to make it
24577become the current frame and display the associated source in the
24578source buffer. Alternatively, click @kbd{Mouse-2} to make the
24579selected frame become the current one. In graphical mode, the
24580speedbar displays watch expressions.
64fabec2 24581
8e04817f
AC
24582If you accidentally delete the source-display buffer, an easy way to get
24583it back is to type the command @code{f} in the @value{GDBN} buffer, to
24584request a frame display; when you run under Emacs, this recreates
24585the source buffer if necessary to show you the context of the current
24586frame.
c906108c 24587
8e04817f
AC
24588The source files displayed in Emacs are in ordinary Emacs buffers
24589which are visiting the source files in the usual way. You can edit
24590the files with these buffers if you wish; but keep in mind that @value{GDBN}
24591communicates with Emacs in terms of line numbers. If you add or
24592delete lines from the text, the line numbers that @value{GDBN} knows cease
24593to correspond properly with the code.
b383017d 24594
5e252a2e
NR
24595A more detailed description of Emacs' interaction with @value{GDBN} is
24596given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
24597Emacs Manual}).
c906108c 24598
922fbb7b
AC
24599@node GDB/MI
24600@chapter The @sc{gdb/mi} Interface
24601
24602@unnumberedsec Function and Purpose
24603
24604@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
24605@sc{gdb/mi} is a line based machine oriented text interface to
24606@value{GDBN} and is activated by specifying using the
24607@option{--interpreter} command line option (@pxref{Mode Options}). It
24608is specifically intended to support the development of systems which
24609use the debugger as just one small component of a larger system.
922fbb7b
AC
24610
24611This chapter is a specification of the @sc{gdb/mi} interface. It is written
24612in the form of a reference manual.
24613
24614Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
24615features described below are incomplete and subject to change
24616(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
24617
24618@unnumberedsec Notation and Terminology
24619
24620@cindex notational conventions, for @sc{gdb/mi}
24621This chapter uses the following notation:
24622
24623@itemize @bullet
24624@item
24625@code{|} separates two alternatives.
24626
24627@item
24628@code{[ @var{something} ]} indicates that @var{something} is optional:
24629it may or may not be given.
24630
24631@item
24632@code{( @var{group} )*} means that @var{group} inside the parentheses
24633may repeat zero or more times.
24634
24635@item
24636@code{( @var{group} )+} means that @var{group} inside the parentheses
24637may repeat one or more times.
24638
24639@item
24640@code{"@var{string}"} means a literal @var{string}.
24641@end itemize
24642
24643@ignore
24644@heading Dependencies
24645@end ignore
24646
922fbb7b 24647@menu
c3b108f7 24648* GDB/MI General Design::
922fbb7b
AC
24649* GDB/MI Command Syntax::
24650* GDB/MI Compatibility with CLI::
af6eff6f 24651* GDB/MI Development and Front Ends::
922fbb7b 24652* GDB/MI Output Records::
ef21caaf 24653* GDB/MI Simple Examples::
922fbb7b 24654* GDB/MI Command Description Format::
ef21caaf 24655* GDB/MI Breakpoint Commands::
3fa7bf06 24656* GDB/MI Catchpoint Commands::
a2c02241
NR
24657* GDB/MI Program Context::
24658* GDB/MI Thread Commands::
5d77fe44 24659* GDB/MI Ada Tasking Commands::
a2c02241
NR
24660* GDB/MI Program Execution::
24661* GDB/MI Stack Manipulation::
24662* GDB/MI Variable Objects::
922fbb7b 24663* GDB/MI Data Manipulation::
a2c02241
NR
24664* GDB/MI Tracepoint Commands::
24665* GDB/MI Symbol Query::
351ff01a 24666* GDB/MI File Commands::
922fbb7b
AC
24667@ignore
24668* GDB/MI Kod Commands::
24669* GDB/MI Memory Overlay Commands::
24670* GDB/MI Signal Handling Commands::
24671@end ignore
922fbb7b 24672* GDB/MI Target Manipulation::
a6b151f1 24673* GDB/MI File Transfer Commands::
58d06528 24674* GDB/MI Ada Exceptions Commands::
d192b373 24675* GDB/MI Support Commands::
ef21caaf 24676* GDB/MI Miscellaneous Commands::
922fbb7b
AC
24677@end menu
24678
c3b108f7
VP
24679@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24680@node GDB/MI General Design
24681@section @sc{gdb/mi} General Design
24682@cindex GDB/MI General Design
24683
24684Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
24685parts---commands sent to @value{GDBN}, responses to those commands
24686and notifications. Each command results in exactly one response,
24687indicating either successful completion of the command, or an error.
24688For the commands that do not resume the target, the response contains the
24689requested information. For the commands that resume the target, the
24690response only indicates whether the target was successfully resumed.
24691Notifications is the mechanism for reporting changes in the state of the
24692target, or in @value{GDBN} state, that cannot conveniently be associated with
24693a command and reported as part of that command response.
24694
24695The important examples of notifications are:
24696@itemize @bullet
24697
24698@item
24699Exec notifications. These are used to report changes in
24700target state---when a target is resumed, or stopped. It would not
24701be feasible to include this information in response of resuming
24702commands, because one resume commands can result in multiple events in
24703different threads. Also, quite some time may pass before any event
24704happens in the target, while a frontend needs to know whether the resuming
24705command itself was successfully executed.
24706
24707@item
24708Console output, and status notifications. Console output
24709notifications are used to report output of CLI commands, as well as
24710diagnostics for other commands. Status notifications are used to
24711report the progress of a long-running operation. Naturally, including
24712this information in command response would mean no output is produced
24713until the command is finished, which is undesirable.
24714
24715@item
24716General notifications. Commands may have various side effects on
24717the @value{GDBN} or target state beyond their official purpose. For example,
24718a command may change the selected thread. Although such changes can
24719be included in command response, using notification allows for more
24720orthogonal frontend design.
24721
24722@end itemize
24723
24724There's no guarantee that whenever an MI command reports an error,
24725@value{GDBN} or the target are in any specific state, and especially,
24726the state is not reverted to the state before the MI command was
24727processed. Therefore, whenever an MI command results in an error,
24728we recommend that the frontend refreshes all the information shown in
24729the user interface.
24730
508094de
NR
24731
24732@menu
24733* Context management::
24734* Asynchronous and non-stop modes::
24735* Thread groups::
24736@end menu
24737
24738@node Context management
c3b108f7
VP
24739@subsection Context management
24740
403cb6b1
JB
24741@subsubsection Threads and Frames
24742
c3b108f7
VP
24743In most cases when @value{GDBN} accesses the target, this access is
24744done in context of a specific thread and frame (@pxref{Frames}).
24745Often, even when accessing global data, the target requires that a thread
24746be specified. The CLI interface maintains the selected thread and frame,
24747and supplies them to target on each command. This is convenient,
24748because a command line user would not want to specify that information
24749explicitly on each command, and because user interacts with
24750@value{GDBN} via a single terminal, so no confusion is possible as
24751to what thread and frame are the current ones.
24752
24753In the case of MI, the concept of selected thread and frame is less
24754useful. First, a frontend can easily remember this information
24755itself. Second, a graphical frontend can have more than one window,
24756each one used for debugging a different thread, and the frontend might
24757want to access additional threads for internal purposes. This
24758increases the risk that by relying on implicitly selected thread, the
24759frontend may be operating on a wrong one. Therefore, each MI command
24760should explicitly specify which thread and frame to operate on. To
24761make it possible, each MI command accepts the @samp{--thread} and
24762@samp{--frame} options, the value to each is @value{GDBN} identifier
24763for thread and frame to operate on.
24764
24765Usually, each top-level window in a frontend allows the user to select
24766a thread and a frame, and remembers the user selection for further
24767operations. However, in some cases @value{GDBN} may suggest that the
24768current thread be changed. For example, when stopping on a breakpoint
24769it is reasonable to switch to the thread where breakpoint is hit. For
24770another example, if the user issues the CLI @samp{thread} command via
24771the frontend, it is desirable to change the frontend's selected thread to the
24772one specified by user. @value{GDBN} communicates the suggestion to
24773change current thread using the @samp{=thread-selected} notification.
24774No such notification is available for the selected frame at the moment.
24775
24776Note that historically, MI shares the selected thread with CLI, so
24777frontends used the @code{-thread-select} to execute commands in the
24778right context. However, getting this to work right is cumbersome. The
24779simplest way is for frontend to emit @code{-thread-select} command
24780before every command. This doubles the number of commands that need
24781to be sent. The alternative approach is to suppress @code{-thread-select}
24782if the selected thread in @value{GDBN} is supposed to be identical to the
24783thread the frontend wants to operate on. However, getting this
24784optimization right can be tricky. In particular, if the frontend
24785sends several commands to @value{GDBN}, and one of the commands changes the
24786selected thread, then the behaviour of subsequent commands will
24787change. So, a frontend should either wait for response from such
24788problematic commands, or explicitly add @code{-thread-select} for
24789all subsequent commands. No frontend is known to do this exactly
24790right, so it is suggested to just always pass the @samp{--thread} and
24791@samp{--frame} options.
24792
403cb6b1
JB
24793@subsubsection Language
24794
24795The execution of several commands depends on which language is selected.
24796By default, the current language (@pxref{show language}) is used.
24797But for commands known to be language-sensitive, it is recommended
24798to use the @samp{--language} option. This option takes one argument,
24799which is the name of the language to use while executing the command.
24800For instance:
24801
24802@smallexample
24803-data-evaluate-expression --language c "sizeof (void*)"
24804^done,value="4"
24805(gdb)
24806@end smallexample
24807
24808The valid language names are the same names accepted by the
24809@samp{set language} command (@pxref{Manually}), excluding @samp{auto},
24810@samp{local} or @samp{unknown}.
24811
508094de 24812@node Asynchronous and non-stop modes
c3b108f7
VP
24813@subsection Asynchronous command execution and non-stop mode
24814
24815On some targets, @value{GDBN} is capable of processing MI commands
24816even while the target is running. This is called @dfn{asynchronous
24817command execution} (@pxref{Background Execution}). The frontend may
24818specify a preferrence for asynchronous execution using the
24819@code{-gdb-set target-async 1} command, which should be emitted before
24820either running the executable or attaching to the target. After the
24821frontend has started the executable or attached to the target, it can
24822find if asynchronous execution is enabled using the
24823@code{-list-target-features} command.
24824
24825Even if @value{GDBN} can accept a command while target is running,
24826many commands that access the target do not work when the target is
24827running. Therefore, asynchronous command execution is most useful
24828when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
24829it is possible to examine the state of one thread, while other threads
24830are running.
24831
24832When a given thread is running, MI commands that try to access the
24833target in the context of that thread may not work, or may work only on
24834some targets. In particular, commands that try to operate on thread's
24835stack will not work, on any target. Commands that read memory, or
24836modify breakpoints, may work or not work, depending on the target. Note
24837that even commands that operate on global state, such as @code{print},
24838@code{set}, and breakpoint commands, still access the target in the
24839context of a specific thread, so frontend should try to find a
24840stopped thread and perform the operation on that thread (using the
24841@samp{--thread} option).
24842
24843Which commands will work in the context of a running thread is
24844highly target dependent. However, the two commands
24845@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
24846to find the state of a thread, will always work.
24847
508094de 24848@node Thread groups
c3b108f7
VP
24849@subsection Thread groups
24850@value{GDBN} may be used to debug several processes at the same time.
24851On some platfroms, @value{GDBN} may support debugging of several
24852hardware systems, each one having several cores with several different
24853processes running on each core. This section describes the MI
24854mechanism to support such debugging scenarios.
24855
24856The key observation is that regardless of the structure of the
24857target, MI can have a global list of threads, because most commands that
24858accept the @samp{--thread} option do not need to know what process that
24859thread belongs to. Therefore, it is not necessary to introduce
24860neither additional @samp{--process} option, nor an notion of the
24861current process in the MI interface. The only strictly new feature
24862that is required is the ability to find how the threads are grouped
24863into processes.
24864
24865To allow the user to discover such grouping, and to support arbitrary
24866hierarchy of machines/cores/processes, MI introduces the concept of a
24867@dfn{thread group}. Thread group is a collection of threads and other
24868thread groups. A thread group always has a string identifier, a type,
24869and may have additional attributes specific to the type. A new
24870command, @code{-list-thread-groups}, returns the list of top-level
24871thread groups, which correspond to processes that @value{GDBN} is
24872debugging at the moment. By passing an identifier of a thread group
24873to the @code{-list-thread-groups} command, it is possible to obtain
24874the members of specific thread group.
24875
24876To allow the user to easily discover processes, and other objects, he
24877wishes to debug, a concept of @dfn{available thread group} is
24878introduced. Available thread group is an thread group that
24879@value{GDBN} is not debugging, but that can be attached to, using the
24880@code{-target-attach} command. The list of available top-level thread
24881groups can be obtained using @samp{-list-thread-groups --available}.
24882In general, the content of a thread group may be only retrieved only
24883after attaching to that thread group.
24884
a79b8f6e
VP
24885Thread groups are related to inferiors (@pxref{Inferiors and
24886Programs}). Each inferior corresponds to a thread group of a special
24887type @samp{process}, and some additional operations are permitted on
24888such thread groups.
24889
922fbb7b
AC
24890@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24891@node GDB/MI Command Syntax
24892@section @sc{gdb/mi} Command Syntax
24893
24894@menu
24895* GDB/MI Input Syntax::
24896* GDB/MI Output Syntax::
922fbb7b
AC
24897@end menu
24898
24899@node GDB/MI Input Syntax
24900@subsection @sc{gdb/mi} Input Syntax
24901
24902@cindex input syntax for @sc{gdb/mi}
24903@cindex @sc{gdb/mi}, input syntax
24904@table @code
24905@item @var{command} @expansion{}
24906@code{@var{cli-command} | @var{mi-command}}
24907
24908@item @var{cli-command} @expansion{}
24909@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
24910@var{cli-command} is any existing @value{GDBN} CLI command.
24911
24912@item @var{mi-command} @expansion{}
24913@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
24914@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
24915
24916@item @var{token} @expansion{}
24917"any sequence of digits"
24918
24919@item @var{option} @expansion{}
24920@code{"-" @var{parameter} [ " " @var{parameter} ]}
24921
24922@item @var{parameter} @expansion{}
24923@code{@var{non-blank-sequence} | @var{c-string}}
24924
24925@item @var{operation} @expansion{}
24926@emph{any of the operations described in this chapter}
24927
24928@item @var{non-blank-sequence} @expansion{}
24929@emph{anything, provided it doesn't contain special characters such as
24930"-", @var{nl}, """ and of course " "}
24931
24932@item @var{c-string} @expansion{}
24933@code{""" @var{seven-bit-iso-c-string-content} """}
24934
24935@item @var{nl} @expansion{}
24936@code{CR | CR-LF}
24937@end table
24938
24939@noindent
24940Notes:
24941
24942@itemize @bullet
24943@item
24944The CLI commands are still handled by the @sc{mi} interpreter; their
24945output is described below.
24946
24947@item
24948The @code{@var{token}}, when present, is passed back when the command
24949finishes.
24950
24951@item
24952Some @sc{mi} commands accept optional arguments as part of the parameter
24953list. Each option is identified by a leading @samp{-} (dash) and may be
24954followed by an optional argument parameter. Options occur first in the
24955parameter list and can be delimited from normal parameters using
24956@samp{--} (this is useful when some parameters begin with a dash).
24957@end itemize
24958
24959Pragmatics:
24960
24961@itemize @bullet
24962@item
24963We want easy access to the existing CLI syntax (for debugging).
24964
24965@item
24966We want it to be easy to spot a @sc{mi} operation.
24967@end itemize
24968
24969@node GDB/MI Output Syntax
24970@subsection @sc{gdb/mi} Output Syntax
24971
24972@cindex output syntax of @sc{gdb/mi}
24973@cindex @sc{gdb/mi}, output syntax
24974The output from @sc{gdb/mi} consists of zero or more out-of-band records
24975followed, optionally, by a single result record. This result record
24976is for the most recent command. The sequence of output records is
594fe323 24977terminated by @samp{(gdb)}.
922fbb7b
AC
24978
24979If an input command was prefixed with a @code{@var{token}} then the
24980corresponding output for that command will also be prefixed by that same
24981@var{token}.
24982
24983@table @code
24984@item @var{output} @expansion{}
594fe323 24985@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
24986
24987@item @var{result-record} @expansion{}
24988@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
24989
24990@item @var{out-of-band-record} @expansion{}
24991@code{@var{async-record} | @var{stream-record}}
24992
24993@item @var{async-record} @expansion{}
24994@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
24995
24996@item @var{exec-async-output} @expansion{}
dcf106f3 24997@code{[ @var{token} ] "*" @var{async-output nl}}
922fbb7b
AC
24998
24999@item @var{status-async-output} @expansion{}
dcf106f3 25000@code{[ @var{token} ] "+" @var{async-output nl}}
922fbb7b
AC
25001
25002@item @var{notify-async-output} @expansion{}
dcf106f3 25003@code{[ @var{token} ] "=" @var{async-output nl}}
922fbb7b
AC
25004
25005@item @var{async-output} @expansion{}
dcf106f3 25006@code{@var{async-class} ( "," @var{result} )*}
922fbb7b
AC
25007
25008@item @var{result-class} @expansion{}
25009@code{"done" | "running" | "connected" | "error" | "exit"}
25010
25011@item @var{async-class} @expansion{}
25012@code{"stopped" | @var{others}} (where @var{others} will be added
25013depending on the needs---this is still in development).
25014
25015@item @var{result} @expansion{}
25016@code{ @var{variable} "=" @var{value}}
25017
25018@item @var{variable} @expansion{}
25019@code{ @var{string} }
25020
25021@item @var{value} @expansion{}
25022@code{ @var{const} | @var{tuple} | @var{list} }
25023
25024@item @var{const} @expansion{}
25025@code{@var{c-string}}
25026
25027@item @var{tuple} @expansion{}
25028@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
25029
25030@item @var{list} @expansion{}
25031@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
25032@var{result} ( "," @var{result} )* "]" }
25033
25034@item @var{stream-record} @expansion{}
25035@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
25036
25037@item @var{console-stream-output} @expansion{}
dcf106f3 25038@code{"~" @var{c-string nl}}
922fbb7b
AC
25039
25040@item @var{target-stream-output} @expansion{}
dcf106f3 25041@code{"@@" @var{c-string nl}}
922fbb7b
AC
25042
25043@item @var{log-stream-output} @expansion{}
dcf106f3 25044@code{"&" @var{c-string nl}}
922fbb7b
AC
25045
25046@item @var{nl} @expansion{}
25047@code{CR | CR-LF}
25048
25049@item @var{token} @expansion{}
25050@emph{any sequence of digits}.
25051@end table
25052
25053@noindent
25054Notes:
25055
25056@itemize @bullet
25057@item
25058All output sequences end in a single line containing a period.
25059
25060@item
721c02de
VP
25061The @code{@var{token}} is from the corresponding request. Note that
25062for all async output, while the token is allowed by the grammar and
25063may be output by future versions of @value{GDBN} for select async
25064output messages, it is generally omitted. Frontends should treat
25065all async output as reporting general changes in the state of the
25066target and there should be no need to associate async output to any
25067prior command.
922fbb7b
AC
25068
25069@item
25070@cindex status output in @sc{gdb/mi}
25071@var{status-async-output} contains on-going status information about the
25072progress of a slow operation. It can be discarded. All status output is
25073prefixed by @samp{+}.
25074
25075@item
25076@cindex async output in @sc{gdb/mi}
25077@var{exec-async-output} contains asynchronous state change on the target
25078(stopped, started, disappeared). All async output is prefixed by
25079@samp{*}.
25080
25081@item
25082@cindex notify output in @sc{gdb/mi}
25083@var{notify-async-output} contains supplementary information that the
25084client should handle (e.g., a new breakpoint information). All notify
25085output is prefixed by @samp{=}.
25086
25087@item
25088@cindex console output in @sc{gdb/mi}
25089@var{console-stream-output} is output that should be displayed as is in the
25090console. It is the textual response to a CLI command. All the console
25091output is prefixed by @samp{~}.
25092
25093@item
25094@cindex target output in @sc{gdb/mi}
25095@var{target-stream-output} is the output produced by the target program.
25096All the target output is prefixed by @samp{@@}.
25097
25098@item
25099@cindex log output in @sc{gdb/mi}
25100@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
25101instance messages that should be displayed as part of an error log. All
25102the log output is prefixed by @samp{&}.
25103
25104@item
25105@cindex list output in @sc{gdb/mi}
25106New @sc{gdb/mi} commands should only output @var{lists} containing
25107@var{values}.
25108
25109
25110@end itemize
25111
25112@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
25113details about the various output records.
25114
922fbb7b
AC
25115@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25116@node GDB/MI Compatibility with CLI
25117@section @sc{gdb/mi} Compatibility with CLI
25118
25119@cindex compatibility, @sc{gdb/mi} and CLI
25120@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 25121
a2c02241
NR
25122For the developers convenience CLI commands can be entered directly,
25123but there may be some unexpected behaviour. For example, commands
25124that query the user will behave as if the user replied yes, breakpoint
25125command lists are not executed and some CLI commands, such as
25126@code{if}, @code{when} and @code{define}, prompt for further input with
25127@samp{>}, which is not valid MI output.
ef21caaf
NR
25128
25129This feature may be removed at some stage in the future and it is
a2c02241
NR
25130recommended that front ends use the @code{-interpreter-exec} command
25131(@pxref{-interpreter-exec}).
922fbb7b 25132
af6eff6f
NR
25133@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25134@node GDB/MI Development and Front Ends
25135@section @sc{gdb/mi} Development and Front Ends
25136@cindex @sc{gdb/mi} development
25137
25138The application which takes the MI output and presents the state of the
25139program being debugged to the user is called a @dfn{front end}.
25140
25141Although @sc{gdb/mi} is still incomplete, it is currently being used
25142by a variety of front ends to @value{GDBN}. This makes it difficult
25143to introduce new functionality without breaking existing usage. This
25144section tries to minimize the problems by describing how the protocol
25145might change.
25146
25147Some changes in MI need not break a carefully designed front end, and
25148for these the MI version will remain unchanged. The following is a
25149list of changes that may occur within one level, so front ends should
25150parse MI output in a way that can handle them:
25151
25152@itemize @bullet
25153@item
25154New MI commands may be added.
25155
25156@item
25157New fields may be added to the output of any MI command.
25158
36ece8b3
NR
25159@item
25160The range of values for fields with specified values, e.g.,
9f708cb2 25161@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 25162
af6eff6f
NR
25163@c The format of field's content e.g type prefix, may change so parse it
25164@c at your own risk. Yes, in general?
25165
25166@c The order of fields may change? Shouldn't really matter but it might
25167@c resolve inconsistencies.
25168@end itemize
25169
25170If the changes are likely to break front ends, the MI version level
25171will be increased by one. This will allow the front end to parse the
25172output according to the MI version. Apart from mi0, new versions of
25173@value{GDBN} will not support old versions of MI and it will be the
25174responsibility of the front end to work with the new one.
25175
25176@c Starting with mi3, add a new command -mi-version that prints the MI
25177@c version?
25178
25179The best way to avoid unexpected changes in MI that might break your front
25180end is to make your project known to @value{GDBN} developers and
7a9a6b69 25181follow development on @email{gdb@@sourceware.org} and
fa0f268d 25182@email{gdb-patches@@sourceware.org}.
af6eff6f
NR
25183@cindex mailing lists
25184
922fbb7b
AC
25185@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25186@node GDB/MI Output Records
25187@section @sc{gdb/mi} Output Records
25188
25189@menu
25190* GDB/MI Result Records::
25191* GDB/MI Stream Records::
82f68b1c 25192* GDB/MI Async Records::
54516a0b 25193* GDB/MI Breakpoint Information::
c3b108f7 25194* GDB/MI Frame Information::
dc146f7c 25195* GDB/MI Thread Information::
4368ebeb 25196* GDB/MI Ada Exception Information::
922fbb7b
AC
25197@end menu
25198
25199@node GDB/MI Result Records
25200@subsection @sc{gdb/mi} Result Records
25201
25202@cindex result records in @sc{gdb/mi}
25203@cindex @sc{gdb/mi}, result records
25204In addition to a number of out-of-band notifications, the response to a
25205@sc{gdb/mi} command includes one of the following result indications:
25206
25207@table @code
25208@findex ^done
25209@item "^done" [ "," @var{results} ]
25210The synchronous operation was successful, @code{@var{results}} are the return
25211values.
25212
25213@item "^running"
25214@findex ^running
8e9c5e02
VP
25215This result record is equivalent to @samp{^done}. Historically, it
25216was output instead of @samp{^done} if the command has resumed the
25217target. This behaviour is maintained for backward compatibility, but
25218all frontends should treat @samp{^done} and @samp{^running}
25219identically and rely on the @samp{*running} output record to determine
25220which threads are resumed.
922fbb7b 25221
ef21caaf
NR
25222@item "^connected"
25223@findex ^connected
3f94c067 25224@value{GDBN} has connected to a remote target.
ef21caaf 25225
2ea126fa 25226@item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
922fbb7b 25227@findex ^error
2ea126fa
JB
25228The operation failed. The @code{msg=@var{c-string}} variable contains
25229the corresponding error message.
25230
25231If present, the @code{code=@var{c-string}} variable provides an error
25232code on which consumers can rely on to detect the corresponding
25233error condition. At present, only one error code is defined:
25234
25235@table @samp
25236@item "undefined-command"
25237Indicates that the command causing the error does not exist.
25238@end table
ef21caaf
NR
25239
25240@item "^exit"
25241@findex ^exit
3f94c067 25242@value{GDBN} has terminated.
ef21caaf 25243
922fbb7b
AC
25244@end table
25245
25246@node GDB/MI Stream Records
25247@subsection @sc{gdb/mi} Stream Records
25248
25249@cindex @sc{gdb/mi}, stream records
25250@cindex stream records in @sc{gdb/mi}
25251@value{GDBN} internally maintains a number of output streams: the console, the
25252target, and the log. The output intended for each of these streams is
25253funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
25254
25255Each stream record begins with a unique @dfn{prefix character} which
25256identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
25257Syntax}). In addition to the prefix, each stream record contains a
25258@code{@var{string-output}}. This is either raw text (with an implicit new
25259line) or a quoted C string (which does not contain an implicit newline).
25260
25261@table @code
25262@item "~" @var{string-output}
25263The console output stream contains text that should be displayed in the
25264CLI console window. It contains the textual responses to CLI commands.
25265
25266@item "@@" @var{string-output}
25267The target output stream contains any textual output from the running
ef21caaf
NR
25268target. This is only present when GDB's event loop is truly
25269asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
25270
25271@item "&" @var{string-output}
25272The log stream contains debugging messages being produced by @value{GDBN}'s
25273internals.
25274@end table
25275
82f68b1c
VP
25276@node GDB/MI Async Records
25277@subsection @sc{gdb/mi} Async Records
922fbb7b 25278
82f68b1c
VP
25279@cindex async records in @sc{gdb/mi}
25280@cindex @sc{gdb/mi}, async records
25281@dfn{Async} records are used to notify the @sc{gdb/mi} client of
922fbb7b 25282additional changes that have occurred. Those changes can either be a
82f68b1c 25283consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
922fbb7b
AC
25284target activity (e.g., target stopped).
25285
8eb41542 25286The following is the list of possible async records:
922fbb7b
AC
25287
25288@table @code
034dad6f 25289
e1ac3328
VP
25290@item *running,thread-id="@var{thread}"
25291The target is now running. The @var{thread} field tells which
25292specific thread is now running, and can be @samp{all} if all threads
25293are running. The frontend should assume that no interaction with a
25294running thread is possible after this notification is produced.
25295The frontend should not assume that this notification is output
25296only once for any command. @value{GDBN} may emit this notification
25297several times, either for different threads, because it cannot resume
25298all threads together, or even for a single thread, if the thread must
25299be stepped though some code before letting it run freely.
25300
dc146f7c 25301@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
82f68b1c
VP
25302The target has stopped. The @var{reason} field can have one of the
25303following values:
034dad6f
BR
25304
25305@table @code
25306@item breakpoint-hit
25307A breakpoint was reached.
25308@item watchpoint-trigger
25309A watchpoint was triggered.
25310@item read-watchpoint-trigger
25311A read watchpoint was triggered.
25312@item access-watchpoint-trigger
25313An access watchpoint was triggered.
25314@item function-finished
25315An -exec-finish or similar CLI command was accomplished.
25316@item location-reached
25317An -exec-until or similar CLI command was accomplished.
25318@item watchpoint-scope
25319A watchpoint has gone out of scope.
25320@item end-stepping-range
25321An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
25322similar CLI command was accomplished.
25323@item exited-signalled
25324The inferior exited because of a signal.
25325@item exited
25326The inferior exited.
25327@item exited-normally
25328The inferior exited normally.
25329@item signal-received
25330A signal was received by the inferior.
36dfb11c
TT
25331@item solib-event
25332The inferior has stopped due to a library being loaded or unloaded.
edcc5120
TT
25333This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
25334set or when a @code{catch load} or @code{catch unload} catchpoint is
25335in use (@pxref{Set Catchpoints}).
36dfb11c
TT
25336@item fork
25337The inferior has forked. This is reported when @code{catch fork}
25338(@pxref{Set Catchpoints}) has been used.
25339@item vfork
25340The inferior has vforked. This is reported in when @code{catch vfork}
25341(@pxref{Set Catchpoints}) has been used.
25342@item syscall-entry
25343The inferior entered a system call. This is reported when @code{catch
25344syscall} (@pxref{Set Catchpoints}) has been used.
25345@item syscall-entry
25346The inferior returned from a system call. This is reported when
25347@code{catch syscall} (@pxref{Set Catchpoints}) has been used.
25348@item exec
25349The inferior called @code{exec}. This is reported when @code{catch exec}
25350(@pxref{Set Catchpoints}) has been used.
922fbb7b
AC
25351@end table
25352
c3b108f7
VP
25353The @var{id} field identifies the thread that directly caused the stop
25354-- for example by hitting a breakpoint. Depending on whether all-stop
25355mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
25356stop all threads, or only the thread that directly triggered the stop.
25357If all threads are stopped, the @var{stopped} field will have the
25358value of @code{"all"}. Otherwise, the value of the @var{stopped}
25359field will be a list of thread identifiers. Presently, this list will
25360always include a single thread, but frontend should be prepared to see
dc146f7c
VP
25361several threads in the list. The @var{core} field reports the
25362processor core on which the stop event has happened. This field may be absent
25363if such information is not available.
c3b108f7 25364
a79b8f6e
VP
25365@item =thread-group-added,id="@var{id}"
25366@itemx =thread-group-removed,id="@var{id}"
25367A thread group was either added or removed. The @var{id} field
25368contains the @value{GDBN} identifier of the thread group. When a thread
25369group is added, it generally might not be associated with a running
25370process. When a thread group is removed, its id becomes invalid and
25371cannot be used in any way.
25372
25373@item =thread-group-started,id="@var{id}",pid="@var{pid}"
25374A thread group became associated with a running program,
25375either because the program was just started or the thread group
25376was attached to a program. The @var{id} field contains the
25377@value{GDBN} identifier of the thread group. The @var{pid} field
25378contains process identifier, specific to the operating system.
25379
8cf64490 25380@item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
a79b8f6e
VP
25381A thread group is no longer associated with a running program,
25382either because the program has exited, or because it was detached
c3b108f7 25383from. The @var{id} field contains the @value{GDBN} identifier of the
8cf64490
TT
25384thread group. @var{code} is the exit code of the inferior; it exists
25385only when the inferior exited with some code.
c3b108f7
VP
25386
25387@item =thread-created,id="@var{id}",group-id="@var{gid}"
25388@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
82f68b1c 25389A thread either was created, or has exited. The @var{id} field
c3b108f7
VP
25390contains the @value{GDBN} identifier of the thread. The @var{gid}
25391field identifies the thread group this thread belongs to.
66bb093b
VP
25392
25393@item =thread-selected,id="@var{id}"
25394Informs that the selected thread was changed as result of the last
25395command. This notification is not emitted as result of @code{-thread-select}
25396command but is emitted whenever an MI command that is not documented
25397to change the selected thread actually changes it. In particular,
25398invoking, directly or indirectly (via user-defined command), the CLI
25399@code{thread} command, will generate this notification.
25400
25401We suggest that in response to this notification, front ends
25402highlight the selected thread and cause subsequent commands to apply to
25403that thread.
25404
c86cf029
VP
25405@item =library-loaded,...
25406Reports that a new library file was loaded by the program. This
25407notification has 4 fields---@var{id}, @var{target-name},
134eb42c 25408@var{host-name}, and @var{symbols-loaded}. The @var{id} field is an
c86cf029
VP
25409opaque identifier of the library. For remote debugging case,
25410@var{target-name} and @var{host-name} fields give the name of the
134eb42c
VP
25411library file on the target, and on the host respectively. For native
25412debugging, both those fields have the same value. The
f1cbe1d3
TT
25413@var{symbols-loaded} field is emitted only for backward compatibility
25414and should not be relied on to convey any useful information. The
25415@var{thread-group} field, if present, specifies the id of the thread
25416group in whose context the library was loaded. If the field is
25417absent, it means the library was loaded in the context of all present
25418thread groups.
c86cf029
VP
25419
25420@item =library-unloaded,...
134eb42c 25421Reports that a library was unloaded by the program. This notification
c86cf029 25422has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
a79b8f6e
VP
25423the same meaning as for the @code{=library-loaded} notification.
25424The @var{thread-group} field, if present, specifies the id of the
25425thread group in whose context the library was unloaded. If the field is
25426absent, it means the library was unloaded in the context of all present
25427thread groups.
c86cf029 25428
201b4506
YQ
25429@item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
25430@itemx =traceframe-changed,end
25431Reports that the trace frame was changed and its new number is
25432@var{tfnum}. The number of the tracepoint associated with this trace
25433frame is @var{tpnum}.
25434
134a2066 25435@item =tsv-created,name=@var{name},initial=@var{initial}
bb25a15c 25436Reports that the new trace state variable @var{name} is created with
134a2066 25437initial value @var{initial}.
bb25a15c
YQ
25438
25439@item =tsv-deleted,name=@var{name}
25440@itemx =tsv-deleted
25441Reports that the trace state variable @var{name} is deleted or all
25442trace state variables are deleted.
25443
134a2066
YQ
25444@item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
25445Reports that the trace state variable @var{name} is modified with
25446the initial value @var{initial}. The current value @var{current} of
25447trace state variable is optional and is reported if the current
25448value of trace state variable is known.
25449
8d3788bd
VP
25450@item =breakpoint-created,bkpt=@{...@}
25451@itemx =breakpoint-modified,bkpt=@{...@}
d9f08f52 25452@itemx =breakpoint-deleted,id=@var{number}
8d3788bd
VP
25453Reports that a breakpoint was created, modified, or deleted,
25454respectively. Only user-visible breakpoints are reported to the MI
25455user.
25456
25457The @var{bkpt} argument is of the same form as returned by the various
d9f08f52
YQ
25458breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
25459@var{number} is the ordinal number of the breakpoint.
8d3788bd
VP
25460
25461Note that if a breakpoint is emitted in the result record of a
25462command, then it will not also be emitted in an async record.
25463
82a90ccf
YQ
25464@item =record-started,thread-group="@var{id}"
25465@itemx =record-stopped,thread-group="@var{id}"
25466Execution log recording was either started or stopped on an
25467inferior. The @var{id} is the @value{GDBN} identifier of the thread
25468group corresponding to the affected inferior.
25469
5b9afe8a
YQ
25470@item =cmd-param-changed,param=@var{param},value=@var{value}
25471Reports that a parameter of the command @code{set @var{param}} is
25472changed to @var{value}. In the multi-word @code{set} command,
25473the @var{param} is the whole parameter list to @code{set} command.
25474For example, In command @code{set check type on}, @var{param}
25475is @code{check type} and @var{value} is @code{on}.
8de0566d
YQ
25476
25477@item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
25478Reports that bytes from @var{addr} to @var{data} + @var{len} were
25479written in an inferior. The @var{id} is the identifier of the
25480thread group corresponding to the affected inferior. The optional
25481@code{type="code"} part is reported if the memory written to holds
25482executable code.
82f68b1c
VP
25483@end table
25484
54516a0b
TT
25485@node GDB/MI Breakpoint Information
25486@subsection @sc{gdb/mi} Breakpoint Information
25487
25488When @value{GDBN} reports information about a breakpoint, a
25489tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
25490following fields:
25491
25492@table @code
25493@item number
25494The breakpoint number. For a breakpoint that represents one location
25495of a multi-location breakpoint, this will be a dotted pair, like
25496@samp{1.2}.
25497
25498@item type
25499The type of the breakpoint. For ordinary breakpoints this will be
25500@samp{breakpoint}, but many values are possible.
25501
8ac3646f
TT
25502@item catch-type
25503If the type of the breakpoint is @samp{catchpoint}, then this
25504indicates the exact type of catchpoint.
25505
54516a0b
TT
25506@item disp
25507This is the breakpoint disposition---either @samp{del}, meaning that
25508the breakpoint will be deleted at the next stop, or @samp{keep},
25509meaning that the breakpoint will not be deleted.
25510
25511@item enabled
25512This indicates whether the breakpoint is enabled, in which case the
25513value is @samp{y}, or disabled, in which case the value is @samp{n}.
25514Note that this is not the same as the field @code{enable}.
25515
25516@item addr
25517The address of the breakpoint. This may be a hexidecimal number,
25518giving the address; or the string @samp{<PENDING>}, for a pending
25519breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
25520multiple locations. This field will not be present if no address can
25521be determined. For example, a watchpoint does not have an address.
25522
25523@item func
25524If known, the function in which the breakpoint appears.
25525If not known, this field is not present.
25526
25527@item filename
25528The name of the source file which contains this function, if known.
25529If not known, this field is not present.
25530
25531@item fullname
25532The full file name of the source file which contains this function, if
25533known. If not known, this field is not present.
25534
25535@item line
25536The line number at which this breakpoint appears, if known.
25537If not known, this field is not present.
25538
25539@item at
25540If the source file is not known, this field may be provided. If
25541provided, this holds the address of the breakpoint, possibly followed
25542by a symbol name.
25543
25544@item pending
25545If this breakpoint is pending, this field is present and holds the
25546text used to set the breakpoint, as entered by the user.
25547
25548@item evaluated-by
25549Where this breakpoint's condition is evaluated, either @samp{host} or
25550@samp{target}.
25551
25552@item thread
25553If this is a thread-specific breakpoint, then this identifies the
25554thread in which the breakpoint can trigger.
25555
25556@item task
25557If this breakpoint is restricted to a particular Ada task, then this
25558field will hold the task identifier.
25559
25560@item cond
25561If the breakpoint is conditional, this is the condition expression.
25562
25563@item ignore
25564The ignore count of the breakpoint.
25565
25566@item enable
25567The enable count of the breakpoint.
25568
25569@item traceframe-usage
25570FIXME.
25571
25572@item static-tracepoint-marker-string-id
25573For a static tracepoint, the name of the static tracepoint marker.
25574
25575@item mask
25576For a masked watchpoint, this is the mask.
25577
25578@item pass
25579A tracepoint's pass count.
25580
25581@item original-location
25582The location of the breakpoint as originally specified by the user.
25583This field is optional.
25584
25585@item times
25586The number of times the breakpoint has been hit.
25587
25588@item installed
25589This field is only given for tracepoints. This is either @samp{y},
25590meaning that the tracepoint is installed, or @samp{n}, meaning that it
25591is not.
25592
25593@item what
25594Some extra data, the exact contents of which are type-dependent.
25595
25596@end table
25597
25598For example, here is what the output of @code{-break-insert}
25599(@pxref{GDB/MI Breakpoint Commands}) might be:
25600
25601@smallexample
25602-> -break-insert main
25603<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
25604 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
25605 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
25606 times="0"@}
54516a0b
TT
25607<- (gdb)
25608@end smallexample
25609
c3b108f7
VP
25610@node GDB/MI Frame Information
25611@subsection @sc{gdb/mi} Frame Information
25612
25613Response from many MI commands includes an information about stack
25614frame. This information is a tuple that may have the following
25615fields:
25616
25617@table @code
25618@item level
25619The level of the stack frame. The innermost frame has the level of
25620zero. This field is always present.
25621
25622@item func
25623The name of the function corresponding to the frame. This field may
25624be absent if @value{GDBN} is unable to determine the function name.
25625
25626@item addr
25627The code address for the frame. This field is always present.
25628
25629@item file
25630The name of the source files that correspond to the frame's code
25631address. This field may be absent.
25632
25633@item line
25634The source line corresponding to the frames' code address. This field
25635may be absent.
25636
25637@item from
25638The name of the binary file (either executable or shared library) the
25639corresponds to the frame's code address. This field may be absent.
25640
25641@end table
82f68b1c 25642
dc146f7c
VP
25643@node GDB/MI Thread Information
25644@subsection @sc{gdb/mi} Thread Information
25645
25646Whenever @value{GDBN} has to report an information about a thread, it
25647uses a tuple with the following fields:
25648
25649@table @code
25650@item id
25651The numeric id assigned to the thread by @value{GDBN}. This field is
25652always present.
25653
25654@item target-id
25655Target-specific string identifying the thread. This field is always present.
25656
25657@item details
25658Additional information about the thread provided by the target.
25659It is supposed to be human-readable and not interpreted by the
25660frontend. This field is optional.
25661
25662@item state
25663Either @samp{stopped} or @samp{running}, depending on whether the
25664thread is presently running. This field is always present.
25665
25666@item core
25667The value of this field is an integer number of the processor core the
25668thread was last seen on. This field is optional.
25669@end table
25670
956a9fb9
JB
25671@node GDB/MI Ada Exception Information
25672@subsection @sc{gdb/mi} Ada Exception Information
25673
25674Whenever a @code{*stopped} record is emitted because the program
25675stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
25676@value{GDBN} provides the name of the exception that was raised via
25677the @code{exception-name} field.
922fbb7b 25678
ef21caaf
NR
25679@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25680@node GDB/MI Simple Examples
25681@section Simple Examples of @sc{gdb/mi} Interaction
25682@cindex @sc{gdb/mi}, simple examples
25683
25684This subsection presents several simple examples of interaction using
25685the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
25686following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
25687the output received from @sc{gdb/mi}.
25688
d3e8051b 25689Note the line breaks shown in the examples are here only for
ef21caaf
NR
25690readability, they don't appear in the real output.
25691
79a6e687 25692@subheading Setting a Breakpoint
ef21caaf
NR
25693
25694Setting a breakpoint generates synchronous output which contains detailed
25695information of the breakpoint.
25696
25697@smallexample
25698-> -break-insert main
25699<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
25700 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
25701 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
25702 times="0"@}
ef21caaf
NR
25703<- (gdb)
25704@end smallexample
25705
25706@subheading Program Execution
25707
25708Program execution generates asynchronous records and MI gives the
25709reason that execution stopped.
25710
25711@smallexample
25712-> -exec-run
25713<- ^running
25714<- (gdb)
a47ec5fe 25715<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
ef21caaf
NR
25716 frame=@{addr="0x08048564",func="main",
25717 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
25718 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
25719<- (gdb)
25720-> -exec-continue
25721<- ^running
25722<- (gdb)
25723<- *stopped,reason="exited-normally"
25724<- (gdb)
25725@end smallexample
25726
3f94c067 25727@subheading Quitting @value{GDBN}
ef21caaf 25728
3f94c067 25729Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
25730
25731@smallexample
25732-> (gdb)
25733<- -gdb-exit
25734<- ^exit
25735@end smallexample
25736
a6b29f87
VP
25737Please note that @samp{^exit} is printed immediately, but it might
25738take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
25739performs necessary cleanups, including killing programs being debugged
25740or disconnecting from debug hardware, so the frontend should wait till
25741@value{GDBN} exits and should only forcibly kill @value{GDBN} if it
25742fails to exit in reasonable time.
25743
a2c02241 25744@subheading A Bad Command
ef21caaf
NR
25745
25746Here's what happens if you pass a non-existent command:
25747
25748@smallexample
25749-> -rubbish
25750<- ^error,msg="Undefined MI command: rubbish"
594fe323 25751<- (gdb)
ef21caaf
NR
25752@end smallexample
25753
25754
922fbb7b
AC
25755@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25756@node GDB/MI Command Description Format
25757@section @sc{gdb/mi} Command Description Format
25758
25759The remaining sections describe blocks of commands. Each block of
25760commands is laid out in a fashion similar to this section.
25761
922fbb7b
AC
25762@subheading Motivation
25763
25764The motivation for this collection of commands.
25765
25766@subheading Introduction
25767
25768A brief introduction to this collection of commands as a whole.
25769
25770@subheading Commands
25771
25772For each command in the block, the following is described:
25773
25774@subsubheading Synopsis
25775
25776@smallexample
25777 -command @var{args}@dots{}
25778@end smallexample
25779
922fbb7b
AC
25780@subsubheading Result
25781
265eeb58 25782@subsubheading @value{GDBN} Command
922fbb7b 25783
265eeb58 25784The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
25785
25786@subsubheading Example
25787
ef21caaf
NR
25788Example(s) formatted for readability. Some of the described commands have
25789not been implemented yet and these are labeled N.A.@: (not available).
25790
25791
922fbb7b 25792@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
25793@node GDB/MI Breakpoint Commands
25794@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
25795
25796@cindex breakpoint commands for @sc{gdb/mi}
25797@cindex @sc{gdb/mi}, breakpoint commands
25798This section documents @sc{gdb/mi} commands for manipulating
25799breakpoints.
25800
25801@subheading The @code{-break-after} Command
25802@findex -break-after
25803
25804@subsubheading Synopsis
25805
25806@smallexample
25807 -break-after @var{number} @var{count}
25808@end smallexample
25809
25810The breakpoint number @var{number} is not in effect until it has been
25811hit @var{count} times. To see how this is reflected in the output of
25812the @samp{-break-list} command, see the description of the
25813@samp{-break-list} command below.
25814
25815@subsubheading @value{GDBN} Command
25816
25817The corresponding @value{GDBN} command is @samp{ignore}.
25818
25819@subsubheading Example
25820
25821@smallexample
594fe323 25822(gdb)
922fbb7b 25823-break-insert main
a47ec5fe
AR
25824^done,bkpt=@{number="1",type="breakpoint",disp="keep",
25825enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
25826fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
25827times="0"@}
594fe323 25828(gdb)
922fbb7b
AC
25829-break-after 1 3
25830~
25831^done
594fe323 25832(gdb)
922fbb7b
AC
25833-break-list
25834^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
25835hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
25836@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
25837@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
25838@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
25839@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
25840@{width="40",alignment="2",col_name="what",colhdr="What"@}],
25841body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 25842addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 25843line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 25844(gdb)
922fbb7b
AC
25845@end smallexample
25846
25847@ignore
25848@subheading The @code{-break-catch} Command
25849@findex -break-catch
48cb2d85 25850@end ignore
922fbb7b
AC
25851
25852@subheading The @code{-break-commands} Command
25853@findex -break-commands
922fbb7b 25854
48cb2d85
VP
25855@subsubheading Synopsis
25856
25857@smallexample
25858 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
25859@end smallexample
25860
25861Specifies the CLI commands that should be executed when breakpoint
25862@var{number} is hit. The parameters @var{command1} to @var{commandN}
25863are the commands. If no command is specified, any previously-set
25864commands are cleared. @xref{Break Commands}. Typical use of this
25865functionality is tracing a program, that is, printing of values of
25866some variables whenever breakpoint is hit and then continuing.
25867
25868@subsubheading @value{GDBN} Command
25869
25870The corresponding @value{GDBN} command is @samp{commands}.
25871
25872@subsubheading Example
25873
25874@smallexample
25875(gdb)
25876-break-insert main
25877^done,bkpt=@{number="1",type="breakpoint",disp="keep",
25878enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
25879fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
25880times="0"@}
48cb2d85
VP
25881(gdb)
25882-break-commands 1 "print v" "continue"
25883^done
25884(gdb)
25885@end smallexample
922fbb7b
AC
25886
25887@subheading The @code{-break-condition} Command
25888@findex -break-condition
25889
25890@subsubheading Synopsis
25891
25892@smallexample
25893 -break-condition @var{number} @var{expr}
25894@end smallexample
25895
25896Breakpoint @var{number} will stop the program only if the condition in
25897@var{expr} is true. The condition becomes part of the
25898@samp{-break-list} output (see the description of the @samp{-break-list}
25899command below).
25900
25901@subsubheading @value{GDBN} Command
25902
25903The corresponding @value{GDBN} command is @samp{condition}.
25904
25905@subsubheading Example
25906
25907@smallexample
594fe323 25908(gdb)
922fbb7b
AC
25909-break-condition 1 1
25910^done
594fe323 25911(gdb)
922fbb7b
AC
25912-break-list
25913^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
25914hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
25915@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
25916@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
25917@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
25918@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
25919@{width="40",alignment="2",col_name="what",colhdr="What"@}],
25920body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 25921addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 25922line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 25923(gdb)
922fbb7b
AC
25924@end smallexample
25925
25926@subheading The @code{-break-delete} Command
25927@findex -break-delete
25928
25929@subsubheading Synopsis
25930
25931@smallexample
25932 -break-delete ( @var{breakpoint} )+
25933@end smallexample
25934
25935Delete the breakpoint(s) whose number(s) are specified in the argument
25936list. This is obviously reflected in the breakpoint list.
25937
79a6e687 25938@subsubheading @value{GDBN} Command
922fbb7b
AC
25939
25940The corresponding @value{GDBN} command is @samp{delete}.
25941
25942@subsubheading Example
25943
25944@smallexample
594fe323 25945(gdb)
922fbb7b
AC
25946-break-delete 1
25947^done
594fe323 25948(gdb)
922fbb7b
AC
25949-break-list
25950^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
25951hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
25952@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
25953@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
25954@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
25955@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
25956@{width="40",alignment="2",col_name="what",colhdr="What"@}],
25957body=[]@}
594fe323 25958(gdb)
922fbb7b
AC
25959@end smallexample
25960
25961@subheading The @code{-break-disable} Command
25962@findex -break-disable
25963
25964@subsubheading Synopsis
25965
25966@smallexample
25967 -break-disable ( @var{breakpoint} )+
25968@end smallexample
25969
25970Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
25971break list is now set to @samp{n} for the named @var{breakpoint}(s).
25972
25973@subsubheading @value{GDBN} Command
25974
25975The corresponding @value{GDBN} command is @samp{disable}.
25976
25977@subsubheading Example
25978
25979@smallexample
594fe323 25980(gdb)
922fbb7b
AC
25981-break-disable 2
25982^done
594fe323 25983(gdb)
922fbb7b
AC
25984-break-list
25985^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
25986hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
25987@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
25988@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
25989@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
25990@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
25991@{width="40",alignment="2",col_name="what",colhdr="What"@}],
25992body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102 25993addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 25994line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 25995(gdb)
922fbb7b
AC
25996@end smallexample
25997
25998@subheading The @code{-break-enable} Command
25999@findex -break-enable
26000
26001@subsubheading Synopsis
26002
26003@smallexample
26004 -break-enable ( @var{breakpoint} )+
26005@end smallexample
26006
26007Enable (previously disabled) @var{breakpoint}(s).
26008
26009@subsubheading @value{GDBN} Command
26010
26011The corresponding @value{GDBN} command is @samp{enable}.
26012
26013@subsubheading Example
26014
26015@smallexample
594fe323 26016(gdb)
922fbb7b
AC
26017-break-enable 2
26018^done
594fe323 26019(gdb)
922fbb7b
AC
26020-break-list
26021^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
26022hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26023@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26024@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26025@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26026@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26027@{width="40",alignment="2",col_name="what",colhdr="What"@}],
26028body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 26029addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 26030line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 26031(gdb)
922fbb7b
AC
26032@end smallexample
26033
26034@subheading The @code{-break-info} Command
26035@findex -break-info
26036
26037@subsubheading Synopsis
26038
26039@smallexample
26040 -break-info @var{breakpoint}
26041@end smallexample
26042
26043@c REDUNDANT???
26044Get information about a single breakpoint.
26045
54516a0b
TT
26046The result is a table of breakpoints. @xref{GDB/MI Breakpoint
26047Information}, for details on the format of each breakpoint in the
26048table.
26049
79a6e687 26050@subsubheading @value{GDBN} Command
922fbb7b
AC
26051
26052The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
26053
26054@subsubheading Example
26055N.A.
26056
26057@subheading The @code{-break-insert} Command
26058@findex -break-insert
26059
26060@subsubheading Synopsis
26061
26062@smallexample
18148017 26063 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
922fbb7b 26064 [ -c @var{condition} ] [ -i @var{ignore-count} ]
472a2379 26065 [ -p @var{thread-id} ] [ @var{location} ]
922fbb7b
AC
26066@end smallexample
26067
26068@noindent
afe8ab22 26069If specified, @var{location}, can be one of:
922fbb7b
AC
26070
26071@itemize @bullet
26072@item function
26073@c @item +offset
26074@c @item -offset
26075@c @item linenum
26076@item filename:linenum
26077@item filename:function
26078@item *address
26079@end itemize
26080
26081The possible optional parameters of this command are:
26082
26083@table @samp
26084@item -t
948d5102 26085Insert a temporary breakpoint.
922fbb7b
AC
26086@item -h
26087Insert a hardware breakpoint.
afe8ab22
VP
26088@item -f
26089If @var{location} cannot be parsed (for example if it
26090refers to unknown files or functions), create a pending
26091breakpoint. Without this flag, @value{GDBN} will report
26092an error, and won't create a breakpoint, if @var{location}
26093cannot be parsed.
41447f92
VP
26094@item -d
26095Create a disabled breakpoint.
18148017
VP
26096@item -a
26097Create a tracepoint. @xref{Tracepoints}. When this parameter
26098is used together with @samp{-h}, a fast tracepoint is created.
472a2379
KS
26099@item -c @var{condition}
26100Make the breakpoint conditional on @var{condition}.
26101@item -i @var{ignore-count}
26102Initialize the @var{ignore-count}.
26103@item -p @var{thread-id}
26104Restrict the breakpoint to the specified @var{thread-id}.
922fbb7b
AC
26105@end table
26106
26107@subsubheading Result
26108
54516a0b
TT
26109@xref{GDB/MI Breakpoint Information}, for details on the format of the
26110resulting breakpoint.
922fbb7b
AC
26111
26112Note: this format is open to change.
26113@c An out-of-band breakpoint instead of part of the result?
26114
26115@subsubheading @value{GDBN} Command
26116
26117The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
496ee73e 26118@samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
922fbb7b
AC
26119
26120@subsubheading Example
26121
26122@smallexample
594fe323 26123(gdb)
922fbb7b 26124-break-insert main
948d5102 26125^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
998580f1
MK
26126fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
26127times="0"@}
594fe323 26128(gdb)
922fbb7b 26129-break-insert -t foo
948d5102 26130^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
998580f1
MK
26131fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
26132times="0"@}
594fe323 26133(gdb)
922fbb7b
AC
26134-break-list
26135^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
26136hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26137@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26138@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26139@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26140@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26141@{width="40",alignment="2",col_name="what",colhdr="What"@}],
26142body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 26143addr="0x0001072c", func="main",file="recursive2.c",
998580f1
MK
26144fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
26145times="0"@},
922fbb7b 26146bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102 26147addr="0x00010774",func="foo",file="recursive2.c",
998580f1
MK
26148fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
26149times="0"@}]@}
594fe323 26150(gdb)
496ee73e
KS
26151@c -break-insert -r foo.*
26152@c ~int foo(int, int);
26153@c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
998580f1
MK
26154@c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
26155@c times="0"@}
496ee73e 26156@c (gdb)
922fbb7b
AC
26157@end smallexample
26158
c5867ab6
HZ
26159@subheading The @code{-dprintf-insert} Command
26160@findex -dprintf-insert
26161
26162@subsubheading Synopsis
26163
26164@smallexample
26165 -dprintf-insert [ -t ] [ -f ] [ -d ]
26166 [ -c @var{condition} ] [ -i @var{ignore-count} ]
26167 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
26168 [ @var{argument} ]
26169@end smallexample
26170
26171@noindent
26172If specified, @var{location}, can be one of:
26173
26174@itemize @bullet
26175@item @var{function}
26176@c @item +offset
26177@c @item -offset
26178@c @item @var{linenum}
26179@item @var{filename}:@var{linenum}
26180@item @var{filename}:function
26181@item *@var{address}
26182@end itemize
26183
26184The possible optional parameters of this command are:
26185
26186@table @samp
26187@item -t
26188Insert a temporary breakpoint.
26189@item -f
26190If @var{location} cannot be parsed (for example, if it
26191refers to unknown files or functions), create a pending
26192breakpoint. Without this flag, @value{GDBN} will report
26193an error, and won't create a breakpoint, if @var{location}
26194cannot be parsed.
26195@item -d
26196Create a disabled breakpoint.
26197@item -c @var{condition}
26198Make the breakpoint conditional on @var{condition}.
26199@item -i @var{ignore-count}
26200Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
26201to @var{ignore-count}.
26202@item -p @var{thread-id}
26203Restrict the breakpoint to the specified @var{thread-id}.
26204@end table
26205
26206@subsubheading Result
26207
26208@xref{GDB/MI Breakpoint Information}, for details on the format of the
26209resulting breakpoint.
26210
26211@c An out-of-band breakpoint instead of part of the result?
26212
26213@subsubheading @value{GDBN} Command
26214
26215The corresponding @value{GDBN} command is @samp{dprintf}.
26216
26217@subsubheading Example
26218
26219@smallexample
26220(gdb)
262214-dprintf-insert foo "At foo entry\n"
262224^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
26223addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
26224fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
26225times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
26226original-location="foo"@}
26227(gdb)
262285-dprintf-insert 26 "arg=%d, g=%d\n" arg g
262295^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
26230addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
26231fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
26232times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
26233original-location="mi-dprintf.c:26"@}
26234(gdb)
26235@end smallexample
26236
922fbb7b
AC
26237@subheading The @code{-break-list} Command
26238@findex -break-list
26239
26240@subsubheading Synopsis
26241
26242@smallexample
26243 -break-list
26244@end smallexample
26245
26246Displays the list of inserted breakpoints, showing the following fields:
26247
26248@table @samp
26249@item Number
26250number of the breakpoint
26251@item Type
26252type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
26253@item Disposition
26254should the breakpoint be deleted or disabled when it is hit: @samp{keep}
26255or @samp{nokeep}
26256@item Enabled
26257is the breakpoint enabled or no: @samp{y} or @samp{n}
26258@item Address
26259memory location at which the breakpoint is set
26260@item What
26261logical location of the breakpoint, expressed by function name, file
26262name, line number
998580f1
MK
26263@item Thread-groups
26264list of thread groups to which this breakpoint applies
922fbb7b
AC
26265@item Times
26266number of times the breakpoint has been hit
26267@end table
26268
26269If there are no breakpoints or watchpoints, the @code{BreakpointTable}
26270@code{body} field is an empty list.
26271
26272@subsubheading @value{GDBN} Command
26273
26274The corresponding @value{GDBN} command is @samp{info break}.
26275
26276@subsubheading Example
26277
26278@smallexample
594fe323 26279(gdb)
922fbb7b
AC
26280-break-list
26281^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
26282hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26283@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26284@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26285@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26286@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26287@{width="40",alignment="2",col_name="what",colhdr="What"@}],
26288body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
998580f1
MK
26289addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
26290times="0"@},
922fbb7b 26291bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 26292addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
998580f1 26293line="13",thread-groups=["i1"],times="0"@}]@}
594fe323 26294(gdb)
922fbb7b
AC
26295@end smallexample
26296
26297Here's an example of the result when there are no breakpoints:
26298
26299@smallexample
594fe323 26300(gdb)
922fbb7b
AC
26301-break-list
26302^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
26303hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26304@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26305@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26306@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26307@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26308@{width="40",alignment="2",col_name="what",colhdr="What"@}],
26309body=[]@}
594fe323 26310(gdb)
922fbb7b
AC
26311@end smallexample
26312
18148017
VP
26313@subheading The @code{-break-passcount} Command
26314@findex -break-passcount
26315
26316@subsubheading Synopsis
26317
26318@smallexample
26319 -break-passcount @var{tracepoint-number} @var{passcount}
26320@end smallexample
26321
26322Set the passcount for tracepoint @var{tracepoint-number} to
26323@var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
26324is not a tracepoint, error is emitted. This corresponds to CLI
26325command @samp{passcount}.
26326
922fbb7b
AC
26327@subheading The @code{-break-watch} Command
26328@findex -break-watch
26329
26330@subsubheading Synopsis
26331
26332@smallexample
26333 -break-watch [ -a | -r ]
26334@end smallexample
26335
26336Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 26337@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 26338read from or on a write to the memory location. With the @samp{-r}
d3e8051b 26339option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
26340trigger only when the memory location is accessed for reading. Without
26341either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 26342i.e., it will trigger when the memory location is accessed for writing.
79a6e687 26343@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
26344
26345Note that @samp{-break-list} will report a single list of watchpoints and
26346breakpoints inserted.
26347
26348@subsubheading @value{GDBN} Command
26349
26350The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
26351@samp{rwatch}.
26352
26353@subsubheading Example
26354
26355Setting a watchpoint on a variable in the @code{main} function:
26356
26357@smallexample
594fe323 26358(gdb)
922fbb7b
AC
26359-break-watch x
26360^done,wpt=@{number="2",exp="x"@}
594fe323 26361(gdb)
922fbb7b
AC
26362-exec-continue
26363^running
0869d01b
NR
26364(gdb)
26365*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 26366value=@{old="-268439212",new="55"@},
76ff342d 26367frame=@{func="main",args=[],file="recursive2.c",
948d5102 26368fullname="/home/foo/bar/recursive2.c",line="5"@}
594fe323 26369(gdb)
922fbb7b
AC
26370@end smallexample
26371
26372Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
26373the program execution twice: first for the variable changing value, then
26374for the watchpoint going out of scope.
26375
26376@smallexample
594fe323 26377(gdb)
922fbb7b
AC
26378-break-watch C
26379^done,wpt=@{number="5",exp="C"@}
594fe323 26380(gdb)
922fbb7b
AC
26381-exec-continue
26382^running
0869d01b
NR
26383(gdb)
26384*stopped,reason="watchpoint-trigger",
922fbb7b
AC
26385wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
26386frame=@{func="callee4",args=[],
76ff342d
DJ
26387file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
26388fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 26389(gdb)
922fbb7b
AC
26390-exec-continue
26391^running
0869d01b
NR
26392(gdb)
26393*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
26394frame=@{func="callee3",args=[@{name="strarg",
26395value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
26396file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
26397fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 26398(gdb)
922fbb7b
AC
26399@end smallexample
26400
26401Listing breakpoints and watchpoints, at different points in the program
26402execution. Note that once the watchpoint goes out of scope, it is
26403deleted.
26404
26405@smallexample
594fe323 26406(gdb)
922fbb7b
AC
26407-break-watch C
26408^done,wpt=@{number="2",exp="C"@}
594fe323 26409(gdb)
922fbb7b
AC
26410-break-list
26411^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
26412hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26413@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26414@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26415@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26416@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26417@{width="40",alignment="2",col_name="what",colhdr="What"@}],
26418body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
26419addr="0x00010734",func="callee4",
948d5102 26420file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
26421fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
26422times="1"@},
922fbb7b 26423bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 26424enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
594fe323 26425(gdb)
922fbb7b
AC
26426-exec-continue
26427^running
0869d01b
NR
26428(gdb)
26429*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
26430value=@{old="-276895068",new="3"@},
26431frame=@{func="callee4",args=[],
76ff342d
DJ
26432file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
26433fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 26434(gdb)
922fbb7b
AC
26435-break-list
26436^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
26437hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26438@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26439@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26440@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26441@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26442@{width="40",alignment="2",col_name="what",colhdr="What"@}],
26443body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
26444addr="0x00010734",func="callee4",
948d5102 26445file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
26446fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
26447times="1"@},
922fbb7b 26448bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 26449enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
594fe323 26450(gdb)
922fbb7b
AC
26451-exec-continue
26452^running
26453^done,reason="watchpoint-scope",wpnum="2",
26454frame=@{func="callee3",args=[@{name="strarg",
26455value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
26456file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
26457fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 26458(gdb)
922fbb7b
AC
26459-break-list
26460^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
26461hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26462@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26463@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26464@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26465@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26466@{width="40",alignment="2",col_name="what",colhdr="What"@}],
26467body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
26468addr="0x00010734",func="callee4",
948d5102
NR
26469file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
26470fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
998580f1 26471thread-groups=["i1"],times="1"@}]@}
594fe323 26472(gdb)
922fbb7b
AC
26473@end smallexample
26474
3fa7bf06
MG
26475
26476@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26477@node GDB/MI Catchpoint Commands
26478@section @sc{gdb/mi} Catchpoint Commands
26479
26480This section documents @sc{gdb/mi} commands for manipulating
26481catchpoints.
26482
40555925
JB
26483@menu
26484* Shared Library GDB/MI Catchpoint Commands::
26485* Ada Exception GDB/MI Catchpoint Commands::
26486@end menu
26487
26488@node Shared Library GDB/MI Catchpoint Commands
26489@subsection Shared Library @sc{gdb/mi} Catchpoints
26490
3fa7bf06
MG
26491@subheading The @code{-catch-load} Command
26492@findex -catch-load
26493
26494@subsubheading Synopsis
26495
26496@smallexample
26497 -catch-load [ -t ] [ -d ] @var{regexp}
26498@end smallexample
26499
26500Add a catchpoint for library load events. If the @samp{-t} option is used,
26501the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
26502Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
26503in a disabled state. The @samp{regexp} argument is a regular
26504expression used to match the name of the loaded library.
26505
26506
26507@subsubheading @value{GDBN} Command
26508
26509The corresponding @value{GDBN} command is @samp{catch load}.
26510
26511@subsubheading Example
26512
26513@smallexample
26514-catch-load -t foo.so
26515^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
8ac3646f 26516what="load of library matching foo.so",catch-type="load",times="0"@}
3fa7bf06
MG
26517(gdb)
26518@end smallexample
26519
26520
26521@subheading The @code{-catch-unload} Command
26522@findex -catch-unload
26523
26524@subsubheading Synopsis
26525
26526@smallexample
26527 -catch-unload [ -t ] [ -d ] @var{regexp}
26528@end smallexample
26529
26530Add a catchpoint for library unload events. If the @samp{-t} option is
26531used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
26532Breakpoints}). If the @samp{-d} option is used, the catchpoint is
26533created in a disabled state. The @samp{regexp} argument is a regular
26534expression used to match the name of the unloaded library.
26535
26536@subsubheading @value{GDBN} Command
26537
26538The corresponding @value{GDBN} command is @samp{catch unload}.
26539
26540@subsubheading Example
26541
26542@smallexample
26543-catch-unload -d bar.so
26544^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
8ac3646f 26545what="load of library matching bar.so",catch-type="unload",times="0"@}
3fa7bf06
MG
26546(gdb)
26547@end smallexample
26548
40555925
JB
26549@node Ada Exception GDB/MI Catchpoint Commands
26550@subsection Ada Exception @sc{gdb/mi} Catchpoints
26551
26552The following @sc{gdb/mi} commands can be used to create catchpoints
26553that stop the execution when Ada exceptions are being raised.
26554
26555@subheading The @code{-catch-assert} Command
26556@findex -catch-assert
26557
26558@subsubheading Synopsis
26559
26560@smallexample
26561 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
26562@end smallexample
26563
26564Add a catchpoint for failed Ada assertions.
26565
26566The possible optional parameters for this command are:
26567
26568@table @samp
26569@item -c @var{condition}
26570Make the catchpoint conditional on @var{condition}.
26571@item -d
26572Create a disabled catchpoint.
26573@item -t
26574Create a temporary catchpoint.
26575@end table
26576
26577@subsubheading @value{GDBN} Command
26578
26579The corresponding @value{GDBN} command is @samp{catch assert}.
26580
26581@subsubheading Example
26582
26583@smallexample
26584-catch-assert
26585^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
26586enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
26587thread-groups=["i1"],times="0",
26588original-location="__gnat_debug_raise_assert_failure"@}
26589(gdb)
26590@end smallexample
26591
26592@subheading The @code{-catch-exception} Command
26593@findex -catch-exception
26594
26595@subsubheading Synopsis
26596
26597@smallexample
26598 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
26599 [ -t ] [ -u ]
26600@end smallexample
26601
26602Add a catchpoint stopping when Ada exceptions are raised.
26603By default, the command stops the program when any Ada exception
26604gets raised. But it is also possible, by using some of the
26605optional parameters described below, to create more selective
26606catchpoints.
26607
26608The possible optional parameters for this command are:
26609
26610@table @samp
26611@item -c @var{condition}
26612Make the catchpoint conditional on @var{condition}.
26613@item -d
26614Create a disabled catchpoint.
26615@item -e @var{exception-name}
26616Only stop when @var{exception-name} is raised. This option cannot
26617be used combined with @samp{-u}.
26618@item -t
26619Create a temporary catchpoint.
26620@item -u
26621Stop only when an unhandled exception gets raised. This option
26622cannot be used combined with @samp{-e}.
26623@end table
26624
26625@subsubheading @value{GDBN} Command
26626
26627The corresponding @value{GDBN} commands are @samp{catch exception}
26628and @samp{catch exception unhandled}.
26629
26630@subsubheading Example
26631
26632@smallexample
26633-catch-exception -e Program_Error
26634^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
26635enabled="y",addr="0x0000000000404874",
26636what="`Program_Error' Ada exception", thread-groups=["i1"],
26637times="0",original-location="__gnat_debug_raise_exception"@}
26638(gdb)
26639@end smallexample
3fa7bf06 26640
922fbb7b 26641@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
26642@node GDB/MI Program Context
26643@section @sc{gdb/mi} Program Context
922fbb7b 26644
a2c02241
NR
26645@subheading The @code{-exec-arguments} Command
26646@findex -exec-arguments
922fbb7b 26647
922fbb7b
AC
26648
26649@subsubheading Synopsis
26650
26651@smallexample
a2c02241 26652 -exec-arguments @var{args}
922fbb7b
AC
26653@end smallexample
26654
a2c02241
NR
26655Set the inferior program arguments, to be used in the next
26656@samp{-exec-run}.
922fbb7b 26657
a2c02241 26658@subsubheading @value{GDBN} Command
922fbb7b 26659
a2c02241 26660The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 26661
a2c02241 26662@subsubheading Example
922fbb7b 26663
fbc5282e
MK
26664@smallexample
26665(gdb)
26666-exec-arguments -v word
26667^done
26668(gdb)
26669@end smallexample
922fbb7b 26670
a2c02241 26671
9901a55b 26672@ignore
a2c02241
NR
26673@subheading The @code{-exec-show-arguments} Command
26674@findex -exec-show-arguments
26675
26676@subsubheading Synopsis
26677
26678@smallexample
26679 -exec-show-arguments
26680@end smallexample
26681
26682Print the arguments of the program.
922fbb7b
AC
26683
26684@subsubheading @value{GDBN} Command
26685
a2c02241 26686The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
26687
26688@subsubheading Example
a2c02241 26689N.A.
9901a55b 26690@end ignore
922fbb7b 26691
922fbb7b 26692
a2c02241
NR
26693@subheading The @code{-environment-cd} Command
26694@findex -environment-cd
922fbb7b 26695
a2c02241 26696@subsubheading Synopsis
922fbb7b
AC
26697
26698@smallexample
a2c02241 26699 -environment-cd @var{pathdir}
922fbb7b
AC
26700@end smallexample
26701
a2c02241 26702Set @value{GDBN}'s working directory.
922fbb7b 26703
a2c02241 26704@subsubheading @value{GDBN} Command
922fbb7b 26705
a2c02241
NR
26706The corresponding @value{GDBN} command is @samp{cd}.
26707
26708@subsubheading Example
922fbb7b
AC
26709
26710@smallexample
594fe323 26711(gdb)
a2c02241
NR
26712-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
26713^done
594fe323 26714(gdb)
922fbb7b
AC
26715@end smallexample
26716
26717
a2c02241
NR
26718@subheading The @code{-environment-directory} Command
26719@findex -environment-directory
922fbb7b
AC
26720
26721@subsubheading Synopsis
26722
26723@smallexample
a2c02241 26724 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
26725@end smallexample
26726
a2c02241
NR
26727Add directories @var{pathdir} to beginning of search path for source files.
26728If the @samp{-r} option is used, the search path is reset to the default
26729search path. If directories @var{pathdir} are supplied in addition to the
26730@samp{-r} option, the search path is first reset and then addition
26731occurs as normal.
26732Multiple directories may be specified, separated by blanks. Specifying
26733multiple directories in a single command
26734results in the directories added to the beginning of the
26735search path in the same order they were presented in the command.
26736If blanks are needed as
26737part of a directory name, double-quotes should be used around
26738the name. In the command output, the path will show up separated
d3e8051b 26739by the system directory-separator character. The directory-separator
a2c02241
NR
26740character must not be used
26741in any directory name.
26742If no directories are specified, the current search path is displayed.
922fbb7b
AC
26743
26744@subsubheading @value{GDBN} Command
26745
a2c02241 26746The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
26747
26748@subsubheading Example
26749
922fbb7b 26750@smallexample
594fe323 26751(gdb)
a2c02241
NR
26752-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
26753^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 26754(gdb)
a2c02241
NR
26755-environment-directory ""
26756^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 26757(gdb)
a2c02241
NR
26758-environment-directory -r /home/jjohnstn/src/gdb /usr/src
26759^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 26760(gdb)
a2c02241
NR
26761-environment-directory -r
26762^done,source-path="$cdir:$cwd"
594fe323 26763(gdb)
922fbb7b
AC
26764@end smallexample
26765
26766
a2c02241
NR
26767@subheading The @code{-environment-path} Command
26768@findex -environment-path
922fbb7b
AC
26769
26770@subsubheading Synopsis
26771
26772@smallexample
a2c02241 26773 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
26774@end smallexample
26775
a2c02241
NR
26776Add directories @var{pathdir} to beginning of search path for object files.
26777If the @samp{-r} option is used, the search path is reset to the original
26778search path that existed at gdb start-up. If directories @var{pathdir} are
26779supplied in addition to the
26780@samp{-r} option, the search path is first reset and then addition
26781occurs as normal.
26782Multiple directories may be specified, separated by blanks. Specifying
26783multiple directories in a single command
26784results in the directories added to the beginning of the
26785search path in the same order they were presented in the command.
26786If blanks are needed as
26787part of a directory name, double-quotes should be used around
26788the name. In the command output, the path will show up separated
d3e8051b 26789by the system directory-separator character. The directory-separator
a2c02241
NR
26790character must not be used
26791in any directory name.
26792If no directories are specified, the current path is displayed.
26793
922fbb7b
AC
26794
26795@subsubheading @value{GDBN} Command
26796
a2c02241 26797The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
26798
26799@subsubheading Example
26800
922fbb7b 26801@smallexample
594fe323 26802(gdb)
a2c02241
NR
26803-environment-path
26804^done,path="/usr/bin"
594fe323 26805(gdb)
a2c02241
NR
26806-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
26807^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 26808(gdb)
a2c02241
NR
26809-environment-path -r /usr/local/bin
26810^done,path="/usr/local/bin:/usr/bin"
594fe323 26811(gdb)
922fbb7b
AC
26812@end smallexample
26813
26814
a2c02241
NR
26815@subheading The @code{-environment-pwd} Command
26816@findex -environment-pwd
922fbb7b
AC
26817
26818@subsubheading Synopsis
26819
26820@smallexample
a2c02241 26821 -environment-pwd
922fbb7b
AC
26822@end smallexample
26823
a2c02241 26824Show the current working directory.
922fbb7b 26825
79a6e687 26826@subsubheading @value{GDBN} Command
922fbb7b 26827
a2c02241 26828The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
26829
26830@subsubheading Example
26831
922fbb7b 26832@smallexample
594fe323 26833(gdb)
a2c02241
NR
26834-environment-pwd
26835^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 26836(gdb)
922fbb7b
AC
26837@end smallexample
26838
a2c02241
NR
26839@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26840@node GDB/MI Thread Commands
26841@section @sc{gdb/mi} Thread Commands
26842
26843
26844@subheading The @code{-thread-info} Command
26845@findex -thread-info
922fbb7b
AC
26846
26847@subsubheading Synopsis
26848
26849@smallexample
8e8901c5 26850 -thread-info [ @var{thread-id} ]
922fbb7b
AC
26851@end smallexample
26852
8e8901c5
VP
26853Reports information about either a specific thread, if
26854the @var{thread-id} parameter is present, or about all
26855threads. When printing information about all threads,
26856also reports the current thread.
26857
79a6e687 26858@subsubheading @value{GDBN} Command
922fbb7b 26859
8e8901c5
VP
26860The @samp{info thread} command prints the same information
26861about all threads.
922fbb7b 26862
4694da01 26863@subsubheading Result
922fbb7b 26864
4694da01
TT
26865The result is a list of threads. The following attributes are
26866defined for a given thread:
26867
26868@table @samp
26869@item current
26870This field exists only for the current thread. It has the value @samp{*}.
26871
26872@item id
26873The identifier that @value{GDBN} uses to refer to the thread.
26874
26875@item target-id
26876The identifier that the target uses to refer to the thread.
26877
26878@item details
26879Extra information about the thread, in a target-specific format. This
26880field is optional.
26881
26882@item name
26883The name of the thread. If the user specified a name using the
26884@code{thread name} command, then this name is given. Otherwise, if
26885@value{GDBN} can extract the thread name from the target, then that
26886name is given. If @value{GDBN} cannot find the thread name, then this
26887field is omitted.
26888
26889@item frame
26890The stack frame currently executing in the thread.
922fbb7b 26891
4694da01
TT
26892@item state
26893The thread's state. The @samp{state} field may have the following
26894values:
c3b108f7
VP
26895
26896@table @code
26897@item stopped
26898The thread is stopped. Frame information is available for stopped
26899threads.
26900
26901@item running
26902The thread is running. There's no frame information for running
26903threads.
26904
26905@end table
26906
4694da01
TT
26907@item core
26908If @value{GDBN} can find the CPU core on which this thread is running,
26909then this field is the core identifier. This field is optional.
26910
26911@end table
26912
26913@subsubheading Example
26914
26915@smallexample
26916-thread-info
26917^done,threads=[
26918@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
26919 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
26920 args=[]@},state="running"@},
26921@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
26922 frame=@{level="0",addr="0x0804891f",func="foo",
26923 args=[@{name="i",value="10"@}],
26924 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},
26925 state="running"@}],
26926current-thread-id="1"
26927(gdb)
26928@end smallexample
26929
a2c02241
NR
26930@subheading The @code{-thread-list-ids} Command
26931@findex -thread-list-ids
922fbb7b 26932
a2c02241 26933@subsubheading Synopsis
922fbb7b 26934
a2c02241
NR
26935@smallexample
26936 -thread-list-ids
26937@end smallexample
922fbb7b 26938
a2c02241
NR
26939Produces a list of the currently known @value{GDBN} thread ids. At the
26940end of the list it also prints the total number of such threads.
922fbb7b 26941
c3b108f7
VP
26942This command is retained for historical reasons, the
26943@code{-thread-info} command should be used instead.
26944
922fbb7b
AC
26945@subsubheading @value{GDBN} Command
26946
a2c02241 26947Part of @samp{info threads} supplies the same information.
922fbb7b
AC
26948
26949@subsubheading Example
26950
922fbb7b 26951@smallexample
594fe323 26952(gdb)
a2c02241
NR
26953-thread-list-ids
26954^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
592375cd 26955current-thread-id="1",number-of-threads="3"
594fe323 26956(gdb)
922fbb7b
AC
26957@end smallexample
26958
a2c02241
NR
26959
26960@subheading The @code{-thread-select} Command
26961@findex -thread-select
922fbb7b
AC
26962
26963@subsubheading Synopsis
26964
26965@smallexample
a2c02241 26966 -thread-select @var{threadnum}
922fbb7b
AC
26967@end smallexample
26968
a2c02241
NR
26969Make @var{threadnum} the current thread. It prints the number of the new
26970current thread, and the topmost frame for that thread.
922fbb7b 26971
c3b108f7
VP
26972This command is deprecated in favor of explicitly using the
26973@samp{--thread} option to each command.
26974
922fbb7b
AC
26975@subsubheading @value{GDBN} Command
26976
a2c02241 26977The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
26978
26979@subsubheading Example
922fbb7b
AC
26980
26981@smallexample
594fe323 26982(gdb)
a2c02241
NR
26983-exec-next
26984^running
594fe323 26985(gdb)
a2c02241
NR
26986*stopped,reason="end-stepping-range",thread-id="2",line="187",
26987file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 26988(gdb)
a2c02241
NR
26989-thread-list-ids
26990^done,
26991thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
26992number-of-threads="3"
594fe323 26993(gdb)
a2c02241
NR
26994-thread-select 3
26995^done,new-thread-id="3",
26996frame=@{level="0",func="vprintf",
26997args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
26998@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
594fe323 26999(gdb)
922fbb7b
AC
27000@end smallexample
27001
5d77fe44
JB
27002@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27003@node GDB/MI Ada Tasking Commands
27004@section @sc{gdb/mi} Ada Tasking Commands
27005
27006@subheading The @code{-ada-task-info} Command
27007@findex -ada-task-info
27008
27009@subsubheading Synopsis
27010
27011@smallexample
27012 -ada-task-info [ @var{task-id} ]
27013@end smallexample
27014
27015Reports information about either a specific Ada task, if the
27016@var{task-id} parameter is present, or about all Ada tasks.
27017
27018@subsubheading @value{GDBN} Command
27019
27020The @samp{info tasks} command prints the same information
27021about all Ada tasks (@pxref{Ada Tasks}).
27022
27023@subsubheading Result
27024
27025The result is a table of Ada tasks. The following columns are
27026defined for each Ada task:
27027
27028@table @samp
27029@item current
27030This field exists only for the current thread. It has the value @samp{*}.
27031
27032@item id
27033The identifier that @value{GDBN} uses to refer to the Ada task.
27034
27035@item task-id
27036The identifier that the target uses to refer to the Ada task.
27037
27038@item thread-id
27039The identifier of the thread corresponding to the Ada task.
27040
27041This field should always exist, as Ada tasks are always implemented
27042on top of a thread. But if @value{GDBN} cannot find this corresponding
27043thread for any reason, the field is omitted.
27044
27045@item parent-id
27046This field exists only when the task was created by another task.
27047In this case, it provides the ID of the parent task.
27048
27049@item priority
27050The base priority of the task.
27051
27052@item state
27053The current state of the task. For a detailed description of the
27054possible states, see @ref{Ada Tasks}.
27055
27056@item name
27057The name of the task.
27058
27059@end table
27060
27061@subsubheading Example
27062
27063@smallexample
27064-ada-task-info
27065^done,tasks=@{nr_rows="3",nr_cols="8",
27066hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
27067@{width="3",alignment="1",col_name="id",colhdr="ID"@},
27068@{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
27069@{width="4",alignment="1",col_name="thread-id",colhdr=""@},
27070@{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
27071@{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
27072@{width="22",alignment="-1",col_name="state",colhdr="State"@},
27073@{width="1",alignment="2",col_name="name",colhdr="Name"@}],
27074body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
27075state="Child Termination Wait",name="main_task"@}]@}
27076(gdb)
27077@end smallexample
27078
a2c02241
NR
27079@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27080@node GDB/MI Program Execution
27081@section @sc{gdb/mi} Program Execution
922fbb7b 27082
ef21caaf 27083These are the asynchronous commands which generate the out-of-band
3f94c067 27084record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
27085asynchronously with remote targets and this interaction is mimicked in
27086other cases.
922fbb7b 27087
922fbb7b
AC
27088@subheading The @code{-exec-continue} Command
27089@findex -exec-continue
27090
27091@subsubheading Synopsis
27092
27093@smallexample
540aa8e7 27094 -exec-continue [--reverse] [--all|--thread-group N]
922fbb7b
AC
27095@end smallexample
27096
540aa8e7
MS
27097Resumes the execution of the inferior program, which will continue
27098to execute until it reaches a debugger stop event. If the
27099@samp{--reverse} option is specified, execution resumes in reverse until
27100it reaches a stop event. Stop events may include
27101@itemize @bullet
27102@item
27103breakpoints or watchpoints
27104@item
27105signals or exceptions
27106@item
27107the end of the process (or its beginning under @samp{--reverse})
27108@item
27109the end or beginning of a replay log if one is being used.
27110@end itemize
27111In all-stop mode (@pxref{All-Stop
27112Mode}), may resume only one thread, or all threads, depending on the
27113value of the @samp{scheduler-locking} variable. If @samp{--all} is
a79b8f6e 27114specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
540aa8e7
MS
27115ignored in all-stop mode. If the @samp{--thread-group} options is
27116specified, then all threads in that thread group are resumed.
922fbb7b
AC
27117
27118@subsubheading @value{GDBN} Command
27119
27120The corresponding @value{GDBN} corresponding is @samp{continue}.
27121
27122@subsubheading Example
27123
27124@smallexample
27125-exec-continue
27126^running
594fe323 27127(gdb)
922fbb7b 27128@@Hello world
a47ec5fe
AR
27129*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
27130func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
27131line="13"@}
594fe323 27132(gdb)
922fbb7b
AC
27133@end smallexample
27134
27135
27136@subheading The @code{-exec-finish} Command
27137@findex -exec-finish
27138
27139@subsubheading Synopsis
27140
27141@smallexample
540aa8e7 27142 -exec-finish [--reverse]
922fbb7b
AC
27143@end smallexample
27144
ef21caaf
NR
27145Resumes the execution of the inferior program until the current
27146function is exited. Displays the results returned by the function.
540aa8e7
MS
27147If the @samp{--reverse} option is specified, resumes the reverse
27148execution of the inferior program until the point where current
27149function was called.
922fbb7b
AC
27150
27151@subsubheading @value{GDBN} Command
27152
27153The corresponding @value{GDBN} command is @samp{finish}.
27154
27155@subsubheading Example
27156
27157Function returning @code{void}.
27158
27159@smallexample
27160-exec-finish
27161^running
594fe323 27162(gdb)
922fbb7b
AC
27163@@hello from foo
27164*stopped,reason="function-finished",frame=@{func="main",args=[],
948d5102 27165file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
594fe323 27166(gdb)
922fbb7b
AC
27167@end smallexample
27168
27169Function returning other than @code{void}. The name of the internal
27170@value{GDBN} variable storing the result is printed, together with the
27171value itself.
27172
27173@smallexample
27174-exec-finish
27175^running
594fe323 27176(gdb)
922fbb7b
AC
27177*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
27178args=[@{name="a",value="1"],@{name="b",value="9"@}@},
948d5102 27179file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
922fbb7b 27180gdb-result-var="$1",return-value="0"
594fe323 27181(gdb)
922fbb7b
AC
27182@end smallexample
27183
27184
27185@subheading The @code{-exec-interrupt} Command
27186@findex -exec-interrupt
27187
27188@subsubheading Synopsis
27189
27190@smallexample
c3b108f7 27191 -exec-interrupt [--all|--thread-group N]
922fbb7b
AC
27192@end smallexample
27193
ef21caaf
NR
27194Interrupts the background execution of the target. Note how the token
27195associated with the stop message is the one for the execution command
27196that has been interrupted. The token for the interrupt itself only
27197appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
27198interrupt a non-running program, an error message will be printed.
27199
c3b108f7
VP
27200Note that when asynchronous execution is enabled, this command is
27201asynchronous just like other execution commands. That is, first the
27202@samp{^done} response will be printed, and the target stop will be
27203reported after that using the @samp{*stopped} notification.
27204
27205In non-stop mode, only the context thread is interrupted by default.
a79b8f6e
VP
27206All threads (in all inferiors) will be interrupted if the
27207@samp{--all} option is specified. If the @samp{--thread-group}
27208option is specified, all threads in that group will be interrupted.
c3b108f7 27209
922fbb7b
AC
27210@subsubheading @value{GDBN} Command
27211
27212The corresponding @value{GDBN} command is @samp{interrupt}.
27213
27214@subsubheading Example
27215
27216@smallexample
594fe323 27217(gdb)
922fbb7b
AC
27218111-exec-continue
27219111^running
27220
594fe323 27221(gdb)
922fbb7b
AC
27222222-exec-interrupt
27223222^done
594fe323 27224(gdb)
922fbb7b 27225111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 27226frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
948d5102 27227fullname="/home/foo/bar/try.c",line="13"@}
594fe323 27228(gdb)
922fbb7b 27229
594fe323 27230(gdb)
922fbb7b
AC
27231-exec-interrupt
27232^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 27233(gdb)
922fbb7b
AC
27234@end smallexample
27235
83eba9b7
VP
27236@subheading The @code{-exec-jump} Command
27237@findex -exec-jump
27238
27239@subsubheading Synopsis
27240
27241@smallexample
27242 -exec-jump @var{location}
27243@end smallexample
27244
27245Resumes execution of the inferior program at the location specified by
27246parameter. @xref{Specify Location}, for a description of the
27247different forms of @var{location}.
27248
27249@subsubheading @value{GDBN} Command
27250
27251The corresponding @value{GDBN} command is @samp{jump}.
27252
27253@subsubheading Example
27254
27255@smallexample
27256-exec-jump foo.c:10
27257*running,thread-id="all"
27258^running
27259@end smallexample
27260
922fbb7b
AC
27261
27262@subheading The @code{-exec-next} Command
27263@findex -exec-next
27264
27265@subsubheading Synopsis
27266
27267@smallexample
540aa8e7 27268 -exec-next [--reverse]
922fbb7b
AC
27269@end smallexample
27270
ef21caaf
NR
27271Resumes execution of the inferior program, stopping when the beginning
27272of the next source line is reached.
922fbb7b 27273
540aa8e7
MS
27274If the @samp{--reverse} option is specified, resumes reverse execution
27275of the inferior program, stopping at the beginning of the previous
27276source line. If you issue this command on the first line of a
27277function, it will take you back to the caller of that function, to the
27278source line where the function was called.
27279
27280
922fbb7b
AC
27281@subsubheading @value{GDBN} Command
27282
27283The corresponding @value{GDBN} command is @samp{next}.
27284
27285@subsubheading Example
27286
27287@smallexample
27288-exec-next
27289^running
594fe323 27290(gdb)
922fbb7b 27291*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 27292(gdb)
922fbb7b
AC
27293@end smallexample
27294
27295
27296@subheading The @code{-exec-next-instruction} Command
27297@findex -exec-next-instruction
27298
27299@subsubheading Synopsis
27300
27301@smallexample
540aa8e7 27302 -exec-next-instruction [--reverse]
922fbb7b
AC
27303@end smallexample
27304
ef21caaf
NR
27305Executes one machine instruction. If the instruction is a function
27306call, continues until the function returns. If the program stops at an
27307instruction in the middle of a source line, the address will be
27308printed as well.
922fbb7b 27309
540aa8e7
MS
27310If the @samp{--reverse} option is specified, resumes reverse execution
27311of the inferior program, stopping at the previous instruction. If the
27312previously executed instruction was a return from another function,
27313it will continue to execute in reverse until the call to that function
27314(from the current stack frame) is reached.
27315
922fbb7b
AC
27316@subsubheading @value{GDBN} Command
27317
27318The corresponding @value{GDBN} command is @samp{nexti}.
27319
27320@subsubheading Example
27321
27322@smallexample
594fe323 27323(gdb)
922fbb7b
AC
27324-exec-next-instruction
27325^running
27326
594fe323 27327(gdb)
922fbb7b
AC
27328*stopped,reason="end-stepping-range",
27329addr="0x000100d4",line="5",file="hello.c"
594fe323 27330(gdb)
922fbb7b
AC
27331@end smallexample
27332
27333
27334@subheading The @code{-exec-return} Command
27335@findex -exec-return
27336
27337@subsubheading Synopsis
27338
27339@smallexample
27340 -exec-return
27341@end smallexample
27342
27343Makes current function return immediately. Doesn't execute the inferior.
27344Displays the new current frame.
27345
27346@subsubheading @value{GDBN} Command
27347
27348The corresponding @value{GDBN} command is @samp{return}.
27349
27350@subsubheading Example
27351
27352@smallexample
594fe323 27353(gdb)
922fbb7b
AC
27354200-break-insert callee4
27355200^done,bkpt=@{number="1",addr="0x00010734",
27356file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 27357(gdb)
922fbb7b
AC
27358000-exec-run
27359000^running
594fe323 27360(gdb)
a47ec5fe 27361000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
922fbb7b 27362frame=@{func="callee4",args=[],
76ff342d
DJ
27363file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27364fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 27365(gdb)
922fbb7b
AC
27366205-break-delete
27367205^done
594fe323 27368(gdb)
922fbb7b
AC
27369111-exec-return
27370111^done,frame=@{level="0",func="callee3",
27371args=[@{name="strarg",
27372value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
27373file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27374fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 27375(gdb)
922fbb7b
AC
27376@end smallexample
27377
27378
27379@subheading The @code{-exec-run} Command
27380@findex -exec-run
27381
27382@subsubheading Synopsis
27383
27384@smallexample
5713b9b5 27385 -exec-run [ --all | --thread-group N ] [ --start ]
922fbb7b
AC
27386@end smallexample
27387
ef21caaf
NR
27388Starts execution of the inferior from the beginning. The inferior
27389executes until either a breakpoint is encountered or the program
27390exits. In the latter case the output will include an exit code, if
27391the program has exited exceptionally.
922fbb7b 27392
5713b9b5
JB
27393When neither the @samp{--all} nor the @samp{--thread-group} option
27394is specified, the current inferior is started. If the
a79b8f6e
VP
27395@samp{--thread-group} option is specified, it should refer to a thread
27396group of type @samp{process}, and that thread group will be started.
27397If the @samp{--all} option is specified, then all inferiors will be started.
27398
5713b9b5
JB
27399Using the @samp{--start} option instructs the debugger to stop
27400the execution at the start of the inferior's main subprogram,
27401following the same behavior as the @code{start} command
27402(@pxref{Starting}).
27403
922fbb7b
AC
27404@subsubheading @value{GDBN} Command
27405
27406The corresponding @value{GDBN} command is @samp{run}.
27407
ef21caaf 27408@subsubheading Examples
922fbb7b
AC
27409
27410@smallexample
594fe323 27411(gdb)
922fbb7b
AC
27412-break-insert main
27413^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 27414(gdb)
922fbb7b
AC
27415-exec-run
27416^running
594fe323 27417(gdb)
a47ec5fe 27418*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
76ff342d 27419frame=@{func="main",args=[],file="recursive2.c",
948d5102 27420fullname="/home/foo/bar/recursive2.c",line="4"@}
594fe323 27421(gdb)
922fbb7b
AC
27422@end smallexample
27423
ef21caaf
NR
27424@noindent
27425Program exited normally:
27426
27427@smallexample
594fe323 27428(gdb)
ef21caaf
NR
27429-exec-run
27430^running
594fe323 27431(gdb)
ef21caaf
NR
27432x = 55
27433*stopped,reason="exited-normally"
594fe323 27434(gdb)
ef21caaf
NR
27435@end smallexample
27436
27437@noindent
27438Program exited exceptionally:
27439
27440@smallexample
594fe323 27441(gdb)
ef21caaf
NR
27442-exec-run
27443^running
594fe323 27444(gdb)
ef21caaf
NR
27445x = 55
27446*stopped,reason="exited",exit-code="01"
594fe323 27447(gdb)
ef21caaf
NR
27448@end smallexample
27449
27450Another way the program can terminate is if it receives a signal such as
27451@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
27452
27453@smallexample
594fe323 27454(gdb)
ef21caaf
NR
27455*stopped,reason="exited-signalled",signal-name="SIGINT",
27456signal-meaning="Interrupt"
27457@end smallexample
27458
922fbb7b 27459
a2c02241
NR
27460@c @subheading -exec-signal
27461
27462
27463@subheading The @code{-exec-step} Command
27464@findex -exec-step
922fbb7b
AC
27465
27466@subsubheading Synopsis
27467
27468@smallexample
540aa8e7 27469 -exec-step [--reverse]
922fbb7b
AC
27470@end smallexample
27471
a2c02241
NR
27472Resumes execution of the inferior program, stopping when the beginning
27473of the next source line is reached, if the next source line is not a
27474function call. If it is, stop at the first instruction of the called
540aa8e7
MS
27475function. If the @samp{--reverse} option is specified, resumes reverse
27476execution of the inferior program, stopping at the beginning of the
27477previously executed source line.
922fbb7b
AC
27478
27479@subsubheading @value{GDBN} Command
27480
a2c02241 27481The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
27482
27483@subsubheading Example
27484
27485Stepping into a function:
27486
27487@smallexample
27488-exec-step
27489^running
594fe323 27490(gdb)
922fbb7b
AC
27491*stopped,reason="end-stepping-range",
27492frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 27493@{name="b",value="0"@}],file="recursive2.c",
948d5102 27494fullname="/home/foo/bar/recursive2.c",line="11"@}
594fe323 27495(gdb)
922fbb7b
AC
27496@end smallexample
27497
27498Regular stepping:
27499
27500@smallexample
27501-exec-step
27502^running
594fe323 27503(gdb)
922fbb7b 27504*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 27505(gdb)
922fbb7b
AC
27506@end smallexample
27507
27508
27509@subheading The @code{-exec-step-instruction} Command
27510@findex -exec-step-instruction
27511
27512@subsubheading Synopsis
27513
27514@smallexample
540aa8e7 27515 -exec-step-instruction [--reverse]
922fbb7b
AC
27516@end smallexample
27517
540aa8e7
MS
27518Resumes the inferior which executes one machine instruction. If the
27519@samp{--reverse} option is specified, resumes reverse execution of the
27520inferior program, stopping at the previously executed instruction.
27521The output, once @value{GDBN} has stopped, will vary depending on
27522whether we have stopped in the middle of a source line or not. In the
27523former case, the address at which the program stopped will be printed
27524as well.
922fbb7b
AC
27525
27526@subsubheading @value{GDBN} Command
27527
27528The corresponding @value{GDBN} command is @samp{stepi}.
27529
27530@subsubheading Example
27531
27532@smallexample
594fe323 27533(gdb)
922fbb7b
AC
27534-exec-step-instruction
27535^running
27536
594fe323 27537(gdb)
922fbb7b 27538*stopped,reason="end-stepping-range",
76ff342d 27539frame=@{func="foo",args=[],file="try.c",
948d5102 27540fullname="/home/foo/bar/try.c",line="10"@}
594fe323 27541(gdb)
922fbb7b
AC
27542-exec-step-instruction
27543^running
27544
594fe323 27545(gdb)
922fbb7b 27546*stopped,reason="end-stepping-range",
76ff342d 27547frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
948d5102 27548fullname="/home/foo/bar/try.c",line="10"@}
594fe323 27549(gdb)
922fbb7b
AC
27550@end smallexample
27551
27552
27553@subheading The @code{-exec-until} Command
27554@findex -exec-until
27555
27556@subsubheading Synopsis
27557
27558@smallexample
27559 -exec-until [ @var{location} ]
27560@end smallexample
27561
ef21caaf
NR
27562Executes the inferior until the @var{location} specified in the
27563argument is reached. If there is no argument, the inferior executes
27564until a source line greater than the current one is reached. The
27565reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
27566
27567@subsubheading @value{GDBN} Command
27568
27569The corresponding @value{GDBN} command is @samp{until}.
27570
27571@subsubheading Example
27572
27573@smallexample
594fe323 27574(gdb)
922fbb7b
AC
27575-exec-until recursive2.c:6
27576^running
594fe323 27577(gdb)
922fbb7b
AC
27578x = 55
27579*stopped,reason="location-reached",frame=@{func="main",args=[],
948d5102 27580file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
594fe323 27581(gdb)
922fbb7b
AC
27582@end smallexample
27583
27584@ignore
27585@subheading -file-clear
27586Is this going away????
27587@end ignore
27588
351ff01a 27589@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
27590@node GDB/MI Stack Manipulation
27591@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 27592
1e611234
PM
27593@subheading The @code{-enable-frame-filters} Command
27594@findex -enable-frame-filters
27595
27596@smallexample
27597-enable-frame-filters
27598@end smallexample
27599
27600@value{GDBN} allows Python-based frame filters to affect the output of
27601the MI commands relating to stack traces. As there is no way to
27602implement this in a fully backward-compatible way, a front end must
27603request that this functionality be enabled.
27604
27605Once enabled, this feature cannot be disabled.
27606
27607Note that if Python support has not been compiled into @value{GDBN},
27608this command will still succeed (and do nothing).
922fbb7b 27609
a2c02241
NR
27610@subheading The @code{-stack-info-frame} Command
27611@findex -stack-info-frame
922fbb7b
AC
27612
27613@subsubheading Synopsis
27614
27615@smallexample
a2c02241 27616 -stack-info-frame
922fbb7b
AC
27617@end smallexample
27618
a2c02241 27619Get info on the selected frame.
922fbb7b
AC
27620
27621@subsubheading @value{GDBN} Command
27622
a2c02241
NR
27623The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
27624(without arguments).
922fbb7b
AC
27625
27626@subsubheading Example
27627
27628@smallexample
594fe323 27629(gdb)
a2c02241
NR
27630-stack-info-frame
27631^done,frame=@{level="1",addr="0x0001076c",func="callee3",
27632file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27633fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
594fe323 27634(gdb)
922fbb7b
AC
27635@end smallexample
27636
a2c02241
NR
27637@subheading The @code{-stack-info-depth} Command
27638@findex -stack-info-depth
922fbb7b
AC
27639
27640@subsubheading Synopsis
27641
27642@smallexample
a2c02241 27643 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
27644@end smallexample
27645
a2c02241
NR
27646Return the depth of the stack. If the integer argument @var{max-depth}
27647is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
27648
27649@subsubheading @value{GDBN} Command
27650
a2c02241 27651There's no equivalent @value{GDBN} command.
922fbb7b
AC
27652
27653@subsubheading Example
27654
a2c02241
NR
27655For a stack with frame levels 0 through 11:
27656
922fbb7b 27657@smallexample
594fe323 27658(gdb)
a2c02241
NR
27659-stack-info-depth
27660^done,depth="12"
594fe323 27661(gdb)
a2c02241
NR
27662-stack-info-depth 4
27663^done,depth="4"
594fe323 27664(gdb)
a2c02241
NR
27665-stack-info-depth 12
27666^done,depth="12"
594fe323 27667(gdb)
a2c02241
NR
27668-stack-info-depth 11
27669^done,depth="11"
594fe323 27670(gdb)
a2c02241
NR
27671-stack-info-depth 13
27672^done,depth="12"
594fe323 27673(gdb)
922fbb7b
AC
27674@end smallexample
27675
1e611234 27676@anchor{-stack-list-arguments}
a2c02241
NR
27677@subheading The @code{-stack-list-arguments} Command
27678@findex -stack-list-arguments
922fbb7b
AC
27679
27680@subsubheading Synopsis
27681
27682@smallexample
6211c335 27683 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
a2c02241 27684 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
27685@end smallexample
27686
a2c02241
NR
27687Display a list of the arguments for the frames between @var{low-frame}
27688and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
27689@var{high-frame} are not provided, list the arguments for the whole
27690call stack. If the two arguments are equal, show the single frame
27691at the corresponding level. It is an error if @var{low-frame} is
27692larger than the actual number of frames. On the other hand,
27693@var{high-frame} may be larger than the actual number of frames, in
27694which case only existing frames will be returned.
a2c02241 27695
3afae151
VP
27696If @var{print-values} is 0 or @code{--no-values}, print only the names of
27697the variables; if it is 1 or @code{--all-values}, print also their
27698values; and if it is 2 or @code{--simple-values}, print the name,
27699type and value for simple data types, and the name and type for arrays,
1e611234
PM
27700structures and unions. If the option @code{--no-frame-filters} is
27701supplied, then Python frame filters will not be executed.
27702
6211c335
YQ
27703If the @code{--skip-unavailable} option is specified, arguments that
27704are not available are not listed. Partially available arguments
27705are still displayed, however.
922fbb7b 27706
b3372f91
VP
27707Use of this command to obtain arguments in a single frame is
27708deprecated in favor of the @samp{-stack-list-variables} command.
27709
922fbb7b
AC
27710@subsubheading @value{GDBN} Command
27711
a2c02241
NR
27712@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
27713@samp{gdb_get_args} command which partially overlaps with the
27714functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
27715
27716@subsubheading Example
922fbb7b 27717
a2c02241 27718@smallexample
594fe323 27719(gdb)
a2c02241
NR
27720-stack-list-frames
27721^done,
27722stack=[
27723frame=@{level="0",addr="0x00010734",func="callee4",
27724file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27725fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
27726frame=@{level="1",addr="0x0001076c",func="callee3",
27727file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27728fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
27729frame=@{level="2",addr="0x0001078c",func="callee2",
27730file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27731fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
27732frame=@{level="3",addr="0x000107b4",func="callee1",
27733file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27734fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
27735frame=@{level="4",addr="0x000107e0",func="main",
27736file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27737fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
594fe323 27738(gdb)
a2c02241
NR
27739-stack-list-arguments 0
27740^done,
27741stack-args=[
27742frame=@{level="0",args=[]@},
27743frame=@{level="1",args=[name="strarg"]@},
27744frame=@{level="2",args=[name="intarg",name="strarg"]@},
27745frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
27746frame=@{level="4",args=[]@}]
594fe323 27747(gdb)
a2c02241
NR
27748-stack-list-arguments 1
27749^done,
27750stack-args=[
27751frame=@{level="0",args=[]@},
27752frame=@{level="1",
27753 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
27754frame=@{level="2",args=[
27755@{name="intarg",value="2"@},
27756@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
27757@{frame=@{level="3",args=[
27758@{name="intarg",value="2"@},
27759@{name="strarg",value="0x11940 \"A string argument.\""@},
27760@{name="fltarg",value="3.5"@}]@},
27761frame=@{level="4",args=[]@}]
594fe323 27762(gdb)
a2c02241
NR
27763-stack-list-arguments 0 2 2
27764^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 27765(gdb)
a2c02241
NR
27766-stack-list-arguments 1 2 2
27767^done,stack-args=[frame=@{level="2",
27768args=[@{name="intarg",value="2"@},
27769@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 27770(gdb)
a2c02241
NR
27771@end smallexample
27772
27773@c @subheading -stack-list-exception-handlers
922fbb7b 27774
a2c02241 27775
1e611234 27776@anchor{-stack-list-frames}
a2c02241
NR
27777@subheading The @code{-stack-list-frames} Command
27778@findex -stack-list-frames
1abaf70c
BR
27779
27780@subsubheading Synopsis
27781
27782@smallexample
1e611234 27783 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
1abaf70c
BR
27784@end smallexample
27785
a2c02241
NR
27786List the frames currently on the stack. For each frame it displays the
27787following info:
27788
27789@table @samp
27790@item @var{level}
d3e8051b 27791The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
27792@item @var{addr}
27793The @code{$pc} value for that frame.
27794@item @var{func}
27795Function name.
27796@item @var{file}
27797File name of the source file where the function lives.
7d288aaa
TT
27798@item @var{fullname}
27799The full file name of the source file where the function lives.
a2c02241
NR
27800@item @var{line}
27801Line number corresponding to the @code{$pc}.
7d288aaa
TT
27802@item @var{from}
27803The shared library where this function is defined. This is only given
27804if the frame's function is not known.
a2c02241
NR
27805@end table
27806
27807If invoked without arguments, this command prints a backtrace for the
27808whole stack. If given two integer arguments, it shows the frames whose
27809levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
27810are equal, it shows the single frame at the corresponding level. It is
27811an error if @var{low-frame} is larger than the actual number of
a5451f4e 27812frames. On the other hand, @var{high-frame} may be larger than the
1e611234
PM
27813actual number of frames, in which case only existing frames will be
27814returned. If the option @code{--no-frame-filters} is supplied, then
27815Python frame filters will not be executed.
1abaf70c
BR
27816
27817@subsubheading @value{GDBN} Command
27818
a2c02241 27819The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
27820
27821@subsubheading Example
27822
a2c02241
NR
27823Full stack backtrace:
27824
1abaf70c 27825@smallexample
594fe323 27826(gdb)
a2c02241
NR
27827-stack-list-frames
27828^done,stack=
27829[frame=@{level="0",addr="0x0001076c",func="foo",
27830 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
27831frame=@{level="1",addr="0x000107a4",func="foo",
27832 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
27833frame=@{level="2",addr="0x000107a4",func="foo",
27834 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
27835frame=@{level="3",addr="0x000107a4",func="foo",
27836 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
27837frame=@{level="4",addr="0x000107a4",func="foo",
27838 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
27839frame=@{level="5",addr="0x000107a4",func="foo",
27840 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
27841frame=@{level="6",addr="0x000107a4",func="foo",
27842 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
27843frame=@{level="7",addr="0x000107a4",func="foo",
27844 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
27845frame=@{level="8",addr="0x000107a4",func="foo",
27846 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
27847frame=@{level="9",addr="0x000107a4",func="foo",
27848 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
27849frame=@{level="10",addr="0x000107a4",func="foo",
27850 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
27851frame=@{level="11",addr="0x00010738",func="main",
27852 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
594fe323 27853(gdb)
1abaf70c
BR
27854@end smallexample
27855
a2c02241 27856Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 27857
a2c02241 27858@smallexample
594fe323 27859(gdb)
a2c02241
NR
27860-stack-list-frames 3 5
27861^done,stack=
27862[frame=@{level="3",addr="0x000107a4",func="foo",
27863 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
27864frame=@{level="4",addr="0x000107a4",func="foo",
27865 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
27866frame=@{level="5",addr="0x000107a4",func="foo",
27867 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 27868(gdb)
a2c02241 27869@end smallexample
922fbb7b 27870
a2c02241 27871Show a single frame:
922fbb7b
AC
27872
27873@smallexample
594fe323 27874(gdb)
a2c02241
NR
27875-stack-list-frames 3 3
27876^done,stack=
27877[frame=@{level="3",addr="0x000107a4",func="foo",
27878 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 27879(gdb)
922fbb7b
AC
27880@end smallexample
27881
922fbb7b 27882
a2c02241
NR
27883@subheading The @code{-stack-list-locals} Command
27884@findex -stack-list-locals
1e611234 27885@anchor{-stack-list-locals}
57c22c6c 27886
a2c02241 27887@subsubheading Synopsis
922fbb7b
AC
27888
27889@smallexample
6211c335 27890 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
922fbb7b
AC
27891@end smallexample
27892
a2c02241
NR
27893Display the local variable names for the selected frame. If
27894@var{print-values} is 0 or @code{--no-values}, print only the names of
27895the variables; if it is 1 or @code{--all-values}, print also their
27896values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 27897type and value for simple data types, and the name and type for arrays,
a2c02241
NR
27898structures and unions. In this last case, a frontend can immediately
27899display the value of simple data types and create variable objects for
d3e8051b 27900other data types when the user wishes to explore their values in
1e611234
PM
27901more detail. If the option @code{--no-frame-filters} is supplied, then
27902Python frame filters will not be executed.
922fbb7b 27903
6211c335
YQ
27904If the @code{--skip-unavailable} option is specified, local variables
27905that are not available are not listed. Partially available local
27906variables are still displayed, however.
27907
b3372f91
VP
27908This command is deprecated in favor of the
27909@samp{-stack-list-variables} command.
27910
922fbb7b
AC
27911@subsubheading @value{GDBN} Command
27912
a2c02241 27913@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
27914
27915@subsubheading Example
922fbb7b
AC
27916
27917@smallexample
594fe323 27918(gdb)
a2c02241
NR
27919-stack-list-locals 0
27920^done,locals=[name="A",name="B",name="C"]
594fe323 27921(gdb)
a2c02241
NR
27922-stack-list-locals --all-values
27923^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
27924 @{name="C",value="@{1, 2, 3@}"@}]
27925-stack-list-locals --simple-values
27926^done,locals=[@{name="A",type="int",value="1"@},
27927 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 27928(gdb)
922fbb7b
AC
27929@end smallexample
27930
1e611234 27931@anchor{-stack-list-variables}
b3372f91
VP
27932@subheading The @code{-stack-list-variables} Command
27933@findex -stack-list-variables
27934
27935@subsubheading Synopsis
27936
27937@smallexample
6211c335 27938 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
b3372f91
VP
27939@end smallexample
27940
27941Display the names of local variables and function arguments for the selected frame. If
27942@var{print-values} is 0 or @code{--no-values}, print only the names of
27943the variables; if it is 1 or @code{--all-values}, print also their
27944values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 27945type and value for simple data types, and the name and type for arrays,
1e611234
PM
27946structures and unions. If the option @code{--no-frame-filters} is
27947supplied, then Python frame filters will not be executed.
b3372f91 27948
6211c335
YQ
27949If the @code{--skip-unavailable} option is specified, local variables
27950and arguments that are not available are not listed. Partially
27951available arguments and local variables are still displayed, however.
27952
b3372f91
VP
27953@subsubheading Example
27954
27955@smallexample
27956(gdb)
27957-stack-list-variables --thread 1 --frame 0 --all-values
4f412fd0 27958^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
b3372f91
VP
27959(gdb)
27960@end smallexample
27961
922fbb7b 27962
a2c02241
NR
27963@subheading The @code{-stack-select-frame} Command
27964@findex -stack-select-frame
922fbb7b
AC
27965
27966@subsubheading Synopsis
27967
27968@smallexample
a2c02241 27969 -stack-select-frame @var{framenum}
922fbb7b
AC
27970@end smallexample
27971
a2c02241
NR
27972Change the selected frame. Select a different frame @var{framenum} on
27973the stack.
922fbb7b 27974
c3b108f7
VP
27975This command in deprecated in favor of passing the @samp{--frame}
27976option to every command.
27977
922fbb7b
AC
27978@subsubheading @value{GDBN} Command
27979
a2c02241
NR
27980The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
27981@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
27982
27983@subsubheading Example
27984
27985@smallexample
594fe323 27986(gdb)
a2c02241 27987-stack-select-frame 2
922fbb7b 27988^done
594fe323 27989(gdb)
922fbb7b
AC
27990@end smallexample
27991
27992@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
27993@node GDB/MI Variable Objects
27994@section @sc{gdb/mi} Variable Objects
922fbb7b 27995
a1b5960f 27996@ignore
922fbb7b 27997
a2c02241 27998@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 27999
a2c02241
NR
28000For the implementation of a variable debugger window (locals, watched
28001expressions, etc.), we are proposing the adaptation of the existing code
28002used by @code{Insight}.
922fbb7b 28003
a2c02241 28004The two main reasons for that are:
922fbb7b 28005
a2c02241
NR
28006@enumerate 1
28007@item
28008It has been proven in practice (it is already on its second generation).
922fbb7b 28009
a2c02241
NR
28010@item
28011It will shorten development time (needless to say how important it is
28012now).
28013@end enumerate
922fbb7b 28014
a2c02241
NR
28015The original interface was designed to be used by Tcl code, so it was
28016slightly changed so it could be used through @sc{gdb/mi}. This section
28017describes the @sc{gdb/mi} operations that will be available and gives some
28018hints about their use.
922fbb7b 28019
a2c02241
NR
28020@emph{Note}: In addition to the set of operations described here, we
28021expect the @sc{gui} implementation of a variable window to require, at
28022least, the following operations:
922fbb7b 28023
a2c02241
NR
28024@itemize @bullet
28025@item @code{-gdb-show} @code{output-radix}
28026@item @code{-stack-list-arguments}
28027@item @code{-stack-list-locals}
28028@item @code{-stack-select-frame}
28029@end itemize
922fbb7b 28030
a1b5960f
VP
28031@end ignore
28032
c8b2f53c 28033@subheading Introduction to Variable Objects
922fbb7b 28034
a2c02241 28035@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
28036
28037Variable objects are "object-oriented" MI interface for examining and
28038changing values of expressions. Unlike some other MI interfaces that
28039work with expressions, variable objects are specifically designed for
28040simple and efficient presentation in the frontend. A variable object
28041is identified by string name. When a variable object is created, the
28042frontend specifies the expression for that variable object. The
28043expression can be a simple variable, or it can be an arbitrary complex
28044expression, and can even involve CPU registers. After creating a
28045variable object, the frontend can invoke other variable object
28046operations---for example to obtain or change the value of a variable
28047object, or to change display format.
28048
28049Variable objects have hierarchical tree structure. Any variable object
28050that corresponds to a composite type, such as structure in C, has
28051a number of child variable objects, for example corresponding to each
28052element of a structure. A child variable object can itself have
28053children, recursively. Recursion ends when we reach
25d5ea92
VP
28054leaf variable objects, which always have built-in types. Child variable
28055objects are created only by explicit request, so if a frontend
28056is not interested in the children of a particular variable object, no
28057child will be created.
c8b2f53c
VP
28058
28059For a leaf variable object it is possible to obtain its value as a
28060string, or set the value from a string. String value can be also
28061obtained for a non-leaf variable object, but it's generally a string
28062that only indicates the type of the object, and does not list its
28063contents. Assignment to a non-leaf variable object is not allowed.
28064
28065A frontend does not need to read the values of all variable objects each time
28066the program stops. Instead, MI provides an update command that lists all
28067variable objects whose values has changed since the last update
28068operation. This considerably reduces the amount of data that must
25d5ea92
VP
28069be transferred to the frontend. As noted above, children variable
28070objects are created on demand, and only leaf variable objects have a
28071real value. As result, gdb will read target memory only for leaf
28072variables that frontend has created.
28073
28074The automatic update is not always desirable. For example, a frontend
28075might want to keep a value of some expression for future reference,
28076and never update it. For another example, fetching memory is
28077relatively slow for embedded targets, so a frontend might want
28078to disable automatic update for the variables that are either not
28079visible on the screen, or ``closed''. This is possible using so
28080called ``frozen variable objects''. Such variable objects are never
28081implicitly updated.
922fbb7b 28082
c3b108f7
VP
28083Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
28084fixed variable object, the expression is parsed when the variable
28085object is created, including associating identifiers to specific
28086variables. The meaning of expression never changes. For a floating
28087variable object the values of variables whose names appear in the
28088expressions are re-evaluated every time in the context of the current
28089frame. Consider this example:
28090
28091@smallexample
28092void do_work(...)
28093@{
28094 struct work_state state;
28095
28096 if (...)
28097 do_work(...);
28098@}
28099@end smallexample
28100
28101If a fixed variable object for the @code{state} variable is created in
7a9dd1b2 28102this function, and we enter the recursive call, the variable
c3b108f7
VP
28103object will report the value of @code{state} in the top-level
28104@code{do_work} invocation. On the other hand, a floating variable
28105object will report the value of @code{state} in the current frame.
28106
28107If an expression specified when creating a fixed variable object
28108refers to a local variable, the variable object becomes bound to the
28109thread and frame in which the variable object is created. When such
28110variable object is updated, @value{GDBN} makes sure that the
28111thread/frame combination the variable object is bound to still exists,
28112and re-evaluates the variable object in context of that thread/frame.
28113
a2c02241
NR
28114The following is the complete set of @sc{gdb/mi} operations defined to
28115access this functionality:
922fbb7b 28116
a2c02241
NR
28117@multitable @columnfractions .4 .6
28118@item @strong{Operation}
28119@tab @strong{Description}
922fbb7b 28120
0cc7d26f
TT
28121@item @code{-enable-pretty-printing}
28122@tab enable Python-based pretty-printing
a2c02241
NR
28123@item @code{-var-create}
28124@tab create a variable object
28125@item @code{-var-delete}
22d8a470 28126@tab delete the variable object and/or its children
a2c02241
NR
28127@item @code{-var-set-format}
28128@tab set the display format of this variable
28129@item @code{-var-show-format}
28130@tab show the display format of this variable
28131@item @code{-var-info-num-children}
28132@tab tells how many children this object has
28133@item @code{-var-list-children}
28134@tab return a list of the object's children
28135@item @code{-var-info-type}
28136@tab show the type of this variable object
28137@item @code{-var-info-expression}
02142340
VP
28138@tab print parent-relative expression that this variable object represents
28139@item @code{-var-info-path-expression}
28140@tab print full expression that this variable object represents
a2c02241
NR
28141@item @code{-var-show-attributes}
28142@tab is this variable editable? does it exist here?
28143@item @code{-var-evaluate-expression}
28144@tab get the value of this variable
28145@item @code{-var-assign}
28146@tab set the value of this variable
28147@item @code{-var-update}
28148@tab update the variable and its children
25d5ea92
VP
28149@item @code{-var-set-frozen}
28150@tab set frozeness attribute
0cc7d26f
TT
28151@item @code{-var-set-update-range}
28152@tab set range of children to display on update
a2c02241 28153@end multitable
922fbb7b 28154
a2c02241
NR
28155In the next subsection we describe each operation in detail and suggest
28156how it can be used.
922fbb7b 28157
a2c02241 28158@subheading Description And Use of Operations on Variable Objects
922fbb7b 28159
0cc7d26f
TT
28160@subheading The @code{-enable-pretty-printing} Command
28161@findex -enable-pretty-printing
28162
28163@smallexample
28164-enable-pretty-printing
28165@end smallexample
28166
28167@value{GDBN} allows Python-based visualizers to affect the output of the
28168MI variable object commands. However, because there was no way to
28169implement this in a fully backward-compatible way, a front end must
28170request that this functionality be enabled.
28171
28172Once enabled, this feature cannot be disabled.
28173
28174Note that if Python support has not been compiled into @value{GDBN},
28175this command will still succeed (and do nothing).
28176
f43030c4
TT
28177This feature is currently (as of @value{GDBN} 7.0) experimental, and
28178may work differently in future versions of @value{GDBN}.
28179
a2c02241
NR
28180@subheading The @code{-var-create} Command
28181@findex -var-create
ef21caaf 28182
a2c02241 28183@subsubheading Synopsis
ef21caaf 28184
a2c02241
NR
28185@smallexample
28186 -var-create @{@var{name} | "-"@}
c3b108f7 28187 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
a2c02241
NR
28188@end smallexample
28189
28190This operation creates a variable object, which allows the monitoring of
28191a variable, the result of an expression, a memory cell or a CPU
28192register.
ef21caaf 28193
a2c02241
NR
28194The @var{name} parameter is the string by which the object can be
28195referenced. It must be unique. If @samp{-} is specified, the varobj
28196system will generate a string ``varNNNNNN'' automatically. It will be
c3b108f7 28197unique provided that one does not specify @var{name} of that format.
a2c02241 28198The command fails if a duplicate name is found.
ef21caaf 28199
a2c02241
NR
28200The frame under which the expression should be evaluated can be
28201specified by @var{frame-addr}. A @samp{*} indicates that the current
c3b108f7
VP
28202frame should be used. A @samp{@@} indicates that a floating variable
28203object must be created.
922fbb7b 28204
a2c02241
NR
28205@var{expression} is any expression valid on the current language set (must not
28206begin with a @samp{*}), or one of the following:
922fbb7b 28207
a2c02241
NR
28208@itemize @bullet
28209@item
28210@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 28211
a2c02241
NR
28212@item
28213@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 28214
a2c02241
NR
28215@item
28216@samp{$@var{regname}} --- a CPU register name
28217@end itemize
922fbb7b 28218
0cc7d26f
TT
28219@cindex dynamic varobj
28220A varobj's contents may be provided by a Python-based pretty-printer. In this
28221case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
28222have slightly different semantics in some cases. If the
28223@code{-enable-pretty-printing} command is not sent, then @value{GDBN}
28224will never create a dynamic varobj. This ensures backward
28225compatibility for existing clients.
28226
a2c02241 28227@subsubheading Result
922fbb7b 28228
0cc7d26f
TT
28229This operation returns attributes of the newly-created varobj. These
28230are:
28231
28232@table @samp
28233@item name
28234The name of the varobj.
28235
28236@item numchild
28237The number of children of the varobj. This number is not necessarily
28238reliable for a dynamic varobj. Instead, you must examine the
28239@samp{has_more} attribute.
28240
28241@item value
28242The varobj's scalar value. For a varobj whose type is some sort of
28243aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
28244will not be interesting.
28245
28246@item type
28247The varobj's type. This is a string representation of the type, as
8264ba82
AG
28248would be printed by the @value{GDBN} CLI. If @samp{print object}
28249(@pxref{Print Settings, set print object}) is set to @code{on}, the
28250@emph{actual} (derived) type of the object is shown rather than the
28251@emph{declared} one.
0cc7d26f
TT
28252
28253@item thread-id
28254If a variable object is bound to a specific thread, then this is the
28255thread's identifier.
28256
28257@item has_more
28258For a dynamic varobj, this indicates whether there appear to be any
28259children available. For a non-dynamic varobj, this will be 0.
28260
28261@item dynamic
28262This attribute will be present and have the value @samp{1} if the
28263varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
28264then this attribute will not be present.
28265
28266@item displayhint
28267A dynamic varobj can supply a display hint to the front end. The
28268value comes directly from the Python pretty-printer object's
4c374409 28269@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
28270@end table
28271
28272Typical output will look like this:
922fbb7b
AC
28273
28274@smallexample
0cc7d26f
TT
28275 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
28276 has_more="@var{has_more}"
dcaaae04
NR
28277@end smallexample
28278
a2c02241
NR
28279
28280@subheading The @code{-var-delete} Command
28281@findex -var-delete
922fbb7b
AC
28282
28283@subsubheading Synopsis
28284
28285@smallexample
22d8a470 28286 -var-delete [ -c ] @var{name}
922fbb7b
AC
28287@end smallexample
28288
a2c02241 28289Deletes a previously created variable object and all of its children.
22d8a470 28290With the @samp{-c} option, just deletes the children.
922fbb7b 28291
a2c02241 28292Returns an error if the object @var{name} is not found.
922fbb7b 28293
922fbb7b 28294
a2c02241
NR
28295@subheading The @code{-var-set-format} Command
28296@findex -var-set-format
922fbb7b 28297
a2c02241 28298@subsubheading Synopsis
922fbb7b
AC
28299
28300@smallexample
a2c02241 28301 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
28302@end smallexample
28303
a2c02241
NR
28304Sets the output format for the value of the object @var{name} to be
28305@var{format-spec}.
28306
de051565 28307@anchor{-var-set-format}
a2c02241
NR
28308The syntax for the @var{format-spec} is as follows:
28309
28310@smallexample
28311 @var{format-spec} @expansion{}
28312 @{binary | decimal | hexadecimal | octal | natural@}
28313@end smallexample
28314
c8b2f53c
VP
28315The natural format is the default format choosen automatically
28316based on the variable type (like decimal for an @code{int}, hex
28317for pointers, etc.).
28318
28319For a variable with children, the format is set only on the
28320variable itself, and the children are not affected.
a2c02241
NR
28321
28322@subheading The @code{-var-show-format} Command
28323@findex -var-show-format
922fbb7b
AC
28324
28325@subsubheading Synopsis
28326
28327@smallexample
a2c02241 28328 -var-show-format @var{name}
922fbb7b
AC
28329@end smallexample
28330
a2c02241 28331Returns the format used to display the value of the object @var{name}.
922fbb7b 28332
a2c02241
NR
28333@smallexample
28334 @var{format} @expansion{}
28335 @var{format-spec}
28336@end smallexample
922fbb7b 28337
922fbb7b 28338
a2c02241
NR
28339@subheading The @code{-var-info-num-children} Command
28340@findex -var-info-num-children
28341
28342@subsubheading Synopsis
28343
28344@smallexample
28345 -var-info-num-children @var{name}
28346@end smallexample
28347
28348Returns the number of children of a variable object @var{name}:
28349
28350@smallexample
28351 numchild=@var{n}
28352@end smallexample
28353
0cc7d26f
TT
28354Note that this number is not completely reliable for a dynamic varobj.
28355It will return the current number of children, but more children may
28356be available.
28357
a2c02241
NR
28358
28359@subheading The @code{-var-list-children} Command
28360@findex -var-list-children
28361
28362@subsubheading Synopsis
28363
28364@smallexample
0cc7d26f 28365 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
a2c02241 28366@end smallexample
b569d230 28367@anchor{-var-list-children}
a2c02241
NR
28368
28369Return a list of the children of the specified variable object and
28370create variable objects for them, if they do not already exist. With
f5011d11 28371a single argument or if @var{print-values} has a value of 0 or
a2c02241
NR
28372@code{--no-values}, print only the names of the variables; if
28373@var{print-values} is 1 or @code{--all-values}, also print their
28374values; and if it is 2 or @code{--simple-values} print the name and
28375value for simple data types and just the name for arrays, structures
28376and unions.
922fbb7b 28377
0cc7d26f
TT
28378@var{from} and @var{to}, if specified, indicate the range of children
28379to report. If @var{from} or @var{to} is less than zero, the range is
28380reset and all children will be reported. Otherwise, children starting
28381at @var{from} (zero-based) and up to and excluding @var{to} will be
28382reported.
28383
28384If a child range is requested, it will only affect the current call to
28385@code{-var-list-children}, but not future calls to @code{-var-update}.
28386For this, you must instead use @code{-var-set-update-range}. The
28387intent of this approach is to enable a front end to implement any
28388update approach it likes; for example, scrolling a view may cause the
28389front end to request more children with @code{-var-list-children}, and
28390then the front end could call @code{-var-set-update-range} with a
28391different range to ensure that future updates are restricted to just
28392the visible items.
28393
b569d230
EZ
28394For each child the following results are returned:
28395
28396@table @var
28397
28398@item name
28399Name of the variable object created for this child.
28400
28401@item exp
28402The expression to be shown to the user by the front end to designate this child.
28403For example this may be the name of a structure member.
28404
0cc7d26f
TT
28405For a dynamic varobj, this value cannot be used to form an
28406expression. There is no way to do this at all with a dynamic varobj.
28407
b569d230
EZ
28408For C/C@t{++} structures there are several pseudo children returned to
28409designate access qualifiers. For these pseudo children @var{exp} is
28410@samp{public}, @samp{private}, or @samp{protected}. In this case the
28411type and value are not present.
28412
0cc7d26f
TT
28413A dynamic varobj will not report the access qualifying
28414pseudo-children, regardless of the language. This information is not
28415available at all with a dynamic varobj.
28416
b569d230 28417@item numchild
0cc7d26f
TT
28418Number of children this child has. For a dynamic varobj, this will be
284190.
b569d230
EZ
28420
28421@item type
8264ba82
AG
28422The type of the child. If @samp{print object}
28423(@pxref{Print Settings, set print object}) is set to @code{on}, the
28424@emph{actual} (derived) type of the object is shown rather than the
28425@emph{declared} one.
b569d230
EZ
28426
28427@item value
28428If values were requested, this is the value.
28429
28430@item thread-id
28431If this variable object is associated with a thread, this is the thread id.
28432Otherwise this result is not present.
28433
28434@item frozen
28435If the variable object is frozen, this variable will be present with a value of 1.
c78feb39 28436
9df9dbe0
YQ
28437@item displayhint
28438A dynamic varobj can supply a display hint to the front end. The
28439value comes directly from the Python pretty-printer object's
28440@code{display_hint} method. @xref{Pretty Printing API}.
28441
c78feb39
YQ
28442@item dynamic
28443This attribute will be present and have the value @samp{1} if the
28444varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
28445then this attribute will not be present.
28446
b569d230
EZ
28447@end table
28448
0cc7d26f
TT
28449The result may have its own attributes:
28450
28451@table @samp
28452@item displayhint
28453A dynamic varobj can supply a display hint to the front end. The
28454value comes directly from the Python pretty-printer object's
4c374409 28455@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
28456
28457@item has_more
28458This is an integer attribute which is nonzero if there are children
28459remaining after the end of the selected range.
28460@end table
28461
922fbb7b
AC
28462@subsubheading Example
28463
28464@smallexample
594fe323 28465(gdb)
a2c02241 28466 -var-list-children n
b569d230 28467 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 28468 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 28469(gdb)
a2c02241 28470 -var-list-children --all-values n
b569d230 28471 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 28472 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
28473@end smallexample
28474
922fbb7b 28475
a2c02241
NR
28476@subheading The @code{-var-info-type} Command
28477@findex -var-info-type
922fbb7b 28478
a2c02241
NR
28479@subsubheading Synopsis
28480
28481@smallexample
28482 -var-info-type @var{name}
28483@end smallexample
28484
28485Returns the type of the specified variable @var{name}. The type is
28486returned as a string in the same format as it is output by the
28487@value{GDBN} CLI:
28488
28489@smallexample
28490 type=@var{typename}
28491@end smallexample
28492
28493
28494@subheading The @code{-var-info-expression} Command
28495@findex -var-info-expression
922fbb7b
AC
28496
28497@subsubheading Synopsis
28498
28499@smallexample
a2c02241 28500 -var-info-expression @var{name}
922fbb7b
AC
28501@end smallexample
28502
02142340
VP
28503Returns a string that is suitable for presenting this
28504variable object in user interface. The string is generally
28505not valid expression in the current language, and cannot be evaluated.
28506
28507For example, if @code{a} is an array, and variable object
28508@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 28509
a2c02241 28510@smallexample
02142340
VP
28511(gdb) -var-info-expression A.1
28512^done,lang="C",exp="1"
a2c02241 28513@end smallexample
922fbb7b 28514
a2c02241 28515@noindent
fa4d0c40
YQ
28516Here, the value of @code{lang} is the language name, which can be
28517found in @ref{Supported Languages}.
02142340
VP
28518
28519Note that the output of the @code{-var-list-children} command also
28520includes those expressions, so the @code{-var-info-expression} command
28521is of limited use.
28522
28523@subheading The @code{-var-info-path-expression} Command
28524@findex -var-info-path-expression
28525
28526@subsubheading Synopsis
28527
28528@smallexample
28529 -var-info-path-expression @var{name}
28530@end smallexample
28531
28532Returns an expression that can be evaluated in the current
28533context and will yield the same value that a variable object has.
28534Compare this with the @code{-var-info-expression} command, which
28535result can be used only for UI presentation. Typical use of
28536the @code{-var-info-path-expression} command is creating a
28537watchpoint from a variable object.
28538
0cc7d26f
TT
28539This command is currently not valid for children of a dynamic varobj,
28540and will give an error when invoked on one.
28541
02142340
VP
28542For example, suppose @code{C} is a C@t{++} class, derived from class
28543@code{Base}, and that the @code{Base} class has a member called
28544@code{m_size}. Assume a variable @code{c} is has the type of
28545@code{C} and a variable object @code{C} was created for variable
28546@code{c}. Then, we'll get this output:
28547@smallexample
28548(gdb) -var-info-path-expression C.Base.public.m_size
28549^done,path_expr=((Base)c).m_size)
28550@end smallexample
922fbb7b 28551
a2c02241
NR
28552@subheading The @code{-var-show-attributes} Command
28553@findex -var-show-attributes
922fbb7b 28554
a2c02241 28555@subsubheading Synopsis
922fbb7b 28556
a2c02241
NR
28557@smallexample
28558 -var-show-attributes @var{name}
28559@end smallexample
922fbb7b 28560
a2c02241 28561List attributes of the specified variable object @var{name}:
922fbb7b
AC
28562
28563@smallexample
a2c02241 28564 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
28565@end smallexample
28566
a2c02241
NR
28567@noindent
28568where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
28569
28570@subheading The @code{-var-evaluate-expression} Command
28571@findex -var-evaluate-expression
28572
28573@subsubheading Synopsis
28574
28575@smallexample
de051565 28576 -var-evaluate-expression [-f @var{format-spec}] @var{name}
a2c02241
NR
28577@end smallexample
28578
28579Evaluates the expression that is represented by the specified variable
de051565
MK
28580object and returns its value as a string. The format of the string
28581can be specified with the @samp{-f} option. The possible values of
28582this option are the same as for @code{-var-set-format}
28583(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
28584the current display format will be used. The current display format
28585can be changed using the @code{-var-set-format} command.
a2c02241
NR
28586
28587@smallexample
28588 value=@var{value}
28589@end smallexample
28590
28591Note that one must invoke @code{-var-list-children} for a variable
28592before the value of a child variable can be evaluated.
28593
28594@subheading The @code{-var-assign} Command
28595@findex -var-assign
28596
28597@subsubheading Synopsis
28598
28599@smallexample
28600 -var-assign @var{name} @var{expression}
28601@end smallexample
28602
28603Assigns the value of @var{expression} to the variable object specified
28604by @var{name}. The object must be @samp{editable}. If the variable's
28605value is altered by the assign, the variable will show up in any
28606subsequent @code{-var-update} list.
28607
28608@subsubheading Example
922fbb7b
AC
28609
28610@smallexample
594fe323 28611(gdb)
a2c02241
NR
28612-var-assign var1 3
28613^done,value="3"
594fe323 28614(gdb)
a2c02241
NR
28615-var-update *
28616^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 28617(gdb)
922fbb7b
AC
28618@end smallexample
28619
a2c02241
NR
28620@subheading The @code{-var-update} Command
28621@findex -var-update
28622
28623@subsubheading Synopsis
28624
28625@smallexample
28626 -var-update [@var{print-values}] @{@var{name} | "*"@}
28627@end smallexample
28628
c8b2f53c
VP
28629Reevaluate the expressions corresponding to the variable object
28630@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
28631list of variable objects whose values have changed; @var{name} must
28632be a root variable object. Here, ``changed'' means that the result of
28633@code{-var-evaluate-expression} before and after the
28634@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
28635object names, all existing variable objects are updated, except
28636for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3 28637@var{print-values} determines whether both names and values, or just
de051565 28638names are printed. The possible values of this option are the same
36ece8b3
NR
28639as for @code{-var-list-children} (@pxref{-var-list-children}). It is
28640recommended to use the @samp{--all-values} option, to reduce the
28641number of MI commands needed on each program stop.
c8b2f53c 28642
c3b108f7
VP
28643With the @samp{*} parameter, if a variable object is bound to a
28644currently running thread, it will not be updated, without any
28645diagnostic.
a2c02241 28646
0cc7d26f
TT
28647If @code{-var-set-update-range} was previously used on a varobj, then
28648only the selected range of children will be reported.
922fbb7b 28649
0cc7d26f
TT
28650@code{-var-update} reports all the changed varobjs in a tuple named
28651@samp{changelist}.
28652
28653Each item in the change list is itself a tuple holding:
28654
28655@table @samp
28656@item name
28657The name of the varobj.
28658
28659@item value
28660If values were requested for this update, then this field will be
28661present and will hold the value of the varobj.
922fbb7b 28662
0cc7d26f 28663@item in_scope
9f708cb2 28664@anchor{-var-update}
0cc7d26f 28665This field is a string which may take one of three values:
36ece8b3
NR
28666
28667@table @code
28668@item "true"
28669The variable object's current value is valid.
28670
28671@item "false"
28672The variable object does not currently hold a valid value but it may
28673hold one in the future if its associated expression comes back into
28674scope.
28675
28676@item "invalid"
28677The variable object no longer holds a valid value.
28678This can occur when the executable file being debugged has changed,
28679either through recompilation or by using the @value{GDBN} @code{file}
28680command. The front end should normally choose to delete these variable
28681objects.
28682@end table
28683
28684In the future new values may be added to this list so the front should
28685be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
28686
0cc7d26f
TT
28687@item type_changed
28688This is only present if the varobj is still valid. If the type
28689changed, then this will be the string @samp{true}; otherwise it will
28690be @samp{false}.
28691
7191c139
JB
28692When a varobj's type changes, its children are also likely to have
28693become incorrect. Therefore, the varobj's children are automatically
28694deleted when this attribute is @samp{true}. Also, the varobj's update
28695range, when set using the @code{-var-set-update-range} command, is
28696unset.
28697
0cc7d26f
TT
28698@item new_type
28699If the varobj's type changed, then this field will be present and will
28700hold the new type.
28701
28702@item new_num_children
28703For a dynamic varobj, if the number of children changed, or if the
28704type changed, this will be the new number of children.
28705
28706The @samp{numchild} field in other varobj responses is generally not
28707valid for a dynamic varobj -- it will show the number of children that
28708@value{GDBN} knows about, but because dynamic varobjs lazily
28709instantiate their children, this will not reflect the number of
28710children which may be available.
28711
28712The @samp{new_num_children} attribute only reports changes to the
28713number of children known by @value{GDBN}. This is the only way to
28714detect whether an update has removed children (which necessarily can
28715only happen at the end of the update range).
28716
28717@item displayhint
28718The display hint, if any.
28719
28720@item has_more
28721This is an integer value, which will be 1 if there are more children
28722available outside the varobj's update range.
28723
28724@item dynamic
28725This attribute will be present and have the value @samp{1} if the
28726varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
28727then this attribute will not be present.
28728
28729@item new_children
28730If new children were added to a dynamic varobj within the selected
28731update range (as set by @code{-var-set-update-range}), then they will
28732be listed in this attribute.
28733@end table
28734
28735@subsubheading Example
28736
28737@smallexample
28738(gdb)
28739-var-assign var1 3
28740^done,value="3"
28741(gdb)
28742-var-update --all-values var1
28743^done,changelist=[@{name="var1",value="3",in_scope="true",
28744type_changed="false"@}]
28745(gdb)
28746@end smallexample
28747
25d5ea92
VP
28748@subheading The @code{-var-set-frozen} Command
28749@findex -var-set-frozen
9f708cb2 28750@anchor{-var-set-frozen}
25d5ea92
VP
28751
28752@subsubheading Synopsis
28753
28754@smallexample
9f708cb2 28755 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
28756@end smallexample
28757
9f708cb2 28758Set the frozenness flag on the variable object @var{name}. The
25d5ea92 28759@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 28760frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 28761frozen, then neither itself, nor any of its children, are
9f708cb2 28762implicitly updated by @code{-var-update} of
25d5ea92
VP
28763a parent variable or by @code{-var-update *}. Only
28764@code{-var-update} of the variable itself will update its value and
28765values of its children. After a variable object is unfrozen, it is
28766implicitly updated by all subsequent @code{-var-update} operations.
28767Unfreezing a variable does not update it, only subsequent
28768@code{-var-update} does.
28769
28770@subsubheading Example
28771
28772@smallexample
28773(gdb)
28774-var-set-frozen V 1
28775^done
28776(gdb)
28777@end smallexample
28778
0cc7d26f
TT
28779@subheading The @code{-var-set-update-range} command
28780@findex -var-set-update-range
28781@anchor{-var-set-update-range}
28782
28783@subsubheading Synopsis
28784
28785@smallexample
28786 -var-set-update-range @var{name} @var{from} @var{to}
28787@end smallexample
28788
28789Set the range of children to be returned by future invocations of
28790@code{-var-update}.
28791
28792@var{from} and @var{to} indicate the range of children to report. If
28793@var{from} or @var{to} is less than zero, the range is reset and all
28794children will be reported. Otherwise, children starting at @var{from}
28795(zero-based) and up to and excluding @var{to} will be reported.
28796
28797@subsubheading Example
28798
28799@smallexample
28800(gdb)
28801-var-set-update-range V 1 2
28802^done
28803@end smallexample
28804
b6313243
TT
28805@subheading The @code{-var-set-visualizer} command
28806@findex -var-set-visualizer
28807@anchor{-var-set-visualizer}
28808
28809@subsubheading Synopsis
28810
28811@smallexample
28812 -var-set-visualizer @var{name} @var{visualizer}
28813@end smallexample
28814
28815Set a visualizer for the variable object @var{name}.
28816
28817@var{visualizer} is the visualizer to use. The special value
28818@samp{None} means to disable any visualizer in use.
28819
28820If not @samp{None}, @var{visualizer} must be a Python expression.
28821This expression must evaluate to a callable object which accepts a
28822single argument. @value{GDBN} will call this object with the value of
28823the varobj @var{name} as an argument (this is done so that the same
28824Python pretty-printing code can be used for both the CLI and MI).
28825When called, this object must return an object which conforms to the
4c374409 28826pretty-printing interface (@pxref{Pretty Printing API}).
b6313243
TT
28827
28828The pre-defined function @code{gdb.default_visualizer} may be used to
28829select a visualizer by following the built-in process
28830(@pxref{Selecting Pretty-Printers}). This is done automatically when
28831a varobj is created, and so ordinarily is not needed.
28832
28833This feature is only available if Python support is enabled. The MI
d192b373 28834command @code{-list-features} (@pxref{GDB/MI Support Commands})
b6313243
TT
28835can be used to check this.
28836
28837@subsubheading Example
28838
28839Resetting the visualizer:
28840
28841@smallexample
28842(gdb)
28843-var-set-visualizer V None
28844^done
28845@end smallexample
28846
28847Reselecting the default (type-based) visualizer:
28848
28849@smallexample
28850(gdb)
28851-var-set-visualizer V gdb.default_visualizer
28852^done
28853@end smallexample
28854
28855Suppose @code{SomeClass} is a visualizer class. A lambda expression
28856can be used to instantiate this class for a varobj:
28857
28858@smallexample
28859(gdb)
28860-var-set-visualizer V "lambda val: SomeClass()"
28861^done
28862@end smallexample
25d5ea92 28863
a2c02241
NR
28864@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28865@node GDB/MI Data Manipulation
28866@section @sc{gdb/mi} Data Manipulation
922fbb7b 28867
a2c02241
NR
28868@cindex data manipulation, in @sc{gdb/mi}
28869@cindex @sc{gdb/mi}, data manipulation
28870This section describes the @sc{gdb/mi} commands that manipulate data:
28871examine memory and registers, evaluate expressions, etc.
28872
28873@c REMOVED FROM THE INTERFACE.
28874@c @subheading -data-assign
28875@c Change the value of a program variable. Plenty of side effects.
79a6e687 28876@c @subsubheading GDB Command
a2c02241
NR
28877@c set variable
28878@c @subsubheading Example
28879@c N.A.
28880
28881@subheading The @code{-data-disassemble} Command
28882@findex -data-disassemble
922fbb7b
AC
28883
28884@subsubheading Synopsis
28885
28886@smallexample
a2c02241
NR
28887 -data-disassemble
28888 [ -s @var{start-addr} -e @var{end-addr} ]
28889 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
28890 -- @var{mode}
922fbb7b
AC
28891@end smallexample
28892
a2c02241
NR
28893@noindent
28894Where:
28895
28896@table @samp
28897@item @var{start-addr}
28898is the beginning address (or @code{$pc})
28899@item @var{end-addr}
28900is the end address
28901@item @var{filename}
28902is the name of the file to disassemble
28903@item @var{linenum}
28904is the line number to disassemble around
28905@item @var{lines}
d3e8051b 28906is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
28907the whole function will be disassembled, in case no @var{end-addr} is
28908specified. If @var{end-addr} is specified as a non-zero value, and
28909@var{lines} is lower than the number of disassembly lines between
28910@var{start-addr} and @var{end-addr}, only @var{lines} lines are
28911displayed; if @var{lines} is higher than the number of lines between
28912@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
28913are displayed.
28914@item @var{mode}
b716877b
AB
28915is either 0 (meaning only disassembly), 1 (meaning mixed source and
28916disassembly), 2 (meaning disassembly with raw opcodes), or 3 (meaning
28917mixed source and disassembly with raw opcodes).
a2c02241
NR
28918@end table
28919
28920@subsubheading Result
28921
ed8a1c2d
AB
28922The result of the @code{-data-disassemble} command will be a list named
28923@samp{asm_insns}, the contents of this list depend on the @var{mode}
28924used with the @code{-data-disassemble} command.
a2c02241 28925
ed8a1c2d
AB
28926For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
28927following fields:
28928
28929@table @code
28930@item address
28931The address at which this instruction was disassembled.
28932
28933@item func-name
28934The name of the function this instruction is within.
28935
28936@item offset
28937The decimal offset in bytes from the start of @samp{func-name}.
28938
28939@item inst
28940The text disassembly for this @samp{address}.
28941
28942@item opcodes
28943This field is only present for mode 2. This contains the raw opcode
28944bytes for the @samp{inst} field.
28945
28946@end table
28947
28948For modes 1 and 3 the @samp{asm_insns} list contains tuples named
28949@samp{src_and_asm_line}, each of which has the following fields:
a2c02241 28950
ed8a1c2d
AB
28951@table @code
28952@item line
28953The line number within @samp{file}.
28954
28955@item file
28956The file name from the compilation unit. This might be an absolute
28957file name or a relative file name depending on the compile command
28958used.
28959
28960@item fullname
f35a17b5
JK
28961Absolute file name of @samp{file}. It is converted to a canonical form
28962using the source file search path
28963(@pxref{Source Path, ,Specifying Source Directories})
28964and after resolving all the symbolic links.
28965
28966If the source file is not found this field will contain the path as
28967present in the debug information.
ed8a1c2d
AB
28968
28969@item line_asm_insn
28970This is a list of tuples containing the disassembly for @samp{line} in
28971@samp{file}. The fields of each tuple are the same as for
28972@code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
28973@samp{func-name}, @samp{offset}, @samp{inst}, and optionally
28974@samp{opcodes}.
28975
28976@end table
28977
28978Note that whatever included in the @samp{inst} field, is not
28979manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
28980adjust its format.
922fbb7b
AC
28981
28982@subsubheading @value{GDBN} Command
28983
ed8a1c2d 28984The corresponding @value{GDBN} command is @samp{disassemble}.
922fbb7b
AC
28985
28986@subsubheading Example
28987
a2c02241
NR
28988Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
28989
922fbb7b 28990@smallexample
594fe323 28991(gdb)
a2c02241
NR
28992-data-disassemble -s $pc -e "$pc + 20" -- 0
28993^done,
28994asm_insns=[
28995@{address="0x000107c0",func-name="main",offset="4",
28996inst="mov 2, %o0"@},
28997@{address="0x000107c4",func-name="main",offset="8",
28998inst="sethi %hi(0x11800), %o2"@},
28999@{address="0x000107c8",func-name="main",offset="12",
29000inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
29001@{address="0x000107cc",func-name="main",offset="16",
29002inst="sethi %hi(0x11800), %o2"@},
29003@{address="0x000107d0",func-name="main",offset="20",
29004inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 29005(gdb)
a2c02241
NR
29006@end smallexample
29007
29008Disassemble the whole @code{main} function. Line 32 is part of
29009@code{main}.
29010
29011@smallexample
29012-data-disassemble -f basics.c -l 32 -- 0
29013^done,asm_insns=[
29014@{address="0x000107bc",func-name="main",offset="0",
29015inst="save %sp, -112, %sp"@},
29016@{address="0x000107c0",func-name="main",offset="4",
29017inst="mov 2, %o0"@},
29018@{address="0x000107c4",func-name="main",offset="8",
29019inst="sethi %hi(0x11800), %o2"@},
29020[@dots{}]
29021@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
29022@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 29023(gdb)
922fbb7b
AC
29024@end smallexample
29025
a2c02241 29026Disassemble 3 instructions from the start of @code{main}:
922fbb7b 29027
a2c02241 29028@smallexample
594fe323 29029(gdb)
a2c02241
NR
29030-data-disassemble -f basics.c -l 32 -n 3 -- 0
29031^done,asm_insns=[
29032@{address="0x000107bc",func-name="main",offset="0",
29033inst="save %sp, -112, %sp"@},
29034@{address="0x000107c0",func-name="main",offset="4",
29035inst="mov 2, %o0"@},
29036@{address="0x000107c4",func-name="main",offset="8",
29037inst="sethi %hi(0x11800), %o2"@}]
594fe323 29038(gdb)
a2c02241
NR
29039@end smallexample
29040
29041Disassemble 3 instructions from the start of @code{main} in mixed mode:
29042
29043@smallexample
594fe323 29044(gdb)
a2c02241
NR
29045-data-disassemble -f basics.c -l 32 -n 3 -- 1
29046^done,asm_insns=[
29047src_and_asm_line=@{line="31",
ed8a1c2d
AB
29048file="../../../src/gdb/testsuite/gdb.mi/basics.c",
29049fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
29050line_asm_insn=[@{address="0x000107bc",
29051func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
a2c02241 29052src_and_asm_line=@{line="32",
ed8a1c2d
AB
29053file="../../../src/gdb/testsuite/gdb.mi/basics.c",
29054fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
29055line_asm_insn=[@{address="0x000107c0",
29056func-name="main",offset="4",inst="mov 2, %o0"@},
a2c02241
NR
29057@{address="0x000107c4",func-name="main",offset="8",
29058inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 29059(gdb)
a2c02241
NR
29060@end smallexample
29061
29062
29063@subheading The @code{-data-evaluate-expression} Command
29064@findex -data-evaluate-expression
922fbb7b
AC
29065
29066@subsubheading Synopsis
29067
29068@smallexample
a2c02241 29069 -data-evaluate-expression @var{expr}
922fbb7b
AC
29070@end smallexample
29071
a2c02241
NR
29072Evaluate @var{expr} as an expression. The expression could contain an
29073inferior function call. The function call will execute synchronously.
29074If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
29075
29076@subsubheading @value{GDBN} Command
29077
a2c02241
NR
29078The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
29079@samp{call}. In @code{gdbtk} only, there's a corresponding
29080@samp{gdb_eval} command.
922fbb7b
AC
29081
29082@subsubheading Example
29083
a2c02241
NR
29084In the following example, the numbers that precede the commands are the
29085@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
29086Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
29087output.
29088
922fbb7b 29089@smallexample
a2c02241
NR
29090211-data-evaluate-expression A
29091211^done,value="1"
594fe323 29092(gdb)
a2c02241
NR
29093311-data-evaluate-expression &A
29094311^done,value="0xefffeb7c"
594fe323 29095(gdb)
a2c02241
NR
29096411-data-evaluate-expression A+3
29097411^done,value="4"
594fe323 29098(gdb)
a2c02241
NR
29099511-data-evaluate-expression "A + 3"
29100511^done,value="4"
594fe323 29101(gdb)
a2c02241 29102@end smallexample
922fbb7b
AC
29103
29104
a2c02241
NR
29105@subheading The @code{-data-list-changed-registers} Command
29106@findex -data-list-changed-registers
922fbb7b
AC
29107
29108@subsubheading Synopsis
29109
29110@smallexample
a2c02241 29111 -data-list-changed-registers
922fbb7b
AC
29112@end smallexample
29113
a2c02241 29114Display a list of the registers that have changed.
922fbb7b
AC
29115
29116@subsubheading @value{GDBN} Command
29117
a2c02241
NR
29118@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
29119has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
29120
29121@subsubheading Example
922fbb7b 29122
a2c02241 29123On a PPC MBX board:
922fbb7b
AC
29124
29125@smallexample
594fe323 29126(gdb)
a2c02241
NR
29127-exec-continue
29128^running
922fbb7b 29129
594fe323 29130(gdb)
a47ec5fe
AR
29131*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
29132func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
29133line="5"@}
594fe323 29134(gdb)
a2c02241
NR
29135-data-list-changed-registers
29136^done,changed-registers=["0","1","2","4","5","6","7","8","9",
29137"10","11","13","14","15","16","17","18","19","20","21","22","23",
29138"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 29139(gdb)
a2c02241 29140@end smallexample
922fbb7b
AC
29141
29142
a2c02241
NR
29143@subheading The @code{-data-list-register-names} Command
29144@findex -data-list-register-names
922fbb7b
AC
29145
29146@subsubheading Synopsis
29147
29148@smallexample
a2c02241 29149 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
29150@end smallexample
29151
a2c02241
NR
29152Show a list of register names for the current target. If no arguments
29153are given, it shows a list of the names of all the registers. If
29154integer numbers are given as arguments, it will print a list of the
29155names of the registers corresponding to the arguments. To ensure
29156consistency between a register name and its number, the output list may
29157include empty register names.
922fbb7b
AC
29158
29159@subsubheading @value{GDBN} Command
29160
a2c02241
NR
29161@value{GDBN} does not have a command which corresponds to
29162@samp{-data-list-register-names}. In @code{gdbtk} there is a
29163corresponding command @samp{gdb_regnames}.
922fbb7b
AC
29164
29165@subsubheading Example
922fbb7b 29166
a2c02241
NR
29167For the PPC MBX board:
29168@smallexample
594fe323 29169(gdb)
a2c02241
NR
29170-data-list-register-names
29171^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
29172"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
29173"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
29174"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
29175"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
29176"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
29177"", "pc","ps","cr","lr","ctr","xer"]
594fe323 29178(gdb)
a2c02241
NR
29179-data-list-register-names 1 2 3
29180^done,register-names=["r1","r2","r3"]
594fe323 29181(gdb)
a2c02241 29182@end smallexample
922fbb7b 29183
a2c02241
NR
29184@subheading The @code{-data-list-register-values} Command
29185@findex -data-list-register-values
922fbb7b
AC
29186
29187@subsubheading Synopsis
29188
29189@smallexample
c898adb7
YQ
29190 -data-list-register-values
29191 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
29192@end smallexample
29193
a2c02241
NR
29194Display the registers' contents. @var{fmt} is the format according to
29195which the registers' contents are to be returned, followed by an optional
29196list of numbers specifying the registers to display. A missing list of
c898adb7
YQ
29197numbers indicates that the contents of all the registers must be
29198returned. The @code{--skip-unavailable} option indicates that only
29199the available registers are to be returned.
a2c02241
NR
29200
29201Allowed formats for @var{fmt} are:
29202
29203@table @code
29204@item x
29205Hexadecimal
29206@item o
29207Octal
29208@item t
29209Binary
29210@item d
29211Decimal
29212@item r
29213Raw
29214@item N
29215Natural
29216@end table
922fbb7b
AC
29217
29218@subsubheading @value{GDBN} Command
29219
a2c02241
NR
29220The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
29221all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
29222
29223@subsubheading Example
922fbb7b 29224
a2c02241
NR
29225For a PPC MBX board (note: line breaks are for readability only, they
29226don't appear in the actual output):
29227
29228@smallexample
594fe323 29229(gdb)
a2c02241
NR
29230-data-list-register-values r 64 65
29231^done,register-values=[@{number="64",value="0xfe00a300"@},
29232@{number="65",value="0x00029002"@}]
594fe323 29233(gdb)
a2c02241
NR
29234-data-list-register-values x
29235^done,register-values=[@{number="0",value="0xfe0043c8"@},
29236@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
29237@{number="3",value="0x0"@},@{number="4",value="0xa"@},
29238@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
29239@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
29240@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
29241@{number="11",value="0x1"@},@{number="12",value="0x0"@},
29242@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
29243@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
29244@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
29245@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
29246@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
29247@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
29248@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
29249@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
29250@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
29251@{number="31",value="0x0"@},@{number="32",value="0x0"@},
29252@{number="33",value="0x0"@},@{number="34",value="0x0"@},
29253@{number="35",value="0x0"@},@{number="36",value="0x0"@},
29254@{number="37",value="0x0"@},@{number="38",value="0x0"@},
29255@{number="39",value="0x0"@},@{number="40",value="0x0"@},
29256@{number="41",value="0x0"@},@{number="42",value="0x0"@},
29257@{number="43",value="0x0"@},@{number="44",value="0x0"@},
29258@{number="45",value="0x0"@},@{number="46",value="0x0"@},
29259@{number="47",value="0x0"@},@{number="48",value="0x0"@},
29260@{number="49",value="0x0"@},@{number="50",value="0x0"@},
29261@{number="51",value="0x0"@},@{number="52",value="0x0"@},
29262@{number="53",value="0x0"@},@{number="54",value="0x0"@},
29263@{number="55",value="0x0"@},@{number="56",value="0x0"@},
29264@{number="57",value="0x0"@},@{number="58",value="0x0"@},
29265@{number="59",value="0x0"@},@{number="60",value="0x0"@},
29266@{number="61",value="0x0"@},@{number="62",value="0x0"@},
29267@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
29268@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
29269@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
29270@{number="69",value="0x20002b03"@}]
594fe323 29271(gdb)
a2c02241 29272@end smallexample
922fbb7b 29273
a2c02241
NR
29274
29275@subheading The @code{-data-read-memory} Command
29276@findex -data-read-memory
922fbb7b 29277
8dedea02
VP
29278This command is deprecated, use @code{-data-read-memory-bytes} instead.
29279
922fbb7b
AC
29280@subsubheading Synopsis
29281
29282@smallexample
a2c02241
NR
29283 -data-read-memory [ -o @var{byte-offset} ]
29284 @var{address} @var{word-format} @var{word-size}
29285 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
29286@end smallexample
29287
a2c02241
NR
29288@noindent
29289where:
922fbb7b 29290
a2c02241
NR
29291@table @samp
29292@item @var{address}
29293An expression specifying the address of the first memory word to be
29294read. Complex expressions containing embedded white space should be
29295quoted using the C convention.
922fbb7b 29296
a2c02241
NR
29297@item @var{word-format}
29298The format to be used to print the memory words. The notation is the
29299same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 29300,Output Formats}).
922fbb7b 29301
a2c02241
NR
29302@item @var{word-size}
29303The size of each memory word in bytes.
922fbb7b 29304
a2c02241
NR
29305@item @var{nr-rows}
29306The number of rows in the output table.
922fbb7b 29307
a2c02241
NR
29308@item @var{nr-cols}
29309The number of columns in the output table.
922fbb7b 29310
a2c02241
NR
29311@item @var{aschar}
29312If present, indicates that each row should include an @sc{ascii} dump. The
29313value of @var{aschar} is used as a padding character when a byte is not a
29314member of the printable @sc{ascii} character set (printable @sc{ascii}
29315characters are those whose code is between 32 and 126, inclusively).
922fbb7b 29316
a2c02241
NR
29317@item @var{byte-offset}
29318An offset to add to the @var{address} before fetching memory.
29319@end table
922fbb7b 29320
a2c02241
NR
29321This command displays memory contents as a table of @var{nr-rows} by
29322@var{nr-cols} words, each word being @var{word-size} bytes. In total,
29323@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
29324(returned as @samp{total-bytes}). Should less than the requested number
29325of bytes be returned by the target, the missing words are identified
29326using @samp{N/A}. The number of bytes read from the target is returned
29327in @samp{nr-bytes} and the starting address used to read memory in
29328@samp{addr}.
29329
29330The address of the next/previous row or page is available in
29331@samp{next-row} and @samp{prev-row}, @samp{next-page} and
29332@samp{prev-page}.
922fbb7b
AC
29333
29334@subsubheading @value{GDBN} Command
29335
a2c02241
NR
29336The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
29337@samp{gdb_get_mem} memory read command.
922fbb7b
AC
29338
29339@subsubheading Example
32e7087d 29340
a2c02241
NR
29341Read six bytes of memory starting at @code{bytes+6} but then offset by
29342@code{-6} bytes. Format as three rows of two columns. One byte per
29343word. Display each word in hex.
32e7087d
JB
29344
29345@smallexample
594fe323 29346(gdb)
a2c02241
NR
293479-data-read-memory -o -6 -- bytes+6 x 1 3 2
293489^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
29349next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
29350prev-page="0x0000138a",memory=[
29351@{addr="0x00001390",data=["0x00","0x01"]@},
29352@{addr="0x00001392",data=["0x02","0x03"]@},
29353@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 29354(gdb)
32e7087d
JB
29355@end smallexample
29356
a2c02241
NR
29357Read two bytes of memory starting at address @code{shorts + 64} and
29358display as a single word formatted in decimal.
32e7087d 29359
32e7087d 29360@smallexample
594fe323 29361(gdb)
a2c02241
NR
293625-data-read-memory shorts+64 d 2 1 1
293635^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
29364next-row="0x00001512",prev-row="0x0000150e",
29365next-page="0x00001512",prev-page="0x0000150e",memory=[
29366@{addr="0x00001510",data=["128"]@}]
594fe323 29367(gdb)
32e7087d
JB
29368@end smallexample
29369
a2c02241
NR
29370Read thirty two bytes of memory starting at @code{bytes+16} and format
29371as eight rows of four columns. Include a string encoding with @samp{x}
29372used as the non-printable character.
922fbb7b
AC
29373
29374@smallexample
594fe323 29375(gdb)
a2c02241
NR
293764-data-read-memory bytes+16 x 1 8 4 x
293774^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
29378next-row="0x000013c0",prev-row="0x0000139c",
29379next-page="0x000013c0",prev-page="0x00001380",memory=[
29380@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
29381@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
29382@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
29383@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
29384@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
29385@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
29386@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
29387@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 29388(gdb)
922fbb7b
AC
29389@end smallexample
29390
8dedea02
VP
29391@subheading The @code{-data-read-memory-bytes} Command
29392@findex -data-read-memory-bytes
29393
29394@subsubheading Synopsis
29395
29396@smallexample
29397 -data-read-memory-bytes [ -o @var{byte-offset} ]
29398 @var{address} @var{count}
29399@end smallexample
29400
29401@noindent
29402where:
29403
29404@table @samp
29405@item @var{address}
29406An expression specifying the address of the first memory word to be
29407read. Complex expressions containing embedded white space should be
29408quoted using the C convention.
29409
29410@item @var{count}
29411The number of bytes to read. This should be an integer literal.
29412
29413@item @var{byte-offset}
29414The offsets in bytes relative to @var{address} at which to start
29415reading. This should be an integer literal. This option is provided
29416so that a frontend is not required to first evaluate address and then
29417perform address arithmetics itself.
29418
29419@end table
29420
29421This command attempts to read all accessible memory regions in the
29422specified range. First, all regions marked as unreadable in the memory
29423map (if one is defined) will be skipped. @xref{Memory Region
29424Attributes}. Second, @value{GDBN} will attempt to read the remaining
29425regions. For each one, if reading full region results in an errors,
29426@value{GDBN} will try to read a subset of the region.
29427
29428In general, every single byte in the region may be readable or not,
29429and the only way to read every readable byte is to try a read at
29430every address, which is not practical. Therefore, @value{GDBN} will
29431attempt to read all accessible bytes at either beginning or the end
29432of the region, using a binary division scheme. This heuristic works
29433well for reading accross a memory map boundary. Note that if a region
29434has a readable range that is neither at the beginning or the end,
29435@value{GDBN} will not read it.
29436
29437The result record (@pxref{GDB/MI Result Records}) that is output of
29438the command includes a field named @samp{memory} whose content is a
29439list of tuples. Each tuple represent a successfully read memory block
29440and has the following fields:
29441
29442@table @code
29443@item begin
29444The start address of the memory block, as hexadecimal literal.
29445
29446@item end
29447The end address of the memory block, as hexadecimal literal.
29448
29449@item offset
29450The offset of the memory block, as hexadecimal literal, relative to
29451the start address passed to @code{-data-read-memory-bytes}.
29452
29453@item contents
29454The contents of the memory block, in hex.
29455
29456@end table
29457
29458
29459
29460@subsubheading @value{GDBN} Command
29461
29462The corresponding @value{GDBN} command is @samp{x}.
29463
29464@subsubheading Example
29465
29466@smallexample
29467(gdb)
29468-data-read-memory-bytes &a 10
29469^done,memory=[@{begin="0xbffff154",offset="0x00000000",
29470 end="0xbffff15e",
29471 contents="01000000020000000300"@}]
29472(gdb)
29473@end smallexample
29474
29475
29476@subheading The @code{-data-write-memory-bytes} Command
29477@findex -data-write-memory-bytes
29478
29479@subsubheading Synopsis
29480
29481@smallexample
29482 -data-write-memory-bytes @var{address} @var{contents}
62747a60 29483 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
8dedea02
VP
29484@end smallexample
29485
29486@noindent
29487where:
29488
29489@table @samp
29490@item @var{address}
29491An expression specifying the address of the first memory word to be
29492read. Complex expressions containing embedded white space should be
29493quoted using the C convention.
29494
29495@item @var{contents}
29496The hex-encoded bytes to write.
29497
62747a60
TT
29498@item @var{count}
29499Optional argument indicating the number of bytes to be written. If @var{count}
29500is greater than @var{contents}' length, @value{GDBN} will repeatedly
29501write @var{contents} until it fills @var{count} bytes.
29502
8dedea02
VP
29503@end table
29504
29505@subsubheading @value{GDBN} Command
29506
29507There's no corresponding @value{GDBN} command.
29508
29509@subsubheading Example
29510
29511@smallexample
29512(gdb)
29513-data-write-memory-bytes &a "aabbccdd"
29514^done
29515(gdb)
29516@end smallexample
29517
62747a60
TT
29518@smallexample
29519(gdb)
29520-data-write-memory-bytes &a "aabbccdd" 16e
29521^done
29522(gdb)
29523@end smallexample
8dedea02 29524
a2c02241
NR
29525@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29526@node GDB/MI Tracepoint Commands
29527@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 29528
18148017
VP
29529The commands defined in this section implement MI support for
29530tracepoints. For detailed introduction, see @ref{Tracepoints}.
29531
29532@subheading The @code{-trace-find} Command
29533@findex -trace-find
29534
29535@subsubheading Synopsis
29536
29537@smallexample
29538 -trace-find @var{mode} [@var{parameters}@dots{}]
29539@end smallexample
29540
29541Find a trace frame using criteria defined by @var{mode} and
29542@var{parameters}. The following table lists permissible
29543modes and their parameters. For details of operation, see @ref{tfind}.
29544
29545@table @samp
29546
29547@item none
29548No parameters are required. Stops examining trace frames.
29549
29550@item frame-number
29551An integer is required as parameter. Selects tracepoint frame with
29552that index.
29553
29554@item tracepoint-number
29555An integer is required as parameter. Finds next
29556trace frame that corresponds to tracepoint with the specified number.
29557
29558@item pc
29559An address is required as parameter. Finds
29560next trace frame that corresponds to any tracepoint at the specified
29561address.
29562
29563@item pc-inside-range
29564Two addresses are required as parameters. Finds next trace
29565frame that corresponds to a tracepoint at an address inside the
29566specified range. Both bounds are considered to be inside the range.
29567
29568@item pc-outside-range
29569Two addresses are required as parameters. Finds
29570next trace frame that corresponds to a tracepoint at an address outside
29571the specified range. Both bounds are considered to be inside the range.
29572
29573@item line
29574Line specification is required as parameter. @xref{Specify Location}.
29575Finds next trace frame that corresponds to a tracepoint at
29576the specified location.
29577
29578@end table
29579
29580If @samp{none} was passed as @var{mode}, the response does not
29581have fields. Otherwise, the response may have the following fields:
29582
29583@table @samp
29584@item found
29585This field has either @samp{0} or @samp{1} as the value, depending
29586on whether a matching tracepoint was found.
29587
29588@item traceframe
29589The index of the found traceframe. This field is present iff
29590the @samp{found} field has value of @samp{1}.
29591
29592@item tracepoint
29593The index of the found tracepoint. This field is present iff
29594the @samp{found} field has value of @samp{1}.
29595
29596@item frame
29597The information about the frame corresponding to the found trace
29598frame. This field is present only if a trace frame was found.
cd64ee31 29599@xref{GDB/MI Frame Information}, for description of this field.
18148017
VP
29600
29601@end table
29602
7d13fe92
SS
29603@subsubheading @value{GDBN} Command
29604
29605The corresponding @value{GDBN} command is @samp{tfind}.
29606
18148017
VP
29607@subheading -trace-define-variable
29608@findex -trace-define-variable
29609
29610@subsubheading Synopsis
29611
29612@smallexample
29613 -trace-define-variable @var{name} [ @var{value} ]
29614@end smallexample
29615
29616Create trace variable @var{name} if it does not exist. If
29617@var{value} is specified, sets the initial value of the specified
29618trace variable to that value. Note that the @var{name} should start
29619with the @samp{$} character.
29620
7d13fe92
SS
29621@subsubheading @value{GDBN} Command
29622
29623The corresponding @value{GDBN} command is @samp{tvariable}.
29624
dc673c81
YQ
29625@subheading The @code{-trace-frame-collected} Command
29626@findex -trace-frame-collected
29627
29628@subsubheading Synopsis
29629
29630@smallexample
29631 -trace-frame-collected
29632 [--var-print-values @var{var_pval}]
29633 [--comp-print-values @var{comp_pval}]
29634 [--registers-format @var{regformat}]
29635 [--memory-contents]
29636@end smallexample
29637
29638This command returns the set of collected objects, register names,
29639trace state variable names, memory ranges and computed expressions
29640that have been collected at a particular trace frame. The optional
29641parameters to the command affect the output format in different ways.
29642See the output description table below for more details.
29643
29644The reported names can be used in the normal manner to create
29645varobjs and inspect the objects themselves. The items returned by
29646this command are categorized so that it is clear which is a variable,
29647which is a register, which is a trace state variable, which is a
29648memory range and which is a computed expression.
29649
29650For instance, if the actions were
29651@smallexample
29652collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
29653collect *(int*)0xaf02bef0@@40
29654@end smallexample
29655
29656@noindent
29657the object collected in its entirety would be @code{myVar}. The
29658object @code{myArray} would be partially collected, because only the
29659element at index @code{myIndex} would be collected. The remaining
29660objects would be computed expressions.
29661
29662An example output would be:
29663
29664@smallexample
29665(gdb)
29666-trace-frame-collected
29667^done,
29668 explicit-variables=[@{name="myVar",value="1"@}],
29669 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
29670 @{name="myObj.field",value="0"@},
29671 @{name="myPtr->field",value="1"@},
29672 @{name="myCount + 2",value="3"@},
29673 @{name="$tvar1 + 1",value="43970027"@}],
29674 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
29675 @{number="1",value="0x0"@},
29676 @{number="2",value="0x4"@},
29677 ...
29678 @{number="125",value="0x0"@}],
29679 tvars=[@{name="$tvar1",current="43970026"@}],
29680 memory=[@{address="0x0000000000602264",length="4"@},
29681 @{address="0x0000000000615bc0",length="4"@}]
29682(gdb)
29683@end smallexample
29684
29685Where:
29686
29687@table @code
29688@item explicit-variables
29689The set of objects that have been collected in their entirety (as
29690opposed to collecting just a few elements of an array or a few struct
29691members). For each object, its name and value are printed.
29692The @code{--var-print-values} option affects how or whether the value
29693field is output. If @var{var_pval} is 0, then print only the names;
29694if it is 1, print also their values; and if it is 2, print the name,
29695type and value for simple data types, and the name and type for
29696arrays, structures and unions.
29697
29698@item computed-expressions
29699The set of computed expressions that have been collected at the
29700current trace frame. The @code{--comp-print-values} option affects
29701this set like the @code{--var-print-values} option affects the
29702@code{explicit-variables} set. See above.
29703
29704@item registers
29705The registers that have been collected at the current trace frame.
29706For each register collected, the name and current value are returned.
29707The value is formatted according to the @code{--registers-format}
29708option. See the @command{-data-list-register-values} command for a
29709list of the allowed formats. The default is @samp{x}.
29710
29711@item tvars
29712The trace state variables that have been collected at the current
29713trace frame. For each trace state variable collected, the name and
29714current value are returned.
29715
29716@item memory
29717The set of memory ranges that have been collected at the current trace
29718frame. Its content is a list of tuples. Each tuple represents a
29719collected memory range and has the following fields:
29720
29721@table @code
29722@item address
29723The start address of the memory range, as hexadecimal literal.
29724
29725@item length
29726The length of the memory range, as decimal literal.
29727
29728@item contents
29729The contents of the memory block, in hex. This field is only present
29730if the @code{--memory-contents} option is specified.
29731
29732@end table
29733
29734@end table
29735
29736@subsubheading @value{GDBN} Command
29737
29738There is no corresponding @value{GDBN} command.
29739
29740@subsubheading Example
29741
18148017
VP
29742@subheading -trace-list-variables
29743@findex -trace-list-variables
922fbb7b 29744
18148017 29745@subsubheading Synopsis
922fbb7b 29746
18148017
VP
29747@smallexample
29748 -trace-list-variables
29749@end smallexample
922fbb7b 29750
18148017
VP
29751Return a table of all defined trace variables. Each element of the
29752table has the following fields:
922fbb7b 29753
18148017
VP
29754@table @samp
29755@item name
29756The name of the trace variable. This field is always present.
922fbb7b 29757
18148017
VP
29758@item initial
29759The initial value. This is a 64-bit signed integer. This
29760field is always present.
922fbb7b 29761
18148017
VP
29762@item current
29763The value the trace variable has at the moment. This is a 64-bit
29764signed integer. This field is absent iff current value is
29765not defined, for example if the trace was never run, or is
29766presently running.
922fbb7b 29767
18148017 29768@end table
922fbb7b 29769
7d13fe92
SS
29770@subsubheading @value{GDBN} Command
29771
29772The corresponding @value{GDBN} command is @samp{tvariables}.
29773
18148017 29774@subsubheading Example
922fbb7b 29775
18148017
VP
29776@smallexample
29777(gdb)
29778-trace-list-variables
29779^done,trace-variables=@{nr_rows="1",nr_cols="3",
29780hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
29781 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
29782 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
29783body=[variable=@{name="$trace_timestamp",initial="0"@}
29784 variable=@{name="$foo",initial="10",current="15"@}]@}
29785(gdb)
29786@end smallexample
922fbb7b 29787
18148017
VP
29788@subheading -trace-save
29789@findex -trace-save
922fbb7b 29790
18148017
VP
29791@subsubheading Synopsis
29792
29793@smallexample
29794 -trace-save [-r ] @var{filename}
29795@end smallexample
29796
29797Saves the collected trace data to @var{filename}. Without the
29798@samp{-r} option, the data is downloaded from the target and saved
29799in a local file. With the @samp{-r} option the target is asked
29800to perform the save.
29801
7d13fe92
SS
29802@subsubheading @value{GDBN} Command
29803
29804The corresponding @value{GDBN} command is @samp{tsave}.
29805
18148017
VP
29806
29807@subheading -trace-start
29808@findex -trace-start
29809
29810@subsubheading Synopsis
29811
29812@smallexample
29813 -trace-start
29814@end smallexample
922fbb7b 29815
18148017
VP
29816Starts a tracing experiments. The result of this command does not
29817have any fields.
922fbb7b 29818
7d13fe92
SS
29819@subsubheading @value{GDBN} Command
29820
29821The corresponding @value{GDBN} command is @samp{tstart}.
29822
18148017
VP
29823@subheading -trace-status
29824@findex -trace-status
922fbb7b 29825
18148017
VP
29826@subsubheading Synopsis
29827
29828@smallexample
29829 -trace-status
29830@end smallexample
29831
a97153c7 29832Obtains the status of a tracing experiment. The result may include
18148017
VP
29833the following fields:
29834
29835@table @samp
29836
29837@item supported
29838May have a value of either @samp{0}, when no tracing operations are
29839supported, @samp{1}, when all tracing operations are supported, or
29840@samp{file} when examining trace file. In the latter case, examining
29841of trace frame is possible but new tracing experiement cannot be
29842started. This field is always present.
29843
29844@item running
29845May have a value of either @samp{0} or @samp{1} depending on whether
29846tracing experiement is in progress on target. This field is present
29847if @samp{supported} field is not @samp{0}.
29848
29849@item stop-reason
29850Report the reason why the tracing was stopped last time. This field
29851may be absent iff tracing was never stopped on target yet. The
29852value of @samp{request} means the tracing was stopped as result of
29853the @code{-trace-stop} command. The value of @samp{overflow} means
29854the tracing buffer is full. The value of @samp{disconnection} means
29855tracing was automatically stopped when @value{GDBN} has disconnected.
29856The value of @samp{passcount} means tracing was stopped when a
29857tracepoint was passed a maximal number of times for that tracepoint.
29858This field is present if @samp{supported} field is not @samp{0}.
29859
29860@item stopping-tracepoint
29861The number of tracepoint whose passcount as exceeded. This field is
29862present iff the @samp{stop-reason} field has the value of
29863@samp{passcount}.
29864
29865@item frames
87290684
SS
29866@itemx frames-created
29867The @samp{frames} field is a count of the total number of trace frames
29868in the trace buffer, while @samp{frames-created} is the total created
29869during the run, including ones that were discarded, such as when a
29870circular trace buffer filled up. Both fields are optional.
18148017
VP
29871
29872@item buffer-size
29873@itemx buffer-free
29874These fields tell the current size of the tracing buffer and the
87290684 29875remaining space. These fields are optional.
18148017 29876
a97153c7
PA
29877@item circular
29878The value of the circular trace buffer flag. @code{1} means that the
29879trace buffer is circular and old trace frames will be discarded if
29880necessary to make room, @code{0} means that the trace buffer is linear
29881and may fill up.
29882
29883@item disconnected
29884The value of the disconnected tracing flag. @code{1} means that
29885tracing will continue after @value{GDBN} disconnects, @code{0} means
29886that the trace run will stop.
29887
f5911ea1
HAQ
29888@item trace-file
29889The filename of the trace file being examined. This field is
29890optional, and only present when examining a trace file.
29891
18148017
VP
29892@end table
29893
7d13fe92
SS
29894@subsubheading @value{GDBN} Command
29895
29896The corresponding @value{GDBN} command is @samp{tstatus}.
29897
18148017
VP
29898@subheading -trace-stop
29899@findex -trace-stop
29900
29901@subsubheading Synopsis
29902
29903@smallexample
29904 -trace-stop
29905@end smallexample
922fbb7b 29906
18148017
VP
29907Stops a tracing experiment. The result of this command has the same
29908fields as @code{-trace-status}, except that the @samp{supported} and
29909@samp{running} fields are not output.
922fbb7b 29910
7d13fe92
SS
29911@subsubheading @value{GDBN} Command
29912
29913The corresponding @value{GDBN} command is @samp{tstop}.
29914
922fbb7b 29915
a2c02241
NR
29916@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29917@node GDB/MI Symbol Query
29918@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
29919
29920
9901a55b 29921@ignore
a2c02241
NR
29922@subheading The @code{-symbol-info-address} Command
29923@findex -symbol-info-address
922fbb7b
AC
29924
29925@subsubheading Synopsis
29926
29927@smallexample
a2c02241 29928 -symbol-info-address @var{symbol}
922fbb7b
AC
29929@end smallexample
29930
a2c02241 29931Describe where @var{symbol} is stored.
922fbb7b
AC
29932
29933@subsubheading @value{GDBN} Command
29934
a2c02241 29935The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
29936
29937@subsubheading Example
29938N.A.
29939
29940
a2c02241
NR
29941@subheading The @code{-symbol-info-file} Command
29942@findex -symbol-info-file
922fbb7b
AC
29943
29944@subsubheading Synopsis
29945
29946@smallexample
a2c02241 29947 -symbol-info-file
922fbb7b
AC
29948@end smallexample
29949
a2c02241 29950Show the file for the symbol.
922fbb7b 29951
a2c02241 29952@subsubheading @value{GDBN} Command
922fbb7b 29953
a2c02241
NR
29954There's no equivalent @value{GDBN} command. @code{gdbtk} has
29955@samp{gdb_find_file}.
922fbb7b
AC
29956
29957@subsubheading Example
29958N.A.
29959
29960
a2c02241
NR
29961@subheading The @code{-symbol-info-function} Command
29962@findex -symbol-info-function
922fbb7b
AC
29963
29964@subsubheading Synopsis
29965
29966@smallexample
a2c02241 29967 -symbol-info-function
922fbb7b
AC
29968@end smallexample
29969
a2c02241 29970Show which function the symbol lives in.
922fbb7b
AC
29971
29972@subsubheading @value{GDBN} Command
29973
a2c02241 29974@samp{gdb_get_function} in @code{gdbtk}.
922fbb7b
AC
29975
29976@subsubheading Example
29977N.A.
29978
29979
a2c02241
NR
29980@subheading The @code{-symbol-info-line} Command
29981@findex -symbol-info-line
922fbb7b
AC
29982
29983@subsubheading Synopsis
29984
29985@smallexample
a2c02241 29986 -symbol-info-line
922fbb7b
AC
29987@end smallexample
29988
a2c02241 29989Show the core addresses of the code for a source line.
922fbb7b 29990
a2c02241 29991@subsubheading @value{GDBN} Command
922fbb7b 29992
a2c02241
NR
29993The corresponding @value{GDBN} command is @samp{info line}.
29994@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
29995
29996@subsubheading Example
a2c02241 29997N.A.
922fbb7b
AC
29998
29999
a2c02241
NR
30000@subheading The @code{-symbol-info-symbol} Command
30001@findex -symbol-info-symbol
07f31aa6
DJ
30002
30003@subsubheading Synopsis
30004
a2c02241
NR
30005@smallexample
30006 -symbol-info-symbol @var{addr}
30007@end smallexample
07f31aa6 30008
a2c02241 30009Describe what symbol is at location @var{addr}.
07f31aa6 30010
a2c02241 30011@subsubheading @value{GDBN} Command
07f31aa6 30012
a2c02241 30013The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
30014
30015@subsubheading Example
a2c02241 30016N.A.
07f31aa6
DJ
30017
30018
a2c02241
NR
30019@subheading The @code{-symbol-list-functions} Command
30020@findex -symbol-list-functions
922fbb7b
AC
30021
30022@subsubheading Synopsis
30023
30024@smallexample
a2c02241 30025 -symbol-list-functions
922fbb7b
AC
30026@end smallexample
30027
a2c02241 30028List the functions in the executable.
922fbb7b
AC
30029
30030@subsubheading @value{GDBN} Command
30031
a2c02241
NR
30032@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
30033@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
30034
30035@subsubheading Example
a2c02241 30036N.A.
9901a55b 30037@end ignore
922fbb7b
AC
30038
30039
a2c02241
NR
30040@subheading The @code{-symbol-list-lines} Command
30041@findex -symbol-list-lines
922fbb7b
AC
30042
30043@subsubheading Synopsis
30044
30045@smallexample
a2c02241 30046 -symbol-list-lines @var{filename}
922fbb7b
AC
30047@end smallexample
30048
a2c02241
NR
30049Print the list of lines that contain code and their associated program
30050addresses for the given source filename. The entries are sorted in
30051ascending PC order.
922fbb7b
AC
30052
30053@subsubheading @value{GDBN} Command
30054
a2c02241 30055There is no corresponding @value{GDBN} command.
922fbb7b
AC
30056
30057@subsubheading Example
a2c02241 30058@smallexample
594fe323 30059(gdb)
a2c02241
NR
30060-symbol-list-lines basics.c
30061^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 30062(gdb)
a2c02241 30063@end smallexample
922fbb7b
AC
30064
30065
9901a55b 30066@ignore
a2c02241
NR
30067@subheading The @code{-symbol-list-types} Command
30068@findex -symbol-list-types
922fbb7b
AC
30069
30070@subsubheading Synopsis
30071
30072@smallexample
a2c02241 30073 -symbol-list-types
922fbb7b
AC
30074@end smallexample
30075
a2c02241 30076List all the type names.
922fbb7b
AC
30077
30078@subsubheading @value{GDBN} Command
30079
a2c02241
NR
30080The corresponding commands are @samp{info types} in @value{GDBN},
30081@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
30082
30083@subsubheading Example
30084N.A.
30085
30086
a2c02241
NR
30087@subheading The @code{-symbol-list-variables} Command
30088@findex -symbol-list-variables
922fbb7b
AC
30089
30090@subsubheading Synopsis
30091
30092@smallexample
a2c02241 30093 -symbol-list-variables
922fbb7b
AC
30094@end smallexample
30095
a2c02241 30096List all the global and static variable names.
922fbb7b
AC
30097
30098@subsubheading @value{GDBN} Command
30099
a2c02241 30100@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
30101
30102@subsubheading Example
30103N.A.
30104
30105
a2c02241
NR
30106@subheading The @code{-symbol-locate} Command
30107@findex -symbol-locate
922fbb7b
AC
30108
30109@subsubheading Synopsis
30110
30111@smallexample
a2c02241 30112 -symbol-locate
922fbb7b
AC
30113@end smallexample
30114
922fbb7b
AC
30115@subsubheading @value{GDBN} Command
30116
a2c02241 30117@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
30118
30119@subsubheading Example
30120N.A.
30121
30122
a2c02241
NR
30123@subheading The @code{-symbol-type} Command
30124@findex -symbol-type
922fbb7b
AC
30125
30126@subsubheading Synopsis
30127
30128@smallexample
a2c02241 30129 -symbol-type @var{variable}
922fbb7b
AC
30130@end smallexample
30131
a2c02241 30132Show type of @var{variable}.
922fbb7b 30133
a2c02241 30134@subsubheading @value{GDBN} Command
922fbb7b 30135
a2c02241
NR
30136The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
30137@samp{gdb_obj_variable}.
30138
30139@subsubheading Example
30140N.A.
9901a55b 30141@end ignore
a2c02241
NR
30142
30143
30144@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30145@node GDB/MI File Commands
30146@section @sc{gdb/mi} File Commands
30147
30148This section describes the GDB/MI commands to specify executable file names
30149and to read in and obtain symbol table information.
30150
30151@subheading The @code{-file-exec-and-symbols} Command
30152@findex -file-exec-and-symbols
30153
30154@subsubheading Synopsis
922fbb7b
AC
30155
30156@smallexample
a2c02241 30157 -file-exec-and-symbols @var{file}
922fbb7b
AC
30158@end smallexample
30159
a2c02241
NR
30160Specify the executable file to be debugged. This file is the one from
30161which the symbol table is also read. If no file is specified, the
30162command clears the executable and symbol information. If breakpoints
30163are set when using this command with no arguments, @value{GDBN} will produce
30164error messages. Otherwise, no output is produced, except a completion
30165notification.
30166
922fbb7b
AC
30167@subsubheading @value{GDBN} Command
30168
a2c02241 30169The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
30170
30171@subsubheading Example
30172
30173@smallexample
594fe323 30174(gdb)
a2c02241
NR
30175-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
30176^done
594fe323 30177(gdb)
922fbb7b
AC
30178@end smallexample
30179
922fbb7b 30180
a2c02241
NR
30181@subheading The @code{-file-exec-file} Command
30182@findex -file-exec-file
922fbb7b
AC
30183
30184@subsubheading Synopsis
30185
30186@smallexample
a2c02241 30187 -file-exec-file @var{file}
922fbb7b
AC
30188@end smallexample
30189
a2c02241
NR
30190Specify the executable file to be debugged. Unlike
30191@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
30192from this file. If used without argument, @value{GDBN} clears the information
30193about the executable file. No output is produced, except a completion
30194notification.
922fbb7b 30195
a2c02241
NR
30196@subsubheading @value{GDBN} Command
30197
30198The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
30199
30200@subsubheading Example
a2c02241
NR
30201
30202@smallexample
594fe323 30203(gdb)
a2c02241
NR
30204-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
30205^done
594fe323 30206(gdb)
a2c02241 30207@end smallexample
922fbb7b
AC
30208
30209
9901a55b 30210@ignore
a2c02241
NR
30211@subheading The @code{-file-list-exec-sections} Command
30212@findex -file-list-exec-sections
922fbb7b
AC
30213
30214@subsubheading Synopsis
30215
30216@smallexample
a2c02241 30217 -file-list-exec-sections
922fbb7b
AC
30218@end smallexample
30219
a2c02241
NR
30220List the sections of the current executable file.
30221
922fbb7b
AC
30222@subsubheading @value{GDBN} Command
30223
a2c02241
NR
30224The @value{GDBN} command @samp{info file} shows, among the rest, the same
30225information as this command. @code{gdbtk} has a corresponding command
30226@samp{gdb_load_info}.
922fbb7b
AC
30227
30228@subsubheading Example
30229N.A.
9901a55b 30230@end ignore
922fbb7b
AC
30231
30232
a2c02241
NR
30233@subheading The @code{-file-list-exec-source-file} Command
30234@findex -file-list-exec-source-file
922fbb7b
AC
30235
30236@subsubheading Synopsis
30237
30238@smallexample
a2c02241 30239 -file-list-exec-source-file
922fbb7b
AC
30240@end smallexample
30241
a2c02241 30242List the line number, the current source file, and the absolute path
44288b44
NR
30243to the current source file for the current executable. The macro
30244information field has a value of @samp{1} or @samp{0} depending on
30245whether or not the file includes preprocessor macro information.
922fbb7b
AC
30246
30247@subsubheading @value{GDBN} Command
30248
a2c02241 30249The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
30250
30251@subsubheading Example
30252
922fbb7b 30253@smallexample
594fe323 30254(gdb)
a2c02241 30255123-file-list-exec-source-file
44288b44 30256123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
594fe323 30257(gdb)
922fbb7b
AC
30258@end smallexample
30259
30260
a2c02241
NR
30261@subheading The @code{-file-list-exec-source-files} Command
30262@findex -file-list-exec-source-files
922fbb7b
AC
30263
30264@subsubheading Synopsis
30265
30266@smallexample
a2c02241 30267 -file-list-exec-source-files
922fbb7b
AC
30268@end smallexample
30269
a2c02241
NR
30270List the source files for the current executable.
30271
f35a17b5
JK
30272It will always output both the filename and fullname (absolute file
30273name) of a source file.
922fbb7b
AC
30274
30275@subsubheading @value{GDBN} Command
30276
a2c02241
NR
30277The @value{GDBN} equivalent is @samp{info sources}.
30278@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
30279
30280@subsubheading Example
922fbb7b 30281@smallexample
594fe323 30282(gdb)
a2c02241
NR
30283-file-list-exec-source-files
30284^done,files=[
30285@{file=foo.c,fullname=/home/foo.c@},
30286@{file=/home/bar.c,fullname=/home/bar.c@},
30287@{file=gdb_could_not_find_fullpath.c@}]
594fe323 30288(gdb)
922fbb7b
AC
30289@end smallexample
30290
9901a55b 30291@ignore
a2c02241
NR
30292@subheading The @code{-file-list-shared-libraries} Command
30293@findex -file-list-shared-libraries
922fbb7b 30294
a2c02241 30295@subsubheading Synopsis
922fbb7b 30296
a2c02241
NR
30297@smallexample
30298 -file-list-shared-libraries
30299@end smallexample
922fbb7b 30300
a2c02241 30301List the shared libraries in the program.
922fbb7b 30302
a2c02241 30303@subsubheading @value{GDBN} Command
922fbb7b 30304
a2c02241 30305The corresponding @value{GDBN} command is @samp{info shared}.
922fbb7b 30306
a2c02241
NR
30307@subsubheading Example
30308N.A.
922fbb7b
AC
30309
30310
a2c02241
NR
30311@subheading The @code{-file-list-symbol-files} Command
30312@findex -file-list-symbol-files
922fbb7b 30313
a2c02241 30314@subsubheading Synopsis
922fbb7b 30315
a2c02241
NR
30316@smallexample
30317 -file-list-symbol-files
30318@end smallexample
922fbb7b 30319
a2c02241 30320List symbol files.
922fbb7b 30321
a2c02241 30322@subsubheading @value{GDBN} Command
922fbb7b 30323
a2c02241 30324The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 30325
a2c02241
NR
30326@subsubheading Example
30327N.A.
9901a55b 30328@end ignore
922fbb7b 30329
922fbb7b 30330
a2c02241
NR
30331@subheading The @code{-file-symbol-file} Command
30332@findex -file-symbol-file
922fbb7b 30333
a2c02241 30334@subsubheading Synopsis
922fbb7b 30335
a2c02241
NR
30336@smallexample
30337 -file-symbol-file @var{file}
30338@end smallexample
922fbb7b 30339
a2c02241
NR
30340Read symbol table info from the specified @var{file} argument. When
30341used without arguments, clears @value{GDBN}'s symbol table info. No output is
30342produced, except for a completion notification.
922fbb7b 30343
a2c02241 30344@subsubheading @value{GDBN} Command
922fbb7b 30345
a2c02241 30346The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 30347
a2c02241 30348@subsubheading Example
922fbb7b 30349
a2c02241 30350@smallexample
594fe323 30351(gdb)
a2c02241
NR
30352-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
30353^done
594fe323 30354(gdb)
a2c02241 30355@end smallexample
922fbb7b 30356
a2c02241 30357@ignore
a2c02241
NR
30358@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30359@node GDB/MI Memory Overlay Commands
30360@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 30361
a2c02241 30362The memory overlay commands are not implemented.
922fbb7b 30363
a2c02241 30364@c @subheading -overlay-auto
922fbb7b 30365
a2c02241 30366@c @subheading -overlay-list-mapping-state
922fbb7b 30367
a2c02241 30368@c @subheading -overlay-list-overlays
922fbb7b 30369
a2c02241 30370@c @subheading -overlay-map
922fbb7b 30371
a2c02241 30372@c @subheading -overlay-off
922fbb7b 30373
a2c02241 30374@c @subheading -overlay-on
922fbb7b 30375
a2c02241 30376@c @subheading -overlay-unmap
922fbb7b 30377
a2c02241
NR
30378@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30379@node GDB/MI Signal Handling Commands
30380@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 30381
a2c02241 30382Signal handling commands are not implemented.
922fbb7b 30383
a2c02241 30384@c @subheading -signal-handle
922fbb7b 30385
a2c02241 30386@c @subheading -signal-list-handle-actions
922fbb7b 30387
a2c02241
NR
30388@c @subheading -signal-list-signal-types
30389@end ignore
922fbb7b 30390
922fbb7b 30391
a2c02241
NR
30392@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30393@node GDB/MI Target Manipulation
30394@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
30395
30396
a2c02241
NR
30397@subheading The @code{-target-attach} Command
30398@findex -target-attach
922fbb7b
AC
30399
30400@subsubheading Synopsis
30401
30402@smallexample
c3b108f7 30403 -target-attach @var{pid} | @var{gid} | @var{file}
922fbb7b
AC
30404@end smallexample
30405
c3b108f7
VP
30406Attach to a process @var{pid} or a file @var{file} outside of
30407@value{GDBN}, or a thread group @var{gid}. If attaching to a thread
30408group, the id previously returned by
30409@samp{-list-thread-groups --available} must be used.
922fbb7b 30410
79a6e687 30411@subsubheading @value{GDBN} Command
922fbb7b 30412
a2c02241 30413The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 30414
a2c02241 30415@subsubheading Example
b56e7235
VP
30416@smallexample
30417(gdb)
30418-target-attach 34
30419=thread-created,id="1"
5ae4183a 30420*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
b56e7235
VP
30421^done
30422(gdb)
30423@end smallexample
a2c02241 30424
9901a55b 30425@ignore
a2c02241
NR
30426@subheading The @code{-target-compare-sections} Command
30427@findex -target-compare-sections
922fbb7b
AC
30428
30429@subsubheading Synopsis
30430
30431@smallexample
a2c02241 30432 -target-compare-sections [ @var{section} ]
922fbb7b
AC
30433@end smallexample
30434
a2c02241
NR
30435Compare data of section @var{section} on target to the exec file.
30436Without the argument, all sections are compared.
922fbb7b 30437
a2c02241 30438@subsubheading @value{GDBN} Command
922fbb7b 30439
a2c02241 30440The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 30441
a2c02241
NR
30442@subsubheading Example
30443N.A.
9901a55b 30444@end ignore
a2c02241
NR
30445
30446
30447@subheading The @code{-target-detach} Command
30448@findex -target-detach
922fbb7b
AC
30449
30450@subsubheading Synopsis
30451
30452@smallexample
c3b108f7 30453 -target-detach [ @var{pid} | @var{gid} ]
922fbb7b
AC
30454@end smallexample
30455
a2c02241 30456Detach from the remote target which normally resumes its execution.
c3b108f7
VP
30457If either @var{pid} or @var{gid} is specified, detaches from either
30458the specified process, or specified thread group. There's no output.
a2c02241 30459
79a6e687 30460@subsubheading @value{GDBN} Command
a2c02241
NR
30461
30462The corresponding @value{GDBN} command is @samp{detach}.
30463
30464@subsubheading Example
922fbb7b
AC
30465
30466@smallexample
594fe323 30467(gdb)
a2c02241
NR
30468-target-detach
30469^done
594fe323 30470(gdb)
922fbb7b
AC
30471@end smallexample
30472
30473
a2c02241
NR
30474@subheading The @code{-target-disconnect} Command
30475@findex -target-disconnect
922fbb7b
AC
30476
30477@subsubheading Synopsis
30478
123dc839 30479@smallexample
a2c02241 30480 -target-disconnect
123dc839 30481@end smallexample
922fbb7b 30482
a2c02241
NR
30483Disconnect from the remote target. There's no output and the target is
30484generally not resumed.
30485
79a6e687 30486@subsubheading @value{GDBN} Command
a2c02241
NR
30487
30488The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
30489
30490@subsubheading Example
922fbb7b
AC
30491
30492@smallexample
594fe323 30493(gdb)
a2c02241
NR
30494-target-disconnect
30495^done
594fe323 30496(gdb)
922fbb7b
AC
30497@end smallexample
30498
30499
a2c02241
NR
30500@subheading The @code{-target-download} Command
30501@findex -target-download
922fbb7b
AC
30502
30503@subsubheading Synopsis
30504
30505@smallexample
a2c02241 30506 -target-download
922fbb7b
AC
30507@end smallexample
30508
a2c02241
NR
30509Loads the executable onto the remote target.
30510It prints out an update message every half second, which includes the fields:
30511
30512@table @samp
30513@item section
30514The name of the section.
30515@item section-sent
30516The size of what has been sent so far for that section.
30517@item section-size
30518The size of the section.
30519@item total-sent
30520The total size of what was sent so far (the current and the previous sections).
30521@item total-size
30522The size of the overall executable to download.
30523@end table
30524
30525@noindent
30526Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
30527@sc{gdb/mi} Output Syntax}).
30528
30529In addition, it prints the name and size of the sections, as they are
30530downloaded. These messages include the following fields:
30531
30532@table @samp
30533@item section
30534The name of the section.
30535@item section-size
30536The size of the section.
30537@item total-size
30538The size of the overall executable to download.
30539@end table
30540
30541@noindent
30542At the end, a summary is printed.
30543
30544@subsubheading @value{GDBN} Command
30545
30546The corresponding @value{GDBN} command is @samp{load}.
30547
30548@subsubheading Example
30549
30550Note: each status message appears on a single line. Here the messages
30551have been broken down so that they can fit onto a page.
922fbb7b
AC
30552
30553@smallexample
594fe323 30554(gdb)
a2c02241
NR
30555-target-download
30556+download,@{section=".text",section-size="6668",total-size="9880"@}
30557+download,@{section=".text",section-sent="512",section-size="6668",
30558total-sent="512",total-size="9880"@}
30559+download,@{section=".text",section-sent="1024",section-size="6668",
30560total-sent="1024",total-size="9880"@}
30561+download,@{section=".text",section-sent="1536",section-size="6668",
30562total-sent="1536",total-size="9880"@}
30563+download,@{section=".text",section-sent="2048",section-size="6668",
30564total-sent="2048",total-size="9880"@}
30565+download,@{section=".text",section-sent="2560",section-size="6668",
30566total-sent="2560",total-size="9880"@}
30567+download,@{section=".text",section-sent="3072",section-size="6668",
30568total-sent="3072",total-size="9880"@}
30569+download,@{section=".text",section-sent="3584",section-size="6668",
30570total-sent="3584",total-size="9880"@}
30571+download,@{section=".text",section-sent="4096",section-size="6668",
30572total-sent="4096",total-size="9880"@}
30573+download,@{section=".text",section-sent="4608",section-size="6668",
30574total-sent="4608",total-size="9880"@}
30575+download,@{section=".text",section-sent="5120",section-size="6668",
30576total-sent="5120",total-size="9880"@}
30577+download,@{section=".text",section-sent="5632",section-size="6668",
30578total-sent="5632",total-size="9880"@}
30579+download,@{section=".text",section-sent="6144",section-size="6668",
30580total-sent="6144",total-size="9880"@}
30581+download,@{section=".text",section-sent="6656",section-size="6668",
30582total-sent="6656",total-size="9880"@}
30583+download,@{section=".init",section-size="28",total-size="9880"@}
30584+download,@{section=".fini",section-size="28",total-size="9880"@}
30585+download,@{section=".data",section-size="3156",total-size="9880"@}
30586+download,@{section=".data",section-sent="512",section-size="3156",
30587total-sent="7236",total-size="9880"@}
30588+download,@{section=".data",section-sent="1024",section-size="3156",
30589total-sent="7748",total-size="9880"@}
30590+download,@{section=".data",section-sent="1536",section-size="3156",
30591total-sent="8260",total-size="9880"@}
30592+download,@{section=".data",section-sent="2048",section-size="3156",
30593total-sent="8772",total-size="9880"@}
30594+download,@{section=".data",section-sent="2560",section-size="3156",
30595total-sent="9284",total-size="9880"@}
30596+download,@{section=".data",section-sent="3072",section-size="3156",
30597total-sent="9796",total-size="9880"@}
30598^done,address="0x10004",load-size="9880",transfer-rate="6586",
30599write-rate="429"
594fe323 30600(gdb)
922fbb7b
AC
30601@end smallexample
30602
30603
9901a55b 30604@ignore
a2c02241
NR
30605@subheading The @code{-target-exec-status} Command
30606@findex -target-exec-status
922fbb7b
AC
30607
30608@subsubheading Synopsis
30609
30610@smallexample
a2c02241 30611 -target-exec-status
922fbb7b
AC
30612@end smallexample
30613
a2c02241
NR
30614Provide information on the state of the target (whether it is running or
30615not, for instance).
922fbb7b 30616
a2c02241 30617@subsubheading @value{GDBN} Command
922fbb7b 30618
a2c02241
NR
30619There's no equivalent @value{GDBN} command.
30620
30621@subsubheading Example
30622N.A.
922fbb7b 30623
a2c02241
NR
30624
30625@subheading The @code{-target-list-available-targets} Command
30626@findex -target-list-available-targets
922fbb7b
AC
30627
30628@subsubheading Synopsis
30629
30630@smallexample
a2c02241 30631 -target-list-available-targets
922fbb7b
AC
30632@end smallexample
30633
a2c02241 30634List the possible targets to connect to.
922fbb7b 30635
a2c02241 30636@subsubheading @value{GDBN} Command
922fbb7b 30637
a2c02241 30638The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 30639
a2c02241
NR
30640@subsubheading Example
30641N.A.
30642
30643
30644@subheading The @code{-target-list-current-targets} Command
30645@findex -target-list-current-targets
922fbb7b
AC
30646
30647@subsubheading Synopsis
30648
30649@smallexample
a2c02241 30650 -target-list-current-targets
922fbb7b
AC
30651@end smallexample
30652
a2c02241 30653Describe the current target.
922fbb7b 30654
a2c02241 30655@subsubheading @value{GDBN} Command
922fbb7b 30656
a2c02241
NR
30657The corresponding information is printed by @samp{info file} (among
30658other things).
922fbb7b 30659
a2c02241
NR
30660@subsubheading Example
30661N.A.
30662
30663
30664@subheading The @code{-target-list-parameters} Command
30665@findex -target-list-parameters
922fbb7b
AC
30666
30667@subsubheading Synopsis
30668
30669@smallexample
a2c02241 30670 -target-list-parameters
922fbb7b
AC
30671@end smallexample
30672
a2c02241 30673@c ????
9901a55b 30674@end ignore
a2c02241
NR
30675
30676@subsubheading @value{GDBN} Command
30677
30678No equivalent.
922fbb7b
AC
30679
30680@subsubheading Example
a2c02241
NR
30681N.A.
30682
30683
30684@subheading The @code{-target-select} Command
30685@findex -target-select
30686
30687@subsubheading Synopsis
922fbb7b
AC
30688
30689@smallexample
a2c02241 30690 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
30691@end smallexample
30692
a2c02241 30693Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 30694
a2c02241
NR
30695@table @samp
30696@item @var{type}
75c99385 30697The type of target, for instance @samp{remote}, etc.
a2c02241
NR
30698@item @var{parameters}
30699Device names, host names and the like. @xref{Target Commands, ,
79a6e687 30700Commands for Managing Targets}, for more details.
a2c02241
NR
30701@end table
30702
30703The output is a connection notification, followed by the address at
30704which the target program is, in the following form:
922fbb7b
AC
30705
30706@smallexample
a2c02241
NR
30707^connected,addr="@var{address}",func="@var{function name}",
30708 args=[@var{arg list}]
922fbb7b
AC
30709@end smallexample
30710
a2c02241
NR
30711@subsubheading @value{GDBN} Command
30712
30713The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
30714
30715@subsubheading Example
922fbb7b 30716
265eeb58 30717@smallexample
594fe323 30718(gdb)
75c99385 30719-target-select remote /dev/ttya
a2c02241 30720^connected,addr="0xfe00a300",func="??",args=[]
594fe323 30721(gdb)
265eeb58 30722@end smallexample
ef21caaf 30723
a6b151f1
DJ
30724@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30725@node GDB/MI File Transfer Commands
30726@section @sc{gdb/mi} File Transfer Commands
30727
30728
30729@subheading The @code{-target-file-put} Command
30730@findex -target-file-put
30731
30732@subsubheading Synopsis
30733
30734@smallexample
30735 -target-file-put @var{hostfile} @var{targetfile}
30736@end smallexample
30737
30738Copy file @var{hostfile} from the host system (the machine running
30739@value{GDBN}) to @var{targetfile} on the target system.
30740
30741@subsubheading @value{GDBN} Command
30742
30743The corresponding @value{GDBN} command is @samp{remote put}.
30744
30745@subsubheading Example
30746
30747@smallexample
30748(gdb)
30749-target-file-put localfile remotefile
30750^done
30751(gdb)
30752@end smallexample
30753
30754
1763a388 30755@subheading The @code{-target-file-get} Command
a6b151f1
DJ
30756@findex -target-file-get
30757
30758@subsubheading Synopsis
30759
30760@smallexample
30761 -target-file-get @var{targetfile} @var{hostfile}
30762@end smallexample
30763
30764Copy file @var{targetfile} from the target system to @var{hostfile}
30765on the host system.
30766
30767@subsubheading @value{GDBN} Command
30768
30769The corresponding @value{GDBN} command is @samp{remote get}.
30770
30771@subsubheading Example
30772
30773@smallexample
30774(gdb)
30775-target-file-get remotefile localfile
30776^done
30777(gdb)
30778@end smallexample
30779
30780
30781@subheading The @code{-target-file-delete} Command
30782@findex -target-file-delete
30783
30784@subsubheading Synopsis
30785
30786@smallexample
30787 -target-file-delete @var{targetfile}
30788@end smallexample
30789
30790Delete @var{targetfile} from the target system.
30791
30792@subsubheading @value{GDBN} Command
30793
30794The corresponding @value{GDBN} command is @samp{remote delete}.
30795
30796@subsubheading Example
30797
30798@smallexample
30799(gdb)
30800-target-file-delete remotefile
30801^done
30802(gdb)
30803@end smallexample
30804
30805
58d06528
JB
30806@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30807@node GDB/MI Ada Exceptions Commands
30808@section Ada Exceptions @sc{gdb/mi} Commands
30809
30810@subheading The @code{-info-ada-exceptions} Command
30811@findex -info-ada-exceptions
30812
30813@subsubheading Synopsis
30814
30815@smallexample
30816 -info-ada-exceptions [ @var{regexp}]
30817@end smallexample
30818
30819List all Ada exceptions defined within the program being debugged.
30820With a regular expression @var{regexp}, only those exceptions whose
30821names match @var{regexp} are listed.
30822
30823@subsubheading @value{GDBN} Command
30824
30825The corresponding @value{GDBN} command is @samp{info exceptions}.
30826
30827@subsubheading Result
30828
30829The result is a table of Ada exceptions. The following columns are
30830defined for each exception:
30831
30832@table @samp
30833@item name
30834The name of the exception.
30835
30836@item address
30837The address of the exception.
30838
30839@end table
30840
30841@subsubheading Example
30842
30843@smallexample
30844-info-ada-exceptions aint
30845^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
30846hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
30847@{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
30848body=[@{name="constraint_error",address="0x0000000000613da0"@},
30849@{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
30850@end smallexample
30851
30852@subheading Catching Ada Exceptions
30853
30854The commands describing how to ask @value{GDBN} to stop when a program
30855raises an exception are described at @ref{Ada Exception GDB/MI
30856Catchpoint Commands}.
30857
30858
ef21caaf 30859@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d192b373
JB
30860@node GDB/MI Support Commands
30861@section @sc{gdb/mi} Support Commands
ef21caaf 30862
d192b373
JB
30863Since new commands and features get regularly added to @sc{gdb/mi},
30864some commands are available to help front-ends query the debugger
30865about support for these capabilities. Similarly, it is also possible
30866to query @value{GDBN} about target support of certain features.
ef21caaf 30867
6b7cbff1
JB
30868@subheading The @code{-info-gdb-mi-command} Command
30869@cindex @code{-info-gdb-mi-command}
30870@findex -info-gdb-mi-command
30871
30872@subsubheading Synopsis
30873
30874@smallexample
30875 -info-gdb-mi-command @var{cmd_name}
30876@end smallexample
30877
30878Query support for the @sc{gdb/mi} command named @var{cmd_name}.
30879
30880Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
30881is technically not part of the command name (@pxref{GDB/MI Input
30882Syntax}), and thus should be omitted in @var{cmd_name}. However,
30883for ease of use, this command also accepts the form with the leading
30884dash.
30885
30886@subsubheading @value{GDBN} Command
30887
30888There is no corresponding @value{GDBN} command.
30889
30890@subsubheading Result
30891
30892The result is a tuple. There is currently only one field:
30893
30894@table @samp
30895@item exists
30896This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
30897@code{"false"} otherwise.
30898
30899@end table
30900
30901@subsubheading Example
30902
30903Here is an example where the @sc{gdb/mi} command does not exist:
30904
30905@smallexample
30906-info-gdb-mi-command unsupported-command
30907^done,command=@{exists="false"@}
30908@end smallexample
30909
30910@noindent
30911And here is an example where the @sc{gdb/mi} command is known
30912to the debugger:
30913
30914@smallexample
30915-info-gdb-mi-command symbol-list-lines
30916^done,command=@{exists="true"@}
30917@end smallexample
30918
084344da
VP
30919@subheading The @code{-list-features} Command
30920@findex -list-features
9b26f0fb 30921@cindex supported @sc{gdb/mi} features, list
084344da
VP
30922
30923Returns a list of particular features of the MI protocol that
30924this version of gdb implements. A feature can be a command,
30925or a new field in an output of some command, or even an
30926important bugfix. While a frontend can sometimes detect presence
30927of a feature at runtime, it is easier to perform detection at debugger
d192b373 30928startup.
084344da
VP
30929
30930The command returns a list of strings, with each string naming an
30931available feature. Each returned string is just a name, it does not
d192b373 30932have any internal structure. The list of possible feature names
084344da
VP
30933is given below.
30934
30935Example output:
30936
30937@smallexample
30938(gdb) -list-features
30939^done,result=["feature1","feature2"]
30940@end smallexample
30941
30942The current list of features is:
30943
edef6000 30944@ftable @samp
30e026bb 30945@item frozen-varobjs
a05336a1
JB
30946Indicates support for the @code{-var-set-frozen} command, as well
30947as possible presense of the @code{frozen} field in the output
30e026bb
VP
30948of @code{-varobj-create}.
30949@item pending-breakpoints
a05336a1
JB
30950Indicates support for the @option{-f} option to the @code{-break-insert}
30951command.
b6313243 30952@item python
a05336a1 30953Indicates Python scripting support, Python-based
b6313243
TT
30954pretty-printing commands, and possible presence of the
30955@samp{display_hint} field in the output of @code{-var-list-children}
30e026bb 30956@item thread-info
a05336a1 30957Indicates support for the @code{-thread-info} command.
8dedea02 30958@item data-read-memory-bytes
a05336a1 30959Indicates support for the @code{-data-read-memory-bytes} and the
8dedea02 30960@code{-data-write-memory-bytes} commands.
39c4d40a
TT
30961@item breakpoint-notifications
30962Indicates that changes to breakpoints and breakpoints created via the
30963CLI will be announced via async records.
5d77fe44 30964@item ada-task-info
6adcee18 30965Indicates support for the @code{-ada-task-info} command.
422ad5c2
JB
30966@item language-option
30967Indicates that all @sc{gdb/mi} commands accept the @option{--language}
30968option (@pxref{Context management}).
6b7cbff1
JB
30969@item info-gdb-mi-command
30970Indicates support for the @code{-info-gdb-mi-command} command.
2ea126fa
JB
30971@item undefined-command-error-code
30972Indicates support for the "undefined-command" error code in error result
30973records, produced when trying to execute an undefined @sc{gdb/mi} command
30974(@pxref{GDB/MI Result Records}).
72bfa06c
JB
30975@item exec-run-start-option
30976Indicates that the @code{-exec-run} command supports the @option{--start}
30977option (@pxref{GDB/MI Program Execution}).
edef6000 30978@end ftable
084344da 30979
c6ebd6cf
VP
30980@subheading The @code{-list-target-features} Command
30981@findex -list-target-features
30982
30983Returns a list of particular features that are supported by the
30984target. Those features affect the permitted MI commands, but
30985unlike the features reported by the @code{-list-features} command, the
30986features depend on which target GDB is using at the moment. Whenever
30987a target can change, due to commands such as @code{-target-select},
30988@code{-target-attach} or @code{-exec-run}, the list of target features
30989may change, and the frontend should obtain it again.
30990Example output:
30991
30992@smallexample
b3d3b4bd 30993(gdb) -list-target-features
c6ebd6cf
VP
30994^done,result=["async"]
30995@end smallexample
30996
30997The current list of features is:
30998
30999@table @samp
31000@item async
31001Indicates that the target is capable of asynchronous command
31002execution, which means that @value{GDBN} will accept further commands
31003while the target is running.
31004
f75d858b
MK
31005@item reverse
31006Indicates that the target is capable of reverse execution.
31007@xref{Reverse Execution}, for more information.
31008
c6ebd6cf
VP
31009@end table
31010
d192b373
JB
31011@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31012@node GDB/MI Miscellaneous Commands
31013@section Miscellaneous @sc{gdb/mi} Commands
31014
31015@c @subheading -gdb-complete
31016
31017@subheading The @code{-gdb-exit} Command
31018@findex -gdb-exit
31019
31020@subsubheading Synopsis
31021
31022@smallexample
31023 -gdb-exit
31024@end smallexample
31025
31026Exit @value{GDBN} immediately.
31027
31028@subsubheading @value{GDBN} Command
31029
31030Approximately corresponds to @samp{quit}.
31031
31032@subsubheading Example
31033
31034@smallexample
31035(gdb)
31036-gdb-exit
31037^exit
31038@end smallexample
31039
31040
31041@ignore
31042@subheading The @code{-exec-abort} Command
31043@findex -exec-abort
31044
31045@subsubheading Synopsis
31046
31047@smallexample
31048 -exec-abort
31049@end smallexample
31050
31051Kill the inferior running program.
31052
31053@subsubheading @value{GDBN} Command
31054
31055The corresponding @value{GDBN} command is @samp{kill}.
31056
31057@subsubheading Example
31058N.A.
31059@end ignore
31060
31061
31062@subheading The @code{-gdb-set} Command
31063@findex -gdb-set
31064
31065@subsubheading Synopsis
31066
31067@smallexample
31068 -gdb-set
31069@end smallexample
31070
31071Set an internal @value{GDBN} variable.
31072@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
31073
31074@subsubheading @value{GDBN} Command
31075
31076The corresponding @value{GDBN} command is @samp{set}.
31077
31078@subsubheading Example
31079
31080@smallexample
31081(gdb)
31082-gdb-set $foo=3
31083^done
31084(gdb)
31085@end smallexample
31086
31087
31088@subheading The @code{-gdb-show} Command
31089@findex -gdb-show
31090
31091@subsubheading Synopsis
31092
31093@smallexample
31094 -gdb-show
31095@end smallexample
31096
31097Show the current value of a @value{GDBN} variable.
31098
31099@subsubheading @value{GDBN} Command
31100
31101The corresponding @value{GDBN} command is @samp{show}.
31102
31103@subsubheading Example
31104
31105@smallexample
31106(gdb)
31107-gdb-show annotate
31108^done,value="0"
31109(gdb)
31110@end smallexample
31111
31112@c @subheading -gdb-source
31113
31114
31115@subheading The @code{-gdb-version} Command
31116@findex -gdb-version
31117
31118@subsubheading Synopsis
31119
31120@smallexample
31121 -gdb-version
31122@end smallexample
31123
31124Show version information for @value{GDBN}. Used mostly in testing.
31125
31126@subsubheading @value{GDBN} Command
31127
31128The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
31129default shows this information when you start an interactive session.
31130
31131@subsubheading Example
31132
31133@c This example modifies the actual output from GDB to avoid overfull
31134@c box in TeX.
31135@smallexample
31136(gdb)
31137-gdb-version
31138~GNU gdb 5.2.1
31139~Copyright 2000 Free Software Foundation, Inc.
31140~GDB is free software, covered by the GNU General Public License, and
31141~you are welcome to change it and/or distribute copies of it under
31142~ certain conditions.
31143~Type "show copying" to see the conditions.
31144~There is absolutely no warranty for GDB. Type "show warranty" for
31145~ details.
31146~This GDB was configured as
31147 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
31148^done
31149(gdb)
31150@end smallexample
31151
c3b108f7
VP
31152@subheading The @code{-list-thread-groups} Command
31153@findex -list-thread-groups
31154
31155@subheading Synopsis
31156
31157@smallexample
dc146f7c 31158-list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
c3b108f7
VP
31159@end smallexample
31160
dc146f7c
VP
31161Lists thread groups (@pxref{Thread groups}). When a single thread
31162group is passed as the argument, lists the children of that group.
31163When several thread group are passed, lists information about those
31164thread groups. Without any parameters, lists information about all
31165top-level thread groups.
31166
31167Normally, thread groups that are being debugged are reported.
31168With the @samp{--available} option, @value{GDBN} reports thread groups
31169available on the target.
31170
31171The output of this command may have either a @samp{threads} result or
31172a @samp{groups} result. The @samp{thread} result has a list of tuples
31173as value, with each tuple describing a thread (@pxref{GDB/MI Thread
31174Information}). The @samp{groups} result has a list of tuples as value,
31175each tuple describing a thread group. If top-level groups are
31176requested (that is, no parameter is passed), or when several groups
31177are passed, the output always has a @samp{groups} result. The format
31178of the @samp{group} result is described below.
31179
31180To reduce the number of roundtrips it's possible to list thread groups
31181together with their children, by passing the @samp{--recurse} option
31182and the recursion depth. Presently, only recursion depth of 1 is
31183permitted. If this option is present, then every reported thread group
31184will also include its children, either as @samp{group} or
31185@samp{threads} field.
31186
31187In general, any combination of option and parameters is permitted, with
31188the following caveats:
31189
31190@itemize @bullet
31191@item
31192When a single thread group is passed, the output will typically
31193be the @samp{threads} result. Because threads may not contain
31194anything, the @samp{recurse} option will be ignored.
31195
31196@item
31197When the @samp{--available} option is passed, limited information may
31198be available. In particular, the list of threads of a process might
31199be inaccessible. Further, specifying specific thread groups might
31200not give any performance advantage over listing all thread groups.
31201The frontend should assume that @samp{-list-thread-groups --available}
31202is always an expensive operation and cache the results.
31203
31204@end itemize
31205
31206The @samp{groups} result is a list of tuples, where each tuple may
31207have the following fields:
31208
31209@table @code
31210@item id
31211Identifier of the thread group. This field is always present.
a79b8f6e
VP
31212The identifier is an opaque string; frontends should not try to
31213convert it to an integer, even though it might look like one.
dc146f7c
VP
31214
31215@item type
31216The type of the thread group. At present, only @samp{process} is a
31217valid type.
31218
31219@item pid
31220The target-specific process identifier. This field is only present
a79b8f6e 31221for thread groups of type @samp{process} and only if the process exists.
c3b108f7 31222
dc146f7c
VP
31223@item num_children
31224The number of children this thread group has. This field may be
31225absent for an available thread group.
31226
31227@item threads
31228This field has a list of tuples as value, each tuple describing a
31229thread. It may be present if the @samp{--recurse} option is
31230specified, and it's actually possible to obtain the threads.
31231
31232@item cores
31233This field is a list of integers, each identifying a core that one
31234thread of the group is running on. This field may be absent if
31235such information is not available.
31236
a79b8f6e
VP
31237@item executable
31238The name of the executable file that corresponds to this thread group.
31239The field is only present for thread groups of type @samp{process},
31240and only if there is a corresponding executable file.
31241
dc146f7c 31242@end table
c3b108f7
VP
31243
31244@subheading Example
31245
31246@smallexample
31247@value{GDBP}
31248-list-thread-groups
31249^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
31250-list-thread-groups 17
31251^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
31252 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
31253@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
31254 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
31255 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}]]
dc146f7c
VP
31256-list-thread-groups --available
31257^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
31258-list-thread-groups --available --recurse 1
31259 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
31260 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
31261 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
31262-list-thread-groups --available --recurse 1 17 18
31263^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
31264 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
31265 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
c3b108f7 31266@end smallexample
c6ebd6cf 31267
f3e0e960
SS
31268@subheading The @code{-info-os} Command
31269@findex -info-os
31270
31271@subsubheading Synopsis
31272
31273@smallexample
31274-info-os [ @var{type} ]
31275@end smallexample
31276
31277If no argument is supplied, the command returns a table of available
31278operating-system-specific information types. If one of these types is
31279supplied as an argument @var{type}, then the command returns a table
31280of data of that type.
31281
31282The types of information available depend on the target operating
31283system.
31284
31285@subsubheading @value{GDBN} Command
31286
31287The corresponding @value{GDBN} command is @samp{info os}.
31288
31289@subsubheading Example
31290
31291When run on a @sc{gnu}/Linux system, the output will look something
31292like this:
31293
31294@smallexample
31295@value{GDBP}
31296-info-os
71caed83 31297^done,OSDataTable=@{nr_rows="9",nr_cols="3",
f3e0e960 31298hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
71caed83
SS
31299 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
31300 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
31301body=[item=@{col0="processes",col1="Listing of all processes",
31302 col2="Processes"@},
31303 item=@{col0="procgroups",col1="Listing of all process groups",
31304 col2="Process groups"@},
31305 item=@{col0="threads",col1="Listing of all threads",
31306 col2="Threads"@},
31307 item=@{col0="files",col1="Listing of all file descriptors",
31308 col2="File descriptors"@},
31309 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
31310 col2="Sockets"@},
31311 item=@{col0="shm",col1="Listing of all shared-memory regions",
31312 col2="Shared-memory regions"@},
31313 item=@{col0="semaphores",col1="Listing of all semaphores",
31314 col2="Semaphores"@},
31315 item=@{col0="msg",col1="Listing of all message queues",
31316 col2="Message queues"@},
31317 item=@{col0="modules",col1="Listing of all loaded kernel modules",
31318 col2="Kernel modules"@}]@}
f3e0e960
SS
31319@value{GDBP}
31320-info-os processes
31321^done,OSDataTable=@{nr_rows="190",nr_cols="4",
31322hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
31323 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
31324 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
31325 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
31326body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
31327 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
31328 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
31329 ...
31330 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
31331 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
31332(gdb)
31333@end smallexample
a79b8f6e 31334
71caed83
SS
31335(Note that the MI output here includes a @code{"Title"} column that
31336does not appear in command-line @code{info os}; this column is useful
31337for MI clients that want to enumerate the types of data, such as in a
31338popup menu, but is needless clutter on the command line, and
31339@code{info os} omits it.)
31340
a79b8f6e
VP
31341@subheading The @code{-add-inferior} Command
31342@findex -add-inferior
31343
31344@subheading Synopsis
31345
31346@smallexample
31347-add-inferior
31348@end smallexample
31349
31350Creates a new inferior (@pxref{Inferiors and Programs}). The created
31351inferior is not associated with any executable. Such association may
31352be established with the @samp{-file-exec-and-symbols} command
31353(@pxref{GDB/MI File Commands}). The command response has a single
b7742092 31354field, @samp{inferior}, whose value is the identifier of the
a79b8f6e
VP
31355thread group corresponding to the new inferior.
31356
31357@subheading Example
31358
31359@smallexample
31360@value{GDBP}
31361-add-inferior
b7742092 31362^done,inferior="i3"
a79b8f6e
VP
31363@end smallexample
31364
ef21caaf
NR
31365@subheading The @code{-interpreter-exec} Command
31366@findex -interpreter-exec
31367
31368@subheading Synopsis
31369
31370@smallexample
31371-interpreter-exec @var{interpreter} @var{command}
31372@end smallexample
a2c02241 31373@anchor{-interpreter-exec}
ef21caaf
NR
31374
31375Execute the specified @var{command} in the given @var{interpreter}.
31376
31377@subheading @value{GDBN} Command
31378
31379The corresponding @value{GDBN} command is @samp{interpreter-exec}.
31380
31381@subheading Example
31382
31383@smallexample
594fe323 31384(gdb)
ef21caaf
NR
31385-interpreter-exec console "break main"
31386&"During symbol reading, couldn't parse type; debugger out of date?.\n"
31387&"During symbol reading, bad structure-type format.\n"
31388~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
31389^done
594fe323 31390(gdb)
ef21caaf
NR
31391@end smallexample
31392
31393@subheading The @code{-inferior-tty-set} Command
31394@findex -inferior-tty-set
31395
31396@subheading Synopsis
31397
31398@smallexample
31399-inferior-tty-set /dev/pts/1
31400@end smallexample
31401
31402Set terminal for future runs of the program being debugged.
31403
31404@subheading @value{GDBN} Command
31405
31406The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
31407
31408@subheading Example
31409
31410@smallexample
594fe323 31411(gdb)
ef21caaf
NR
31412-inferior-tty-set /dev/pts/1
31413^done
594fe323 31414(gdb)
ef21caaf
NR
31415@end smallexample
31416
31417@subheading The @code{-inferior-tty-show} Command
31418@findex -inferior-tty-show
31419
31420@subheading Synopsis
31421
31422@smallexample
31423-inferior-tty-show
31424@end smallexample
31425
31426Show terminal for future runs of program being debugged.
31427
31428@subheading @value{GDBN} Command
31429
31430The corresponding @value{GDBN} command is @samp{show inferior-tty}.
31431
31432@subheading Example
31433
31434@smallexample
594fe323 31435(gdb)
ef21caaf
NR
31436-inferior-tty-set /dev/pts/1
31437^done
594fe323 31438(gdb)
ef21caaf
NR
31439-inferior-tty-show
31440^done,inferior_tty_terminal="/dev/pts/1"
594fe323 31441(gdb)
ef21caaf 31442@end smallexample
922fbb7b 31443
a4eefcd8
NR
31444@subheading The @code{-enable-timings} Command
31445@findex -enable-timings
31446
31447@subheading Synopsis
31448
31449@smallexample
31450-enable-timings [yes | no]
31451@end smallexample
31452
31453Toggle the printing of the wallclock, user and system times for an MI
31454command as a field in its output. This command is to help frontend
31455developers optimize the performance of their code. No argument is
31456equivalent to @samp{yes}.
31457
31458@subheading @value{GDBN} Command
31459
31460No equivalent.
31461
31462@subheading Example
31463
31464@smallexample
31465(gdb)
31466-enable-timings
31467^done
31468(gdb)
31469-break-insert main
31470^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31471addr="0x080484ed",func="main",file="myprog.c",
998580f1
MK
31472fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
31473times="0"@},
a4eefcd8
NR
31474time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
31475(gdb)
31476-enable-timings no
31477^done
31478(gdb)
31479-exec-run
31480^running
31481(gdb)
a47ec5fe 31482*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
a4eefcd8
NR
31483frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
31484@{name="argv",value="0xbfb60364"@}],file="myprog.c",
31485fullname="/home/nickrob/myprog.c",line="73"@}
31486(gdb)
31487@end smallexample
31488
922fbb7b
AC
31489@node Annotations
31490@chapter @value{GDBN} Annotations
31491
086432e2
AC
31492This chapter describes annotations in @value{GDBN}. Annotations were
31493designed to interface @value{GDBN} to graphical user interfaces or other
31494similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
31495relatively high level.
31496
d3e8051b 31497The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
31498(@pxref{GDB/MI}).
31499
922fbb7b
AC
31500@ignore
31501This is Edition @value{EDITION}, @value{DATE}.
31502@end ignore
31503
31504@menu
31505* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 31506* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
31507* Prompting:: Annotations marking @value{GDBN}'s need for input.
31508* Errors:: Annotations for error messages.
922fbb7b
AC
31509* Invalidation:: Some annotations describe things now invalid.
31510* Annotations for Running::
31511 Whether the program is running, how it stopped, etc.
31512* Source Annotations:: Annotations describing source code.
922fbb7b
AC
31513@end menu
31514
31515@node Annotations Overview
31516@section What is an Annotation?
31517@cindex annotations
31518
922fbb7b
AC
31519Annotations start with a newline character, two @samp{control-z}
31520characters, and the name of the annotation. If there is no additional
31521information associated with this annotation, the name of the annotation
31522is followed immediately by a newline. If there is additional
31523information, the name of the annotation is followed by a space, the
31524additional information, and a newline. The additional information
31525cannot contain newline characters.
31526
31527Any output not beginning with a newline and two @samp{control-z}
31528characters denotes literal output from @value{GDBN}. Currently there is
31529no need for @value{GDBN} to output a newline followed by two
31530@samp{control-z} characters, but if there was such a need, the
31531annotations could be extended with an @samp{escape} annotation which
31532means those three characters as output.
31533
086432e2
AC
31534The annotation @var{level}, which is specified using the
31535@option{--annotate} command line option (@pxref{Mode Options}), controls
31536how much information @value{GDBN} prints together with its prompt,
31537values of expressions, source lines, and other types of output. Level 0
d3e8051b 31538is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
31539subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
31540for programs that control @value{GDBN}, and level 2 annotations have
31541been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
31542Interface, annotate, GDB's Obsolete Annotations}).
31543
31544@table @code
31545@kindex set annotate
31546@item set annotate @var{level}
e09f16f9 31547The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 31548annotations to the specified @var{level}.
9c16f35a
EZ
31549
31550@item show annotate
31551@kindex show annotate
31552Show the current annotation level.
09d4efe1
EZ
31553@end table
31554
31555This chapter describes level 3 annotations.
086432e2 31556
922fbb7b
AC
31557A simple example of starting up @value{GDBN} with annotations is:
31558
31559@smallexample
086432e2
AC
31560$ @kbd{gdb --annotate=3}
31561GNU gdb 6.0
31562Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
31563GDB is free software, covered by the GNU General Public License,
31564and you are welcome to change it and/or distribute copies of it
31565under certain conditions.
31566Type "show copying" to see the conditions.
31567There is absolutely no warranty for GDB. Type "show warranty"
31568for details.
086432e2 31569This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
31570
31571^Z^Zpre-prompt
f7dc1244 31572(@value{GDBP})
922fbb7b 31573^Z^Zprompt
086432e2 31574@kbd{quit}
922fbb7b
AC
31575
31576^Z^Zpost-prompt
b383017d 31577$
922fbb7b
AC
31578@end smallexample
31579
31580Here @samp{quit} is input to @value{GDBN}; the rest is output from
31581@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
31582denotes a @samp{control-z} character) are annotations; the rest is
31583output from @value{GDBN}.
31584
9e6c4bd5
NR
31585@node Server Prefix
31586@section The Server Prefix
31587@cindex server prefix
31588
31589If you prefix a command with @samp{server } then it will not affect
31590the command history, nor will it affect @value{GDBN}'s notion of which
31591command to repeat if @key{RET} is pressed on a line by itself. This
31592means that commands can be run behind a user's back by a front-end in
31593a transparent manner.
31594
d837706a
NR
31595The @code{server } prefix does not affect the recording of values into
31596the value history; to print a value without recording it into the
31597value history, use the @code{output} command instead of the
31598@code{print} command.
31599
31600Using this prefix also disables confirmation requests
31601(@pxref{confirmation requests}).
9e6c4bd5 31602
922fbb7b
AC
31603@node Prompting
31604@section Annotation for @value{GDBN} Input
31605
31606@cindex annotations for prompts
31607When @value{GDBN} prompts for input, it annotates this fact so it is possible
31608to know when to send output, when the output from a given command is
31609over, etc.
31610
31611Different kinds of input each have a different @dfn{input type}. Each
31612input type has three annotations: a @code{pre-} annotation, which
31613denotes the beginning of any prompt which is being output, a plain
31614annotation, which denotes the end of the prompt, and then a @code{post-}
31615annotation which denotes the end of any echo which may (or may not) be
31616associated with the input. For example, the @code{prompt} input type
31617features the following annotations:
31618
31619@smallexample
31620^Z^Zpre-prompt
31621^Z^Zprompt
31622^Z^Zpost-prompt
31623@end smallexample
31624
31625The input types are
31626
31627@table @code
e5ac9b53
EZ
31628@findex pre-prompt annotation
31629@findex prompt annotation
31630@findex post-prompt annotation
922fbb7b
AC
31631@item prompt
31632When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
31633
e5ac9b53
EZ
31634@findex pre-commands annotation
31635@findex commands annotation
31636@findex post-commands annotation
922fbb7b
AC
31637@item commands
31638When @value{GDBN} prompts for a set of commands, like in the @code{commands}
31639command. The annotations are repeated for each command which is input.
31640
e5ac9b53
EZ
31641@findex pre-overload-choice annotation
31642@findex overload-choice annotation
31643@findex post-overload-choice annotation
922fbb7b
AC
31644@item overload-choice
31645When @value{GDBN} wants the user to select between various overloaded functions.
31646
e5ac9b53
EZ
31647@findex pre-query annotation
31648@findex query annotation
31649@findex post-query annotation
922fbb7b
AC
31650@item query
31651When @value{GDBN} wants the user to confirm a potentially dangerous operation.
31652
e5ac9b53
EZ
31653@findex pre-prompt-for-continue annotation
31654@findex prompt-for-continue annotation
31655@findex post-prompt-for-continue annotation
922fbb7b
AC
31656@item prompt-for-continue
31657When @value{GDBN} is asking the user to press return to continue. Note: Don't
31658expect this to work well; instead use @code{set height 0} to disable
31659prompting. This is because the counting of lines is buggy in the
31660presence of annotations.
31661@end table
31662
31663@node Errors
31664@section Errors
31665@cindex annotations for errors, warnings and interrupts
31666
e5ac9b53 31667@findex quit annotation
922fbb7b
AC
31668@smallexample
31669^Z^Zquit
31670@end smallexample
31671
31672This annotation occurs right before @value{GDBN} responds to an interrupt.
31673
e5ac9b53 31674@findex error annotation
922fbb7b
AC
31675@smallexample
31676^Z^Zerror
31677@end smallexample
31678
31679This annotation occurs right before @value{GDBN} responds to an error.
31680
31681Quit and error annotations indicate that any annotations which @value{GDBN} was
31682in the middle of may end abruptly. For example, if a
31683@code{value-history-begin} annotation is followed by a @code{error}, one
31684cannot expect to receive the matching @code{value-history-end}. One
31685cannot expect not to receive it either, however; an error annotation
31686does not necessarily mean that @value{GDBN} is immediately returning all the way
31687to the top level.
31688
e5ac9b53 31689@findex error-begin annotation
922fbb7b
AC
31690A quit or error annotation may be preceded by
31691
31692@smallexample
31693^Z^Zerror-begin
31694@end smallexample
31695
31696Any output between that and the quit or error annotation is the error
31697message.
31698
31699Warning messages are not yet annotated.
31700@c If we want to change that, need to fix warning(), type_error(),
31701@c range_error(), and possibly other places.
31702
922fbb7b
AC
31703@node Invalidation
31704@section Invalidation Notices
31705
31706@cindex annotations for invalidation messages
31707The following annotations say that certain pieces of state may have
31708changed.
31709
31710@table @code
e5ac9b53 31711@findex frames-invalid annotation
922fbb7b
AC
31712@item ^Z^Zframes-invalid
31713
31714The frames (for example, output from the @code{backtrace} command) may
31715have changed.
31716
e5ac9b53 31717@findex breakpoints-invalid annotation
922fbb7b
AC
31718@item ^Z^Zbreakpoints-invalid
31719
31720The breakpoints may have changed. For example, the user just added or
31721deleted a breakpoint.
31722@end table
31723
31724@node Annotations for Running
31725@section Running the Program
31726@cindex annotations for running programs
31727
e5ac9b53
EZ
31728@findex starting annotation
31729@findex stopping annotation
922fbb7b 31730When the program starts executing due to a @value{GDBN} command such as
b383017d 31731@code{step} or @code{continue},
922fbb7b
AC
31732
31733@smallexample
31734^Z^Zstarting
31735@end smallexample
31736
b383017d 31737is output. When the program stops,
922fbb7b
AC
31738
31739@smallexample
31740^Z^Zstopped
31741@end smallexample
31742
31743is output. Before the @code{stopped} annotation, a variety of
31744annotations describe how the program stopped.
31745
31746@table @code
e5ac9b53 31747@findex exited annotation
922fbb7b
AC
31748@item ^Z^Zexited @var{exit-status}
31749The program exited, and @var{exit-status} is the exit status (zero for
31750successful exit, otherwise nonzero).
31751
e5ac9b53
EZ
31752@findex signalled annotation
31753@findex signal-name annotation
31754@findex signal-name-end annotation
31755@findex signal-string annotation
31756@findex signal-string-end annotation
922fbb7b
AC
31757@item ^Z^Zsignalled
31758The program exited with a signal. After the @code{^Z^Zsignalled}, the
31759annotation continues:
31760
31761@smallexample
31762@var{intro-text}
31763^Z^Zsignal-name
31764@var{name}
31765^Z^Zsignal-name-end
31766@var{middle-text}
31767^Z^Zsignal-string
31768@var{string}
31769^Z^Zsignal-string-end
31770@var{end-text}
31771@end smallexample
31772
31773@noindent
31774where @var{name} is the name of the signal, such as @code{SIGILL} or
31775@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
31776as @code{Illegal Instruction} or @code{Segmentation fault}.
31777@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
31778user's benefit and have no particular format.
31779
e5ac9b53 31780@findex signal annotation
922fbb7b
AC
31781@item ^Z^Zsignal
31782The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
31783just saying that the program received the signal, not that it was
31784terminated with it.
31785
e5ac9b53 31786@findex breakpoint annotation
922fbb7b
AC
31787@item ^Z^Zbreakpoint @var{number}
31788The program hit breakpoint number @var{number}.
31789
e5ac9b53 31790@findex watchpoint annotation
922fbb7b
AC
31791@item ^Z^Zwatchpoint @var{number}
31792The program hit watchpoint number @var{number}.
31793@end table
31794
31795@node Source Annotations
31796@section Displaying Source
31797@cindex annotations for source display
31798
e5ac9b53 31799@findex source annotation
922fbb7b
AC
31800The following annotation is used instead of displaying source code:
31801
31802@smallexample
31803^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
31804@end smallexample
31805
31806where @var{filename} is an absolute file name indicating which source
31807file, @var{line} is the line number within that file (where 1 is the
31808first line in the file), @var{character} is the character position
31809within the file (where 0 is the first character in the file) (for most
31810debug formats this will necessarily point to the beginning of a line),
31811@var{middle} is @samp{middle} if @var{addr} is in the middle of the
31812line, or @samp{beg} if @var{addr} is at the beginning of the line, and
31813@var{addr} is the address in the target program associated with the
31814source which is being displayed. @var{addr} is in the form @samp{0x}
31815followed by one or more lowercase hex digits (note that this does not
31816depend on the language).
31817
4efc6507
DE
31818@node JIT Interface
31819@chapter JIT Compilation Interface
31820@cindex just-in-time compilation
31821@cindex JIT compilation interface
31822
31823This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
31824interface. A JIT compiler is a program or library that generates native
31825executable code at runtime and executes it, usually in order to achieve good
31826performance while maintaining platform independence.
31827
31828Programs that use JIT compilation are normally difficult to debug because
31829portions of their code are generated at runtime, instead of being loaded from
31830object files, which is where @value{GDBN} normally finds the program's symbols
31831and debug information. In order to debug programs that use JIT compilation,
31832@value{GDBN} has an interface that allows the program to register in-memory
31833symbol files with @value{GDBN} at runtime.
31834
31835If you are using @value{GDBN} to debug a program that uses this interface, then
31836it should work transparently so long as you have not stripped the binary. If
31837you are developing a JIT compiler, then the interface is documented in the rest
31838of this chapter. At this time, the only known client of this interface is the
31839LLVM JIT.
31840
31841Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
31842JIT compiler communicates with @value{GDBN} by writing data into a global
31843variable and calling a fuction at a well-known symbol. When @value{GDBN}
31844attaches, it reads a linked list of symbol files from the global variable to
31845find existing code, and puts a breakpoint in the function so that it can find
31846out about additional code.
31847
31848@menu
31849* Declarations:: Relevant C struct declarations
31850* Registering Code:: Steps to register code
31851* Unregistering Code:: Steps to unregister code
f85b53f8 31852* Custom Debug Info:: Emit debug information in a custom format
4efc6507
DE
31853@end menu
31854
31855@node Declarations
31856@section JIT Declarations
31857
31858These are the relevant struct declarations that a C program should include to
31859implement the interface:
31860
31861@smallexample
31862typedef enum
31863@{
31864 JIT_NOACTION = 0,
31865 JIT_REGISTER_FN,
31866 JIT_UNREGISTER_FN
31867@} jit_actions_t;
31868
31869struct jit_code_entry
31870@{
31871 struct jit_code_entry *next_entry;
31872 struct jit_code_entry *prev_entry;
31873 const char *symfile_addr;
31874 uint64_t symfile_size;
31875@};
31876
31877struct jit_descriptor
31878@{
31879 uint32_t version;
31880 /* This type should be jit_actions_t, but we use uint32_t
31881 to be explicit about the bitwidth. */
31882 uint32_t action_flag;
31883 struct jit_code_entry *relevant_entry;
31884 struct jit_code_entry *first_entry;
31885@};
31886
31887/* GDB puts a breakpoint in this function. */
31888void __attribute__((noinline)) __jit_debug_register_code() @{ @};
31889
31890/* Make sure to specify the version statically, because the
31891 debugger may check the version before we can set it. */
31892struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
31893@end smallexample
31894
31895If the JIT is multi-threaded, then it is important that the JIT synchronize any
31896modifications to this global data properly, which can easily be done by putting
31897a global mutex around modifications to these structures.
31898
31899@node Registering Code
31900@section Registering Code
31901
31902To register code with @value{GDBN}, the JIT should follow this protocol:
31903
31904@itemize @bullet
31905@item
31906Generate an object file in memory with symbols and other desired debug
31907information. The file must include the virtual addresses of the sections.
31908
31909@item
31910Create a code entry for the file, which gives the start and size of the symbol
31911file.
31912
31913@item
31914Add it to the linked list in the JIT descriptor.
31915
31916@item
31917Point the relevant_entry field of the descriptor at the entry.
31918
31919@item
31920Set @code{action_flag} to @code{JIT_REGISTER} and call
31921@code{__jit_debug_register_code}.
31922@end itemize
31923
31924When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
31925@code{relevant_entry} pointer so it doesn't have to walk the list looking for
31926new code. However, the linked list must still be maintained in order to allow
31927@value{GDBN} to attach to a running process and still find the symbol files.
31928
31929@node Unregistering Code
31930@section Unregistering Code
31931
31932If code is freed, then the JIT should use the following protocol:
31933
31934@itemize @bullet
31935@item
31936Remove the code entry corresponding to the code from the linked list.
31937
31938@item
31939Point the @code{relevant_entry} field of the descriptor at the code entry.
31940
31941@item
31942Set @code{action_flag} to @code{JIT_UNREGISTER} and call
31943@code{__jit_debug_register_code}.
31944@end itemize
31945
31946If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
31947and the JIT will leak the memory used for the associated symbol files.
31948
f85b53f8
SD
31949@node Custom Debug Info
31950@section Custom Debug Info
31951@cindex custom JIT debug info
31952@cindex JIT debug info reader
31953
31954Generating debug information in platform-native file formats (like ELF
31955or COFF) may be an overkill for JIT compilers; especially if all the
31956debug info is used for is displaying a meaningful backtrace. The
31957issue can be resolved by having the JIT writers decide on a debug info
31958format and also provide a reader that parses the debug info generated
31959by the JIT compiler. This section gives a brief overview on writing
31960such a parser. More specific details can be found in the source file
31961@file{gdb/jit-reader.in}, which is also installed as a header at
31962@file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
31963
31964The reader is implemented as a shared object (so this functionality is
31965not available on platforms which don't allow loading shared objects at
31966runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
31967@code{jit-reader-unload} are provided, to be used to load and unload
31968the readers from a preconfigured directory. Once loaded, the shared
31969object is used the parse the debug information emitted by the JIT
31970compiler.
31971
31972@menu
31973* Using JIT Debug Info Readers:: How to use supplied readers correctly
31974* Writing JIT Debug Info Readers:: Creating a debug-info reader
31975@end menu
31976
31977@node Using JIT Debug Info Readers
31978@subsection Using JIT Debug Info Readers
31979@kindex jit-reader-load
31980@kindex jit-reader-unload
31981
31982Readers can be loaded and unloaded using the @code{jit-reader-load}
31983and @code{jit-reader-unload} commands.
31984
31985@table @code
c9fb1240
SD
31986@item jit-reader-load @var{reader}
31987Load the JIT reader named @var{reader}. @var{reader} is a shared
31988object specified as either an absolute or a relative file name. In
31989the latter case, @value{GDBN} will try to load the reader from a
31990pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
31991system (here @var{libdir} is the system library directory, often
31992@file{/usr/local/lib}).
31993
31994Only one reader can be active at a time; trying to load a second
31995reader when one is already loaded will result in @value{GDBN}
31996reporting an error. A new JIT reader can be loaded by first unloading
31997the current one using @code{jit-reader-unload} and then invoking
31998@code{jit-reader-load}.
f85b53f8
SD
31999
32000@item jit-reader-unload
32001Unload the currently loaded JIT reader.
32002
32003@end table
32004
32005@node Writing JIT Debug Info Readers
32006@subsection Writing JIT Debug Info Readers
32007@cindex writing JIT debug info readers
32008
32009As mentioned, a reader is essentially a shared object conforming to a
32010certain ABI. This ABI is described in @file{jit-reader.h}.
32011
32012@file{jit-reader.h} defines the structures, macros and functions
32013required to write a reader. It is installed (along with
32014@value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
32015the system include directory.
32016
32017Readers need to be released under a GPL compatible license. A reader
32018can be declared as released under such a license by placing the macro
32019@code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
32020
32021The entry point for readers is the symbol @code{gdb_init_reader},
32022which is expected to be a function with the prototype
32023
32024@findex gdb_init_reader
32025@smallexample
32026extern struct gdb_reader_funcs *gdb_init_reader (void);
32027@end smallexample
32028
32029@cindex @code{struct gdb_reader_funcs}
32030
32031@code{struct gdb_reader_funcs} contains a set of pointers to callback
32032functions. These functions are executed to read the debug info
32033generated by the JIT compiler (@code{read}), to unwind stack frames
32034(@code{unwind}) and to create canonical frame IDs
32035(@code{get_Frame_id}). It also has a callback that is called when the
32036reader is being unloaded (@code{destroy}). The struct looks like this
32037
32038@smallexample
32039struct gdb_reader_funcs
32040@{
32041 /* Must be set to GDB_READER_INTERFACE_VERSION. */
32042 int reader_version;
32043
32044 /* For use by the reader. */
32045 void *priv_data;
32046
32047 gdb_read_debug_info *read;
32048 gdb_unwind_frame *unwind;
32049 gdb_get_frame_id *get_frame_id;
32050 gdb_destroy_reader *destroy;
32051@};
32052@end smallexample
32053
32054@cindex @code{struct gdb_symbol_callbacks}
32055@cindex @code{struct gdb_unwind_callbacks}
32056
32057The callbacks are provided with another set of callbacks by
32058@value{GDBN} to do their job. For @code{read}, these callbacks are
32059passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
32060and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
32061@code{struct gdb_symbol_callbacks} has callbacks to create new object
32062files and new symbol tables inside those object files. @code{struct
32063gdb_unwind_callbacks} has callbacks to read registers off the current
32064frame and to write out the values of the registers in the previous
32065frame. Both have a callback (@code{target_read}) to read bytes off the
32066target's address space.
32067
d1feda86
YQ
32068@node In-Process Agent
32069@chapter In-Process Agent
32070@cindex debugging agent
32071The traditional debugging model is conceptually low-speed, but works fine,
32072because most bugs can be reproduced in debugging-mode execution. However,
32073as multi-core or many-core processors are becoming mainstream, and
32074multi-threaded programs become more and more popular, there should be more
32075and more bugs that only manifest themselves at normal-mode execution, for
32076example, thread races, because debugger's interference with the program's
32077timing may conceal the bugs. On the other hand, in some applications,
32078it is not feasible for the debugger to interrupt the program's execution
32079long enough for the developer to learn anything helpful about its behavior.
32080If the program's correctness depends on its real-time behavior, delays
32081introduced by a debugger might cause the program to fail, even when the
32082code itself is correct. It is useful to be able to observe the program's
32083behavior without interrupting it.
32084
32085Therefore, traditional debugging model is too intrusive to reproduce
32086some bugs. In order to reduce the interference with the program, we can
32087reduce the number of operations performed by debugger. The
32088@dfn{In-Process Agent}, a shared library, is running within the same
32089process with inferior, and is able to perform some debugging operations
32090itself. As a result, debugger is only involved when necessary, and
32091performance of debugging can be improved accordingly. Note that
32092interference with program can be reduced but can't be removed completely,
32093because the in-process agent will still stop or slow down the program.
32094
32095The in-process agent can interpret and execute Agent Expressions
32096(@pxref{Agent Expressions}) during performing debugging operations. The
32097agent expressions can be used for different purposes, such as collecting
32098data in tracepoints, and condition evaluation in breakpoints.
32099
32100@anchor{Control Agent}
32101You can control whether the in-process agent is used as an aid for
32102debugging with the following commands:
32103
32104@table @code
32105@kindex set agent on
32106@item set agent on
32107Causes the in-process agent to perform some operations on behalf of the
32108debugger. Just which operations requested by the user will be done
32109by the in-process agent depends on the its capabilities. For example,
32110if you request to evaluate breakpoint conditions in the in-process agent,
32111and the in-process agent has such capability as well, then breakpoint
32112conditions will be evaluated in the in-process agent.
32113
32114@kindex set agent off
32115@item set agent off
32116Disables execution of debugging operations by the in-process agent. All
32117of the operations will be performed by @value{GDBN}.
32118
32119@kindex show agent
32120@item show agent
32121Display the current setting of execution of debugging operations by
32122the in-process agent.
32123@end table
32124
16bdd41f
YQ
32125@menu
32126* In-Process Agent Protocol::
32127@end menu
32128
32129@node In-Process Agent Protocol
32130@section In-Process Agent Protocol
32131@cindex in-process agent protocol
32132
32133The in-process agent is able to communicate with both @value{GDBN} and
32134GDBserver (@pxref{In-Process Agent}). This section documents the protocol
32135used for communications between @value{GDBN} or GDBserver and the IPA.
32136In general, @value{GDBN} or GDBserver sends commands
32137(@pxref{IPA Protocol Commands}) and data to in-process agent, and then
32138in-process agent replies back with the return result of the command, or
32139some other information. The data sent to in-process agent is composed
32140of primitive data types, such as 4-byte or 8-byte type, and composite
32141types, which are called objects (@pxref{IPA Protocol Objects}).
32142
32143@menu
32144* IPA Protocol Objects::
32145* IPA Protocol Commands::
32146@end menu
32147
32148@node IPA Protocol Objects
32149@subsection IPA Protocol Objects
32150@cindex ipa protocol objects
32151
32152The commands sent to and results received from agent may contain some
32153complex data types called @dfn{objects}.
32154
32155The in-process agent is running on the same machine with @value{GDBN}
32156or GDBserver, so it doesn't have to handle as much differences between
32157two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
32158However, there are still some differences of two ends in two processes:
32159
32160@enumerate
32161@item
32162word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
32163compiled as a 64-bit executable, while in-process agent is a 32-bit one.
32164@item
32165ABI. Some machines may have multiple types of ABI, @value{GDBN} or
32166GDBserver is compiled with one, and in-process agent is compiled with
32167the other one.
32168@end enumerate
32169
32170Here are the IPA Protocol Objects:
32171
32172@enumerate
32173@item
32174agent expression object. It represents an agent expression
32175(@pxref{Agent Expressions}).
32176@anchor{agent expression object}
32177@item
32178tracepoint action object. It represents a tracepoint action
32179(@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
32180memory, static trace data and to evaluate expression.
32181@anchor{tracepoint action object}
32182@item
32183tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
32184@anchor{tracepoint object}
32185
32186@end enumerate
32187
32188The following table describes important attributes of each IPA protocol
32189object:
32190
32191@multitable @columnfractions .30 .20 .50
32192@headitem Name @tab Size @tab Description
32193@item @emph{agent expression object} @tab @tab
32194@item length @tab 4 @tab length of bytes code
32195@item byte code @tab @var{length} @tab contents of byte code
32196@item @emph{tracepoint action for collecting memory} @tab @tab
32197@item 'M' @tab 1 @tab type of tracepoint action
32198@item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
32199address of the lowest byte to collect, otherwise @var{addr} is the offset
32200of @var{basereg} for memory collecting.
32201@item len @tab 8 @tab length of memory for collecting
32202@item basereg @tab 4 @tab the register number containing the starting
32203memory address for collecting.
32204@item @emph{tracepoint action for collecting registers} @tab @tab
32205@item 'R' @tab 1 @tab type of tracepoint action
32206@item @emph{tracepoint action for collecting static trace data} @tab @tab
32207@item 'L' @tab 1 @tab type of tracepoint action
32208@item @emph{tracepoint action for expression evaluation} @tab @tab
32209@item 'X' @tab 1 @tab type of tracepoint action
32210@item agent expression @tab length of @tab @ref{agent expression object}
32211@item @emph{tracepoint object} @tab @tab
32212@item number @tab 4 @tab number of tracepoint
32213@item address @tab 8 @tab address of tracepoint inserted on
32214@item type @tab 4 @tab type of tracepoint
32215@item enabled @tab 1 @tab enable or disable of tracepoint
32216@item step_count @tab 8 @tab step
32217@item pass_count @tab 8 @tab pass
32218@item numactions @tab 4 @tab number of tracepoint actions
32219@item hit count @tab 8 @tab hit count
32220@item trace frame usage @tab 8 @tab trace frame usage
32221@item compiled_cond @tab 8 @tab compiled condition
32222@item orig_size @tab 8 @tab orig size
32223@item condition @tab 4 if condition is NULL otherwise length of
32224@ref{agent expression object}
32225@tab zero if condition is NULL, otherwise is
32226@ref{agent expression object}
32227@item actions @tab variable
32228@tab numactions number of @ref{tracepoint action object}
32229@end multitable
32230
32231@node IPA Protocol Commands
32232@subsection IPA Protocol Commands
32233@cindex ipa protocol commands
32234
32235The spaces in each command are delimiters to ease reading this commands
32236specification. They don't exist in real commands.
32237
32238@table @samp
32239
32240@item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
32241Installs a new fast tracepoint described by @var{tracepoint_object}
32242(@pxref{tracepoint object}). @var{gdb_jump_pad_head}, 8-byte long, is the
32243head of @dfn{jumppad}, which is used to jump to data collection routine
32244in IPA finally.
32245
32246Replies:
32247@table @samp
32248@item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
32249@var{target_address} is address of tracepoint in the inferior.
32250@var{gdb_jump_pad_head} is updated head of jumppad. Both of
32251@var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
32252@var{fjump} contains a sequence of instructions jump to jumppad entry.
32253@var{fjump_size}, 4-byte long, is the size of @var{fjump}.
32254@item E @var{NN}
32255for an error
32256
32257@end table
32258
7255706c
YQ
32259@item close
32260Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
32261is about to kill inferiors.
32262
16bdd41f
YQ
32263@item qTfSTM
32264@xref{qTfSTM}.
32265@item qTsSTM
32266@xref{qTsSTM}.
32267@item qTSTMat
32268@xref{qTSTMat}.
32269@item probe_marker_at:@var{address}
32270Asks in-process agent to probe the marker at @var{address}.
32271
32272Replies:
32273@table @samp
32274@item E @var{NN}
32275for an error
32276@end table
32277@item unprobe_marker_at:@var{address}
32278Asks in-process agent to unprobe the marker at @var{address}.
32279@end table
32280
8e04817f
AC
32281@node GDB Bugs
32282@chapter Reporting Bugs in @value{GDBN}
32283@cindex bugs in @value{GDBN}
32284@cindex reporting bugs in @value{GDBN}
c906108c 32285
8e04817f 32286Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 32287
8e04817f
AC
32288Reporting a bug may help you by bringing a solution to your problem, or it
32289may not. But in any case the principal function of a bug report is to help
32290the entire community by making the next version of @value{GDBN} work better. Bug
32291reports are your contribution to the maintenance of @value{GDBN}.
c906108c 32292
8e04817f
AC
32293In order for a bug report to serve its purpose, you must include the
32294information that enables us to fix the bug.
c4555f82
SC
32295
32296@menu
8e04817f
AC
32297* Bug Criteria:: Have you found a bug?
32298* Bug Reporting:: How to report bugs
c4555f82
SC
32299@end menu
32300
8e04817f 32301@node Bug Criteria
79a6e687 32302@section Have You Found a Bug?
8e04817f 32303@cindex bug criteria
c4555f82 32304
8e04817f 32305If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
32306
32307@itemize @bullet
8e04817f
AC
32308@cindex fatal signal
32309@cindex debugger crash
32310@cindex crash of debugger
c4555f82 32311@item
8e04817f
AC
32312If the debugger gets a fatal signal, for any input whatever, that is a
32313@value{GDBN} bug. Reliable debuggers never crash.
32314
32315@cindex error on valid input
32316@item
32317If @value{GDBN} produces an error message for valid input, that is a
32318bug. (Note that if you're cross debugging, the problem may also be
32319somewhere in the connection to the target.)
c4555f82 32320
8e04817f 32321@cindex invalid input
c4555f82 32322@item
8e04817f
AC
32323If @value{GDBN} does not produce an error message for invalid input,
32324that is a bug. However, you should note that your idea of
32325``invalid input'' might be our idea of ``an extension'' or ``support
32326for traditional practice''.
32327
32328@item
32329If you are an experienced user of debugging tools, your suggestions
32330for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
32331@end itemize
32332
8e04817f 32333@node Bug Reporting
79a6e687 32334@section How to Report Bugs
8e04817f
AC
32335@cindex bug reports
32336@cindex @value{GDBN} bugs, reporting
32337
32338A number of companies and individuals offer support for @sc{gnu} products.
32339If you obtained @value{GDBN} from a support organization, we recommend you
32340contact that organization first.
32341
32342You can find contact information for many support companies and
32343individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
32344distribution.
32345@c should add a web page ref...
32346
c16158bc
JM
32347@ifset BUGURL
32348@ifset BUGURL_DEFAULT
129188f6 32349In any event, we also recommend that you submit bug reports for
d3e8051b 32350@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
32351@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
32352page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
32353be used.
8e04817f
AC
32354
32355@strong{Do not send bug reports to @samp{info-gdb}, or to
32356@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
32357not want to receive bug reports. Those that do have arranged to receive
32358@samp{bug-gdb}.
32359
32360The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
32361serves as a repeater. The mailing list and the newsgroup carry exactly
32362the same messages. Often people think of posting bug reports to the
32363newsgroup instead of mailing them. This appears to work, but it has one
32364problem which can be crucial: a newsgroup posting often lacks a mail
32365path back to the sender. Thus, if we need to ask for more information,
32366we may be unable to reach you. For this reason, it is better to send
32367bug reports to the mailing list.
c16158bc
JM
32368@end ifset
32369@ifclear BUGURL_DEFAULT
32370In any event, we also recommend that you submit bug reports for
32371@value{GDBN} to @value{BUGURL}.
32372@end ifclear
32373@end ifset
c4555f82 32374
8e04817f
AC
32375The fundamental principle of reporting bugs usefully is this:
32376@strong{report all the facts}. If you are not sure whether to state a
32377fact or leave it out, state it!
c4555f82 32378
8e04817f
AC
32379Often people omit facts because they think they know what causes the
32380problem and assume that some details do not matter. Thus, you might
32381assume that the name of the variable you use in an example does not matter.
32382Well, probably it does not, but one cannot be sure. Perhaps the bug is a
32383stray memory reference which happens to fetch from the location where that
32384name is stored in memory; perhaps, if the name were different, the contents
32385of that location would fool the debugger into doing the right thing despite
32386the bug. Play it safe and give a specific, complete example. That is the
32387easiest thing for you to do, and the most helpful.
c4555f82 32388
8e04817f
AC
32389Keep in mind that the purpose of a bug report is to enable us to fix the
32390bug. It may be that the bug has been reported previously, but neither
32391you nor we can know that unless your bug report is complete and
32392self-contained.
c4555f82 32393
8e04817f
AC
32394Sometimes people give a few sketchy facts and ask, ``Does this ring a
32395bell?'' Those bug reports are useless, and we urge everyone to
32396@emph{refuse to respond to them} except to chide the sender to report
32397bugs properly.
32398
32399To enable us to fix the bug, you should include all these things:
c4555f82
SC
32400
32401@itemize @bullet
32402@item
8e04817f
AC
32403The version of @value{GDBN}. @value{GDBN} announces it if you start
32404with no arguments; you can also print it at any time using @code{show
32405version}.
c4555f82 32406
8e04817f
AC
32407Without this, we will not know whether there is any point in looking for
32408the bug in the current version of @value{GDBN}.
c4555f82
SC
32409
32410@item
8e04817f
AC
32411The type of machine you are using, and the operating system name and
32412version number.
c4555f82 32413
6eaaf48b
EZ
32414@item
32415The details of the @value{GDBN} build-time configuration.
32416@value{GDBN} shows these details if you invoke it with the
32417@option{--configuration} command-line option, or if you type
32418@code{show configuration} at @value{GDBN}'s prompt.
32419
c4555f82 32420@item
c1468174 32421What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 32422``@value{GCC}--2.8.1''.
c4555f82
SC
32423
32424@item
8e04817f 32425What compiler (and its version) was used to compile the program you are
c1468174 32426debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
32427C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
32428to get this information; for other compilers, see the documentation for
32429those compilers.
c4555f82 32430
8e04817f
AC
32431@item
32432The command arguments you gave the compiler to compile your example and
32433observe the bug. For example, did you use @samp{-O}? To guarantee
32434you will not omit something important, list them all. A copy of the
32435Makefile (or the output from make) is sufficient.
c4555f82 32436
8e04817f
AC
32437If we were to try to guess the arguments, we would probably guess wrong
32438and then we might not encounter the bug.
c4555f82 32439
8e04817f
AC
32440@item
32441A complete input script, and all necessary source files, that will
32442reproduce the bug.
c4555f82 32443
8e04817f
AC
32444@item
32445A description of what behavior you observe that you believe is
32446incorrect. For example, ``It gets a fatal signal.''
c4555f82 32447
8e04817f
AC
32448Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
32449will certainly notice it. But if the bug is incorrect output, we might
32450not notice unless it is glaringly wrong. You might as well not give us
32451a chance to make a mistake.
c4555f82 32452
8e04817f
AC
32453Even if the problem you experience is a fatal signal, you should still
32454say so explicitly. Suppose something strange is going on, such as, your
32455copy of @value{GDBN} is out of synch, or you have encountered a bug in
32456the C library on your system. (This has happened!) Your copy might
32457crash and ours would not. If you told us to expect a crash, then when
32458ours fails to crash, we would know that the bug was not happening for
32459us. If you had not told us to expect a crash, then we would not be able
32460to draw any conclusion from our observations.
c4555f82 32461
e0c07bf0
MC
32462@pindex script
32463@cindex recording a session script
32464To collect all this information, you can use a session recording program
32465such as @command{script}, which is available on many Unix systems.
32466Just run your @value{GDBN} session inside @command{script} and then
32467include the @file{typescript} file with your bug report.
32468
32469Another way to record a @value{GDBN} session is to run @value{GDBN}
32470inside Emacs and then save the entire buffer to a file.
32471
8e04817f
AC
32472@item
32473If you wish to suggest changes to the @value{GDBN} source, send us context
32474diffs. If you even discuss something in the @value{GDBN} source, refer to
32475it by context, not by line number.
c4555f82 32476
8e04817f
AC
32477The line numbers in our development sources will not match those in your
32478sources. Your line numbers would convey no useful information to us.
c4555f82 32479
8e04817f 32480@end itemize
c4555f82 32481
8e04817f 32482Here are some things that are not necessary:
c4555f82 32483
8e04817f
AC
32484@itemize @bullet
32485@item
32486A description of the envelope of the bug.
c4555f82 32487
8e04817f
AC
32488Often people who encounter a bug spend a lot of time investigating
32489which changes to the input file will make the bug go away and which
32490changes will not affect it.
c4555f82 32491
8e04817f
AC
32492This is often time consuming and not very useful, because the way we
32493will find the bug is by running a single example under the debugger
32494with breakpoints, not by pure deduction from a series of examples.
32495We recommend that you save your time for something else.
c4555f82 32496
8e04817f
AC
32497Of course, if you can find a simpler example to report @emph{instead}
32498of the original one, that is a convenience for us. Errors in the
32499output will be easier to spot, running under the debugger will take
32500less time, and so on.
c4555f82 32501
8e04817f
AC
32502However, simplification is not vital; if you do not want to do this,
32503report the bug anyway and send us the entire test case you used.
c4555f82 32504
8e04817f
AC
32505@item
32506A patch for the bug.
c4555f82 32507
8e04817f
AC
32508A patch for the bug does help us if it is a good one. But do not omit
32509the necessary information, such as the test case, on the assumption that
32510a patch is all we need. We might see problems with your patch and decide
32511to fix the problem another way, or we might not understand it at all.
c4555f82 32512
8e04817f
AC
32513Sometimes with a program as complicated as @value{GDBN} it is very hard to
32514construct an example that will make the program follow a certain path
32515through the code. If you do not send us the example, we will not be able
32516to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 32517
8e04817f
AC
32518And if we cannot understand what bug you are trying to fix, or why your
32519patch should be an improvement, we will not install it. A test case will
32520help us to understand.
c4555f82 32521
8e04817f
AC
32522@item
32523A guess about what the bug is or what it depends on.
c4555f82 32524
8e04817f
AC
32525Such guesses are usually wrong. Even we cannot guess right about such
32526things without first using the debugger to find the facts.
32527@end itemize
c4555f82 32528
8e04817f
AC
32529@c The readline documentation is distributed with the readline code
32530@c and consists of the two following files:
cc88a640
JK
32531@c rluser.texi
32532@c hsuser.texi
8e04817f
AC
32533@c Use -I with makeinfo to point to the appropriate directory,
32534@c environment var TEXINPUTS with TeX.
39037522 32535@ifclear SYSTEM_READLINE
5bdf8622 32536@include rluser.texi
cc88a640 32537@include hsuser.texi
39037522 32538@end ifclear
c4555f82 32539
4ceed123
JB
32540@node In Memoriam
32541@appendix In Memoriam
32542
9ed350ad
JB
32543The @value{GDBN} project mourns the loss of the following long-time
32544contributors:
4ceed123
JB
32545
32546@table @code
32547@item Fred Fish
9ed350ad
JB
32548Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
32549to Free Software in general. Outside of @value{GDBN}, he was known in
32550the Amiga world for his series of Fish Disks, and the GeekGadget project.
4ceed123
JB
32551
32552@item Michael Snyder
9ed350ad
JB
32553Michael was one of the Global Maintainers of the @value{GDBN} project,
32554with contributions recorded as early as 1996, until 2011. In addition
32555to his day to day participation, he was a large driving force behind
32556adding Reverse Debugging to @value{GDBN}.
4ceed123
JB
32557@end table
32558
32559Beyond their technical contributions to the project, they were also
32560enjoyable members of the Free Software Community. We will miss them.
c4555f82 32561
8e04817f
AC
32562@node Formatting Documentation
32563@appendix Formatting Documentation
c4555f82 32564
8e04817f
AC
32565@cindex @value{GDBN} reference card
32566@cindex reference card
32567The @value{GDBN} 4 release includes an already-formatted reference card, ready
32568for printing with PostScript or Ghostscript, in the @file{gdb}
32569subdirectory of the main source directory@footnote{In
32570@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
32571release.}. If you can use PostScript or Ghostscript with your printer,
32572you can print the reference card immediately with @file{refcard.ps}.
c4555f82 32573
8e04817f
AC
32574The release also includes the source for the reference card. You
32575can format it, using @TeX{}, by typing:
c4555f82 32576
474c8240 32577@smallexample
8e04817f 32578make refcard.dvi
474c8240 32579@end smallexample
c4555f82 32580
8e04817f
AC
32581The @value{GDBN} reference card is designed to print in @dfn{landscape}
32582mode on US ``letter'' size paper;
32583that is, on a sheet 11 inches wide by 8.5 inches
32584high. You will need to specify this form of printing as an option to
32585your @sc{dvi} output program.
c4555f82 32586
8e04817f 32587@cindex documentation
c4555f82 32588
8e04817f
AC
32589All the documentation for @value{GDBN} comes as part of the machine-readable
32590distribution. The documentation is written in Texinfo format, which is
32591a documentation system that uses a single source file to produce both
32592on-line information and a printed manual. You can use one of the Info
32593formatting commands to create the on-line version of the documentation
32594and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 32595
8e04817f
AC
32596@value{GDBN} includes an already formatted copy of the on-line Info
32597version of this manual in the @file{gdb} subdirectory. The main Info
32598file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
32599subordinate files matching @samp{gdb.info*} in the same directory. If
32600necessary, you can print out these files, or read them with any editor;
32601but they are easier to read using the @code{info} subsystem in @sc{gnu}
32602Emacs or the standalone @code{info} program, available as part of the
32603@sc{gnu} Texinfo distribution.
c4555f82 32604
8e04817f
AC
32605If you want to format these Info files yourself, you need one of the
32606Info formatting programs, such as @code{texinfo-format-buffer} or
32607@code{makeinfo}.
c4555f82 32608
8e04817f
AC
32609If you have @code{makeinfo} installed, and are in the top level
32610@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
32611version @value{GDBVN}), you can make the Info file by typing:
c4555f82 32612
474c8240 32613@smallexample
8e04817f
AC
32614cd gdb
32615make gdb.info
474c8240 32616@end smallexample
c4555f82 32617
8e04817f
AC
32618If you want to typeset and print copies of this manual, you need @TeX{},
32619a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
32620Texinfo definitions file.
c4555f82 32621
8e04817f
AC
32622@TeX{} is a typesetting program; it does not print files directly, but
32623produces output files called @sc{dvi} files. To print a typeset
32624document, you need a program to print @sc{dvi} files. If your system
32625has @TeX{} installed, chances are it has such a program. The precise
32626command to use depends on your system; @kbd{lpr -d} is common; another
32627(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
32628require a file name without any extension or a @samp{.dvi} extension.
c4555f82 32629
8e04817f
AC
32630@TeX{} also requires a macro definitions file called
32631@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
32632written in Texinfo format. On its own, @TeX{} cannot either read or
32633typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
32634and is located in the @file{gdb-@var{version-number}/texinfo}
32635directory.
c4555f82 32636
8e04817f 32637If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 32638typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
32639subdirectory of the main source directory (for example, to
32640@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 32641
474c8240 32642@smallexample
8e04817f 32643make gdb.dvi
474c8240 32644@end smallexample
c4555f82 32645
8e04817f 32646Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 32647
8e04817f
AC
32648@node Installing GDB
32649@appendix Installing @value{GDBN}
8e04817f 32650@cindex installation
c4555f82 32651
7fa2210b
DJ
32652@menu
32653* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 32654* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
32655* Separate Objdir:: Compiling @value{GDBN} in another directory
32656* Config Names:: Specifying names for hosts and targets
32657* Configure Options:: Summary of options for configure
098b41a6 32658* System-wide configuration:: Having a system-wide init file
7fa2210b
DJ
32659@end menu
32660
32661@node Requirements
79a6e687 32662@section Requirements for Building @value{GDBN}
7fa2210b
DJ
32663@cindex building @value{GDBN}, requirements for
32664
32665Building @value{GDBN} requires various tools and packages to be available.
32666Other packages will be used only if they are found.
32667
79a6e687 32668@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b
DJ
32669@table @asis
32670@item ISO C90 compiler
32671@value{GDBN} is written in ISO C90. It should be buildable with any
32672working C90 compiler, e.g.@: GCC.
32673
32674@end table
32675
79a6e687 32676@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
32677@table @asis
32678@item Expat
123dc839 32679@anchor{Expat}
7fa2210b
DJ
32680@value{GDBN} can use the Expat XML parsing library. This library may be
32681included with your operating system distribution; if it is not, you
32682can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 32683The @file{configure} script will search for this library in several
7fa2210b
DJ
32684standard locations; if it is installed in an unusual path, you can
32685use the @option{--with-libexpat-prefix} option to specify its location.
32686
9cceb671
DJ
32687Expat is used for:
32688
32689@itemize @bullet
32690@item
32691Remote protocol memory maps (@pxref{Memory Map Format})
32692@item
32693Target descriptions (@pxref{Target Descriptions})
32694@item
2268b414
JK
32695Remote shared library lists (@xref{Library List Format},
32696or alternatively @pxref{Library List Format for SVR4 Targets})
9cceb671
DJ
32697@item
32698MS-Windows shared libraries (@pxref{Shared Libraries})
b3b9301e
PA
32699@item
32700Traceframe info (@pxref{Traceframe Info Format})
2ae8c8e7
MM
32701@item
32702Branch trace (@pxref{Branch Trace Format})
9cceb671 32703@end itemize
7fa2210b 32704
31fffb02
CS
32705@item zlib
32706@cindex compressed debug sections
32707@value{GDBN} will use the @samp{zlib} library, if available, to read
32708compressed debug sections. Some linkers, such as GNU gold, are capable
32709of producing binaries with compressed debug sections. If @value{GDBN}
32710is compiled with @samp{zlib}, it will be able to read the debug
32711information in such binaries.
32712
32713The @samp{zlib} library is likely included with your operating system
32714distribution; if it is not, you can get the latest version from
32715@url{http://zlib.net}.
32716
6c7a06a3
TT
32717@item iconv
32718@value{GDBN}'s features related to character sets (@pxref{Character
32719Sets}) require a functioning @code{iconv} implementation. If you are
32720on a GNU system, then this is provided by the GNU C Library. Some
32721other systems also provide a working @code{iconv}.
32722
478aac75
DE
32723If @value{GDBN} is using the @code{iconv} program which is installed
32724in a non-standard place, you will need to tell @value{GDBN} where to find it.
32725This is done with @option{--with-iconv-bin} which specifies the
32726directory that contains the @code{iconv} program.
32727
32728On systems without @code{iconv}, you can install GNU Libiconv. If you
6c7a06a3
TT
32729have previously installed Libiconv, you can use the
32730@option{--with-libiconv-prefix} option to configure.
32731
32732@value{GDBN}'s top-level @file{configure} and @file{Makefile} will
32733arrange to build Libiconv if a directory named @file{libiconv} appears
32734in the top-most source directory. If Libiconv is built this way, and
32735if the operating system does not provide a suitable @code{iconv}
32736implementation, then the just-built library will automatically be used
32737by @value{GDBN}. One easy way to set this up is to download GNU
32738Libiconv, unpack it, and then rename the directory holding the
32739Libiconv source code to @samp{libiconv}.
7fa2210b
DJ
32740@end table
32741
32742@node Running Configure
db2e3e2e 32743@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 32744@cindex configuring @value{GDBN}
db2e3e2e 32745@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
32746of preparing @value{GDBN} for installation; you can then use @code{make} to
32747build the @code{gdb} program.
32748@iftex
32749@c irrelevant in info file; it's as current as the code it lives with.
32750@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
32751look at the @file{README} file in the sources; we may have improved the
32752installation procedures since publishing this manual.}
32753@end iftex
c4555f82 32754
8e04817f
AC
32755The @value{GDBN} distribution includes all the source code you need for
32756@value{GDBN} in a single directory, whose name is usually composed by
32757appending the version number to @samp{gdb}.
c4555f82 32758
8e04817f
AC
32759For example, the @value{GDBN} version @value{GDBVN} distribution is in the
32760@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 32761
8e04817f
AC
32762@table @code
32763@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
32764script for configuring @value{GDBN} and all its supporting libraries
c4555f82 32765
8e04817f
AC
32766@item gdb-@value{GDBVN}/gdb
32767the source specific to @value{GDBN} itself
c4555f82 32768
8e04817f
AC
32769@item gdb-@value{GDBVN}/bfd
32770source for the Binary File Descriptor library
c906108c 32771
8e04817f
AC
32772@item gdb-@value{GDBVN}/include
32773@sc{gnu} include files
c906108c 32774
8e04817f
AC
32775@item gdb-@value{GDBVN}/libiberty
32776source for the @samp{-liberty} free software library
c906108c 32777
8e04817f
AC
32778@item gdb-@value{GDBVN}/opcodes
32779source for the library of opcode tables and disassemblers
c906108c 32780
8e04817f
AC
32781@item gdb-@value{GDBVN}/readline
32782source for the @sc{gnu} command-line interface
c906108c 32783
8e04817f
AC
32784@item gdb-@value{GDBVN}/glob
32785source for the @sc{gnu} filename pattern-matching subroutine
c906108c 32786
8e04817f
AC
32787@item gdb-@value{GDBVN}/mmalloc
32788source for the @sc{gnu} memory-mapped malloc package
32789@end table
c906108c 32790
db2e3e2e 32791The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
32792from the @file{gdb-@var{version-number}} source directory, which in
32793this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 32794
8e04817f 32795First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 32796if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
32797identifier for the platform on which @value{GDBN} will run as an
32798argument.
c906108c 32799
8e04817f 32800For example:
c906108c 32801
474c8240 32802@smallexample
8e04817f
AC
32803cd gdb-@value{GDBVN}
32804./configure @var{host}
32805make
474c8240 32806@end smallexample
c906108c 32807
8e04817f
AC
32808@noindent
32809where @var{host} is an identifier such as @samp{sun4} or
32810@samp{decstation}, that identifies the platform where @value{GDBN} will run.
db2e3e2e 32811(You can often leave off @var{host}; @file{configure} tries to guess the
8e04817f 32812correct value by examining your system.)
c906108c 32813
8e04817f
AC
32814Running @samp{configure @var{host}} and then running @code{make} builds the
32815@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
32816libraries, then @code{gdb} itself. The configured source files, and the
32817binaries, are left in the corresponding source directories.
c906108c 32818
8e04817f 32819@need 750
db2e3e2e 32820@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
32821system does not recognize this automatically when you run a different
32822shell, you may need to run @code{sh} on it explicitly:
c906108c 32823
474c8240 32824@smallexample
8e04817f 32825sh configure @var{host}
474c8240 32826@end smallexample
c906108c 32827
db2e3e2e 32828If you run @file{configure} from a directory that contains source
8e04817f 32829directories for multiple libraries or programs, such as the
db2e3e2e
BW
32830@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
32831@file{configure}
8e04817f
AC
32832creates configuration files for every directory level underneath (unless
32833you tell it not to, with the @samp{--norecursion} option).
32834
db2e3e2e 32835You should run the @file{configure} script from the top directory in the
94e91d6d 32836source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 32837@file{configure} from one of the subdirectories, you will configure only
94e91d6d 32838that subdirectory. That is usually not what you want. In particular,
db2e3e2e 32839if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
32840of the @file{gdb-@var{version-number}} directory, you will omit the
32841configuration of @file{bfd}, @file{readline}, and other sibling
32842directories of the @file{gdb} subdirectory. This leads to build errors
32843about missing include files such as @file{bfd/bfd.h}.
c906108c 32844
8e04817f
AC
32845You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
32846However, you should make sure that the shell on your path (named by
32847the @samp{SHELL} environment variable) is publicly readable. Remember
32848that @value{GDBN} uses the shell to start your program---some systems refuse to
32849let @value{GDBN} debug child processes whose programs are not readable.
c906108c 32850
8e04817f 32851@node Separate Objdir
79a6e687 32852@section Compiling @value{GDBN} in Another Directory
c906108c 32853
8e04817f
AC
32854If you want to run @value{GDBN} versions for several host or target machines,
32855you need a different @code{gdb} compiled for each combination of
db2e3e2e 32856host and target. @file{configure} is designed to make this easy by
8e04817f
AC
32857allowing you to generate each configuration in a separate subdirectory,
32858rather than in the source directory. If your @code{make} program
32859handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
32860@code{make} in each of these directories builds the @code{gdb}
32861program specified there.
c906108c 32862
db2e3e2e 32863To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 32864with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
32865(You also need to specify a path to find @file{configure}
32866itself from your working directory. If the path to @file{configure}
8e04817f
AC
32867would be the same as the argument to @samp{--srcdir}, you can leave out
32868the @samp{--srcdir} option; it is assumed.)
c906108c 32869
8e04817f
AC
32870For example, with version @value{GDBVN}, you can build @value{GDBN} in a
32871separate directory for a Sun 4 like this:
c906108c 32872
474c8240 32873@smallexample
8e04817f
AC
32874@group
32875cd gdb-@value{GDBVN}
32876mkdir ../gdb-sun4
32877cd ../gdb-sun4
32878../gdb-@value{GDBVN}/configure sun4
32879make
32880@end group
474c8240 32881@end smallexample
c906108c 32882
db2e3e2e 32883When @file{configure} builds a configuration using a remote source
8e04817f
AC
32884directory, it creates a tree for the binaries with the same structure
32885(and using the same names) as the tree under the source directory. In
32886the example, you'd find the Sun 4 library @file{libiberty.a} in the
32887directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
32888@file{gdb-sun4/gdb}.
c906108c 32889
94e91d6d
MC
32890Make sure that your path to the @file{configure} script has just one
32891instance of @file{gdb} in it. If your path to @file{configure} looks
32892like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
32893one subdirectory of @value{GDBN}, not the whole package. This leads to
32894build errors about missing include files such as @file{bfd/bfd.h}.
32895
8e04817f
AC
32896One popular reason to build several @value{GDBN} configurations in separate
32897directories is to configure @value{GDBN} for cross-compiling (where
32898@value{GDBN} runs on one machine---the @dfn{host}---while debugging
32899programs that run on another machine---the @dfn{target}).
32900You specify a cross-debugging target by
db2e3e2e 32901giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 32902
8e04817f
AC
32903When you run @code{make} to build a program or library, you must run
32904it in a configured directory---whatever directory you were in when you
db2e3e2e 32905called @file{configure} (or one of its subdirectories).
c906108c 32906
db2e3e2e 32907The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
32908directory also runs recursively. If you type @code{make} in a source
32909directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
32910directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
32911will build all the required libraries, and then build GDB.
c906108c 32912
8e04817f
AC
32913When you have multiple hosts or targets configured in separate
32914directories, you can run @code{make} on them in parallel (for example,
32915if they are NFS-mounted on each of the hosts); they will not interfere
32916with each other.
c906108c 32917
8e04817f 32918@node Config Names
79a6e687 32919@section Specifying Names for Hosts and Targets
c906108c 32920
db2e3e2e 32921The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
32922script are based on a three-part naming scheme, but some short predefined
32923aliases are also supported. The full naming scheme encodes three pieces
32924of information in the following pattern:
c906108c 32925
474c8240 32926@smallexample
8e04817f 32927@var{architecture}-@var{vendor}-@var{os}
474c8240 32928@end smallexample
c906108c 32929
8e04817f
AC
32930For example, you can use the alias @code{sun4} as a @var{host} argument,
32931or as the value for @var{target} in a @code{--target=@var{target}}
32932option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 32933
db2e3e2e 32934The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 32935any query facility to list all supported host and target names or
db2e3e2e 32936aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
32937@code{config.sub} to map abbreviations to full names; you can read the
32938script, if you wish, or you can use it to test your guesses on
32939abbreviations---for example:
c906108c 32940
8e04817f
AC
32941@smallexample
32942% sh config.sub i386-linux
32943i386-pc-linux-gnu
32944% sh config.sub alpha-linux
32945alpha-unknown-linux-gnu
32946% sh config.sub hp9k700
32947hppa1.1-hp-hpux
32948% sh config.sub sun4
32949sparc-sun-sunos4.1.1
32950% sh config.sub sun3
32951m68k-sun-sunos4.1.1
32952% sh config.sub i986v
32953Invalid configuration `i986v': machine `i986v' not recognized
32954@end smallexample
c906108c 32955
8e04817f
AC
32956@noindent
32957@code{config.sub} is also distributed in the @value{GDBN} source
32958directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 32959
8e04817f 32960@node Configure Options
db2e3e2e 32961@section @file{configure} Options
c906108c 32962
db2e3e2e
BW
32963Here is a summary of the @file{configure} options and arguments that
32964are most often useful for building @value{GDBN}. @file{configure} also has
8e04817f 32965several other options not listed here. @inforef{What Configure
db2e3e2e 32966Does,,configure.info}, for a full explanation of @file{configure}.
c906108c 32967
474c8240 32968@smallexample
8e04817f
AC
32969configure @r{[}--help@r{]}
32970 @r{[}--prefix=@var{dir}@r{]}
32971 @r{[}--exec-prefix=@var{dir}@r{]}
32972 @r{[}--srcdir=@var{dirname}@r{]}
32973 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
32974 @r{[}--target=@var{target}@r{]}
32975 @var{host}
474c8240 32976@end smallexample
c906108c 32977
8e04817f
AC
32978@noindent
32979You may introduce options with a single @samp{-} rather than
32980@samp{--} if you prefer; but you may abbreviate option names if you use
32981@samp{--}.
c906108c 32982
8e04817f
AC
32983@table @code
32984@item --help
db2e3e2e 32985Display a quick summary of how to invoke @file{configure}.
c906108c 32986
8e04817f
AC
32987@item --prefix=@var{dir}
32988Configure the source to install programs and files under directory
32989@file{@var{dir}}.
c906108c 32990
8e04817f
AC
32991@item --exec-prefix=@var{dir}
32992Configure the source to install programs under directory
32993@file{@var{dir}}.
c906108c 32994
8e04817f
AC
32995@c avoid splitting the warning from the explanation:
32996@need 2000
32997@item --srcdir=@var{dirname}
32998@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
32999@code{make} that implements the @code{VPATH} feature.}@*
33000Use this option to make configurations in directories separate from the
33001@value{GDBN} source directories. Among other things, you can use this to
33002build (or maintain) several configurations simultaneously, in separate
db2e3e2e 33003directories. @file{configure} writes configuration-specific files in
8e04817f 33004the current directory, but arranges for them to use the source in the
db2e3e2e 33005directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
33006the working directory in parallel to the source directories below
33007@var{dirname}.
c906108c 33008
8e04817f 33009@item --norecursion
db2e3e2e 33010Configure only the directory level where @file{configure} is executed; do not
8e04817f 33011propagate configuration to subdirectories.
c906108c 33012
8e04817f
AC
33013@item --target=@var{target}
33014Configure @value{GDBN} for cross-debugging programs running on the specified
33015@var{target}. Without this option, @value{GDBN} is configured to debug
33016programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 33017
8e04817f 33018There is no convenient way to generate a list of all available targets.
c906108c 33019
8e04817f
AC
33020@item @var{host} @dots{}
33021Configure @value{GDBN} to run on the specified @var{host}.
c906108c 33022
8e04817f
AC
33023There is no convenient way to generate a list of all available hosts.
33024@end table
c906108c 33025
8e04817f
AC
33026There are many other options available as well, but they are generally
33027needed for special purposes only.
c906108c 33028
098b41a6
JG
33029@node System-wide configuration
33030@section System-wide configuration and settings
33031@cindex system-wide init file
33032
33033@value{GDBN} can be configured to have a system-wide init file;
33034this file will be read and executed at startup (@pxref{Startup, , What
33035@value{GDBN} does during startup}).
33036
33037Here is the corresponding configure option:
33038
33039@table @code
33040@item --with-system-gdbinit=@var{file}
33041Specify that the default location of the system-wide init file is
33042@var{file}.
33043@end table
33044
33045If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
33046it may be subject to relocation. Two possible cases:
33047
33048@itemize @bullet
33049@item
33050If the default location of this init file contains @file{$prefix},
33051it will be subject to relocation. Suppose that the configure options
33052are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
33053if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
33054init file is looked for as @file{$install/etc/gdbinit} instead of
33055@file{$prefix/etc/gdbinit}.
33056
33057@item
33058By contrast, if the default location does not contain the prefix,
33059it will not be relocated. E.g.@: if @value{GDBN} has been configured with
33060@option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
33061then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
33062wherever @value{GDBN} is installed.
33063@end itemize
33064
e64e0392
DE
33065If the configured location of the system-wide init file (as given by the
33066@option{--with-system-gdbinit} option at configure time) is in the
33067data-directory (as specified by @option{--with-gdb-datadir} at configure
33068time) or in one of its subdirectories, then @value{GDBN} will look for the
33069system-wide init file in the directory specified by the
33070@option{--data-directory} command-line option.
33071Note that the system-wide init file is only read once, during @value{GDBN}
33072initialization. If the data-directory is changed after @value{GDBN} has
33073started with the @code{set data-directory} command, the file will not be
33074reread.
33075
5901af59
JB
33076@menu
33077* System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
33078@end menu
33079
33080@node System-wide Configuration Scripts
0201faac
JB
33081@subsection Installed System-wide Configuration Scripts
33082@cindex system-wide configuration scripts
33083
33084The @file{system-gdbinit} directory, located inside the data-directory
33085(as specified by @option{--with-gdb-datadir} at configure time) contains
33086a number of scripts which can be used as system-wide init files. To
33087automatically source those scripts at startup, @value{GDBN} should be
33088configured with @option{--with-system-gdbinit}. Otherwise, any user
33089should be able to source them by hand as needed.
33090
33091The following scripts are currently available:
33092@itemize @bullet
33093
33094@item @file{elinos.py}
33095@pindex elinos.py
33096@cindex ELinOS system-wide configuration script
33097This script is useful when debugging a program on an ELinOS target.
33098It takes advantage of the environment variables defined in a standard
33099ELinOS environment in order to determine the location of the system
33100shared libraries, and then sets the @samp{solib-absolute-prefix}
33101and @samp{solib-search-path} variables appropriately.
33102
33103@item @file{wrs-linux.py}
33104@pindex wrs-linux.py
33105@cindex Wind River Linux system-wide configuration script
33106This script is useful when debugging a program on a target running
33107Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
33108the host-side sysroot used by the target system.
33109
33110@end itemize
33111
8e04817f
AC
33112@node Maintenance Commands
33113@appendix Maintenance Commands
33114@cindex maintenance commands
33115@cindex internal commands
c906108c 33116
8e04817f 33117In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
33118includes a number of commands intended for @value{GDBN} developers,
33119that are not documented elsewhere in this manual. These commands are
da316a69
EZ
33120provided here for reference. (For commands that turn on debugging
33121messages, see @ref{Debugging Output}.)
c906108c 33122
8e04817f 33123@table @code
09d4efe1 33124@kindex maint agent
782b2b07 33125@kindex maint agent-eval
f77cc5f0
HZ
33126@item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
33127@itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
09d4efe1
EZ
33128Translate the given @var{expression} into remote agent bytecodes.
33129This command is useful for debugging the Agent Expression mechanism
782b2b07
SS
33130(@pxref{Agent Expressions}). The @samp{agent} version produces an
33131expression useful for data collection, such as by tracepoints, while
33132@samp{maint agent-eval} produces an expression that evaluates directly
33133to a result. For instance, a collection expression for @code{globa +
33134globb} will include bytecodes to record four bytes of memory at each
33135of the addresses of @code{globa} and @code{globb}, while discarding
33136the result of the addition, while an evaluation expression will do the
33137addition and return the sum.
f77cc5f0
HZ
33138If @code{-at} is given, generate remote agent bytecode for @var{location}.
33139If not, generate remote agent bytecode for current frame PC address.
09d4efe1 33140
d3ce09f5
SS
33141@kindex maint agent-printf
33142@item maint agent-printf @var{format},@var{expr},...
33143Translate the given format string and list of argument expressions
33144into remote agent bytecodes and display them as a disassembled list.
33145This command is useful for debugging the agent version of dynamic
6dd24dfa 33146printf (@pxref{Dynamic Printf}).
d3ce09f5 33147
8e04817f
AC
33148@kindex maint info breakpoints
33149@item @anchor{maint info breakpoints}maint info breakpoints
33150Using the same format as @samp{info breakpoints}, display both the
33151breakpoints you've set explicitly, and those @value{GDBN} is using for
33152internal purposes. Internal breakpoints are shown with negative
33153breakpoint numbers. The type column identifies what kind of breakpoint
33154is shown:
c906108c 33155
8e04817f
AC
33156@table @code
33157@item breakpoint
33158Normal, explicitly set breakpoint.
c906108c 33159
8e04817f
AC
33160@item watchpoint
33161Normal, explicitly set watchpoint.
c906108c 33162
8e04817f
AC
33163@item longjmp
33164Internal breakpoint, used to handle correctly stepping through
33165@code{longjmp} calls.
c906108c 33166
8e04817f
AC
33167@item longjmp resume
33168Internal breakpoint at the target of a @code{longjmp}.
c906108c 33169
8e04817f
AC
33170@item until
33171Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 33172
8e04817f
AC
33173@item finish
33174Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 33175
8e04817f
AC
33176@item shlib events
33177Shared library events.
c906108c 33178
8e04817f 33179@end table
c906108c 33180
d6b28940
TT
33181@kindex maint info bfds
33182@item maint info bfds
33183This prints information about each @code{bfd} object that is known to
33184@value{GDBN}. @xref{Top, , BFD, bfd, The Binary File Descriptor Library}.
33185
fff08868
HZ
33186@kindex set displaced-stepping
33187@kindex show displaced-stepping
237fc4c9
PA
33188@cindex displaced stepping support
33189@cindex out-of-line single-stepping
fff08868
HZ
33190@item set displaced-stepping
33191@itemx show displaced-stepping
237fc4c9 33192Control whether or not @value{GDBN} will do @dfn{displaced stepping}
fff08868
HZ
33193if the target supports it. Displaced stepping is a way to single-step
33194over breakpoints without removing them from the inferior, by executing
33195an out-of-line copy of the instruction that was originally at the
33196breakpoint location. It is also known as out-of-line single-stepping.
33197
33198@table @code
33199@item set displaced-stepping on
33200If the target architecture supports it, @value{GDBN} will use
33201displaced stepping to step over breakpoints.
33202
33203@item set displaced-stepping off
33204@value{GDBN} will not use displaced stepping to step over breakpoints,
33205even if such is supported by the target architecture.
33206
33207@cindex non-stop mode, and @samp{set displaced-stepping}
33208@item set displaced-stepping auto
33209This is the default mode. @value{GDBN} will use displaced stepping
33210only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
33211architecture supports displaced stepping.
33212@end table
237fc4c9 33213
7d0c9981
DE
33214@kindex maint check-psymtabs
33215@item maint check-psymtabs
33216Check the consistency of currently expanded psymtabs versus symtabs.
33217Use this to check, for example, whether a symbol is in one but not the other.
33218
09d4efe1
EZ
33219@kindex maint check-symtabs
33220@item maint check-symtabs
7d0c9981
DE
33221Check the consistency of currently expanded symtabs.
33222
33223@kindex maint expand-symtabs
33224@item maint expand-symtabs [@var{regexp}]
33225Expand symbol tables.
33226If @var{regexp} is specified, only expand symbol tables for file
33227names matching @var{regexp}.
09d4efe1
EZ
33228
33229@kindex maint cplus first_component
33230@item maint cplus first_component @var{name}
33231Print the first C@t{++} class/namespace component of @var{name}.
33232
33233@kindex maint cplus namespace
33234@item maint cplus namespace
33235Print the list of possible C@t{++} namespaces.
33236
33237@kindex maint demangle
33238@item maint demangle @var{name}
d3e8051b 33239Demangle a C@t{++} or Objective-C mangled @var{name}.
09d4efe1
EZ
33240
33241@kindex maint deprecate
33242@kindex maint undeprecate
33243@cindex deprecated commands
33244@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
33245@itemx maint undeprecate @var{command}
33246Deprecate or undeprecate the named @var{command}. Deprecated commands
33247cause @value{GDBN} to issue a warning when you use them. The optional
33248argument @var{replacement} says which newer command should be used in
33249favor of the deprecated one; if it is given, @value{GDBN} will mention
33250the replacement as part of the warning.
33251
33252@kindex maint dump-me
33253@item maint dump-me
721c2651 33254@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 33255Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
33256This is supported only on systems which support aborting a program
33257with the @code{SIGQUIT} signal.
09d4efe1 33258
8d30a00d
AC
33259@kindex maint internal-error
33260@kindex maint internal-warning
09d4efe1
EZ
33261@item maint internal-error @r{[}@var{message-text}@r{]}
33262@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
33263Cause @value{GDBN} to call the internal function @code{internal_error}
33264or @code{internal_warning} and hence behave as though an internal error
33265or internal warning has been detected. In addition to reporting the
33266internal problem, these functions give the user the opportunity to
33267either quit @value{GDBN} or create a core file of the current
33268@value{GDBN} session.
33269
09d4efe1
EZ
33270These commands take an optional parameter @var{message-text} that is
33271used as the text of the error or warning message.
33272
d3e8051b 33273Here's an example of using @code{internal-error}:
09d4efe1 33274
8d30a00d 33275@smallexample
f7dc1244 33276(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
33277@dots{}/maint.c:121: internal-error: testing, 1, 2
33278A problem internal to GDB has been detected. Further
33279debugging may prove unreliable.
33280Quit this debugging session? (y or n) @kbd{n}
33281Create a core file? (y or n) @kbd{n}
f7dc1244 33282(@value{GDBP})
8d30a00d
AC
33283@end smallexample
33284
3c16cced
PA
33285@cindex @value{GDBN} internal error
33286@cindex internal errors, control of @value{GDBN} behavior
33287
33288@kindex maint set internal-error
33289@kindex maint show internal-error
33290@kindex maint set internal-warning
33291@kindex maint show internal-warning
33292@item maint set internal-error @var{action} [ask|yes|no]
33293@itemx maint show internal-error @var{action}
33294@itemx maint set internal-warning @var{action} [ask|yes|no]
33295@itemx maint show internal-warning @var{action}
33296When @value{GDBN} reports an internal problem (error or warning) it
33297gives the user the opportunity to both quit @value{GDBN} and create a
33298core file of the current @value{GDBN} session. These commands let you
33299override the default behaviour for each particular @var{action},
33300described in the table below.
33301
33302@table @samp
33303@item quit
33304You can specify that @value{GDBN} should always (yes) or never (no)
33305quit. The default is to ask the user what to do.
33306
33307@item corefile
33308You can specify that @value{GDBN} should always (yes) or never (no)
33309create a core file. The default is to ask the user what to do.
33310@end table
33311
09d4efe1
EZ
33312@kindex maint packet
33313@item maint packet @var{text}
33314If @value{GDBN} is talking to an inferior via the serial protocol,
33315then this command sends the string @var{text} to the inferior, and
33316displays the response packet. @value{GDBN} supplies the initial
33317@samp{$} character, the terminating @samp{#} character, and the
33318checksum.
33319
33320@kindex maint print architecture
33321@item maint print architecture @r{[}@var{file}@r{]}
33322Print the entire architecture configuration. The optional argument
33323@var{file} names the file where the output goes.
8d30a00d 33324
81adfced
DJ
33325@kindex maint print c-tdesc
33326@item maint print c-tdesc
33327Print the current target description (@pxref{Target Descriptions}) as
33328a C source file. The created source file can be used in @value{GDBN}
33329when an XML parser is not available to parse the description.
33330
00905d52
AC
33331@kindex maint print dummy-frames
33332@item maint print dummy-frames
00905d52
AC
33333Prints the contents of @value{GDBN}'s internal dummy-frame stack.
33334
33335@smallexample
f7dc1244 33336(@value{GDBP}) @kbd{b add}
00905d52 33337@dots{}
f7dc1244 33338(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
33339Breakpoint 2, add (a=2, b=3) at @dots{}
3334058 return (a + b);
33341The program being debugged stopped while in a function called from GDB.
33342@dots{}
f7dc1244 33343(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
333440x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
33345 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
33346 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 33347(@value{GDBP})
00905d52
AC
33348@end smallexample
33349
33350Takes an optional file parameter.
33351
0680b120
AC
33352@kindex maint print registers
33353@kindex maint print raw-registers
33354@kindex maint print cooked-registers
617073a9 33355@kindex maint print register-groups
c21236dc 33356@kindex maint print remote-registers
09d4efe1
EZ
33357@item maint print registers @r{[}@var{file}@r{]}
33358@itemx maint print raw-registers @r{[}@var{file}@r{]}
33359@itemx maint print cooked-registers @r{[}@var{file}@r{]}
33360@itemx maint print register-groups @r{[}@var{file}@r{]}
c21236dc 33361@itemx maint print remote-registers @r{[}@var{file}@r{]}
0680b120
AC
33362Print @value{GDBN}'s internal register data structures.
33363
617073a9 33364The command @code{maint print raw-registers} includes the contents of
c21236dc
PA
33365the raw register cache; the command @code{maint print
33366cooked-registers} includes the (cooked) value of all registers,
33367including registers which aren't available on the target nor visible
33368to user; the command @code{maint print register-groups} includes the
33369groups that each register is a member of; and the command @code{maint
33370print remote-registers} includes the remote target's register numbers
0a7cfe2c 33371and offsets in the `G' packets.
0680b120 33372
09d4efe1
EZ
33373These commands take an optional parameter, a file name to which to
33374write the information.
0680b120 33375
617073a9 33376@kindex maint print reggroups
09d4efe1
EZ
33377@item maint print reggroups @r{[}@var{file}@r{]}
33378Print @value{GDBN}'s internal register group data structures. The
33379optional argument @var{file} tells to what file to write the
33380information.
617073a9 33381
09d4efe1 33382The register groups info looks like this:
617073a9
AC
33383
33384@smallexample
f7dc1244 33385(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
33386 Group Type
33387 general user
33388 float user
33389 all user
33390 vector user
33391 system user
33392 save internal
33393 restore internal
617073a9
AC
33394@end smallexample
33395
09d4efe1
EZ
33396@kindex flushregs
33397@item flushregs
33398This command forces @value{GDBN} to flush its internal register cache.
33399
33400@kindex maint print objfiles
33401@cindex info for known object files
52e260a3
DE
33402@item maint print objfiles @r{[}@var{regexp}@r{]}
33403Print a dump of all known object files.
33404If @var{regexp} is specified, only print object files whose names
33405match @var{regexp}. For each object file, this command prints its name,
33406address in memory, and all of its psymtabs and symtabs.
09d4efe1 33407
8a1ea21f
DE
33408@kindex maint print section-scripts
33409@cindex info for known .debug_gdb_scripts-loaded scripts
33410@item maint print section-scripts [@var{regexp}]
33411Print a dump of scripts specified in the @code{.debug_gdb_section} section.
33412If @var{regexp} is specified, only print scripts loaded by object files
33413matching @var{regexp}.
33414For each script, this command prints its name as specified in the objfile,
33415and the full path if known.
8e0583c8 33416@xref{dotdebug_gdb_scripts section}.
8a1ea21f 33417
09d4efe1
EZ
33418@kindex maint print statistics
33419@cindex bcache statistics
33420@item maint print statistics
33421This command prints, for each object file in the program, various data
33422about that object file followed by the byte cache (@dfn{bcache})
33423statistics for the object file. The objfile data includes the number
d3e8051b 33424of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
33425defined by the objfile, the number of as yet unexpanded psym tables,
33426the number of line tables and string tables, and the amount of memory
33427used by the various tables. The bcache statistics include the counts,
33428sizes, and counts of duplicates of all and unique objects, max,
33429average, and median entry size, total memory used and its overhead and
33430savings, and various measures of the hash table size and chain
33431lengths.
33432
c7ba131e
JB
33433@kindex maint print target-stack
33434@cindex target stack description
33435@item maint print target-stack
33436A @dfn{target} is an interface between the debugger and a particular
33437kind of file or process. Targets can be stacked in @dfn{strata},
33438so that more than one target can potentially respond to a request.
33439In particular, memory accesses will walk down the stack of targets
33440until they find a target that is interested in handling that particular
33441address.
33442
33443This command prints a short description of each layer that was pushed on
33444the @dfn{target stack}, starting from the top layer down to the bottom one.
33445
09d4efe1
EZ
33446@kindex maint print type
33447@cindex type chain of a data type
33448@item maint print type @var{expr}
33449Print the type chain for a type specified by @var{expr}. The argument
33450can be either a type name or a symbol. If it is a symbol, the type of
33451that symbol is described. The type chain produced by this command is
33452a recursive definition of the data type as stored in @value{GDBN}'s
33453data structures, including its flags and contained types.
33454
9eae7c52
TT
33455@kindex maint set dwarf2 always-disassemble
33456@kindex maint show dwarf2 always-disassemble
33457@item maint set dwarf2 always-disassemble
33458@item maint show dwarf2 always-disassemble
33459Control the behavior of @code{info address} when using DWARF debugging
33460information.
33461
33462The default is @code{off}, which means that @value{GDBN} should try to
33463describe a variable's location in an easily readable format. When
33464@code{on}, @value{GDBN} will instead display the DWARF location
33465expression in an assembly-like format. Note that some locations are
33466too complex for @value{GDBN} to describe simply; in this case you will
33467always see the disassembly form.
33468
33469Here is an example of the resulting disassembly:
33470
33471@smallexample
33472(gdb) info addr argc
33473Symbol "argc" is a complex DWARF expression:
33474 1: DW_OP_fbreg 0
33475@end smallexample
33476
33477For more information on these expressions, see
33478@uref{http://www.dwarfstd.org/, the DWARF standard}.
33479
09d4efe1
EZ
33480@kindex maint set dwarf2 max-cache-age
33481@kindex maint show dwarf2 max-cache-age
33482@item maint set dwarf2 max-cache-age
33483@itemx maint show dwarf2 max-cache-age
33484Control the DWARF 2 compilation unit cache.
33485
33486@cindex DWARF 2 compilation units cache
33487In object files with inter-compilation-unit references, such as those
33488produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
33489reader needs to frequently refer to previously read compilation units.
33490This setting controls how long a compilation unit will remain in the
33491cache if it is not referenced. A higher limit means that cached
33492compilation units will be stored in memory longer, and more total
33493memory will be used. Setting it to zero disables caching, which will
33494slow down @value{GDBN} startup, but reduce memory consumption.
33495
e7ba9c65
DJ
33496@kindex maint set profile
33497@kindex maint show profile
33498@cindex profiling GDB
33499@item maint set profile
33500@itemx maint show profile
33501Control profiling of @value{GDBN}.
33502
33503Profiling will be disabled until you use the @samp{maint set profile}
33504command to enable it. When you enable profiling, the system will begin
33505collecting timing and execution count data; when you disable profiling or
33506exit @value{GDBN}, the results will be written to a log file. Remember that
33507if you use profiling, @value{GDBN} will overwrite the profiling log file
33508(often called @file{gmon.out}). If you have a record of important profiling
33509data in a @file{gmon.out} file, be sure to move it to a safe location.
33510
33511Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 33512compiled with the @samp{-pg} compiler option.
e7ba9c65 33513
cbe54154
PA
33514@kindex maint set show-debug-regs
33515@kindex maint show show-debug-regs
eac35c4e 33516@cindex hardware debug registers
cbe54154
PA
33517@item maint set show-debug-regs
33518@itemx maint show show-debug-regs
eac35c4e 33519Control whether to show variables that mirror the hardware debug
6dd315ba 33520registers. Use @code{on} to enable, @code{off} to disable. If
3f94c067 33521enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
33522removes a hardware breakpoint or watchpoint, and when the inferior
33523triggers a hardware-assisted breakpoint or watchpoint.
33524
711e434b
PM
33525@kindex maint set show-all-tib
33526@kindex maint show show-all-tib
33527@item maint set show-all-tib
33528@itemx maint show show-all-tib
33529Control whether to show all non zero areas within a 1k block starting
33530at thread local base, when using the @samp{info w32 thread-information-block}
33531command.
33532
bd712aed
DE
33533@kindex maint set per-command
33534@kindex maint show per-command
33535@item maint set per-command
33536@itemx maint show per-command
33537@cindex resources used by commands
09d4efe1 33538
bd712aed
DE
33539@value{GDBN} can display the resources used by each command.
33540This is useful in debugging performance problems.
33541
33542@table @code
33543@item maint set per-command space [on|off]
33544@itemx maint show per-command space
33545Enable or disable the printing of the memory used by GDB for each command.
33546If enabled, @value{GDBN} will display how much memory each command
33547took, following the command's own output.
33548This can also be requested by invoking @value{GDBN} with the
33549@option{--statistics} command-line switch (@pxref{Mode Options}).
33550
33551@item maint set per-command time [on|off]
33552@itemx maint show per-command time
33553Enable or disable the printing of the execution time of @value{GDBN}
33554for each command.
33555If enabled, @value{GDBN} will display how much time it
09d4efe1 33556took to execute each command, following the command's own output.
0a1c4d10
DE
33557Both CPU time and wallclock time are printed.
33558Printing both is useful when trying to determine whether the cost is
bd712aed 33559CPU or, e.g., disk/network latency.
0a1c4d10
DE
33560Note that the CPU time printed is for @value{GDBN} only, it does not include
33561the execution time of the inferior because there's no mechanism currently
33562to compute how much time was spent by @value{GDBN} and how much time was
33563spent by the program been debugged.
09d4efe1
EZ
33564This can also be requested by invoking @value{GDBN} with the
33565@option{--statistics} command-line switch (@pxref{Mode Options}).
33566
bd712aed
DE
33567@item maint set per-command symtab [on|off]
33568@itemx maint show per-command symtab
33569Enable or disable the printing of basic symbol table statistics
33570for each command.
33571If enabled, @value{GDBN} will display the following information:
33572
215b9f98
EZ
33573@enumerate a
33574@item
33575number of symbol tables
33576@item
33577number of primary symbol tables
33578@item
33579number of blocks in the blockvector
33580@end enumerate
bd712aed
DE
33581@end table
33582
33583@kindex maint space
33584@cindex memory used by commands
33585@item maint space @var{value}
33586An alias for @code{maint set per-command space}.
33587A non-zero value enables it, zero disables it.
33588
33589@kindex maint time
33590@cindex time of command execution
33591@item maint time @var{value}
33592An alias for @code{maint set per-command time}.
33593A non-zero value enables it, zero disables it.
33594
09d4efe1
EZ
33595@kindex maint translate-address
33596@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
33597Find the symbol stored at the location specified by the address
33598@var{addr} and an optional section name @var{section}. If found,
33599@value{GDBN} prints the name of the closest symbol and an offset from
33600the symbol's location to the specified address. This is similar to
33601the @code{info address} command (@pxref{Symbols}), except that this
33602command also allows to find symbols in other sections.
ae038cb0 33603
c14c28ba
PP
33604If section was not specified, the section in which the symbol was found
33605is also printed. For dynamically linked executables, the name of
33606executable or shared library containing the symbol is printed as well.
33607
8e04817f 33608@end table
c906108c 33609
9c16f35a
EZ
33610The following command is useful for non-interactive invocations of
33611@value{GDBN}, such as in the test suite.
33612
33613@table @code
33614@item set watchdog @var{nsec}
33615@kindex set watchdog
33616@cindex watchdog timer
33617@cindex timeout for commands
33618Set the maximum number of seconds @value{GDBN} will wait for the
33619target operation to finish. If this time expires, @value{GDBN}
33620reports and error and the command is aborted.
33621
33622@item show watchdog
33623Show the current setting of the target wait timeout.
33624@end table
c906108c 33625
e0ce93ac 33626@node Remote Protocol
8e04817f 33627@appendix @value{GDBN} Remote Serial Protocol
c906108c 33628
ee2d5c50
AC
33629@menu
33630* Overview::
33631* Packets::
33632* Stop Reply Packets::
33633* General Query Packets::
a1dcb23a 33634* Architecture-Specific Protocol Details::
9d29849a 33635* Tracepoint Packets::
a6b151f1 33636* Host I/O Packets::
9a6253be 33637* Interrupts::
8b23ecc4
SL
33638* Notification Packets::
33639* Remote Non-Stop::
a6f3e723 33640* Packet Acknowledgment::
ee2d5c50 33641* Examples::
79a6e687 33642* File-I/O Remote Protocol Extension::
cfa9d6d9 33643* Library List Format::
2268b414 33644* Library List Format for SVR4 Targets::
79a6e687 33645* Memory Map Format::
dc146f7c 33646* Thread List Format::
b3b9301e 33647* Traceframe Info Format::
2ae8c8e7 33648* Branch Trace Format::
ee2d5c50
AC
33649@end menu
33650
33651@node Overview
33652@section Overview
33653
8e04817f
AC
33654There may be occasions when you need to know something about the
33655protocol---for example, if there is only one serial port to your target
33656machine, you might want your program to do something special if it
33657recognizes a packet meant for @value{GDBN}.
c906108c 33658
d2c6833e 33659In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 33660transmitted and received data, respectively.
c906108c 33661
8e04817f
AC
33662@cindex protocol, @value{GDBN} remote serial
33663@cindex serial protocol, @value{GDBN} remote
33664@cindex remote serial protocol
8b23ecc4
SL
33665All @value{GDBN} commands and responses (other than acknowledgments
33666and notifications, see @ref{Notification Packets}) are sent as a
33667@var{packet}. A @var{packet} is introduced with the character
8e04817f
AC
33668@samp{$}, the actual @var{packet-data}, and the terminating character
33669@samp{#} followed by a two-digit @var{checksum}:
c906108c 33670
474c8240 33671@smallexample
8e04817f 33672@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 33673@end smallexample
8e04817f 33674@noindent
c906108c 33675
8e04817f
AC
33676@cindex checksum, for @value{GDBN} remote
33677@noindent
33678The two-digit @var{checksum} is computed as the modulo 256 sum of all
33679characters between the leading @samp{$} and the trailing @samp{#} (an
33680eight bit unsigned checksum).
c906108c 33681
8e04817f
AC
33682Implementors should note that prior to @value{GDBN} 5.0 the protocol
33683specification also included an optional two-digit @var{sequence-id}:
c906108c 33684
474c8240 33685@smallexample
8e04817f 33686@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 33687@end smallexample
c906108c 33688
8e04817f
AC
33689@cindex sequence-id, for @value{GDBN} remote
33690@noindent
33691That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
33692has never output @var{sequence-id}s. Stubs that handle packets added
33693since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 33694
8e04817f
AC
33695When either the host or the target machine receives a packet, the first
33696response expected is an acknowledgment: either @samp{+} (to indicate
33697the package was received correctly) or @samp{-} (to request
33698retransmission):
c906108c 33699
474c8240 33700@smallexample
d2c6833e
AC
33701-> @code{$}@var{packet-data}@code{#}@var{checksum}
33702<- @code{+}
474c8240 33703@end smallexample
8e04817f 33704@noindent
53a5351d 33705
a6f3e723
SL
33706The @samp{+}/@samp{-} acknowledgments can be disabled
33707once a connection is established.
33708@xref{Packet Acknowledgment}, for details.
33709
8e04817f
AC
33710The host (@value{GDBN}) sends @var{command}s, and the target (the
33711debugging stub incorporated in your program) sends a @var{response}. In
33712the case of step and continue @var{command}s, the response is only sent
8b23ecc4
SL
33713when the operation has completed, and the target has again stopped all
33714threads in all attached processes. This is the default all-stop mode
33715behavior, but the remote protocol also supports @value{GDBN}'s non-stop
33716execution mode; see @ref{Remote Non-Stop}, for details.
c906108c 33717
8e04817f
AC
33718@var{packet-data} consists of a sequence of characters with the
33719exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
33720exceptions).
c906108c 33721
ee2d5c50 33722@cindex remote protocol, field separator
0876f84a 33723Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 33724@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 33725@sc{hex} with leading zeros suppressed.
c906108c 33726
8e04817f
AC
33727Implementors should note that prior to @value{GDBN} 5.0, the character
33728@samp{:} could not appear as the third character in a packet (as it
33729would potentially conflict with the @var{sequence-id}).
c906108c 33730
0876f84a
DJ
33731@cindex remote protocol, binary data
33732@anchor{Binary Data}
33733Binary data in most packets is encoded either as two hexadecimal
33734digits per byte of binary data. This allowed the traditional remote
33735protocol to work over connections which were only seven-bit clean.
33736Some packets designed more recently assume an eight-bit clean
33737connection, and use a more efficient encoding to send and receive
33738binary data.
33739
33740The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
33741as an escape character. Any escaped byte is transmitted as the escape
33742character followed by the original character XORed with @code{0x20}.
33743For example, the byte @code{0x7d} would be transmitted as the two
33744bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
33745@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
33746@samp{@}}) must always be escaped. Responses sent by the stub
33747must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
33748is not interpreted as the start of a run-length encoded sequence
33749(described next).
33750
1d3811f6
DJ
33751Response @var{data} can be run-length encoded to save space.
33752Run-length encoding replaces runs of identical characters with one
33753instance of the repeated character, followed by a @samp{*} and a
33754repeat count. The repeat count is itself sent encoded, to avoid
33755binary characters in @var{data}: a value of @var{n} is sent as
33756@code{@var{n}+29}. For a repeat count greater or equal to 3, this
33757produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
33758code 32) for a repeat count of 3. (This is because run-length
33759encoding starts to win for counts 3 or more.) Thus, for example,
33760@samp{0* } is a run-length encoding of ``0000'': the space character
33761after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
337623}} more times.
33763
33764The printable characters @samp{#} and @samp{$} or with a numeric value
33765greater than 126 must not be used. Runs of six repeats (@samp{#}) or
33766seven repeats (@samp{$}) can be expanded using a repeat count of only
33767five (@samp{"}). For example, @samp{00000000} can be encoded as
33768@samp{0*"00}.
c906108c 33769
8e04817f
AC
33770The error response returned for some packets includes a two character
33771error number. That number is not well defined.
c906108c 33772
f8da2bff 33773@cindex empty response, for unsupported packets
8e04817f
AC
33774For any @var{command} not supported by the stub, an empty response
33775(@samp{$#00}) should be returned. That way it is possible to extend the
33776protocol. A newer @value{GDBN} can tell if a packet is supported based
33777on that response.
c906108c 33778
393eab54
PA
33779At a minimum, a stub is required to support the @samp{g} and @samp{G}
33780commands for register access, and the @samp{m} and @samp{M} commands
33781for memory access. Stubs that only control single-threaded targets
33782can implement run control with the @samp{c} (continue), and @samp{s}
33783(step) commands. Stubs that support multi-threading targets should
33784support the @samp{vCont} command. All other commands are optional.
c906108c 33785
ee2d5c50
AC
33786@node Packets
33787@section Packets
33788
33789The following table provides a complete list of all currently defined
33790@var{command}s and their corresponding response @var{data}.
79a6e687 33791@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 33792I/O extension of the remote protocol.
ee2d5c50 33793
b8ff78ce
JB
33794Each packet's description has a template showing the packet's overall
33795syntax, followed by an explanation of the packet's meaning. We
33796include spaces in some of the templates for clarity; these are not
33797part of the packet's syntax. No @value{GDBN} packet uses spaces to
33798separate its components. For example, a template like @samp{foo
33799@var{bar} @var{baz}} describes a packet beginning with the three ASCII
33800bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 33801@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
33802@samp{foo} and the @var{bar}, or between the @var{bar} and the
33803@var{baz}.
33804
b90a069a
SL
33805@cindex @var{thread-id}, in remote protocol
33806@anchor{thread-id syntax}
33807Several packets and replies include a @var{thread-id} field to identify
33808a thread. Normally these are positive numbers with a target-specific
33809interpretation, formatted as big-endian hex strings. A @var{thread-id}
33810can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
33811pick any thread.
33812
33813In addition, the remote protocol supports a multiprocess feature in
33814which the @var{thread-id} syntax is extended to optionally include both
33815process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
33816The @var{pid} (process) and @var{tid} (thread) components each have the
33817format described above: a positive number with target-specific
33818interpretation formatted as a big-endian hex string, literal @samp{-1}
33819to indicate all processes or threads (respectively), or @samp{0} to
33820indicate an arbitrary process or thread. Specifying just a process, as
33821@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
33822error to specify all processes but a specific thread, such as
33823@samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
33824for those packets and replies explicitly documented to include a process
33825ID, rather than a @var{thread-id}.
33826
33827The multiprocess @var{thread-id} syntax extensions are only used if both
33828@value{GDBN} and the stub report support for the @samp{multiprocess}
33829feature using @samp{qSupported}. @xref{multiprocess extensions}, for
33830more information.
33831
8ffe2530
JB
33832Note that all packet forms beginning with an upper- or lower-case
33833letter, other than those described here, are reserved for future use.
33834
b8ff78ce 33835Here are the packet descriptions.
ee2d5c50 33836
b8ff78ce 33837@table @samp
ee2d5c50 33838
b8ff78ce
JB
33839@item !
33840@cindex @samp{!} packet
2d717e4f 33841@anchor{extended mode}
8e04817f
AC
33842Enable extended mode. In extended mode, the remote server is made
33843persistent. The @samp{R} packet is used to restart the program being
33844debugged.
ee2d5c50
AC
33845
33846Reply:
33847@table @samp
33848@item OK
8e04817f 33849The remote target both supports and has enabled extended mode.
ee2d5c50 33850@end table
c906108c 33851
b8ff78ce
JB
33852@item ?
33853@cindex @samp{?} packet
36cb1214 33854@anchor{? packet}
ee2d5c50 33855Indicate the reason the target halted. The reply is the same as for
8b23ecc4
SL
33856step and continue. This packet has a special interpretation when the
33857target is in non-stop mode; see @ref{Remote Non-Stop}.
c906108c 33858
ee2d5c50
AC
33859Reply:
33860@xref{Stop Reply Packets}, for the reply specifications.
33861
b8ff78ce
JB
33862@item A @var{arglen},@var{argnum},@var{arg},@dots{}
33863@cindex @samp{A} packet
33864Initialized @code{argv[]} array passed into program. @var{arglen}
33865specifies the number of bytes in the hex encoded byte stream
33866@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
33867
33868Reply:
33869@table @samp
33870@item OK
b8ff78ce
JB
33871The arguments were set.
33872@item E @var{NN}
33873An error occurred.
ee2d5c50
AC
33874@end table
33875
b8ff78ce
JB
33876@item b @var{baud}
33877@cindex @samp{b} packet
33878(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
33879Change the serial line speed to @var{baud}.
33880
33881JTC: @emph{When does the transport layer state change? When it's
33882received, or after the ACK is transmitted. In either case, there are
33883problems if the command or the acknowledgment packet is dropped.}
33884
33885Stan: @emph{If people really wanted to add something like this, and get
33886it working for the first time, they ought to modify ser-unix.c to send
33887some kind of out-of-band message to a specially-setup stub and have the
33888switch happen "in between" packets, so that from remote protocol's point
33889of view, nothing actually happened.}
33890
b8ff78ce
JB
33891@item B @var{addr},@var{mode}
33892@cindex @samp{B} packet
8e04817f 33893Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
33894breakpoint at @var{addr}.
33895
b8ff78ce 33896Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 33897(@pxref{insert breakpoint or watchpoint packet}).
c906108c 33898
bacec72f 33899@cindex @samp{bc} packet
0d772ac9
MS
33900@anchor{bc}
33901@item bc
bacec72f
MS
33902Backward continue. Execute the target system in reverse. No parameter.
33903@xref{Reverse Execution}, for more information.
33904
33905Reply:
33906@xref{Stop Reply Packets}, for the reply specifications.
33907
bacec72f 33908@cindex @samp{bs} packet
0d772ac9
MS
33909@anchor{bs}
33910@item bs
bacec72f
MS
33911Backward single step. Execute one instruction in reverse. No parameter.
33912@xref{Reverse Execution}, for more information.
33913
33914Reply:
33915@xref{Stop Reply Packets}, for the reply specifications.
33916
4f553f88 33917@item c @r{[}@var{addr}@r{]}
b8ff78ce
JB
33918@cindex @samp{c} packet
33919Continue. @var{addr} is address to resume. If @var{addr} is omitted,
33920resume at current address.
c906108c 33921
393eab54
PA
33922This packet is deprecated for multi-threading support. @xref{vCont
33923packet}.
33924
ee2d5c50
AC
33925Reply:
33926@xref{Stop Reply Packets}, for the reply specifications.
33927
4f553f88 33928@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 33929@cindex @samp{C} packet
8e04817f 33930Continue with signal @var{sig} (hex signal number). If
b8ff78ce 33931@samp{;@var{addr}} is omitted, resume at same address.
c906108c 33932
393eab54
PA
33933This packet is deprecated for multi-threading support. @xref{vCont
33934packet}.
33935
ee2d5c50
AC
33936Reply:
33937@xref{Stop Reply Packets}, for the reply specifications.
c906108c 33938
b8ff78ce
JB
33939@item d
33940@cindex @samp{d} packet
ee2d5c50
AC
33941Toggle debug flag.
33942
b8ff78ce
JB
33943Don't use this packet; instead, define a general set packet
33944(@pxref{General Query Packets}).
ee2d5c50 33945
b8ff78ce 33946@item D
b90a069a 33947@itemx D;@var{pid}
b8ff78ce 33948@cindex @samp{D} packet
b90a069a
SL
33949The first form of the packet is used to detach @value{GDBN} from the
33950remote system. It is sent to the remote target
07f31aa6 33951before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50 33952
b90a069a
SL
33953The second form, including a process ID, is used when multiprocess
33954protocol extensions are enabled (@pxref{multiprocess extensions}), to
33955detach only a specific process. The @var{pid} is specified as a
33956big-endian hex string.
33957
ee2d5c50
AC
33958Reply:
33959@table @samp
10fac096
NW
33960@item OK
33961for success
b8ff78ce 33962@item E @var{NN}
10fac096 33963for an error
ee2d5c50 33964@end table
c906108c 33965
b8ff78ce
JB
33966@item F @var{RC},@var{EE},@var{CF};@var{XX}
33967@cindex @samp{F} packet
33968A reply from @value{GDBN} to an @samp{F} packet sent by the target.
33969This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 33970Remote Protocol Extension}, for the specification.
ee2d5c50 33971
b8ff78ce 33972@item g
ee2d5c50 33973@anchor{read registers packet}
b8ff78ce 33974@cindex @samp{g} packet
ee2d5c50
AC
33975Read general registers.
33976
33977Reply:
33978@table @samp
33979@item @var{XX@dots{}}
8e04817f
AC
33980Each byte of register data is described by two hex digits. The bytes
33981with the register are transmitted in target byte order. The size of
b8ff78ce 33982each register and their position within the @samp{g} packet are
4a9bb1df
UW
33983determined by the @value{GDBN} internal gdbarch functions
33984@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}. The
b8ff78ce 33985specification of several standard @samp{g} packets is specified below.
ad196637
PA
33986
33987When reading registers from a trace frame (@pxref{Analyze Collected
33988Data,,Using the Collected Data}), the stub may also return a string of
33989literal @samp{x}'s in place of the register data digits, to indicate
33990that the corresponding register has not been collected, thus its value
33991is unavailable. For example, for an architecture with 4 registers of
339924 bytes each, the following reply indicates to @value{GDBN} that
33993registers 0 and 2 have not been collected, while registers 1 and 3
33994have been collected, and both have zero value:
33995
33996@smallexample
33997-> @code{g}
33998<- @code{xxxxxxxx00000000xxxxxxxx00000000}
33999@end smallexample
34000
b8ff78ce 34001@item E @var{NN}
ee2d5c50
AC
34002for an error.
34003@end table
c906108c 34004
b8ff78ce
JB
34005@item G @var{XX@dots{}}
34006@cindex @samp{G} packet
34007Write general registers. @xref{read registers packet}, for a
34008description of the @var{XX@dots{}} data.
ee2d5c50
AC
34009
34010Reply:
34011@table @samp
34012@item OK
34013for success
b8ff78ce 34014@item E @var{NN}
ee2d5c50
AC
34015for an error
34016@end table
34017
393eab54 34018@item H @var{op} @var{thread-id}
b8ff78ce 34019@cindex @samp{H} packet
8e04817f 34020Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
393eab54
PA
34021@samp{G}, et.al.). @var{op} depends on the operation to be performed:
34022it should be @samp{c} for step and continue operations (note that this
34023is deprecated, supporting the @samp{vCont} command is a better
34024option), @samp{g} for other operations. The thread designator
34025@var{thread-id} has the format and interpretation described in
34026@ref{thread-id syntax}.
ee2d5c50
AC
34027
34028Reply:
34029@table @samp
34030@item OK
34031for success
b8ff78ce 34032@item E @var{NN}
ee2d5c50
AC
34033for an error
34034@end table
c906108c 34035
8e04817f
AC
34036@c FIXME: JTC:
34037@c 'H': How restrictive (or permissive) is the thread model. If a
34038@c thread is selected and stopped, are other threads allowed
34039@c to continue to execute? As I mentioned above, I think the
34040@c semantics of each command when a thread is selected must be
34041@c described. For example:
34042@c
34043@c 'g': If the stub supports threads and a specific thread is
34044@c selected, returns the register block from that thread;
34045@c otherwise returns current registers.
34046@c
34047@c 'G' If the stub supports threads and a specific thread is
34048@c selected, sets the registers of the register block of
34049@c that thread; otherwise sets current registers.
c906108c 34050
b8ff78ce 34051@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 34052@anchor{cycle step packet}
b8ff78ce
JB
34053@cindex @samp{i} packet
34054Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
34055present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
34056step starting at that address.
c906108c 34057
b8ff78ce
JB
34058@item I
34059@cindex @samp{I} packet
34060Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
34061step packet}.
ee2d5c50 34062
b8ff78ce
JB
34063@item k
34064@cindex @samp{k} packet
34065Kill request.
c906108c 34066
36cb1214
HZ
34067The exact effect of this packet is not specified.
34068
34069For a bare-metal target, it may power cycle or reset the target
34070system. For that reason, the @samp{k} packet has no reply.
34071
34072For a single-process target, it may kill that process if possible.
34073
34074A multiple-process target may choose to kill just one process, or all
34075that are under @value{GDBN}'s control. For more precise control, use
34076the vKill packet (@pxref{vKill packet}).
34077
34078If the target system immediately closes the connection in response to
34079@samp{k}, @value{GDBN} does not consider the lack of packet
34080acknowledgment to be an error, and assumes the kill was successful.
34081
34082If connected using @kbd{target extended-remote}, and the target does
34083not close the connection in response to a kill request, @value{GDBN}
34084probes the target state as if a new connection was opened
34085(@pxref{? packet}).
c906108c 34086
b8ff78ce
JB
34087@item m @var{addr},@var{length}
34088@cindex @samp{m} packet
8e04817f 34089Read @var{length} bytes of memory starting at address @var{addr}.
fb031cdf
JB
34090Note that @var{addr} may not be aligned to any particular boundary.
34091
34092The stub need not use any particular size or alignment when gathering
34093data from memory for the response; even if @var{addr} is word-aligned
34094and @var{length} is a multiple of the word size, the stub is free to
34095use byte accesses, or not. For this reason, this packet may not be
34096suitable for accessing memory-mapped I/O devices.
c43c5473
JB
34097@cindex alignment of remote memory accesses
34098@cindex size of remote memory accesses
34099@cindex memory, alignment and size of remote accesses
c906108c 34100
ee2d5c50
AC
34101Reply:
34102@table @samp
34103@item @var{XX@dots{}}
599b237a 34104Memory contents; each byte is transmitted as a two-digit hexadecimal
b8ff78ce
JB
34105number. The reply may contain fewer bytes than requested if the
34106server was able to read only part of the region of memory.
34107@item E @var{NN}
ee2d5c50
AC
34108@var{NN} is errno
34109@end table
34110
b8ff78ce
JB
34111@item M @var{addr},@var{length}:@var{XX@dots{}}
34112@cindex @samp{M} packet
8e04817f 34113Write @var{length} bytes of memory starting at address @var{addr}.
b8ff78ce 34114@var{XX@dots{}} is the data; each byte is transmitted as a two-digit
599b237a 34115hexadecimal number.
ee2d5c50
AC
34116
34117Reply:
34118@table @samp
34119@item OK
34120for success
b8ff78ce 34121@item E @var{NN}
8e04817f
AC
34122for an error (this includes the case where only part of the data was
34123written).
ee2d5c50 34124@end table
c906108c 34125
b8ff78ce
JB
34126@item p @var{n}
34127@cindex @samp{p} packet
34128Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
34129@xref{read registers packet}, for a description of how the returned
34130register value is encoded.
ee2d5c50
AC
34131
34132Reply:
34133@table @samp
2e868123
AC
34134@item @var{XX@dots{}}
34135the register's value
b8ff78ce 34136@item E @var{NN}
2e868123 34137for an error
d57350ea 34138@item @w{}
2e868123 34139Indicating an unrecognized @var{query}.
ee2d5c50
AC
34140@end table
34141
b8ff78ce 34142@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 34143@anchor{write register packet}
b8ff78ce
JB
34144@cindex @samp{P} packet
34145Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 34146number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 34147digits for each byte in the register (target byte order).
c906108c 34148
ee2d5c50
AC
34149Reply:
34150@table @samp
34151@item OK
34152for success
b8ff78ce 34153@item E @var{NN}
ee2d5c50
AC
34154for an error
34155@end table
34156
5f3bebba
JB
34157@item q @var{name} @var{params}@dots{}
34158@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 34159@cindex @samp{q} packet
b8ff78ce 34160@cindex @samp{Q} packet
5f3bebba
JB
34161General query (@samp{q}) and set (@samp{Q}). These packets are
34162described fully in @ref{General Query Packets}.
c906108c 34163
b8ff78ce
JB
34164@item r
34165@cindex @samp{r} packet
8e04817f 34166Reset the entire system.
c906108c 34167
b8ff78ce 34168Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 34169
b8ff78ce
JB
34170@item R @var{XX}
34171@cindex @samp{R} packet
8e04817f 34172Restart the program being debugged. @var{XX}, while needed, is ignored.
2d717e4f 34173This packet is only available in extended mode (@pxref{extended mode}).
ee2d5c50 34174
8e04817f 34175The @samp{R} packet has no reply.
ee2d5c50 34176
4f553f88 34177@item s @r{[}@var{addr}@r{]}
b8ff78ce
JB
34178@cindex @samp{s} packet
34179Single step. @var{addr} is the address at which to resume. If
34180@var{addr} is omitted, resume at same address.
c906108c 34181
393eab54
PA
34182This packet is deprecated for multi-threading support. @xref{vCont
34183packet}.
34184
ee2d5c50
AC
34185Reply:
34186@xref{Stop Reply Packets}, for the reply specifications.
34187
4f553f88 34188@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 34189@anchor{step with signal packet}
b8ff78ce
JB
34190@cindex @samp{S} packet
34191Step with signal. This is analogous to the @samp{C} packet, but
34192requests a single-step, rather than a normal resumption of execution.
c906108c 34193
393eab54
PA
34194This packet is deprecated for multi-threading support. @xref{vCont
34195packet}.
34196
ee2d5c50
AC
34197Reply:
34198@xref{Stop Reply Packets}, for the reply specifications.
34199
b8ff78ce
JB
34200@item t @var{addr}:@var{PP},@var{MM}
34201@cindex @samp{t} packet
8e04817f 34202Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
34203@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
34204@var{addr} must be at least 3 digits.
c906108c 34205
b90a069a 34206@item T @var{thread-id}
b8ff78ce 34207@cindex @samp{T} packet
b90a069a 34208Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
c906108c 34209
ee2d5c50
AC
34210Reply:
34211@table @samp
34212@item OK
34213thread is still alive
b8ff78ce 34214@item E @var{NN}
ee2d5c50
AC
34215thread is dead
34216@end table
34217
b8ff78ce
JB
34218@item v
34219Packets starting with @samp{v} are identified by a multi-letter name,
34220up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 34221
2d717e4f
DJ
34222@item vAttach;@var{pid}
34223@cindex @samp{vAttach} packet
8b23ecc4
SL
34224Attach to a new process with the specified process ID @var{pid}.
34225The process ID is a
34226hexadecimal integer identifying the process. In all-stop mode, all
34227threads in the attached process are stopped; in non-stop mode, it may be
34228attached without being stopped if that is supported by the target.
34229
34230@c In non-stop mode, on a successful vAttach, the stub should set the
34231@c current thread to a thread of the newly-attached process. After
34232@c attaching, GDB queries for the attached process's thread ID with qC.
34233@c Also note that, from a user perspective, whether or not the
34234@c target is stopped on attach in non-stop mode depends on whether you
34235@c use the foreground or background version of the attach command, not
34236@c on what vAttach does; GDB does the right thing with respect to either
34237@c stopping or restarting threads.
2d717e4f
DJ
34238
34239This packet is only available in extended mode (@pxref{extended mode}).
34240
34241Reply:
34242@table @samp
34243@item E @var{nn}
34244for an error
34245@item @r{Any stop packet}
8b23ecc4
SL
34246for success in all-stop mode (@pxref{Stop Reply Packets})
34247@item OK
34248for success in non-stop mode (@pxref{Remote Non-Stop})
2d717e4f
DJ
34249@end table
34250
b90a069a 34251@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
b8ff78ce 34252@cindex @samp{vCont} packet
393eab54 34253@anchor{vCont packet}
b8ff78ce 34254Resume the inferior, specifying different actions for each thread.
b90a069a 34255If an action is specified with no @var{thread-id}, then it is applied to any
86d30acc 34256threads that don't have a specific action specified; if no default action is
8b23ecc4
SL
34257specified then other threads should remain stopped in all-stop mode and
34258in their current state in non-stop mode.
34259Specifying multiple
86d30acc 34260default actions is an error; specifying no actions is also an error.
b90a069a
SL
34261Thread IDs are specified using the syntax described in @ref{thread-id syntax}.
34262
34263Currently supported actions are:
86d30acc 34264
b8ff78ce 34265@table @samp
86d30acc
DJ
34266@item c
34267Continue.
b8ff78ce 34268@item C @var{sig}
8b23ecc4 34269Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
34270@item s
34271Step.
b8ff78ce 34272@item S @var{sig}
8b23ecc4
SL
34273Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
34274@item t
34275Stop.
c1e36e3e
PA
34276@item r @var{start},@var{end}
34277Step once, and then keep stepping as long as the thread stops at
34278addresses between @var{start} (inclusive) and @var{end} (exclusive).
34279The remote stub reports a stop reply when either the thread goes out
34280of the range or is stopped due to an unrelated reason, such as hitting
34281a breakpoint. @xref{range stepping}.
34282
34283If the range is empty (@var{start} == @var{end}), then the action
34284becomes equivalent to the @samp{s} action. In other words,
34285single-step once, and report the stop (even if the stepped instruction
34286jumps to @var{start}).
34287
34288(A stop reply may be sent at any point even if the PC is still within
34289the stepping range; for example, it is valid to implement this packet
34290in a degenerate way as a single instruction step operation.)
34291
86d30acc
DJ
34292@end table
34293
8b23ecc4
SL
34294The optional argument @var{addr} normally associated with the
34295@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
b8ff78ce 34296not supported in @samp{vCont}.
86d30acc 34297
08a0efd0
PA
34298The @samp{t} action is only relevant in non-stop mode
34299(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
8b23ecc4
SL
34300A stop reply should be generated for any affected thread not already stopped.
34301When a thread is stopped by means of a @samp{t} action,
34302the corresponding stop reply should indicate that the thread has stopped with
34303signal @samp{0}, regardless of whether the target uses some other signal
34304as an implementation detail.
34305
4220b2f8
TS
34306The stub must support @samp{vCont} if it reports support for
34307multiprocess extensions (@pxref{multiprocess extensions}). Note that in
34308this case @samp{vCont} actions can be specified to apply to all threads
34309in a process by using the @samp{p@var{pid}.-1} form of the
34310@var{thread-id}.
34311
86d30acc
DJ
34312Reply:
34313@xref{Stop Reply Packets}, for the reply specifications.
34314
b8ff78ce
JB
34315@item vCont?
34316@cindex @samp{vCont?} packet
d3e8051b 34317Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
34318
34319Reply:
34320@table @samp
b8ff78ce
JB
34321@item vCont@r{[};@var{action}@dots{}@r{]}
34322The @samp{vCont} packet is supported. Each @var{action} is a supported
34323command in the @samp{vCont} packet.
d57350ea 34324@item @w{}
b8ff78ce 34325The @samp{vCont} packet is not supported.
86d30acc 34326@end table
ee2d5c50 34327
a6b151f1
DJ
34328@item vFile:@var{operation}:@var{parameter}@dots{}
34329@cindex @samp{vFile} packet
34330Perform a file operation on the target system. For details,
34331see @ref{Host I/O Packets}.
34332
68437a39
DJ
34333@item vFlashErase:@var{addr},@var{length}
34334@cindex @samp{vFlashErase} packet
34335Direct the stub to erase @var{length} bytes of flash starting at
34336@var{addr}. The region may enclose any number of flash blocks, but
34337its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
34338flash block size appearing in the memory map (@pxref{Memory Map
34339Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
34340together, and sends a @samp{vFlashDone} request after each group; the
34341stub is allowed to delay erase operation until the @samp{vFlashDone}
34342packet is received.
34343
34344Reply:
34345@table @samp
34346@item OK
34347for success
34348@item E @var{NN}
34349for an error
34350@end table
34351
34352@item vFlashWrite:@var{addr}:@var{XX@dots{}}
34353@cindex @samp{vFlashWrite} packet
34354Direct the stub to write data to flash address @var{addr}. The data
34355is passed in binary form using the same encoding as for the @samp{X}
34356packet (@pxref{Binary Data}). The memory ranges specified by
34357@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
34358not overlap, and must appear in order of increasing addresses
34359(although @samp{vFlashErase} packets for higher addresses may already
34360have been received; the ordering is guaranteed only between
34361@samp{vFlashWrite} packets). If a packet writes to an address that was
34362neither erased by a preceding @samp{vFlashErase} packet nor by some other
34363target-specific method, the results are unpredictable.
34364
34365
34366Reply:
34367@table @samp
34368@item OK
34369for success
34370@item E.memtype
34371for vFlashWrite addressing non-flash memory
34372@item E @var{NN}
34373for an error
34374@end table
34375
34376@item vFlashDone
34377@cindex @samp{vFlashDone} packet
34378Indicate to the stub that flash programming operation is finished.
34379The stub is permitted to delay or batch the effects of a group of
34380@samp{vFlashErase} and @samp{vFlashWrite} packets until a
34381@samp{vFlashDone} packet is received. The contents of the affected
34382regions of flash memory are unpredictable until the @samp{vFlashDone}
34383request is completed.
34384
b90a069a
SL
34385@item vKill;@var{pid}
34386@cindex @samp{vKill} packet
36cb1214 34387@anchor{vKill packet}
b90a069a
SL
34388Kill the process with the specified process ID. @var{pid} is a
34389hexadecimal integer identifying the process. This packet is used in
34390preference to @samp{k} when multiprocess protocol extensions are
34391supported; see @ref{multiprocess extensions}.
34392
34393Reply:
34394@table @samp
34395@item E @var{nn}
34396for an error
34397@item OK
34398for success
34399@end table
34400
2d717e4f
DJ
34401@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
34402@cindex @samp{vRun} packet
34403Run the program @var{filename}, passing it each @var{argument} on its
34404command line. The file and arguments are hex-encoded strings. If
34405@var{filename} is an empty string, the stub may use a default program
34406(e.g.@: the last program run). The program is created in the stopped
9b562ab8 34407state.
2d717e4f 34408
8b23ecc4
SL
34409@c FIXME: What about non-stop mode?
34410
2d717e4f
DJ
34411This packet is only available in extended mode (@pxref{extended mode}).
34412
34413Reply:
34414@table @samp
34415@item E @var{nn}
34416for an error
34417@item @r{Any stop packet}
34418for success (@pxref{Stop Reply Packets})
34419@end table
34420
8b23ecc4 34421@item vStopped
8b23ecc4 34422@cindex @samp{vStopped} packet
8dbe8ece 34423@xref{Notification Packets}.
8b23ecc4 34424
b8ff78ce 34425@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 34426@anchor{X packet}
b8ff78ce
JB
34427@cindex @samp{X} packet
34428Write data to memory, where the data is transmitted in binary.
34429@var{addr} is address, @var{length} is number of bytes,
0876f84a 34430@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 34431
ee2d5c50
AC
34432Reply:
34433@table @samp
34434@item OK
34435for success
b8ff78ce 34436@item E @var{NN}
ee2d5c50
AC
34437for an error
34438@end table
34439
a1dcb23a
DJ
34440@item z @var{type},@var{addr},@var{kind}
34441@itemx Z @var{type},@var{addr},@var{kind}
2f870471 34442@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
34443@cindex @samp{z} packet
34444@cindex @samp{Z} packets
34445Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
a1dcb23a 34446watchpoint starting at address @var{address} of kind @var{kind}.
ee2d5c50 34447
2f870471
AC
34448Each breakpoint and watchpoint packet @var{type} is documented
34449separately.
34450
512217c7
AC
34451@emph{Implementation notes: A remote target shall return an empty string
34452for an unrecognized breakpoint or watchpoint packet @var{type}. A
34453remote target shall support either both or neither of a given
b8ff78ce 34454@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
34455avoid potential problems with duplicate packets, the operations should
34456be implemented in an idempotent way.}
34457
a1dcb23a 34458@item z0,@var{addr},@var{kind}
d3ce09f5 34459@itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
34460@cindex @samp{z0} packet
34461@cindex @samp{Z0} packet
34462Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
a1dcb23a 34463@var{addr} of type @var{kind}.
2f870471
AC
34464
34465A memory breakpoint is implemented by replacing the instruction at
34466@var{addr} with a software breakpoint or trap instruction. The
a1dcb23a
DJ
34467@var{kind} is target-specific and typically indicates the size of
34468the breakpoint in bytes that should be inserted. E.g., the @sc{arm}
34469and @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
34470architectures have additional meanings for @var{kind};
83364271
LM
34471@var{cond_list} is an optional list of conditional expressions in bytecode
34472form that should be evaluated on the target's side. These are the
34473conditions that should be taken into consideration when deciding if
34474the breakpoint trigger should be reported back to @var{GDBN}.
34475
34476The @var{cond_list} parameter is comprised of a series of expressions,
34477concatenated without separators. Each expression has the following form:
34478
34479@table @samp
34480
34481@item X @var{len},@var{expr}
34482@var{len} is the length of the bytecode expression and @var{expr} is the
34483actual conditional expression in bytecode form.
34484
34485@end table
34486
d3ce09f5
SS
34487The optional @var{cmd_list} parameter introduces commands that may be
34488run on the target, rather than being reported back to @value{GDBN}.
34489The parameter starts with a numeric flag @var{persist}; if the flag is
34490nonzero, then the breakpoint may remain active and the commands
34491continue to be run even when @value{GDBN} disconnects from the target.
34492Following this flag is a series of expressions concatenated with no
34493separators. Each expression has the following form:
34494
34495@table @samp
34496
34497@item X @var{len},@var{expr}
34498@var{len} is the length of the bytecode expression and @var{expr} is the
34499actual conditional expression in bytecode form.
34500
34501@end table
34502
a1dcb23a 34503see @ref{Architecture-Specific Protocol Details}.
c906108c 34504
2f870471
AC
34505@emph{Implementation note: It is possible for a target to copy or move
34506code that contains memory breakpoints (e.g., when implementing
34507overlays). The behavior of this packet, in the presence of such a
34508target, is not defined.}
c906108c 34509
ee2d5c50
AC
34510Reply:
34511@table @samp
2f870471
AC
34512@item OK
34513success
d57350ea 34514@item @w{}
2f870471 34515not supported
b8ff78ce 34516@item E @var{NN}
ee2d5c50 34517for an error
2f870471
AC
34518@end table
34519
a1dcb23a 34520@item z1,@var{addr},@var{kind}
83364271 34521@itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}
b8ff78ce
JB
34522@cindex @samp{z1} packet
34523@cindex @samp{Z1} packet
34524Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
a1dcb23a 34525address @var{addr}.
2f870471
AC
34526
34527A hardware breakpoint is implemented using a mechanism that is not
a1dcb23a 34528dependant on being able to modify the target's memory. @var{kind}
83364271 34529and @var{cond_list} have the same meaning as in @samp{Z0} packets.
2f870471
AC
34530
34531@emph{Implementation note: A hardware breakpoint is not affected by code
34532movement.}
34533
34534Reply:
34535@table @samp
ee2d5c50 34536@item OK
2f870471 34537success
d57350ea 34538@item @w{}
2f870471 34539not supported
b8ff78ce 34540@item E @var{NN}
2f870471
AC
34541for an error
34542@end table
34543
a1dcb23a
DJ
34544@item z2,@var{addr},@var{kind}
34545@itemx Z2,@var{addr},@var{kind}
b8ff78ce
JB
34546@cindex @samp{z2} packet
34547@cindex @samp{Z2} packet
a1dcb23a
DJ
34548Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
34549@var{kind} is interpreted as the number of bytes to watch.
2f870471
AC
34550
34551Reply:
34552@table @samp
34553@item OK
34554success
d57350ea 34555@item @w{}
2f870471 34556not supported
b8ff78ce 34557@item E @var{NN}
2f870471
AC
34558for an error
34559@end table
34560
a1dcb23a
DJ
34561@item z3,@var{addr},@var{kind}
34562@itemx Z3,@var{addr},@var{kind}
b8ff78ce
JB
34563@cindex @samp{z3} packet
34564@cindex @samp{Z3} packet
a1dcb23a
DJ
34565Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
34566@var{kind} is interpreted as the number of bytes to watch.
2f870471
AC
34567
34568Reply:
34569@table @samp
34570@item OK
34571success
d57350ea 34572@item @w{}
2f870471 34573not supported
b8ff78ce 34574@item E @var{NN}
2f870471
AC
34575for an error
34576@end table
34577
a1dcb23a
DJ
34578@item z4,@var{addr},@var{kind}
34579@itemx Z4,@var{addr},@var{kind}
b8ff78ce
JB
34580@cindex @samp{z4} packet
34581@cindex @samp{Z4} packet
a1dcb23a
DJ
34582Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
34583@var{kind} is interpreted as the number of bytes to watch.
2f870471
AC
34584
34585Reply:
34586@table @samp
34587@item OK
34588success
d57350ea 34589@item @w{}
2f870471 34590not supported
b8ff78ce 34591@item E @var{NN}
2f870471 34592for an error
ee2d5c50
AC
34593@end table
34594
34595@end table
c906108c 34596
ee2d5c50
AC
34597@node Stop Reply Packets
34598@section Stop Reply Packets
34599@cindex stop reply packets
c906108c 34600
8b23ecc4
SL
34601The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
34602@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
34603receive any of the below as a reply. Except for @samp{?}
34604and @samp{vStopped}, that reply is only returned
b8ff78ce 34605when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
34606number} is defined by the header @file{include/gdb/signals.h} in the
34607@value{GDBN} source code.
c906108c 34608
b8ff78ce
JB
34609As in the description of request packets, we include spaces in the
34610reply templates for clarity; these are not part of the reply packet's
34611syntax. No @value{GDBN} stop reply packet uses spaces to separate its
34612components.
c906108c 34613
b8ff78ce 34614@table @samp
ee2d5c50 34615
b8ff78ce 34616@item S @var{AA}
599b237a 34617The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
34618number). This is equivalent to a @samp{T} response with no
34619@var{n}:@var{r} pairs.
c906108c 34620
b8ff78ce
JB
34621@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
34622@cindex @samp{T} packet reply
599b237a 34623The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
34624number). This is equivalent to an @samp{S} response, except that the
34625@samp{@var{n}:@var{r}} pairs can carry values of important registers
34626and other information directly in the stop reply packet, reducing
34627round-trip latency. Single-step and breakpoint traps are reported
34628this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
34629
34630@itemize @bullet
b8ff78ce 34631@item
599b237a 34632If @var{n} is a hexadecimal number, it is a register number, and the
b8ff78ce
JB
34633corresponding @var{r} gives that register's value. @var{r} is a
34634series of bytes in target byte order, with each byte given by a
34635two-digit hex number.
cfa9d6d9 34636
b8ff78ce 34637@item
b90a069a
SL
34638If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
34639the stopped thread, as specified in @ref{thread-id syntax}.
cfa9d6d9 34640
dc146f7c
VP
34641@item
34642If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
34643the core on which the stop event was detected.
34644
b8ff78ce 34645@item
cfa9d6d9
DJ
34646If @var{n} is a recognized @dfn{stop reason}, it describes a more
34647specific event that stopped the target. The currently defined stop
34648reasons are listed below. @var{aa} should be @samp{05}, the trap
34649signal. At most one stop reason should be present.
34650
b8ff78ce
JB
34651@item
34652Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
34653and go on to the next; this allows us to extend the protocol in the
34654future.
cfa9d6d9
DJ
34655@end itemize
34656
34657The currently defined stop reasons are:
34658
34659@table @samp
34660@item watch
34661@itemx rwatch
34662@itemx awatch
34663The packet indicates a watchpoint hit, and @var{r} is the data address, in
34664hex.
34665
34666@cindex shared library events, remote reply
34667@item library
34668The packet indicates that the loaded libraries have changed.
34669@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
34670list of loaded libraries. @var{r} is ignored.
bacec72f
MS
34671
34672@cindex replay log events, remote reply
34673@item replaylog
34674The packet indicates that the target cannot continue replaying
34675logged execution events, because it has reached the end (or the
34676beginning when executing backward) of the log. The value of @var{r}
34677will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
34678for more information.
cfa9d6d9 34679@end table
ee2d5c50 34680
b8ff78ce 34681@item W @var{AA}
b90a069a 34682@itemx W @var{AA} ; process:@var{pid}
8e04817f 34683The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
34684applicable to certain targets.
34685
b90a069a
SL
34686The second form of the response, including the process ID of the exited
34687process, can be used only when @value{GDBN} has reported support for
34688multiprocess protocol extensions; see @ref{multiprocess extensions}.
34689The @var{pid} is formatted as a big-endian hex string.
34690
b8ff78ce 34691@item X @var{AA}
b90a069a 34692@itemx X @var{AA} ; process:@var{pid}
8e04817f 34693The process terminated with signal @var{AA}.
c906108c 34694
b90a069a
SL
34695The second form of the response, including the process ID of the
34696terminated process, can be used only when @value{GDBN} has reported
34697support for multiprocess protocol extensions; see @ref{multiprocess
34698extensions}. The @var{pid} is formatted as a big-endian hex string.
34699
b8ff78ce
JB
34700@item O @var{XX}@dots{}
34701@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
34702written as the program's console output. This can happen at any time
34703while the program is running and the debugger should continue to wait
8b23ecc4 34704for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
0ce1b118 34705
b8ff78ce 34706@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
34707@var{call-id} is the identifier which says which host system call should
34708be called. This is just the name of the function. Translation into the
34709correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 34710@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
34711system calls.
34712
b8ff78ce
JB
34713@samp{@var{parameter}@dots{}} is a list of parameters as defined for
34714this very system call.
0ce1b118 34715
b8ff78ce
JB
34716The target replies with this packet when it expects @value{GDBN} to
34717call a host system call on behalf of the target. @value{GDBN} replies
34718with an appropriate @samp{F} packet and keeps up waiting for the next
34719reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
34720or @samp{s} action is expected to be continued. @xref{File-I/O Remote
34721Protocol Extension}, for more details.
0ce1b118 34722
ee2d5c50
AC
34723@end table
34724
34725@node General Query Packets
34726@section General Query Packets
9c16f35a 34727@cindex remote query requests
c906108c 34728
5f3bebba
JB
34729Packets starting with @samp{q} are @dfn{general query packets};
34730packets starting with @samp{Q} are @dfn{general set packets}. General
34731query and set packets are a semi-unified form for retrieving and
34732sending information to and from the stub.
34733
34734The initial letter of a query or set packet is followed by a name
34735indicating what sort of thing the packet applies to. For example,
34736@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
34737definitions with the stub. These packet names follow some
34738conventions:
34739
34740@itemize @bullet
34741@item
34742The name must not contain commas, colons or semicolons.
34743@item
34744Most @value{GDBN} query and set packets have a leading upper case
34745letter.
34746@item
34747The names of custom vendor packets should use a company prefix, in
34748lower case, followed by a period. For example, packets designed at
34749the Acme Corporation might begin with @samp{qacme.foo} (for querying
34750foos) or @samp{Qacme.bar} (for setting bars).
34751@end itemize
34752
aa56d27a
JB
34753The name of a query or set packet should be separated from any
34754parameters by a @samp{:}; the parameters themselves should be
34755separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
34756full packet name, and check for a separator or the end of the packet,
34757in case two packet names share a common prefix. New packets should not begin
34758with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
34759packets predate these conventions, and have arguments without any terminator
34760for the packet name; we suspect they are in widespread use in places that
34761are difficult to upgrade. The @samp{qC} packet has no arguments, but some
34762existing stubs (e.g.@: RedBoot) are known to not check for the end of the
34763packet.}.
c906108c 34764
b8ff78ce
JB
34765Like the descriptions of the other packets, each description here
34766has a template showing the packet's overall syntax, followed by an
34767explanation of the packet's meaning. We include spaces in some of the
34768templates for clarity; these are not part of the packet's syntax. No
34769@value{GDBN} packet uses spaces to separate its components.
34770
5f3bebba
JB
34771Here are the currently defined query and set packets:
34772
b8ff78ce 34773@table @samp
c906108c 34774
d1feda86 34775@item QAgent:1
af4238e5 34776@itemx QAgent:0
d1feda86
YQ
34777Turn on or off the agent as a helper to perform some debugging operations
34778delegated from @value{GDBN} (@pxref{Control Agent}).
34779
d914c394
SS
34780@item QAllow:@var{op}:@var{val}@dots{}
34781@cindex @samp{QAllow} packet
34782Specify which operations @value{GDBN} expects to request of the
34783target, as a semicolon-separated list of operation name and value
34784pairs. Possible values for @var{op} include @samp{WriteReg},
34785@samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
34786@samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
34787indicating that @value{GDBN} will not request the operation, or 1,
34788indicating that it may. (The target can then use this to set up its
34789own internals optimally, for instance if the debugger never expects to
34790insert breakpoints, it may not need to install its own trap handler.)
34791
b8ff78ce 34792@item qC
9c16f35a 34793@cindex current thread, remote request
b8ff78ce 34794@cindex @samp{qC} packet
b90a069a 34795Return the current thread ID.
ee2d5c50
AC
34796
34797Reply:
34798@table @samp
b90a069a
SL
34799@item QC @var{thread-id}
34800Where @var{thread-id} is a thread ID as documented in
34801@ref{thread-id syntax}.
b8ff78ce 34802@item @r{(anything else)}
b90a069a 34803Any other reply implies the old thread ID.
ee2d5c50
AC
34804@end table
34805
b8ff78ce 34806@item qCRC:@var{addr},@var{length}
ff2587ec 34807@cindex CRC of memory block, remote request
b8ff78ce 34808@cindex @samp{qCRC} packet
936d2992 34809@anchor{qCRC packet}
99e008fe
EZ
34810Compute the CRC checksum of a block of memory using CRC-32 defined in
34811IEEE 802.3. The CRC is computed byte at a time, taking the most
34812significant bit of each byte first. The initial pattern code
34813@code{0xffffffff} is used to ensure leading zeros affect the CRC.
34814
34815@emph{Note:} This is the same CRC used in validating separate debug
34816files (@pxref{Separate Debug Files, , Debugging Information in Separate
34817Files}). However the algorithm is slightly different. When validating
34818separate debug files, the CRC is computed taking the @emph{least}
34819significant bit of each byte first, and the final result is inverted to
34820detect trailing zeros.
34821
ff2587ec
WZ
34822Reply:
34823@table @samp
b8ff78ce 34824@item E @var{NN}
ff2587ec 34825An error (such as memory fault)
b8ff78ce
JB
34826@item C @var{crc32}
34827The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
34828@end table
34829
03583c20
UW
34830@item QDisableRandomization:@var{value}
34831@cindex disable address space randomization, remote request
34832@cindex @samp{QDisableRandomization} packet
34833Some target operating systems will randomize the virtual address space
34834of the inferior process as a security feature, but provide a feature
34835to disable such randomization, e.g.@: to allow for a more deterministic
34836debugging experience. On such systems, this packet with a @var{value}
34837of 1 directs the target to disable address space randomization for
34838processes subsequently started via @samp{vRun} packets, while a packet
34839with a @var{value} of 0 tells the target to enable address space
34840randomization.
34841
34842This packet is only available in extended mode (@pxref{extended mode}).
34843
34844Reply:
34845@table @samp
34846@item OK
34847The request succeeded.
34848
34849@item E @var{nn}
34850An error occurred. @var{nn} are hex digits.
34851
d57350ea 34852@item @w{}
03583c20
UW
34853An empty reply indicates that @samp{QDisableRandomization} is not supported
34854by the stub.
34855@end table
34856
34857This packet is not probed by default; the remote stub must request it,
34858by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
34859This should only be done on targets that actually support disabling
34860address space randomization.
34861
b8ff78ce
JB
34862@item qfThreadInfo
34863@itemx qsThreadInfo
9c16f35a 34864@cindex list active threads, remote request
b8ff78ce
JB
34865@cindex @samp{qfThreadInfo} packet
34866@cindex @samp{qsThreadInfo} packet
b90a069a 34867Obtain a list of all active thread IDs from the target (OS). Since there
8e04817f
AC
34868may be too many active threads to fit into one reply packet, this query
34869works iteratively: it may require more than one query/reply sequence to
34870obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
34871be the @samp{qfThreadInfo} query; subsequent queries in the
34872sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 34873
b8ff78ce 34874NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
34875
34876Reply:
34877@table @samp
b90a069a
SL
34878@item m @var{thread-id}
34879A single thread ID
34880@item m @var{thread-id},@var{thread-id}@dots{}
34881a comma-separated list of thread IDs
b8ff78ce
JB
34882@item l
34883(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
34884@end table
34885
34886In response to each query, the target will reply with a list of one or
b90a069a 34887more thread IDs, separated by commas.
e1aac25b 34888@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce 34889ids (using the @samp{qs} form of the query), until the target responds
501994c0 34890with @samp{l} (lower-case ell, for @dfn{last}).
b90a069a
SL
34891Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
34892fields.
c906108c 34893
8dfcab11
DT
34894@emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
34895initial connection with the remote target, and the very first thread ID
34896mentioned in the reply will be stopped by @value{GDBN} in a subsequent
34897message. Therefore, the stub should ensure that the first thread ID in
34898the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
34899
b8ff78ce 34900@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 34901@cindex get thread-local storage address, remote request
b8ff78ce 34902@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
34903Fetch the address associated with thread local storage specified
34904by @var{thread-id}, @var{offset}, and @var{lm}.
34905
b90a069a
SL
34906@var{thread-id} is the thread ID associated with the
34907thread for which to fetch the TLS address. @xref{thread-id syntax}.
ff2587ec
WZ
34908
34909@var{offset} is the (big endian, hex encoded) offset associated with the
34910thread local variable. (This offset is obtained from the debug
34911information associated with the variable.)
34912
db2e3e2e 34913@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
7a9dd1b2 34914load module associated with the thread local storage. For example,
ff2587ec
WZ
34915a @sc{gnu}/Linux system will pass the link map address of the shared
34916object associated with the thread local storage under consideration.
34917Other operating environments may choose to represent the load module
34918differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
34919
34920Reply:
b8ff78ce
JB
34921@table @samp
34922@item @var{XX}@dots{}
ff2587ec
WZ
34923Hex encoded (big endian) bytes representing the address of the thread
34924local storage requested.
34925
b8ff78ce
JB
34926@item E @var{nn}
34927An error occurred. @var{nn} are hex digits.
ff2587ec 34928
d57350ea 34929@item @w{}
b8ff78ce 34930An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
34931@end table
34932
711e434b
PM
34933@item qGetTIBAddr:@var{thread-id}
34934@cindex get thread information block address
34935@cindex @samp{qGetTIBAddr} packet
34936Fetch address of the Windows OS specific Thread Information Block.
34937
34938@var{thread-id} is the thread ID associated with the thread.
34939
34940Reply:
34941@table @samp
34942@item @var{XX}@dots{}
34943Hex encoded (big endian) bytes representing the linear address of the
34944thread information block.
34945
34946@item E @var{nn}
34947An error occured. This means that either the thread was not found, or the
34948address could not be retrieved.
34949
d57350ea 34950@item @w{}
711e434b
PM
34951An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
34952@end table
34953
b8ff78ce 34954@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
34955Obtain thread information from RTOS. Where: @var{startflag} (one hex
34956digit) is one to indicate the first query and zero to indicate a
34957subsequent query; @var{threadcount} (two hex digits) is the maximum
34958number of threads the response packet can contain; and @var{nextthread}
34959(eight hex digits), for subsequent queries (@var{startflag} is zero), is
34960returned in the response as @var{argthread}.
ee2d5c50 34961
b8ff78ce 34962Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
34963
34964Reply:
34965@table @samp
b8ff78ce 34966@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
34967Where: @var{count} (two hex digits) is the number of threads being
34968returned; @var{done} (one hex digit) is zero to indicate more threads
34969and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 34970digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
ee2d5c50 34971is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 34972digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 34973@end table
c906108c 34974
b8ff78ce 34975@item qOffsets
9c16f35a 34976@cindex section offsets, remote request
b8ff78ce 34977@cindex @samp{qOffsets} packet
31d99776
DJ
34978Get section offsets that the target used when relocating the downloaded
34979image.
c906108c 34980
ee2d5c50
AC
34981Reply:
34982@table @samp
31d99776
DJ
34983@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
34984Relocate the @code{Text} section by @var{xxx} from its original address.
34985Relocate the @code{Data} section by @var{yyy} from its original address.
34986If the object file format provides segment information (e.g.@: @sc{elf}
34987@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
34988segments by the supplied offsets.
34989
34990@emph{Note: while a @code{Bss} offset may be included in the response,
34991@value{GDBN} ignores this and instead applies the @code{Data} offset
34992to the @code{Bss} section.}
34993
34994@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
34995Relocate the first segment of the object file, which conventionally
34996contains program code, to a starting address of @var{xxx}. If
34997@samp{DataSeg} is specified, relocate the second segment, which
34998conventionally contains modifiable data, to a starting address of
34999@var{yyy}. @value{GDBN} will report an error if the object file
35000does not contain segment information, or does not contain at least
35001as many segments as mentioned in the reply. Extra segments are
35002kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
35003@end table
35004
b90a069a 35005@item qP @var{mode} @var{thread-id}
9c16f35a 35006@cindex thread information, remote request
b8ff78ce 35007@cindex @samp{qP} packet
b90a069a
SL
35008Returns information on @var{thread-id}. Where: @var{mode} is a hex
35009encoded 32 bit mode; @var{thread-id} is a thread ID
35010(@pxref{thread-id syntax}).
ee2d5c50 35011
aa56d27a
JB
35012Don't use this packet; use the @samp{qThreadExtraInfo} query instead
35013(see below).
35014
b8ff78ce 35015Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 35016
8b23ecc4 35017@item QNonStop:1
687e43a4 35018@itemx QNonStop:0
8b23ecc4
SL
35019@cindex non-stop mode, remote request
35020@cindex @samp{QNonStop} packet
35021@anchor{QNonStop}
35022Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
35023@xref{Remote Non-Stop}, for more information.
35024
35025Reply:
35026@table @samp
35027@item OK
35028The request succeeded.
35029
35030@item E @var{nn}
35031An error occurred. @var{nn} are hex digits.
35032
d57350ea 35033@item @w{}
8b23ecc4
SL
35034An empty reply indicates that @samp{QNonStop} is not supported by
35035the stub.
35036@end table
35037
35038This packet is not probed by default; the remote stub must request it,
35039by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35040Use of this packet is controlled by the @code{set non-stop} command;
35041@pxref{Non-Stop Mode}.
35042
89be2091
DJ
35043@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
35044@cindex pass signals to inferior, remote request
35045@cindex @samp{QPassSignals} packet
23181151 35046@anchor{QPassSignals}
89be2091
DJ
35047Each listed @var{signal} should be passed directly to the inferior process.
35048Signals are numbered identically to continue packets and stop replies
35049(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
35050strictly greater than the previous item. These signals do not need to stop
35051the inferior, or be reported to @value{GDBN}. All other signals should be
35052reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
35053combine; any earlier @samp{QPassSignals} list is completely replaced by the
35054new list. This packet improves performance when using @samp{handle
35055@var{signal} nostop noprint pass}.
35056
35057Reply:
35058@table @samp
35059@item OK
35060The request succeeded.
35061
35062@item E @var{nn}
35063An error occurred. @var{nn} are hex digits.
35064
d57350ea 35065@item @w{}
89be2091
DJ
35066An empty reply indicates that @samp{QPassSignals} is not supported by
35067the stub.
35068@end table
35069
35070Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 35071command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
35072This packet is not probed by default; the remote stub must request it,
35073by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35074
9b224c5e
PA
35075@item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
35076@cindex signals the inferior may see, remote request
35077@cindex @samp{QProgramSignals} packet
35078@anchor{QProgramSignals}
35079Each listed @var{signal} may be delivered to the inferior process.
35080Others should be silently discarded.
35081
35082In some cases, the remote stub may need to decide whether to deliver a
35083signal to the program or not without @value{GDBN} involvement. One
35084example of that is while detaching --- the program's threads may have
35085stopped for signals that haven't yet had a chance of being reported to
35086@value{GDBN}, and so the remote stub can use the signal list specified
35087by this packet to know whether to deliver or ignore those pending
35088signals.
35089
35090This does not influence whether to deliver a signal as requested by a
35091resumption packet (@pxref{vCont packet}).
35092
35093Signals are numbered identically to continue packets and stop replies
35094(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
35095strictly greater than the previous item. Multiple
35096@samp{QProgramSignals} packets do not combine; any earlier
35097@samp{QProgramSignals} list is completely replaced by the new list.
35098
35099Reply:
35100@table @samp
35101@item OK
35102The request succeeded.
35103
35104@item E @var{nn}
35105An error occurred. @var{nn} are hex digits.
35106
d57350ea 35107@item @w{}
9b224c5e
PA
35108An empty reply indicates that @samp{QProgramSignals} is not supported
35109by the stub.
35110@end table
35111
35112Use of this packet is controlled by the @code{set remote program-signals}
35113command (@pxref{Remote Configuration, set remote program-signals}).
35114This packet is not probed by default; the remote stub must request it,
35115by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35116
b8ff78ce 35117@item qRcmd,@var{command}
ff2587ec 35118@cindex execute remote command, remote request
b8ff78ce 35119@cindex @samp{qRcmd} packet
ff2587ec 35120@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
35121execution. Invalid commands should be reported using the output
35122string. Before the final result packet, the target may also respond
35123with a number of intermediate @samp{O@var{output}} console output
35124packets. @emph{Implementors should note that providing access to a
35125stubs's interpreter may have security implications}.
fa93a9d8 35126
ff2587ec
WZ
35127Reply:
35128@table @samp
35129@item OK
35130A command response with no output.
35131@item @var{OUTPUT}
35132A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 35133@item E @var{NN}
ff2587ec 35134Indicate a badly formed request.
d57350ea 35135@item @w{}
b8ff78ce 35136An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 35137@end table
fa93a9d8 35138
aa56d27a
JB
35139(Note that the @code{qRcmd} packet's name is separated from the
35140command by a @samp{,}, not a @samp{:}, contrary to the naming
35141conventions above. Please don't use this packet as a model for new
35142packets.)
35143
08388c79
DE
35144@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
35145@cindex searching memory, in remote debugging
5c4808ca 35146@ifnotinfo
08388c79 35147@cindex @samp{qSearch:memory} packet
5c4808ca
EZ
35148@end ifnotinfo
35149@cindex @samp{qSearch memory} packet
08388c79
DE
35150@anchor{qSearch memory}
35151Search @var{length} bytes at @var{address} for @var{search-pattern}.
35152@var{address} and @var{length} are encoded in hex.
35153@var{search-pattern} is a sequence of bytes, hex encoded.
35154
35155Reply:
35156@table @samp
35157@item 0
35158The pattern was not found.
35159@item 1,address
35160The pattern was found at @var{address}.
35161@item E @var{NN}
35162A badly formed request or an error was encountered while searching memory.
d57350ea 35163@item @w{}
08388c79
DE
35164An empty reply indicates that @samp{qSearch:memory} is not recognized.
35165@end table
35166
a6f3e723
SL
35167@item QStartNoAckMode
35168@cindex @samp{QStartNoAckMode} packet
35169@anchor{QStartNoAckMode}
35170Request that the remote stub disable the normal @samp{+}/@samp{-}
35171protocol acknowledgments (@pxref{Packet Acknowledgment}).
35172
35173Reply:
35174@table @samp
35175@item OK
35176The stub has switched to no-acknowledgment mode.
35177@value{GDBN} acknowledges this reponse,
35178but neither the stub nor @value{GDBN} shall send or expect further
35179@samp{+}/@samp{-} acknowledgments in the current connection.
d57350ea 35180@item @w{}
a6f3e723
SL
35181An empty reply indicates that the stub does not support no-acknowledgment mode.
35182@end table
35183
be2a5f71
DJ
35184@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
35185@cindex supported packets, remote query
35186@cindex features of the remote protocol
35187@cindex @samp{qSupported} packet
0876f84a 35188@anchor{qSupported}
be2a5f71
DJ
35189Tell the remote stub about features supported by @value{GDBN}, and
35190query the stub for features it supports. This packet allows
35191@value{GDBN} and the remote stub to take advantage of each others'
35192features. @samp{qSupported} also consolidates multiple feature probes
35193at startup, to improve @value{GDBN} performance---a single larger
35194packet performs better than multiple smaller probe packets on
35195high-latency links. Some features may enable behavior which must not
35196be on by default, e.g.@: because it would confuse older clients or
35197stubs. Other features may describe packets which could be
35198automatically probed for, but are not. These features must be
35199reported before @value{GDBN} will use them. This ``default
35200unsupported'' behavior is not appropriate for all packets, but it
35201helps to keep the initial connection time under control with new
35202versions of @value{GDBN} which support increasing numbers of packets.
35203
35204Reply:
35205@table @samp
35206@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
35207The stub supports or does not support each returned @var{stubfeature},
35208depending on the form of each @var{stubfeature} (see below for the
35209possible forms).
d57350ea 35210@item @w{}
be2a5f71
DJ
35211An empty reply indicates that @samp{qSupported} is not recognized,
35212or that no features needed to be reported to @value{GDBN}.
35213@end table
35214
35215The allowed forms for each feature (either a @var{gdbfeature} in the
35216@samp{qSupported} packet, or a @var{stubfeature} in the response)
35217are:
35218
35219@table @samp
35220@item @var{name}=@var{value}
35221The remote protocol feature @var{name} is supported, and associated
35222with the specified @var{value}. The format of @var{value} depends
35223on the feature, but it must not include a semicolon.
35224@item @var{name}+
35225The remote protocol feature @var{name} is supported, and does not
35226need an associated value.
35227@item @var{name}-
35228The remote protocol feature @var{name} is not supported.
35229@item @var{name}?
35230The remote protocol feature @var{name} may be supported, and
35231@value{GDBN} should auto-detect support in some other way when it is
35232needed. This form will not be used for @var{gdbfeature} notifications,
35233but may be used for @var{stubfeature} responses.
35234@end table
35235
35236Whenever the stub receives a @samp{qSupported} request, the
35237supplied set of @value{GDBN} features should override any previous
35238request. This allows @value{GDBN} to put the stub in a known
35239state, even if the stub had previously been communicating with
35240a different version of @value{GDBN}.
35241
b90a069a
SL
35242The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
35243are defined:
35244
35245@table @samp
35246@item multiprocess
35247This feature indicates whether @value{GDBN} supports multiprocess
35248extensions to the remote protocol. @value{GDBN} does not use such
35249extensions unless the stub also reports that it supports them by
35250including @samp{multiprocess+} in its @samp{qSupported} reply.
35251@xref{multiprocess extensions}, for details.
c8d5aac9
L
35252
35253@item xmlRegisters
35254This feature indicates that @value{GDBN} supports the XML target
35255description. If the stub sees @samp{xmlRegisters=} with target
35256specific strings separated by a comma, it will report register
35257description.
dde08ee1
PA
35258
35259@item qRelocInsn
35260This feature indicates whether @value{GDBN} supports the
35261@samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
35262instruction reply packet}).
b90a069a
SL
35263@end table
35264
35265Stubs should ignore any unknown values for
be2a5f71
DJ
35266@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
35267packet supports receiving packets of unlimited length (earlier
b90a069a 35268versions of @value{GDBN} may reject overly long responses). Additional values
be2a5f71
DJ
35269for @var{gdbfeature} may be defined in the future to let the stub take
35270advantage of new features in @value{GDBN}, e.g.@: incompatible
b90a069a
SL
35271improvements in the remote protocol---the @samp{multiprocess} feature is
35272an example of such a feature. The stub's reply should be independent
be2a5f71
DJ
35273of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
35274describes all the features it supports, and then the stub replies with
35275all the features it supports.
35276
35277Similarly, @value{GDBN} will silently ignore unrecognized stub feature
35278responses, as long as each response uses one of the standard forms.
35279
35280Some features are flags. A stub which supports a flag feature
35281should respond with a @samp{+} form response. Other features
35282require values, and the stub should respond with an @samp{=}
35283form response.
35284
35285Each feature has a default value, which @value{GDBN} will use if
35286@samp{qSupported} is not available or if the feature is not mentioned
35287in the @samp{qSupported} response. The default values are fixed; a
35288stub is free to omit any feature responses that match the defaults.
35289
35290Not all features can be probed, but for those which can, the probing
35291mechanism is useful: in some cases, a stub's internal
35292architecture may not allow the protocol layer to know some information
35293about the underlying target in advance. This is especially common in
35294stubs which may be configured for multiple targets.
35295
35296These are the currently defined stub features and their properties:
35297
cfa9d6d9 35298@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
35299@c NOTE: The first row should be @headitem, but we do not yet require
35300@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 35301@item Feature Name
be2a5f71
DJ
35302@tab Value Required
35303@tab Default
35304@tab Probe Allowed
35305
35306@item @samp{PacketSize}
35307@tab Yes
35308@tab @samp{-}
35309@tab No
35310
0876f84a
DJ
35311@item @samp{qXfer:auxv:read}
35312@tab No
35313@tab @samp{-}
35314@tab Yes
35315
2ae8c8e7
MM
35316@item @samp{qXfer:btrace:read}
35317@tab No
35318@tab @samp{-}
35319@tab Yes
35320
23181151
DJ
35321@item @samp{qXfer:features:read}
35322@tab No
35323@tab @samp{-}
35324@tab Yes
35325
cfa9d6d9
DJ
35326@item @samp{qXfer:libraries:read}
35327@tab No
35328@tab @samp{-}
35329@tab Yes
35330
85dc5a12
GB
35331@item @samp{qXfer:libraries-svr4:read}
35332@tab No
35333@tab @samp{-}
35334@tab Yes
35335
35336@item @samp{augmented-libraries-svr4-read}
35337@tab No
35338@tab @samp{-}
35339@tab No
35340
68437a39
DJ
35341@item @samp{qXfer:memory-map:read}
35342@tab No
35343@tab @samp{-}
35344@tab Yes
35345
0fb4aa4b
PA
35346@item @samp{qXfer:sdata:read}
35347@tab No
35348@tab @samp{-}
35349@tab Yes
35350
0e7f50da
UW
35351@item @samp{qXfer:spu:read}
35352@tab No
35353@tab @samp{-}
35354@tab Yes
35355
35356@item @samp{qXfer:spu:write}
35357@tab No
35358@tab @samp{-}
35359@tab Yes
35360
4aa995e1
PA
35361@item @samp{qXfer:siginfo:read}
35362@tab No
35363@tab @samp{-}
35364@tab Yes
35365
35366@item @samp{qXfer:siginfo:write}
35367@tab No
35368@tab @samp{-}
35369@tab Yes
35370
dc146f7c
VP
35371@item @samp{qXfer:threads:read}
35372@tab No
35373@tab @samp{-}
35374@tab Yes
35375
b3b9301e
PA
35376@item @samp{qXfer:traceframe-info:read}
35377@tab No
35378@tab @samp{-}
35379@tab Yes
35380
169081d0
TG
35381@item @samp{qXfer:uib:read}
35382@tab No
35383@tab @samp{-}
35384@tab Yes
35385
78d85199
YQ
35386@item @samp{qXfer:fdpic:read}
35387@tab No
35388@tab @samp{-}
35389@tab Yes
dc146f7c 35390
2ae8c8e7
MM
35391@item @samp{Qbtrace:off}
35392@tab Yes
35393@tab @samp{-}
35394@tab Yes
35395
35396@item @samp{Qbtrace:bts}
35397@tab Yes
35398@tab @samp{-}
35399@tab Yes
35400
8b23ecc4
SL
35401@item @samp{QNonStop}
35402@tab No
35403@tab @samp{-}
35404@tab Yes
35405
89be2091
DJ
35406@item @samp{QPassSignals}
35407@tab No
35408@tab @samp{-}
35409@tab Yes
35410
a6f3e723
SL
35411@item @samp{QStartNoAckMode}
35412@tab No
35413@tab @samp{-}
35414@tab Yes
35415
b90a069a
SL
35416@item @samp{multiprocess}
35417@tab No
35418@tab @samp{-}
35419@tab No
35420
83364271
LM
35421@item @samp{ConditionalBreakpoints}
35422@tab No
35423@tab @samp{-}
35424@tab No
35425
782b2b07
SS
35426@item @samp{ConditionalTracepoints}
35427@tab No
35428@tab @samp{-}
35429@tab No
35430
0d772ac9
MS
35431@item @samp{ReverseContinue}
35432@tab No
2f8132f3 35433@tab @samp{-}
0d772ac9
MS
35434@tab No
35435
35436@item @samp{ReverseStep}
35437@tab No
2f8132f3 35438@tab @samp{-}
0d772ac9
MS
35439@tab No
35440
409873ef
SS
35441@item @samp{TracepointSource}
35442@tab No
35443@tab @samp{-}
35444@tab No
35445
d1feda86
YQ
35446@item @samp{QAgent}
35447@tab No
35448@tab @samp{-}
35449@tab No
35450
d914c394
SS
35451@item @samp{QAllow}
35452@tab No
35453@tab @samp{-}
35454@tab No
35455
03583c20
UW
35456@item @samp{QDisableRandomization}
35457@tab No
35458@tab @samp{-}
35459@tab No
35460
d248b706
KY
35461@item @samp{EnableDisableTracepoints}
35462@tab No
35463@tab @samp{-}
35464@tab No
35465
f6f899bf
HAQ
35466@item @samp{QTBuffer:size}
35467@tab No
35468@tab @samp{-}
35469@tab No
35470
3065dfb6
SS
35471@item @samp{tracenz}
35472@tab No
35473@tab @samp{-}
35474@tab No
35475
d3ce09f5
SS
35476@item @samp{BreakpointCommands}
35477@tab No
35478@tab @samp{-}
35479@tab No
35480
be2a5f71
DJ
35481@end multitable
35482
35483These are the currently defined stub features, in more detail:
35484
35485@table @samp
35486@cindex packet size, remote protocol
35487@item PacketSize=@var{bytes}
35488The remote stub can accept packets up to at least @var{bytes} in
35489length. @value{GDBN} will send packets up to this size for bulk
35490transfers, and will never send larger packets. This is a limit on the
35491data characters in the packet, including the frame and checksum.
35492There is no trailing NUL byte in a remote protocol packet; if the stub
35493stores packets in a NUL-terminated format, it should allow an extra
35494byte in its buffer for the NUL. If this stub feature is not supported,
35495@value{GDBN} guesses based on the size of the @samp{g} packet response.
35496
0876f84a
DJ
35497@item qXfer:auxv:read
35498The remote stub understands the @samp{qXfer:auxv:read} packet
35499(@pxref{qXfer auxiliary vector read}).
35500
2ae8c8e7
MM
35501@item qXfer:btrace:read
35502The remote stub understands the @samp{qXfer:btrace:read}
35503packet (@pxref{qXfer btrace read}).
35504
23181151
DJ
35505@item qXfer:features:read
35506The remote stub understands the @samp{qXfer:features:read} packet
35507(@pxref{qXfer target description read}).
35508
cfa9d6d9
DJ
35509@item qXfer:libraries:read
35510The remote stub understands the @samp{qXfer:libraries:read} packet
35511(@pxref{qXfer library list read}).
35512
2268b414
JK
35513@item qXfer:libraries-svr4:read
35514The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
35515(@pxref{qXfer svr4 library list read}).
35516
85dc5a12
GB
35517@item augmented-libraries-svr4-read
35518The remote stub understands the augmented form of the
35519@samp{qXfer:libraries-svr4:read} packet
35520(@pxref{qXfer svr4 library list read}).
35521
23181151
DJ
35522@item qXfer:memory-map:read
35523The remote stub understands the @samp{qXfer:memory-map:read} packet
35524(@pxref{qXfer memory map read}).
35525
0fb4aa4b
PA
35526@item qXfer:sdata:read
35527The remote stub understands the @samp{qXfer:sdata:read} packet
35528(@pxref{qXfer sdata read}).
35529
0e7f50da
UW
35530@item qXfer:spu:read
35531The remote stub understands the @samp{qXfer:spu:read} packet
35532(@pxref{qXfer spu read}).
35533
35534@item qXfer:spu:write
35535The remote stub understands the @samp{qXfer:spu:write} packet
35536(@pxref{qXfer spu write}).
35537
4aa995e1
PA
35538@item qXfer:siginfo:read
35539The remote stub understands the @samp{qXfer:siginfo:read} packet
35540(@pxref{qXfer siginfo read}).
35541
35542@item qXfer:siginfo:write
35543The remote stub understands the @samp{qXfer:siginfo:write} packet
35544(@pxref{qXfer siginfo write}).
35545
dc146f7c
VP
35546@item qXfer:threads:read
35547The remote stub understands the @samp{qXfer:threads:read} packet
35548(@pxref{qXfer threads read}).
35549
b3b9301e
PA
35550@item qXfer:traceframe-info:read
35551The remote stub understands the @samp{qXfer:traceframe-info:read}
35552packet (@pxref{qXfer traceframe info read}).
35553
169081d0
TG
35554@item qXfer:uib:read
35555The remote stub understands the @samp{qXfer:uib:read}
35556packet (@pxref{qXfer unwind info block}).
35557
78d85199
YQ
35558@item qXfer:fdpic:read
35559The remote stub understands the @samp{qXfer:fdpic:read}
35560packet (@pxref{qXfer fdpic loadmap read}).
35561
8b23ecc4
SL
35562@item QNonStop
35563The remote stub understands the @samp{QNonStop} packet
35564(@pxref{QNonStop}).
35565
23181151
DJ
35566@item QPassSignals
35567The remote stub understands the @samp{QPassSignals} packet
35568(@pxref{QPassSignals}).
35569
a6f3e723
SL
35570@item QStartNoAckMode
35571The remote stub understands the @samp{QStartNoAckMode} packet and
35572prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
35573
b90a069a
SL
35574@item multiprocess
35575@anchor{multiprocess extensions}
35576@cindex multiprocess extensions, in remote protocol
35577The remote stub understands the multiprocess extensions to the remote
35578protocol syntax. The multiprocess extensions affect the syntax of
35579thread IDs in both packets and replies (@pxref{thread-id syntax}), and
35580add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
35581replies. Note that reporting this feature indicates support for the
35582syntactic extensions only, not that the stub necessarily supports
35583debugging of more than one process at a time. The stub must not use
35584multiprocess extensions in packet replies unless @value{GDBN} has also
35585indicated it supports them in its @samp{qSupported} request.
35586
07e059b5
VP
35587@item qXfer:osdata:read
35588The remote stub understands the @samp{qXfer:osdata:read} packet
35589((@pxref{qXfer osdata read}).
35590
83364271
LM
35591@item ConditionalBreakpoints
35592The target accepts and implements evaluation of conditional expressions
35593defined for breakpoints. The target will only report breakpoint triggers
35594when such conditions are true (@pxref{Conditions, ,Break Conditions}).
35595
782b2b07
SS
35596@item ConditionalTracepoints
35597The remote stub accepts and implements conditional expressions defined
35598for tracepoints (@pxref{Tracepoint Conditions}).
35599
0d772ac9
MS
35600@item ReverseContinue
35601The remote stub accepts and implements the reverse continue packet
35602(@pxref{bc}).
35603
35604@item ReverseStep
35605The remote stub accepts and implements the reverse step packet
35606(@pxref{bs}).
35607
409873ef
SS
35608@item TracepointSource
35609The remote stub understands the @samp{QTDPsrc} packet that supplies
35610the source form of tracepoint definitions.
35611
d1feda86
YQ
35612@item QAgent
35613The remote stub understands the @samp{QAgent} packet.
35614
d914c394
SS
35615@item QAllow
35616The remote stub understands the @samp{QAllow} packet.
35617
03583c20
UW
35618@item QDisableRandomization
35619The remote stub understands the @samp{QDisableRandomization} packet.
35620
0fb4aa4b
PA
35621@item StaticTracepoint
35622@cindex static tracepoints, in remote protocol
35623The remote stub supports static tracepoints.
35624
1e4d1764
YQ
35625@item InstallInTrace
35626@anchor{install tracepoint in tracing}
35627The remote stub supports installing tracepoint in tracing.
35628
d248b706
KY
35629@item EnableDisableTracepoints
35630The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
35631@samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
35632to be enabled and disabled while a trace experiment is running.
35633
f6f899bf 35634@item QTBuffer:size
28abe188 35635The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
f6f899bf
HAQ
35636packet that allows to change the size of the trace buffer.
35637
3065dfb6
SS
35638@item tracenz
35639@cindex string tracing, in remote protocol
35640The remote stub supports the @samp{tracenz} bytecode for collecting strings.
35641See @ref{Bytecode Descriptions} for details about the bytecode.
35642
d3ce09f5
SS
35643@item BreakpointCommands
35644@cindex breakpoint commands, in remote protocol
35645The remote stub supports running a breakpoint's command list itself,
35646rather than reporting the hit to @value{GDBN}.
35647
2ae8c8e7
MM
35648@item Qbtrace:off
35649The remote stub understands the @samp{Qbtrace:off} packet.
35650
35651@item Qbtrace:bts
35652The remote stub understands the @samp{Qbtrace:bts} packet.
35653
be2a5f71
DJ
35654@end table
35655
b8ff78ce 35656@item qSymbol::
ff2587ec 35657@cindex symbol lookup, remote request
b8ff78ce 35658@cindex @samp{qSymbol} packet
ff2587ec
WZ
35659Notify the target that @value{GDBN} is prepared to serve symbol lookup
35660requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
35661
35662Reply:
ff2587ec 35663@table @samp
b8ff78ce 35664@item OK
ff2587ec 35665The target does not need to look up any (more) symbols.
b8ff78ce 35666@item qSymbol:@var{sym_name}
ff2587ec
WZ
35667The target requests the value of symbol @var{sym_name} (hex encoded).
35668@value{GDBN} may provide the value by using the
b8ff78ce
JB
35669@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
35670below.
ff2587ec 35671@end table
83761cbd 35672
b8ff78ce 35673@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
35674Set the value of @var{sym_name} to @var{sym_value}.
35675
35676@var{sym_name} (hex encoded) is the name of a symbol whose value the
35677target has previously requested.
35678
35679@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
35680@value{GDBN} cannot supply a value for @var{sym_name}, then this field
35681will be empty.
35682
35683Reply:
35684@table @samp
b8ff78ce 35685@item OK
ff2587ec 35686The target does not need to look up any (more) symbols.
b8ff78ce 35687@item qSymbol:@var{sym_name}
ff2587ec
WZ
35688The target requests the value of a new symbol @var{sym_name} (hex
35689encoded). @value{GDBN} will continue to supply the values of symbols
35690(if available), until the target ceases to request them.
fa93a9d8 35691@end table
0abb7bc7 35692
00bf0b85 35693@item qTBuffer
687e43a4
TT
35694@itemx QTBuffer
35695@itemx QTDisconnected
d5551862 35696@itemx QTDP
409873ef 35697@itemx QTDPsrc
d5551862 35698@itemx QTDV
00bf0b85
SS
35699@itemx qTfP
35700@itemx qTfV
9d29849a 35701@itemx QTFrame
405f8e94
SS
35702@itemx qTMinFTPILen
35703
9d29849a
JB
35704@xref{Tracepoint Packets}.
35705
b90a069a 35706@item qThreadExtraInfo,@var{thread-id}
ff2587ec 35707@cindex thread attributes info, remote request
b8ff78ce
JB
35708@cindex @samp{qThreadExtraInfo} packet
35709Obtain a printable string description of a thread's attributes from
b90a069a
SL
35710the target OS. @var{thread-id} is a thread ID;
35711see @ref{thread-id syntax}. This
b8ff78ce
JB
35712string may contain anything that the target OS thinks is interesting
35713for @value{GDBN} to tell the user about the thread. The string is
35714displayed in @value{GDBN}'s @code{info threads} display. Some
35715examples of possible thread extra info strings are @samp{Runnable}, or
35716@samp{Blocked on Mutex}.
ff2587ec
WZ
35717
35718Reply:
35719@table @samp
b8ff78ce
JB
35720@item @var{XX}@dots{}
35721Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
35722comprising the printable string containing the extra information about
35723the thread's attributes.
ff2587ec 35724@end table
814e32d7 35725
aa56d27a
JB
35726(Note that the @code{qThreadExtraInfo} packet's name is separated from
35727the command by a @samp{,}, not a @samp{:}, contrary to the naming
35728conventions above. Please don't use this packet as a model for new
35729packets.)
35730
f196051f 35731@item QTNotes
687e43a4
TT
35732@itemx qTP
35733@itemx QTSave
35734@itemx qTsP
35735@itemx qTsV
d5551862 35736@itemx QTStart
9d29849a 35737@itemx QTStop
d248b706
KY
35738@itemx QTEnable
35739@itemx QTDisable
9d29849a
JB
35740@itemx QTinit
35741@itemx QTro
35742@itemx qTStatus
d5551862 35743@itemx qTV
0fb4aa4b
PA
35744@itemx qTfSTM
35745@itemx qTsSTM
35746@itemx qTSTMat
9d29849a
JB
35747@xref{Tracepoint Packets}.
35748
0876f84a
DJ
35749@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
35750@cindex read special object, remote request
35751@cindex @samp{qXfer} packet
68437a39 35752@anchor{qXfer read}
0876f84a
DJ
35753Read uninterpreted bytes from the target's special data area
35754identified by the keyword @var{object}. Request @var{length} bytes
35755starting at @var{offset} bytes into the data. The content and
0e7f50da 35756encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
35757additional details about what data to access.
35758
35759Here are the specific requests of this form defined so far. All
35760@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
35761formats, listed below.
35762
35763@table @samp
35764@item qXfer:auxv:read::@var{offset},@var{length}
35765@anchor{qXfer auxiliary vector read}
35766Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 35767auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
35768
35769This packet is not probed by default; the remote stub must request it,
89be2091 35770by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 35771
2ae8c8e7
MM
35772@item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
35773@anchor{qXfer btrace read}
35774
35775Return a description of the current branch trace.
35776@xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
35777packet may have one of the following values:
35778
35779@table @code
35780@item all
35781Returns all available branch trace.
35782
35783@item new
35784Returns all available branch trace if the branch trace changed since
35785the last read request.
969c39fb
MM
35786
35787@item delta
35788Returns the new branch trace since the last read request. Adds a new
35789block to the end of the trace that begins at zero and ends at the source
35790location of the first branch in the trace buffer. This extra block is
35791used to stitch traces together.
35792
35793If the trace buffer overflowed, returns an error indicating the overflow.
2ae8c8e7
MM
35794@end table
35795
35796This packet is not probed by default; the remote stub must request it
35797by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35798
23181151
DJ
35799@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
35800@anchor{qXfer target description read}
35801Access the @dfn{target description}. @xref{Target Descriptions}. The
35802annex specifies which XML document to access. The main description is
35803always loaded from the @samp{target.xml} annex.
35804
35805This packet is not probed by default; the remote stub must request it,
35806by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35807
cfa9d6d9
DJ
35808@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
35809@anchor{qXfer library list read}
35810Access the target's list of loaded libraries. @xref{Library List Format}.
35811The annex part of the generic @samp{qXfer} packet must be empty
35812(@pxref{qXfer read}).
35813
35814Targets which maintain a list of libraries in the program's memory do
35815not need to implement this packet; it is designed for platforms where
35816the operating system manages the list of loaded libraries.
35817
35818This packet is not probed by default; the remote stub must request it,
35819by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35820
2268b414
JK
35821@item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
35822@anchor{qXfer svr4 library list read}
35823Access the target's list of loaded libraries when the target is an SVR4
35824platform. @xref{Library List Format for SVR4 Targets}. The annex part
85dc5a12
GB
35825of the generic @samp{qXfer} packet must be empty unless the remote
35826stub indicated it supports the augmented form of this packet
35827by supplying an appropriate @samp{qSupported} response
35828(@pxref{qXfer read}, @ref{qSupported}).
2268b414
JK
35829
35830This packet is optional for better performance on SVR4 targets.
35831@value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
35832
35833This packet is not probed by default; the remote stub must request it,
35834by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35835
85dc5a12
GB
35836If the remote stub indicates it supports the augmented form of this
35837packet then the annex part of the generic @samp{qXfer} packet may
35838contain a semicolon-separated list of @samp{@var{name}=@var{value}}
35839arguments. The currently supported arguments are:
35840
35841@table @code
35842@item start=@var{address}
35843A hexadecimal number specifying the address of the @samp{struct
35844link_map} to start reading the library list from. If unset or zero
35845then the first @samp{struct link_map} in the library list will be
35846chosen as the starting point.
35847
35848@item prev=@var{address}
35849A hexadecimal number specifying the address of the @samp{struct
35850link_map} immediately preceding the @samp{struct link_map}
35851specified by the @samp{start} argument. If unset or zero then
35852the remote stub will expect that no @samp{struct link_map}
35853exists prior to the starting point.
35854
35855@end table
35856
35857Arguments that are not understood by the remote stub will be silently
35858ignored.
35859
68437a39
DJ
35860@item qXfer:memory-map:read::@var{offset},@var{length}
35861@anchor{qXfer memory map read}
79a6e687 35862Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
35863annex part of the generic @samp{qXfer} packet must be empty
35864(@pxref{qXfer read}).
35865
0e7f50da
UW
35866This packet is not probed by default; the remote stub must request it,
35867by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35868
0fb4aa4b
PA
35869@item qXfer:sdata:read::@var{offset},@var{length}
35870@anchor{qXfer sdata read}
35871
35872Read contents of the extra collected static tracepoint marker
35873information. The annex part of the generic @samp{qXfer} packet must
35874be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
35875Action Lists}.
35876
35877This packet is not probed by default; the remote stub must request it,
35878by supplying an appropriate @samp{qSupported} response
35879(@pxref{qSupported}).
35880
4aa995e1
PA
35881@item qXfer:siginfo:read::@var{offset},@var{length}
35882@anchor{qXfer siginfo read}
35883Read contents of the extra signal information on the target
35884system. The annex part of the generic @samp{qXfer} packet must be
35885empty (@pxref{qXfer read}).
35886
35887This packet is not probed by default; the remote stub must request it,
35888by supplying an appropriate @samp{qSupported} response
35889(@pxref{qSupported}).
35890
0e7f50da
UW
35891@item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
35892@anchor{qXfer spu read}
35893Read contents of an @code{spufs} file on the target system. The
35894annex specifies which file to read; it must be of the form
35895@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
35896in the target process, and @var{name} identifes the @code{spufs} file
35897in that context to be accessed.
35898
68437a39 35899This packet is not probed by default; the remote stub must request it,
07e059b5
VP
35900by supplying an appropriate @samp{qSupported} response
35901(@pxref{qSupported}).
35902
dc146f7c
VP
35903@item qXfer:threads:read::@var{offset},@var{length}
35904@anchor{qXfer threads read}
35905Access the list of threads on target. @xref{Thread List Format}. The
35906annex part of the generic @samp{qXfer} packet must be empty
35907(@pxref{qXfer read}).
35908
35909This packet is not probed by default; the remote stub must request it,
35910by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35911
b3b9301e
PA
35912@item qXfer:traceframe-info:read::@var{offset},@var{length}
35913@anchor{qXfer traceframe info read}
35914
35915Return a description of the current traceframe's contents.
35916@xref{Traceframe Info Format}. The annex part of the generic
35917@samp{qXfer} packet must be empty (@pxref{qXfer read}).
35918
35919This packet is not probed by default; the remote stub must request it,
35920by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35921
169081d0
TG
35922@item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
35923@anchor{qXfer unwind info block}
35924
35925Return the unwind information block for @var{pc}. This packet is used
35926on OpenVMS/ia64 to ask the kernel unwind information.
35927
35928This packet is not probed by default.
35929
78d85199
YQ
35930@item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
35931@anchor{qXfer fdpic loadmap read}
35932Read contents of @code{loadmap}s on the target system. The
35933annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
35934executable @code{loadmap} or interpreter @code{loadmap} to read.
35935
35936This packet is not probed by default; the remote stub must request it,
35937by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35938
07e059b5
VP
35939@item qXfer:osdata:read::@var{offset},@var{length}
35940@anchor{qXfer osdata read}
35941Access the target's @dfn{operating system information}.
35942@xref{Operating System Information}.
35943
68437a39
DJ
35944@end table
35945
0876f84a
DJ
35946Reply:
35947@table @samp
35948@item m @var{data}
35949Data @var{data} (@pxref{Binary Data}) has been read from the
35950target. There may be more data at a higher address (although
35951it is permitted to return @samp{m} even for the last valid
35952block of data, as long as at least one byte of data was read).
35953@var{data} may have fewer bytes than the @var{length} in the
35954request.
35955
35956@item l @var{data}
35957Data @var{data} (@pxref{Binary Data}) has been read from the target.
35958There is no more data to be read. @var{data} may have fewer bytes
35959than the @var{length} in the request.
35960
35961@item l
35962The @var{offset} in the request is at the end of the data.
35963There is no more data to be read.
35964
35965@item E00
35966The request was malformed, or @var{annex} was invalid.
35967
35968@item E @var{nn}
35969The offset was invalid, or there was an error encountered reading the data.
35970@var{nn} is a hex-encoded @code{errno} value.
35971
d57350ea 35972@item @w{}
0876f84a
DJ
35973An empty reply indicates the @var{object} string was not recognized by
35974the stub, or that the object does not support reading.
35975@end table
35976
35977@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
35978@cindex write data into object, remote request
4aa995e1 35979@anchor{qXfer write}
0876f84a
DJ
35980Write uninterpreted bytes into the target's special data area
35981identified by the keyword @var{object}, starting at @var{offset} bytes
0e7f50da 35982into the data. @var{data}@dots{} is the binary-encoded data
0876f84a 35983(@pxref{Binary Data}) to be written. The content and encoding of @var{annex}
0e7f50da 35984is specific to @var{object}; it can supply additional details about what data
0876f84a
DJ
35985to access.
35986
0e7f50da
UW
35987Here are the specific requests of this form defined so far. All
35988@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
35989formats, listed below.
35990
35991@table @samp
4aa995e1
PA
35992@item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
35993@anchor{qXfer siginfo write}
35994Write @var{data} to the extra signal information on the target system.
35995The annex part of the generic @samp{qXfer} packet must be
35996empty (@pxref{qXfer write}).
35997
35998This packet is not probed by default; the remote stub must request it,
35999by supplying an appropriate @samp{qSupported} response
36000(@pxref{qSupported}).
36001
84fcdf95 36002@item qXfer:spu:write:@var{annex}:@var{offset}:@var{data}@dots{}
0e7f50da
UW
36003@anchor{qXfer spu write}
36004Write @var{data} to an @code{spufs} file on the target system. The
36005annex specifies which file to write; it must be of the form
36006@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
36007in the target process, and @var{name} identifes the @code{spufs} file
36008in that context to be accessed.
36009
36010This packet is not probed by default; the remote stub must request it,
36011by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
36012@end table
0876f84a
DJ
36013
36014Reply:
36015@table @samp
36016@item @var{nn}
36017@var{nn} (hex encoded) is the number of bytes written.
36018This may be fewer bytes than supplied in the request.
36019
36020@item E00
36021The request was malformed, or @var{annex} was invalid.
36022
36023@item E @var{nn}
36024The offset was invalid, or there was an error encountered writing the data.
36025@var{nn} is a hex-encoded @code{errno} value.
36026
d57350ea 36027@item @w{}
0876f84a
DJ
36028An empty reply indicates the @var{object} string was not
36029recognized by the stub, or that the object does not support writing.
36030@end table
36031
36032@item qXfer:@var{object}:@var{operation}:@dots{}
36033Requests of this form may be added in the future. When a stub does
36034not recognize the @var{object} keyword, or its support for
36035@var{object} does not recognize the @var{operation} keyword, the stub
36036must respond with an empty packet.
36037
0b16c5cf
PA
36038@item qAttached:@var{pid}
36039@cindex query attached, remote request
36040@cindex @samp{qAttached} packet
36041Return an indication of whether the remote server attached to an
36042existing process or created a new process. When the multiprocess
36043protocol extensions are supported (@pxref{multiprocess extensions}),
36044@var{pid} is an integer in hexadecimal format identifying the target
36045process. Otherwise, @value{GDBN} will omit the @var{pid} field and
36046the query packet will be simplified as @samp{qAttached}.
36047
36048This query is used, for example, to know whether the remote process
36049should be detached or killed when a @value{GDBN} session is ended with
36050the @code{quit} command.
36051
36052Reply:
36053@table @samp
36054@item 1
36055The remote server attached to an existing process.
36056@item 0
36057The remote server created a new process.
36058@item E @var{NN}
36059A badly formed request or an error was encountered.
36060@end table
36061
2ae8c8e7
MM
36062@item Qbtrace:bts
36063Enable branch tracing for the current thread using bts tracing.
36064
36065Reply:
36066@table @samp
36067@item OK
36068Branch tracing has been enabled.
36069@item E.errtext
36070A badly formed request or an error was encountered.
36071@end table
36072
36073@item Qbtrace:off
36074Disable branch tracing for the current thread.
36075
36076Reply:
36077@table @samp
36078@item OK
36079Branch tracing has been disabled.
36080@item E.errtext
36081A badly formed request or an error was encountered.
36082@end table
36083
ee2d5c50
AC
36084@end table
36085
a1dcb23a
DJ
36086@node Architecture-Specific Protocol Details
36087@section Architecture-Specific Protocol Details
36088
36089This section describes how the remote protocol is applied to specific
36090target architectures. Also see @ref{Standard Target Features}, for
36091details of XML target descriptions for each architecture.
36092
02b67415
MR
36093@menu
36094* ARM-Specific Protocol Details::
36095* MIPS-Specific Protocol Details::
36096@end menu
36097
36098@node ARM-Specific Protocol Details
36099@subsection @acronym{ARM}-specific Protocol Details
36100
36101@menu
36102* ARM Breakpoint Kinds::
36103@end menu
a1dcb23a 36104
02b67415
MR
36105@node ARM Breakpoint Kinds
36106@subsubsection @acronym{ARM} Breakpoint Kinds
36107@cindex breakpoint kinds, @acronym{ARM}
a1dcb23a
DJ
36108
36109These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
36110
36111@table @r
36112
36113@item 2
3611416-bit Thumb mode breakpoint.
36115
36116@item 3
3611732-bit Thumb mode (Thumb-2) breakpoint.
36118
36119@item 4
02b67415 3612032-bit @acronym{ARM} mode breakpoint.
a1dcb23a
DJ
36121
36122@end table
36123
02b67415
MR
36124@node MIPS-Specific Protocol Details
36125@subsection @acronym{MIPS}-specific Protocol Details
36126
36127@menu
36128* MIPS Register packet Format::
4cc0665f 36129* MIPS Breakpoint Kinds::
02b67415 36130@end menu
a1dcb23a 36131
02b67415
MR
36132@node MIPS Register packet Format
36133@subsubsection @acronym{MIPS} Register Packet Format
eb17f351 36134@cindex register packet format, @acronym{MIPS}
eb12ee30 36135
b8ff78ce 36136The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
36137In the below, some thirty-two bit registers are transferred as
36138sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
36139to fill the space allocated. Register bytes are transferred in target
36140byte order. The two nibbles within a register byte are transferred
02b67415 36141most-significant -- least-significant.
eb12ee30 36142
ee2d5c50 36143@table @r
eb12ee30 36144
8e04817f 36145@item MIPS32
599b237a 36146All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
3614732 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
36148registers; fsr; fir; fp.
eb12ee30 36149
8e04817f 36150@item MIPS64
599b237a 36151All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
36152thirty-two bit registers such as @code{sr}). The ordering is the same
36153as @code{MIPS32}.
eb12ee30 36154
ee2d5c50
AC
36155@end table
36156
4cc0665f
MR
36157@node MIPS Breakpoint Kinds
36158@subsubsection @acronym{MIPS} Breakpoint Kinds
36159@cindex breakpoint kinds, @acronym{MIPS}
36160
36161These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
36162
36163@table @r
36164
36165@item 2
3616616-bit @acronym{MIPS16} mode breakpoint.
36167
36168@item 3
3616916-bit @acronym{microMIPS} mode breakpoint.
36170
36171@item 4
3617232-bit standard @acronym{MIPS} mode breakpoint.
36173
36174@item 5
3617532-bit @acronym{microMIPS} mode breakpoint.
36176
36177@end table
36178
9d29849a
JB
36179@node Tracepoint Packets
36180@section Tracepoint Packets
36181@cindex tracepoint packets
36182@cindex packets, tracepoint
36183
36184Here we describe the packets @value{GDBN} uses to implement
36185tracepoints (@pxref{Tracepoints}).
36186
36187@table @samp
36188
7a697b8d 36189@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
c614397c 36190@cindex @samp{QTDP} packet
9d29849a
JB
36191Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
36192is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
36193the tracepoint is disabled. @var{step} is the tracepoint's step
7a697b8d
SS
36194count, and @var{pass} is its pass count. If an @samp{F} is present,
36195then the tracepoint is to be a fast tracepoint, and the @var{flen} is
36196the number of bytes that the target should copy elsewhere to make room
36197for the tracepoint. If an @samp{X} is present, it introduces a
36198tracepoint condition, which consists of a hexadecimal length, followed
36199by a comma and hex-encoded bytes, in a manner similar to action
36200encodings as described below. If the trailing @samp{-} is present,
36201further @samp{QTDP} packets will follow to specify this tracepoint's
36202actions.
9d29849a
JB
36203
36204Replies:
36205@table @samp
36206@item OK
36207The packet was understood and carried out.
dde08ee1
PA
36208@item qRelocInsn
36209@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 36210@item @w{}
9d29849a
JB
36211The packet was not recognized.
36212@end table
36213
36214@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
36215Define actions to be taken when a tracepoint is hit. @var{n} and
36216@var{addr} must be the same as in the initial @samp{QTDP} packet for
36217this tracepoint. This packet may only be sent immediately after
36218another @samp{QTDP} packet that ended with a @samp{-}. If the
36219trailing @samp{-} is present, further @samp{QTDP} packets will follow,
36220specifying more actions for this tracepoint.
36221
36222In the series of action packets for a given tracepoint, at most one
36223can have an @samp{S} before its first @var{action}. If such a packet
36224is sent, it and the following packets define ``while-stepping''
36225actions. Any prior packets define ordinary actions --- that is, those
36226taken when the tracepoint is first hit. If no action packet has an
36227@samp{S}, then all the packets in the series specify ordinary
36228tracepoint actions.
36229
36230The @samp{@var{action}@dots{}} portion of the packet is a series of
36231actions, concatenated without separators. Each action has one of the
36232following forms:
36233
36234@table @samp
36235
36236@item R @var{mask}
36237Collect the registers whose bits are set in @var{mask}. @var{mask} is
599b237a 36238a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
36239@var{i} should be collected. (The least significant bit is numbered
36240zero.) Note that @var{mask} may be any number of digits long; it may
36241not fit in a 32-bit word.
36242
36243@item M @var{basereg},@var{offset},@var{len}
36244Collect @var{len} bytes of memory starting at the address in register
36245number @var{basereg}, plus @var{offset}. If @var{basereg} is
36246@samp{-1}, then the range has a fixed address: @var{offset} is the
36247address of the lowest byte to collect. The @var{basereg},
599b237a 36248@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
36249values (the @samp{-1} value for @var{basereg} is a special case).
36250
36251@item X @var{len},@var{expr}
36252Evaluate @var{expr}, whose length is @var{len}, and collect memory as
36253it directs. @var{expr} is an agent expression, as described in
36254@ref{Agent Expressions}. Each byte of the expression is encoded as a
36255two-digit hex number in the packet; @var{len} is the number of bytes
36256in the expression (and thus one-half the number of hex digits in the
36257packet).
36258
36259@end table
36260
36261Any number of actions may be packed together in a single @samp{QTDP}
36262packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
36263length (400 bytes, for many stubs). There may be only one @samp{R}
36264action per tracepoint, and it must precede any @samp{M} or @samp{X}
36265actions. Any registers referred to by @samp{M} and @samp{X} actions
36266must be collected by a preceding @samp{R} action. (The
36267``while-stepping'' actions are treated as if they were attached to a
36268separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
36269
36270Replies:
36271@table @samp
36272@item OK
36273The packet was understood and carried out.
dde08ee1
PA
36274@item qRelocInsn
36275@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 36276@item @w{}
9d29849a
JB
36277The packet was not recognized.
36278@end table
36279
409873ef
SS
36280@item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
36281@cindex @samp{QTDPsrc} packet
36282Specify a source string of tracepoint @var{n} at address @var{addr}.
36283This is useful to get accurate reproduction of the tracepoints
36284originally downloaded at the beginning of the trace run. @var{type}
36285is the name of the tracepoint part, such as @samp{cond} for the
36286tracepoint's conditional expression (see below for a list of types), while
36287@var{bytes} is the string, encoded in hexadecimal.
36288
36289@var{start} is the offset of the @var{bytes} within the overall source
36290string, while @var{slen} is the total length of the source string.
36291This is intended for handling source strings that are longer than will
36292fit in a single packet.
36293@c Add detailed example when this info is moved into a dedicated
36294@c tracepoint descriptions section.
36295
36296The available string types are @samp{at} for the location,
36297@samp{cond} for the conditional, and @samp{cmd} for an action command.
36298@value{GDBN} sends a separate packet for each command in the action
36299list, in the same order in which the commands are stored in the list.
36300
36301The target does not need to do anything with source strings except
36302report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
36303query packets.
36304
36305Although this packet is optional, and @value{GDBN} will only send it
36306if the target replies with @samp{TracepointSource} @xref{General
36307Query Packets}, it makes both disconnected tracing and trace files
36308much easier to use. Otherwise the user must be careful that the
36309tracepoints in effect while looking at trace frames are identical to
36310the ones in effect during the trace run; even a small discrepancy
36311could cause @samp{tdump} not to work, or a particular trace frame not
36312be found.
36313
f61e138d
SS
36314@item QTDV:@var{n}:@var{value}
36315@cindex define trace state variable, remote request
36316@cindex @samp{QTDV} packet
36317Create a new trace state variable, number @var{n}, with an initial
36318value of @var{value}, which is a 64-bit signed integer. Both @var{n}
36319and @var{value} are encoded as hexadecimal values. @value{GDBN} has
36320the option of not using this packet for initial values of zero; the
36321target should simply create the trace state variables as they are
36322mentioned in expressions.
36323
9d29849a 36324@item QTFrame:@var{n}
c614397c 36325@cindex @samp{QTFrame} packet
9d29849a
JB
36326Select the @var{n}'th tracepoint frame from the buffer, and use the
36327register and memory contents recorded there to answer subsequent
36328request packets from @value{GDBN}.
36329
36330A successful reply from the stub indicates that the stub has found the
36331requested frame. The response is a series of parts, concatenated
36332without separators, describing the frame we selected. Each part has
36333one of the following forms:
36334
36335@table @samp
36336@item F @var{f}
36337The selected frame is number @var{n} in the trace frame buffer;
599b237a 36338@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
36339was no frame matching the criteria in the request packet.
36340
36341@item T @var{t}
36342The selected trace frame records a hit of tracepoint number @var{t};
599b237a 36343@var{t} is a hexadecimal number.
9d29849a
JB
36344
36345@end table
36346
36347@item QTFrame:pc:@var{addr}
36348Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
36349currently selected frame whose PC is @var{addr};
599b237a 36350@var{addr} is a hexadecimal number.
9d29849a
JB
36351
36352@item QTFrame:tdp:@var{t}
36353Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
36354currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 36355is a hexadecimal number.
9d29849a
JB
36356
36357@item QTFrame:range:@var{start}:@var{end}
36358Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
36359currently selected frame whose PC is between @var{start} (inclusive)
081dfbf7 36360and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
36361numbers.
36362
36363@item QTFrame:outside:@var{start}:@var{end}
36364Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
081dfbf7 36365frame @emph{outside} the given range of addresses (exclusive).
9d29849a 36366
405f8e94 36367@item qTMinFTPILen
c614397c 36368@cindex @samp{qTMinFTPILen} packet
405f8e94
SS
36369This packet requests the minimum length of instruction at which a fast
36370tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
36371the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
36372it depends on the target system being able to create trampolines in
36373the first 64K of memory, which might or might not be possible for that
36374system. So the reply to this packet will be 4 if it is able to
36375arrange for that.
36376
36377Replies:
36378
36379@table @samp
36380@item 0
36381The minimum instruction length is currently unknown.
36382@item @var{length}
36383The minimum instruction length is @var{length}, where @var{length} is greater
36384or equal to 1. @var{length} is a hexadecimal number. A reply of 1 means
36385that a fast tracepoint may be placed on any instruction regardless of size.
36386@item E
36387An error has occurred.
d57350ea 36388@item @w{}
405f8e94
SS
36389An empty reply indicates that the request is not supported by the stub.
36390@end table
36391
9d29849a 36392@item QTStart
c614397c 36393@cindex @samp{QTStart} packet
dde08ee1
PA
36394Begin the tracepoint experiment. Begin collecting data from
36395tracepoint hits in the trace frame buffer. This packet supports the
36396@samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
36397instruction reply packet}).
9d29849a
JB
36398
36399@item QTStop
c614397c 36400@cindex @samp{QTStop} packet
9d29849a
JB
36401End the tracepoint experiment. Stop collecting trace frames.
36402
d248b706
KY
36403@item QTEnable:@var{n}:@var{addr}
36404@anchor{QTEnable}
c614397c 36405@cindex @samp{QTEnable} packet
d248b706
KY
36406Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
36407experiment. If the tracepoint was previously disabled, then collection
36408of data from it will resume.
36409
36410@item QTDisable:@var{n}:@var{addr}
36411@anchor{QTDisable}
c614397c 36412@cindex @samp{QTDisable} packet
d248b706
KY
36413Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
36414experiment. No more data will be collected from the tracepoint unless
36415@samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
36416
9d29849a 36417@item QTinit
c614397c 36418@cindex @samp{QTinit} packet
9d29849a
JB
36419Clear the table of tracepoints, and empty the trace frame buffer.
36420
36421@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
c614397c 36422@cindex @samp{QTro} packet
9d29849a
JB
36423Establish the given ranges of memory as ``transparent''. The stub
36424will answer requests for these ranges from memory's current contents,
36425if they were not collected as part of the tracepoint hit.
36426
36427@value{GDBN} uses this to mark read-only regions of memory, like those
36428containing program code. Since these areas never change, they should
36429still have the same contents they did when the tracepoint was hit, so
36430there's no reason for the stub to refuse to provide their contents.
36431
d5551862 36432@item QTDisconnected:@var{value}
c614397c 36433@cindex @samp{QTDisconnected} packet
d5551862
SS
36434Set the choice to what to do with the tracing run when @value{GDBN}
36435disconnects from the target. A @var{value} of 1 directs the target to
36436continue the tracing run, while 0 tells the target to stop tracing if
36437@value{GDBN} is no longer in the picture.
36438
9d29849a 36439@item qTStatus
c614397c 36440@cindex @samp{qTStatus} packet
9d29849a
JB
36441Ask the stub if there is a trace experiment running right now.
36442
4daf5ac0
SS
36443The reply has the form:
36444
36445@table @samp
36446
36447@item T@var{running}@r{[};@var{field}@r{]}@dots{}
36448@var{running} is a single digit @code{1} if the trace is presently
36449running, or @code{0} if not. It is followed by semicolon-separated
36450optional fields that an agent may use to report additional status.
36451
36452@end table
36453
36454If the trace is not running, the agent may report any of several
36455explanations as one of the optional fields:
36456
36457@table @samp
36458
36459@item tnotrun:0
36460No trace has been run yet.
36461
f196051f
SS
36462@item tstop[:@var{text}]:0
36463The trace was stopped by a user-originated stop command. The optional
36464@var{text} field is a user-supplied string supplied as part of the
36465stop command (for instance, an explanation of why the trace was
36466stopped manually). It is hex-encoded.
4daf5ac0
SS
36467
36468@item tfull:0
36469The trace stopped because the trace buffer filled up.
36470
36471@item tdisconnected:0
36472The trace stopped because @value{GDBN} disconnected from the target.
36473
36474@item tpasscount:@var{tpnum}
36475The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
36476
6c28cbf2
SS
36477@item terror:@var{text}:@var{tpnum}
36478The trace stopped because tracepoint @var{tpnum} had an error. The
36479string @var{text} is available to describe the nature of the error
36480(for instance, a divide by zero in the condition expression).
99b5e152 36481@var{text} is hex encoded.
6c28cbf2 36482
4daf5ac0
SS
36483@item tunknown:0
36484The trace stopped for some other reason.
36485
36486@end table
36487
33da3f1c
SS
36488Additional optional fields supply statistical and other information.
36489Although not required, they are extremely useful for users monitoring
36490the progress of a trace run. If a trace has stopped, and these
36491numbers are reported, they must reflect the state of the just-stopped
36492trace.
4daf5ac0 36493
9d29849a 36494@table @samp
4daf5ac0
SS
36495
36496@item tframes:@var{n}
36497The number of trace frames in the buffer.
36498
36499@item tcreated:@var{n}
36500The total number of trace frames created during the run. This may
36501be larger than the trace frame count, if the buffer is circular.
36502
36503@item tsize:@var{n}
36504The total size of the trace buffer, in bytes.
36505
36506@item tfree:@var{n}
36507The number of bytes still unused in the buffer.
36508
33da3f1c
SS
36509@item circular:@var{n}
36510The value of the circular trace buffer flag. @code{1} means that the
36511trace buffer is circular and old trace frames will be discarded if
36512necessary to make room, @code{0} means that the trace buffer is linear
36513and may fill up.
36514
36515@item disconn:@var{n}
36516The value of the disconnected tracing flag. @code{1} means that
36517tracing will continue after @value{GDBN} disconnects, @code{0} means
36518that the trace run will stop.
36519
9d29849a
JB
36520@end table
36521
f196051f
SS
36522@item qTP:@var{tp}:@var{addr}
36523@cindex tracepoint status, remote request
36524@cindex @samp{qTP} packet
36525Ask the stub for the current state of tracepoint number @var{tp} at
36526address @var{addr}.
36527
36528Replies:
36529@table @samp
36530@item V@var{hits}:@var{usage}
36531The tracepoint has been hit @var{hits} times so far during the trace
36532run, and accounts for @var{usage} in the trace buffer. Note that
36533@code{while-stepping} steps are not counted as separate hits, but the
36534steps' space consumption is added into the usage number.
36535
36536@end table
36537
f61e138d
SS
36538@item qTV:@var{var}
36539@cindex trace state variable value, remote request
36540@cindex @samp{qTV} packet
36541Ask the stub for the value of the trace state variable number @var{var}.
36542
36543Replies:
36544@table @samp
36545@item V@var{value}
36546The value of the variable is @var{value}. This will be the current
36547value of the variable if the user is examining a running target, or a
36548saved value if the variable was collected in the trace frame that the
36549user is looking at. Note that multiple requests may result in
36550different reply values, such as when requesting values while the
36551program is running.
36552
36553@item U
36554The value of the variable is unknown. This would occur, for example,
36555if the user is examining a trace frame in which the requested variable
36556was not collected.
9d29849a
JB
36557@end table
36558
d5551862 36559@item qTfP
c614397c 36560@cindex @samp{qTfP} packet
d5551862 36561@itemx qTsP
c614397c 36562@cindex @samp{qTsP} packet
d5551862
SS
36563These packets request data about tracepoints that are being used by
36564the target. @value{GDBN} sends @code{qTfP} to get the first piece
36565of data, and multiple @code{qTsP} to get additional pieces. Replies
36566to these packets generally take the form of the @code{QTDP} packets
36567that define tracepoints. (FIXME add detailed syntax)
36568
00bf0b85 36569@item qTfV
c614397c 36570@cindex @samp{qTfV} packet
00bf0b85 36571@itemx qTsV
c614397c 36572@cindex @samp{qTsV} packet
00bf0b85
SS
36573These packets request data about trace state variables that are on the
36574target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
36575and multiple @code{qTsV} to get additional variables. Replies to
36576these packets follow the syntax of the @code{QTDV} packets that define
36577trace state variables.
36578
0fb4aa4b
PA
36579@item qTfSTM
36580@itemx qTsSTM
16bdd41f
YQ
36581@anchor{qTfSTM}
36582@anchor{qTsSTM}
c614397c
YQ
36583@cindex @samp{qTfSTM} packet
36584@cindex @samp{qTsSTM} packet
0fb4aa4b
PA
36585These packets request data about static tracepoint markers that exist
36586in the target program. @value{GDBN} sends @code{qTfSTM} to get the
36587first piece of data, and multiple @code{qTsSTM} to get additional
36588pieces. Replies to these packets take the following form:
36589
36590Reply:
36591@table @samp
36592@item m @var{address}:@var{id}:@var{extra}
36593A single marker
36594@item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
36595a comma-separated list of markers
36596@item l
36597(lower case letter @samp{L}) denotes end of list.
36598@item E @var{nn}
36599An error occurred. @var{nn} are hex digits.
d57350ea 36600@item @w{}
0fb4aa4b
PA
36601An empty reply indicates that the request is not supported by the
36602stub.
36603@end table
36604
36605@var{address} is encoded in hex.
36606@var{id} and @var{extra} are strings encoded in hex.
36607
36608In response to each query, the target will reply with a list of one or
36609more markers, separated by commas. @value{GDBN} will respond to each
36610reply with a request for more markers (using the @samp{qs} form of the
36611query), until the target responds with @samp{l} (lower-case ell, for
36612@dfn{last}).
36613
36614@item qTSTMat:@var{address}
16bdd41f 36615@anchor{qTSTMat}
c614397c 36616@cindex @samp{qTSTMat} packet
0fb4aa4b
PA
36617This packets requests data about static tracepoint markers in the
36618target program at @var{address}. Replies to this packet follow the
36619syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
36620tracepoint markers.
36621
00bf0b85 36622@item QTSave:@var{filename}
c614397c 36623@cindex @samp{QTSave} packet
00bf0b85
SS
36624This packet directs the target to save trace data to the file name
36625@var{filename} in the target's filesystem. @var{filename} is encoded
36626as a hex string; the interpretation of the file name (relative vs
36627absolute, wild cards, etc) is up to the target.
36628
36629@item qTBuffer:@var{offset},@var{len}
c614397c 36630@cindex @samp{qTBuffer} packet
00bf0b85
SS
36631Return up to @var{len} bytes of the current contents of trace buffer,
36632starting at @var{offset}. The trace buffer is treated as if it were
36633a contiguous collection of traceframes, as per the trace file format.
36634The reply consists as many hex-encoded bytes as the target can deliver
36635in a packet; it is not an error to return fewer than were asked for.
36636A reply consisting of just @code{l} indicates that no bytes are
36637available.
36638
4daf5ac0
SS
36639@item QTBuffer:circular:@var{value}
36640This packet directs the target to use a circular trace buffer if
36641@var{value} is 1, or a linear buffer if the value is 0.
36642
f6f899bf 36643@item QTBuffer:size:@var{size}
28abe188
EZ
36644@anchor{QTBuffer-size}
36645@cindex @samp{QTBuffer size} packet
f6f899bf
HAQ
36646This packet directs the target to make the trace buffer be of size
36647@var{size} if possible. A value of @code{-1} tells the target to
36648use whatever size it prefers.
36649
f196051f 36650@item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
c614397c 36651@cindex @samp{QTNotes} packet
f196051f
SS
36652This packet adds optional textual notes to the trace run. Allowable
36653types include @code{user}, @code{notes}, and @code{tstop}, the
36654@var{text} fields are arbitrary strings, hex-encoded.
36655
f61e138d 36656@end table
9d29849a 36657
dde08ee1
PA
36658@subsection Relocate instruction reply packet
36659When installing fast tracepoints in memory, the target may need to
36660relocate the instruction currently at the tracepoint address to a
36661different address in memory. For most instructions, a simple copy is
36662enough, but, for example, call instructions that implicitly push the
36663return address on the stack, and relative branches or other
36664PC-relative instructions require offset adjustment, so that the effect
36665of executing the instruction at a different address is the same as if
36666it had executed in the original location.
36667
36668In response to several of the tracepoint packets, the target may also
36669respond with a number of intermediate @samp{qRelocInsn} request
36670packets before the final result packet, to have @value{GDBN} handle
36671this relocation operation. If a packet supports this mechanism, its
36672documentation will explicitly say so. See for example the above
36673descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
36674format of the request is:
36675
36676@table @samp
36677@item qRelocInsn:@var{from};@var{to}
36678
36679This requests @value{GDBN} to copy instruction at address @var{from}
36680to address @var{to}, possibly adjusted so that executing the
36681instruction at @var{to} has the same effect as executing it at
36682@var{from}. @value{GDBN} writes the adjusted instruction to target
36683memory starting at @var{to}.
36684@end table
36685
36686Replies:
36687@table @samp
36688@item qRelocInsn:@var{adjusted_size}
36689Informs the stub the relocation is complete. @var{adjusted_size} is
36690the length in bytes of resulting relocated instruction sequence.
36691@item E @var{NN}
36692A badly formed request was detected, or an error was encountered while
36693relocating the instruction.
36694@end table
36695
a6b151f1
DJ
36696@node Host I/O Packets
36697@section Host I/O Packets
36698@cindex Host I/O, remote protocol
36699@cindex file transfer, remote protocol
36700
36701The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
36702operations on the far side of a remote link. For example, Host I/O is
36703used to upload and download files to a remote target with its own
36704filesystem. Host I/O uses the same constant values and data structure
36705layout as the target-initiated File-I/O protocol. However, the
36706Host I/O packets are structured differently. The target-initiated
36707protocol relies on target memory to store parameters and buffers.
36708Host I/O requests are initiated by @value{GDBN}, and the
36709target's memory is not involved. @xref{File-I/O Remote Protocol
36710Extension}, for more details on the target-initiated protocol.
36711
36712The Host I/O request packets all encode a single operation along with
36713its arguments. They have this format:
36714
36715@table @samp
36716
36717@item vFile:@var{operation}: @var{parameter}@dots{}
36718@var{operation} is the name of the particular request; the target
36719should compare the entire packet name up to the second colon when checking
36720for a supported operation. The format of @var{parameter} depends on
36721the operation. Numbers are always passed in hexadecimal. Negative
36722numbers have an explicit minus sign (i.e.@: two's complement is not
36723used). Strings (e.g.@: filenames) are encoded as a series of
36724hexadecimal bytes. The last argument to a system call may be a
36725buffer of escaped binary data (@pxref{Binary Data}).
36726
36727@end table
36728
36729The valid responses to Host I/O packets are:
36730
36731@table @samp
36732
36733@item F @var{result} [, @var{errno}] [; @var{attachment}]
36734@var{result} is the integer value returned by this operation, usually
36735non-negative for success and -1 for errors. If an error has occured,
36736@var{errno} will be included in the result. @var{errno} will have a
36737value defined by the File-I/O protocol (@pxref{Errno Values}). For
36738operations which return data, @var{attachment} supplies the data as a
36739binary buffer. Binary buffers in response packets are escaped in the
36740normal way (@pxref{Binary Data}). See the individual packet
36741documentation for the interpretation of @var{result} and
36742@var{attachment}.
36743
d57350ea 36744@item @w{}
a6b151f1
DJ
36745An empty response indicates that this operation is not recognized.
36746
36747@end table
36748
36749These are the supported Host I/O operations:
36750
36751@table @samp
36752@item vFile:open: @var{pathname}, @var{flags}, @var{mode}
36753Open a file at @var{pathname} and return a file descriptor for it, or
36754return -1 if an error occurs. @var{pathname} is a string,
36755@var{flags} is an integer indicating a mask of open flags
36756(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
36757of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 36758@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
36759
36760@item vFile:close: @var{fd}
36761Close the open file corresponding to @var{fd} and return 0, or
36762-1 if an error occurs.
36763
36764@item vFile:pread: @var{fd}, @var{count}, @var{offset}
36765Read data from the open file corresponding to @var{fd}. Up to
36766@var{count} bytes will be read from the file, starting at @var{offset}
36767relative to the start of the file. The target may read fewer bytes;
36768common reasons include packet size limits and an end-of-file
36769condition. The number of bytes read is returned. Zero should only be
36770returned for a successful read at the end of the file, or if
36771@var{count} was zero.
36772
36773The data read should be returned as a binary attachment on success.
36774If zero bytes were read, the response should include an empty binary
36775attachment (i.e.@: a trailing semicolon). The return value is the
36776number of target bytes read; the binary attachment may be longer if
36777some characters were escaped.
36778
36779@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
36780Write @var{data} (a binary buffer) to the open file corresponding
36781to @var{fd}. Start the write at @var{offset} from the start of the
36782file. Unlike many @code{write} system calls, there is no
36783separate @var{count} argument; the length of @var{data} in the
36784packet is used. @samp{vFile:write} returns the number of bytes written,
36785which may be shorter than the length of @var{data}, or -1 if an
36786error occurred.
36787
36788@item vFile:unlink: @var{pathname}
36789Delete the file at @var{pathname} on the target. Return 0,
36790or -1 if an error occurs. @var{pathname} is a string.
36791
b9e7b9c3
UW
36792@item vFile:readlink: @var{filename}
36793Read value of symbolic link @var{filename} on the target. Return
36794the number of bytes read, or -1 if an error occurs.
36795
36796The data read should be returned as a binary attachment on success.
36797If zero bytes were read, the response should include an empty binary
36798attachment (i.e.@: a trailing semicolon). The return value is the
36799number of target bytes read; the binary attachment may be longer if
36800some characters were escaped.
36801
a6b151f1
DJ
36802@end table
36803
9a6253be
KB
36804@node Interrupts
36805@section Interrupts
36806@cindex interrupts (remote protocol)
36807
36808When a program on the remote target is running, @value{GDBN} may
9a7071a8
JB
36809attempt to interrupt it by sending a @samp{Ctrl-C}, @code{BREAK} or
36810a @code{BREAK} followed by @code{g},
36811control of which is specified via @value{GDBN}'s @samp{interrupt-sequence}.
9a6253be
KB
36812
36813The precise meaning of @code{BREAK} is defined by the transport
8775bb90
MS
36814mechanism and may, in fact, be undefined. @value{GDBN} does not
36815currently define a @code{BREAK} mechanism for any of the network
36816interfaces except for TCP, in which case @value{GDBN} sends the
36817@code{telnet} BREAK sequence.
9a6253be
KB
36818
36819@samp{Ctrl-C}, on the other hand, is defined and implemented for all
36820transport mechanisms. It is represented by sending the single byte
36821@code{0x03} without any of the usual packet overhead described in
36822the Overview section (@pxref{Overview}). When a @code{0x03} byte is
36823transmitted as part of a packet, it is considered to be packet data
36824and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 36825(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
36826@code{0x03} as part of its packet.
36827
9a7071a8
JB
36828@code{BREAK} followed by @code{g} is also known as Magic SysRq g.
36829When Linux kernel receives this sequence from serial port,
36830it stops execution and connects to gdb.
36831
9a6253be
KB
36832Stubs are not required to recognize these interrupt mechanisms and the
36833precise meaning associated with receipt of the interrupt is
8b23ecc4
SL
36834implementation defined. If the target supports debugging of multiple
36835threads and/or processes, it should attempt to interrupt all
36836currently-executing threads and processes.
36837If the stub is successful at interrupting the
36838running program, it should send one of the stop
36839reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
36840of successfully stopping the program in all-stop mode, and a stop reply
36841for each stopped thread in non-stop mode.
36842Interrupts received while the
36843program is stopped are discarded.
36844
36845@node Notification Packets
36846@section Notification Packets
36847@cindex notification packets
36848@cindex packets, notification
36849
36850The @value{GDBN} remote serial protocol includes @dfn{notifications},
36851packets that require no acknowledgment. Both the GDB and the stub
36852may send notifications (although the only notifications defined at
36853present are sent by the stub). Notifications carry information
36854without incurring the round-trip latency of an acknowledgment, and so
36855are useful for low-impact communications where occasional packet loss
36856is not a problem.
36857
36858A notification packet has the form @samp{% @var{data} #
36859@var{checksum}}, where @var{data} is the content of the notification,
36860and @var{checksum} is a checksum of @var{data}, computed and formatted
36861as for ordinary @value{GDBN} packets. A notification's @var{data}
36862never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
36863receiving a notification, the recipient sends no @samp{+} or @samp{-}
36864to acknowledge the notification's receipt or to report its corruption.
36865
36866Every notification's @var{data} begins with a name, which contains no
36867colon characters, followed by a colon character.
36868
36869Recipients should silently ignore corrupted notifications and
36870notifications they do not understand. Recipients should restart
36871timeout periods on receipt of a well-formed notification, whether or
36872not they understand it.
36873
36874Senders should only send the notifications described here when this
36875protocol description specifies that they are permitted. In the
36876future, we may extend the protocol to permit existing notifications in
36877new contexts; this rule helps older senders avoid confusing newer
36878recipients.
36879
36880(Older versions of @value{GDBN} ignore bytes received until they see
36881the @samp{$} byte that begins an ordinary packet, so new stubs may
36882transmit notifications without fear of confusing older clients. There
36883are no notifications defined for @value{GDBN} to send at the moment, but we
36884assume that most older stubs would ignore them, as well.)
36885
8dbe8ece 36886Each notification is comprised of three parts:
8b23ecc4 36887@table @samp
8dbe8ece
YQ
36888@item @var{name}:@var{event}
36889The notification packet is sent by the side that initiates the
36890exchange (currently, only the stub does that), with @var{event}
36891carrying the specific information about the notification.
36892@var{name} is the name of the notification.
36893@item @var{ack}
36894The acknowledge sent by the other side, usually @value{GDBN}, to
36895acknowledge the exchange and request the event.
36896@end table
36897
36898The purpose of an asynchronous notification mechanism is to report to
36899@value{GDBN} that something interesting happened in the remote stub.
36900
36901The remote stub may send notification @var{name}:@var{event}
36902at any time, but @value{GDBN} acknowledges the notification when
36903appropriate. The notification event is pending before @value{GDBN}
36904acknowledges. Only one notification at a time may be pending; if
36905additional events occur before @value{GDBN} has acknowledged the
36906previous notification, they must be queued by the stub for later
36907synchronous transmission in response to @var{ack} packets from
36908@value{GDBN}. Because the notification mechanism is unreliable,
36909the stub is permitted to resend a notification if it believes
36910@value{GDBN} may not have received it.
36911
36912Specifically, notifications may appear when @value{GDBN} is not
36913otherwise reading input from the stub, or when @value{GDBN} is
36914expecting to read a normal synchronous response or a
36915@samp{+}/@samp{-} acknowledgment to a packet it has sent.
36916Notification packets are distinct from any other communication from
36917the stub so there is no ambiguity.
36918
36919After receiving a notification, @value{GDBN} shall acknowledge it by
36920sending a @var{ack} packet as a regular, synchronous request to the
36921stub. Such acknowledgment is not required to happen immediately, as
36922@value{GDBN} is permitted to send other, unrelated packets to the
36923stub first, which the stub should process normally.
36924
36925Upon receiving a @var{ack} packet, if the stub has other queued
36926events to report to @value{GDBN}, it shall respond by sending a
36927normal @var{event}. @value{GDBN} shall then send another @var{ack}
36928packet to solicit further responses; again, it is permitted to send
36929other, unrelated packets as well which the stub should process
36930normally.
36931
36932If the stub receives a @var{ack} packet and there are no additional
36933@var{event} to report, the stub shall return an @samp{OK} response.
36934At this point, @value{GDBN} has finished processing a notification
36935and the stub has completed sending any queued events. @value{GDBN}
36936won't accept any new notifications until the final @samp{OK} is
36937received . If further notification events occur, the stub shall send
36938a new notification, @value{GDBN} shall accept the notification, and
36939the process shall be repeated.
36940
36941The process of asynchronous notification can be illustrated by the
36942following example:
36943@smallexample
36944<- @code{%%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
36945@code{...}
36946-> @code{vStopped}
36947<- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
36948-> @code{vStopped}
36949<- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
36950-> @code{vStopped}
36951<- @code{OK}
36952@end smallexample
36953
36954The following notifications are defined:
36955@multitable @columnfractions 0.12 0.12 0.38 0.38
36956
36957@item Notification
36958@tab Ack
36959@tab Event
36960@tab Description
36961
36962@item Stop
36963@tab vStopped
36964@tab @var{reply}. The @var{reply} has the form of a stop reply, as
8b23ecc4
SL
36965described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
36966for information on how these notifications are acknowledged by
36967@value{GDBN}.
8dbe8ece
YQ
36968@tab Report an asynchronous stop event in non-stop mode.
36969
36970@end multitable
8b23ecc4
SL
36971
36972@node Remote Non-Stop
36973@section Remote Protocol Support for Non-Stop Mode
36974
36975@value{GDBN}'s remote protocol supports non-stop debugging of
36976multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
36977supports non-stop mode, it should report that to @value{GDBN} by including
36978@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
36979
36980@value{GDBN} typically sends a @samp{QNonStop} packet only when
36981establishing a new connection with the stub. Entering non-stop mode
36982does not alter the state of any currently-running threads, but targets
36983must stop all threads in any already-attached processes when entering
36984all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
36985probe the target state after a mode change.
36986
36987In non-stop mode, when an attached process encounters an event that
36988would otherwise be reported with a stop reply, it uses the
36989asynchronous notification mechanism (@pxref{Notification Packets}) to
36990inform @value{GDBN}. In contrast to all-stop mode, where all threads
36991in all processes are stopped when a stop reply is sent, in non-stop
36992mode only the thread reporting the stop event is stopped. That is,
36993when reporting a @samp{S} or @samp{T} response to indicate completion
36994of a step operation, hitting a breakpoint, or a fault, only the
36995affected thread is stopped; any other still-running threads continue
36996to run. When reporting a @samp{W} or @samp{X} response, all running
36997threads belonging to other attached processes continue to run.
36998
8b23ecc4
SL
36999In non-stop mode, the target shall respond to the @samp{?} packet as
37000follows. First, any incomplete stop reply notification/@samp{vStopped}
37001sequence in progress is abandoned. The target must begin a new
37002sequence reporting stop events for all stopped threads, whether or not
37003it has previously reported those events to @value{GDBN}. The first
37004stop reply is sent as a synchronous reply to the @samp{?} packet, and
37005subsequent stop replies are sent as responses to @samp{vStopped} packets
37006using the mechanism described above. The target must not send
37007asynchronous stop reply notifications until the sequence is complete.
37008If all threads are running when the target receives the @samp{?} packet,
37009or if the target is not attached to any process, it shall respond
37010@samp{OK}.
9a6253be 37011
a6f3e723
SL
37012@node Packet Acknowledgment
37013@section Packet Acknowledgment
37014
37015@cindex acknowledgment, for @value{GDBN} remote
37016@cindex packet acknowledgment, for @value{GDBN} remote
37017By default, when either the host or the target machine receives a packet,
37018the first response expected is an acknowledgment: either @samp{+} (to indicate
37019the package was received correctly) or @samp{-} (to request retransmission).
37020This mechanism allows the @value{GDBN} remote protocol to operate over
37021unreliable transport mechanisms, such as a serial line.
37022
37023In cases where the transport mechanism is itself reliable (such as a pipe or
37024TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
37025It may be desirable to disable them in that case to reduce communication
37026overhead, or for other reasons. This can be accomplished by means of the
37027@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
37028
37029When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
37030expect @samp{+}/@samp{-} protocol acknowledgments. The packet
37031and response format still includes the normal checksum, as described in
37032@ref{Overview}, but the checksum may be ignored by the receiver.
37033
37034If the stub supports @samp{QStartNoAckMode} and prefers to operate in
37035no-acknowledgment mode, it should report that to @value{GDBN}
37036by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
37037@pxref{qSupported}.
37038If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
37039disabled via the @code{set remote noack-packet off} command
37040(@pxref{Remote Configuration}),
37041@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
37042Only then may the stub actually turn off packet acknowledgments.
37043@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
37044response, which can be safely ignored by the stub.
37045
37046Note that @code{set remote noack-packet} command only affects negotiation
37047between @value{GDBN} and the stub when subsequent connections are made;
37048it does not affect the protocol acknowledgment state for any current
37049connection.
37050Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
37051new connection is established,
37052there is also no protocol request to re-enable the acknowledgments
37053for the current connection, once disabled.
37054
ee2d5c50
AC
37055@node Examples
37056@section Examples
eb12ee30 37057
8e04817f
AC
37058Example sequence of a target being re-started. Notice how the restart
37059does not get any direct output:
eb12ee30 37060
474c8240 37061@smallexample
d2c6833e
AC
37062-> @code{R00}
37063<- @code{+}
8e04817f 37064@emph{target restarts}
d2c6833e 37065-> @code{?}
8e04817f 37066<- @code{+}
d2c6833e
AC
37067<- @code{T001:1234123412341234}
37068-> @code{+}
474c8240 37069@end smallexample
eb12ee30 37070
8e04817f 37071Example sequence of a target being stepped by a single instruction:
eb12ee30 37072
474c8240 37073@smallexample
d2c6833e 37074-> @code{G1445@dots{}}
8e04817f 37075<- @code{+}
d2c6833e
AC
37076-> @code{s}
37077<- @code{+}
37078@emph{time passes}
37079<- @code{T001:1234123412341234}
8e04817f 37080-> @code{+}
d2c6833e 37081-> @code{g}
8e04817f 37082<- @code{+}
d2c6833e
AC
37083<- @code{1455@dots{}}
37084-> @code{+}
474c8240 37085@end smallexample
eb12ee30 37086
79a6e687
BW
37087@node File-I/O Remote Protocol Extension
37088@section File-I/O Remote Protocol Extension
0ce1b118
CV
37089@cindex File-I/O remote protocol extension
37090
37091@menu
37092* File-I/O Overview::
79a6e687
BW
37093* Protocol Basics::
37094* The F Request Packet::
37095* The F Reply Packet::
37096* The Ctrl-C Message::
0ce1b118 37097* Console I/O::
79a6e687 37098* List of Supported Calls::
db2e3e2e 37099* Protocol-specific Representation of Datatypes::
0ce1b118
CV
37100* Constants::
37101* File-I/O Examples::
37102@end menu
37103
37104@node File-I/O Overview
37105@subsection File-I/O Overview
37106@cindex file-i/o overview
37107
9c16f35a 37108The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 37109target to use the host's file system and console I/O to perform various
0ce1b118 37110system calls. System calls on the target system are translated into a
fc320d37
SL
37111remote protocol packet to the host system, which then performs the needed
37112actions and returns a response packet to the target system.
0ce1b118
CV
37113This simulates file system operations even on targets that lack file systems.
37114
fc320d37
SL
37115The protocol is defined to be independent of both the host and target systems.
37116It uses its own internal representation of datatypes and values. Both
0ce1b118 37117@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
37118translating the system-dependent value representations into the internal
37119protocol representations when data is transmitted.
0ce1b118 37120
fc320d37
SL
37121The communication is synchronous. A system call is possible only when
37122@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
37123or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 37124the target is stopped to allow deterministic access to the target's
fc320d37
SL
37125memory. Therefore File-I/O is not interruptible by target signals. On
37126the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 37127(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
37128
37129The target's request to perform a host system call does not finish
37130the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
37131after finishing the system call, the target returns to continuing the
37132previous activity (continue, step). No additional continue or step
37133request from @value{GDBN} is required.
37134
37135@smallexample
f7dc1244 37136(@value{GDBP}) continue
0ce1b118
CV
37137 <- target requests 'system call X'
37138 target is stopped, @value{GDBN} executes system call
3f94c067
BW
37139 -> @value{GDBN} returns result
37140 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
37141 <- target hits breakpoint and sends a Txx packet
37142@end smallexample
37143
fc320d37
SL
37144The protocol only supports I/O on the console and to regular files on
37145the host file system. Character or block special devices, pipes,
37146named pipes, sockets or any other communication method on the host
0ce1b118
CV
37147system are not supported by this protocol.
37148
8b23ecc4
SL
37149File I/O is not supported in non-stop mode.
37150
79a6e687
BW
37151@node Protocol Basics
37152@subsection Protocol Basics
0ce1b118
CV
37153@cindex protocol basics, file-i/o
37154
fc320d37
SL
37155The File-I/O protocol uses the @code{F} packet as the request as well
37156as reply packet. Since a File-I/O system call can only occur when
37157@value{GDBN} is waiting for a response from the continuing or stepping target,
37158the File-I/O request is a reply that @value{GDBN} has to expect as a result
37159of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
37160This @code{F} packet contains all information needed to allow @value{GDBN}
37161to call the appropriate host system call:
37162
37163@itemize @bullet
b383017d 37164@item
0ce1b118
CV
37165A unique identifier for the requested system call.
37166
37167@item
37168All parameters to the system call. Pointers are given as addresses
37169in the target memory address space. Pointers to strings are given as
b383017d 37170pointer/length pair. Numerical values are given as they are.
db2e3e2e 37171Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
37172
37173@end itemize
37174
fc320d37 37175At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
37176
37177@itemize @bullet
b383017d 37178@item
fc320d37
SL
37179If the parameters include pointer values to data needed as input to a
37180system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
37181standard @code{m} packet request. This additional communication has to be
37182expected by the target implementation and is handled as any other @code{m}
37183packet.
37184
37185@item
37186@value{GDBN} translates all value from protocol representation to host
37187representation as needed. Datatypes are coerced into the host types.
37188
37189@item
fc320d37 37190@value{GDBN} calls the system call.
0ce1b118
CV
37191
37192@item
37193It then coerces datatypes back to protocol representation.
37194
37195@item
fc320d37
SL
37196If the system call is expected to return data in buffer space specified
37197by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
37198target using a @code{M} or @code{X} packet. This packet has to be expected
37199by the target implementation and is handled as any other @code{M} or @code{X}
37200packet.
37201
37202@end itemize
37203
37204Eventually @value{GDBN} replies with another @code{F} packet which contains all
37205necessary information for the target to continue. This at least contains
37206
37207@itemize @bullet
37208@item
37209Return value.
37210
37211@item
37212@code{errno}, if has been changed by the system call.
37213
37214@item
37215``Ctrl-C'' flag.
37216
37217@end itemize
37218
37219After having done the needed type and value coercion, the target continues
37220the latest continue or step action.
37221
79a6e687
BW
37222@node The F Request Packet
37223@subsection The @code{F} Request Packet
0ce1b118
CV
37224@cindex file-i/o request packet
37225@cindex @code{F} request packet
37226
37227The @code{F} request packet has the following format:
37228
37229@table @samp
fc320d37 37230@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
37231
37232@var{call-id} is the identifier to indicate the host system call to be called.
37233This is just the name of the function.
37234
fc320d37
SL
37235@var{parameter@dots{}} are the parameters to the system call.
37236Parameters are hexadecimal integer values, either the actual values in case
37237of scalar datatypes, pointers to target buffer space in case of compound
37238datatypes and unspecified memory areas, or pointer/length pairs in case
37239of string parameters. These are appended to the @var{call-id} as a
37240comma-delimited list. All values are transmitted in ASCII
37241string representation, pointer/length pairs separated by a slash.
0ce1b118 37242
b383017d 37243@end table
0ce1b118 37244
fc320d37 37245
0ce1b118 37246
79a6e687
BW
37247@node The F Reply Packet
37248@subsection The @code{F} Reply Packet
0ce1b118
CV
37249@cindex file-i/o reply packet
37250@cindex @code{F} reply packet
37251
37252The @code{F} reply packet has the following format:
37253
37254@table @samp
37255
d3bdde98 37256@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
37257
37258@var{retcode} is the return code of the system call as hexadecimal value.
37259
db2e3e2e
BW
37260@var{errno} is the @code{errno} set by the call, in protocol-specific
37261representation.
0ce1b118
CV
37262This parameter can be omitted if the call was successful.
37263
fc320d37
SL
37264@var{Ctrl-C flag} is only sent if the user requested a break. In this
37265case, @var{errno} must be sent as well, even if the call was successful.
37266The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
37267
37268@smallexample
37269F0,0,C
37270@end smallexample
37271
37272@noindent
fc320d37 37273or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
37274
37275@smallexample
37276F-1,4,C
37277@end smallexample
37278
37279@noindent
db2e3e2e 37280assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
37281
37282@end table
37283
0ce1b118 37284
79a6e687
BW
37285@node The Ctrl-C Message
37286@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
37287@cindex ctrl-c message, in file-i/o protocol
37288
c8aa23ab 37289If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 37290reply packet (@pxref{The F Reply Packet}),
fc320d37 37291the target should behave as if it had
0ce1b118 37292gotten a break message. The meaning for the target is ``system call
fc320d37 37293interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 37294(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 37295packet.
fc320d37
SL
37296
37297It's important for the target to know in which
37298state the system call was interrupted. There are two possible cases:
0ce1b118
CV
37299
37300@itemize @bullet
37301@item
37302The system call hasn't been performed on the host yet.
37303
37304@item
37305The system call on the host has been finished.
37306
37307@end itemize
37308
37309These two states can be distinguished by the target by the value of the
37310returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
37311call hasn't been performed. This is equivalent to the @code{EINTR} handling
37312on POSIX systems. In any other case, the target may presume that the
fc320d37 37313system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
37314as if the break message arrived right after the system call.
37315
fc320d37 37316@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
37317yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
37318@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
37319before the user requests a break, the full action must be finished by
37320@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
37321The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
37322or the full action has been completed.
37323
37324@node Console I/O
37325@subsection Console I/O
37326@cindex console i/o as part of file-i/o
37327
d3e8051b 37328By default and if not explicitly closed by the target system, the file
0ce1b118
CV
37329descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
37330on the @value{GDBN} console is handled as any other file output operation
37331(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
37332by @value{GDBN} so that after the target read request from file descriptor
373330 all following typing is buffered until either one of the following
37334conditions is met:
37335
37336@itemize @bullet
37337@item
c8aa23ab 37338The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
37339@code{read}
37340system call is treated as finished.
37341
37342@item
7f9087cb 37343The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 37344newline.
0ce1b118
CV
37345
37346@item
c8aa23ab
EZ
37347The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
37348character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
37349
37350@end itemize
37351
fc320d37
SL
37352If the user has typed more characters than fit in the buffer given to
37353the @code{read} call, the trailing characters are buffered in @value{GDBN} until
37354either another @code{read(0, @dots{})} is requested by the target, or debugging
37355is stopped at the user's request.
0ce1b118 37356
0ce1b118 37357
79a6e687
BW
37358@node List of Supported Calls
37359@subsection List of Supported Calls
0ce1b118
CV
37360@cindex list of supported file-i/o calls
37361
37362@menu
37363* open::
37364* close::
37365* read::
37366* write::
37367* lseek::
37368* rename::
37369* unlink::
37370* stat/fstat::
37371* gettimeofday::
37372* isatty::
37373* system::
37374@end menu
37375
37376@node open
37377@unnumberedsubsubsec open
37378@cindex open, file-i/o system call
37379
fc320d37
SL
37380@table @asis
37381@item Synopsis:
0ce1b118 37382@smallexample
0ce1b118
CV
37383int open(const char *pathname, int flags);
37384int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
37385@end smallexample
37386
fc320d37
SL
37387@item Request:
37388@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
37389
0ce1b118 37390@noindent
fc320d37 37391@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
37392
37393@table @code
b383017d 37394@item O_CREAT
0ce1b118
CV
37395If the file does not exist it will be created. The host
37396rules apply as far as file ownership and time stamps
37397are concerned.
37398
b383017d 37399@item O_EXCL
fc320d37 37400When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
37401an error and open() fails.
37402
b383017d 37403@item O_TRUNC
0ce1b118 37404If the file already exists and the open mode allows
fc320d37
SL
37405writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
37406truncated to zero length.
0ce1b118 37407
b383017d 37408@item O_APPEND
0ce1b118
CV
37409The file is opened in append mode.
37410
b383017d 37411@item O_RDONLY
0ce1b118
CV
37412The file is opened for reading only.
37413
b383017d 37414@item O_WRONLY
0ce1b118
CV
37415The file is opened for writing only.
37416
b383017d 37417@item O_RDWR
0ce1b118 37418The file is opened for reading and writing.
fc320d37 37419@end table
0ce1b118
CV
37420
37421@noindent
fc320d37 37422Other bits are silently ignored.
0ce1b118 37423
0ce1b118
CV
37424
37425@noindent
fc320d37 37426@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
37427
37428@table @code
b383017d 37429@item S_IRUSR
0ce1b118
CV
37430User has read permission.
37431
b383017d 37432@item S_IWUSR
0ce1b118
CV
37433User has write permission.
37434
b383017d 37435@item S_IRGRP
0ce1b118
CV
37436Group has read permission.
37437
b383017d 37438@item S_IWGRP
0ce1b118
CV
37439Group has write permission.
37440
b383017d 37441@item S_IROTH
0ce1b118
CV
37442Others have read permission.
37443
b383017d 37444@item S_IWOTH
0ce1b118 37445Others have write permission.
fc320d37 37446@end table
0ce1b118
CV
37447
37448@noindent
fc320d37 37449Other bits are silently ignored.
0ce1b118 37450
0ce1b118 37451
fc320d37
SL
37452@item Return value:
37453@code{open} returns the new file descriptor or -1 if an error
37454occurred.
0ce1b118 37455
fc320d37 37456@item Errors:
0ce1b118
CV
37457
37458@table @code
b383017d 37459@item EEXIST
fc320d37 37460@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 37461
b383017d 37462@item EISDIR
fc320d37 37463@var{pathname} refers to a directory.
0ce1b118 37464
b383017d 37465@item EACCES
0ce1b118
CV
37466The requested access is not allowed.
37467
37468@item ENAMETOOLONG
fc320d37 37469@var{pathname} was too long.
0ce1b118 37470
b383017d 37471@item ENOENT
fc320d37 37472A directory component in @var{pathname} does not exist.
0ce1b118 37473
b383017d 37474@item ENODEV
fc320d37 37475@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 37476
b383017d 37477@item EROFS
fc320d37 37478@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
37479write access was requested.
37480
b383017d 37481@item EFAULT
fc320d37 37482@var{pathname} is an invalid pointer value.
0ce1b118 37483
b383017d 37484@item ENOSPC
0ce1b118
CV
37485No space on device to create the file.
37486
b383017d 37487@item EMFILE
0ce1b118
CV
37488The process already has the maximum number of files open.
37489
b383017d 37490@item ENFILE
0ce1b118
CV
37491The limit on the total number of files open on the system
37492has been reached.
37493
b383017d 37494@item EINTR
0ce1b118
CV
37495The call was interrupted by the user.
37496@end table
37497
fc320d37
SL
37498@end table
37499
0ce1b118
CV
37500@node close
37501@unnumberedsubsubsec close
37502@cindex close, file-i/o system call
37503
fc320d37
SL
37504@table @asis
37505@item Synopsis:
0ce1b118 37506@smallexample
0ce1b118 37507int close(int fd);
fc320d37 37508@end smallexample
0ce1b118 37509
fc320d37
SL
37510@item Request:
37511@samp{Fclose,@var{fd}}
0ce1b118 37512
fc320d37
SL
37513@item Return value:
37514@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 37515
fc320d37 37516@item Errors:
0ce1b118
CV
37517
37518@table @code
b383017d 37519@item EBADF
fc320d37 37520@var{fd} isn't a valid open file descriptor.
0ce1b118 37521
b383017d 37522@item EINTR
0ce1b118
CV
37523The call was interrupted by the user.
37524@end table
37525
fc320d37
SL
37526@end table
37527
0ce1b118
CV
37528@node read
37529@unnumberedsubsubsec read
37530@cindex read, file-i/o system call
37531
fc320d37
SL
37532@table @asis
37533@item Synopsis:
0ce1b118 37534@smallexample
0ce1b118 37535int read(int fd, void *buf, unsigned int count);
fc320d37 37536@end smallexample
0ce1b118 37537
fc320d37
SL
37538@item Request:
37539@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 37540
fc320d37 37541@item Return value:
0ce1b118
CV
37542On success, the number of bytes read is returned.
37543Zero indicates end of file. If count is zero, read
b383017d 37544returns zero as well. On error, -1 is returned.
0ce1b118 37545
fc320d37 37546@item Errors:
0ce1b118
CV
37547
37548@table @code
b383017d 37549@item EBADF
fc320d37 37550@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
37551reading.
37552
b383017d 37553@item EFAULT
fc320d37 37554@var{bufptr} is an invalid pointer value.
0ce1b118 37555
b383017d 37556@item EINTR
0ce1b118
CV
37557The call was interrupted by the user.
37558@end table
37559
fc320d37
SL
37560@end table
37561
0ce1b118
CV
37562@node write
37563@unnumberedsubsubsec write
37564@cindex write, file-i/o system call
37565
fc320d37
SL
37566@table @asis
37567@item Synopsis:
0ce1b118 37568@smallexample
0ce1b118 37569int write(int fd, const void *buf, unsigned int count);
fc320d37 37570@end smallexample
0ce1b118 37571
fc320d37
SL
37572@item Request:
37573@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 37574
fc320d37 37575@item Return value:
0ce1b118
CV
37576On success, the number of bytes written are returned.
37577Zero indicates nothing was written. On error, -1
37578is returned.
37579
fc320d37 37580@item Errors:
0ce1b118
CV
37581
37582@table @code
b383017d 37583@item EBADF
fc320d37 37584@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
37585writing.
37586
b383017d 37587@item EFAULT
fc320d37 37588@var{bufptr} is an invalid pointer value.
0ce1b118 37589
b383017d 37590@item EFBIG
0ce1b118 37591An attempt was made to write a file that exceeds the
db2e3e2e 37592host-specific maximum file size allowed.
0ce1b118 37593
b383017d 37594@item ENOSPC
0ce1b118
CV
37595No space on device to write the data.
37596
b383017d 37597@item EINTR
0ce1b118
CV
37598The call was interrupted by the user.
37599@end table
37600
fc320d37
SL
37601@end table
37602
0ce1b118
CV
37603@node lseek
37604@unnumberedsubsubsec lseek
37605@cindex lseek, file-i/o system call
37606
fc320d37
SL
37607@table @asis
37608@item Synopsis:
0ce1b118 37609@smallexample
0ce1b118 37610long lseek (int fd, long offset, int flag);
0ce1b118
CV
37611@end smallexample
37612
fc320d37
SL
37613@item Request:
37614@samp{Flseek,@var{fd},@var{offset},@var{flag}}
37615
37616@var{flag} is one of:
0ce1b118
CV
37617
37618@table @code
b383017d 37619@item SEEK_SET
fc320d37 37620The offset is set to @var{offset} bytes.
0ce1b118 37621
b383017d 37622@item SEEK_CUR
fc320d37 37623The offset is set to its current location plus @var{offset}
0ce1b118
CV
37624bytes.
37625
b383017d 37626@item SEEK_END
fc320d37 37627The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
37628bytes.
37629@end table
37630
fc320d37 37631@item Return value:
0ce1b118
CV
37632On success, the resulting unsigned offset in bytes from
37633the beginning of the file is returned. Otherwise, a
37634value of -1 is returned.
37635
fc320d37 37636@item Errors:
0ce1b118
CV
37637
37638@table @code
b383017d 37639@item EBADF
fc320d37 37640@var{fd} is not a valid open file descriptor.
0ce1b118 37641
b383017d 37642@item ESPIPE
fc320d37 37643@var{fd} is associated with the @value{GDBN} console.
0ce1b118 37644
b383017d 37645@item EINVAL
fc320d37 37646@var{flag} is not a proper value.
0ce1b118 37647
b383017d 37648@item EINTR
0ce1b118
CV
37649The call was interrupted by the user.
37650@end table
37651
fc320d37
SL
37652@end table
37653
0ce1b118
CV
37654@node rename
37655@unnumberedsubsubsec rename
37656@cindex rename, file-i/o system call
37657
fc320d37
SL
37658@table @asis
37659@item Synopsis:
0ce1b118 37660@smallexample
0ce1b118 37661int rename(const char *oldpath, const char *newpath);
fc320d37 37662@end smallexample
0ce1b118 37663
fc320d37
SL
37664@item Request:
37665@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 37666
fc320d37 37667@item Return value:
0ce1b118
CV
37668On success, zero is returned. On error, -1 is returned.
37669
fc320d37 37670@item Errors:
0ce1b118
CV
37671
37672@table @code
b383017d 37673@item EISDIR
fc320d37 37674@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
37675directory.
37676
b383017d 37677@item EEXIST
fc320d37 37678@var{newpath} is a non-empty directory.
0ce1b118 37679
b383017d 37680@item EBUSY
fc320d37 37681@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
37682process.
37683
b383017d 37684@item EINVAL
0ce1b118
CV
37685An attempt was made to make a directory a subdirectory
37686of itself.
37687
b383017d 37688@item ENOTDIR
fc320d37
SL
37689A component used as a directory in @var{oldpath} or new
37690path is not a directory. Or @var{oldpath} is a directory
37691and @var{newpath} exists but is not a directory.
0ce1b118 37692
b383017d 37693@item EFAULT
fc320d37 37694@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 37695
b383017d 37696@item EACCES
0ce1b118
CV
37697No access to the file or the path of the file.
37698
37699@item ENAMETOOLONG
b383017d 37700
fc320d37 37701@var{oldpath} or @var{newpath} was too long.
0ce1b118 37702
b383017d 37703@item ENOENT
fc320d37 37704A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 37705
b383017d 37706@item EROFS
0ce1b118
CV
37707The file is on a read-only filesystem.
37708
b383017d 37709@item ENOSPC
0ce1b118
CV
37710The device containing the file has no room for the new
37711directory entry.
37712
b383017d 37713@item EINTR
0ce1b118
CV
37714The call was interrupted by the user.
37715@end table
37716
fc320d37
SL
37717@end table
37718
0ce1b118
CV
37719@node unlink
37720@unnumberedsubsubsec unlink
37721@cindex unlink, file-i/o system call
37722
fc320d37
SL
37723@table @asis
37724@item Synopsis:
0ce1b118 37725@smallexample
0ce1b118 37726int unlink(const char *pathname);
fc320d37 37727@end smallexample
0ce1b118 37728
fc320d37
SL
37729@item Request:
37730@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 37731
fc320d37 37732@item Return value:
0ce1b118
CV
37733On success, zero is returned. On error, -1 is returned.
37734
fc320d37 37735@item Errors:
0ce1b118
CV
37736
37737@table @code
b383017d 37738@item EACCES
0ce1b118
CV
37739No access to the file or the path of the file.
37740
b383017d 37741@item EPERM
0ce1b118
CV
37742The system does not allow unlinking of directories.
37743
b383017d 37744@item EBUSY
fc320d37 37745The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
37746being used by another process.
37747
b383017d 37748@item EFAULT
fc320d37 37749@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
37750
37751@item ENAMETOOLONG
fc320d37 37752@var{pathname} was too long.
0ce1b118 37753
b383017d 37754@item ENOENT
fc320d37 37755A directory component in @var{pathname} does not exist.
0ce1b118 37756
b383017d 37757@item ENOTDIR
0ce1b118
CV
37758A component of the path is not a directory.
37759
b383017d 37760@item EROFS
0ce1b118
CV
37761The file is on a read-only filesystem.
37762
b383017d 37763@item EINTR
0ce1b118
CV
37764The call was interrupted by the user.
37765@end table
37766
fc320d37
SL
37767@end table
37768
0ce1b118
CV
37769@node stat/fstat
37770@unnumberedsubsubsec stat/fstat
37771@cindex fstat, file-i/o system call
37772@cindex stat, file-i/o system call
37773
fc320d37
SL
37774@table @asis
37775@item Synopsis:
0ce1b118 37776@smallexample
0ce1b118
CV
37777int stat(const char *pathname, struct stat *buf);
37778int fstat(int fd, struct stat *buf);
fc320d37 37779@end smallexample
0ce1b118 37780
fc320d37
SL
37781@item Request:
37782@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
37783@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 37784
fc320d37 37785@item Return value:
0ce1b118
CV
37786On success, zero is returned. On error, -1 is returned.
37787
fc320d37 37788@item Errors:
0ce1b118
CV
37789
37790@table @code
b383017d 37791@item EBADF
fc320d37 37792@var{fd} is not a valid open file.
0ce1b118 37793
b383017d 37794@item ENOENT
fc320d37 37795A directory component in @var{pathname} does not exist or the
0ce1b118
CV
37796path is an empty string.
37797
b383017d 37798@item ENOTDIR
0ce1b118
CV
37799A component of the path is not a directory.
37800
b383017d 37801@item EFAULT
fc320d37 37802@var{pathnameptr} is an invalid pointer value.
0ce1b118 37803
b383017d 37804@item EACCES
0ce1b118
CV
37805No access to the file or the path of the file.
37806
37807@item ENAMETOOLONG
fc320d37 37808@var{pathname} was too long.
0ce1b118 37809
b383017d 37810@item EINTR
0ce1b118
CV
37811The call was interrupted by the user.
37812@end table
37813
fc320d37
SL
37814@end table
37815
0ce1b118
CV
37816@node gettimeofday
37817@unnumberedsubsubsec gettimeofday
37818@cindex gettimeofday, file-i/o system call
37819
fc320d37
SL
37820@table @asis
37821@item Synopsis:
0ce1b118 37822@smallexample
0ce1b118 37823int gettimeofday(struct timeval *tv, void *tz);
fc320d37 37824@end smallexample
0ce1b118 37825
fc320d37
SL
37826@item Request:
37827@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 37828
fc320d37 37829@item Return value:
0ce1b118
CV
37830On success, 0 is returned, -1 otherwise.
37831
fc320d37 37832@item Errors:
0ce1b118
CV
37833
37834@table @code
b383017d 37835@item EINVAL
fc320d37 37836@var{tz} is a non-NULL pointer.
0ce1b118 37837
b383017d 37838@item EFAULT
fc320d37
SL
37839@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
37840@end table
37841
0ce1b118
CV
37842@end table
37843
37844@node isatty
37845@unnumberedsubsubsec isatty
37846@cindex isatty, file-i/o system call
37847
fc320d37
SL
37848@table @asis
37849@item Synopsis:
0ce1b118 37850@smallexample
0ce1b118 37851int isatty(int fd);
fc320d37 37852@end smallexample
0ce1b118 37853
fc320d37
SL
37854@item Request:
37855@samp{Fisatty,@var{fd}}
0ce1b118 37856
fc320d37
SL
37857@item Return value:
37858Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 37859
fc320d37 37860@item Errors:
0ce1b118
CV
37861
37862@table @code
b383017d 37863@item EINTR
0ce1b118
CV
37864The call was interrupted by the user.
37865@end table
37866
fc320d37
SL
37867@end table
37868
37869Note that the @code{isatty} call is treated as a special case: it returns
378701 to the target if the file descriptor is attached
37871to the @value{GDBN} console, 0 otherwise. Implementing through system calls
37872would require implementing @code{ioctl} and would be more complex than
37873needed.
37874
37875
0ce1b118
CV
37876@node system
37877@unnumberedsubsubsec system
37878@cindex system, file-i/o system call
37879
fc320d37
SL
37880@table @asis
37881@item Synopsis:
0ce1b118 37882@smallexample
0ce1b118 37883int system(const char *command);
fc320d37 37884@end smallexample
0ce1b118 37885
fc320d37
SL
37886@item Request:
37887@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 37888
fc320d37 37889@item Return value:
5600ea19
NS
37890If @var{len} is zero, the return value indicates whether a shell is
37891available. A zero return value indicates a shell is not available.
37892For non-zero @var{len}, the value returned is -1 on error and the
37893return status of the command otherwise. Only the exit status of the
37894command is returned, which is extracted from the host's @code{system}
37895return value by calling @code{WEXITSTATUS(retval)}. In case
37896@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 37897
fc320d37 37898@item Errors:
0ce1b118
CV
37899
37900@table @code
b383017d 37901@item EINTR
0ce1b118
CV
37902The call was interrupted by the user.
37903@end table
37904
fc320d37
SL
37905@end table
37906
37907@value{GDBN} takes over the full task of calling the necessary host calls
37908to perform the @code{system} call. The return value of @code{system} on
37909the host is simplified before it's returned
37910to the target. Any termination signal information from the child process
37911is discarded, and the return value consists
37912entirely of the exit status of the called command.
37913
37914Due to security concerns, the @code{system} call is by default refused
37915by @value{GDBN}. The user has to allow this call explicitly with the
37916@code{set remote system-call-allowed 1} command.
37917
37918@table @code
37919@item set remote system-call-allowed
37920@kindex set remote system-call-allowed
37921Control whether to allow the @code{system} calls in the File I/O
37922protocol for the remote target. The default is zero (disabled).
37923
37924@item show remote system-call-allowed
37925@kindex show remote system-call-allowed
37926Show whether the @code{system} calls are allowed in the File I/O
37927protocol.
37928@end table
37929
db2e3e2e
BW
37930@node Protocol-specific Representation of Datatypes
37931@subsection Protocol-specific Representation of Datatypes
37932@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
37933
37934@menu
79a6e687
BW
37935* Integral Datatypes::
37936* Pointer Values::
37937* Memory Transfer::
0ce1b118
CV
37938* struct stat::
37939* struct timeval::
37940@end menu
37941
79a6e687
BW
37942@node Integral Datatypes
37943@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
37944@cindex integral datatypes, in file-i/o protocol
37945
fc320d37
SL
37946The integral datatypes used in the system calls are @code{int},
37947@code{unsigned int}, @code{long}, @code{unsigned long},
37948@code{mode_t}, and @code{time_t}.
0ce1b118 37949
fc320d37 37950@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
37951implemented as 32 bit values in this protocol.
37952
fc320d37 37953@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 37954
0ce1b118
CV
37955@xref{Limits}, for corresponding MIN and MAX values (similar to those
37956in @file{limits.h}) to allow range checking on host and target.
37957
37958@code{time_t} datatypes are defined as seconds since the Epoch.
37959
37960All integral datatypes transferred as part of a memory read or write of a
37961structured datatype e.g.@: a @code{struct stat} have to be given in big endian
37962byte order.
37963
79a6e687
BW
37964@node Pointer Values
37965@unnumberedsubsubsec Pointer Values
0ce1b118
CV
37966@cindex pointer values, in file-i/o protocol
37967
37968Pointers to target data are transmitted as they are. An exception
37969is made for pointers to buffers for which the length isn't
37970transmitted as part of the function call, namely strings. Strings
37971are transmitted as a pointer/length pair, both as hex values, e.g.@:
37972
37973@smallexample
37974@code{1aaf/12}
37975@end smallexample
37976
37977@noindent
37978which is a pointer to data of length 18 bytes at position 0x1aaf.
37979The length is defined as the full string length in bytes, including
fc320d37
SL
37980the trailing null byte. For example, the string @code{"hello world"}
37981at address 0x123456 is transmitted as
0ce1b118
CV
37982
37983@smallexample
fc320d37 37984@code{123456/d}
0ce1b118
CV
37985@end smallexample
37986
79a6e687
BW
37987@node Memory Transfer
37988@unnumberedsubsubsec Memory Transfer
fc320d37
SL
37989@cindex memory transfer, in file-i/o protocol
37990
37991Structured data which is transferred using a memory read or write (for
db2e3e2e 37992example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
37993with all scalar multibyte datatypes being big endian. Translation to
37994this representation needs to be done both by the target before the @code{F}
37995packet is sent, and by @value{GDBN} before
37996it transfers memory to the target. Transferred pointers to structured
37997data should point to the already-coerced data at any time.
0ce1b118 37998
0ce1b118
CV
37999
38000@node struct stat
38001@unnumberedsubsubsec struct stat
38002@cindex struct stat, in file-i/o protocol
38003
fc320d37
SL
38004The buffer of type @code{struct stat} used by the target and @value{GDBN}
38005is defined as follows:
0ce1b118
CV
38006
38007@smallexample
38008struct stat @{
38009 unsigned int st_dev; /* device */
38010 unsigned int st_ino; /* inode */
38011 mode_t st_mode; /* protection */
38012 unsigned int st_nlink; /* number of hard links */
38013 unsigned int st_uid; /* user ID of owner */
38014 unsigned int st_gid; /* group ID of owner */
38015 unsigned int st_rdev; /* device type (if inode device) */
38016 unsigned long st_size; /* total size, in bytes */
38017 unsigned long st_blksize; /* blocksize for filesystem I/O */
38018 unsigned long st_blocks; /* number of blocks allocated */
38019 time_t st_atime; /* time of last access */
38020 time_t st_mtime; /* time of last modification */
38021 time_t st_ctime; /* time of last change */
38022@};
38023@end smallexample
38024
fc320d37 38025The integral datatypes conform to the definitions given in the
79a6e687 38026appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
38027structure is of size 64 bytes.
38028
38029The values of several fields have a restricted meaning and/or
38030range of values.
38031
fc320d37 38032@table @code
0ce1b118 38033
fc320d37
SL
38034@item st_dev
38035A value of 0 represents a file, 1 the console.
0ce1b118 38036
fc320d37
SL
38037@item st_ino
38038No valid meaning for the target. Transmitted unchanged.
0ce1b118 38039
fc320d37
SL
38040@item st_mode
38041Valid mode bits are described in @ref{Constants}. Any other
38042bits have currently no meaning for the target.
0ce1b118 38043
fc320d37
SL
38044@item st_uid
38045@itemx st_gid
38046@itemx st_rdev
38047No valid meaning for the target. Transmitted unchanged.
0ce1b118 38048
fc320d37
SL
38049@item st_atime
38050@itemx st_mtime
38051@itemx st_ctime
38052These values have a host and file system dependent
38053accuracy. Especially on Windows hosts, the file system may not
38054support exact timing values.
38055@end table
0ce1b118 38056
fc320d37
SL
38057The target gets a @code{struct stat} of the above representation and is
38058responsible for coercing it to the target representation before
0ce1b118
CV
38059continuing.
38060
fc320d37
SL
38061Note that due to size differences between the host, target, and protocol
38062representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
38063get truncated on the target.
38064
38065@node struct timeval
38066@unnumberedsubsubsec struct timeval
38067@cindex struct timeval, in file-i/o protocol
38068
fc320d37 38069The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
38070is defined as follows:
38071
38072@smallexample
b383017d 38073struct timeval @{
0ce1b118
CV
38074 time_t tv_sec; /* second */
38075 long tv_usec; /* microsecond */
38076@};
38077@end smallexample
38078
fc320d37 38079The integral datatypes conform to the definitions given in the
79a6e687 38080appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
38081structure is of size 8 bytes.
38082
38083@node Constants
38084@subsection Constants
38085@cindex constants, in file-i/o protocol
38086
38087The following values are used for the constants inside of the
fc320d37 38088protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
38089values before and after the call as needed.
38090
38091@menu
79a6e687
BW
38092* Open Flags::
38093* mode_t Values::
38094* Errno Values::
38095* Lseek Flags::
0ce1b118
CV
38096* Limits::
38097@end menu
38098
79a6e687
BW
38099@node Open Flags
38100@unnumberedsubsubsec Open Flags
0ce1b118
CV
38101@cindex open flags, in file-i/o protocol
38102
38103All values are given in hexadecimal representation.
38104
38105@smallexample
38106 O_RDONLY 0x0
38107 O_WRONLY 0x1
38108 O_RDWR 0x2
38109 O_APPEND 0x8
38110 O_CREAT 0x200
38111 O_TRUNC 0x400
38112 O_EXCL 0x800
38113@end smallexample
38114
79a6e687
BW
38115@node mode_t Values
38116@unnumberedsubsubsec mode_t Values
0ce1b118
CV
38117@cindex mode_t values, in file-i/o protocol
38118
38119All values are given in octal representation.
38120
38121@smallexample
38122 S_IFREG 0100000
38123 S_IFDIR 040000
38124 S_IRUSR 0400
38125 S_IWUSR 0200
38126 S_IXUSR 0100
38127 S_IRGRP 040
38128 S_IWGRP 020
38129 S_IXGRP 010
38130 S_IROTH 04
38131 S_IWOTH 02
38132 S_IXOTH 01
38133@end smallexample
38134
79a6e687
BW
38135@node Errno Values
38136@unnumberedsubsubsec Errno Values
0ce1b118
CV
38137@cindex errno values, in file-i/o protocol
38138
38139All values are given in decimal representation.
38140
38141@smallexample
38142 EPERM 1
38143 ENOENT 2
38144 EINTR 4
38145 EBADF 9
38146 EACCES 13
38147 EFAULT 14
38148 EBUSY 16
38149 EEXIST 17
38150 ENODEV 19
38151 ENOTDIR 20
38152 EISDIR 21
38153 EINVAL 22
38154 ENFILE 23
38155 EMFILE 24
38156 EFBIG 27
38157 ENOSPC 28
38158 ESPIPE 29
38159 EROFS 30
38160 ENAMETOOLONG 91
38161 EUNKNOWN 9999
38162@end smallexample
38163
fc320d37 38164 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
38165 any error value not in the list of supported error numbers.
38166
79a6e687
BW
38167@node Lseek Flags
38168@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
38169@cindex lseek flags, in file-i/o protocol
38170
38171@smallexample
38172 SEEK_SET 0
38173 SEEK_CUR 1
38174 SEEK_END 2
38175@end smallexample
38176
38177@node Limits
38178@unnumberedsubsubsec Limits
38179@cindex limits, in file-i/o protocol
38180
38181All values are given in decimal representation.
38182
38183@smallexample
38184 INT_MIN -2147483648
38185 INT_MAX 2147483647
38186 UINT_MAX 4294967295
38187 LONG_MIN -9223372036854775808
38188 LONG_MAX 9223372036854775807
38189 ULONG_MAX 18446744073709551615
38190@end smallexample
38191
38192@node File-I/O Examples
38193@subsection File-I/O Examples
38194@cindex file-i/o examples
38195
38196Example sequence of a write call, file descriptor 3, buffer is at target
38197address 0x1234, 6 bytes should be written:
38198
38199@smallexample
38200<- @code{Fwrite,3,1234,6}
38201@emph{request memory read from target}
38202-> @code{m1234,6}
38203<- XXXXXX
38204@emph{return "6 bytes written"}
38205-> @code{F6}
38206@end smallexample
38207
38208Example sequence of a read call, file descriptor 3, buffer is at target
38209address 0x1234, 6 bytes should be read:
38210
38211@smallexample
38212<- @code{Fread,3,1234,6}
38213@emph{request memory write to target}
38214-> @code{X1234,6:XXXXXX}
38215@emph{return "6 bytes read"}
38216-> @code{F6}
38217@end smallexample
38218
38219Example sequence of a read call, call fails on the host due to invalid
fc320d37 38220file descriptor (@code{EBADF}):
0ce1b118
CV
38221
38222@smallexample
38223<- @code{Fread,3,1234,6}
38224-> @code{F-1,9}
38225@end smallexample
38226
c8aa23ab 38227Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
38228host is called:
38229
38230@smallexample
38231<- @code{Fread,3,1234,6}
38232-> @code{F-1,4,C}
38233<- @code{T02}
38234@end smallexample
38235
c8aa23ab 38236Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
38237host is called:
38238
38239@smallexample
38240<- @code{Fread,3,1234,6}
38241-> @code{X1234,6:XXXXXX}
38242<- @code{T02}
38243@end smallexample
38244
cfa9d6d9
DJ
38245@node Library List Format
38246@section Library List Format
38247@cindex library list format, remote protocol
38248
38249On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
38250same process as your application to manage libraries. In this case,
38251@value{GDBN} can use the loader's symbol table and normal memory
38252operations to maintain a list of shared libraries. On other
38253platforms, the operating system manages loaded libraries.
38254@value{GDBN} can not retrieve the list of currently loaded libraries
38255through memory operations, so it uses the @samp{qXfer:libraries:read}
38256packet (@pxref{qXfer library list read}) instead. The remote stub
38257queries the target's operating system and reports which libraries
38258are loaded.
38259
38260The @samp{qXfer:libraries:read} packet returns an XML document which
38261lists loaded libraries and their offsets. Each library has an
1fddbabb
PA
38262associated name and one or more segment or section base addresses,
38263which report where the library was loaded in memory.
38264
38265For the common case of libraries that are fully linked binaries, the
38266library should have a list of segments. If the target supports
38267dynamic linking of a relocatable object file, its library XML element
38268should instead include a list of allocated sections. The segment or
38269section bases are start addresses, not relocation offsets; they do not
38270depend on the library's link-time base addresses.
cfa9d6d9 38271
9cceb671
DJ
38272@value{GDBN} must be linked with the Expat library to support XML
38273library lists. @xref{Expat}.
38274
cfa9d6d9
DJ
38275A simple memory map, with one loaded library relocated by a single
38276offset, looks like this:
38277
38278@smallexample
38279<library-list>
38280 <library name="/lib/libc.so.6">
38281 <segment address="0x10000000"/>
38282 </library>
38283</library-list>
38284@end smallexample
38285
1fddbabb
PA
38286Another simple memory map, with one loaded library with three
38287allocated sections (.text, .data, .bss), looks like this:
38288
38289@smallexample
38290<library-list>
38291 <library name="sharedlib.o">
38292 <section address="0x10000000"/>
38293 <section address="0x20000000"/>
38294 <section address="0x30000000"/>
38295 </library>
38296</library-list>
38297@end smallexample
38298
cfa9d6d9
DJ
38299The format of a library list is described by this DTD:
38300
38301@smallexample
38302<!-- library-list: Root element with versioning -->
38303<!ELEMENT library-list (library)*>
38304<!ATTLIST library-list version CDATA #FIXED "1.0">
1fddbabb 38305<!ELEMENT library (segment*, section*)>
cfa9d6d9
DJ
38306<!ATTLIST library name CDATA #REQUIRED>
38307<!ELEMENT segment EMPTY>
38308<!ATTLIST segment address CDATA #REQUIRED>
1fddbabb
PA
38309<!ELEMENT section EMPTY>
38310<!ATTLIST section address CDATA #REQUIRED>
cfa9d6d9
DJ
38311@end smallexample
38312
1fddbabb
PA
38313In addition, segments and section descriptors cannot be mixed within a
38314single library element, and you must supply at least one segment or
38315section for each library.
38316
2268b414
JK
38317@node Library List Format for SVR4 Targets
38318@section Library List Format for SVR4 Targets
38319@cindex library list format, remote protocol
38320
38321On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
38322(e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
38323shared libraries. Still a special library list provided by this packet is
38324more efficient for the @value{GDBN} remote protocol.
38325
38326The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
38327loaded libraries and their SVR4 linker parameters. For each library on SVR4
38328target, the following parameters are reported:
38329
38330@itemize @minus
38331@item
38332@code{name}, the absolute file name from the @code{l_name} field of
38333@code{struct link_map}.
38334@item
38335@code{lm} with address of @code{struct link_map} used for TLS
38336(Thread Local Storage) access.
38337@item
38338@code{l_addr}, the displacement as read from the field @code{l_addr} of
38339@code{struct link_map}. For prelinked libraries this is not an absolute
38340memory address. It is a displacement of absolute memory address against
38341address the file was prelinked to during the library load.
38342@item
38343@code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
38344@end itemize
38345
38346Additionally the single @code{main-lm} attribute specifies address of
38347@code{struct link_map} used for the main executable. This parameter is used
38348for TLS access and its presence is optional.
38349
38350@value{GDBN} must be linked with the Expat library to support XML
38351SVR4 library lists. @xref{Expat}.
38352
38353A simple memory map, with two loaded libraries (which do not use prelink),
38354looks like this:
38355
38356@smallexample
38357<library-list-svr4 version="1.0" main-lm="0xe4f8f8">
38358 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
38359 l_ld="0xe4eefc"/>
38360 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
38361 l_ld="0x152350"/>
38362</library-list-svr>
38363@end smallexample
38364
38365The format of an SVR4 library list is described by this DTD:
38366
38367@smallexample
38368<!-- library-list-svr4: Root element with versioning -->
38369<!ELEMENT library-list-svr4 (library)*>
38370<!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
38371<!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
38372<!ELEMENT library EMPTY>
38373<!ATTLIST library name CDATA #REQUIRED>
38374<!ATTLIST library lm CDATA #REQUIRED>
38375<!ATTLIST library l_addr CDATA #REQUIRED>
38376<!ATTLIST library l_ld CDATA #REQUIRED>
38377@end smallexample
38378
79a6e687
BW
38379@node Memory Map Format
38380@section Memory Map Format
68437a39
DJ
38381@cindex memory map format
38382
38383To be able to write into flash memory, @value{GDBN} needs to obtain a
38384memory map from the target. This section describes the format of the
38385memory map.
38386
38387The memory map is obtained using the @samp{qXfer:memory-map:read}
38388(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
38389lists memory regions.
38390
38391@value{GDBN} must be linked with the Expat library to support XML
38392memory maps. @xref{Expat}.
38393
38394The top-level structure of the document is shown below:
68437a39
DJ
38395
38396@smallexample
38397<?xml version="1.0"?>
38398<!DOCTYPE memory-map
38399 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
38400 "http://sourceware.org/gdb/gdb-memory-map.dtd">
38401<memory-map>
38402 region...
38403</memory-map>
38404@end smallexample
38405
38406Each region can be either:
38407
38408@itemize
38409
38410@item
38411A region of RAM starting at @var{addr} and extending for @var{length}
38412bytes from there:
38413
38414@smallexample
38415<memory type="ram" start="@var{addr}" length="@var{length}"/>
38416@end smallexample
38417
38418
38419@item
38420A region of read-only memory:
38421
38422@smallexample
38423<memory type="rom" start="@var{addr}" length="@var{length}"/>
38424@end smallexample
38425
38426
38427@item
38428A region of flash memory, with erasure blocks @var{blocksize}
38429bytes in length:
38430
38431@smallexample
38432<memory type="flash" start="@var{addr}" length="@var{length}">
38433 <property name="blocksize">@var{blocksize}</property>
38434</memory>
38435@end smallexample
38436
38437@end itemize
38438
38439Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
38440by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
38441packets to write to addresses in such ranges.
38442
38443The formal DTD for memory map format is given below:
38444
38445@smallexample
38446<!-- ................................................... -->
38447<!-- Memory Map XML DTD ................................ -->
38448<!-- File: memory-map.dtd .............................. -->
38449<!-- .................................... .............. -->
38450<!-- memory-map.dtd -->
38451<!-- memory-map: Root element with versioning -->
38452<!ELEMENT memory-map (memory | property)>
38453<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
38454<!ELEMENT memory (property)>
38455<!-- memory: Specifies a memory region,
38456 and its type, or device. -->
38457<!ATTLIST memory type CDATA #REQUIRED
38458 start CDATA #REQUIRED
38459 length CDATA #REQUIRED
38460 device CDATA #IMPLIED>
38461<!-- property: Generic attribute tag -->
38462<!ELEMENT property (#PCDATA | property)*>
38463<!ATTLIST property name CDATA #REQUIRED>
38464@end smallexample
38465
dc146f7c
VP
38466@node Thread List Format
38467@section Thread List Format
38468@cindex thread list format
38469
38470To efficiently update the list of threads and their attributes,
38471@value{GDBN} issues the @samp{qXfer:threads:read} packet
38472(@pxref{qXfer threads read}) and obtains the XML document with
38473the following structure:
38474
38475@smallexample
38476<?xml version="1.0"?>
38477<threads>
38478 <thread id="id" core="0">
38479 ... description ...
38480 </thread>
38481</threads>
38482@end smallexample
38483
38484Each @samp{thread} element must have the @samp{id} attribute that
38485identifies the thread (@pxref{thread-id syntax}). The
38486@samp{core} attribute, if present, specifies which processor core
38487the thread was last executing on. The content of the of @samp{thread}
38488element is interpreted as human-readable auxilliary information.
38489
b3b9301e
PA
38490@node Traceframe Info Format
38491@section Traceframe Info Format
38492@cindex traceframe info format
38493
38494To be able to know which objects in the inferior can be examined when
38495inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
38496memory ranges, registers and trace state variables that have been
38497collected in a traceframe.
38498
38499This list is obtained using the @samp{qXfer:traceframe-info:read}
38500(@pxref{qXfer traceframe info read}) packet and is an XML document.
38501
38502@value{GDBN} must be linked with the Expat library to support XML
38503traceframe info discovery. @xref{Expat}.
38504
38505The top-level structure of the document is shown below:
38506
38507@smallexample
38508<?xml version="1.0"?>
38509<!DOCTYPE traceframe-info
38510 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
38511 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
38512<traceframe-info>
38513 block...
38514</traceframe-info>
38515@end smallexample
38516
38517Each traceframe block can be either:
38518
38519@itemize
38520
38521@item
38522A region of collected memory starting at @var{addr} and extending for
38523@var{length} bytes from there:
38524
38525@smallexample
38526<memory start="@var{addr}" length="@var{length}"/>
38527@end smallexample
38528
28a93511
YQ
38529@item
38530A block indicating trace state variable numbered @var{number} has been
38531collected:
38532
38533@smallexample
38534<tvar id="@var{number}"/>
38535@end smallexample
38536
b3b9301e
PA
38537@end itemize
38538
38539The formal DTD for the traceframe info format is given below:
38540
38541@smallexample
28a93511 38542<!ELEMENT traceframe-info (memory | tvar)* >
b3b9301e
PA
38543<!ATTLIST traceframe-info version CDATA #FIXED "1.0">
38544
38545<!ELEMENT memory EMPTY>
38546<!ATTLIST memory start CDATA #REQUIRED
38547 length CDATA #REQUIRED>
28a93511
YQ
38548<!ELEMENT tvar>
38549<!ATTLIST tvar id CDATA #REQUIRED>
b3b9301e
PA
38550@end smallexample
38551
2ae8c8e7
MM
38552@node Branch Trace Format
38553@section Branch Trace Format
38554@cindex branch trace format
38555
38556In order to display the branch trace of an inferior thread,
38557@value{GDBN} needs to obtain the list of branches. This list is
38558represented as list of sequential code blocks that are connected via
38559branches. The code in each block has been executed sequentially.
38560
38561This list is obtained using the @samp{qXfer:btrace:read}
38562(@pxref{qXfer btrace read}) packet and is an XML document.
38563
38564@value{GDBN} must be linked with the Expat library to support XML
38565traceframe info discovery. @xref{Expat}.
38566
38567The top-level structure of the document is shown below:
38568
38569@smallexample
38570<?xml version="1.0"?>
38571<!DOCTYPE btrace
38572 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
38573 "http://sourceware.org/gdb/gdb-btrace.dtd">
38574<btrace>
38575 block...
38576</btrace>
38577@end smallexample
38578
38579@itemize
38580
38581@item
38582A block of sequentially executed instructions starting at @var{begin}
38583and ending at @var{end}:
38584
38585@smallexample
38586<block begin="@var{begin}" end="@var{end}"/>
38587@end smallexample
38588
38589@end itemize
38590
38591The formal DTD for the branch trace format is given below:
38592
38593@smallexample
38594<!ELEMENT btrace (block)* >
38595<!ATTLIST btrace version CDATA #FIXED "1.0">
38596
38597<!ELEMENT block EMPTY>
38598<!ATTLIST block begin CDATA #REQUIRED
38599 end CDATA #REQUIRED>
38600@end smallexample
38601
f418dd93
DJ
38602@include agentexpr.texi
38603
23181151
DJ
38604@node Target Descriptions
38605@appendix Target Descriptions
38606@cindex target descriptions
38607
23181151
DJ
38608One of the challenges of using @value{GDBN} to debug embedded systems
38609is that there are so many minor variants of each processor
38610architecture in use. It is common practice for vendors to start with
eb17f351 38611a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
23181151
DJ
38612and then make changes to adapt it to a particular market niche. Some
38613architectures have hundreds of variants, available from dozens of
38614vendors. This leads to a number of problems:
38615
38616@itemize @bullet
38617@item
38618With so many different customized processors, it is difficult for
38619the @value{GDBN} maintainers to keep up with the changes.
38620@item
38621Since individual variants may have short lifetimes or limited
38622audiences, it may not be worthwhile to carry information about every
38623variant in the @value{GDBN} source tree.
38624@item
38625When @value{GDBN} does support the architecture of the embedded system
38626at hand, the task of finding the correct architecture name to give the
38627@command{set architecture} command can be error-prone.
38628@end itemize
38629
38630To address these problems, the @value{GDBN} remote protocol allows a
38631target system to not only identify itself to @value{GDBN}, but to
38632actually describe its own features. This lets @value{GDBN} support
38633processor variants it has never seen before --- to the extent that the
38634descriptions are accurate, and that @value{GDBN} understands them.
38635
9cceb671
DJ
38636@value{GDBN} must be linked with the Expat library to support XML
38637target descriptions. @xref{Expat}.
123dc839 38638
23181151
DJ
38639@menu
38640* Retrieving Descriptions:: How descriptions are fetched from a target.
38641* Target Description Format:: The contents of a target description.
123dc839
DJ
38642* Predefined Target Types:: Standard types available for target
38643 descriptions.
38644* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
38645@end menu
38646
38647@node Retrieving Descriptions
38648@section Retrieving Descriptions
38649
38650Target descriptions can be read from the target automatically, or
38651specified by the user manually. The default behavior is to read the
38652description from the target. @value{GDBN} retrieves it via the remote
38653protocol using @samp{qXfer} requests (@pxref{General Query Packets,
38654qXfer}). The @var{annex} in the @samp{qXfer} packet will be
38655@samp{target.xml}. The contents of the @samp{target.xml} annex are an
38656XML document, of the form described in @ref{Target Description
38657Format}.
38658
38659Alternatively, you can specify a file to read for the target description.
38660If a file is set, the target will not be queried. The commands to
38661specify a file are:
38662
38663@table @code
38664@cindex set tdesc filename
38665@item set tdesc filename @var{path}
38666Read the target description from @var{path}.
38667
38668@cindex unset tdesc filename
38669@item unset tdesc filename
38670Do not read the XML target description from a file. @value{GDBN}
38671will use the description supplied by the current target.
38672
38673@cindex show tdesc filename
38674@item show tdesc filename
38675Show the filename to read for a target description, if any.
38676@end table
38677
38678
38679@node Target Description Format
38680@section Target Description Format
38681@cindex target descriptions, XML format
38682
38683A target description annex is an @uref{http://www.w3.org/XML/, XML}
38684document which complies with the Document Type Definition provided in
38685the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
38686means you can use generally available tools like @command{xmllint} to
38687check that your feature descriptions are well-formed and valid.
38688However, to help people unfamiliar with XML write descriptions for
38689their targets, we also describe the grammar here.
38690
123dc839
DJ
38691Target descriptions can identify the architecture of the remote target
38692and (for some architectures) provide information about custom register
08d16641
PA
38693sets. They can also identify the OS ABI of the remote target.
38694@value{GDBN} can use this information to autoconfigure for your
123dc839 38695target, or to warn you if you connect to an unsupported target.
23181151
DJ
38696
38697Here is a simple target description:
38698
123dc839 38699@smallexample
1780a0ed 38700<target version="1.0">
23181151
DJ
38701 <architecture>i386:x86-64</architecture>
38702</target>
123dc839 38703@end smallexample
23181151
DJ
38704
38705@noindent
38706This minimal description only says that the target uses
38707the x86-64 architecture.
38708
123dc839
DJ
38709A target description has the following overall form, with [ ] marking
38710optional elements and @dots{} marking repeatable elements. The elements
38711are explained further below.
23181151 38712
123dc839 38713@smallexample
23181151
DJ
38714<?xml version="1.0"?>
38715<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 38716<target version="1.0">
123dc839 38717 @r{[}@var{architecture}@r{]}
08d16641 38718 @r{[}@var{osabi}@r{]}
e35359c5 38719 @r{[}@var{compatible}@r{]}
123dc839 38720 @r{[}@var{feature}@dots{}@r{]}
23181151 38721</target>
123dc839 38722@end smallexample
23181151
DJ
38723
38724@noindent
38725The description is generally insensitive to whitespace and line
38726breaks, under the usual common-sense rules. The XML version
38727declaration and document type declaration can generally be omitted
38728(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
38729useful for XML validation tools. The @samp{version} attribute for
38730@samp{<target>} may also be omitted, but we recommend
38731including it; if future versions of @value{GDBN} use an incompatible
38732revision of @file{gdb-target.dtd}, they will detect and report
38733the version mismatch.
23181151 38734
108546a0
DJ
38735@subsection Inclusion
38736@cindex target descriptions, inclusion
38737@cindex XInclude
38738@ifnotinfo
38739@cindex <xi:include>
38740@end ifnotinfo
38741
38742It can sometimes be valuable to split a target description up into
38743several different annexes, either for organizational purposes, or to
38744share files between different possible target descriptions. You can
38745divide a description into multiple files by replacing any element of
38746the target description with an inclusion directive of the form:
38747
123dc839 38748@smallexample
108546a0 38749<xi:include href="@var{document}"/>
123dc839 38750@end smallexample
108546a0
DJ
38751
38752@noindent
38753When @value{GDBN} encounters an element of this form, it will retrieve
38754the named XML @var{document}, and replace the inclusion directive with
38755the contents of that document. If the current description was read
38756using @samp{qXfer}, then so will be the included document;
38757@var{document} will be interpreted as the name of an annex. If the
38758current description was read from a file, @value{GDBN} will look for
38759@var{document} as a file in the same directory where it found the
38760original description.
38761
123dc839
DJ
38762@subsection Architecture
38763@cindex <architecture>
38764
38765An @samp{<architecture>} element has this form:
38766
38767@smallexample
38768 <architecture>@var{arch}</architecture>
38769@end smallexample
38770
e35359c5
UW
38771@var{arch} is one of the architectures from the set accepted by
38772@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
123dc839 38773
08d16641
PA
38774@subsection OS ABI
38775@cindex @code{<osabi>}
38776
38777This optional field was introduced in @value{GDBN} version 7.0.
38778Previous versions of @value{GDBN} ignore it.
38779
38780An @samp{<osabi>} element has this form:
38781
38782@smallexample
38783 <osabi>@var{abi-name}</osabi>
38784@end smallexample
38785
38786@var{abi-name} is an OS ABI name from the same selection accepted by
38787@w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
38788
e35359c5
UW
38789@subsection Compatible Architecture
38790@cindex @code{<compatible>}
38791
38792This optional field was introduced in @value{GDBN} version 7.0.
38793Previous versions of @value{GDBN} ignore it.
38794
38795A @samp{<compatible>} element has this form:
38796
38797@smallexample
38798 <compatible>@var{arch}</compatible>
38799@end smallexample
38800
38801@var{arch} is one of the architectures from the set accepted by
38802@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
38803
38804A @samp{<compatible>} element is used to specify that the target
38805is able to run binaries in some other than the main target architecture
38806given by the @samp{<architecture>} element. For example, on the
38807Cell Broadband Engine, the main architecture is @code{powerpc:common}
38808or @code{powerpc:common64}, but the system is able to run binaries
38809in the @code{spu} architecture as well. The way to describe this
38810capability with @samp{<compatible>} is as follows:
38811
38812@smallexample
38813 <architecture>powerpc:common</architecture>
38814 <compatible>spu</compatible>
38815@end smallexample
38816
123dc839
DJ
38817@subsection Features
38818@cindex <feature>
38819
38820Each @samp{<feature>} describes some logical portion of the target
38821system. Features are currently used to describe available CPU
38822registers and the types of their contents. A @samp{<feature>} element
38823has this form:
38824
38825@smallexample
38826<feature name="@var{name}">
38827 @r{[}@var{type}@dots{}@r{]}
38828 @var{reg}@dots{}
38829</feature>
38830@end smallexample
38831
38832@noindent
38833Each feature's name should be unique within the description. The name
38834of a feature does not matter unless @value{GDBN} has some special
38835knowledge of the contents of that feature; if it does, the feature
38836should have its standard name. @xref{Standard Target Features}.
38837
38838@subsection Types
38839
38840Any register's value is a collection of bits which @value{GDBN} must
38841interpret. The default interpretation is a two's complement integer,
38842but other types can be requested by name in the register description.
38843Some predefined types are provided by @value{GDBN} (@pxref{Predefined
38844Target Types}), and the description can define additional composite types.
38845
38846Each type element must have an @samp{id} attribute, which gives
38847a unique (within the containing @samp{<feature>}) name to the type.
38848Types must be defined before they are used.
38849
38850@cindex <vector>
38851Some targets offer vector registers, which can be treated as arrays
38852of scalar elements. These types are written as @samp{<vector>} elements,
38853specifying the array element type, @var{type}, and the number of elements,
38854@var{count}:
38855
38856@smallexample
38857<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
38858@end smallexample
38859
38860@cindex <union>
38861If a register's value is usefully viewed in multiple ways, define it
38862with a union type containing the useful representations. The
38863@samp{<union>} element contains one or more @samp{<field>} elements,
38864each of which has a @var{name} and a @var{type}:
38865
38866@smallexample
38867<union id="@var{id}">
38868 <field name="@var{name}" type="@var{type}"/>
38869 @dots{}
38870</union>
38871@end smallexample
38872
f5dff777
DJ
38873@cindex <struct>
38874If a register's value is composed from several separate values, define
38875it with a structure type. There are two forms of the @samp{<struct>}
38876element; a @samp{<struct>} element must either contain only bitfields
38877or contain no bitfields. If the structure contains only bitfields,
38878its total size in bytes must be specified, each bitfield must have an
38879explicit start and end, and bitfields are automatically assigned an
38880integer type. The field's @var{start} should be less than or
38881equal to its @var{end}, and zero represents the least significant bit.
38882
38883@smallexample
38884<struct id="@var{id}" size="@var{size}">
38885 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
38886 @dots{}
38887</struct>
38888@end smallexample
38889
38890If the structure contains no bitfields, then each field has an
38891explicit type, and no implicit padding is added.
38892
38893@smallexample
38894<struct id="@var{id}">
38895 <field name="@var{name}" type="@var{type}"/>
38896 @dots{}
38897</struct>
38898@end smallexample
38899
38900@cindex <flags>
38901If a register's value is a series of single-bit flags, define it with
38902a flags type. The @samp{<flags>} element has an explicit @var{size}
38903and contains one or more @samp{<field>} elements. Each field has a
38904@var{name}, a @var{start}, and an @var{end}. Only single-bit flags
38905are supported.
38906
38907@smallexample
38908<flags id="@var{id}" size="@var{size}">
38909 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
38910 @dots{}
38911</flags>
38912@end smallexample
38913
123dc839
DJ
38914@subsection Registers
38915@cindex <reg>
38916
38917Each register is represented as an element with this form:
38918
38919@smallexample
38920<reg name="@var{name}"
38921 bitsize="@var{size}"
38922 @r{[}regnum="@var{num}"@r{]}
38923 @r{[}save-restore="@var{save-restore}"@r{]}
38924 @r{[}type="@var{type}"@r{]}
38925 @r{[}group="@var{group}"@r{]}/>
38926@end smallexample
38927
38928@noindent
38929The components are as follows:
38930
38931@table @var
38932
38933@item name
38934The register's name; it must be unique within the target description.
38935
38936@item bitsize
38937The register's size, in bits.
38938
38939@item regnum
38940The register's number. If omitted, a register's number is one greater
38941than that of the previous register (either in the current feature or in
177b42fe 38942a preceding feature); the first register in the target description
123dc839
DJ
38943defaults to zero. This register number is used to read or write
38944the register; e.g.@: it is used in the remote @code{p} and @code{P}
38945packets, and registers appear in the @code{g} and @code{G} packets
38946in order of increasing register number.
38947
38948@item save-restore
38949Whether the register should be preserved across inferior function
38950calls; this must be either @code{yes} or @code{no}. The default is
38951@code{yes}, which is appropriate for most registers except for
38952some system control registers; this is not related to the target's
38953ABI.
38954
38955@item type
38956The type of the register. @var{type} may be a predefined type, a type
38957defined in the current feature, or one of the special types @code{int}
38958and @code{float}. @code{int} is an integer type of the correct size
38959for @var{bitsize}, and @code{float} is a floating point type (in the
38960architecture's normal floating point format) of the correct size for
38961@var{bitsize}. The default is @code{int}.
38962
38963@item group
38964The register group to which this register belongs. @var{group} must
38965be either @code{general}, @code{float}, or @code{vector}. If no
38966@var{group} is specified, @value{GDBN} will not display the register
38967in @code{info registers}.
38968
38969@end table
38970
38971@node Predefined Target Types
38972@section Predefined Target Types
38973@cindex target descriptions, predefined types
38974
38975Type definitions in the self-description can build up composite types
38976from basic building blocks, but can not define fundamental types. Instead,
38977standard identifiers are provided by @value{GDBN} for the fundamental
38978types. The currently supported types are:
38979
38980@table @code
38981
38982@item int8
38983@itemx int16
38984@itemx int32
38985@itemx int64
7cc46491 38986@itemx int128
123dc839
DJ
38987Signed integer types holding the specified number of bits.
38988
38989@item uint8
38990@itemx uint16
38991@itemx uint32
38992@itemx uint64
7cc46491 38993@itemx uint128
123dc839
DJ
38994Unsigned integer types holding the specified number of bits.
38995
38996@item code_ptr
38997@itemx data_ptr
38998Pointers to unspecified code and data. The program counter and
38999any dedicated return address register may be marked as code
39000pointers; printing a code pointer converts it into a symbolic
39001address. The stack pointer and any dedicated address registers
39002may be marked as data pointers.
39003
6e3bbd1a
PB
39004@item ieee_single
39005Single precision IEEE floating point.
39006
39007@item ieee_double
39008Double precision IEEE floating point.
39009
123dc839
DJ
39010@item arm_fpa_ext
39011The 12-byte extended precision format used by ARM FPA registers.
39012
075b51b7
L
39013@item i387_ext
39014The 10-byte extended precision format used by x87 registers.
39015
39016@item i386_eflags
3901732bit @sc{eflags} register used by x86.
39018
39019@item i386_mxcsr
3902032bit @sc{mxcsr} register used by x86.
39021
123dc839
DJ
39022@end table
39023
39024@node Standard Target Features
39025@section Standard Target Features
39026@cindex target descriptions, standard features
39027
39028A target description must contain either no registers or all the
39029target's registers. If the description contains no registers, then
39030@value{GDBN} will assume a default register layout, selected based on
39031the architecture. If the description contains any registers, the
39032default layout will not be used; the standard registers must be
39033described in the target description, in such a way that @value{GDBN}
39034can recognize them.
39035
39036This is accomplished by giving specific names to feature elements
39037which contain standard registers. @value{GDBN} will look for features
39038with those names and verify that they contain the expected registers;
39039if any known feature is missing required registers, or if any required
39040feature is missing, @value{GDBN} will reject the target
39041description. You can add additional registers to any of the
39042standard features --- @value{GDBN} will display them just as if
39043they were added to an unrecognized feature.
39044
39045This section lists the known features and their expected contents.
39046Sample XML documents for these features are included in the
39047@value{GDBN} source tree, in the directory @file{gdb/features}.
39048
39049Names recognized by @value{GDBN} should include the name of the
39050company or organization which selected the name, and the overall
39051architecture to which the feature applies; so e.g.@: the feature
39052containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
39053
ff6f572f
DJ
39054The names of registers are not case sensitive for the purpose
39055of recognizing standard features, but @value{GDBN} will only display
39056registers using the capitalization used in the description.
39057
e9c17194 39058@menu
430ed3f0 39059* AArch64 Features::
e9c17194 39060* ARM Features::
3bb8d5c3 39061* i386 Features::
1e26b4f8 39062* MIPS Features::
e9c17194 39063* M68K Features::
a1217d97 39064* Nios II Features::
1e26b4f8 39065* PowerPC Features::
4ac33720 39066* S/390 and System z Features::
224bbe49 39067* TIC6x Features::
e9c17194
VP
39068@end menu
39069
39070
430ed3f0
MS
39071@node AArch64 Features
39072@subsection AArch64 Features
39073@cindex target descriptions, AArch64 features
39074
39075The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
39076targets. It should contain registers @samp{x0} through @samp{x30},
39077@samp{sp}, @samp{pc}, and @samp{cpsr}.
39078
39079The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
39080it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
39081and @samp{fpcr}.
39082
e9c17194 39083@node ARM Features
123dc839
DJ
39084@subsection ARM Features
39085@cindex target descriptions, ARM features
39086
9779414d
DJ
39087The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
39088ARM targets.
123dc839
DJ
39089It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
39090@samp{lr}, @samp{pc}, and @samp{cpsr}.
39091
9779414d
DJ
39092For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
39093feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
39094registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
39095and @samp{xpsr}.
39096
123dc839
DJ
39097The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
39098should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
39099
ff6f572f
DJ
39100The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
39101it should contain at least registers @samp{wR0} through @samp{wR15} and
39102@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
39103@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 39104
58d6951d
DJ
39105The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
39106should contain at least registers @samp{d0} through @samp{d15}. If
39107they are present, @samp{d16} through @samp{d31} should also be included.
39108@value{GDBN} will synthesize the single-precision registers from
39109halves of the double-precision registers.
39110
39111The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
39112need to contain registers; it instructs @value{GDBN} to display the
39113VFP double-precision registers as vectors and to synthesize the
39114quad-precision registers from pairs of double-precision registers.
39115If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
39116be present and include 32 double-precision registers.
39117
3bb8d5c3
L
39118@node i386 Features
39119@subsection i386 Features
39120@cindex target descriptions, i386 features
39121
39122The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
39123targets. It should describe the following registers:
39124
39125@itemize @minus
39126@item
39127@samp{eax} through @samp{edi} plus @samp{eip} for i386
39128@item
39129@samp{rax} through @samp{r15} plus @samp{rip} for amd64
39130@item
39131@samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
39132@samp{fs}, @samp{gs}
39133@item
39134@samp{st0} through @samp{st7}
39135@item
39136@samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
39137@samp{foseg}, @samp{fooff} and @samp{fop}
39138@end itemize
39139
39140The register sets may be different, depending on the target.
39141
3a13a53b 39142The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
3bb8d5c3
L
39143describe registers:
39144
39145@itemize @minus
39146@item
39147@samp{xmm0} through @samp{xmm7} for i386
39148@item
39149@samp{xmm0} through @samp{xmm15} for amd64
39150@item
39151@samp{mxcsr}
39152@end itemize
39153
3a13a53b
L
39154The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
39155@samp{org.gnu.gdb.i386.sse} feature. It should
f68eb612
L
39156describe the upper 128 bits of @sc{ymm} registers:
39157
39158@itemize @minus
39159@item
39160@samp{ymm0h} through @samp{ymm7h} for i386
39161@item
39162@samp{ymm0h} through @samp{ymm15h} for amd64
f68eb612
L
39163@end itemize
39164
ca8941bb
WT
39165The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel(R)
39166Memory Protection Extension (MPX). It should describe the following registers:
39167
39168@itemize @minus
39169@item
39170@samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
39171@item
39172@samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
39173@end itemize
39174
3bb8d5c3
L
39175The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
39176describe a single register, @samp{orig_eax}.
39177
01f9f808
MS
39178The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
39179@samp{org.gnu.gdb.i386.avx} feature. It should
39180describe additional @sc{xmm} registers:
39181
39182@itemize @minus
39183@item
39184@samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
39185@end itemize
39186
39187It should describe the upper 128 bits of additional @sc{ymm} registers:
39188
39189@itemize @minus
39190@item
39191@samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
39192@end itemize
39193
39194It should
39195describe the upper 256 bits of @sc{zmm} registers:
39196
39197@itemize @minus
39198@item
39199@samp{zmm0h} through @samp{zmm7h} for i386.
39200@item
39201@samp{zmm0h} through @samp{zmm15h} for amd64.
39202@end itemize
39203
39204It should
39205describe the additional @sc{zmm} registers:
39206
39207@itemize @minus
39208@item
39209@samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
39210@end itemize
39211
1e26b4f8 39212@node MIPS Features
eb17f351
EZ
39213@subsection @acronym{MIPS} Features
39214@cindex target descriptions, @acronym{MIPS} features
f8b73d13 39215
eb17f351 39216The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
f8b73d13
DJ
39217It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
39218@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
39219on the target.
39220
39221The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
39222contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
39223registers. They may be 32-bit or 64-bit depending on the target.
39224
39225The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
39226it may be optional in a future version of @value{GDBN}. It should
39227contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
39228@samp{fir}. They may be 32-bit or 64-bit depending on the target.
39229
1faeff08
MR
39230The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
39231contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
39232@samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
39233be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
39234
822b6570
DJ
39235The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
39236contain a single register, @samp{restart}, which is used by the
39237Linux kernel to control restartable syscalls.
39238
e9c17194
VP
39239@node M68K Features
39240@subsection M68K Features
39241@cindex target descriptions, M68K features
39242
39243@table @code
39244@item @samp{org.gnu.gdb.m68k.core}
39245@itemx @samp{org.gnu.gdb.coldfire.core}
39246@itemx @samp{org.gnu.gdb.fido.core}
39247One of those features must be always present.
249e1128 39248The feature that is present determines which flavor of m68k is
e9c17194
VP
39249used. The feature that is present should contain registers
39250@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
39251@samp{sp}, @samp{ps} and @samp{pc}.
39252
39253@item @samp{org.gnu.gdb.coldfire.fp}
39254This feature is optional. If present, it should contain registers
39255@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
39256@samp{fpiaddr}.
39257@end table
39258
a1217d97
SL
39259@node Nios II Features
39260@subsection Nios II Features
39261@cindex target descriptions, Nios II features
39262
39263The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
39264targets. It should contain the 32 core registers (@samp{zero},
39265@samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
39266@samp{pc}, and the 16 control registers (@samp{status} through
39267@samp{mpuacc}).
39268
1e26b4f8 39269@node PowerPC Features
7cc46491
DJ
39270@subsection PowerPC Features
39271@cindex target descriptions, PowerPC features
39272
39273The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
39274targets. It should contain registers @samp{r0} through @samp{r31},
39275@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
39276@samp{xer}. They may be 32-bit or 64-bit depending on the target.
39277
39278The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
39279contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
39280
39281The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
39282contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
39283and @samp{vrsave}.
39284
677c5bb1
LM
39285The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
39286contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN}
39287will combine these registers with the floating point registers
39288(@samp{f0} through @samp{f31}) and the altivec registers (@samp{vr0}
aeac0ff9 39289through @samp{vr31}) to present the 128-bit wide registers @samp{vs0}
677c5bb1
LM
39290through @samp{vs63}, the set of vector registers for POWER7.
39291
7cc46491
DJ
39292The @samp{org.gnu.gdb.power.spe} feature is optional. It should
39293contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
39294@samp{spefscr}. SPE targets should provide 32-bit registers in
39295@samp{org.gnu.gdb.power.core} and provide the upper halves in
39296@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
39297these to present registers @samp{ev0} through @samp{ev31} to the
39298user.
39299
4ac33720
UW
39300@node S/390 and System z Features
39301@subsection S/390 and System z Features
39302@cindex target descriptions, S/390 features
39303@cindex target descriptions, System z features
39304
39305The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
39306System z targets. It should contain the PSW and the 16 general
39307registers. In particular, System z targets should provide the 64-bit
39308registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
39309S/390 targets should provide the 32-bit versions of these registers.
39310A System z target that runs in 31-bit addressing mode should provide
3931132-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
39312register's upper halves @samp{r0h} through @samp{r15h}, and their
39313lower halves @samp{r0l} through @samp{r15l}.
39314
39315The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
39316contain the 64-bit registers @samp{f0} through @samp{f15}, and
39317@samp{fpc}.
39318
39319The @samp{org.gnu.gdb.s390.acr} feature is required. It should
39320contain the 32-bit registers @samp{acr0} through @samp{acr15}.
39321
39322The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
39323contain the register @samp{orig_r2}, which is 64-bit wide on System z
39324targets and 32-bit otherwise. In addition, the feature may contain
39325the @samp{last_break} register, whose width depends on the addressing
39326mode, as well as the @samp{system_call} register, which is always
3932732-bit wide.
39328
39329The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
39330contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
39331@samp{atia}, and @samp{tr0} through @samp{tr15}.
39332
224bbe49
YQ
39333@node TIC6x Features
39334@subsection TMS320C6x Features
39335@cindex target descriptions, TIC6x features
39336@cindex target descriptions, TMS320C6x features
39337The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
39338targets. It should contain registers @samp{A0} through @samp{A15},
39339registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
39340
39341The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
39342contain registers @samp{A16} through @samp{A31} and @samp{B16}
39343through @samp{B31}.
39344
39345The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
39346contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
39347
07e059b5
VP
39348@node Operating System Information
39349@appendix Operating System Information
39350@cindex operating system information
39351
39352@menu
39353* Process list::
39354@end menu
39355
39356Users of @value{GDBN} often wish to obtain information about the state of
39357the operating system running on the target---for example the list of
39358processes, or the list of open files. This section describes the
39359mechanism that makes it possible. This mechanism is similar to the
39360target features mechanism (@pxref{Target Descriptions}), but focuses
39361on a different aspect of target.
39362
39363Operating system information is retrived from the target via the
39364remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
39365read}). The object name in the request should be @samp{osdata}, and
39366the @var{annex} identifies the data to be fetched.
39367
39368@node Process list
39369@appendixsection Process list
39370@cindex operating system information, process list
39371
39372When requesting the process list, the @var{annex} field in the
39373@samp{qXfer} request should be @samp{processes}. The returned data is
39374an XML document. The formal syntax of this document is defined in
39375@file{gdb/features/osdata.dtd}.
39376
39377An example document is:
39378
39379@smallexample
39380<?xml version="1.0"?>
39381<!DOCTYPE target SYSTEM "osdata.dtd">
39382<osdata type="processes">
39383 <item>
39384 <column name="pid">1</column>
39385 <column name="user">root</column>
39386 <column name="command">/sbin/init</column>
dc146f7c 39387 <column name="cores">1,2,3</column>
07e059b5
VP
39388 </item>
39389</osdata>
39390@end smallexample
39391
39392Each item should include a column whose name is @samp{pid}. The value
39393of that column should identify the process on the target. The
39394@samp{user} and @samp{command} columns are optional, and will be
dc146f7c
VP
39395displayed by @value{GDBN}. The @samp{cores} column, if present,
39396should contain a comma-separated list of cores that this process
39397is running on. Target may provide additional columns,
07e059b5
VP
39398which @value{GDBN} currently ignores.
39399
05c8c3f5
TT
39400@node Trace File Format
39401@appendix Trace File Format
39402@cindex trace file format
39403
39404The trace file comes in three parts: a header, a textual description
39405section, and a trace frame section with binary data.
39406
39407The header has the form @code{\x7fTRACE0\n}. The first byte is
39408@code{0x7f} so as to indicate that the file contains binary data,
39409while the @code{0} is a version number that may have different values
39410in the future.
39411
39412The description section consists of multiple lines of @sc{ascii} text
39413separated by newline characters (@code{0xa}). The lines may include a
39414variety of optional descriptive or context-setting information, such
39415as tracepoint definitions or register set size. @value{GDBN} will
39416ignore any line that it does not recognize. An empty line marks the end
39417of this section.
39418
39419@c FIXME add some specific types of data
39420
39421The trace frame section consists of a number of consecutive frames.
39422Each frame begins with a two-byte tracepoint number, followed by a
39423four-byte size giving the amount of data in the frame. The data in
39424the frame consists of a number of blocks, each introduced by a
39425character indicating its type (at least register, memory, and trace
39426state variable). The data in this section is raw binary, not a
39427hexadecimal or other encoding; its endianness matches the target's
39428endianness.
39429
39430@c FIXME bi-arch may require endianness/arch info in description section
39431
39432@table @code
39433@item R @var{bytes}
39434Register block. The number and ordering of bytes matches that of a
39435@code{g} packet in the remote protocol. Note that these are the
39436actual bytes, in target order and @value{GDBN} register order, not a
39437hexadecimal encoding.
39438
39439@item M @var{address} @var{length} @var{bytes}...
39440Memory block. This is a contiguous block of memory, at the 8-byte
39441address @var{address}, with a 2-byte length @var{length}, followed by
39442@var{length} bytes.
39443
39444@item V @var{number} @var{value}
39445Trace state variable block. This records the 8-byte signed value
39446@var{value} of trace state variable numbered @var{number}.
39447
39448@end table
39449
39450Future enhancements of the trace file format may include additional types
39451of blocks.
39452
90476074
TT
39453@node Index Section Format
39454@appendix @code{.gdb_index} section format
39455@cindex .gdb_index section format
39456@cindex index section format
39457
39458This section documents the index section that is created by @code{save
39459gdb-index} (@pxref{Index Files}). The index section is
39460DWARF-specific; some knowledge of DWARF is assumed in this
39461description.
39462
39463The mapped index file format is designed to be directly
39464@code{mmap}able on any architecture. In most cases, a datum is
39465represented using a little-endian 32-bit integer value, called an
39466@code{offset_type}. Big endian machines must byte-swap the values
39467before using them. Exceptions to this rule are noted. The data is
39468laid out such that alignment is always respected.
39469
39470A mapped index consists of several areas, laid out in order.
39471
39472@enumerate
39473@item
39474The file header. This is a sequence of values, of @code{offset_type}
39475unless otherwise noted:
39476
39477@enumerate
39478@item
796a7ff8 39479The version number, currently 8. Versions 1, 2 and 3 are obsolete.
481860b3 39480Version 4 uses a different hashing function from versions 5 and 6.
b6ba681c
TT
39481Version 6 includes symbols for inlined functions, whereas versions 4
39482and 5 do not. Version 7 adds attributes to the CU indices in the
796a7ff8
DE
39483symbol table. Version 8 specifies that symbols from DWARF type units
39484(@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
39485compilation unit (@samp{DW_TAG_comp_unit}) using the type.
39486
39487@value{GDBN} will only read version 4, 5, or 6 indices
e615022a 39488by specifying @code{set use-deprecated-index-sections on}.
796a7ff8
DE
39489GDB has a workaround for potentially broken version 7 indices so it is
39490currently not flagged as deprecated.
90476074
TT
39491
39492@item
39493The offset, from the start of the file, of the CU list.
39494
39495@item
39496The offset, from the start of the file, of the types CU list. Note
39497that this area can be empty, in which case this offset will be equal
39498to the next offset.
39499
39500@item
39501The offset, from the start of the file, of the address area.
39502
39503@item
39504The offset, from the start of the file, of the symbol table.
39505
39506@item
39507The offset, from the start of the file, of the constant pool.
39508@end enumerate
39509
39510@item
39511The CU list. This is a sequence of pairs of 64-bit little-endian
39512values, sorted by the CU offset. The first element in each pair is
39513the offset of a CU in the @code{.debug_info} section. The second
39514element in each pair is the length of that CU. References to a CU
39515elsewhere in the map are done using a CU index, which is just the
395160-based index into this table. Note that if there are type CUs, then
39517conceptually CUs and type CUs form a single list for the purposes of
39518CU indices.
39519
39520@item
39521The types CU list. This is a sequence of triplets of 64-bit
39522little-endian values. In a triplet, the first value is the CU offset,
39523the second value is the type offset in the CU, and the third value is
39524the type signature. The types CU list is not sorted.
39525
39526@item
39527The address area. The address area consists of a sequence of address
39528entries. Each address entry has three elements:
39529
39530@enumerate
39531@item
39532The low address. This is a 64-bit little-endian value.
39533
39534@item
39535The high address. This is a 64-bit little-endian value. Like
39536@code{DW_AT_high_pc}, the value is one byte beyond the end.
39537
39538@item
39539The CU index. This is an @code{offset_type} value.
39540@end enumerate
39541
39542@item
39543The symbol table. This is an open-addressed hash table. The size of
39544the hash table is always a power of 2.
39545
39546Each slot in the hash table consists of a pair of @code{offset_type}
39547values. The first value is the offset of the symbol's name in the
39548constant pool. The second value is the offset of the CU vector in the
39549constant pool.
39550
39551If both values are 0, then this slot in the hash table is empty. This
39552is ok because while 0 is a valid constant pool index, it cannot be a
39553valid index for both a string and a CU vector.
39554
39555The hash value for a table entry is computed by applying an
39556iterative hash function to the symbol's name. Starting with an
39557initial value of @code{r = 0}, each (unsigned) character @samp{c} in
559a7a62
JK
39558the string is incorporated into the hash using the formula depending on the
39559index version:
39560
39561@table @asis
39562@item Version 4
39563The formula is @code{r = r * 67 + c - 113}.
39564
156942c7 39565@item Versions 5 to 7
559a7a62
JK
39566The formula is @code{r = r * 67 + tolower (c) - 113}.
39567@end table
39568
39569The terminating @samp{\0} is not incorporated into the hash.
90476074
TT
39570
39571The step size used in the hash table is computed via
39572@code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
39573value, and @samp{size} is the size of the hash table. The step size
39574is used to find the next candidate slot when handling a hash
39575collision.
39576
39577The names of C@t{++} symbols in the hash table are canonicalized. We
39578don't currently have a simple description of the canonicalization
39579algorithm; if you intend to create new index sections, you must read
39580the code.
39581
39582@item
39583The constant pool. This is simply a bunch of bytes. It is organized
39584so that alignment is correct: CU vectors are stored first, followed by
39585strings.
39586
39587A CU vector in the constant pool is a sequence of @code{offset_type}
39588values. The first value is the number of CU indices in the vector.
156942c7
DE
39589Each subsequent value is the index and symbol attributes of a CU in
39590the CU list. This element in the hash table is used to indicate which
39591CUs define the symbol and how the symbol is used.
39592See below for the format of each CU index+attributes entry.
90476074
TT
39593
39594A string in the constant pool is zero-terminated.
39595@end enumerate
39596
156942c7
DE
39597Attributes were added to CU index values in @code{.gdb_index} version 7.
39598If a symbol has multiple uses within a CU then there is one
39599CU index+attributes value for each use.
39600
39601The format of each CU index+attributes entry is as follows
39602(bit 0 = LSB):
39603
39604@table @asis
39605
39606@item Bits 0-23
39607This is the index of the CU in the CU list.
39608@item Bits 24-27
39609These bits are reserved for future purposes and must be zero.
39610@item Bits 28-30
39611The kind of the symbol in the CU.
39612
39613@table @asis
39614@item 0
39615This value is reserved and should not be used.
39616By reserving zero the full @code{offset_type} value is backwards compatible
39617with previous versions of the index.
39618@item 1
39619The symbol is a type.
39620@item 2
39621The symbol is a variable or an enum value.
39622@item 3
39623The symbol is a function.
39624@item 4
39625Any other kind of symbol.
39626@item 5,6,7
39627These values are reserved.
39628@end table
39629
39630@item Bit 31
39631This bit is zero if the value is global and one if it is static.
39632
39633The determination of whether a symbol is global or static is complicated.
39634The authorative reference is the file @file{dwarf2read.c} in
39635@value{GDBN} sources.
39636
39637@end table
39638
39639This pseudo-code describes the computation of a symbol's kind and
39640global/static attributes in the index.
39641
39642@smallexample
39643is_external = get_attribute (die, DW_AT_external);
39644language = get_attribute (cu_die, DW_AT_language);
39645switch (die->tag)
39646 @{
39647 case DW_TAG_typedef:
39648 case DW_TAG_base_type:
39649 case DW_TAG_subrange_type:
39650 kind = TYPE;
39651 is_static = 1;
39652 break;
39653 case DW_TAG_enumerator:
39654 kind = VARIABLE;
39655 is_static = (language != CPLUS && language != JAVA);
39656 break;
39657 case DW_TAG_subprogram:
39658 kind = FUNCTION;
39659 is_static = ! (is_external || language == ADA);
39660 break;
39661 case DW_TAG_constant:
39662 kind = VARIABLE;
39663 is_static = ! is_external;
39664 break;
39665 case DW_TAG_variable:
39666 kind = VARIABLE;
39667 is_static = ! is_external;
39668 break;
39669 case DW_TAG_namespace:
39670 kind = TYPE;
39671 is_static = 0;
39672 break;
39673 case DW_TAG_class_type:
39674 case DW_TAG_interface_type:
39675 case DW_TAG_structure_type:
39676 case DW_TAG_union_type:
39677 case DW_TAG_enumeration_type:
39678 kind = TYPE;
39679 is_static = (language != CPLUS && language != JAVA);
39680 break;
39681 default:
39682 assert (0);
39683 @}
39684@end smallexample
39685
43662968
JK
39686@node Man Pages
39687@appendix Manual pages
39688@cindex Man pages
39689
39690@menu
39691* gdb man:: The GNU Debugger man page
39692* gdbserver man:: Remote Server for the GNU Debugger man page
b292c783 39693* gcore man:: Generate a core file of a running program
43662968
JK
39694* gdbinit man:: gdbinit scripts
39695@end menu
39696
39697@node gdb man
39698@heading gdb man
39699
39700@c man title gdb The GNU Debugger
39701
39702@c man begin SYNOPSIS gdb
39703gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
39704[@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
39705[@option{-b}@w{ }@var{bps}]
39706 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
39707[@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
906ccdf0
JK
39708[@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
39709 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
39710[@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
43662968
JK
39711@c man end
39712
39713@c man begin DESCRIPTION gdb
39714The purpose of a debugger such as @value{GDBN} is to allow you to see what is
39715going on ``inside'' another program while it executes -- or what another
39716program was doing at the moment it crashed.
39717
39718@value{GDBN} can do four main kinds of things (plus other things in support of
39719these) to help you catch bugs in the act:
39720
39721@itemize @bullet
39722@item
39723Start your program, specifying anything that might affect its behavior.
39724
39725@item
39726Make your program stop on specified conditions.
39727
39728@item
39729Examine what has happened, when your program has stopped.
39730
39731@item
39732Change things in your program, so you can experiment with correcting the
39733effects of one bug and go on to learn about another.
39734@end itemize
39735
906ccdf0
JK
39736You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
39737Modula-2.
43662968
JK
39738
39739@value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
39740commands from the terminal until you tell it to exit with the @value{GDBN}
39741command @code{quit}. You can get online help from @value{GDBN} itself
39742by using the command @code{help}.
39743
39744You can run @code{gdb} with no arguments or options; but the most
39745usual way to start @value{GDBN} is with one argument or two, specifying an
39746executable program as the argument:
39747
39748@smallexample
39749gdb program
39750@end smallexample
39751
39752You can also start with both an executable program and a core file specified:
39753
39754@smallexample
39755gdb program core
39756@end smallexample
39757
39758You can, instead, specify a process ID as a second argument, if you want
39759to debug a running process:
39760
39761@smallexample
39762gdb program 1234
906ccdf0 39763gdb -p 1234
43662968
JK
39764@end smallexample
39765
39766@noindent
39767would attach @value{GDBN} to process @code{1234} (unless you also have a file
39768named @file{1234}; @value{GDBN} does check for a core file first).
906ccdf0 39769With option @option{-p} you can omit the @var{program} filename.
43662968
JK
39770
39771Here are some of the most frequently needed @value{GDBN} commands:
39772
39773@c pod2man highlights the right hand side of the @item lines.
39774@table @env
39775@item break [@var{file}:]@var{functiop}
39776Set a breakpoint at @var{function} (in @var{file}).
39777
39778@item run [@var{arglist}]
39779Start your program (with @var{arglist}, if specified).
39780
39781@item bt
39782Backtrace: display the program stack.
39783
39784@item print @var{expr}
39785Display the value of an expression.
39786
39787@item c
39788Continue running your program (after stopping, e.g. at a breakpoint).
39789
39790@item next
39791Execute next program line (after stopping); step @emph{over} any
39792function calls in the line.
39793
39794@item edit [@var{file}:]@var{function}
39795look at the program line where it is presently stopped.
39796
39797@item list [@var{file}:]@var{function}
39798type the text of the program in the vicinity of where it is presently stopped.
39799
39800@item step
39801Execute next program line (after stopping); step @emph{into} any
39802function calls in the line.
39803
39804@item help [@var{name}]
39805Show information about @value{GDBN} command @var{name}, or general information
39806about using @value{GDBN}.
39807
39808@item quit
39809Exit from @value{GDBN}.
39810@end table
39811
39812@ifset man
39813For full details on @value{GDBN},
39814see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
39815by Richard M. Stallman and Roland H. Pesch. The same text is available online
39816as the @code{gdb} entry in the @code{info} program.
39817@end ifset
39818@c man end
39819
39820@c man begin OPTIONS gdb
39821Any arguments other than options specify an executable
39822file and core file (or process ID); that is, the first argument
39823encountered with no
39824associated option flag is equivalent to a @option{-se} option, and the second,
39825if any, is equivalent to a @option{-c} option if it's the name of a file.
39826Many options have
39827both long and short forms; both are shown here. The long forms are also
39828recognized if you truncate them, so long as enough of the option is
39829present to be unambiguous. (If you prefer, you can flag option
39830arguments with @option{+} rather than @option{-}, though we illustrate the
39831more usual convention.)
39832
39833All the options and command line arguments you give are processed
39834in sequential order. The order makes a difference when the @option{-x}
39835option is used.
39836
39837@table @env
39838@item -help
39839@itemx -h
39840List all options, with brief explanations.
39841
39842@item -symbols=@var{file}
39843@itemx -s @var{file}
39844Read symbol table from file @var{file}.
39845
39846@item -write
39847Enable writing into executable and core files.
39848
39849@item -exec=@var{file}
39850@itemx -e @var{file}
39851Use file @var{file} as the executable file to execute when
39852appropriate, and for examining pure data in conjunction with a core
39853dump.
39854
39855@item -se=@var{file}
39856Read symbol table from file @var{file} and use it as the executable
39857file.
39858
39859@item -core=@var{file}
39860@itemx -c @var{file}
39861Use file @var{file} as a core dump to examine.
39862
39863@item -command=@var{file}
39864@itemx -x @var{file}
39865Execute @value{GDBN} commands from file @var{file}.
39866
39867@item -ex @var{command}
39868Execute given @value{GDBN} @var{command}.
39869
39870@item -directory=@var{directory}
39871@itemx -d @var{directory}
39872Add @var{directory} to the path to search for source files.
39873
39874@item -nh
39875Do not execute commands from @file{~/.gdbinit}.
39876
39877@item -nx
39878@itemx -n
39879Do not execute commands from any @file{.gdbinit} initialization files.
39880
39881@item -quiet
39882@itemx -q
39883``Quiet''. Do not print the introductory and copyright messages. These
39884messages are also suppressed in batch mode.
39885
39886@item -batch
39887Run in batch mode. Exit with status @code{0} after processing all the command
39888files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
39889Exit with nonzero status if an error occurs in executing the @value{GDBN}
39890commands in the command files.
39891
39892Batch mode may be useful for running @value{GDBN} as a filter, for example to
39893download and run a program on another computer; in order to make this
39894more useful, the message
39895
39896@smallexample
39897Program exited normally.
39898@end smallexample
39899
39900@noindent
39901(which is ordinarily issued whenever a program running under @value{GDBN} control
39902terminates) is not issued when running in batch mode.
39903
39904@item -cd=@var{directory}
39905Run @value{GDBN} using @var{directory} as its working directory,
39906instead of the current directory.
39907
39908@item -fullname
39909@itemx -f
39910Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
39911@value{GDBN} to output the full file name and line number in a standard,
39912recognizable fashion each time a stack frame is displayed (which
39913includes each time the program stops). This recognizable format looks
39914like two @samp{\032} characters, followed by the file name, line number
39915and character position separated by colons, and a newline. The
39916Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
39917characters as a signal to display the source code for the frame.
39918
39919@item -b @var{bps}
39920Set the line speed (baud rate or bits per second) of any serial
39921interface used by @value{GDBN} for remote debugging.
39922
39923@item -tty=@var{device}
39924Run using @var{device} for your program's standard input and output.
39925@end table
39926@c man end
39927
39928@c man begin SEEALSO gdb
39929@ifset man
39930The full documentation for @value{GDBN} is maintained as a Texinfo manual.
39931If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
39932documentation are properly installed at your site, the command
39933
39934@smallexample
39935info gdb
39936@end smallexample
39937
39938@noindent
39939should give you access to the complete manual.
39940
39941@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
39942Richard M. Stallman and Roland H. Pesch, July 1991.
39943@end ifset
39944@c man end
39945
39946@node gdbserver man
39947@heading gdbserver man
39948
39949@c man title gdbserver Remote Server for the GNU Debugger
39950@format
39951@c man begin SYNOPSIS gdbserver
5b8b6385 39952gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
43662968 39953
5b8b6385
JK
39954gdbserver --attach @var{comm} @var{pid}
39955
39956gdbserver --multi @var{comm}
43662968
JK
39957@c man end
39958@end format
39959
39960@c man begin DESCRIPTION gdbserver
39961@command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
39962than the one which is running the program being debugged.
39963
39964@ifclear man
39965@subheading Usage (server (target) side)
39966@end ifclear
39967@ifset man
39968Usage (server (target) side):
39969@end ifset
39970
39971First, you need to have a copy of the program you want to debug put onto
39972the target system. The program can be stripped to save space if needed, as
39973@command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
39974the @value{GDBN} running on the host system.
39975
39976To use the server, you log on to the target system, and run the @command{gdbserver}
39977program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
39978your program, and (c) its arguments. The general syntax is:
39979
39980@smallexample
39981target> gdbserver @var{comm} @var{program} [@var{args} ...]
39982@end smallexample
39983
39984For example, using a serial port, you might say:
39985
39986@smallexample
39987@ifset man
39988@c @file would wrap it as F</dev/com1>.
39989target> gdbserver /dev/com1 emacs foo.txt
39990@end ifset
39991@ifclear man
39992target> gdbserver @file{/dev/com1} emacs foo.txt
39993@end ifclear
39994@end smallexample
39995
39996This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
39997to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
39998waits patiently for the host @value{GDBN} to communicate with it.
39999
40000To use a TCP connection, you could say:
40001
40002@smallexample
40003target> gdbserver host:2345 emacs foo.txt
40004@end smallexample
40005
40006This says pretty much the same thing as the last example, except that we are
40007going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
40008that we are expecting to see a TCP connection from @code{host} to local TCP port
400092345. (Currently, the @code{host} part is ignored.) You can choose any number you
40010want for the port number as long as it does not conflict with any existing TCP
40011ports on the target system. This same port number must be used in the host
40012@value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
40013you chose a port number that conflicts with another service, @command{gdbserver} will
40014print an error message and exit.
40015
5b8b6385 40016@command{gdbserver} can also attach to running programs.
43662968
JK
40017This is accomplished via the @option{--attach} argument. The syntax is:
40018
40019@smallexample
5b8b6385 40020target> gdbserver --attach @var{comm} @var{pid}
43662968
JK
40021@end smallexample
40022
40023@var{pid} is the process ID of a currently running process. It isn't
40024necessary to point @command{gdbserver} at a binary for the running process.
40025
5b8b6385
JK
40026To start @code{gdbserver} without supplying an initial command to run
40027or process ID to attach, use the @option{--multi} command line option.
40028In such case you should connect using @kbd{target extended-remote} to start
40029the program you want to debug.
40030
40031@smallexample
40032target> gdbserver --multi @var{comm}
40033@end smallexample
40034
43662968
JK
40035@ifclear man
40036@subheading Usage (host side)
40037@end ifclear
40038@ifset man
40039Usage (host side):
40040@end ifset
40041
40042You need an unstripped copy of the target program on your host system, since
40043@value{GDBN} needs to examine it's symbol tables and such. Start up @value{GDBN} as you normally
40044would, with the target program as the first argument. (You may need to use the
40045@option{--baud} option if the serial line is running at anything except 9600 baud.)
40046That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
5b8b6385
JK
40047new command you need to know about is @code{target remote}
40048(or @code{target extended-remote}). Its argument is either
43662968
JK
40049a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
40050descriptor. For example:
40051
40052@smallexample
40053@ifset man
40054@c @file would wrap it as F</dev/ttyb>.
40055(gdb) target remote /dev/ttyb
40056@end ifset
40057@ifclear man
40058(gdb) target remote @file{/dev/ttyb}
40059@end ifclear
40060@end smallexample
40061
40062@noindent
40063communicates with the server via serial line @file{/dev/ttyb}, and:
40064
40065@smallexample
40066(gdb) target remote the-target:2345
40067@end smallexample
40068
40069@noindent
40070communicates via a TCP connection to port 2345 on host `the-target', where
40071you previously started up @command{gdbserver} with the same port number. Note that for
40072TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
40073command, otherwise you may get an error that looks something like
40074`Connection refused'.
5b8b6385
JK
40075
40076@command{gdbserver} can also debug multiple inferiors at once,
40077described in
40078@ifset man
40079the @value{GDBN} manual in node @code{Inferiors and Programs}
40080-- shell command @code{info -f gdb -n 'Inferiors and Programs'}.
40081@end ifset
40082@ifclear man
40083@ref{Inferiors and Programs}.
40084@end ifclear
40085In such case use the @code{extended-remote} @value{GDBN} command variant:
40086
40087@smallexample
40088(gdb) target extended-remote the-target:2345
40089@end smallexample
40090
40091The @command{gdbserver} option @option{--multi} may or may not be used in such
40092case.
43662968
JK
40093@c man end
40094
40095@c man begin OPTIONS gdbserver
5b8b6385
JK
40096There are three different modes for invoking @command{gdbserver}:
40097
40098@itemize @bullet
40099
40100@item
40101Debug a specific program specified by its program name:
40102
40103@smallexample
40104gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
40105@end smallexample
40106
40107The @var{comm} parameter specifies how should the server communicate
40108with @value{GDBN}; it is either a device name (to use a serial line),
40109a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
40110stdin/stdout of @code{gdbserver}. Specify the name of the program to
40111debug in @var{prog}. Any remaining arguments will be passed to the
40112program verbatim. When the program exits, @value{GDBN} will close the
40113connection, and @code{gdbserver} will exit.
40114
40115@item
40116Debug a specific program by specifying the process ID of a running
40117program:
40118
40119@smallexample
40120gdbserver --attach @var{comm} @var{pid}
40121@end smallexample
40122
40123The @var{comm} parameter is as described above. Supply the process ID
40124of a running program in @var{pid}; @value{GDBN} will do everything
40125else. Like with the previous mode, when the process @var{pid} exits,
40126@value{GDBN} will close the connection, and @code{gdbserver} will exit.
40127
40128@item
40129Multi-process mode -- debug more than one program/process:
40130
40131@smallexample
40132gdbserver --multi @var{comm}
40133@end smallexample
40134
40135In this mode, @value{GDBN} can instruct @command{gdbserver} which
40136command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
40137close the connection when a process being debugged exits, so you can
40138debug several processes in the same session.
40139@end itemize
40140
40141In each of the modes you may specify these options:
40142
40143@table @env
40144
40145@item --help
40146List all options, with brief explanations.
40147
40148@item --version
40149This option causes @command{gdbserver} to print its version number and exit.
40150
40151@item --attach
40152@command{gdbserver} will attach to a running program. The syntax is:
40153
40154@smallexample
40155target> gdbserver --attach @var{comm} @var{pid}
40156@end smallexample
40157
40158@var{pid} is the process ID of a currently running process. It isn't
40159necessary to point @command{gdbserver} at a binary for the running process.
40160
40161@item --multi
40162To start @code{gdbserver} without supplying an initial command to run
40163or process ID to attach, use this command line option.
40164Then you can connect using @kbd{target extended-remote} and start
40165the program you want to debug. The syntax is:
40166
40167@smallexample
40168target> gdbserver --multi @var{comm}
40169@end smallexample
40170
40171@item --debug
40172Instruct @code{gdbserver} to display extra status information about the debugging
40173process.
40174This option is intended for @code{gdbserver} development and for bug reports to
40175the developers.
40176
40177@item --remote-debug
40178Instruct @code{gdbserver} to display remote protocol debug output.
40179This option is intended for @code{gdbserver} development and for bug reports to
40180the developers.
40181
87ce2a04
DE
40182@item --debug-format=option1@r{[},option2,...@r{]}
40183Instruct @code{gdbserver} to include extra information in each line
40184of debugging output.
40185@xref{Other Command-Line Arguments for gdbserver}.
40186
5b8b6385
JK
40187@item --wrapper
40188Specify a wrapper to launch programs
40189for debugging. The option should be followed by the name of the
40190wrapper, then any command-line arguments to pass to the wrapper, then
40191@kbd{--} indicating the end of the wrapper arguments.
40192
40193@item --once
40194By default, @command{gdbserver} keeps the listening TCP port open, so that
40195additional connections are possible. However, if you start @code{gdbserver}
40196with the @option{--once} option, it will stop listening for any further
40197connection attempts after connecting to the first @value{GDBN} session.
40198
40199@c --disable-packet is not documented for users.
40200
40201@c --disable-randomization and --no-disable-randomization are superseded by
40202@c QDisableRandomization.
40203
40204@end table
43662968
JK
40205@c man end
40206
40207@c man begin SEEALSO gdbserver
40208@ifset man
40209The full documentation for @value{GDBN} is maintained as a Texinfo manual.
40210If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
40211documentation are properly installed at your site, the command
40212
40213@smallexample
40214info gdb
40215@end smallexample
40216
40217should give you access to the complete manual.
40218
40219@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
40220Richard M. Stallman and Roland H. Pesch, July 1991.
40221@end ifset
40222@c man end
40223
b292c783
JK
40224@node gcore man
40225@heading gcore
40226
40227@c man title gcore Generate a core file of a running program
40228
40229@format
40230@c man begin SYNOPSIS gcore
40231gcore [-o @var{filename}] @var{pid}
40232@c man end
40233@end format
40234
40235@c man begin DESCRIPTION gcore
40236Generate a core dump of a running program with process ID @var{pid}.
40237Produced file is equivalent to a kernel produced core file as if the process
40238crashed (and if @kbd{ulimit -c} were used to set up an appropriate core dump
40239limit). Unlike after a crash, after @command{gcore} the program remains
40240running without any change.
40241@c man end
40242
40243@c man begin OPTIONS gcore
40244@table @env
40245@item -o @var{filename}
40246The optional argument
40247@var{filename} specifies the file name where to put the core dump.
40248If not specified, the file name defaults to @file{core.@var{pid}},
40249where @var{pid} is the running program process ID.
40250@end table
40251@c man end
40252
40253@c man begin SEEALSO gcore
40254@ifset man
40255The full documentation for @value{GDBN} is maintained as a Texinfo manual.
40256If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
40257documentation are properly installed at your site, the command
40258
40259@smallexample
40260info gdb
40261@end smallexample
40262
40263@noindent
40264should give you access to the complete manual.
40265
40266@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
40267Richard M. Stallman and Roland H. Pesch, July 1991.
40268@end ifset
40269@c man end
40270
43662968
JK
40271@node gdbinit man
40272@heading gdbinit
40273
40274@c man title gdbinit GDB initialization scripts
40275
40276@format
40277@c man begin SYNOPSIS gdbinit
40278@ifset SYSTEM_GDBINIT
40279@value{SYSTEM_GDBINIT}
40280@end ifset
40281
40282~/.gdbinit
40283
40284./.gdbinit
40285@c man end
40286@end format
40287
40288@c man begin DESCRIPTION gdbinit
40289These files contain @value{GDBN} commands to automatically execute during
40290@value{GDBN} startup. The lines of contents are canned sequences of commands,
40291described in
40292@ifset man
40293the @value{GDBN} manual in node @code{Sequences}
40294-- shell command @code{info -f gdb -n Sequences}.
40295@end ifset
40296@ifclear man
40297@ref{Sequences}.
40298@end ifclear
40299
40300Please read more in
40301@ifset man
40302the @value{GDBN} manual in node @code{Startup}
40303-- shell command @code{info -f gdb -n Startup}.
40304@end ifset
40305@ifclear man
40306@ref{Startup}.
40307@end ifclear
40308
40309@table @env
40310@ifset SYSTEM_GDBINIT
40311@item @value{SYSTEM_GDBINIT}
40312@end ifset
40313@ifclear SYSTEM_GDBINIT
40314@item (not enabled with @code{--with-system-gdbinit} during compilation)
40315@end ifclear
40316System-wide initialization file. It is executed unless user specified
40317@value{GDBN} option @code{-nx} or @code{-n}.
40318See more in
40319@ifset man
40320the @value{GDBN} manual in node @code{System-wide configuration}
40321-- shell command @code{info -f gdb -n 'System-wide configuration'}.
40322@end ifset
40323@ifclear man
40324@ref{System-wide configuration}.
40325@end ifclear
40326
40327@item ~/.gdbinit
40328User initialization file. It is executed unless user specified
40329@value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
40330
40331@item ./.gdbinit
40332Initialization file for current directory. It may need to be enabled with
40333@value{GDBN} security command @code{set auto-load local-gdbinit}.
40334See more in
40335@ifset man
40336the @value{GDBN} manual in node @code{Init File in the Current Directory}
40337-- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
40338@end ifset
40339@ifclear man
40340@ref{Init File in the Current Directory}.
40341@end ifclear
40342@end table
40343@c man end
40344
40345@c man begin SEEALSO gdbinit
40346@ifset man
40347gdb(1), @code{info -f gdb -n Startup}
40348
40349The full documentation for @value{GDBN} is maintained as a Texinfo manual.
40350If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
40351documentation are properly installed at your site, the command
40352
40353@smallexample
40354info gdb
40355@end smallexample
40356
40357should give you access to the complete manual.
40358
40359@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
40360Richard M. Stallman and Roland H. Pesch, July 1991.
40361@end ifset
40362@c man end
40363
aab4e0ec 40364@include gpl.texi
eb12ee30 40365
e4c0cfae
SS
40366@node GNU Free Documentation License
40367@appendix GNU Free Documentation License
6826cf00
EZ
40368@include fdl.texi
40369
00595b5e
EZ
40370@node Concept Index
40371@unnumbered Concept Index
c906108c
SS
40372
40373@printindex cp
40374
00595b5e
EZ
40375@node Command and Variable Index
40376@unnumbered Command, Variable, and Function Index
40377
40378@printindex fn
40379
c906108c 40380@tex
984359d2 40381% I think something like @@colophon should be in texinfo. In the
c906108c
SS
40382% meantime:
40383\long\def\colophon{\hbox to0pt{}\vfill
40384\centerline{The body of this manual is set in}
40385\centerline{\fontname\tenrm,}
40386\centerline{with headings in {\bf\fontname\tenbf}}
40387\centerline{and examples in {\tt\fontname\tentt}.}
40388\centerline{{\it\fontname\tenit\/},}
40389\centerline{{\bf\fontname\tenbf}, and}
40390\centerline{{\sl\fontname\tensl\/}}
40391\centerline{are used for emphasis.}\vfill}
40392\page\colophon
984359d2 40393% Blame: doc@@cygnus.com, 1991.
c906108c
SS
40394@end tex
40395
c906108c 40396@bye
This page took 6.152508 seconds and 4 git commands to generate.