gdb/
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
28e7fd62 2@c Copyright (C) 1988-2013 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.
96a2c332
SS
48@end direntry
49
a67ec3f4 50@copying
43662968 51@c man begin COPYRIGHT
28e7fd62 52Copyright @copyright{} 1988-2013 Free Software Foundation, Inc.
c906108c 53
e9c75b65 54Permission is granted to copy, distribute and/or modify this document
4f5d9f07 55under the terms of the GNU Free Documentation License, Version 1.3 or
e9c75b65 56any later version published by the Free Software Foundation; with the
959acfd1
EZ
57Invariant Sections being ``Free Software'' and ``Free Software Needs
58Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
59and with the Back-Cover Texts as in (a) below.
c906108c 60
b8533aec
DJ
61(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
62this GNU Manual. Buying copies from GNU Press supports the FSF in
63developing GNU and promoting software freedom.''
43662968 64@c man end
a67ec3f4
JM
65@end copying
66
67@ifnottex
68This file documents the @sc{gnu} debugger @value{GDBN}.
69
70This is the @value{EDITION} Edition, of @cite{Debugging with
71@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
72@ifset VERSION_PACKAGE
73@value{VERSION_PACKAGE}
74@end ifset
75Version @value{GDBVN}.
76
77@insertcopying
78@end ifnottex
c906108c
SS
79
80@titlepage
81@title Debugging with @value{GDBN}
82@subtitle The @sc{gnu} Source-Level Debugger
c906108c 83@sp 1
c906108c 84@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
c16158bc
JM
85@ifset VERSION_PACKAGE
86@sp 1
87@subtitle @value{VERSION_PACKAGE}
88@end ifset
9e9c5ae7 89@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 90@page
c906108c
SS
91@tex
92{\parskip=0pt
c16158bc 93\hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
c906108c
SS
94\hfill {\it Debugging with @value{GDBN}}\par
95\hfill \TeX{}info \texinfoversion\par
96}
97@end tex
53a5351d 98
c906108c 99@vskip 0pt plus 1filll
c906108c 100Published by the Free Software Foundation @*
c02a867d
EZ
10151 Franklin Street, Fifth Floor,
102Boston, MA 02110-1301, USA@*
26829f2b 103ISBN 978-0-9831592-3-0 @*
e9c75b65 104
a67ec3f4 105@insertcopying
c906108c
SS
106@end titlepage
107@page
108
6c0e9fb3 109@ifnottex
6d2ebf8b
SS
110@node Top, Summary, (dir), (dir)
111
c906108c
SS
112@top Debugging with @value{GDBN}
113
114This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
115
c16158bc
JM
116This is the @value{EDITION} Edition, for @value{GDBN}
117@ifset VERSION_PACKAGE
118@value{VERSION_PACKAGE}
119@end ifset
120Version @value{GDBVN}.
c906108c 121
28e7fd62 122Copyright (C) 1988-2013 Free Software Foundation, Inc.
6d2ebf8b 123
3fb6a982
JB
124This edition of the GDB manual is dedicated to the memory of Fred
125Fish. Fred was a long-standing contributor to GDB and to Free
126software in general. We will miss him.
127
6d2ebf8b
SS
128@menu
129* Summary:: Summary of @value{GDBN}
130* Sample Session:: A sample @value{GDBN} session
131
132* Invocation:: Getting in and out of @value{GDBN}
133* Commands:: @value{GDBN} commands
134* Running:: Running programs under @value{GDBN}
135* Stopping:: Stopping and continuing
bacec72f 136* Reverse Execution:: Running programs backward
a2311334 137* Process Record and Replay:: Recording inferior's execution and replaying it
6d2ebf8b
SS
138* Stack:: Examining the stack
139* Source:: Examining source files
140* Data:: Examining data
edb3359d 141* Optimized Code:: Debugging optimized code
e2e0bcd1 142* Macros:: Preprocessor Macros
b37052ae 143* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 144* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
145
146* Languages:: Using @value{GDBN} with different languages
147
148* Symbols:: Examining the symbol table
149* Altering:: Altering execution
150* GDB Files:: @value{GDBN} files
151* Targets:: Specifying a debugging target
6b2f586d 152* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
153* Configurations:: Configuration-specific information
154* Controlling GDB:: Controlling @value{GDBN}
d57a3c85 155* Extending GDB:: Extending @value{GDBN}
21c294e6 156* Interpreters:: Command Interpreters
c8f4133a 157* TUI:: @value{GDBN} Text User Interface
6d2ebf8b 158* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
7162c0ca 159* GDB/MI:: @value{GDBN}'s Machine Interface.
c8f4133a 160* Annotations:: @value{GDBN}'s annotation interface.
4efc6507 161* JIT Interface:: Using the JIT debugging interface.
d1feda86 162* In-Process Agent:: In-Process Agent
6d2ebf8b
SS
163
164* GDB Bugs:: Reporting bugs in @value{GDBN}
6d2ebf8b 165
39037522
TT
166@ifset SYSTEM_READLINE
167* Command Line Editing: (rluserman). Command Line Editing
168* Using History Interactively: (history). Using History Interactively
169@end ifset
170@ifclear SYSTEM_READLINE
6d2ebf8b
SS
171* Command Line Editing:: Command Line Editing
172* Using History Interactively:: Using History Interactively
39037522 173@end ifclear
4ceed123 174* In Memoriam:: In Memoriam
0869d01b 175* Formatting Documentation:: How to format and print @value{GDBN} documentation
6d2ebf8b 176* Installing GDB:: Installing GDB
eb12ee30 177* Maintenance Commands:: Maintenance Commands
e0ce93ac 178* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 179* Agent Expressions:: The GDB Agent Expression Mechanism
23181151
DJ
180* Target Descriptions:: How targets can describe themselves to
181 @value{GDBN}
07e059b5
VP
182* Operating System Information:: Getting additional information from
183 the operating system
00bf0b85 184* Trace File Format:: GDB trace file format
90476074 185* Index Section Format:: .gdb_index section format
43662968 186* Man Pages:: Manual pages
aab4e0ec
AC
187* Copying:: GNU General Public License says
188 how you can copy and share GDB
6826cf00 189* GNU Free Documentation License:: The license for this documentation
00595b5e
EZ
190* Concept Index:: Index of @value{GDBN} concepts
191* Command and Variable Index:: Index of @value{GDBN} commands, variables,
192 functions, and Python data types
6d2ebf8b
SS
193@end menu
194
6c0e9fb3 195@end ifnottex
c906108c 196
449f3b6c 197@contents
449f3b6c 198
6d2ebf8b 199@node Summary
c906108c
SS
200@unnumbered Summary of @value{GDBN}
201
202The purpose of a debugger such as @value{GDBN} is to allow you to see what is
203going on ``inside'' another program while it executes---or what another
204program was doing at the moment it crashed.
205
206@value{GDBN} can do four main kinds of things (plus other things in support of
207these) to help you catch bugs in the act:
208
209@itemize @bullet
210@item
211Start your program, specifying anything that might affect its behavior.
212
213@item
214Make your program stop on specified conditions.
215
216@item
217Examine what has happened, when your program has stopped.
218
219@item
220Change things in your program, so you can experiment with correcting the
221effects of one bug and go on to learn about another.
222@end itemize
223
49efadf5 224You can use @value{GDBN} to debug programs written in C and C@t{++}.
79a6e687 225For more information, see @ref{Supported Languages,,Supported Languages}.
c906108c
SS
226For more information, see @ref{C,,C and C++}.
227
6aecb9c2
JB
228Support for D is partial. For information on D, see
229@ref{D,,D}.
230
cce74817 231@cindex Modula-2
e632838e
AC
232Support for Modula-2 is partial. For information on Modula-2, see
233@ref{Modula-2,,Modula-2}.
c906108c 234
f4b8a18d
KW
235Support for OpenCL C is partial. For information on OpenCL C, see
236@ref{OpenCL C,,OpenCL C}.
237
cce74817
JM
238@cindex Pascal
239Debugging Pascal programs which use sets, subranges, file variables, or
240nested functions does not currently work. @value{GDBN} does not support
241entering expressions, printing values, or similar features using Pascal
242syntax.
c906108c 243
c906108c
SS
244@cindex Fortran
245@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 246it may be necessary to refer to some variables with a trailing
cce74817 247underscore.
c906108c 248
b37303ee
AF
249@value{GDBN} can be used to debug programs written in Objective-C,
250using either the Apple/NeXT or the GNU Objective-C runtime.
251
c906108c
SS
252@menu
253* Free Software:: Freely redistributable software
984359d2 254* Free Documentation:: Free Software Needs Free Documentation
c906108c
SS
255* Contributors:: Contributors to GDB
256@end menu
257
6d2ebf8b 258@node Free Software
79a6e687 259@unnumberedsec Free Software
c906108c 260
5d161b24 261@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
262General Public License
263(GPL). The GPL gives you the freedom to copy or adapt a licensed
264program---but every person getting a copy also gets with it the
265freedom to modify that copy (which means that they must get access to
266the source code), and the freedom to distribute further copies.
267Typical software companies use copyrights to limit your freedoms; the
268Free Software Foundation uses the GPL to preserve these freedoms.
269
270Fundamentally, the General Public License is a license which says that
271you have these freedoms and that you cannot take these freedoms away
272from anyone else.
273
984359d2 274@node Free Documentation
2666264b 275@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
276
277The biggest deficiency in the free software community today is not in
278the software---it is the lack of good free documentation that we can
279include with the free software. Many of our most important
280programs do not come with free reference manuals and free introductory
281texts. Documentation is an essential part of any software package;
282when an important free software package does not come with a free
283manual and a free tutorial, that is a major gap. We have many such
284gaps today.
285
286Consider Perl, for instance. The tutorial manuals that people
287normally use are non-free. How did this come about? Because the
288authors of those manuals published them with restrictive terms---no
289copying, no modification, source files not available---which exclude
290them from the free software world.
291
292That wasn't the first time this sort of thing happened, and it was far
293from the last. Many times we have heard a GNU user eagerly describe a
294manual that he is writing, his intended contribution to the community,
295only to learn that he had ruined everything by signing a publication
296contract to make it non-free.
297
298Free documentation, like free software, is a matter of freedom, not
299price. The problem with the non-free manual is not that publishers
300charge a price for printed copies---that in itself is fine. (The Free
301Software Foundation sells printed copies of manuals, too.) The
302problem is the restrictions on the use of the manual. Free manuals
303are available in source code form, and give you permission to copy and
304modify. Non-free manuals do not allow this.
305
306The criteria of freedom for a free manual are roughly the same as for
307free software. Redistribution (including the normal kinds of
308commercial redistribution) must be permitted, so that the manual can
309accompany every copy of the program, both on-line and on paper.
310
311Permission for modification of the technical content is crucial too.
312When people modify the software, adding or changing features, if they
313are conscientious they will change the manual too---so they can
314provide accurate and clear documentation for the modified program. A
315manual that leaves you no choice but to write a new manual to document
316a changed version of the program is not really available to our
317community.
318
319Some kinds of limits on the way modification is handled are
320acceptable. For example, requirements to preserve the original
321author's copyright notice, the distribution terms, or the list of
322authors, are ok. It is also no problem to require modified versions
323to include notice that they were modified. Even entire sections that
324may not be deleted or changed are acceptable, as long as they deal
325with nontechnical topics (like this one). These kinds of restrictions
326are acceptable because they don't obstruct the community's normal use
327of the manual.
328
329However, it must be possible to modify all the @emph{technical}
330content of the manual, and then distribute the result in all the usual
331media, through all the usual channels. Otherwise, the restrictions
332obstruct the use of the manual, it is not free, and we need another
333manual to replace it.
334
335Please spread the word about this issue. Our community continues to
336lose manuals to proprietary publishing. If we spread the word that
337free software needs free reference manuals and free tutorials, perhaps
338the next person who wants to contribute by writing documentation will
339realize, before it is too late, that only free manuals contribute to
340the free software community.
341
342If you are writing documentation, please insist on publishing it under
343the GNU Free Documentation License or another free documentation
344license. Remember that this decision requires your approval---you
345don't have to let the publisher decide. Some commercial publishers
346will use a free license if you insist, but they will not propose the
347option; it is up to you to raise the issue and say firmly that this is
348what you want. If the publisher you are dealing with refuses, please
349try other publishers. If you're not sure whether a proposed license
42584a72 350is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
351
352You can encourage commercial publishers to sell more free, copylefted
353manuals and tutorials by buying them, and particularly by buying
354copies from the publishers that paid for their writing or for major
355improvements. Meanwhile, try to avoid buying non-free documentation
356at all. Check the distribution terms of a manual before you buy it,
357and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
358Check the history of the book, and try to reward the publishers that
359have paid or pay the authors to work on it.
959acfd1
EZ
360
361The Free Software Foundation maintains a list of free documentation
362published by other publishers, at
363@url{http://www.fsf.org/doc/other-free-books.html}.
364
6d2ebf8b 365@node Contributors
96a2c332
SS
366@unnumberedsec Contributors to @value{GDBN}
367
368Richard Stallman was the original author of @value{GDBN}, and of many
369other @sc{gnu} programs. Many others have contributed to its
370development. This section attempts to credit major contributors. One
371of the virtues of free software is that everyone is free to contribute
372to it; with regret, we cannot actually acknowledge everyone here. The
373file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
374blow-by-blow account.
375
376Changes much prior to version 2.0 are lost in the mists of time.
377
378@quotation
379@emph{Plea:} Additions to this section are particularly welcome. If you
380or your friends (or enemies, to be evenhanded) have been unfairly
381omitted from this list, we would like to add your names!
382@end quotation
383
384So that they may not regard their many labors as thankless, we
385particularly thank those who shepherded @value{GDBN} through major
386releases:
7ba3cf9c 387Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
388Jim Blandy (release 4.18);
389Jason Molenda (release 4.17);
390Stan Shebs (release 4.14);
391Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
392Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
393John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
394Jim Kingdon (releases 3.5, 3.4, and 3.3);
395and Randy Smith (releases 3.2, 3.1, and 3.0).
396
397Richard Stallman, assisted at various times by Peter TerMaat, Chris
398Hanson, and Richard Mlynarik, handled releases through 2.8.
399
b37052ae
EZ
400Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
401in @value{GDBN}, with significant additional contributions from Per
402Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
403demangler. Early work on C@t{++} was by Peter TerMaat (who also did
404much general update work leading to release 3.0).
c906108c 405
b37052ae 406@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
407object-file formats; BFD was a joint project of David V.
408Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
409
410David Johnson wrote the original COFF support; Pace Willison did
411the original support for encapsulated COFF.
412
0179ffac 413Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
414
415Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
416Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
417support.
418Jean-Daniel Fekete contributed Sun 386i support.
419Chris Hanson improved the HP9000 support.
420Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
421David Johnson contributed Encore Umax support.
422Jyrki Kuoppala contributed Altos 3068 support.
423Jeff Law contributed HP PA and SOM support.
424Keith Packard contributed NS32K support.
425Doug Rabson contributed Acorn Risc Machine support.
426Bob Rusk contributed Harris Nighthawk CX-UX support.
427Chris Smith contributed Convex support (and Fortran debugging).
428Jonathan Stone contributed Pyramid support.
429Michael Tiemann contributed SPARC support.
430Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
431Pace Willison contributed Intel 386 support.
432Jay Vosburgh contributed Symmetry support.
a37295f9 433Marko Mlinar contributed OpenRISC 1000 support.
c906108c 434
1104b9e7 435Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
436
437Rich Schaefer and Peter Schauer helped with support of SunOS shared
438libraries.
439
440Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
441about several machine instruction sets.
442
443Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
444remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
445contributed remote debugging modules for the i960, VxWorks, A29K UDI,
446and RDI targets, respectively.
447
448Brian Fox is the author of the readline libraries providing
449command-line editing and command history.
450
7a292a7a
SS
451Andrew Beers of SUNY Buffalo wrote the language-switching code, the
452Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 453
5d161b24 454Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 455He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 456symbols.
c906108c 457
f24c5e49
KI
458Hitachi America (now Renesas America), Ltd. sponsored the support for
459H8/300, H8/500, and Super-H processors.
c906108c
SS
460
461NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
462
f24c5e49
KI
463Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
464processors.
c906108c
SS
465
466Toshiba sponsored the support for the TX39 Mips processor.
467
468Matsushita sponsored the support for the MN10200 and MN10300 processors.
469
96a2c332 470Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
471
472Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
473watchpoints.
474
475Michael Snyder added support for tracepoints.
476
477Stu Grossman wrote gdbserver.
478
479Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 480nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
481
482The following people at the Hewlett-Packard Company contributed
483support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 484(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
485compiler, and the Text User Interface (nee Terminal User Interface):
486Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
487Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
488provided HP-specific information in this manual.
c906108c 489
b37052ae
EZ
490DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
491Robert Hoehne made significant contributions to the DJGPP port.
492
96a2c332
SS
493Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
494development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
495fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
496Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
497Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
498Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
499Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
500addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
501JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
502Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
503Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
504Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
505Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
506Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
507Zuhn have made contributions both large and small.
c906108c 508
ffed4509
AC
509Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
510Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
511
e2e0bcd1
JB
512Jim Blandy added support for preprocessor macros, while working for Red
513Hat.
c906108c 514
a9967aef
AC
515Andrew Cagney designed @value{GDBN}'s architecture vector. Many
516people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
517Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
518Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
519Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
520with the migration of old architectures to this new framework.
521
c5e30d01
AC
522Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
523unwinder framework, this consisting of a fresh new design featuring
524frame IDs, independent frame sniffers, and the sentinel frame. Mark
525Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
526libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
db2e3e2e 527trad unwinders. The architecture-specific changes, each involving a
c5e30d01
AC
528complete rewrite of the architecture's frame code, were carried out by
529Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
530Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
531Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
532Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
533Weigand.
534
ca3bf3bd
DJ
535Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
536Tensilica, Inc.@: contributed support for Xtensa processors. Others
537who have worked on the Xtensa port of @value{GDBN} in the past include
538Steve Tjiang, John Newlin, and Scott Foehner.
539
08be9d71
ME
540Michael Eager and staff of Xilinx, Inc., contributed support for the
541Xilinx MicroBlaze architecture.
542
6d2ebf8b 543@node Sample Session
c906108c
SS
544@chapter A Sample @value{GDBN} Session
545
546You can use this manual at your leisure to read all about @value{GDBN}.
547However, a handful of commands are enough to get started using the
548debugger. This chapter illustrates those commands.
549
550@iftex
551In this sample session, we emphasize user input like this: @b{input},
552to make it easier to pick out from the surrounding output.
553@end iftex
554
555@c FIXME: this example may not be appropriate for some configs, where
556@c FIXME...primary interest is in remote use.
557
558One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
559processor) exhibits the following bug: sometimes, when we change its
560quote strings from the default, the commands used to capture one macro
561definition within another stop working. In the following short @code{m4}
562session, we define a macro @code{foo} which expands to @code{0000}; we
563then use the @code{m4} built-in @code{defn} to define @code{bar} as the
564same thing. However, when we change the open quote string to
565@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
566procedure fails to define a new synonym @code{baz}:
567
568@smallexample
569$ @b{cd gnu/m4}
570$ @b{./m4}
571@b{define(foo,0000)}
572
573@b{foo}
5740000
575@b{define(bar,defn(`foo'))}
576
577@b{bar}
5780000
579@b{changequote(<QUOTE>,<UNQUOTE>)}
580
581@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
582@b{baz}
c8aa23ab 583@b{Ctrl-d}
c906108c
SS
584m4: End of input: 0: fatal error: EOF in string
585@end smallexample
586
587@noindent
588Let us use @value{GDBN} to try to see what is going on.
589
c906108c
SS
590@smallexample
591$ @b{@value{GDBP} m4}
592@c FIXME: this falsifies the exact text played out, to permit smallbook
593@c FIXME... format to come out better.
594@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 595 of it under certain conditions; type "show copying" to see
c906108c 596 the conditions.
5d161b24 597There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
598 for details.
599
600@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
601(@value{GDBP})
602@end smallexample
c906108c
SS
603
604@noindent
605@value{GDBN} reads only enough symbol data to know where to find the
606rest when needed; as a result, the first prompt comes up very quickly.
607We now tell @value{GDBN} to use a narrower display width than usual, so
608that examples fit in this manual.
609
610@smallexample
611(@value{GDBP}) @b{set width 70}
612@end smallexample
613
614@noindent
615We need to see how the @code{m4} built-in @code{changequote} works.
616Having looked at the source, we know the relevant subroutine is
617@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
618@code{break} command.
619
620@smallexample
621(@value{GDBP}) @b{break m4_changequote}
622Breakpoint 1 at 0x62f4: file builtin.c, line 879.
623@end smallexample
624
625@noindent
626Using the @code{run} command, we start @code{m4} running under @value{GDBN}
627control; as long as control does not reach the @code{m4_changequote}
628subroutine, the program runs as usual:
629
630@smallexample
631(@value{GDBP}) @b{run}
632Starting program: /work/Editorial/gdb/gnu/m4/m4
633@b{define(foo,0000)}
634
635@b{foo}
6360000
637@end smallexample
638
639@noindent
640To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
641suspends execution of @code{m4}, displaying information about the
642context where it stops.
643
644@smallexample
645@b{changequote(<QUOTE>,<UNQUOTE>)}
646
5d161b24 647Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
648 at builtin.c:879
649879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
650@end smallexample
651
652@noindent
653Now we use the command @code{n} (@code{next}) to advance execution to
654the next line of the current function.
655
656@smallexample
657(@value{GDBP}) @b{n}
658882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
659 : nil,
660@end smallexample
661
662@noindent
663@code{set_quotes} looks like a promising subroutine. We can go into it
664by using the command @code{s} (@code{step}) instead of @code{next}.
665@code{step} goes to the next line to be executed in @emph{any}
666subroutine, so it steps into @code{set_quotes}.
667
668@smallexample
669(@value{GDBP}) @b{s}
670set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
671 at input.c:530
672530 if (lquote != def_lquote)
673@end smallexample
674
675@noindent
676The display that shows the subroutine where @code{m4} is now
677suspended (and its arguments) is called a stack frame display. It
678shows a summary of the stack. We can use the @code{backtrace}
679command (which can also be spelled @code{bt}), to see where we are
680in the stack as a whole: the @code{backtrace} command displays a
681stack frame for each active subroutine.
682
683@smallexample
684(@value{GDBP}) @b{bt}
685#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
686 at input.c:530
5d161b24 687#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
688 at builtin.c:882
689#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
690#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
691 at macro.c:71
692#4 0x79dc in expand_input () at macro.c:40
693#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
694@end smallexample
695
696@noindent
697We step through a few more lines to see what happens. The first two
698times, we can use @samp{s}; the next two times we use @code{n} to avoid
699falling into the @code{xstrdup} subroutine.
700
701@smallexample
702(@value{GDBP}) @b{s}
7030x3b5c 532 if (rquote != def_rquote)
704(@value{GDBP}) @b{s}
7050x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
706def_lquote : xstrdup(lq);
707(@value{GDBP}) @b{n}
708536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
709 : xstrdup(rq);
710(@value{GDBP}) @b{n}
711538 len_lquote = strlen(rquote);
712@end smallexample
713
714@noindent
715The last line displayed looks a little odd; we can examine the variables
716@code{lquote} and @code{rquote} to see if they are in fact the new left
717and right quotes we specified. We use the command @code{p}
718(@code{print}) to see their values.
719
720@smallexample
721(@value{GDBP}) @b{p lquote}
722$1 = 0x35d40 "<QUOTE>"
723(@value{GDBP}) @b{p rquote}
724$2 = 0x35d50 "<UNQUOTE>"
725@end smallexample
726
727@noindent
728@code{lquote} and @code{rquote} are indeed the new left and right quotes.
729To look at some context, we can display ten lines of source
730surrounding the current line with the @code{l} (@code{list}) command.
731
732@smallexample
733(@value{GDBP}) @b{l}
734533 xfree(rquote);
735534
736535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
737 : xstrdup (lq);
738536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
739 : xstrdup (rq);
740537
741538 len_lquote = strlen(rquote);
742539 len_rquote = strlen(lquote);
743540 @}
744541
745542 void
746@end smallexample
747
748@noindent
749Let us step past the two lines that set @code{len_lquote} and
750@code{len_rquote}, and then examine the values of those variables.
751
752@smallexample
753(@value{GDBP}) @b{n}
754539 len_rquote = strlen(lquote);
755(@value{GDBP}) @b{n}
756540 @}
757(@value{GDBP}) @b{p len_lquote}
758$3 = 9
759(@value{GDBP}) @b{p len_rquote}
760$4 = 7
761@end smallexample
762
763@noindent
764That certainly looks wrong, assuming @code{len_lquote} and
765@code{len_rquote} are meant to be the lengths of @code{lquote} and
766@code{rquote} respectively. We can set them to better values using
767the @code{p} command, since it can print the value of
768any expression---and that expression can include subroutine calls and
769assignments.
770
771@smallexample
772(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
773$5 = 7
774(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
775$6 = 9
776@end smallexample
777
778@noindent
779Is that enough to fix the problem of using the new quotes with the
780@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
781executing with the @code{c} (@code{continue}) command, and then try the
782example that caused trouble initially:
783
784@smallexample
785(@value{GDBP}) @b{c}
786Continuing.
787
788@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
789
790baz
7910000
792@end smallexample
793
794@noindent
795Success! The new quotes now work just as well as the default ones. The
796problem seems to have been just the two typos defining the wrong
797lengths. We allow @code{m4} exit by giving it an EOF as input:
798
799@smallexample
c8aa23ab 800@b{Ctrl-d}
c906108c
SS
801Program exited normally.
802@end smallexample
803
804@noindent
805The message @samp{Program exited normally.} is from @value{GDBN}; it
806indicates @code{m4} has finished executing. We can end our @value{GDBN}
807session with the @value{GDBN} @code{quit} command.
808
809@smallexample
810(@value{GDBP}) @b{quit}
811@end smallexample
c906108c 812
6d2ebf8b 813@node Invocation
c906108c
SS
814@chapter Getting In and Out of @value{GDBN}
815
816This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 817The essentials are:
c906108c 818@itemize @bullet
5d161b24 819@item
53a5351d 820type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 821@item
c8aa23ab 822type @kbd{quit} or @kbd{Ctrl-d} to exit.
c906108c
SS
823@end itemize
824
825@menu
826* Invoking GDB:: How to start @value{GDBN}
827* Quitting GDB:: How to quit @value{GDBN}
828* Shell Commands:: How to use shell commands inside @value{GDBN}
79a6e687 829* Logging Output:: How to log @value{GDBN}'s output to a file
c906108c
SS
830@end menu
831
6d2ebf8b 832@node Invoking GDB
c906108c
SS
833@section Invoking @value{GDBN}
834
c906108c
SS
835Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
836@value{GDBN} reads commands from the terminal until you tell it to exit.
837
838You can also run @code{@value{GDBP}} with a variety of arguments and options,
839to specify more of your debugging environment at the outset.
840
c906108c
SS
841The command-line options described here are designed
842to cover a variety of situations; in some environments, some of these
5d161b24 843options may effectively be unavailable.
c906108c
SS
844
845The most usual way to start @value{GDBN} is with one argument,
846specifying an executable program:
847
474c8240 848@smallexample
c906108c 849@value{GDBP} @var{program}
474c8240 850@end smallexample
c906108c 851
c906108c
SS
852@noindent
853You can also start with both an executable program and a core file
854specified:
855
474c8240 856@smallexample
c906108c 857@value{GDBP} @var{program} @var{core}
474c8240 858@end smallexample
c906108c
SS
859
860You can, instead, specify a process ID as a second argument, if you want
861to debug a running process:
862
474c8240 863@smallexample
c906108c 864@value{GDBP} @var{program} 1234
474c8240 865@end smallexample
c906108c
SS
866
867@noindent
868would attach @value{GDBN} to process @code{1234} (unless you also have a file
869named @file{1234}; @value{GDBN} does check for a core file first).
870
c906108c 871Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
872complete operating system; when you use @value{GDBN} as a remote
873debugger attached to a bare board, there may not be any notion of
874``process'', and there is often no way to get a core dump. @value{GDBN}
875will warn you if it is unable to attach or to read core dumps.
c906108c 876
aa26fa3a
TT
877You can optionally have @code{@value{GDBP}} pass any arguments after the
878executable file to the inferior using @code{--args}. This option stops
879option processing.
474c8240 880@smallexample
3f94c067 881@value{GDBP} --args gcc -O2 -c foo.c
474c8240 882@end smallexample
aa26fa3a
TT
883This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
884@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
885
96a2c332 886You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
887@value{GDBN}'s non-warranty, by specifying @code{-silent}:
888
889@smallexample
890@value{GDBP} -silent
891@end smallexample
892
893@noindent
894You can further control how @value{GDBN} starts up by using command-line
895options. @value{GDBN} itself can remind you of the options available.
896
897@noindent
898Type
899
474c8240 900@smallexample
c906108c 901@value{GDBP} -help
474c8240 902@end smallexample
c906108c
SS
903
904@noindent
905to display all available options and briefly describe their use
906(@samp{@value{GDBP} -h} is a shorter equivalent).
907
908All options and command line arguments you give are processed
909in sequential order. The order makes a difference when the
910@samp{-x} option is used.
911
912
913@menu
c906108c
SS
914* File Options:: Choosing files
915* Mode Options:: Choosing modes
6fc08d32 916* Startup:: What @value{GDBN} does during startup
c906108c
SS
917@end menu
918
6d2ebf8b 919@node File Options
79a6e687 920@subsection Choosing Files
c906108c 921
2df3850c 922When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
923specifying an executable file and core file (or process ID). This is
924the same as if the arguments were specified by the @samp{-se} and
d52fb0e9 925@samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
19837790
MS
926first argument that does not have an associated option flag as
927equivalent to the @samp{-se} option followed by that argument; and the
928second argument that does not have an associated option flag, if any, as
929equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
930If the second argument begins with a decimal digit, @value{GDBN} will
931first attempt to attach to it as a process, and if that fails, attempt
932to open it as a corefile. If you have a corefile whose name begins with
b383017d 933a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 934prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
935
936If @value{GDBN} has not been configured to included core file support,
937such as for most embedded targets, then it will complain about a second
938argument and ignore it.
c906108c
SS
939
940Many options have both long and short forms; both are shown in the
941following list. @value{GDBN} also recognizes the long forms if you truncate
942them, so long as enough of the option is present to be unambiguous.
943(If you prefer, you can flag option arguments with @samp{--} rather
944than @samp{-}, though we illustrate the more usual convention.)
945
d700128c
EZ
946@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
947@c way, both those who look for -foo and --foo in the index, will find
948@c it.
949
c906108c
SS
950@table @code
951@item -symbols @var{file}
952@itemx -s @var{file}
d700128c
EZ
953@cindex @code{--symbols}
954@cindex @code{-s}
c906108c
SS
955Read symbol table from file @var{file}.
956
957@item -exec @var{file}
958@itemx -e @var{file}
d700128c
EZ
959@cindex @code{--exec}
960@cindex @code{-e}
7a292a7a
SS
961Use file @var{file} as the executable file to execute when appropriate,
962and for examining pure data in conjunction with a core dump.
c906108c
SS
963
964@item -se @var{file}
d700128c 965@cindex @code{--se}
c906108c
SS
966Read symbol table from file @var{file} and use it as the executable
967file.
968
c906108c
SS
969@item -core @var{file}
970@itemx -c @var{file}
d700128c
EZ
971@cindex @code{--core}
972@cindex @code{-c}
b383017d 973Use file @var{file} as a core dump to examine.
c906108c 974
19837790
MS
975@item -pid @var{number}
976@itemx -p @var{number}
977@cindex @code{--pid}
978@cindex @code{-p}
979Connect to process ID @var{number}, as with the @code{attach} command.
c906108c
SS
980
981@item -command @var{file}
982@itemx -x @var{file}
d700128c
EZ
983@cindex @code{--command}
984@cindex @code{-x}
95433b34
JB
985Execute commands from file @var{file}. The contents of this file is
986evaluated exactly as the @code{source} command would.
8150ff9c 987@xref{Command Files,, Command files}.
c906108c 988
8a5a3c82
AS
989@item -eval-command @var{command}
990@itemx -ex @var{command}
991@cindex @code{--eval-command}
992@cindex @code{-ex}
993Execute a single @value{GDBN} command.
994
995This option may be used multiple times to call multiple commands. It may
996also be interleaved with @samp{-command} as required.
997
998@smallexample
999@value{GDBP} -ex 'target sim' -ex 'load' \
1000 -x setbreakpoints -ex 'run' a.out
1001@end smallexample
1002
8320cc4f
JK
1003@item -init-command @var{file}
1004@itemx -ix @var{file}
1005@cindex @code{--init-command}
1006@cindex @code{-ix}
2d7b58e8
JK
1007Execute commands from file @var{file} before loading the inferior (but
1008after loading gdbinit files).
8320cc4f
JK
1009@xref{Startup}.
1010
1011@item -init-eval-command @var{command}
1012@itemx -iex @var{command}
1013@cindex @code{--init-eval-command}
1014@cindex @code{-iex}
2d7b58e8
JK
1015Execute a single @value{GDBN} command before loading the inferior (but
1016after loading gdbinit files).
8320cc4f
JK
1017@xref{Startup}.
1018
c906108c
SS
1019@item -directory @var{directory}
1020@itemx -d @var{directory}
d700128c
EZ
1021@cindex @code{--directory}
1022@cindex @code{-d}
4b505b12 1023Add @var{directory} to the path to search for source and script files.
c906108c 1024
c906108c
SS
1025@item -r
1026@itemx -readnow
d700128c
EZ
1027@cindex @code{--readnow}
1028@cindex @code{-r}
c906108c
SS
1029Read each symbol file's entire symbol table immediately, rather than
1030the default, which is to read it incrementally as it is needed.
1031This makes startup slower, but makes future operations faster.
53a5351d 1032
c906108c
SS
1033@end table
1034
6d2ebf8b 1035@node Mode Options
79a6e687 1036@subsection Choosing Modes
c906108c
SS
1037
1038You can run @value{GDBN} in various alternative modes---for example, in
1039batch mode or quiet mode.
1040
1041@table @code
bf88dd68 1042@anchor{-nx}
c906108c
SS
1043@item -nx
1044@itemx -n
d700128c
EZ
1045@cindex @code{--nx}
1046@cindex @code{-n}
07540c15
DE
1047Do not execute commands found in any initialization file.
1048There are three init files, loaded in the following order:
1049
1050@table @code
1051@item @file{system.gdbinit}
1052This is the system-wide init file.
1053Its location is specified with the @code{--with-system-gdbinit}
1054configure option (@pxref{System-wide configuration}).
1055It is loaded first when @value{GDBN} starts, before command line options
1056have been processed.
1057@item @file{~/.gdbinit}
1058This is the init file in your home directory.
1059It is loaded next, after @file{system.gdbinit}, and before
1060command options have been processed.
1061@item @file{./.gdbinit}
1062This is the init file in the current directory.
1063It is loaded last, after command line options other than @code{-x} and
1064@code{-ex} have been processed. Command line options @code{-x} and
1065@code{-ex} are processed last, after @file{./.gdbinit} has been loaded.
1066@end table
1067
1068For further documentation on startup processing, @xref{Startup}.
1069For documentation on how to write command files,
1070@xref{Command Files,,Command Files}.
1071
1072@anchor{-nh}
1073@item -nh
1074@cindex @code{--nh}
1075Do not execute commands found in @file{~/.gdbinit}, the init file
1076in your home directory.
1077@xref{Startup}.
c906108c
SS
1078
1079@item -quiet
d700128c 1080@itemx -silent
c906108c 1081@itemx -q
d700128c
EZ
1082@cindex @code{--quiet}
1083@cindex @code{--silent}
1084@cindex @code{-q}
c906108c
SS
1085``Quiet''. Do not print the introductory and copyright messages. These
1086messages are also suppressed in batch mode.
1087
1088@item -batch
d700128c 1089@cindex @code{--batch}
c906108c
SS
1090Run in batch mode. Exit with status @code{0} after processing all the
1091command files specified with @samp{-x} (and all commands from
1092initialization files, if not inhibited with @samp{-n}). Exit with
1093nonzero status if an error occurs in executing the @value{GDBN} commands
5da1313b
JK
1094in the command files. Batch mode also disables pagination, sets unlimited
1095terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1096off} were in effect (@pxref{Messages/Warnings}).
c906108c 1097
2df3850c
JM
1098Batch mode may be useful for running @value{GDBN} as a filter, for
1099example to download and run a program on another computer; in order to
1100make this more useful, the message
c906108c 1101
474c8240 1102@smallexample
c906108c 1103Program exited normally.
474c8240 1104@end smallexample
c906108c
SS
1105
1106@noindent
2df3850c
JM
1107(which is ordinarily issued whenever a program running under
1108@value{GDBN} control terminates) is not issued when running in batch
1109mode.
1110
1a088d06
AS
1111@item -batch-silent
1112@cindex @code{--batch-silent}
1113Run in batch mode exactly like @samp{-batch}, but totally silently. All
1114@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1115unaffected). This is much quieter than @samp{-silent} and would be useless
1116for an interactive session.
1117
1118This is particularly useful when using targets that give @samp{Loading section}
1119messages, for example.
1120
1121Note that targets that give their output via @value{GDBN}, as opposed to
1122writing directly to @code{stdout}, will also be made silent.
1123
4b0ad762
AS
1124@item -return-child-result
1125@cindex @code{--return-child-result}
1126The return code from @value{GDBN} will be the return code from the child
1127process (the process being debugged), with the following exceptions:
1128
1129@itemize @bullet
1130@item
1131@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1132internal error. In this case the exit code is the same as it would have been
1133without @samp{-return-child-result}.
1134@item
1135The user quits with an explicit value. E.g., @samp{quit 1}.
1136@item
1137The child process never runs, or is not allowed to terminate, in which case
1138the exit code will be -1.
1139@end itemize
1140
1141This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1142when @value{GDBN} is being used as a remote program loader or simulator
1143interface.
1144
2df3850c
JM
1145@item -nowindows
1146@itemx -nw
d700128c
EZ
1147@cindex @code{--nowindows}
1148@cindex @code{-nw}
2df3850c 1149``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1150(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1151interface. If no GUI is available, this option has no effect.
1152
1153@item -windows
1154@itemx -w
d700128c
EZ
1155@cindex @code{--windows}
1156@cindex @code{-w}
2df3850c
JM
1157If @value{GDBN} includes a GUI, then this option requires it to be
1158used if possible.
c906108c
SS
1159
1160@item -cd @var{directory}
d700128c 1161@cindex @code{--cd}
c906108c
SS
1162Run @value{GDBN} using @var{directory} as its working directory,
1163instead of the current directory.
1164
aae1c79a
DE
1165@item -data-directory @var{directory}
1166@cindex @code{--data-directory}
1167Run @value{GDBN} using @var{directory} as its data directory.
1168The data directory is where @value{GDBN} searches for its
1169auxiliary files. @xref{Data Files}.
1170
c906108c
SS
1171@item -fullname
1172@itemx -f
d700128c
EZ
1173@cindex @code{--fullname}
1174@cindex @code{-f}
7a292a7a
SS
1175@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1176subprocess. It tells @value{GDBN} to output the full file name and line
1177number in a standard, recognizable fashion each time a stack frame is
1178displayed (which includes each time your program stops). This
1179recognizable format looks like two @samp{\032} characters, followed by
1180the file name, line number and character position separated by colons,
1181and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1182@samp{\032} characters as a signal to display the source code for the
1183frame.
c906108c 1184
d700128c
EZ
1185@item -annotate @var{level}
1186@cindex @code{--annotate}
1187This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1188effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1189(@pxref{Annotations}). The annotation @var{level} controls how much
1190information @value{GDBN} prints together with its prompt, values of
1191expressions, source lines, and other types of output. Level 0 is the
1192normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1193@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1194that control @value{GDBN}, and level 2 has been deprecated.
1195
265eeb58 1196The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1197(@pxref{GDB/MI}).
d700128c 1198
aa26fa3a
TT
1199@item --args
1200@cindex @code{--args}
1201Change interpretation of command line so that arguments following the
1202executable file are passed as command line arguments to the inferior.
1203This option stops option processing.
1204
2df3850c
JM
1205@item -baud @var{bps}
1206@itemx -b @var{bps}
d700128c
EZ
1207@cindex @code{--baud}
1208@cindex @code{-b}
c906108c
SS
1209Set the line speed (baud rate or bits per second) of any serial
1210interface used by @value{GDBN} for remote debugging.
c906108c 1211
f47b1503
AS
1212@item -l @var{timeout}
1213@cindex @code{-l}
1214Set the timeout (in seconds) of any communication used by @value{GDBN}
1215for remote debugging.
1216
c906108c 1217@item -tty @var{device}
d700128c
EZ
1218@itemx -t @var{device}
1219@cindex @code{--tty}
1220@cindex @code{-t}
c906108c
SS
1221Run using @var{device} for your program's standard input and output.
1222@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1223
53a5351d 1224@c resolve the situation of these eventually
c4555f82
SC
1225@item -tui
1226@cindex @code{--tui}
d0d5df6f
AC
1227Activate the @dfn{Text User Interface} when starting. The Text User
1228Interface manages several text windows on the terminal, showing
1229source, assembly, registers and @value{GDBN} command outputs
217bff3e
JK
1230(@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1231option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1232Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1233
1234@c @item -xdb
d700128c 1235@c @cindex @code{--xdb}
53a5351d
JM
1236@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1237@c For information, see the file @file{xdb_trans.html}, which is usually
1238@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1239@c systems.
1240
d700128c
EZ
1241@item -interpreter @var{interp}
1242@cindex @code{--interpreter}
1243Use the interpreter @var{interp} for interface with the controlling
1244program or device. This option is meant to be set by programs which
94bbb2c0 1245communicate with @value{GDBN} using it as a back end.
21c294e6 1246@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1247
da0f9dcd 1248@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1249@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1250The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1251previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1252selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1253@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1254
1255@item -write
1256@cindex @code{--write}
1257Open the executable and core files for both reading and writing. This
1258is equivalent to the @samp{set write on} command inside @value{GDBN}
1259(@pxref{Patching}).
1260
1261@item -statistics
1262@cindex @code{--statistics}
1263This option causes @value{GDBN} to print statistics about time and
1264memory usage after it completes each command and returns to the prompt.
1265
1266@item -version
1267@cindex @code{--version}
1268This option causes @value{GDBN} to print its version number and
1269no-warranty blurb, and exit.
1270
c906108c
SS
1271@end table
1272
6fc08d32 1273@node Startup
79a6e687 1274@subsection What @value{GDBN} Does During Startup
6fc08d32
EZ
1275@cindex @value{GDBN} startup
1276
1277Here's the description of what @value{GDBN} does during session startup:
1278
1279@enumerate
1280@item
1281Sets up the command interpreter as specified by the command line
1282(@pxref{Mode Options, interpreter}).
1283
1284@item
1285@cindex init file
098b41a6
JG
1286Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1287used when building @value{GDBN}; @pxref{System-wide configuration,
1288 ,System-wide configuration and settings}) and executes all the commands in
1289that file.
1290
bf88dd68 1291@anchor{Home Directory Init File}
098b41a6
JG
1292@item
1293Reads the init file (if any) in your home directory@footnote{On
6fc08d32
EZ
1294DOS/Windows systems, the home directory is the one pointed to by the
1295@code{HOME} environment variable.} and executes all the commands in
1296that file.
1297
2d7b58e8
JK
1298@anchor{Option -init-eval-command}
1299@item
1300Executes commands and command files specified by the @samp{-iex} and
1301@samp{-ix} options in their specified order. Usually you should use the
1302@samp{-ex} and @samp{-x} options instead, but this way you can apply
1303settings before @value{GDBN} init files get executed and before inferior
1304gets loaded.
1305
6fc08d32
EZ
1306@item
1307Processes command line options and operands.
1308
bf88dd68 1309@anchor{Init File in the Current Directory during Startup}
6fc08d32
EZ
1310@item
1311Reads and executes the commands from init file (if any) in the current
bf88dd68
JK
1312working directory as long as @samp{set auto-load local-gdbinit} is set to
1313@samp{on} (@pxref{Init File in the Current Directory}).
1314This is only done if the current directory is
119b882a
EZ
1315different from your home directory. Thus, you can have more than one
1316init file, one generic in your home directory, and another, specific
1317to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1318@value{GDBN}.
1319
a86caf66
DE
1320@item
1321If the command line specified a program to debug, or a process to
1322attach to, or a core file, @value{GDBN} loads any auto-loaded
1323scripts provided for the program or for its loaded shared libraries.
1324@xref{Auto-loading}.
1325
1326If you wish to disable the auto-loading during startup,
1327you must do something like the following:
1328
1329@smallexample
bf88dd68 1330$ gdb -iex "set auto-load python-scripts off" myprogram
a86caf66
DE
1331@end smallexample
1332
8320cc4f
JK
1333Option @samp{-ex} does not work because the auto-loading is then turned
1334off too late.
a86caf66 1335
6fc08d32 1336@item
6fe37d23
JK
1337Executes commands and command files specified by the @samp{-ex} and
1338@samp{-x} options in their specified order. @xref{Command Files}, for
1339more details about @value{GDBN} command files.
6fc08d32
EZ
1340
1341@item
1342Reads the command history recorded in the @dfn{history file}.
d620b259 1343@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1344files where @value{GDBN} records it.
1345@end enumerate
1346
1347Init files use the same syntax as @dfn{command files} (@pxref{Command
1348Files}) and are processed by @value{GDBN} in the same way. The init
1349file in your home directory can set options (such as @samp{set
1350complaints}) that affect subsequent processing of command line options
1351and operands. Init files are not executed if you use the @samp{-nx}
79a6e687 1352option (@pxref{Mode Options, ,Choosing Modes}).
6fc08d32 1353
098b41a6
JG
1354To display the list of init files loaded by gdb at startup, you
1355can use @kbd{gdb --help}.
1356
6fc08d32
EZ
1357@cindex init file name
1358@cindex @file{.gdbinit}
119b882a 1359@cindex @file{gdb.ini}
8807d78b 1360The @value{GDBN} init files are normally called @file{.gdbinit}.
119b882a
EZ
1361The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1362the limitations of file names imposed by DOS filesystems. The Windows
4d3f93a2
JB
1363port of @value{GDBN} uses the standard name, but if it finds a
1364@file{gdb.ini} file in your home directory, it warns you about that
1365and suggests to rename the file to the standard name.
119b882a 1366
6fc08d32 1367
6d2ebf8b 1368@node Quitting GDB
c906108c
SS
1369@section Quitting @value{GDBN}
1370@cindex exiting @value{GDBN}
1371@cindex leaving @value{GDBN}
1372
1373@table @code
1374@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1375@kindex q @r{(@code{quit})}
96a2c332
SS
1376@item quit @r{[}@var{expression}@r{]}
1377@itemx q
1378To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1379@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1380do not supply @var{expression}, @value{GDBN} will terminate normally;
1381otherwise it will terminate using the result of @var{expression} as the
1382error code.
c906108c
SS
1383@end table
1384
1385@cindex interrupt
c8aa23ab 1386An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1387terminates the action of any @value{GDBN} command that is in progress and
1388returns to @value{GDBN} command level. It is safe to type the interrupt
1389character at any time because @value{GDBN} does not allow it to take effect
1390until a time when it is safe.
1391
c906108c
SS
1392If you have been using @value{GDBN} to control an attached process or
1393device, you can release it with the @code{detach} command
79a6e687 1394(@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 1395
6d2ebf8b 1396@node Shell Commands
79a6e687 1397@section Shell Commands
c906108c
SS
1398
1399If you need to execute occasional shell commands during your
1400debugging session, there is no need to leave or suspend @value{GDBN}; you can
1401just use the @code{shell} command.
1402
1403@table @code
1404@kindex shell
ed59ded5 1405@kindex !
c906108c 1406@cindex shell escape
ed59ded5
DE
1407@item shell @var{command-string}
1408@itemx !@var{command-string}
1409Invoke a standard shell to execute @var{command-string}.
1410Note that no space is needed between @code{!} and @var{command-string}.
c906108c 1411If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1412shell to run. Otherwise @value{GDBN} uses the default shell
1413(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1414@end table
1415
1416The utility @code{make} is often needed in development environments.
1417You do not have to use the @code{shell} command for this purpose in
1418@value{GDBN}:
1419
1420@table @code
1421@kindex make
1422@cindex calling make
1423@item make @var{make-args}
1424Execute the @code{make} program with the specified
1425arguments. This is equivalent to @samp{shell make @var{make-args}}.
1426@end table
1427
79a6e687
BW
1428@node Logging Output
1429@section Logging Output
0fac0b41 1430@cindex logging @value{GDBN} output
9c16f35a 1431@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1432
1433You may want to save the output of @value{GDBN} commands to a file.
1434There are several commands to control @value{GDBN}'s logging.
1435
1436@table @code
1437@kindex set logging
1438@item set logging on
1439Enable logging.
1440@item set logging off
1441Disable logging.
9c16f35a 1442@cindex logging file name
0fac0b41
DJ
1443@item set logging file @var{file}
1444Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1445@item set logging overwrite [on|off]
1446By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1447you want @code{set logging on} to overwrite the logfile instead.
1448@item set logging redirect [on|off]
1449By default, @value{GDBN} output will go to both the terminal and the logfile.
1450Set @code{redirect} if you want output to go only to the log file.
1451@kindex show logging
1452@item show logging
1453Show the current values of the logging settings.
1454@end table
1455
6d2ebf8b 1456@node Commands
c906108c
SS
1457@chapter @value{GDBN} Commands
1458
1459You can abbreviate a @value{GDBN} command to the first few letters of the command
1460name, if that abbreviation is unambiguous; and you can repeat certain
1461@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1462key to get @value{GDBN} to fill out the rest of a word in a command (or to
1463show you the alternatives available, if there is more than one possibility).
1464
1465@menu
1466* Command Syntax:: How to give commands to @value{GDBN}
1467* Completion:: Command completion
1468* Help:: How to ask @value{GDBN} for help
1469@end menu
1470
6d2ebf8b 1471@node Command Syntax
79a6e687 1472@section Command Syntax
c906108c
SS
1473
1474A @value{GDBN} command is a single line of input. There is no limit on
1475how long it can be. It starts with a command name, which is followed by
1476arguments whose meaning depends on the command name. For example, the
1477command @code{step} accepts an argument which is the number of times to
1478step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1479with no arguments. Some commands do not allow any arguments.
c906108c
SS
1480
1481@cindex abbreviation
1482@value{GDBN} command names may always be truncated if that abbreviation is
1483unambiguous. Other possible command abbreviations are listed in the
1484documentation for individual commands. In some cases, even ambiguous
1485abbreviations are allowed; for example, @code{s} is specially defined as
1486equivalent to @code{step} even though there are other commands whose
1487names start with @code{s}. You can test abbreviations by using them as
1488arguments to the @code{help} command.
1489
1490@cindex repeating commands
41afff9a 1491@kindex RET @r{(repeat last command)}
c906108c 1492A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1493repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1494will not repeat this way; these are commands whose unintentional
1495repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1496repeat. User-defined commands can disable this feature; see
1497@ref{Define, dont-repeat}.
c906108c
SS
1498
1499The @code{list} and @code{x} commands, when you repeat them with
1500@key{RET}, construct new arguments rather than repeating
1501exactly as typed. This permits easy scanning of source or memory.
1502
1503@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1504output, in a way similar to the common utility @code{more}
79a6e687 1505(@pxref{Screen Size,,Screen Size}). Since it is easy to press one
c906108c
SS
1506@key{RET} too many in this situation, @value{GDBN} disables command
1507repetition after any command that generates this sort of display.
1508
41afff9a 1509@kindex # @r{(a comment)}
c906108c
SS
1510@cindex comment
1511Any text from a @kbd{#} to the end of the line is a comment; it does
1512nothing. This is useful mainly in command files (@pxref{Command
79a6e687 1513Files,,Command Files}).
c906108c 1514
88118b3a 1515@cindex repeating command sequences
c8aa23ab
EZ
1516@kindex Ctrl-o @r{(operate-and-get-next)}
1517The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1518commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1519then fetches the next line relative to the current line from the history
1520for editing.
1521
6d2ebf8b 1522@node Completion
79a6e687 1523@section Command Completion
c906108c
SS
1524
1525@cindex completion
1526@cindex word completion
1527@value{GDBN} can fill in the rest of a word in a command for you, if there is
1528only one possibility; it can also show you what the valid possibilities
1529are for the next word in a command, at any time. This works for @value{GDBN}
1530commands, @value{GDBN} subcommands, and the names of symbols in your program.
1531
1532Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1533of a word. If there is only one possibility, @value{GDBN} fills in the
1534word, and waits for you to finish the command (or press @key{RET} to
1535enter it). For example, if you type
1536
1537@c FIXME "@key" does not distinguish its argument sufficiently to permit
1538@c complete accuracy in these examples; space introduced for clarity.
1539@c If texinfo enhancements make it unnecessary, it would be nice to
1540@c replace " @key" by "@key" in the following...
474c8240 1541@smallexample
c906108c 1542(@value{GDBP}) info bre @key{TAB}
474c8240 1543@end smallexample
c906108c
SS
1544
1545@noindent
1546@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1547the only @code{info} subcommand beginning with @samp{bre}:
1548
474c8240 1549@smallexample
c906108c 1550(@value{GDBP}) info breakpoints
474c8240 1551@end smallexample
c906108c
SS
1552
1553@noindent
1554You can either press @key{RET} at this point, to run the @code{info
1555breakpoints} command, or backspace and enter something else, if
1556@samp{breakpoints} does not look like the command you expected. (If you
1557were sure you wanted @code{info breakpoints} in the first place, you
1558might as well just type @key{RET} immediately after @samp{info bre},
1559to exploit command abbreviations rather than command completion).
1560
1561If there is more than one possibility for the next word when you press
1562@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1563characters and try again, or just press @key{TAB} a second time;
1564@value{GDBN} displays all the possible completions for that word. For
1565example, you might want to set a breakpoint on a subroutine whose name
1566begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1567just sounds the bell. Typing @key{TAB} again displays all the
1568function names in your program that begin with those characters, for
1569example:
1570
474c8240 1571@smallexample
c906108c
SS
1572(@value{GDBP}) b make_ @key{TAB}
1573@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1574make_a_section_from_file make_environ
1575make_abs_section make_function_type
1576make_blockvector make_pointer_type
1577make_cleanup make_reference_type
c906108c
SS
1578make_command make_symbol_completion_list
1579(@value{GDBP}) b make_
474c8240 1580@end smallexample
c906108c
SS
1581
1582@noindent
1583After displaying the available possibilities, @value{GDBN} copies your
1584partial input (@samp{b make_} in the example) so you can finish the
1585command.
1586
1587If you just want to see the list of alternatives in the first place, you
b37052ae 1588can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1589means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1590key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1591one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1592
1593@cindex quotes in commands
1594@cindex completion of quoted strings
1595Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1596parentheses or other characters that @value{GDBN} normally excludes from
1597its notion of a word. To permit word completion to work in this
1598situation, you may enclose words in @code{'} (single quote marks) in
1599@value{GDBN} commands.
c906108c 1600
c906108c 1601The most likely situation where you might need this is in typing the
b37052ae
EZ
1602name of a C@t{++} function. This is because C@t{++} allows function
1603overloading (multiple definitions of the same function, distinguished
1604by argument type). For example, when you want to set a breakpoint you
1605may need to distinguish whether you mean the version of @code{name}
1606that takes an @code{int} parameter, @code{name(int)}, or the version
1607that takes a @code{float} parameter, @code{name(float)}. To use the
1608word-completion facilities in this situation, type a single quote
1609@code{'} at the beginning of the function name. This alerts
1610@value{GDBN} that it may need to consider more information than usual
1611when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1612
474c8240 1613@smallexample
96a2c332 1614(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1615bubble(double,double) bubble(int,int)
1616(@value{GDBP}) b 'bubble(
474c8240 1617@end smallexample
c906108c
SS
1618
1619In some cases, @value{GDBN} can tell that completing a name requires using
1620quotes. When this happens, @value{GDBN} inserts the quote for you (while
1621completing as much as it can) if you do not type the quote in the first
1622place:
1623
474c8240 1624@smallexample
c906108c
SS
1625(@value{GDBP}) b bub @key{TAB}
1626@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1627(@value{GDBP}) b 'bubble(
474c8240 1628@end smallexample
c906108c
SS
1629
1630@noindent
1631In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1632you have not yet started typing the argument list when you ask for
1633completion on an overloaded symbol.
1634
79a6e687
BW
1635For more information about overloaded functions, see @ref{C Plus Plus
1636Expressions, ,C@t{++} Expressions}. You can use the command @code{set
c906108c 1637overload-resolution off} to disable overload resolution;
79a6e687 1638see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
c906108c 1639
65d12d83
TT
1640@cindex completion of structure field names
1641@cindex structure field name completion
1642@cindex completion of union field names
1643@cindex union field name completion
1644When completing in an expression which looks up a field in a
1645structure, @value{GDBN} also tries@footnote{The completer can be
1646confused by certain kinds of invalid expressions. Also, it only
1647examines the static type of the expression, not the dynamic type.} to
1648limit completions to the field names available in the type of the
1649left-hand-side:
1650
1651@smallexample
1652(@value{GDBP}) p gdb_stdout.@kbd{M-?}
01124a23
DE
1653magic to_fputs to_rewind
1654to_data to_isatty to_write
1655to_delete to_put to_write_async_safe
1656to_flush to_read
65d12d83
TT
1657@end smallexample
1658
1659@noindent
1660This is because the @code{gdb_stdout} is a variable of the type
1661@code{struct ui_file} that is defined in @value{GDBN} sources as
1662follows:
1663
1664@smallexample
1665struct ui_file
1666@{
1667 int *magic;
1668 ui_file_flush_ftype *to_flush;
1669 ui_file_write_ftype *to_write;
01124a23 1670 ui_file_write_async_safe_ftype *to_write_async_safe;
65d12d83
TT
1671 ui_file_fputs_ftype *to_fputs;
1672 ui_file_read_ftype *to_read;
1673 ui_file_delete_ftype *to_delete;
1674 ui_file_isatty_ftype *to_isatty;
1675 ui_file_rewind_ftype *to_rewind;
1676 ui_file_put_ftype *to_put;
1677 void *to_data;
1678@}
1679@end smallexample
1680
c906108c 1681
6d2ebf8b 1682@node Help
79a6e687 1683@section Getting Help
c906108c
SS
1684@cindex online documentation
1685@kindex help
1686
5d161b24 1687You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1688using the command @code{help}.
1689
1690@table @code
41afff9a 1691@kindex h @r{(@code{help})}
c906108c
SS
1692@item help
1693@itemx h
1694You can use @code{help} (abbreviated @code{h}) with no arguments to
1695display a short list of named classes of commands:
1696
1697@smallexample
1698(@value{GDBP}) help
1699List of classes of commands:
1700
2df3850c 1701aliases -- Aliases of other commands
c906108c 1702breakpoints -- Making program stop at certain points
2df3850c 1703data -- Examining data
c906108c 1704files -- Specifying and examining files
2df3850c
JM
1705internals -- Maintenance commands
1706obscure -- Obscure features
1707running -- Running the program
1708stack -- Examining the stack
c906108c
SS
1709status -- Status inquiries
1710support -- Support facilities
12c27660 1711tracepoints -- Tracing of program execution without
96a2c332 1712 stopping the program
c906108c 1713user-defined -- User-defined commands
c906108c 1714
5d161b24 1715Type "help" followed by a class name for a list of
c906108c 1716commands in that class.
5d161b24 1717Type "help" followed by command name for full
c906108c
SS
1718documentation.
1719Command name abbreviations are allowed if unambiguous.
1720(@value{GDBP})
1721@end smallexample
96a2c332 1722@c the above line break eliminates huge line overfull...
c906108c
SS
1723
1724@item help @var{class}
1725Using one of the general help classes as an argument, you can get a
1726list of the individual commands in that class. For example, here is the
1727help display for the class @code{status}:
1728
1729@smallexample
1730(@value{GDBP}) help status
1731Status inquiries.
1732
1733List of commands:
1734
1735@c Line break in "show" line falsifies real output, but needed
1736@c to fit in smallbook page size.
2df3850c 1737info -- Generic command for showing things
12c27660 1738 about the program being debugged
2df3850c 1739show -- Generic command for showing things
12c27660 1740 about the debugger
c906108c 1741
5d161b24 1742Type "help" followed by command name for full
c906108c
SS
1743documentation.
1744Command name abbreviations are allowed if unambiguous.
1745(@value{GDBP})
1746@end smallexample
1747
1748@item help @var{command}
1749With a command name as @code{help} argument, @value{GDBN} displays a
1750short paragraph on how to use that command.
1751
6837a0a2
DB
1752@kindex apropos
1753@item apropos @var{args}
09d4efe1 1754The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2 1755commands, and their documentation, for the regular expression specified in
99e008fe 1756@var{args}. It prints out all matches found. For example:
6837a0a2
DB
1757
1758@smallexample
16899756 1759apropos alias
6837a0a2
DB
1760@end smallexample
1761
b37052ae
EZ
1762@noindent
1763results in:
6837a0a2
DB
1764
1765@smallexample
6d2ebf8b 1766@c @group
16899756
DE
1767alias -- Define a new command that is an alias of an existing command
1768aliases -- Aliases of other commands
1769d -- Delete some breakpoints or auto-display expressions
1770del -- Delete some breakpoints or auto-display expressions
1771delete -- Delete some breakpoints or auto-display expressions
6d2ebf8b 1772@c @end group
6837a0a2
DB
1773@end smallexample
1774
c906108c
SS
1775@kindex complete
1776@item complete @var{args}
1777The @code{complete @var{args}} command lists all the possible completions
1778for the beginning of a command. Use @var{args} to specify the beginning of the
1779command you want completed. For example:
1780
1781@smallexample
1782complete i
1783@end smallexample
1784
1785@noindent results in:
1786
1787@smallexample
1788@group
2df3850c
JM
1789if
1790ignore
c906108c
SS
1791info
1792inspect
c906108c
SS
1793@end group
1794@end smallexample
1795
1796@noindent This is intended for use by @sc{gnu} Emacs.
1797@end table
1798
1799In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1800and @code{show} to inquire about the state of your program, or the state
1801of @value{GDBN} itself. Each command supports many topics of inquiry; this
1802manual introduces each of them in the appropriate context. The listings
00595b5e
EZ
1803under @code{info} and under @code{show} in the Command, Variable, and
1804Function Index point to all the sub-commands. @xref{Command and Variable
1805Index}.
c906108c
SS
1806
1807@c @group
1808@table @code
1809@kindex info
41afff9a 1810@kindex i @r{(@code{info})}
c906108c
SS
1811@item info
1812This command (abbreviated @code{i}) is for describing the state of your
cda4ce5a 1813program. For example, you can show the arguments passed to a function
c906108c
SS
1814with @code{info args}, list the registers currently in use with @code{info
1815registers}, or list the breakpoints you have set with @code{info breakpoints}.
1816You can get a complete list of the @code{info} sub-commands with
1817@w{@code{help info}}.
1818
1819@kindex set
1820@item set
5d161b24 1821You can assign the result of an expression to an environment variable with
c906108c
SS
1822@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1823@code{set prompt $}.
1824
1825@kindex show
1826@item show
5d161b24 1827In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1828@value{GDBN} itself.
1829You can change most of the things you can @code{show}, by using the
1830related command @code{set}; for example, you can control what number
1831system is used for displays with @code{set radix}, or simply inquire
1832which is currently in use with @code{show radix}.
1833
1834@kindex info set
1835To display all the settable parameters and their current
1836values, you can use @code{show} with no arguments; you may also use
1837@code{info set}. Both commands produce the same display.
1838@c FIXME: "info set" violates the rule that "info" is for state of
1839@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1840@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1841@end table
1842@c @end group
1843
1844Here are three miscellaneous @code{show} subcommands, all of which are
1845exceptional in lacking corresponding @code{set} commands:
1846
1847@table @code
1848@kindex show version
9c16f35a 1849@cindex @value{GDBN} version number
c906108c
SS
1850@item show version
1851Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1852information in @value{GDBN} bug-reports. If multiple versions of
1853@value{GDBN} are in use at your site, you may need to determine which
1854version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1855commands are introduced, and old ones may wither away. Also, many
1856system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1857variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1858The version number is the same as the one announced when you start
1859@value{GDBN}.
c906108c
SS
1860
1861@kindex show copying
09d4efe1 1862@kindex info copying
9c16f35a 1863@cindex display @value{GDBN} copyright
c906108c 1864@item show copying
09d4efe1 1865@itemx info copying
c906108c
SS
1866Display information about permission for copying @value{GDBN}.
1867
1868@kindex show warranty
09d4efe1 1869@kindex info warranty
c906108c 1870@item show warranty
09d4efe1 1871@itemx info warranty
2df3850c 1872Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1873if your version of @value{GDBN} comes with one.
2df3850c 1874
c906108c
SS
1875@end table
1876
6d2ebf8b 1877@node Running
c906108c
SS
1878@chapter Running Programs Under @value{GDBN}
1879
1880When you run a program under @value{GDBN}, you must first generate
1881debugging information when you compile it.
7a292a7a
SS
1882
1883You may start @value{GDBN} with its arguments, if any, in an environment
1884of your choice. If you are doing native debugging, you may redirect
1885your program's input and output, debug an already running process, or
1886kill a child process.
c906108c
SS
1887
1888@menu
1889* Compilation:: Compiling for debugging
1890* Starting:: Starting your program
c906108c
SS
1891* Arguments:: Your program's arguments
1892* Environment:: Your program's environment
c906108c
SS
1893
1894* Working Directory:: Your program's working directory
1895* Input/Output:: Your program's input and output
1896* Attach:: Debugging an already-running process
1897* Kill Process:: Killing the child process
c906108c 1898
6c95b8df 1899* Inferiors and Programs:: Debugging multiple inferiors and programs
c906108c 1900* Threads:: Debugging programs with multiple threads
6c95b8df 1901* Forks:: Debugging forks
5c95884b 1902* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
1903@end menu
1904
6d2ebf8b 1905@node Compilation
79a6e687 1906@section Compiling for Debugging
c906108c
SS
1907
1908In order to debug a program effectively, you need to generate
1909debugging information when you compile it. This debugging information
1910is stored in the object file; it describes the data type of each
1911variable or function and the correspondence between source line numbers
1912and addresses in the executable code.
1913
1914To request debugging information, specify the @samp{-g} option when you run
1915the compiler.
1916
514c4d71 1917Programs that are to be shipped to your customers are compiled with
edb3359d 1918optimizations, using the @samp{-O} compiler option. However, some
514c4d71
EZ
1919compilers are unable to handle the @samp{-g} and @samp{-O} options
1920together. Using those compilers, you cannot generate optimized
c906108c
SS
1921executables containing debugging information.
1922
514c4d71 1923@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1924without @samp{-O}, making it possible to debug optimized code. We
1925recommend that you @emph{always} use @samp{-g} whenever you compile a
1926program. You may think your program is correct, but there is no sense
edb3359d 1927in pushing your luck. For more information, see @ref{Optimized Code}.
c906108c
SS
1928
1929Older versions of the @sc{gnu} C compiler permitted a variant option
1930@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1931format; if your @sc{gnu} C compiler has this option, do not use it.
1932
514c4d71
EZ
1933@value{GDBN} knows about preprocessor macros and can show you their
1934expansion (@pxref{Macros}). Most compilers do not include information
1935about preprocessor macros in the debugging information if you specify
e0f8f636
TT
1936the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
1937the @sc{gnu} C compiler, provides macro information if you are using
1938the DWARF debugging format, and specify the option @option{-g3}.
1939
1940@xref{Debugging Options,,Options for Debugging Your Program or GCC,
1941gcc.info, Using the @sc{gnu} Compiler Collection (GCC)}, for more
1942information on @value{NGCC} options affecting debug information.
1943
1944You will have the best debugging experience if you use the latest
1945version of the DWARF debugging format that your compiler supports.
1946DWARF is currently the most expressive and best supported debugging
1947format in @value{GDBN}.
514c4d71 1948
c906108c 1949@need 2000
6d2ebf8b 1950@node Starting
79a6e687 1951@section Starting your Program
c906108c
SS
1952@cindex starting
1953@cindex running
1954
1955@table @code
1956@kindex run
41afff9a 1957@kindex r @r{(@code{run})}
c906108c
SS
1958@item run
1959@itemx r
7a292a7a
SS
1960Use the @code{run} command to start your program under @value{GDBN}.
1961You must first specify the program name (except on VxWorks) with an
1962argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1963@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
79a6e687 1964(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
1965
1966@end table
1967
c906108c
SS
1968If you are running your program in an execution environment that
1969supports processes, @code{run} creates an inferior process and makes
8edfe269
DJ
1970that process run your program. In some environments without processes,
1971@code{run} jumps to the start of your program. Other targets,
1972like @samp{remote}, are always running. If you get an error
1973message like this one:
1974
1975@smallexample
1976The "remote" target does not support "run".
1977Try "help target" or "continue".
1978@end smallexample
1979
1980@noindent
1981then use @code{continue} to run your program. You may need @code{load}
1982first (@pxref{load}).
c906108c
SS
1983
1984The execution of a program is affected by certain information it
1985receives from its superior. @value{GDBN} provides ways to specify this
1986information, which you must do @emph{before} starting your program. (You
1987can change it after starting your program, but such changes only affect
1988your program the next time you start it.) This information may be
1989divided into four categories:
1990
1991@table @asis
1992@item The @emph{arguments.}
1993Specify the arguments to give your program as the arguments of the
1994@code{run} command. If a shell is available on your target, the shell
1995is used to pass the arguments, so that you may use normal conventions
1996(such as wildcard expansion or variable substitution) in describing
1997the arguments.
1998In Unix systems, you can control which shell is used with the
1999@code{SHELL} environment variable.
79a6e687 2000@xref{Arguments, ,Your Program's Arguments}.
c906108c
SS
2001
2002@item The @emph{environment.}
2003Your program normally inherits its environment from @value{GDBN}, but you can
2004use the @value{GDBN} commands @code{set environment} and @code{unset
2005environment} to change parts of the environment that affect
79a6e687 2006your program. @xref{Environment, ,Your Program's Environment}.
c906108c
SS
2007
2008@item The @emph{working directory.}
2009Your program inherits its working directory from @value{GDBN}. You can set
2010the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
79a6e687 2011@xref{Working Directory, ,Your Program's Working Directory}.
c906108c
SS
2012
2013@item The @emph{standard input and output.}
2014Your program normally uses the same device for standard input and
2015standard output as @value{GDBN} is using. You can redirect input and output
2016in the @code{run} command line, or you can use the @code{tty} command to
2017set a different device for your program.
79a6e687 2018@xref{Input/Output, ,Your Program's Input and Output}.
c906108c
SS
2019
2020@cindex pipes
2021@emph{Warning:} While input and output redirection work, you cannot use
2022pipes to pass the output of the program you are debugging to another
2023program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2024wrong program.
2025@end table
c906108c
SS
2026
2027When you issue the @code{run} command, your program begins to execute
79a6e687 2028immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
c906108c
SS
2029of how to arrange for your program to stop. Once your program has
2030stopped, you may call functions in your program, using the @code{print}
2031or @code{call} commands. @xref{Data, ,Examining Data}.
2032
2033If the modification time of your symbol file has changed since the last
2034time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2035table, and reads it again. When it does this, @value{GDBN} tries to retain
2036your current breakpoints.
2037
4e8b0763
JB
2038@table @code
2039@kindex start
2040@item start
2041@cindex run to main procedure
2042The name of the main procedure can vary from language to language.
2043With C or C@t{++}, the main procedure name is always @code{main}, but
2044other languages such as Ada do not require a specific name for their
2045main procedure. The debugger provides a convenient way to start the
2046execution of the program and to stop at the beginning of the main
2047procedure, depending on the language used.
2048
2049The @samp{start} command does the equivalent of setting a temporary
2050breakpoint at the beginning of the main procedure and then invoking
2051the @samp{run} command.
2052
f018e82f
EZ
2053@cindex elaboration phase
2054Some programs contain an @dfn{elaboration} phase where some startup code is
2055executed before the main procedure is called. This depends on the
2056languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
2057constructors for static and global objects are executed before
2058@code{main} is called. It is therefore possible that the debugger stops
2059before reaching the main procedure. However, the temporary breakpoint
2060will remain to halt execution.
2061
2062Specify the arguments to give to your program as arguments to the
2063@samp{start} command. These arguments will be given verbatim to the
2064underlying @samp{run} command. Note that the same arguments will be
2065reused if no argument is provided during subsequent calls to
2066@samp{start} or @samp{run}.
2067
2068It is sometimes necessary to debug the program during elaboration. In
2069these cases, using the @code{start} command would stop the execution of
2070your program too late, as the program would have already completed the
2071elaboration phase. Under these circumstances, insert breakpoints in your
2072elaboration code before running your program.
ccd213ac
DJ
2073
2074@kindex set exec-wrapper
2075@item set exec-wrapper @var{wrapper}
2076@itemx show exec-wrapper
2077@itemx unset exec-wrapper
2078When @samp{exec-wrapper} is set, the specified wrapper is used to
2079launch programs for debugging. @value{GDBN} starts your program
2080with a shell command of the form @kbd{exec @var{wrapper}
2081@var{program}}. Quoting is added to @var{program} and its
2082arguments, but not to @var{wrapper}, so you should add quotes if
2083appropriate for your shell. The wrapper runs until it executes
2084your program, and then @value{GDBN} takes control.
2085
2086You can use any program that eventually calls @code{execve} with
2087its arguments as a wrapper. Several standard Unix utilities do
2088this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2089with @code{exec "$@@"} will also work.
2090
2091For example, you can use @code{env} to pass an environment variable to
2092the debugged program, without setting the variable in your shell's
2093environment:
2094
2095@smallexample
2096(@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2097(@value{GDBP}) run
2098@end smallexample
2099
2100This command is available when debugging locally on most targets, excluding
2101@sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2102
10568435
JK
2103@kindex set disable-randomization
2104@item set disable-randomization
2105@itemx set disable-randomization on
2106This option (enabled by default in @value{GDBN}) will turn off the native
2107randomization of the virtual address space of the started program. This option
2108is useful for multiple debugging sessions to make the execution better
2109reproducible and memory addresses reusable across debugging sessions.
2110
03583c20
UW
2111This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2112On @sc{gnu}/Linux you can get the same behavior using
10568435
JK
2113
2114@smallexample
2115(@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2116@end smallexample
2117
2118@item set disable-randomization off
2119Leave the behavior of the started executable unchanged. Some bugs rear their
2120ugly heads only when the program is loaded at certain addresses. If your bug
2121disappears when you run the program under @value{GDBN}, that might be because
2122@value{GDBN} by default disables the address randomization on platforms, such
2123as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2124disable-randomization off} to try to reproduce such elusive bugs.
2125
03583c20
UW
2126On targets where it is available, virtual address space randomization
2127protects the programs against certain kinds of security attacks. In these
10568435
JK
2128cases the attacker needs to know the exact location of a concrete executable
2129code. Randomizing its location makes it impossible to inject jumps misusing
2130a code at its expected addresses.
2131
2132Prelinking shared libraries provides a startup performance advantage but it
2133makes addresses in these libraries predictable for privileged processes by
2134having just unprivileged access at the target system. Reading the shared
2135library binary gives enough information for assembling the malicious code
2136misusing it. Still even a prelinked shared library can get loaded at a new
2137random address just requiring the regular relocation process during the
2138startup. Shared libraries not already prelinked are always loaded at
2139a randomly chosen address.
2140
2141Position independent executables (PIE) contain position independent code
2142similar to the shared libraries and therefore such executables get loaded at
2143a randomly chosen address upon startup. PIE executables always load even
2144already prelinked shared libraries at a random address. You can build such
2145executable using @command{gcc -fPIE -pie}.
2146
2147Heap (malloc storage), stack and custom mmap areas are always placed randomly
2148(as long as the randomization is enabled).
2149
2150@item show disable-randomization
2151Show the current setting of the explicit disable of the native randomization of
2152the virtual address space of the started program.
2153
4e8b0763
JB
2154@end table
2155
6d2ebf8b 2156@node Arguments
79a6e687 2157@section Your Program's Arguments
c906108c
SS
2158
2159@cindex arguments (to your program)
2160The arguments to your program can be specified by the arguments of the
5d161b24 2161@code{run} command.
c906108c
SS
2162They are passed to a shell, which expands wildcard characters and
2163performs redirection of I/O, and thence to your program. Your
2164@code{SHELL} environment variable (if it exists) specifies what shell
2165@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
2166the default shell (@file{/bin/sh} on Unix).
2167
2168On non-Unix systems, the program is usually invoked directly by
2169@value{GDBN}, which emulates I/O redirection via the appropriate system
2170calls, and the wildcard characters are expanded by the startup code of
2171the program, not by the shell.
c906108c
SS
2172
2173@code{run} with no arguments uses the same arguments used by the previous
2174@code{run}, or those set by the @code{set args} command.
2175
c906108c 2176@table @code
41afff9a 2177@kindex set args
c906108c
SS
2178@item set args
2179Specify the arguments to be used the next time your program is run. If
2180@code{set args} has no arguments, @code{run} executes your program
2181with no arguments. Once you have run your program with arguments,
2182using @code{set args} before the next @code{run} is the only way to run
2183it again without arguments.
2184
2185@kindex show args
2186@item show args
2187Show the arguments to give your program when it is started.
2188@end table
2189
6d2ebf8b 2190@node Environment
79a6e687 2191@section Your Program's Environment
c906108c
SS
2192
2193@cindex environment (of your program)
2194The @dfn{environment} consists of a set of environment variables and
2195their values. Environment variables conventionally record such things as
2196your user name, your home directory, your terminal type, and your search
2197path for programs to run. Usually you set up environment variables with
2198the shell and they are inherited by all the other programs you run. When
2199debugging, it can be useful to try running your program with a modified
2200environment without having to start @value{GDBN} over again.
2201
2202@table @code
2203@kindex path
2204@item path @var{directory}
2205Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
2206(the search path for executables) that will be passed to your program.
2207The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
2208You may specify several directory names, separated by whitespace or by a
2209system-dependent separator character (@samp{:} on Unix, @samp{;} on
2210MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2211is moved to the front, so it is searched sooner.
c906108c
SS
2212
2213You can use the string @samp{$cwd} to refer to whatever is the current
2214working directory at the time @value{GDBN} searches the path. If you
2215use @samp{.} instead, it refers to the directory where you executed the
2216@code{path} command. @value{GDBN} replaces @samp{.} in the
2217@var{directory} argument (with the current path) before adding
2218@var{directory} to the search path.
2219@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2220@c document that, since repeating it would be a no-op.
2221
2222@kindex show paths
2223@item show paths
2224Display the list of search paths for executables (the @code{PATH}
2225environment variable).
2226
2227@kindex show environment
2228@item show environment @r{[}@var{varname}@r{]}
2229Print the value of environment variable @var{varname} to be given to
2230your program when it starts. If you do not supply @var{varname},
2231print the names and values of all environment variables to be given to
2232your program. You can abbreviate @code{environment} as @code{env}.
2233
2234@kindex set environment
53a5351d 2235@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
2236Set environment variable @var{varname} to @var{value}. The value
2237changes for your program only, not for @value{GDBN} itself. @var{value} may
2238be any string; the values of environment variables are just strings, and
2239any interpretation is supplied by your program itself. The @var{value}
2240parameter is optional; if it is eliminated, the variable is set to a
2241null value.
2242@c "any string" here does not include leading, trailing
2243@c blanks. Gnu asks: does anyone care?
2244
2245For example, this command:
2246
474c8240 2247@smallexample
c906108c 2248set env USER = foo
474c8240 2249@end smallexample
c906108c
SS
2250
2251@noindent
d4f3574e 2252tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2253@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2254are not actually required.)
2255
2256@kindex unset environment
2257@item unset environment @var{varname}
2258Remove variable @var{varname} from the environment to be passed to your
2259program. This is different from @samp{set env @var{varname} =};
2260@code{unset environment} removes the variable from the environment,
2261rather than assigning it an empty value.
2262@end table
2263
d4f3574e
SS
2264@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2265the shell indicated
c906108c
SS
2266by your @code{SHELL} environment variable if it exists (or
2267@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2268that runs an initialization file---such as @file{.cshrc} for C-shell, or
2269@file{.bashrc} for BASH---any variables you set in that file affect
2270your program. You may wish to move setting of environment variables to
2271files that are only run when you sign on, such as @file{.login} or
2272@file{.profile}.
2273
6d2ebf8b 2274@node Working Directory
79a6e687 2275@section Your Program's Working Directory
c906108c
SS
2276
2277@cindex working directory (of your program)
2278Each time you start your program with @code{run}, it inherits its
2279working directory from the current working directory of @value{GDBN}.
2280The @value{GDBN} working directory is initially whatever it inherited
2281from its parent process (typically the shell), but you can specify a new
2282working directory in @value{GDBN} with the @code{cd} command.
2283
2284The @value{GDBN} working directory also serves as a default for the commands
2285that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
79a6e687 2286Specify Files}.
c906108c
SS
2287
2288@table @code
2289@kindex cd
721c2651 2290@cindex change working directory
f3c8a52a
JK
2291@item cd @r{[}@var{directory}@r{]}
2292Set the @value{GDBN} working directory to @var{directory}. If not
2293given, @var{directory} uses @file{'~'}.
c906108c
SS
2294
2295@kindex pwd
2296@item pwd
2297Print the @value{GDBN} working directory.
2298@end table
2299
60bf7e09
EZ
2300It is generally impossible to find the current working directory of
2301the process being debugged (since a program can change its directory
2302during its run). If you work on a system where @value{GDBN} is
2303configured with the @file{/proc} support, you can use the @code{info
2304proc} command (@pxref{SVR4 Process Information}) to find out the
2305current working directory of the debuggee.
2306
6d2ebf8b 2307@node Input/Output
79a6e687 2308@section Your Program's Input and Output
c906108c
SS
2309
2310@cindex redirection
2311@cindex i/o
2312@cindex terminal
2313By default, the program you run under @value{GDBN} does input and output to
5d161b24 2314the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2315to its own terminal modes to interact with you, but it records the terminal
2316modes your program was using and switches back to them when you continue
2317running your program.
2318
2319@table @code
2320@kindex info terminal
2321@item info terminal
2322Displays information recorded by @value{GDBN} about the terminal modes your
2323program is using.
2324@end table
2325
2326You can redirect your program's input and/or output using shell
2327redirection with the @code{run} command. For example,
2328
474c8240 2329@smallexample
c906108c 2330run > outfile
474c8240 2331@end smallexample
c906108c
SS
2332
2333@noindent
2334starts your program, diverting its output to the file @file{outfile}.
2335
2336@kindex tty
2337@cindex controlling terminal
2338Another way to specify where your program should do input and output is
2339with the @code{tty} command. This command accepts a file name as
2340argument, and causes this file to be the default for future @code{run}
2341commands. It also resets the controlling terminal for the child
2342process, for future @code{run} commands. For example,
2343
474c8240 2344@smallexample
c906108c 2345tty /dev/ttyb
474c8240 2346@end smallexample
c906108c
SS
2347
2348@noindent
2349directs that processes started with subsequent @code{run} commands
2350default to do input and output on the terminal @file{/dev/ttyb} and have
2351that as their controlling terminal.
2352
2353An explicit redirection in @code{run} overrides the @code{tty} command's
2354effect on the input/output device, but not its effect on the controlling
2355terminal.
2356
2357When you use the @code{tty} command or redirect input in the @code{run}
2358command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2359for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2360for @code{set inferior-tty}.
2361
2362@cindex inferior tty
2363@cindex set inferior controlling terminal
2364You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2365display the name of the terminal that will be used for future runs of your
2366program.
2367
2368@table @code
2369@item set inferior-tty /dev/ttyb
2370@kindex set inferior-tty
2371Set the tty for the program being debugged to /dev/ttyb.
2372
2373@item show inferior-tty
2374@kindex show inferior-tty
2375Show the current tty for the program being debugged.
2376@end table
c906108c 2377
6d2ebf8b 2378@node Attach
79a6e687 2379@section Debugging an Already-running Process
c906108c
SS
2380@kindex attach
2381@cindex attach
2382
2383@table @code
2384@item attach @var{process-id}
2385This command attaches to a running process---one that was started
2386outside @value{GDBN}. (@code{info files} shows your active
2387targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2388find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2389or with the @samp{jobs -l} shell command.
2390
2391@code{attach} does not repeat if you press @key{RET} a second time after
2392executing the command.
2393@end table
2394
2395To use @code{attach}, your program must be running in an environment
2396which supports processes; for example, @code{attach} does not work for
2397programs on bare-board targets that lack an operating system. You must
2398also have permission to send the process a signal.
2399
2400When you use @code{attach}, the debugger finds the program running in
2401the process first by looking in the current working directory, then (if
2402the program is not found) by using the source file search path
79a6e687 2403(@pxref{Source Path, ,Specifying Source Directories}). You can also use
c906108c
SS
2404the @code{file} command to load the program. @xref{Files, ,Commands to
2405Specify Files}.
2406
2407The first thing @value{GDBN} does after arranging to debug the specified
2408process is to stop it. You can examine and modify an attached process
53a5351d
JM
2409with all the @value{GDBN} commands that are ordinarily available when
2410you start processes with @code{run}. You can insert breakpoints; you
2411can step and continue; you can modify storage. If you would rather the
2412process continue running, you may use the @code{continue} command after
c906108c
SS
2413attaching @value{GDBN} to the process.
2414
2415@table @code
2416@kindex detach
2417@item detach
2418When you have finished debugging the attached process, you can use the
2419@code{detach} command to release it from @value{GDBN} control. Detaching
2420the process continues its execution. After the @code{detach} command,
2421that process and @value{GDBN} become completely independent once more, and you
2422are ready to @code{attach} another process or start one with @code{run}.
2423@code{detach} does not repeat if you press @key{RET} again after
2424executing the command.
2425@end table
2426
159fcc13
JK
2427If you exit @value{GDBN} while you have an attached process, you detach
2428that process. If you use the @code{run} command, you kill that process.
2429By default, @value{GDBN} asks for confirmation if you try to do either of these
2430things; you can control whether or not you need to confirm by using the
2431@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
79a6e687 2432Messages}).
c906108c 2433
6d2ebf8b 2434@node Kill Process
79a6e687 2435@section Killing the Child Process
c906108c
SS
2436
2437@table @code
2438@kindex kill
2439@item kill
2440Kill the child process in which your program is running under @value{GDBN}.
2441@end table
2442
2443This command is useful if you wish to debug a core dump instead of a
2444running process. @value{GDBN} ignores any core dump file while your program
2445is running.
2446
2447On some operating systems, a program cannot be executed outside @value{GDBN}
2448while you have breakpoints set on it inside @value{GDBN}. You can use the
2449@code{kill} command in this situation to permit running your program
2450outside the debugger.
2451
2452The @code{kill} command is also useful if you wish to recompile and
2453relink your program, since on many systems it is impossible to modify an
2454executable file while it is running in a process. In this case, when you
2455next type @code{run}, @value{GDBN} notices that the file has changed, and
2456reads the symbol table again (while trying to preserve your current
2457breakpoint settings).
2458
6c95b8df
PA
2459@node Inferiors and Programs
2460@section Debugging Multiple Inferiors and Programs
b77209e0 2461
6c95b8df
PA
2462@value{GDBN} lets you run and debug multiple programs in a single
2463session. In addition, @value{GDBN} on some systems may let you run
2464several programs simultaneously (otherwise you have to exit from one
2465before starting another). In the most general case, you can have
2466multiple threads of execution in each of multiple processes, launched
2467from multiple executables.
b77209e0
PA
2468
2469@cindex inferior
2470@value{GDBN} represents the state of each program execution with an
2471object called an @dfn{inferior}. An inferior typically corresponds to
2472a process, but is more general and applies also to targets that do not
2473have processes. Inferiors may be created before a process runs, and
6c95b8df
PA
2474may be retained after a process exits. Inferiors have unique
2475identifiers that are different from process ids. Usually each
2476inferior will also have its own distinct address space, although some
2477embedded targets may have several inferiors running in different parts
2478of a single address space. Each inferior may in turn have multiple
2479threads running in it.
b77209e0 2480
6c95b8df
PA
2481To find out what inferiors exist at any moment, use @w{@code{info
2482inferiors}}:
b77209e0
PA
2483
2484@table @code
2485@kindex info inferiors
2486@item info inferiors
2487Print a list of all inferiors currently being managed by @value{GDBN}.
3a1ff0b6
PA
2488
2489@value{GDBN} displays for each inferior (in this order):
2490
2491@enumerate
2492@item
2493the inferior number assigned by @value{GDBN}
2494
2495@item
2496the target system's inferior identifier
6c95b8df
PA
2497
2498@item
2499the name of the executable the inferior is running.
2500
3a1ff0b6
PA
2501@end enumerate
2502
2503@noindent
2504An asterisk @samp{*} preceding the @value{GDBN} inferior number
2505indicates the current inferior.
2506
2507For example,
2277426b 2508@end table
3a1ff0b6
PA
2509@c end table here to get a little more width for example
2510
2511@smallexample
2512(@value{GDBP}) info inferiors
6c95b8df
PA
2513 Num Description Executable
2514 2 process 2307 hello
2515* 1 process 3401 goodbye
3a1ff0b6 2516@end smallexample
2277426b
PA
2517
2518To switch focus between inferiors, use the @code{inferior} command:
2519
2520@table @code
3a1ff0b6
PA
2521@kindex inferior @var{infno}
2522@item inferior @var{infno}
2523Make inferior number @var{infno} the current inferior. The argument
2524@var{infno} is the inferior number assigned by @value{GDBN}, as shown
2525in the first field of the @samp{info inferiors} display.
2277426b
PA
2526@end table
2527
6c95b8df
PA
2528
2529You can get multiple executables into a debugging session via the
2530@code{add-inferior} and @w{@code{clone-inferior}} commands. On some
2531systems @value{GDBN} can add inferiors to the debug session
2532automatically by following calls to @code{fork} and @code{exec}. To
2533remove inferiors from the debugging session use the
af624141 2534@w{@code{remove-inferiors}} command.
6c95b8df
PA
2535
2536@table @code
2537@kindex add-inferior
2538@item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ]
2539Adds @var{n} inferiors to be run using @var{executable} as the
2540executable. @var{n} defaults to 1. If no executable is specified,
2541the inferiors begins empty, with no program. You can still assign or
2542change the program assigned to the inferior at any time by using the
2543@code{file} command with the executable name as its argument.
2544
2545@kindex clone-inferior
2546@item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
2547Adds @var{n} inferiors ready to execute the same program as inferior
2548@var{infno}. @var{n} defaults to 1. @var{infno} defaults to the
2549number of the current inferior. This is a convenient command when you
2550want to run another instance of the inferior you are debugging.
2551
2552@smallexample
2553(@value{GDBP}) info inferiors
2554 Num Description Executable
2555* 1 process 29964 helloworld
2556(@value{GDBP}) clone-inferior
2557Added inferior 2.
25581 inferiors added.
2559(@value{GDBP}) info inferiors
2560 Num Description Executable
2561 2 <null> helloworld
2562* 1 process 29964 helloworld
2563@end smallexample
2564
2565You can now simply switch focus to inferior 2 and run it.
2566
af624141
MS
2567@kindex remove-inferiors
2568@item remove-inferiors @var{infno}@dots{}
2569Removes the inferior or inferiors @var{infno}@dots{}. It is not
2570possible to remove an inferior that is running with this command. For
2571those, use the @code{kill} or @code{detach} command first.
6c95b8df
PA
2572
2573@end table
2574
2575To quit debugging one of the running inferiors that is not the current
2576inferior, you can either detach from it by using the @w{@code{detach
2577inferior}} command (allowing it to run independently), or kill it
af624141 2578using the @w{@code{kill inferiors}} command:
2277426b
PA
2579
2580@table @code
af624141
MS
2581@kindex detach inferiors @var{infno}@dots{}
2582@item detach inferior @var{infno}@dots{}
2583Detach from the inferior or inferiors identified by @value{GDBN}
5e30da2c 2584inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
af624141
MS
2585still stays on the list of inferiors shown by @code{info inferiors},
2586but its Description will show @samp{<null>}.
2587
2588@kindex kill inferiors @var{infno}@dots{}
2589@item kill inferiors @var{infno}@dots{}
2590Kill the inferior or inferiors identified by @value{GDBN} inferior
2591number(s) @var{infno}@dots{}. Note that the inferior's entry still
2592stays on the list of inferiors shown by @code{info inferiors}, but its
2593Description will show @samp{<null>}.
2277426b
PA
2594@end table
2595
6c95b8df 2596After the successful completion of a command such as @code{detach},
af624141 2597@code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
6c95b8df
PA
2598a normal process exit, the inferior is still valid and listed with
2599@code{info inferiors}, ready to be restarted.
2600
2601
2277426b
PA
2602To be notified when inferiors are started or exit under @value{GDBN}'s
2603control use @w{@code{set print inferior-events}}:
b77209e0 2604
2277426b 2605@table @code
b77209e0
PA
2606@kindex set print inferior-events
2607@cindex print messages on inferior start and exit
2608@item set print inferior-events
2609@itemx set print inferior-events on
2610@itemx set print inferior-events off
2611The @code{set print inferior-events} command allows you to enable or
2612disable printing of messages when @value{GDBN} notices that new
2613inferiors have started or that inferiors have exited or have been
2614detached. By default, these messages will not be printed.
2615
2616@kindex show print inferior-events
2617@item show print inferior-events
2618Show whether messages will be printed when @value{GDBN} detects that
2619inferiors have started, exited or have been detached.
2620@end table
2621
6c95b8df
PA
2622Many commands will work the same with multiple programs as with a
2623single program: e.g., @code{print myglobal} will simply display the
2624value of @code{myglobal} in the current inferior.
2625
2626
2627Occasionaly, when debugging @value{GDBN} itself, it may be useful to
2628get more info about the relationship of inferiors, programs, address
2629spaces in a debug session. You can do that with the @w{@code{maint
2630info program-spaces}} command.
2631
2632@table @code
2633@kindex maint info program-spaces
2634@item maint info program-spaces
2635Print a list of all program spaces currently being managed by
2636@value{GDBN}.
2637
2638@value{GDBN} displays for each program space (in this order):
2639
2640@enumerate
2641@item
2642the program space number assigned by @value{GDBN}
2643
2644@item
2645the name of the executable loaded into the program space, with e.g.,
2646the @code{file} command.
2647
2648@end enumerate
2649
2650@noindent
2651An asterisk @samp{*} preceding the @value{GDBN} program space number
2652indicates the current program space.
2653
2654In addition, below each program space line, @value{GDBN} prints extra
2655information that isn't suitable to display in tabular form. For
2656example, the list of inferiors bound to the program space.
2657
2658@smallexample
2659(@value{GDBP}) maint info program-spaces
2660 Id Executable
2661 2 goodbye
2662 Bound inferiors: ID 1 (process 21561)
2663* 1 hello
2664@end smallexample
2665
2666Here we can see that no inferior is running the program @code{hello},
2667while @code{process 21561} is running the program @code{goodbye}. On
2668some targets, it is possible that multiple inferiors are bound to the
2669same program space. The most common example is that of debugging both
2670the parent and child processes of a @code{vfork} call. For example,
2671
2672@smallexample
2673(@value{GDBP}) maint info program-spaces
2674 Id Executable
2675* 1 vfork-test
2676 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
2677@end smallexample
2678
2679Here, both inferior 2 and inferior 1 are running in the same program
2680space as a result of inferior 1 having executed a @code{vfork} call.
2681@end table
2682
6d2ebf8b 2683@node Threads
79a6e687 2684@section Debugging Programs with Multiple Threads
c906108c
SS
2685
2686@cindex threads of execution
2687@cindex multiple threads
2688@cindex switching threads
2689In some operating systems, such as HP-UX and Solaris, a single program
2690may have more than one @dfn{thread} of execution. The precise semantics
2691of threads differ from one operating system to another, but in general
2692the threads of a single program are akin to multiple processes---except
2693that they share one address space (that is, they can all examine and
2694modify the same variables). On the other hand, each thread has its own
2695registers and execution stack, and perhaps private memory.
2696
2697@value{GDBN} provides these facilities for debugging multi-thread
2698programs:
2699
2700@itemize @bullet
2701@item automatic notification of new threads
2702@item @samp{thread @var{threadno}}, a command to switch among threads
2703@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2704@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2705a command to apply a command to a list of threads
2706@item thread-specific breakpoints
93815fbf
VP
2707@item @samp{set print thread-events}, which controls printing of
2708messages on thread start and exit.
17a37d48
PP
2709@item @samp{set libthread-db-search-path @var{path}}, which lets
2710the user specify which @code{libthread_db} to use if the default choice
2711isn't compatible with the program.
c906108c
SS
2712@end itemize
2713
c906108c
SS
2714@quotation
2715@emph{Warning:} These facilities are not yet available on every
2716@value{GDBN} configuration where the operating system supports threads.
2717If your @value{GDBN} does not support threads, these commands have no
2718effect. For example, a system without thread support shows no output
2719from @samp{info threads}, and always rejects the @code{thread} command,
2720like this:
2721
2722@smallexample
2723(@value{GDBP}) info threads
2724(@value{GDBP}) thread 1
2725Thread ID 1 not known. Use the "info threads" command to
2726see the IDs of currently known threads.
2727@end smallexample
2728@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2729@c doesn't support threads"?
2730@end quotation
c906108c
SS
2731
2732@cindex focus of debugging
2733@cindex current thread
2734The @value{GDBN} thread debugging facility allows you to observe all
2735threads while your program runs---but whenever @value{GDBN} takes
2736control, one thread in particular is always the focus of debugging.
2737This thread is called the @dfn{current thread}. Debugging commands show
2738program information from the perspective of the current thread.
2739
41afff9a 2740@cindex @code{New} @var{systag} message
c906108c
SS
2741@cindex thread identifier (system)
2742@c FIXME-implementors!! It would be more helpful if the [New...] message
2743@c included GDB's numeric thread handle, so you could just go to that
2744@c thread without first checking `info threads'.
2745Whenever @value{GDBN} detects a new thread in your program, it displays
2746the target system's identification for the thread with a message in the
2747form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2748whose form varies depending on the particular system. For example, on
8807d78b 2749@sc{gnu}/Linux, you might see
c906108c 2750
474c8240 2751@smallexample
08e796bc 2752[New Thread 0x41e02940 (LWP 25582)]
474c8240 2753@end smallexample
c906108c
SS
2754
2755@noindent
2756when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2757the @var{systag} is simply something like @samp{process 368}, with no
2758further qualifier.
2759
2760@c FIXME!! (1) Does the [New...] message appear even for the very first
2761@c thread of a program, or does it only appear for the
6ca652b0 2762@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2763@c program?
2764@c (2) *Is* there necessarily a first thread always? Or do some
2765@c multithread systems permit starting a program with multiple
5d161b24 2766@c threads ab initio?
c906108c
SS
2767
2768@cindex thread number
2769@cindex thread identifier (GDB)
2770For debugging purposes, @value{GDBN} associates its own thread
2771number---always a single integer---with each thread in your program.
2772
2773@table @code
2774@kindex info threads
60f98dde
MS
2775@item info threads @r{[}@var{id}@dots{}@r{]}
2776Display a summary of all threads currently in your program. Optional
2777argument @var{id}@dots{} is one or more thread ids separated by spaces, and
2778means to print information only about the specified thread or threads.
2779@value{GDBN} displays for each thread (in this order):
c906108c
SS
2780
2781@enumerate
09d4efe1
EZ
2782@item
2783the thread number assigned by @value{GDBN}
c906108c 2784
09d4efe1
EZ
2785@item
2786the target system's thread identifier (@var{systag})
c906108c 2787
4694da01
TT
2788@item
2789the thread's name, if one is known. A thread can either be named by
2790the user (see @code{thread name}, below), or, in some cases, by the
2791program itself.
2792
09d4efe1
EZ
2793@item
2794the current stack frame summary for that thread
c906108c
SS
2795@end enumerate
2796
2797@noindent
2798An asterisk @samp{*} to the left of the @value{GDBN} thread number
2799indicates the current thread.
2800
5d161b24 2801For example,
c906108c
SS
2802@end table
2803@c end table here to get a little more width for example
2804
2805@smallexample
2806(@value{GDBP}) info threads
13fd8b81
TT
2807 Id Target Id Frame
2808 3 process 35 thread 27 0x34e5 in sigpause ()
2809 2 process 35 thread 23 0x34e5 in sigpause ()
2810* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
c906108c
SS
2811 at threadtest.c:68
2812@end smallexample
53a5351d 2813
c45da7e6
EZ
2814On Solaris, you can display more information about user threads with a
2815Solaris-specific command:
2816
2817@table @code
2818@item maint info sol-threads
2819@kindex maint info sol-threads
2820@cindex thread info (Solaris)
2821Display info on Solaris user threads.
2822@end table
2823
c906108c
SS
2824@table @code
2825@kindex thread @var{threadno}
2826@item thread @var{threadno}
2827Make thread number @var{threadno} the current thread. The command
2828argument @var{threadno} is the internal @value{GDBN} thread number, as
2829shown in the first field of the @samp{info threads} display.
2830@value{GDBN} responds by displaying the system identifier of the thread
2831you selected, and its current stack frame summary:
2832
2833@smallexample
c906108c 2834(@value{GDBP}) thread 2
13fd8b81
TT
2835[Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
2836#0 some_function (ignore=0x0) at example.c:8
28378 printf ("hello\n");
c906108c
SS
2838@end smallexample
2839
2840@noindent
2841As with the @samp{[New @dots{}]} message, the form of the text after
2842@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2843threads.
c906108c 2844
6aed2dbc
SS
2845@vindex $_thread@r{, convenience variable}
2846The debugger convenience variable @samp{$_thread} contains the number
2847of the current thread. You may find this useful in writing breakpoint
2848conditional expressions, command scripts, and so forth. See
2849@xref{Convenience Vars,, Convenience Variables}, for general
2850information on convenience variables.
2851
9c16f35a 2852@kindex thread apply
638ac427 2853@cindex apply command to several threads
13fd8b81 2854@item thread apply [@var{threadno} | all] @var{command}
839c27b7
EZ
2855The @code{thread apply} command allows you to apply the named
2856@var{command} to one or more threads. Specify the numbers of the
2857threads that you want affected with the command argument
2858@var{threadno}. It can be a single thread number, one of the numbers
2859shown in the first field of the @samp{info threads} display; or it
2860could be a range of thread numbers, as in @code{2-4}. To apply a
2861command to all threads, type @kbd{thread apply all @var{command}}.
93815fbf 2862
4694da01
TT
2863@kindex thread name
2864@cindex name a thread
2865@item thread name [@var{name}]
2866This command assigns a name to the current thread. If no argument is
2867given, any existing user-specified name is removed. The thread name
2868appears in the @samp{info threads} display.
2869
2870On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
2871determine the name of the thread as given by the OS. On these
2872systems, a name specified with @samp{thread name} will override the
2873system-give name, and removing the user-specified name will cause
2874@value{GDBN} to once again display the system-specified name.
2875
60f98dde
MS
2876@kindex thread find
2877@cindex search for a thread
2878@item thread find [@var{regexp}]
2879Search for and display thread ids whose name or @var{systag}
2880matches the supplied regular expression.
2881
2882As well as being the complement to the @samp{thread name} command,
2883this command also allows you to identify a thread by its target
2884@var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
2885is the LWP id.
2886
2887@smallexample
2888(@value{GDBN}) thread find 26688
2889Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
2890(@value{GDBN}) info thread 4
2891 Id Target Id Frame
2892 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
2893@end smallexample
2894
93815fbf
VP
2895@kindex set print thread-events
2896@cindex print messages on thread start and exit
2897@item set print thread-events
2898@itemx set print thread-events on
2899@itemx set print thread-events off
2900The @code{set print thread-events} command allows you to enable or
2901disable printing of messages when @value{GDBN} notices that new threads have
2902started or that threads have exited. By default, these messages will
2903be printed if detection of these events is supported by the target.
2904Note that these messages cannot be disabled on all targets.
2905
2906@kindex show print thread-events
2907@item show print thread-events
2908Show whether messages will be printed when @value{GDBN} detects that threads
2909have started and exited.
c906108c
SS
2910@end table
2911
79a6e687 2912@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
c906108c
SS
2913more information about how @value{GDBN} behaves when you stop and start
2914programs with multiple threads.
2915
79a6e687 2916@xref{Set Watchpoints,,Setting Watchpoints}, for information about
c906108c 2917watchpoints in programs with multiple threads.
c906108c 2918
bf88dd68 2919@anchor{set libthread-db-search-path}
17a37d48
PP
2920@table @code
2921@kindex set libthread-db-search-path
2922@cindex search path for @code{libthread_db}
2923@item set libthread-db-search-path @r{[}@var{path}@r{]}
2924If this variable is set, @var{path} is a colon-separated list of
2925directories @value{GDBN} will use to search for @code{libthread_db}.
2926If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
98a5dd13 2927its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
7e0396aa
DE
2928Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
2929macro.
17a37d48
PP
2930
2931On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
2932@code{libthread_db} library to obtain information about threads in the
2933inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
bf88dd68
JK
2934to find @code{libthread_db}. @value{GDBN} also consults first if inferior
2935specific thread debugging library loading is enabled
2936by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
98a5dd13
DE
2937
2938A special entry @samp{$sdir} for @samp{libthread-db-search-path}
2939refers to the default system directories that are
bf88dd68
JK
2940normally searched for loading shared libraries. The @samp{$sdir} entry
2941is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
2942(@pxref{libthread_db.so.1 file}).
98a5dd13
DE
2943
2944A special entry @samp{$pdir} for @samp{libthread-db-search-path}
2945refers to the directory from which @code{libpthread}
2946was loaded in the inferior process.
17a37d48
PP
2947
2948For any @code{libthread_db} library @value{GDBN} finds in above directories,
2949@value{GDBN} attempts to initialize it with the current inferior process.
2950If this initialization fails (which could happen because of a version
2951mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
2952will unload @code{libthread_db}, and continue with the next directory.
2953If none of @code{libthread_db} libraries initialize successfully,
2954@value{GDBN} will issue a warning and thread debugging will be disabled.
2955
2956Setting @code{libthread-db-search-path} is currently implemented
2957only on some platforms.
2958
2959@kindex show libthread-db-search-path
2960@item show libthread-db-search-path
2961Display current libthread_db search path.
02d868e8
PP
2962
2963@kindex set debug libthread-db
2964@kindex show debug libthread-db
2965@cindex debugging @code{libthread_db}
2966@item set debug libthread-db
2967@itemx show debug libthread-db
2968Turns on or off display of @code{libthread_db}-related events.
2969Use @code{1} to enable, @code{0} to disable.
17a37d48
PP
2970@end table
2971
6c95b8df
PA
2972@node Forks
2973@section Debugging Forks
c906108c
SS
2974
2975@cindex fork, debugging programs which call
2976@cindex multiple processes
2977@cindex processes, multiple
53a5351d
JM
2978On most systems, @value{GDBN} has no special support for debugging
2979programs which create additional processes using the @code{fork}
2980function. When a program forks, @value{GDBN} will continue to debug the
2981parent process and the child process will run unimpeded. If you have
2982set a breakpoint in any code which the child then executes, the child
2983will get a @code{SIGTRAP} signal which (unless it catches the signal)
2984will cause it to terminate.
c906108c
SS
2985
2986However, if you want to debug the child process there is a workaround
2987which isn't too painful. Put a call to @code{sleep} in the code which
2988the child process executes after the fork. It may be useful to sleep
2989only if a certain environment variable is set, or a certain file exists,
2990so that the delay need not occur when you don't want to run @value{GDBN}
2991on the child. While the child is sleeping, use the @code{ps} program to
2992get its process ID. Then tell @value{GDBN} (a new invocation of
2993@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2994the child process (@pxref{Attach}). From that point on you can debug
c906108c 2995the child process just like any other process which you attached to.
c906108c 2996
b51970ac
DJ
2997On some systems, @value{GDBN} provides support for debugging programs that
2998create additional processes using the @code{fork} or @code{vfork} functions.
2999Currently, the only platforms with this feature are HP-UX (11.x and later
a6b151f1 3000only?) and @sc{gnu}/Linux (kernel version 2.5.60 and later).
c906108c
SS
3001
3002By default, when a program forks, @value{GDBN} will continue to debug
3003the parent process and the child process will run unimpeded.
3004
3005If you want to follow the child process instead of the parent process,
3006use the command @w{@code{set follow-fork-mode}}.
3007
3008@table @code
3009@kindex set follow-fork-mode
3010@item set follow-fork-mode @var{mode}
3011Set the debugger response to a program call of @code{fork} or
3012@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 3013process. The @var{mode} argument can be:
c906108c
SS
3014
3015@table @code
3016@item parent
3017The original process is debugged after a fork. The child process runs
2df3850c 3018unimpeded. This is the default.
c906108c
SS
3019
3020@item child
3021The new process is debugged after a fork. The parent process runs
3022unimpeded.
3023
c906108c
SS
3024@end table
3025
9c16f35a 3026@kindex show follow-fork-mode
c906108c 3027@item show follow-fork-mode
2df3850c 3028Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
3029@end table
3030
5c95884b
MS
3031@cindex debugging multiple processes
3032On Linux, if you want to debug both the parent and child processes, use the
3033command @w{@code{set detach-on-fork}}.
3034
3035@table @code
3036@kindex set detach-on-fork
3037@item set detach-on-fork @var{mode}
3038Tells gdb whether to detach one of the processes after a fork, or
3039retain debugger control over them both.
3040
3041@table @code
3042@item on
3043The child process (or parent process, depending on the value of
3044@code{follow-fork-mode}) will be detached and allowed to run
3045independently. This is the default.
3046
3047@item off
3048Both processes will be held under the control of @value{GDBN}.
3049One process (child or parent, depending on the value of
3050@code{follow-fork-mode}) is debugged as usual, while the other
3051is held suspended.
3052
3053@end table
3054
11310833
NR
3055@kindex show detach-on-fork
3056@item show detach-on-fork
3057Show whether detach-on-fork mode is on/off.
5c95884b
MS
3058@end table
3059
2277426b
PA
3060If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3061will retain control of all forked processes (including nested forks).
3062You can list the forked processes under the control of @value{GDBN} by
3063using the @w{@code{info inferiors}} command, and switch from one fork
6c95b8df
PA
3064to another by using the @code{inferior} command (@pxref{Inferiors and
3065Programs, ,Debugging Multiple Inferiors and Programs}).
5c95884b
MS
3066
3067To quit debugging one of the forked processes, you can either detach
af624141
MS
3068from it by using the @w{@code{detach inferiors}} command (allowing it
3069to run independently), or kill it using the @w{@code{kill inferiors}}
6c95b8df
PA
3070command. @xref{Inferiors and Programs, ,Debugging Multiple Inferiors
3071and Programs}.
5c95884b 3072
c906108c
SS
3073If you ask to debug a child process and a @code{vfork} is followed by an
3074@code{exec}, @value{GDBN} executes the new target up to the first
3075breakpoint in the new target. If you have a breakpoint set on
3076@code{main} in your original program, the breakpoint will also be set on
3077the child process's @code{main}.
3078
2277426b
PA
3079On some systems, when a child process is spawned by @code{vfork}, you
3080cannot debug the child or parent until an @code{exec} call completes.
c906108c
SS
3081
3082If you issue a @code{run} command to @value{GDBN} after an @code{exec}
6c95b8df
PA
3083call executes, the new target restarts. To restart the parent
3084process, use the @code{file} command with the parent executable name
3085as its argument. By default, after an @code{exec} call executes,
3086@value{GDBN} discards the symbols of the previous executable image.
3087You can change this behaviour with the @w{@code{set follow-exec-mode}}
3088command.
3089
3090@table @code
3091@kindex set follow-exec-mode
3092@item set follow-exec-mode @var{mode}
3093
3094Set debugger response to a program call of @code{exec}. An
3095@code{exec} call replaces the program image of a process.
3096
3097@code{follow-exec-mode} can be:
3098
3099@table @code
3100@item new
3101@value{GDBN} creates a new inferior and rebinds the process to this
3102new inferior. The program the process was running before the
3103@code{exec} call can be restarted afterwards by restarting the
3104original inferior.
3105
3106For example:
3107
3108@smallexample
3109(@value{GDBP}) info inferiors
3110(gdb) info inferior
3111 Id Description Executable
3112* 1 <null> prog1
3113(@value{GDBP}) run
3114process 12020 is executing new program: prog2
3115Program exited normally.
3116(@value{GDBP}) info inferiors
3117 Id Description Executable
3118* 2 <null> prog2
3119 1 <null> prog1
3120@end smallexample
3121
3122@item same
3123@value{GDBN} keeps the process bound to the same inferior. The new
3124executable image replaces the previous executable loaded in the
3125inferior. Restarting the inferior after the @code{exec} call, with
3126e.g., the @code{run} command, restarts the executable the process was
3127running after the @code{exec} call. This is the default mode.
3128
3129For example:
3130
3131@smallexample
3132(@value{GDBP}) info inferiors
3133 Id Description Executable
3134* 1 <null> prog1
3135(@value{GDBP}) run
3136process 12020 is executing new program: prog2
3137Program exited normally.
3138(@value{GDBP}) info inferiors
3139 Id Description Executable
3140* 1 <null> prog2
3141@end smallexample
3142
3143@end table
3144@end table
c906108c
SS
3145
3146You can use the @code{catch} command to make @value{GDBN} stop whenever
3147a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
79a6e687 3148Catchpoints, ,Setting Catchpoints}.
c906108c 3149
5c95884b 3150@node Checkpoint/Restart
79a6e687 3151@section Setting a @emph{Bookmark} to Return to Later
5c95884b
MS
3152
3153@cindex checkpoint
3154@cindex restart
3155@cindex bookmark
3156@cindex snapshot of a process
3157@cindex rewind program state
3158
3159On certain operating systems@footnote{Currently, only
3160@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3161program's state, called a @dfn{checkpoint}, and come back to it
3162later.
3163
3164Returning to a checkpoint effectively undoes everything that has
3165happened in the program since the @code{checkpoint} was saved. This
3166includes changes in memory, registers, and even (within some limits)
3167system state. Effectively, it is like going back in time to the
3168moment when the checkpoint was saved.
3169
3170Thus, if you're stepping thru a program and you think you're
3171getting close to the point where things go wrong, you can save
3172a checkpoint. Then, if you accidentally go too far and miss
3173the critical statement, instead of having to restart your program
3174from the beginning, you can just go back to the checkpoint and
3175start again from there.
3176
3177This can be especially useful if it takes a lot of time or
3178steps to reach the point where you think the bug occurs.
3179
3180To use the @code{checkpoint}/@code{restart} method of debugging:
3181
3182@table @code
3183@kindex checkpoint
3184@item checkpoint
3185Save a snapshot of the debugged program's current execution state.
3186The @code{checkpoint} command takes no arguments, but each checkpoint
3187is assigned a small integer id, similar to a breakpoint id.
3188
3189@kindex info checkpoints
3190@item info checkpoints
3191List the checkpoints that have been saved in the current debugging
3192session. For each checkpoint, the following information will be
3193listed:
3194
3195@table @code
3196@item Checkpoint ID
3197@item Process ID
3198@item Code Address
3199@item Source line, or label
3200@end table
3201
3202@kindex restart @var{checkpoint-id}
3203@item restart @var{checkpoint-id}
3204Restore the program state that was saved as checkpoint number
3205@var{checkpoint-id}. All program variables, registers, stack frames
3206etc.@: will be returned to the values that they had when the checkpoint
3207was saved. In essence, gdb will ``wind back the clock'' to the point
3208in time when the checkpoint was saved.
3209
3210Note that breakpoints, @value{GDBN} variables, command history etc.
3211are not affected by restoring a checkpoint. In general, a checkpoint
3212only restores things that reside in the program being debugged, not in
3213the debugger.
3214
b8db102d
MS
3215@kindex delete checkpoint @var{checkpoint-id}
3216@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
3217Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
3218
3219@end table
3220
3221Returning to a previously saved checkpoint will restore the user state
3222of the program being debugged, plus a significant subset of the system
3223(OS) state, including file pointers. It won't ``un-write'' data from
3224a file, but it will rewind the file pointer to the previous location,
3225so that the previously written data can be overwritten. For files
3226opened in read mode, the pointer will also be restored so that the
3227previously read data can be read again.
3228
3229Of course, characters that have been sent to a printer (or other
3230external device) cannot be ``snatched back'', and characters received
3231from eg.@: a serial device can be removed from internal program buffers,
3232but they cannot be ``pushed back'' into the serial pipeline, ready to
3233be received again. Similarly, the actual contents of files that have
3234been changed cannot be restored (at this time).
3235
3236However, within those constraints, you actually can ``rewind'' your
3237program to a previously saved point in time, and begin debugging it
3238again --- and you can change the course of events so as to debug a
3239different execution path this time.
3240
3241@cindex checkpoints and process id
3242Finally, there is one bit of internal program state that will be
3243different when you return to a checkpoint --- the program's process
3244id. Each checkpoint will have a unique process id (or @var{pid}),
3245and each will be different from the program's original @var{pid}.
3246If your program has saved a local copy of its process id, this could
3247potentially pose a problem.
3248
79a6e687 3249@subsection A Non-obvious Benefit of Using Checkpoints
5c95884b
MS
3250
3251On some systems such as @sc{gnu}/Linux, address space randomization
3252is performed on new processes for security reasons. This makes it
3253difficult or impossible to set a breakpoint, or watchpoint, on an
3254absolute address if you have to restart the program, since the
3255absolute location of a symbol will change from one execution to the
3256next.
3257
3258A checkpoint, however, is an @emph{identical} copy of a process.
3259Therefore if you create a checkpoint at (eg.@:) the start of main,
3260and simply return to that checkpoint instead of restarting the
3261process, you can avoid the effects of address randomization and
3262your symbols will all stay in the same place.
3263
6d2ebf8b 3264@node Stopping
c906108c
SS
3265@chapter Stopping and Continuing
3266
3267The principal purposes of using a debugger are so that you can stop your
3268program before it terminates; or so that, if your program runs into
3269trouble, you can investigate and find out why.
3270
7a292a7a
SS
3271Inside @value{GDBN}, your program may stop for any of several reasons,
3272such as a signal, a breakpoint, or reaching a new line after a
3273@value{GDBN} command such as @code{step}. You may then examine and
3274change variables, set new breakpoints or remove old ones, and then
3275continue execution. Usually, the messages shown by @value{GDBN} provide
3276ample explanation of the status of your program---but you can also
3277explicitly request this information at any time.
c906108c
SS
3278
3279@table @code
3280@kindex info program
3281@item info program
3282Display information about the status of your program: whether it is
7a292a7a 3283running or not, what process it is, and why it stopped.
c906108c
SS
3284@end table
3285
3286@menu
3287* Breakpoints:: Breakpoints, watchpoints, and catchpoints
3288* Continuing and Stepping:: Resuming execution
aad1c02c
TT
3289* Skipping Over Functions and Files::
3290 Skipping over functions and files
c906108c 3291* Signals:: Signals
c906108c 3292* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
3293@end menu
3294
6d2ebf8b 3295@node Breakpoints
79a6e687 3296@section Breakpoints, Watchpoints, and Catchpoints
c906108c
SS
3297
3298@cindex breakpoints
3299A @dfn{breakpoint} makes your program stop whenever a certain point in
3300the program is reached. For each breakpoint, you can add conditions to
3301control in finer detail whether your program stops. You can set
3302breakpoints with the @code{break} command and its variants (@pxref{Set
79a6e687 3303Breaks, ,Setting Breakpoints}), to specify the place where your program
c906108c
SS
3304should stop by line number, function name or exact address in the
3305program.
3306
09d4efe1
EZ
3307On some systems, you can set breakpoints in shared libraries before
3308the executable is run. There is a minor limitation on HP-UX systems:
3309you must wait until the executable is run in order to set breakpoints
3310in shared library routines that are not called directly by the program
3311(for example, routines that are arguments in a @code{pthread_create}
3312call).
c906108c
SS
3313
3314@cindex watchpoints
fd60e0df 3315@cindex data breakpoints
c906108c
SS
3316@cindex memory tracing
3317@cindex breakpoint on memory address
3318@cindex breakpoint on variable modification
3319A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 3320when the value of an expression changes. The expression may be a value
0ced0c34 3321of a variable, or it could involve values of one or more variables
fd60e0df
EZ
3322combined by operators, such as @samp{a + b}. This is sometimes called
3323@dfn{data breakpoints}. You must use a different command to set
79a6e687 3324watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
fd60e0df
EZ
3325from that, you can manage a watchpoint like any other breakpoint: you
3326enable, disable, and delete both breakpoints and watchpoints using the
3327same commands.
c906108c
SS
3328
3329You can arrange to have values from your program displayed automatically
3330whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
79a6e687 3331Automatic Display}.
c906108c
SS
3332
3333@cindex catchpoints
3334@cindex breakpoint on events
3335A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 3336when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
3337exception or the loading of a library. As with watchpoints, you use a
3338different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
79a6e687 3339Catchpoints}), but aside from that, you can manage a catchpoint like any
c906108c 3340other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 3341@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
3342
3343@cindex breakpoint numbers
3344@cindex numbers for breakpoints
3345@value{GDBN} assigns a number to each breakpoint, watchpoint, or
3346catchpoint when you create it; these numbers are successive integers
3347starting with one. In many of the commands for controlling various
3348features of breakpoints you use the breakpoint number to say which
3349breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
3350@dfn{disabled}; if disabled, it has no effect on your program until you
3351enable it again.
3352
c5394b80
JM
3353@cindex breakpoint ranges
3354@cindex ranges of breakpoints
3355Some @value{GDBN} commands accept a range of breakpoints on which to
3356operate. A breakpoint range is either a single breakpoint number, like
3357@samp{5}, or two such numbers, in increasing order, separated by a
3358hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
d52fb0e9 3359all breakpoints in that range are operated on.
c5394b80 3360
c906108c
SS
3361@menu
3362* Set Breaks:: Setting breakpoints
3363* Set Watchpoints:: Setting watchpoints
3364* Set Catchpoints:: Setting catchpoints
3365* Delete Breaks:: Deleting breakpoints
3366* Disabling:: Disabling breakpoints
3367* Conditions:: Break conditions
3368* Break Commands:: Breakpoint command lists
e7e0cddf 3369* Dynamic Printf:: Dynamic printf
6149aea9 3370* Save Breakpoints:: How to save breakpoints in a file
62e5f89c 3371* Static Probe Points:: Listing static probe points
d4f3574e 3372* Error in Breakpoints:: ``Cannot insert breakpoints''
79a6e687 3373* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
c906108c
SS
3374@end menu
3375
6d2ebf8b 3376@node Set Breaks
79a6e687 3377@subsection Setting Breakpoints
c906108c 3378
5d161b24 3379@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
3380@c consider in particular declaration with/without initialization.
3381@c
3382@c FIXME 2 is there stuff on this already? break at fun start, already init?
3383
3384@kindex break
41afff9a
EZ
3385@kindex b @r{(@code{break})}
3386@vindex $bpnum@r{, convenience variable}
c906108c
SS
3387@cindex latest breakpoint
3388Breakpoints are set with the @code{break} command (abbreviated
5d161b24 3389@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 3390number of the breakpoint you've set most recently; see @ref{Convenience
79a6e687 3391Vars,, Convenience Variables}, for a discussion of what you can do with
c906108c
SS
3392convenience variables.
3393
c906108c 3394@table @code
2a25a5ba
EZ
3395@item break @var{location}
3396Set a breakpoint at the given @var{location}, which can specify a
3397function name, a line number, or an address of an instruction.
3398(@xref{Specify Location}, for a list of all the possible ways to
3399specify a @var{location}.) The breakpoint will stop your program just
3400before it executes any of the code in the specified @var{location}.
3401
c906108c 3402When using source languages that permit overloading of symbols, such as
2a25a5ba 3403C@t{++}, a function name may refer to more than one possible place to break.
6ba66d6a
JB
3404@xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
3405that situation.
c906108c 3406
45ac276d 3407It is also possible to insert a breakpoint that will stop the program
2c88c651
JB
3408only if a specific thread (@pxref{Thread-Specific Breakpoints})
3409or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
45ac276d 3410
c906108c
SS
3411@item break
3412When called without any arguments, @code{break} sets a breakpoint at
3413the next instruction to be executed in the selected stack frame
3414(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
3415innermost, this makes your program stop as soon as control
3416returns to that frame. This is similar to the effect of a
3417@code{finish} command in the frame inside the selected frame---except
3418that @code{finish} does not leave an active breakpoint. If you use
3419@code{break} without an argument in the innermost frame, @value{GDBN} stops
3420the next time it reaches the current location; this may be useful
3421inside loops.
3422
3423@value{GDBN} normally ignores breakpoints when it resumes execution, until at
3424least one instruction has been executed. If it did not do this, you
3425would be unable to proceed past a breakpoint without first disabling the
3426breakpoint. This rule applies whether or not the breakpoint already
3427existed when your program stopped.
3428
3429@item break @dots{} if @var{cond}
3430Set a breakpoint with condition @var{cond}; evaluate the expression
3431@var{cond} each time the breakpoint is reached, and stop only if the
3432value is nonzero---that is, if @var{cond} evaluates as true.
3433@samp{@dots{}} stands for one of the possible arguments described
3434above (or no argument) specifying where to break. @xref{Conditions,
79a6e687 3435,Break Conditions}, for more information on breakpoint conditions.
c906108c
SS
3436
3437@kindex tbreak
3438@item tbreak @var{args}
3439Set a breakpoint enabled only for one stop. @var{args} are the
3440same as for the @code{break} command, and the breakpoint is set in the same
3441way, but the breakpoint is automatically deleted after the first time your
79a6e687 3442program stops there. @xref{Disabling, ,Disabling Breakpoints}.
c906108c 3443
c906108c 3444@kindex hbreak
ba04e063 3445@cindex hardware breakpoints
c906108c 3446@item hbreak @var{args}
d4f3574e
SS
3447Set a hardware-assisted breakpoint. @var{args} are the same as for the
3448@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
3449breakpoint requires hardware support and some target hardware may not
3450have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
3451debugging, so you can set a breakpoint at an instruction without
3452changing the instruction. This can be used with the new trap-generation
09d4efe1 3453provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
3454will generate traps when a program accesses some data or instruction
3455address that is assigned to the debug registers. However the hardware
3456breakpoint registers can take a limited number of breakpoints. For
3457example, on the DSU, only two data breakpoints can be set at a time, and
3458@value{GDBN} will reject this command if more than two are used. Delete
3459or disable unused hardware breakpoints before setting new ones
79a6e687
BW
3460(@pxref{Disabling, ,Disabling Breakpoints}).
3461@xref{Conditions, ,Break Conditions}.
9c16f35a
EZ
3462For remote targets, you can restrict the number of hardware
3463breakpoints @value{GDBN} will use, see @ref{set remote
3464hardware-breakpoint-limit}.
501eef12 3465
c906108c
SS
3466@kindex thbreak
3467@item thbreak @var{args}
3468Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
3469are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 3470the same way. However, like the @code{tbreak} command,
c906108c
SS
3471the breakpoint is automatically deleted after the
3472first time your program stops there. Also, like the @code{hbreak}
5d161b24 3473command, the breakpoint requires hardware support and some target hardware
79a6e687
BW
3474may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
3475See also @ref{Conditions, ,Break Conditions}.
c906108c
SS
3476
3477@kindex rbreak
3478@cindex regular expression
8bd10a10 3479@cindex breakpoints at functions matching a regexp
c45da7e6 3480@cindex set breakpoints in many functions
c906108c 3481@item rbreak @var{regex}
c906108c 3482Set breakpoints on all functions matching the regular expression
11cf8741
JM
3483@var{regex}. This command sets an unconditional breakpoint on all
3484matches, printing a list of all breakpoints it set. Once these
3485breakpoints are set, they are treated just like the breakpoints set with
3486the @code{break} command. You can delete them, disable them, or make
3487them conditional the same way as any other breakpoint.
3488
3489The syntax of the regular expression is the standard one used with tools
3490like @file{grep}. Note that this is different from the syntax used by
3491shells, so for instance @code{foo*} matches all functions that include
3492an @code{fo} followed by zero or more @code{o}s. There is an implicit
3493@code{.*} leading and trailing the regular expression you supply, so to
3494match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 3495
f7dc1244 3496@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 3497When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
3498breakpoints on overloaded functions that are not members of any special
3499classes.
c906108c 3500
f7dc1244
EZ
3501@cindex set breakpoints on all functions
3502The @code{rbreak} command can be used to set breakpoints in
3503@strong{all} the functions in a program, like this:
3504
3505@smallexample
3506(@value{GDBP}) rbreak .
3507@end smallexample
3508
8bd10a10
CM
3509@item rbreak @var{file}:@var{regex}
3510If @code{rbreak} is called with a filename qualification, it limits
3511the search for functions matching the given regular expression to the
3512specified @var{file}. This can be used, for example, to set breakpoints on
3513every function in a given file:
3514
3515@smallexample
3516(@value{GDBP}) rbreak file.c:.
3517@end smallexample
3518
3519The colon separating the filename qualifier from the regex may
3520optionally be surrounded by spaces.
3521
c906108c
SS
3522@kindex info breakpoints
3523@cindex @code{$_} and @code{info breakpoints}
e5a67952
MS
3524@item info breakpoints @r{[}@var{n}@dots{}@r{]}
3525@itemx info break @r{[}@var{n}@dots{}@r{]}
c906108c 3526Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734 3527not deleted. Optional argument @var{n} means print information only
e5a67952
MS
3528about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
3529For each breakpoint, following columns are printed:
c906108c
SS
3530
3531@table @emph
3532@item Breakpoint Numbers
3533@item Type
3534Breakpoint, watchpoint, or catchpoint.
3535@item Disposition
3536Whether the breakpoint is marked to be disabled or deleted when hit.
3537@item Enabled or Disabled
3538Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
b3db7447 3539that are not enabled.
c906108c 3540@item Address
fe6fbf8b 3541Where the breakpoint is in your program, as a memory address. For a
b3db7447
NR
3542pending breakpoint whose address is not yet known, this field will
3543contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
3544library that has the symbol or line referred by breakpoint is loaded.
3545See below for details. A breakpoint with several locations will
3b784c4f 3546have @samp{<MULTIPLE>} in this field---see below for details.
c906108c
SS
3547@item What
3548Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
3549line number. For a pending breakpoint, the original string passed to
3550the breakpoint command will be listed as it cannot be resolved until
3551the appropriate shared library is loaded in the future.
c906108c
SS
3552@end table
3553
3554@noindent
83364271
LM
3555If a breakpoint is conditional, there are two evaluation modes: ``host'' and
3556``target''. If mode is ``host'', breakpoint condition evaluation is done by
3557@value{GDBN} on the host's side. If it is ``target'', then the condition
3558is evaluated by the target. The @code{info break} command shows
3559the condition on the line following the affected breakpoint, together with
3560its condition evaluation mode in between parentheses.
3561
3562Breakpoint commands, if any, are listed after that. A pending breakpoint is
3563allowed to have a condition specified for it. The condition is not parsed for
3564validity until a shared library is loaded that allows the pending
3565breakpoint to resolve to a valid location.
c906108c
SS
3566
3567@noindent
3568@code{info break} with a breakpoint
3569number @var{n} as argument lists only that breakpoint. The
3570convenience variable @code{$_} and the default examining-address for
3571the @code{x} command are set to the address of the last breakpoint
79a6e687 3572listed (@pxref{Memory, ,Examining Memory}).
c906108c
SS
3573
3574@noindent
3575@code{info break} displays a count of the number of times the breakpoint
3576has been hit. This is especially useful in conjunction with the
3577@code{ignore} command. You can ignore a large number of breakpoint
3578hits, look at the breakpoint info to see how many times the breakpoint
3579was hit, and then run again, ignoring one less than that number. This
3580will get you quickly to the last hit of that breakpoint.
816338b5
SS
3581
3582@noindent
3583For a breakpoints with an enable count (xref) greater than 1,
3584@code{info break} also displays that count.
3585
c906108c
SS
3586@end table
3587
3588@value{GDBN} allows you to set any number of breakpoints at the same place in
3589your program. There is nothing silly or meaningless about this. When
3590the breakpoints are conditional, this is even useful
79a6e687 3591(@pxref{Conditions, ,Break Conditions}).
c906108c 3592
2e9132cc
EZ
3593@cindex multiple locations, breakpoints
3594@cindex breakpoints, multiple locations
fcda367b 3595It is possible that a breakpoint corresponds to several locations
fe6fbf8b
VP
3596in your program. Examples of this situation are:
3597
3598@itemize @bullet
f8eba3c6
TT
3599@item
3600Multiple functions in the program may have the same name.
3601
fe6fbf8b
VP
3602@item
3603For a C@t{++} constructor, the @value{NGCC} compiler generates several
3604instances of the function body, used in different cases.
3605
3606@item
3607For a C@t{++} template function, a given line in the function can
3608correspond to any number of instantiations.
3609
3610@item
3611For an inlined function, a given source line can correspond to
3612several places where that function is inlined.
fe6fbf8b
VP
3613@end itemize
3614
3615In all those cases, @value{GDBN} will insert a breakpoint at all
f8eba3c6 3616the relevant locations.
fe6fbf8b 3617
3b784c4f
EZ
3618A breakpoint with multiple locations is displayed in the breakpoint
3619table using several rows---one header row, followed by one row for
3620each breakpoint location. The header row has @samp{<MULTIPLE>} in the
3621address column. The rows for individual locations contain the actual
3622addresses for locations, and show the functions to which those
3623locations belong. The number column for a location is of the form
fe6fbf8b
VP
3624@var{breakpoint-number}.@var{location-number}.
3625
3626For example:
3b784c4f 3627
fe6fbf8b
VP
3628@smallexample
3629Num Type Disp Enb Address What
36301 breakpoint keep y <MULTIPLE>
3631 stop only if i==1
3632 breakpoint already hit 1 time
36331.1 y 0x080486a2 in void foo<int>() at t.cc:8
36341.2 y 0x080486ca in void foo<double>() at t.cc:8
3635@end smallexample
3636
3637Each location can be individually enabled or disabled by passing
3638@var{breakpoint-number}.@var{location-number} as argument to the
3b784c4f
EZ
3639@code{enable} and @code{disable} commands. Note that you cannot
3640delete the individual locations from the list, you can only delete the
16bfc218 3641entire list of locations that belong to their parent breakpoint (with
3b784c4f
EZ
3642the @kbd{delete @var{num}} command, where @var{num} is the number of
3643the parent breakpoint, 1 in the above example). Disabling or enabling
3644the parent breakpoint (@pxref{Disabling}) affects all of the locations
3645that belong to that breakpoint.
fe6fbf8b 3646
2650777c 3647@cindex pending breakpoints
fe6fbf8b 3648It's quite common to have a breakpoint inside a shared library.
3b784c4f 3649Shared libraries can be loaded and unloaded explicitly,
fe6fbf8b
VP
3650and possibly repeatedly, as the program is executed. To support
3651this use case, @value{GDBN} updates breakpoint locations whenever
3652any shared library is loaded or unloaded. Typically, you would
fcda367b 3653set a breakpoint in a shared library at the beginning of your
fe6fbf8b
VP
3654debugging session, when the library is not loaded, and when the
3655symbols from the library are not available. When you try to set
3656breakpoint, @value{GDBN} will ask you if you want to set
3b784c4f 3657a so called @dfn{pending breakpoint}---breakpoint whose address
fe6fbf8b
VP
3658is not yet resolved.
3659
3660After the program is run, whenever a new shared library is loaded,
3661@value{GDBN} reevaluates all the breakpoints. When a newly loaded
3662shared library contains the symbol or line referred to by some
3663pending breakpoint, that breakpoint is resolved and becomes an
3664ordinary breakpoint. When a library is unloaded, all breakpoints
3665that refer to its symbols or source lines become pending again.
3666
3667This logic works for breakpoints with multiple locations, too. For
3668example, if you have a breakpoint in a C@t{++} template function, and
3669a newly loaded shared library has an instantiation of that template,
3670a new location is added to the list of locations for the breakpoint.
3671
3672Except for having unresolved address, pending breakpoints do not
3673differ from regular breakpoints. You can set conditions or commands,
3674enable and disable them and perform other breakpoint operations.
3675
3676@value{GDBN} provides some additional commands for controlling what
3677happens when the @samp{break} command cannot resolve breakpoint
3678address specification to an address:
dd79a6cf
JJ
3679
3680@kindex set breakpoint pending
3681@kindex show breakpoint pending
3682@table @code
3683@item set breakpoint pending auto
3684This is the default behavior. When @value{GDBN} cannot find the breakpoint
3685location, it queries you whether a pending breakpoint should be created.
3686
3687@item set breakpoint pending on
3688This indicates that an unrecognized breakpoint location should automatically
3689result in a pending breakpoint being created.
3690
3691@item set breakpoint pending off
3692This indicates that pending breakpoints are not to be created. Any
3693unrecognized breakpoint location results in an error. This setting does
3694not affect any pending breakpoints previously created.
3695
3696@item show breakpoint pending
3697Show the current behavior setting for creating pending breakpoints.
3698@end table
2650777c 3699
fe6fbf8b
VP
3700The settings above only affect the @code{break} command and its
3701variants. Once breakpoint is set, it will be automatically updated
3702as shared libraries are loaded and unloaded.
2650777c 3703
765dc015
VP
3704@cindex automatic hardware breakpoints
3705For some targets, @value{GDBN} can automatically decide if hardware or
3706software breakpoints should be used, depending on whether the
3707breakpoint address is read-only or read-write. This applies to
3708breakpoints set with the @code{break} command as well as to internal
3709breakpoints set by commands like @code{next} and @code{finish}. For
fcda367b 3710breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
765dc015
VP
3711breakpoints.
3712
3713You can control this automatic behaviour with the following commands::
3714
3715@kindex set breakpoint auto-hw
3716@kindex show breakpoint auto-hw
3717@table @code
3718@item set breakpoint auto-hw on
3719This is the default behavior. When @value{GDBN} sets a breakpoint, it
3720will try to use the target memory map to decide if software or hardware
3721breakpoint must be used.
3722
3723@item set breakpoint auto-hw off
3724This indicates @value{GDBN} should not automatically select breakpoint
3725type. If the target provides a memory map, @value{GDBN} will warn when
3726trying to set software breakpoint at a read-only address.
3727@end table
3728
74960c60
VP
3729@value{GDBN} normally implements breakpoints by replacing the program code
3730at the breakpoint address with a special instruction, which, when
3731executed, given control to the debugger. By default, the program
3732code is so modified only when the program is resumed. As soon as
3733the program stops, @value{GDBN} restores the original instructions. This
3734behaviour guards against leaving breakpoints inserted in the
3735target should gdb abrubptly disconnect. However, with slow remote
3736targets, inserting and removing breakpoint can reduce the performance.
3737This behavior can be controlled with the following commands::
3738
3739@kindex set breakpoint always-inserted
3740@kindex show breakpoint always-inserted
3741@table @code
3742@item set breakpoint always-inserted off
33e5cbd6
PA
3743All breakpoints, including newly added by the user, are inserted in
3744the target only when the target is resumed. All breakpoints are
3745removed from the target when it stops.
74960c60
VP
3746
3747@item set breakpoint always-inserted on
3748Causes all breakpoints to be inserted in the target at all times. If
3749the user adds a new breakpoint, or changes an existing breakpoint, the
3750breakpoints in the target are updated immediately. A breakpoint is
3751removed from the target only when breakpoint itself is removed.
33e5cbd6
PA
3752
3753@cindex non-stop mode, and @code{breakpoint always-inserted}
3754@item set breakpoint always-inserted auto
3755This is the default mode. If @value{GDBN} is controlling the inferior
3756in non-stop mode (@pxref{Non-Stop Mode}), gdb behaves as if
3757@code{breakpoint always-inserted} mode is on. If @value{GDBN} is
3758controlling the inferior in all-stop mode, @value{GDBN} behaves as if
3759@code{breakpoint always-inserted} mode is off.
74960c60 3760@end table
765dc015 3761
83364271
LM
3762@value{GDBN} handles conditional breakpoints by evaluating these conditions
3763when a breakpoint breaks. If the condition is true, then the process being
3764debugged stops, otherwise the process is resumed.
3765
3766If the target supports evaluating conditions on its end, @value{GDBN} may
3767download the breakpoint, together with its conditions, to it.
3768
3769This feature can be controlled via the following commands:
3770
3771@kindex set breakpoint condition-evaluation
3772@kindex show breakpoint condition-evaluation
3773@table @code
3774@item set breakpoint condition-evaluation host
3775This option commands @value{GDBN} to evaluate the breakpoint
3776conditions on the host's side. Unconditional breakpoints are sent to
3777the target which in turn receives the triggers and reports them back to GDB
3778for condition evaluation. This is the standard evaluation mode.
3779
3780@item set breakpoint condition-evaluation target
3781This option commands @value{GDBN} to download breakpoint conditions
3782to the target at the moment of their insertion. The target
3783is responsible for evaluating the conditional expression and reporting
3784breakpoint stop events back to @value{GDBN} whenever the condition
3785is true. Due to limitations of target-side evaluation, some conditions
3786cannot be evaluated there, e.g., conditions that depend on local data
3787that is only known to the host. Examples include
3788conditional expressions involving convenience variables, complex types
3789that cannot be handled by the agent expression parser and expressions
3790that are too long to be sent over to the target, specially when the
3791target is a remote system. In these cases, the conditions will be
3792evaluated by @value{GDBN}.
3793
3794@item set breakpoint condition-evaluation auto
3795This is the default mode. If the target supports evaluating breakpoint
3796conditions on its end, @value{GDBN} will download breakpoint conditions to
3797the target (limitations mentioned previously apply). If the target does
3798not support breakpoint condition evaluation, then @value{GDBN} will fallback
3799to evaluating all these conditions on the host's side.
3800@end table
3801
3802
c906108c
SS
3803@cindex negative breakpoint numbers
3804@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
3805@value{GDBN} itself sometimes sets breakpoints in your program for
3806special purposes, such as proper handling of @code{longjmp} (in C
3807programs). These internal breakpoints are assigned negative numbers,
3808starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 3809You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 3810@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
3811
3812
6d2ebf8b 3813@node Set Watchpoints
79a6e687 3814@subsection Setting Watchpoints
c906108c
SS
3815
3816@cindex setting watchpoints
c906108c
SS
3817You can use a watchpoint to stop execution whenever the value of an
3818expression changes, without having to predict a particular place where
fd60e0df
EZ
3819this may happen. (This is sometimes called a @dfn{data breakpoint}.)
3820The expression may be as simple as the value of a single variable, or
3821as complex as many variables combined by operators. Examples include:
3822
3823@itemize @bullet
3824@item
3825A reference to the value of a single variable.
3826
3827@item
3828An address cast to an appropriate data type. For example,
3829@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
3830address (assuming an @code{int} occupies 4 bytes).
3831
3832@item
3833An arbitrarily complex expression, such as @samp{a*b + c/d}. The
3834expression can use any operators valid in the program's native
3835language (@pxref{Languages}).
3836@end itemize
c906108c 3837
fa4727a6
DJ
3838You can set a watchpoint on an expression even if the expression can
3839not be evaluated yet. For instance, you can set a watchpoint on
3840@samp{*global_ptr} before @samp{global_ptr} is initialized.
3841@value{GDBN} will stop when your program sets @samp{global_ptr} and
3842the expression produces a valid value. If the expression becomes
3843valid in some other way than changing a variable (e.g.@: if the memory
3844pointed to by @samp{*global_ptr} becomes readable as the result of a
3845@code{malloc} call), @value{GDBN} may not stop until the next time
3846the expression changes.
3847
82f2d802
EZ
3848@cindex software watchpoints
3849@cindex hardware watchpoints
c906108c 3850Depending on your system, watchpoints may be implemented in software or
2df3850c 3851hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
3852program and testing the variable's value each time, which is hundreds of
3853times slower than normal execution. (But this may still be worth it, to
3854catch errors where you have no clue what part of your program is the
3855culprit.)
3856
37e4754d 3857On some systems, such as HP-UX, PowerPC, @sc{gnu}/Linux and most other
82f2d802
EZ
3858x86-based targets, @value{GDBN} includes support for hardware
3859watchpoints, which do not slow down the running of your program.
c906108c
SS
3860
3861@table @code
3862@kindex watch
9c06b0b4 3863@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
fd60e0df
EZ
3864Set a watchpoint for an expression. @value{GDBN} will break when the
3865expression @var{expr} is written into by the program and its value
3866changes. The simplest (and the most popular) use of this command is
3867to watch the value of a single variable:
3868
3869@smallexample
3870(@value{GDBP}) watch foo
3871@end smallexample
c906108c 3872
d8b2a693 3873If the command includes a @code{@r{[}thread @var{threadnum}@r{]}}
9c06b0b4 3874argument, @value{GDBN} breaks only when the thread identified by
d8b2a693
JB
3875@var{threadnum} changes the value of @var{expr}. If any other threads
3876change the value of @var{expr}, @value{GDBN} will not break. Note
3877that watchpoints restricted to a single thread in this way only work
3878with Hardware Watchpoints.
3879
06a64a0b
TT
3880Ordinarily a watchpoint respects the scope of variables in @var{expr}
3881(see below). The @code{-location} argument tells @value{GDBN} to
3882instead watch the memory referred to by @var{expr}. In this case,
3883@value{GDBN} will evaluate @var{expr}, take the address of the result,
3884and watch the memory at that address. The type of the result is used
3885to determine the size of the watched memory. If the expression's
3886result does not have an address, then @value{GDBN} will print an
3887error.
3888
9c06b0b4
TJB
3889The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
3890of masked watchpoints, if the current architecture supports this
3891feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
3892Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
3893to an address to watch. The mask specifies that some bits of an address
3894(the bits which are reset in the mask) should be ignored when matching
3895the address accessed by the inferior against the watchpoint address.
3896Thus, a masked watchpoint watches many addresses simultaneously---those
3897addresses whose unmasked bits are identical to the unmasked bits in the
3898watchpoint address. The @code{mask} argument implies @code{-location}.
3899Examples:
3900
3901@smallexample
3902(@value{GDBP}) watch foo mask 0xffff00ff
3903(@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
3904@end smallexample
3905
c906108c 3906@kindex rwatch
9c06b0b4 3907@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
3908Set a watchpoint that will break when the value of @var{expr} is read
3909by the program.
c906108c
SS
3910
3911@kindex awatch
9c06b0b4 3912@item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
3913Set a watchpoint that will break when @var{expr} is either read from
3914or written into by the program.
c906108c 3915
e5a67952
MS
3916@kindex info watchpoints @r{[}@var{n}@dots{}@r{]}
3917@item info watchpoints @r{[}@var{n}@dots{}@r{]}
d77f58be
SS
3918This command prints a list of watchpoints, using the same format as
3919@code{info break} (@pxref{Set Breaks}).
c906108c
SS
3920@end table
3921
65d79d4b
SDJ
3922If you watch for a change in a numerically entered address you need to
3923dereference it, as the address itself is just a constant number which will
3924never change. @value{GDBN} refuses to create a watchpoint that watches
3925a never-changing value:
3926
3927@smallexample
3928(@value{GDBP}) watch 0x600850
3929Cannot watch constant value 0x600850.
3930(@value{GDBP}) watch *(int *) 0x600850
3931Watchpoint 1: *(int *) 6293584
3932@end smallexample
3933
c906108c
SS
3934@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
3935watchpoints execute very quickly, and the debugger reports a change in
3936value at the exact instruction where the change occurs. If @value{GDBN}
3937cannot set a hardware watchpoint, it sets a software watchpoint, which
3938executes more slowly and reports the change in value at the next
82f2d802
EZ
3939@emph{statement}, not the instruction, after the change occurs.
3940
82f2d802
EZ
3941@cindex use only software watchpoints
3942You can force @value{GDBN} to use only software watchpoints with the
3943@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
3944zero, @value{GDBN} will never try to use hardware watchpoints, even if
3945the underlying system supports them. (Note that hardware-assisted
3946watchpoints that were set @emph{before} setting
3947@code{can-use-hw-watchpoints} to zero will still use the hardware
d3e8051b 3948mechanism of watching expression values.)
c906108c 3949
9c16f35a
EZ
3950@table @code
3951@item set can-use-hw-watchpoints
3952@kindex set can-use-hw-watchpoints
3953Set whether or not to use hardware watchpoints.
3954
3955@item show can-use-hw-watchpoints
3956@kindex show can-use-hw-watchpoints
3957Show the current mode of using hardware watchpoints.
3958@end table
3959
3960For remote targets, you can restrict the number of hardware
3961watchpoints @value{GDBN} will use, see @ref{set remote
3962hardware-breakpoint-limit}.
3963
c906108c
SS
3964When you issue the @code{watch} command, @value{GDBN} reports
3965
474c8240 3966@smallexample
c906108c 3967Hardware watchpoint @var{num}: @var{expr}
474c8240 3968@end smallexample
c906108c
SS
3969
3970@noindent
3971if it was able to set a hardware watchpoint.
3972
7be570e7
JM
3973Currently, the @code{awatch} and @code{rwatch} commands can only set
3974hardware watchpoints, because accesses to data that don't change the
3975value of the watched expression cannot be detected without examining
3976every instruction as it is being executed, and @value{GDBN} does not do
3977that currently. If @value{GDBN} finds that it is unable to set a
3978hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3979will print a message like this:
3980
3981@smallexample
3982Expression cannot be implemented with read/access watchpoint.
3983@end smallexample
3984
3985Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
3986data type of the watched expression is wider than what a hardware
3987watchpoint on the target machine can handle. For example, some systems
3988can only watch regions that are up to 4 bytes wide; on such systems you
3989cannot set hardware watchpoints for an expression that yields a
3990double-precision floating-point number (which is typically 8 bytes
3991wide). As a work-around, it might be possible to break the large region
3992into a series of smaller ones and watch them with separate watchpoints.
3993
3994If you set too many hardware watchpoints, @value{GDBN} might be unable
3995to insert all of them when you resume the execution of your program.
3996Since the precise number of active watchpoints is unknown until such
3997time as the program is about to be resumed, @value{GDBN} might not be
3998able to warn you about this when you set the watchpoints, and the
3999warning will be printed only when the program is resumed:
4000
4001@smallexample
4002Hardware watchpoint @var{num}: Could not insert watchpoint
4003@end smallexample
4004
4005@noindent
4006If this happens, delete or disable some of the watchpoints.
4007
fd60e0df
EZ
4008Watching complex expressions that reference many variables can also
4009exhaust the resources available for hardware-assisted watchpoints.
4010That's because @value{GDBN} needs to watch every variable in the
4011expression with separately allocated resources.
4012
c906108c 4013If you call a function interactively using @code{print} or @code{call},
2df3850c 4014any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
4015kind of breakpoint or the call completes.
4016
7be570e7
JM
4017@value{GDBN} automatically deletes watchpoints that watch local
4018(automatic) variables, or expressions that involve such variables, when
4019they go out of scope, that is, when the execution leaves the block in
4020which these variables were defined. In particular, when the program
4021being debugged terminates, @emph{all} local variables go out of scope,
4022and so only watchpoints that watch global variables remain set. If you
4023rerun the program, you will need to set all such watchpoints again. One
4024way of doing that would be to set a code breakpoint at the entry to the
4025@code{main} function and when it breaks, set all the watchpoints.
4026
c906108c
SS
4027@cindex watchpoints and threads
4028@cindex threads and watchpoints
d983da9c
DJ
4029In multi-threaded programs, watchpoints will detect changes to the
4030watched expression from every thread.
4031
4032@quotation
4033@emph{Warning:} In multi-threaded programs, software watchpoints
53a5351d
JM
4034have only limited usefulness. If @value{GDBN} creates a software
4035watchpoint, it can only watch the value of an expression @emph{in a
4036single thread}. If you are confident that the expression can only
4037change due to the current thread's activity (and if you are also
4038confident that no other thread can become current), then you can use
4039software watchpoints as usual. However, @value{GDBN} may not notice
4040when a non-current thread's activity changes the expression. (Hardware
4041watchpoints, in contrast, watch an expression in all threads.)
c906108c 4042@end quotation
c906108c 4043
501eef12
AC
4044@xref{set remote hardware-watchpoint-limit}.
4045
6d2ebf8b 4046@node Set Catchpoints
79a6e687 4047@subsection Setting Catchpoints
d4f3574e 4048@cindex catchpoints, setting
c906108c
SS
4049@cindex exception handlers
4050@cindex event handling
4051
4052You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 4053kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
4054shared library. Use the @code{catch} command to set a catchpoint.
4055
4056@table @code
4057@kindex catch
4058@item catch @var{event}
4059Stop when @var{event} occurs. @var{event} can be any of the following:
4060@table @code
4061@item throw
4644b6e3 4062@cindex stop on C@t{++} exceptions
b37052ae 4063The throwing of a C@t{++} exception.
c906108c
SS
4064
4065@item catch
b37052ae 4066The catching of a C@t{++} exception.
c906108c 4067
8936fcda
JB
4068@item exception
4069@cindex Ada exception catching
4070@cindex catch Ada exceptions
4071An Ada exception being raised. If an exception name is specified
4072at the end of the command (eg @code{catch exception Program_Error}),
4073the debugger will stop only when this specific exception is raised.
4074Otherwise, the debugger stops execution when any Ada exception is raised.
4075
87f67dba
JB
4076When inserting an exception catchpoint on a user-defined exception whose
4077name is identical to one of the exceptions defined by the language, the
4078fully qualified name must be used as the exception name. Otherwise,
4079@value{GDBN} will assume that it should stop on the pre-defined exception
4080rather than the user-defined one. For instance, assuming an exception
4081called @code{Constraint_Error} is defined in package @code{Pck}, then
4082the command to use to catch such exceptions is @kbd{catch exception
4083Pck.Constraint_Error}.
4084
8936fcda
JB
4085@item exception unhandled
4086An exception that was raised but is not handled by the program.
4087
4088@item assert
4089A failed Ada assertion.
4090
c906108c 4091@item exec
4644b6e3 4092@cindex break on fork/exec
5ee187d7
DJ
4093A call to @code{exec}. This is currently only available for HP-UX
4094and @sc{gnu}/Linux.
c906108c 4095
a96d9b2e 4096@item syscall
ee8e71d4 4097@itemx syscall @r{[}@var{name} @r{|} @var{number}@r{]} @dots{}
a96d9b2e
SDJ
4098@cindex break on a system call.
4099A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
4100syscall is a mechanism for application programs to request a service
4101from the operating system (OS) or one of the OS system services.
4102@value{GDBN} can catch some or all of the syscalls issued by the
4103debuggee, and show the related information for each syscall. If no
4104argument is specified, calls to and returns from all system calls
4105will be caught.
4106
4107@var{name} can be any system call name that is valid for the
4108underlying OS. Just what syscalls are valid depends on the OS. On
4109GNU and Unix systems, you can find the full list of valid syscall
4110names on @file{/usr/include/asm/unistd.h}.
4111
4112@c For MS-Windows, the syscall names and the corresponding numbers
4113@c can be found, e.g., on this URL:
4114@c http://www.metasploit.com/users/opcode/syscalls.html
4115@c but we don't support Windows syscalls yet.
4116
4117Normally, @value{GDBN} knows in advance which syscalls are valid for
4118each OS, so you can use the @value{GDBN} command-line completion
4119facilities (@pxref{Completion,, command completion}) to list the
4120available choices.
4121
4122You may also specify the system call numerically. A syscall's
4123number is the value passed to the OS's syscall dispatcher to
4124identify the requested service. When you specify the syscall by its
4125name, @value{GDBN} uses its database of syscalls to convert the name
4126into the corresponding numeric code, but using the number directly
4127may be useful if @value{GDBN}'s database does not have the complete
4128list of syscalls on your system (e.g., because @value{GDBN} lags
4129behind the OS upgrades).
4130
4131The example below illustrates how this command works if you don't provide
4132arguments to it:
4133
4134@smallexample
4135(@value{GDBP}) catch syscall
4136Catchpoint 1 (syscall)
4137(@value{GDBP}) r
4138Starting program: /tmp/catch-syscall
4139
4140Catchpoint 1 (call to syscall 'close'), \
4141 0xffffe424 in __kernel_vsyscall ()
4142(@value{GDBP}) c
4143Continuing.
4144
4145Catchpoint 1 (returned from syscall 'close'), \
4146 0xffffe424 in __kernel_vsyscall ()
4147(@value{GDBP})
4148@end smallexample
4149
4150Here is an example of catching a system call by name:
4151
4152@smallexample
4153(@value{GDBP}) catch syscall chroot
4154Catchpoint 1 (syscall 'chroot' [61])
4155(@value{GDBP}) r
4156Starting program: /tmp/catch-syscall
4157
4158Catchpoint 1 (call to syscall 'chroot'), \
4159 0xffffe424 in __kernel_vsyscall ()
4160(@value{GDBP}) c
4161Continuing.
4162
4163Catchpoint 1 (returned from syscall 'chroot'), \
4164 0xffffe424 in __kernel_vsyscall ()
4165(@value{GDBP})
4166@end smallexample
4167
4168An example of specifying a system call numerically. In the case
4169below, the syscall number has a corresponding entry in the XML
4170file, so @value{GDBN} finds its name and prints it:
4171
4172@smallexample
4173(@value{GDBP}) catch syscall 252
4174Catchpoint 1 (syscall(s) 'exit_group')
4175(@value{GDBP}) r
4176Starting program: /tmp/catch-syscall
4177
4178Catchpoint 1 (call to syscall 'exit_group'), \
4179 0xffffe424 in __kernel_vsyscall ()
4180(@value{GDBP}) c
4181Continuing.
4182
4183Program exited normally.
4184(@value{GDBP})
4185@end smallexample
4186
4187However, there can be situations when there is no corresponding name
4188in XML file for that syscall number. In this case, @value{GDBN} prints
4189a warning message saying that it was not able to find the syscall name,
4190but the catchpoint will be set anyway. See the example below:
4191
4192@smallexample
4193(@value{GDBP}) catch syscall 764
4194warning: The number '764' does not represent a known syscall.
4195Catchpoint 2 (syscall 764)
4196(@value{GDBP})
4197@end smallexample
4198
4199If you configure @value{GDBN} using the @samp{--without-expat} option,
4200it will not be able to display syscall names. Also, if your
4201architecture does not have an XML file describing its system calls,
4202you will not be able to see the syscall names. It is important to
4203notice that these two features are used for accessing the syscall
4204name database. In either case, you will see a warning like this:
4205
4206@smallexample
4207(@value{GDBP}) catch syscall
4208warning: Could not open "syscalls/i386-linux.xml"
4209warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
4210GDB will not be able to display syscall names.
4211Catchpoint 1 (syscall)
4212(@value{GDBP})
4213@end smallexample
4214
4215Of course, the file name will change depending on your architecture and system.
4216
4217Still using the example above, you can also try to catch a syscall by its
4218number. In this case, you would see something like:
4219
4220@smallexample
4221(@value{GDBP}) catch syscall 252
4222Catchpoint 1 (syscall(s) 252)
4223@end smallexample
4224
4225Again, in this case @value{GDBN} would not be able to display syscall's names.
4226
c906108c 4227@item fork
5ee187d7
DJ
4228A call to @code{fork}. This is currently only available for HP-UX
4229and @sc{gnu}/Linux.
c906108c
SS
4230
4231@item vfork
5ee187d7
DJ
4232A call to @code{vfork}. This is currently only available for HP-UX
4233and @sc{gnu}/Linux.
c906108c 4234
edcc5120
TT
4235@item load @r{[}regexp@r{]}
4236@itemx unload @r{[}regexp@r{]}
4237The loading or unloading of a shared library. If @var{regexp} is
4238given, then the catchpoint will stop only if the regular expression
4239matches one of the affected libraries.
4240
ab04a2af
TT
4241@item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
4242The delivery of a signal.
4243
4244With no arguments, this catchpoint will catch any signal that is not
4245used internally by @value{GDBN}, specifically, all signals except
4246@samp{SIGTRAP} and @samp{SIGINT}.
4247
4248With the argument @samp{all}, all signals, including those used by
4249@value{GDBN}, will be caught. This argument cannot be used with other
4250signal names.
4251
4252Otherwise, the arguments are a list of signal names as given to
4253@code{handle} (@pxref{Signals}). Only signals specified in this list
4254will be caught.
4255
4256One reason that @code{catch signal} can be more useful than
4257@code{handle} is that you can attach commands and conditions to the
4258catchpoint.
4259
4260When a signal is caught by a catchpoint, the signal's @code{stop} and
4261@code{print} settings, as specified by @code{handle}, are ignored.
4262However, whether the signal is still delivered to the inferior depends
4263on the @code{pass} setting; this can be changed in the catchpoint's
4264commands.
4265
c906108c
SS
4266@end table
4267
4268@item tcatch @var{event}
4269Set a catchpoint that is enabled only for one stop. The catchpoint is
4270automatically deleted after the first time the event is caught.
4271
4272@end table
4273
4274Use the @code{info break} command to list the current catchpoints.
4275
b37052ae 4276There are currently some limitations to C@t{++} exception handling
c906108c
SS
4277(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
4278
4279@itemize @bullet
4280@item
4281If you call a function interactively, @value{GDBN} normally returns
4282control to you when the function has finished executing. If the call
4283raises an exception, however, the call may bypass the mechanism that
4284returns control to you and cause your program either to abort or to
4285simply continue running until it hits a breakpoint, catches a signal
4286that @value{GDBN} is listening for, or exits. This is the case even if
4287you set a catchpoint for the exception; catchpoints on exceptions are
4288disabled within interactive calls.
4289
4290@item
4291You cannot raise an exception interactively.
4292
4293@item
4294You cannot install an exception handler interactively.
4295@end itemize
4296
4297@cindex raise exceptions
4298Sometimes @code{catch} is not the best way to debug exception handling:
4299if you need to know exactly where an exception is raised, it is better to
4300stop @emph{before} the exception handler is called, since that way you
4301can see the stack before any unwinding takes place. If you set a
4302breakpoint in an exception handler instead, it may not be easy to find
4303out where the exception was raised.
4304
4305To stop just before an exception handler is called, you need some
b37052ae 4306knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
4307raised by calling a library function named @code{__raise_exception}
4308which has the following ANSI C interface:
4309
474c8240 4310@smallexample
c906108c 4311 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
4312 @var{id} is the exception identifier. */
4313 void __raise_exception (void **addr, void *id);
474c8240 4314@end smallexample
c906108c
SS
4315
4316@noindent
4317To make the debugger catch all exceptions before any stack
4318unwinding takes place, set a breakpoint on @code{__raise_exception}
79a6e687 4319(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Exceptions}).
c906108c 4320
79a6e687 4321With a conditional breakpoint (@pxref{Conditions, ,Break Conditions})
c906108c
SS
4322that depends on the value of @var{id}, you can stop your program when
4323a specific exception is raised. You can use multiple conditional
4324breakpoints to stop your program when any of a number of exceptions are
4325raised.
4326
4327
6d2ebf8b 4328@node Delete Breaks
79a6e687 4329@subsection Deleting Breakpoints
c906108c
SS
4330
4331@cindex clearing breakpoints, watchpoints, catchpoints
4332@cindex deleting breakpoints, watchpoints, catchpoints
4333It is often necessary to eliminate a breakpoint, watchpoint, or
4334catchpoint once it has done its job and you no longer want your program
4335to stop there. This is called @dfn{deleting} the breakpoint. A
4336breakpoint that has been deleted no longer exists; it is forgotten.
4337
4338With the @code{clear} command you can delete breakpoints according to
4339where they are in your program. With the @code{delete} command you can
4340delete individual breakpoints, watchpoints, or catchpoints by specifying
4341their breakpoint numbers.
4342
4343It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
4344automatically ignores breakpoints on the first instruction to be executed
4345when you continue execution without changing the execution address.
4346
4347@table @code
4348@kindex clear
4349@item clear
4350Delete any breakpoints at the next instruction to be executed in the
79a6e687 4351selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
c906108c
SS
4352the innermost frame is selected, this is a good way to delete a
4353breakpoint where your program just stopped.
4354
2a25a5ba
EZ
4355@item clear @var{location}
4356Delete any breakpoints set at the specified @var{location}.
4357@xref{Specify Location}, for the various forms of @var{location}; the
4358most useful ones are listed below:
4359
4360@table @code
c906108c
SS
4361@item clear @var{function}
4362@itemx clear @var{filename}:@var{function}
09d4efe1 4363Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
4364
4365@item clear @var{linenum}
4366@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
4367Delete any breakpoints set at or within the code of the specified
4368@var{linenum} of the specified @var{filename}.
2a25a5ba 4369@end table
c906108c
SS
4370
4371@cindex delete breakpoints
4372@kindex delete
41afff9a 4373@kindex d @r{(@code{delete})}
c5394b80
JM
4374@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4375Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
4376ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
4377breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
4378confirm off}). You can abbreviate this command as @code{d}.
4379@end table
4380
6d2ebf8b 4381@node Disabling
79a6e687 4382@subsection Disabling Breakpoints
c906108c 4383
4644b6e3 4384@cindex enable/disable a breakpoint
c906108c
SS
4385Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
4386prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
4387it had been deleted, but remembers the information on the breakpoint so
4388that you can @dfn{enable} it again later.
4389
4390You disable and enable breakpoints, watchpoints, and catchpoints with
d77f58be
SS
4391the @code{enable} and @code{disable} commands, optionally specifying
4392one or more breakpoint numbers as arguments. Use @code{info break} to
4393print a list of all breakpoints, watchpoints, and catchpoints if you
4394do not know which numbers to use.
c906108c 4395
3b784c4f
EZ
4396Disabling and enabling a breakpoint that has multiple locations
4397affects all of its locations.
4398
816338b5
SS
4399A breakpoint, watchpoint, or catchpoint can have any of several
4400different states of enablement:
c906108c
SS
4401
4402@itemize @bullet
4403@item
4404Enabled. The breakpoint stops your program. A breakpoint set
4405with the @code{break} command starts out in this state.
4406@item
4407Disabled. The breakpoint has no effect on your program.
4408@item
4409Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 4410disabled.
c906108c 4411@item
816338b5
SS
4412Enabled for a count. The breakpoint stops your program for the next
4413N times, then becomes disabled.
4414@item
c906108c 4415Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
4416immediately after it does so it is deleted permanently. A breakpoint
4417set with the @code{tbreak} command starts out in this state.
c906108c
SS
4418@end itemize
4419
4420You can use the following commands to enable or disable breakpoints,
4421watchpoints, and catchpoints:
4422
4423@table @code
c906108c 4424@kindex disable
41afff9a 4425@kindex dis @r{(@code{disable})}
c5394b80 4426@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4427Disable the specified breakpoints---or all breakpoints, if none are
4428listed. A disabled breakpoint has no effect but is not forgotten. All
4429options such as ignore-counts, conditions and commands are remembered in
4430case the breakpoint is enabled again later. You may abbreviate
4431@code{disable} as @code{dis}.
4432
c906108c 4433@kindex enable
c5394b80 4434@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4435Enable the specified breakpoints (or all defined breakpoints). They
4436become effective once again in stopping your program.
4437
c5394b80 4438@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
4439Enable the specified breakpoints temporarily. @value{GDBN} disables any
4440of these breakpoints immediately after stopping your program.
4441
816338b5
SS
4442@item enable @r{[}breakpoints@r{]} count @var{count} @var{range}@dots{}
4443Enable the specified breakpoints temporarily. @value{GDBN} records
4444@var{count} with each of the specified breakpoints, and decrements a
4445breakpoint's count when it is hit. When any count reaches 0,
4446@value{GDBN} disables that breakpoint. If a breakpoint has an ignore
4447count (@pxref{Conditions, ,Break Conditions}), that will be
4448decremented to 0 before @var{count} is affected.
4449
c5394b80 4450@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
4451Enable the specified breakpoints to work once, then die. @value{GDBN}
4452deletes any of these breakpoints as soon as your program stops there.
09d4efe1 4453Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
4454@end table
4455
d4f3574e
SS
4456@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
4457@c confusing: tbreak is also initially enabled.
c906108c 4458Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
79a6e687 4459,Setting Breakpoints}), breakpoints that you set are initially enabled;
c906108c
SS
4460subsequently, they become disabled or enabled only when you use one of
4461the commands above. (The command @code{until} can set and delete a
4462breakpoint of its own, but it does not change the state of your other
4463breakpoints; see @ref{Continuing and Stepping, ,Continuing and
79a6e687 4464Stepping}.)
c906108c 4465
6d2ebf8b 4466@node Conditions
79a6e687 4467@subsection Break Conditions
c906108c
SS
4468@cindex conditional breakpoints
4469@cindex breakpoint conditions
4470
4471@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 4472@c in particular for a watchpoint?
c906108c
SS
4473The simplest sort of breakpoint breaks every time your program reaches a
4474specified place. You can also specify a @dfn{condition} for a
4475breakpoint. A condition is just a Boolean expression in your
4476programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
4477a condition evaluates the expression each time your program reaches it,
4478and your program stops only if the condition is @emph{true}.
4479
4480This is the converse of using assertions for program validation; in that
4481situation, you want to stop when the assertion is violated---that is,
4482when the condition is false. In C, if you want to test an assertion expressed
4483by the condition @var{assert}, you should set the condition
4484@samp{! @var{assert}} on the appropriate breakpoint.
4485
4486Conditions are also accepted for watchpoints; you may not need them,
4487since a watchpoint is inspecting the value of an expression anyhow---but
4488it might be simpler, say, to just set a watchpoint on a variable name,
4489and specify a condition that tests whether the new value is an interesting
4490one.
4491
4492Break conditions can have side effects, and may even call functions in
4493your program. This can be useful, for example, to activate functions
4494that log program progress, or to use your own print functions to
99e008fe 4495format special data structures. The effects are completely predictable
c906108c
SS
4496unless there is another enabled breakpoint at the same address. (In
4497that case, @value{GDBN} might see the other breakpoint first and stop your
4498program without checking the condition of this one.) Note that
d4f3574e
SS
4499breakpoint commands are usually more convenient and flexible than break
4500conditions for the
c906108c 4501purpose of performing side effects when a breakpoint is reached
79a6e687 4502(@pxref{Break Commands, ,Breakpoint Command Lists}).
c906108c 4503
83364271
LM
4504Breakpoint conditions can also be evaluated on the target's side if
4505the target supports it. Instead of evaluating the conditions locally,
4506@value{GDBN} encodes the expression into an agent expression
4507(@pxref{Agent Expressions}) suitable for execution on the target,
4508independently of @value{GDBN}. Global variables become raw memory
4509locations, locals become stack accesses, and so forth.
4510
4511In this case, @value{GDBN} will only be notified of a breakpoint trigger
4512when its condition evaluates to true. This mechanism may provide faster
4513response times depending on the performance characteristics of the target
4514since it does not need to keep @value{GDBN} informed about
4515every breakpoint trigger, even those with false conditions.
4516
c906108c
SS
4517Break conditions can be specified when a breakpoint is set, by using
4518@samp{if} in the arguments to the @code{break} command. @xref{Set
79a6e687 4519Breaks, ,Setting Breakpoints}. They can also be changed at any time
c906108c 4520with the @code{condition} command.
53a5351d 4521
c906108c
SS
4522You can also use the @code{if} keyword with the @code{watch} command.
4523The @code{catch} command does not recognize the @code{if} keyword;
4524@code{condition} is the only way to impose a further condition on a
4525catchpoint.
c906108c
SS
4526
4527@table @code
4528@kindex condition
4529@item condition @var{bnum} @var{expression}
4530Specify @var{expression} as the break condition for breakpoint,
4531watchpoint, or catchpoint number @var{bnum}. After you set a condition,
4532breakpoint @var{bnum} stops your program only if the value of
4533@var{expression} is true (nonzero, in C). When you use
4534@code{condition}, @value{GDBN} checks @var{expression} immediately for
4535syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
4536referents in the context of your breakpoint. If @var{expression} uses
4537symbols not referenced in the context of the breakpoint, @value{GDBN}
4538prints an error message:
4539
474c8240 4540@smallexample
d4f3574e 4541No symbol "foo" in current context.
474c8240 4542@end smallexample
d4f3574e
SS
4543
4544@noindent
c906108c
SS
4545@value{GDBN} does
4546not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
4547command (or a command that sets a breakpoint with a condition, like
4548@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
4549
4550@item condition @var{bnum}
4551Remove the condition from breakpoint number @var{bnum}. It becomes
4552an ordinary unconditional breakpoint.
4553@end table
4554
4555@cindex ignore count (of breakpoint)
4556A special case of a breakpoint condition is to stop only when the
4557breakpoint has been reached a certain number of times. This is so
4558useful that there is a special way to do it, using the @dfn{ignore
4559count} of the breakpoint. Every breakpoint has an ignore count, which
4560is an integer. Most of the time, the ignore count is zero, and
4561therefore has no effect. But if your program reaches a breakpoint whose
4562ignore count is positive, then instead of stopping, it just decrements
4563the ignore count by one and continues. As a result, if the ignore count
4564value is @var{n}, the breakpoint does not stop the next @var{n} times
4565your program reaches it.
4566
4567@table @code
4568@kindex ignore
4569@item ignore @var{bnum} @var{count}
4570Set the ignore count of breakpoint number @var{bnum} to @var{count}.
4571The next @var{count} times the breakpoint is reached, your program's
4572execution does not stop; other than to decrement the ignore count, @value{GDBN}
4573takes no action.
4574
4575To make the breakpoint stop the next time it is reached, specify
4576a count of zero.
4577
4578When you use @code{continue} to resume execution of your program from a
4579breakpoint, you can specify an ignore count directly as an argument to
4580@code{continue}, rather than using @code{ignore}. @xref{Continuing and
79a6e687 4581Stepping,,Continuing and Stepping}.
c906108c
SS
4582
4583If a breakpoint has a positive ignore count and a condition, the
4584condition is not checked. Once the ignore count reaches zero,
4585@value{GDBN} resumes checking the condition.
4586
4587You could achieve the effect of the ignore count with a condition such
4588as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
4589is decremented each time. @xref{Convenience Vars, ,Convenience
79a6e687 4590Variables}.
c906108c
SS
4591@end table
4592
4593Ignore counts apply to breakpoints, watchpoints, and catchpoints.
4594
4595
6d2ebf8b 4596@node Break Commands
79a6e687 4597@subsection Breakpoint Command Lists
c906108c
SS
4598
4599@cindex breakpoint commands
4600You can give any breakpoint (or watchpoint or catchpoint) a series of
4601commands to execute when your program stops due to that breakpoint. For
4602example, you might want to print the values of certain expressions, or
4603enable other breakpoints.
4604
4605@table @code
4606@kindex commands
ca91424e 4607@kindex end@r{ (breakpoint commands)}
95a42b64 4608@item commands @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4609@itemx @dots{} @var{command-list} @dots{}
4610@itemx end
95a42b64 4611Specify a list of commands for the given breakpoints. The commands
c906108c
SS
4612themselves appear on the following lines. Type a line containing just
4613@code{end} to terminate the commands.
4614
4615To remove all commands from a breakpoint, type @code{commands} and
4616follow it immediately with @code{end}; that is, give no commands.
4617
95a42b64
TT
4618With no argument, @code{commands} refers to the last breakpoint,
4619watchpoint, or catchpoint set (not to the breakpoint most recently
4620encountered). If the most recent breakpoints were set with a single
4621command, then the @code{commands} will apply to all the breakpoints
4622set by that command. This applies to breakpoints set by
86b17b60
PA
4623@code{rbreak}, and also applies when a single @code{break} command
4624creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
4625Expressions}).
c906108c
SS
4626@end table
4627
4628Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
4629disabled within a @var{command-list}.
4630
4631You can use breakpoint commands to start your program up again. Simply
4632use the @code{continue} command, or @code{step}, or any other command
4633that resumes execution.
4634
4635Any other commands in the command list, after a command that resumes
4636execution, are ignored. This is because any time you resume execution
4637(even with a simple @code{next} or @code{step}), you may encounter
4638another breakpoint---which could have its own command list, leading to
4639ambiguities about which list to execute.
4640
4641@kindex silent
4642If the first command you specify in a command list is @code{silent}, the
4643usual message about stopping at a breakpoint is not printed. This may
4644be desirable for breakpoints that are to print a specific message and
4645then continue. If none of the remaining commands print anything, you
4646see no sign that the breakpoint was reached. @code{silent} is
4647meaningful only at the beginning of a breakpoint command list.
4648
4649The commands @code{echo}, @code{output}, and @code{printf} allow you to
4650print precisely controlled output, and are often useful in silent
79a6e687 4651breakpoints. @xref{Output, ,Commands for Controlled Output}.
c906108c
SS
4652
4653For example, here is how you could use breakpoint commands to print the
4654value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
4655
474c8240 4656@smallexample
c906108c
SS
4657break foo if x>0
4658commands
4659silent
4660printf "x is %d\n",x
4661cont
4662end
474c8240 4663@end smallexample
c906108c
SS
4664
4665One application for breakpoint commands is to compensate for one bug so
4666you can test for another. Put a breakpoint just after the erroneous line
4667of code, give it a condition to detect the case in which something
4668erroneous has been done, and give it commands to assign correct values
4669to any variables that need them. End with the @code{continue} command
4670so that your program does not stop, and start with the @code{silent}
4671command so that no output is produced. Here is an example:
4672
474c8240 4673@smallexample
c906108c
SS
4674break 403
4675commands
4676silent
4677set x = y + 4
4678cont
4679end
474c8240 4680@end smallexample
c906108c 4681
e7e0cddf
SS
4682@node Dynamic Printf
4683@subsection Dynamic Printf
4684
4685@cindex dynamic printf
4686@cindex dprintf
4687The dynamic printf command @code{dprintf} combines a breakpoint with
4688formatted printing of your program's data to give you the effect of
4689inserting @code{printf} calls into your program on-the-fly, without
4690having to recompile it.
4691
4692In its most basic form, the output goes to the GDB console. However,
4693you can set the variable @code{dprintf-style} for alternate handling.
4694For instance, you can ask to format the output by calling your
4695program's @code{printf} function. This has the advantage that the
4696characters go to the program's output device, so they can recorded in
4697redirects to files and so forth.
4698
d3ce09f5
SS
4699If you are doing remote debugging with a stub or agent, you can also
4700ask to have the printf handled by the remote agent. In addition to
4701ensuring that the output goes to the remote program's device along
4702with any other output the program might produce, you can also ask that
4703the dprintf remain active even after disconnecting from the remote
4704target. Using the stub/agent is also more efficient, as it can do
4705everything without needing to communicate with @value{GDBN}.
4706
e7e0cddf
SS
4707@table @code
4708@kindex dprintf
4709@item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
4710Whenever execution reaches @var{location}, print the values of one or
4711more @var{expressions} under the control of the string @var{template}.
4712To print several values, separate them with commas.
4713
4714@item set dprintf-style @var{style}
4715Set the dprintf output to be handled in one of several different
4716styles enumerated below. A change of style affects all existing
4717dynamic printfs immediately. (If you need individual control over the
4718print commands, simply define normal breakpoints with
4719explicitly-supplied command lists.)
4720
4721@item gdb
4722@kindex dprintf-style gdb
4723Handle the output using the @value{GDBN} @code{printf} command.
4724
4725@item call
4726@kindex dprintf-style call
4727Handle the output by calling a function in your program (normally
4728@code{printf}).
4729
d3ce09f5
SS
4730@item agent
4731@kindex dprintf-style agent
4732Have the remote debugging agent (such as @code{gdbserver}) handle
4733the output itself. This style is only available for agents that
4734support running commands on the target.
4735
e7e0cddf
SS
4736@item set dprintf-function @var{function}
4737Set the function to call if the dprintf style is @code{call}. By
4738default its value is @code{printf}. You may set it to any expression.
4739that @value{GDBN} can evaluate to a function, as per the @code{call}
4740command.
4741
4742@item set dprintf-channel @var{channel}
4743Set a ``channel'' for dprintf. If set to a non-empty value,
4744@value{GDBN} will evaluate it as an expression and pass the result as
4745a first argument to the @code{dprintf-function}, in the manner of
4746@code{fprintf} and similar functions. Otherwise, the dprintf format
4747string will be the first argument, in the manner of @code{printf}.
4748
4749As an example, if you wanted @code{dprintf} output to go to a logfile
4750that is a standard I/O stream assigned to the variable @code{mylog},
4751you could do the following:
4752
4753@example
4754(gdb) set dprintf-style call
4755(gdb) set dprintf-function fprintf
4756(gdb) set dprintf-channel mylog
4757(gdb) dprintf 25,"at line 25, glob=%d\n",glob
4758Dprintf 1 at 0x123456: file main.c, line 25.
4759(gdb) info break
47601 dprintf keep y 0x00123456 in main at main.c:25
4761 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
4762 continue
4763(gdb)
4764@end example
4765
4766Note that the @code{info break} displays the dynamic printf commands
4767as normal breakpoint commands; you can thus easily see the effect of
4768the variable settings.
4769
d3ce09f5
SS
4770@item set disconnected-dprintf on
4771@itemx set disconnected-dprintf off
4772@kindex set disconnected-dprintf
4773Choose whether @code{dprintf} commands should continue to run if
4774@value{GDBN} has disconnected from the target. This only applies
4775if the @code{dprintf-style} is @code{agent}.
4776
4777@item show disconnected-dprintf off
4778@kindex show disconnected-dprintf
4779Show the current choice for disconnected @code{dprintf}.
4780
e7e0cddf
SS
4781@end table
4782
4783@value{GDBN} does not check the validity of function and channel,
4784relying on you to supply values that are meaningful for the contexts
4785in which they are being used. For instance, the function and channel
4786may be the values of local variables, but if that is the case, then
4787all enabled dynamic prints must be at locations within the scope of
4788those locals. If evaluation fails, @value{GDBN} will report an error.
4789
6149aea9
PA
4790@node Save Breakpoints
4791@subsection How to save breakpoints to a file
4792
4793To save breakpoint definitions to a file use the @w{@code{save
4794breakpoints}} command.
4795
4796@table @code
4797@kindex save breakpoints
4798@cindex save breakpoints to a file for future sessions
4799@item save breakpoints [@var{filename}]
4800This command saves all current breakpoint definitions together with
4801their commands and ignore counts, into a file @file{@var{filename}}
4802suitable for use in a later debugging session. This includes all
4803types of breakpoints (breakpoints, watchpoints, catchpoints,
4804tracepoints). To read the saved breakpoint definitions, use the
4805@code{source} command (@pxref{Command Files}). Note that watchpoints
4806with expressions involving local variables may fail to be recreated
4807because it may not be possible to access the context where the
4808watchpoint is valid anymore. Because the saved breakpoint definitions
4809are simply a sequence of @value{GDBN} commands that recreate the
4810breakpoints, you can edit the file in your favorite editing program,
4811and remove the breakpoint definitions you're not interested in, or
4812that can no longer be recreated.
4813@end table
4814
62e5f89c
SDJ
4815@node Static Probe Points
4816@subsection Static Probe Points
4817
4818@cindex static probe point, SystemTap
4819@value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
4820for Statically Defined Tracing, and the probes are designed to have a tiny
4821runtime code and data footprint, and no dynamic relocations. They are
4822usable from assembly, C and C@t{++} languages. See
4823@uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
4824for a good reference on how the @acronym{SDT} probes are implemented.
4825
4826Currently, @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
4827@acronym{SDT} probes are supported on ELF-compatible systems. See
4828@uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
4829for more information on how to add @code{SystemTap} @acronym{SDT} probes
4830in your applications.
4831
4832@cindex semaphores on static probe points
4833Some probes have an associated semaphore variable; for instance, this
4834happens automatically if you defined your probe using a DTrace-style
4835@file{.d} file. If your probe has a semaphore, @value{GDBN} will
4836automatically enable it when you specify a breakpoint using the
4837@samp{-probe-stap} notation. But, if you put a breakpoint at a probe's
4838location by some other method (e.g., @code{break file:line}), then
4839@value{GDBN} will not automatically set the semaphore.
4840
4841You can examine the available static static probes using @code{info
4842probes}, with optional arguments:
4843
4844@table @code
4845@kindex info probes
4846@item info probes stap @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
4847If given, @var{provider} is a regular expression used to match against provider
4848names when selecting which probes to list. If omitted, probes by all
4849probes from all providers are listed.
4850
4851If given, @var{name} is a regular expression to match against probe names
4852when selecting which probes to list. If omitted, probe names are not
4853considered when deciding whether to display them.
4854
4855If given, @var{objfile} is a regular expression used to select which
4856object files (executable or shared libraries) to examine. If not
4857given, all object files are considered.
4858
4859@item info probes all
4860List the available static probes, from all types.
4861@end table
4862
4863@vindex $_probe_arg@r{, convenience variable}
4864A probe may specify up to twelve arguments. These are available at the
4865point at which the probe is defined---that is, when the current PC is
4866at the probe's location. The arguments are available using the
4867convenience variables (@pxref{Convenience Vars})
4868@code{$_probe_arg0}@dots{}@code{$_probe_arg11}. Each probe argument is
4869an integer of the appropriate size; types are not preserved. The
4870convenience variable @code{$_probe_argc} holds the number of arguments
4871at the current probe point.
4872
4873These variables are always available, but attempts to access them at
4874any location other than a probe point will cause @value{GDBN} to give
4875an error message.
4876
4877
c906108c 4878@c @ifclear BARETARGET
6d2ebf8b 4879@node Error in Breakpoints
d4f3574e 4880@subsection ``Cannot insert breakpoints''
c906108c 4881
fa3a767f
PA
4882If you request too many active hardware-assisted breakpoints and
4883watchpoints, you will see this error message:
d4f3574e
SS
4884
4885@c FIXME: the precise wording of this message may change; the relevant
4886@c source change is not committed yet (Sep 3, 1999).
4887@smallexample
4888Stopped; cannot insert breakpoints.
4889You may have requested too many hardware breakpoints and watchpoints.
4890@end smallexample
4891
4892@noindent
4893This message is printed when you attempt to resume the program, since
4894only then @value{GDBN} knows exactly how many hardware breakpoints and
4895watchpoints it needs to insert.
4896
4897When this message is printed, you need to disable or remove some of the
4898hardware-assisted breakpoints and watchpoints, and then continue.
4899
79a6e687 4900@node Breakpoint-related Warnings
1485d690
KB
4901@subsection ``Breakpoint address adjusted...''
4902@cindex breakpoint address adjusted
4903
4904Some processor architectures place constraints on the addresses at
4905which breakpoints may be placed. For architectures thus constrained,
4906@value{GDBN} will attempt to adjust the breakpoint's address to comply
4907with the constraints dictated by the architecture.
4908
4909One example of such an architecture is the Fujitsu FR-V. The FR-V is
4910a VLIW architecture in which a number of RISC-like instructions may be
4911bundled together for parallel execution. The FR-V architecture
4912constrains the location of a breakpoint instruction within such a
4913bundle to the instruction with the lowest address. @value{GDBN}
4914honors this constraint by adjusting a breakpoint's address to the
4915first in the bundle.
4916
4917It is not uncommon for optimized code to have bundles which contain
4918instructions from different source statements, thus it may happen that
4919a breakpoint's address will be adjusted from one source statement to
4920another. Since this adjustment may significantly alter @value{GDBN}'s
4921breakpoint related behavior from what the user expects, a warning is
4922printed when the breakpoint is first set and also when the breakpoint
4923is hit.
4924
4925A warning like the one below is printed when setting a breakpoint
4926that's been subject to address adjustment:
4927
4928@smallexample
4929warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
4930@end smallexample
4931
4932Such warnings are printed both for user settable and @value{GDBN}'s
4933internal breakpoints. If you see one of these warnings, you should
4934verify that a breakpoint set at the adjusted address will have the
4935desired affect. If not, the breakpoint in question may be removed and
b383017d 4936other breakpoints may be set which will have the desired behavior.
1485d690
KB
4937E.g., it may be sufficient to place the breakpoint at a later
4938instruction. A conditional breakpoint may also be useful in some
4939cases to prevent the breakpoint from triggering too often.
4940
4941@value{GDBN} will also issue a warning when stopping at one of these
4942adjusted breakpoints:
4943
4944@smallexample
4945warning: Breakpoint 1 address previously adjusted from 0x00010414
4946to 0x00010410.
4947@end smallexample
4948
4949When this warning is encountered, it may be too late to take remedial
4950action except in cases where the breakpoint is hit earlier or more
4951frequently than expected.
d4f3574e 4952
6d2ebf8b 4953@node Continuing and Stepping
79a6e687 4954@section Continuing and Stepping
c906108c
SS
4955
4956@cindex stepping
4957@cindex continuing
4958@cindex resuming execution
4959@dfn{Continuing} means resuming program execution until your program
4960completes normally. In contrast, @dfn{stepping} means executing just
4961one more ``step'' of your program, where ``step'' may mean either one
4962line of source code, or one machine instruction (depending on what
7a292a7a
SS
4963particular command you use). Either when continuing or when stepping,
4964your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
4965it stops due to a signal, you may want to use @code{handle}, or use
4966@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
4967
4968@table @code
4969@kindex continue
41afff9a
EZ
4970@kindex c @r{(@code{continue})}
4971@kindex fg @r{(resume foreground execution)}
c906108c
SS
4972@item continue @r{[}@var{ignore-count}@r{]}
4973@itemx c @r{[}@var{ignore-count}@r{]}
4974@itemx fg @r{[}@var{ignore-count}@r{]}
4975Resume program execution, at the address where your program last stopped;
4976any breakpoints set at that address are bypassed. The optional argument
4977@var{ignore-count} allows you to specify a further number of times to
4978ignore a breakpoint at this location; its effect is like that of
79a6e687 4979@code{ignore} (@pxref{Conditions, ,Break Conditions}).
c906108c
SS
4980
4981The argument @var{ignore-count} is meaningful only when your program
4982stopped due to a breakpoint. At other times, the argument to
4983@code{continue} is ignored.
4984
d4f3574e
SS
4985The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
4986debugged program is deemed to be the foreground program) are provided
4987purely for convenience, and have exactly the same behavior as
4988@code{continue}.
c906108c
SS
4989@end table
4990
4991To resume execution at a different place, you can use @code{return}
79a6e687 4992(@pxref{Returning, ,Returning from a Function}) to go back to the
c906108c 4993calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
79a6e687 4994Different Address}) to go to an arbitrary location in your program.
c906108c
SS
4995
4996A typical technique for using stepping is to set a breakpoint
79a6e687 4997(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
c906108c
SS
4998beginning of the function or the section of your program where a problem
4999is believed to lie, run your program until it stops at that breakpoint,
5000and then step through the suspect area, examining the variables that are
5001interesting, until you see the problem happen.
5002
5003@table @code
5004@kindex step
41afff9a 5005@kindex s @r{(@code{step})}
c906108c
SS
5006@item step
5007Continue running your program until control reaches a different source
5008line, then stop it and return control to @value{GDBN}. This command is
5009abbreviated @code{s}.
5010
5011@quotation
5012@c "without debugging information" is imprecise; actually "without line
5013@c numbers in the debugging information". (gcc -g1 has debugging info but
5014@c not line numbers). But it seems complex to try to make that
5015@c distinction here.
5016@emph{Warning:} If you use the @code{step} command while control is
5017within a function that was compiled without debugging information,
5018execution proceeds until control reaches a function that does have
5019debugging information. Likewise, it will not step into a function which
5020is compiled without debugging information. To step through functions
5021without debugging information, use the @code{stepi} command, described
5022below.
5023@end quotation
5024
4a92d011
EZ
5025The @code{step} command only stops at the first instruction of a source
5026line. This prevents the multiple stops that could otherwise occur in
5027@code{switch} statements, @code{for} loops, etc. @code{step} continues
5028to stop if a function that has debugging information is called within
5029the line. In other words, @code{step} @emph{steps inside} any functions
5030called within the line.
c906108c 5031
d4f3574e
SS
5032Also, the @code{step} command only enters a function if there is line
5033number information for the function. Otherwise it acts like the
5d161b24 5034@code{next} command. This avoids problems when using @code{cc -gl}
eb17f351 5035on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5d161b24 5036was any debugging information about the routine.
c906108c
SS
5037
5038@item step @var{count}
5039Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
5040breakpoint is reached, or a signal not related to stepping occurs before
5041@var{count} steps, stepping stops right away.
c906108c
SS
5042
5043@kindex next
41afff9a 5044@kindex n @r{(@code{next})}
c906108c
SS
5045@item next @r{[}@var{count}@r{]}
5046Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
5047This is similar to @code{step}, but function calls that appear within
5048the line of code are executed without stopping. Execution stops when
5049control reaches a different line of code at the original stack level
5050that was executing when you gave the @code{next} command. This command
5051is abbreviated @code{n}.
c906108c
SS
5052
5053An argument @var{count} is a repeat count, as for @code{step}.
5054
5055
5056@c FIX ME!! Do we delete this, or is there a way it fits in with
5057@c the following paragraph? --- Vctoria
5058@c
5059@c @code{next} within a function that lacks debugging information acts like
5060@c @code{step}, but any function calls appearing within the code of the
5061@c function are executed without stopping.
5062
d4f3574e
SS
5063The @code{next} command only stops at the first instruction of a
5064source line. This prevents multiple stops that could otherwise occur in
4a92d011 5065@code{switch} statements, @code{for} loops, etc.
c906108c 5066
b90a5f51
CF
5067@kindex set step-mode
5068@item set step-mode
5069@cindex functions without line info, and stepping
5070@cindex stepping into functions with no line info
5071@itemx set step-mode on
4a92d011 5072The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
5073stop at the first instruction of a function which contains no debug line
5074information rather than stepping over it.
5075
4a92d011
EZ
5076This is useful in cases where you may be interested in inspecting the
5077machine instructions of a function which has no symbolic info and do not
5078want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
5079
5080@item set step-mode off
4a92d011 5081Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
5082debug information. This is the default.
5083
9c16f35a
EZ
5084@item show step-mode
5085Show whether @value{GDBN} will stop in or step over functions without
5086source line debug information.
5087
c906108c 5088@kindex finish
8dfa32fc 5089@kindex fin @r{(@code{finish})}
c906108c
SS
5090@item finish
5091Continue running until just after function in the selected stack frame
8dfa32fc
JB
5092returns. Print the returned value (if any). This command can be
5093abbreviated as @code{fin}.
c906108c
SS
5094
5095Contrast this with the @code{return} command (@pxref{Returning,
79a6e687 5096,Returning from a Function}).
c906108c
SS
5097
5098@kindex until
41afff9a 5099@kindex u @r{(@code{until})}
09d4efe1 5100@cindex run until specified location
c906108c
SS
5101@item until
5102@itemx u
5103Continue running until a source line past the current line, in the
5104current stack frame, is reached. This command is used to avoid single
5105stepping through a loop more than once. It is like the @code{next}
5106command, except that when @code{until} encounters a jump, it
5107automatically continues execution until the program counter is greater
5108than the address of the jump.
5109
5110This means that when you reach the end of a loop after single stepping
5111though it, @code{until} makes your program continue execution until it
5112exits the loop. In contrast, a @code{next} command at the end of a loop
5113simply steps back to the beginning of the loop, which forces you to step
5114through the next iteration.
5115
5116@code{until} always stops your program if it attempts to exit the current
5117stack frame.
5118
5119@code{until} may produce somewhat counterintuitive results if the order
5120of machine code does not match the order of the source lines. For
5121example, in the following excerpt from a debugging session, the @code{f}
5122(@code{frame}) command shows that execution is stopped at line
5123@code{206}; yet when we use @code{until}, we get to line @code{195}:
5124
474c8240 5125@smallexample
c906108c
SS
5126(@value{GDBP}) f
5127#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
5128206 expand_input();
5129(@value{GDBP}) until
5130195 for ( ; argc > 0; NEXTARG) @{
474c8240 5131@end smallexample
c906108c
SS
5132
5133This happened because, for execution efficiency, the compiler had
5134generated code for the loop closure test at the end, rather than the
5135start, of the loop---even though the test in a C @code{for}-loop is
5136written before the body of the loop. The @code{until} command appeared
5137to step back to the beginning of the loop when it advanced to this
5138expression; however, it has not really gone to an earlier
5139statement---not in terms of the actual machine code.
5140
5141@code{until} with no argument works by means of single
5142instruction stepping, and hence is slower than @code{until} with an
5143argument.
5144
5145@item until @var{location}
5146@itemx u @var{location}
5147Continue running your program until either the specified location is
5148reached, or the current stack frame returns. @var{location} is any of
2a25a5ba
EZ
5149the forms described in @ref{Specify Location}.
5150This form of the command uses temporary breakpoints, and
c60eb6f1
EZ
5151hence is quicker than @code{until} without an argument. The specified
5152location is actually reached only if it is in the current frame. This
5153implies that @code{until} can be used to skip over recursive function
5154invocations. For instance in the code below, if the current location is
5155line @code{96}, issuing @code{until 99} will execute the program up to
db2e3e2e 5156line @code{99} in the same invocation of factorial, i.e., after the inner
c60eb6f1
EZ
5157invocations have returned.
5158
5159@smallexample
516094 int factorial (int value)
516195 @{
516296 if (value > 1) @{
516397 value *= factorial (value - 1);
516498 @}
516599 return (value);
5166100 @}
5167@end smallexample
5168
5169
5170@kindex advance @var{location}
984359d2 5171@item advance @var{location}
09d4efe1 5172Continue running the program up to the given @var{location}. An argument is
2a25a5ba
EZ
5173required, which should be of one of the forms described in
5174@ref{Specify Location}.
5175Execution will also stop upon exit from the current stack
c60eb6f1
EZ
5176frame. This command is similar to @code{until}, but @code{advance} will
5177not skip over recursive function calls, and the target location doesn't
5178have to be in the same frame as the current one.
5179
c906108c
SS
5180
5181@kindex stepi
41afff9a 5182@kindex si @r{(@code{stepi})}
c906108c 5183@item stepi
96a2c332 5184@itemx stepi @var{arg}
c906108c
SS
5185@itemx si
5186Execute one machine instruction, then stop and return to the debugger.
5187
5188It is often useful to do @samp{display/i $pc} when stepping by machine
5189instructions. This makes @value{GDBN} automatically display the next
5190instruction to be executed, each time your program stops. @xref{Auto
79a6e687 5191Display,, Automatic Display}.
c906108c
SS
5192
5193An argument is a repeat count, as in @code{step}.
5194
5195@need 750
5196@kindex nexti
41afff9a 5197@kindex ni @r{(@code{nexti})}
c906108c 5198@item nexti
96a2c332 5199@itemx nexti @var{arg}
c906108c
SS
5200@itemx ni
5201Execute one machine instruction, but if it is a function call,
5202proceed until the function returns.
5203
5204An argument is a repeat count, as in @code{next}.
5205@end table
5206
aad1c02c
TT
5207@node Skipping Over Functions and Files
5208@section Skipping Over Functions and Files
1bfeeb0f
JL
5209@cindex skipping over functions and files
5210
5211The program you are debugging may contain some functions which are
5212uninteresting to debug. The @code{skip} comand lets you tell @value{GDBN} to
5213skip a function or all functions in a file when stepping.
5214
5215For example, consider the following C function:
5216
5217@smallexample
5218101 int func()
5219102 @{
5220103 foo(boring());
5221104 bar(boring());
5222105 @}
5223@end smallexample
5224
5225@noindent
5226Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
5227are not interested in stepping through @code{boring}. If you run @code{step}
5228at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
5229step over both @code{foo} and @code{boring}!
5230
5231One solution is to @code{step} into @code{boring} and use the @code{finish}
5232command to immediately exit it. But this can become tedious if @code{boring}
5233is called from many places.
5234
5235A more flexible solution is to execute @kbd{skip boring}. This instructs
5236@value{GDBN} never to step into @code{boring}. Now when you execute
5237@code{step} at line 103, you'll step over @code{boring} and directly into
5238@code{foo}.
5239
5240You can also instruct @value{GDBN} to skip all functions in a file, with, for
5241example, @code{skip file boring.c}.
5242
5243@table @code
5244@kindex skip function
5245@item skip @r{[}@var{linespec}@r{]}
5246@itemx skip function @r{[}@var{linespec}@r{]}
5247After running this command, the function named by @var{linespec} or the
5248function containing the line named by @var{linespec} will be skipped over when
983fb131 5249stepping. @xref{Specify Location}.
1bfeeb0f
JL
5250
5251If you do not specify @var{linespec}, the function you're currently debugging
5252will be skipped.
5253
5254(If you have a function called @code{file} that you want to skip, use
5255@kbd{skip function file}.)
5256
5257@kindex skip file
5258@item skip file @r{[}@var{filename}@r{]}
5259After running this command, any function whose source lives in @var{filename}
5260will be skipped over when stepping.
5261
5262If you do not specify @var{filename}, functions whose source lives in the file
5263you're currently debugging will be skipped.
5264@end table
5265
5266Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
5267These are the commands for managing your list of skips:
5268
5269@table @code
5270@kindex info skip
5271@item info skip @r{[}@var{range}@r{]}
5272Print details about the specified skip(s). If @var{range} is not specified,
5273print a table with details about all functions and files marked for skipping.
5274@code{info skip} prints the following information about each skip:
5275
5276@table @emph
5277@item Identifier
5278A number identifying this skip.
5279@item Type
5280The type of this skip, either @samp{function} or @samp{file}.
5281@item Enabled or Disabled
5282Enabled skips are marked with @samp{y}. Disabled skips are marked with @samp{n}.
5283@item Address
5284For function skips, this column indicates the address in memory of the function
5285being skipped. If you've set a function skip on a function which has not yet
5286been loaded, this field will contain @samp{<PENDING>}. Once a shared library
5287which has the function is loaded, @code{info skip} will show the function's
5288address here.
5289@item What
5290For file skips, this field contains the filename being skipped. For functions
5291skips, this field contains the function name and its line number in the file
5292where it is defined.
5293@end table
5294
5295@kindex skip delete
5296@item skip delete @r{[}@var{range}@r{]}
5297Delete the specified skip(s). If @var{range} is not specified, delete all
5298skips.
5299
5300@kindex skip enable
5301@item skip enable @r{[}@var{range}@r{]}
5302Enable the specified skip(s). If @var{range} is not specified, enable all
5303skips.
5304
5305@kindex skip disable
5306@item skip disable @r{[}@var{range}@r{]}
5307Disable the specified skip(s). If @var{range} is not specified, disable all
5308skips.
5309
5310@end table
5311
6d2ebf8b 5312@node Signals
c906108c
SS
5313@section Signals
5314@cindex signals
5315
5316A signal is an asynchronous event that can happen in a program. The
5317operating system defines the possible kinds of signals, and gives each
5318kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 5319signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
5320@code{SIGSEGV} is the signal a program gets from referencing a place in
5321memory far away from all the areas in use; @code{SIGALRM} occurs when
5322the alarm clock timer goes off (which happens only if your program has
5323requested an alarm).
5324
5325@cindex fatal signals
5326Some signals, including @code{SIGALRM}, are a normal part of the
5327functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 5328errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
5329program has not specified in advance some other way to handle the signal.
5330@code{SIGINT} does not indicate an error in your program, but it is normally
5331fatal so it can carry out the purpose of the interrupt: to kill the program.
5332
5333@value{GDBN} has the ability to detect any occurrence of a signal in your
5334program. You can tell @value{GDBN} in advance what to do for each kind of
5335signal.
5336
5337@cindex handling signals
24f93129
EZ
5338Normally, @value{GDBN} is set up to let the non-erroneous signals like
5339@code{SIGALRM} be silently passed to your program
5340(so as not to interfere with their role in the program's functioning)
c906108c
SS
5341but to stop your program immediately whenever an error signal happens.
5342You can change these settings with the @code{handle} command.
5343
5344@table @code
5345@kindex info signals
09d4efe1 5346@kindex info handle
c906108c 5347@item info signals
96a2c332 5348@itemx info handle
c906108c
SS
5349Print a table of all the kinds of signals and how @value{GDBN} has been told to
5350handle each one. You can use this to see the signal numbers of all
5351the defined types of signals.
5352
45ac1734
EZ
5353@item info signals @var{sig}
5354Similar, but print information only about the specified signal number.
5355
d4f3574e 5356@code{info handle} is an alias for @code{info signals}.
c906108c 5357
ab04a2af
TT
5358@item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
5359Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
5360for details about this command.
5361
c906108c 5362@kindex handle
45ac1734 5363@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
5ece1a18
EZ
5364Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
5365can be the number of a signal or its name (with or without the
24f93129 5366@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 5367@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
5368known signals. Optional arguments @var{keywords}, described below,
5369say what change to make.
c906108c
SS
5370@end table
5371
5372@c @group
5373The keywords allowed by the @code{handle} command can be abbreviated.
5374Their full names are:
5375
5376@table @code
5377@item nostop
5378@value{GDBN} should not stop your program when this signal happens. It may
5379still print a message telling you that the signal has come in.
5380
5381@item stop
5382@value{GDBN} should stop your program when this signal happens. This implies
5383the @code{print} keyword as well.
5384
5385@item print
5386@value{GDBN} should print a message when this signal happens.
5387
5388@item noprint
5389@value{GDBN} should not mention the occurrence of the signal at all. This
5390implies the @code{nostop} keyword as well.
5391
5392@item pass
5ece1a18 5393@itemx noignore
c906108c
SS
5394@value{GDBN} should allow your program to see this signal; your program
5395can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 5396and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
5397
5398@item nopass
5ece1a18 5399@itemx ignore
c906108c 5400@value{GDBN} should not allow your program to see this signal.
5ece1a18 5401@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
5402@end table
5403@c @end group
5404
d4f3574e
SS
5405When a signal stops your program, the signal is not visible to the
5406program until you
c906108c
SS
5407continue. Your program sees the signal then, if @code{pass} is in
5408effect for the signal in question @emph{at that time}. In other words,
5409after @value{GDBN} reports a signal, you can use the @code{handle}
5410command with @code{pass} or @code{nopass} to control whether your
5411program sees that signal when you continue.
5412
24f93129
EZ
5413The default is set to @code{nostop}, @code{noprint}, @code{pass} for
5414non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
5415@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
5416erroneous signals.
5417
c906108c
SS
5418You can also use the @code{signal} command to prevent your program from
5419seeing a signal, or cause it to see a signal it normally would not see,
5420or to give it any signal at any time. For example, if your program stopped
5421due to some sort of memory reference error, you might store correct
5422values into the erroneous variables and continue, hoping to see more
5423execution; but your program would probably terminate immediately as
5424a result of the fatal signal once it saw the signal. To prevent this,
5425you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
79a6e687 5426Program a Signal}.
c906108c 5427
4aa995e1
PA
5428@cindex extra signal information
5429@anchor{extra signal information}
5430
5431On some targets, @value{GDBN} can inspect extra signal information
5432associated with the intercepted signal, before it is actually
5433delivered to the program being debugged. This information is exported
5434by the convenience variable @code{$_siginfo}, and consists of data
5435that is passed by the kernel to the signal handler at the time of the
5436receipt of a signal. The data type of the information itself is
5437target dependent. You can see the data type using the @code{ptype
5438$_siginfo} command. On Unix systems, it typically corresponds to the
5439standard @code{siginfo_t} type, as defined in the @file{signal.h}
5440system header.
5441
5442Here's an example, on a @sc{gnu}/Linux system, printing the stray
5443referenced address that raised a segmentation fault.
5444
5445@smallexample
5446@group
5447(@value{GDBP}) continue
5448Program received signal SIGSEGV, Segmentation fault.
54490x0000000000400766 in main ()
545069 *(int *)p = 0;
5451(@value{GDBP}) ptype $_siginfo
5452type = struct @{
5453 int si_signo;
5454 int si_errno;
5455 int si_code;
5456 union @{
5457 int _pad[28];
5458 struct @{...@} _kill;
5459 struct @{...@} _timer;
5460 struct @{...@} _rt;
5461 struct @{...@} _sigchld;
5462 struct @{...@} _sigfault;
5463 struct @{...@} _sigpoll;
5464 @} _sifields;
5465@}
5466(@value{GDBP}) ptype $_siginfo._sifields._sigfault
5467type = struct @{
5468 void *si_addr;
5469@}
5470(@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
5471$1 = (void *) 0x7ffff7ff7000
5472@end group
5473@end smallexample
5474
5475Depending on target support, @code{$_siginfo} may also be writable.
5476
6d2ebf8b 5477@node Thread Stops
79a6e687 5478@section Stopping and Starting Multi-thread Programs
c906108c 5479
0606b73b
SL
5480@cindex stopped threads
5481@cindex threads, stopped
5482
5483@cindex continuing threads
5484@cindex threads, continuing
5485
5486@value{GDBN} supports debugging programs with multiple threads
5487(@pxref{Threads,, Debugging Programs with Multiple Threads}). There
5488are two modes of controlling execution of your program within the
5489debugger. In the default mode, referred to as @dfn{all-stop mode},
5490when any thread in your program stops (for example, at a breakpoint
5491or while being stepped), all other threads in the program are also stopped by
5492@value{GDBN}. On some targets, @value{GDBN} also supports
5493@dfn{non-stop mode}, in which other threads can continue to run freely while
5494you examine the stopped thread in the debugger.
5495
5496@menu
5497* All-Stop Mode:: All threads stop when GDB takes control
5498* Non-Stop Mode:: Other threads continue to execute
5499* Background Execution:: Running your program asynchronously
5500* Thread-Specific Breakpoints:: Controlling breakpoints
5501* Interrupted System Calls:: GDB may interfere with system calls
d914c394 5502* Observer Mode:: GDB does not alter program behavior
0606b73b
SL
5503@end menu
5504
5505@node All-Stop Mode
5506@subsection All-Stop Mode
5507
5508@cindex all-stop mode
5509
5510In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
5511@emph{all} threads of execution stop, not just the current thread. This
5512allows you to examine the overall state of the program, including
5513switching between threads, without worrying that things may change
5514underfoot.
5515
5516Conversely, whenever you restart the program, @emph{all} threads start
5517executing. @emph{This is true even when single-stepping} with commands
5518like @code{step} or @code{next}.
5519
5520In particular, @value{GDBN} cannot single-step all threads in lockstep.
5521Since thread scheduling is up to your debugging target's operating
5522system (not controlled by @value{GDBN}), other threads may
5523execute more than one statement while the current thread completes a
5524single step. Moreover, in general other threads stop in the middle of a
5525statement, rather than at a clean statement boundary, when the program
5526stops.
5527
5528You might even find your program stopped in another thread after
5529continuing or even single-stepping. This happens whenever some other
5530thread runs into a breakpoint, a signal, or an exception before the
5531first thread completes whatever you requested.
5532
5533@cindex automatic thread selection
5534@cindex switching threads automatically
5535@cindex threads, automatic switching
5536Whenever @value{GDBN} stops your program, due to a breakpoint or a
5537signal, it automatically selects the thread where that breakpoint or
5538signal happened. @value{GDBN} alerts you to the context switch with a
5539message such as @samp{[Switching to Thread @var{n}]} to identify the
5540thread.
5541
5542On some OSes, you can modify @value{GDBN}'s default behavior by
5543locking the OS scheduler to allow only a single thread to run.
5544
5545@table @code
5546@item set scheduler-locking @var{mode}
5547@cindex scheduler locking mode
5548@cindex lock scheduler
5549Set the scheduler locking mode. If it is @code{off}, then there is no
5550locking and any thread may run at any time. If @code{on}, then only the
5551current thread may run when the inferior is resumed. The @code{step}
5552mode optimizes for single-stepping; it prevents other threads
5553from preempting the current thread while you are stepping, so that
5554the focus of debugging does not change unexpectedly.
5555Other threads only rarely (or never) get a chance to run
5556when you step. They are more likely to run when you @samp{next} over a
5557function call, and they are completely free to run when you use commands
5558like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
5559thread hits a breakpoint during its timeslice, @value{GDBN} does not change
5560the current thread away from the thread that you are debugging.
5561
5562@item show scheduler-locking
5563Display the current scheduler locking mode.
5564@end table
5565
d4db2f36
PA
5566@cindex resume threads of multiple processes simultaneously
5567By default, when you issue one of the execution commands such as
5568@code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
5569threads of the current inferior to run. For example, if @value{GDBN}
5570is attached to two inferiors, each with two threads, the
5571@code{continue} command resumes only the two threads of the current
5572inferior. This is useful, for example, when you debug a program that
5573forks and you want to hold the parent stopped (so that, for instance,
5574it doesn't run to exit), while you debug the child. In other
5575situations, you may not be interested in inspecting the current state
5576of any of the processes @value{GDBN} is attached to, and you may want
5577to resume them all until some breakpoint is hit. In the latter case,
5578you can instruct @value{GDBN} to allow all threads of all the
5579inferiors to run with the @w{@code{set schedule-multiple}} command.
5580
5581@table @code
5582@kindex set schedule-multiple
5583@item set schedule-multiple
5584Set the mode for allowing threads of multiple processes to be resumed
5585when an execution command is issued. When @code{on}, all threads of
5586all processes are allowed to run. When @code{off}, only the threads
5587of the current process are resumed. The default is @code{off}. The
5588@code{scheduler-locking} mode takes precedence when set to @code{on},
5589or while you are stepping and set to @code{step}.
5590
5591@item show schedule-multiple
5592Display the current mode for resuming the execution of threads of
5593multiple processes.
5594@end table
5595
0606b73b
SL
5596@node Non-Stop Mode
5597@subsection Non-Stop Mode
5598
5599@cindex non-stop mode
5600
5601@c This section is really only a place-holder, and needs to be expanded
5602@c with more details.
5603
5604For some multi-threaded targets, @value{GDBN} supports an optional
5605mode of operation in which you can examine stopped program threads in
5606the debugger while other threads continue to execute freely. This
5607minimizes intrusion when debugging live systems, such as programs
5608where some threads have real-time constraints or must continue to
5609respond to external events. This is referred to as @dfn{non-stop} mode.
5610
5611In non-stop mode, when a thread stops to report a debugging event,
5612@emph{only} that thread is stopped; @value{GDBN} does not stop other
5613threads as well, in contrast to the all-stop mode behavior. Additionally,
5614execution commands such as @code{continue} and @code{step} apply by default
5615only to the current thread in non-stop mode, rather than all threads as
5616in all-stop mode. This allows you to control threads explicitly in
5617ways that are not possible in all-stop mode --- for example, stepping
5618one thread while allowing others to run freely, stepping
5619one thread while holding all others stopped, or stepping several threads
5620independently and simultaneously.
5621
5622To enter non-stop mode, use this sequence of commands before you run
5623or attach to your program:
5624
0606b73b
SL
5625@smallexample
5626# Enable the async interface.
c6ebd6cf 5627set target-async 1
0606b73b 5628
0606b73b
SL
5629# If using the CLI, pagination breaks non-stop.
5630set pagination off
5631
5632# Finally, turn it on!
5633set non-stop on
5634@end smallexample
5635
5636You can use these commands to manipulate the non-stop mode setting:
5637
5638@table @code
5639@kindex set non-stop
5640@item set non-stop on
5641Enable selection of non-stop mode.
5642@item set non-stop off
5643Disable selection of non-stop mode.
5644@kindex show non-stop
5645@item show non-stop
5646Show the current non-stop enablement setting.
5647@end table
5648
5649Note these commands only reflect whether non-stop mode is enabled,
5650not whether the currently-executing program is being run in non-stop mode.
5651In particular, the @code{set non-stop} preference is only consulted when
5652@value{GDBN} starts or connects to the target program, and it is generally
5653not possible to switch modes once debugging has started. Furthermore,
5654since not all targets support non-stop mode, even when you have enabled
5655non-stop mode, @value{GDBN} may still fall back to all-stop operation by
5656default.
5657
5658In non-stop mode, all execution commands apply only to the current thread
5659by default. That is, @code{continue} only continues one thread.
5660To continue all threads, issue @code{continue -a} or @code{c -a}.
5661
5662You can use @value{GDBN}'s background execution commands
5663(@pxref{Background Execution}) to run some threads in the background
5664while you continue to examine or step others from @value{GDBN}.
5665The MI execution commands (@pxref{GDB/MI Program Execution}) are
5666always executed asynchronously in non-stop mode.
5667
5668Suspending execution is done with the @code{interrupt} command when
5669running in the background, or @kbd{Ctrl-c} during foreground execution.
5670In all-stop mode, this stops the whole process;
5671but in non-stop mode the interrupt applies only to the current thread.
5672To stop the whole program, use @code{interrupt -a}.
5673
5674Other execution commands do not currently support the @code{-a} option.
5675
5676In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
5677that thread current, as it does in all-stop mode. This is because the
5678thread stop notifications are asynchronous with respect to @value{GDBN}'s
5679command interpreter, and it would be confusing if @value{GDBN} unexpectedly
5680changed to a different thread just as you entered a command to operate on the
5681previously current thread.
5682
5683@node Background Execution
5684@subsection Background Execution
5685
5686@cindex foreground execution
5687@cindex background execution
5688@cindex asynchronous execution
5689@cindex execution, foreground, background and asynchronous
5690
5691@value{GDBN}'s execution commands have two variants: the normal
5692foreground (synchronous) behavior, and a background
5693(asynchronous) behavior. In foreground execution, @value{GDBN} waits for
5694the program to report that some thread has stopped before prompting for
5695another command. In background execution, @value{GDBN} immediately gives
5696a command prompt so that you can issue other commands while your program runs.
5697
32fc0df9
PA
5698You need to explicitly enable asynchronous mode before you can use
5699background execution commands. You can use these commands to
5700manipulate the asynchronous mode setting:
5701
5702@table @code
5703@kindex set target-async
5704@item set target-async on
5705Enable asynchronous mode.
5706@item set target-async off
5707Disable asynchronous mode.
5708@kindex show target-async
5709@item show target-async
5710Show the current target-async setting.
5711@end table
5712
5713If the target doesn't support async mode, @value{GDBN} issues an error
5714message if you attempt to use the background execution commands.
5715
0606b73b
SL
5716To specify background execution, add a @code{&} to the command. For example,
5717the background form of the @code{continue} command is @code{continue&}, or
5718just @code{c&}. The execution commands that accept background execution
5719are:
5720
5721@table @code
5722@kindex run&
5723@item run
5724@xref{Starting, , Starting your Program}.
5725
5726@item attach
5727@kindex attach&
5728@xref{Attach, , Debugging an Already-running Process}.
5729
5730@item step
5731@kindex step&
5732@xref{Continuing and Stepping, step}.
5733
5734@item stepi
5735@kindex stepi&
5736@xref{Continuing and Stepping, stepi}.
5737
5738@item next
5739@kindex next&
5740@xref{Continuing and Stepping, next}.
5741
7ce58dd2
DE
5742@item nexti
5743@kindex nexti&
5744@xref{Continuing and Stepping, nexti}.
5745
0606b73b
SL
5746@item continue
5747@kindex continue&
5748@xref{Continuing and Stepping, continue}.
5749
5750@item finish
5751@kindex finish&
5752@xref{Continuing and Stepping, finish}.
5753
5754@item until
5755@kindex until&
5756@xref{Continuing and Stepping, until}.
5757
5758@end table
5759
5760Background execution is especially useful in conjunction with non-stop
5761mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
5762However, you can also use these commands in the normal all-stop mode with
5763the restriction that you cannot issue another execution command until the
5764previous one finishes. Examples of commands that are valid in all-stop
5765mode while the program is running include @code{help} and @code{info break}.
5766
5767You can interrupt your program while it is running in the background by
5768using the @code{interrupt} command.
5769
5770@table @code
5771@kindex interrupt
5772@item interrupt
5773@itemx interrupt -a
5774
5775Suspend execution of the running program. In all-stop mode,
5776@code{interrupt} stops the whole process, but in non-stop mode, it stops
5777only the current thread. To stop the whole program in non-stop mode,
5778use @code{interrupt -a}.
5779@end table
5780
0606b73b
SL
5781@node Thread-Specific Breakpoints
5782@subsection Thread-Specific Breakpoints
5783
c906108c 5784When your program has multiple threads (@pxref{Threads,, Debugging
79a6e687 5785Programs with Multiple Threads}), you can choose whether to set
c906108c
SS
5786breakpoints on all threads, or on a particular thread.
5787
5788@table @code
5789@cindex breakpoints and threads
5790@cindex thread breakpoints
5791@kindex break @dots{} thread @var{threadno}
5792@item break @var{linespec} thread @var{threadno}
5793@itemx break @var{linespec} thread @var{threadno} if @dots{}
5794@var{linespec} specifies source lines; there are several ways of
2a25a5ba
EZ
5795writing them (@pxref{Specify Location}), but the effect is always to
5796specify some source line.
c906108c
SS
5797
5798Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
5799to specify that you only want @value{GDBN} to stop the program when a
5800particular thread reaches this breakpoint. @var{threadno} is one of the
5801numeric thread identifiers assigned by @value{GDBN}, shown in the first
5802column of the @samp{info threads} display.
5803
5804If you do not specify @samp{thread @var{threadno}} when you set a
5805breakpoint, the breakpoint applies to @emph{all} threads of your
5806program.
5807
5808You can use the @code{thread} qualifier on conditional breakpoints as
b6199126
DJ
5809well; in this case, place @samp{thread @var{threadno}} before or
5810after the breakpoint condition, like this:
c906108c
SS
5811
5812@smallexample
2df3850c 5813(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
5814@end smallexample
5815
5816@end table
5817
0606b73b
SL
5818@node Interrupted System Calls
5819@subsection Interrupted System Calls
c906108c 5820
36d86913
MC
5821@cindex thread breakpoints and system calls
5822@cindex system calls and thread breakpoints
5823@cindex premature return from system calls
0606b73b
SL
5824There is an unfortunate side effect when using @value{GDBN} to debug
5825multi-threaded programs. If one thread stops for a
36d86913
MC
5826breakpoint, or for some other reason, and another thread is blocked in a
5827system call, then the system call may return prematurely. This is a
5828consequence of the interaction between multiple threads and the signals
5829that @value{GDBN} uses to implement breakpoints and other events that
5830stop execution.
5831
5832To handle this problem, your program should check the return value of
5833each system call and react appropriately. This is good programming
5834style anyways.
5835
5836For example, do not write code like this:
5837
5838@smallexample
5839 sleep (10);
5840@end smallexample
5841
5842The call to @code{sleep} will return early if a different thread stops
5843at a breakpoint or for some other reason.
5844
5845Instead, write this:
5846
5847@smallexample
5848 int unslept = 10;
5849 while (unslept > 0)
5850 unslept = sleep (unslept);
5851@end smallexample
5852
5853A system call is allowed to return early, so the system is still
5854conforming to its specification. But @value{GDBN} does cause your
5855multi-threaded program to behave differently than it would without
5856@value{GDBN}.
5857
5858Also, @value{GDBN} uses internal breakpoints in the thread library to
5859monitor certain events such as thread creation and thread destruction.
5860When such an event happens, a system call in another thread may return
5861prematurely, even though your program does not appear to stop.
5862
d914c394
SS
5863@node Observer Mode
5864@subsection Observer Mode
5865
5866If you want to build on non-stop mode and observe program behavior
5867without any chance of disruption by @value{GDBN}, you can set
5868variables to disable all of the debugger's attempts to modify state,
5869whether by writing memory, inserting breakpoints, etc. These operate
5870at a low level, intercepting operations from all commands.
5871
5872When all of these are set to @code{off}, then @value{GDBN} is said to
5873be @dfn{observer mode}. As a convenience, the variable
5874@code{observer} can be set to disable these, plus enable non-stop
5875mode.
5876
5877Note that @value{GDBN} will not prevent you from making nonsensical
5878combinations of these settings. For instance, if you have enabled
5879@code{may-insert-breakpoints} but disabled @code{may-write-memory},
5880then breakpoints that work by writing trap instructions into the code
5881stream will still not be able to be placed.
5882
5883@table @code
5884
5885@kindex observer
5886@item set observer on
5887@itemx set observer off
5888When set to @code{on}, this disables all the permission variables
5889below (except for @code{insert-fast-tracepoints}), plus enables
5890non-stop debugging. Setting this to @code{off} switches back to
5891normal debugging, though remaining in non-stop mode.
5892
5893@item show observer
5894Show whether observer mode is on or off.
5895
5896@kindex may-write-registers
5897@item set may-write-registers on
5898@itemx set may-write-registers off
5899This controls whether @value{GDBN} will attempt to alter the values of
5900registers, such as with assignment expressions in @code{print}, or the
5901@code{jump} command. It defaults to @code{on}.
5902
5903@item show may-write-registers
5904Show the current permission to write registers.
5905
5906@kindex may-write-memory
5907@item set may-write-memory on
5908@itemx set may-write-memory off
5909This controls whether @value{GDBN} will attempt to alter the contents
5910of memory, such as with assignment expressions in @code{print}. It
5911defaults to @code{on}.
5912
5913@item show may-write-memory
5914Show the current permission to write memory.
5915
5916@kindex may-insert-breakpoints
5917@item set may-insert-breakpoints on
5918@itemx set may-insert-breakpoints off
5919This controls whether @value{GDBN} will attempt to insert breakpoints.
5920This affects all breakpoints, including internal breakpoints defined
5921by @value{GDBN}. It defaults to @code{on}.
5922
5923@item show may-insert-breakpoints
5924Show the current permission to insert breakpoints.
5925
5926@kindex may-insert-tracepoints
5927@item set may-insert-tracepoints on
5928@itemx set may-insert-tracepoints off
5929This controls whether @value{GDBN} will attempt to insert (regular)
5930tracepoints at the beginning of a tracing experiment. It affects only
5931non-fast tracepoints, fast tracepoints being under the control of
5932@code{may-insert-fast-tracepoints}. It defaults to @code{on}.
5933
5934@item show may-insert-tracepoints
5935Show the current permission to insert tracepoints.
5936
5937@kindex may-insert-fast-tracepoints
5938@item set may-insert-fast-tracepoints on
5939@itemx set may-insert-fast-tracepoints off
5940This controls whether @value{GDBN} will attempt to insert fast
5941tracepoints at the beginning of a tracing experiment. It affects only
5942fast tracepoints, regular (non-fast) tracepoints being under the
5943control of @code{may-insert-tracepoints}. It defaults to @code{on}.
5944
5945@item show may-insert-fast-tracepoints
5946Show the current permission to insert fast tracepoints.
5947
5948@kindex may-interrupt
5949@item set may-interrupt on
5950@itemx set may-interrupt off
5951This controls whether @value{GDBN} will attempt to interrupt or stop
5952program execution. When this variable is @code{off}, the
5953@code{interrupt} command will have no effect, nor will
5954@kbd{Ctrl-c}. It defaults to @code{on}.
5955
5956@item show may-interrupt
5957Show the current permission to interrupt or stop the program.
5958
5959@end table
c906108c 5960
bacec72f
MS
5961@node Reverse Execution
5962@chapter Running programs backward
5963@cindex reverse execution
5964@cindex running programs backward
5965
5966When you are debugging a program, it is not unusual to realize that
5967you have gone too far, and some event of interest has already happened.
5968If the target environment supports it, @value{GDBN} can allow you to
5969``rewind'' the program by running it backward.
5970
5971A target environment that supports reverse execution should be able
5972to ``undo'' the changes in machine state that have taken place as the
5973program was executing normally. Variables, registers etc.@: should
5974revert to their previous values. Obviously this requires a great
5975deal of sophistication on the part of the target environment; not
5976all target environments can support reverse execution.
5977
5978When a program is executed in reverse, the instructions that
5979have most recently been executed are ``un-executed'', in reverse
5980order. The program counter runs backward, following the previous
5981thread of execution in reverse. As each instruction is ``un-executed'',
5982the values of memory and/or registers that were changed by that
5983instruction are reverted to their previous states. After executing
5984a piece of source code in reverse, all side effects of that code
5985should be ``undone'', and all variables should be returned to their
5986prior values@footnote{
5987Note that some side effects are easier to undo than others. For instance,
5988memory and registers are relatively easy, but device I/O is hard. Some
5989targets may be able undo things like device I/O, and some may not.
5990
5991The contract between @value{GDBN} and the reverse executing target
5992requires only that the target do something reasonable when
5993@value{GDBN} tells it to execute backwards, and then report the
5994results back to @value{GDBN}. Whatever the target reports back to
5995@value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
5996assumes that the memory and registers that the target reports are in a
5997consistant state, but @value{GDBN} accepts whatever it is given.
5998}.
5999
6000If you are debugging in a target environment that supports
6001reverse execution, @value{GDBN} provides the following commands.
6002
6003@table @code
6004@kindex reverse-continue
6005@kindex rc @r{(@code{reverse-continue})}
6006@item reverse-continue @r{[}@var{ignore-count}@r{]}
6007@itemx rc @r{[}@var{ignore-count}@r{]}
6008Beginning at the point where your program last stopped, start executing
6009in reverse. Reverse execution will stop for breakpoints and synchronous
6010exceptions (signals), just like normal execution. Behavior of
6011asynchronous signals depends on the target environment.
6012
6013@kindex reverse-step
6014@kindex rs @r{(@code{step})}
6015@item reverse-step @r{[}@var{count}@r{]}
6016Run the program backward until control reaches the start of a
6017different source line; then stop it, and return control to @value{GDBN}.
6018
6019Like the @code{step} command, @code{reverse-step} will only stop
6020at the beginning of a source line. It ``un-executes'' the previously
6021executed source line. If the previous source line included calls to
6022debuggable functions, @code{reverse-step} will step (backward) into
6023the called function, stopping at the beginning of the @emph{last}
6024statement in the called function (typically a return statement).
6025
6026Also, as with the @code{step} command, if non-debuggable functions are
6027called, @code{reverse-step} will run thru them backward without stopping.
6028
6029@kindex reverse-stepi
6030@kindex rsi @r{(@code{reverse-stepi})}
6031@item reverse-stepi @r{[}@var{count}@r{]}
6032Reverse-execute one machine instruction. Note that the instruction
6033to be reverse-executed is @emph{not} the one pointed to by the program
6034counter, but the instruction executed prior to that one. For instance,
6035if the last instruction was a jump, @code{reverse-stepi} will take you
6036back from the destination of the jump to the jump instruction itself.
6037
6038@kindex reverse-next
6039@kindex rn @r{(@code{reverse-next})}
6040@item reverse-next @r{[}@var{count}@r{]}
6041Run backward to the beginning of the previous line executed in
6042the current (innermost) stack frame. If the line contains function
6043calls, they will be ``un-executed'' without stopping. Starting from
6044the first line of a function, @code{reverse-next} will take you back
6045to the caller of that function, @emph{before} the function was called,
6046just as the normal @code{next} command would take you from the last
6047line of a function back to its return to its caller
16af530a 6048@footnote{Unless the code is too heavily optimized.}.
bacec72f
MS
6049
6050@kindex reverse-nexti
6051@kindex rni @r{(@code{reverse-nexti})}
6052@item reverse-nexti @r{[}@var{count}@r{]}
6053Like @code{nexti}, @code{reverse-nexti} executes a single instruction
6054in reverse, except that called functions are ``un-executed'' atomically.
6055That is, if the previously executed instruction was a return from
540aa8e7 6056another function, @code{reverse-nexti} will continue to execute
bacec72f
MS
6057in reverse until the call to that function (from the current stack
6058frame) is reached.
6059
6060@kindex reverse-finish
6061@item reverse-finish
6062Just as the @code{finish} command takes you to the point where the
6063current function returns, @code{reverse-finish} takes you to the point
6064where it was called. Instead of ending up at the end of the current
6065function invocation, you end up at the beginning.
6066
6067@kindex set exec-direction
6068@item set exec-direction
6069Set the direction of target execution.
984359d2 6070@item set exec-direction reverse
bacec72f
MS
6071@cindex execute forward or backward in time
6072@value{GDBN} will perform all execution commands in reverse, until the
6073exec-direction mode is changed to ``forward''. Affected commands include
6074@code{step, stepi, next, nexti, continue, and finish}. The @code{return}
6075command cannot be used in reverse mode.
6076@item set exec-direction forward
6077@value{GDBN} will perform all execution commands in the normal fashion.
6078This is the default.
6079@end table
6080
c906108c 6081
a2311334
EZ
6082@node Process Record and Replay
6083@chapter Recording Inferior's Execution and Replaying It
53cc454a
HZ
6084@cindex process record and replay
6085@cindex recording inferior's execution and replaying it
6086
8e05493c
EZ
6087On some platforms, @value{GDBN} provides a special @dfn{process record
6088and replay} target that can record a log of the process execution, and
6089replay it later with both forward and reverse execution commands.
a2311334
EZ
6090
6091@cindex replay mode
6092When this target is in use, if the execution log includes the record
6093for the next instruction, @value{GDBN} will debug in @dfn{replay
6094mode}. In the replay mode, the inferior does not really execute code
6095instructions. Instead, all the events that normally happen during
6096code execution are taken from the execution log. While code is not
6097really executed in replay mode, the values of registers (including the
6098program counter register) and the memory of the inferior are still
8e05493c
EZ
6099changed as they normally would. Their contents are taken from the
6100execution log.
a2311334
EZ
6101
6102@cindex record mode
6103If the record for the next instruction is not in the execution log,
6104@value{GDBN} will debug in @dfn{record mode}. In this mode, the
6105inferior executes normally, and @value{GDBN} records the execution log
6106for future replay.
6107
8e05493c
EZ
6108The process record and replay target supports reverse execution
6109(@pxref{Reverse Execution}), even if the platform on which the
6110inferior runs does not. However, the reverse execution is limited in
6111this case by the range of the instructions recorded in the execution
6112log. In other words, reverse execution on platforms that don't
6113support it directly can only be done in the replay mode.
6114
6115When debugging in the reverse direction, @value{GDBN} will work in
6116replay mode as long as the execution log includes the record for the
6117previous instruction; otherwise, it will work in record mode, if the
6118platform supports reverse execution, or stop if not.
6119
a2311334
EZ
6120For architecture environments that support process record and replay,
6121@value{GDBN} provides the following commands:
53cc454a
HZ
6122
6123@table @code
6124@kindex target record
59ea5688
MM
6125@kindex target record-full
6126@kindex target record-btrace
53cc454a 6127@kindex record
59ea5688
MM
6128@kindex record full
6129@kindex record btrace
53cc454a 6130@kindex rec
59ea5688
MM
6131@kindex rec full
6132@kindex rec btrace
6133@item record @var{method}
6134This command starts the process record and replay target. The
6135recording method can be specified as parameter. Without a parameter
6136the command uses the @code{full} recording method. The following
6137recording methods are available:
a2311334 6138
59ea5688
MM
6139@table @code
6140@item full
6141Full record/replay recording using @value{GDBN}'s software record and
6142replay implementation. This method allows replaying and reverse
6143execution.
6144
6145@item btrace
6146Hardware-supported instruction recording. This method does not allow
6147replaying and reverse execution.
6148
6149This recording method may not be available on all processors.
6150@end table
6151
6152The process record and replay target can only debug a process that is
6153already running. Therefore, you need first to start the process with
6154the @kbd{run} or @kbd{start} commands, and then start the recording
6155with the @kbd{record @var{method}} command.
6156
6157Both @code{record @var{method}} and @code{rec @var{method}} are
6158aliases of @code{target record-@var{method}}.
a2311334
EZ
6159
6160@cindex displaced stepping, and process record and replay
6161Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
6162will be automatically disabled when process record and replay target
6163is started. That's because the process record and replay target
6164doesn't support displaced stepping.
6165
6166@cindex non-stop mode, and process record and replay
6167@cindex asynchronous execution, and process record and replay
6168If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
59ea5688
MM
6169the asynchronous execution mode (@pxref{Background Execution}), not
6170all recording methods are available. The @code{full} recording method
6171does not support these two modes.
53cc454a
HZ
6172
6173@kindex record stop
6174@kindex rec s
6175@item record stop
a2311334
EZ
6176Stop the process record and replay target. When process record and
6177replay target stops, the entire execution log will be deleted and the
6178inferior will either be terminated, or will remain in its final state.
53cc454a 6179
a2311334
EZ
6180When you stop the process record and replay target in record mode (at
6181the end of the execution log), the inferior will be stopped at the
6182next instruction that would have been recorded. In other words, if
6183you record for a while and then stop recording, the inferior process
6184will be left in the same state as if the recording never happened.
53cc454a 6185
a2311334
EZ
6186On the other hand, if the process record and replay target is stopped
6187while in replay mode (that is, not at the end of the execution log,
6188but at some earlier point), the inferior process will become ``live''
6189at that earlier state, and it will then be possible to continue the
6190usual ``live'' debugging of the process from that state.
53cc454a 6191
a2311334
EZ
6192When the inferior process exits, or @value{GDBN} detaches from it,
6193process record and replay target will automatically stop itself.
53cc454a 6194
24e933df
HZ
6195@kindex record save
6196@item record save @var{filename}
6197Save the execution log to a file @file{@var{filename}}.
6198Default filename is @file{gdb_record.@var{process_id}}, where
6199@var{process_id} is the process ID of the inferior.
6200
59ea5688
MM
6201This command may not be available for all recording methods.
6202
24e933df
HZ
6203@kindex record restore
6204@item record restore @var{filename}
6205Restore the execution log from a file @file{@var{filename}}.
6206File must have been created with @code{record save}.
6207
59ea5688
MM
6208@kindex set record full
6209@item set record full insn-number-max @var{limit}
f81d1120 6210@itemx set record full insn-number-max unlimited
59ea5688
MM
6211Set the limit of instructions to be recorded for the @code{full}
6212recording method. Default value is 200000.
53cc454a 6213
a2311334
EZ
6214If @var{limit} is a positive number, then @value{GDBN} will start
6215deleting instructions from the log once the number of the record
6216instructions becomes greater than @var{limit}. For every new recorded
6217instruction, @value{GDBN} will delete the earliest recorded
6218instruction to keep the number of recorded instructions at the limit.
6219(Since deleting recorded instructions loses information, @value{GDBN}
6220lets you control what happens when the limit is reached, by means of
6221the @code{stop-at-limit} option, described below.)
53cc454a 6222
f81d1120
PA
6223If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
6224delete recorded instructions from the execution log. The number of
6225recorded instructions is limited only by the available memory.
53cc454a 6226
59ea5688
MM
6227@kindex show record full
6228@item show record full insn-number-max
6229Show the limit of instructions to be recorded with the @code{full}
6230recording method.
53cc454a 6231
59ea5688
MM
6232@item set record full stop-at-limit
6233Control the behavior of the @code{full} recording method when the
6234number of recorded instructions reaches the limit. If ON (the
6235default), @value{GDBN} will stop when the limit is reached for the
6236first time and ask you whether you want to stop the inferior or
6237continue running it and recording the execution log. If you decide
6238to continue recording, each new recorded instruction will cause the
6239oldest one to be deleted.
53cc454a 6240
a2311334
EZ
6241If this option is OFF, @value{GDBN} will automatically delete the
6242oldest record to make room for each new one, without asking.
53cc454a 6243
59ea5688 6244@item show record full stop-at-limit
a2311334 6245Show the current setting of @code{stop-at-limit}.
53cc454a 6246
59ea5688 6247@item set record full memory-query
bb08c432 6248Control the behavior when @value{GDBN} is unable to record memory
59ea5688
MM
6249changes caused by an instruction for the @code{full} recording method.
6250If ON, @value{GDBN} will query whether to stop the inferior in that
6251case.
bb08c432
HZ
6252
6253If this option is OFF (the default), @value{GDBN} will automatically
6254ignore the effect of such instructions on memory. Later, when
6255@value{GDBN} replays this execution log, it will mark the log of this
6256instruction as not accessible, and it will not affect the replay
6257results.
6258
59ea5688 6259@item show record full memory-query
bb08c432
HZ
6260Show the current setting of @code{memory-query}.
6261
29153c24
MS
6262@kindex info record
6263@item info record
59ea5688
MM
6264Show various statistics about the recording depending on the recording
6265method:
6266
6267@table @code
6268@item full
6269For the @code{full} recording method, it shows the state of process
6270record and its in-memory execution log buffer, including:
29153c24
MS
6271
6272@itemize @bullet
6273@item
6274Whether in record mode or replay mode.
6275@item
6276Lowest recorded instruction number (counting from when the current execution log started recording instructions).
6277@item
6278Highest recorded instruction number.
6279@item
6280Current instruction about to be replayed (if in replay mode).
6281@item
6282Number of instructions contained in the execution log.
6283@item
6284Maximum number of instructions that may be contained in the execution log.
6285@end itemize
53cc454a 6286
59ea5688
MM
6287@item btrace
6288For the @code{btrace} recording method, it shows the number of
6289instructions that have been recorded and the number of blocks of
6290sequential control-flow that is formed by the recorded instructions.
6291@end table
6292
53cc454a
HZ
6293@kindex record delete
6294@kindex rec del
6295@item record delete
a2311334 6296When record target runs in replay mode (``in the past''), delete the
53cc454a 6297subsequent execution log and begin to record a new execution log starting
a2311334 6298from the current address. This means you will abandon the previously
53cc454a 6299recorded ``future'' and begin recording a new ``future''.
59ea5688
MM
6300
6301@kindex record instruction-history
6302@kindex rec instruction-history
6303@item record instruction-history
6304Disassembles instructions from the recorded execution log. By
6305default, ten instructions are disassembled. This can be changed using
6306the @code{set record instruction-history-size} command. Instructions
6307are printed in execution order. There are several ways to specify
6308what part of the execution log to disassemble:
6309
6310@table @code
6311@item record instruction-history @var{insn}
6312Disassembles ten instructions starting from instruction number
6313@var{insn}.
6314
6315@item record instruction-history @var{insn}, +/-@var{n}
6316Disassembles @var{n} instructions around instruction number
6317@var{insn}. If @var{n} is preceded with @code{+}, disassembles
6318@var{n} instructions after instruction number @var{insn}. If
6319@var{n} is preceded with @code{-}, disassembles @var{n}
6320instructions before instruction number @var{insn}.
6321
6322@item record instruction-history
6323Disassembles ten more instructions after the last disassembly.
6324
6325@item record instruction-history -
6326Disassembles ten more instructions before the last disassembly.
6327
6328@item record instruction-history @var{begin} @var{end}
6329Disassembles instructions beginning with instruction number
6330@var{begin} until instruction number @var{end}. The instruction
6331number @var{end} is not included.
6332@end table
6333
6334This command may not be available for all recording methods.
6335
6336@kindex set record
f81d1120
PA
6337@item set record instruction-history-size @var{size}
6338@itemx set record instruction-history-size unlimited
59ea5688
MM
6339Define how many instructions to disassemble in the @code{record
6340instruction-history} command. The default value is 10.
f81d1120 6341A @var{size} of @code{unlimited} means unlimited instructions.
59ea5688
MM
6342
6343@kindex show record
6344@item show record instruction-history-size
6345Show how many instructions to disassemble in the @code{record
6346instruction-history} command.
6347
6348@kindex record function-call-history
6349@kindex rec function-call-history
6350@item record function-call-history
6351Prints the execution history at function granularity. It prints one
6352line for each sequence of instructions that belong to the same
6353function giving the name of that function, the source lines
6354for this instruction sequence (if the @code{/l} modifier is
6355specified), and the instructions numbers that form the sequence (if
6356the @code{/i} modifier is specified).
6357
6358@smallexample
6359(@value{GDBP}) @b{list 1, 10}
63601 void foo (void)
63612 @{
63623 @}
63634
63645 void bar (void)
63656 @{
63667 ...
63678 foo ();
63689 ...
636910 @}
6370(@value{GDBP}) @b{record function-call-history /l}
63711 foo.c:6-8 bar
63722 foo.c:2-3 foo
63733 foo.c:9-10 bar
6374@end smallexample
6375
6376By default, ten lines are printed. This can be changed using the
6377@code{set record function-call-history-size} command. Functions are
6378printed in execution order. There are several ways to specify what
6379to print:
6380
6381@table @code
6382@item record function-call-history @var{func}
6383Prints ten functions starting from function number @var{func}.
6384
6385@item record function-call-history @var{func}, +/-@var{n}
6386Prints @var{n} functions around function number @var{func}. If
6387@var{n} is preceded with @code{+}, prints @var{n} functions after
6388function number @var{func}. If @var{n} is preceded with @code{-},
6389prints @var{n} functions before function number @var{func}.
6390
6391@item record function-call-history
6392Prints ten more functions after the last ten-line print.
6393
6394@item record function-call-history -
6395Prints ten more functions before the last ten-line print.
6396
6397@item record function-call-history @var{begin} @var{end}
6398Prints functions beginning with function number @var{begin} until
6399function number @var{end}. The function number @var{end} is not
6400included.
6401@end table
6402
6403This command may not be available for all recording methods.
6404
f81d1120
PA
6405@item set record function-call-history-size @var{size}
6406@itemx set record function-call-history-size unlimited
59ea5688
MM
6407Define how many lines to print in the
6408@code{record function-call-history} command. The default value is 10.
f81d1120 6409A size of @code{unlimited} means unlimited lines.
59ea5688
MM
6410
6411@item show record function-call-history-size
6412Show how many lines to print in the
6413@code{record function-call-history} command.
53cc454a
HZ
6414@end table
6415
6416
6d2ebf8b 6417@node Stack
c906108c
SS
6418@chapter Examining the Stack
6419
6420When your program has stopped, the first thing you need to know is where it
6421stopped and how it got there.
6422
6423@cindex call stack
5d161b24
DB
6424Each time your program performs a function call, information about the call
6425is generated.
6426That information includes the location of the call in your program,
6427the arguments of the call,
c906108c 6428and the local variables of the function being called.
5d161b24 6429The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
6430The stack frames are allocated in a region of memory called the @dfn{call
6431stack}.
6432
6433When your program stops, the @value{GDBN} commands for examining the
6434stack allow you to see all of this information.
6435
6436@cindex selected frame
6437One of the stack frames is @dfn{selected} by @value{GDBN} and many
6438@value{GDBN} commands refer implicitly to the selected frame. In
6439particular, whenever you ask @value{GDBN} for the value of a variable in
6440your program, the value is found in the selected frame. There are
6441special @value{GDBN} commands to select whichever frame you are
79a6e687 6442interested in. @xref{Selection, ,Selecting a Frame}.
c906108c
SS
6443
6444When your program stops, @value{GDBN} automatically selects the
5d161b24 6445currently executing frame and describes it briefly, similar to the
79a6e687 6446@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
c906108c
SS
6447
6448@menu
6449* Frames:: Stack frames
6450* Backtrace:: Backtraces
6451* Selection:: Selecting a frame
6452* Frame Info:: Information on a frame
c906108c
SS
6453
6454@end menu
6455
6d2ebf8b 6456@node Frames
79a6e687 6457@section Stack Frames
c906108c 6458
d4f3574e 6459@cindex frame, definition
c906108c
SS
6460@cindex stack frame
6461The call stack is divided up into contiguous pieces called @dfn{stack
6462frames}, or @dfn{frames} for short; each frame is the data associated
6463with one call to one function. The frame contains the arguments given
6464to the function, the function's local variables, and the address at
6465which the function is executing.
6466
6467@cindex initial frame
6468@cindex outermost frame
6469@cindex innermost frame
6470When your program is started, the stack has only one frame, that of the
6471function @code{main}. This is called the @dfn{initial} frame or the
6472@dfn{outermost} frame. Each time a function is called, a new frame is
6473made. Each time a function returns, the frame for that function invocation
6474is eliminated. If a function is recursive, there can be many frames for
6475the same function. The frame for the function in which execution is
6476actually occurring is called the @dfn{innermost} frame. This is the most
6477recently created of all the stack frames that still exist.
6478
6479@cindex frame pointer
6480Inside your program, stack frames are identified by their addresses. A
6481stack frame consists of many bytes, each of which has its own address; each
6482kind of computer has a convention for choosing one byte whose
6483address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
6484in a register called the @dfn{frame pointer register}
6485(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
6486
6487@cindex frame number
6488@value{GDBN} assigns numbers to all existing stack frames, starting with
6489zero for the innermost frame, one for the frame that called it,
6490and so on upward. These numbers do not really exist in your program;
6491they are assigned by @value{GDBN} to give you a way of designating stack
6492frames in @value{GDBN} commands.
6493
6d2ebf8b
SS
6494@c The -fomit-frame-pointer below perennially causes hbox overflow
6495@c underflow problems.
c906108c
SS
6496@cindex frameless execution
6497Some compilers provide a way to compile functions so that they operate
e22ea452 6498without stack frames. (For example, the @value{NGCC} option
474c8240 6499@smallexample
6d2ebf8b 6500@samp{-fomit-frame-pointer}
474c8240 6501@end smallexample
6d2ebf8b 6502generates functions without a frame.)
c906108c
SS
6503This is occasionally done with heavily used library functions to save
6504the frame setup time. @value{GDBN} has limited facilities for dealing
6505with these function invocations. If the innermost function invocation
6506has no stack frame, @value{GDBN} nevertheless regards it as though
6507it had a separate frame, which is numbered zero as usual, allowing
6508correct tracing of the function call chain. However, @value{GDBN} has
6509no provision for frameless functions elsewhere in the stack.
6510
6511@table @code
d4f3574e 6512@kindex frame@r{, command}
41afff9a 6513@cindex current stack frame
c906108c 6514@item frame @var{args}
5d161b24 6515The @code{frame} command allows you to move from one stack frame to another,
c906108c 6516and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
6517address of the frame or the stack frame number. Without an argument,
6518@code{frame} prints the current stack frame.
c906108c
SS
6519
6520@kindex select-frame
41afff9a 6521@cindex selecting frame silently
c906108c
SS
6522@item select-frame
6523The @code{select-frame} command allows you to move from one stack frame
6524to another without printing the frame. This is the silent version of
6525@code{frame}.
6526@end table
6527
6d2ebf8b 6528@node Backtrace
c906108c
SS
6529@section Backtraces
6530
09d4efe1
EZ
6531@cindex traceback
6532@cindex call stack traces
c906108c
SS
6533A backtrace is a summary of how your program got where it is. It shows one
6534line per frame, for many frames, starting with the currently executing
6535frame (frame zero), followed by its caller (frame one), and on up the
6536stack.
6537
6538@table @code
6539@kindex backtrace
41afff9a 6540@kindex bt @r{(@code{backtrace})}
c906108c
SS
6541@item backtrace
6542@itemx bt
6543Print a backtrace of the entire stack: one line per frame for all
6544frames in the stack.
6545
6546You can stop the backtrace at any time by typing the system interrupt
c8aa23ab 6547character, normally @kbd{Ctrl-c}.
c906108c
SS
6548
6549@item backtrace @var{n}
6550@itemx bt @var{n}
6551Similar, but print only the innermost @var{n} frames.
6552
6553@item backtrace -@var{n}
6554@itemx bt -@var{n}
6555Similar, but print only the outermost @var{n} frames.
0f061b69
NR
6556
6557@item backtrace full
0f061b69 6558@itemx bt full
dd74f6ae
NR
6559@itemx bt full @var{n}
6560@itemx bt full -@var{n}
e7109c7e 6561Print the values of the local variables also. @var{n} specifies the
286ba84d 6562number of frames to print, as described above.
c906108c
SS
6563@end table
6564
6565@kindex where
6566@kindex info stack
c906108c
SS
6567The names @code{where} and @code{info stack} (abbreviated @code{info s})
6568are additional aliases for @code{backtrace}.
6569
839c27b7
EZ
6570@cindex multiple threads, backtrace
6571In a multi-threaded program, @value{GDBN} by default shows the
6572backtrace only for the current thread. To display the backtrace for
6573several or all of the threads, use the command @code{thread apply}
6574(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
6575apply all backtrace}, @value{GDBN} will display the backtrace for all
6576the threads; this is handy when you debug a core dump of a
6577multi-threaded program.
6578
c906108c
SS
6579Each line in the backtrace shows the frame number and the function name.
6580The program counter value is also shown---unless you use @code{set
6581print address off}. The backtrace also shows the source file name and
6582line number, as well as the arguments to the function. The program
6583counter value is omitted if it is at the beginning of the code for that
6584line number.
6585
6586Here is an example of a backtrace. It was made with the command
6587@samp{bt 3}, so it shows the innermost three frames.
6588
6589@smallexample
6590@group
5d161b24 6591#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c 6592 at builtin.c:993
4f5376b2 6593#1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
c906108c
SS
6594#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
6595 at macro.c:71
6596(More stack frames follow...)
6597@end group
6598@end smallexample
6599
6600@noindent
6601The display for frame zero does not begin with a program counter
6602value, indicating that your program has stopped at the beginning of the
6603code for line @code{993} of @code{builtin.c}.
6604
4f5376b2
JB
6605@noindent
6606The value of parameter @code{data} in frame 1 has been replaced by
6607@code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
6608only if it is a scalar (integer, pointer, enumeration, etc). See command
6609@kbd{set print frame-arguments} in @ref{Print Settings} for more details
6610on how to configure the way function parameter values are printed.
6611
585fdaa1 6612@cindex optimized out, in backtrace
18999be5
EZ
6613@cindex function call arguments, optimized out
6614If your program was compiled with optimizations, some compilers will
6615optimize away arguments passed to functions if those arguments are
6616never used after the call. Such optimizations generate code that
6617passes arguments through registers, but doesn't store those arguments
6618in the stack frame. @value{GDBN} has no way of displaying such
6619arguments in stack frames other than the innermost one. Here's what
6620such a backtrace might look like:
6621
6622@smallexample
6623@group
6624#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
6625 at builtin.c:993
585fdaa1
PA
6626#1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
6627#2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
18999be5
EZ
6628 at macro.c:71
6629(More stack frames follow...)
6630@end group
6631@end smallexample
6632
6633@noindent
6634The values of arguments that were not saved in their stack frames are
585fdaa1 6635shown as @samp{<optimized out>}.
18999be5
EZ
6636
6637If you need to display the values of such optimized-out arguments,
6638either deduce that from other variables whose values depend on the one
6639you are interested in, or recompile without optimizations.
6640
a8f24a35
EZ
6641@cindex backtrace beyond @code{main} function
6642@cindex program entry point
6643@cindex startup code, and backtrace
25d29d70
AC
6644Most programs have a standard user entry point---a place where system
6645libraries and startup code transition into user code. For C this is
d416eeec
EZ
6646@code{main}@footnote{
6647Note that embedded programs (the so-called ``free-standing''
6648environment) are not required to have a @code{main} function as the
6649entry point. They could even have multiple entry points.}.
6650When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
6651it will terminate the backtrace, to avoid tracing into highly
6652system-specific (and generally uninteresting) code.
6653
6654If you need to examine the startup code, or limit the number of levels
6655in a backtrace, you can change this behavior:
95f90d25
DJ
6656
6657@table @code
25d29d70
AC
6658@item set backtrace past-main
6659@itemx set backtrace past-main on
4644b6e3 6660@kindex set backtrace
25d29d70
AC
6661Backtraces will continue past the user entry point.
6662
6663@item set backtrace past-main off
95f90d25
DJ
6664Backtraces will stop when they encounter the user entry point. This is the
6665default.
6666
25d29d70 6667@item show backtrace past-main
4644b6e3 6668@kindex show backtrace
25d29d70
AC
6669Display the current user entry point backtrace policy.
6670
2315ffec
RC
6671@item set backtrace past-entry
6672@itemx set backtrace past-entry on
a8f24a35 6673Backtraces will continue past the internal entry point of an application.
2315ffec
RC
6674This entry point is encoded by the linker when the application is built,
6675and is likely before the user entry point @code{main} (or equivalent) is called.
6676
6677@item set backtrace past-entry off
d3e8051b 6678Backtraces will stop when they encounter the internal entry point of an
2315ffec
RC
6679application. This is the default.
6680
6681@item show backtrace past-entry
6682Display the current internal entry point backtrace policy.
6683
25d29d70
AC
6684@item set backtrace limit @var{n}
6685@itemx set backtrace limit 0
f81d1120 6686@itemx set backtrace limit unlimited
25d29d70 6687@cindex backtrace limit
f81d1120
PA
6688Limit the backtrace to @var{n} levels. A value of @code{unlimited}
6689or zero means unlimited levels.
95f90d25 6690
25d29d70
AC
6691@item show backtrace limit
6692Display the current limit on backtrace levels.
95f90d25
DJ
6693@end table
6694
1b56eb55
JK
6695You can control how file names are displayed.
6696
6697@table @code
6698@item set filename-display
6699@itemx set filename-display relative
6700@cindex filename-display
6701Display file names relative to the compilation directory. This is the default.
6702
6703@item set filename-display basename
6704Display only basename of a filename.
6705
6706@item set filename-display absolute
6707Display an absolute filename.
6708
6709@item show filename-display
6710Show the current way to display filenames.
6711@end table
6712
6d2ebf8b 6713@node Selection
79a6e687 6714@section Selecting a Frame
c906108c
SS
6715
6716Most commands for examining the stack and other data in your program work on
6717whichever stack frame is selected at the moment. Here are the commands for
6718selecting a stack frame; all of them finish by printing a brief description
6719of the stack frame just selected.
6720
6721@table @code
d4f3574e 6722@kindex frame@r{, selecting}
41afff9a 6723@kindex f @r{(@code{frame})}
c906108c
SS
6724@item frame @var{n}
6725@itemx f @var{n}
6726Select frame number @var{n}. Recall that frame zero is the innermost
6727(currently executing) frame, frame one is the frame that called the
6728innermost one, and so on. The highest-numbered frame is the one for
6729@code{main}.
6730
6731@item frame @var{addr}
6732@itemx f @var{addr}
6733Select the frame at address @var{addr}. This is useful mainly if the
6734chaining of stack frames has been damaged by a bug, making it
6735impossible for @value{GDBN} to assign numbers properly to all frames. In
6736addition, this can be useful when your program has multiple stacks and
6737switches between them.
6738
c906108c
SS
6739On the SPARC architecture, @code{frame} needs two addresses to
6740select an arbitrary frame: a frame pointer and a stack pointer.
6741
eb17f351 6742On the @acronym{MIPS} and Alpha architecture, it needs two addresses: a stack
c906108c
SS
6743pointer and a program counter.
6744
6745On the 29k architecture, it needs three addresses: a register stack
6746pointer, a program counter, and a memory stack pointer.
c906108c
SS
6747
6748@kindex up
6749@item up @var{n}
6750Move @var{n} frames up the stack. For positive numbers @var{n}, this
6751advances toward the outermost frame, to higher frame numbers, to frames
6752that have existed longer. @var{n} defaults to one.
6753
6754@kindex down
41afff9a 6755@kindex do @r{(@code{down})}
c906108c
SS
6756@item down @var{n}
6757Move @var{n} frames down the stack. For positive numbers @var{n}, this
6758advances toward the innermost frame, to lower frame numbers, to frames
6759that were created more recently. @var{n} defaults to one. You may
6760abbreviate @code{down} as @code{do}.
6761@end table
6762
6763All of these commands end by printing two lines of output describing the
6764frame. The first line shows the frame number, the function name, the
6765arguments, and the source file and line number of execution in that
5d161b24 6766frame. The second line shows the text of that source line.
c906108c
SS
6767
6768@need 1000
6769For example:
6770
6771@smallexample
6772@group
6773(@value{GDBP}) up
6774#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
6775 at env.c:10
677610 read_input_file (argv[i]);
6777@end group
6778@end smallexample
6779
6780After such a printout, the @code{list} command with no arguments
6781prints ten lines centered on the point of execution in the frame.
87885426
FN
6782You can also edit the program at the point of execution with your favorite
6783editing program by typing @code{edit}.
79a6e687 6784@xref{List, ,Printing Source Lines},
87885426 6785for details.
c906108c
SS
6786
6787@table @code
6788@kindex down-silently
6789@kindex up-silently
6790@item up-silently @var{n}
6791@itemx down-silently @var{n}
6792These two commands are variants of @code{up} and @code{down},
6793respectively; they differ in that they do their work silently, without
6794causing display of the new frame. They are intended primarily for use
6795in @value{GDBN} command scripts, where the output might be unnecessary and
6796distracting.
6797@end table
6798
6d2ebf8b 6799@node Frame Info
79a6e687 6800@section Information About a Frame
c906108c
SS
6801
6802There are several other commands to print information about the selected
6803stack frame.
6804
6805@table @code
6806@item frame
6807@itemx f
6808When used without any argument, this command does not change which
6809frame is selected, but prints a brief description of the currently
6810selected stack frame. It can be abbreviated @code{f}. With an
6811argument, this command is used to select a stack frame.
79a6e687 6812@xref{Selection, ,Selecting a Frame}.
c906108c
SS
6813
6814@kindex info frame
41afff9a 6815@kindex info f @r{(@code{info frame})}
c906108c
SS
6816@item info frame
6817@itemx info f
6818This command prints a verbose description of the selected stack frame,
6819including:
6820
6821@itemize @bullet
5d161b24
DB
6822@item
6823the address of the frame
c906108c
SS
6824@item
6825the address of the next frame down (called by this frame)
6826@item
6827the address of the next frame up (caller of this frame)
6828@item
6829the language in which the source code corresponding to this frame is written
6830@item
6831the address of the frame's arguments
6832@item
d4f3574e
SS
6833the address of the frame's local variables
6834@item
c906108c
SS
6835the program counter saved in it (the address of execution in the caller frame)
6836@item
6837which registers were saved in the frame
6838@end itemize
6839
6840@noindent The verbose description is useful when
6841something has gone wrong that has made the stack format fail to fit
6842the usual conventions.
6843
6844@item info frame @var{addr}
6845@itemx info f @var{addr}
6846Print a verbose description of the frame at address @var{addr}, without
6847selecting that frame. The selected frame remains unchanged by this
6848command. This requires the same kind of address (more than one for some
6849architectures) that you specify in the @code{frame} command.
79a6e687 6850@xref{Selection, ,Selecting a Frame}.
c906108c
SS
6851
6852@kindex info args
6853@item info args
6854Print the arguments of the selected frame, each on a separate line.
6855
6856@item info locals
6857@kindex info locals
6858Print the local variables of the selected frame, each on a separate
6859line. These are all variables (declared either static or automatic)
6860accessible at the point of execution of the selected frame.
6861
c906108c
SS
6862@end table
6863
c906108c 6864
6d2ebf8b 6865@node Source
c906108c
SS
6866@chapter Examining Source Files
6867
6868@value{GDBN} can print parts of your program's source, since the debugging
6869information recorded in the program tells @value{GDBN} what source files were
6870used to build it. When your program stops, @value{GDBN} spontaneously prints
6871the line where it stopped. Likewise, when you select a stack frame
79a6e687 6872(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
c906108c
SS
6873execution in that frame has stopped. You can print other portions of
6874source files by explicit command.
6875
7a292a7a 6876If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 6877prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 6878@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
6879
6880@menu
6881* List:: Printing source lines
2a25a5ba 6882* Specify Location:: How to specify code locations
87885426 6883* Edit:: Editing source files
c906108c 6884* Search:: Searching source files
c906108c
SS
6885* Source Path:: Specifying source directories
6886* Machine Code:: Source and machine code
6887@end menu
6888
6d2ebf8b 6889@node List
79a6e687 6890@section Printing Source Lines
c906108c
SS
6891
6892@kindex list
41afff9a 6893@kindex l @r{(@code{list})}
c906108c 6894To print lines from a source file, use the @code{list} command
5d161b24 6895(abbreviated @code{l}). By default, ten lines are printed.
2a25a5ba
EZ
6896There are several ways to specify what part of the file you want to
6897print; see @ref{Specify Location}, for the full list.
c906108c
SS
6898
6899Here are the forms of the @code{list} command most commonly used:
6900
6901@table @code
6902@item list @var{linenum}
6903Print lines centered around line number @var{linenum} in the
6904current source file.
6905
6906@item list @var{function}
6907Print lines centered around the beginning of function
6908@var{function}.
6909
6910@item list
6911Print more lines. If the last lines printed were printed with a
6912@code{list} command, this prints lines following the last lines
6913printed; however, if the last line printed was a solitary line printed
6914as part of displaying a stack frame (@pxref{Stack, ,Examining the
6915Stack}), this prints lines centered around that line.
6916
6917@item list -
6918Print lines just before the lines last printed.
6919@end table
6920
9c16f35a 6921@cindex @code{list}, how many lines to display
c906108c
SS
6922By default, @value{GDBN} prints ten source lines with any of these forms of
6923the @code{list} command. You can change this using @code{set listsize}:
6924
6925@table @code
6926@kindex set listsize
6927@item set listsize @var{count}
f81d1120 6928@itemx set listsize unlimited
c906108c
SS
6929Make the @code{list} command display @var{count} source lines (unless
6930the @code{list} argument explicitly specifies some other number).
f81d1120 6931Setting @var{count} to @code{unlimited} or 0 means there's no limit.
c906108c
SS
6932
6933@kindex show listsize
6934@item show listsize
6935Display the number of lines that @code{list} prints.
6936@end table
6937
6938Repeating a @code{list} command with @key{RET} discards the argument,
6939so it is equivalent to typing just @code{list}. This is more useful
6940than listing the same lines again. An exception is made for an
6941argument of @samp{-}; that argument is preserved in repetition so that
6942each repetition moves up in the source file.
6943
c906108c
SS
6944In general, the @code{list} command expects you to supply zero, one or two
6945@dfn{linespecs}. Linespecs specify source lines; there are several ways
2a25a5ba
EZ
6946of writing them (@pxref{Specify Location}), but the effect is always
6947to specify some source line.
6948
c906108c
SS
6949Here is a complete description of the possible arguments for @code{list}:
6950
6951@table @code
6952@item list @var{linespec}
6953Print lines centered around the line specified by @var{linespec}.
6954
6955@item list @var{first},@var{last}
6956Print lines from @var{first} to @var{last}. Both arguments are
2a25a5ba
EZ
6957linespecs. When a @code{list} command has two linespecs, and the
6958source file of the second linespec is omitted, this refers to
6959the same source file as the first linespec.
c906108c
SS
6960
6961@item list ,@var{last}
6962Print lines ending with @var{last}.
6963
6964@item list @var{first},
6965Print lines starting with @var{first}.
6966
6967@item list +
6968Print lines just after the lines last printed.
6969
6970@item list -
6971Print lines just before the lines last printed.
6972
6973@item list
6974As described in the preceding table.
6975@end table
6976
2a25a5ba
EZ
6977@node Specify Location
6978@section Specifying a Location
6979@cindex specifying location
6980@cindex linespec
c906108c 6981
2a25a5ba
EZ
6982Several @value{GDBN} commands accept arguments that specify a location
6983of your program's code. Since @value{GDBN} is a source-level
6984debugger, a location usually specifies some line in the source code;
6985for that reason, locations are also known as @dfn{linespecs}.
c906108c 6986
2a25a5ba
EZ
6987Here are all the different ways of specifying a code location that
6988@value{GDBN} understands:
c906108c 6989
2a25a5ba
EZ
6990@table @code
6991@item @var{linenum}
6992Specifies the line number @var{linenum} of the current source file.
c906108c 6993
2a25a5ba
EZ
6994@item -@var{offset}
6995@itemx +@var{offset}
6996Specifies the line @var{offset} lines before or after the @dfn{current
6997line}. For the @code{list} command, the current line is the last one
6998printed; for the breakpoint commands, this is the line at which
6999execution stopped in the currently selected @dfn{stack frame}
7000(@pxref{Frames, ,Frames}, for a description of stack frames.) When
7001used as the second of the two linespecs in a @code{list} command,
7002this specifies the line @var{offset} lines up or down from the first
7003linespec.
7004
7005@item @var{filename}:@var{linenum}
7006Specifies the line @var{linenum} in the source file @var{filename}.
4aac40c8
TT
7007If @var{filename} is a relative file name, then it will match any
7008source file name with the same trailing components. For example, if
7009@var{filename} is @samp{gcc/expr.c}, then it will match source file
7010name of @file{/build/trunk/gcc/expr.c}, but not
7011@file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
c906108c
SS
7012
7013@item @var{function}
7014Specifies the line that begins the body of the function @var{function}.
2a25a5ba 7015For example, in C, this is the line with the open brace.
c906108c 7016
9ef07c8c
TT
7017@item @var{function}:@var{label}
7018Specifies the line where @var{label} appears in @var{function}.
7019
c906108c 7020@item @var{filename}:@var{function}
2a25a5ba
EZ
7021Specifies the line that begins the body of the function @var{function}
7022in the file @var{filename}. You only need the file name with a
7023function name to avoid ambiguity when there are identically named
7024functions in different source files.
c906108c 7025
0f5238ed
TT
7026@item @var{label}
7027Specifies the line at which the label named @var{label} appears.
7028@value{GDBN} searches for the label in the function corresponding to
7029the currently selected stack frame. If there is no current selected
7030stack frame (for instance, if the inferior is not running), then
7031@value{GDBN} will not search for a label.
7032
c906108c 7033@item *@var{address}
2a25a5ba
EZ
7034Specifies the program address @var{address}. For line-oriented
7035commands, such as @code{list} and @code{edit}, this specifies a source
7036line that contains @var{address}. For @code{break} and other
7037breakpoint oriented commands, this can be used to set breakpoints in
7038parts of your program which do not have debugging information or
7039source files.
7040
7041Here @var{address} may be any expression valid in the current working
7042language (@pxref{Languages, working language}) that specifies a code
5fa54e5d
EZ
7043address. In addition, as a convenience, @value{GDBN} extends the
7044semantics of expressions used in locations to cover the situations
7045that frequently happen during debugging. Here are the various forms
7046of @var{address}:
2a25a5ba
EZ
7047
7048@table @code
7049@item @var{expression}
7050Any expression valid in the current working language.
7051
7052@item @var{funcaddr}
7053An address of a function or procedure derived from its name. In C,
7054C@t{++}, Java, Objective-C, Fortran, minimal, and assembly, this is
7055simply the function's name @var{function} (and actually a special case
7056of a valid expression). In Pascal and Modula-2, this is
7057@code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
7058(although the Pascal form also works).
7059
7060This form specifies the address of the function's first instruction,
7061before the stack frame and arguments have been set up.
7062
7063@item '@var{filename}'::@var{funcaddr}
7064Like @var{funcaddr} above, but also specifies the name of the source
7065file explicitly. This is useful if the name of the function does not
7066specify the function unambiguously, e.g., if there are several
7067functions with identical names in different source files.
c906108c
SS
7068@end table
7069
62e5f89c
SDJ
7070@cindex breakpoint at static probe point
7071@item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
7072The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
7073applications to embed static probes. @xref{Static Probe Points}, for more
7074information on finding and using static probes. This form of linespec
7075specifies the location of such a static probe.
7076
7077If @var{objfile} is given, only probes coming from that shared library
7078or executable matching @var{objfile} as a regular expression are considered.
7079If @var{provider} is given, then only probes from that provider are considered.
7080If several probes match the spec, @value{GDBN} will insert a breakpoint at
7081each one of those probes.
7082
2a25a5ba
EZ
7083@end table
7084
7085
87885426 7086@node Edit
79a6e687 7087@section Editing Source Files
87885426
FN
7088@cindex editing source files
7089
7090@kindex edit
7091@kindex e @r{(@code{edit})}
7092To edit the lines in a source file, use the @code{edit} command.
7093The editing program of your choice
7094is invoked with the current line set to
7095the active line in the program.
7096Alternatively, there are several ways to specify what part of the file you
2a25a5ba 7097want to print if you want to see other parts of the program:
87885426
FN
7098
7099@table @code
2a25a5ba
EZ
7100@item edit @var{location}
7101Edit the source file specified by @code{location}. Editing starts at
7102that @var{location}, e.g., at the specified source line of the
7103specified file. @xref{Specify Location}, for all the possible forms
7104of the @var{location} argument; here are the forms of the @code{edit}
7105command most commonly used:
87885426 7106
2a25a5ba 7107@table @code
87885426
FN
7108@item edit @var{number}
7109Edit the current source file with @var{number} as the active line number.
7110
7111@item edit @var{function}
7112Edit the file containing @var{function} at the beginning of its definition.
2a25a5ba 7113@end table
87885426 7114
87885426
FN
7115@end table
7116
79a6e687 7117@subsection Choosing your Editor
87885426
FN
7118You can customize @value{GDBN} to use any editor you want
7119@footnote{
7120The only restriction is that your editor (say @code{ex}), recognizes the
7121following command-line syntax:
10998722 7122@smallexample
87885426 7123ex +@var{number} file
10998722 7124@end smallexample
15387254
EZ
7125The optional numeric value +@var{number} specifies the number of the line in
7126the file where to start editing.}.
7127By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
7128by setting the environment variable @code{EDITOR} before using
7129@value{GDBN}. For example, to configure @value{GDBN} to use the
7130@code{vi} editor, you could use these commands with the @code{sh} shell:
7131@smallexample
87885426
FN
7132EDITOR=/usr/bin/vi
7133export EDITOR
15387254 7134gdb @dots{}
10998722 7135@end smallexample
87885426 7136or in the @code{csh} shell,
10998722 7137@smallexample
87885426 7138setenv EDITOR /usr/bin/vi
15387254 7139gdb @dots{}
10998722 7140@end smallexample
87885426 7141
6d2ebf8b 7142@node Search
79a6e687 7143@section Searching Source Files
15387254 7144@cindex searching source files
c906108c
SS
7145
7146There are two commands for searching through the current source file for a
7147regular expression.
7148
7149@table @code
7150@kindex search
7151@kindex forward-search
1e96de83 7152@kindex fo @r{(@code{forward-search})}
c906108c
SS
7153@item forward-search @var{regexp}
7154@itemx search @var{regexp}
7155The command @samp{forward-search @var{regexp}} checks each line,
7156starting with the one following the last line listed, for a match for
5d161b24 7157@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
7158synonym @samp{search @var{regexp}} or abbreviate the command name as
7159@code{fo}.
7160
09d4efe1 7161@kindex reverse-search
c906108c
SS
7162@item reverse-search @var{regexp}
7163The command @samp{reverse-search @var{regexp}} checks each line, starting
7164with the one before the last line listed and going backward, for a match
7165for @var{regexp}. It lists the line that is found. You can abbreviate
7166this command as @code{rev}.
7167@end table
c906108c 7168
6d2ebf8b 7169@node Source Path
79a6e687 7170@section Specifying Source Directories
c906108c
SS
7171
7172@cindex source path
7173@cindex directories for source files
7174Executable programs sometimes do not record the directories of the source
7175files from which they were compiled, just the names. Even when they do,
7176the directories could be moved between the compilation and your debugging
7177session. @value{GDBN} has a list of directories to search for source files;
7178this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
7179it tries all the directories in the list, in the order they are present
0b66e38c
EZ
7180in the list, until it finds a file with the desired name.
7181
7182For example, suppose an executable references the file
7183@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
7184@file{/mnt/cross}. The file is first looked up literally; if this
7185fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
7186fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
7187message is printed. @value{GDBN} does not look up the parts of the
7188source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
7189Likewise, the subdirectories of the source path are not searched: if
7190the source path is @file{/mnt/cross}, and the binary refers to
7191@file{foo.c}, @value{GDBN} would not find it under
7192@file{/mnt/cross/usr/src/foo-1.0/lib}.
7193
7194Plain file names, relative file names with leading directories, file
7195names containing dots, etc.@: are all treated as described above; for
7196instance, if the source path is @file{/mnt/cross}, and the source file
7197is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
7198@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
7199that---@file{/mnt/cross/foo.c}.
7200
7201Note that the executable search path is @emph{not} used to locate the
cd852561 7202source files.
c906108c
SS
7203
7204Whenever you reset or rearrange the source path, @value{GDBN} clears out
7205any information it has cached about where source files are found and where
7206each line is in the file.
7207
7208@kindex directory
7209@kindex dir
d4f3574e
SS
7210When you start @value{GDBN}, its source path includes only @samp{cdir}
7211and @samp{cwd}, in that order.
c906108c
SS
7212To add other directories, use the @code{directory} command.
7213
4b505b12
AS
7214The search path is used to find both program source files and @value{GDBN}
7215script files (read using the @samp{-command} option and @samp{source} command).
7216
30daae6c
JB
7217In addition to the source path, @value{GDBN} provides a set of commands
7218that manage a list of source path substitution rules. A @dfn{substitution
7219rule} specifies how to rewrite source directories stored in the program's
7220debug information in case the sources were moved to a different
7221directory between compilation and debugging. A rule is made of
7222two strings, the first specifying what needs to be rewritten in
7223the path, and the second specifying how it should be rewritten.
7224In @ref{set substitute-path}, we name these two parts @var{from} and
7225@var{to} respectively. @value{GDBN} does a simple string replacement
7226of @var{from} with @var{to} at the start of the directory part of the
7227source file name, and uses that result instead of the original file
7228name to look up the sources.
7229
7230Using the previous example, suppose the @file{foo-1.0} tree has been
7231moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
3f94c067 7232@value{GDBN} to replace @file{/usr/src} in all source path names with
30daae6c
JB
7233@file{/mnt/cross}. The first lookup will then be
7234@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
7235of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
7236substitution rule, use the @code{set substitute-path} command
7237(@pxref{set substitute-path}).
7238
7239To avoid unexpected substitution results, a rule is applied only if the
7240@var{from} part of the directory name ends at a directory separator.
7241For instance, a rule substituting @file{/usr/source} into
7242@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
7243not to @file{/usr/sourceware/foo-2.0}. And because the substitution
d3e8051b 7244is applied only at the beginning of the directory name, this rule will
30daae6c
JB
7245not be applied to @file{/root/usr/source/baz.c} either.
7246
7247In many cases, you can achieve the same result using the @code{directory}
7248command. However, @code{set substitute-path} can be more efficient in
7249the case where the sources are organized in a complex tree with multiple
7250subdirectories. With the @code{directory} command, you need to add each
7251subdirectory of your project. If you moved the entire tree while
7252preserving its internal organization, then @code{set substitute-path}
7253allows you to direct the debugger to all the sources with one single
7254command.
7255
7256@code{set substitute-path} is also more than just a shortcut command.
7257The source path is only used if the file at the original location no
7258longer exists. On the other hand, @code{set substitute-path} modifies
7259the debugger behavior to look at the rewritten location instead. So, if
7260for any reason a source file that is not relevant to your executable is
7261located at the original location, a substitution rule is the only
3f94c067 7262method available to point @value{GDBN} at the new location.
30daae6c 7263
29b0e8a2
JM
7264@cindex @samp{--with-relocated-sources}
7265@cindex default source path substitution
7266You can configure a default source path substitution rule by
7267configuring @value{GDBN} with the
7268@samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
7269should be the name of a directory under @value{GDBN}'s configured
7270prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
7271directory names in debug information under @var{dir} will be adjusted
7272automatically if the installed @value{GDBN} is moved to a new
7273location. This is useful if @value{GDBN}, libraries or executables
7274with debug information and corresponding source code are being moved
7275together.
7276
c906108c
SS
7277@table @code
7278@item directory @var{dirname} @dots{}
7279@item dir @var{dirname} @dots{}
7280Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
7281directory names may be given to this command, separated by @samp{:}
7282(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
7283part of absolute file names) or
c906108c
SS
7284whitespace. You may specify a directory that is already in the source
7285path; this moves it forward, so @value{GDBN} searches it sooner.
7286
7287@kindex cdir
7288@kindex cwd
41afff9a 7289@vindex $cdir@r{, convenience variable}
d3e8051b 7290@vindex $cwd@r{, convenience variable}
c906108c
SS
7291@cindex compilation directory
7292@cindex current directory
7293@cindex working directory
7294@cindex directory, current
7295@cindex directory, compilation
7296You can use the string @samp{$cdir} to refer to the compilation
7297directory (if one is recorded), and @samp{$cwd} to refer to the current
7298working directory. @samp{$cwd} is not the same as @samp{.}---the former
7299tracks the current working directory as it changes during your @value{GDBN}
7300session, while the latter is immediately expanded to the current
7301directory at the time you add an entry to the source path.
7302
7303@item directory
cd852561 7304Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
7305
7306@c RET-repeat for @code{directory} is explicitly disabled, but since
7307@c repeating it would be a no-op we do not say that. (thanks to RMS)
7308
99e7ae30
DE
7309@item set directories @var{path-list}
7310@kindex set directories
7311Set the source path to @var{path-list}.
7312@samp{$cdir:$cwd} are added if missing.
7313
c906108c
SS
7314@item show directories
7315@kindex show directories
7316Print the source path: show which directories it contains.
30daae6c
JB
7317
7318@anchor{set substitute-path}
7319@item set substitute-path @var{from} @var{to}
7320@kindex set substitute-path
7321Define a source path substitution rule, and add it at the end of the
7322current list of existing substitution rules. If a rule with the same
7323@var{from} was already defined, then the old rule is also deleted.
7324
7325For example, if the file @file{/foo/bar/baz.c} was moved to
7326@file{/mnt/cross/baz.c}, then the command
7327
7328@smallexample
7329(@value{GDBP}) set substitute-path /usr/src /mnt/cross
7330@end smallexample
7331
7332@noindent
7333will tell @value{GDBN} to replace @samp{/usr/src} with
7334@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
7335@file{baz.c} even though it was moved.
7336
7337In the case when more than one substitution rule have been defined,
7338the rules are evaluated one by one in the order where they have been
7339defined. The first one matching, if any, is selected to perform
7340the substitution.
7341
7342For instance, if we had entered the following commands:
7343
7344@smallexample
7345(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
7346(@value{GDBP}) set substitute-path /usr/src /mnt/src
7347@end smallexample
7348
7349@noindent
7350@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
7351@file{/mnt/include/defs.h} by using the first rule. However, it would
7352use the second rule to rewrite @file{/usr/src/lib/foo.c} into
7353@file{/mnt/src/lib/foo.c}.
7354
7355
7356@item unset substitute-path [path]
7357@kindex unset substitute-path
7358If a path is specified, search the current list of substitution rules
7359for a rule that would rewrite that path. Delete that rule if found.
7360A warning is emitted by the debugger if no rule could be found.
7361
7362If no path is specified, then all substitution rules are deleted.
7363
7364@item show substitute-path [path]
7365@kindex show substitute-path
7366If a path is specified, then print the source path substitution rule
7367which would rewrite that path, if any.
7368
7369If no path is specified, then print all existing source path substitution
7370rules.
7371
c906108c
SS
7372@end table
7373
7374If your source path is cluttered with directories that are no longer of
7375interest, @value{GDBN} may sometimes cause confusion by finding the wrong
7376versions of source. You can correct the situation as follows:
7377
7378@enumerate
7379@item
cd852561 7380Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
7381
7382@item
7383Use @code{directory} with suitable arguments to reinstall the
7384directories you want in the source path. You can add all the
7385directories in one command.
7386@end enumerate
7387
6d2ebf8b 7388@node Machine Code
79a6e687 7389@section Source and Machine Code
15387254 7390@cindex source line and its code address
c906108c
SS
7391
7392You can use the command @code{info line} to map source lines to program
7393addresses (and vice versa), and the command @code{disassemble} to display
91440f57
HZ
7394a range of addresses as machine instructions. You can use the command
7395@code{set disassemble-next-line} to set whether to disassemble next
7396source line when execution stops. When run under @sc{gnu} Emacs
d4f3574e 7397mode, the @code{info line} command causes the arrow to point to the
5d161b24 7398line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
7399well as hex.
7400
7401@table @code
7402@kindex info line
7403@item info line @var{linespec}
7404Print the starting and ending addresses of the compiled code for
7405source line @var{linespec}. You can specify source lines in any of
2a25a5ba 7406the ways documented in @ref{Specify Location}.
c906108c
SS
7407@end table
7408
7409For example, we can use @code{info line} to discover the location of
7410the object code for the first line of function
7411@code{m4_changequote}:
7412
d4f3574e
SS
7413@c FIXME: I think this example should also show the addresses in
7414@c symbolic form, as they usually would be displayed.
c906108c 7415@smallexample
96a2c332 7416(@value{GDBP}) info line m4_changequote
c906108c
SS
7417Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
7418@end smallexample
7419
7420@noindent
15387254 7421@cindex code address and its source line
c906108c
SS
7422We can also inquire (using @code{*@var{addr}} as the form for
7423@var{linespec}) what source line covers a particular address:
7424@smallexample
7425(@value{GDBP}) info line *0x63ff
7426Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
7427@end smallexample
7428
7429@cindex @code{$_} and @code{info line}
15387254 7430@cindex @code{x} command, default address
41afff9a 7431@kindex x@r{(examine), and} info line
c906108c
SS
7432After @code{info line}, the default address for the @code{x} command
7433is changed to the starting address of the line, so that @samp{x/i} is
7434sufficient to begin examining the machine code (@pxref{Memory,
79a6e687 7435,Examining Memory}). Also, this address is saved as the value of the
c906108c 7436convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
79a6e687 7437Variables}).
c906108c
SS
7438
7439@table @code
7440@kindex disassemble
7441@cindex assembly instructions
7442@cindex instructions, assembly
7443@cindex machine instructions
7444@cindex listing machine instructions
7445@item disassemble
d14508fe 7446@itemx disassemble /m
9b117ef3 7447@itemx disassemble /r
c906108c 7448This specialized command dumps a range of memory as machine
d14508fe 7449instructions. It can also print mixed source+disassembly by specifying
9b117ef3
HZ
7450the @code{/m} modifier and print the raw instructions in hex as well as
7451in symbolic form by specifying the @code{/r}.
d14508fe 7452The default memory range is the function surrounding the
c906108c
SS
7453program counter of the selected frame. A single argument to this
7454command is a program counter value; @value{GDBN} dumps the function
21a0512e
PP
7455surrounding this value. When two arguments are given, they should
7456be separated by a comma, possibly surrounded by whitespace. The
53a71c06
CR
7457arguments specify a range of addresses to dump, in one of two forms:
7458
7459@table @code
7460@item @var{start},@var{end}
7461the addresses from @var{start} (inclusive) to @var{end} (exclusive)
7462@item @var{start},+@var{length}
7463the addresses from @var{start} (inclusive) to
7464@code{@var{start}+@var{length}} (exclusive).
7465@end table
7466
7467@noindent
7468When 2 arguments are specified, the name of the function is also
7469printed (since there could be several functions in the given range).
21a0512e
PP
7470
7471The argument(s) can be any expression yielding a numeric value, such as
7472@samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
2b28d209
PP
7473
7474If the range of memory being disassembled contains current program counter,
7475the instruction at that location is shown with a @code{=>} marker.
c906108c
SS
7476@end table
7477
c906108c
SS
7478The following example shows the disassembly of a range of addresses of
7479HP PA-RISC 2.0 code:
7480
7481@smallexample
21a0512e 7482(@value{GDBP}) disas 0x32c4, 0x32e4
c906108c 7483Dump of assembler code from 0x32c4 to 0x32e4:
2b28d209
PP
7484 0x32c4 <main+204>: addil 0,dp
7485 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
7486 0x32cc <main+212>: ldil 0x3000,r31
7487 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
7488 0x32d4 <main+220>: ldo 0(r31),rp
7489 0x32d8 <main+224>: addil -0x800,dp
7490 0x32dc <main+228>: ldo 0x588(r1),r26
7491 0x32e0 <main+232>: ldil 0x3000,r31
c906108c
SS
7492End of assembler dump.
7493@end smallexample
c906108c 7494
2b28d209
PP
7495Here is an example showing mixed source+assembly for Intel x86, when the
7496program is stopped just after function prologue:
d14508fe
DE
7497
7498@smallexample
7499(@value{GDBP}) disas /m main
7500Dump of assembler code for function main:
75015 @{
9c419145
PP
7502 0x08048330 <+0>: push %ebp
7503 0x08048331 <+1>: mov %esp,%ebp
7504 0x08048333 <+3>: sub $0x8,%esp
7505 0x08048336 <+6>: and $0xfffffff0,%esp
7506 0x08048339 <+9>: sub $0x10,%esp
d14508fe
DE
7507
75086 printf ("Hello.\n");
9c419145
PP
7509=> 0x0804833c <+12>: movl $0x8048440,(%esp)
7510 0x08048343 <+19>: call 0x8048284 <puts@@plt>
d14508fe
DE
7511
75127 return 0;
75138 @}
9c419145
PP
7514 0x08048348 <+24>: mov $0x0,%eax
7515 0x0804834d <+29>: leave
7516 0x0804834e <+30>: ret
d14508fe
DE
7517
7518End of assembler dump.
7519@end smallexample
7520
53a71c06
CR
7521Here is another example showing raw instructions in hex for AMD x86-64,
7522
7523@smallexample
7524(gdb) disas /r 0x400281,+10
7525Dump of assembler code from 0x400281 to 0x40028b:
7526 0x0000000000400281: 38 36 cmp %dh,(%rsi)
7527 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
7528 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
7529 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
7530End of assembler dump.
7531@end smallexample
7532
7e1e0340
DE
7533Addresses cannot be specified as a linespec (@pxref{Specify Location}).
7534So, for example, if you want to disassemble function @code{bar}
7535in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
7536and not @samp{disassemble foo.c:bar}.
7537
c906108c
SS
7538Some architectures have more than one commonly-used set of instruction
7539mnemonics or other syntax.
7540
76d17f34
EZ
7541For programs that were dynamically linked and use shared libraries,
7542instructions that call functions or branch to locations in the shared
7543libraries might show a seemingly bogus location---it's actually a
7544location of the relocation table. On some architectures, @value{GDBN}
7545might be able to resolve these to actual function names.
7546
c906108c 7547@table @code
d4f3574e 7548@kindex set disassembly-flavor
d4f3574e
SS
7549@cindex Intel disassembly flavor
7550@cindex AT&T disassembly flavor
7551@item set disassembly-flavor @var{instruction-set}
c906108c
SS
7552Select the instruction set to use when disassembling the
7553program via the @code{disassemble} or @code{x/i} commands.
7554
7555Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
7556can set @var{instruction-set} to either @code{intel} or @code{att}.
7557The default is @code{att}, the AT&T flavor used by default by Unix
7558assemblers for x86-based targets.
9c16f35a
EZ
7559
7560@kindex show disassembly-flavor
7561@item show disassembly-flavor
7562Show the current setting of the disassembly flavor.
c906108c
SS
7563@end table
7564
91440f57
HZ
7565@table @code
7566@kindex set disassemble-next-line
7567@kindex show disassemble-next-line
7568@item set disassemble-next-line
7569@itemx show disassemble-next-line
32ae1842
EZ
7570Control whether or not @value{GDBN} will disassemble the next source
7571line or instruction when execution stops. If ON, @value{GDBN} will
7572display disassembly of the next source line when execution of the
7573program being debugged stops. This is @emph{in addition} to
7574displaying the source line itself, which @value{GDBN} always does if
7575possible. If the next source line cannot be displayed for some reason
7576(e.g., if @value{GDBN} cannot find the source file, or there's no line
7577info in the debug info), @value{GDBN} will display disassembly of the
7578next @emph{instruction} instead of showing the next source line. If
7579AUTO, @value{GDBN} will display disassembly of next instruction only
7580if the source line cannot be displayed. This setting causes
7581@value{GDBN} to display some feedback when you step through a function
7582with no line info or whose source file is unavailable. The default is
7583OFF, which means never display the disassembly of the next line or
7584instruction.
91440f57
HZ
7585@end table
7586
c906108c 7587
6d2ebf8b 7588@node Data
c906108c
SS
7589@chapter Examining Data
7590
7591@cindex printing data
7592@cindex examining data
7593@kindex print
7594@kindex inspect
c906108c 7595The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
7596command (abbreviated @code{p}), or its synonym @code{inspect}. It
7597evaluates and prints the value of an expression of the language your
7598program is written in (@pxref{Languages, ,Using @value{GDBN} with
78e2826b
TT
7599Different Languages}). It may also print the expression using a
7600Python-based pretty-printer (@pxref{Pretty Printing}).
c906108c
SS
7601
7602@table @code
d4f3574e
SS
7603@item print @var{expr}
7604@itemx print /@var{f} @var{expr}
7605@var{expr} is an expression (in the source language). By default the
7606value of @var{expr} is printed in a format appropriate to its data type;
c906108c 7607you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 7608@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
79a6e687 7609Formats}.
c906108c
SS
7610
7611@item print
7612@itemx print /@var{f}
15387254 7613@cindex reprint the last value
d4f3574e 7614If you omit @var{expr}, @value{GDBN} displays the last value again (from the
79a6e687 7615@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
c906108c
SS
7616conveniently inspect the same value in an alternative format.
7617@end table
7618
7619A more low-level way of examining data is with the @code{x} command.
7620It examines data in memory at a specified address and prints it in a
79a6e687 7621specified format. @xref{Memory, ,Examining Memory}.
c906108c 7622
7a292a7a 7623If you are interested in information about types, or about how the
d4f3574e
SS
7624fields of a struct or a class are declared, use the @code{ptype @var{exp}}
7625command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 7626Table}.
c906108c 7627
06fc020f
SCR
7628@cindex exploring hierarchical data structures
7629@kindex explore
7630Another way of examining values of expressions and type information is
7631through the Python extension command @code{explore} (available only if
7632the @value{GDBN} build is configured with @code{--with-python}). It
7633offers an interactive way to start at the highest level (or, the most
7634abstract level) of the data type of an expression (or, the data type
7635itself) and explore all the way down to leaf scalar values/fields
7636embedded in the higher level data types.
7637
7638@table @code
7639@item explore @var{arg}
7640@var{arg} is either an expression (in the source language), or a type
7641visible in the current context of the program being debugged.
7642@end table
7643
7644The working of the @code{explore} command can be illustrated with an
7645example. If a data type @code{struct ComplexStruct} is defined in your
7646C program as
7647
7648@smallexample
7649struct SimpleStruct
7650@{
7651 int i;
7652 double d;
7653@};
7654
7655struct ComplexStruct
7656@{
7657 struct SimpleStruct *ss_p;
7658 int arr[10];
7659@};
7660@end smallexample
7661
7662@noindent
7663followed by variable declarations as
7664
7665@smallexample
7666struct SimpleStruct ss = @{ 10, 1.11 @};
7667struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
7668@end smallexample
7669
7670@noindent
7671then, the value of the variable @code{cs} can be explored using the
7672@code{explore} command as follows.
7673
7674@smallexample
7675(gdb) explore cs
7676The value of `cs' is a struct/class of type `struct ComplexStruct' with
7677the following fields:
7678
7679 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
7680 arr = <Enter 1 to explore this field of type `int [10]'>
7681
7682Enter the field number of choice:
7683@end smallexample
7684
7685@noindent
7686Since the fields of @code{cs} are not scalar values, you are being
7687prompted to chose the field you want to explore. Let's say you choose
7688the field @code{ss_p} by entering @code{0}. Then, since this field is a
7689pointer, you will be asked if it is pointing to a single value. From
7690the declaration of @code{cs} above, it is indeed pointing to a single
7691value, hence you enter @code{y}. If you enter @code{n}, then you will
7692be asked if it were pointing to an array of values, in which case this
7693field will be explored as if it were an array.
7694
7695@smallexample
7696`cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
7697Continue exploring it as a pointer to a single value [y/n]: y
7698The value of `*(cs.ss_p)' is a struct/class of type `struct
7699SimpleStruct' with the following fields:
7700
7701 i = 10 .. (Value of type `int')
7702 d = 1.1100000000000001 .. (Value of type `double')
7703
7704Press enter to return to parent value:
7705@end smallexample
7706
7707@noindent
7708If the field @code{arr} of @code{cs} was chosen for exploration by
7709entering @code{1} earlier, then since it is as array, you will be
7710prompted to enter the index of the element in the array that you want
7711to explore.
7712
7713@smallexample
7714`cs.arr' is an array of `int'.
7715Enter the index of the element you want to explore in `cs.arr': 5
7716
7717`(cs.arr)[5]' is a scalar value of type `int'.
7718
7719(cs.arr)[5] = 4
7720
7721Press enter to return to parent value:
7722@end smallexample
7723
7724In general, at any stage of exploration, you can go deeper towards the
7725leaf values by responding to the prompts appropriately, or hit the
7726return key to return to the enclosing data structure (the @i{higher}
7727level data structure).
7728
7729Similar to exploring values, you can use the @code{explore} command to
7730explore types. Instead of specifying a value (which is typically a
7731variable name or an expression valid in the current context of the
7732program being debugged), you specify a type name. If you consider the
7733same example as above, your can explore the type
7734@code{struct ComplexStruct} by passing the argument
7735@code{struct ComplexStruct} to the @code{explore} command.
7736
7737@smallexample
7738(gdb) explore struct ComplexStruct
7739@end smallexample
7740
7741@noindent
7742By responding to the prompts appropriately in the subsequent interactive
7743session, you can explore the type @code{struct ComplexStruct} in a
7744manner similar to how the value @code{cs} was explored in the above
7745example.
7746
7747The @code{explore} command also has two sub-commands,
7748@code{explore value} and @code{explore type}. The former sub-command is
7749a way to explicitly specify that value exploration of the argument is
7750being invoked, while the latter is a way to explicitly specify that type
7751exploration of the argument is being invoked.
7752
7753@table @code
7754@item explore value @var{expr}
7755@cindex explore value
7756This sub-command of @code{explore} explores the value of the
7757expression @var{expr} (if @var{expr} is an expression valid in the
7758current context of the program being debugged). The behavior of this
7759command is identical to that of the behavior of the @code{explore}
7760command being passed the argument @var{expr}.
7761
7762@item explore type @var{arg}
7763@cindex explore type
7764This sub-command of @code{explore} explores the type of @var{arg} (if
7765@var{arg} is a type visible in the current context of program being
7766debugged), or the type of the value/expression @var{arg} (if @var{arg}
7767is an expression valid in the current context of the program being
7768debugged). If @var{arg} is a type, then the behavior of this command is
7769identical to that of the @code{explore} command being passed the
7770argument @var{arg}. If @var{arg} is an expression, then the behavior of
7771this command will be identical to that of the @code{explore} command
7772being passed the type of @var{arg} as the argument.
7773@end table
7774
c906108c
SS
7775@menu
7776* Expressions:: Expressions
6ba66d6a 7777* Ambiguous Expressions:: Ambiguous Expressions
c906108c
SS
7778* Variables:: Program variables
7779* Arrays:: Artificial arrays
7780* Output Formats:: Output formats
7781* Memory:: Examining memory
7782* Auto Display:: Automatic display
7783* Print Settings:: Print settings
4c374409 7784* Pretty Printing:: Python pretty printing
c906108c
SS
7785* Value History:: Value history
7786* Convenience Vars:: Convenience variables
a72c3253 7787* Convenience Funs:: Convenience functions
c906108c 7788* Registers:: Registers
c906108c 7789* Floating Point Hardware:: Floating point hardware
53c69bd7 7790* Vector Unit:: Vector Unit
721c2651 7791* OS Information:: Auxiliary data provided by operating system
29e57380 7792* Memory Region Attributes:: Memory region attributes
16d9dec6 7793* Dump/Restore Files:: Copy between memory and a file
384ee23f 7794* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
7795* Character Sets:: Debugging programs that use a different
7796 character set than GDB does
09d4efe1 7797* Caching Remote Data:: Data caching for remote targets
08388c79 7798* Searching Memory:: Searching memory for a sequence of bytes
c906108c
SS
7799@end menu
7800
6d2ebf8b 7801@node Expressions
c906108c
SS
7802@section Expressions
7803
7804@cindex expressions
7805@code{print} and many other @value{GDBN} commands accept an expression and
7806compute its value. Any kind of constant, variable or operator defined
7807by the programming language you are using is valid in an expression in
e2e0bcd1
JB
7808@value{GDBN}. This includes conditional expressions, function calls,
7809casts, and string constants. It also includes preprocessor macros, if
7810you compiled your program to include this information; see
7811@ref{Compilation}.
c906108c 7812
15387254 7813@cindex arrays in expressions
d4f3574e
SS
7814@value{GDBN} supports array constants in expressions input by
7815the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
63092375
DJ
7816you can use the command @code{print @{1, 2, 3@}} to create an array
7817of three integers. If you pass an array to a function or assign it
7818to a program variable, @value{GDBN} copies the array to memory that
7819is @code{malloc}ed in the target program.
c906108c 7820
c906108c
SS
7821Because C is so widespread, most of the expressions shown in examples in
7822this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
7823Languages}, for information on how to use expressions in other
7824languages.
7825
7826In this section, we discuss operators that you can use in @value{GDBN}
7827expressions regardless of your programming language.
7828
15387254 7829@cindex casts, in expressions
c906108c
SS
7830Casts are supported in all languages, not just in C, because it is so
7831useful to cast a number into a pointer in order to examine a structure
7832at that address in memory.
7833@c FIXME: casts supported---Mod2 true?
c906108c
SS
7834
7835@value{GDBN} supports these operators, in addition to those common
7836to programming languages:
7837
7838@table @code
7839@item @@
7840@samp{@@} is a binary operator for treating parts of memory as arrays.
79a6e687 7841@xref{Arrays, ,Artificial Arrays}, for more information.
c906108c
SS
7842
7843@item ::
7844@samp{::} allows you to specify a variable in terms of the file or
79a6e687 7845function where it is defined. @xref{Variables, ,Program Variables}.
c906108c
SS
7846
7847@cindex @{@var{type}@}
7848@cindex type casting memory
7849@cindex memory, viewing as typed object
7850@cindex casts, to view memory
7851@item @{@var{type}@} @var{addr}
7852Refers to an object of type @var{type} stored at address @var{addr} in
7853memory. @var{addr} may be any expression whose value is an integer or
7854pointer (but parentheses are required around binary operators, just as in
7855a cast). This construct is allowed regardless of what kind of data is
7856normally supposed to reside at @var{addr}.
7857@end table
7858
6ba66d6a
JB
7859@node Ambiguous Expressions
7860@section Ambiguous Expressions
7861@cindex ambiguous expressions
7862
7863Expressions can sometimes contain some ambiguous elements. For instance,
7864some programming languages (notably Ada, C@t{++} and Objective-C) permit
7865a single function name to be defined several times, for application in
7866different contexts. This is called @dfn{overloading}. Another example
7867involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
7868templates and is typically instantiated several times, resulting in
7869the same function name being defined in different contexts.
7870
7871In some cases and depending on the language, it is possible to adjust
7872the expression to remove the ambiguity. For instance in C@t{++}, you
7873can specify the signature of the function you want to break on, as in
7874@kbd{break @var{function}(@var{types})}. In Ada, using the fully
7875qualified name of your function often makes the expression unambiguous
7876as well.
7877
7878When an ambiguity that needs to be resolved is detected, the debugger
7879has the capability to display a menu of numbered choices for each
7880possibility, and then waits for the selection with the prompt @samp{>}.
7881The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
7882aborts the current command. If the command in which the expression was
7883used allows more than one choice to be selected, the next option in the
7884menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
7885choices.
7886
7887For example, the following session excerpt shows an attempt to set a
7888breakpoint at the overloaded symbol @code{String::after}.
7889We choose three particular definitions of that function name:
7890
7891@c FIXME! This is likely to change to show arg type lists, at least
7892@smallexample
7893@group
7894(@value{GDBP}) b String::after
7895[0] cancel
7896[1] all
7897[2] file:String.cc; line number:867
7898[3] file:String.cc; line number:860
7899[4] file:String.cc; line number:875
7900[5] file:String.cc; line number:853
7901[6] file:String.cc; line number:846
7902[7] file:String.cc; line number:735
7903> 2 4 6
7904Breakpoint 1 at 0xb26c: file String.cc, line 867.
7905Breakpoint 2 at 0xb344: file String.cc, line 875.
7906Breakpoint 3 at 0xafcc: file String.cc, line 846.
7907Multiple breakpoints were set.
7908Use the "delete" command to delete unwanted
7909 breakpoints.
7910(@value{GDBP})
7911@end group
7912@end smallexample
7913
7914@table @code
7915@kindex set multiple-symbols
7916@item set multiple-symbols @var{mode}
7917@cindex multiple-symbols menu
7918
7919This option allows you to adjust the debugger behavior when an expression
7920is ambiguous.
7921
7922By default, @var{mode} is set to @code{all}. If the command with which
7923the expression is used allows more than one choice, then @value{GDBN}
7924automatically selects all possible choices. For instance, inserting
7925a breakpoint on a function using an ambiguous name results in a breakpoint
7926inserted on each possible match. However, if a unique choice must be made,
7927then @value{GDBN} uses the menu to help you disambiguate the expression.
7928For instance, printing the address of an overloaded function will result
7929in the use of the menu.
7930
7931When @var{mode} is set to @code{ask}, the debugger always uses the menu
7932when an ambiguity is detected.
7933
7934Finally, when @var{mode} is set to @code{cancel}, the debugger reports
7935an error due to the ambiguity and the command is aborted.
7936
7937@kindex show multiple-symbols
7938@item show multiple-symbols
7939Show the current value of the @code{multiple-symbols} setting.
7940@end table
7941
6d2ebf8b 7942@node Variables
79a6e687 7943@section Program Variables
c906108c
SS
7944
7945The most common kind of expression to use is the name of a variable
7946in your program.
7947
7948Variables in expressions are understood in the selected stack frame
79a6e687 7949(@pxref{Selection, ,Selecting a Frame}); they must be either:
c906108c
SS
7950
7951@itemize @bullet
7952@item
7953global (or file-static)
7954@end itemize
7955
5d161b24 7956@noindent or
c906108c
SS
7957
7958@itemize @bullet
7959@item
7960visible according to the scope rules of the
7961programming language from the point of execution in that frame
5d161b24 7962@end itemize
c906108c
SS
7963
7964@noindent This means that in the function
7965
474c8240 7966@smallexample
c906108c
SS
7967foo (a)
7968 int a;
7969@{
7970 bar (a);
7971 @{
7972 int b = test ();
7973 bar (b);
7974 @}
7975@}
474c8240 7976@end smallexample
c906108c
SS
7977
7978@noindent
7979you can examine and use the variable @code{a} whenever your program is
7980executing within the function @code{foo}, but you can only use or
7981examine the variable @code{b} while your program is executing inside
7982the block where @code{b} is declared.
7983
7984@cindex variable name conflict
7985There is an exception: you can refer to a variable or function whose
7986scope is a single source file even if the current execution point is not
7987in this file. But it is possible to have more than one such variable or
7988function with the same name (in different source files). If that
7989happens, referring to that name has unpredictable effects. If you wish,
72384ba3 7990you can specify a static variable in a particular function or file by
15387254 7991using the colon-colon (@code{::}) notation:
c906108c 7992
d4f3574e 7993@cindex colon-colon, context for variables/functions
12c27660 7994@ifnotinfo
c906108c 7995@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 7996@cindex @code{::}, context for variables/functions
12c27660 7997@end ifnotinfo
474c8240 7998@smallexample
c906108c
SS
7999@var{file}::@var{variable}
8000@var{function}::@var{variable}
474c8240 8001@end smallexample
c906108c
SS
8002
8003@noindent
8004Here @var{file} or @var{function} is the name of the context for the
8005static @var{variable}. In the case of file names, you can use quotes to
8006make sure @value{GDBN} parses the file name as a single word---for example,
8007to print a global value of @code{x} defined in @file{f2.c}:
8008
474c8240 8009@smallexample
c906108c 8010(@value{GDBP}) p 'f2.c'::x
474c8240 8011@end smallexample
c906108c 8012
72384ba3
PH
8013The @code{::} notation is normally used for referring to
8014static variables, since you typically disambiguate uses of local variables
8015in functions by selecting the appropriate frame and using the
8016simple name of the variable. However, you may also use this notation
8017to refer to local variables in frames enclosing the selected frame:
8018
8019@smallexample
8020void
8021foo (int a)
8022@{
8023 if (a < 10)
8024 bar (a);
8025 else
8026 process (a); /* Stop here */
8027@}
8028
8029int
8030bar (int a)
8031@{
8032 foo (a + 5);
8033@}
8034@end smallexample
8035
8036@noindent
8037For example, if there is a breakpoint at the commented line,
8038here is what you might see
8039when the program stops after executing the call @code{bar(0)}:
8040
8041@smallexample
8042(@value{GDBP}) p a
8043$1 = 10
8044(@value{GDBP}) p bar::a
8045$2 = 5
8046(@value{GDBP}) up 2
8047#2 0x080483d0 in foo (a=5) at foobar.c:12
8048(@value{GDBP}) p a
8049$3 = 5
8050(@value{GDBP}) p bar::a
8051$4 = 0
8052@end smallexample
8053
b37052ae 8054@cindex C@t{++} scope resolution
72384ba3 8055These uses of @samp{::} are very rarely in conflict with the very similar
b37052ae 8056use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
8057scope resolution operator in @value{GDBN} expressions.
8058@c FIXME: Um, so what happens in one of those rare cases where it's in
8059@c conflict?? --mew
c906108c
SS
8060
8061@cindex wrong values
8062@cindex variable values, wrong
15387254
EZ
8063@cindex function entry/exit, wrong values of variables
8064@cindex optimized code, wrong values of variables
c906108c
SS
8065@quotation
8066@emph{Warning:} Occasionally, a local variable may appear to have the
8067wrong value at certain points in a function---just after entry to a new
8068scope, and just before exit.
8069@end quotation
8070You may see this problem when you are stepping by machine instructions.
8071This is because, on most machines, it takes more than one instruction to
8072set up a stack frame (including local variable definitions); if you are
8073stepping by machine instructions, variables may appear to have the wrong
8074values until the stack frame is completely built. On exit, it usually
8075also takes more than one machine instruction to destroy a stack frame;
8076after you begin stepping through that group of instructions, local
8077variable definitions may be gone.
8078
8079This may also happen when the compiler does significant optimizations.
8080To be sure of always seeing accurate values, turn off all optimization
8081when compiling.
8082
d4f3574e
SS
8083@cindex ``No symbol "foo" in current context''
8084Another possible effect of compiler optimizations is to optimize
8085unused variables out of existence, or assign variables to registers (as
8086opposed to memory addresses). Depending on the support for such cases
8087offered by the debug info format used by the compiler, @value{GDBN}
8088might not be able to display values for such local variables. If that
8089happens, @value{GDBN} will print a message like this:
8090
474c8240 8091@smallexample
d4f3574e 8092No symbol "foo" in current context.
474c8240 8093@end smallexample
d4f3574e
SS
8094
8095To solve such problems, either recompile without optimizations, or use a
8096different debug info format, if the compiler supports several such
e0f8f636
TT
8097formats. @xref{Compilation}, for more information on choosing compiler
8098options. @xref{C, ,C and C@t{++}}, for more information about debug
8099info formats that are best suited to C@t{++} programs.
d4f3574e 8100
ab1adacd
EZ
8101If you ask to print an object whose contents are unknown to
8102@value{GDBN}, e.g., because its data type is not completely specified
8103by the debug information, @value{GDBN} will say @samp{<incomplete
8104type>}. @xref{Symbols, incomplete type}, for more about this.
8105
36b11add
JK
8106If you append @kbd{@@entry} string to a function parameter name you get its
8107value at the time the function got called. If the value is not available an
8108error message is printed. Entry values are available only with some compilers.
8109Entry values are normally also printed at the function parameter list according
8110to @ref{set print entry-values}.
8111
8112@smallexample
8113Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
811429 i++;
8115(gdb) next
811630 e (i);
8117(gdb) print i
8118$1 = 31
8119(gdb) print i@@entry
8120$2 = 30
8121@end smallexample
8122
3a60f64e
JK
8123Strings are identified as arrays of @code{char} values without specified
8124signedness. Arrays of either @code{signed char} or @code{unsigned char} get
8125printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
8126@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
8127defines literal string type @code{"char"} as @code{char} without a sign.
8128For program code
8129
8130@smallexample
8131char var0[] = "A";
8132signed char var1[] = "A";
8133@end smallexample
8134
8135You get during debugging
8136@smallexample
8137(gdb) print var0
8138$1 = "A"
8139(gdb) print var1
8140$2 = @{65 'A', 0 '\0'@}
8141@end smallexample
8142
6d2ebf8b 8143@node Arrays
79a6e687 8144@section Artificial Arrays
c906108c
SS
8145
8146@cindex artificial array
15387254 8147@cindex arrays
41afff9a 8148@kindex @@@r{, referencing memory as an array}
c906108c
SS
8149It is often useful to print out several successive objects of the
8150same type in memory; a section of an array, or an array of
8151dynamically determined size for which only a pointer exists in the
8152program.
8153
8154You can do this by referring to a contiguous span of memory as an
8155@dfn{artificial array}, using the binary operator @samp{@@}. The left
8156operand of @samp{@@} should be the first element of the desired array
8157and be an individual object. The right operand should be the desired length
8158of the array. The result is an array value whose elements are all of
8159the type of the left argument. The first element is actually the left
8160argument; the second element comes from bytes of memory immediately
8161following those that hold the first element, and so on. Here is an
8162example. If a program says
8163
474c8240 8164@smallexample
c906108c 8165int *array = (int *) malloc (len * sizeof (int));
474c8240 8166@end smallexample
c906108c
SS
8167
8168@noindent
8169you can print the contents of @code{array} with
8170
474c8240 8171@smallexample
c906108c 8172p *array@@len
474c8240 8173@end smallexample
c906108c
SS
8174
8175The left operand of @samp{@@} must reside in memory. Array values made
8176with @samp{@@} in this way behave just like other arrays in terms of
8177subscripting, and are coerced to pointers when used in expressions.
8178Artificial arrays most often appear in expressions via the value history
79a6e687 8179(@pxref{Value History, ,Value History}), after printing one out.
c906108c
SS
8180
8181Another way to create an artificial array is to use a cast.
8182This re-interprets a value as if it were an array.
8183The value need not be in memory:
474c8240 8184@smallexample
c906108c
SS
8185(@value{GDBP}) p/x (short[2])0x12345678
8186$1 = @{0x1234, 0x5678@}
474c8240 8187@end smallexample
c906108c
SS
8188
8189As a convenience, if you leave the array length out (as in
c3f6f71d 8190@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 8191the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 8192@smallexample
c906108c
SS
8193(@value{GDBP}) p/x (short[])0x12345678
8194$2 = @{0x1234, 0x5678@}
474c8240 8195@end smallexample
c906108c
SS
8196
8197Sometimes the artificial array mechanism is not quite enough; in
8198moderately complex data structures, the elements of interest may not
8199actually be adjacent---for example, if you are interested in the values
8200of pointers in an array. One useful work-around in this situation is
8201to use a convenience variable (@pxref{Convenience Vars, ,Convenience
79a6e687 8202Variables}) as a counter in an expression that prints the first
c906108c
SS
8203interesting value, and then repeat that expression via @key{RET}. For
8204instance, suppose you have an array @code{dtab} of pointers to
8205structures, and you are interested in the values of a field @code{fv}
8206in each structure. Here is an example of what you might type:
8207
474c8240 8208@smallexample
c906108c
SS
8209set $i = 0
8210p dtab[$i++]->fv
8211@key{RET}
8212@key{RET}
8213@dots{}
474c8240 8214@end smallexample
c906108c 8215
6d2ebf8b 8216@node Output Formats
79a6e687 8217@section Output Formats
c906108c
SS
8218
8219@cindex formatted output
8220@cindex output formats
8221By default, @value{GDBN} prints a value according to its data type. Sometimes
8222this is not what you want. For example, you might want to print a number
8223in hex, or a pointer in decimal. Or you might want to view data in memory
8224at a certain address as a character string or as an instruction. To do
8225these things, specify an @dfn{output format} when you print a value.
8226
8227The simplest use of output formats is to say how to print a value
8228already computed. This is done by starting the arguments of the
8229@code{print} command with a slash and a format letter. The format
8230letters supported are:
8231
8232@table @code
8233@item x
8234Regard the bits of the value as an integer, and print the integer in
8235hexadecimal.
8236
8237@item d
8238Print as integer in signed decimal.
8239
8240@item u
8241Print as integer in unsigned decimal.
8242
8243@item o
8244Print as integer in octal.
8245
8246@item t
8247Print as integer in binary. The letter @samp{t} stands for ``two''.
8248@footnote{@samp{b} cannot be used because these format letters are also
8249used with the @code{x} command, where @samp{b} stands for ``byte'';
79a6e687 8250see @ref{Memory,,Examining Memory}.}
c906108c
SS
8251
8252@item a
8253@cindex unknown address, locating
3d67e040 8254@cindex locate address
c906108c
SS
8255Print as an address, both absolute in hexadecimal and as an offset from
8256the nearest preceding symbol. You can use this format used to discover
8257where (in what function) an unknown address is located:
8258
474c8240 8259@smallexample
c906108c
SS
8260(@value{GDBP}) p/a 0x54320
8261$3 = 0x54320 <_initialize_vx+396>
474c8240 8262@end smallexample
c906108c 8263
3d67e040
EZ
8264@noindent
8265The command @code{info symbol 0x54320} yields similar results.
8266@xref{Symbols, info symbol}.
8267
c906108c 8268@item c
51274035
EZ
8269Regard as an integer and print it as a character constant. This
8270prints both the numerical value and its character representation. The
8271character representation is replaced with the octal escape @samp{\nnn}
8272for characters outside the 7-bit @sc{ascii} range.
c906108c 8273
ea37ba09
DJ
8274Without this format, @value{GDBN} displays @code{char},
8275@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
8276constants. Single-byte members of vectors are displayed as integer
8277data.
8278
c906108c
SS
8279@item f
8280Regard the bits of the value as a floating point number and print
8281using typical floating point syntax.
ea37ba09
DJ
8282
8283@item s
8284@cindex printing strings
8285@cindex printing byte arrays
8286Regard as a string, if possible. With this format, pointers to single-byte
8287data are displayed as null-terminated strings and arrays of single-byte data
8288are displayed as fixed-length strings. Other values are displayed in their
8289natural types.
8290
8291Without this format, @value{GDBN} displays pointers to and arrays of
8292@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
8293strings. Single-byte members of a vector are displayed as an integer
8294array.
a6bac58e
TT
8295
8296@item r
8297@cindex raw printing
8298Print using the @samp{raw} formatting. By default, @value{GDBN} will
78e2826b
TT
8299use a Python-based pretty-printer, if one is available (@pxref{Pretty
8300Printing}). This typically results in a higher-level display of the
8301value's contents. The @samp{r} format bypasses any Python
8302pretty-printer which might exist.
c906108c
SS
8303@end table
8304
8305For example, to print the program counter in hex (@pxref{Registers}), type
8306
474c8240 8307@smallexample
c906108c 8308p/x $pc
474c8240 8309@end smallexample
c906108c
SS
8310
8311@noindent
8312Note that no space is required before the slash; this is because command
8313names in @value{GDBN} cannot contain a slash.
8314
8315To reprint the last value in the value history with a different format,
8316you can use the @code{print} command with just a format and no
8317expression. For example, @samp{p/x} reprints the last value in hex.
8318
6d2ebf8b 8319@node Memory
79a6e687 8320@section Examining Memory
c906108c
SS
8321
8322You can use the command @code{x} (for ``examine'') to examine memory in
8323any of several formats, independently of your program's data types.
8324
8325@cindex examining memory
8326@table @code
41afff9a 8327@kindex x @r{(examine memory)}
c906108c
SS
8328@item x/@var{nfu} @var{addr}
8329@itemx x @var{addr}
8330@itemx x
8331Use the @code{x} command to examine memory.
8332@end table
8333
8334@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
8335much memory to display and how to format it; @var{addr} is an
8336expression giving the address where you want to start displaying memory.
8337If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
8338Several commands set convenient defaults for @var{addr}.
8339
8340@table @r
8341@item @var{n}, the repeat count
8342The repeat count is a decimal integer; the default is 1. It specifies
8343how much memory (counting by units @var{u}) to display.
8344@c This really is **decimal**; unaffected by 'set radix' as of GDB
8345@c 4.1.2.
8346
8347@item @var{f}, the display format
51274035
EZ
8348The display format is one of the formats used by @code{print}
8349(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
ea37ba09
DJ
8350@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
8351The default is @samp{x} (hexadecimal) initially. The default changes
8352each time you use either @code{x} or @code{print}.
c906108c
SS
8353
8354@item @var{u}, the unit size
8355The unit size is any of
8356
8357@table @code
8358@item b
8359Bytes.
8360@item h
8361Halfwords (two bytes).
8362@item w
8363Words (four bytes). This is the initial default.
8364@item g
8365Giant words (eight bytes).
8366@end table
8367
8368Each time you specify a unit size with @code{x}, that size becomes the
9a22f0d0
PM
8369default unit the next time you use @code{x}. For the @samp{i} format,
8370the unit size is ignored and is normally not written. For the @samp{s} format,
8371the unit size defaults to @samp{b}, unless it is explicitly given.
8372Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
837332-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
8374Note that the results depend on the programming language of the
8375current compilation unit. If the language is C, the @samp{s}
8376modifier will use the UTF-16 encoding while @samp{w} will use
8377UTF-32. The encoding is set by the programming language and cannot
8378be altered.
c906108c
SS
8379
8380@item @var{addr}, starting display address
8381@var{addr} is the address where you want @value{GDBN} to begin displaying
8382memory. The expression need not have a pointer value (though it may);
8383it is always interpreted as an integer address of a byte of memory.
8384@xref{Expressions, ,Expressions}, for more information on expressions. The default for
8385@var{addr} is usually just after the last address examined---but several
8386other commands also set the default address: @code{info breakpoints} (to
8387the address of the last breakpoint listed), @code{info line} (to the
8388starting address of a line), and @code{print} (if you use it to display
8389a value from memory).
8390@end table
8391
8392For example, @samp{x/3uh 0x54320} is a request to display three halfwords
8393(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
8394starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
8395words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 8396@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
8397
8398Since the letters indicating unit sizes are all distinct from the
8399letters specifying output formats, you do not have to remember whether
8400unit size or format comes first; either order works. The output
8401specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
8402(However, the count @var{n} must come first; @samp{wx4} does not work.)
8403
8404Even though the unit size @var{u} is ignored for the formats @samp{s}
8405and @samp{i}, you might still want to use a count @var{n}; for example,
8406@samp{3i} specifies that you want to see three machine instructions,
a4642986
MR
8407including any operands. For convenience, especially when used with
8408the @code{display} command, the @samp{i} format also prints branch delay
8409slot instructions, if any, beyond the count specified, which immediately
8410follow the last instruction that is within the count. The command
8411@code{disassemble} gives an alternative way of inspecting machine
8412instructions; see @ref{Machine Code,,Source and Machine Code}.
c906108c
SS
8413
8414All the defaults for the arguments to @code{x} are designed to make it
8415easy to continue scanning memory with minimal specifications each time
8416you use @code{x}. For example, after you have inspected three machine
8417instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
8418with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
8419the repeat count @var{n} is used again; the other arguments default as
8420for successive uses of @code{x}.
8421
2b28d209
PP
8422When examining machine instructions, the instruction at current program
8423counter is shown with a @code{=>} marker. For example:
8424
8425@smallexample
8426(@value{GDBP}) x/5i $pc-6
8427 0x804837f <main+11>: mov %esp,%ebp
8428 0x8048381 <main+13>: push %ecx
8429 0x8048382 <main+14>: sub $0x4,%esp
8430=> 0x8048385 <main+17>: movl $0x8048460,(%esp)
8431 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
8432@end smallexample
8433
c906108c
SS
8434@cindex @code{$_}, @code{$__}, and value history
8435The addresses and contents printed by the @code{x} command are not saved
8436in the value history because there is often too much of them and they
8437would get in the way. Instead, @value{GDBN} makes these values available for
8438subsequent use in expressions as values of the convenience variables
8439@code{$_} and @code{$__}. After an @code{x} command, the last address
8440examined is available for use in expressions in the convenience variable
8441@code{$_}. The contents of that address, as examined, are available in
8442the convenience variable @code{$__}.
8443
8444If the @code{x} command has a repeat count, the address and contents saved
8445are from the last memory unit printed; this is not the same as the last
8446address printed if several units were printed on the last line of output.
8447
09d4efe1
EZ
8448@cindex remote memory comparison
8449@cindex verify remote memory image
8450When you are debugging a program running on a remote target machine
ea35711c 8451(@pxref{Remote Debugging}), you may wish to verify the program's image in the
09d4efe1
EZ
8452remote machine's memory against the executable file you downloaded to
8453the target. The @code{compare-sections} command is provided for such
8454situations.
8455
8456@table @code
8457@kindex compare-sections
8458@item compare-sections @r{[}@var{section-name}@r{]}
8459Compare the data of a loadable section @var{section-name} in the
8460executable file of the program being debugged with the same section in
8461the remote machine's memory, and report any mismatches. With no
8462arguments, compares all loadable sections. This command's
8463availability depends on the target's support for the @code{"qCRC"}
8464remote request.
8465@end table
8466
6d2ebf8b 8467@node Auto Display
79a6e687 8468@section Automatic Display
c906108c
SS
8469@cindex automatic display
8470@cindex display of expressions
8471
8472If you find that you want to print the value of an expression frequently
8473(to see how it changes), you might want to add it to the @dfn{automatic
8474display list} so that @value{GDBN} prints its value each time your program stops.
8475Each expression added to the list is given a number to identify it;
8476to remove an expression from the list, you specify that number.
8477The automatic display looks like this:
8478
474c8240 8479@smallexample
c906108c
SS
84802: foo = 38
84813: bar[5] = (struct hack *) 0x3804
474c8240 8482@end smallexample
c906108c
SS
8483
8484@noindent
8485This display shows item numbers, expressions and their current values. As with
8486displays you request manually using @code{x} or @code{print}, you can
8487specify the output format you prefer; in fact, @code{display} decides
ea37ba09
DJ
8488whether to use @code{print} or @code{x} depending your format
8489specification---it uses @code{x} if you specify either the @samp{i}
8490or @samp{s} format, or a unit size; otherwise it uses @code{print}.
c906108c
SS
8491
8492@table @code
8493@kindex display
d4f3574e
SS
8494@item display @var{expr}
8495Add the expression @var{expr} to the list of expressions to display
c906108c
SS
8496each time your program stops. @xref{Expressions, ,Expressions}.
8497
8498@code{display} does not repeat if you press @key{RET} again after using it.
8499
d4f3574e 8500@item display/@var{fmt} @var{expr}
c906108c 8501For @var{fmt} specifying only a display format and not a size or
d4f3574e 8502count, add the expression @var{expr} to the auto-display list but
c906108c 8503arrange to display it each time in the specified format @var{fmt}.
79a6e687 8504@xref{Output Formats,,Output Formats}.
c906108c
SS
8505
8506@item display/@var{fmt} @var{addr}
8507For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
8508number of units, add the expression @var{addr} as a memory address to
8509be examined each time your program stops. Examining means in effect
79a6e687 8510doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
c906108c
SS
8511@end table
8512
8513For example, @samp{display/i $pc} can be helpful, to see the machine
8514instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 8515is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
8516
8517@table @code
8518@kindex delete display
8519@kindex undisplay
8520@item undisplay @var{dnums}@dots{}
8521@itemx delete display @var{dnums}@dots{}
c9174737
PA
8522Remove items from the list of expressions to display. Specify the
8523numbers of the displays that you want affected with the command
8524argument @var{dnums}. It can be a single display number, one of the
8525numbers shown in the first field of the @samp{info display} display;
8526or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
8527
8528@code{undisplay} does not repeat if you press @key{RET} after using it.
8529(Otherwise you would just get the error @samp{No display number @dots{}}.)
8530
8531@kindex disable display
8532@item disable display @var{dnums}@dots{}
8533Disable the display of item numbers @var{dnums}. A disabled display
8534item is not printed automatically, but is not forgotten. It may be
c9174737
PA
8535enabled again later. Specify the numbers of the displays that you
8536want affected with the command argument @var{dnums}. It can be a
8537single display number, one of the numbers shown in the first field of
8538the @samp{info display} display; or it could be a range of display
8539numbers, as in @code{2-4}.
c906108c
SS
8540
8541@kindex enable display
8542@item enable display @var{dnums}@dots{}
8543Enable display of item numbers @var{dnums}. It becomes effective once
8544again in auto display of its expression, until you specify otherwise.
c9174737
PA
8545Specify the numbers of the displays that you want affected with the
8546command argument @var{dnums}. It can be a single display number, one
8547of the numbers shown in the first field of the @samp{info display}
8548display; or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
8549
8550@item display
8551Display the current values of the expressions on the list, just as is
8552done when your program stops.
8553
8554@kindex info display
8555@item info display
8556Print the list of expressions previously set up to display
8557automatically, each one with its item number, but without showing the
8558values. This includes disabled expressions, which are marked as such.
8559It also includes expressions which would not be displayed right now
8560because they refer to automatic variables not currently available.
8561@end table
8562
15387254 8563@cindex display disabled out of scope
c906108c
SS
8564If a display expression refers to local variables, then it does not make
8565sense outside the lexical context for which it was set up. Such an
8566expression is disabled when execution enters a context where one of its
8567variables is not defined. For example, if you give the command
8568@code{display last_char} while inside a function with an argument
8569@code{last_char}, @value{GDBN} displays this argument while your program
8570continues to stop inside that function. When it stops elsewhere---where
8571there is no variable @code{last_char}---the display is disabled
8572automatically. The next time your program stops where @code{last_char}
8573is meaningful, you can enable the display expression once again.
8574
6d2ebf8b 8575@node Print Settings
79a6e687 8576@section Print Settings
c906108c
SS
8577
8578@cindex format options
8579@cindex print settings
8580@value{GDBN} provides the following ways to control how arrays, structures,
8581and symbols are printed.
8582
8583@noindent
8584These settings are useful for debugging programs in any language:
8585
8586@table @code
4644b6e3 8587@kindex set print
c906108c
SS
8588@item set print address
8589@itemx set print address on
4644b6e3 8590@cindex print/don't print memory addresses
c906108c
SS
8591@value{GDBN} prints memory addresses showing the location of stack
8592traces, structure values, pointer values, breakpoints, and so forth,
8593even when it also displays the contents of those addresses. The default
8594is @code{on}. For example, this is what a stack frame display looks like with
8595@code{set print address on}:
8596
8597@smallexample
8598@group
8599(@value{GDBP}) f
8600#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
8601 at input.c:530
8602530 if (lquote != def_lquote)
8603@end group
8604@end smallexample
8605
8606@item set print address off
8607Do not print addresses when displaying their contents. For example,
8608this is the same stack frame displayed with @code{set print address off}:
8609
8610@smallexample
8611@group
8612(@value{GDBP}) set print addr off
8613(@value{GDBP}) f
8614#0 set_quotes (lq="<<", rq=">>") at input.c:530
8615530 if (lquote != def_lquote)
8616@end group
8617@end smallexample
8618
8619You can use @samp{set print address off} to eliminate all machine
8620dependent displays from the @value{GDBN} interface. For example, with
8621@code{print address off}, you should get the same text for backtraces on
8622all machines---whether or not they involve pointer arguments.
8623
4644b6e3 8624@kindex show print
c906108c
SS
8625@item show print address
8626Show whether or not addresses are to be printed.
8627@end table
8628
8629When @value{GDBN} prints a symbolic address, it normally prints the
8630closest earlier symbol plus an offset. If that symbol does not uniquely
8631identify the address (for example, it is a name whose scope is a single
8632source file), you may need to clarify. One way to do this is with
8633@code{info line}, for example @samp{info line *0x4537}. Alternately,
8634you can set @value{GDBN} to print the source file and line number when
8635it prints a symbolic address:
8636
8637@table @code
c906108c 8638@item set print symbol-filename on
9c16f35a
EZ
8639@cindex source file and line of a symbol
8640@cindex symbol, source file and line
c906108c
SS
8641Tell @value{GDBN} to print the source file name and line number of a
8642symbol in the symbolic form of an address.
8643
8644@item set print symbol-filename off
8645Do not print source file name and line number of a symbol. This is the
8646default.
8647
c906108c
SS
8648@item show print symbol-filename
8649Show whether or not @value{GDBN} will print the source file name and
8650line number of a symbol in the symbolic form of an address.
8651@end table
8652
8653Another situation where it is helpful to show symbol filenames and line
8654numbers is when disassembling code; @value{GDBN} shows you the line
8655number and source file that corresponds to each instruction.
8656
8657Also, you may wish to see the symbolic form only if the address being
8658printed is reasonably close to the closest earlier symbol:
8659
8660@table @code
c906108c 8661@item set print max-symbolic-offset @var{max-offset}
f81d1120 8662@itemx set print max-symbolic-offset unlimited
4644b6e3 8663@cindex maximum value for offset of closest symbol
c906108c
SS
8664Tell @value{GDBN} to only display the symbolic form of an address if the
8665offset between the closest earlier symbol and the address is less than
f81d1120
PA
8666@var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
8667to always print the symbolic form of an address if any symbol precedes
8668it. Zero is equivalent to @code{unlimited}.
c906108c 8669
c906108c
SS
8670@item show print max-symbolic-offset
8671Ask how large the maximum offset is that @value{GDBN} prints in a
8672symbolic address.
8673@end table
8674
8675@cindex wild pointer, interpreting
8676@cindex pointer, finding referent
8677If you have a pointer and you are not sure where it points, try
8678@samp{set print symbol-filename on}. Then you can determine the name
8679and source file location of the variable where it points, using
8680@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
8681For example, here @value{GDBN} shows that a variable @code{ptt} points
8682at another variable @code{t}, defined in @file{hi2.c}:
8683
474c8240 8684@smallexample
c906108c
SS
8685(@value{GDBP}) set print symbol-filename on
8686(@value{GDBP}) p/a ptt
8687$4 = 0xe008 <t in hi2.c>
474c8240 8688@end smallexample
c906108c
SS
8689
8690@quotation
8691@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
8692does not show the symbol name and filename of the referent, even with
8693the appropriate @code{set print} options turned on.
8694@end quotation
8695
9cb709b6
TT
8696You can also enable @samp{/a}-like formatting all the time using
8697@samp{set print symbol on}:
8698
8699@table @code
8700@item set print symbol on
8701Tell @value{GDBN} to print the symbol corresponding to an address, if
8702one exists.
8703
8704@item set print symbol off
8705Tell @value{GDBN} not to print the symbol corresponding to an
8706address. In this mode, @value{GDBN} will still print the symbol
8707corresponding to pointers to functions. This is the default.
8708
8709@item show print symbol
8710Show whether @value{GDBN} will display the symbol corresponding to an
8711address.
8712@end table
8713
c906108c
SS
8714Other settings control how different kinds of objects are printed:
8715
8716@table @code
c906108c
SS
8717@item set print array
8718@itemx set print array on
4644b6e3 8719@cindex pretty print arrays
c906108c
SS
8720Pretty print arrays. This format is more convenient to read,
8721but uses more space. The default is off.
8722
8723@item set print array off
8724Return to compressed format for arrays.
8725
c906108c
SS
8726@item show print array
8727Show whether compressed or pretty format is selected for displaying
8728arrays.
8729
3c9c013a
JB
8730@cindex print array indexes
8731@item set print array-indexes
8732@itemx set print array-indexes on
8733Print the index of each element when displaying arrays. May be more
8734convenient to locate a given element in the array or quickly find the
8735index of a given element in that printed array. The default is off.
8736
8737@item set print array-indexes off
8738Stop printing element indexes when displaying arrays.
8739
8740@item show print array-indexes
8741Show whether the index of each element is printed when displaying
8742arrays.
8743
c906108c 8744@item set print elements @var{number-of-elements}
f81d1120 8745@itemx set print elements unlimited
4644b6e3 8746@cindex number of array elements to print
9c16f35a 8747@cindex limit on number of printed array elements
c906108c
SS
8748Set a limit on how many elements of an array @value{GDBN} will print.
8749If @value{GDBN} is printing a large array, it stops printing after it has
8750printed the number of elements set by the @code{set print elements} command.
8751This limit also applies to the display of strings.
d4f3574e 8752When @value{GDBN} starts, this limit is set to 200.
f81d1120
PA
8753Setting @var{number-of-elements} to @code{unlimited} or zero means
8754that the number of elements to print is unlimited.
c906108c 8755
c906108c
SS
8756@item show print elements
8757Display the number of elements of a large array that @value{GDBN} will print.
8758If the number is 0, then the printing is unlimited.
8759
b4740add 8760@item set print frame-arguments @var{value}
a0381d3a 8761@kindex set print frame-arguments
b4740add
JB
8762@cindex printing frame argument values
8763@cindex print all frame argument values
8764@cindex print frame argument values for scalars only
8765@cindex do not print frame argument values
8766This command allows to control how the values of arguments are printed
8767when the debugger prints a frame (@pxref{Frames}). The possible
8768values are:
8769
8770@table @code
8771@item all
4f5376b2 8772The values of all arguments are printed.
b4740add
JB
8773
8774@item scalars
8775Print the value of an argument only if it is a scalar. The value of more
8776complex arguments such as arrays, structures, unions, etc, is replaced
4f5376b2
JB
8777by @code{@dots{}}. This is the default. Here is an example where
8778only scalar arguments are shown:
b4740add
JB
8779
8780@smallexample
8781#1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
8782 at frame-args.c:23
8783@end smallexample
8784
8785@item none
8786None of the argument values are printed. Instead, the value of each argument
8787is replaced by @code{@dots{}}. In this case, the example above now becomes:
8788
8789@smallexample
8790#1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
8791 at frame-args.c:23
8792@end smallexample
8793@end table
8794
4f5376b2
JB
8795By default, only scalar arguments are printed. This command can be used
8796to configure the debugger to print the value of all arguments, regardless
8797of their type. However, it is often advantageous to not print the value
8798of more complex parameters. For instance, it reduces the amount of
8799information printed in each frame, making the backtrace more readable.
8800Also, it improves performance when displaying Ada frames, because
8801the computation of large arguments can sometimes be CPU-intensive,
8802especially in large applications. Setting @code{print frame-arguments}
8803to @code{scalars} (the default) or @code{none} avoids this computation,
8804thus speeding up the display of each Ada frame.
b4740add
JB
8805
8806@item show print frame-arguments
8807Show how the value of arguments should be displayed when printing a frame.
8808
36b11add 8809@anchor{set print entry-values}
e18b2753
JK
8810@item set print entry-values @var{value}
8811@kindex set print entry-values
8812Set printing of frame argument values at function entry. In some cases
8813@value{GDBN} can determine the value of function argument which was passed by
8814the function caller, even if the value was modified inside the called function
8815and therefore is different. With optimized code, the current value could be
8816unavailable, but the entry value may still be known.
8817
8818The default value is @code{default} (see below for its description). Older
8819@value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
8820this feature will behave in the @code{default} setting the same way as with the
8821@code{no} setting.
8822
8823This functionality is currently supported only by DWARF 2 debugging format and
8824the compiler has to produce @samp{DW_TAG_GNU_call_site} tags. With
8825@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
8826this information.
8827
8828The @var{value} parameter can be one of the following:
8829
8830@table @code
8831@item no
8832Print only actual parameter values, never print values from function entry
8833point.
8834@smallexample
8835#0 equal (val=5)
8836#0 different (val=6)
8837#0 lost (val=<optimized out>)
8838#0 born (val=10)
8839#0 invalid (val=<optimized out>)
8840@end smallexample
8841
8842@item only
8843Print only parameter values from function entry point. The actual parameter
8844values are never printed.
8845@smallexample
8846#0 equal (val@@entry=5)
8847#0 different (val@@entry=5)
8848#0 lost (val@@entry=5)
8849#0 born (val@@entry=<optimized out>)
8850#0 invalid (val@@entry=<optimized out>)
8851@end smallexample
8852
8853@item preferred
8854Print only parameter values from function entry point. If value from function
8855entry point is not known while the actual value is known, print the actual
8856value for such parameter.
8857@smallexample
8858#0 equal (val@@entry=5)
8859#0 different (val@@entry=5)
8860#0 lost (val@@entry=5)
8861#0 born (val=10)
8862#0 invalid (val@@entry=<optimized out>)
8863@end smallexample
8864
8865@item if-needed
8866Print actual parameter values. If actual parameter value is not known while
8867value from function entry point is known, print the entry point value for such
8868parameter.
8869@smallexample
8870#0 equal (val=5)
8871#0 different (val=6)
8872#0 lost (val@@entry=5)
8873#0 born (val=10)
8874#0 invalid (val=<optimized out>)
8875@end smallexample
8876
8877@item both
8878Always print both the actual parameter value and its value from function entry
8879point, even if values of one or both are not available due to compiler
8880optimizations.
8881@smallexample
8882#0 equal (val=5, val@@entry=5)
8883#0 different (val=6, val@@entry=5)
8884#0 lost (val=<optimized out>, val@@entry=5)
8885#0 born (val=10, val@@entry=<optimized out>)
8886#0 invalid (val=<optimized out>, val@@entry=<optimized out>)
8887@end smallexample
8888
8889@item compact
8890Print the actual parameter value if it is known and also its value from
8891function entry point if it is known. If neither is known, print for the actual
8892value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
8893values are known and identical, print the shortened
8894@code{param=param@@entry=VALUE} notation.
8895@smallexample
8896#0 equal (val=val@@entry=5)
8897#0 different (val=6, val@@entry=5)
8898#0 lost (val@@entry=5)
8899#0 born (val=10)
8900#0 invalid (val=<optimized out>)
8901@end smallexample
8902
8903@item default
8904Always print the actual parameter value. Print also its value from function
8905entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
8906if both values are known and identical, print the shortened
8907@code{param=param@@entry=VALUE} notation.
8908@smallexample
8909#0 equal (val=val@@entry=5)
8910#0 different (val=6, val@@entry=5)
8911#0 lost (val=<optimized out>, val@@entry=5)
8912#0 born (val=10)
8913#0 invalid (val=<optimized out>)
8914@end smallexample
8915@end table
8916
8917For analysis messages on possible failures of frame argument values at function
8918entry resolution see @ref{set debug entry-values}.
8919
8920@item show print entry-values
8921Show the method being used for printing of frame argument values at function
8922entry.
8923
f81d1120
PA
8924@item set print repeats @var{number-of-repeats}
8925@itemx set print repeats unlimited
9c16f35a
EZ
8926@cindex repeated array elements
8927Set the threshold for suppressing display of repeated array
d3e8051b 8928elements. When the number of consecutive identical elements of an
9c16f35a
EZ
8929array exceeds the threshold, @value{GDBN} prints the string
8930@code{"<repeats @var{n} times>"}, where @var{n} is the number of
8931identical repetitions, instead of displaying the identical elements
f81d1120
PA
8932themselves. Setting the threshold to @code{unlimited} or zero will
8933cause all elements to be individually printed. The default threshold
8934is 10.
9c16f35a
EZ
8935
8936@item show print repeats
8937Display the current threshold for printing repeated identical
8938elements.
8939
c906108c 8940@item set print null-stop
4644b6e3 8941@cindex @sc{null} elements in arrays
c906108c 8942Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 8943@sc{null} is encountered. This is useful when large arrays actually
c906108c 8944contain only short strings.
d4f3574e 8945The default is off.
c906108c 8946
9c16f35a
EZ
8947@item show print null-stop
8948Show whether @value{GDBN} stops printing an array on the first
8949@sc{null} character.
8950
c906108c 8951@item set print pretty on
9c16f35a
EZ
8952@cindex print structures in indented form
8953@cindex indentation in structure display
5d161b24 8954Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
8955per line, like this:
8956
8957@smallexample
8958@group
8959$1 = @{
8960 next = 0x0,
8961 flags = @{
8962 sweet = 1,
8963 sour = 1
8964 @},
8965 meat = 0x54 "Pork"
8966@}
8967@end group
8968@end smallexample
8969
8970@item set print pretty off
8971Cause @value{GDBN} to print structures in a compact format, like this:
8972
8973@smallexample
8974@group
8975$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
8976meat = 0x54 "Pork"@}
8977@end group
8978@end smallexample
8979
8980@noindent
8981This is the default format.
8982
c906108c
SS
8983@item show print pretty
8984Show which format @value{GDBN} is using to print structures.
8985
c906108c 8986@item set print sevenbit-strings on
4644b6e3
EZ
8987@cindex eight-bit characters in strings
8988@cindex octal escapes in strings
c906108c
SS
8989Print using only seven-bit characters; if this option is set,
8990@value{GDBN} displays any eight-bit characters (in strings or
8991character values) using the notation @code{\}@var{nnn}. This setting is
8992best if you are working in English (@sc{ascii}) and you use the
8993high-order bit of characters as a marker or ``meta'' bit.
8994
8995@item set print sevenbit-strings off
8996Print full eight-bit characters. This allows the use of more
8997international character sets, and is the default.
8998
c906108c
SS
8999@item show print sevenbit-strings
9000Show whether or not @value{GDBN} is printing only seven-bit characters.
9001
c906108c 9002@item set print union on
4644b6e3 9003@cindex unions in structures, printing
9c16f35a
EZ
9004Tell @value{GDBN} to print unions which are contained in structures
9005and other unions. This is the default setting.
c906108c
SS
9006
9007@item set print union off
9c16f35a
EZ
9008Tell @value{GDBN} not to print unions which are contained in
9009structures and other unions. @value{GDBN} will print @code{"@{...@}"}
9010instead.
c906108c 9011
c906108c
SS
9012@item show print union
9013Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 9014structures and other unions.
c906108c
SS
9015
9016For example, given the declarations
9017
9018@smallexample
9019typedef enum @{Tree, Bug@} Species;
9020typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 9021typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
9022 Bug_forms;
9023
9024struct thing @{
9025 Species it;
9026 union @{
9027 Tree_forms tree;
9028 Bug_forms bug;
9029 @} form;
9030@};
9031
9032struct thing foo = @{Tree, @{Acorn@}@};
9033@end smallexample
9034
9035@noindent
9036with @code{set print union on} in effect @samp{p foo} would print
9037
9038@smallexample
9039$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
9040@end smallexample
9041
9042@noindent
9043and with @code{set print union off} in effect it would print
9044
9045@smallexample
9046$1 = @{it = Tree, form = @{...@}@}
9047@end smallexample
9c16f35a
EZ
9048
9049@noindent
9050@code{set print union} affects programs written in C-like languages
9051and in Pascal.
c906108c
SS
9052@end table
9053
c906108c
SS
9054@need 1000
9055@noindent
b37052ae 9056These settings are of interest when debugging C@t{++} programs:
c906108c
SS
9057
9058@table @code
4644b6e3 9059@cindex demangling C@t{++} names
c906108c
SS
9060@item set print demangle
9061@itemx set print demangle on
b37052ae 9062Print C@t{++} names in their source form rather than in the encoded
c906108c 9063(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 9064linkage. The default is on.
c906108c 9065
c906108c 9066@item show print demangle
b37052ae 9067Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 9068
c906108c
SS
9069@item set print asm-demangle
9070@itemx set print asm-demangle on
b37052ae 9071Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
9072in assembler code printouts such as instruction disassemblies.
9073The default is off.
9074
c906108c 9075@item show print asm-demangle
b37052ae 9076Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
9077or demangled form.
9078
b37052ae
EZ
9079@cindex C@t{++} symbol decoding style
9080@cindex symbol decoding style, C@t{++}
a8f24a35 9081@kindex set demangle-style
c906108c
SS
9082@item set demangle-style @var{style}
9083Choose among several encoding schemes used by different compilers to
b37052ae 9084represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
9085
9086@table @code
9087@item auto
9088Allow @value{GDBN} to choose a decoding style by inspecting your program.
891df0ea 9089This is the default.
c906108c
SS
9090
9091@item gnu
b37052ae 9092Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c
SS
9093
9094@item hp
b37052ae 9095Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
9096
9097@item lucid
b37052ae 9098Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
9099
9100@item arm
b37052ae 9101Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
9102@strong{Warning:} this setting alone is not sufficient to allow
9103debugging @code{cfront}-generated executables. @value{GDBN} would
9104require further enhancement to permit that.
9105
9106@end table
9107If you omit @var{style}, you will see a list of possible formats.
9108
c906108c 9109@item show demangle-style
b37052ae 9110Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 9111
c906108c
SS
9112@item set print object
9113@itemx set print object on
4644b6e3 9114@cindex derived type of an object, printing
9c16f35a 9115@cindex display derived types
c906108c
SS
9116When displaying a pointer to an object, identify the @emph{actual}
9117(derived) type of the object rather than the @emph{declared} type, using
625c0d47
TT
9118the virtual function table. Note that the virtual function table is
9119required---this feature can only work for objects that have run-time
9120type identification; a single virtual method in the object's declared
8264ba82
AG
9121type is sufficient. Note that this setting is also taken into account when
9122working with variable objects via MI (@pxref{GDB/MI}).
c906108c
SS
9123
9124@item set print object off
9125Display only the declared type of objects, without reference to the
9126virtual function table. This is the default setting.
9127
c906108c
SS
9128@item show print object
9129Show whether actual, or declared, object types are displayed.
9130
c906108c
SS
9131@item set print static-members
9132@itemx set print static-members on
4644b6e3 9133@cindex static members of C@t{++} objects
b37052ae 9134Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
9135
9136@item set print static-members off
b37052ae 9137Do not print static members when displaying a C@t{++} object.
c906108c 9138
c906108c 9139@item show print static-members
9c16f35a
EZ
9140Show whether C@t{++} static members are printed or not.
9141
9142@item set print pascal_static-members
9143@itemx set print pascal_static-members on
d3e8051b
EZ
9144@cindex static members of Pascal objects
9145@cindex Pascal objects, static members display
9c16f35a
EZ
9146Print static members when displaying a Pascal object. The default is on.
9147
9148@item set print pascal_static-members off
9149Do not print static members when displaying a Pascal object.
9150
9151@item show print pascal_static-members
9152Show whether Pascal static members are printed or not.
c906108c
SS
9153
9154@c These don't work with HP ANSI C++ yet.
c906108c
SS
9155@item set print vtbl
9156@itemx set print vtbl on
4644b6e3 9157@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
9158@cindex virtual functions (C@t{++}) display
9159@cindex VTBL display
b37052ae 9160Pretty print C@t{++} virtual function tables. The default is off.
c906108c 9161(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 9162ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
9163
9164@item set print vtbl off
b37052ae 9165Do not pretty print C@t{++} virtual function tables.
c906108c 9166
c906108c 9167@item show print vtbl
b37052ae 9168Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 9169@end table
c906108c 9170
4c374409
JK
9171@node Pretty Printing
9172@section Pretty Printing
9173
9174@value{GDBN} provides a mechanism to allow pretty-printing of values using
9175Python code. It greatly simplifies the display of complex objects. This
9176mechanism works for both MI and the CLI.
9177
7b51bc51
DE
9178@menu
9179* Pretty-Printer Introduction:: Introduction to pretty-printers
9180* Pretty-Printer Example:: An example pretty-printer
9181* Pretty-Printer Commands:: Pretty-printer commands
9182@end menu
9183
9184@node Pretty-Printer Introduction
9185@subsection Pretty-Printer Introduction
9186
9187When @value{GDBN} prints a value, it first sees if there is a pretty-printer
9188registered for the value. If there is then @value{GDBN} invokes the
9189pretty-printer to print the value. Otherwise the value is printed normally.
9190
9191Pretty-printers are normally named. This makes them easy to manage.
9192The @samp{info pretty-printer} command will list all the installed
9193pretty-printers with their names.
9194If a pretty-printer can handle multiple data types, then its
9195@dfn{subprinters} are the printers for the individual data types.
9196Each such subprinter has its own name.
4e04c971 9197The format of the name is @var{printer-name};@var{subprinter-name}.
7b51bc51
DE
9198
9199Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
9200Typically they are automatically loaded and registered when the corresponding
9201debug information is loaded, thus making them available without having to
9202do anything special.
9203
9204There are three places where a pretty-printer can be registered.
9205
9206@itemize @bullet
9207@item
9208Pretty-printers registered globally are available when debugging
9209all inferiors.
9210
9211@item
9212Pretty-printers registered with a program space are available only
9213when debugging that program.
9214@xref{Progspaces In Python}, for more details on program spaces in Python.
9215
9216@item
9217Pretty-printers registered with an objfile are loaded and unloaded
9218with the corresponding objfile (e.g., shared library).
9219@xref{Objfiles In Python}, for more details on objfiles in Python.
9220@end itemize
9221
9222@xref{Selecting Pretty-Printers}, for further information on how
9223pretty-printers are selected,
9224
9225@xref{Writing a Pretty-Printer}, for implementing pretty printers
9226for new types.
9227
9228@node Pretty-Printer Example
9229@subsection Pretty-Printer Example
9230
9231Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
4c374409
JK
9232
9233@smallexample
9234(@value{GDBP}) print s
9235$1 = @{
9236 static npos = 4294967295,
9237 _M_dataplus = @{
9238 <std::allocator<char>> = @{
9239 <__gnu_cxx::new_allocator<char>> = @{
9240 <No data fields>@}, <No data fields>
9241 @},
9242 members of std::basic_string<char, std::char_traits<char>,
9243 std::allocator<char> >::_Alloc_hider:
9244 _M_p = 0x804a014 "abcd"
9245 @}
9246@}
9247@end smallexample
9248
9249With a pretty-printer for @code{std::string} only the contents are printed:
9250
9251@smallexample
9252(@value{GDBP}) print s
9253$2 = "abcd"
9254@end smallexample
9255
7b51bc51
DE
9256@node Pretty-Printer Commands
9257@subsection Pretty-Printer Commands
9258@cindex pretty-printer commands
9259
9260@table @code
9261@kindex info pretty-printer
9262@item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9263Print the list of installed pretty-printers.
9264This includes disabled pretty-printers, which are marked as such.
9265
9266@var{object-regexp} is a regular expression matching the objects
9267whose pretty-printers to list.
9268Objects can be @code{global}, the program space's file
9269(@pxref{Progspaces In Python}),
9270and the object files within that program space (@pxref{Objfiles In Python}).
9271@xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
9272looks up a printer from these three objects.
9273
9274@var{name-regexp} is a regular expression matching the name of the printers
9275to list.
9276
9277@kindex disable pretty-printer
9278@item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9279Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
9280A disabled pretty-printer is not forgotten, it may be enabled again later.
9281
9282@kindex enable pretty-printer
9283@item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9284Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
9285@end table
9286
9287Example:
9288
9289Suppose we have three pretty-printers installed: one from library1.so
9290named @code{foo} that prints objects of type @code{foo}, and
9291another from library2.so named @code{bar} that prints two types of objects,
9292@code{bar1} and @code{bar2}.
9293
9294@smallexample
9295(gdb) info pretty-printer
9296library1.so:
9297 foo
9298library2.so:
9299 bar
9300 bar1
9301 bar2
9302(gdb) info pretty-printer library2
9303library2.so:
9304 bar
9305 bar1
9306 bar2
9307(gdb) disable pretty-printer library1
93081 printer disabled
93092 of 3 printers enabled
9310(gdb) info pretty-printer
9311library1.so:
9312 foo [disabled]
9313library2.so:
9314 bar
9315 bar1
9316 bar2
9317(gdb) disable pretty-printer library2 bar:bar1
93181 printer disabled
93191 of 3 printers enabled
9320(gdb) info pretty-printer library2
9321library1.so:
9322 foo [disabled]
9323library2.so:
9324 bar
9325 bar1 [disabled]
9326 bar2
9327(gdb) disable pretty-printer library2 bar
93281 printer disabled
93290 of 3 printers enabled
9330(gdb) info pretty-printer library2
9331library1.so:
9332 foo [disabled]
9333library2.so:
9334 bar [disabled]
9335 bar1 [disabled]
9336 bar2
9337@end smallexample
9338
9339Note that for @code{bar} the entire printer can be disabled,
9340as can each individual subprinter.
4c374409 9341
6d2ebf8b 9342@node Value History
79a6e687 9343@section Value History
c906108c
SS
9344
9345@cindex value history
9c16f35a 9346@cindex history of values printed by @value{GDBN}
5d161b24
DB
9347Values printed by the @code{print} command are saved in the @value{GDBN}
9348@dfn{value history}. This allows you to refer to them in other expressions.
9349Values are kept until the symbol table is re-read or discarded
9350(for example with the @code{file} or @code{symbol-file} commands).
9351When the symbol table changes, the value history is discarded,
9352since the values may contain pointers back to the types defined in the
c906108c
SS
9353symbol table.
9354
9355@cindex @code{$}
9356@cindex @code{$$}
9357@cindex history number
9358The values printed are given @dfn{history numbers} by which you can
9359refer to them. These are successive integers starting with one.
9360@code{print} shows you the history number assigned to a value by
9361printing @samp{$@var{num} = } before the value; here @var{num} is the
9362history number.
9363
9364To refer to any previous value, use @samp{$} followed by the value's
9365history number. The way @code{print} labels its output is designed to
9366remind you of this. Just @code{$} refers to the most recent value in
9367the history, and @code{$$} refers to the value before that.
9368@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
9369is the value just prior to @code{$$}, @code{$$1} is equivalent to
9370@code{$$}, and @code{$$0} is equivalent to @code{$}.
9371
9372For example, suppose you have just printed a pointer to a structure and
9373want to see the contents of the structure. It suffices to type
9374
474c8240 9375@smallexample
c906108c 9376p *$
474c8240 9377@end smallexample
c906108c
SS
9378
9379If you have a chain of structures where the component @code{next} points
9380to the next one, you can print the contents of the next one with this:
9381
474c8240 9382@smallexample
c906108c 9383p *$.next
474c8240 9384@end smallexample
c906108c
SS
9385
9386@noindent
9387You can print successive links in the chain by repeating this
9388command---which you can do by just typing @key{RET}.
9389
9390Note that the history records values, not expressions. If the value of
9391@code{x} is 4 and you type these commands:
9392
474c8240 9393@smallexample
c906108c
SS
9394print x
9395set x=5
474c8240 9396@end smallexample
c906108c
SS
9397
9398@noindent
9399then the value recorded in the value history by the @code{print} command
9400remains 4 even though the value of @code{x} has changed.
9401
9402@table @code
9403@kindex show values
9404@item show values
9405Print the last ten values in the value history, with their item numbers.
9406This is like @samp{p@ $$9} repeated ten times, except that @code{show
9407values} does not change the history.
9408
9409@item show values @var{n}
9410Print ten history values centered on history item number @var{n}.
9411
9412@item show values +
9413Print ten history values just after the values last printed. If no more
9414values are available, @code{show values +} produces no display.
9415@end table
9416
9417Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
9418same effect as @samp{show values +}.
9419
6d2ebf8b 9420@node Convenience Vars
79a6e687 9421@section Convenience Variables
c906108c
SS
9422
9423@cindex convenience variables
9c16f35a 9424@cindex user-defined variables
c906108c
SS
9425@value{GDBN} provides @dfn{convenience variables} that you can use within
9426@value{GDBN} to hold on to a value and refer to it later. These variables
9427exist entirely within @value{GDBN}; they are not part of your program, and
9428setting a convenience variable has no direct effect on further execution
9429of your program. That is why you can use them freely.
9430
9431Convenience variables are prefixed with @samp{$}. Any name preceded by
9432@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 9433the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c 9434(Value history references, in contrast, are @emph{numbers} preceded
79a6e687 9435by @samp{$}. @xref{Value History, ,Value History}.)
c906108c
SS
9436
9437You can save a value in a convenience variable with an assignment
9438expression, just as you would set a variable in your program.
9439For example:
9440
474c8240 9441@smallexample
c906108c 9442set $foo = *object_ptr
474c8240 9443@end smallexample
c906108c
SS
9444
9445@noindent
9446would save in @code{$foo} the value contained in the object pointed to by
9447@code{object_ptr}.
9448
9449Using a convenience variable for the first time creates it, but its
9450value is @code{void} until you assign a new value. You can alter the
9451value with another assignment at any time.
9452
9453Convenience variables have no fixed types. You can assign a convenience
9454variable any type of value, including structures and arrays, even if
9455that variable already has a value of a different type. The convenience
9456variable, when used as an expression, has the type of its current value.
9457
9458@table @code
9459@kindex show convenience
f47f77df 9460@cindex show all user variables and functions
c906108c 9461@item show convenience
f47f77df
DE
9462Print a list of convenience variables used so far, and their values,
9463as well as a list of the convenience functions.
d4f3574e 9464Abbreviated @code{show conv}.
53e5f3cf
AS
9465
9466@kindex init-if-undefined
9467@cindex convenience variables, initializing
9468@item init-if-undefined $@var{variable} = @var{expression}
9469Set a convenience variable if it has not already been set. This is useful
9470for user-defined commands that keep some state. It is similar, in concept,
9471to using local static variables with initializers in C (except that
9472convenience variables are global). It can also be used to allow users to
9473override default values used in a command script.
9474
9475If the variable is already defined then the expression is not evaluated so
9476any side-effects do not occur.
c906108c
SS
9477@end table
9478
9479One of the ways to use a convenience variable is as a counter to be
9480incremented or a pointer to be advanced. For example, to print
9481a field from successive elements of an array of structures:
9482
474c8240 9483@smallexample
c906108c
SS
9484set $i = 0
9485print bar[$i++]->contents
474c8240 9486@end smallexample
c906108c 9487
d4f3574e
SS
9488@noindent
9489Repeat that command by typing @key{RET}.
c906108c
SS
9490
9491Some convenience variables are created automatically by @value{GDBN} and given
9492values likely to be useful.
9493
9494@table @code
41afff9a 9495@vindex $_@r{, convenience variable}
c906108c
SS
9496@item $_
9497The variable @code{$_} is automatically set by the @code{x} command to
79a6e687 9498the last address examined (@pxref{Memory, ,Examining Memory}). Other
c906108c
SS
9499commands which provide a default address for @code{x} to examine also
9500set @code{$_} to that address; these commands include @code{info line}
9501and @code{info breakpoint}. The type of @code{$_} is @code{void *}
9502except when set by the @code{x} command, in which case it is a pointer
9503to the type of @code{$__}.
9504
41afff9a 9505@vindex $__@r{, convenience variable}
c906108c
SS
9506@item $__
9507The variable @code{$__} is automatically set by the @code{x} command
9508to the value found in the last address examined. Its type is chosen
9509to match the format in which the data was printed.
9510
9511@item $_exitcode
41afff9a 9512@vindex $_exitcode@r{, convenience variable}
c906108c
SS
9513The variable @code{$_exitcode} is automatically set to the exit code when
9514the program being debugged terminates.
4aa995e1 9515
62e5f89c
SDJ
9516@item $_probe_argc
9517@itemx $_probe_arg0@dots{}$_probe_arg11
9518Arguments to a static probe. @xref{Static Probe Points}.
9519
0fb4aa4b
PA
9520@item $_sdata
9521@vindex $_sdata@r{, inspect, convenience variable}
9522The variable @code{$_sdata} contains extra collected static tracepoint
9523data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
9524@code{$_sdata} could be empty, if not inspecting a trace buffer, or
9525if extra static tracepoint data has not been collected.
9526
4aa995e1
PA
9527@item $_siginfo
9528@vindex $_siginfo@r{, convenience variable}
ec7e75e7
PP
9529The variable @code{$_siginfo} contains extra signal information
9530(@pxref{extra signal information}). Note that @code{$_siginfo}
9531could be empty, if the application has not yet received any signals.
9532For example, it will be empty before you execute the @code{run} command.
711e434b
PM
9533
9534@item $_tlb
9535@vindex $_tlb@r{, convenience variable}
9536The variable @code{$_tlb} is automatically set when debugging
9537applications running on MS-Windows in native mode or connected to
9538gdbserver that supports the @code{qGetTIBAddr} request.
9539@xref{General Query Packets}.
9540This variable contains the address of the thread information block.
9541
c906108c
SS
9542@end table
9543
53a5351d
JM
9544On HP-UX systems, if you refer to a function or variable name that
9545begins with a dollar sign, @value{GDBN} searches for a user or system
9546name first, before it searches for a convenience variable.
c906108c 9547
a72c3253
DE
9548@node Convenience Funs
9549@section Convenience Functions
9550
bc3b79fd
TJB
9551@cindex convenience functions
9552@value{GDBN} also supplies some @dfn{convenience functions}. These
9553have a syntax similar to convenience variables. A convenience
9554function can be used in an expression just like an ordinary function;
9555however, a convenience function is implemented internally to
9556@value{GDBN}.
9557
a72c3253
DE
9558These functions require @value{GDBN} to be configured with
9559@code{Python} support.
9560
9561@table @code
9562
9563@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
9564@findex $_memeq@r{, convenience function}
9565Returns one if the @var{length} bytes at the addresses given by
9566@var{buf1} and @var{buf2} are equal.
9567Otherwise it returns zero.
9568
9569@item $_regex(@var{str}, @var{regex})
9570@findex $_regex@r{, convenience function}
9571Returns one if the string @var{str} matches the regular expression
9572@var{regex}. Otherwise it returns zero.
9573The syntax of the regular expression is that specified by @code{Python}'s
9574regular expression support.
9575
9576@item $_streq(@var{str1}, @var{str2})
9577@findex $_streq@r{, convenience function}
9578Returns one if the strings @var{str1} and @var{str2} are equal.
9579Otherwise it returns zero.
9580
9581@item $_strlen(@var{str})
9582@findex $_strlen@r{, convenience function}
9583Returns the length of string @var{str}.
9584
9585@end table
9586
9587@value{GDBN} provides the ability to list and get help on
9588convenience functions.
9589
bc3b79fd
TJB
9590@table @code
9591@item help function
9592@kindex help function
9593@cindex show all convenience functions
9594Print a list of all convenience functions.
9595@end table
9596
6d2ebf8b 9597@node Registers
c906108c
SS
9598@section Registers
9599
9600@cindex registers
9601You can refer to machine register contents, in expressions, as variables
9602with names starting with @samp{$}. The names of registers are different
9603for each machine; use @code{info registers} to see the names used on
9604your machine.
9605
9606@table @code
9607@kindex info registers
9608@item info registers
9609Print the names and values of all registers except floating-point
c85508ee 9610and vector registers (in the selected stack frame).
c906108c
SS
9611
9612@kindex info all-registers
9613@cindex floating point registers
9614@item info all-registers
9615Print the names and values of all registers, including floating-point
c85508ee 9616and vector registers (in the selected stack frame).
c906108c
SS
9617
9618@item info registers @var{regname} @dots{}
9619Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
9620As discussed in detail below, register values are normally relative to
9621the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
9622the machine you are using, with or without the initial @samp{$}.
9623@end table
9624
e09f16f9
EZ
9625@cindex stack pointer register
9626@cindex program counter register
9627@cindex process status register
9628@cindex frame pointer register
9629@cindex standard registers
c906108c
SS
9630@value{GDBN} has four ``standard'' register names that are available (in
9631expressions) on most machines---whenever they do not conflict with an
9632architecture's canonical mnemonics for registers. The register names
9633@code{$pc} and @code{$sp} are used for the program counter register and
9634the stack pointer. @code{$fp} is used for a register that contains a
9635pointer to the current stack frame, and @code{$ps} is used for a
9636register that contains the processor status. For example,
9637you could print the program counter in hex with
9638
474c8240 9639@smallexample
c906108c 9640p/x $pc
474c8240 9641@end smallexample
c906108c
SS
9642
9643@noindent
9644or print the instruction to be executed next with
9645
474c8240 9646@smallexample
c906108c 9647x/i $pc
474c8240 9648@end smallexample
c906108c
SS
9649
9650@noindent
9651or add four to the stack pointer@footnote{This is a way of removing
9652one word from the stack, on machines where stacks grow downward in
9653memory (most machines, nowadays). This assumes that the innermost
9654stack frame is selected; setting @code{$sp} is not allowed when other
9655stack frames are selected. To pop entire frames off the stack,
9656regardless of machine architecture, use @code{return};
79a6e687 9657see @ref{Returning, ,Returning from a Function}.} with
c906108c 9658
474c8240 9659@smallexample
c906108c 9660set $sp += 4
474c8240 9661@end smallexample
c906108c
SS
9662
9663Whenever possible, these four standard register names are available on
9664your machine even though the machine has different canonical mnemonics,
9665so long as there is no conflict. The @code{info registers} command
9666shows the canonical names. For example, on the SPARC, @code{info
9667registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
9668can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
9669is an alias for the @sc{eflags} register.
c906108c
SS
9670
9671@value{GDBN} always considers the contents of an ordinary register as an
9672integer when the register is examined in this way. Some machines have
9673special registers which can hold nothing but floating point; these
9674registers are considered to have floating point values. There is no way
9675to refer to the contents of an ordinary register as floating point value
9676(although you can @emph{print} it as a floating point value with
9677@samp{print/f $@var{regname}}).
9678
9679Some registers have distinct ``raw'' and ``virtual'' data formats. This
9680means that the data format in which the register contents are saved by
9681the operating system is not the same one that your program normally
9682sees. For example, the registers of the 68881 floating point
9683coprocessor are always saved in ``extended'' (raw) format, but all C
9684programs expect to work with ``double'' (virtual) format. In such
5d161b24 9685cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
9686that makes sense for your program), but the @code{info registers} command
9687prints the data in both formats.
9688
36b80e65
EZ
9689@cindex SSE registers (x86)
9690@cindex MMX registers (x86)
9691Some machines have special registers whose contents can be interpreted
9692in several different ways. For example, modern x86-based machines
9693have SSE and MMX registers that can hold several values packed
9694together in several different formats. @value{GDBN} refers to such
9695registers in @code{struct} notation:
9696
9697@smallexample
9698(@value{GDBP}) print $xmm1
9699$1 = @{
9700 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
9701 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
9702 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
9703 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
9704 v4_int32 = @{0, 20657912, 11, 13@},
9705 v2_int64 = @{88725056443645952, 55834574859@},
9706 uint128 = 0x0000000d0000000b013b36f800000000
9707@}
9708@end smallexample
9709
9710@noindent
9711To set values of such registers, you need to tell @value{GDBN} which
9712view of the register you wish to change, as if you were assigning
9713value to a @code{struct} member:
9714
9715@smallexample
9716 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
9717@end smallexample
9718
c906108c 9719Normally, register values are relative to the selected stack frame
79a6e687 9720(@pxref{Selection, ,Selecting a Frame}). This means that you get the
c906108c
SS
9721value that the register would contain if all stack frames farther in
9722were exited and their saved registers restored. In order to see the
9723true contents of hardware registers, you must select the innermost
9724frame (with @samp{frame 0}).
9725
9726However, @value{GDBN} must deduce where registers are saved, from the machine
9727code generated by your compiler. If some registers are not saved, or if
9728@value{GDBN} is unable to locate the saved registers, the selected stack
9729frame makes no difference.
9730
6d2ebf8b 9731@node Floating Point Hardware
79a6e687 9732@section Floating Point Hardware
c906108c
SS
9733@cindex floating point
9734
9735Depending on the configuration, @value{GDBN} may be able to give
9736you more information about the status of the floating point hardware.
9737
9738@table @code
9739@kindex info float
9740@item info float
9741Display hardware-dependent information about the floating
9742point unit. The exact contents and layout vary depending on the
9743floating point chip. Currently, @samp{info float} is supported on
9744the ARM and x86 machines.
9745@end table
c906108c 9746
e76f1f2e
AC
9747@node Vector Unit
9748@section Vector Unit
9749@cindex vector unit
9750
9751Depending on the configuration, @value{GDBN} may be able to give you
9752more information about the status of the vector unit.
9753
9754@table @code
9755@kindex info vector
9756@item info vector
9757Display information about the vector unit. The exact contents and
9758layout vary depending on the hardware.
9759@end table
9760
721c2651 9761@node OS Information
79a6e687 9762@section Operating System Auxiliary Information
721c2651
EZ
9763@cindex OS information
9764
9765@value{GDBN} provides interfaces to useful OS facilities that can help
9766you debug your program.
9767
b383017d
RM
9768@cindex auxiliary vector
9769@cindex vector, auxiliary
b383017d
RM
9770Some operating systems supply an @dfn{auxiliary vector} to programs at
9771startup. This is akin to the arguments and environment that you
9772specify for a program, but contains a system-dependent variety of
9773binary values that tell system libraries important details about the
9774hardware, operating system, and process. Each value's purpose is
9775identified by an integer tag; the meanings are well-known but system-specific.
9776Depending on the configuration and operating system facilities,
9c16f35a
EZ
9777@value{GDBN} may be able to show you this information. For remote
9778targets, this functionality may further depend on the remote stub's
427c3a89
DJ
9779support of the @samp{qXfer:auxv:read} packet, see
9780@ref{qXfer auxiliary vector read}.
b383017d
RM
9781
9782@table @code
9783@kindex info auxv
9784@item info auxv
9785Display the auxiliary vector of the inferior, which can be either a
e4937fc1 9786live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
9787numerically, and also shows names and text descriptions for recognized
9788tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 9789pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
9790most appropriate form for a recognized tag, and in hexadecimal for
9791an unrecognized tag.
9792@end table
9793
85d4a676
SS
9794On some targets, @value{GDBN} can access operating system-specific
9795information and show it to you. The types of information available
9796will differ depending on the type of operating system running on the
9797target. The mechanism used to fetch the data is described in
9798@ref{Operating System Information}. For remote targets, this
9799functionality depends on the remote stub's support of the
07e059b5
VP
9800@samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
9801
9802@table @code
a61408f8 9803@kindex info os
85d4a676
SS
9804@item info os @var{infotype}
9805
9806Display OS information of the requested type.
a61408f8 9807
85d4a676
SS
9808On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
9809
9810@anchor{linux info os infotypes}
9811@table @code
07e059b5 9812@kindex info os processes
85d4a676 9813@item processes
07e059b5 9814Display the list of processes on the target. For each process,
85d4a676
SS
9815@value{GDBN} prints the process identifier, the name of the user, the
9816command corresponding to the process, and the list of processor cores
9817that the process is currently running on. (To understand what these
9818properties mean, for this and the following info types, please consult
9819the general @sc{gnu}/Linux documentation.)
9820
9821@kindex info os procgroups
9822@item procgroups
9823Display the list of process groups on the target. For each process,
9824@value{GDBN} prints the identifier of the process group that it belongs
9825to, the command corresponding to the process group leader, the process
9826identifier, and the command line of the process. The list is sorted
9827first by the process group identifier, then by the process identifier,
9828so that processes belonging to the same process group are grouped together
9829and the process group leader is listed first.
9830
9831@kindex info os threads
9832@item threads
9833Display the list of threads running on the target. For each thread,
9834@value{GDBN} prints the identifier of the process that the thread
9835belongs to, the command of the process, the thread identifier, and the
9836processor core that it is currently running on. The main thread of a
9837process is not listed.
9838
9839@kindex info os files
9840@item files
9841Display the list of open file descriptors on the target. For each
9842file descriptor, @value{GDBN} prints the identifier of the process
9843owning the descriptor, the command of the owning process, the value
9844of the descriptor, and the target of the descriptor.
9845
9846@kindex info os sockets
9847@item sockets
9848Display the list of Internet-domain sockets on the target. For each
9849socket, @value{GDBN} prints the address and port of the local and
9850remote endpoints, the current state of the connection, the creator of
9851the socket, the IP address family of the socket, and the type of the
9852connection.
9853
9854@kindex info os shm
9855@item shm
9856Display the list of all System V shared-memory regions on the target.
9857For each shared-memory region, @value{GDBN} prints the region key,
9858the shared-memory identifier, the access permissions, the size of the
9859region, the process that created the region, the process that last
9860attached to or detached from the region, the current number of live
9861attaches to the region, and the times at which the region was last
9862attached to, detach from, and changed.
9863
9864@kindex info os semaphores
9865@item semaphores
9866Display the list of all System V semaphore sets on the target. For each
9867semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
9868set identifier, the access permissions, the number of semaphores in the
9869set, the user and group of the owner and creator of the semaphore set,
9870and the times at which the semaphore set was operated upon and changed.
9871
9872@kindex info os msg
9873@item msg
9874Display the list of all System V message queues on the target. For each
9875message queue, @value{GDBN} prints the message queue key, the message
9876queue identifier, the access permissions, the current number of bytes
9877on the queue, the current number of messages on the queue, the processes
9878that last sent and received a message on the queue, the user and group
9879of the owner and creator of the message queue, the times at which a
9880message was last sent and received on the queue, and the time at which
9881the message queue was last changed.
9882
9883@kindex info os modules
9884@item modules
9885Display the list of all loaded kernel modules on the target. For each
9886module, @value{GDBN} prints the module name, the size of the module in
9887bytes, the number of times the module is used, the dependencies of the
9888module, the status of the module, and the address of the loaded module
9889in memory.
9890@end table
9891
9892@item info os
9893If @var{infotype} is omitted, then list the possible values for
9894@var{infotype} and the kind of OS information available for each
9895@var{infotype}. If the target does not return a list of possible
9896types, this command will report an error.
07e059b5 9897@end table
721c2651 9898
29e57380 9899@node Memory Region Attributes
79a6e687 9900@section Memory Region Attributes
29e57380
C
9901@cindex memory region attributes
9902
b383017d 9903@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
9904required by regions of your target's memory. @value{GDBN} uses
9905attributes to determine whether to allow certain types of memory
9906accesses; whether to use specific width accesses; and whether to cache
9907target memory. By default the description of memory regions is
9908fetched from the target (if the current target supports this), but the
9909user can override the fetched regions.
29e57380
C
9910
9911Defined memory regions can be individually enabled and disabled. When a
9912memory region is disabled, @value{GDBN} uses the default attributes when
9913accessing memory in that region. Similarly, if no memory regions have
9914been defined, @value{GDBN} uses the default attributes when accessing
9915all memory.
9916
b383017d 9917When a memory region is defined, it is given a number to identify it;
29e57380
C
9918to enable, disable, or remove a memory region, you specify that number.
9919
9920@table @code
9921@kindex mem
bfac230e 9922@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
9923Define a memory region bounded by @var{lower} and @var{upper} with
9924attributes @var{attributes}@dots{}, and add it to the list of regions
9925monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
d3e8051b 9926case: it is treated as the target's maximum memory address.
bfac230e 9927(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 9928
fd79ecee
DJ
9929@item mem auto
9930Discard any user changes to the memory regions and use target-supplied
9931regions, if available, or no regions if the target does not support.
9932
29e57380
C
9933@kindex delete mem
9934@item delete mem @var{nums}@dots{}
09d4efe1
EZ
9935Remove memory regions @var{nums}@dots{} from the list of regions
9936monitored by @value{GDBN}.
29e57380
C
9937
9938@kindex disable mem
9939@item disable mem @var{nums}@dots{}
09d4efe1 9940Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 9941A disabled memory region is not forgotten.
29e57380
C
9942It may be enabled again later.
9943
9944@kindex enable mem
9945@item enable mem @var{nums}@dots{}
09d4efe1 9946Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
9947
9948@kindex info mem
9949@item info mem
9950Print a table of all defined memory regions, with the following columns
09d4efe1 9951for each region:
29e57380
C
9952
9953@table @emph
9954@item Memory Region Number
9955@item Enabled or Disabled.
b383017d 9956Enabled memory regions are marked with @samp{y}.
29e57380
C
9957Disabled memory regions are marked with @samp{n}.
9958
9959@item Lo Address
9960The address defining the inclusive lower bound of the memory region.
9961
9962@item Hi Address
9963The address defining the exclusive upper bound of the memory region.
9964
9965@item Attributes
9966The list of attributes set for this memory region.
9967@end table
9968@end table
9969
9970
9971@subsection Attributes
9972
b383017d 9973@subsubsection Memory Access Mode
29e57380
C
9974The access mode attributes set whether @value{GDBN} may make read or
9975write accesses to a memory region.
9976
9977While these attributes prevent @value{GDBN} from performing invalid
9978memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 9979etc.@: from accessing memory.
29e57380
C
9980
9981@table @code
9982@item ro
9983Memory is read only.
9984@item wo
9985Memory is write only.
9986@item rw
6ca652b0 9987Memory is read/write. This is the default.
29e57380
C
9988@end table
9989
9990@subsubsection Memory Access Size
d3e8051b 9991The access size attribute tells @value{GDBN} to use specific sized
29e57380
C
9992accesses in the memory region. Often memory mapped device registers
9993require specific sized accesses. If no access size attribute is
9994specified, @value{GDBN} may use accesses of any size.
9995
9996@table @code
9997@item 8
9998Use 8 bit memory accesses.
9999@item 16
10000Use 16 bit memory accesses.
10001@item 32
10002Use 32 bit memory accesses.
10003@item 64
10004Use 64 bit memory accesses.
10005@end table
10006
10007@c @subsubsection Hardware/Software Breakpoints
10008@c The hardware/software breakpoint attributes set whether @value{GDBN}
10009@c will use hardware or software breakpoints for the internal breakpoints
10010@c used by the step, next, finish, until, etc. commands.
10011@c
10012@c @table @code
10013@c @item hwbreak
b383017d 10014@c Always use hardware breakpoints
29e57380
C
10015@c @item swbreak (default)
10016@c @end table
10017
10018@subsubsection Data Cache
10019The data cache attributes set whether @value{GDBN} will cache target
10020memory. While this generally improves performance by reducing debug
10021protocol overhead, it can lead to incorrect results because @value{GDBN}
10022does not know about volatile variables or memory mapped device
10023registers.
10024
10025@table @code
10026@item cache
b383017d 10027Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
10028@item nocache
10029Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
10030@end table
10031
4b5752d0
VP
10032@subsection Memory Access Checking
10033@value{GDBN} can be instructed to refuse accesses to memory that is
10034not explicitly described. This can be useful if accessing such
10035regions has undesired effects for a specific target, or to provide
10036better error checking. The following commands control this behaviour.
10037
10038@table @code
10039@kindex set mem inaccessible-by-default
10040@item set mem inaccessible-by-default [on|off]
10041If @code{on} is specified, make @value{GDBN} treat memory not
10042explicitly described by the memory ranges as non-existent and refuse accesses
10043to such memory. The checks are only performed if there's at least one
10044memory range defined. If @code{off} is specified, make @value{GDBN}
10045treat the memory not explicitly described by the memory ranges as RAM.
56cf5405 10046The default value is @code{on}.
4b5752d0
VP
10047@kindex show mem inaccessible-by-default
10048@item show mem inaccessible-by-default
10049Show the current handling of accesses to unknown memory.
10050@end table
10051
10052
29e57380 10053@c @subsubsection Memory Write Verification
b383017d 10054@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
10055@c will re-reads data after each write to verify the write was successful.
10056@c
10057@c @table @code
10058@c @item verify
10059@c @item noverify (default)
10060@c @end table
10061
16d9dec6 10062@node Dump/Restore Files
79a6e687 10063@section Copy Between Memory and a File
16d9dec6
MS
10064@cindex dump/restore files
10065@cindex append data to a file
10066@cindex dump data to a file
10067@cindex restore data from a file
16d9dec6 10068
df5215a6
JB
10069You can use the commands @code{dump}, @code{append}, and
10070@code{restore} to copy data between target memory and a file. The
10071@code{dump} and @code{append} commands write data to a file, and the
10072@code{restore} command reads data from a file back into the inferior's
10073memory. Files may be in binary, Motorola S-record, Intel hex, or
10074Tektronix Hex format; however, @value{GDBN} can only append to binary
10075files.
10076
10077@table @code
10078
10079@kindex dump
10080@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
10081@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
10082Dump the contents of memory from @var{start_addr} to @var{end_addr},
10083or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 10084
df5215a6 10085The @var{format} parameter may be any one of:
16d9dec6 10086@table @code
df5215a6
JB
10087@item binary
10088Raw binary form.
10089@item ihex
10090Intel hex format.
10091@item srec
10092Motorola S-record format.
10093@item tekhex
10094Tektronix Hex format.
10095@end table
10096
10097@value{GDBN} uses the same definitions of these formats as the
10098@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
10099@var{format} is omitted, @value{GDBN} dumps the data in raw binary
10100form.
10101
10102@kindex append
10103@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
10104@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
10105Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 10106or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
10107(@value{GDBN} can only append data to files in raw binary form.)
10108
10109@kindex restore
10110@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
10111Restore the contents of file @var{filename} into memory. The
10112@code{restore} command can automatically recognize any known @sc{bfd}
10113file format, except for raw binary. To restore a raw binary file you
10114must specify the optional keyword @code{binary} after the filename.
16d9dec6 10115
b383017d 10116If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
10117contained in the file. Binary files always start at address zero, so
10118they will be restored at address @var{bias}. Other bfd files have
10119a built-in location; they will be restored at offset @var{bias}
10120from that location.
10121
10122If @var{start} and/or @var{end} are non-zero, then only data between
10123file offset @var{start} and file offset @var{end} will be restored.
b383017d 10124These offsets are relative to the addresses in the file, before
16d9dec6
MS
10125the @var{bias} argument is applied.
10126
10127@end table
10128
384ee23f
EZ
10129@node Core File Generation
10130@section How to Produce a Core File from Your Program
10131@cindex dump core from inferior
10132
10133A @dfn{core file} or @dfn{core dump} is a file that records the memory
10134image of a running process and its process status (register values
10135etc.). Its primary use is post-mortem debugging of a program that
10136crashed while it ran outside a debugger. A program that crashes
10137automatically produces a core file, unless this feature is disabled by
10138the user. @xref{Files}, for information on invoking @value{GDBN} in
10139the post-mortem debugging mode.
10140
10141Occasionally, you may wish to produce a core file of the program you
10142are debugging in order to preserve a snapshot of its state.
10143@value{GDBN} has a special command for that.
10144
10145@table @code
10146@kindex gcore
10147@kindex generate-core-file
10148@item generate-core-file [@var{file}]
10149@itemx gcore [@var{file}]
10150Produce a core dump of the inferior process. The optional argument
10151@var{file} specifies the file name where to put the core dump. If not
10152specified, the file name defaults to @file{core.@var{pid}}, where
10153@var{pid} is the inferior process ID.
10154
10155Note that this command is implemented only for some systems (as of
05b4bd79 10156this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
384ee23f
EZ
10157@end table
10158
a0eb71c5
KB
10159@node Character Sets
10160@section Character Sets
10161@cindex character sets
10162@cindex charset
10163@cindex translating between character sets
10164@cindex host character set
10165@cindex target character set
10166
10167If the program you are debugging uses a different character set to
10168represent characters and strings than the one @value{GDBN} uses itself,
10169@value{GDBN} can automatically translate between the character sets for
10170you. The character set @value{GDBN} uses we call the @dfn{host
10171character set}; the one the inferior program uses we call the
10172@dfn{target character set}.
10173
10174For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
10175uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
ea35711c 10176remote protocol (@pxref{Remote Debugging}) to debug a program
a0eb71c5
KB
10177running on an IBM mainframe, which uses the @sc{ebcdic} character set,
10178then the host character set is Latin-1, and the target character set is
10179@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 10180target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
10181@sc{ebcdic} and Latin 1 as you print character or string values, or use
10182character and string literals in expressions.
10183
10184@value{GDBN} has no way to automatically recognize which character set
10185the inferior program uses; you must tell it, using the @code{set
10186target-charset} command, described below.
10187
10188Here are the commands for controlling @value{GDBN}'s character set
10189support:
10190
10191@table @code
10192@item set target-charset @var{charset}
10193@kindex set target-charset
10af6951
EZ
10194Set the current target character set to @var{charset}. To display the
10195list of supported target character sets, type
10196@kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
a0eb71c5 10197
a0eb71c5
KB
10198@item set host-charset @var{charset}
10199@kindex set host-charset
10200Set the current host character set to @var{charset}.
10201
10202By default, @value{GDBN} uses a host character set appropriate to the
10203system it is running on; you can override that default using the
732f6a93
TT
10204@code{set host-charset} command. On some systems, @value{GDBN} cannot
10205automatically determine the appropriate host character set. In this
10206case, @value{GDBN} uses @samp{UTF-8}.
a0eb71c5
KB
10207
10208@value{GDBN} can only use certain character sets as its host character
c1b6b909 10209set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
10af6951 10210@value{GDBN} will list the host character sets it supports.
a0eb71c5
KB
10211
10212@item set charset @var{charset}
10213@kindex set charset
e33d66ec 10214Set the current host and target character sets to @var{charset}. As
10af6951
EZ
10215above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
10216@value{GDBN} will list the names of the character sets that can be used
e33d66ec
EZ
10217for both host and target.
10218
a0eb71c5 10219@item show charset
a0eb71c5 10220@kindex show charset
10af6951 10221Show the names of the current host and target character sets.
e33d66ec 10222
10af6951 10223@item show host-charset
a0eb71c5 10224@kindex show host-charset
10af6951 10225Show the name of the current host character set.
e33d66ec 10226
10af6951 10227@item show target-charset
a0eb71c5 10228@kindex show target-charset
10af6951 10229Show the name of the current target character set.
a0eb71c5 10230
10af6951
EZ
10231@item set target-wide-charset @var{charset}
10232@kindex set target-wide-charset
10233Set the current target's wide character set to @var{charset}. This is
10234the character set used by the target's @code{wchar_t} type. To
10235display the list of supported wide character sets, type
10236@kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
10237
10238@item show target-wide-charset
10239@kindex show target-wide-charset
10240Show the name of the current target's wide character set.
a0eb71c5
KB
10241@end table
10242
a0eb71c5
KB
10243Here is an example of @value{GDBN}'s character set support in action.
10244Assume that the following source code has been placed in the file
10245@file{charset-test.c}:
10246
10247@smallexample
10248#include <stdio.h>
10249
10250char ascii_hello[]
10251 = @{72, 101, 108, 108, 111, 44, 32, 119,
10252 111, 114, 108, 100, 33, 10, 0@};
10253char ibm1047_hello[]
10254 = @{200, 133, 147, 147, 150, 107, 64, 166,
10255 150, 153, 147, 132, 90, 37, 0@};
10256
10257main ()
10258@{
10259 printf ("Hello, world!\n");
10260@}
10998722 10261@end smallexample
a0eb71c5
KB
10262
10263In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
10264containing the string @samp{Hello, world!} followed by a newline,
10265encoded in the @sc{ascii} and @sc{ibm1047} character sets.
10266
10267We compile the program, and invoke the debugger on it:
10268
10269@smallexample
10270$ gcc -g charset-test.c -o charset-test
10271$ gdb -nw charset-test
10272GNU gdb 2001-12-19-cvs
10273Copyright 2001 Free Software Foundation, Inc.
10274@dots{}
f7dc1244 10275(@value{GDBP})
10998722 10276@end smallexample
a0eb71c5
KB
10277
10278We can use the @code{show charset} command to see what character sets
10279@value{GDBN} is currently using to interpret and display characters and
10280strings:
10281
10282@smallexample
f7dc1244 10283(@value{GDBP}) show charset
e33d66ec 10284The current host and target character set is `ISO-8859-1'.
f7dc1244 10285(@value{GDBP})
10998722 10286@end smallexample
a0eb71c5
KB
10287
10288For the sake of printing this manual, let's use @sc{ascii} as our
10289initial character set:
10290@smallexample
f7dc1244
EZ
10291(@value{GDBP}) set charset ASCII
10292(@value{GDBP}) show charset
e33d66ec 10293The current host and target character set is `ASCII'.
f7dc1244 10294(@value{GDBP})
10998722 10295@end smallexample
a0eb71c5
KB
10296
10297Let's assume that @sc{ascii} is indeed the correct character set for our
10298host system --- in other words, let's assume that if @value{GDBN} prints
10299characters using the @sc{ascii} character set, our terminal will display
10300them properly. Since our current target character set is also
10301@sc{ascii}, the contents of @code{ascii_hello} print legibly:
10302
10303@smallexample
f7dc1244 10304(@value{GDBP}) print ascii_hello
a0eb71c5 10305$1 = 0x401698 "Hello, world!\n"
f7dc1244 10306(@value{GDBP}) print ascii_hello[0]
a0eb71c5 10307$2 = 72 'H'
f7dc1244 10308(@value{GDBP})
10998722 10309@end smallexample
a0eb71c5
KB
10310
10311@value{GDBN} uses the target character set for character and string
10312literals you use in expressions:
10313
10314@smallexample
f7dc1244 10315(@value{GDBP}) print '+'
a0eb71c5 10316$3 = 43 '+'
f7dc1244 10317(@value{GDBP})
10998722 10318@end smallexample
a0eb71c5
KB
10319
10320The @sc{ascii} character set uses the number 43 to encode the @samp{+}
10321character.
10322
10323@value{GDBN} relies on the user to tell it which character set the
10324target program uses. If we print @code{ibm1047_hello} while our target
10325character set is still @sc{ascii}, we get jibberish:
10326
10327@smallexample
f7dc1244 10328(@value{GDBP}) print ibm1047_hello
a0eb71c5 10329$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 10330(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 10331$5 = 200 '\310'
f7dc1244 10332(@value{GDBP})
10998722 10333@end smallexample
a0eb71c5 10334
e33d66ec 10335If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
10336@value{GDBN} tells us the character sets it supports:
10337
10338@smallexample
f7dc1244 10339(@value{GDBP}) set target-charset
b383017d 10340ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 10341(@value{GDBP}) set target-charset
10998722 10342@end smallexample
a0eb71c5
KB
10343
10344We can select @sc{ibm1047} as our target character set, and examine the
10345program's strings again. Now the @sc{ascii} string is wrong, but
10346@value{GDBN} translates the contents of @code{ibm1047_hello} from the
10347target character set, @sc{ibm1047}, to the host character set,
10348@sc{ascii}, and they display correctly:
10349
10350@smallexample
f7dc1244
EZ
10351(@value{GDBP}) set target-charset IBM1047
10352(@value{GDBP}) show charset
e33d66ec
EZ
10353The current host character set is `ASCII'.
10354The current target character set is `IBM1047'.
f7dc1244 10355(@value{GDBP}) print ascii_hello
a0eb71c5 10356$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 10357(@value{GDBP}) print ascii_hello[0]
a0eb71c5 10358$7 = 72 '\110'
f7dc1244 10359(@value{GDBP}) print ibm1047_hello
a0eb71c5 10360$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 10361(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 10362$9 = 200 'H'
f7dc1244 10363(@value{GDBP})
10998722 10364@end smallexample
a0eb71c5
KB
10365
10366As above, @value{GDBN} uses the target character set for character and
10367string literals you use in expressions:
10368
10369@smallexample
f7dc1244 10370(@value{GDBP}) print '+'
a0eb71c5 10371$10 = 78 '+'
f7dc1244 10372(@value{GDBP})
10998722 10373@end smallexample
a0eb71c5 10374
e33d66ec 10375The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
10376character.
10377
09d4efe1
EZ
10378@node Caching Remote Data
10379@section Caching Data of Remote Targets
10380@cindex caching data of remote targets
10381
4e5d721f 10382@value{GDBN} caches data exchanged between the debugger and a
ea35711c 10383remote target (@pxref{Remote Debugging}). Such caching generally improves
09d4efe1 10384performance, because it reduces the overhead of the remote protocol by
4e5d721f
DE
10385bundling memory reads and writes into large chunks. Unfortunately, simply
10386caching everything would lead to incorrect results, since @value{GDBN}
10387does not necessarily know anything about volatile values, memory-mapped I/O
29b090c0
DE
10388addresses, etc. Furthermore, in non-stop mode (@pxref{Non-Stop Mode})
10389memory can be changed @emph{while} a gdb command is executing.
10390Therefore, by default, @value{GDBN} only caches data
10391known to be on the stack@footnote{In non-stop mode, it is moderately
10392rare for a running thread to modify the stack of a stopped thread
10393in a way that would interfere with a backtrace, and caching of
10394stack reads provides a significant speed up of remote backtraces.}.
10395Other regions of memory can be explicitly marked as
4e5d721f 10396cacheable; see @pxref{Memory Region Attributes}.
09d4efe1
EZ
10397
10398@table @code
10399@kindex set remotecache
10400@item set remotecache on
10401@itemx set remotecache off
4e5d721f
DE
10402This option no longer does anything; it exists for compatibility
10403with old scripts.
09d4efe1
EZ
10404
10405@kindex show remotecache
10406@item show remotecache
4e5d721f
DE
10407Show the current state of the obsolete remotecache flag.
10408
10409@kindex set stack-cache
10410@item set stack-cache on
10411@itemx set stack-cache off
10412Enable or disable caching of stack accesses. When @code{ON}, use
10413caching. By default, this option is @code{ON}.
10414
10415@kindex show stack-cache
10416@item show stack-cache
10417Show the current state of data caching for memory accesses.
09d4efe1
EZ
10418
10419@kindex info dcache
4e5d721f 10420@item info dcache @r{[}line@r{]}
09d4efe1 10421Print the information about the data cache performance. The
4e5d721f
DE
10422information displayed includes the dcache width and depth, and for
10423each cache line, its number, address, and how many times it was
10424referenced. This command is useful for debugging the data cache
10425operation.
10426
10427If a line number is specified, the contents of that line will be
10428printed in hex.
1a532630
PP
10429
10430@item set dcache size @var{size}
10431@cindex dcache size
10432@kindex set dcache size
10433Set maximum number of entries in dcache (dcache depth above).
10434
10435@item set dcache line-size @var{line-size}
10436@cindex dcache line-size
10437@kindex set dcache line-size
10438Set number of bytes each dcache entry caches (dcache width above).
10439Must be a power of 2.
10440
10441@item show dcache size
10442@kindex show dcache size
10443Show maximum number of dcache entries. See also @ref{Caching Remote Data, info dcache}.
10444
10445@item show dcache line-size
10446@kindex show dcache line-size
10447Show default size of dcache lines. See also @ref{Caching Remote Data, info dcache}.
10448
09d4efe1
EZ
10449@end table
10450
08388c79
DE
10451@node Searching Memory
10452@section Search Memory
10453@cindex searching memory
10454
10455Memory can be searched for a particular sequence of bytes with the
10456@code{find} command.
10457
10458@table @code
10459@kindex find
10460@item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
10461@itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
10462Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
10463etc. The search begins at address @var{start_addr} and continues for either
10464@var{len} bytes or through to @var{end_addr} inclusive.
10465@end table
10466
10467@var{s} and @var{n} are optional parameters.
10468They may be specified in either order, apart or together.
10469
10470@table @r
10471@item @var{s}, search query size
10472The size of each search query value.
10473
10474@table @code
10475@item b
10476bytes
10477@item h
10478halfwords (two bytes)
10479@item w
10480words (four bytes)
10481@item g
10482giant words (eight bytes)
10483@end table
10484
10485All values are interpreted in the current language.
10486This means, for example, that if the current source language is C/C@t{++}
10487then searching for the string ``hello'' includes the trailing '\0'.
10488
10489If the value size is not specified, it is taken from the
10490value's type in the current language.
10491This is useful when one wants to specify the search
10492pattern as a mixture of types.
10493Note that this means, for example, that in the case of C-like languages
10494a search for an untyped 0x42 will search for @samp{(int) 0x42}
10495which is typically four bytes.
10496
10497@item @var{n}, maximum number of finds
10498The maximum number of matches to print. The default is to print all finds.
10499@end table
10500
10501You can use strings as search values. Quote them with double-quotes
10502 (@code{"}).
10503The string value is copied into the search pattern byte by byte,
10504regardless of the endianness of the target and the size specification.
10505
10506The address of each match found is printed as well as a count of the
10507number of matches found.
10508
10509The address of the last value found is stored in convenience variable
10510@samp{$_}.
10511A count of the number of matches is stored in @samp{$numfound}.
10512
10513For example, if stopped at the @code{printf} in this function:
10514
10515@smallexample
10516void
10517hello ()
10518@{
10519 static char hello[] = "hello-hello";
10520 static struct @{ char c; short s; int i; @}
10521 __attribute__ ((packed)) mixed
10522 = @{ 'c', 0x1234, 0x87654321 @};
10523 printf ("%s\n", hello);
10524@}
10525@end smallexample
10526
10527@noindent
10528you get during debugging:
10529
10530@smallexample
10531(gdb) find &hello[0], +sizeof(hello), "hello"
105320x804956d <hello.1620+6>
105331 pattern found
10534(gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
105350x8049567 <hello.1620>
105360x804956d <hello.1620+6>
105372 patterns found
10538(gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
105390x8049567 <hello.1620>
105401 pattern found
10541(gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
105420x8049560 <mixed.1625>
105431 pattern found
10544(gdb) print $numfound
10545$1 = 1
10546(gdb) print $_
10547$2 = (void *) 0x8049560
10548@end smallexample
a0eb71c5 10549
edb3359d
DJ
10550@node Optimized Code
10551@chapter Debugging Optimized Code
10552@cindex optimized code, debugging
10553@cindex debugging optimized code
10554
10555Almost all compilers support optimization. With optimization
10556disabled, the compiler generates assembly code that corresponds
10557directly to your source code, in a simplistic way. As the compiler
10558applies more powerful optimizations, the generated assembly code
10559diverges from your original source code. With help from debugging
10560information generated by the compiler, @value{GDBN} can map from
10561the running program back to constructs from your original source.
10562
10563@value{GDBN} is more accurate with optimization disabled. If you
10564can recompile without optimization, it is easier to follow the
10565progress of your program during debugging. But, there are many cases
10566where you may need to debug an optimized version.
10567
10568When you debug a program compiled with @samp{-g -O}, remember that the
10569optimizer has rearranged your code; the debugger shows you what is
10570really there. Do not be too surprised when the execution path does not
10571exactly match your source file! An extreme example: if you define a
10572variable, but never use it, @value{GDBN} never sees that
10573variable---because the compiler optimizes it out of existence.
10574
10575Some things do not work as well with @samp{-g -O} as with just
10576@samp{-g}, particularly on machines with instruction scheduling. If in
10577doubt, recompile with @samp{-g} alone, and if this fixes the problem,
10578please report it to us as a bug (including a test case!).
10579@xref{Variables}, for more information about debugging optimized code.
10580
10581@menu
10582* Inline Functions:: How @value{GDBN} presents inlining
111c6489 10583* Tail Call Frames:: @value{GDBN} analysis of jumps to functions
edb3359d
DJ
10584@end menu
10585
10586@node Inline Functions
10587@section Inline Functions
10588@cindex inline functions, debugging
10589
10590@dfn{Inlining} is an optimization that inserts a copy of the function
10591body directly at each call site, instead of jumping to a shared
10592routine. @value{GDBN} displays inlined functions just like
10593non-inlined functions. They appear in backtraces. You can view their
10594arguments and local variables, step into them with @code{step}, skip
10595them with @code{next}, and escape from them with @code{finish}.
10596You can check whether a function was inlined by using the
10597@code{info frame} command.
10598
10599For @value{GDBN} to support inlined functions, the compiler must
10600record information about inlining in the debug information ---
10601@value{NGCC} using the @sc{dwarf 2} format does this, and several
10602other compilers do also. @value{GDBN} only supports inlined functions
10603when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
10604do not emit two required attributes (@samp{DW_AT_call_file} and
10605@samp{DW_AT_call_line}); @value{GDBN} does not display inlined
10606function calls with earlier versions of @value{NGCC}. It instead
10607displays the arguments and local variables of inlined functions as
10608local variables in the caller.
10609
10610The body of an inlined function is directly included at its call site;
10611unlike a non-inlined function, there are no instructions devoted to
10612the call. @value{GDBN} still pretends that the call site and the
10613start of the inlined function are different instructions. Stepping to
10614the call site shows the call site, and then stepping again shows
10615the first line of the inlined function, even though no additional
10616instructions are executed.
10617
10618This makes source-level debugging much clearer; you can see both the
10619context of the call and then the effect of the call. Only stepping by
10620a single instruction using @code{stepi} or @code{nexti} does not do
10621this; single instruction steps always show the inlined body.
10622
10623There are some ways that @value{GDBN} does not pretend that inlined
10624function calls are the same as normal calls:
10625
10626@itemize @bullet
edb3359d
DJ
10627@item
10628Setting breakpoints at the call site of an inlined function may not
10629work, because the call site does not contain any code. @value{GDBN}
10630may incorrectly move the breakpoint to the next line of the enclosing
10631function, after the call. This limitation will be removed in a future
10632version of @value{GDBN}; until then, set a breakpoint on an earlier line
10633or inside the inlined function instead.
10634
10635@item
10636@value{GDBN} cannot locate the return value of inlined calls after
10637using the @code{finish} command. This is a limitation of compiler-generated
10638debugging information; after @code{finish}, you can step to the next line
10639and print a variable where your program stored the return value.
10640
10641@end itemize
10642
111c6489
JK
10643@node Tail Call Frames
10644@section Tail Call Frames
10645@cindex tail call frames, debugging
10646
10647Function @code{B} can call function @code{C} in its very last statement. In
10648unoptimized compilation the call of @code{C} is immediately followed by return
10649instruction at the end of @code{B} code. Optimizing compiler may replace the
10650call and return in function @code{B} into one jump to function @code{C}
10651instead. Such use of a jump instruction is called @dfn{tail call}.
10652
10653During execution of function @code{C}, there will be no indication in the
10654function call stack frames that it was tail-called from @code{B}. If function
10655@code{A} regularly calls function @code{B} which tail-calls function @code{C},
10656then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
10657some cases @value{GDBN} can determine that @code{C} was tail-called from
10658@code{B}, and it will then create fictitious call frame for that, with the
10659return address set up as if @code{B} called @code{C} normally.
10660
10661This functionality is currently supported only by DWARF 2 debugging format and
10662the compiler has to produce @samp{DW_TAG_GNU_call_site} tags. With
10663@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
10664this information.
10665
10666@kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
10667kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
10668
10669@smallexample
10670(gdb) x/i $pc - 2
10671 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
10672(gdb) info frame
10673Stack level 1, frame at 0x7fffffffda30:
10674 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
10675 tail call frame, caller of frame at 0x7fffffffda30
10676 source language c++.
10677 Arglist at unknown address.
10678 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
10679@end smallexample
10680
10681The detection of all the possible code path executions can find them ambiguous.
10682There is no execution history stored (possible @ref{Reverse Execution} is never
10683used for this purpose) and the last known caller could have reached the known
10684callee by multiple different jump sequences. In such case @value{GDBN} still
10685tries to show at least all the unambiguous top tail callers and all the
10686unambiguous bottom tail calees, if any.
10687
10688@table @code
e18b2753 10689@anchor{set debug entry-values}
111c6489
JK
10690@item set debug entry-values
10691@kindex set debug entry-values
10692When set to on, enables printing of analysis messages for both frame argument
10693values at function entry and tail calls. It will show all the possible valid
10694tail calls code paths it has considered. It will also print the intersection
10695of them with the final unambiguous (possibly partial or even empty) code path
10696result.
10697
10698@item show debug entry-values
10699@kindex show debug entry-values
10700Show the current state of analysis messages printing for both frame argument
10701values at function entry and tail calls.
10702@end table
10703
10704The analysis messages for tail calls can for example show why the virtual tail
10705call frame for function @code{c} has not been recognized (due to the indirect
10706reference by variable @code{x}):
10707
10708@smallexample
10709static void __attribute__((noinline, noclone)) c (void);
10710void (*x) (void) = c;
10711static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
10712static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
10713int main (void) @{ x (); return 0; @}
10714
10715Breakpoint 1, DW_OP_GNU_entry_value resolving cannot find
10716DW_TAG_GNU_call_site 0x40039a in main
10717a () at t.c:3
107183 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
10719(gdb) bt
10720#0 a () at t.c:3
10721#1 0x000000000040039a in main () at t.c:5
10722@end smallexample
10723
10724Another possibility is an ambiguous virtual tail call frames resolution:
10725
10726@smallexample
10727int i;
10728static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
10729static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
10730static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
10731static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
10732static void __attribute__((noinline, noclone)) b (void)
10733@{ if (i) c (); else e (); @}
10734static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
10735int main (void) @{ a (); return 0; @}
10736
10737tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
10738tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
10739tailcall: reduced: 0x4004d2(a) |
10740(gdb) bt
10741#0 f () at t.c:2
10742#1 0x00000000004004d2 in a () at t.c:8
10743#2 0x0000000000400395 in main () at t.c:9
10744@end smallexample
10745
5048e516
JK
10746@set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
10747@set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
10748
10749@c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
10750@ifset HAVE_MAKEINFO_CLICK
10751@set ARROW @click{}
10752@set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
10753@set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
10754@end ifset
10755@ifclear HAVE_MAKEINFO_CLICK
10756@set ARROW ->
10757@set CALLSEQ1B @value{CALLSEQ1A}
10758@set CALLSEQ2B @value{CALLSEQ2A}
10759@end ifclear
10760
10761Frames #0 and #2 are real, #1 is a virtual tail call frame.
10762The code can have possible execution paths @value{CALLSEQ1B} or
10763@value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
111c6489
JK
10764
10765@code{initial:} state shows some random possible calling sequence @value{GDBN}
10766has found. It then finds another possible calling sequcen - that one is
10767prefixed by @code{compare:}. The non-ambiguous intersection of these two is
10768printed as the @code{reduced:} calling sequence. That one could have many
10769futher @code{compare:} and @code{reduced:} statements as long as there remain
10770any non-ambiguous sequence entries.
10771
10772For the frame of function @code{b} in both cases there are different possible
10773@code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
10774also ambigous. The only non-ambiguous frame is the one for function @code{a},
10775therefore this one is displayed to the user while the ambiguous frames are
10776omitted.
edb3359d 10777
e18b2753
JK
10778There can be also reasons why printing of frame argument values at function
10779entry may fail:
10780
10781@smallexample
10782int v;
10783static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
10784static void __attribute__((noinline, noclone)) a (int i);
10785static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
10786static void __attribute__((noinline, noclone)) a (int i)
10787@{ if (i) b (i - 1); else c (0); @}
10788int main (void) @{ a (5); return 0; @}
10789
10790(gdb) bt
10791#0 c (i=i@@entry=0) at t.c:2
10792#1 0x0000000000400428 in a (DW_OP_GNU_entry_value resolving has found
10793function "a" at 0x400420 can call itself via tail calls
10794i=<optimized out>) at t.c:6
10795#2 0x000000000040036e in main () at t.c:7
10796@end smallexample
10797
10798@value{GDBN} cannot find out from the inferior state if and how many times did
10799function @code{a} call itself (via function @code{b}) as these calls would be
10800tail calls. Such tail calls would modify thue @code{i} variable, therefore
10801@value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
10802prints @code{<optimized out>} instead.
10803
e2e0bcd1
JB
10804@node Macros
10805@chapter C Preprocessor Macros
10806
49efadf5 10807Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
10808``preprocessor macros'' which expand into strings of tokens.
10809@value{GDBN} can evaluate expressions containing macro invocations, show
10810the result of macro expansion, and show a macro's definition, including
10811where it was defined.
10812
10813You may need to compile your program specially to provide @value{GDBN}
10814with information about preprocessor macros. Most compilers do not
10815include macros in their debugging information, even when you compile
10816with the @option{-g} flag. @xref{Compilation}.
10817
10818A program may define a macro at one point, remove that definition later,
10819and then provide a different definition after that. Thus, at different
10820points in the program, a macro may have different definitions, or have
10821no definition at all. If there is a current stack frame, @value{GDBN}
10822uses the macros in scope at that frame's source code line. Otherwise,
10823@value{GDBN} uses the macros in scope at the current listing location;
10824see @ref{List}.
10825
e2e0bcd1
JB
10826Whenever @value{GDBN} evaluates an expression, it always expands any
10827macro invocations present in the expression. @value{GDBN} also provides
10828the following commands for working with macros explicitly.
10829
10830@table @code
10831
10832@kindex macro expand
10833@cindex macro expansion, showing the results of preprocessor
10834@cindex preprocessor macro expansion, showing the results of
10835@cindex expanding preprocessor macros
10836@item macro expand @var{expression}
10837@itemx macro exp @var{expression}
10838Show the results of expanding all preprocessor macro invocations in
10839@var{expression}. Since @value{GDBN} simply expands macros, but does
10840not parse the result, @var{expression} need not be a valid expression;
10841it can be any string of tokens.
10842
09d4efe1 10843@kindex macro exp1
e2e0bcd1
JB
10844@item macro expand-once @var{expression}
10845@itemx macro exp1 @var{expression}
4644b6e3 10846@cindex expand macro once
e2e0bcd1
JB
10847@i{(This command is not yet implemented.)} Show the results of
10848expanding those preprocessor macro invocations that appear explicitly in
10849@var{expression}. Macro invocations appearing in that expansion are
10850left unchanged. This command allows you to see the effect of a
10851particular macro more clearly, without being confused by further
10852expansions. Since @value{GDBN} simply expands macros, but does not
10853parse the result, @var{expression} need not be a valid expression; it
10854can be any string of tokens.
10855
475b0867 10856@kindex info macro
e2e0bcd1 10857@cindex macro definition, showing
9b158ba0 10858@cindex definition of a macro, showing
10859@cindex macros, from debug info
71eba9c2 10860@item info macro [-a|-all] [--] @var{macro}
10861Show the current definition or all definitions of the named @var{macro},
10862and describe the source location or compiler command-line where that
10863definition was established. The optional double dash is to signify the end of
10864argument processing and the beginning of @var{macro} for non C-like macros where
10865the macro may begin with a hyphen.
e2e0bcd1 10866
9b158ba0 10867@kindex info macros
10868@item info macros @var{linespec}
10869Show all macro definitions that are in effect at the location specified
10870by @var{linespec}, and describe the source location or compiler
10871command-line where those definitions were established.
10872
e2e0bcd1
JB
10873@kindex macro define
10874@cindex user-defined macros
10875@cindex defining macros interactively
10876@cindex macros, user-defined
10877@item macro define @var{macro} @var{replacement-list}
10878@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
d7d9f01e
TT
10879Introduce a definition for a preprocessor macro named @var{macro},
10880invocations of which are replaced by the tokens given in
10881@var{replacement-list}. The first form of this command defines an
10882``object-like'' macro, which takes no arguments; the second form
10883defines a ``function-like'' macro, which takes the arguments given in
10884@var{arglist}.
10885
10886A definition introduced by this command is in scope in every
10887expression evaluated in @value{GDBN}, until it is removed with the
10888@code{macro undef} command, described below. The definition overrides
10889all definitions for @var{macro} present in the program being debugged,
10890as well as any previous user-supplied definition.
e2e0bcd1
JB
10891
10892@kindex macro undef
10893@item macro undef @var{macro}
d7d9f01e
TT
10894Remove any user-supplied definition for the macro named @var{macro}.
10895This command only affects definitions provided with the @code{macro
10896define} command, described above; it cannot remove definitions present
10897in the program being debugged.
e2e0bcd1 10898
09d4efe1
EZ
10899@kindex macro list
10900@item macro list
d7d9f01e 10901List all the macros defined using the @code{macro define} command.
e2e0bcd1
JB
10902@end table
10903
10904@cindex macros, example of debugging with
10905Here is a transcript showing the above commands in action. First, we
10906show our source files:
10907
10908@smallexample
10909$ cat sample.c
10910#include <stdio.h>
10911#include "sample.h"
10912
10913#define M 42
10914#define ADD(x) (M + x)
10915
10916main ()
10917@{
10918#define N 28
10919 printf ("Hello, world!\n");
10920#undef N
10921 printf ("We're so creative.\n");
10922#define N 1729
10923 printf ("Goodbye, world!\n");
10924@}
10925$ cat sample.h
10926#define Q <
10927$
10928@end smallexample
10929
e0f8f636
TT
10930Now, we compile the program using the @sc{gnu} C compiler,
10931@value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
10932minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
10933and @option{-gdwarf-4}; we recommend always choosing the most recent
10934version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
10935includes information about preprocessor macros in the debugging
e2e0bcd1
JB
10936information.
10937
10938@smallexample
10939$ gcc -gdwarf-2 -g3 sample.c -o sample
10940$
10941@end smallexample
10942
10943Now, we start @value{GDBN} on our sample program:
10944
10945@smallexample
10946$ gdb -nw sample
10947GNU gdb 2002-05-06-cvs
10948Copyright 2002 Free Software Foundation, Inc.
10949GDB is free software, @dots{}
f7dc1244 10950(@value{GDBP})
e2e0bcd1
JB
10951@end smallexample
10952
10953We can expand macros and examine their definitions, even when the
10954program is not running. @value{GDBN} uses the current listing position
10955to decide which macro definitions are in scope:
10956
10957@smallexample
f7dc1244 10958(@value{GDBP}) list main
e2e0bcd1
JB
109593
109604 #define M 42
109615 #define ADD(x) (M + x)
109626
109637 main ()
109648 @{
109659 #define N 28
1096610 printf ("Hello, world!\n");
1096711 #undef N
1096812 printf ("We're so creative.\n");
f7dc1244 10969(@value{GDBP}) info macro ADD
e2e0bcd1
JB
10970Defined at /home/jimb/gdb/macros/play/sample.c:5
10971#define ADD(x) (M + x)
f7dc1244 10972(@value{GDBP}) info macro Q
e2e0bcd1
JB
10973Defined at /home/jimb/gdb/macros/play/sample.h:1
10974 included at /home/jimb/gdb/macros/play/sample.c:2
10975#define Q <
f7dc1244 10976(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 10977expands to: (42 + 1)
f7dc1244 10978(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 10979expands to: once (M + 1)
f7dc1244 10980(@value{GDBP})
e2e0bcd1
JB
10981@end smallexample
10982
d7d9f01e 10983In the example above, note that @code{macro expand-once} expands only
e2e0bcd1
JB
10984the macro invocation explicit in the original text --- the invocation of
10985@code{ADD} --- but does not expand the invocation of the macro @code{M},
10986which was introduced by @code{ADD}.
10987
3f94c067
BW
10988Once the program is running, @value{GDBN} uses the macro definitions in
10989force at the source line of the current stack frame:
e2e0bcd1
JB
10990
10991@smallexample
f7dc1244 10992(@value{GDBP}) break main
e2e0bcd1 10993Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 10994(@value{GDBP}) run
b383017d 10995Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
10996
10997Breakpoint 1, main () at sample.c:10
1099810 printf ("Hello, world!\n");
f7dc1244 10999(@value{GDBP})
e2e0bcd1
JB
11000@end smallexample
11001
11002At line 10, the definition of the macro @code{N} at line 9 is in force:
11003
11004@smallexample
f7dc1244 11005(@value{GDBP}) info macro N
e2e0bcd1
JB
11006Defined at /home/jimb/gdb/macros/play/sample.c:9
11007#define N 28
f7dc1244 11008(@value{GDBP}) macro expand N Q M
e2e0bcd1 11009expands to: 28 < 42
f7dc1244 11010(@value{GDBP}) print N Q M
e2e0bcd1 11011$1 = 1
f7dc1244 11012(@value{GDBP})
e2e0bcd1
JB
11013@end smallexample
11014
11015As we step over directives that remove @code{N}'s definition, and then
11016give it a new definition, @value{GDBN} finds the definition (or lack
11017thereof) in force at each point:
11018
11019@smallexample
f7dc1244 11020(@value{GDBP}) next
e2e0bcd1
JB
11021Hello, world!
1102212 printf ("We're so creative.\n");
f7dc1244 11023(@value{GDBP}) info macro N
e2e0bcd1
JB
11024The symbol `N' has no definition as a C/C++ preprocessor macro
11025at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 11026(@value{GDBP}) next
e2e0bcd1
JB
11027We're so creative.
1102814 printf ("Goodbye, world!\n");
f7dc1244 11029(@value{GDBP}) info macro N
e2e0bcd1
JB
11030Defined at /home/jimb/gdb/macros/play/sample.c:13
11031#define N 1729
f7dc1244 11032(@value{GDBP}) macro expand N Q M
e2e0bcd1 11033expands to: 1729 < 42
f7dc1244 11034(@value{GDBP}) print N Q M
e2e0bcd1 11035$2 = 0
f7dc1244 11036(@value{GDBP})
e2e0bcd1
JB
11037@end smallexample
11038
484086b7
JK
11039In addition to source files, macros can be defined on the compilation command
11040line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
11041such a way, @value{GDBN} displays the location of their definition as line zero
11042of the source file submitted to the compiler.
11043
11044@smallexample
11045(@value{GDBP}) info macro __STDC__
11046Defined at /home/jimb/gdb/macros/play/sample.c:0
11047-D__STDC__=1
11048(@value{GDBP})
11049@end smallexample
11050
e2e0bcd1 11051
b37052ae
EZ
11052@node Tracepoints
11053@chapter Tracepoints
11054@c This chapter is based on the documentation written by Michael
11055@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
11056
11057@cindex tracepoints
11058In some applications, it is not feasible for the debugger to interrupt
11059the program's execution long enough for the developer to learn
11060anything helpful about its behavior. If the program's correctness
11061depends on its real-time behavior, delays introduced by a debugger
11062might cause the program to change its behavior drastically, or perhaps
11063fail, even when the code itself is correct. It is useful to be able
11064to observe the program's behavior without interrupting it.
11065
11066Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
11067specify locations in the program, called @dfn{tracepoints}, and
11068arbitrary expressions to evaluate when those tracepoints are reached.
11069Later, using the @code{tfind} command, you can examine the values
11070those expressions had when the program hit the tracepoints. The
11071expressions may also denote objects in memory---structures or arrays,
11072for example---whose values @value{GDBN} should record; while visiting
11073a particular tracepoint, you may inspect those objects as if they were
11074in memory at that moment. However, because @value{GDBN} records these
11075values without interacting with you, it can do so quickly and
11076unobtrusively, hopefully not disturbing the program's behavior.
11077
11078The tracepoint facility is currently available only for remote
9d29849a
JB
11079targets. @xref{Targets}. In addition, your remote target must know
11080how to collect trace data. This functionality is implemented in the
11081remote stub; however, none of the stubs distributed with @value{GDBN}
11082support tracepoints as of this writing. The format of the remote
11083packets used to implement tracepoints are described in @ref{Tracepoint
11084Packets}.
b37052ae 11085
00bf0b85
SS
11086It is also possible to get trace data from a file, in a manner reminiscent
11087of corefiles; you specify the filename, and use @code{tfind} to search
11088through the file. @xref{Trace Files}, for more details.
11089
b37052ae
EZ
11090This chapter describes the tracepoint commands and features.
11091
11092@menu
b383017d
RM
11093* Set Tracepoints::
11094* Analyze Collected Data::
11095* Tracepoint Variables::
00bf0b85 11096* Trace Files::
b37052ae
EZ
11097@end menu
11098
11099@node Set Tracepoints
11100@section Commands to Set Tracepoints
11101
11102Before running such a @dfn{trace experiment}, an arbitrary number of
1042e4c0
SS
11103tracepoints can be set. A tracepoint is actually a special type of
11104breakpoint (@pxref{Set Breaks}), so you can manipulate it using
11105standard breakpoint commands. For instance, as with breakpoints,
11106tracepoint numbers are successive integers starting from one, and many
11107of the commands associated with tracepoints take the tracepoint number
11108as their argument, to identify which tracepoint to work on.
b37052ae
EZ
11109
11110For each tracepoint, you can specify, in advance, some arbitrary set
11111of data that you want the target to collect in the trace buffer when
11112it hits that tracepoint. The collected data can include registers,
11113local variables, or global data. Later, you can use @value{GDBN}
11114commands to examine the values these data had at the time the
11115tracepoint was hit.
11116
7d13fe92
SS
11117Tracepoints do not support every breakpoint feature. Ignore counts on
11118tracepoints have no effect, and tracepoints cannot run @value{GDBN}
11119commands when they are hit. Tracepoints may not be thread-specific
11120either.
1042e4c0 11121
7a697b8d
SS
11122@cindex fast tracepoints
11123Some targets may support @dfn{fast tracepoints}, which are inserted in
11124a different way (such as with a jump instead of a trap), that is
11125faster but possibly restricted in where they may be installed.
11126
0fb4aa4b
PA
11127@cindex static tracepoints
11128@cindex markers, static tracepoints
11129@cindex probing markers, static tracepoints
11130Regular and fast tracepoints are dynamic tracing facilities, meaning
11131that they can be used to insert tracepoints at (almost) any location
11132in the target. Some targets may also support controlling @dfn{static
11133tracepoints} from @value{GDBN}. With static tracing, a set of
11134instrumentation points, also known as @dfn{markers}, are embedded in
11135the target program, and can be activated or deactivated by name or
11136address. These are usually placed at locations which facilitate
11137investigating what the target is actually doing. @value{GDBN}'s
11138support for static tracing includes being able to list instrumentation
11139points, and attach them with @value{GDBN} defined high level
11140tracepoints that expose the whole range of convenience of
8786b2bd 11141@value{GDBN}'s tracepoints support. Namely, support for collecting
0fb4aa4b
PA
11142registers values and values of global or local (to the instrumentation
11143point) variables; tracepoint conditions and trace state variables.
11144The act of installing a @value{GDBN} static tracepoint on an
11145instrumentation point, or marker, is referred to as @dfn{probing} a
11146static tracepoint marker.
11147
fa593d66
PA
11148@code{gdbserver} supports tracepoints on some target systems.
11149@xref{Server,,Tracepoints support in @code{gdbserver}}.
11150
b37052ae
EZ
11151This section describes commands to set tracepoints and associated
11152conditions and actions.
11153
11154@menu
b383017d
RM
11155* Create and Delete Tracepoints::
11156* Enable and Disable Tracepoints::
11157* Tracepoint Passcounts::
782b2b07 11158* Tracepoint Conditions::
f61e138d 11159* Trace State Variables::
b383017d
RM
11160* Tracepoint Actions::
11161* Listing Tracepoints::
0fb4aa4b 11162* Listing Static Tracepoint Markers::
79a6e687 11163* Starting and Stopping Trace Experiments::
c9429232 11164* Tracepoint Restrictions::
b37052ae
EZ
11165@end menu
11166
11167@node Create and Delete Tracepoints
11168@subsection Create and Delete Tracepoints
11169
11170@table @code
11171@cindex set tracepoint
11172@kindex trace
1042e4c0 11173@item trace @var{location}
b37052ae 11174The @code{trace} command is very similar to the @code{break} command.
1042e4c0
SS
11175Its argument @var{location} can be a source line, a function name, or
11176an address in the target program. @xref{Specify Location}. The
11177@code{trace} command defines a tracepoint, which is a point in the
11178target program where the debugger will briefly stop, collect some
11179data, and then allow the program to continue. Setting a tracepoint or
1e4d1764
YQ
11180changing its actions takes effect immediately if the remote stub
11181supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
11182in tracing}).
11183If remote stub doesn't support the @samp{InstallInTrace} feature, all
11184these changes don't take effect until the next @code{tstart}
1042e4c0 11185command, and once a trace experiment is running, further changes will
bfccc43c
YQ
11186not have any effect until the next trace experiment starts. In addition,
11187@value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
11188address is not yet resolved. (This is similar to pending breakpoints.)
11189Pending tracepoints are not downloaded to the target and not installed
11190until they are resolved. The resolution of pending tracepoints requires
11191@value{GDBN} support---when debugging with the remote target, and
11192@value{GDBN} disconnects from the remote stub (@pxref{disconnected
11193tracing}), pending tracepoints can not be resolved (and downloaded to
11194the remote stub) while @value{GDBN} is disconnected.
b37052ae
EZ
11195
11196Here are some examples of using the @code{trace} command:
11197
11198@smallexample
11199(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
11200
11201(@value{GDBP}) @b{trace +2} // 2 lines forward
11202
11203(@value{GDBP}) @b{trace my_function} // first source line of function
11204
11205(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
11206
11207(@value{GDBP}) @b{trace *0x2117c4} // an address
11208@end smallexample
11209
11210@noindent
11211You can abbreviate @code{trace} as @code{tr}.
11212
782b2b07
SS
11213@item trace @var{location} if @var{cond}
11214Set a tracepoint with condition @var{cond}; evaluate the expression
11215@var{cond} each time the tracepoint is reached, and collect data only
11216if the value is nonzero---that is, if @var{cond} evaluates as true.
11217@xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
11218information on tracepoint conditions.
11219
7a697b8d
SS
11220@item ftrace @var{location} [ if @var{cond} ]
11221@cindex set fast tracepoint
74c761c1 11222@cindex fast tracepoints, setting
7a697b8d
SS
11223@kindex ftrace
11224The @code{ftrace} command sets a fast tracepoint. For targets that
11225support them, fast tracepoints will use a more efficient but possibly
11226less general technique to trigger data collection, such as a jump
11227instruction instead of a trap, or some sort of hardware support. It
11228may not be possible to create a fast tracepoint at the desired
11229location, in which case the command will exit with an explanatory
11230message.
11231
11232@value{GDBN} handles arguments to @code{ftrace} exactly as for
11233@code{trace}.
11234
405f8e94
SS
11235On 32-bit x86-architecture systems, fast tracepoints normally need to
11236be placed at an instruction that is 5 bytes or longer, but can be
11237placed at 4-byte instructions if the low 64K of memory of the target
11238program is available to install trampolines. Some Unix-type systems,
11239such as @sc{gnu}/Linux, exclude low addresses from the program's
11240address space; but for instance with the Linux kernel it is possible
11241to let @value{GDBN} use this area by doing a @command{sysctl} command
11242to set the @code{mmap_min_addr} kernel parameter, as in
11243
11244@example
11245sudo sysctl -w vm.mmap_min_addr=32768
11246@end example
11247
11248@noindent
11249which sets the low address to 32K, which leaves plenty of room for
11250trampolines. The minimum address should be set to a page boundary.
11251
0fb4aa4b 11252@item strace @var{location} [ if @var{cond} ]
74c761c1
PA
11253@cindex set static tracepoint
11254@cindex static tracepoints, setting
11255@cindex probe static tracepoint marker
0fb4aa4b
PA
11256@kindex strace
11257The @code{strace} command sets a static tracepoint. For targets that
11258support it, setting a static tracepoint probes a static
11259instrumentation point, or marker, found at @var{location}. It may not
11260be possible to set a static tracepoint at the desired location, in
11261which case the command will exit with an explanatory message.
11262
11263@value{GDBN} handles arguments to @code{strace} exactly as for
11264@code{trace}, with the addition that the user can also specify
11265@code{-m @var{marker}} as @var{location}. This probes the marker
11266identified by the @var{marker} string identifier. This identifier
11267depends on the static tracepoint backend library your program is
11268using. You can find all the marker identifiers in the @samp{ID} field
11269of the @code{info static-tracepoint-markers} command output.
11270@xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
11271Markers}. For example, in the following small program using the UST
11272tracing engine:
11273
11274@smallexample
11275main ()
11276@{
11277 trace_mark(ust, bar33, "str %s", "FOOBAZ");
11278@}
11279@end smallexample
11280
11281@noindent
11282the marker id is composed of joining the first two arguments to the
11283@code{trace_mark} call with a slash, which translates to:
11284
11285@smallexample
11286(@value{GDBP}) info static-tracepoint-markers
11287Cnt Enb ID Address What
112881 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
11289 Data: "str %s"
11290[etc...]
11291@end smallexample
11292
11293@noindent
11294so you may probe the marker above with:
11295
11296@smallexample
11297(@value{GDBP}) strace -m ust/bar33
11298@end smallexample
11299
11300Static tracepoints accept an extra collect action --- @code{collect
11301$_sdata}. This collects arbitrary user data passed in the probe point
11302call to the tracing library. In the UST example above, you'll see
11303that the third argument to @code{trace_mark} is a printf-like format
11304string. The user data is then the result of running that formating
11305string against the following arguments. Note that @code{info
11306static-tracepoint-markers} command output lists that format string in
11307the @samp{Data:} field.
11308
11309You can inspect this data when analyzing the trace buffer, by printing
11310the $_sdata variable like any other variable available to
11311@value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
11312
b37052ae
EZ
11313@vindex $tpnum
11314@cindex last tracepoint number
11315@cindex recent tracepoint number
11316@cindex tracepoint number
11317The convenience variable @code{$tpnum} records the tracepoint number
11318of the most recently set tracepoint.
11319
11320@kindex delete tracepoint
11321@cindex tracepoint deletion
11322@item delete tracepoint @r{[}@var{num}@r{]}
11323Permanently delete one or more tracepoints. With no argument, the
1042e4c0
SS
11324default is to delete all tracepoints. Note that the regular
11325@code{delete} command can remove tracepoints also.
b37052ae
EZ
11326
11327Examples:
11328
11329@smallexample
11330(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
11331
11332(@value{GDBP}) @b{delete trace} // remove all tracepoints
11333@end smallexample
11334
11335@noindent
11336You can abbreviate this command as @code{del tr}.
11337@end table
11338
11339@node Enable and Disable Tracepoints
11340@subsection Enable and Disable Tracepoints
11341
1042e4c0
SS
11342These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
11343
b37052ae
EZ
11344@table @code
11345@kindex disable tracepoint
11346@item disable tracepoint @r{[}@var{num}@r{]}
11347Disable tracepoint @var{num}, or all tracepoints if no argument
11348@var{num} is given. A disabled tracepoint will have no effect during
d248b706 11349a trace experiment, but it is not forgotten. You can re-enable
b37052ae 11350a disabled tracepoint using the @code{enable tracepoint} command.
d248b706
KY
11351If the command is issued during a trace experiment and the debug target
11352has support for disabling tracepoints during a trace experiment, then the
11353change will be effective immediately. Otherwise, it will be applied to the
11354next trace experiment.
b37052ae
EZ
11355
11356@kindex enable tracepoint
11357@item enable tracepoint @r{[}@var{num}@r{]}
d248b706
KY
11358Enable tracepoint @var{num}, or all tracepoints. If this command is
11359issued during a trace experiment and the debug target supports enabling
11360tracepoints during a trace experiment, then the enabled tracepoints will
11361become effective immediately. Otherwise, they will become effective the
11362next time a trace experiment is run.
b37052ae
EZ
11363@end table
11364
11365@node Tracepoint Passcounts
11366@subsection Tracepoint Passcounts
11367
11368@table @code
11369@kindex passcount
11370@cindex tracepoint pass count
11371@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
11372Set the @dfn{passcount} of a tracepoint. The passcount is a way to
11373automatically stop a trace experiment. If a tracepoint's passcount is
11374@var{n}, then the trace experiment will be automatically stopped on
11375the @var{n}'th time that tracepoint is hit. If the tracepoint number
11376@var{num} is not specified, the @code{passcount} command sets the
11377passcount of the most recently defined tracepoint. If no passcount is
11378given, the trace experiment will run until stopped explicitly by the
11379user.
11380
11381Examples:
11382
11383@smallexample
b383017d 11384(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 11385@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
11386
11387(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 11388@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
11389(@value{GDBP}) @b{trace foo}
11390(@value{GDBP}) @b{pass 3}
11391(@value{GDBP}) @b{trace bar}
11392(@value{GDBP}) @b{pass 2}
11393(@value{GDBP}) @b{trace baz}
11394(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
11395@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
11396@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
11397@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
11398@end smallexample
11399@end table
11400
782b2b07
SS
11401@node Tracepoint Conditions
11402@subsection Tracepoint Conditions
11403@cindex conditional tracepoints
11404@cindex tracepoint conditions
11405
11406The simplest sort of tracepoint collects data every time your program
11407reaches a specified place. You can also specify a @dfn{condition} for
11408a tracepoint. A condition is just a Boolean expression in your
11409programming language (@pxref{Expressions, ,Expressions}). A
11410tracepoint with a condition evaluates the expression each time your
11411program reaches it, and data collection happens only if the condition
11412is true.
11413
11414Tracepoint conditions can be specified when a tracepoint is set, by
11415using @samp{if} in the arguments to the @code{trace} command.
11416@xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
11417also be set or changed at any time with the @code{condition} command,
11418just as with breakpoints.
11419
11420Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
11421the conditional expression itself. Instead, @value{GDBN} encodes the
6dcd5565 11422expression into an agent expression (@pxref{Agent Expressions})
782b2b07
SS
11423suitable for execution on the target, independently of @value{GDBN}.
11424Global variables become raw memory locations, locals become stack
11425accesses, and so forth.
11426
11427For instance, suppose you have a function that is usually called
11428frequently, but should not be called after an error has occurred. You
11429could use the following tracepoint command to collect data about calls
11430of that function that happen while the error code is propagating
11431through the program; an unconditional tracepoint could end up
11432collecting thousands of useless trace frames that you would have to
11433search through.
11434
11435@smallexample
11436(@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
11437@end smallexample
11438
f61e138d
SS
11439@node Trace State Variables
11440@subsection Trace State Variables
11441@cindex trace state variables
11442
11443A @dfn{trace state variable} is a special type of variable that is
11444created and managed by target-side code. The syntax is the same as
11445that for GDB's convenience variables (a string prefixed with ``$''),
11446but they are stored on the target. They must be created explicitly,
11447using a @code{tvariable} command. They are always 64-bit signed
11448integers.
11449
11450Trace state variables are remembered by @value{GDBN}, and downloaded
11451to the target along with tracepoint information when the trace
11452experiment starts. There are no intrinsic limits on the number of
11453trace state variables, beyond memory limitations of the target.
11454
11455@cindex convenience variables, and trace state variables
11456Although trace state variables are managed by the target, you can use
11457them in print commands and expressions as if they were convenience
11458variables; @value{GDBN} will get the current value from the target
11459while the trace experiment is running. Trace state variables share
11460the same namespace as other ``$'' variables, which means that you
11461cannot have trace state variables with names like @code{$23} or
11462@code{$pc}, nor can you have a trace state variable and a convenience
11463variable with the same name.
11464
11465@table @code
11466
11467@item tvariable $@var{name} [ = @var{expression} ]
11468@kindex tvariable
11469The @code{tvariable} command creates a new trace state variable named
11470@code{$@var{name}}, and optionally gives it an initial value of
11471@var{expression}. @var{expression} is evaluated when this command is
11472entered; the result will be converted to an integer if possible,
11473otherwise @value{GDBN} will report an error. A subsequent
11474@code{tvariable} command specifying the same name does not create a
11475variable, but instead assigns the supplied initial value to the
11476existing variable of that name, overwriting any previous initial
11477value. The default initial value is 0.
11478
11479@item info tvariables
11480@kindex info tvariables
11481List all the trace state variables along with their initial values.
11482Their current values may also be displayed, if the trace experiment is
11483currently running.
11484
11485@item delete tvariable @r{[} $@var{name} @dots{} @r{]}
11486@kindex delete tvariable
11487Delete the given trace state variables, or all of them if no arguments
11488are specified.
11489
11490@end table
11491
b37052ae
EZ
11492@node Tracepoint Actions
11493@subsection Tracepoint Action Lists
11494
11495@table @code
11496@kindex actions
11497@cindex tracepoint actions
11498@item actions @r{[}@var{num}@r{]}
11499This command will prompt for a list of actions to be taken when the
11500tracepoint is hit. If the tracepoint number @var{num} is not
11501specified, this command sets the actions for the one that was most
11502recently defined (so that you can define a tracepoint and then say
11503@code{actions} without bothering about its number). You specify the
11504actions themselves on the following lines, one action at a time, and
11505terminate the actions list with a line containing just @code{end}. So
7d13fe92 11506far, the only defined actions are @code{collect}, @code{teval}, and
b37052ae
EZ
11507@code{while-stepping}.
11508
5a9351ae
SS
11509@code{actions} is actually equivalent to @code{commands} (@pxref{Break
11510Commands, ,Breakpoint Command Lists}), except that only the defined
11511actions are allowed; any other @value{GDBN} command is rejected.
11512
b37052ae
EZ
11513@cindex remove actions from a tracepoint
11514To remove all actions from a tracepoint, type @samp{actions @var{num}}
11515and follow it immediately with @samp{end}.
11516
11517@smallexample
11518(@value{GDBP}) @b{collect @var{data}} // collect some data
11519
6826cf00 11520(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 11521
6826cf00 11522(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
11523@end smallexample
11524
11525In the following example, the action list begins with @code{collect}
11526commands indicating the things to be collected when the tracepoint is
11527hit. Then, in order to single-step and collect additional data
11528following the tracepoint, a @code{while-stepping} command is used,
7d13fe92
SS
11529followed by the list of things to be collected after each step in a
11530sequence of single steps. The @code{while-stepping} command is
11531terminated by its own separate @code{end} command. Lastly, the action
11532list is terminated by an @code{end} command.
b37052ae
EZ
11533
11534@smallexample
11535(@value{GDBP}) @b{trace foo}
11536(@value{GDBP}) @b{actions}
11537Enter actions for tracepoint 1, one per line:
11538> collect bar,baz
11539> collect $regs
11540> while-stepping 12
5a9351ae 11541 > collect $pc, arr[i]
b37052ae
EZ
11542 > end
11543end
11544@end smallexample
11545
11546@kindex collect @r{(tracepoints)}
3065dfb6 11547@item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
b37052ae
EZ
11548Collect values of the given expressions when the tracepoint is hit.
11549This command accepts a comma-separated list of any valid expressions.
11550In addition to global, static, or local variables, the following
11551special arguments are supported:
11552
11553@table @code
11554@item $regs
0fb4aa4b 11555Collect all registers.
b37052ae
EZ
11556
11557@item $args
0fb4aa4b 11558Collect all function arguments.
b37052ae
EZ
11559
11560@item $locals
0fb4aa4b
PA
11561Collect all local variables.
11562
6710bf39
SS
11563@item $_ret
11564Collect the return address. This is helpful if you want to see more
11565of a backtrace.
11566
62e5f89c
SDJ
11567@item $_probe_argc
11568Collects the number of arguments from the static probe at which the
11569tracepoint is located.
11570@xref{Static Probe Points}.
11571
11572@item $_probe_arg@var{n}
11573@var{n} is an integer between 0 and 11. Collects the @var{n}th argument
11574from the static probe at which the tracepoint is located.
11575@xref{Static Probe Points}.
11576
0fb4aa4b
PA
11577@item $_sdata
11578@vindex $_sdata@r{, collect}
11579Collect static tracepoint marker specific data. Only available for
11580static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
11581Lists}. On the UST static tracepoints library backend, an
11582instrumentation point resembles a @code{printf} function call. The
11583tracing library is able to collect user specified data formatted to a
11584character string using the format provided by the programmer that
11585instrumented the program. Other backends have similar mechanisms.
11586Here's an example of a UST marker call:
11587
11588@smallexample
11589 const char master_name[] = "$your_name";
11590 trace_mark(channel1, marker1, "hello %s", master_name)
11591@end smallexample
11592
11593In this case, collecting @code{$_sdata} collects the string
11594@samp{hello $yourname}. When analyzing the trace buffer, you can
11595inspect @samp{$_sdata} like any other variable available to
11596@value{GDBN}.
b37052ae
EZ
11597@end table
11598
11599You can give several consecutive @code{collect} commands, each one
11600with a single argument, or one @code{collect} command with several
5a9351ae 11601arguments separated by commas; the effect is the same.
b37052ae 11602
3065dfb6
SS
11603The optional @var{mods} changes the usual handling of the arguments.
11604@code{s} requests that pointers to chars be handled as strings, in
11605particular collecting the contents of the memory being pointed at, up
11606to the first zero. The upper bound is by default the value of the
11607@code{print elements} variable; if @code{s} is followed by a decimal
11608number, that is the upper bound instead. So for instance
11609@samp{collect/s25 mystr} collects as many as 25 characters at
11610@samp{mystr}.
11611
f5c37c66
EZ
11612The command @code{info scope} (@pxref{Symbols, info scope}) is
11613particularly useful for figuring out what data to collect.
11614
6da95a67
SS
11615@kindex teval @r{(tracepoints)}
11616@item teval @var{expr1}, @var{expr2}, @dots{}
11617Evaluate the given expressions when the tracepoint is hit. This
11618command accepts a comma-separated list of expressions. The results
11619are discarded, so this is mainly useful for assigning values to trace
11620state variables (@pxref{Trace State Variables}) without adding those
11621values to the trace buffer, as would be the case if the @code{collect}
11622action were used.
11623
b37052ae
EZ
11624@kindex while-stepping @r{(tracepoints)}
11625@item while-stepping @var{n}
c9429232 11626Perform @var{n} single-step instruction traces after the tracepoint,
7d13fe92 11627collecting new data after each step. The @code{while-stepping}
c9429232
SS
11628command is followed by the list of what to collect while stepping
11629(followed by its own @code{end} command):
b37052ae
EZ
11630
11631@smallexample
11632> while-stepping 12
11633 > collect $regs, myglobal
11634 > end
11635>
11636@end smallexample
11637
11638@noindent
7d13fe92
SS
11639Note that @code{$pc} is not automatically collected by
11640@code{while-stepping}; you need to explicitly collect that register if
11641you need it. You may abbreviate @code{while-stepping} as @code{ws} or
b37052ae 11642@code{stepping}.
236f1d4d
SS
11643
11644@item set default-collect @var{expr1}, @var{expr2}, @dots{}
11645@kindex set default-collect
11646@cindex default collection action
11647This variable is a list of expressions to collect at each tracepoint
11648hit. It is effectively an additional @code{collect} action prepended
11649to every tracepoint action list. The expressions are parsed
11650individually for each tracepoint, so for instance a variable named
11651@code{xyz} may be interpreted as a global for one tracepoint, and a
11652local for another, as appropriate to the tracepoint's location.
11653
11654@item show default-collect
11655@kindex show default-collect
11656Show the list of expressions that are collected by default at each
11657tracepoint hit.
11658
b37052ae
EZ
11659@end table
11660
11661@node Listing Tracepoints
11662@subsection Listing Tracepoints
11663
11664@table @code
e5a67952
MS
11665@kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
11666@kindex info tp @r{[}@var{n}@dots{}@r{]}
b37052ae 11667@cindex information about tracepoints
e5a67952 11668@item info tracepoints @r{[}@var{num}@dots{}@r{]}
1042e4c0
SS
11669Display information about the tracepoint @var{num}. If you don't
11670specify a tracepoint number, displays information about all the
11671tracepoints defined so far. The format is similar to that used for
11672@code{info breakpoints}; in fact, @code{info tracepoints} is the same
11673command, simply restricting itself to tracepoints.
11674
11675A tracepoint's listing may include additional information specific to
11676tracing:
b37052ae
EZ
11677
11678@itemize @bullet
11679@item
b37052ae 11680its passcount as given by the @code{passcount @var{n}} command
f2a8bc8a
YQ
11681
11682@item
11683the state about installed on target of each location
b37052ae
EZ
11684@end itemize
11685
11686@smallexample
11687(@value{GDBP}) @b{info trace}
1042e4c0
SS
11688Num Type Disp Enb Address What
116891 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
5a9351ae
SS
11690 while-stepping 20
11691 collect globfoo, $regs
11692 end
11693 collect globfoo2
11694 end
1042e4c0 11695 pass count 1200
f2a8bc8a
YQ
116962 tracepoint keep y <MULTIPLE>
11697 collect $eip
116982.1 y 0x0804859c in func4 at change-loc.h:35
11699 installed on target
117002.2 y 0xb7ffc480 in func4 at change-loc.h:35
11701 installed on target
117022.3 y <PENDING> set_tracepoint
117033 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
11704 not installed on target
b37052ae
EZ
11705(@value{GDBP})
11706@end smallexample
11707
11708@noindent
11709This command can be abbreviated @code{info tp}.
11710@end table
11711
0fb4aa4b
PA
11712@node Listing Static Tracepoint Markers
11713@subsection Listing Static Tracepoint Markers
11714
11715@table @code
11716@kindex info static-tracepoint-markers
11717@cindex information about static tracepoint markers
11718@item info static-tracepoint-markers
11719Display information about all static tracepoint markers defined in the
11720program.
11721
11722For each marker, the following columns are printed:
11723
11724@table @emph
11725@item Count
11726An incrementing counter, output to help readability. This is not a
11727stable identifier.
11728@item ID
11729The marker ID, as reported by the target.
11730@item Enabled or Disabled
11731Probed markers are tagged with @samp{y}. @samp{n} identifies marks
11732that are not enabled.
11733@item Address
11734Where the marker is in your program, as a memory address.
11735@item What
11736Where the marker is in the source for your program, as a file and line
11737number. If the debug information included in the program does not
11738allow @value{GDBN} to locate the source of the marker, this column
11739will be left blank.
11740@end table
11741
11742@noindent
11743In addition, the following information may be printed for each marker:
11744
11745@table @emph
11746@item Data
11747User data passed to the tracing library by the marker call. In the
11748UST backend, this is the format string passed as argument to the
11749marker call.
11750@item Static tracepoints probing the marker
11751The list of static tracepoints attached to the marker.
11752@end table
11753
11754@smallexample
11755(@value{GDBP}) info static-tracepoint-markers
11756Cnt ID Enb Address What
117571 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
11758 Data: number1 %d number2 %d
11759 Probed by static tracepoints: #2
117602 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
11761 Data: str %s
11762(@value{GDBP})
11763@end smallexample
11764@end table
11765
79a6e687
BW
11766@node Starting and Stopping Trace Experiments
11767@subsection Starting and Stopping Trace Experiments
b37052ae
EZ
11768
11769@table @code
f196051f 11770@kindex tstart [ @var{notes} ]
b37052ae
EZ
11771@cindex start a new trace experiment
11772@cindex collected data discarded
11773@item tstart
f196051f
SS
11774This command starts the trace experiment, and begins collecting data.
11775It has the side effect of discarding all the data collected in the
11776trace buffer during the previous trace experiment. If any arguments
11777are supplied, they are taken as a note and stored with the trace
11778experiment's state. The notes may be arbitrary text, and are
11779especially useful with disconnected tracing in a multi-user context;
11780the notes can explain what the trace is doing, supply user contact
11781information, and so forth.
11782
11783@kindex tstop [ @var{notes} ]
b37052ae
EZ
11784@cindex stop a running trace experiment
11785@item tstop
f196051f
SS
11786This command stops the trace experiment. If any arguments are
11787supplied, they are recorded with the experiment as a note. This is
11788useful if you are stopping a trace started by someone else, for
11789instance if the trace is interfering with the system's behavior and
11790needs to be stopped quickly.
b37052ae 11791
68c71a2e 11792@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
11793automatically if any tracepoint's passcount is reached
11794(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
11795
11796@kindex tstatus
11797@cindex status of trace data collection
11798@cindex trace experiment, status of
11799@item tstatus
11800This command displays the status of the current trace data
11801collection.
11802@end table
11803
11804Here is an example of the commands we described so far:
11805
11806@smallexample
11807(@value{GDBP}) @b{trace gdb_c_test}
11808(@value{GDBP}) @b{actions}
11809Enter actions for tracepoint #1, one per line.
11810> collect $regs,$locals,$args
11811> while-stepping 11
11812 > collect $regs
11813 > end
11814> end
11815(@value{GDBP}) @b{tstart}
11816 [time passes @dots{}]
11817(@value{GDBP}) @b{tstop}
11818@end smallexample
11819
03f2bd59 11820@anchor{disconnected tracing}
d5551862
SS
11821@cindex disconnected tracing
11822You can choose to continue running the trace experiment even if
11823@value{GDBN} disconnects from the target, voluntarily or
11824involuntarily. For commands such as @code{detach}, the debugger will
11825ask what you want to do with the trace. But for unexpected
11826terminations (@value{GDBN} crash, network outage), it would be
11827unfortunate to lose hard-won trace data, so the variable
11828@code{disconnected-tracing} lets you decide whether the trace should
11829continue running without @value{GDBN}.
11830
11831@table @code
11832@item set disconnected-tracing on
11833@itemx set disconnected-tracing off
11834@kindex set disconnected-tracing
11835Choose whether a tracing run should continue to run if @value{GDBN}
11836has disconnected from the target. Note that @code{detach} or
11837@code{quit} will ask you directly what to do about a running trace no
11838matter what this variable's setting, so the variable is mainly useful
11839for handling unexpected situations, such as loss of the network.
11840
11841@item show disconnected-tracing
11842@kindex show disconnected-tracing
11843Show the current choice for disconnected tracing.
11844
11845@end table
11846
11847When you reconnect to the target, the trace experiment may or may not
11848still be running; it might have filled the trace buffer in the
11849meantime, or stopped for one of the other reasons. If it is running,
11850it will continue after reconnection.
11851
11852Upon reconnection, the target will upload information about the
11853tracepoints in effect. @value{GDBN} will then compare that
11854information to the set of tracepoints currently defined, and attempt
11855to match them up, allowing for the possibility that the numbers may
11856have changed due to creation and deletion in the meantime. If one of
11857the target's tracepoints does not match any in @value{GDBN}, the
11858debugger will create a new tracepoint, so that you have a number with
11859which to specify that tracepoint. This matching-up process is
11860necessarily heuristic, and it may result in useless tracepoints being
11861created; you may simply delete them if they are of no use.
b37052ae 11862
4daf5ac0
SS
11863@cindex circular trace buffer
11864If your target agent supports a @dfn{circular trace buffer}, then you
11865can run a trace experiment indefinitely without filling the trace
11866buffer; when space runs out, the agent deletes already-collected trace
11867frames, oldest first, until there is enough room to continue
11868collecting. This is especially useful if your tracepoints are being
11869hit too often, and your trace gets terminated prematurely because the
11870buffer is full. To ask for a circular trace buffer, simply set
81896e36 11871@samp{circular-trace-buffer} to on. You can set this at any time,
4daf5ac0
SS
11872including during tracing; if the agent can do it, it will change
11873buffer handling on the fly, otherwise it will not take effect until
11874the next run.
11875
11876@table @code
11877@item set circular-trace-buffer on
11878@itemx set circular-trace-buffer off
11879@kindex set circular-trace-buffer
11880Choose whether a tracing run should use a linear or circular buffer
11881for trace data. A linear buffer will not lose any trace data, but may
11882fill up prematurely, while a circular buffer will discard old trace
11883data, but it will have always room for the latest tracepoint hits.
11884
11885@item show circular-trace-buffer
11886@kindex show circular-trace-buffer
11887Show the current choice for the trace buffer. Note that this may not
11888match the agent's current buffer handling, nor is it guaranteed to
11889match the setting that might have been in effect during a past run,
11890for instance if you are looking at frames from a trace file.
11891
11892@end table
11893
f6f899bf
HAQ
11894@table @code
11895@item set trace-buffer-size @var{n}
f81d1120 11896@itemx set trace-buffer-size unlimited
f6f899bf
HAQ
11897@kindex set trace-buffer-size
11898Request that the target use a trace buffer of @var{n} bytes. Not all
11899targets will honor the request; they may have a compiled-in size for
11900the trace buffer, or some other limitation. Set to a value of
f81d1120
PA
11901@code{unlimited} or @code{-1} to let the target use whatever size it
11902likes. This is also the default.
f6f899bf
HAQ
11903
11904@item show trace-buffer-size
11905@kindex show trace-buffer-size
11906Show the current requested size for the trace buffer. Note that this
11907will only match the actual size if the target supports size-setting,
11908and was able to handle the requested size. For instance, if the
11909target can only change buffer size between runs, this variable will
11910not reflect the change until the next run starts. Use @code{tstatus}
11911to get a report of the actual buffer size.
11912@end table
11913
f196051f
SS
11914@table @code
11915@item set trace-user @var{text}
11916@kindex set trace-user
11917
11918@item show trace-user
11919@kindex show trace-user
11920
11921@item set trace-notes @var{text}
11922@kindex set trace-notes
11923Set the trace run's notes.
11924
11925@item show trace-notes
11926@kindex show trace-notes
11927Show the trace run's notes.
11928
11929@item set trace-stop-notes @var{text}
11930@kindex set trace-stop-notes
11931Set the trace run's stop notes. The handling of the note is as for
11932@code{tstop} arguments; the set command is convenient way to fix a
11933stop note that is mistaken or incomplete.
11934
11935@item show trace-stop-notes
11936@kindex show trace-stop-notes
11937Show the trace run's stop notes.
11938
11939@end table
11940
c9429232
SS
11941@node Tracepoint Restrictions
11942@subsection Tracepoint Restrictions
11943
11944@cindex tracepoint restrictions
11945There are a number of restrictions on the use of tracepoints. As
11946described above, tracepoint data gathering occurs on the target
11947without interaction from @value{GDBN}. Thus the full capabilities of
11948the debugger are not available during data gathering, and then at data
11949examination time, you will be limited by only having what was
11950collected. The following items describe some common problems, but it
11951is not exhaustive, and you may run into additional difficulties not
11952mentioned here.
11953
11954@itemize @bullet
11955
11956@item
11957Tracepoint expressions are intended to gather objects (lvalues). Thus
11958the full flexibility of GDB's expression evaluator is not available.
11959You cannot call functions, cast objects to aggregate types, access
11960convenience variables or modify values (except by assignment to trace
11961state variables). Some language features may implicitly call
11962functions (for instance Objective-C fields with accessors), and therefore
11963cannot be collected either.
11964
11965@item
11966Collection of local variables, either individually or in bulk with
11967@code{$locals} or @code{$args}, during @code{while-stepping} may
11968behave erratically. The stepping action may enter a new scope (for
11969instance by stepping into a function), or the location of the variable
11970may change (for instance it is loaded into a register). The
11971tracepoint data recorded uses the location information for the
11972variables that is correct for the tracepoint location. When the
11973tracepoint is created, it is not possible, in general, to determine
11974where the steps of a @code{while-stepping} sequence will advance the
11975program---particularly if a conditional branch is stepped.
11976
11977@item
11978Collection of an incompletely-initialized or partially-destroyed object
11979may result in something that @value{GDBN} cannot display, or displays
11980in a misleading way.
11981
11982@item
11983When @value{GDBN} displays a pointer to character it automatically
11984dereferences the pointer to also display characters of the string
11985being pointed to. However, collecting the pointer during tracing does
11986not automatically collect the string. You need to explicitly
11987dereference the pointer and provide size information if you want to
11988collect not only the pointer, but the memory pointed to. For example,
11989@code{*ptr@@50} can be used to collect the 50 element array pointed to
11990by @code{ptr}.
11991
11992@item
11993It is not possible to collect a complete stack backtrace at a
11994tracepoint. Instead, you may collect the registers and a few hundred
d99f7e48 11995bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
c9429232
SS
11996(adjust to use the name of the actual stack pointer register on your
11997target architecture, and the amount of stack you wish to capture).
11998Then the @code{backtrace} command will show a partial backtrace when
11999using a trace frame. The number of stack frames that can be examined
12000depends on the sizes of the frames in the collected stack. Note that
12001if you ask for a block so large that it goes past the bottom of the
12002stack, the target agent may report an error trying to read from an
12003invalid address.
12004
af54718e
SS
12005@item
12006If you do not collect registers at a tracepoint, @value{GDBN} can
12007infer that the value of @code{$pc} must be the same as the address of
12008the tracepoint and use that when you are looking at a trace frame
12009for that tracepoint. However, this cannot work if the tracepoint has
12010multiple locations (for instance if it was set in a function that was
12011inlined), or if it has a @code{while-stepping} loop. In those cases
12012@value{GDBN} will warn you that it can't infer @code{$pc}, and default
12013it to zero.
12014
c9429232
SS
12015@end itemize
12016
b37052ae 12017@node Analyze Collected Data
79a6e687 12018@section Using the Collected Data
b37052ae
EZ
12019
12020After the tracepoint experiment ends, you use @value{GDBN} commands
12021for examining the trace data. The basic idea is that each tracepoint
12022collects a trace @dfn{snapshot} every time it is hit and another
12023snapshot every time it single-steps. All these snapshots are
12024consecutively numbered from zero and go into a buffer, and you can
12025examine them later. The way you examine them is to @dfn{focus} on a
12026specific trace snapshot. When the remote stub is focused on a trace
12027snapshot, it will respond to all @value{GDBN} requests for memory and
12028registers by reading from the buffer which belongs to that snapshot,
12029rather than from @emph{real} memory or registers of the program being
12030debugged. This means that @strong{all} @value{GDBN} commands
12031(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
12032behave as if we were currently debugging the program state as it was
12033when the tracepoint occurred. Any requests for data that are not in
12034the buffer will fail.
12035
12036@menu
12037* tfind:: How to select a trace snapshot
12038* tdump:: How to display all data for a snapshot
6149aea9 12039* save tracepoints:: How to save tracepoints for a future run
b37052ae
EZ
12040@end menu
12041
12042@node tfind
12043@subsection @code{tfind @var{n}}
12044
12045@kindex tfind
12046@cindex select trace snapshot
12047@cindex find trace snapshot
12048The basic command for selecting a trace snapshot from the buffer is
12049@code{tfind @var{n}}, which finds trace snapshot number @var{n},
12050counting from zero. If no argument @var{n} is given, the next
12051snapshot is selected.
12052
12053Here are the various forms of using the @code{tfind} command.
12054
12055@table @code
12056@item tfind start
12057Find the first snapshot in the buffer. This is a synonym for
12058@code{tfind 0} (since 0 is the number of the first snapshot).
12059
12060@item tfind none
12061Stop debugging trace snapshots, resume @emph{live} debugging.
12062
12063@item tfind end
12064Same as @samp{tfind none}.
12065
12066@item tfind
12067No argument means find the next trace snapshot.
12068
12069@item tfind -
12070Find the previous trace snapshot before the current one. This permits
12071retracing earlier steps.
12072
12073@item tfind tracepoint @var{num}
12074Find the next snapshot associated with tracepoint @var{num}. Search
12075proceeds forward from the last examined trace snapshot. If no
12076argument @var{num} is given, it means find the next snapshot collected
12077for the same tracepoint as the current snapshot.
12078
12079@item tfind pc @var{addr}
12080Find the next snapshot associated with the value @var{addr} of the
12081program counter. Search proceeds forward from the last examined trace
12082snapshot. If no argument @var{addr} is given, it means find the next
12083snapshot with the same value of PC as the current snapshot.
12084
12085@item tfind outside @var{addr1}, @var{addr2}
12086Find the next snapshot whose PC is outside the given range of
081dfbf7 12087addresses (exclusive).
b37052ae
EZ
12088
12089@item tfind range @var{addr1}, @var{addr2}
12090Find the next snapshot whose PC is between @var{addr1} and
081dfbf7 12091@var{addr2} (inclusive).
b37052ae
EZ
12092
12093@item tfind line @r{[}@var{file}:@r{]}@var{n}
12094Find the next snapshot associated with the source line @var{n}. If
12095the optional argument @var{file} is given, refer to line @var{n} in
12096that source file. Search proceeds forward from the last examined
12097trace snapshot. If no argument @var{n} is given, it means find the
12098next line other than the one currently being examined; thus saying
12099@code{tfind line} repeatedly can appear to have the same effect as
12100stepping from line to line in a @emph{live} debugging session.
12101@end table
12102
12103The default arguments for the @code{tfind} commands are specifically
12104designed to make it easy to scan through the trace buffer. For
12105instance, @code{tfind} with no argument selects the next trace
12106snapshot, and @code{tfind -} with no argument selects the previous
12107trace snapshot. So, by giving one @code{tfind} command, and then
12108simply hitting @key{RET} repeatedly you can examine all the trace
12109snapshots in order. Or, by saying @code{tfind -} and then hitting
12110@key{RET} repeatedly you can examine the snapshots in reverse order.
12111The @code{tfind line} command with no argument selects the snapshot
12112for the next source line executed. The @code{tfind pc} command with
12113no argument selects the next snapshot with the same program counter
12114(PC) as the current frame. The @code{tfind tracepoint} command with
12115no argument selects the next trace snapshot collected by the same
12116tracepoint as the current one.
12117
12118In addition to letting you scan through the trace buffer manually,
12119these commands make it easy to construct @value{GDBN} scripts that
12120scan through the trace buffer and print out whatever collected data
12121you are interested in. Thus, if we want to examine the PC, FP, and SP
12122registers from each trace frame in the buffer, we can say this:
12123
12124@smallexample
12125(@value{GDBP}) @b{tfind start}
12126(@value{GDBP}) @b{while ($trace_frame != -1)}
12127> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
12128 $trace_frame, $pc, $sp, $fp
12129> tfind
12130> end
12131
12132Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
12133Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
12134Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
12135Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
12136Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
12137Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
12138Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
12139Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
12140Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
12141Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
12142Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
12143@end smallexample
12144
12145Or, if we want to examine the variable @code{X} at each source line in
12146the buffer:
12147
12148@smallexample
12149(@value{GDBP}) @b{tfind start}
12150(@value{GDBP}) @b{while ($trace_frame != -1)}
12151> printf "Frame %d, X == %d\n", $trace_frame, X
12152> tfind line
12153> end
12154
12155Frame 0, X = 1
12156Frame 7, X = 2
12157Frame 13, X = 255
12158@end smallexample
12159
12160@node tdump
12161@subsection @code{tdump}
12162@kindex tdump
12163@cindex dump all data collected at tracepoint
12164@cindex tracepoint data, display
12165
12166This command takes no arguments. It prints all the data collected at
12167the current trace snapshot.
12168
12169@smallexample
12170(@value{GDBP}) @b{trace 444}
12171(@value{GDBP}) @b{actions}
12172Enter actions for tracepoint #2, one per line:
12173> collect $regs, $locals, $args, gdb_long_test
12174> end
12175
12176(@value{GDBP}) @b{tstart}
12177
12178(@value{GDBP}) @b{tfind line 444}
12179#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
12180at gdb_test.c:444
12181444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
12182
12183(@value{GDBP}) @b{tdump}
12184Data collected at tracepoint 2, trace frame 1:
12185d0 0xc4aa0085 -995491707
12186d1 0x18 24
12187d2 0x80 128
12188d3 0x33 51
12189d4 0x71aea3d 119204413
12190d5 0x22 34
12191d6 0xe0 224
12192d7 0x380035 3670069
12193a0 0x19e24a 1696330
12194a1 0x3000668 50333288
12195a2 0x100 256
12196a3 0x322000 3284992
12197a4 0x3000698 50333336
12198a5 0x1ad3cc 1758156
12199fp 0x30bf3c 0x30bf3c
12200sp 0x30bf34 0x30bf34
12201ps 0x0 0
12202pc 0x20b2c8 0x20b2c8
12203fpcontrol 0x0 0
12204fpstatus 0x0 0
12205fpiaddr 0x0 0
12206p = 0x20e5b4 "gdb-test"
12207p1 = (void *) 0x11
12208p2 = (void *) 0x22
12209p3 = (void *) 0x33
12210p4 = (void *) 0x44
12211p5 = (void *) 0x55
12212p6 = (void *) 0x66
12213gdb_long_test = 17 '\021'
12214
12215(@value{GDBP})
12216@end smallexample
12217
af54718e
SS
12218@code{tdump} works by scanning the tracepoint's current collection
12219actions and printing the value of each expression listed. So
12220@code{tdump} can fail, if after a run, you change the tracepoint's
12221actions to mention variables that were not collected during the run.
12222
12223Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
12224uses the collected value of @code{$pc} to distinguish between trace
12225frames that were collected at the tracepoint hit, and frames that were
12226collected while stepping. This allows it to correctly choose whether
12227to display the basic list of collections, or the collections from the
12228body of the while-stepping loop. However, if @code{$pc} was not collected,
12229then @code{tdump} will always attempt to dump using the basic collection
12230list, and may fail if a while-stepping frame does not include all the
12231same data that is collected at the tracepoint hit.
12232@c This is getting pretty arcane, example would be good.
12233
6149aea9
PA
12234@node save tracepoints
12235@subsection @code{save tracepoints @var{filename}}
12236@kindex save tracepoints
b37052ae
EZ
12237@kindex save-tracepoints
12238@cindex save tracepoints for future sessions
12239
12240This command saves all current tracepoint definitions together with
12241their actions and passcounts, into a file @file{@var{filename}}
12242suitable for use in a later debugging session. To read the saved
12243tracepoint definitions, use the @code{source} command (@pxref{Command
6149aea9
PA
12244Files}). The @w{@code{save-tracepoints}} command is a deprecated
12245alias for @w{@code{save tracepoints}}
b37052ae
EZ
12246
12247@node Tracepoint Variables
12248@section Convenience Variables for Tracepoints
12249@cindex tracepoint variables
12250@cindex convenience variables for tracepoints
12251
12252@table @code
12253@vindex $trace_frame
12254@item (int) $trace_frame
12255The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
12256snapshot is selected.
12257
12258@vindex $tracepoint
12259@item (int) $tracepoint
12260The tracepoint for the current trace snapshot.
12261
12262@vindex $trace_line
12263@item (int) $trace_line
12264The line number for the current trace snapshot.
12265
12266@vindex $trace_file
12267@item (char []) $trace_file
12268The source file for the current trace snapshot.
12269
12270@vindex $trace_func
12271@item (char []) $trace_func
12272The name of the function containing @code{$tracepoint}.
12273@end table
12274
12275Note: @code{$trace_file} is not suitable for use in @code{printf},
12276use @code{output} instead.
12277
12278Here's a simple example of using these convenience variables for
12279stepping through all the trace snapshots and printing some of their
f61e138d
SS
12280data. Note that these are not the same as trace state variables,
12281which are managed by the target.
b37052ae
EZ
12282
12283@smallexample
12284(@value{GDBP}) @b{tfind start}
12285
12286(@value{GDBP}) @b{while $trace_frame != -1}
12287> output $trace_file
12288> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
12289> tfind
12290> end
12291@end smallexample
12292
00bf0b85
SS
12293@node Trace Files
12294@section Using Trace Files
12295@cindex trace files
12296
12297In some situations, the target running a trace experiment may no
12298longer be available; perhaps it crashed, or the hardware was needed
12299for a different activity. To handle these cases, you can arrange to
12300dump the trace data into a file, and later use that file as a source
12301of trace data, via the @code{target tfile} command.
12302
12303@table @code
12304
12305@kindex tsave
12306@item tsave [ -r ] @var{filename}
d0353e76 12307@itemx tsave [-ctf] @var{dirname}
00bf0b85
SS
12308Save the trace data to @var{filename}. By default, this command
12309assumes that @var{filename} refers to the host filesystem, so if
12310necessary @value{GDBN} will copy raw trace data up from the target and
12311then save it. If the target supports it, you can also supply the
12312optional argument @code{-r} (``remote'') to direct the target to save
12313the data directly into @var{filename} in its own filesystem, which may be
12314more efficient if the trace buffer is very large. (Note, however, that
12315@code{target tfile} can only read from files accessible to the host.)
d0353e76
YQ
12316By default, this command will save trace frame in tfile format.
12317You can supply the optional argument @code{-ctf} to save date in CTF
12318format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
12319that can be shared by multiple debugging and tracing tools. Please go to
12320@indicateurl{http://www.efficios.com/ctf} to get more information.
00bf0b85
SS
12321
12322@kindex target tfile
12323@kindex tfile
393fd4c3
YQ
12324@kindex target ctf
12325@kindex ctf
00bf0b85 12326@item target tfile @var{filename}
393fd4c3
YQ
12327@itemx target ctf @var{dirname}
12328Use the file named @var{filename} or directory named @var{dirname} as
12329a source of trace data. Commands that examine data work as they do with
12330a live target, but it is not possible to run any new trace experiments.
12331@code{tstatus} will report the state of the trace run at the moment
12332the data was saved, as well as the current trace frame you are examining.
12333@var{filename} or @var{dirname} must be on a filesystem accessible to
12334the host.
12335
12336@smallexample
12337(@value{GDBP}) target ctf ctf.ctf
12338(@value{GDBP}) tfind
12339Found trace frame 0, tracepoint 2
1234039 ++a; /* set tracepoint 1 here */
12341(@value{GDBP}) tdump
12342Data collected at tracepoint 2, trace frame 0:
12343i = 0
12344a = 0
12345b = 1 '\001'
12346c = @{"123", "456", "789", "123", "456", "789"@}
12347d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
12348(@value{GDBP}) p b
12349$1 = 1
12350@end smallexample
00bf0b85
SS
12351
12352@end table
12353
df0cd8c5
JB
12354@node Overlays
12355@chapter Debugging Programs That Use Overlays
12356@cindex overlays
12357
12358If your program is too large to fit completely in your target system's
12359memory, you can sometimes use @dfn{overlays} to work around this
12360problem. @value{GDBN} provides some support for debugging programs that
12361use overlays.
12362
12363@menu
12364* How Overlays Work:: A general explanation of overlays.
12365* Overlay Commands:: Managing overlays in @value{GDBN}.
12366* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
12367 mapped by asking the inferior.
12368* Overlay Sample Program:: A sample program using overlays.
12369@end menu
12370
12371@node How Overlays Work
12372@section How Overlays Work
12373@cindex mapped overlays
12374@cindex unmapped overlays
12375@cindex load address, overlay's
12376@cindex mapped address
12377@cindex overlay area
12378
12379Suppose you have a computer whose instruction address space is only 64
12380kilobytes long, but which has much more memory which can be accessed by
12381other means: special instructions, segment registers, or memory
12382management hardware, for example. Suppose further that you want to
12383adapt a program which is larger than 64 kilobytes to run on this system.
12384
12385One solution is to identify modules of your program which are relatively
12386independent, and need not call each other directly; call these modules
12387@dfn{overlays}. Separate the overlays from the main program, and place
12388their machine code in the larger memory. Place your main program in
12389instruction memory, but leave at least enough space there to hold the
12390largest overlay as well.
12391
12392Now, to call a function located in an overlay, you must first copy that
12393overlay's machine code from the large memory into the space set aside
12394for it in the instruction memory, and then jump to its entry point
12395there.
12396
c928edc0
AC
12397@c NB: In the below the mapped area's size is greater or equal to the
12398@c size of all overlays. This is intentional to remind the developer
12399@c that overlays don't necessarily need to be the same size.
12400
474c8240 12401@smallexample
df0cd8c5 12402@group
c928edc0
AC
12403 Data Instruction Larger
12404Address Space Address Space Address Space
12405+-----------+ +-----------+ +-----------+
12406| | | | | |
12407+-----------+ +-----------+ +-----------+<-- overlay 1
12408| program | | main | .----| overlay 1 | load address
12409| variables | | program | | +-----------+
12410| and heap | | | | | |
12411+-----------+ | | | +-----------+<-- overlay 2
12412| | +-----------+ | | | load address
12413+-----------+ | | | .-| overlay 2 |
12414 | | | | | |
12415 mapped --->+-----------+ | | +-----------+
12416 address | | | | | |
12417 | overlay | <-' | | |
12418 | area | <---' +-----------+<-- overlay 3
12419 | | <---. | | load address
12420 +-----------+ `--| overlay 3 |
12421 | | | |
12422 +-----------+ | |
12423 +-----------+
12424 | |
12425 +-----------+
12426
12427 @anchor{A code overlay}A code overlay
df0cd8c5 12428@end group
474c8240 12429@end smallexample
df0cd8c5 12430
c928edc0
AC
12431The diagram (@pxref{A code overlay}) shows a system with separate data
12432and instruction address spaces. To map an overlay, the program copies
12433its code from the larger address space to the instruction address space.
12434Since the overlays shown here all use the same mapped address, only one
12435may be mapped at a time. For a system with a single address space for
12436data and instructions, the diagram would be similar, except that the
12437program variables and heap would share an address space with the main
12438program and the overlay area.
df0cd8c5
JB
12439
12440An overlay loaded into instruction memory and ready for use is called a
12441@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
12442instruction memory. An overlay not present (or only partially present)
12443in instruction memory is called @dfn{unmapped}; its @dfn{load address}
12444is its address in the larger memory. The mapped address is also called
12445the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
12446called the @dfn{load memory address}, or @dfn{LMA}.
12447
12448Unfortunately, overlays are not a completely transparent way to adapt a
12449program to limited instruction memory. They introduce a new set of
12450global constraints you must keep in mind as you design your program:
12451
12452@itemize @bullet
12453
12454@item
12455Before calling or returning to a function in an overlay, your program
12456must make sure that overlay is actually mapped. Otherwise, the call or
12457return will transfer control to the right address, but in the wrong
12458overlay, and your program will probably crash.
12459
12460@item
12461If the process of mapping an overlay is expensive on your system, you
12462will need to choose your overlays carefully to minimize their effect on
12463your program's performance.
12464
12465@item
12466The executable file you load onto your system must contain each
12467overlay's instructions, appearing at the overlay's load address, not its
12468mapped address. However, each overlay's instructions must be relocated
12469and its symbols defined as if the overlay were at its mapped address.
12470You can use GNU linker scripts to specify different load and relocation
12471addresses for pieces of your program; see @ref{Overlay Description,,,
12472ld.info, Using ld: the GNU linker}.
12473
12474@item
12475The procedure for loading executable files onto your system must be able
12476to load their contents into the larger address space as well as the
12477instruction and data spaces.
12478
12479@end itemize
12480
12481The overlay system described above is rather simple, and could be
12482improved in many ways:
12483
12484@itemize @bullet
12485
12486@item
12487If your system has suitable bank switch registers or memory management
12488hardware, you could use those facilities to make an overlay's load area
12489contents simply appear at their mapped address in instruction space.
12490This would probably be faster than copying the overlay to its mapped
12491area in the usual way.
12492
12493@item
12494If your overlays are small enough, you could set aside more than one
12495overlay area, and have more than one overlay mapped at a time.
12496
12497@item
12498You can use overlays to manage data, as well as instructions. In
12499general, data overlays are even less transparent to your design than
12500code overlays: whereas code overlays only require care when you call or
12501return to functions, data overlays require care every time you access
12502the data. Also, if you change the contents of a data overlay, you
12503must copy its contents back out to its load address before you can copy a
12504different data overlay into the same mapped area.
12505
12506@end itemize
12507
12508
12509@node Overlay Commands
12510@section Overlay Commands
12511
12512To use @value{GDBN}'s overlay support, each overlay in your program must
12513correspond to a separate section of the executable file. The section's
12514virtual memory address and load memory address must be the overlay's
12515mapped and load addresses. Identifying overlays with sections allows
12516@value{GDBN} to determine the appropriate address of a function or
12517variable, depending on whether the overlay is mapped or not.
12518
12519@value{GDBN}'s overlay commands all start with the word @code{overlay};
12520you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
12521
12522@table @code
12523@item overlay off
4644b6e3 12524@kindex overlay
df0cd8c5
JB
12525Disable @value{GDBN}'s overlay support. When overlay support is
12526disabled, @value{GDBN} assumes that all functions and variables are
12527always present at their mapped addresses. By default, @value{GDBN}'s
12528overlay support is disabled.
12529
12530@item overlay manual
df0cd8c5
JB
12531@cindex manual overlay debugging
12532Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
12533relies on you to tell it which overlays are mapped, and which are not,
12534using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
12535commands described below.
12536
12537@item overlay map-overlay @var{overlay}
12538@itemx overlay map @var{overlay}
df0cd8c5
JB
12539@cindex map an overlay
12540Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
12541be the name of the object file section containing the overlay. When an
12542overlay is mapped, @value{GDBN} assumes it can find the overlay's
12543functions and variables at their mapped addresses. @value{GDBN} assumes
12544that any other overlays whose mapped ranges overlap that of
12545@var{overlay} are now unmapped.
12546
12547@item overlay unmap-overlay @var{overlay}
12548@itemx overlay unmap @var{overlay}
df0cd8c5
JB
12549@cindex unmap an overlay
12550Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
12551must be the name of the object file section containing the overlay.
12552When an overlay is unmapped, @value{GDBN} assumes it can find the
12553overlay's functions and variables at their load addresses.
12554
12555@item overlay auto
df0cd8c5
JB
12556Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
12557consults a data structure the overlay manager maintains in the inferior
12558to see which overlays are mapped. For details, see @ref{Automatic
12559Overlay Debugging}.
12560
12561@item overlay load-target
12562@itemx overlay load
df0cd8c5
JB
12563@cindex reloading the overlay table
12564Re-read the overlay table from the inferior. Normally, @value{GDBN}
12565re-reads the table @value{GDBN} automatically each time the inferior
12566stops, so this command should only be necessary if you have changed the
12567overlay mapping yourself using @value{GDBN}. This command is only
12568useful when using automatic overlay debugging.
12569
12570@item overlay list-overlays
12571@itemx overlay list
12572@cindex listing mapped overlays
12573Display a list of the overlays currently mapped, along with their mapped
12574addresses, load addresses, and sizes.
12575
12576@end table
12577
12578Normally, when @value{GDBN} prints a code address, it includes the name
12579of the function the address falls in:
12580
474c8240 12581@smallexample
f7dc1244 12582(@value{GDBP}) print main
df0cd8c5 12583$3 = @{int ()@} 0x11a0 <main>
474c8240 12584@end smallexample
df0cd8c5
JB
12585@noindent
12586When overlay debugging is enabled, @value{GDBN} recognizes code in
12587unmapped overlays, and prints the names of unmapped functions with
12588asterisks around them. For example, if @code{foo} is a function in an
12589unmapped overlay, @value{GDBN} prints it this way:
12590
474c8240 12591@smallexample
f7dc1244 12592(@value{GDBP}) overlay list
df0cd8c5 12593No sections are mapped.
f7dc1244 12594(@value{GDBP}) print foo
df0cd8c5 12595$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 12596@end smallexample
df0cd8c5
JB
12597@noindent
12598When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
12599name normally:
12600
474c8240 12601@smallexample
f7dc1244 12602(@value{GDBP}) overlay list
b383017d 12603Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 12604 mapped at 0x1016 - 0x104a
f7dc1244 12605(@value{GDBP}) print foo
df0cd8c5 12606$6 = @{int (int)@} 0x1016 <foo>
474c8240 12607@end smallexample
df0cd8c5
JB
12608
12609When overlay debugging is enabled, @value{GDBN} can find the correct
12610address for functions and variables in an overlay, whether or not the
12611overlay is mapped. This allows most @value{GDBN} commands, like
12612@code{break} and @code{disassemble}, to work normally, even on unmapped
12613code. However, @value{GDBN}'s breakpoint support has some limitations:
12614
12615@itemize @bullet
12616@item
12617@cindex breakpoints in overlays
12618@cindex overlays, setting breakpoints in
12619You can set breakpoints in functions in unmapped overlays, as long as
12620@value{GDBN} can write to the overlay at its load address.
12621@item
12622@value{GDBN} can not set hardware or simulator-based breakpoints in
12623unmapped overlays. However, if you set a breakpoint at the end of your
12624overlay manager (and tell @value{GDBN} which overlays are now mapped, if
12625you are using manual overlay management), @value{GDBN} will re-set its
12626breakpoints properly.
12627@end itemize
12628
12629
12630@node Automatic Overlay Debugging
12631@section Automatic Overlay Debugging
12632@cindex automatic overlay debugging
12633
12634@value{GDBN} can automatically track which overlays are mapped and which
12635are not, given some simple co-operation from the overlay manager in the
12636inferior. If you enable automatic overlay debugging with the
12637@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
12638looks in the inferior's memory for certain variables describing the
12639current state of the overlays.
12640
12641Here are the variables your overlay manager must define to support
12642@value{GDBN}'s automatic overlay debugging:
12643
12644@table @asis
12645
12646@item @code{_ovly_table}:
12647This variable must be an array of the following structures:
12648
474c8240 12649@smallexample
df0cd8c5
JB
12650struct
12651@{
12652 /* The overlay's mapped address. */
12653 unsigned long vma;
12654
12655 /* The size of the overlay, in bytes. */
12656 unsigned long size;
12657
12658 /* The overlay's load address. */
12659 unsigned long lma;
12660
12661 /* Non-zero if the overlay is currently mapped;
12662 zero otherwise. */
12663 unsigned long mapped;
12664@}
474c8240 12665@end smallexample
df0cd8c5
JB
12666
12667@item @code{_novlys}:
12668This variable must be a four-byte signed integer, holding the total
12669number of elements in @code{_ovly_table}.
12670
12671@end table
12672
12673To decide whether a particular overlay is mapped or not, @value{GDBN}
12674looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
12675@code{lma} members equal the VMA and LMA of the overlay's section in the
12676executable file. When @value{GDBN} finds a matching entry, it consults
12677the entry's @code{mapped} member to determine whether the overlay is
12678currently mapped.
12679
81d46470 12680In addition, your overlay manager may define a function called
def71bfa 12681@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
12682will silently set a breakpoint there. If the overlay manager then
12683calls this function whenever it has changed the overlay table, this
12684will enable @value{GDBN} to accurately keep track of which overlays
12685are in program memory, and update any breakpoints that may be set
b383017d 12686in overlays. This will allow breakpoints to work even if the
81d46470
MS
12687overlays are kept in ROM or other non-writable memory while they
12688are not being executed.
df0cd8c5
JB
12689
12690@node Overlay Sample Program
12691@section Overlay Sample Program
12692@cindex overlay example program
12693
12694When linking a program which uses overlays, you must place the overlays
12695at their load addresses, while relocating them to run at their mapped
12696addresses. To do this, you must write a linker script (@pxref{Overlay
12697Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
12698since linker scripts are specific to a particular host system, target
12699architecture, and target memory layout, this manual cannot provide
12700portable sample code demonstrating @value{GDBN}'s overlay support.
12701
12702However, the @value{GDBN} source distribution does contain an overlaid
12703program, with linker scripts for a few systems, as part of its test
12704suite. The program consists of the following files from
12705@file{gdb/testsuite/gdb.base}:
12706
12707@table @file
12708@item overlays.c
12709The main program file.
12710@item ovlymgr.c
12711A simple overlay manager, used by @file{overlays.c}.
12712@item foo.c
12713@itemx bar.c
12714@itemx baz.c
12715@itemx grbx.c
12716Overlay modules, loaded and used by @file{overlays.c}.
12717@item d10v.ld
12718@itemx m32r.ld
12719Linker scripts for linking the test program on the @code{d10v-elf}
12720and @code{m32r-elf} targets.
12721@end table
12722
12723You can build the test program using the @code{d10v-elf} GCC
12724cross-compiler like this:
12725
474c8240 12726@smallexample
df0cd8c5
JB
12727$ d10v-elf-gcc -g -c overlays.c
12728$ d10v-elf-gcc -g -c ovlymgr.c
12729$ d10v-elf-gcc -g -c foo.c
12730$ d10v-elf-gcc -g -c bar.c
12731$ d10v-elf-gcc -g -c baz.c
12732$ d10v-elf-gcc -g -c grbx.c
12733$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
12734 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 12735@end smallexample
df0cd8c5
JB
12736
12737The build process is identical for any other architecture, except that
12738you must substitute the appropriate compiler and linker script for the
12739target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
12740
12741
6d2ebf8b 12742@node Languages
c906108c
SS
12743@chapter Using @value{GDBN} with Different Languages
12744@cindex languages
12745
c906108c
SS
12746Although programming languages generally have common aspects, they are
12747rarely expressed in the same manner. For instance, in ANSI C,
12748dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
12749Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 12750represented (and displayed) differently. Hex numbers in C appear as
c906108c 12751@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
12752
12753@cindex working language
12754Language-specific information is built into @value{GDBN} for some languages,
12755allowing you to express operations like the above in your program's
12756native language, and allowing @value{GDBN} to output values in a manner
12757consistent with the syntax of your program's native language. The
12758language you use to build expressions is called the @dfn{working
12759language}.
12760
12761@menu
12762* Setting:: Switching between source languages
12763* Show:: Displaying the language
c906108c 12764* Checks:: Type and range checks
79a6e687
BW
12765* Supported Languages:: Supported languages
12766* Unsupported Languages:: Unsupported languages
c906108c
SS
12767@end menu
12768
6d2ebf8b 12769@node Setting
79a6e687 12770@section Switching Between Source Languages
c906108c
SS
12771
12772There are two ways to control the working language---either have @value{GDBN}
12773set it automatically, or select it manually yourself. You can use the
12774@code{set language} command for either purpose. On startup, @value{GDBN}
12775defaults to setting the language automatically. The working language is
12776used to determine how expressions you type are interpreted, how values
12777are printed, etc.
12778
12779In addition to the working language, every source file that
12780@value{GDBN} knows about has its own working language. For some object
12781file formats, the compiler might indicate which language a particular
12782source file is in. However, most of the time @value{GDBN} infers the
12783language from the name of the file. The language of a source file
b37052ae 12784controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 12785show each frame appropriately for its own language. There is no way to
d4f3574e
SS
12786set the language of a source file from within @value{GDBN}, but you can
12787set the language associated with a filename extension. @xref{Show, ,
79a6e687 12788Displaying the Language}.
c906108c
SS
12789
12790This is most commonly a problem when you use a program, such
5d161b24 12791as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
12792another language. In that case, make the
12793program use @code{#line} directives in its C output; that way
12794@value{GDBN} will know the correct language of the source code of the original
12795program, and will display that source code, not the generated C code.
12796
12797@menu
12798* Filenames:: Filename extensions and languages.
12799* Manually:: Setting the working language manually
12800* Automatically:: Having @value{GDBN} infer the source language
12801@end menu
12802
6d2ebf8b 12803@node Filenames
79a6e687 12804@subsection List of Filename Extensions and Languages
c906108c
SS
12805
12806If a source file name ends in one of the following extensions, then
12807@value{GDBN} infers that its language is the one indicated.
12808
12809@table @file
e07c999f
PH
12810@item .ada
12811@itemx .ads
12812@itemx .adb
12813@itemx .a
12814Ada source file.
c906108c
SS
12815
12816@item .c
12817C source file
12818
12819@item .C
12820@itemx .cc
12821@itemx .cp
12822@itemx .cpp
12823@itemx .cxx
12824@itemx .c++
b37052ae 12825C@t{++} source file
c906108c 12826
6aecb9c2
JB
12827@item .d
12828D source file
12829
b37303ee
AF
12830@item .m
12831Objective-C source file
12832
c906108c
SS
12833@item .f
12834@itemx .F
12835Fortran source file
12836
c906108c
SS
12837@item .mod
12838Modula-2 source file
c906108c
SS
12839
12840@item .s
12841@itemx .S
12842Assembler source file. This actually behaves almost like C, but
12843@value{GDBN} does not skip over function prologues when stepping.
12844@end table
12845
12846In addition, you may set the language associated with a filename
79a6e687 12847extension. @xref{Show, , Displaying the Language}.
c906108c 12848
6d2ebf8b 12849@node Manually
79a6e687 12850@subsection Setting the Working Language
c906108c
SS
12851
12852If you allow @value{GDBN} to set the language automatically,
12853expressions are interpreted the same way in your debugging session and
12854your program.
12855
12856@kindex set language
12857If you wish, you may set the language manually. To do this, issue the
12858command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 12859a language, such as
c906108c 12860@code{c} or @code{modula-2}.
c906108c
SS
12861For a list of the supported languages, type @samp{set language}.
12862
c906108c
SS
12863Setting the language manually prevents @value{GDBN} from updating the working
12864language automatically. This can lead to confusion if you try
12865to debug a program when the working language is not the same as the
12866source language, when an expression is acceptable to both
12867languages---but means different things. For instance, if the current
12868source file were written in C, and @value{GDBN} was parsing Modula-2, a
12869command such as:
12870
474c8240 12871@smallexample
c906108c 12872print a = b + c
474c8240 12873@end smallexample
c906108c
SS
12874
12875@noindent
12876might not have the effect you intended. In C, this means to add
12877@code{b} and @code{c} and place the result in @code{a}. The result
12878printed would be the value of @code{a}. In Modula-2, this means to compare
12879@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 12880
6d2ebf8b 12881@node Automatically
79a6e687 12882@subsection Having @value{GDBN} Infer the Source Language
c906108c
SS
12883
12884To have @value{GDBN} set the working language automatically, use
12885@samp{set language local} or @samp{set language auto}. @value{GDBN}
12886then infers the working language. That is, when your program stops in a
12887frame (usually by encountering a breakpoint), @value{GDBN} sets the
12888working language to the language recorded for the function in that
12889frame. If the language for a frame is unknown (that is, if the function
12890or block corresponding to the frame was defined in a source file that
12891does not have a recognized extension), the current working language is
12892not changed, and @value{GDBN} issues a warning.
12893
12894This may not seem necessary for most programs, which are written
12895entirely in one source language. However, program modules and libraries
12896written in one source language can be used by a main program written in
12897a different source language. Using @samp{set language auto} in this
12898case frees you from having to set the working language manually.
12899
6d2ebf8b 12900@node Show
79a6e687 12901@section Displaying the Language
c906108c
SS
12902
12903The following commands help you find out which language is the
12904working language, and also what language source files were written in.
12905
c906108c
SS
12906@table @code
12907@item show language
9c16f35a 12908@kindex show language
c906108c
SS
12909Display the current working language. This is the
12910language you can use with commands such as @code{print} to
12911build and compute expressions that may involve variables in your program.
12912
12913@item info frame
4644b6e3 12914@kindex info frame@r{, show the source language}
5d161b24 12915Display the source language for this frame. This language becomes the
c906108c 12916working language if you use an identifier from this frame.
79a6e687 12917@xref{Frame Info, ,Information about a Frame}, to identify the other
c906108c
SS
12918information listed here.
12919
12920@item info source
4644b6e3 12921@kindex info source@r{, show the source language}
c906108c 12922Display the source language of this source file.
5d161b24 12923@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
12924information listed here.
12925@end table
12926
12927In unusual circumstances, you may have source files with extensions
12928not in the standard list. You can then set the extension associated
12929with a language explicitly:
12930
c906108c 12931@table @code
09d4efe1 12932@item set extension-language @var{ext} @var{language}
9c16f35a 12933@kindex set extension-language
09d4efe1
EZ
12934Tell @value{GDBN} that source files with extension @var{ext} are to be
12935assumed as written in the source language @var{language}.
c906108c
SS
12936
12937@item info extensions
9c16f35a 12938@kindex info extensions
c906108c
SS
12939List all the filename extensions and the associated languages.
12940@end table
12941
6d2ebf8b 12942@node Checks
79a6e687 12943@section Type and Range Checking
c906108c 12944
c906108c
SS
12945Some languages are designed to guard you against making seemingly common
12946errors through a series of compile- and run-time checks. These include
a451cb65 12947checking the type of arguments to functions and operators and making
c906108c
SS
12948sure mathematical overflows are caught at run time. Checks such as
12949these help to ensure a program's correctness once it has been compiled
a451cb65 12950by eliminating type mismatches and providing active checks for range
c906108c
SS
12951errors when your program is running.
12952
a451cb65
KS
12953By default @value{GDBN} checks for these errors according to the
12954rules of the current source language. Although @value{GDBN} does not check
12955the statements in your program, it can check expressions entered directly
12956into @value{GDBN} for evaluation via the @code{print} command, for example.
c906108c
SS
12957
12958@menu
12959* Type Checking:: An overview of type checking
12960* Range Checking:: An overview of range checking
12961@end menu
12962
12963@cindex type checking
12964@cindex checks, type
6d2ebf8b 12965@node Type Checking
79a6e687 12966@subsection An Overview of Type Checking
c906108c 12967
a451cb65 12968Some languages, such as C and C@t{++}, are strongly typed, meaning that the
c906108c
SS
12969arguments to operators and functions have to be of the correct type,
12970otherwise an error occurs. These checks prevent type mismatch
12971errors from ever causing any run-time problems. For example,
12972
12973@smallexample
a451cb65
KS
12974int klass::my_method(char *b) @{ return b ? 1 : 2; @}
12975
12976(@value{GDBP}) print obj.my_method (0)
12977$1 = 2
c906108c 12978@exdent but
a451cb65
KS
12979(@value{GDBP}) print obj.my_method (0x1234)
12980Cannot resolve method klass::my_method to any overloaded instance
c906108c
SS
12981@end smallexample
12982
a451cb65
KS
12983The second example fails because in C@t{++} the integer constant
12984@samp{0x1234} is not type-compatible with the pointer parameter type.
c906108c 12985
a451cb65
KS
12986For the expressions you use in @value{GDBN} commands, you can tell
12987@value{GDBN} to not enforce strict type checking or
5d161b24 12988to treat any mismatches as errors and abandon the expression;
a451cb65
KS
12989When type checking is disabled, @value{GDBN} successfully evaluates
12990expressions like the second example above.
c906108c 12991
a451cb65 12992Even if type checking is off, there may be other reasons
5d161b24
DB
12993related to type that prevent @value{GDBN} from evaluating an expression.
12994For instance, @value{GDBN} does not know how to add an @code{int} and
12995a @code{struct foo}. These particular type errors have nothing to do
a451cb65
KS
12996with the language in use and usually arise from expressions which make
12997little sense to evaluate anyway.
c906108c 12998
a451cb65 12999@value{GDBN} provides some additional commands for controlling type checking:
c906108c 13000
c906108c
SS
13001@kindex set check type
13002@kindex show check type
13003@table @code
c906108c
SS
13004@item set check type on
13005@itemx set check type off
a451cb65 13006Set strict type checking on or off. If any type mismatches occur in
d4f3574e 13007evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
13008message and aborts evaluation of the expression.
13009
a451cb65
KS
13010@item show check type
13011Show the current setting of type checking and whether @value{GDBN}
13012is enforcing strict type checking rules.
c906108c
SS
13013@end table
13014
13015@cindex range checking
13016@cindex checks, range
6d2ebf8b 13017@node Range Checking
79a6e687 13018@subsection An Overview of Range Checking
c906108c
SS
13019
13020In some languages (such as Modula-2), it is an error to exceed the
13021bounds of a type; this is enforced with run-time checks. Such range
13022checking is meant to ensure program correctness by making sure
13023computations do not overflow, or indices on an array element access do
13024not exceed the bounds of the array.
13025
13026For expressions you use in @value{GDBN} commands, you can tell
13027@value{GDBN} to treat range errors in one of three ways: ignore them,
13028always treat them as errors and abandon the expression, or issue
13029warnings but evaluate the expression anyway.
13030
13031A range error can result from numerical overflow, from exceeding an
13032array index bound, or when you type a constant that is not a member
13033of any type. Some languages, however, do not treat overflows as an
13034error. In many implementations of C, mathematical overflow causes the
13035result to ``wrap around'' to lower values---for example, if @var{m} is
13036the largest integer value, and @var{s} is the smallest, then
13037
474c8240 13038@smallexample
c906108c 13039@var{m} + 1 @result{} @var{s}
474c8240 13040@end smallexample
c906108c
SS
13041
13042This, too, is specific to individual languages, and in some cases
79a6e687
BW
13043specific to individual compilers or machines. @xref{Supported Languages, ,
13044Supported Languages}, for further details on specific languages.
c906108c
SS
13045
13046@value{GDBN} provides some additional commands for controlling the range checker:
13047
c906108c
SS
13048@kindex set check range
13049@kindex show check range
13050@table @code
13051@item set check range auto
13052Set range checking on or off based on the current working language.
79a6e687 13053@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
13054each language.
13055
13056@item set check range on
13057@itemx set check range off
13058Set range checking on or off, overriding the default setting for the
13059current working language. A warning is issued if the setting does not
c3f6f71d
JM
13060match the language default. If a range error occurs and range checking is on,
13061then a message is printed and evaluation of the expression is aborted.
c906108c
SS
13062
13063@item set check range warn
13064Output messages when the @value{GDBN} range checker detects a range error,
13065but attempt to evaluate the expression anyway. Evaluating the
13066expression may still be impossible for other reasons, such as accessing
13067memory that the process does not own (a typical example from many Unix
13068systems).
13069
13070@item show range
13071Show the current setting of the range checker, and whether or not it is
13072being set automatically by @value{GDBN}.
13073@end table
c906108c 13074
79a6e687
BW
13075@node Supported Languages
13076@section Supported Languages
c906108c 13077
a766d390
DE
13078@value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran, Java,
13079OpenCL C, Pascal, assembly, Modula-2, and Ada.
cce74817 13080@c This is false ...
c906108c
SS
13081Some @value{GDBN} features may be used in expressions regardless of the
13082language you use: the @value{GDBN} @code{@@} and @code{::} operators,
13083and the @samp{@{type@}addr} construct (@pxref{Expressions,
13084,Expressions}) can be used with the constructs of any supported
13085language.
13086
13087The following sections detail to what degree each source language is
13088supported by @value{GDBN}. These sections are not meant to be language
13089tutorials or references, but serve only as a reference guide to what the
13090@value{GDBN} expression parser accepts, and what input and output
13091formats should look like for different languages. There are many good
13092books written on each of these languages; please look to these for a
13093language reference or tutorial.
13094
c906108c 13095@menu
b37303ee 13096* C:: C and C@t{++}
6aecb9c2 13097* D:: D
a766d390 13098* Go:: Go
b383017d 13099* Objective-C:: Objective-C
f4b8a18d 13100* OpenCL C:: OpenCL C
09d4efe1 13101* Fortran:: Fortran
9c16f35a 13102* Pascal:: Pascal
b37303ee 13103* Modula-2:: Modula-2
e07c999f 13104* Ada:: Ada
c906108c
SS
13105@end menu
13106
6d2ebf8b 13107@node C
b37052ae 13108@subsection C and C@t{++}
7a292a7a 13109
b37052ae
EZ
13110@cindex C and C@t{++}
13111@cindex expressions in C or C@t{++}
c906108c 13112
b37052ae 13113Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
13114to both languages. Whenever this is the case, we discuss those languages
13115together.
13116
41afff9a
EZ
13117@cindex C@t{++}
13118@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
13119@cindex @sc{gnu} C@t{++}
13120The C@t{++} debugging facilities are jointly implemented by the C@t{++}
13121compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
13122effectively, you must compile your C@t{++} programs with a supported
13123C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
13124compiler (@code{aCC}).
13125
c906108c 13126@menu
b37052ae
EZ
13127* C Operators:: C and C@t{++} operators
13128* C Constants:: C and C@t{++} constants
79a6e687 13129* C Plus Plus Expressions:: C@t{++} expressions
b37052ae
EZ
13130* C Defaults:: Default settings for C and C@t{++}
13131* C Checks:: C and C@t{++} type and range checks
c906108c 13132* Debugging C:: @value{GDBN} and C
79a6e687 13133* Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
febe4383 13134* Decimal Floating Point:: Numbers in Decimal Floating Point format
c906108c 13135@end menu
c906108c 13136
6d2ebf8b 13137@node C Operators
79a6e687 13138@subsubsection C and C@t{++} Operators
7a292a7a 13139
b37052ae 13140@cindex C and C@t{++} operators
c906108c
SS
13141
13142Operators must be defined on values of specific types. For instance,
13143@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 13144often defined on groups of types.
c906108c 13145
b37052ae 13146For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
13147
13148@itemize @bullet
53a5351d 13149
c906108c 13150@item
c906108c 13151@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 13152specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
13153
13154@item
d4f3574e
SS
13155@emph{Floating-point types} include @code{float}, @code{double}, and
13156@code{long double} (if supported by the target platform).
c906108c
SS
13157
13158@item
53a5351d 13159@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
13160
13161@item
13162@emph{Scalar types} include all of the above.
53a5351d 13163
c906108c
SS
13164@end itemize
13165
13166@noindent
13167The following operators are supported. They are listed here
13168in order of increasing precedence:
13169
13170@table @code
13171@item ,
13172The comma or sequencing operator. Expressions in a comma-separated list
13173are evaluated from left to right, with the result of the entire
13174expression being the last expression evaluated.
13175
13176@item =
13177Assignment. The value of an assignment expression is the value
13178assigned. Defined on scalar types.
13179
13180@item @var{op}=
13181Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
13182and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 13183@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
13184@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
13185@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
13186
13187@item ?:
13188The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
13189of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
13190integral type.
13191
13192@item ||
13193Logical @sc{or}. Defined on integral types.
13194
13195@item &&
13196Logical @sc{and}. Defined on integral types.
13197
13198@item |
13199Bitwise @sc{or}. Defined on integral types.
13200
13201@item ^
13202Bitwise exclusive-@sc{or}. Defined on integral types.
13203
13204@item &
13205Bitwise @sc{and}. Defined on integral types.
13206
13207@item ==@r{, }!=
13208Equality and inequality. Defined on scalar types. The value of these
13209expressions is 0 for false and non-zero for true.
13210
13211@item <@r{, }>@r{, }<=@r{, }>=
13212Less than, greater than, less than or equal, greater than or equal.
13213Defined on scalar types. The value of these expressions is 0 for false
13214and non-zero for true.
13215
13216@item <<@r{, }>>
13217left shift, and right shift. Defined on integral types.
13218
13219@item @@
13220The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
13221
13222@item +@r{, }-
13223Addition and subtraction. Defined on integral types, floating-point types and
13224pointer types.
13225
13226@item *@r{, }/@r{, }%
13227Multiplication, division, and modulus. Multiplication and division are
13228defined on integral and floating-point types. Modulus is defined on
13229integral types.
13230
13231@item ++@r{, }--
13232Increment and decrement. When appearing before a variable, the
13233operation is performed before the variable is used in an expression;
13234when appearing after it, the variable's value is used before the
13235operation takes place.
13236
13237@item *
13238Pointer dereferencing. Defined on pointer types. Same precedence as
13239@code{++}.
13240
13241@item &
13242Address operator. Defined on variables. Same precedence as @code{++}.
13243
b37052ae
EZ
13244For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
13245allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
b17828ca 13246to examine the address
b37052ae 13247where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 13248stored.
c906108c
SS
13249
13250@item -
13251Negative. Defined on integral and floating-point types. Same
13252precedence as @code{++}.
13253
13254@item !
13255Logical negation. Defined on integral types. Same precedence as
13256@code{++}.
13257
13258@item ~
13259Bitwise complement operator. Defined on integral types. Same precedence as
13260@code{++}.
13261
13262
13263@item .@r{, }->
13264Structure member, and pointer-to-structure member. For convenience,
13265@value{GDBN} regards the two as equivalent, choosing whether to dereference a
13266pointer based on the stored type information.
13267Defined on @code{struct} and @code{union} data.
13268
c906108c
SS
13269@item .*@r{, }->*
13270Dereferences of pointers to members.
c906108c
SS
13271
13272@item []
13273Array indexing. @code{@var{a}[@var{i}]} is defined as
13274@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
13275
13276@item ()
13277Function parameter list. Same precedence as @code{->}.
13278
c906108c 13279@item ::
b37052ae 13280C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 13281and @code{class} types.
c906108c
SS
13282
13283@item ::
7a292a7a
SS
13284Doubled colons also represent the @value{GDBN} scope operator
13285(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
13286above.
c906108c
SS
13287@end table
13288
c906108c
SS
13289If an operator is redefined in the user code, @value{GDBN} usually
13290attempts to invoke the redefined version instead of using the operator's
13291predefined meaning.
c906108c 13292
6d2ebf8b 13293@node C Constants
79a6e687 13294@subsubsection C and C@t{++} Constants
c906108c 13295
b37052ae 13296@cindex C and C@t{++} constants
c906108c 13297
b37052ae 13298@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 13299following ways:
c906108c
SS
13300
13301@itemize @bullet
13302@item
13303Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
13304specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
13305by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
13306@samp{l}, specifying that the constant should be treated as a
13307@code{long} value.
13308
13309@item
13310Floating point constants are a sequence of digits, followed by a decimal
13311point, followed by a sequence of digits, and optionally followed by an
13312exponent. An exponent is of the form:
13313@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
13314sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
13315A floating-point constant may also end with a letter @samp{f} or
13316@samp{F}, specifying that the constant should be treated as being of
13317the @code{float} (as opposed to the default @code{double}) type; or with
13318a letter @samp{l} or @samp{L}, which specifies a @code{long double}
13319constant.
c906108c
SS
13320
13321@item
13322Enumerated constants consist of enumerated identifiers, or their
13323integral equivalents.
13324
13325@item
13326Character constants are a single character surrounded by single quotes
13327(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 13328(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
13329be represented by a letter or by @dfn{escape sequences}, which are of
13330the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
13331of the character's ordinal value; or of the form @samp{\@var{x}}, where
13332@samp{@var{x}} is a predefined special character---for example,
13333@samp{\n} for newline.
13334
e0f8f636
TT
13335Wide character constants can be written by prefixing a character
13336constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
13337form of @samp{x}. The target wide character set is used when
13338computing the value of this constant (@pxref{Character Sets}).
13339
c906108c 13340@item
96a2c332
SS
13341String constants are a sequence of character constants surrounded by
13342double quotes (@code{"}). Any valid character constant (as described
13343above) may appear. Double quotes within the string must be preceded by
13344a backslash, so for instance @samp{"a\"b'c"} is a string of five
13345characters.
c906108c 13346
e0f8f636
TT
13347Wide string constants can be written by prefixing a string constant
13348with @samp{L}, as in C. The target wide character set is used when
13349computing the value of this constant (@pxref{Character Sets}).
13350
c906108c
SS
13351@item
13352Pointer constants are an integral value. You can also write pointers
13353to constants using the C operator @samp{&}.
13354
13355@item
13356Array constants are comma-separated lists surrounded by braces @samp{@{}
13357and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
13358integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
13359and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
13360@end itemize
13361
79a6e687
BW
13362@node C Plus Plus Expressions
13363@subsubsection C@t{++} Expressions
b37052ae
EZ
13364
13365@cindex expressions in C@t{++}
13366@value{GDBN} expression handling can interpret most C@t{++} expressions.
13367
0179ffac
DC
13368@cindex debugging C@t{++} programs
13369@cindex C@t{++} compilers
13370@cindex debug formats and C@t{++}
13371@cindex @value{NGCC} and C@t{++}
c906108c 13372@quotation
e0f8f636
TT
13373@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
13374the proper compiler and the proper debug format. Currently,
13375@value{GDBN} works best when debugging C@t{++} code that is compiled
13376with the most recent version of @value{NGCC} possible. The DWARF
13377debugging format is preferred; @value{NGCC} defaults to this on most
13378popular platforms. Other compilers and/or debug formats are likely to
13379work badly or not at all when using @value{GDBN} to debug C@t{++}
13380code. @xref{Compilation}.
c906108c 13381@end quotation
c906108c
SS
13382
13383@enumerate
13384
13385@cindex member functions
13386@item
13387Member function calls are allowed; you can use expressions like
13388
474c8240 13389@smallexample
c906108c 13390count = aml->GetOriginal(x, y)
474c8240 13391@end smallexample
c906108c 13392
41afff9a 13393@vindex this@r{, inside C@t{++} member functions}
b37052ae 13394@cindex namespace in C@t{++}
c906108c
SS
13395@item
13396While a member function is active (in the selected stack frame), your
13397expressions have the same namespace available as the member function;
13398that is, @value{GDBN} allows implicit references to the class instance
e0f8f636
TT
13399pointer @code{this} following the same rules as C@t{++}. @code{using}
13400declarations in the current scope are also respected by @value{GDBN}.
c906108c 13401
c906108c 13402@cindex call overloaded functions
d4f3574e 13403@cindex overloaded functions, calling
b37052ae 13404@cindex type conversions in C@t{++}
c906108c
SS
13405@item
13406You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 13407call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
13408perform overload resolution involving user-defined type conversions,
13409calls to constructors, or instantiations of templates that do not exist
13410in the program. It also cannot handle ellipsis argument lists or
13411default arguments.
13412
13413It does perform integral conversions and promotions, floating-point
13414promotions, arithmetic conversions, pointer conversions, conversions of
13415class objects to base classes, and standard conversions such as those of
13416functions or arrays to pointers; it requires an exact match on the
13417number of function arguments.
13418
13419Overload resolution is always performed, unless you have specified
79a6e687
BW
13420@code{set overload-resolution off}. @xref{Debugging C Plus Plus,
13421,@value{GDBN} Features for C@t{++}}.
c906108c 13422
d4f3574e 13423You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
13424explicit function signature to call an overloaded function, as in
13425@smallexample
13426p 'foo(char,int)'('x', 13)
13427@end smallexample
d4f3574e 13428
c906108c 13429The @value{GDBN} command-completion facility can simplify this;
79a6e687 13430see @ref{Completion, ,Command Completion}.
c906108c 13431
c906108c
SS
13432@cindex reference declarations
13433@item
b37052ae
EZ
13434@value{GDBN} understands variables declared as C@t{++} references; you can use
13435them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
13436dereferenced.
13437
13438In the parameter list shown when @value{GDBN} displays a frame, the values of
13439reference variables are not displayed (unlike other variables); this
13440avoids clutter, since references are often used for large structures.
13441The @emph{address} of a reference variable is always shown, unless
13442you have specified @samp{set print address off}.
13443
13444@item
b37052ae 13445@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
13446expressions can use it just as expressions in your program do. Since
13447one scope may be defined in another, you can use @code{::} repeatedly if
13448necessary, for example in an expression like
13449@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 13450resolving name scope by reference to source files, in both C and C@t{++}
79a6e687 13451debugging (@pxref{Variables, ,Program Variables}).
c906108c 13452
e0f8f636
TT
13453@item
13454@value{GDBN} performs argument-dependent lookup, following the C@t{++}
13455specification.
13456@end enumerate
c906108c 13457
6d2ebf8b 13458@node C Defaults
79a6e687 13459@subsubsection C and C@t{++} Defaults
7a292a7a 13460
b37052ae 13461@cindex C and C@t{++} defaults
c906108c 13462
a451cb65
KS
13463If you allow @value{GDBN} to set range checking automatically, it
13464defaults to @code{off} whenever the working language changes to
b37052ae 13465C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 13466selects the working language.
c906108c
SS
13467
13468If you allow @value{GDBN} to set the language automatically, it
13469recognizes source files whose names end with @file{.c}, @file{.C}, or
13470@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 13471these files, it sets the working language to C or C@t{++}.
79a6e687 13472@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
c906108c
SS
13473for further details.
13474
6d2ebf8b 13475@node C Checks
79a6e687 13476@subsubsection C and C@t{++} Type and Range Checks
7a292a7a 13477
b37052ae 13478@cindex C and C@t{++} checks
c906108c 13479
a451cb65
KS
13480By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
13481checking is used. However, if you turn type checking off, @value{GDBN}
13482will allow certain non-standard conversions, such as promoting integer
13483constants to pointers.
c906108c
SS
13484
13485Range checking, if turned on, is done on mathematical operations. Array
13486indices are not checked, since they are often used to index a pointer
13487that is not itself an array.
c906108c 13488
6d2ebf8b 13489@node Debugging C
c906108c 13490@subsubsection @value{GDBN} and C
c906108c
SS
13491
13492The @code{set print union} and @code{show print union} commands apply to
13493the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
13494inside a @code{struct} or @code{class} is also printed. Otherwise, it
13495appears as @samp{@{...@}}.
c906108c
SS
13496
13497The @code{@@} operator aids in the debugging of dynamic arrays, formed
13498with pointers and a memory allocation function. @xref{Expressions,
13499,Expressions}.
13500
79a6e687
BW
13501@node Debugging C Plus Plus
13502@subsubsection @value{GDBN} Features for C@t{++}
c906108c 13503
b37052ae 13504@cindex commands for C@t{++}
7a292a7a 13505
b37052ae
EZ
13506Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
13507designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
13508
13509@table @code
13510@cindex break in overloaded functions
13511@item @r{breakpoint menus}
13512When you want a breakpoint in a function whose name is overloaded,
6ba66d6a
JB
13513@value{GDBN} has the capability to display a menu of possible breakpoint
13514locations to help you specify which function definition you want.
13515@xref{Ambiguous Expressions,,Ambiguous Expressions}.
c906108c 13516
b37052ae 13517@cindex overloading in C@t{++}
c906108c
SS
13518@item rbreak @var{regex}
13519Setting breakpoints using regular expressions is helpful for setting
13520breakpoints on overloaded functions that are not members of any special
13521classes.
79a6e687 13522@xref{Set Breaks, ,Setting Breakpoints}.
c906108c 13523
b37052ae 13524@cindex C@t{++} exception handling
c906108c
SS
13525@item catch throw
13526@itemx catch catch
b37052ae 13527Debug C@t{++} exception handling using these commands. @xref{Set
79a6e687 13528Catchpoints, , Setting Catchpoints}.
c906108c
SS
13529
13530@cindex inheritance
13531@item ptype @var{typename}
13532Print inheritance relationships as well as other information for type
13533@var{typename}.
13534@xref{Symbols, ,Examining the Symbol Table}.
13535
c4aeac85
TT
13536@item info vtbl @var{expression}.
13537The @code{info vtbl} command can be used to display the virtual
13538method tables of the object computed by @var{expression}. This shows
13539one entry per virtual table; there may be multiple virtual tables when
13540multiple inheritance is in use.
13541
b37052ae 13542@cindex C@t{++} symbol display
c906108c
SS
13543@item set print demangle
13544@itemx show print demangle
13545@itemx set print asm-demangle
13546@itemx show print asm-demangle
b37052ae
EZ
13547Control whether C@t{++} symbols display in their source form, both when
13548displaying code as C@t{++} source and when displaying disassemblies.
79a6e687 13549@xref{Print Settings, ,Print Settings}.
c906108c
SS
13550
13551@item set print object
13552@itemx show print object
13553Choose whether to print derived (actual) or declared types of objects.
79a6e687 13554@xref{Print Settings, ,Print Settings}.
c906108c
SS
13555
13556@item set print vtbl
13557@itemx show print vtbl
13558Control the format for printing virtual function tables.
79a6e687 13559@xref{Print Settings, ,Print Settings}.
c906108c 13560(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 13561ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
13562
13563@kindex set overload-resolution
d4f3574e 13564@cindex overloaded functions, overload resolution
c906108c 13565@item set overload-resolution on
b37052ae 13566Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
13567is on. For overloaded functions, @value{GDBN} evaluates the arguments
13568and searches for a function whose signature matches the argument types,
79a6e687
BW
13569using the standard C@t{++} conversion rules (see @ref{C Plus Plus
13570Expressions, ,C@t{++} Expressions}, for details).
13571If it cannot find a match, it emits a message.
c906108c
SS
13572
13573@item set overload-resolution off
b37052ae 13574Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
13575overloaded functions that are not class member functions, @value{GDBN}
13576chooses the first function of the specified name that it finds in the
13577symbol table, whether or not its arguments are of the correct type. For
13578overloaded functions that are class member functions, @value{GDBN}
13579searches for a function whose signature @emph{exactly} matches the
13580argument types.
c906108c 13581
9c16f35a
EZ
13582@kindex show overload-resolution
13583@item show overload-resolution
13584Show the current setting of overload resolution.
13585
c906108c
SS
13586@item @r{Overloaded symbol names}
13587You can specify a particular definition of an overloaded symbol, using
b37052ae 13588the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
13589@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
13590also use the @value{GDBN} command-line word completion facilities to list the
13591available choices, or to finish the type list for you.
79a6e687 13592@xref{Completion,, Command Completion}, for details on how to do this.
c906108c 13593@end table
c906108c 13594
febe4383
TJB
13595@node Decimal Floating Point
13596@subsubsection Decimal Floating Point format
13597@cindex decimal floating point format
13598
13599@value{GDBN} can examine, set and perform computations with numbers in
13600decimal floating point format, which in the C language correspond to the
13601@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
13602specified by the extension to support decimal floating-point arithmetic.
13603
13604There are two encodings in use, depending on the architecture: BID (Binary
13605Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
99e008fe 13606PowerPC. @value{GDBN} will use the appropriate encoding for the configured
febe4383
TJB
13607target.
13608
13609Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
13610to manipulate decimal floating point numbers, it is not possible to convert
13611(using a cast, for example) integers wider than 32-bit to decimal float.
13612
13613In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
13614point computations, error checking in decimal float operations ignores
13615underflow, overflow and divide by zero exceptions.
13616
4acd40f3 13617In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
99e008fe
EZ
13618to inspect @code{_Decimal128} values stored in floating point registers.
13619See @ref{PowerPC,,PowerPC} for more details.
4acd40f3 13620
6aecb9c2
JB
13621@node D
13622@subsection D
13623
13624@cindex D
13625@value{GDBN} can be used to debug programs written in D and compiled with
13626GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
13627specific feature --- dynamic arrays.
13628
a766d390
DE
13629@node Go
13630@subsection Go
13631
13632@cindex Go (programming language)
13633@value{GDBN} can be used to debug programs written in Go and compiled with
13634@file{gccgo} or @file{6g} compilers.
13635
13636Here is a summary of the Go-specific features and restrictions:
13637
13638@table @code
13639@cindex current Go package
13640@item The current Go package
13641The name of the current package does not need to be specified when
13642specifying global variables and functions.
13643
13644For example, given the program:
13645
13646@example
13647package main
13648var myglob = "Shall we?"
13649func main () @{
13650 // ...
13651@}
13652@end example
13653
13654When stopped inside @code{main} either of these work:
13655
13656@example
13657(gdb) p myglob
13658(gdb) p main.myglob
13659@end example
13660
13661@cindex builtin Go types
13662@item Builtin Go types
13663The @code{string} type is recognized by @value{GDBN} and is printed
13664as a string.
13665
13666@cindex builtin Go functions
13667@item Builtin Go functions
13668The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
13669function and handles it internally.
a766d390
DE
13670
13671@cindex restrictions on Go expressions
13672@item Restrictions on Go expressions
13673All Go operators are supported except @code{&^}.
13674The Go @code{_} ``blank identifier'' is not supported.
13675Automatic dereferencing of pointers is not supported.
50f042b9 13676@end table
a766d390 13677
b37303ee
AF
13678@node Objective-C
13679@subsection Objective-C
13680
13681@cindex Objective-C
13682This section provides information about some commands and command
721c2651
EZ
13683options that are useful for debugging Objective-C code. See also
13684@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
13685few more commands specific to Objective-C support.
b37303ee
AF
13686
13687@menu
b383017d
RM
13688* Method Names in Commands::
13689* The Print Command with Objective-C::
b37303ee
AF
13690@end menu
13691
c8f4133a 13692@node Method Names in Commands
b37303ee
AF
13693@subsubsection Method Names in Commands
13694
13695The following commands have been extended to accept Objective-C method
13696names as line specifications:
13697
13698@kindex clear@r{, and Objective-C}
13699@kindex break@r{, and Objective-C}
13700@kindex info line@r{, and Objective-C}
13701@kindex jump@r{, and Objective-C}
13702@kindex list@r{, and Objective-C}
13703@itemize
13704@item @code{clear}
13705@item @code{break}
13706@item @code{info line}
13707@item @code{jump}
13708@item @code{list}
13709@end itemize
13710
13711A fully qualified Objective-C method name is specified as
13712
13713@smallexample
13714-[@var{Class} @var{methodName}]
13715@end smallexample
13716
c552b3bb
JM
13717where the minus sign is used to indicate an instance method and a
13718plus sign (not shown) is used to indicate a class method. The class
13719name @var{Class} and method name @var{methodName} are enclosed in
13720brackets, similar to the way messages are specified in Objective-C
13721source code. For example, to set a breakpoint at the @code{create}
13722instance method of class @code{Fruit} in the program currently being
13723debugged, enter:
b37303ee
AF
13724
13725@smallexample
13726break -[Fruit create]
13727@end smallexample
13728
13729To list ten program lines around the @code{initialize} class method,
13730enter:
13731
13732@smallexample
13733list +[NSText initialize]
13734@end smallexample
13735
c552b3bb
JM
13736In the current version of @value{GDBN}, the plus or minus sign is
13737required. In future versions of @value{GDBN}, the plus or minus
13738sign will be optional, but you can use it to narrow the search. It
13739is also possible to specify just a method name:
b37303ee
AF
13740
13741@smallexample
13742break create
13743@end smallexample
13744
13745You must specify the complete method name, including any colons. If
13746your program's source files contain more than one @code{create} method,
13747you'll be presented with a numbered list of classes that implement that
13748method. Indicate your choice by number, or type @samp{0} to exit if
13749none apply.
13750
13751As another example, to clear a breakpoint established at the
13752@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
13753
13754@smallexample
13755clear -[NSWindow makeKeyAndOrderFront:]
13756@end smallexample
13757
13758@node The Print Command with Objective-C
13759@subsubsection The Print Command With Objective-C
721c2651 13760@cindex Objective-C, print objects
c552b3bb
JM
13761@kindex print-object
13762@kindex po @r{(@code{print-object})}
b37303ee 13763
c552b3bb 13764The print command has also been extended to accept methods. For example:
b37303ee
AF
13765
13766@smallexample
c552b3bb 13767print -[@var{object} hash]
b37303ee
AF
13768@end smallexample
13769
13770@cindex print an Objective-C object description
c552b3bb
JM
13771@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
13772@noindent
13773will tell @value{GDBN} to send the @code{hash} message to @var{object}
13774and print the result. Also, an additional command has been added,
13775@code{print-object} or @code{po} for short, which is meant to print
13776the description of an object. However, this command may only work
13777with certain Objective-C libraries that have a particular hook
13778function, @code{_NSPrintForDebugger}, defined.
b37303ee 13779
f4b8a18d
KW
13780@node OpenCL C
13781@subsection OpenCL C
13782
13783@cindex OpenCL C
13784This section provides information about @value{GDBN}s OpenCL C support.
13785
13786@menu
13787* OpenCL C Datatypes::
13788* OpenCL C Expressions::
13789* OpenCL C Operators::
13790@end menu
13791
13792@node OpenCL C Datatypes
13793@subsubsection OpenCL C Datatypes
13794
13795@cindex OpenCL C Datatypes
13796@value{GDBN} supports the builtin scalar and vector datatypes specified
13797by OpenCL 1.1. In addition the half- and double-precision floating point
13798data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
13799extensions are also known to @value{GDBN}.
13800
13801@node OpenCL C Expressions
13802@subsubsection OpenCL C Expressions
13803
13804@cindex OpenCL C Expressions
13805@value{GDBN} supports accesses to vector components including the access as
13806lvalue where possible. Since OpenCL C is based on C99 most C expressions
13807supported by @value{GDBN} can be used as well.
13808
13809@node OpenCL C Operators
13810@subsubsection OpenCL C Operators
13811
13812@cindex OpenCL C Operators
13813@value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
13814vector data types.
13815
09d4efe1
EZ
13816@node Fortran
13817@subsection Fortran
13818@cindex Fortran-specific support in @value{GDBN}
13819
814e32d7
WZ
13820@value{GDBN} can be used to debug programs written in Fortran, but it
13821currently supports only the features of Fortran 77 language.
13822
13823@cindex trailing underscore, in Fortran symbols
13824Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
13825among them) append an underscore to the names of variables and
13826functions. When you debug programs compiled by those compilers, you
13827will need to refer to variables and functions with a trailing
13828underscore.
13829
13830@menu
13831* Fortran Operators:: Fortran operators and expressions
13832* Fortran Defaults:: Default settings for Fortran
79a6e687 13833* Special Fortran Commands:: Special @value{GDBN} commands for Fortran
814e32d7
WZ
13834@end menu
13835
13836@node Fortran Operators
79a6e687 13837@subsubsection Fortran Operators and Expressions
814e32d7
WZ
13838
13839@cindex Fortran operators and expressions
13840
13841Operators must be defined on values of specific types. For instance,
13842@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 13843arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
13844
13845@table @code
13846@item **
99e008fe 13847The exponentiation operator. It raises the first operand to the power
814e32d7
WZ
13848of the second one.
13849
13850@item :
13851The range operator. Normally used in the form of array(low:high) to
13852represent a section of array.
68837c9d
MD
13853
13854@item %
13855The access component operator. Normally used to access elements in derived
13856types. Also suitable for unions. As unions aren't part of regular Fortran,
13857this can only happen when accessing a register that uses a gdbarch-defined
13858union type.
814e32d7
WZ
13859@end table
13860
13861@node Fortran Defaults
13862@subsubsection Fortran Defaults
13863
13864@cindex Fortran Defaults
13865
13866Fortran symbols are usually case-insensitive, so @value{GDBN} by
13867default uses case-insensitive matches for Fortran symbols. You can
13868change that with the @samp{set case-insensitive} command, see
13869@ref{Symbols}, for the details.
13870
79a6e687
BW
13871@node Special Fortran Commands
13872@subsubsection Special Fortran Commands
814e32d7
WZ
13873
13874@cindex Special Fortran commands
13875
db2e3e2e
BW
13876@value{GDBN} has some commands to support Fortran-specific features,
13877such as displaying common blocks.
814e32d7 13878
09d4efe1
EZ
13879@table @code
13880@cindex @code{COMMON} blocks, Fortran
13881@kindex info common
13882@item info common @r{[}@var{common-name}@r{]}
13883This command prints the values contained in the Fortran @code{COMMON}
13884block whose name is @var{common-name}. With no argument, the names of
d52fb0e9 13885all @code{COMMON} blocks visible at the current program location are
09d4efe1
EZ
13886printed.
13887@end table
13888
9c16f35a
EZ
13889@node Pascal
13890@subsection Pascal
13891
13892@cindex Pascal support in @value{GDBN}, limitations
13893Debugging Pascal programs which use sets, subranges, file variables, or
13894nested functions does not currently work. @value{GDBN} does not support
13895entering expressions, printing values, or similar features using Pascal
13896syntax.
13897
13898The Pascal-specific command @code{set print pascal_static-members}
13899controls whether static members of Pascal objects are displayed.
13900@xref{Print Settings, pascal_static-members}.
13901
09d4efe1 13902@node Modula-2
c906108c 13903@subsection Modula-2
7a292a7a 13904
d4f3574e 13905@cindex Modula-2, @value{GDBN} support
c906108c
SS
13906
13907The extensions made to @value{GDBN} to support Modula-2 only support
13908output from the @sc{gnu} Modula-2 compiler (which is currently being
13909developed). Other Modula-2 compilers are not currently supported, and
13910attempting to debug executables produced by them is most likely
13911to give an error as @value{GDBN} reads in the executable's symbol
13912table.
13913
13914@cindex expressions in Modula-2
13915@menu
13916* M2 Operators:: Built-in operators
13917* Built-In Func/Proc:: Built-in functions and procedures
13918* M2 Constants:: Modula-2 constants
72019c9c 13919* M2 Types:: Modula-2 types
c906108c
SS
13920* M2 Defaults:: Default settings for Modula-2
13921* Deviations:: Deviations from standard Modula-2
13922* M2 Checks:: Modula-2 type and range checks
13923* M2 Scope:: The scope operators @code{::} and @code{.}
13924* GDB/M2:: @value{GDBN} and Modula-2
13925@end menu
13926
6d2ebf8b 13927@node M2 Operators
c906108c
SS
13928@subsubsection Operators
13929@cindex Modula-2 operators
13930
13931Operators must be defined on values of specific types. For instance,
13932@code{+} is defined on numbers, but not on structures. Operators are
13933often defined on groups of types. For the purposes of Modula-2, the
13934following definitions hold:
13935
13936@itemize @bullet
13937
13938@item
13939@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
13940their subranges.
13941
13942@item
13943@emph{Character types} consist of @code{CHAR} and its subranges.
13944
13945@item
13946@emph{Floating-point types} consist of @code{REAL}.
13947
13948@item
13949@emph{Pointer types} consist of anything declared as @code{POINTER TO
13950@var{type}}.
13951
13952@item
13953@emph{Scalar types} consist of all of the above.
13954
13955@item
13956@emph{Set types} consist of @code{SET} and @code{BITSET} types.
13957
13958@item
13959@emph{Boolean types} consist of @code{BOOLEAN}.
13960@end itemize
13961
13962@noindent
13963The following operators are supported, and appear in order of
13964increasing precedence:
13965
13966@table @code
13967@item ,
13968Function argument or array index separator.
13969
13970@item :=
13971Assignment. The value of @var{var} @code{:=} @var{value} is
13972@var{value}.
13973
13974@item <@r{, }>
13975Less than, greater than on integral, floating-point, or enumerated
13976types.
13977
13978@item <=@r{, }>=
96a2c332 13979Less than or equal to, greater than or equal to
c906108c
SS
13980on integral, floating-point and enumerated types, or set inclusion on
13981set types. Same precedence as @code{<}.
13982
13983@item =@r{, }<>@r{, }#
13984Equality and two ways of expressing inequality, valid on scalar types.
13985Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
13986available for inequality, since @code{#} conflicts with the script
13987comment character.
13988
13989@item IN
13990Set membership. Defined on set types and the types of their members.
13991Same precedence as @code{<}.
13992
13993@item OR
13994Boolean disjunction. Defined on boolean types.
13995
13996@item AND@r{, }&
d4f3574e 13997Boolean conjunction. Defined on boolean types.
c906108c
SS
13998
13999@item @@
14000The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
14001
14002@item +@r{, }-
14003Addition and subtraction on integral and floating-point types, or union
14004and difference on set types.
14005
14006@item *
14007Multiplication on integral and floating-point types, or set intersection
14008on set types.
14009
14010@item /
14011Division on floating-point types, or symmetric set difference on set
14012types. Same precedence as @code{*}.
14013
14014@item DIV@r{, }MOD
14015Integer division and remainder. Defined on integral types. Same
14016precedence as @code{*}.
14017
14018@item -
99e008fe 14019Negative. Defined on @code{INTEGER} and @code{REAL} data.
c906108c
SS
14020
14021@item ^
14022Pointer dereferencing. Defined on pointer types.
14023
14024@item NOT
14025Boolean negation. Defined on boolean types. Same precedence as
14026@code{^}.
14027
14028@item .
14029@code{RECORD} field selector. Defined on @code{RECORD} data. Same
14030precedence as @code{^}.
14031
14032@item []
14033Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
14034
14035@item ()
14036Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
14037as @code{^}.
14038
14039@item ::@r{, }.
14040@value{GDBN} and Modula-2 scope operators.
14041@end table
14042
14043@quotation
72019c9c 14044@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
14045treats the use of the operator @code{IN}, or the use of operators
14046@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
14047@code{<=}, and @code{>=} on sets as an error.
14048@end quotation
14049
cb51c4e0 14050
6d2ebf8b 14051@node Built-In Func/Proc
79a6e687 14052@subsubsection Built-in Functions and Procedures
cb51c4e0 14053@cindex Modula-2 built-ins
c906108c
SS
14054
14055Modula-2 also makes available several built-in procedures and functions.
14056In describing these, the following metavariables are used:
14057
14058@table @var
14059
14060@item a
14061represents an @code{ARRAY} variable.
14062
14063@item c
14064represents a @code{CHAR} constant or variable.
14065
14066@item i
14067represents a variable or constant of integral type.
14068
14069@item m
14070represents an identifier that belongs to a set. Generally used in the
14071same function with the metavariable @var{s}. The type of @var{s} should
14072be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
14073
14074@item n
14075represents a variable or constant of integral or floating-point type.
14076
14077@item r
14078represents a variable or constant of floating-point type.
14079
14080@item t
14081represents a type.
14082
14083@item v
14084represents a variable.
14085
14086@item x
14087represents a variable or constant of one of many types. See the
14088explanation of the function for details.
14089@end table
14090
14091All Modula-2 built-in procedures also return a result, described below.
14092
14093@table @code
14094@item ABS(@var{n})
14095Returns the absolute value of @var{n}.
14096
14097@item CAP(@var{c})
14098If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 14099equivalent, otherwise it returns its argument.
c906108c
SS
14100
14101@item CHR(@var{i})
14102Returns the character whose ordinal value is @var{i}.
14103
14104@item DEC(@var{v})
c3f6f71d 14105Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
14106
14107@item DEC(@var{v},@var{i})
14108Decrements the value in the variable @var{v} by @var{i}. Returns the
14109new value.
14110
14111@item EXCL(@var{m},@var{s})
14112Removes the element @var{m} from the set @var{s}. Returns the new
14113set.
14114
14115@item FLOAT(@var{i})
14116Returns the floating point equivalent of the integer @var{i}.
14117
14118@item HIGH(@var{a})
14119Returns the index of the last member of @var{a}.
14120
14121@item INC(@var{v})
c3f6f71d 14122Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
14123
14124@item INC(@var{v},@var{i})
14125Increments the value in the variable @var{v} by @var{i}. Returns the
14126new value.
14127
14128@item INCL(@var{m},@var{s})
14129Adds the element @var{m} to the set @var{s} if it is not already
14130there. Returns the new set.
14131
14132@item MAX(@var{t})
14133Returns the maximum value of the type @var{t}.
14134
14135@item MIN(@var{t})
14136Returns the minimum value of the type @var{t}.
14137
14138@item ODD(@var{i})
14139Returns boolean TRUE if @var{i} is an odd number.
14140
14141@item ORD(@var{x})
14142Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
14143value of a character is its @sc{ascii} value (on machines supporting the
14144@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
14145integral, character and enumerated types.
14146
14147@item SIZE(@var{x})
14148Returns the size of its argument. @var{x} can be a variable or a type.
14149
14150@item TRUNC(@var{r})
14151Returns the integral part of @var{r}.
14152
844781a1
GM
14153@item TSIZE(@var{x})
14154Returns the size of its argument. @var{x} can be a variable or a type.
14155
c906108c
SS
14156@item VAL(@var{t},@var{i})
14157Returns the member of the type @var{t} whose ordinal value is @var{i}.
14158@end table
14159
14160@quotation
14161@emph{Warning:} Sets and their operations are not yet supported, so
14162@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
14163an error.
14164@end quotation
14165
14166@cindex Modula-2 constants
6d2ebf8b 14167@node M2 Constants
c906108c
SS
14168@subsubsection Constants
14169
14170@value{GDBN} allows you to express the constants of Modula-2 in the following
14171ways:
14172
14173@itemize @bullet
14174
14175@item
14176Integer constants are simply a sequence of digits. When used in an
14177expression, a constant is interpreted to be type-compatible with the
14178rest of the expression. Hexadecimal integers are specified by a
14179trailing @samp{H}, and octal integers by a trailing @samp{B}.
14180
14181@item
14182Floating point constants appear as a sequence of digits, followed by a
14183decimal point and another sequence of digits. An optional exponent can
14184then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
14185@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
14186digits of the floating point constant must be valid decimal (base 10)
14187digits.
14188
14189@item
14190Character constants consist of a single character enclosed by a pair of
14191like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 14192also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
14193followed by a @samp{C}.
14194
14195@item
14196String constants consist of a sequence of characters enclosed by a
14197pair of like quotes, either single (@code{'}) or double (@code{"}).
14198Escape sequences in the style of C are also allowed. @xref{C
79a6e687 14199Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
c906108c
SS
14200sequences.
14201
14202@item
14203Enumerated constants consist of an enumerated identifier.
14204
14205@item
14206Boolean constants consist of the identifiers @code{TRUE} and
14207@code{FALSE}.
14208
14209@item
14210Pointer constants consist of integral values only.
14211
14212@item
14213Set constants are not yet supported.
14214@end itemize
14215
72019c9c
GM
14216@node M2 Types
14217@subsubsection Modula-2 Types
14218@cindex Modula-2 types
14219
14220Currently @value{GDBN} can print the following data types in Modula-2
14221syntax: array types, record types, set types, pointer types, procedure
14222types, enumerated types, subrange types and base types. You can also
14223print the contents of variables declared using these type.
14224This section gives a number of simple source code examples together with
14225sample @value{GDBN} sessions.
14226
14227The first example contains the following section of code:
14228
14229@smallexample
14230VAR
14231 s: SET OF CHAR ;
14232 r: [20..40] ;
14233@end smallexample
14234
14235@noindent
14236and you can request @value{GDBN} to interrogate the type and value of
14237@code{r} and @code{s}.
14238
14239@smallexample
14240(@value{GDBP}) print s
14241@{'A'..'C', 'Z'@}
14242(@value{GDBP}) ptype s
14243SET OF CHAR
14244(@value{GDBP}) print r
1424521
14246(@value{GDBP}) ptype r
14247[20..40]
14248@end smallexample
14249
14250@noindent
14251Likewise if your source code declares @code{s} as:
14252
14253@smallexample
14254VAR
14255 s: SET ['A'..'Z'] ;
14256@end smallexample
14257
14258@noindent
14259then you may query the type of @code{s} by:
14260
14261@smallexample
14262(@value{GDBP}) ptype s
14263type = SET ['A'..'Z']
14264@end smallexample
14265
14266@noindent
14267Note that at present you cannot interactively manipulate set
14268expressions using the debugger.
14269
14270The following example shows how you might declare an array in Modula-2
14271and how you can interact with @value{GDBN} to print its type and contents:
14272
14273@smallexample
14274VAR
14275 s: ARRAY [-10..10] OF CHAR ;
14276@end smallexample
14277
14278@smallexample
14279(@value{GDBP}) ptype s
14280ARRAY [-10..10] OF CHAR
14281@end smallexample
14282
14283Note that the array handling is not yet complete and although the type
14284is printed correctly, expression handling still assumes that all
14285arrays have a lower bound of zero and not @code{-10} as in the example
844781a1 14286above.
72019c9c
GM
14287
14288Here are some more type related Modula-2 examples:
14289
14290@smallexample
14291TYPE
14292 colour = (blue, red, yellow, green) ;
14293 t = [blue..yellow] ;
14294VAR
14295 s: t ;
14296BEGIN
14297 s := blue ;
14298@end smallexample
14299
14300@noindent
14301The @value{GDBN} interaction shows how you can query the data type
14302and value of a variable.
14303
14304@smallexample
14305(@value{GDBP}) print s
14306$1 = blue
14307(@value{GDBP}) ptype t
14308type = [blue..yellow]
14309@end smallexample
14310
14311@noindent
14312In this example a Modula-2 array is declared and its contents
14313displayed. Observe that the contents are written in the same way as
14314their @code{C} counterparts.
14315
14316@smallexample
14317VAR
14318 s: ARRAY [1..5] OF CARDINAL ;
14319BEGIN
14320 s[1] := 1 ;
14321@end smallexample
14322
14323@smallexample
14324(@value{GDBP}) print s
14325$1 = @{1, 0, 0, 0, 0@}
14326(@value{GDBP}) ptype s
14327type = ARRAY [1..5] OF CARDINAL
14328@end smallexample
14329
14330The Modula-2 language interface to @value{GDBN} also understands
14331pointer types as shown in this example:
14332
14333@smallexample
14334VAR
14335 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
14336BEGIN
14337 NEW(s) ;
14338 s^[1] := 1 ;
14339@end smallexample
14340
14341@noindent
14342and you can request that @value{GDBN} describes the type of @code{s}.
14343
14344@smallexample
14345(@value{GDBP}) ptype s
14346type = POINTER TO ARRAY [1..5] OF CARDINAL
14347@end smallexample
14348
14349@value{GDBN} handles compound types as we can see in this example.
14350Here we combine array types, record types, pointer types and subrange
14351types:
14352
14353@smallexample
14354TYPE
14355 foo = RECORD
14356 f1: CARDINAL ;
14357 f2: CHAR ;
14358 f3: myarray ;
14359 END ;
14360
14361 myarray = ARRAY myrange OF CARDINAL ;
14362 myrange = [-2..2] ;
14363VAR
14364 s: POINTER TO ARRAY myrange OF foo ;
14365@end smallexample
14366
14367@noindent
14368and you can ask @value{GDBN} to describe the type of @code{s} as shown
14369below.
14370
14371@smallexample
14372(@value{GDBP}) ptype s
14373type = POINTER TO ARRAY [-2..2] OF foo = RECORD
14374 f1 : CARDINAL;
14375 f2 : CHAR;
14376 f3 : ARRAY [-2..2] OF CARDINAL;
14377END
14378@end smallexample
14379
6d2ebf8b 14380@node M2 Defaults
79a6e687 14381@subsubsection Modula-2 Defaults
c906108c
SS
14382@cindex Modula-2 defaults
14383
14384If type and range checking are set automatically by @value{GDBN}, they
14385both default to @code{on} whenever the working language changes to
d4f3574e 14386Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
14387selected the working language.
14388
14389If you allow @value{GDBN} to set the language automatically, then entering
14390code compiled from a file whose name ends with @file{.mod} sets the
79a6e687
BW
14391working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
14392Infer the Source Language}, for further details.
c906108c 14393
6d2ebf8b 14394@node Deviations
79a6e687 14395@subsubsection Deviations from Standard Modula-2
c906108c
SS
14396@cindex Modula-2, deviations from
14397
14398A few changes have been made to make Modula-2 programs easier to debug.
14399This is done primarily via loosening its type strictness:
14400
14401@itemize @bullet
14402@item
14403Unlike in standard Modula-2, pointer constants can be formed by
14404integers. This allows you to modify pointer variables during
14405debugging. (In standard Modula-2, the actual address contained in a
14406pointer variable is hidden from you; it can only be modified
14407through direct assignment to another pointer variable or expression that
14408returned a pointer.)
14409
14410@item
14411C escape sequences can be used in strings and characters to represent
14412non-printable characters. @value{GDBN} prints out strings with these
14413escape sequences embedded. Single non-printable characters are
14414printed using the @samp{CHR(@var{nnn})} format.
14415
14416@item
14417The assignment operator (@code{:=}) returns the value of its right-hand
14418argument.
14419
14420@item
14421All built-in procedures both modify @emph{and} return their argument.
14422@end itemize
14423
6d2ebf8b 14424@node M2 Checks
79a6e687 14425@subsubsection Modula-2 Type and Range Checks
c906108c
SS
14426@cindex Modula-2 checks
14427
14428@quotation
14429@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
14430range checking.
14431@end quotation
14432@c FIXME remove warning when type/range checks added
14433
14434@value{GDBN} considers two Modula-2 variables type equivalent if:
14435
14436@itemize @bullet
14437@item
14438They are of types that have been declared equivalent via a @code{TYPE
14439@var{t1} = @var{t2}} statement
14440
14441@item
14442They have been declared on the same line. (Note: This is true of the
14443@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
14444@end itemize
14445
14446As long as type checking is enabled, any attempt to combine variables
14447whose types are not equivalent is an error.
14448
14449Range checking is done on all mathematical operations, assignment, array
14450index bounds, and all built-in functions and procedures.
14451
6d2ebf8b 14452@node M2 Scope
79a6e687 14453@subsubsection The Scope Operators @code{::} and @code{.}
c906108c 14454@cindex scope
41afff9a 14455@cindex @code{.}, Modula-2 scope operator
c906108c
SS
14456@cindex colon, doubled as scope operator
14457@ifinfo
41afff9a 14458@vindex colon-colon@r{, in Modula-2}
c906108c
SS
14459@c Info cannot handle :: but TeX can.
14460@end ifinfo
a67ec3f4 14461@ifnotinfo
41afff9a 14462@vindex ::@r{, in Modula-2}
a67ec3f4 14463@end ifnotinfo
c906108c
SS
14464
14465There are a few subtle differences between the Modula-2 scope operator
14466(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
14467similar syntax:
14468
474c8240 14469@smallexample
c906108c
SS
14470
14471@var{module} . @var{id}
14472@var{scope} :: @var{id}
474c8240 14473@end smallexample
c906108c
SS
14474
14475@noindent
14476where @var{scope} is the name of a module or a procedure,
14477@var{module} the name of a module, and @var{id} is any declared
14478identifier within your program, except another module.
14479
14480Using the @code{::} operator makes @value{GDBN} search the scope
14481specified by @var{scope} for the identifier @var{id}. If it is not
14482found in the specified scope, then @value{GDBN} searches all scopes
14483enclosing the one specified by @var{scope}.
14484
14485Using the @code{.} operator makes @value{GDBN} search the current scope for
14486the identifier specified by @var{id} that was imported from the
14487definition module specified by @var{module}. With this operator, it is
14488an error if the identifier @var{id} was not imported from definition
14489module @var{module}, or if @var{id} is not an identifier in
14490@var{module}.
14491
6d2ebf8b 14492@node GDB/M2
c906108c
SS
14493@subsubsection @value{GDBN} and Modula-2
14494
14495Some @value{GDBN} commands have little use when debugging Modula-2 programs.
14496Five subcommands of @code{set print} and @code{show print} apply
b37052ae 14497specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 14498@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 14499apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
14500analogue in Modula-2.
14501
14502The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 14503with any language, is not useful with Modula-2. Its
c906108c 14504intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 14505created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 14506address can be specified by an integral constant, the construct
d4f3574e 14507@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
14508
14509@cindex @code{#} in Modula-2
14510In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
14511interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 14512
e07c999f
PH
14513@node Ada
14514@subsection Ada
14515@cindex Ada
14516
14517The extensions made to @value{GDBN} for Ada only support
14518output from the @sc{gnu} Ada (GNAT) compiler.
14519Other Ada compilers are not currently supported, and
14520attempting to debug executables produced by them is most likely
14521to be difficult.
14522
14523
14524@cindex expressions in Ada
14525@menu
14526* Ada Mode Intro:: General remarks on the Ada syntax
14527 and semantics supported by Ada mode
14528 in @value{GDBN}.
14529* Omissions from Ada:: Restrictions on the Ada expression syntax.
14530* Additions to Ada:: Extensions of the Ada expression syntax.
14531* Stopping Before Main Program:: Debugging the program during elaboration.
20924a55
JB
14532* Ada Tasks:: Listing and setting breakpoints in tasks.
14533* Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
6e1bb179
JB
14534* Ravenscar Profile:: Tasking Support when using the Ravenscar
14535 Profile
e07c999f
PH
14536* Ada Glitches:: Known peculiarities of Ada mode.
14537@end menu
14538
14539@node Ada Mode Intro
14540@subsubsection Introduction
14541@cindex Ada mode, general
14542
14543The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
14544syntax, with some extensions.
14545The philosophy behind the design of this subset is
14546
14547@itemize @bullet
14548@item
14549That @value{GDBN} should provide basic literals and access to operations for
14550arithmetic, dereferencing, field selection, indexing, and subprogram calls,
14551leaving more sophisticated computations to subprograms written into the
14552program (which therefore may be called from @value{GDBN}).
14553
14554@item
14555That type safety and strict adherence to Ada language restrictions
14556are not particularly important to the @value{GDBN} user.
14557
14558@item
14559That brevity is important to the @value{GDBN} user.
14560@end itemize
14561
f3a2dd1a
JB
14562Thus, for brevity, the debugger acts as if all names declared in
14563user-written packages are directly visible, even if they are not visible
14564according to Ada rules, thus making it unnecessary to fully qualify most
14565names with their packages, regardless of context. Where this causes
14566ambiguity, @value{GDBN} asks the user's intent.
e07c999f
PH
14567
14568The debugger will start in Ada mode if it detects an Ada main program.
14569As for other languages, it will enter Ada mode when stopped in a program that
14570was translated from an Ada source file.
14571
14572While in Ada mode, you may use `@t{--}' for comments. This is useful
14573mostly for documenting command files. The standard @value{GDBN} comment
14574(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
14575middle (to allow based literals).
14576
14577The debugger supports limited overloading. Given a subprogram call in which
14578the function symbol has multiple definitions, it will use the number of
14579actual parameters and some information about their types to attempt to narrow
14580the set of definitions. It also makes very limited use of context, preferring
14581procedures to functions in the context of the @code{call} command, and
14582functions to procedures elsewhere.
14583
14584@node Omissions from Ada
14585@subsubsection Omissions from Ada
14586@cindex Ada, omissions from
14587
14588Here are the notable omissions from the subset:
14589
14590@itemize @bullet
14591@item
14592Only a subset of the attributes are supported:
14593
14594@itemize @minus
14595@item
14596@t{'First}, @t{'Last}, and @t{'Length}
14597 on array objects (not on types and subtypes).
14598
14599@item
14600@t{'Min} and @t{'Max}.
14601
14602@item
14603@t{'Pos} and @t{'Val}.
14604
14605@item
14606@t{'Tag}.
14607
14608@item
14609@t{'Range} on array objects (not subtypes), but only as the right
14610operand of the membership (@code{in}) operator.
14611
14612@item
14613@t{'Access}, @t{'Unchecked_Access}, and
14614@t{'Unrestricted_Access} (a GNAT extension).
14615
14616@item
14617@t{'Address}.
14618@end itemize
14619
14620@item
14621The names in
14622@code{Characters.Latin_1} are not available and
14623concatenation is not implemented. Thus, escape characters in strings are
14624not currently available.
14625
14626@item
14627Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
14628equality of representations. They will generally work correctly
14629for strings and arrays whose elements have integer or enumeration types.
14630They may not work correctly for arrays whose element
14631types have user-defined equality, for arrays of real values
14632(in particular, IEEE-conformant floating point, because of negative
14633zeroes and NaNs), and for arrays whose elements contain unused bits with
14634indeterminate values.
14635
14636@item
14637The other component-by-component array operations (@code{and}, @code{or},
14638@code{xor}, @code{not}, and relational tests other than equality)
14639are not implemented.
14640
14641@item
860701dc
PH
14642@cindex array aggregates (Ada)
14643@cindex record aggregates (Ada)
14644@cindex aggregates (Ada)
14645There is limited support for array and record aggregates. They are
14646permitted only on the right sides of assignments, as in these examples:
14647
14648@smallexample
077e0a52
JB
14649(@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
14650(@value{GDBP}) set An_Array := (1, others => 0)
14651(@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
14652(@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
14653(@value{GDBP}) set A_Record := (1, "Peter", True);
14654(@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
860701dc
PH
14655@end smallexample
14656
14657Changing a
14658discriminant's value by assigning an aggregate has an
14659undefined effect if that discriminant is used within the record.
14660However, you can first modify discriminants by directly assigning to
14661them (which normally would not be allowed in Ada), and then performing an
14662aggregate assignment. For example, given a variable @code{A_Rec}
14663declared to have a type such as:
14664
14665@smallexample
14666type Rec (Len : Small_Integer := 0) is record
14667 Id : Integer;
14668 Vals : IntArray (1 .. Len);
14669end record;
14670@end smallexample
14671
14672you can assign a value with a different size of @code{Vals} with two
14673assignments:
14674
14675@smallexample
077e0a52
JB
14676(@value{GDBP}) set A_Rec.Len := 4
14677(@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
860701dc
PH
14678@end smallexample
14679
14680As this example also illustrates, @value{GDBN} is very loose about the usual
14681rules concerning aggregates. You may leave out some of the
14682components of an array or record aggregate (such as the @code{Len}
14683component in the assignment to @code{A_Rec} above); they will retain their
14684original values upon assignment. You may freely use dynamic values as
14685indices in component associations. You may even use overlapping or
14686redundant component associations, although which component values are
14687assigned in such cases is not defined.
e07c999f
PH
14688
14689@item
14690Calls to dispatching subprograms are not implemented.
14691
14692@item
14693The overloading algorithm is much more limited (i.e., less selective)
ae21e955
BW
14694than that of real Ada. It makes only limited use of the context in
14695which a subexpression appears to resolve its meaning, and it is much
14696looser in its rules for allowing type matches. As a result, some
14697function calls will be ambiguous, and the user will be asked to choose
14698the proper resolution.
e07c999f
PH
14699
14700@item
14701The @code{new} operator is not implemented.
14702
14703@item
14704Entry calls are not implemented.
14705
14706@item
14707Aside from printing, arithmetic operations on the native VAX floating-point
14708formats are not supported.
14709
14710@item
14711It is not possible to slice a packed array.
158c7665
PH
14712
14713@item
14714The names @code{True} and @code{False}, when not part of a qualified name,
14715are interpreted as if implicitly prefixed by @code{Standard}, regardless of
14716context.
14717Should your program
14718redefine these names in a package or procedure (at best a dubious practice),
14719you will have to use fully qualified names to access their new definitions.
e07c999f
PH
14720@end itemize
14721
14722@node Additions to Ada
14723@subsubsection Additions to Ada
14724@cindex Ada, deviations from
14725
14726As it does for other languages, @value{GDBN} makes certain generic
14727extensions to Ada (@pxref{Expressions}):
14728
14729@itemize @bullet
14730@item
ae21e955
BW
14731If the expression @var{E} is a variable residing in memory (typically
14732a local variable or array element) and @var{N} is a positive integer,
14733then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
14734@var{N}-1 adjacent variables following it in memory as an array. In
14735Ada, this operator is generally not necessary, since its prime use is
14736in displaying parts of an array, and slicing will usually do this in
14737Ada. However, there are occasional uses when debugging programs in
14738which certain debugging information has been optimized away.
e07c999f
PH
14739
14740@item
ae21e955
BW
14741@code{@var{B}::@var{var}} means ``the variable named @var{var} that
14742appears in function or file @var{B}.'' When @var{B} is a file name,
14743you must typically surround it in single quotes.
e07c999f
PH
14744
14745@item
14746The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
14747@var{type} that appears at address @var{addr}.''
14748
14749@item
14750A name starting with @samp{$} is a convenience variable
14751(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
14752@end itemize
14753
ae21e955
BW
14754In addition, @value{GDBN} provides a few other shortcuts and outright
14755additions specific to Ada:
e07c999f
PH
14756
14757@itemize @bullet
14758@item
14759The assignment statement is allowed as an expression, returning
14760its right-hand operand as its value. Thus, you may enter
14761
14762@smallexample
077e0a52
JB
14763(@value{GDBP}) set x := y + 3
14764(@value{GDBP}) print A(tmp := y + 1)
e07c999f
PH
14765@end smallexample
14766
14767@item
14768The semicolon is allowed as an ``operator,'' returning as its value
14769the value of its right-hand operand.
14770This allows, for example,
14771complex conditional breaks:
14772
14773@smallexample
077e0a52
JB
14774(@value{GDBP}) break f
14775(@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
e07c999f
PH
14776@end smallexample
14777
14778@item
14779Rather than use catenation and symbolic character names to introduce special
14780characters into strings, one may instead use a special bracket notation,
14781which is also used to print strings. A sequence of characters of the form
14782@samp{["@var{XX}"]} within a string or character literal denotes the
14783(single) character whose numeric encoding is @var{XX} in hexadecimal. The
14784sequence of characters @samp{["""]} also denotes a single quotation mark
14785in strings. For example,
14786@smallexample
14787 "One line.["0a"]Next line.["0a"]"
14788@end smallexample
14789@noindent
ae21e955
BW
14790contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
14791after each period.
e07c999f
PH
14792
14793@item
14794The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
14795@t{'Max} is optional (and is ignored in any case). For example, it is valid
14796to write
14797
14798@smallexample
077e0a52 14799(@value{GDBP}) print 'max(x, y)
e07c999f
PH
14800@end smallexample
14801
14802@item
14803When printing arrays, @value{GDBN} uses positional notation when the
14804array has a lower bound of 1, and uses a modified named notation otherwise.
ae21e955
BW
14805For example, a one-dimensional array of three integers with a lower bound
14806of 3 might print as
e07c999f
PH
14807
14808@smallexample
14809(3 => 10, 17, 1)
14810@end smallexample
14811
14812@noindent
14813That is, in contrast to valid Ada, only the first component has a @code{=>}
14814clause.
14815
14816@item
14817You may abbreviate attributes in expressions with any unique,
14818multi-character subsequence of
14819their names (an exact match gets preference).
14820For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
14821in place of @t{a'length}.
14822
14823@item
14824@cindex quoting Ada internal identifiers
14825Since Ada is case-insensitive, the debugger normally maps identifiers you type
14826to lower case. The GNAT compiler uses upper-case characters for
14827some of its internal identifiers, which are normally of no interest to users.
14828For the rare occasions when you actually have to look at them,
14829enclose them in angle brackets to avoid the lower-case mapping.
14830For example,
14831@smallexample
077e0a52 14832(@value{GDBP}) print <JMPBUF_SAVE>[0]
e07c999f
PH
14833@end smallexample
14834
14835@item
14836Printing an object of class-wide type or dereferencing an
14837access-to-class-wide value will display all the components of the object's
14838specific type (as indicated by its run-time tag). Likewise, component
14839selection on such a value will operate on the specific type of the
14840object.
14841
14842@end itemize
14843
14844@node Stopping Before Main Program
14845@subsubsection Stopping at the Very Beginning
14846
14847@cindex breakpointing Ada elaboration code
14848It is sometimes necessary to debug the program during elaboration, and
14849before reaching the main procedure.
14850As defined in the Ada Reference
14851Manual, the elaboration code is invoked from a procedure called
14852@code{adainit}. To run your program up to the beginning of
14853elaboration, simply use the following two commands:
14854@code{tbreak adainit} and @code{run}.
14855
20924a55
JB
14856@node Ada Tasks
14857@subsubsection Extensions for Ada Tasks
14858@cindex Ada, tasking
14859
14860Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
14861@value{GDBN} provides the following task-related commands:
14862
14863@table @code
14864@kindex info tasks
14865@item info tasks
14866This command shows a list of current Ada tasks, as in the following example:
14867
14868
14869@smallexample
14870@iftex
14871@leftskip=0.5cm
14872@end iftex
14873(@value{GDBP}) info tasks
14874 ID TID P-ID Pri State Name
14875 1 8088000 0 15 Child Activation Wait main_task
14876 2 80a4000 1 15 Accept Statement b
14877 3 809a800 1 15 Child Activation Wait a
32cd1edc 14878* 4 80ae800 3 15 Runnable c
20924a55
JB
14879
14880@end smallexample
14881
14882@noindent
14883In this listing, the asterisk before the last task indicates it to be the
14884task currently being inspected.
14885
14886@table @asis
14887@item ID
14888Represents @value{GDBN}'s internal task number.
14889
14890@item TID
14891The Ada task ID.
14892
14893@item P-ID
14894The parent's task ID (@value{GDBN}'s internal task number).
14895
14896@item Pri
14897The base priority of the task.
14898
14899@item State
14900Current state of the task.
14901
14902@table @code
14903@item Unactivated
14904The task has been created but has not been activated. It cannot be
14905executing.
14906
20924a55
JB
14907@item Runnable
14908The task is not blocked for any reason known to Ada. (It may be waiting
14909for a mutex, though.) It is conceptually "executing" in normal mode.
14910
14911@item Terminated
14912The task is terminated, in the sense of ARM 9.3 (5). Any dependents
14913that were waiting on terminate alternatives have been awakened and have
14914terminated themselves.
14915
14916@item Child Activation Wait
14917The task is waiting for created tasks to complete activation.
14918
14919@item Accept Statement
14920The task is waiting on an accept or selective wait statement.
14921
14922@item Waiting on entry call
14923The task is waiting on an entry call.
14924
14925@item Async Select Wait
14926The task is waiting to start the abortable part of an asynchronous
14927select statement.
14928
14929@item Delay Sleep
14930The task is waiting on a select statement with only a delay
14931alternative open.
14932
14933@item Child Termination Wait
14934The task is sleeping having completed a master within itself, and is
14935waiting for the tasks dependent on that master to become terminated or
14936waiting on a terminate Phase.
14937
14938@item Wait Child in Term Alt
14939The task is sleeping waiting for tasks on terminate alternatives to
14940finish terminating.
14941
14942@item Accepting RV with @var{taskno}
14943The task is accepting a rendez-vous with the task @var{taskno}.
14944@end table
14945
14946@item Name
14947Name of the task in the program.
14948
14949@end table
14950
14951@kindex info task @var{taskno}
14952@item info task @var{taskno}
14953This command shows detailled informations on the specified task, as in
14954the following example:
14955@smallexample
14956@iftex
14957@leftskip=0.5cm
14958@end iftex
14959(@value{GDBP}) info tasks
14960 ID TID P-ID Pri State Name
14961 1 8077880 0 15 Child Activation Wait main_task
32cd1edc 14962* 2 807c468 1 15 Runnable task_1
20924a55
JB
14963(@value{GDBP}) info task 2
14964Ada Task: 0x807c468
14965Name: task_1
14966Thread: 0x807f378
14967Parent: 1 (main_task)
14968Base Priority: 15
14969State: Runnable
14970@end smallexample
14971
14972@item task
14973@kindex task@r{ (Ada)}
14974@cindex current Ada task ID
14975This command prints the ID of the current task.
14976
14977@smallexample
14978@iftex
14979@leftskip=0.5cm
14980@end iftex
14981(@value{GDBP}) info tasks
14982 ID TID P-ID Pri State Name
14983 1 8077870 0 15 Child Activation Wait main_task
32cd1edc 14984* 2 807c458 1 15 Runnable t
20924a55
JB
14985(@value{GDBP}) task
14986[Current task is 2]
14987@end smallexample
14988
14989@item task @var{taskno}
14990@cindex Ada task switching
14991This command is like the @code{thread @var{threadno}}
14992command (@pxref{Threads}). It switches the context of debugging
14993from the current task to the given task.
14994
14995@smallexample
14996@iftex
14997@leftskip=0.5cm
14998@end iftex
14999(@value{GDBP}) info tasks
15000 ID TID P-ID Pri State Name
15001 1 8077870 0 15 Child Activation Wait main_task
32cd1edc 15002* 2 807c458 1 15 Runnable t
20924a55
JB
15003(@value{GDBP}) task 1
15004[Switching to task 1]
15005#0 0x8067726 in pthread_cond_wait ()
15006(@value{GDBP}) bt
15007#0 0x8067726 in pthread_cond_wait ()
15008#1 0x8056714 in system.os_interface.pthread_cond_wait ()
15009#2 0x805cb63 in system.task_primitives.operations.sleep ()
15010#3 0x806153e in system.tasking.stages.activate_tasks ()
15011#4 0x804aacc in un () at un.adb:5
15012@end smallexample
15013
45ac276d
JB
15014@item break @var{linespec} task @var{taskno}
15015@itemx break @var{linespec} task @var{taskno} if @dots{}
15016@cindex breakpoints and tasks, in Ada
15017@cindex task breakpoints, in Ada
15018@kindex break @dots{} task @var{taskno}@r{ (Ada)}
15019These commands are like the @code{break @dots{} thread @dots{}}
15020command (@pxref{Thread Stops}).
15021@var{linespec} specifies source lines, as described
15022in @ref{Specify Location}.
15023
15024Use the qualifier @samp{task @var{taskno}} with a breakpoint command
15025to specify that you only want @value{GDBN} to stop the program when a
15026particular Ada task reaches this breakpoint. @var{taskno} is one of the
15027numeric task identifiers assigned by @value{GDBN}, shown in the first
15028column of the @samp{info tasks} display.
15029
15030If you do not specify @samp{task @var{taskno}} when you set a
15031breakpoint, the breakpoint applies to @emph{all} tasks of your
15032program.
15033
15034You can use the @code{task} qualifier on conditional breakpoints as
15035well; in this case, place @samp{task @var{taskno}} before the
15036breakpoint condition (before the @code{if}).
15037
15038For example,
15039
15040@smallexample
15041@iftex
15042@leftskip=0.5cm
15043@end iftex
15044(@value{GDBP}) info tasks
15045 ID TID P-ID Pri State Name
15046 1 140022020 0 15 Child Activation Wait main_task
15047 2 140045060 1 15 Accept/Select Wait t2
15048 3 140044840 1 15 Runnable t1
15049* 4 140056040 1 15 Runnable t3
15050(@value{GDBP}) b 15 task 2
15051Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
15052(@value{GDBP}) cont
15053Continuing.
15054task # 1 running
15055task # 2 running
15056
15057Breakpoint 5, test_task_debug () at test_task_debug.adb:15
1505815 flush;
15059(@value{GDBP}) info tasks
15060 ID TID P-ID Pri State Name
15061 1 140022020 0 15 Child Activation Wait main_task
15062* 2 140045060 1 15 Runnable t2
15063 3 140044840 1 15 Runnable t1
15064 4 140056040 1 15 Delay Sleep t3
15065@end smallexample
20924a55
JB
15066@end table
15067
15068@node Ada Tasks and Core Files
15069@subsubsection Tasking Support when Debugging Core Files
15070@cindex Ada tasking and core file debugging
15071
15072When inspecting a core file, as opposed to debugging a live program,
15073tasking support may be limited or even unavailable, depending on
15074the platform being used.
15075For instance, on x86-linux, the list of tasks is available, but task
15076switching is not supported. On Tru64, however, task switching will work
15077as usual.
15078
15079On certain platforms, including Tru64, the debugger needs to perform some
15080memory writes in order to provide Ada tasking support. When inspecting
15081a core file, this means that the core file must be opened with read-write
15082privileges, using the command @samp{"set write on"} (@pxref{Patching}).
15083Under these circumstances, you should make a backup copy of the core
15084file before inspecting it with @value{GDBN}.
15085
6e1bb179
JB
15086@node Ravenscar Profile
15087@subsubsection Tasking Support when using the Ravenscar Profile
15088@cindex Ravenscar Profile
15089
15090The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
15091specifically designed for systems with safety-critical real-time
15092requirements.
15093
15094@table @code
15095@kindex set ravenscar task-switching on
15096@cindex task switching with program using Ravenscar Profile
15097@item set ravenscar task-switching on
15098Allows task switching when debugging a program that uses the Ravenscar
15099Profile. This is the default.
15100
15101@kindex set ravenscar task-switching off
15102@item set ravenscar task-switching off
15103Turn off task switching when debugging a program that uses the Ravenscar
15104Profile. This is mostly intended to disable the code that adds support
15105for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
15106the Ravenscar runtime is preventing @value{GDBN} from working properly.
15107To be effective, this command should be run before the program is started.
15108
15109@kindex show ravenscar task-switching
15110@item show ravenscar task-switching
15111Show whether it is possible to switch from task to task in a program
15112using the Ravenscar Profile.
15113
15114@end table
15115
e07c999f
PH
15116@node Ada Glitches
15117@subsubsection Known Peculiarities of Ada Mode
15118@cindex Ada, problems
15119
15120Besides the omissions listed previously (@pxref{Omissions from Ada}),
15121we know of several problems with and limitations of Ada mode in
15122@value{GDBN},
15123some of which will be fixed with planned future releases of the debugger
15124and the GNU Ada compiler.
15125
15126@itemize @bullet
e07c999f
PH
15127@item
15128Static constants that the compiler chooses not to materialize as objects in
15129storage are invisible to the debugger.
15130
15131@item
15132Named parameter associations in function argument lists are ignored (the
15133argument lists are treated as positional).
15134
15135@item
15136Many useful library packages are currently invisible to the debugger.
15137
15138@item
15139Fixed-point arithmetic, conversions, input, and output is carried out using
15140floating-point arithmetic, and may give results that only approximate those on
15141the host machine.
15142
e07c999f
PH
15143@item
15144The GNAT compiler never generates the prefix @code{Standard} for any of
15145the standard symbols defined by the Ada language. @value{GDBN} knows about
15146this: it will strip the prefix from names when you use it, and will never
15147look for a name you have so qualified among local symbols, nor match against
15148symbols in other packages or subprograms. If you have
15149defined entities anywhere in your program other than parameters and
15150local variables whose simple names match names in @code{Standard},
15151GNAT's lack of qualification here can cause confusion. When this happens,
15152you can usually resolve the confusion
15153by qualifying the problematic names with package
15154@code{Standard} explicitly.
15155@end itemize
15156
95433b34
JB
15157Older versions of the compiler sometimes generate erroneous debugging
15158information, resulting in the debugger incorrectly printing the value
15159of affected entities. In some cases, the debugger is able to work
15160around an issue automatically. In other cases, the debugger is able
15161to work around the issue, but the work-around has to be specifically
15162enabled.
15163
15164@kindex set ada trust-PAD-over-XVS
15165@kindex show ada trust-PAD-over-XVS
15166@table @code
15167
15168@item set ada trust-PAD-over-XVS on
15169Configure GDB to strictly follow the GNAT encoding when computing the
15170value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
15171types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
15172a complete description of the encoding used by the GNAT compiler).
15173This is the default.
15174
15175@item set ada trust-PAD-over-XVS off
15176This is related to the encoding using by the GNAT compiler. If @value{GDBN}
15177sometimes prints the wrong value for certain entities, changing @code{ada
15178trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
15179the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
15180@code{off}, but this incurs a slight performance penalty, so it is
15181recommended to leave this setting to @code{on} unless necessary.
15182
15183@end table
15184
79a6e687
BW
15185@node Unsupported Languages
15186@section Unsupported Languages
4e562065
JB
15187
15188@cindex unsupported languages
15189@cindex minimal language
15190In addition to the other fully-supported programming languages,
15191@value{GDBN} also provides a pseudo-language, called @code{minimal}.
15192It does not represent a real programming language, but provides a set
15193of capabilities close to what the C or assembly languages provide.
15194This should allow most simple operations to be performed while debugging
15195an application that uses a language currently not supported by @value{GDBN}.
15196
15197If the language is set to @code{auto}, @value{GDBN} will automatically
15198select this language if the current frame corresponds to an unsupported
15199language.
15200
6d2ebf8b 15201@node Symbols
c906108c
SS
15202@chapter Examining the Symbol Table
15203
d4f3574e 15204The commands described in this chapter allow you to inquire about the
c906108c
SS
15205symbols (names of variables, functions and types) defined in your
15206program. This information is inherent in the text of your program and
15207does not change as your program executes. @value{GDBN} finds it in your
15208program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
15209(@pxref{File Options, ,Choosing Files}), or by one of the
15210file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
15211
15212@cindex symbol names
15213@cindex names of symbols
15214@cindex quoting names
15215Occasionally, you may need to refer to symbols that contain unusual
15216characters, which @value{GDBN} ordinarily treats as word delimiters. The
15217most frequent case is in referring to static variables in other
79a6e687 15218source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
15219are recorded in object files as debugging symbols, but @value{GDBN} would
15220ordinarily parse a typical file name, like @file{foo.c}, as the three words
15221@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
15222@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
15223
474c8240 15224@smallexample
c906108c 15225p 'foo.c'::x
474c8240 15226@end smallexample
c906108c
SS
15227
15228@noindent
15229looks up the value of @code{x} in the scope of the file @file{foo.c}.
15230
15231@table @code
a8f24a35
EZ
15232@cindex case-insensitive symbol names
15233@cindex case sensitivity in symbol names
15234@kindex set case-sensitive
15235@item set case-sensitive on
15236@itemx set case-sensitive off
15237@itemx set case-sensitive auto
15238Normally, when @value{GDBN} looks up symbols, it matches their names
15239with case sensitivity determined by the current source language.
15240Occasionally, you may wish to control that. The command @code{set
15241case-sensitive} lets you do that by specifying @code{on} for
15242case-sensitive matches or @code{off} for case-insensitive ones. If
15243you specify @code{auto}, case sensitivity is reset to the default
15244suitable for the source language. The default is case-sensitive
15245matches for all languages except for Fortran, for which the default is
15246case-insensitive matches.
15247
9c16f35a
EZ
15248@kindex show case-sensitive
15249@item show case-sensitive
a8f24a35
EZ
15250This command shows the current setting of case sensitivity for symbols
15251lookups.
15252
53342f27
TT
15253@kindex set print type methods
15254@item set print type methods
15255@itemx set print type methods on
15256@itemx set print type methods off
15257Normally, when @value{GDBN} prints a class, it displays any methods
15258declared in that class. You can control this behavior either by
15259passing the appropriate flag to @code{ptype}, or using @command{set
15260print type methods}. Specifying @code{on} will cause @value{GDBN} to
15261display the methods; this is the default. Specifying @code{off} will
15262cause @value{GDBN} to omit the methods.
15263
15264@kindex show print type methods
15265@item show print type methods
15266This command shows the current setting of method display when printing
15267classes.
15268
15269@kindex set print type typedefs
15270@item set print type typedefs
15271@itemx set print type typedefs on
15272@itemx set print type typedefs off
15273
15274Normally, when @value{GDBN} prints a class, it displays any typedefs
15275defined in that class. You can control this behavior either by
15276passing the appropriate flag to @code{ptype}, or using @command{set
15277print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
15278display the typedef definitions; this is the default. Specifying
15279@code{off} will cause @value{GDBN} to omit the typedef definitions.
15280Note that this controls whether the typedef definition itself is
15281printed, not whether typedef names are substituted when printing other
15282types.
15283
15284@kindex show print type typedefs
15285@item show print type typedefs
15286This command shows the current setting of typedef display when
15287printing classes.
15288
c906108c 15289@kindex info address
b37052ae 15290@cindex address of a symbol
c906108c
SS
15291@item info address @var{symbol}
15292Describe where the data for @var{symbol} is stored. For a register
15293variable, this says which register it is kept in. For a non-register
15294local variable, this prints the stack-frame offset at which the variable
15295is always stored.
15296
15297Note the contrast with @samp{print &@var{symbol}}, which does not work
15298at all for a register variable, and for a stack local variable prints
15299the exact address of the current instantiation of the variable.
15300
3d67e040 15301@kindex info symbol
b37052ae 15302@cindex symbol from address
9c16f35a 15303@cindex closest symbol and offset for an address
3d67e040
EZ
15304@item info symbol @var{addr}
15305Print the name of a symbol which is stored at the address @var{addr}.
15306If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
15307nearest symbol and an offset from it:
15308
474c8240 15309@smallexample
3d67e040
EZ
15310(@value{GDBP}) info symbol 0x54320
15311_initialize_vx + 396 in section .text
474c8240 15312@end smallexample
3d67e040
EZ
15313
15314@noindent
15315This is the opposite of the @code{info address} command. You can use
15316it to find out the name of a variable or a function given its address.
15317
c14c28ba
PP
15318For dynamically linked executables, the name of executable or shared
15319library containing the symbol is also printed:
15320
15321@smallexample
15322(@value{GDBP}) info symbol 0x400225
15323_start + 5 in section .text of /tmp/a.out
15324(@value{GDBP}) info symbol 0x2aaaac2811cf
15325__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
15326@end smallexample
15327
c906108c 15328@kindex whatis
53342f27 15329@item whatis[/@var{flags}] [@var{arg}]
177bc839
JK
15330Print the data type of @var{arg}, which can be either an expression
15331or a name of a data type. With no argument, print the data type of
15332@code{$}, the last value in the value history.
15333
15334If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
15335is not actually evaluated, and any side-effecting operations (such as
15336assignments or function calls) inside it do not take place.
15337
15338If @var{arg} is a variable or an expression, @code{whatis} prints its
15339literal type as it is used in the source code. If the type was
15340defined using a @code{typedef}, @code{whatis} will @emph{not} print
15341the data type underlying the @code{typedef}. If the type of the
15342variable or the expression is a compound data type, such as
15343@code{struct} or @code{class}, @code{whatis} never prints their
15344fields or methods. It just prints the @code{struct}/@code{class}
15345name (a.k.a.@: its @dfn{tag}). If you want to see the members of
15346such a compound data type, use @code{ptype}.
15347
15348If @var{arg} is a type name that was defined using @code{typedef},
15349@code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
15350Unrolling means that @code{whatis} will show the underlying type used
15351in the @code{typedef} declaration of @var{arg}. However, if that
15352underlying type is also a @code{typedef}, @code{whatis} will not
15353unroll it.
15354
15355For C code, the type names may also have the form @samp{class
15356@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
15357@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 15358
53342f27
TT
15359@var{flags} can be used to modify how the type is displayed.
15360Available flags are:
15361
15362@table @code
15363@item r
15364Display in ``raw'' form. Normally, @value{GDBN} substitutes template
15365parameters and typedefs defined in a class when printing the class'
15366members. The @code{/r} flag disables this.
15367
15368@item m
15369Do not print methods defined in the class.
15370
15371@item M
15372Print methods defined in the class. This is the default, but the flag
15373exists in case you change the default with @command{set print type methods}.
15374
15375@item t
15376Do not print typedefs defined in the class. Note that this controls
15377whether the typedef definition itself is printed, not whether typedef
15378names are substituted when printing other types.
15379
15380@item T
15381Print typedefs defined in the class. This is the default, but the flag
15382exists in case you change the default with @command{set print type typedefs}.
15383@end table
15384
c906108c 15385@kindex ptype
53342f27 15386@item ptype[/@var{flags}] [@var{arg}]
62f3a2ba
FF
15387@code{ptype} accepts the same arguments as @code{whatis}, but prints a
15388detailed description of the type, instead of just the name of the type.
15389@xref{Expressions, ,Expressions}.
c906108c 15390
177bc839
JK
15391Contrary to @code{whatis}, @code{ptype} always unrolls any
15392@code{typedef}s in its argument declaration, whether the argument is
15393a variable, expression, or a data type. This means that @code{ptype}
15394of a variable or an expression will not print literally its type as
15395present in the source code---use @code{whatis} for that. @code{typedef}s at
15396the pointer or reference targets are also unrolled. Only @code{typedef}s of
15397fields, methods and inner @code{class typedef}s of @code{struct}s,
15398@code{class}es and @code{union}s are not unrolled even with @code{ptype}.
15399
c906108c
SS
15400For example, for this variable declaration:
15401
474c8240 15402@smallexample
177bc839
JK
15403typedef double real_t;
15404struct complex @{ real_t real; double imag; @};
15405typedef struct complex complex_t;
15406complex_t var;
15407real_t *real_pointer_var;
474c8240 15408@end smallexample
c906108c
SS
15409
15410@noindent
15411the two commands give this output:
15412
474c8240 15413@smallexample
c906108c 15414@group
177bc839
JK
15415(@value{GDBP}) whatis var
15416type = complex_t
15417(@value{GDBP}) ptype var
15418type = struct complex @{
15419 real_t real;
15420 double imag;
15421@}
15422(@value{GDBP}) whatis complex_t
15423type = struct complex
15424(@value{GDBP}) whatis struct complex
c906108c 15425type = struct complex
177bc839 15426(@value{GDBP}) ptype struct complex
c906108c 15427type = struct complex @{
177bc839 15428 real_t real;
c906108c
SS
15429 double imag;
15430@}
177bc839
JK
15431(@value{GDBP}) whatis real_pointer_var
15432type = real_t *
15433(@value{GDBP}) ptype real_pointer_var
15434type = double *
c906108c 15435@end group
474c8240 15436@end smallexample
c906108c
SS
15437
15438@noindent
15439As with @code{whatis}, using @code{ptype} without an argument refers to
15440the type of @code{$}, the last value in the value history.
15441
ab1adacd
EZ
15442@cindex incomplete type
15443Sometimes, programs use opaque data types or incomplete specifications
15444of complex data structure. If the debug information included in the
15445program does not allow @value{GDBN} to display a full declaration of
15446the data type, it will say @samp{<incomplete type>}. For example,
15447given these declarations:
15448
15449@smallexample
15450 struct foo;
15451 struct foo *fooptr;
15452@end smallexample
15453
15454@noindent
15455but no definition for @code{struct foo} itself, @value{GDBN} will say:
15456
15457@smallexample
ddb50cd7 15458 (@value{GDBP}) ptype foo
ab1adacd
EZ
15459 $1 = <incomplete type>
15460@end smallexample
15461
15462@noindent
15463``Incomplete type'' is C terminology for data types that are not
15464completely specified.
15465
c906108c
SS
15466@kindex info types
15467@item info types @var{regexp}
15468@itemx info types
09d4efe1
EZ
15469Print a brief description of all types whose names match the regular
15470expression @var{regexp} (or all types in your program, if you supply
15471no argument). Each complete typename is matched as though it were a
15472complete line; thus, @samp{i type value} gives information on all
15473types in your program whose names include the string @code{value}, but
15474@samp{i type ^value$} gives information only on types whose complete
15475name is @code{value}.
c906108c
SS
15476
15477This command differs from @code{ptype} in two ways: first, like
15478@code{whatis}, it does not print a detailed description; second, it
15479lists all source files where a type is defined.
15480
18a9fc12
TT
15481@kindex info type-printers
15482@item info type-printers
15483Versions of @value{GDBN} that ship with Python scripting enabled may
15484have ``type printers'' available. When using @command{ptype} or
15485@command{whatis}, these printers are consulted when the name of a type
15486is needed. @xref{Type Printing API}, for more information on writing
15487type printers.
15488
15489@code{info type-printers} displays all the available type printers.
15490
15491@kindex enable type-printer
15492@kindex disable type-printer
15493@item enable type-printer @var{name}@dots{}
15494@item disable type-printer @var{name}@dots{}
15495These commands can be used to enable or disable type printers.
15496
b37052ae
EZ
15497@kindex info scope
15498@cindex local variables
09d4efe1 15499@item info scope @var{location}
b37052ae 15500List all the variables local to a particular scope. This command
09d4efe1
EZ
15501accepts a @var{location} argument---a function name, a source line, or
15502an address preceded by a @samp{*}, and prints all the variables local
2a25a5ba
EZ
15503to the scope defined by that location. (@xref{Specify Location}, for
15504details about supported forms of @var{location}.) For example:
b37052ae
EZ
15505
15506@smallexample
15507(@value{GDBP}) @b{info scope command_line_handler}
15508Scope for command_line_handler:
15509Symbol rl is an argument at stack/frame offset 8, length 4.
15510Symbol linebuffer is in static storage at address 0x150a18, length 4.
15511Symbol linelength is in static storage at address 0x150a1c, length 4.
15512Symbol p is a local variable in register $esi, length 4.
15513Symbol p1 is a local variable in register $ebx, length 4.
15514Symbol nline is a local variable in register $edx, length 4.
15515Symbol repeat is a local variable at frame offset -8, length 4.
15516@end smallexample
15517
f5c37c66
EZ
15518@noindent
15519This command is especially useful for determining what data to collect
15520during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
15521collect}.
15522
c906108c
SS
15523@kindex info source
15524@item info source
919d772c
JB
15525Show information about the current source file---that is, the source file for
15526the function containing the current point of execution:
15527@itemize @bullet
15528@item
15529the name of the source file, and the directory containing it,
15530@item
15531the directory it was compiled in,
15532@item
15533its length, in lines,
15534@item
15535which programming language it is written in,
15536@item
15537whether the executable includes debugging information for that file, and
15538if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
15539@item
15540whether the debugging information includes information about
15541preprocessor macros.
15542@end itemize
15543
c906108c
SS
15544
15545@kindex info sources
15546@item info sources
15547Print the names of all source files in your program for which there is
15548debugging information, organized into two lists: files whose symbols
15549have already been read, and files whose symbols will be read when needed.
15550
15551@kindex info functions
15552@item info functions
15553Print the names and data types of all defined functions.
15554
15555@item info functions @var{regexp}
15556Print the names and data types of all defined functions
15557whose names contain a match for regular expression @var{regexp}.
15558Thus, @samp{info fun step} finds all functions whose names
15559include @code{step}; @samp{info fun ^step} finds those whose names
b383017d 15560start with @code{step}. If a function name contains characters
c1468174 15561that conflict with the regular expression language (e.g.@:
1c5dfdad 15562@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
15563
15564@kindex info variables
15565@item info variables
0fe7935b 15566Print the names and data types of all variables that are defined
6ca652b0 15567outside of functions (i.e.@: excluding local variables).
c906108c
SS
15568
15569@item info variables @var{regexp}
15570Print the names and data types of all variables (except for local
15571variables) whose names contain a match for regular expression
15572@var{regexp}.
15573
b37303ee 15574@kindex info classes
721c2651 15575@cindex Objective-C, classes and selectors
b37303ee
AF
15576@item info classes
15577@itemx info classes @var{regexp}
15578Display all Objective-C classes in your program, or
15579(with the @var{regexp} argument) all those matching a particular regular
15580expression.
15581
15582@kindex info selectors
15583@item info selectors
15584@itemx info selectors @var{regexp}
15585Display all Objective-C selectors in your program, or
15586(with the @var{regexp} argument) all those matching a particular regular
15587expression.
15588
c906108c
SS
15589@ignore
15590This was never implemented.
15591@kindex info methods
15592@item info methods
15593@itemx info methods @var{regexp}
15594The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
15595methods within C@t{++} program, or (with the @var{regexp} argument) a
15596specific set of methods found in the various C@t{++} classes. Many
15597C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
15598from the @code{ptype} command can be overwhelming and hard to use. The
15599@code{info-methods} command filters the methods, printing only those
15600which match the regular-expression @var{regexp}.
15601@end ignore
15602
9c16f35a 15603@cindex opaque data types
c906108c
SS
15604@kindex set opaque-type-resolution
15605@item set opaque-type-resolution on
15606Tell @value{GDBN} to resolve opaque types. An opaque type is a type
15607declared as a pointer to a @code{struct}, @code{class}, or
15608@code{union}---for example, @code{struct MyType *}---that is used in one
15609source file although the full declaration of @code{struct MyType} is in
15610another source file. The default is on.
15611
15612A change in the setting of this subcommand will not take effect until
15613the next time symbols for a file are loaded.
15614
15615@item set opaque-type-resolution off
15616Tell @value{GDBN} not to resolve opaque types. In this case, the type
15617is printed as follows:
15618@smallexample
15619@{<no data fields>@}
15620@end smallexample
15621
15622@kindex show opaque-type-resolution
15623@item show opaque-type-resolution
15624Show whether opaque types are resolved or not.
c906108c
SS
15625
15626@kindex maint print symbols
15627@cindex symbol dump
15628@kindex maint print psymbols
15629@cindex partial symbol dump
15630@item maint print symbols @var{filename}
15631@itemx maint print psymbols @var{filename}
15632@itemx maint print msymbols @var{filename}
15633Write a dump of debugging symbol data into the file @var{filename}.
15634These commands are used to debug the @value{GDBN} symbol-reading code. Only
15635symbols with debugging data are included. If you use @samp{maint print
15636symbols}, @value{GDBN} includes all the symbols for which it has already
15637collected full details: that is, @var{filename} reflects symbols for
15638only those files whose symbols @value{GDBN} has read. You can use the
15639command @code{info sources} to find out which files these are. If you
15640use @samp{maint print psymbols} instead, the dump shows information about
15641symbols that @value{GDBN} only knows partially---that is, symbols defined in
15642files that @value{GDBN} has skimmed, but not yet read completely. Finally,
15643@samp{maint print msymbols} dumps just the minimal symbol information
15644required for each object file from which @value{GDBN} has read some symbols.
79a6e687 15645@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 15646@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 15647
5e7b2f39
JB
15648@kindex maint info symtabs
15649@kindex maint info psymtabs
44ea7b70
JB
15650@cindex listing @value{GDBN}'s internal symbol tables
15651@cindex symbol tables, listing @value{GDBN}'s internal
15652@cindex full symbol tables, listing @value{GDBN}'s internal
15653@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
15654@item maint info symtabs @r{[} @var{regexp} @r{]}
15655@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
15656
15657List the @code{struct symtab} or @code{struct partial_symtab}
15658structures whose names match @var{regexp}. If @var{regexp} is not
15659given, list them all. The output includes expressions which you can
15660copy into a @value{GDBN} debugging this one to examine a particular
15661structure in more detail. For example:
15662
15663@smallexample
5e7b2f39 15664(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
15665@{ objfile /home/gnu/build/gdb/gdb
15666 ((struct objfile *) 0x82e69d0)
b383017d 15667 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
15668 ((struct partial_symtab *) 0x8474b10)
15669 readin no
15670 fullname (null)
15671 text addresses 0x814d3c8 -- 0x8158074
15672 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
15673 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
15674 dependencies (none)
15675 @}
15676@}
5e7b2f39 15677(@value{GDBP}) maint info symtabs
44ea7b70
JB
15678(@value{GDBP})
15679@end smallexample
15680@noindent
15681We see that there is one partial symbol table whose filename contains
15682the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
15683and we see that @value{GDBN} has not read in any symtabs yet at all.
15684If we set a breakpoint on a function, that will cause @value{GDBN} to
15685read the symtab for the compilation unit containing that function:
15686
15687@smallexample
15688(@value{GDBP}) break dwarf2_psymtab_to_symtab
15689Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
15690line 1574.
5e7b2f39 15691(@value{GDBP}) maint info symtabs
b383017d 15692@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 15693 ((struct objfile *) 0x82e69d0)
b383017d 15694 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
15695 ((struct symtab *) 0x86c1f38)
15696 dirname (null)
15697 fullname (null)
15698 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 15699 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
15700 debugformat DWARF 2
15701 @}
15702@}
b383017d 15703(@value{GDBP})
44ea7b70 15704@end smallexample
c906108c
SS
15705@end table
15706
44ea7b70 15707
6d2ebf8b 15708@node Altering
c906108c
SS
15709@chapter Altering Execution
15710
15711Once you think you have found an error in your program, you might want to
15712find out for certain whether correcting the apparent error would lead to
15713correct results in the rest of the run. You can find the answer by
15714experiment, using the @value{GDBN} features for altering execution of the
15715program.
15716
15717For example, you can store new values into variables or memory
7a292a7a
SS
15718locations, give your program a signal, restart it at a different
15719address, or even return prematurely from a function.
c906108c
SS
15720
15721@menu
15722* Assignment:: Assignment to variables
15723* Jumping:: Continuing at a different address
c906108c 15724* Signaling:: Giving your program a signal
c906108c
SS
15725* Returning:: Returning from a function
15726* Calling:: Calling your program's functions
15727* Patching:: Patching your program
15728@end menu
15729
6d2ebf8b 15730@node Assignment
79a6e687 15731@section Assignment to Variables
c906108c
SS
15732
15733@cindex assignment
15734@cindex setting variables
15735To alter the value of a variable, evaluate an assignment expression.
15736@xref{Expressions, ,Expressions}. For example,
15737
474c8240 15738@smallexample
c906108c 15739print x=4
474c8240 15740@end smallexample
c906108c
SS
15741
15742@noindent
15743stores the value 4 into the variable @code{x}, and then prints the
5d161b24 15744value of the assignment expression (which is 4).
c906108c
SS
15745@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
15746information on operators in supported languages.
c906108c
SS
15747
15748@kindex set variable
15749@cindex variables, setting
15750If you are not interested in seeing the value of the assignment, use the
15751@code{set} command instead of the @code{print} command. @code{set} is
15752really the same as @code{print} except that the expression's value is
15753not printed and is not put in the value history (@pxref{Value History,
79a6e687 15754,Value History}). The expression is evaluated only for its effects.
c906108c 15755
c906108c
SS
15756If the beginning of the argument string of the @code{set} command
15757appears identical to a @code{set} subcommand, use the @code{set
15758variable} command instead of just @code{set}. This command is identical
15759to @code{set} except for its lack of subcommands. For example, if your
15760program has a variable @code{width}, you get an error if you try to set
15761a new value with just @samp{set width=13}, because @value{GDBN} has the
15762command @code{set width}:
15763
474c8240 15764@smallexample
c906108c
SS
15765(@value{GDBP}) whatis width
15766type = double
15767(@value{GDBP}) p width
15768$4 = 13
15769(@value{GDBP}) set width=47
15770Invalid syntax in expression.
474c8240 15771@end smallexample
c906108c
SS
15772
15773@noindent
15774The invalid expression, of course, is @samp{=47}. In
15775order to actually set the program's variable @code{width}, use
15776
474c8240 15777@smallexample
c906108c 15778(@value{GDBP}) set var width=47
474c8240 15779@end smallexample
53a5351d 15780
c906108c
SS
15781Because the @code{set} command has many subcommands that can conflict
15782with the names of program variables, it is a good idea to use the
15783@code{set variable} command instead of just @code{set}. For example, if
15784your program has a variable @code{g}, you run into problems if you try
15785to set a new value with just @samp{set g=4}, because @value{GDBN} has
15786the command @code{set gnutarget}, abbreviated @code{set g}:
15787
474c8240 15788@smallexample
c906108c
SS
15789@group
15790(@value{GDBP}) whatis g
15791type = double
15792(@value{GDBP}) p g
15793$1 = 1
15794(@value{GDBP}) set g=4
2df3850c 15795(@value{GDBP}) p g
c906108c
SS
15796$2 = 1
15797(@value{GDBP}) r
15798The program being debugged has been started already.
15799Start it from the beginning? (y or n) y
15800Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
15801"/home/smith/cc_progs/a.out": can't open to read symbols:
15802 Invalid bfd target.
c906108c
SS
15803(@value{GDBP}) show g
15804The current BFD target is "=4".
15805@end group
474c8240 15806@end smallexample
c906108c
SS
15807
15808@noindent
15809The program variable @code{g} did not change, and you silently set the
15810@code{gnutarget} to an invalid value. In order to set the variable
15811@code{g}, use
15812
474c8240 15813@smallexample
c906108c 15814(@value{GDBP}) set var g=4
474c8240 15815@end smallexample
c906108c
SS
15816
15817@value{GDBN} allows more implicit conversions in assignments than C; you can
15818freely store an integer value into a pointer variable or vice versa,
15819and you can convert any structure to any other structure that is the
15820same length or shorter.
15821@comment FIXME: how do structs align/pad in these conversions?
15822@comment /doc@cygnus.com 18dec1990
15823
15824To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
15825construct to generate a value of specified type at a specified address
15826(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
15827to memory location @code{0x83040} as an integer (which implies a certain size
15828and representation in memory), and
15829
474c8240 15830@smallexample
c906108c 15831set @{int@}0x83040 = 4
474c8240 15832@end smallexample
c906108c
SS
15833
15834@noindent
15835stores the value 4 into that memory location.
15836
6d2ebf8b 15837@node Jumping
79a6e687 15838@section Continuing at a Different Address
c906108c
SS
15839
15840Ordinarily, when you continue your program, you do so at the place where
15841it stopped, with the @code{continue} command. You can instead continue at
15842an address of your own choosing, with the following commands:
15843
15844@table @code
15845@kindex jump
c1d780c2 15846@kindex j @r{(@code{jump})}
c906108c 15847@item jump @var{linespec}
c1d780c2 15848@itemx j @var{linespec}
2a25a5ba 15849@itemx jump @var{location}
c1d780c2 15850@itemx j @var{location}
2a25a5ba
EZ
15851Resume execution at line @var{linespec} or at address given by
15852@var{location}. Execution stops again immediately if there is a
15853breakpoint there. @xref{Specify Location}, for a description of the
15854different forms of @var{linespec} and @var{location}. It is common
15855practice to use the @code{tbreak} command in conjunction with
15856@code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
c906108c
SS
15857
15858The @code{jump} command does not change the current stack frame, or
15859the stack pointer, or the contents of any memory location or any
15860register other than the program counter. If line @var{linespec} is in
15861a different function from the one currently executing, the results may
15862be bizarre if the two functions expect different patterns of arguments or
15863of local variables. For this reason, the @code{jump} command requests
15864confirmation if the specified line is not in the function currently
15865executing. However, even bizarre results are predictable if you are
15866well acquainted with the machine-language code of your program.
c906108c
SS
15867@end table
15868
c906108c 15869@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
15870On many systems, you can get much the same effect as the @code{jump}
15871command by storing a new value into the register @code{$pc}. The
15872difference is that this does not start your program running; it only
15873changes the address of where it @emph{will} run when you continue. For
15874example,
c906108c 15875
474c8240 15876@smallexample
c906108c 15877set $pc = 0x485
474c8240 15878@end smallexample
c906108c
SS
15879
15880@noindent
15881makes the next @code{continue} command or stepping command execute at
15882address @code{0x485}, rather than at the address where your program stopped.
79a6e687 15883@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
15884
15885The most common occasion to use the @code{jump} command is to back
15886up---perhaps with more breakpoints set---over a portion of a program
15887that has already executed, in order to examine its execution in more
15888detail.
15889
c906108c 15890@c @group
6d2ebf8b 15891@node Signaling
79a6e687 15892@section Giving your Program a Signal
9c16f35a 15893@cindex deliver a signal to a program
c906108c
SS
15894
15895@table @code
15896@kindex signal
15897@item signal @var{signal}
15898Resume execution where your program stopped, but immediately give it the
15899signal @var{signal}. @var{signal} can be the name or the number of a
15900signal. For example, on many systems @code{signal 2} and @code{signal
15901SIGINT} are both ways of sending an interrupt signal.
15902
15903Alternatively, if @var{signal} is zero, continue execution without
15904giving a signal. This is useful when your program stopped on account of
ae606bee 15905a signal and would ordinarily see the signal when resumed with the
c906108c
SS
15906@code{continue} command; @samp{signal 0} causes it to resume without a
15907signal.
15908
15909@code{signal} does not repeat when you press @key{RET} a second time
15910after executing the command.
15911@end table
15912@c @end group
15913
15914Invoking the @code{signal} command is not the same as invoking the
15915@code{kill} utility from the shell. Sending a signal with @code{kill}
15916causes @value{GDBN} to decide what to do with the signal depending on
15917the signal handling tables (@pxref{Signals}). The @code{signal} command
15918passes the signal directly to your program.
15919
c906108c 15920
6d2ebf8b 15921@node Returning
79a6e687 15922@section Returning from a Function
c906108c
SS
15923
15924@table @code
15925@cindex returning from a function
15926@kindex return
15927@item return
15928@itemx return @var{expression}
15929You can cancel execution of a function call with the @code{return}
15930command. If you give an
15931@var{expression} argument, its value is used as the function's return
15932value.
15933@end table
15934
15935When you use @code{return}, @value{GDBN} discards the selected stack frame
15936(and all frames within it). You can think of this as making the
15937discarded frame return prematurely. If you wish to specify a value to
15938be returned, give that value as the argument to @code{return}.
15939
15940This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 15941Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
15942innermost remaining frame. That frame becomes selected. The
15943specified value is stored in the registers used for returning values
15944of functions.
15945
15946The @code{return} command does not resume execution; it leaves the
15947program stopped in the state that would exist if the function had just
15948returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 15949and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
15950selected stack frame returns naturally.
15951
61ff14c6
JK
15952@value{GDBN} needs to know how the @var{expression} argument should be set for
15953the inferior. The concrete registers assignment depends on the OS ABI and the
15954type being returned by the selected stack frame. For example it is common for
15955OS ABI to return floating point values in FPU registers while integer values in
15956CPU registers. Still some ABIs return even floating point values in CPU
15957registers. Larger integer widths (such as @code{long long int}) also have
15958specific placement rules. @value{GDBN} already knows the OS ABI from its
15959current target so it needs to find out also the type being returned to make the
15960assignment into the right register(s).
15961
15962Normally, the selected stack frame has debug info. @value{GDBN} will always
15963use the debug info instead of the implicit type of @var{expression} when the
15964debug info is available. For example, if you type @kbd{return -1}, and the
15965function in the current stack frame is declared to return a @code{long long
15966int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
15967into a @code{long long int}:
15968
15969@smallexample
15970Breakpoint 1, func () at gdb.base/return-nodebug.c:29
1597129 return 31;
15972(@value{GDBP}) return -1
15973Make func return now? (y or n) y
15974#0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
1597543 printf ("result=%lld\n", func ());
15976(@value{GDBP})
15977@end smallexample
15978
15979However, if the selected stack frame does not have a debug info, e.g., if the
15980function was compiled without debug info, @value{GDBN} has to find out the type
15981to return from user. Specifying a different type by mistake may set the value
15982in different inferior registers than the caller code expects. For example,
15983typing @kbd{return -1} with its implicit type @code{int} would set only a part
15984of a @code{long long int} result for a debug info less function (on 32-bit
15985architectures). Therefore the user is required to specify the return type by
15986an appropriate cast explicitly:
15987
15988@smallexample
15989Breakpoint 2, 0x0040050b in func ()
15990(@value{GDBP}) return -1
15991Return value type not available for selected stack frame.
15992Please use an explicit cast of the value to return.
15993(@value{GDBP}) return (long long int) -1
15994Make selected stack frame return now? (y or n) y
15995#0 0x00400526 in main ()
15996(@value{GDBP})
15997@end smallexample
15998
6d2ebf8b 15999@node Calling
79a6e687 16000@section Calling Program Functions
c906108c 16001
f8568604 16002@table @code
c906108c 16003@cindex calling functions
f8568604
EZ
16004@cindex inferior functions, calling
16005@item print @var{expr}
d3e8051b 16006Evaluate the expression @var{expr} and display the resulting value.
f8568604
EZ
16007@var{expr} may include calls to functions in the program being
16008debugged.
16009
c906108c 16010@kindex call
c906108c
SS
16011@item call @var{expr}
16012Evaluate the expression @var{expr} without displaying @code{void}
16013returned values.
c906108c
SS
16014
16015You can use this variant of the @code{print} command if you want to
f8568604
EZ
16016execute a function from your program that does not return anything
16017(a.k.a.@: @dfn{a void function}), but without cluttering the output
16018with @code{void} returned values that @value{GDBN} will otherwise
16019print. If the result is not void, it is printed and saved in the
16020value history.
16021@end table
16022
9c16f35a
EZ
16023It is possible for the function you call via the @code{print} or
16024@code{call} command to generate a signal (e.g., if there's a bug in
16025the function, or if you passed it incorrect arguments). What happens
16026in that case is controlled by the @code{set unwindonsignal} command.
16027
7cd1089b
PM
16028Similarly, with a C@t{++} program it is possible for the function you
16029call via the @code{print} or @code{call} command to generate an
16030exception that is not handled due to the constraints of the dummy
16031frame. In this case, any exception that is raised in the frame, but has
16032an out-of-frame exception handler will not be found. GDB builds a
16033dummy-frame for the inferior function call, and the unwinder cannot
16034seek for exception handlers outside of this dummy-frame. What happens
16035in that case is controlled by the
16036@code{set unwind-on-terminating-exception} command.
16037
9c16f35a
EZ
16038@table @code
16039@item set unwindonsignal
16040@kindex set unwindonsignal
16041@cindex unwind stack in called functions
16042@cindex call dummy stack unwinding
16043Set unwinding of the stack if a signal is received while in a function
16044that @value{GDBN} called in the program being debugged. If set to on,
16045@value{GDBN} unwinds the stack it created for the call and restores
16046the context to what it was before the call. If set to off (the
16047default), @value{GDBN} stops in the frame where the signal was
16048received.
16049
16050@item show unwindonsignal
16051@kindex show unwindonsignal
16052Show the current setting of stack unwinding in the functions called by
16053@value{GDBN}.
7cd1089b
PM
16054
16055@item set unwind-on-terminating-exception
16056@kindex set unwind-on-terminating-exception
16057@cindex unwind stack in called functions with unhandled exceptions
16058@cindex call dummy stack unwinding on unhandled exception.
16059Set unwinding of the stack if a C@t{++} exception is raised, but left
16060unhandled while in a function that @value{GDBN} called in the program being
16061debugged. If set to on (the default), @value{GDBN} unwinds the stack
16062it created for the call and restores the context to what it was before
16063the call. If set to off, @value{GDBN} the exception is delivered to
16064the default C@t{++} exception handler and the inferior terminated.
16065
16066@item show unwind-on-terminating-exception
16067@kindex show unwind-on-terminating-exception
16068Show the current setting of stack unwinding in the functions called by
16069@value{GDBN}.
16070
9c16f35a
EZ
16071@end table
16072
f8568604
EZ
16073@cindex weak alias functions
16074Sometimes, a function you wish to call is actually a @dfn{weak alias}
16075for another function. In such case, @value{GDBN} might not pick up
16076the type information, including the types of the function arguments,
16077which causes @value{GDBN} to call the inferior function incorrectly.
16078As a result, the called function will function erroneously and may
16079even crash. A solution to that is to use the name of the aliased
16080function instead.
c906108c 16081
6d2ebf8b 16082@node Patching
79a6e687 16083@section Patching Programs
7a292a7a 16084
c906108c
SS
16085@cindex patching binaries
16086@cindex writing into executables
c906108c 16087@cindex writing into corefiles
c906108c 16088
7a292a7a
SS
16089By default, @value{GDBN} opens the file containing your program's
16090executable code (or the corefile) read-only. This prevents accidental
16091alterations to machine code; but it also prevents you from intentionally
16092patching your program's binary.
c906108c
SS
16093
16094If you'd like to be able to patch the binary, you can specify that
16095explicitly with the @code{set write} command. For example, you might
16096want to turn on internal debugging flags, or even to make emergency
16097repairs.
16098
16099@table @code
16100@kindex set write
16101@item set write on
16102@itemx set write off
7a292a7a 16103If you specify @samp{set write on}, @value{GDBN} opens executable and
20924a55 16104core files for both reading and writing; if you specify @kbd{set write
c906108c
SS
16105off} (the default), @value{GDBN} opens them read-only.
16106
16107If you have already loaded a file, you must load it again (using the
7a292a7a
SS
16108@code{exec-file} or @code{core-file} command) after changing @code{set
16109write}, for your new setting to take effect.
c906108c
SS
16110
16111@item show write
16112@kindex show write
7a292a7a
SS
16113Display whether executable files and core files are opened for writing
16114as well as reading.
c906108c
SS
16115@end table
16116
6d2ebf8b 16117@node GDB Files
c906108c
SS
16118@chapter @value{GDBN} Files
16119
7a292a7a
SS
16120@value{GDBN} needs to know the file name of the program to be debugged,
16121both in order to read its symbol table and in order to start your
16122program. To debug a core dump of a previous run, you must also tell
16123@value{GDBN} the name of the core dump file.
c906108c
SS
16124
16125@menu
16126* Files:: Commands to specify files
5b5d99cf 16127* Separate Debug Files:: Debugging information in separate files
608e2dbb 16128* MiniDebugInfo:: Debugging information in a special section
9291a0cd 16129* Index Files:: Index files speed up GDB
c906108c 16130* Symbol Errors:: Errors reading symbol files
b14b1491 16131* Data Files:: GDB data files
c906108c
SS
16132@end menu
16133
6d2ebf8b 16134@node Files
79a6e687 16135@section Commands to Specify Files
c906108c 16136
7a292a7a 16137@cindex symbol table
c906108c 16138@cindex core dump file
7a292a7a
SS
16139
16140You may want to specify executable and core dump file names. The usual
16141way to do this is at start-up time, using the arguments to
16142@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
16143Out of @value{GDBN}}).
c906108c
SS
16144
16145Occasionally it is necessary to change to a different file during a
397ca115
EZ
16146@value{GDBN} session. Or you may run @value{GDBN} and forget to
16147specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
16148via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
16149Program}). In these situations the @value{GDBN} commands to specify
0869d01b 16150new files are useful.
c906108c
SS
16151
16152@table @code
16153@cindex executable file
16154@kindex file
16155@item file @var{filename}
16156Use @var{filename} as the program to be debugged. It is read for its
16157symbols and for the contents of pure memory. It is also the program
16158executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
16159directory and the file is not found in the @value{GDBN} working directory,
16160@value{GDBN} uses the environment variable @code{PATH} as a list of
16161directories to search, just as the shell does when looking for a program
16162to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
16163and your program, using the @code{path} command.
16164
fc8be69e
EZ
16165@cindex unlinked object files
16166@cindex patching object files
16167You can load unlinked object @file{.o} files into @value{GDBN} using
16168the @code{file} command. You will not be able to ``run'' an object
16169file, but you can disassemble functions and inspect variables. Also,
16170if the underlying BFD functionality supports it, you could use
16171@kbd{gdb -write} to patch object files using this technique. Note
16172that @value{GDBN} can neither interpret nor modify relocations in this
16173case, so branches and some initialized variables will appear to go to
16174the wrong place. But this feature is still handy from time to time.
16175
c906108c
SS
16176@item file
16177@code{file} with no argument makes @value{GDBN} discard any information it
16178has on both executable file and the symbol table.
16179
16180@kindex exec-file
16181@item exec-file @r{[} @var{filename} @r{]}
16182Specify that the program to be run (but not the symbol table) is found
16183in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
16184if necessary to locate your program. Omitting @var{filename} means to
16185discard information on the executable file.
16186
16187@kindex symbol-file
16188@item symbol-file @r{[} @var{filename} @r{]}
16189Read symbol table information from file @var{filename}. @code{PATH} is
16190searched when necessary. Use the @code{file} command to get both symbol
16191table and program to run from the same file.
16192
16193@code{symbol-file} with no argument clears out @value{GDBN} information on your
16194program's symbol table.
16195
ae5a43e0
DJ
16196The @code{symbol-file} command causes @value{GDBN} to forget the contents of
16197some breakpoints and auto-display expressions. This is because they may
16198contain pointers to the internal data recording symbols and data types,
16199which are part of the old symbol table data being discarded inside
16200@value{GDBN}.
c906108c
SS
16201
16202@code{symbol-file} does not repeat if you press @key{RET} again after
16203executing it once.
16204
16205When @value{GDBN} is configured for a particular environment, it
16206understands debugging information in whatever format is the standard
16207generated for that environment; you may use either a @sc{gnu} compiler, or
16208other compilers that adhere to the local conventions.
c906108c 16209Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 16210using @code{@value{NGCC}} you can generate debugging information for
c906108c 16211optimized code.
c906108c
SS
16212
16213For most kinds of object files, with the exception of old SVR3 systems
16214using COFF, the @code{symbol-file} command does not normally read the
16215symbol table in full right away. Instead, it scans the symbol table
16216quickly to find which source files and which symbols are present. The
16217details are read later, one source file at a time, as they are needed.
16218
16219The purpose of this two-stage reading strategy is to make @value{GDBN}
16220start up faster. For the most part, it is invisible except for
16221occasional pauses while the symbol table details for a particular source
16222file are being read. (The @code{set verbose} command can turn these
16223pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 16224Warnings and Messages}.)
c906108c 16225
c906108c
SS
16226We have not implemented the two-stage strategy for COFF yet. When the
16227symbol table is stored in COFF format, @code{symbol-file} reads the
16228symbol table data in full right away. Note that ``stabs-in-COFF''
16229still does the two-stage strategy, since the debug info is actually
16230in stabs format.
16231
16232@kindex readnow
16233@cindex reading symbols immediately
16234@cindex symbols, reading immediately
6ac33a4e
TT
16235@item symbol-file @r{[} -readnow @r{]} @var{filename}
16236@itemx file @r{[} -readnow @r{]} @var{filename}
c906108c
SS
16237You can override the @value{GDBN} two-stage strategy for reading symbol
16238tables by using the @samp{-readnow} option with any of the commands that
16239load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 16240entire symbol table available.
c906108c 16241
c906108c
SS
16242@c FIXME: for now no mention of directories, since this seems to be in
16243@c flux. 13mar1992 status is that in theory GDB would look either in
16244@c current dir or in same dir as myprog; but issues like competing
16245@c GDB's, or clutter in system dirs, mean that in practice right now
16246@c only current dir is used. FFish says maybe a special GDB hierarchy
16247@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
16248@c files.
16249
c906108c 16250@kindex core-file
09d4efe1 16251@item core-file @r{[}@var{filename}@r{]}
4644b6e3 16252@itemx core
c906108c
SS
16253Specify the whereabouts of a core dump file to be used as the ``contents
16254of memory''. Traditionally, core files contain only some parts of the
16255address space of the process that generated them; @value{GDBN} can access the
16256executable file itself for other parts.
16257
16258@code{core-file} with no argument specifies that no core file is
16259to be used.
16260
16261Note that the core file is ignored when your program is actually running
7a292a7a
SS
16262under @value{GDBN}. So, if you have been running your program and you
16263wish to debug a core file instead, you must kill the subprocess in which
16264the program is running. To do this, use the @code{kill} command
79a6e687 16265(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 16266
c906108c
SS
16267@kindex add-symbol-file
16268@cindex dynamic linking
16269@item add-symbol-file @var{filename} @var{address}
a94ab193 16270@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
24bdad53 16271@itemx add-symbol-file @var{filename} @var{address} -s @var{section} @var{address} @dots{}
96a2c332
SS
16272The @code{add-symbol-file} command reads additional symbol table
16273information from the file @var{filename}. You would use this command
16274when @var{filename} has been dynamically loaded (by some other means)
16275into the program that is running. @var{address} should be the memory
16276address at which the file has been loaded; @value{GDBN} cannot figure
d167840f 16277this out for itself. You can additionally specify an arbitrary number
24bdad53 16278of @samp{-s @var{section} @var{address}} pairs, to give an explicit
d167840f
EZ
16279section name and base address for that section. You can specify any
16280@var{address} as an expression.
c906108c
SS
16281
16282The symbol table of the file @var{filename} is added to the symbol table
16283originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
16284@code{add-symbol-file} command any number of times; the new symbol data
16285thus read keeps adding to the old. To discard all old symbol data
16286instead, use the @code{symbol-file} command without any arguments.
c906108c 16287
17d9d558
JB
16288@cindex relocatable object files, reading symbols from
16289@cindex object files, relocatable, reading symbols from
16290@cindex reading symbols from relocatable object files
16291@cindex symbols, reading from relocatable object files
16292@cindex @file{.o} files, reading symbols from
16293Although @var{filename} is typically a shared library file, an
16294executable file, or some other object file which has been fully
16295relocated for loading into a process, you can also load symbolic
16296information from relocatable @file{.o} files, as long as:
16297
16298@itemize @bullet
16299@item
16300the file's symbolic information refers only to linker symbols defined in
16301that file, not to symbols defined by other object files,
16302@item
16303every section the file's symbolic information refers to has actually
16304been loaded into the inferior, as it appears in the file, and
16305@item
16306you can determine the address at which every section was loaded, and
16307provide these to the @code{add-symbol-file} command.
16308@end itemize
16309
16310@noindent
16311Some embedded operating systems, like Sun Chorus and VxWorks, can load
16312relocatable files into an already running program; such systems
16313typically make the requirements above easy to meet. However, it's
16314important to recognize that many native systems use complex link
49efadf5 16315procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
16316assembly, for example) that make the requirements difficult to meet. In
16317general, one cannot assume that using @code{add-symbol-file} to read a
16318relocatable object file's symbolic information will have the same effect
16319as linking the relocatable object file into the program in the normal
16320way.
16321
c906108c
SS
16322@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
16323
c45da7e6
EZ
16324@kindex add-symbol-file-from-memory
16325@cindex @code{syscall DSO}
16326@cindex load symbols from memory
16327@item add-symbol-file-from-memory @var{address}
16328Load symbols from the given @var{address} in a dynamically loaded
16329object file whose image is mapped directly into the inferior's memory.
16330For example, the Linux kernel maps a @code{syscall DSO} into each
16331process's address space; this DSO provides kernel-specific code for
16332some system calls. The argument can be any expression whose
16333evaluation yields the address of the file's shared object file header.
16334For this command to work, you must have used @code{symbol-file} or
16335@code{exec-file} commands in advance.
16336
09d4efe1
EZ
16337@kindex add-shared-symbol-files
16338@kindex assf
16339@item add-shared-symbol-files @var{library-file}
16340@itemx assf @var{library-file}
16341The @code{add-shared-symbol-files} command can currently be used only
16342in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
16343alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
16344@value{GDBN} automatically looks for shared libraries, however if
16345@value{GDBN} does not find yours, you can invoke
16346@code{add-shared-symbol-files}. It takes one argument: the shared
16347library's file name. @code{assf} is a shorthand alias for
16348@code{add-shared-symbol-files}.
c906108c 16349
c906108c 16350@kindex section
09d4efe1
EZ
16351@item section @var{section} @var{addr}
16352The @code{section} command changes the base address of the named
16353@var{section} of the exec file to @var{addr}. This can be used if the
16354exec file does not contain section addresses, (such as in the
16355@code{a.out} format), or when the addresses specified in the file
16356itself are wrong. Each section must be changed separately. The
16357@code{info files} command, described below, lists all the sections and
16358their addresses.
c906108c
SS
16359
16360@kindex info files
16361@kindex info target
16362@item info files
16363@itemx info target
7a292a7a
SS
16364@code{info files} and @code{info target} are synonymous; both print the
16365current target (@pxref{Targets, ,Specifying a Debugging Target}),
16366including the names of the executable and core dump files currently in
16367use by @value{GDBN}, and the files from which symbols were loaded. The
16368command @code{help target} lists all possible targets rather than
16369current ones.
16370
fe95c787
MS
16371@kindex maint info sections
16372@item maint info sections
16373Another command that can give you extra information about program sections
16374is @code{maint info sections}. In addition to the section information
16375displayed by @code{info files}, this command displays the flags and file
16376offset of each section in the executable and core dump files. In addition,
16377@code{maint info sections} provides the following command options (which
16378may be arbitrarily combined):
16379
16380@table @code
16381@item ALLOBJ
16382Display sections for all loaded object files, including shared libraries.
16383@item @var{sections}
6600abed 16384Display info only for named @var{sections}.
fe95c787
MS
16385@item @var{section-flags}
16386Display info only for sections for which @var{section-flags} are true.
16387The section flags that @value{GDBN} currently knows about are:
16388@table @code
16389@item ALLOC
16390Section will have space allocated in the process when loaded.
16391Set for all sections except those containing debug information.
16392@item LOAD
16393Section will be loaded from the file into the child process memory.
16394Set for pre-initialized code and data, clear for @code{.bss} sections.
16395@item RELOC
16396Section needs to be relocated before loading.
16397@item READONLY
16398Section cannot be modified by the child process.
16399@item CODE
16400Section contains executable code only.
6600abed 16401@item DATA
fe95c787
MS
16402Section contains data only (no executable code).
16403@item ROM
16404Section will reside in ROM.
16405@item CONSTRUCTOR
16406Section contains data for constructor/destructor lists.
16407@item HAS_CONTENTS
16408Section is not empty.
16409@item NEVER_LOAD
16410An instruction to the linker to not output the section.
16411@item COFF_SHARED_LIBRARY
16412A notification to the linker that the section contains
16413COFF shared library information.
16414@item IS_COMMON
16415Section contains common symbols.
16416@end table
16417@end table
6763aef9 16418@kindex set trust-readonly-sections
9c16f35a 16419@cindex read-only sections
6763aef9
MS
16420@item set trust-readonly-sections on
16421Tell @value{GDBN} that readonly sections in your object file
6ca652b0 16422really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
16423In that case, @value{GDBN} can fetch values from these sections
16424out of the object file, rather than from the target program.
16425For some targets (notably embedded ones), this can be a significant
16426enhancement to debugging performance.
16427
16428The default is off.
16429
16430@item set trust-readonly-sections off
15110bc3 16431Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
16432the contents of the section might change while the program is running,
16433and must therefore be fetched from the target when needed.
9c16f35a
EZ
16434
16435@item show trust-readonly-sections
16436Show the current setting of trusting readonly sections.
c906108c
SS
16437@end table
16438
16439All file-specifying commands allow both absolute and relative file names
16440as arguments. @value{GDBN} always converts the file name to an absolute file
16441name and remembers it that way.
16442
c906108c 16443@cindex shared libraries
9cceb671
DJ
16444@anchor{Shared Libraries}
16445@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
9c16f35a 16446and IBM RS/6000 AIX shared libraries.
53a5351d 16447
9cceb671
DJ
16448On MS-Windows @value{GDBN} must be linked with the Expat library to support
16449shared libraries. @xref{Expat}.
16450
c906108c
SS
16451@value{GDBN} automatically loads symbol definitions from shared libraries
16452when you use the @code{run} command, or when you examine a core file.
16453(Before you issue the @code{run} command, @value{GDBN} does not understand
16454references to a function in a shared library, however---unless you are
16455debugging a core file).
53a5351d
JM
16456
16457On HP-UX, if the program loads a library explicitly, @value{GDBN}
16458automatically loads the symbols at the time of the @code{shl_load} call.
16459
c906108c
SS
16460@c FIXME: some @value{GDBN} release may permit some refs to undef
16461@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
16462@c FIXME...lib; check this from time to time when updating manual
16463
b7209cb4
FF
16464There are times, however, when you may wish to not automatically load
16465symbol definitions from shared libraries, such as when they are
16466particularly large or there are many of them.
16467
16468To control the automatic loading of shared library symbols, use the
16469commands:
16470
16471@table @code
16472@kindex set auto-solib-add
16473@item set auto-solib-add @var{mode}
16474If @var{mode} is @code{on}, symbols from all shared object libraries
16475will be loaded automatically when the inferior begins execution, you
16476attach to an independently started inferior, or when the dynamic linker
16477informs @value{GDBN} that a new library has been loaded. If @var{mode}
16478is @code{off}, symbols must be loaded manually, using the
16479@code{sharedlibrary} command. The default value is @code{on}.
16480
dcaf7c2c
EZ
16481@cindex memory used for symbol tables
16482If your program uses lots of shared libraries with debug info that
16483takes large amounts of memory, you can decrease the @value{GDBN}
16484memory footprint by preventing it from automatically loading the
16485symbols from shared libraries. To that end, type @kbd{set
16486auto-solib-add off} before running the inferior, then load each
16487library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 16488@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
16489the libraries whose symbols you want to be loaded.
16490
b7209cb4
FF
16491@kindex show auto-solib-add
16492@item show auto-solib-add
16493Display the current autoloading mode.
16494@end table
16495
c45da7e6 16496@cindex load shared library
b7209cb4
FF
16497To explicitly load shared library symbols, use the @code{sharedlibrary}
16498command:
16499
c906108c
SS
16500@table @code
16501@kindex info sharedlibrary
16502@kindex info share
55333a84
DE
16503@item info share @var{regex}
16504@itemx info sharedlibrary @var{regex}
16505Print the names of the shared libraries which are currently loaded
16506that match @var{regex}. If @var{regex} is omitted then print
16507all shared libraries that are loaded.
c906108c
SS
16508
16509@kindex sharedlibrary
16510@kindex share
16511@item sharedlibrary @var{regex}
16512@itemx share @var{regex}
c906108c
SS
16513Load shared object library symbols for files matching a
16514Unix regular expression.
16515As with files loaded automatically, it only loads shared libraries
16516required by your program for a core file or after typing @code{run}. If
16517@var{regex} is omitted all shared libraries required by your program are
16518loaded.
c45da7e6
EZ
16519
16520@item nosharedlibrary
16521@kindex nosharedlibrary
16522@cindex unload symbols from shared libraries
16523Unload all shared object library symbols. This discards all symbols
16524that have been loaded from all shared libraries. Symbols from shared
16525libraries that were loaded by explicit user requests are not
16526discarded.
c906108c
SS
16527@end table
16528
721c2651 16529Sometimes you may wish that @value{GDBN} stops and gives you control
edcc5120
TT
16530when any of shared library events happen. The best way to do this is
16531to use @code{catch load} and @code{catch unload} (@pxref{Set
16532Catchpoints}).
16533
16534@value{GDBN} also supports the the @code{set stop-on-solib-events}
16535command for this. This command exists for historical reasons. It is
16536less useful than setting a catchpoint, because it does not allow for
16537conditions or commands as a catchpoint does.
721c2651
EZ
16538
16539@table @code
16540@item set stop-on-solib-events
16541@kindex set stop-on-solib-events
16542This command controls whether @value{GDBN} should give you control
16543when the dynamic linker notifies it about some shared library event.
16544The most common event of interest is loading or unloading of a new
16545shared library.
16546
16547@item show stop-on-solib-events
16548@kindex show stop-on-solib-events
16549Show whether @value{GDBN} stops and gives you control when shared
16550library events happen.
16551@end table
16552
f5ebfba0 16553Shared libraries are also supported in many cross or remote debugging
f1838a98
UW
16554configurations. @value{GDBN} needs to have access to the target's libraries;
16555this can be accomplished either by providing copies of the libraries
16556on the host system, or by asking @value{GDBN} to automatically retrieve the
16557libraries from the target. If copies of the target libraries are
16558provided, they need to be the same as the target libraries, although the
f5ebfba0
DJ
16559copies on the target can be stripped as long as the copies on the host are
16560not.
16561
59b7b46f
EZ
16562@cindex where to look for shared libraries
16563For remote debugging, you need to tell @value{GDBN} where the target
16564libraries are, so that it can load the correct copies---otherwise, it
16565may try to load the host's libraries. @value{GDBN} has two variables
16566to specify the search directories for target libraries.
f5ebfba0
DJ
16567
16568@table @code
59b7b46f 16569@cindex prefix for shared library file names
f822c95b 16570@cindex system root, alternate
f5ebfba0 16571@kindex set solib-absolute-prefix
f822c95b
DJ
16572@kindex set sysroot
16573@item set sysroot @var{path}
16574Use @var{path} as the system root for the program being debugged. Any
16575absolute shared library paths will be prefixed with @var{path}; many
16576runtime loaders store the absolute paths to the shared library in the
16577target program's memory. If you use @code{set sysroot} to find shared
16578libraries, they need to be laid out in the same way that they are on
16579the target, with e.g.@: a @file{/lib} and @file{/usr/lib} hierarchy
16580under @var{path}.
16581
f1838a98
UW
16582If @var{path} starts with the sequence @file{remote:}, @value{GDBN} will
16583retrieve the target libraries from the remote system. This is only
16584supported when using a remote target that supports the @code{remote get}
16585command (@pxref{File Transfer,,Sending files to a remote system}).
16586The part of @var{path} following the initial @file{remote:}
16587(if present) is used as system root prefix on the remote file system.
16588@footnote{If you want to specify a local system root using a directory
16589that happens to be named @file{remote:}, you need to use some equivalent
16590variant of the name like @file{./remote:}.}
16591
ab38a727
PA
16592For targets with an MS-DOS based filesystem, such as MS-Windows and
16593SymbianOS, @value{GDBN} tries prefixing a few variants of the target
16594absolute file name with @var{path}. But first, on Unix hosts,
16595@value{GDBN} converts all backslash directory separators into forward
16596slashes, because the backslash is not a directory separator on Unix:
16597
16598@smallexample
16599 c:\foo\bar.dll @result{} c:/foo/bar.dll
16600@end smallexample
16601
16602Then, @value{GDBN} attempts prefixing the target file name with
16603@var{path}, and looks for the resulting file name in the host file
16604system:
16605
16606@smallexample
16607 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
16608@end smallexample
16609
16610If that does not find the shared library, @value{GDBN} tries removing
16611the @samp{:} character from the drive spec, both for convenience, and,
16612for the case of the host file system not supporting file names with
16613colons:
16614
16615@smallexample
16616 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
16617@end smallexample
16618
16619This makes it possible to have a system root that mirrors a target
16620with more than one drive. E.g., you may want to setup your local
16621copies of the target system shared libraries like so (note @samp{c} vs
16622@samp{z}):
16623
16624@smallexample
16625 @file{/path/to/sysroot/c/sys/bin/foo.dll}
16626 @file{/path/to/sysroot/c/sys/bin/bar.dll}
16627 @file{/path/to/sysroot/z/sys/bin/bar.dll}
16628@end smallexample
16629
16630@noindent
16631and point the system root at @file{/path/to/sysroot}, so that
16632@value{GDBN} can find the correct copies of both
16633@file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
16634
16635If that still does not find the shared library, @value{GDBN} tries
16636removing the whole drive spec from the target file name:
16637
16638@smallexample
16639 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
16640@end smallexample
16641
16642This last lookup makes it possible to not care about the drive name,
16643if you don't want or need to.
16644
f822c95b
DJ
16645The @code{set solib-absolute-prefix} command is an alias for @code{set
16646sysroot}.
16647
16648@cindex default system root
59b7b46f 16649@cindex @samp{--with-sysroot}
f822c95b
DJ
16650You can set the default system root by using the configure-time
16651@samp{--with-sysroot} option. If the system root is inside
16652@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
16653@samp{--exec-prefix}), then the default system root will be updated
16654automatically if the installed @value{GDBN} is moved to a new
16655location.
16656
16657@kindex show sysroot
16658@item show sysroot
f5ebfba0
DJ
16659Display the current shared library prefix.
16660
16661@kindex set solib-search-path
16662@item set solib-search-path @var{path}
f822c95b
DJ
16663If this variable is set, @var{path} is a colon-separated list of
16664directories to search for shared libraries. @samp{solib-search-path}
16665is used after @samp{sysroot} fails to locate the library, or if the
16666path to the library is relative instead of absolute. If you want to
16667use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 16668@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 16669finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 16670it to a nonexistent directory may interfere with automatic loading
f822c95b 16671of shared library symbols.
f5ebfba0
DJ
16672
16673@kindex show solib-search-path
16674@item show solib-search-path
16675Display the current shared library search path.
ab38a727
PA
16676
16677@cindex DOS file-name semantics of file names.
16678@kindex set target-file-system-kind (unix|dos-based|auto)
16679@kindex show target-file-system-kind
16680@item set target-file-system-kind @var{kind}
16681Set assumed file system kind for target reported file names.
16682
16683Shared library file names as reported by the target system may not
16684make sense as is on the system @value{GDBN} is running on. For
16685example, when remote debugging a target that has MS-DOS based file
16686system semantics, from a Unix host, the target may be reporting to
16687@value{GDBN} a list of loaded shared libraries with file names such as
16688@file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
16689drive letters, so the @samp{c:\} prefix is not normally understood as
16690indicating an absolute file name, and neither is the backslash
16691normally considered a directory separator character. In that case,
16692the native file system would interpret this whole absolute file name
16693as a relative file name with no directory components. This would make
16694it impossible to point @value{GDBN} at a copy of the remote target's
16695shared libraries on the host using @code{set sysroot}, and impractical
16696with @code{set solib-search-path}. Setting
16697@code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
16698to interpret such file names similarly to how the target would, and to
16699map them to file names valid on @value{GDBN}'s native file system
16700semantics. The value of @var{kind} can be @code{"auto"}, in addition
16701to one of the supported file system kinds. In that case, @value{GDBN}
16702tries to determine the appropriate file system variant based on the
16703current target's operating system (@pxref{ABI, ,Configuring the
16704Current ABI}). The supported file system settings are:
16705
16706@table @code
16707@item unix
16708Instruct @value{GDBN} to assume the target file system is of Unix
16709kind. Only file names starting the forward slash (@samp{/}) character
16710are considered absolute, and the directory separator character is also
16711the forward slash.
16712
16713@item dos-based
16714Instruct @value{GDBN} to assume the target file system is DOS based.
16715File names starting with either a forward slash, or a drive letter
16716followed by a colon (e.g., @samp{c:}), are considered absolute, and
16717both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
16718considered directory separators.
16719
16720@item auto
16721Instruct @value{GDBN} to use the file system kind associated with the
16722target operating system (@pxref{ABI, ,Configuring the Current ABI}).
16723This is the default.
16724@end table
f5ebfba0
DJ
16725@end table
16726
c011a4f4
DE
16727@cindex file name canonicalization
16728@cindex base name differences
16729When processing file names provided by the user, @value{GDBN}
16730frequently needs to compare them to the file names recorded in the
16731program's debug info. Normally, @value{GDBN} compares just the
16732@dfn{base names} of the files as strings, which is reasonably fast
16733even for very large programs. (The base name of a file is the last
16734portion of its name, after stripping all the leading directories.)
16735This shortcut in comparison is based upon the assumption that files
16736cannot have more than one base name. This is usually true, but
16737references to files that use symlinks or similar filesystem
16738facilities violate that assumption. If your program records files
16739using such facilities, or if you provide file names to @value{GDBN}
16740using symlinks etc., you can set @code{basenames-may-differ} to
16741@code{true} to instruct @value{GDBN} to completely canonicalize each
16742pair of file names it needs to compare. This will make file-name
16743comparisons accurate, but at a price of a significant slowdown.
16744
16745@table @code
16746@item set basenames-may-differ
16747@kindex set basenames-may-differ
16748Set whether a source file may have multiple base names.
16749
16750@item show basenames-may-differ
16751@kindex show basenames-may-differ
16752Show whether a source file may have multiple base names.
16753@end table
5b5d99cf
JB
16754
16755@node Separate Debug Files
16756@section Debugging Information in Separate Files
16757@cindex separate debugging information files
16758@cindex debugging information in separate files
16759@cindex @file{.debug} subdirectories
16760@cindex debugging information directory, global
f307c045 16761@cindex global debugging information directories
c7e83d54
EZ
16762@cindex build ID, and separate debugging files
16763@cindex @file{.build-id} directory
5b5d99cf
JB
16764
16765@value{GDBN} allows you to put a program's debugging information in a
16766file separate from the executable itself, in a way that allows
16767@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
16768Since debugging information can be very large---sometimes larger
16769than the executable code itself---some systems distribute debugging
5b5d99cf
JB
16770information for their executables in separate files, which users can
16771install only when they need to debug a problem.
16772
c7e83d54
EZ
16773@value{GDBN} supports two ways of specifying the separate debug info
16774file:
5b5d99cf
JB
16775
16776@itemize @bullet
16777@item
c7e83d54
EZ
16778The executable contains a @dfn{debug link} that specifies the name of
16779the separate debug info file. The separate debug file's name is
16780usually @file{@var{executable}.debug}, where @var{executable} is the
16781name of the corresponding executable file without leading directories
16782(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
99e008fe
EZ
16783debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
16784checksum for the debug file, which @value{GDBN} uses to validate that
16785the executable and the debug file came from the same build.
c7e83d54
EZ
16786
16787@item
7e27a47a 16788The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 16789also present in the corresponding debug info file. (This is supported
7e27a47a
EZ
16790only on some operating systems, notably those which use the ELF format
16791for binary files and the @sc{gnu} Binutils.) For more details about
16792this feature, see the description of the @option{--build-id}
16793command-line option in @ref{Options, , Command Line Options, ld.info,
16794The GNU Linker}. The debug info file's name is not specified
16795explicitly by the build ID, but can be computed from the build ID, see
16796below.
d3750b24
JK
16797@end itemize
16798
c7e83d54
EZ
16799Depending on the way the debug info file is specified, @value{GDBN}
16800uses two different methods of looking for the debug file:
d3750b24
JK
16801
16802@itemize @bullet
16803@item
c7e83d54
EZ
16804For the ``debug link'' method, @value{GDBN} looks up the named file in
16805the directory of the executable file, then in a subdirectory of that
f307c045
JK
16806directory named @file{.debug}, and finally under each one of the global debug
16807directories, in a subdirectory whose name is identical to the leading
c7e83d54
EZ
16808directories of the executable's absolute file name.
16809
16810@item
83f83d7f 16811For the ``build ID'' method, @value{GDBN} looks in the
f307c045
JK
16812@file{.build-id} subdirectory of each one of the global debug directories for
16813a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
16814first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
16815are the rest of the bit string. (Real build ID strings are 32 or more
16816hex characters, not 10.)
c7e83d54
EZ
16817@end itemize
16818
16819So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
16820@file{/usr/bin/ls}, which has a debug link that specifies the
16821file @file{ls.debug}, and a build ID whose value in hex is
f307c045 16822@code{abcdef1234}. If the list of the global debug directories includes
c7e83d54
EZ
16823@file{/usr/lib/debug}, then @value{GDBN} will look for the following
16824debug information files, in the indicated order:
16825
16826@itemize @minus
16827@item
16828@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 16829@item
c7e83d54 16830@file{/usr/bin/ls.debug}
5b5d99cf 16831@item
c7e83d54 16832@file{/usr/bin/.debug/ls.debug}
5b5d99cf 16833@item
c7e83d54 16834@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 16835@end itemize
5b5d99cf 16836
1564a261
JK
16837@anchor{debug-file-directory}
16838Global debugging info directories default to what is set by @value{GDBN}
16839configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
16840you can also set the global debugging info directories, and view the list
16841@value{GDBN} is currently using.
5b5d99cf
JB
16842
16843@table @code
16844
16845@kindex set debug-file-directory
24ddea62
JK
16846@item set debug-file-directory @var{directories}
16847Set the directories which @value{GDBN} searches for separate debugging
d9242c17
JK
16848information files to @var{directory}. Multiple path components can be set
16849concatenating them by a path separator.
5b5d99cf
JB
16850
16851@kindex show debug-file-directory
16852@item show debug-file-directory
24ddea62 16853Show the directories @value{GDBN} searches for separate debugging
5b5d99cf
JB
16854information files.
16855
16856@end table
16857
16858@cindex @code{.gnu_debuglink} sections
c7e83d54 16859@cindex debug link sections
5b5d99cf
JB
16860A debug link is a special section of the executable file named
16861@code{.gnu_debuglink}. The section must contain:
16862
16863@itemize
16864@item
16865A filename, with any leading directory components removed, followed by
16866a zero byte,
16867@item
16868zero to three bytes of padding, as needed to reach the next four-byte
16869boundary within the section, and
16870@item
16871a four-byte CRC checksum, stored in the same endianness used for the
16872executable file itself. The checksum is computed on the debugging
16873information file's full contents by the function given below, passing
16874zero as the @var{crc} argument.
16875@end itemize
16876
16877Any executable file format can carry a debug link, as long as it can
16878contain a section named @code{.gnu_debuglink} with the contents
16879described above.
16880
d3750b24 16881@cindex @code{.note.gnu.build-id} sections
c7e83d54 16882@cindex build ID sections
7e27a47a
EZ
16883The build ID is a special section in the executable file (and in other
16884ELF binary files that @value{GDBN} may consider). This section is
16885often named @code{.note.gnu.build-id}, but that name is not mandatory.
16886It contains unique identification for the built files---the ID remains
16887the same across multiple builds of the same build tree. The default
16888algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
16889content for the build ID string. The same section with an identical
16890value is present in the original built binary with symbols, in its
16891stripped variant, and in the separate debugging information file.
d3750b24 16892
5b5d99cf
JB
16893The debugging information file itself should be an ordinary
16894executable, containing a full set of linker symbols, sections, and
16895debugging information. The sections of the debugging information file
c7e83d54
EZ
16896should have the same names, addresses, and sizes as the original file,
16897but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
16898in an ordinary executable.
16899
7e27a47a 16900The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
16901@samp{objcopy} utility that can produce
16902the separated executable / debugging information file pairs using the
16903following commands:
16904
16905@smallexample
16906@kbd{objcopy --only-keep-debug foo foo.debug}
16907@kbd{strip -g foo}
c7e83d54
EZ
16908@end smallexample
16909
16910@noindent
16911These commands remove the debugging
83f83d7f
JK
16912information from the executable file @file{foo} and place it in the file
16913@file{foo.debug}. You can use the first, second or both methods to link the
16914two files:
16915
16916@itemize @bullet
16917@item
16918The debug link method needs the following additional command to also leave
16919behind a debug link in @file{foo}:
16920
16921@smallexample
16922@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
16923@end smallexample
16924
16925Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 16926a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
16927foo.debug} has the same functionality as the two @code{objcopy} commands and
16928the @code{ln -s} command above, together.
16929
16930@item
16931Build ID gets embedded into the main executable using @code{ld --build-id} or
16932the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
16933compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 16934utilities (Binutils) package since version 2.18.
83f83d7f
JK
16935@end itemize
16936
16937@noindent
d3750b24 16938
99e008fe
EZ
16939@cindex CRC algorithm definition
16940The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
16941IEEE 802.3 using the polynomial:
16942
16943@c TexInfo requires naked braces for multi-digit exponents for Tex
16944@c output, but this causes HTML output to barf. HTML has to be set using
16945@c raw commands. So we end up having to specify this equation in 2
16946@c different ways!
16947@ifhtml
16948@display
16949@html
16950 <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>
16951 + <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
16952@end html
16953@end display
16954@end ifhtml
16955@ifnothtml
16956@display
16957 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
16958 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
16959@end display
16960@end ifnothtml
16961
16962The function is computed byte at a time, taking the least
16963significant bit of each byte first. The initial pattern
16964@code{0xffffffff} is used, to ensure leading zeros affect the CRC and
16965the final result is inverted to ensure trailing zeros also affect the
16966CRC.
16967
16968@emph{Note:} This is the same CRC polynomial as used in handling the
16969@dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{Remote Protocol,
16970, @value{GDBN} Remote Serial Protocol}). However in the
16971case of the Remote Serial Protocol, the CRC is computed @emph{most}
16972significant bit first, and the result is not inverted, so trailing
16973zeros have no effect on the CRC value.
16974
16975To complete the description, we show below the code of the function
16976which produces the CRC used in @code{.gnu_debuglink}. Inverting the
16977initially supplied @code{crc} argument means that an initial call to
16978this function passing in zero will start computing the CRC using
16979@code{0xffffffff}.
5b5d99cf 16980
4644b6e3 16981@kindex gnu_debuglink_crc32
5b5d99cf
JB
16982@smallexample
16983unsigned long
16984gnu_debuglink_crc32 (unsigned long crc,
16985 unsigned char *buf, size_t len)
16986@{
16987 static const unsigned long crc32_table[256] =
16988 @{
16989 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
16990 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
16991 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
16992 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
16993 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
16994 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
16995 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
16996 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
16997 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
16998 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
16999 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
17000 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
17001 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
17002 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
17003 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
17004 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
17005 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
17006 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
17007 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
17008 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
17009 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
17010 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
17011 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
17012 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
17013 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
17014 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
17015 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
17016 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
17017 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
17018 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
17019 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
17020 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
17021 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
17022 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
17023 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
17024 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
17025 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
17026 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
17027 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
17028 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
17029 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
17030 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
17031 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
17032 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
17033 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
17034 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
17035 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
17036 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
17037 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
17038 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
17039 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
17040 0x2d02ef8d
17041 @};
17042 unsigned char *end;
17043
17044 crc = ~crc & 0xffffffff;
17045 for (end = buf + len; buf < end; ++buf)
17046 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 17047 return ~crc & 0xffffffff;
5b5d99cf
JB
17048@}
17049@end smallexample
17050
c7e83d54
EZ
17051@noindent
17052This computation does not apply to the ``build ID'' method.
17053
608e2dbb
TT
17054@node MiniDebugInfo
17055@section Debugging information in a special section
17056@cindex separate debug sections
17057@cindex @samp{.gnu_debugdata} section
17058
17059Some systems ship pre-built executables and libraries that have a
17060special @samp{.gnu_debugdata} section. This feature is called
17061@dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
17062is used to supply extra symbols for backtraces.
17063
17064The intent of this section is to provide extra minimal debugging
17065information for use in simple backtraces. It is not intended to be a
17066replacement for full separate debugging information (@pxref{Separate
17067Debug Files}). The example below shows the intended use; however,
17068@value{GDBN} does not currently put restrictions on what sort of
17069debugging information might be included in the section.
17070
17071@value{GDBN} has support for this extension. If the section exists,
17072then it is used provided that no other source of debugging information
17073can be found, and that @value{GDBN} was configured with LZMA support.
17074
17075This section can be easily created using @command{objcopy} and other
17076standard utilities:
17077
17078@smallexample
17079# Extract the dynamic symbols from the main binary, there is no need
17080# to also have these in the normal symbol table
17081nm -D @var{binary} --format=posix --defined-only \
17082 | awk '@{ print $1 @}' | sort > dynsyms
17083
17084# Extract all the text (i.e. function) symbols from the debuginfo .
17085nm @var{binary} --format=posix --defined-only \
17086 | awk '@{ if ($2 == "T" || $2 == "t") print $1 @}' \
17087 | sort > funcsyms
17088
17089# Keep all the function symbols not already in the dynamic symbol
17090# table.
17091comm -13 dynsyms funcsyms > keep_symbols
17092
17093# Copy the full debuginfo, keeping only a minimal set of symbols and
17094# removing some unnecessary sections.
17095objcopy -S --remove-section .gdb_index --remove-section .comment \
17096 --keep-symbols=keep_symbols @var{binary} mini_debuginfo
17097
17098# Inject the compressed data into the .gnu_debugdata section of the
17099# original binary.
17100xz mini_debuginfo
17101objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
17102@end smallexample
5b5d99cf 17103
9291a0cd
TT
17104@node Index Files
17105@section Index Files Speed Up @value{GDBN}
17106@cindex index files
17107@cindex @samp{.gdb_index} section
17108
17109When @value{GDBN} finds a symbol file, it scans the symbols in the
17110file in order to construct an internal symbol table. This lets most
17111@value{GDBN} operations work quickly---at the cost of a delay early
17112on. For large programs, this delay can be quite lengthy, so
17113@value{GDBN} provides a way to build an index, which speeds up
17114startup.
17115
17116The index is stored as a section in the symbol file. @value{GDBN} can
17117write the index to a file, then you can put it into the symbol file
17118using @command{objcopy}.
17119
17120To create an index file, use the @code{save gdb-index} command:
17121
17122@table @code
17123@item save gdb-index @var{directory}
17124@kindex save gdb-index
17125Create an index file for each symbol file currently known by
17126@value{GDBN}. Each file is named after its corresponding symbol file,
17127with @samp{.gdb-index} appended, and is written into the given
17128@var{directory}.
17129@end table
17130
17131Once you have created an index file you can merge it into your symbol
17132file, here named @file{symfile}, using @command{objcopy}:
17133
17134@smallexample
17135$ objcopy --add-section .gdb_index=symfile.gdb-index \
17136 --set-section-flags .gdb_index=readonly symfile symfile
17137@end smallexample
17138
e615022a
DE
17139@value{GDBN} will normally ignore older versions of @file{.gdb_index}
17140sections that have been deprecated. Usually they are deprecated because
17141they are missing a new feature or have performance issues.
17142To tell @value{GDBN} to use a deprecated index section anyway
17143specify @code{set use-deprecated-index-sections on}.
17144The default is @code{off}.
17145This can speed up startup, but may result in some functionality being lost.
17146@xref{Index Section Format}.
17147
17148@emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
17149must be done before gdb reads the file. The following will not work:
17150
17151@smallexample
17152$ gdb -ex "set use-deprecated-index-sections on" <program>
17153@end smallexample
17154
17155Instead you must do, for example,
17156
17157@smallexample
17158$ gdb -iex "set use-deprecated-index-sections on" <program>
17159@end smallexample
17160
9291a0cd
TT
17161There are currently some limitation on indices. They only work when
17162for DWARF debugging information, not stabs. And, they do not
17163currently work for programs using Ada.
17164
6d2ebf8b 17165@node Symbol Errors
79a6e687 17166@section Errors Reading Symbol Files
c906108c
SS
17167
17168While reading a symbol file, @value{GDBN} occasionally encounters problems,
17169such as symbol types it does not recognize, or known bugs in compiler
17170output. By default, @value{GDBN} does not notify you of such problems, since
17171they are relatively common and primarily of interest to people
17172debugging compilers. If you are interested in seeing information
17173about ill-constructed symbol tables, you can either ask @value{GDBN} to print
17174only one message about each such type of problem, no matter how many
17175times the problem occurs; or you can ask @value{GDBN} to print more messages,
17176to see how many times the problems occur, with the @code{set
79a6e687
BW
17177complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
17178Messages}).
c906108c
SS
17179
17180The messages currently printed, and their meanings, include:
17181
17182@table @code
17183@item inner block not inside outer block in @var{symbol}
17184
17185The symbol information shows where symbol scopes begin and end
17186(such as at the start of a function or a block of statements). This
17187error indicates that an inner scope block is not fully contained
17188in its outer scope blocks.
17189
17190@value{GDBN} circumvents the problem by treating the inner block as if it had
17191the same scope as the outer block. In the error message, @var{symbol}
17192may be shown as ``@code{(don't know)}'' if the outer block is not a
17193function.
17194
17195@item block at @var{address} out of order
17196
17197The symbol information for symbol scope blocks should occur in
17198order of increasing addresses. This error indicates that it does not
17199do so.
17200
17201@value{GDBN} does not circumvent this problem, and has trouble
17202locating symbols in the source file whose symbols it is reading. (You
17203can often determine what source file is affected by specifying
79a6e687
BW
17204@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
17205Messages}.)
c906108c
SS
17206
17207@item bad block start address patched
17208
17209The symbol information for a symbol scope block has a start address
17210smaller than the address of the preceding source line. This is known
17211to occur in the SunOS 4.1.1 (and earlier) C compiler.
17212
17213@value{GDBN} circumvents the problem by treating the symbol scope block as
17214starting on the previous source line.
17215
17216@item bad string table offset in symbol @var{n}
17217
17218@cindex foo
17219Symbol number @var{n} contains a pointer into the string table which is
17220larger than the size of the string table.
17221
17222@value{GDBN} circumvents the problem by considering the symbol to have the
17223name @code{foo}, which may cause other problems if many symbols end up
17224with this name.
17225
17226@item unknown symbol type @code{0x@var{nn}}
17227
7a292a7a
SS
17228The symbol information contains new data types that @value{GDBN} does
17229not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 17230uncomprehended information, in hexadecimal.
c906108c 17231
7a292a7a
SS
17232@value{GDBN} circumvents the error by ignoring this symbol information.
17233This usually allows you to debug your program, though certain symbols
c906108c 17234are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
17235debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
17236on @code{complain}, then go up to the function @code{read_dbx_symtab}
17237and examine @code{*bufp} to see the symbol.
c906108c
SS
17238
17239@item stub type has NULL name
c906108c 17240
7a292a7a 17241@value{GDBN} could not find the full definition for a struct or class.
c906108c 17242
7a292a7a 17243@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 17244The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
17245information that recent versions of the compiler should have output for
17246it.
c906108c
SS
17247
17248@item info mismatch between compiler and debugger
17249
17250@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 17251
c906108c
SS
17252@end table
17253
b14b1491
TT
17254@node Data Files
17255@section GDB Data Files
17256
17257@cindex prefix for data files
17258@value{GDBN} will sometimes read an auxiliary data file. These files
17259are kept in a directory known as the @dfn{data directory}.
17260
17261You can set the data directory's name, and view the name @value{GDBN}
17262is currently using.
17263
17264@table @code
17265@kindex set data-directory
17266@item set data-directory @var{directory}
17267Set the directory which @value{GDBN} searches for auxiliary data files
17268to @var{directory}.
17269
17270@kindex show data-directory
17271@item show data-directory
17272Show the directory @value{GDBN} searches for auxiliary data files.
17273@end table
17274
17275@cindex default data directory
17276@cindex @samp{--with-gdb-datadir}
17277You can set the default data directory by using the configure-time
17278@samp{--with-gdb-datadir} option. If the data directory is inside
17279@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
17280@samp{--exec-prefix}), then the default data directory will be updated
17281automatically if the installed @value{GDBN} is moved to a new
17282location.
17283
aae1c79a
DE
17284The data directory may also be specified with the
17285@code{--data-directory} command line option.
17286@xref{Mode Options}.
17287
6d2ebf8b 17288@node Targets
c906108c 17289@chapter Specifying a Debugging Target
7a292a7a 17290
c906108c 17291@cindex debugging target
c906108c 17292A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
17293
17294Often, @value{GDBN} runs in the same host environment as your program;
17295in that case, the debugging target is specified as a side effect when
17296you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
17297flexibility---for example, running @value{GDBN} on a physically separate
17298host, or controlling a standalone system over a serial port or a
53a5351d
JM
17299realtime system over a TCP/IP connection---you can use the @code{target}
17300command to specify one of the target types configured for @value{GDBN}
79a6e687 17301(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 17302
a8f24a35
EZ
17303@cindex target architecture
17304It is possible to build @value{GDBN} for several different @dfn{target
17305architectures}. When @value{GDBN} is built like that, you can choose
17306one of the available architectures with the @kbd{set architecture}
17307command.
17308
17309@table @code
17310@kindex set architecture
17311@kindex show architecture
17312@item set architecture @var{arch}
17313This command sets the current target architecture to @var{arch}. The
17314value of @var{arch} can be @code{"auto"}, in addition to one of the
17315supported architectures.
17316
17317@item show architecture
17318Show the current target architecture.
9c16f35a
EZ
17319
17320@item set processor
17321@itemx processor
17322@kindex set processor
17323@kindex show processor
17324These are alias commands for, respectively, @code{set architecture}
17325and @code{show architecture}.
a8f24a35
EZ
17326@end table
17327
c906108c
SS
17328@menu
17329* Active Targets:: Active targets
17330* Target Commands:: Commands for managing targets
c906108c 17331* Byte Order:: Choosing target byte order
c906108c
SS
17332@end menu
17333
6d2ebf8b 17334@node Active Targets
79a6e687 17335@section Active Targets
7a292a7a 17336
c906108c
SS
17337@cindex stacking targets
17338@cindex active targets
17339@cindex multiple targets
17340
8ea5bce5 17341There are multiple classes of targets such as: processes, executable files or
c0edd9ed
JK
17342recording sessions. Core files belong to the process class, making core file
17343and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
17344on multiple active targets, one in each class. This allows you to (for
17345example) start a process and inspect its activity, while still having access to
17346the executable file after the process finishes. Or if you start process
17347recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
17348presented a virtual layer of the recording target, while the process target
17349remains stopped at the chronologically last point of the process execution.
17350
17351Use the @code{core-file} and @code{exec-file} commands to select a new core
17352file or executable target (@pxref{Files, ,Commands to Specify Files}). To
17353specify as a target a process that is already running, use the @code{attach}
17354command (@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 17355
6d2ebf8b 17356@node Target Commands
79a6e687 17357@section Commands for Managing Targets
c906108c
SS
17358
17359@table @code
17360@item target @var{type} @var{parameters}
7a292a7a
SS
17361Connects the @value{GDBN} host environment to a target machine or
17362process. A target is typically a protocol for talking to debugging
17363facilities. You use the argument @var{type} to specify the type or
17364protocol of the target machine.
c906108c
SS
17365
17366Further @var{parameters} are interpreted by the target protocol, but
17367typically include things like device names or host names to connect
17368with, process numbers, and baud rates.
c906108c
SS
17369
17370The @code{target} command does not repeat if you press @key{RET} again
17371after executing the command.
17372
17373@kindex help target
17374@item help target
17375Displays the names of all targets available. To display targets
17376currently selected, use either @code{info target} or @code{info files}
79a6e687 17377(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
17378
17379@item help target @var{name}
17380Describe a particular target, including any parameters necessary to
17381select it.
17382
17383@kindex set gnutarget
17384@item set gnutarget @var{args}
5d161b24 17385@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 17386knows whether it is reading an @dfn{executable},
5d161b24
DB
17387a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
17388with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
17389with @code{gnutarget} the @code{target} refers to a program, not a machine.
17390
d4f3574e 17391@quotation
c906108c
SS
17392@emph{Warning:} To specify a file format with @code{set gnutarget},
17393you must know the actual BFD name.
d4f3574e 17394@end quotation
c906108c 17395
d4f3574e 17396@noindent
79a6e687 17397@xref{Files, , Commands to Specify Files}.
c906108c 17398
5d161b24 17399@kindex show gnutarget
c906108c
SS
17400@item show gnutarget
17401Use the @code{show gnutarget} command to display what file format
17402@code{gnutarget} is set to read. If you have not set @code{gnutarget},
17403@value{GDBN} will determine the file format for each file automatically,
c4957902 17404and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
c906108c
SS
17405@end table
17406
4644b6e3 17407@cindex common targets
c906108c
SS
17408Here are some common targets (available, or not, depending on the GDB
17409configuration):
c906108c
SS
17410
17411@table @code
4644b6e3 17412@kindex target
c906108c 17413@item target exec @var{program}
4644b6e3 17414@cindex executable file target
c906108c
SS
17415An executable file. @samp{target exec @var{program}} is the same as
17416@samp{exec-file @var{program}}.
17417
c906108c 17418@item target core @var{filename}
4644b6e3 17419@cindex core dump file target
c906108c
SS
17420A core dump file. @samp{target core @var{filename}} is the same as
17421@samp{core-file @var{filename}}.
c906108c 17422
1a10341b 17423@item target remote @var{medium}
4644b6e3 17424@cindex remote target
1a10341b
JB
17425A remote system connected to @value{GDBN} via a serial line or network
17426connection. This command tells @value{GDBN} to use its own remote
17427protocol over @var{medium} for debugging. @xref{Remote Debugging}.
17428
17429For example, if you have a board connected to @file{/dev/ttya} on the
17430machine running @value{GDBN}, you could say:
17431
17432@smallexample
17433target remote /dev/ttya
17434@end smallexample
17435
17436@code{target remote} supports the @code{load} command. This is only
17437useful if you have some other way of getting the stub to the target
17438system, and you can put it somewhere in memory where it won't get
17439clobbered by the download.
c906108c 17440
ee8e71d4 17441@item target sim @r{[}@var{simargs}@r{]} @dots{}
4644b6e3 17442@cindex built-in simulator target
2df3850c 17443Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 17444In general,
474c8240 17445@smallexample
104c1213
JM
17446 target sim
17447 load
17448 run
474c8240 17449@end smallexample
d4f3574e 17450@noindent
104c1213 17451works; however, you cannot assume that a specific memory map, device
d4f3574e 17452drivers, or even basic I/O is available, although some simulators do
104c1213
JM
17453provide these. For info about any processor-specific simulator details,
17454see the appropriate section in @ref{Embedded Processors, ,Embedded
17455Processors}.
17456
c906108c
SS
17457@end table
17458
104c1213 17459Some configurations may include these targets as well:
c906108c
SS
17460
17461@table @code
17462
c906108c 17463@item target nrom @var{dev}
4644b6e3 17464@cindex NetROM ROM emulator target
c906108c
SS
17465NetROM ROM emulator. This target only supports downloading.
17466
c906108c
SS
17467@end table
17468
5d161b24 17469Different targets are available on different configurations of @value{GDBN};
c906108c 17470your configuration may have more or fewer targets.
c906108c 17471
721c2651
EZ
17472Many remote targets require you to download the executable's code once
17473you've successfully established a connection. You may wish to control
3d00d119
DJ
17474various aspects of this process.
17475
17476@table @code
721c2651
EZ
17477
17478@item set hash
17479@kindex set hash@r{, for remote monitors}
17480@cindex hash mark while downloading
17481This command controls whether a hash mark @samp{#} is displayed while
17482downloading a file to the remote monitor. If on, a hash mark is
17483displayed after each S-record is successfully downloaded to the
17484monitor.
17485
17486@item show hash
17487@kindex show hash@r{, for remote monitors}
17488Show the current status of displaying the hash mark.
17489
17490@item set debug monitor
17491@kindex set debug monitor
17492@cindex display remote monitor communications
17493Enable or disable display of communications messages between
17494@value{GDBN} and the remote monitor.
17495
17496@item show debug monitor
17497@kindex show debug monitor
17498Show the current status of displaying communications between
17499@value{GDBN} and the remote monitor.
a8f24a35 17500@end table
c906108c
SS
17501
17502@table @code
17503
17504@kindex load @var{filename}
17505@item load @var{filename}
8edfe269 17506@anchor{load}
c906108c
SS
17507Depending on what remote debugging facilities are configured into
17508@value{GDBN}, the @code{load} command may be available. Where it exists, it
17509is meant to make @var{filename} (an executable) available for debugging
17510on the remote system---by downloading, or dynamic linking, for example.
17511@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
17512the @code{add-symbol-file} command.
17513
17514If your @value{GDBN} does not have a @code{load} command, attempting to
17515execute it gets the error message ``@code{You can't do that when your
17516target is @dots{}}''
c906108c
SS
17517
17518The file is loaded at whatever address is specified in the executable.
17519For some object file formats, you can specify the load address when you
17520link the program; for other formats, like a.out, the object file format
17521specifies a fixed address.
17522@c FIXME! This would be a good place for an xref to the GNU linker doc.
17523
68437a39
DJ
17524Depending on the remote side capabilities, @value{GDBN} may be able to
17525load programs into flash memory.
17526
c906108c
SS
17527@code{load} does not repeat if you press @key{RET} again after using it.
17528@end table
17529
6d2ebf8b 17530@node Byte Order
79a6e687 17531@section Choosing Target Byte Order
7a292a7a 17532
c906108c
SS
17533@cindex choosing target byte order
17534@cindex target byte order
c906108c 17535
eb17f351 17536Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
c906108c
SS
17537offer the ability to run either big-endian or little-endian byte
17538orders. Usually the executable or symbol will include a bit to
17539designate the endian-ness, and you will not need to worry about
17540which to use. However, you may still find it useful to adjust
d4f3574e 17541@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
17542
17543@table @code
4644b6e3 17544@kindex set endian
c906108c
SS
17545@item set endian big
17546Instruct @value{GDBN} to assume the target is big-endian.
17547
c906108c
SS
17548@item set endian little
17549Instruct @value{GDBN} to assume the target is little-endian.
17550
c906108c
SS
17551@item set endian auto
17552Instruct @value{GDBN} to use the byte order associated with the
17553executable.
17554
17555@item show endian
17556Display @value{GDBN}'s current idea of the target byte order.
17557
17558@end table
17559
17560Note that these commands merely adjust interpretation of symbolic
17561data on the host, and that they have absolutely no effect on the
17562target system.
17563
ea35711c
DJ
17564
17565@node Remote Debugging
17566@chapter Debugging Remote Programs
c906108c
SS
17567@cindex remote debugging
17568
17569If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
17570@value{GDBN} in the usual way, it is often useful to use remote debugging.
17571For example, you might use remote debugging on an operating system kernel,
c906108c
SS
17572or on a small system which does not have a general purpose operating system
17573powerful enough to run a full-featured debugger.
17574
17575Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
17576to make this work with particular debugging targets. In addition,
5d161b24 17577@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
17578but not specific to any particular target system) which you can use if you
17579write the remote stubs---the code that runs on the remote system to
17580communicate with @value{GDBN}.
17581
17582Other remote targets may be available in your
17583configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 17584
6b2f586d 17585@menu
07f31aa6 17586* Connecting:: Connecting to a remote target
a6b151f1 17587* File Transfer:: Sending files to a remote system
6b2f586d 17588* Server:: Using the gdbserver program
79a6e687
BW
17589* Remote Configuration:: Remote configuration
17590* Remote Stub:: Implementing a remote stub
6b2f586d
AC
17591@end menu
17592
07f31aa6 17593@node Connecting
79a6e687 17594@section Connecting to a Remote Target
07f31aa6
DJ
17595
17596On the @value{GDBN} host machine, you will need an unstripped copy of
d3e8051b 17597your program, since @value{GDBN} needs symbol and debugging information.
07f31aa6
DJ
17598Start up @value{GDBN} as usual, using the name of the local copy of your
17599program as the first argument.
17600
86941c27
JB
17601@cindex @code{target remote}
17602@value{GDBN} can communicate with the target over a serial line, or
17603over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
17604each case, @value{GDBN} uses the same protocol for debugging your
17605program; only the medium carrying the debugging packets varies. The
17606@code{target remote} command establishes a connection to the target.
17607Its arguments indicate which medium to use:
17608
17609@table @code
17610
17611@item target remote @var{serial-device}
07f31aa6 17612@cindex serial line, @code{target remote}
86941c27
JB
17613Use @var{serial-device} to communicate with the target. For example,
17614to use a serial line connected to the device named @file{/dev/ttyb}:
17615
17616@smallexample
17617target remote /dev/ttyb
17618@end smallexample
17619
07f31aa6
DJ
17620If you're using a serial line, you may want to give @value{GDBN} the
17621@w{@samp{--baud}} option, or use the @code{set remotebaud} command
79a6e687 17622(@pxref{Remote Configuration, set remotebaud}) before the
9c16f35a 17623@code{target} command.
07f31aa6 17624
86941c27
JB
17625@item target remote @code{@var{host}:@var{port}}
17626@itemx target remote @code{tcp:@var{host}:@var{port}}
17627@cindex @acronym{TCP} port, @code{target remote}
17628Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
17629The @var{host} may be either a host name or a numeric @acronym{IP}
17630address; @var{port} must be a decimal number. The @var{host} could be
17631the target machine itself, if it is directly connected to the net, or
17632it might be a terminal server which in turn has a serial line to the
17633target.
07f31aa6 17634
86941c27
JB
17635For example, to connect to port 2828 on a terminal server named
17636@code{manyfarms}:
07f31aa6
DJ
17637
17638@smallexample
17639target remote manyfarms:2828
17640@end smallexample
17641
86941c27
JB
17642If your remote target is actually running on the same machine as your
17643debugger session (e.g.@: a simulator for your target running on the
17644same host), you can omit the hostname. For example, to connect to
17645port 1234 on your local machine:
07f31aa6
DJ
17646
17647@smallexample
17648target remote :1234
17649@end smallexample
17650@noindent
17651
17652Note that the colon is still required here.
17653
86941c27
JB
17654@item target remote @code{udp:@var{host}:@var{port}}
17655@cindex @acronym{UDP} port, @code{target remote}
17656Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
17657connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
17658
17659@smallexample
17660target remote udp:manyfarms:2828
17661@end smallexample
17662
86941c27
JB
17663When using a @acronym{UDP} connection for remote debugging, you should
17664keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
17665can silently drop packets on busy or unreliable networks, which will
17666cause havoc with your debugging session.
17667
66b8c7f6
JB
17668@item target remote | @var{command}
17669@cindex pipe, @code{target remote} to
17670Run @var{command} in the background and communicate with it using a
17671pipe. The @var{command} is a shell command, to be parsed and expanded
17672by the system's command shell, @code{/bin/sh}; it should expect remote
17673protocol packets on its standard input, and send replies on its
17674standard output. You could use this to run a stand-alone simulator
17675that speaks the remote debugging protocol, to make net connections
17676using programs like @code{ssh}, or for other similar tricks.
17677
17678If @var{command} closes its standard output (perhaps by exiting),
17679@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
17680program has already exited, this will have no effect.)
17681
86941c27 17682@end table
07f31aa6 17683
86941c27 17684Once the connection has been established, you can use all the usual
8edfe269
DJ
17685commands to examine and change data. The remote program is already
17686running; you can use @kbd{step} and @kbd{continue}, and you do not
17687need to use @kbd{run}.
07f31aa6
DJ
17688
17689@cindex interrupting remote programs
17690@cindex remote programs, interrupting
17691Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 17692interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
17693program. This may or may not succeed, depending in part on the hardware
17694and the serial drivers the remote system uses. If you type the
17695interrupt character once again, @value{GDBN} displays this prompt:
17696
17697@smallexample
17698Interrupted while waiting for the program.
17699Give up (and stop debugging it)? (y or n)
17700@end smallexample
17701
17702If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
17703(If you decide you want to try again later, you can use @samp{target
17704remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
17705goes back to waiting.
17706
17707@table @code
17708@kindex detach (remote)
17709@item detach
17710When you have finished debugging the remote program, you can use the
17711@code{detach} command to release it from @value{GDBN} control.
17712Detaching from the target normally resumes its execution, but the results
17713will depend on your particular remote stub. After the @code{detach}
17714command, @value{GDBN} is free to connect to another target.
17715
17716@kindex disconnect
17717@item disconnect
17718The @code{disconnect} command behaves like @code{detach}, except that
17719the target is generally not resumed. It will wait for @value{GDBN}
17720(this instance or another one) to connect and continue debugging. After
17721the @code{disconnect} command, @value{GDBN} is again free to connect to
17722another target.
09d4efe1
EZ
17723
17724@cindex send command to remote monitor
fad38dfa
EZ
17725@cindex extend @value{GDBN} for remote targets
17726@cindex add new commands for external monitor
09d4efe1
EZ
17727@kindex monitor
17728@item monitor @var{cmd}
fad38dfa
EZ
17729This command allows you to send arbitrary commands directly to the
17730remote monitor. Since @value{GDBN} doesn't care about the commands it
17731sends like this, this command is the way to extend @value{GDBN}---you
17732can add new commands that only the external monitor will understand
17733and implement.
07f31aa6
DJ
17734@end table
17735
a6b151f1
DJ
17736@node File Transfer
17737@section Sending files to a remote system
17738@cindex remote target, file transfer
17739@cindex file transfer
17740@cindex sending files to remote systems
17741
17742Some remote targets offer the ability to transfer files over the same
17743connection used to communicate with @value{GDBN}. This is convenient
17744for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
17745running @code{gdbserver} over a network interface. For other targets,
17746e.g.@: embedded devices with only a single serial port, this may be
17747the only way to upload or download files.
17748
17749Not all remote targets support these commands.
17750
17751@table @code
17752@kindex remote put
17753@item remote put @var{hostfile} @var{targetfile}
17754Copy file @var{hostfile} from the host system (the machine running
17755@value{GDBN}) to @var{targetfile} on the target system.
17756
17757@kindex remote get
17758@item remote get @var{targetfile} @var{hostfile}
17759Copy file @var{targetfile} from the target system to @var{hostfile}
17760on the host system.
17761
17762@kindex remote delete
17763@item remote delete @var{targetfile}
17764Delete @var{targetfile} from the target system.
17765
17766@end table
17767
6f05cf9f 17768@node Server
79a6e687 17769@section Using the @code{gdbserver} Program
6f05cf9f
AC
17770
17771@kindex gdbserver
17772@cindex remote connection without stubs
17773@code{gdbserver} is a control program for Unix-like systems, which
17774allows you to connect your program with a remote @value{GDBN} via
17775@code{target remote}---but without linking in the usual debugging stub.
17776
17777@code{gdbserver} is not a complete replacement for the debugging stubs,
17778because it requires essentially the same operating-system facilities
17779that @value{GDBN} itself does. In fact, a system that can run
17780@code{gdbserver} to connect to a remote @value{GDBN} could also run
17781@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
17782because it is a much smaller program than @value{GDBN} itself. It is
17783also easier to port than all of @value{GDBN}, so you may be able to get
17784started more quickly on a new system by using @code{gdbserver}.
17785Finally, if you develop code for real-time systems, you may find that
17786the tradeoffs involved in real-time operation make it more convenient to
17787do as much development work as possible on another system, for example
17788by cross-compiling. You can use @code{gdbserver} to make a similar
17789choice for debugging.
17790
17791@value{GDBN} and @code{gdbserver} communicate via either a serial line
17792or a TCP connection, using the standard @value{GDBN} remote serial
17793protocol.
17794
2d717e4f
DJ
17795@quotation
17796@emph{Warning:} @code{gdbserver} does not have any built-in security.
17797Do not run @code{gdbserver} connected to any public network; a
17798@value{GDBN} connection to @code{gdbserver} provides access to the
17799target system with the same privileges as the user running
17800@code{gdbserver}.
17801@end quotation
17802
17803@subsection Running @code{gdbserver}
17804@cindex arguments, to @code{gdbserver}
d9b1a651 17805@cindex @code{gdbserver}, command-line arguments
2d717e4f
DJ
17806
17807Run @code{gdbserver} on the target system. You need a copy of the
17808program you want to debug, including any libraries it requires.
6f05cf9f
AC
17809@code{gdbserver} does not need your program's symbol table, so you can
17810strip the program if necessary to save space. @value{GDBN} on the host
17811system does all the symbol handling.
17812
17813To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 17814the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
17815syntax is:
17816
17817@smallexample
17818target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
17819@end smallexample
17820
e0f9f062
DE
17821@var{comm} is either a device name (to use a serial line), or a TCP
17822hostname and portnumber, or @code{-} or @code{stdio} to use
17823stdin/stdout of @code{gdbserver}.
17824For example, to debug Emacs with the argument
6f05cf9f
AC
17825@samp{foo.txt} and communicate with @value{GDBN} over the serial port
17826@file{/dev/com1}:
17827
17828@smallexample
17829target> gdbserver /dev/com1 emacs foo.txt
17830@end smallexample
17831
17832@code{gdbserver} waits passively for the host @value{GDBN} to communicate
17833with it.
17834
17835To use a TCP connection instead of a serial line:
17836
17837@smallexample
17838target> gdbserver host:2345 emacs foo.txt
17839@end smallexample
17840
17841The only difference from the previous example is the first argument,
17842specifying that you are communicating with the host @value{GDBN} via
17843TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
17844expect a TCP connection from machine @samp{host} to local TCP port 2345.
17845(Currently, the @samp{host} part is ignored.) You can choose any number
17846you want for the port number as long as it does not conflict with any
17847TCP ports already in use on the target system (for example, @code{23} is
17848reserved for @code{telnet}).@footnote{If you choose a port number that
17849conflicts with another service, @code{gdbserver} prints an error message
17850and exits.} You must use the same port number with the host @value{GDBN}
17851@code{target remote} command.
17852
e0f9f062
DE
17853The @code{stdio} connection is useful when starting @code{gdbserver}
17854with ssh:
17855
17856@smallexample
17857(gdb) target remote | ssh -T hostname gdbserver - hello
17858@end smallexample
17859
17860The @samp{-T} option to ssh is provided because we don't need a remote pty,
17861and we don't want escape-character handling. Ssh does this by default when
17862a command is provided, the flag is provided to make it explicit.
17863You could elide it if you want to.
17864
17865Programs started with stdio-connected gdbserver have @file{/dev/null} for
17866@code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
17867display through a pipe connected to gdbserver.
17868Both @code{stdout} and @code{stderr} use the same pipe.
17869
2d717e4f 17870@subsubsection Attaching to a Running Program
d9b1a651
EZ
17871@cindex attach to a program, @code{gdbserver}
17872@cindex @option{--attach}, @code{gdbserver} option
2d717e4f 17873
56460a61
DJ
17874On some targets, @code{gdbserver} can also attach to running programs.
17875This is accomplished via the @code{--attach} argument. The syntax is:
17876
17877@smallexample
2d717e4f 17878target> gdbserver --attach @var{comm} @var{pid}
56460a61
DJ
17879@end smallexample
17880
17881@var{pid} is the process ID of a currently running process. It isn't necessary
17882to point @code{gdbserver} at a binary for the running process.
17883
b1fe9455 17884@pindex pidof
b1fe9455
DJ
17885You can debug processes by name instead of process ID if your target has the
17886@code{pidof} utility:
17887
17888@smallexample
2d717e4f 17889target> gdbserver --attach @var{comm} `pidof @var{program}`
b1fe9455
DJ
17890@end smallexample
17891
f822c95b 17892In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
17893has multiple threads, most versions of @code{pidof} support the
17894@code{-s} option to only return the first process ID.
17895
2d717e4f 17896@subsubsection Multi-Process Mode for @code{gdbserver}
d9b1a651
EZ
17897@cindex @code{gdbserver}, multiple processes
17898@cindex multiple processes with @code{gdbserver}
2d717e4f
DJ
17899
17900When you connect to @code{gdbserver} using @code{target remote},
17901@code{gdbserver} debugs the specified program only once. When the
17902program exits, or you detach from it, @value{GDBN} closes the connection
17903and @code{gdbserver} exits.
17904
6e6c6f50 17905If you connect using @kbd{target extended-remote}, @code{gdbserver}
2d717e4f
DJ
17906enters multi-process mode. When the debugged program exits, or you
17907detach from it, @value{GDBN} stays connected to @code{gdbserver} even
17908though no program is running. The @code{run} and @code{attach}
17909commands instruct @code{gdbserver} to run or attach to a new program.
17910The @code{run} command uses @code{set remote exec-file} (@pxref{set
17911remote exec-file}) to select the program to run. Command line
17912arguments are supported, except for wildcard expansion and I/O
17913redirection (@pxref{Arguments}).
17914
d9b1a651 17915@cindex @option{--multi}, @code{gdbserver} option
2d717e4f
DJ
17916To start @code{gdbserver} without supplying an initial command to run
17917or process ID to attach, use the @option{--multi} command line option.
6e6c6f50 17918Then you can connect using @kbd{target extended-remote} and start
2d717e4f
DJ
17919the program you want to debug.
17920
03f2bd59
JK
17921In multi-process mode @code{gdbserver} does not automatically exit unless you
17922use the option @option{--once}. You can terminate it by using
17923@code{monitor exit} (@pxref{Monitor Commands for gdbserver}). Note that the
17924conditions under which @code{gdbserver} terminates depend on how @value{GDBN}
17925connects to it (@kbd{target remote} or @kbd{target extended-remote}). The
17926@option{--multi} option to @code{gdbserver} has no influence on that.
17927
17928@subsubsection TCP port allocation lifecycle of @code{gdbserver}
17929
17930This section applies only when @code{gdbserver} is run to listen on a TCP port.
17931
17932@code{gdbserver} normally terminates after all of its debugged processes have
17933terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
17934extended-remote}, @code{gdbserver} stays running even with no processes left.
17935@value{GDBN} normally terminates the spawned debugged process on its exit,
17936which normally also terminates @code{gdbserver} in the @kbd{target remote}
17937mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
17938cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
17939stays running even in the @kbd{target remote} mode.
17940
17941When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
17942Such reconnecting is useful for features like @ref{disconnected tracing}. For
17943completeness, at most one @value{GDBN} can be connected at a time.
17944
17945@cindex @option{--once}, @code{gdbserver} option
17946By default, @code{gdbserver} keeps the listening TCP port open, so that
17947additional connections are possible. However, if you start @code{gdbserver}
17948with the @option{--once} option, it will stop listening for any further
17949connection attempts after connecting to the first @value{GDBN} session. This
17950means no further connections to @code{gdbserver} will be possible after the
17951first one. It also means @code{gdbserver} will terminate after the first
17952connection with remote @value{GDBN} has closed, even for unexpectedly closed
17953connections and even in the @kbd{target extended-remote} mode. The
17954@option{--once} option allows reusing the same port number for connecting to
17955multiple instances of @code{gdbserver} running on the same host, since each
17956instance closes its port after the first connection.
2d717e4f
DJ
17957
17958@subsubsection Other Command-Line Arguments for @code{gdbserver}
17959
d9b1a651 17960@cindex @option{--debug}, @code{gdbserver} option
62709adf 17961The @option{--debug} option tells @code{gdbserver} to display extra
d9b1a651
EZ
17962status information about the debugging process.
17963@cindex @option{--remote-debug}, @code{gdbserver} option
17964The @option{--remote-debug} option tells @code{gdbserver} to display
62709adf
PA
17965remote protocol debug output. These options are intended for
17966@code{gdbserver} development and for bug reports to the developers.
2d717e4f 17967
d9b1a651 17968@cindex @option{--wrapper}, @code{gdbserver} option
ccd213ac
DJ
17969The @option{--wrapper} option specifies a wrapper to launch programs
17970for debugging. The option should be followed by the name of the
17971wrapper, then any command-line arguments to pass to the wrapper, then
17972@kbd{--} indicating the end of the wrapper arguments.
17973
17974@code{gdbserver} runs the specified wrapper program with a combined
17975command line including the wrapper arguments, then the name of the
17976program to debug, then any arguments to the program. The wrapper
17977runs until it executes your program, and then @value{GDBN} gains control.
17978
17979You can use any program that eventually calls @code{execve} with
17980its arguments as a wrapper. Several standard Unix utilities do
17981this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
17982with @code{exec "$@@"} will also work.
17983
17984For example, you can use @code{env} to pass an environment variable to
17985the debugged program, without setting the variable in @code{gdbserver}'s
17986environment:
17987
17988@smallexample
17989$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
17990@end smallexample
17991
2d717e4f
DJ
17992@subsection Connecting to @code{gdbserver}
17993
17994Run @value{GDBN} on the host system.
17995
17996First make sure you have the necessary symbol files. Load symbols for
f822c95b
DJ
17997your application using the @code{file} command before you connect. Use
17998@code{set sysroot} to locate target libraries (unless your @value{GDBN}
2d717e4f 17999was compiled with the correct sysroot using @code{--with-sysroot}).
f822c95b
DJ
18000
18001The symbol file and target libraries must exactly match the executable
18002and libraries on the target, with one exception: the files on the host
18003system should not be stripped, even if the files on the target system
18004are. Mismatched or missing files will lead to confusing results
18005during debugging. On @sc{gnu}/Linux targets, mismatched or missing
18006files may also prevent @code{gdbserver} from debugging multi-threaded
18007programs.
18008
79a6e687 18009Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f
AC
18010For TCP connections, you must start up @code{gdbserver} prior to using
18011the @code{target remote} command. Otherwise you may get an error whose
18012text depends on the host system, but which usually looks something like
2d717e4f 18013@samp{Connection refused}. Don't use the @code{load}
397ca115 18014command in @value{GDBN} when using @code{gdbserver}, since the program is
f822c95b 18015already on the target.
07f31aa6 18016
79a6e687 18017@subsection Monitor Commands for @code{gdbserver}
c74d0ad8 18018@cindex monitor commands, for @code{gdbserver}
2d717e4f 18019@anchor{Monitor Commands for gdbserver}
c74d0ad8
DJ
18020
18021During a @value{GDBN} session using @code{gdbserver}, you can use the
18022@code{monitor} command to send special requests to @code{gdbserver}.
2d717e4f 18023Here are the available commands.
c74d0ad8
DJ
18024
18025@table @code
18026@item monitor help
18027List the available monitor commands.
18028
18029@item monitor set debug 0
18030@itemx monitor set debug 1
18031Disable or enable general debugging messages.
18032
18033@item monitor set remote-debug 0
18034@itemx monitor set remote-debug 1
18035Disable or enable specific debugging messages associated with the remote
18036protocol (@pxref{Remote Protocol}).
18037
cdbfd419
PP
18038@item monitor set libthread-db-search-path [PATH]
18039@cindex gdbserver, search path for @code{libthread_db}
18040When this command is issued, @var{path} is a colon-separated list of
18041directories to search for @code{libthread_db} (@pxref{Threads,,set
18042libthread-db-search-path}). If you omit @var{path},
84e578fb 18043@samp{libthread-db-search-path} will be reset to its default value.
cdbfd419 18044
98a5dd13
DE
18045The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
18046not supported in @code{gdbserver}.
18047
2d717e4f
DJ
18048@item monitor exit
18049Tell gdbserver to exit immediately. This command should be followed by
18050@code{disconnect} to close the debugging session. @code{gdbserver} will
18051detach from any attached processes and kill any processes it created.
18052Use @code{monitor exit} to terminate @code{gdbserver} at the end
18053of a multi-process mode debug session.
18054
c74d0ad8
DJ
18055@end table
18056
fa593d66
PA
18057@subsection Tracepoints support in @code{gdbserver}
18058@cindex tracepoints support in @code{gdbserver}
18059
0fb4aa4b
PA
18060On some targets, @code{gdbserver} supports tracepoints, fast
18061tracepoints and static tracepoints.
fa593d66 18062
0fb4aa4b 18063For fast or static tracepoints to work, a special library called the
fa593d66
PA
18064@dfn{in-process agent} (IPA), must be loaded in the inferior process.
18065This library is built and distributed as an integral part of
0fb4aa4b
PA
18066@code{gdbserver}. In addition, support for static tracepoints
18067requires building the in-process agent library with static tracepoints
18068support. At present, the UST (LTTng Userspace Tracer,
18069@url{http://lttng.org/ust}) tracing engine is supported. This support
18070is automatically available if UST development headers are found in the
18071standard include path when @code{gdbserver} is built, or if
18072@code{gdbserver} was explicitly configured using @option{--with-ust}
18073to point at such headers. You can explicitly disable the support
18074using @option{--with-ust=no}.
fa593d66
PA
18075
18076There are several ways to load the in-process agent in your program:
18077
18078@table @code
18079@item Specifying it as dependency at link time
18080
18081You can link your program dynamically with the in-process agent
18082library. On most systems, this is accomplished by adding
18083@code{-linproctrace} to the link command.
18084
18085@item Using the system's preloading mechanisms
18086
18087You can force loading the in-process agent at startup time by using
18088your system's support for preloading shared libraries. Many Unixes
18089support the concept of preloading user defined libraries. In most
18090cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
18091in the environment. See also the description of @code{gdbserver}'s
18092@option{--wrapper} command line option.
18093
18094@item Using @value{GDBN} to force loading the agent at run time
18095
18096On some systems, you can force the inferior to load a shared library,
18097by calling a dynamic loader function in the inferior that takes care
18098of dynamically looking up and loading a shared library. On most Unix
18099systems, the function is @code{dlopen}. You'll use the @code{call}
18100command for that. For example:
18101
18102@smallexample
18103(@value{GDBP}) call dlopen ("libinproctrace.so", ...)
18104@end smallexample
18105
18106Note that on most Unix systems, for the @code{dlopen} function to be
18107available, the program needs to be linked with @code{-ldl}.
18108@end table
18109
18110On systems that have a userspace dynamic loader, like most Unix
18111systems, when you connect to @code{gdbserver} using @code{target
18112remote}, you'll find that the program is stopped at the dynamic
18113loader's entry point, and no shared library has been loaded in the
18114program's address space yet, including the in-process agent. In that
0fb4aa4b
PA
18115case, before being able to use any of the fast or static tracepoints
18116features, you need to let the loader run and load the shared
18117libraries. The simplest way to do that is to run the program to the
18118main procedure. E.g., if debugging a C or C@t{++} program, start
fa593d66
PA
18119@code{gdbserver} like so:
18120
18121@smallexample
18122$ gdbserver :9999 myprogram
18123@end smallexample
18124
18125Start GDB and connect to @code{gdbserver} like so, and run to main:
18126
18127@smallexample
18128$ gdb myprogram
18129(@value{GDBP}) target remote myhost:9999
181300x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
18131(@value{GDBP}) b main
18132(@value{GDBP}) continue
18133@end smallexample
18134
18135The in-process tracing agent library should now be loaded into the
18136process; you can confirm it with the @code{info sharedlibrary}
18137command, which will list @file{libinproctrace.so} as loaded in the
0fb4aa4b
PA
18138process. You are now ready to install fast tracepoints, list static
18139tracepoint markers, probe static tracepoints markers, and start
fa593d66
PA
18140tracing.
18141
79a6e687
BW
18142@node Remote Configuration
18143@section Remote Configuration
501eef12 18144
9c16f35a
EZ
18145@kindex set remote
18146@kindex show remote
18147This section documents the configuration options available when
18148debugging remote programs. For the options related to the File I/O
fc320d37 18149extensions of the remote protocol, see @ref{system,
9c16f35a 18150system-call-allowed}.
501eef12
AC
18151
18152@table @code
9c16f35a 18153@item set remoteaddresssize @var{bits}
d3e8051b 18154@cindex address size for remote targets
9c16f35a
EZ
18155@cindex bits in remote address
18156Set the maximum size of address in a memory packet to the specified
18157number of bits. @value{GDBN} will mask off the address bits above
18158that number, when it passes addresses to the remote target. The
18159default value is the number of bits in the target's address.
18160
18161@item show remoteaddresssize
18162Show the current value of remote address size in bits.
18163
18164@item set remotebaud @var{n}
18165@cindex baud rate for remote targets
18166Set the baud rate for the remote serial I/O to @var{n} baud. The
18167value is used to set the speed of the serial port used for debugging
18168remote targets.
18169
18170@item show remotebaud
18171Show the current speed of the remote connection.
18172
18173@item set remotebreak
18174@cindex interrupt remote programs
18175@cindex BREAK signal instead of Ctrl-C
9a6253be 18176@anchor{set remotebreak}
9c16f35a 18177If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 18178when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 18179on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
18180character instead. The default is off, since most remote systems
18181expect to see @samp{Ctrl-C} as the interrupt signal.
18182
18183@item show remotebreak
18184Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
18185interrupt the remote program.
18186
23776285
MR
18187@item set remoteflow on
18188@itemx set remoteflow off
18189@kindex set remoteflow
18190Enable or disable hardware flow control (@code{RTS}/@code{CTS})
18191on the serial port used to communicate to the remote target.
18192
18193@item show remoteflow
18194@kindex show remoteflow
18195Show the current setting of hardware flow control.
18196
9c16f35a
EZ
18197@item set remotelogbase @var{base}
18198Set the base (a.k.a.@: radix) of logging serial protocol
18199communications to @var{base}. Supported values of @var{base} are:
18200@code{ascii}, @code{octal}, and @code{hex}. The default is
18201@code{ascii}.
18202
18203@item show remotelogbase
18204Show the current setting of the radix for logging remote serial
18205protocol.
18206
18207@item set remotelogfile @var{file}
18208@cindex record serial communications on file
18209Record remote serial communications on the named @var{file}. The
18210default is not to record at all.
18211
18212@item show remotelogfile.
18213Show the current setting of the file name on which to record the
18214serial communications.
18215
18216@item set remotetimeout @var{num}
18217@cindex timeout for serial communications
18218@cindex remote timeout
18219Set the timeout limit to wait for the remote target to respond to
18220@var{num} seconds. The default is 2 seconds.
18221
18222@item show remotetimeout
18223Show the current number of seconds to wait for the remote target
18224responses.
18225
18226@cindex limit hardware breakpoints and watchpoints
18227@cindex remote target, limit break- and watchpoints
501eef12
AC
18228@anchor{set remote hardware-watchpoint-limit}
18229@anchor{set remote hardware-breakpoint-limit}
18230@item set remote hardware-watchpoint-limit @var{limit}
18231@itemx set remote hardware-breakpoint-limit @var{limit}
18232Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
18233watchpoints. A limit of -1, the default, is treated as unlimited.
2d717e4f 18234
480a3f21
PW
18235@cindex limit hardware watchpoints length
18236@cindex remote target, limit watchpoints length
18237@anchor{set remote hardware-watchpoint-length-limit}
18238@item set remote hardware-watchpoint-length-limit @var{limit}
18239Restrict @value{GDBN} to using @var{limit} bytes for the maximum length of
18240a remote hardware watchpoint. A limit of -1, the default, is treated
18241as unlimited.
18242
18243@item show remote hardware-watchpoint-length-limit
18244Show the current limit (in bytes) of the maximum length of
18245a remote hardware watchpoint.
18246
2d717e4f
DJ
18247@item set remote exec-file @var{filename}
18248@itemx show remote exec-file
18249@anchor{set remote exec-file}
18250@cindex executable file, for remote target
18251Select the file used for @code{run} with @code{target
18252extended-remote}. This should be set to a filename valid on the
18253target system. If it is not set, the target will use a default
18254filename (e.g.@: the last program run).
84603566 18255
9a7071a8
JB
18256@item set remote interrupt-sequence
18257@cindex interrupt remote programs
18258@cindex select Ctrl-C, BREAK or BREAK-g
18259Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
18260@samp{BREAK-g} as the
18261sequence to the remote target in order to interrupt the execution.
18262@samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
18263is high level of serial line for some certain time.
18264Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
18265It is @code{BREAK} signal followed by character @code{g}.
18266
18267@item show interrupt-sequence
18268Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
18269is sent by @value{GDBN} to interrupt the remote program.
18270@code{BREAK-g} is BREAK signal followed by @code{g} and
18271also known as Magic SysRq g.
18272
18273@item set remote interrupt-on-connect
18274@cindex send interrupt-sequence on start
18275Specify whether interrupt-sequence is sent to remote target when
18276@value{GDBN} connects to it. This is mostly needed when you debug
18277Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
18278which is known as Magic SysRq g in order to connect @value{GDBN}.
18279
18280@item show interrupt-on-connect
18281Show whether interrupt-sequence is sent
18282to remote target when @value{GDBN} connects to it.
18283
84603566
SL
18284@kindex set tcp
18285@kindex show tcp
18286@item set tcp auto-retry on
18287@cindex auto-retry, for remote TCP target
18288Enable auto-retry for remote TCP connections. This is useful if the remote
18289debugging agent is launched in parallel with @value{GDBN}; there is a race
18290condition because the agent may not become ready to accept the connection
18291before @value{GDBN} attempts to connect. When auto-retry is
18292enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
18293to establish the connection using the timeout specified by
18294@code{set tcp connect-timeout}.
18295
18296@item set tcp auto-retry off
18297Do not auto-retry failed TCP connections.
18298
18299@item show tcp auto-retry
18300Show the current auto-retry setting.
18301
18302@item set tcp connect-timeout @var{seconds}
f81d1120 18303@itemx set tcp connect-timeout unlimited
84603566
SL
18304@cindex connection timeout, for remote TCP target
18305@cindex timeout, for remote target connection
18306Set the timeout for establishing a TCP connection to the remote target to
18307@var{seconds}. The timeout affects both polling to retry failed connections
18308(enabled by @code{set tcp auto-retry on}) and waiting for connections
18309that are merely slow to complete, and represents an approximate cumulative
f81d1120
PA
18310value. If @var{seconds} is @code{unlimited}, there is no timeout and
18311@value{GDBN} will keep attempting to establish a connection forever,
18312unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
84603566
SL
18313
18314@item show tcp connect-timeout
18315Show the current connection timeout setting.
501eef12
AC
18316@end table
18317
427c3a89
DJ
18318@cindex remote packets, enabling and disabling
18319The @value{GDBN} remote protocol autodetects the packets supported by
18320your debugging stub. If you need to override the autodetection, you
18321can use these commands to enable or disable individual packets. Each
18322packet can be set to @samp{on} (the remote target supports this
18323packet), @samp{off} (the remote target does not support this packet),
18324or @samp{auto} (detect remote target support for this packet). They
18325all default to @samp{auto}. For more information about each packet,
18326see @ref{Remote Protocol}.
18327
18328During normal use, you should not have to use any of these commands.
18329If you do, that may be a bug in your remote debugging stub, or a bug
18330in @value{GDBN}. You may want to report the problem to the
18331@value{GDBN} developers.
18332
cfa9d6d9
DJ
18333For each packet @var{name}, the command to enable or disable the
18334packet is @code{set remote @var{name}-packet}. The available settings
18335are:
427c3a89 18336
cfa9d6d9 18337@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
18338@item Command Name
18339@tab Remote Packet
18340@tab Related Features
18341
cfa9d6d9 18342@item @code{fetch-register}
427c3a89
DJ
18343@tab @code{p}
18344@tab @code{info registers}
18345
cfa9d6d9 18346@item @code{set-register}
427c3a89
DJ
18347@tab @code{P}
18348@tab @code{set}
18349
cfa9d6d9 18350@item @code{binary-download}
427c3a89
DJ
18351@tab @code{X}
18352@tab @code{load}, @code{set}
18353
cfa9d6d9 18354@item @code{read-aux-vector}
427c3a89
DJ
18355@tab @code{qXfer:auxv:read}
18356@tab @code{info auxv}
18357
cfa9d6d9 18358@item @code{symbol-lookup}
427c3a89
DJ
18359@tab @code{qSymbol}
18360@tab Detecting multiple threads
18361
2d717e4f
DJ
18362@item @code{attach}
18363@tab @code{vAttach}
18364@tab @code{attach}
18365
cfa9d6d9 18366@item @code{verbose-resume}
427c3a89
DJ
18367@tab @code{vCont}
18368@tab Stepping or resuming multiple threads
18369
2d717e4f
DJ
18370@item @code{run}
18371@tab @code{vRun}
18372@tab @code{run}
18373
cfa9d6d9 18374@item @code{software-breakpoint}
427c3a89
DJ
18375@tab @code{Z0}
18376@tab @code{break}
18377
cfa9d6d9 18378@item @code{hardware-breakpoint}
427c3a89
DJ
18379@tab @code{Z1}
18380@tab @code{hbreak}
18381
cfa9d6d9 18382@item @code{write-watchpoint}
427c3a89
DJ
18383@tab @code{Z2}
18384@tab @code{watch}
18385
cfa9d6d9 18386@item @code{read-watchpoint}
427c3a89
DJ
18387@tab @code{Z3}
18388@tab @code{rwatch}
18389
cfa9d6d9 18390@item @code{access-watchpoint}
427c3a89
DJ
18391@tab @code{Z4}
18392@tab @code{awatch}
18393
cfa9d6d9
DJ
18394@item @code{target-features}
18395@tab @code{qXfer:features:read}
18396@tab @code{set architecture}
18397
18398@item @code{library-info}
18399@tab @code{qXfer:libraries:read}
18400@tab @code{info sharedlibrary}
18401
18402@item @code{memory-map}
18403@tab @code{qXfer:memory-map:read}
18404@tab @code{info mem}
18405
0fb4aa4b
PA
18406@item @code{read-sdata-object}
18407@tab @code{qXfer:sdata:read}
18408@tab @code{print $_sdata}
18409
cfa9d6d9
DJ
18410@item @code{read-spu-object}
18411@tab @code{qXfer:spu:read}
18412@tab @code{info spu}
18413
18414@item @code{write-spu-object}
18415@tab @code{qXfer:spu:write}
18416@tab @code{info spu}
18417
4aa995e1
PA
18418@item @code{read-siginfo-object}
18419@tab @code{qXfer:siginfo:read}
18420@tab @code{print $_siginfo}
18421
18422@item @code{write-siginfo-object}
18423@tab @code{qXfer:siginfo:write}
18424@tab @code{set $_siginfo}
18425
dc146f7c
VP
18426@item @code{threads}
18427@tab @code{qXfer:threads:read}
18428@tab @code{info threads}
18429
cfa9d6d9 18430@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
18431@tab @code{qGetTLSAddr}
18432@tab Displaying @code{__thread} variables
18433
711e434b
PM
18434@item @code{get-thread-information-block-address}
18435@tab @code{qGetTIBAddr}
18436@tab Display MS-Windows Thread Information Block.
18437
08388c79
DE
18438@item @code{search-memory}
18439@tab @code{qSearch:memory}
18440@tab @code{find}
18441
427c3a89
DJ
18442@item @code{supported-packets}
18443@tab @code{qSupported}
18444@tab Remote communications parameters
18445
cfa9d6d9 18446@item @code{pass-signals}
89be2091
DJ
18447@tab @code{QPassSignals}
18448@tab @code{handle @var{signal}}
18449
9b224c5e
PA
18450@item @code{program-signals}
18451@tab @code{QProgramSignals}
18452@tab @code{handle @var{signal}}
18453
a6b151f1
DJ
18454@item @code{hostio-close-packet}
18455@tab @code{vFile:close}
18456@tab @code{remote get}, @code{remote put}
18457
18458@item @code{hostio-open-packet}
18459@tab @code{vFile:open}
18460@tab @code{remote get}, @code{remote put}
18461
18462@item @code{hostio-pread-packet}
18463@tab @code{vFile:pread}
18464@tab @code{remote get}, @code{remote put}
18465
18466@item @code{hostio-pwrite-packet}
18467@tab @code{vFile:pwrite}
18468@tab @code{remote get}, @code{remote put}
18469
18470@item @code{hostio-unlink-packet}
18471@tab @code{vFile:unlink}
18472@tab @code{remote delete}
a6f3e723 18473
b9e7b9c3
UW
18474@item @code{hostio-readlink-packet}
18475@tab @code{vFile:readlink}
18476@tab Host I/O
18477
a6f3e723
SL
18478@item @code{noack-packet}
18479@tab @code{QStartNoAckMode}
18480@tab Packet acknowledgment
07e059b5
VP
18481
18482@item @code{osdata}
18483@tab @code{qXfer:osdata:read}
18484@tab @code{info os}
0b16c5cf
PA
18485
18486@item @code{query-attached}
18487@tab @code{qAttached}
18488@tab Querying remote process attach state.
b3b9301e 18489
a46c1e42
PA
18490@item @code{trace-buffer-size}
18491@tab @code{QTBuffer:size}
18492@tab @code{set trace-buffer-size}
18493
bd3eecc3
PA
18494@item @code{trace-status}
18495@tab @code{qTStatus}
18496@tab @code{tstatus}
18497
b3b9301e
PA
18498@item @code{traceframe-info}
18499@tab @code{qXfer:traceframe-info:read}
18500@tab Traceframe info
03583c20 18501
1e4d1764
YQ
18502@item @code{install-in-trace}
18503@tab @code{InstallInTrace}
18504@tab Install tracepoint in tracing
18505
03583c20
UW
18506@item @code{disable-randomization}
18507@tab @code{QDisableRandomization}
18508@tab @code{set disable-randomization}
83364271
LM
18509
18510@item @code{conditional-breakpoints-packet}
18511@tab @code{Z0 and Z1}
18512@tab @code{Support for target-side breakpoint condition evaluation}
427c3a89
DJ
18513@end multitable
18514
79a6e687
BW
18515@node Remote Stub
18516@section Implementing a Remote Stub
7a292a7a 18517
8e04817f
AC
18518@cindex debugging stub, example
18519@cindex remote stub, example
18520@cindex stub example, remote debugging
18521The stub files provided with @value{GDBN} implement the target side of the
18522communication protocol, and the @value{GDBN} side is implemented in the
18523@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
18524these subroutines to communicate, and ignore the details. (If you're
18525implementing your own stub file, you can still ignore the details: start
18526with one of the existing stub files. @file{sparc-stub.c} is the best
18527organized, and therefore the easiest to read.)
18528
104c1213
JM
18529@cindex remote serial debugging, overview
18530To debug a program running on another machine (the debugging
18531@dfn{target} machine), you must first arrange for all the usual
18532prerequisites for the program to run by itself. For example, for a C
18533program, you need:
c906108c 18534
104c1213
JM
18535@enumerate
18536@item
18537A startup routine to set up the C runtime environment; these usually
18538have a name like @file{crt0}. The startup routine may be supplied by
18539your hardware supplier, or you may have to write your own.
96baa820 18540
5d161b24 18541@item
d4f3574e 18542A C subroutine library to support your program's
104c1213 18543subroutine calls, notably managing input and output.
96baa820 18544
104c1213
JM
18545@item
18546A way of getting your program to the other machine---for example, a
18547download program. These are often supplied by the hardware
18548manufacturer, but you may have to write your own from hardware
18549documentation.
18550@end enumerate
96baa820 18551
104c1213
JM
18552The next step is to arrange for your program to use a serial port to
18553communicate with the machine where @value{GDBN} is running (the @dfn{host}
18554machine). In general terms, the scheme looks like this:
96baa820 18555
104c1213
JM
18556@table @emph
18557@item On the host,
18558@value{GDBN} already understands how to use this protocol; when everything
18559else is set up, you can simply use the @samp{target remote} command
18560(@pxref{Targets,,Specifying a Debugging Target}).
18561
18562@item On the target,
18563you must link with your program a few special-purpose subroutines that
18564implement the @value{GDBN} remote serial protocol. The file containing these
18565subroutines is called a @dfn{debugging stub}.
18566
18567On certain remote targets, you can use an auxiliary program
18568@code{gdbserver} instead of linking a stub into your program.
79a6e687 18569@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 18570@end table
96baa820 18571
104c1213
JM
18572The debugging stub is specific to the architecture of the remote
18573machine; for example, use @file{sparc-stub.c} to debug programs on
18574@sc{sparc} boards.
96baa820 18575
104c1213
JM
18576@cindex remote serial stub list
18577These working remote stubs are distributed with @value{GDBN}:
96baa820 18578
104c1213
JM
18579@table @code
18580
18581@item i386-stub.c
41afff9a 18582@cindex @file{i386-stub.c}
104c1213
JM
18583@cindex Intel
18584@cindex i386
18585For Intel 386 and compatible architectures.
18586
18587@item m68k-stub.c
41afff9a 18588@cindex @file{m68k-stub.c}
104c1213
JM
18589@cindex Motorola 680x0
18590@cindex m680x0
18591For Motorola 680x0 architectures.
18592
18593@item sh-stub.c
41afff9a 18594@cindex @file{sh-stub.c}
172c2a43 18595@cindex Renesas
104c1213 18596@cindex SH
172c2a43 18597For Renesas SH architectures.
104c1213
JM
18598
18599@item sparc-stub.c
41afff9a 18600@cindex @file{sparc-stub.c}
104c1213
JM
18601@cindex Sparc
18602For @sc{sparc} architectures.
18603
18604@item sparcl-stub.c
41afff9a 18605@cindex @file{sparcl-stub.c}
104c1213
JM
18606@cindex Fujitsu
18607@cindex SparcLite
18608For Fujitsu @sc{sparclite} architectures.
18609
18610@end table
18611
18612The @file{README} file in the @value{GDBN} distribution may list other
18613recently added stubs.
18614
18615@menu
18616* Stub Contents:: What the stub can do for you
18617* Bootstrapping:: What you must do for the stub
18618* Debug Session:: Putting it all together
104c1213
JM
18619@end menu
18620
6d2ebf8b 18621@node Stub Contents
79a6e687 18622@subsection What the Stub Can Do for You
104c1213
JM
18623
18624@cindex remote serial stub
18625The debugging stub for your architecture supplies these three
18626subroutines:
18627
18628@table @code
18629@item set_debug_traps
4644b6e3 18630@findex set_debug_traps
104c1213
JM
18631@cindex remote serial stub, initialization
18632This routine arranges for @code{handle_exception} to run when your
2fb860fc
PA
18633program stops. You must call this subroutine explicitly in your
18634program's startup code.
104c1213
JM
18635
18636@item handle_exception
4644b6e3 18637@findex handle_exception
104c1213
JM
18638@cindex remote serial stub, main routine
18639This is the central workhorse, but your program never calls it
18640explicitly---the setup code arranges for @code{handle_exception} to
18641run when a trap is triggered.
18642
18643@code{handle_exception} takes control when your program stops during
18644execution (for example, on a breakpoint), and mediates communications
18645with @value{GDBN} on the host machine. This is where the communications
18646protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 18647representative on the target machine. It begins by sending summary
104c1213
JM
18648information on the state of your program, then continues to execute,
18649retrieving and transmitting any information @value{GDBN} needs, until you
18650execute a @value{GDBN} command that makes your program resume; at that point,
18651@code{handle_exception} returns control to your own code on the target
5d161b24 18652machine.
104c1213
JM
18653
18654@item breakpoint
18655@cindex @code{breakpoint} subroutine, remote
18656Use this auxiliary subroutine to make your program contain a
18657breakpoint. Depending on the particular situation, this may be the only
18658way for @value{GDBN} to get control. For instance, if your target
18659machine has some sort of interrupt button, you won't need to call this;
18660pressing the interrupt button transfers control to
18661@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
18662simply receiving characters on the serial port may also trigger a trap;
18663again, in that situation, you don't need to call @code{breakpoint} from
18664your own program---simply running @samp{target remote} from the host
5d161b24 18665@value{GDBN} session gets control.
104c1213
JM
18666
18667Call @code{breakpoint} if none of these is true, or if you simply want
18668to make certain your program stops at a predetermined point for the
18669start of your debugging session.
18670@end table
18671
6d2ebf8b 18672@node Bootstrapping
79a6e687 18673@subsection What You Must Do for the Stub
104c1213
JM
18674
18675@cindex remote stub, support routines
18676The debugging stubs that come with @value{GDBN} are set up for a particular
18677chip architecture, but they have no information about the rest of your
18678debugging target machine.
18679
18680First of all you need to tell the stub how to communicate with the
18681serial port.
18682
18683@table @code
18684@item int getDebugChar()
4644b6e3 18685@findex getDebugChar
104c1213
JM
18686Write this subroutine to read a single character from the serial port.
18687It may be identical to @code{getchar} for your target system; a
18688different name is used to allow you to distinguish the two if you wish.
18689
18690@item void putDebugChar(int)
4644b6e3 18691@findex putDebugChar
104c1213 18692Write this subroutine to write a single character to the serial port.
5d161b24 18693It may be identical to @code{putchar} for your target system; a
104c1213
JM
18694different name is used to allow you to distinguish the two if you wish.
18695@end table
18696
18697@cindex control C, and remote debugging
18698@cindex interrupting remote targets
18699If you want @value{GDBN} to be able to stop your program while it is
18700running, you need to use an interrupt-driven serial driver, and arrange
18701for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
18702character). That is the character which @value{GDBN} uses to tell the
18703remote system to stop.
18704
18705Getting the debugging target to return the proper status to @value{GDBN}
18706probably requires changes to the standard stub; one quick and dirty way
18707is to just execute a breakpoint instruction (the ``dirty'' part is that
18708@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
18709
18710Other routines you need to supply are:
18711
18712@table @code
18713@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 18714@findex exceptionHandler
104c1213
JM
18715Write this function to install @var{exception_address} in the exception
18716handling tables. You need to do this because the stub does not have any
18717way of knowing what the exception handling tables on your target system
18718are like (for example, the processor's table might be in @sc{rom},
18719containing entries which point to a table in @sc{ram}).
18720@var{exception_number} is the exception number which should be changed;
18721its meaning is architecture-dependent (for example, different numbers
18722might represent divide by zero, misaligned access, etc). When this
18723exception occurs, control should be transferred directly to
18724@var{exception_address}, and the processor state (stack, registers,
18725and so on) should be just as it is when a processor exception occurs. So if
18726you want to use a jump instruction to reach @var{exception_address}, it
18727should be a simple jump, not a jump to subroutine.
18728
18729For the 386, @var{exception_address} should be installed as an interrupt
18730gate so that interrupts are masked while the handler runs. The gate
18731should be at privilege level 0 (the most privileged level). The
18732@sc{sparc} and 68k stubs are able to mask interrupts themselves without
18733help from @code{exceptionHandler}.
18734
18735@item void flush_i_cache()
4644b6e3 18736@findex flush_i_cache
d4f3574e 18737On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
18738instruction cache, if any, on your target machine. If there is no
18739instruction cache, this subroutine may be a no-op.
18740
18741On target machines that have instruction caches, @value{GDBN} requires this
18742function to make certain that the state of your program is stable.
18743@end table
18744
18745@noindent
18746You must also make sure this library routine is available:
18747
18748@table @code
18749@item void *memset(void *, int, int)
4644b6e3 18750@findex memset
104c1213
JM
18751This is the standard library function @code{memset} that sets an area of
18752memory to a known value. If you have one of the free versions of
18753@code{libc.a}, @code{memset} can be found there; otherwise, you must
18754either obtain it from your hardware manufacturer, or write your own.
18755@end table
18756
18757If you do not use the GNU C compiler, you may need other standard
18758library subroutines as well; this varies from one stub to another,
18759but in general the stubs are likely to use any of the common library
e22ea452 18760subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
18761
18762
6d2ebf8b 18763@node Debug Session
79a6e687 18764@subsection Putting it All Together
104c1213
JM
18765
18766@cindex remote serial debugging summary
18767In summary, when your program is ready to debug, you must follow these
18768steps.
18769
18770@enumerate
18771@item
6d2ebf8b 18772Make sure you have defined the supporting low-level routines
79a6e687 18773(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
18774@display
18775@code{getDebugChar}, @code{putDebugChar},
18776@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
18777@end display
18778
18779@item
2fb860fc
PA
18780Insert these lines in your program's startup code, before the main
18781procedure is called:
104c1213 18782
474c8240 18783@smallexample
104c1213
JM
18784set_debug_traps();
18785breakpoint();
474c8240 18786@end smallexample
104c1213 18787
2fb860fc
PA
18788On some machines, when a breakpoint trap is raised, the hardware
18789automatically makes the PC point to the instruction after the
18790breakpoint. If your machine doesn't do that, you may need to adjust
18791@code{handle_exception} to arrange for it to return to the instruction
18792after the breakpoint on this first invocation, so that your program
18793doesn't keep hitting the initial breakpoint instead of making
18794progress.
18795
104c1213
JM
18796@item
18797For the 680x0 stub only, you need to provide a variable called
18798@code{exceptionHook}. Normally you just use:
18799
474c8240 18800@smallexample
104c1213 18801void (*exceptionHook)() = 0;
474c8240 18802@end smallexample
104c1213 18803
d4f3574e 18804@noindent
104c1213 18805but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 18806function in your program, that function is called when
104c1213
JM
18807@code{@value{GDBN}} continues after stopping on a trap (for example, bus
18808error). The function indicated by @code{exceptionHook} is called with
18809one parameter: an @code{int} which is the exception number.
18810
18811@item
18812Compile and link together: your program, the @value{GDBN} debugging stub for
18813your target architecture, and the supporting subroutines.
18814
18815@item
18816Make sure you have a serial connection between your target machine and
18817the @value{GDBN} host, and identify the serial port on the host.
18818
18819@item
18820@c The "remote" target now provides a `load' command, so we should
18821@c document that. FIXME.
18822Download your program to your target machine (or get it there by
18823whatever means the manufacturer provides), and start it.
18824
18825@item
07f31aa6 18826Start @value{GDBN} on the host, and connect to the target
79a6e687 18827(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 18828
104c1213
JM
18829@end enumerate
18830
8e04817f
AC
18831@node Configurations
18832@chapter Configuration-Specific Information
104c1213 18833
8e04817f
AC
18834While nearly all @value{GDBN} commands are available for all native and
18835cross versions of the debugger, there are some exceptions. This chapter
18836describes things that are only available in certain configurations.
104c1213 18837
8e04817f
AC
18838There are three major categories of configurations: native
18839configurations, where the host and target are the same, embedded
18840operating system configurations, which are usually the same for several
18841different processor architectures, and bare embedded processors, which
18842are quite different from each other.
104c1213 18843
8e04817f
AC
18844@menu
18845* Native::
18846* Embedded OS::
18847* Embedded Processors::
18848* Architectures::
18849@end menu
104c1213 18850
8e04817f
AC
18851@node Native
18852@section Native
104c1213 18853
8e04817f
AC
18854This section describes details specific to particular native
18855configurations.
6cf7e474 18856
8e04817f
AC
18857@menu
18858* HP-UX:: HP-UX
7561d450 18859* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
18860* SVR4 Process Information:: SVR4 process information
18861* DJGPP Native:: Features specific to the DJGPP port
78c47bea 18862* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 18863* Hurd Native:: Features specific to @sc{gnu} Hurd
a80b95ba 18864* Darwin:: Features specific to Darwin
8e04817f 18865@end menu
6cf7e474 18866
8e04817f
AC
18867@node HP-UX
18868@subsection HP-UX
104c1213 18869
8e04817f
AC
18870On HP-UX systems, if you refer to a function or variable name that
18871begins with a dollar sign, @value{GDBN} searches for a user or system
18872name first, before it searches for a convenience variable.
104c1213 18873
9c16f35a 18874
7561d450
MK
18875@node BSD libkvm Interface
18876@subsection BSD libkvm Interface
18877
18878@cindex libkvm
18879@cindex kernel memory image
18880@cindex kernel crash dump
18881
18882BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
18883interface that provides a uniform interface for accessing kernel virtual
18884memory images, including live systems and crash dumps. @value{GDBN}
18885uses this interface to allow you to debug live kernels and kernel crash
18886dumps on many native BSD configurations. This is implemented as a
18887special @code{kvm} debugging target. For debugging a live system, load
18888the currently running kernel into @value{GDBN} and connect to the
18889@code{kvm} target:
18890
18891@smallexample
18892(@value{GDBP}) @b{target kvm}
18893@end smallexample
18894
18895For debugging crash dumps, provide the file name of the crash dump as an
18896argument:
18897
18898@smallexample
18899(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
18900@end smallexample
18901
18902Once connected to the @code{kvm} target, the following commands are
18903available:
18904
18905@table @code
18906@kindex kvm
18907@item kvm pcb
721c2651 18908Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
18909
18910@item kvm proc
18911Set current context from proc address. This command isn't available on
18912modern FreeBSD systems.
18913@end table
18914
8e04817f 18915@node SVR4 Process Information
79a6e687 18916@subsection SVR4 Process Information
60bf7e09
EZ
18917@cindex /proc
18918@cindex examine process image
18919@cindex process info via @file{/proc}
104c1213 18920
60bf7e09
EZ
18921Many versions of SVR4 and compatible systems provide a facility called
18922@samp{/proc} that can be used to examine the image of a running
451b7c33
TT
18923process using file-system subroutines.
18924
18925If @value{GDBN} is configured for an operating system with this
18926facility, the command @code{info proc} is available to report
18927information about the process running your program, or about any
18928process running on your system. This includes, as of this writing,
18929@sc{gnu}/Linux, OSF/1 (Digital Unix), Solaris, and Irix, but
18930not HP-UX, for example.
18931
18932This command may also work on core files that were created on a system
18933that has the @samp{/proc} facility.
104c1213 18934
8e04817f
AC
18935@table @code
18936@kindex info proc
60bf7e09 18937@cindex process ID
8e04817f 18938@item info proc
60bf7e09
EZ
18939@itemx info proc @var{process-id}
18940Summarize available information about any running process. If a
18941process ID is specified by @var{process-id}, display information about
18942that process; otherwise display information about the program being
18943debugged. The summary includes the debugged process ID, the command
18944line used to invoke it, its current working directory, and its
18945executable file's absolute file name.
18946
18947On some systems, @var{process-id} can be of the form
18948@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
18949within a process. If the optional @var{pid} part is missing, it means
18950a thread from the process being debugged (the leading @samp{/} still
18951needs to be present, or else @value{GDBN} will interpret the number as
18952a process ID rather than a thread ID).
6cf7e474 18953
0c631110
TT
18954@item info proc cmdline
18955@cindex info proc cmdline
18956Show the original command line of the process. This command is
18957specific to @sc{gnu}/Linux.
18958
18959@item info proc cwd
18960@cindex info proc cwd
18961Show the current working directory of the process. This command is
18962specific to @sc{gnu}/Linux.
18963
18964@item info proc exe
18965@cindex info proc exe
18966Show the name of executable of the process. This command is specific
18967to @sc{gnu}/Linux.
18968
8e04817f 18969@item info proc mappings
60bf7e09
EZ
18970@cindex memory address space mappings
18971Report the memory address space ranges accessible in the program, with
18972information on whether the process has read, write, or execute access
18973rights to each range. On @sc{gnu}/Linux systems, each memory range
18974includes the object file which is mapped to that range, instead of the
18975memory access rights to that range.
18976
18977@item info proc stat
18978@itemx info proc status
18979@cindex process detailed status information
18980These subcommands are specific to @sc{gnu}/Linux systems. They show
18981the process-related information, including the user ID and group ID;
18982how many threads are there in the process; its virtual memory usage;
18983the signals that are pending, blocked, and ignored; its TTY; its
18984consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 18985value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
18986(type @kbd{man 5 proc} from your shell prompt).
18987
18988@item info proc all
18989Show all the information about the process described under all of the
18990above @code{info proc} subcommands.
18991
8e04817f
AC
18992@ignore
18993@comment These sub-options of 'info proc' were not included when
18994@comment procfs.c was re-written. Keep their descriptions around
18995@comment against the day when someone finds the time to put them back in.
18996@kindex info proc times
18997@item info proc times
18998Starting time, user CPU time, and system CPU time for your program and
18999its children.
6cf7e474 19000
8e04817f
AC
19001@kindex info proc id
19002@item info proc id
19003Report on the process IDs related to your program: its own process ID,
19004the ID of its parent, the process group ID, and the session ID.
8e04817f 19005@end ignore
721c2651
EZ
19006
19007@item set procfs-trace
19008@kindex set procfs-trace
19009@cindex @code{procfs} API calls
19010This command enables and disables tracing of @code{procfs} API calls.
19011
19012@item show procfs-trace
19013@kindex show procfs-trace
19014Show the current state of @code{procfs} API call tracing.
19015
19016@item set procfs-file @var{file}
19017@kindex set procfs-file
19018Tell @value{GDBN} to write @code{procfs} API trace to the named
19019@var{file}. @value{GDBN} appends the trace info to the previous
19020contents of the file. The default is to display the trace on the
19021standard output.
19022
19023@item show procfs-file
19024@kindex show procfs-file
19025Show the file to which @code{procfs} API trace is written.
19026
19027@item proc-trace-entry
19028@itemx proc-trace-exit
19029@itemx proc-untrace-entry
19030@itemx proc-untrace-exit
19031@kindex proc-trace-entry
19032@kindex proc-trace-exit
19033@kindex proc-untrace-entry
19034@kindex proc-untrace-exit
19035These commands enable and disable tracing of entries into and exits
19036from the @code{syscall} interface.
19037
19038@item info pidlist
19039@kindex info pidlist
19040@cindex process list, QNX Neutrino
19041For QNX Neutrino only, this command displays the list of all the
19042processes and all the threads within each process.
19043
19044@item info meminfo
19045@kindex info meminfo
19046@cindex mapinfo list, QNX Neutrino
19047For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 19048@end table
104c1213 19049
8e04817f
AC
19050@node DJGPP Native
19051@subsection Features for Debugging @sc{djgpp} Programs
19052@cindex @sc{djgpp} debugging
19053@cindex native @sc{djgpp} debugging
19054@cindex MS-DOS-specific commands
104c1213 19055
514c4d71
EZ
19056@cindex DPMI
19057@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
19058MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
19059that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
19060top of real-mode DOS systems and their emulations.
104c1213 19061
8e04817f
AC
19062@value{GDBN} supports native debugging of @sc{djgpp} programs, and
19063defines a few commands specific to the @sc{djgpp} port. This
19064subsection describes those commands.
104c1213 19065
8e04817f
AC
19066@table @code
19067@kindex info dos
19068@item info dos
19069This is a prefix of @sc{djgpp}-specific commands which print
19070information about the target system and important OS structures.
f1251bdd 19071
8e04817f
AC
19072@kindex sysinfo
19073@cindex MS-DOS system info
19074@cindex free memory information (MS-DOS)
19075@item info dos sysinfo
19076This command displays assorted information about the underlying
19077platform: the CPU type and features, the OS version and flavor, the
19078DPMI version, and the available conventional and DPMI memory.
104c1213 19079
8e04817f
AC
19080@cindex GDT
19081@cindex LDT
19082@cindex IDT
19083@cindex segment descriptor tables
19084@cindex descriptor tables display
19085@item info dos gdt
19086@itemx info dos ldt
19087@itemx info dos idt
19088These 3 commands display entries from, respectively, Global, Local,
19089and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
19090tables are data structures which store a descriptor for each segment
19091that is currently in use. The segment's selector is an index into a
19092descriptor table; the table entry for that index holds the
19093descriptor's base address and limit, and its attributes and access
19094rights.
104c1213 19095
8e04817f
AC
19096A typical @sc{djgpp} program uses 3 segments: a code segment, a data
19097segment (used for both data and the stack), and a DOS segment (which
19098allows access to DOS/BIOS data structures and absolute addresses in
19099conventional memory). However, the DPMI host will usually define
19100additional segments in order to support the DPMI environment.
d4f3574e 19101
8e04817f
AC
19102@cindex garbled pointers
19103These commands allow to display entries from the descriptor tables.
19104Without an argument, all entries from the specified table are
19105displayed. An argument, which should be an integer expression, means
19106display a single entry whose index is given by the argument. For
19107example, here's a convenient way to display information about the
19108debugged program's data segment:
104c1213 19109
8e04817f
AC
19110@smallexample
19111@exdent @code{(@value{GDBP}) info dos ldt $ds}
19112@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
19113@end smallexample
104c1213 19114
8e04817f
AC
19115@noindent
19116This comes in handy when you want to see whether a pointer is outside
19117the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 19118
8e04817f
AC
19119@cindex page tables display (MS-DOS)
19120@item info dos pde
19121@itemx info dos pte
19122These two commands display entries from, respectively, the Page
19123Directory and the Page Tables. Page Directories and Page Tables are
19124data structures which control how virtual memory addresses are mapped
19125into physical addresses. A Page Table includes an entry for every
19126page of memory that is mapped into the program's address space; there
19127may be several Page Tables, each one holding up to 4096 entries. A
19128Page Directory has up to 4096 entries, one each for every Page Table
19129that is currently in use.
104c1213 19130
8e04817f
AC
19131Without an argument, @kbd{info dos pde} displays the entire Page
19132Directory, and @kbd{info dos pte} displays all the entries in all of
19133the Page Tables. An argument, an integer expression, given to the
19134@kbd{info dos pde} command means display only that entry from the Page
19135Directory table. An argument given to the @kbd{info dos pte} command
19136means display entries from a single Page Table, the one pointed to by
19137the specified entry in the Page Directory.
104c1213 19138
8e04817f
AC
19139@cindex direct memory access (DMA) on MS-DOS
19140These commands are useful when your program uses @dfn{DMA} (Direct
19141Memory Access), which needs physical addresses to program the DMA
19142controller.
104c1213 19143
8e04817f 19144These commands are supported only with some DPMI servers.
104c1213 19145
8e04817f
AC
19146@cindex physical address from linear address
19147@item info dos address-pte @var{addr}
19148This command displays the Page Table entry for a specified linear
514c4d71
EZ
19149address. The argument @var{addr} is a linear address which should
19150already have the appropriate segment's base address added to it,
19151because this command accepts addresses which may belong to @emph{any}
19152segment. For example, here's how to display the Page Table entry for
19153the page where a variable @code{i} is stored:
104c1213 19154
b383017d 19155@smallexample
8e04817f
AC
19156@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
19157@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 19158@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 19159@end smallexample
104c1213 19160
8e04817f
AC
19161@noindent
19162This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 19163whose physical base address is @code{0x02698000}, and shows all the
8e04817f 19164attributes of that page.
104c1213 19165
8e04817f
AC
19166Note that you must cast the addresses of variables to a @code{char *},
19167since otherwise the value of @code{__djgpp_base_address}, the base
19168address of all variables and functions in a @sc{djgpp} program, will
19169be added using the rules of C pointer arithmetics: if @code{i} is
19170declared an @code{int}, @value{GDBN} will add 4 times the value of
19171@code{__djgpp_base_address} to the address of @code{i}.
104c1213 19172
8e04817f
AC
19173Here's another example, it displays the Page Table entry for the
19174transfer buffer:
104c1213 19175
8e04817f
AC
19176@smallexample
19177@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
19178@exdent @code{Page Table entry for address 0x29110:}
19179@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
19180@end smallexample
104c1213 19181
8e04817f
AC
19182@noindent
19183(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
191843rd member of the @code{_go32_info_block} structure.) The output
19185clearly shows that this DPMI server maps the addresses in conventional
19186memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
19187linear (@code{0x29110}) addresses are identical.
104c1213 19188
8e04817f
AC
19189This command is supported only with some DPMI servers.
19190@end table
104c1213 19191
c45da7e6 19192@cindex DOS serial data link, remote debugging
a8f24a35
EZ
19193In addition to native debugging, the DJGPP port supports remote
19194debugging via a serial data link. The following commands are specific
19195to remote serial debugging in the DJGPP port of @value{GDBN}.
19196
19197@table @code
19198@kindex set com1base
19199@kindex set com1irq
19200@kindex set com2base
19201@kindex set com2irq
19202@kindex set com3base
19203@kindex set com3irq
19204@kindex set com4base
19205@kindex set com4irq
19206@item set com1base @var{addr}
19207This command sets the base I/O port address of the @file{COM1} serial
19208port.
19209
19210@item set com1irq @var{irq}
19211This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
19212for the @file{COM1} serial port.
19213
19214There are similar commands @samp{set com2base}, @samp{set com3irq},
19215etc.@: for setting the port address and the @code{IRQ} lines for the
19216other 3 COM ports.
19217
19218@kindex show com1base
19219@kindex show com1irq
19220@kindex show com2base
19221@kindex show com2irq
19222@kindex show com3base
19223@kindex show com3irq
19224@kindex show com4base
19225@kindex show com4irq
19226The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
19227display the current settings of the base address and the @code{IRQ}
19228lines used by the COM ports.
c45da7e6
EZ
19229
19230@item info serial
19231@kindex info serial
19232@cindex DOS serial port status
19233This command prints the status of the 4 DOS serial ports. For each
19234port, it prints whether it's active or not, its I/O base address and
19235IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
19236counts of various errors encountered so far.
a8f24a35
EZ
19237@end table
19238
19239
78c47bea 19240@node Cygwin Native
79a6e687 19241@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
19242@cindex MS Windows debugging
19243@cindex native Cygwin debugging
19244@cindex Cygwin-specific commands
19245
be448670 19246@value{GDBN} supports native debugging of MS Windows programs, including
cbb8f428
EZ
19247DLLs with and without symbolic debugging information.
19248
19249@cindex Ctrl-BREAK, MS-Windows
19250@cindex interrupt debuggee on MS-Windows
19251MS-Windows programs that call @code{SetConsoleMode} to switch off the
19252special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
19253by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
19254supports @kbd{C-@key{BREAK}} as an alternative interrupt key
19255sequence, which can be used to interrupt the debuggee even if it
19256ignores @kbd{C-c}.
19257
19258There are various additional Cygwin-specific commands, described in
19259this section. Working with DLLs that have no debugging symbols is
19260described in @ref{Non-debug DLL Symbols}.
78c47bea
PM
19261
19262@table @code
19263@kindex info w32
19264@item info w32
db2e3e2e 19265This is a prefix of MS Windows-specific commands which print
78c47bea
PM
19266information about the target system and important OS structures.
19267
19268@item info w32 selector
19269This command displays information returned by
19270the Win32 API @code{GetThreadSelectorEntry} function.
19271It takes an optional argument that is evaluated to
19272a long value to give the information about this given selector.
19273Without argument, this command displays information
d3e8051b 19274about the six segment registers.
78c47bea 19275
711e434b
PM
19276@item info w32 thread-information-block
19277This command displays thread specific information stored in the
19278Thread Information Block (readable on the X86 CPU family using @code{$fs}
19279selector for 32-bit programs and @code{$gs} for 64-bit programs).
19280
78c47bea
PM
19281@kindex info dll
19282@item info dll
db2e3e2e 19283This is a Cygwin-specific alias of @code{info shared}.
78c47bea
PM
19284
19285@kindex dll-symbols
19286@item dll-symbols
19287This command loads symbols from a dll similarly to
19288add-sym command but without the need to specify a base address.
19289
be90c084 19290@kindex set cygwin-exceptions
e16b02ee
EZ
19291@cindex debugging the Cygwin DLL
19292@cindex Cygwin DLL, debugging
be90c084 19293@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
19294If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
19295happen inside the Cygwin DLL. If @var{mode} is @code{off},
19296@value{GDBN} will delay recognition of exceptions, and may ignore some
19297exceptions which seem to be caused by internal Cygwin DLL
19298``bookkeeping''. This option is meant primarily for debugging the
19299Cygwin DLL itself; the default value is @code{off} to avoid annoying
19300@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
19301
19302@kindex show cygwin-exceptions
19303@item show cygwin-exceptions
e16b02ee
EZ
19304Displays whether @value{GDBN} will break on exceptions that happen
19305inside the Cygwin DLL itself.
be90c084 19306
b383017d 19307@kindex set new-console
78c47bea 19308@item set new-console @var{mode}
b383017d 19309If @var{mode} is @code{on} the debuggee will
78c47bea 19310be started in a new console on next start.
e03e5e7b 19311If @var{mode} is @code{off}, the debuggee will
78c47bea
PM
19312be started in the same console as the debugger.
19313
19314@kindex show new-console
19315@item show new-console
19316Displays whether a new console is used
19317when the debuggee is started.
19318
19319@kindex set new-group
19320@item set new-group @var{mode}
19321This boolean value controls whether the debuggee should
19322start a new group or stay in the same group as the debugger.
19323This affects the way the Windows OS handles
c8aa23ab 19324@samp{Ctrl-C}.
78c47bea
PM
19325
19326@kindex show new-group
19327@item show new-group
19328Displays current value of new-group boolean.
19329
19330@kindex set debugevents
19331@item set debugevents
219eec71
EZ
19332This boolean value adds debug output concerning kernel events related
19333to the debuggee seen by the debugger. This includes events that
19334signal thread and process creation and exit, DLL loading and
19335unloading, console interrupts, and debugging messages produced by the
19336Windows @code{OutputDebugString} API call.
78c47bea
PM
19337
19338@kindex set debugexec
19339@item set debugexec
b383017d 19340This boolean value adds debug output concerning execute events
219eec71 19341(such as resume thread) seen by the debugger.
78c47bea
PM
19342
19343@kindex set debugexceptions
19344@item set debugexceptions
219eec71
EZ
19345This boolean value adds debug output concerning exceptions in the
19346debuggee seen by the debugger.
78c47bea
PM
19347
19348@kindex set debugmemory
19349@item set debugmemory
219eec71
EZ
19350This boolean value adds debug output concerning debuggee memory reads
19351and writes by the debugger.
78c47bea
PM
19352
19353@kindex set shell
19354@item set shell
19355This boolean values specifies whether the debuggee is called
19356via a shell or directly (default value is on).
19357
19358@kindex show shell
19359@item show shell
19360Displays if the debuggee will be started with a shell.
19361
19362@end table
19363
be448670 19364@menu
79a6e687 19365* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
19366@end menu
19367
79a6e687
BW
19368@node Non-debug DLL Symbols
19369@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
19370@cindex DLLs with no debugging symbols
19371@cindex Minimal symbols and DLLs
19372
19373Very often on windows, some of the DLLs that your program relies on do
19374not include symbolic debugging information (for example,
db2e3e2e 19375@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 19376symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 19377information contained in the DLL's export table. This section
be448670
CF
19378describes working with such symbols, known internally to @value{GDBN} as
19379``minimal symbols''.
19380
19381Note that before the debugged program has started execution, no DLLs
db2e3e2e 19382will have been loaded. The easiest way around this problem is simply to
be448670 19383start the program --- either by setting a breakpoint or letting the
db2e3e2e 19384program run once to completion. It is also possible to force
be448670 19385@value{GDBN} to load a particular DLL before starting the executable ---
12c27660 19386see the shared library information in @ref{Files}, or the
db2e3e2e 19387@code{dll-symbols} command in @ref{Cygwin Native}. Currently,
be448670
CF
19388explicitly loading symbols from a DLL with no debugging information will
19389cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
19390which may adversely affect symbol lookup performance.
19391
79a6e687 19392@subsubsection DLL Name Prefixes
be448670
CF
19393
19394In keeping with the naming conventions used by the Microsoft debugging
19395tools, DLL export symbols are made available with a prefix based on the
19396DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
19397also entered into the symbol table, so @code{CreateFileA} is often
99e008fe 19398sufficient. In some cases there will be name clashes within a program
be448670
CF
19399(particularly if the executable itself includes full debugging symbols)
19400necessitating the use of the fully qualified name when referring to the
99e008fe 19401contents of the DLL. Use single-quotes around the name to avoid the
be448670
CF
19402exclamation mark (``!'') being interpreted as a language operator.
19403
19404Note that the internal name of the DLL may be all upper-case, even
99e008fe 19405though the file name of the DLL is lower-case, or vice-versa. Since
be448670
CF
19406symbols within @value{GDBN} are @emph{case-sensitive} this may cause
19407some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
19408@code{info variables} commands or even @code{maint print msymbols}
19409(@pxref{Symbols}). Here's an example:
be448670
CF
19410
19411@smallexample
f7dc1244 19412(@value{GDBP}) info function CreateFileA
be448670
CF
19413All functions matching regular expression "CreateFileA":
19414
19415Non-debugging symbols:
194160x77e885f4 CreateFileA
194170x77e885f4 KERNEL32!CreateFileA
19418@end smallexample
19419
19420@smallexample
f7dc1244 19421(@value{GDBP}) info function !
be448670
CF
19422All functions matching regular expression "!":
19423
19424Non-debugging symbols:
194250x6100114c cygwin1!__assert
194260x61004034 cygwin1!_dll_crt0@@0
194270x61004240 cygwin1!dll_crt0(per_process *)
19428[etc...]
19429@end smallexample
19430
79a6e687 19431@subsubsection Working with Minimal Symbols
be448670
CF
19432
19433Symbols extracted from a DLL's export table do not contain very much
19434type information. All that @value{GDBN} can do is guess whether a symbol
19435refers to a function or variable depending on the linker section that
19436contains the symbol. Also note that the actual contents of the memory
19437contained in a DLL are not available unless the program is running. This
19438means that you cannot examine the contents of a variable or disassemble
19439a function within a DLL without a running program.
19440
19441Variables are generally treated as pointers and dereferenced
19442automatically. For this reason, it is often necessary to prefix a
19443variable name with the address-of operator (``&'') and provide explicit
19444type information in the command. Here's an example of the type of
19445problem:
19446
19447@smallexample
f7dc1244 19448(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
19449$1 = 268572168
19450@end smallexample
19451
19452@smallexample
f7dc1244 19453(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
194540x10021610: "\230y\""
19455@end smallexample
19456
19457And two possible solutions:
19458
19459@smallexample
f7dc1244 19460(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
19461$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
19462@end smallexample
19463
19464@smallexample
f7dc1244 19465(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 194660x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 19467(@value{GDBP}) x/x 0x10021608
be448670 194680x10021608: 0x0022fd98
f7dc1244 19469(@value{GDBP}) x/s 0x0022fd98
be448670
CF
194700x22fd98: "/cygdrive/c/mydirectory/myprogram"
19471@end smallexample
19472
19473Setting a break point within a DLL is possible even before the program
19474starts execution. However, under these circumstances, @value{GDBN} can't
19475examine the initial instructions of the function in order to skip the
19476function's frame set-up code. You can work around this by using ``*&''
19477to set the breakpoint at a raw memory address:
19478
19479@smallexample
f7dc1244 19480(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
19481Breakpoint 1 at 0x1e04eff0
19482@end smallexample
19483
19484The author of these extensions is not entirely convinced that setting a
19485break point within a shared DLL like @file{kernel32.dll} is completely
19486safe.
19487
14d6dd68 19488@node Hurd Native
79a6e687 19489@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
19490@cindex @sc{gnu} Hurd debugging
19491
19492This subsection describes @value{GDBN} commands specific to the
19493@sc{gnu} Hurd native debugging.
19494
19495@table @code
19496@item set signals
19497@itemx set sigs
19498@kindex set signals@r{, Hurd command}
19499@kindex set sigs@r{, Hurd command}
19500This command toggles the state of inferior signal interception by
19501@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
19502affected by this command. @code{sigs} is a shorthand alias for
19503@code{signals}.
19504
19505@item show signals
19506@itemx show sigs
19507@kindex show signals@r{, Hurd command}
19508@kindex show sigs@r{, Hurd command}
19509Show the current state of intercepting inferior's signals.
19510
19511@item set signal-thread
19512@itemx set sigthread
19513@kindex set signal-thread
19514@kindex set sigthread
19515This command tells @value{GDBN} which thread is the @code{libc} signal
19516thread. That thread is run when a signal is delivered to a running
19517process. @code{set sigthread} is the shorthand alias of @code{set
19518signal-thread}.
19519
19520@item show signal-thread
19521@itemx show sigthread
19522@kindex show signal-thread
19523@kindex show sigthread
19524These two commands show which thread will run when the inferior is
19525delivered a signal.
19526
19527@item set stopped
19528@kindex set stopped@r{, Hurd command}
19529This commands tells @value{GDBN} that the inferior process is stopped,
19530as with the @code{SIGSTOP} signal. The stopped process can be
19531continued by delivering a signal to it.
19532
19533@item show stopped
19534@kindex show stopped@r{, Hurd command}
19535This command shows whether @value{GDBN} thinks the debuggee is
19536stopped.
19537
19538@item set exceptions
19539@kindex set exceptions@r{, Hurd command}
19540Use this command to turn off trapping of exceptions in the inferior.
19541When exception trapping is off, neither breakpoints nor
19542single-stepping will work. To restore the default, set exception
19543trapping on.
19544
19545@item show exceptions
19546@kindex show exceptions@r{, Hurd command}
19547Show the current state of trapping exceptions in the inferior.
19548
19549@item set task pause
19550@kindex set task@r{, Hurd commands}
19551@cindex task attributes (@sc{gnu} Hurd)
19552@cindex pause current task (@sc{gnu} Hurd)
19553This command toggles task suspension when @value{GDBN} has control.
19554Setting it to on takes effect immediately, and the task is suspended
19555whenever @value{GDBN} gets control. Setting it to off will take
19556effect the next time the inferior is continued. If this option is set
19557to off, you can use @code{set thread default pause on} or @code{set
19558thread pause on} (see below) to pause individual threads.
19559
19560@item show task pause
19561@kindex show task@r{, Hurd commands}
19562Show the current state of task suspension.
19563
19564@item set task detach-suspend-count
19565@cindex task suspend count
19566@cindex detach from task, @sc{gnu} Hurd
19567This command sets the suspend count the task will be left with when
19568@value{GDBN} detaches from it.
19569
19570@item show task detach-suspend-count
19571Show the suspend count the task will be left with when detaching.
19572
19573@item set task exception-port
19574@itemx set task excp
19575@cindex task exception port, @sc{gnu} Hurd
19576This command sets the task exception port to which @value{GDBN} will
19577forward exceptions. The argument should be the value of the @dfn{send
19578rights} of the task. @code{set task excp} is a shorthand alias.
19579
19580@item set noninvasive
19581@cindex noninvasive task options
19582This command switches @value{GDBN} to a mode that is the least
19583invasive as far as interfering with the inferior is concerned. This
19584is the same as using @code{set task pause}, @code{set exceptions}, and
19585@code{set signals} to values opposite to the defaults.
19586
19587@item info send-rights
19588@itemx info receive-rights
19589@itemx info port-rights
19590@itemx info port-sets
19591@itemx info dead-names
19592@itemx info ports
19593@itemx info psets
19594@cindex send rights, @sc{gnu} Hurd
19595@cindex receive rights, @sc{gnu} Hurd
19596@cindex port rights, @sc{gnu} Hurd
19597@cindex port sets, @sc{gnu} Hurd
19598@cindex dead names, @sc{gnu} Hurd
19599These commands display information about, respectively, send rights,
19600receive rights, port rights, port sets, and dead names of a task.
19601There are also shorthand aliases: @code{info ports} for @code{info
19602port-rights} and @code{info psets} for @code{info port-sets}.
19603
19604@item set thread pause
19605@kindex set thread@r{, Hurd command}
19606@cindex thread properties, @sc{gnu} Hurd
19607@cindex pause current thread (@sc{gnu} Hurd)
19608This command toggles current thread suspension when @value{GDBN} has
19609control. Setting it to on takes effect immediately, and the current
19610thread is suspended whenever @value{GDBN} gets control. Setting it to
19611off will take effect the next time the inferior is continued.
19612Normally, this command has no effect, since when @value{GDBN} has
19613control, the whole task is suspended. However, if you used @code{set
19614task pause off} (see above), this command comes in handy to suspend
19615only the current thread.
19616
19617@item show thread pause
19618@kindex show thread@r{, Hurd command}
19619This command shows the state of current thread suspension.
19620
19621@item set thread run
d3e8051b 19622This command sets whether the current thread is allowed to run.
14d6dd68
EZ
19623
19624@item show thread run
19625Show whether the current thread is allowed to run.
19626
19627@item set thread detach-suspend-count
19628@cindex thread suspend count, @sc{gnu} Hurd
19629@cindex detach from thread, @sc{gnu} Hurd
19630This command sets the suspend count @value{GDBN} will leave on a
19631thread when detaching. This number is relative to the suspend count
19632found by @value{GDBN} when it notices the thread; use @code{set thread
19633takeover-suspend-count} to force it to an absolute value.
19634
19635@item show thread detach-suspend-count
19636Show the suspend count @value{GDBN} will leave on the thread when
19637detaching.
19638
19639@item set thread exception-port
19640@itemx set thread excp
19641Set the thread exception port to which to forward exceptions. This
19642overrides the port set by @code{set task exception-port} (see above).
19643@code{set thread excp} is the shorthand alias.
19644
19645@item set thread takeover-suspend-count
19646Normally, @value{GDBN}'s thread suspend counts are relative to the
19647value @value{GDBN} finds when it notices each thread. This command
19648changes the suspend counts to be absolute instead.
19649
19650@item set thread default
19651@itemx show thread default
19652@cindex thread default settings, @sc{gnu} Hurd
19653Each of the above @code{set thread} commands has a @code{set thread
19654default} counterpart (e.g., @code{set thread default pause}, @code{set
19655thread default exception-port}, etc.). The @code{thread default}
19656variety of commands sets the default thread properties for all
19657threads; you can then change the properties of individual threads with
19658the non-default commands.
19659@end table
19660
a80b95ba
TG
19661@node Darwin
19662@subsection Darwin
19663@cindex Darwin
19664
19665@value{GDBN} provides the following commands specific to the Darwin target:
19666
19667@table @code
19668@item set debug darwin @var{num}
19669@kindex set debug darwin
19670When set to a non zero value, enables debugging messages specific to
19671the Darwin support. Higher values produce more verbose output.
19672
19673@item show debug darwin
19674@kindex show debug darwin
19675Show the current state of Darwin messages.
19676
19677@item set debug mach-o @var{num}
19678@kindex set debug mach-o
19679When set to a non zero value, enables debugging messages while
19680@value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
19681file format used on Darwin for object and executable files.) Higher
19682values produce more verbose output. This is a command to diagnose
19683problems internal to @value{GDBN} and should not be needed in normal
19684usage.
19685
19686@item show debug mach-o
19687@kindex show debug mach-o
19688Show the current state of Mach-O file messages.
19689
19690@item set mach-exceptions on
19691@itemx set mach-exceptions off
19692@kindex set mach-exceptions
19693On Darwin, faults are first reported as a Mach exception and are then
19694mapped to a Posix signal. Use this command to turn on trapping of
19695Mach exceptions in the inferior. This might be sometimes useful to
19696better understand the cause of a fault. The default is off.
19697
19698@item show mach-exceptions
19699@kindex show mach-exceptions
19700Show the current state of exceptions trapping.
19701@end table
19702
a64548ea 19703
8e04817f
AC
19704@node Embedded OS
19705@section Embedded Operating Systems
104c1213 19706
8e04817f
AC
19707This section describes configurations involving the debugging of
19708embedded operating systems that are available for several different
19709architectures.
d4f3574e 19710
8e04817f
AC
19711@menu
19712* VxWorks:: Using @value{GDBN} with VxWorks
19713@end menu
104c1213 19714
8e04817f
AC
19715@value{GDBN} includes the ability to debug programs running on
19716various real-time operating systems.
104c1213 19717
8e04817f
AC
19718@node VxWorks
19719@subsection Using @value{GDBN} with VxWorks
104c1213 19720
8e04817f 19721@cindex VxWorks
104c1213 19722
8e04817f 19723@table @code
104c1213 19724
8e04817f
AC
19725@kindex target vxworks
19726@item target vxworks @var{machinename}
19727A VxWorks system, attached via TCP/IP. The argument @var{machinename}
19728is the target system's machine name or IP address.
104c1213 19729
8e04817f 19730@end table
104c1213 19731
8e04817f
AC
19732On VxWorks, @code{load} links @var{filename} dynamically on the
19733current target system as well as adding its symbols in @value{GDBN}.
104c1213 19734
8e04817f
AC
19735@value{GDBN} enables developers to spawn and debug tasks running on networked
19736VxWorks targets from a Unix host. Already-running tasks spawned from
19737the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
19738both the Unix host and on the VxWorks target. The program
19739@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
19740installed with the name @code{vxgdb}, to distinguish it from a
19741@value{GDBN} for debugging programs on the host itself.)
104c1213 19742
8e04817f
AC
19743@table @code
19744@item VxWorks-timeout @var{args}
19745@kindex vxworks-timeout
19746All VxWorks-based targets now support the option @code{vxworks-timeout}.
19747This option is set by the user, and @var{args} represents the number of
19748seconds @value{GDBN} waits for responses to rpc's. You might use this if
19749your VxWorks target is a slow software simulator or is on the far side
19750of a thin network line.
19751@end table
104c1213 19752
8e04817f
AC
19753The following information on connecting to VxWorks was current when
19754this manual was produced; newer releases of VxWorks may use revised
19755procedures.
104c1213 19756
4644b6e3 19757@findex INCLUDE_RDB
8e04817f
AC
19758To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
19759to include the remote debugging interface routines in the VxWorks
19760library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
19761VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
19762kernel. The resulting kernel contains @file{rdb.a}, and spawns the
19763source debugging task @code{tRdbTask} when VxWorks is booted. For more
19764information on configuring and remaking VxWorks, see the manufacturer's
19765manual.
19766@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 19767
8e04817f
AC
19768Once you have included @file{rdb.a} in your VxWorks system image and set
19769your Unix execution search path to find @value{GDBN}, you are ready to
19770run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
19771@code{vxgdb}, depending on your installation).
104c1213 19772
8e04817f 19773@value{GDBN} comes up showing the prompt:
104c1213 19774
474c8240 19775@smallexample
8e04817f 19776(vxgdb)
474c8240 19777@end smallexample
104c1213 19778
8e04817f
AC
19779@menu
19780* VxWorks Connection:: Connecting to VxWorks
19781* VxWorks Download:: VxWorks download
19782* VxWorks Attach:: Running tasks
19783@end menu
104c1213 19784
8e04817f
AC
19785@node VxWorks Connection
19786@subsubsection Connecting to VxWorks
104c1213 19787
8e04817f
AC
19788The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
19789network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 19790
474c8240 19791@smallexample
8e04817f 19792(vxgdb) target vxworks tt
474c8240 19793@end smallexample
104c1213 19794
8e04817f
AC
19795@need 750
19796@value{GDBN} displays messages like these:
104c1213 19797
8e04817f
AC
19798@smallexample
19799Attaching remote machine across net...
19800Connected to tt.
19801@end smallexample
104c1213 19802
8e04817f
AC
19803@need 1000
19804@value{GDBN} then attempts to read the symbol tables of any object modules
19805loaded into the VxWorks target since it was last booted. @value{GDBN} locates
19806these files by searching the directories listed in the command search
79a6e687 19807path (@pxref{Environment, ,Your Program's Environment}); if it fails
8e04817f 19808to find an object file, it displays a message such as:
5d161b24 19809
474c8240 19810@smallexample
8e04817f 19811prog.o: No such file or directory.
474c8240 19812@end smallexample
104c1213 19813
8e04817f
AC
19814When this happens, add the appropriate directory to the search path with
19815the @value{GDBN} command @code{path}, and execute the @code{target}
19816command again.
104c1213 19817
8e04817f 19818@node VxWorks Download
79a6e687 19819@subsubsection VxWorks Download
104c1213 19820
8e04817f
AC
19821@cindex download to VxWorks
19822If you have connected to the VxWorks target and you want to debug an
19823object that has not yet been loaded, you can use the @value{GDBN}
19824@code{load} command to download a file from Unix to VxWorks
19825incrementally. The object file given as an argument to the @code{load}
19826command is actually opened twice: first by the VxWorks target in order
19827to download the code, then by @value{GDBN} in order to read the symbol
19828table. This can lead to problems if the current working directories on
19829the two systems differ. If both systems have NFS mounted the same
19830filesystems, you can avoid these problems by using absolute paths.
19831Otherwise, it is simplest to set the working directory on both systems
19832to the directory in which the object file resides, and then to reference
19833the file by its name, without any path. For instance, a program
19834@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
19835and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
19836program, type this on VxWorks:
104c1213 19837
474c8240 19838@smallexample
8e04817f 19839-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 19840@end smallexample
104c1213 19841
8e04817f
AC
19842@noindent
19843Then, in @value{GDBN}, type:
104c1213 19844
474c8240 19845@smallexample
8e04817f
AC
19846(vxgdb) cd @var{hostpath}/vw/demo/rdb
19847(vxgdb) load prog.o
474c8240 19848@end smallexample
104c1213 19849
8e04817f 19850@value{GDBN} displays a response similar to this:
104c1213 19851
8e04817f
AC
19852@smallexample
19853Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
19854@end smallexample
104c1213 19855
8e04817f
AC
19856You can also use the @code{load} command to reload an object module
19857after editing and recompiling the corresponding source file. Note that
19858this makes @value{GDBN} delete all currently-defined breakpoints,
19859auto-displays, and convenience variables, and to clear the value
19860history. (This is necessary in order to preserve the integrity of
19861debugger's data structures that reference the target system's symbol
19862table.)
104c1213 19863
8e04817f 19864@node VxWorks Attach
79a6e687 19865@subsubsection Running Tasks
104c1213
JM
19866
19867@cindex running VxWorks tasks
19868You can also attach to an existing task using the @code{attach} command as
19869follows:
19870
474c8240 19871@smallexample
104c1213 19872(vxgdb) attach @var{task}
474c8240 19873@end smallexample
104c1213
JM
19874
19875@noindent
19876where @var{task} is the VxWorks hexadecimal task ID. The task can be running
19877or suspended when you attach to it. Running tasks are suspended at
19878the time of attachment.
19879
6d2ebf8b 19880@node Embedded Processors
104c1213
JM
19881@section Embedded Processors
19882
19883This section goes into details specific to particular embedded
19884configurations.
19885
c45da7e6
EZ
19886@cindex send command to simulator
19887Whenever a specific embedded processor has a simulator, @value{GDBN}
19888allows to send an arbitrary command to the simulator.
19889
19890@table @code
19891@item sim @var{command}
19892@kindex sim@r{, a command}
19893Send an arbitrary @var{command} string to the simulator. Consult the
19894documentation for the specific simulator in use for information about
19895acceptable commands.
19896@end table
19897
7d86b5d5 19898
104c1213 19899@menu
c45da7e6 19900* ARM:: ARM RDI
172c2a43 19901* M32R/D:: Renesas M32R/D
104c1213 19902* M68K:: Motorola M68K
08be9d71 19903* MicroBlaze:: Xilinx MicroBlaze
104c1213 19904* MIPS Embedded:: MIPS Embedded
4acd40f3 19905* PowerPC Embedded:: PowerPC Embedded
984359d2 19906* PA:: HP PA Embedded
104c1213
JM
19907* Sparclet:: Tsqware Sparclet
19908* Sparclite:: Fujitsu Sparclite
104c1213 19909* Z8000:: Zilog Z8000
a64548ea
EZ
19910* AVR:: Atmel AVR
19911* CRIS:: CRIS
19912* Super-H:: Renesas Super-H
104c1213
JM
19913@end menu
19914
6d2ebf8b 19915@node ARM
104c1213 19916@subsection ARM
c45da7e6 19917@cindex ARM RDI
104c1213
JM
19918
19919@table @code
8e04817f
AC
19920@kindex target rdi
19921@item target rdi @var{dev}
19922ARM Angel monitor, via RDI library interface to ADP protocol. You may
19923use this target to communicate with both boards running the Angel
19924monitor, or with the EmbeddedICE JTAG debug device.
19925
19926@kindex target rdp
19927@item target rdp @var{dev}
19928ARM Demon monitor.
19929
19930@end table
19931
e2f4edfd
EZ
19932@value{GDBN} provides the following ARM-specific commands:
19933
19934@table @code
19935@item set arm disassembler
19936@kindex set arm
19937This commands selects from a list of disassembly styles. The
19938@code{"std"} style is the standard style.
19939
19940@item show arm disassembler
19941@kindex show arm
19942Show the current disassembly style.
19943
19944@item set arm apcs32
19945@cindex ARM 32-bit mode
19946This command toggles ARM operation mode between 32-bit and 26-bit.
19947
19948@item show arm apcs32
19949Display the current usage of the ARM 32-bit mode.
19950
19951@item set arm fpu @var{fputype}
19952This command sets the ARM floating-point unit (FPU) type. The
19953argument @var{fputype} can be one of these:
19954
19955@table @code
19956@item auto
19957Determine the FPU type by querying the OS ABI.
19958@item softfpa
19959Software FPU, with mixed-endian doubles on little-endian ARM
19960processors.
19961@item fpa
19962GCC-compiled FPA co-processor.
19963@item softvfp
19964Software FPU with pure-endian doubles.
19965@item vfp
19966VFP co-processor.
19967@end table
19968
19969@item show arm fpu
19970Show the current type of the FPU.
19971
19972@item set arm abi
19973This command forces @value{GDBN} to use the specified ABI.
19974
19975@item show arm abi
19976Show the currently used ABI.
19977
0428b8f5
DJ
19978@item set arm fallback-mode (arm|thumb|auto)
19979@value{GDBN} uses the symbol table, when available, to determine
19980whether instructions are ARM or Thumb. This command controls
19981@value{GDBN}'s default behavior when the symbol table is not
19982available. The default is @samp{auto}, which causes @value{GDBN} to
19983use the current execution mode (from the @code{T} bit in the @code{CPSR}
19984register).
19985
19986@item show arm fallback-mode
19987Show the current fallback instruction mode.
19988
19989@item set arm force-mode (arm|thumb|auto)
19990This command overrides use of the symbol table to determine whether
19991instructions are ARM or Thumb. The default is @samp{auto}, which
19992causes @value{GDBN} to use the symbol table and then the setting
19993of @samp{set arm fallback-mode}.
19994
19995@item show arm force-mode
19996Show the current forced instruction mode.
19997
e2f4edfd
EZ
19998@item set debug arm
19999Toggle whether to display ARM-specific debugging messages from the ARM
20000target support subsystem.
20001
20002@item show debug arm
20003Show whether ARM-specific debugging messages are enabled.
20004@end table
20005
c45da7e6
EZ
20006The following commands are available when an ARM target is debugged
20007using the RDI interface:
20008
20009@table @code
20010@item rdilogfile @r{[}@var{file}@r{]}
20011@kindex rdilogfile
20012@cindex ADP (Angel Debugger Protocol) logging
20013Set the filename for the ADP (Angel Debugger Protocol) packet log.
20014With an argument, sets the log file to the specified @var{file}. With
20015no argument, show the current log file name. The default log file is
20016@file{rdi.log}.
20017
20018@item rdilogenable @r{[}@var{arg}@r{]}
20019@kindex rdilogenable
20020Control logging of ADP packets. With an argument of 1 or @code{"yes"}
20021enables logging, with an argument 0 or @code{"no"} disables it. With
20022no arguments displays the current setting. When logging is enabled,
20023ADP packets exchanged between @value{GDBN} and the RDI target device
20024are logged to a file.
20025
20026@item set rdiromatzero
20027@kindex set rdiromatzero
20028@cindex ROM at zero address, RDI
20029Tell @value{GDBN} whether the target has ROM at address 0. If on,
20030vector catching is disabled, so that zero address can be used. If off
20031(the default), vector catching is enabled. For this command to take
20032effect, it needs to be invoked prior to the @code{target rdi} command.
20033
20034@item show rdiromatzero
20035@kindex show rdiromatzero
20036Show the current setting of ROM at zero address.
20037
20038@item set rdiheartbeat
20039@kindex set rdiheartbeat
20040@cindex RDI heartbeat
20041Enable or disable RDI heartbeat packets. It is not recommended to
20042turn on this option, since it confuses ARM and EPI JTAG interface, as
20043well as the Angel monitor.
20044
20045@item show rdiheartbeat
20046@kindex show rdiheartbeat
20047Show the setting of RDI heartbeat packets.
20048@end table
20049
ee8e71d4
EZ
20050@table @code
20051@item target sim @r{[}@var{simargs}@r{]} @dots{}
20052The @value{GDBN} ARM simulator accepts the following optional arguments.
20053
20054@table @code
20055@item --swi-support=@var{type}
20056Tell the simulator which SWI interfaces to support.
20057@var{type} may be a comma separated list of the following values.
20058The default value is @code{all}.
20059
20060@table @code
20061@item none
20062@item demon
20063@item angel
20064@item redboot
20065@item all
20066@end table
20067@end table
20068@end table
e2f4edfd 20069
8e04817f 20070@node M32R/D
ba04e063 20071@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
20072
20073@table @code
8e04817f
AC
20074@kindex target m32r
20075@item target m32r @var{dev}
172c2a43 20076Renesas M32R/D ROM monitor.
8e04817f 20077
fb3e19c0
KI
20078@kindex target m32rsdi
20079@item target m32rsdi @var{dev}
20080Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
20081@end table
20082
20083The following @value{GDBN} commands are specific to the M32R monitor:
20084
20085@table @code
20086@item set download-path @var{path}
20087@kindex set download-path
20088@cindex find downloadable @sc{srec} files (M32R)
d3e8051b 20089Set the default path for finding downloadable @sc{srec} files.
721c2651
EZ
20090
20091@item show download-path
20092@kindex show download-path
20093Show the default path for downloadable @sc{srec} files.
fb3e19c0 20094
721c2651
EZ
20095@item set board-address @var{addr}
20096@kindex set board-address
20097@cindex M32-EVA target board address
20098Set the IP address for the M32R-EVA target board.
20099
20100@item show board-address
20101@kindex show board-address
20102Show the current IP address of the target board.
20103
20104@item set server-address @var{addr}
20105@kindex set server-address
20106@cindex download server address (M32R)
20107Set the IP address for the download server, which is the @value{GDBN}'s
20108host machine.
20109
20110@item show server-address
20111@kindex show server-address
20112Display the IP address of the download server.
20113
20114@item upload @r{[}@var{file}@r{]}
20115@kindex upload@r{, M32R}
20116Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
20117upload capability. If no @var{file} argument is given, the current
20118executable file is uploaded.
20119
20120@item tload @r{[}@var{file}@r{]}
20121@kindex tload@r{, M32R}
20122Test the @code{upload} command.
8e04817f
AC
20123@end table
20124
ba04e063
EZ
20125The following commands are available for M32R/SDI:
20126
20127@table @code
20128@item sdireset
20129@kindex sdireset
20130@cindex reset SDI connection, M32R
20131This command resets the SDI connection.
20132
20133@item sdistatus
20134@kindex sdistatus
20135This command shows the SDI connection status.
20136
20137@item debug_chaos
20138@kindex debug_chaos
20139@cindex M32R/Chaos debugging
20140Instructs the remote that M32R/Chaos debugging is to be used.
20141
20142@item use_debug_dma
20143@kindex use_debug_dma
20144Instructs the remote to use the DEBUG_DMA method of accessing memory.
20145
20146@item use_mon_code
20147@kindex use_mon_code
20148Instructs the remote to use the MON_CODE method of accessing memory.
20149
20150@item use_ib_break
20151@kindex use_ib_break
20152Instructs the remote to set breakpoints by IB break.
20153
20154@item use_dbt_break
20155@kindex use_dbt_break
20156Instructs the remote to set breakpoints by DBT.
20157@end table
20158
8e04817f
AC
20159@node M68K
20160@subsection M68k
20161
7ce59000
DJ
20162The Motorola m68k configuration includes ColdFire support, and a
20163target command for the following ROM monitor.
8e04817f
AC
20164
20165@table @code
20166
8e04817f
AC
20167@kindex target dbug
20168@item target dbug @var{dev}
20169dBUG ROM monitor for Motorola ColdFire.
20170
8e04817f
AC
20171@end table
20172
08be9d71
ME
20173@node MicroBlaze
20174@subsection MicroBlaze
20175@cindex Xilinx MicroBlaze
20176@cindex XMD, Xilinx Microprocessor Debugger
20177
20178The MicroBlaze is a soft-core processor supported on various Xilinx
20179FPGAs, such as Spartan or Virtex series. Boards with these processors
20180usually have JTAG ports which connect to a host system running the Xilinx
20181Embedded Development Kit (EDK) or Software Development Kit (SDK).
20182This host system is used to download the configuration bitstream to
20183the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
20184communicates with the target board using the JTAG interface and
20185presents a @code{gdbserver} interface to the board. By default
20186@code{xmd} uses port @code{1234}. (While it is possible to change
20187this default port, it requires the use of undocumented @code{xmd}
20188commands. Contact Xilinx support if you need to do this.)
20189
20190Use these GDB commands to connect to the MicroBlaze target processor.
20191
20192@table @code
20193@item target remote :1234
20194Use this command to connect to the target if you are running @value{GDBN}
20195on the same system as @code{xmd}.
20196
20197@item target remote @var{xmd-host}:1234
20198Use this command to connect to the target if it is connected to @code{xmd}
20199running on a different system named @var{xmd-host}.
20200
20201@item load
20202Use this command to download a program to the MicroBlaze target.
20203
20204@item set debug microblaze @var{n}
20205Enable MicroBlaze-specific debugging messages if non-zero.
20206
20207@item show debug microblaze @var{n}
20208Show MicroBlaze-specific debugging level.
20209@end table
20210
8e04817f 20211@node MIPS Embedded
eb17f351 20212@subsection @acronym{MIPS} Embedded
8e04817f 20213
eb17f351
EZ
20214@cindex @acronym{MIPS} boards
20215@value{GDBN} can use the @acronym{MIPS} remote debugging protocol to talk to a
20216@acronym{MIPS} board attached to a serial line. This is available when
cc30c4bd 20217you configure @value{GDBN} with @samp{--target=mips-elf}.
104c1213 20218
8e04817f
AC
20219@need 1000
20220Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 20221
8e04817f
AC
20222@table @code
20223@item target mips @var{port}
20224@kindex target mips @var{port}
20225To run a program on the board, start up @code{@value{GDBP}} with the
20226name of your program as the argument. To connect to the board, use the
20227command @samp{target mips @var{port}}, where @var{port} is the name of
20228the serial port connected to the board. If the program has not already
20229been downloaded to the board, you may use the @code{load} command to
20230download it. You can then use all the usual @value{GDBN} commands.
104c1213 20231
8e04817f
AC
20232For example, this sequence connects to the target board through a serial
20233port, and loads and runs a program called @var{prog} through the
20234debugger:
104c1213 20235
474c8240 20236@smallexample
8e04817f
AC
20237host$ @value{GDBP} @var{prog}
20238@value{GDBN} is free software and @dots{}
20239(@value{GDBP}) target mips /dev/ttyb
20240(@value{GDBP}) load @var{prog}
20241(@value{GDBP}) run
474c8240 20242@end smallexample
104c1213 20243
8e04817f
AC
20244@item target mips @var{hostname}:@var{portnumber}
20245On some @value{GDBN} host configurations, you can specify a TCP
20246connection (for instance, to a serial line managed by a terminal
20247concentrator) instead of a serial port, using the syntax
20248@samp{@var{hostname}:@var{portnumber}}.
104c1213 20249
8e04817f
AC
20250@item target pmon @var{port}
20251@kindex target pmon @var{port}
20252PMON ROM monitor.
104c1213 20253
8e04817f
AC
20254@item target ddb @var{port}
20255@kindex target ddb @var{port}
20256NEC's DDB variant of PMON for Vr4300.
104c1213 20257
8e04817f
AC
20258@item target lsi @var{port}
20259@kindex target lsi @var{port}
20260LSI variant of PMON.
104c1213 20261
8e04817f
AC
20262@kindex target r3900
20263@item target r3900 @var{dev}
20264Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 20265
8e04817f
AC
20266@kindex target array
20267@item target array @var{dev}
20268Array Tech LSI33K RAID controller board.
104c1213 20269
8e04817f 20270@end table
104c1213 20271
104c1213 20272
8e04817f 20273@noindent
eb17f351 20274@value{GDBN} also supports these special commands for @acronym{MIPS} targets:
104c1213 20275
8e04817f 20276@table @code
8e04817f
AC
20277@item set mipsfpu double
20278@itemx set mipsfpu single
20279@itemx set mipsfpu none
a64548ea 20280@itemx set mipsfpu auto
8e04817f
AC
20281@itemx show mipsfpu
20282@kindex set mipsfpu
20283@kindex show mipsfpu
eb17f351
EZ
20284@cindex @acronym{MIPS} remote floating point
20285@cindex floating point, @acronym{MIPS} remote
20286If your target board does not support the @acronym{MIPS} floating point
8e04817f
AC
20287coprocessor, you should use the command @samp{set mipsfpu none} (if you
20288need this, you may wish to put the command in your @value{GDBN} init
20289file). This tells @value{GDBN} how to find the return value of
20290functions which return floating point values. It also allows
20291@value{GDBN} to avoid saving the floating point registers when calling
20292functions on the board. If you are using a floating point coprocessor
20293with only single precision floating point support, as on the @sc{r4650}
20294processor, use the command @samp{set mipsfpu single}. The default
20295double precision floating point coprocessor may be selected using
20296@samp{set mipsfpu double}.
104c1213 20297
8e04817f
AC
20298In previous versions the only choices were double precision or no
20299floating point, so @samp{set mipsfpu on} will select double precision
20300and @samp{set mipsfpu off} will select no floating point.
104c1213 20301
8e04817f
AC
20302As usual, you can inquire about the @code{mipsfpu} variable with
20303@samp{show mipsfpu}.
104c1213 20304
8e04817f
AC
20305@item set timeout @var{seconds}
20306@itemx set retransmit-timeout @var{seconds}
20307@itemx show timeout
20308@itemx show retransmit-timeout
eb17f351
EZ
20309@cindex @code{timeout}, @acronym{MIPS} protocol
20310@cindex @code{retransmit-timeout}, @acronym{MIPS} protocol
8e04817f
AC
20311@kindex set timeout
20312@kindex show timeout
20313@kindex set retransmit-timeout
20314@kindex show retransmit-timeout
eb17f351 20315You can control the timeout used while waiting for a packet, in the @acronym{MIPS}
8e04817f
AC
20316remote protocol, with the @code{set timeout @var{seconds}} command. The
20317default is 5 seconds. Similarly, you can control the timeout used while
a6f3e723 20318waiting for an acknowledgment of a packet with the @code{set
8e04817f
AC
20319retransmit-timeout @var{seconds}} command. The default is 3 seconds.
20320You can inspect both values with @code{show timeout} and @code{show
20321retransmit-timeout}. (These commands are @emph{only} available when
cc30c4bd 20322@value{GDBN} is configured for @samp{--target=mips-elf}.)
104c1213 20323
8e04817f
AC
20324The timeout set by @code{set timeout} does not apply when @value{GDBN}
20325is waiting for your program to stop. In that case, @value{GDBN} waits
20326forever because it has no way of knowing how long the program is going
20327to run before stopping.
ba04e063
EZ
20328
20329@item set syn-garbage-limit @var{num}
eb17f351
EZ
20330@kindex set syn-garbage-limit@r{, @acronym{MIPS} remote}
20331@cindex synchronize with remote @acronym{MIPS} target
ba04e063
EZ
20332Limit the maximum number of characters @value{GDBN} should ignore when
20333it tries to synchronize with the remote target. The default is 10
20334characters. Setting the limit to -1 means there's no limit.
20335
20336@item show syn-garbage-limit
eb17f351 20337@kindex show syn-garbage-limit@r{, @acronym{MIPS} remote}
ba04e063
EZ
20338Show the current limit on the number of characters to ignore when
20339trying to synchronize with the remote system.
20340
20341@item set monitor-prompt @var{prompt}
eb17f351 20342@kindex set monitor-prompt@r{, @acronym{MIPS} remote}
ba04e063
EZ
20343@cindex remote monitor prompt
20344Tell @value{GDBN} to expect the specified @var{prompt} string from the
20345remote monitor. The default depends on the target:
20346@table @asis
20347@item pmon target
20348@samp{PMON}
20349@item ddb target
20350@samp{NEC010}
20351@item lsi target
20352@samp{PMON>}
20353@end table
20354
20355@item show monitor-prompt
eb17f351 20356@kindex show monitor-prompt@r{, @acronym{MIPS} remote}
ba04e063
EZ
20357Show the current strings @value{GDBN} expects as the prompt from the
20358remote monitor.
20359
20360@item set monitor-warnings
eb17f351 20361@kindex set monitor-warnings@r{, @acronym{MIPS} remote}
ba04e063
EZ
20362Enable or disable monitor warnings about hardware breakpoints. This
20363has effect only for the @code{lsi} target. When on, @value{GDBN} will
20364display warning messages whose codes are returned by the @code{lsi}
20365PMON monitor for breakpoint commands.
20366
20367@item show monitor-warnings
eb17f351 20368@kindex show monitor-warnings@r{, @acronym{MIPS} remote}
ba04e063
EZ
20369Show the current setting of printing monitor warnings.
20370
20371@item pmon @var{command}
eb17f351 20372@kindex pmon@r{, @acronym{MIPS} remote}
ba04e063
EZ
20373@cindex send PMON command
20374This command allows sending an arbitrary @var{command} string to the
20375monitor. The monitor must be in debug mode for this to work.
8e04817f 20376@end table
104c1213 20377
4acd40f3
TJB
20378@node PowerPC Embedded
20379@subsection PowerPC Embedded
104c1213 20380
66b73624
TJB
20381@cindex DVC register
20382@value{GDBN} supports using the DVC (Data Value Compare) register to
20383implement in hardware simple hardware watchpoint conditions of the form:
20384
20385@smallexample
20386(@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
20387 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
20388@end smallexample
20389
e09342b5
TJB
20390The DVC register will be automatically used when @value{GDBN} detects
20391such pattern in a condition expression, and the created watchpoint uses one
20392debug register (either the @code{exact-watchpoints} option is on and the
20393variable is scalar, or the variable has a length of one byte). This feature
20394is available in native @value{GDBN} running on a Linux kernel version 2.6.34
20395or newer.
20396
20397When running on PowerPC embedded processors, @value{GDBN} automatically uses
20398ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
20399in which case watchpoints using only one debug register are created when
20400watching variables of scalar types.
20401
20402You can create an artificial array to watch an arbitrary memory
20403region using one of the following commands (@pxref{Expressions}):
20404
20405@smallexample
20406(@value{GDBP}) watch *((char *) @var{address})@@@var{length}
20407(@value{GDBP}) watch @{char[@var{length}]@} @var{address}
20408@end smallexample
66b73624 20409
9c06b0b4
TJB
20410PowerPC embedded processors support masked watchpoints. See the discussion
20411about the @code{mask} argument in @ref{Set Watchpoints}.
20412
f1310107
TJB
20413@cindex ranged breakpoint
20414PowerPC embedded processors support hardware accelerated
20415@dfn{ranged breakpoints}. A ranged breakpoint stops execution of
20416the inferior whenever it executes an instruction at any address within
20417the range it specifies. To set a ranged breakpoint in @value{GDBN},
20418use the @code{break-range} command.
20419
55eddb0f
DJ
20420@value{GDBN} provides the following PowerPC-specific commands:
20421
104c1213 20422@table @code
f1310107
TJB
20423@kindex break-range
20424@item break-range @var{start-location}, @var{end-location}
20425Set a breakpoint for an address range.
20426@var{start-location} and @var{end-location} can specify a function name,
20427a line number, an offset of lines from the current line or from the start
20428location, or an address of an instruction (see @ref{Specify Location},
20429for a list of all the possible ways to specify a @var{location}.)
20430The breakpoint will stop execution of the inferior whenever it
20431executes an instruction at any address within the specified range,
20432(including @var{start-location} and @var{end-location}.)
20433
55eddb0f
DJ
20434@kindex set powerpc
20435@item set powerpc soft-float
20436@itemx show powerpc soft-float
20437Force @value{GDBN} to use (or not use) a software floating point calling
20438convention. By default, @value{GDBN} selects the calling convention based
20439on the selected architecture and the provided executable file.
20440
20441@item set powerpc vector-abi
20442@itemx show powerpc vector-abi
20443Force @value{GDBN} to use the specified calling convention for vector
20444arguments and return values. The valid options are @samp{auto};
20445@samp{generic}, to avoid vector registers even if they are present;
20446@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
20447registers. By default, @value{GDBN} selects the calling convention
20448based on the selected architecture and the provided executable file.
20449
e09342b5
TJB
20450@item set powerpc exact-watchpoints
20451@itemx show powerpc exact-watchpoints
20452Allow @value{GDBN} to use only one debug register when watching a variable
20453of scalar type, thus assuming that the variable is accessed through the
20454address of its first byte.
20455
8e04817f
AC
20456@kindex target dink32
20457@item target dink32 @var{dev}
20458DINK32 ROM monitor.
104c1213 20459
8e04817f
AC
20460@kindex target ppcbug
20461@item target ppcbug @var{dev}
20462@kindex target ppcbug1
20463@item target ppcbug1 @var{dev}
20464PPCBUG ROM monitor for PowerPC.
104c1213 20465
8e04817f
AC
20466@kindex target sds
20467@item target sds @var{dev}
20468SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 20469@end table
8e04817f 20470
c45da7e6 20471@cindex SDS protocol
d52fb0e9 20472The following commands specific to the SDS protocol are supported
55eddb0f 20473by @value{GDBN}:
c45da7e6
EZ
20474
20475@table @code
20476@item set sdstimeout @var{nsec}
20477@kindex set sdstimeout
20478Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
20479default is 2 seconds.
20480
20481@item show sdstimeout
20482@kindex show sdstimeout
20483Show the current value of the SDS timeout.
20484
20485@item sds @var{command}
20486@kindex sds@r{, a command}
20487Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
20488@end table
20489
c45da7e6 20490
8e04817f
AC
20491@node PA
20492@subsection HP PA Embedded
104c1213
JM
20493
20494@table @code
20495
8e04817f
AC
20496@kindex target op50n
20497@item target op50n @var{dev}
20498OP50N monitor, running on an OKI HPPA board.
20499
20500@kindex target w89k
20501@item target w89k @var{dev}
20502W89K monitor, running on a Winbond HPPA board.
104c1213
JM
20503
20504@end table
20505
8e04817f
AC
20506@node Sparclet
20507@subsection Tsqware Sparclet
104c1213 20508
8e04817f
AC
20509@cindex Sparclet
20510
20511@value{GDBN} enables developers to debug tasks running on
20512Sparclet targets from a Unix host.
20513@value{GDBN} uses code that runs on
20514both the Unix host and on the Sparclet target. The program
20515@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 20516
8e04817f
AC
20517@table @code
20518@item remotetimeout @var{args}
20519@kindex remotetimeout
20520@value{GDBN} supports the option @code{remotetimeout}.
20521This option is set by the user, and @var{args} represents the number of
20522seconds @value{GDBN} waits for responses.
104c1213
JM
20523@end table
20524
8e04817f
AC
20525@cindex compiling, on Sparclet
20526When compiling for debugging, include the options @samp{-g} to get debug
20527information and @samp{-Ttext} to relocate the program to where you wish to
20528load it on the target. You may also want to add the options @samp{-n} or
20529@samp{-N} in order to reduce the size of the sections. Example:
104c1213 20530
474c8240 20531@smallexample
8e04817f 20532sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 20533@end smallexample
104c1213 20534
8e04817f 20535You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 20536
474c8240 20537@smallexample
8e04817f 20538sparclet-aout-objdump --headers --syms prog
474c8240 20539@end smallexample
104c1213 20540
8e04817f
AC
20541@cindex running, on Sparclet
20542Once you have set
20543your Unix execution search path to find @value{GDBN}, you are ready to
20544run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
20545(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 20546
8e04817f
AC
20547@value{GDBN} comes up showing the prompt:
20548
474c8240 20549@smallexample
8e04817f 20550(gdbslet)
474c8240 20551@end smallexample
104c1213
JM
20552
20553@menu
8e04817f
AC
20554* Sparclet File:: Setting the file to debug
20555* Sparclet Connection:: Connecting to Sparclet
20556* Sparclet Download:: Sparclet download
20557* Sparclet Execution:: Running and debugging
104c1213
JM
20558@end menu
20559
8e04817f 20560@node Sparclet File
79a6e687 20561@subsubsection Setting File to Debug
104c1213 20562
8e04817f 20563The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 20564
474c8240 20565@smallexample
8e04817f 20566(gdbslet) file prog
474c8240 20567@end smallexample
104c1213 20568
8e04817f
AC
20569@need 1000
20570@value{GDBN} then attempts to read the symbol table of @file{prog}.
20571@value{GDBN} locates
20572the file by searching the directories listed in the command search
20573path.
12c27660 20574If the file was compiled with debug information (option @samp{-g}), source
8e04817f
AC
20575files will be searched as well.
20576@value{GDBN} locates
20577the source files by searching the directories listed in the directory search
79a6e687 20578path (@pxref{Environment, ,Your Program's Environment}).
8e04817f
AC
20579If it fails
20580to find a file, it displays a message such as:
104c1213 20581
474c8240 20582@smallexample
8e04817f 20583prog: No such file or directory.
474c8240 20584@end smallexample
104c1213 20585
8e04817f
AC
20586When this happens, add the appropriate directories to the search paths with
20587the @value{GDBN} commands @code{path} and @code{dir}, and execute the
20588@code{target} command again.
104c1213 20589
8e04817f
AC
20590@node Sparclet Connection
20591@subsubsection Connecting to Sparclet
104c1213 20592
8e04817f
AC
20593The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
20594To connect to a target on serial port ``@code{ttya}'', type:
104c1213 20595
474c8240 20596@smallexample
8e04817f
AC
20597(gdbslet) target sparclet /dev/ttya
20598Remote target sparclet connected to /dev/ttya
20599main () at ../prog.c:3
474c8240 20600@end smallexample
104c1213 20601
8e04817f
AC
20602@need 750
20603@value{GDBN} displays messages like these:
104c1213 20604
474c8240 20605@smallexample
8e04817f 20606Connected to ttya.
474c8240 20607@end smallexample
104c1213 20608
8e04817f 20609@node Sparclet Download
79a6e687 20610@subsubsection Sparclet Download
104c1213 20611
8e04817f
AC
20612@cindex download to Sparclet
20613Once connected to the Sparclet target,
20614you can use the @value{GDBN}
20615@code{load} command to download the file from the host to the target.
20616The file name and load offset should be given as arguments to the @code{load}
20617command.
20618Since the file format is aout, the program must be loaded to the starting
20619address. You can use @code{objdump} to find out what this value is. The load
20620offset is an offset which is added to the VMA (virtual memory address)
20621of each of the file's sections.
20622For instance, if the program
20623@file{prog} was linked to text address 0x1201000, with data at 0x12010160
20624and bss at 0x12010170, in @value{GDBN}, type:
104c1213 20625
474c8240 20626@smallexample
8e04817f
AC
20627(gdbslet) load prog 0x12010000
20628Loading section .text, size 0xdb0 vma 0x12010000
474c8240 20629@end smallexample
104c1213 20630
8e04817f
AC
20631If the code is loaded at a different address then what the program was linked
20632to, you may need to use the @code{section} and @code{add-symbol-file} commands
20633to tell @value{GDBN} where to map the symbol table.
20634
20635@node Sparclet Execution
79a6e687 20636@subsubsection Running and Debugging
8e04817f
AC
20637
20638@cindex running and debugging Sparclet programs
20639You can now begin debugging the task using @value{GDBN}'s execution control
20640commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
20641manual for the list of commands.
20642
474c8240 20643@smallexample
8e04817f
AC
20644(gdbslet) b main
20645Breakpoint 1 at 0x12010000: file prog.c, line 3.
20646(gdbslet) run
20647Starting program: prog
20648Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
206493 char *symarg = 0;
20650(gdbslet) step
206514 char *execarg = "hello!";
20652(gdbslet)
474c8240 20653@end smallexample
8e04817f
AC
20654
20655@node Sparclite
20656@subsection Fujitsu Sparclite
104c1213
JM
20657
20658@table @code
20659
8e04817f
AC
20660@kindex target sparclite
20661@item target sparclite @var{dev}
20662Fujitsu sparclite boards, used only for the purpose of loading.
20663You must use an additional command to debug the program.
20664For example: target remote @var{dev} using @value{GDBN} standard
20665remote protocol.
104c1213
JM
20666
20667@end table
20668
8e04817f
AC
20669@node Z8000
20670@subsection Zilog Z8000
104c1213 20671
8e04817f
AC
20672@cindex Z8000
20673@cindex simulator, Z8000
20674@cindex Zilog Z8000 simulator
104c1213 20675
8e04817f
AC
20676When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
20677a Z8000 simulator.
20678
20679For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
20680unsegmented variant of the Z8000 architecture) or the Z8001 (the
20681segmented variant). The simulator recognizes which architecture is
20682appropriate by inspecting the object code.
104c1213 20683
8e04817f
AC
20684@table @code
20685@item target sim @var{args}
20686@kindex sim
20687@kindex target sim@r{, with Z8000}
20688Debug programs on a simulated CPU. If the simulator supports setup
20689options, specify them via @var{args}.
104c1213
JM
20690@end table
20691
8e04817f
AC
20692@noindent
20693After specifying this target, you can debug programs for the simulated
20694CPU in the same style as programs for your host computer; use the
20695@code{file} command to load a new program image, the @code{run} command
20696to run your program, and so on.
20697
20698As well as making available all the usual machine registers
20699(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
20700additional items of information as specially named registers:
104c1213
JM
20701
20702@table @code
20703
8e04817f
AC
20704@item cycles
20705Counts clock-ticks in the simulator.
104c1213 20706
8e04817f
AC
20707@item insts
20708Counts instructions run in the simulator.
104c1213 20709
8e04817f
AC
20710@item time
20711Execution time in 60ths of a second.
104c1213 20712
8e04817f 20713@end table
104c1213 20714
8e04817f
AC
20715You can refer to these values in @value{GDBN} expressions with the usual
20716conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
20717conditional breakpoint that suspends only after at least 5000
20718simulated clock ticks.
104c1213 20719
a64548ea
EZ
20720@node AVR
20721@subsection Atmel AVR
20722@cindex AVR
20723
20724When configured for debugging the Atmel AVR, @value{GDBN} supports the
20725following AVR-specific commands:
20726
20727@table @code
20728@item info io_registers
20729@kindex info io_registers@r{, AVR}
20730@cindex I/O registers (Atmel AVR)
20731This command displays information about the AVR I/O registers. For
20732each register, @value{GDBN} prints its number and value.
20733@end table
20734
20735@node CRIS
20736@subsection CRIS
20737@cindex CRIS
20738
20739When configured for debugging CRIS, @value{GDBN} provides the
20740following CRIS-specific commands:
20741
20742@table @code
20743@item set cris-version @var{ver}
20744@cindex CRIS version
e22e55c9
OF
20745Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
20746The CRIS version affects register names and sizes. This command is useful in
20747case autodetection of the CRIS version fails.
a64548ea
EZ
20748
20749@item show cris-version
20750Show the current CRIS version.
20751
20752@item set cris-dwarf2-cfi
20753@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
20754Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
20755Change to @samp{off} when using @code{gcc-cris} whose version is below
20756@code{R59}.
a64548ea
EZ
20757
20758@item show cris-dwarf2-cfi
20759Show the current state of using DWARF-2 CFI.
e22e55c9
OF
20760
20761@item set cris-mode @var{mode}
20762@cindex CRIS mode
20763Set the current CRIS mode to @var{mode}. It should only be changed when
20764debugging in guru mode, in which case it should be set to
20765@samp{guru} (the default is @samp{normal}).
20766
20767@item show cris-mode
20768Show the current CRIS mode.
a64548ea
EZ
20769@end table
20770
20771@node Super-H
20772@subsection Renesas Super-H
20773@cindex Super-H
20774
20775For the Renesas Super-H processor, @value{GDBN} provides these
20776commands:
20777
20778@table @code
c055b101
CV
20779@item set sh calling-convention @var{convention}
20780@kindex set sh calling-convention
20781Set the calling-convention used when calling functions from @value{GDBN}.
20782Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
20783With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
20784convention. If the DWARF-2 information of the called function specifies
20785that the function follows the Renesas calling convention, the function
20786is called using the Renesas calling convention. If the calling convention
20787is set to @samp{renesas}, the Renesas calling convention is always used,
20788regardless of the DWARF-2 information. This can be used to override the
20789default of @samp{gcc} if debug information is missing, or the compiler
20790does not emit the DWARF-2 calling convention entry for a function.
20791
20792@item show sh calling-convention
20793@kindex show sh calling-convention
20794Show the current calling convention setting.
20795
a64548ea
EZ
20796@end table
20797
20798
8e04817f
AC
20799@node Architectures
20800@section Architectures
104c1213 20801
8e04817f
AC
20802This section describes characteristics of architectures that affect
20803all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 20804
8e04817f 20805@menu
430ed3f0 20806* AArch64::
9c16f35a 20807* i386::
8e04817f
AC
20808* Alpha::
20809* MIPS::
a64548ea 20810* HPPA:: HP PA architecture
23d964e7 20811* SPU:: Cell Broadband Engine SPU architecture
4acd40f3 20812* PowerPC::
8e04817f 20813@end menu
104c1213 20814
430ed3f0
MS
20815@node AArch64
20816@subsection AArch64
20817@cindex AArch64 support
20818
20819When @value{GDBN} is debugging the AArch64 architecture, it provides the
20820following special commands:
20821
20822@table @code
20823@item set debug aarch64
20824@kindex set debug aarch64
20825This command determines whether AArch64 architecture-specific debugging
20826messages are to be displayed.
20827
20828@item show debug aarch64
20829Show whether AArch64 debugging messages are displayed.
20830
20831@end table
20832
9c16f35a 20833@node i386
db2e3e2e 20834@subsection x86 Architecture-specific Issues
9c16f35a
EZ
20835
20836@table @code
20837@item set struct-convention @var{mode}
20838@kindex set struct-convention
20839@cindex struct return convention
20840@cindex struct/union returned in registers
20841Set the convention used by the inferior to return @code{struct}s and
20842@code{union}s from functions to @var{mode}. Possible values of
20843@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
20844default). @code{"default"} or @code{"pcc"} means that @code{struct}s
20845are returned on the stack, while @code{"reg"} means that a
20846@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
20847be returned in a register.
20848
20849@item show struct-convention
20850@kindex show struct-convention
20851Show the current setting of the convention to return @code{struct}s
20852from functions.
20853@end table
20854
8e04817f
AC
20855@node Alpha
20856@subsection Alpha
104c1213 20857
8e04817f 20858See the following section.
104c1213 20859
8e04817f 20860@node MIPS
eb17f351 20861@subsection @acronym{MIPS}
104c1213 20862
8e04817f 20863@cindex stack on Alpha
eb17f351 20864@cindex stack on @acronym{MIPS}
8e04817f 20865@cindex Alpha stack
eb17f351
EZ
20866@cindex @acronym{MIPS} stack
20867Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
8e04817f
AC
20868sometimes requires @value{GDBN} to search backward in the object code to
20869find the beginning of a function.
104c1213 20870
eb17f351 20871@cindex response time, @acronym{MIPS} debugging
8e04817f
AC
20872To improve response time (especially for embedded applications, where
20873@value{GDBN} may be restricted to a slow serial line for this search)
20874you may want to limit the size of this search, using one of these
20875commands:
104c1213 20876
8e04817f 20877@table @code
eb17f351 20878@cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
8e04817f
AC
20879@item set heuristic-fence-post @var{limit}
20880Restrict @value{GDBN} to examining at most @var{limit} bytes in its
20881search for the beginning of a function. A value of @var{0} (the
20882default) means there is no limit. However, except for @var{0}, the
20883larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
20884and therefore the longer it takes to run. You should only need to use
20885this command when debugging a stripped executable.
104c1213 20886
8e04817f
AC
20887@item show heuristic-fence-post
20888Display the current limit.
20889@end table
104c1213
JM
20890
20891@noindent
8e04817f 20892These commands are available @emph{only} when @value{GDBN} is configured
eb17f351 20893for debugging programs on Alpha or @acronym{MIPS} processors.
104c1213 20894
eb17f351 20895Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
a64548ea
EZ
20896programs:
20897
20898@table @code
a64548ea
EZ
20899@item set mips abi @var{arg}
20900@kindex set mips abi
eb17f351
EZ
20901@cindex set ABI for @acronym{MIPS}
20902Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
a64548ea
EZ
20903values of @var{arg} are:
20904
20905@table @samp
20906@item auto
20907The default ABI associated with the current binary (this is the
20908default).
20909@item o32
20910@item o64
20911@item n32
20912@item n64
20913@item eabi32
20914@item eabi64
a64548ea
EZ
20915@end table
20916
20917@item show mips abi
20918@kindex show mips abi
eb17f351 20919Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
a64548ea 20920
4cc0665f
MR
20921@item set mips compression @var{arg}
20922@kindex set mips compression
20923@cindex code compression, @acronym{MIPS}
20924Tell @value{GDBN} which @acronym{MIPS} compressed
20925@acronym{ISA, Instruction Set Architecture} encoding is used by the
20926inferior. @value{GDBN} uses this for code disassembly and other
20927internal interpretation purposes. This setting is only referred to
20928when no executable has been associated with the debugging session or
20929the executable does not provide information about the encoding it uses.
20930Otherwise this setting is automatically updated from information
20931provided by the executable.
20932
20933Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
20934The default compressed @acronym{ISA} encoding is @samp{mips16}, as
20935executables containing @acronym{MIPS16} code frequently are not
20936identified as such.
20937
20938This setting is ``sticky''; that is, it retains its value across
20939debugging sessions until reset either explicitly with this command or
20940implicitly from an executable.
20941
20942The compiler and/or assembler typically add symbol table annotations to
20943identify functions compiled for the @acronym{MIPS16} or
20944@acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
20945are present, @value{GDBN} uses them in preference to the global
20946compressed @acronym{ISA} encoding setting.
20947
20948@item show mips compression
20949@kindex show mips compression
20950Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
20951@value{GDBN} to debug the inferior.
20952
a64548ea
EZ
20953@item set mipsfpu
20954@itemx show mipsfpu
20955@xref{MIPS Embedded, set mipsfpu}.
20956
20957@item set mips mask-address @var{arg}
20958@kindex set mips mask-address
eb17f351 20959@cindex @acronym{MIPS} addresses, masking
a64548ea 20960This command determines whether the most-significant 32 bits of 64-bit
eb17f351 20961@acronym{MIPS} addresses are masked off. The argument @var{arg} can be
a64548ea
EZ
20962@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
20963setting, which lets @value{GDBN} determine the correct value.
20964
20965@item show mips mask-address
20966@kindex show mips mask-address
eb17f351 20967Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
a64548ea
EZ
20968not.
20969
20970@item set remote-mips64-transfers-32bit-regs
20971@kindex set remote-mips64-transfers-32bit-regs
eb17f351
EZ
20972This command controls compatibility with 64-bit @acronym{MIPS} targets that
20973transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
a64548ea
EZ
20974that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
20975and 64 bits for other registers, set this option to @samp{on}.
20976
20977@item show remote-mips64-transfers-32bit-regs
20978@kindex show remote-mips64-transfers-32bit-regs
eb17f351 20979Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
a64548ea
EZ
20980
20981@item set debug mips
20982@kindex set debug mips
eb17f351 20983This command turns on and off debugging messages for the @acronym{MIPS}-specific
a64548ea
EZ
20984target code in @value{GDBN}.
20985
20986@item show debug mips
20987@kindex show debug mips
eb17f351 20988Show the current setting of @acronym{MIPS} debugging messages.
a64548ea
EZ
20989@end table
20990
20991
20992@node HPPA
20993@subsection HPPA
20994@cindex HPPA support
20995
d3e8051b 20996When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
20997following special commands:
20998
20999@table @code
21000@item set debug hppa
21001@kindex set debug hppa
db2e3e2e 21002This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
21003messages are to be displayed.
21004
21005@item show debug hppa
21006Show whether HPPA debugging messages are displayed.
21007
21008@item maint print unwind @var{address}
21009@kindex maint print unwind@r{, HPPA}
21010This command displays the contents of the unwind table entry at the
21011given @var{address}.
21012
21013@end table
21014
104c1213 21015
23d964e7
UW
21016@node SPU
21017@subsection Cell Broadband Engine SPU architecture
21018@cindex Cell Broadband Engine
21019@cindex SPU
21020
21021When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
21022it provides the following special commands:
21023
21024@table @code
21025@item info spu event
21026@kindex info spu
21027Display SPU event facility status. Shows current event mask
21028and pending event status.
21029
21030@item info spu signal
21031Display SPU signal notification facility status. Shows pending
21032signal-control word and signal notification mode of both signal
21033notification channels.
21034
21035@item info spu mailbox
21036Display SPU mailbox facility status. Shows all pending entries,
21037in order of processing, in each of the SPU Write Outbound,
21038SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
21039
21040@item info spu dma
21041Display MFC DMA status. Shows all pending commands in the MFC
21042DMA queue. For each entry, opcode, tag, class IDs, effective
21043and local store addresses and transfer size are shown.
21044
21045@item info spu proxydma
21046Display MFC Proxy-DMA status. Shows all pending commands in the MFC
21047Proxy-DMA queue. For each entry, opcode, tag, class IDs, effective
21048and local store addresses and transfer size are shown.
21049
21050@end table
21051
3285f3fe
UW
21052When @value{GDBN} is debugging a combined PowerPC/SPU application
21053on the Cell Broadband Engine, it provides in addition the following
21054special commands:
21055
21056@table @code
21057@item set spu stop-on-load @var{arg}
21058@kindex set spu
21059Set whether to stop for new SPE threads. When set to @code{on}, @value{GDBN}
21060will give control to the user when a new SPE thread enters its @code{main}
21061function. The default is @code{off}.
21062
21063@item show spu stop-on-load
21064@kindex show spu
21065Show whether to stop for new SPE threads.
21066
ff1a52c6
UW
21067@item set spu auto-flush-cache @var{arg}
21068Set whether to automatically flush the software-managed cache. When set to
21069@code{on}, @value{GDBN} will automatically cause the SPE software-managed
21070cache to be flushed whenever SPE execution stops. This provides a consistent
21071view of PowerPC memory that is accessed via the cache. If an application
21072does not use the software-managed cache, this option has no effect.
21073
21074@item show spu auto-flush-cache
21075Show whether to automatically flush the software-managed cache.
21076
3285f3fe
UW
21077@end table
21078
4acd40f3
TJB
21079@node PowerPC
21080@subsection PowerPC
21081@cindex PowerPC architecture
21082
21083When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
21084pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
21085numbers stored in the floating point registers. These values must be stored
21086in two consecutive registers, always starting at an even register like
21087@code{f0} or @code{f2}.
21088
21089The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
21090by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
21091@code{f2} and @code{f3} for @code{$dl1} and so on.
21092
aeac0ff9 21093For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
677c5bb1
LM
21094wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
21095
23d964e7 21096
8e04817f
AC
21097@node Controlling GDB
21098@chapter Controlling @value{GDBN}
21099
21100You can alter the way @value{GDBN} interacts with you by using the
21101@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 21102data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
21103described here.
21104
21105@menu
21106* Prompt:: Prompt
21107* Editing:: Command editing
d620b259 21108* Command History:: Command history
8e04817f
AC
21109* Screen Size:: Screen size
21110* Numbers:: Numbers
1e698235 21111* ABI:: Configuring the current ABI
bf88dd68 21112* Auto-loading:: Automatically loading associated files
8e04817f
AC
21113* Messages/Warnings:: Optional warnings and messages
21114* Debugging Output:: Optional messages about internal happenings
14fb1bac 21115* Other Misc Settings:: Other Miscellaneous Settings
8e04817f
AC
21116@end menu
21117
21118@node Prompt
21119@section Prompt
104c1213 21120
8e04817f 21121@cindex prompt
104c1213 21122
8e04817f
AC
21123@value{GDBN} indicates its readiness to read a command by printing a string
21124called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
21125can change the prompt string with the @code{set prompt} command. For
21126instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
21127the prompt in one of the @value{GDBN} sessions so that you can always tell
21128which one you are talking to.
104c1213 21129
8e04817f
AC
21130@emph{Note:} @code{set prompt} does not add a space for you after the
21131prompt you set. This allows you to set a prompt which ends in a space
21132or a prompt that does not.
104c1213 21133
8e04817f
AC
21134@table @code
21135@kindex set prompt
21136@item set prompt @var{newprompt}
21137Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 21138
8e04817f
AC
21139@kindex show prompt
21140@item show prompt
21141Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
21142@end table
21143
fa3a4f15
PM
21144Versions of @value{GDBN} that ship with Python scripting enabled have
21145prompt extensions. The commands for interacting with these extensions
21146are:
21147
21148@table @code
21149@kindex set extended-prompt
21150@item set extended-prompt @var{prompt}
21151Set an extended prompt that allows for substitutions.
21152@xref{gdb.prompt}, for a list of escape sequences that can be used for
21153substitution. Any escape sequences specified as part of the prompt
21154string are replaced with the corresponding strings each time the prompt
21155is displayed.
21156
21157For example:
21158
21159@smallexample
21160set extended-prompt Current working directory: \w (gdb)
21161@end smallexample
21162
21163Note that when an extended-prompt is set, it takes control of the
21164@var{prompt_hook} hook. @xref{prompt_hook}, for further information.
21165
21166@kindex show extended-prompt
21167@item show extended-prompt
21168Prints the extended prompt. Any escape sequences specified as part of
21169the prompt string with @code{set extended-prompt}, are replaced with the
21170corresponding strings each time the prompt is displayed.
21171@end table
21172
8e04817f 21173@node Editing
79a6e687 21174@section Command Editing
8e04817f
AC
21175@cindex readline
21176@cindex command line editing
104c1213 21177
703663ab 21178@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
21179@sc{gnu} library provides consistent behavior for programs which provide a
21180command line interface to the user. Advantages are @sc{gnu} Emacs-style
21181or @dfn{vi}-style inline editing of commands, @code{csh}-like history
21182substitution, and a storage and recall of command history across
21183debugging sessions.
104c1213 21184
8e04817f
AC
21185You may control the behavior of command line editing in @value{GDBN} with the
21186command @code{set}.
104c1213 21187
8e04817f
AC
21188@table @code
21189@kindex set editing
21190@cindex editing
21191@item set editing
21192@itemx set editing on
21193Enable command line editing (enabled by default).
104c1213 21194
8e04817f
AC
21195@item set editing off
21196Disable command line editing.
104c1213 21197
8e04817f
AC
21198@kindex show editing
21199@item show editing
21200Show whether command line editing is enabled.
104c1213
JM
21201@end table
21202
39037522
TT
21203@ifset SYSTEM_READLINE
21204@xref{Command Line Editing, , , rluserman, GNU Readline Library},
21205@end ifset
21206@ifclear SYSTEM_READLINE
21207@xref{Command Line Editing},
21208@end ifclear
21209for more details about the Readline
703663ab
EZ
21210interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
21211encouraged to read that chapter.
21212
d620b259 21213@node Command History
79a6e687 21214@section Command History
703663ab 21215@cindex command history
8e04817f
AC
21216
21217@value{GDBN} can keep track of the commands you type during your
21218debugging sessions, so that you can be certain of precisely what
21219happened. Use these commands to manage the @value{GDBN} command
21220history facility.
104c1213 21221
703663ab 21222@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
39037522
TT
21223package, to provide the history facility.
21224@ifset SYSTEM_READLINE
21225@xref{Using History Interactively, , , history, GNU History Library},
21226@end ifset
21227@ifclear SYSTEM_READLINE
21228@xref{Using History Interactively},
21229@end ifclear
21230for the detailed description of the History library.
703663ab 21231
d620b259 21232To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
21233the state which is seen by users, prefix it with @samp{server }
21234(@pxref{Server Prefix}). This
d620b259
NR
21235means that this command will not affect the command history, nor will it
21236affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
21237pressed on a line by itself.
21238
21239@cindex @code{server}, command prefix
21240The server prefix does not affect the recording of values into the value
21241history; to print a value without recording it into the value history,
21242use the @code{output} command instead of the @code{print} command.
21243
703663ab
EZ
21244Here is the description of @value{GDBN} commands related to command
21245history.
21246
104c1213 21247@table @code
8e04817f
AC
21248@cindex history substitution
21249@cindex history file
21250@kindex set history filename
4644b6e3 21251@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
21252@item set history filename @var{fname}
21253Set the name of the @value{GDBN} command history file to @var{fname}.
21254This is the file where @value{GDBN} reads an initial command history
21255list, and where it writes the command history from this session when it
21256exits. You can access this list through history expansion or through
21257the history command editing characters listed below. This file defaults
21258to the value of the environment variable @code{GDBHISTFILE}, or to
21259@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
21260is not set.
104c1213 21261
9c16f35a
EZ
21262@cindex save command history
21263@kindex set history save
8e04817f
AC
21264@item set history save
21265@itemx set history save on
21266Record command history in a file, whose name may be specified with the
21267@code{set history filename} command. By default, this option is disabled.
104c1213 21268
8e04817f
AC
21269@item set history save off
21270Stop recording command history in a file.
104c1213 21271
8e04817f 21272@cindex history size
9c16f35a 21273@kindex set history size
6fc08d32 21274@cindex @env{HISTSIZE}, environment variable
8e04817f 21275@item set history size @var{size}
f81d1120 21276@itemx set history size unlimited
8e04817f
AC
21277Set the number of commands which @value{GDBN} keeps in its history list.
21278This defaults to the value of the environment variable
f81d1120
PA
21279@code{HISTSIZE}, or to 256 if this variable is not set. If @var{size}
21280is @code{unlimited}, the number of commands @value{GDBN} keeps in the
21281history list is unlimited.
104c1213
JM
21282@end table
21283
8e04817f 21284History expansion assigns special meaning to the character @kbd{!}.
39037522
TT
21285@ifset SYSTEM_READLINE
21286@xref{Event Designators, , , history, GNU History Library},
21287@end ifset
21288@ifclear SYSTEM_READLINE
21289@xref{Event Designators},
21290@end ifclear
21291for more details.
8e04817f 21292
703663ab 21293@cindex history expansion, turn on/off
8e04817f
AC
21294Since @kbd{!} is also the logical not operator in C, history expansion
21295is off by default. If you decide to enable history expansion with the
21296@code{set history expansion on} command, you may sometimes need to
21297follow @kbd{!} (when it is used as logical not, in an expression) with
21298a space or a tab to prevent it from being expanded. The readline
21299history facilities do not attempt substitution on the strings
21300@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
21301
21302The commands to control history expansion are:
104c1213
JM
21303
21304@table @code
8e04817f
AC
21305@item set history expansion on
21306@itemx set history expansion
703663ab 21307@kindex set history expansion
8e04817f 21308Enable history expansion. History expansion is off by default.
104c1213 21309
8e04817f
AC
21310@item set history expansion off
21311Disable history expansion.
104c1213 21312
8e04817f
AC
21313@c @group
21314@kindex show history
21315@item show history
21316@itemx show history filename
21317@itemx show history save
21318@itemx show history size
21319@itemx show history expansion
21320These commands display the state of the @value{GDBN} history parameters.
21321@code{show history} by itself displays all four states.
21322@c @end group
21323@end table
21324
21325@table @code
9c16f35a
EZ
21326@kindex show commands
21327@cindex show last commands
21328@cindex display command history
8e04817f
AC
21329@item show commands
21330Display the last ten commands in the command history.
104c1213 21331
8e04817f
AC
21332@item show commands @var{n}
21333Print ten commands centered on command number @var{n}.
21334
21335@item show commands +
21336Print ten commands just after the commands last printed.
104c1213
JM
21337@end table
21338
8e04817f 21339@node Screen Size
79a6e687 21340@section Screen Size
8e04817f
AC
21341@cindex size of screen
21342@cindex pauses in output
104c1213 21343
8e04817f
AC
21344Certain commands to @value{GDBN} may produce large amounts of
21345information output to the screen. To help you read all of it,
21346@value{GDBN} pauses and asks you for input at the end of each page of
21347output. Type @key{RET} when you want to continue the output, or @kbd{q}
21348to discard the remaining output. Also, the screen width setting
21349determines when to wrap lines of output. Depending on what is being
21350printed, @value{GDBN} tries to break the line at a readable place,
21351rather than simply letting it overflow onto the following line.
21352
21353Normally @value{GDBN} knows the size of the screen from the terminal
21354driver software. For example, on Unix @value{GDBN} uses the termcap data base
21355together with the value of the @code{TERM} environment variable and the
21356@code{stty rows} and @code{stty cols} settings. If this is not correct,
21357you can override it with the @code{set height} and @code{set
21358width} commands:
21359
21360@table @code
21361@kindex set height
21362@kindex set width
21363@kindex show width
21364@kindex show height
21365@item set height @var{lpp}
f81d1120 21366@itemx set height unlimited
8e04817f
AC
21367@itemx show height
21368@itemx set width @var{cpl}
f81d1120 21369@itemx set width unlimited
8e04817f
AC
21370@itemx show width
21371These @code{set} commands specify a screen height of @var{lpp} lines and
21372a screen width of @var{cpl} characters. The associated @code{show}
21373commands display the current settings.
104c1213 21374
f81d1120
PA
21375If you specify a height of either @code{unlimited} or zero lines,
21376@value{GDBN} does not pause during output no matter how long the
21377output is. This is useful if output is to a file or to an editor
21378buffer.
104c1213 21379
f81d1120
PA
21380Likewise, you can specify @samp{set width unlimited} or @samp{set
21381width 0} to prevent @value{GDBN} from wrapping its output.
9c16f35a
EZ
21382
21383@item set pagination on
21384@itemx set pagination off
21385@kindex set pagination
21386Turn the output pagination on or off; the default is on. Turning
f81d1120 21387pagination off is the alternative to @code{set height unlimited}. Note that
7c953934
TT
21388running @value{GDBN} with the @option{--batch} option (@pxref{Mode
21389Options, -batch}) also automatically disables pagination.
9c16f35a
EZ
21390
21391@item show pagination
21392@kindex show pagination
21393Show the current pagination mode.
104c1213
JM
21394@end table
21395
8e04817f
AC
21396@node Numbers
21397@section Numbers
21398@cindex number representation
21399@cindex entering numbers
104c1213 21400
8e04817f
AC
21401You can always enter numbers in octal, decimal, or hexadecimal in
21402@value{GDBN} by the usual conventions: octal numbers begin with
21403@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
21404begin with @samp{0x}. Numbers that neither begin with @samp{0} or
21405@samp{0x}, nor end with a @samp{.} are, by default, entered in base
2140610; likewise, the default display for numbers---when no particular
21407format is specified---is base 10. You can change the default base for
21408both input and output with the commands described below.
104c1213 21409
8e04817f
AC
21410@table @code
21411@kindex set input-radix
21412@item set input-radix @var{base}
21413Set the default base for numeric input. Supported choices
21414for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 21415specified either unambiguously or using the current input radix; for
8e04817f 21416example, any of
104c1213 21417
8e04817f 21418@smallexample
9c16f35a
EZ
21419set input-radix 012
21420set input-radix 10.
21421set input-radix 0xa
8e04817f 21422@end smallexample
104c1213 21423
8e04817f 21424@noindent
9c16f35a 21425sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
21426leaves the input radix unchanged, no matter what it was, since
21427@samp{10}, being without any leading or trailing signs of its base, is
21428interpreted in the current radix. Thus, if the current radix is 16,
21429@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
21430change the radix.
104c1213 21431
8e04817f
AC
21432@kindex set output-radix
21433@item set output-radix @var{base}
21434Set the default base for numeric display. Supported choices
21435for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 21436specified either unambiguously or using the current input radix.
104c1213 21437
8e04817f
AC
21438@kindex show input-radix
21439@item show input-radix
21440Display the current default base for numeric input.
104c1213 21441
8e04817f
AC
21442@kindex show output-radix
21443@item show output-radix
21444Display the current default base for numeric display.
9c16f35a
EZ
21445
21446@item set radix @r{[}@var{base}@r{]}
21447@itemx show radix
21448@kindex set radix
21449@kindex show radix
21450These commands set and show the default base for both input and output
21451of numbers. @code{set radix} sets the radix of input and output to
21452the same base; without an argument, it resets the radix back to its
21453default value of 10.
21454
8e04817f 21455@end table
104c1213 21456
1e698235 21457@node ABI
79a6e687 21458@section Configuring the Current ABI
1e698235
DJ
21459
21460@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
21461application automatically. However, sometimes you need to override its
21462conclusions. Use these commands to manage @value{GDBN}'s view of the
21463current ABI.
21464
98b45e30
DJ
21465@cindex OS ABI
21466@kindex set osabi
b4e9345d 21467@kindex show osabi
430ed3f0 21468@cindex Newlib OS ABI and its influence on the longjmp handling
98b45e30
DJ
21469
21470One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 21471system targets, either via remote debugging or native emulation.
98b45e30
DJ
21472@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
21473but you can override its conclusion using the @code{set osabi} command.
21474One example where this is useful is in debugging of binaries which use
21475an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
21476not have the same identifying marks that the standard C library for your
21477platform provides.
21478
430ed3f0
MS
21479When @value{GDBN} is debugging the AArch64 architecture, it provides a
21480``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
21481@code{longjmp} when debugging binaries that use the @sc{newlib} C library.
21482The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
21483
98b45e30
DJ
21484@table @code
21485@item show osabi
21486Show the OS ABI currently in use.
21487
21488@item set osabi
21489With no argument, show the list of registered available OS ABI's.
21490
21491@item set osabi @var{abi}
21492Set the current OS ABI to @var{abi}.
21493@end table
21494
1e698235 21495@cindex float promotion
1e698235
DJ
21496
21497Generally, the way that an argument of type @code{float} is passed to a
21498function depends on whether the function is prototyped. For a prototyped
21499(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
21500according to the architecture's convention for @code{float}. For unprototyped
21501(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
21502@code{double} and then passed.
21503
21504Unfortunately, some forms of debug information do not reliably indicate whether
21505a function is prototyped. If @value{GDBN} calls a function that is not marked
21506as prototyped, it consults @kbd{set coerce-float-to-double}.
21507
21508@table @code
a8f24a35 21509@kindex set coerce-float-to-double
1e698235
DJ
21510@item set coerce-float-to-double
21511@itemx set coerce-float-to-double on
21512Arguments of type @code{float} will be promoted to @code{double} when passed
21513to an unprototyped function. This is the default setting.
21514
21515@item set coerce-float-to-double off
21516Arguments of type @code{float} will be passed directly to unprototyped
21517functions.
9c16f35a
EZ
21518
21519@kindex show coerce-float-to-double
21520@item show coerce-float-to-double
21521Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
21522@end table
21523
f1212245
DJ
21524@kindex set cp-abi
21525@kindex show cp-abi
21526@value{GDBN} needs to know the ABI used for your program's C@t{++}
21527objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
21528used to build your application. @value{GDBN} only fully supports
21529programs with a single C@t{++} ABI; if your program contains code using
21530multiple C@t{++} ABI's or if @value{GDBN} can not identify your
21531program's ABI correctly, you can tell @value{GDBN} which ABI to use.
21532Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
21533before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
21534``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
21535use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
21536``auto''.
21537
21538@table @code
21539@item show cp-abi
21540Show the C@t{++} ABI currently in use.
21541
21542@item set cp-abi
21543With no argument, show the list of supported C@t{++} ABI's.
21544
21545@item set cp-abi @var{abi}
21546@itemx set cp-abi auto
21547Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
21548@end table
21549
bf88dd68
JK
21550@node Auto-loading
21551@section Automatically loading associated files
21552@cindex auto-loading
21553
21554@value{GDBN} sometimes reads files with commands and settings automatically,
21555without being explicitly told so by the user. We call this feature
21556@dfn{auto-loading}. While auto-loading is useful for automatically adapting
21557@value{GDBN} to the needs of your project, it can sometimes produce unexpected
21558results or introduce security risks (e.g., if the file comes from untrusted
21559sources).
21560
c1668e4e
JK
21561Note that loading of these associated files (including the local @file{.gdbinit}
21562file) requires accordingly configured @code{auto-load safe-path}
21563(@pxref{Auto-loading safe path}).
21564
bf88dd68
JK
21565For these reasons, @value{GDBN} includes commands and options to let you
21566control when to auto-load files and which files should be auto-loaded.
21567
21568@table @code
21569@anchor{set auto-load off}
21570@kindex set auto-load off
21571@item set auto-load off
21572Globally disable loading of all auto-loaded files.
21573You may want to use this command with the @samp{-iex} option
21574(@pxref{Option -init-eval-command}) such as:
21575@smallexample
21576$ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
21577@end smallexample
21578
21579Be aware that system init file (@pxref{System-wide configuration})
21580and init files from your home directory (@pxref{Home Directory Init File})
21581still get read (as they come from generally trusted directories).
21582To prevent @value{GDBN} from auto-loading even those init files, use the
21583@option{-nx} option (@pxref{Mode Options}), in addition to
21584@code{set auto-load no}.
21585
21586@anchor{show auto-load}
21587@kindex show auto-load
21588@item show auto-load
21589Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
21590or disabled.
21591
21592@smallexample
21593(gdb) show auto-load
21594gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
21595libthread-db: Auto-loading of inferior specific libthread_db is on.
1ccacbcd
JK
21596local-gdbinit: Auto-loading of .gdbinit script from current directory
21597 is on.
bf88dd68 21598python-scripts: Auto-loading of Python scripts is on.
bccbefd2 21599safe-path: List of directories from which it is safe to auto-load files
1564a261 21600 is $debugdir:$datadir/auto-load.
7349ff92 21601scripts-directory: List of directories from which to load auto-loaded scripts
1564a261 21602 is $debugdir:$datadir/auto-load.
bf88dd68
JK
21603@end smallexample
21604
21605@anchor{info auto-load}
21606@kindex info auto-load
21607@item info auto-load
21608Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
21609not.
21610
21611@smallexample
21612(gdb) info auto-load
21613gdb-scripts:
21614Loaded Script
21615Yes /home/user/gdb/gdb-gdb.gdb
21616libthread-db: No auto-loaded libthread-db.
1ccacbcd
JK
21617local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
21618 loaded.
bf88dd68
JK
21619python-scripts:
21620Loaded Script
21621Yes /home/user/gdb/gdb-gdb.py
21622@end smallexample
21623@end table
21624
21625These are various kinds of files @value{GDBN} can automatically load:
21626
21627@itemize @bullet
21628@item
21629@xref{objfile-gdb.py file}, controlled by @ref{set auto-load python-scripts}.
21630@item
21631@xref{objfile-gdb.gdb file}, controlled by @ref{set auto-load gdb-scripts}.
21632@item
21633@xref{dotdebug_gdb_scripts section},
21634controlled by @ref{set auto-load python-scripts}.
21635@item
21636@xref{Init File in the Current Directory},
21637controlled by @ref{set auto-load local-gdbinit}.
21638@item
21639@xref{libthread_db.so.1 file}, controlled by @ref{set auto-load libthread-db}.
21640@end itemize
21641
21642These are @value{GDBN} control commands for the auto-loading:
21643
21644@multitable @columnfractions .5 .5
21645@item @xref{set auto-load off}.
21646@tab Disable auto-loading globally.
21647@item @xref{show auto-load}.
21648@tab Show setting of all kinds of files.
21649@item @xref{info auto-load}.
21650@tab Show state of all kinds of files.
21651@item @xref{set auto-load gdb-scripts}.
21652@tab Control for @value{GDBN} command scripts.
21653@item @xref{show auto-load gdb-scripts}.
21654@tab Show setting of @value{GDBN} command scripts.
21655@item @xref{info auto-load gdb-scripts}.
21656@tab Show state of @value{GDBN} command scripts.
21657@item @xref{set auto-load python-scripts}.
21658@tab Control for @value{GDBN} Python scripts.
21659@item @xref{show auto-load python-scripts}.
21660@tab Show setting of @value{GDBN} Python scripts.
21661@item @xref{info auto-load python-scripts}.
21662@tab Show state of @value{GDBN} Python scripts.
7349ff92
JK
21663@item @xref{set auto-load scripts-directory}.
21664@tab Control for @value{GDBN} auto-loaded scripts location.
21665@item @xref{show auto-load scripts-directory}.
21666@tab Show @value{GDBN} auto-loaded scripts location.
bf88dd68
JK
21667@item @xref{set auto-load local-gdbinit}.
21668@tab Control for init file in the current directory.
21669@item @xref{show auto-load local-gdbinit}.
21670@tab Show setting of init file in the current directory.
21671@item @xref{info auto-load local-gdbinit}.
21672@tab Show state of init file in the current directory.
21673@item @xref{set auto-load libthread-db}.
21674@tab Control for thread debugging library.
21675@item @xref{show auto-load libthread-db}.
21676@tab Show setting of thread debugging library.
21677@item @xref{info auto-load libthread-db}.
21678@tab Show state of thread debugging library.
bccbefd2
JK
21679@item @xref{set auto-load safe-path}.
21680@tab Control directories trusted for automatic loading.
21681@item @xref{show auto-load safe-path}.
21682@tab Show directories trusted for automatic loading.
21683@item @xref{add-auto-load-safe-path}.
21684@tab Add directory trusted for automatic loading.
bf88dd68
JK
21685@end multitable
21686
21687@menu
21688* Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
21689* libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
21690* objfile-gdb.gdb file:: @samp{set/show/info auto-load gdb-script}
bccbefd2 21691* Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
4dc84fd1 21692* Auto-loading verbose mode:: @samp{set/show debug auto-load}
bf88dd68
JK
21693@xref{Python Auto-loading}.
21694@end menu
21695
21696@node Init File in the Current Directory
21697@subsection Automatically loading init file in the current directory
21698@cindex auto-loading init file in the current directory
21699
21700By default, @value{GDBN} reads and executes the canned sequences of commands
21701from init file (if any) in the current working directory,
21702see @ref{Init File in the Current Directory during Startup}.
21703
c1668e4e
JK
21704Note that loading of this local @file{.gdbinit} file also requires accordingly
21705configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
21706
bf88dd68
JK
21707@table @code
21708@anchor{set auto-load local-gdbinit}
21709@kindex set auto-load local-gdbinit
21710@item set auto-load local-gdbinit [on|off]
21711Enable or disable the auto-loading of canned sequences of commands
21712(@pxref{Sequences}) found in init file in the current directory.
21713
21714@anchor{show auto-load local-gdbinit}
21715@kindex show auto-load local-gdbinit
21716@item show auto-load local-gdbinit
21717Show whether auto-loading of canned sequences of commands from init file in the
21718current directory is enabled or disabled.
21719
21720@anchor{info auto-load local-gdbinit}
21721@kindex info auto-load local-gdbinit
21722@item info auto-load local-gdbinit
21723Print whether canned sequences of commands from init file in the
21724current directory have been auto-loaded.
21725@end table
21726
21727@node libthread_db.so.1 file
21728@subsection Automatically loading thread debugging library
21729@cindex auto-loading libthread_db.so.1
21730
21731This feature is currently present only on @sc{gnu}/Linux native hosts.
21732
21733@value{GDBN} reads in some cases thread debugging library from places specific
21734to the inferior (@pxref{set libthread-db-search-path}).
21735
21736The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
21737without checking this @samp{set auto-load libthread-db} switch as system
21738libraries have to be trusted in general. In all other cases of
21739@samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
21740auto-load libthread-db} is enabled before trying to open such thread debugging
21741library.
21742
c1668e4e
JK
21743Note that loading of this debugging library also requires accordingly configured
21744@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
21745
bf88dd68
JK
21746@table @code
21747@anchor{set auto-load libthread-db}
21748@kindex set auto-load libthread-db
21749@item set auto-load libthread-db [on|off]
21750Enable or disable the auto-loading of inferior specific thread debugging library.
21751
21752@anchor{show auto-load libthread-db}
21753@kindex show auto-load libthread-db
21754@item show auto-load libthread-db
21755Show whether auto-loading of inferior specific thread debugging library is
21756enabled or disabled.
21757
21758@anchor{info auto-load libthread-db}
21759@kindex info auto-load libthread-db
21760@item info auto-load libthread-db
21761Print the list of all loaded inferior specific thread debugging libraries and
21762for each such library print list of inferior @var{pid}s using it.
21763@end table
21764
21765@node objfile-gdb.gdb file
21766@subsection The @file{@var{objfile}-gdb.gdb} file
21767@cindex auto-loading @file{@var{objfile}-gdb.gdb}
21768
21769@value{GDBN} tries to load an @file{@var{objfile}-gdb.gdb} file containing
21770canned sequences of commands (@pxref{Sequences}), as long as @samp{set
21771auto-load gdb-scripts} is set to @samp{on}.
21772
c1668e4e
JK
21773Note that loading of this script file also requires accordingly configured
21774@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
21775
bf88dd68
JK
21776For more background refer to the similar Python scripts auto-loading
21777description (@pxref{objfile-gdb.py file}).
21778
21779@table @code
21780@anchor{set auto-load gdb-scripts}
21781@kindex set auto-load gdb-scripts
21782@item set auto-load gdb-scripts [on|off]
21783Enable or disable the auto-loading of canned sequences of commands scripts.
21784
21785@anchor{show auto-load gdb-scripts}
21786@kindex show auto-load gdb-scripts
21787@item show auto-load gdb-scripts
21788Show whether auto-loading of canned sequences of commands scripts is enabled or
21789disabled.
21790
21791@anchor{info auto-load gdb-scripts}
21792@kindex info auto-load gdb-scripts
21793@cindex print list of auto-loaded canned sequences of commands scripts
21794@item info auto-load gdb-scripts [@var{regexp}]
21795Print the list of all canned sequences of commands scripts that @value{GDBN}
21796auto-loaded.
21797@end table
21798
21799If @var{regexp} is supplied only canned sequences of commands scripts with
21800matching names are printed.
21801
bccbefd2
JK
21802@node Auto-loading safe path
21803@subsection Security restriction for auto-loading
21804@cindex auto-loading safe-path
21805
21806As the files of inferior can come from untrusted source (such as submitted by
21807an application user) @value{GDBN} does not always load any files automatically.
21808@value{GDBN} provides the @samp{set auto-load safe-path} setting to list
21809directories trusted for loading files not explicitly requested by user.
202cbf1c 21810Each directory can also be a shell wildcard pattern.
bccbefd2
JK
21811
21812If the path is not set properly you will see a warning and the file will not
21813get loaded:
21814
21815@smallexample
21816$ ./gdb -q ./gdb
21817Reading symbols from /home/user/gdb/gdb...done.
21818warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
1564a261
JK
21819 declined by your `auto-load safe-path' set
21820 to "$debugdir:$datadir/auto-load".
bccbefd2 21821warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
1564a261
JK
21822 declined by your `auto-load safe-path' set
21823 to "$debugdir:$datadir/auto-load".
bccbefd2
JK
21824@end smallexample
21825
21826The list of trusted directories is controlled by the following commands:
21827
21828@table @code
21829@anchor{set auto-load safe-path}
21830@kindex set auto-load safe-path
af2c1515 21831@item set auto-load safe-path @r{[}@var{directories}@r{]}
bccbefd2
JK
21832Set the list of directories (and their subdirectories) trusted for automatic
21833loading and execution of scripts. You can also enter a specific trusted file.
202cbf1c
JK
21834Each directory can also be a shell wildcard pattern; wildcards do not match
21835directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
21836(@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
af2c1515
JK
21837If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
21838its default value as specified during @value{GDBN} compilation.
21839
d9242c17 21840The list of directories uses path separator (@samp{:} on GNU and Unix
bccbefd2
JK
21841systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
21842to the @env{PATH} environment variable.
21843
21844@anchor{show auto-load safe-path}
21845@kindex show auto-load safe-path
21846@item show auto-load safe-path
21847Show the list of directories trusted for automatic loading and execution of
21848scripts.
21849
21850@anchor{add-auto-load-safe-path}
21851@kindex add-auto-load-safe-path
21852@item add-auto-load-safe-path
21853Add an entry (or list of entries) the list of directories trusted for automatic
21854loading and execution of scripts. Multiple entries may be delimited by the
d9242c17 21855host platform path separator in use.
bccbefd2
JK
21856@end table
21857
7349ff92 21858This variable defaults to what @code{--with-auto-load-dir} has been configured
1564a261
JK
21859to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
21860substitution applies the same as for @ref{set auto-load scripts-directory}.
21861The default @code{set auto-load safe-path} value can be also overriden by
21862@value{GDBN} configuration option @option{--with-auto-load-safe-path}.
6dea1fbd 21863
6dea1fbd
JK
21864Setting this variable to @file{/} disables this security protection,
21865corresponding @value{GDBN} configuration option is
21866@option{--without-auto-load-safe-path}.
bccbefd2
JK
21867This variable is supposed to be set to the system directories writable by the
21868system superuser only. Users can add their source directories in init files in
21869their home directories (@pxref{Home Directory Init File}). See also deprecated
21870init file in the current directory
21871(@pxref{Init File in the Current Directory during Startup}).
21872
21873To force @value{GDBN} to load the files it declined to load in the previous
21874example, you could use one of the following ways:
21875
0511cc75
JK
21876@table @asis
21877@item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
bccbefd2
JK
21878Specify this trusted directory (or a file) as additional component of the list.
21879You have to specify also any existing directories displayed by
21880by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
21881
174bb630 21882@item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
bccbefd2
JK
21883Specify this directory as in the previous case but just for a single
21884@value{GDBN} session.
21885
af2c1515 21886@item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
bccbefd2
JK
21887Disable auto-loading safety for a single @value{GDBN} session.
21888This assumes all the files you debug during this @value{GDBN} session will come
21889from trusted sources.
21890
21891@item @kbd{./configure --without-auto-load-safe-path}
21892During compilation of @value{GDBN} you may disable any auto-loading safety.
21893This assumes all the files you will ever debug with this @value{GDBN} come from
21894trusted sources.
0511cc75 21895@end table
bccbefd2
JK
21896
21897On the other hand you can also explicitly forbid automatic files loading which
21898also suppresses any such warning messages:
21899
0511cc75 21900@table @asis
174bb630 21901@item @kbd{gdb -iex "set auto-load no" @dots{}}
bccbefd2
JK
21902You can use @value{GDBN} command-line option for a single @value{GDBN} session.
21903
0511cc75 21904@item @file{~/.gdbinit}: @samp{set auto-load no}
bccbefd2
JK
21905Disable auto-loading globally for the user
21906(@pxref{Home Directory Init File}). While it is improbable, you could also
21907use system init file instead (@pxref{System-wide configuration}).
0511cc75 21908@end table
bccbefd2
JK
21909
21910This setting applies to the file names as entered by user. If no entry matches
21911@value{GDBN} tries as a last resort to also resolve all the file names into
21912their canonical form (typically resolving symbolic links) and compare the
21913entries again. @value{GDBN} already canonicalizes most of the filenames on its
21914own before starting the comparison so a canonical form of directories is
21915recommended to be entered.
21916
4dc84fd1
JK
21917@node Auto-loading verbose mode
21918@subsection Displaying files tried for auto-load
21919@cindex auto-loading verbose mode
21920
21921For better visibility of all the file locations where you can place scripts to
21922be auto-loaded with inferior --- or to protect yourself against accidental
21923execution of untrusted scripts --- @value{GDBN} provides a feature for printing
21924all the files attempted to be loaded. Both existing and non-existing files may
21925be printed.
21926
21927For example the list of directories from which it is safe to auto-load files
21928(@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
21929may not be too obvious while setting it up.
21930
21931@smallexample
0070f25a 21932(gdb) set debug auto-load on
4dc84fd1
JK
21933(gdb) file ~/src/t/true
21934auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
21935 for objfile "/tmp/true".
21936auto-load: Updating directories of "/usr:/opt".
21937auto-load: Using directory "/usr".
21938auto-load: Using directory "/opt".
21939warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
21940 by your `auto-load safe-path' set to "/usr:/opt".
21941@end smallexample
21942
21943@table @code
21944@anchor{set debug auto-load}
21945@kindex set debug auto-load
21946@item set debug auto-load [on|off]
21947Set whether to print the filenames attempted to be auto-loaded.
21948
21949@anchor{show debug auto-load}
21950@kindex show debug auto-load
21951@item show debug auto-load
21952Show whether printing of the filenames attempted to be auto-loaded is turned
21953on or off.
21954@end table
21955
8e04817f 21956@node Messages/Warnings
79a6e687 21957@section Optional Warnings and Messages
104c1213 21958
9c16f35a
EZ
21959@cindex verbose operation
21960@cindex optional warnings
8e04817f
AC
21961By default, @value{GDBN} is silent about its inner workings. If you are
21962running on a slow machine, you may want to use the @code{set verbose}
21963command. This makes @value{GDBN} tell you when it does a lengthy
21964internal operation, so you will not think it has crashed.
104c1213 21965
8e04817f
AC
21966Currently, the messages controlled by @code{set verbose} are those
21967which announce that the symbol table for a source file is being read;
79a6e687 21968see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 21969
8e04817f
AC
21970@table @code
21971@kindex set verbose
21972@item set verbose on
21973Enables @value{GDBN} output of certain informational messages.
104c1213 21974
8e04817f
AC
21975@item set verbose off
21976Disables @value{GDBN} output of certain informational messages.
104c1213 21977
8e04817f
AC
21978@kindex show verbose
21979@item show verbose
21980Displays whether @code{set verbose} is on or off.
21981@end table
104c1213 21982
8e04817f
AC
21983By default, if @value{GDBN} encounters bugs in the symbol table of an
21984object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
21985find this information useful (@pxref{Symbol Errors, ,Errors Reading
21986Symbol Files}).
104c1213 21987
8e04817f 21988@table @code
104c1213 21989
8e04817f
AC
21990@kindex set complaints
21991@item set complaints @var{limit}
21992Permits @value{GDBN} to output @var{limit} complaints about each type of
21993unusual symbols before becoming silent about the problem. Set
21994@var{limit} to zero to suppress all complaints; set it to a large number
21995to prevent complaints from being suppressed.
104c1213 21996
8e04817f
AC
21997@kindex show complaints
21998@item show complaints
21999Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 22000
8e04817f 22001@end table
104c1213 22002
d837706a 22003@anchor{confirmation requests}
8e04817f
AC
22004By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
22005lot of stupid questions to confirm certain commands. For example, if
22006you try to run a program which is already running:
104c1213 22007
474c8240 22008@smallexample
8e04817f
AC
22009(@value{GDBP}) run
22010The program being debugged has been started already.
22011Start it from the beginning? (y or n)
474c8240 22012@end smallexample
104c1213 22013
8e04817f
AC
22014If you are willing to unflinchingly face the consequences of your own
22015commands, you can disable this ``feature'':
104c1213 22016
8e04817f 22017@table @code
104c1213 22018
8e04817f
AC
22019@kindex set confirm
22020@cindex flinching
22021@cindex confirmation
22022@cindex stupid questions
22023@item set confirm off
7c953934
TT
22024Disables confirmation requests. Note that running @value{GDBN} with
22025the @option{--batch} option (@pxref{Mode Options, -batch}) also
22026automatically disables confirmation requests.
104c1213 22027
8e04817f
AC
22028@item set confirm on
22029Enables confirmation requests (the default).
104c1213 22030
8e04817f
AC
22031@kindex show confirm
22032@item show confirm
22033Displays state of confirmation requests.
22034
22035@end table
104c1213 22036
16026cd7
AS
22037@cindex command tracing
22038If you need to debug user-defined commands or sourced files you may find it
22039useful to enable @dfn{command tracing}. In this mode each command will be
22040printed as it is executed, prefixed with one or more @samp{+} symbols, the
22041quantity denoting the call depth of each command.
22042
22043@table @code
22044@kindex set trace-commands
22045@cindex command scripts, debugging
22046@item set trace-commands on
22047Enable command tracing.
22048@item set trace-commands off
22049Disable command tracing.
22050@item show trace-commands
22051Display the current state of command tracing.
22052@end table
22053
8e04817f 22054@node Debugging Output
79a6e687 22055@section Optional Messages about Internal Happenings
4644b6e3
EZ
22056@cindex optional debugging messages
22057
da316a69
EZ
22058@value{GDBN} has commands that enable optional debugging messages from
22059various @value{GDBN} subsystems; normally these commands are of
22060interest to @value{GDBN} maintainers, or when reporting a bug. This
22061section documents those commands.
22062
104c1213 22063@table @code
a8f24a35
EZ
22064@kindex set exec-done-display
22065@item set exec-done-display
22066Turns on or off the notification of asynchronous commands'
22067completion. When on, @value{GDBN} will print a message when an
22068asynchronous command finishes its execution. The default is off.
22069@kindex show exec-done-display
22070@item show exec-done-display
22071Displays the current setting of asynchronous command completion
22072notification.
4644b6e3 22073@kindex set debug
be9a8770
PA
22074@cindex ARM AArch64
22075@item set debug aarch64
22076Turns on or off display of debugging messages related to ARM AArch64.
22077The default is off.
22078@kindex show debug
22079@item show debug aarch64
22080Displays the current state of displaying debugging messages related to
22081ARM AArch64.
4644b6e3 22082@cindex gdbarch debugging info
a8f24a35 22083@cindex architecture debugging info
8e04817f 22084@item set debug arch
a8f24a35 22085Turns on or off display of gdbarch debugging info. The default is off
8e04817f
AC
22086@item show debug arch
22087Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
22088@item set debug aix-thread
22089@cindex AIX threads
22090Display debugging messages about inner workings of the AIX thread
22091module.
22092@item show debug aix-thread
22093Show the current state of AIX thread debugging info display.
900e11f9
JK
22094@item set debug check-physname
22095@cindex physname
22096Check the results of the ``physname'' computation. When reading DWARF
22097debugging information for C@t{++}, @value{GDBN} attempts to compute
22098each entity's name. @value{GDBN} can do this computation in two
22099different ways, depending on exactly what information is present.
22100When enabled, this setting causes @value{GDBN} to compute the names
22101both ways and display any discrepancies.
22102@item show debug check-physname
22103Show the current state of ``physname'' checking.
be9a8770
PA
22104@item set debug coff-pe-read
22105@cindex COFF/PE exported symbols
22106Control display of debugging messages related to reading of COFF/PE
22107exported symbols. The default is off.
22108@item show debug coff-pe-read
22109Displays the current state of displaying debugging messages related to
22110reading of COFF/PE exported symbols.
d97bc12b
DE
22111@item set debug dwarf2-die
22112@cindex DWARF2 DIEs
22113Dump DWARF2 DIEs after they are read in.
22114The value is the number of nesting levels to print.
22115A value of zero turns off the display.
22116@item show debug dwarf2-die
22117Show the current state of DWARF2 DIE debugging.
45cfd468
DE
22118@item set debug dwarf2-read
22119@cindex DWARF2 Reading
22120Turns on or off display of debugging messages related to reading
22121DWARF debug info. The default is off.
22122@item show debug dwarf2-read
22123Show the current state of DWARF2 reader debugging.
237fc4c9
PA
22124@item set debug displaced
22125@cindex displaced stepping debugging info
22126Turns on or off display of @value{GDBN} debugging info for the
22127displaced stepping support. The default is off.
22128@item show debug displaced
22129Displays the current state of displaying @value{GDBN} debugging info
22130related to displaced stepping.
8e04817f 22131@item set debug event
4644b6e3 22132@cindex event debugging info
a8f24a35 22133Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 22134default is off.
8e04817f
AC
22135@item show debug event
22136Displays the current state of displaying @value{GDBN} event debugging
22137info.
8e04817f 22138@item set debug expression
4644b6e3 22139@cindex expression debugging info
721c2651
EZ
22140Turns on or off display of debugging info about @value{GDBN}
22141expression parsing. The default is off.
8e04817f 22142@item show debug expression
721c2651
EZ
22143Displays the current state of displaying debugging info about
22144@value{GDBN} expression parsing.
7453dc06 22145@item set debug frame
4644b6e3 22146@cindex frame debugging info
7453dc06
AC
22147Turns on or off display of @value{GDBN} frame debugging info. The
22148default is off.
7453dc06
AC
22149@item show debug frame
22150Displays the current state of displaying @value{GDBN} frame debugging
22151info.
cbe54154
PA
22152@item set debug gnu-nat
22153@cindex @sc{gnu}/Hurd debug messages
22154Turns on or off debugging messages from the @sc{gnu}/Hurd debug support.
22155@item show debug gnu-nat
22156Show the current state of @sc{gnu}/Hurd debugging messages.
30e91e0b
RC
22157@item set debug infrun
22158@cindex inferior debugging info
22159Turns on or off display of @value{GDBN} debugging info for running the inferior.
22160The default is off. @file{infrun.c} contains GDB's runtime state machine used
22161for implementing operations such as single-stepping the inferior.
22162@item show debug infrun
22163Displays the current state of @value{GDBN} inferior debugging.
a255712f
PP
22164@item set debug jit
22165@cindex just-in-time compilation, debugging messages
22166Turns on or off debugging messages from JIT debug support.
22167@item show debug jit
22168Displays the current state of @value{GDBN} JIT debugging.
da316a69
EZ
22169@item set debug lin-lwp
22170@cindex @sc{gnu}/Linux LWP debug messages
22171@cindex Linux lightweight processes
721c2651 22172Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
22173@item show debug lin-lwp
22174Show the current state of Linux LWP debugging messages.
be9a8770
PA
22175@item set debug mach-o
22176@cindex Mach-O symbols processing
22177Control display of debugging messages related to Mach-O symbols
22178processing. The default is off.
22179@item show debug mach-o
22180Displays the current state of displaying debugging messages related to
22181reading of COFF/PE exported symbols.
c9b6281a
YQ
22182@item set debug notification
22183@cindex remote async notification debugging info
22184Turns on or off debugging messages about remote async notification.
22185The default is off.
22186@item show debug notification
22187Displays the current state of remote async notification debugging messages.
2b4855ab 22188@item set debug observer
4644b6e3 22189@cindex observer debugging info
2b4855ab
AC
22190Turns on or off display of @value{GDBN} observer debugging. This
22191includes info such as the notification of observable events.
2b4855ab
AC
22192@item show debug observer
22193Displays the current state of observer debugging.
8e04817f 22194@item set debug overload
4644b6e3 22195@cindex C@t{++} overload debugging info
8e04817f 22196Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 22197info. This includes info such as ranking of functions, etc. The default
8e04817f 22198is off.
8e04817f
AC
22199@item show debug overload
22200Displays the current state of displaying @value{GDBN} C@t{++} overload
22201debugging info.
92981e24
TT
22202@cindex expression parser, debugging info
22203@cindex debug expression parser
22204@item set debug parser
22205Turns on or off the display of expression parser debugging output.
22206Internally, this sets the @code{yydebug} variable in the expression
22207parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
22208details. The default is off.
22209@item show debug parser
22210Show the current state of expression parser debugging.
8e04817f
AC
22211@cindex packets, reporting on stdout
22212@cindex serial connections, debugging
605a56cb
DJ
22213@cindex debug remote protocol
22214@cindex remote protocol debugging
22215@cindex display remote packets
8e04817f
AC
22216@item set debug remote
22217Turns on or off display of reports on all packets sent back and forth across
22218the serial line to the remote machine. The info is printed on the
22219@value{GDBN} standard output stream. The default is off.
8e04817f
AC
22220@item show debug remote
22221Displays the state of display of remote packets.
8e04817f
AC
22222@item set debug serial
22223Turns on or off display of @value{GDBN} serial debugging info. The
22224default is off.
8e04817f
AC
22225@item show debug serial
22226Displays the current state of displaying @value{GDBN} serial debugging
22227info.
c45da7e6
EZ
22228@item set debug solib-frv
22229@cindex FR-V shared-library debugging
22230Turns on or off debugging messages for FR-V shared-library code.
22231@item show debug solib-frv
22232Display the current state of FR-V shared-library code debugging
22233messages.
45cfd468
DE
22234@item set debug symtab-create
22235@cindex symbol table creation
22236Turns on or off display of debugging messages related to symbol table creation.
22237The default is off.
22238@item show debug symtab-create
22239Show the current state of symbol table creation debugging.
8e04817f 22240@item set debug target
4644b6e3 22241@cindex target debugging info
8e04817f
AC
22242Turns on or off display of @value{GDBN} target debugging info. This info
22243includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
22244default is 0. Set it to 1 to track events, and to 2 to also track the
22245value of large memory transfers. Changes to this flag do not take effect
22246until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
22247@item show debug target
22248Displays the current state of displaying @value{GDBN} target debugging
22249info.
75feb17d
DJ
22250@item set debug timestamp
22251@cindex timestampping debugging info
22252Turns on or off display of timestamps with @value{GDBN} debugging info.
22253When enabled, seconds and microseconds are displayed before each debugging
22254message.
22255@item show debug timestamp
22256Displays the current state of displaying timestamps with @value{GDBN}
22257debugging info.
c45da7e6 22258@item set debugvarobj
4644b6e3 22259@cindex variable object debugging info
8e04817f
AC
22260Turns on or off display of @value{GDBN} variable object debugging
22261info. The default is off.
c45da7e6 22262@item show debugvarobj
8e04817f
AC
22263Displays the current state of displaying @value{GDBN} variable object
22264debugging info.
e776119f
DJ
22265@item set debug xml
22266@cindex XML parser debugging
22267Turns on or off debugging messages for built-in XML parsers.
22268@item show debug xml
22269Displays the current state of XML debugging messages.
8e04817f 22270@end table
104c1213 22271
14fb1bac
JB
22272@node Other Misc Settings
22273@section Other Miscellaneous Settings
22274@cindex miscellaneous settings
22275
22276@table @code
22277@kindex set interactive-mode
22278@item set interactive-mode
7bfc9434
JB
22279If @code{on}, forces @value{GDBN} to assume that GDB was started
22280in a terminal. In practice, this means that @value{GDBN} should wait
22281for the user to answer queries generated by commands entered at
22282the command prompt. If @code{off}, forces @value{GDBN} to operate
22283in the opposite mode, and it uses the default answers to all queries.
22284If @code{auto} (the default), @value{GDBN} tries to determine whether
22285its standard input is a terminal, and works in interactive-mode if it
22286is, non-interactively otherwise.
14fb1bac
JB
22287
22288In the vast majority of cases, the debugger should be able to guess
22289correctly which mode should be used. But this setting can be useful
22290in certain specific cases, such as running a MinGW @value{GDBN}
22291inside a cygwin window.
22292
22293@kindex show interactive-mode
22294@item show interactive-mode
22295Displays whether the debugger is operating in interactive mode or not.
22296@end table
22297
d57a3c85
TJB
22298@node Extending GDB
22299@chapter Extending @value{GDBN}
22300@cindex extending GDB
22301
5a56e9c5
DE
22302@value{GDBN} provides three mechanisms for extension. The first is based
22303on composition of @value{GDBN} commands, the second is based on the
22304Python scripting language, and the third is for defining new aliases of
22305existing commands.
d57a3c85 22306
5a56e9c5 22307To facilitate the use of the first two extensions, @value{GDBN} is capable
95433b34
JB
22308of evaluating the contents of a file. When doing so, @value{GDBN}
22309can recognize which scripting language is being used by looking at
22310the filename extension. Files with an unrecognized filename extension
22311are always treated as a @value{GDBN} Command Files.
22312@xref{Command Files,, Command files}.
22313
22314You can control how @value{GDBN} evaluates these files with the following
22315setting:
22316
22317@table @code
22318@kindex set script-extension
22319@kindex show script-extension
22320@item set script-extension off
22321All scripts are always evaluated as @value{GDBN} Command Files.
22322
22323@item set script-extension soft
22324The debugger determines the scripting language based on filename
22325extension. If this scripting language is supported, @value{GDBN}
22326evaluates the script using that language. Otherwise, it evaluates
22327the file as a @value{GDBN} Command File.
22328
22329@item set script-extension strict
22330The debugger determines the scripting language based on filename
22331extension, and evaluates the script using that language. If the
22332language is not supported, then the evaluation fails.
22333
22334@item show script-extension
22335Display the current value of the @code{script-extension} option.
22336
22337@end table
22338
d57a3c85
TJB
22339@menu
22340* Sequences:: Canned Sequences of Commands
22341* Python:: Scripting @value{GDBN} using Python
5a56e9c5 22342* Aliases:: Creating new spellings of existing commands
d57a3c85
TJB
22343@end menu
22344
8e04817f 22345@node Sequences
d57a3c85 22346@section Canned Sequences of Commands
104c1213 22347
8e04817f 22348Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 22349Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
22350commands for execution as a unit: user-defined commands and command
22351files.
104c1213 22352
8e04817f 22353@menu
fcc73fe3
EZ
22354* Define:: How to define your own commands
22355* Hooks:: Hooks for user-defined commands
22356* Command Files:: How to write scripts of commands to be stored in a file
22357* Output:: Commands for controlled output
8e04817f 22358@end menu
104c1213 22359
8e04817f 22360@node Define
d57a3c85 22361@subsection User-defined Commands
104c1213 22362
8e04817f 22363@cindex user-defined command
fcc73fe3 22364@cindex arguments, to user-defined commands
8e04817f
AC
22365A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
22366which you assign a new name as a command. This is done with the
22367@code{define} command. User commands may accept up to 10 arguments
22368separated by whitespace. Arguments are accessed within the user command
c03c782f 22369via @code{$arg0@dots{}$arg9}. A trivial example:
104c1213 22370
8e04817f
AC
22371@smallexample
22372define adder
22373 print $arg0 + $arg1 + $arg2
c03c782f 22374end
8e04817f 22375@end smallexample
104c1213
JM
22376
22377@noindent
8e04817f 22378To execute the command use:
104c1213 22379
8e04817f
AC
22380@smallexample
22381adder 1 2 3
22382@end smallexample
104c1213 22383
8e04817f
AC
22384@noindent
22385This defines the command @code{adder}, which prints the sum of
22386its three arguments. Note the arguments are text substitutions, so they may
22387reference variables, use complex expressions, or even perform inferior
22388functions calls.
104c1213 22389
fcc73fe3
EZ
22390@cindex argument count in user-defined commands
22391@cindex how many arguments (user-defined commands)
c03c782f
AS
22392In addition, @code{$argc} may be used to find out how many arguments have
22393been passed. This expands to a number in the range 0@dots{}10.
22394
22395@smallexample
22396define adder
22397 if $argc == 2
22398 print $arg0 + $arg1
22399 end
22400 if $argc == 3
22401 print $arg0 + $arg1 + $arg2
22402 end
22403end
22404@end smallexample
22405
104c1213 22406@table @code
104c1213 22407
8e04817f
AC
22408@kindex define
22409@item define @var{commandname}
22410Define a command named @var{commandname}. If there is already a command
22411by that name, you are asked to confirm that you want to redefine it.
adb483fe
DJ
22412@var{commandname} may be a bare command name consisting of letters,
22413numbers, dashes, and underscores. It may also start with any predefined
22414prefix command. For example, @samp{define target my-target} creates
22415a user-defined @samp{target my-target} command.
104c1213 22416
8e04817f
AC
22417The definition of the command is made up of other @value{GDBN} command lines,
22418which are given following the @code{define} command. The end of these
22419commands is marked by a line containing @code{end}.
104c1213 22420
8e04817f 22421@kindex document
ca91424e 22422@kindex end@r{ (user-defined commands)}
8e04817f
AC
22423@item document @var{commandname}
22424Document the user-defined command @var{commandname}, so that it can be
22425accessed by @code{help}. The command @var{commandname} must already be
22426defined. This command reads lines of documentation just as @code{define}
22427reads the lines of the command definition, ending with @code{end}.
22428After the @code{document} command is finished, @code{help} on command
22429@var{commandname} displays the documentation you have written.
104c1213 22430
8e04817f
AC
22431You may use the @code{document} command again to change the
22432documentation of a command. Redefining the command with @code{define}
22433does not change the documentation.
104c1213 22434
c45da7e6
EZ
22435@kindex dont-repeat
22436@cindex don't repeat command
22437@item dont-repeat
22438Used inside a user-defined command, this tells @value{GDBN} that this
22439command should not be repeated when the user hits @key{RET}
22440(@pxref{Command Syntax, repeat last command}).
22441
8e04817f
AC
22442@kindex help user-defined
22443@item help user-defined
7d74f244
DE
22444List all user-defined commands and all python commands defined in class
22445COMAND_USER. The first line of the documentation or docstring is
22446included (if any).
104c1213 22447
8e04817f
AC
22448@kindex show user
22449@item show user
22450@itemx show user @var{commandname}
22451Display the @value{GDBN} commands used to define @var{commandname} (but
22452not its documentation). If no @var{commandname} is given, display the
22453definitions for all user-defined commands.
7d74f244 22454This does not work for user-defined python commands.
104c1213 22455
fcc73fe3 22456@cindex infinite recursion in user-defined commands
20f01a46
DH
22457@kindex show max-user-call-depth
22458@kindex set max-user-call-depth
22459@item show max-user-call-depth
5ca0cb28
DH
22460@itemx set max-user-call-depth
22461The value of @code{max-user-call-depth} controls how many recursion
3f94c067 22462levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 22463infinite recursion and aborts the command.
7d74f244 22464This does not apply to user-defined python commands.
104c1213
JM
22465@end table
22466
fcc73fe3
EZ
22467In addition to the above commands, user-defined commands frequently
22468use control flow commands, described in @ref{Command Files}.
22469
8e04817f
AC
22470When user-defined commands are executed, the
22471commands of the definition are not printed. An error in any command
22472stops execution of the user-defined command.
104c1213 22473
8e04817f
AC
22474If used interactively, commands that would ask for confirmation proceed
22475without asking when used inside a user-defined command. Many @value{GDBN}
22476commands that normally print messages to say what they are doing omit the
22477messages when used in a user-defined command.
104c1213 22478
8e04817f 22479@node Hooks
d57a3c85 22480@subsection User-defined Command Hooks
8e04817f
AC
22481@cindex command hooks
22482@cindex hooks, for commands
22483@cindex hooks, pre-command
104c1213 22484
8e04817f 22485@kindex hook
8e04817f
AC
22486You may define @dfn{hooks}, which are a special kind of user-defined
22487command. Whenever you run the command @samp{foo}, if the user-defined
22488command @samp{hook-foo} exists, it is executed (with no arguments)
22489before that command.
104c1213 22490
8e04817f
AC
22491@cindex hooks, post-command
22492@kindex hookpost
8e04817f
AC
22493A hook may also be defined which is run after the command you executed.
22494Whenever you run the command @samp{foo}, if the user-defined command
22495@samp{hookpost-foo} exists, it is executed (with no arguments) after
22496that command. Post-execution hooks may exist simultaneously with
22497pre-execution hooks, for the same command.
104c1213 22498
8e04817f 22499It is valid for a hook to call the command which it hooks. If this
9f1c6395 22500occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 22501
8e04817f
AC
22502@c It would be nice if hookpost could be passed a parameter indicating
22503@c if the command it hooks executed properly or not. FIXME!
104c1213 22504
8e04817f
AC
22505@kindex stop@r{, a pseudo-command}
22506In addition, a pseudo-command, @samp{stop} exists. Defining
22507(@samp{hook-stop}) makes the associated commands execute every time
22508execution stops in your program: before breakpoint commands are run,
22509displays are printed, or the stack frame is printed.
104c1213 22510
8e04817f
AC
22511For example, to ignore @code{SIGALRM} signals while
22512single-stepping, but treat them normally during normal execution,
22513you could define:
104c1213 22514
474c8240 22515@smallexample
8e04817f
AC
22516define hook-stop
22517handle SIGALRM nopass
22518end
104c1213 22519
8e04817f
AC
22520define hook-run
22521handle SIGALRM pass
22522end
104c1213 22523
8e04817f 22524define hook-continue
d3e8051b 22525handle SIGALRM pass
8e04817f 22526end
474c8240 22527@end smallexample
104c1213 22528
d3e8051b 22529As a further example, to hook at the beginning and end of the @code{echo}
b383017d 22530command, and to add extra text to the beginning and end of the message,
8e04817f 22531you could define:
104c1213 22532
474c8240 22533@smallexample
8e04817f
AC
22534define hook-echo
22535echo <<<---
22536end
104c1213 22537
8e04817f
AC
22538define hookpost-echo
22539echo --->>>\n
22540end
104c1213 22541
8e04817f
AC
22542(@value{GDBP}) echo Hello World
22543<<<---Hello World--->>>
22544(@value{GDBP})
104c1213 22545
474c8240 22546@end smallexample
104c1213 22547
8e04817f
AC
22548You can define a hook for any single-word command in @value{GDBN}, but
22549not for command aliases; you should define a hook for the basic command
c1468174 22550name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
22551@c FIXME! So how does Joe User discover whether a command is an alias
22552@c or not?
adb483fe
DJ
22553You can hook a multi-word command by adding @code{hook-} or
22554@code{hookpost-} to the last word of the command, e.g.@:
22555@samp{define target hook-remote} to add a hook to @samp{target remote}.
22556
8e04817f
AC
22557If an error occurs during the execution of your hook, execution of
22558@value{GDBN} commands stops and @value{GDBN} issues a prompt
22559(before the command that you actually typed had a chance to run).
104c1213 22560
8e04817f
AC
22561If you try to define a hook which does not match any known command, you
22562get a warning from the @code{define} command.
c906108c 22563
8e04817f 22564@node Command Files
d57a3c85 22565@subsection Command Files
c906108c 22566
8e04817f 22567@cindex command files
fcc73fe3 22568@cindex scripting commands
6fc08d32
EZ
22569A command file for @value{GDBN} is a text file made of lines that are
22570@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
22571also be included. An empty line in a command file does nothing; it
22572does not mean to repeat the last command, as it would from the
22573terminal.
c906108c 22574
6fc08d32 22575You can request the execution of a command file with the @code{source}
95433b34
JB
22576command. Note that the @code{source} command is also used to evaluate
22577scripts that are not Command Files. The exact behavior can be configured
22578using the @code{script-extension} setting.
22579@xref{Extending GDB,, Extending GDB}.
c906108c 22580
8e04817f
AC
22581@table @code
22582@kindex source
ca91424e 22583@cindex execute commands from a file
3f7b2faa 22584@item source [-s] [-v] @var{filename}
8e04817f 22585Execute the command file @var{filename}.
c906108c
SS
22586@end table
22587
fcc73fe3
EZ
22588The lines in a command file are generally executed sequentially,
22589unless the order of execution is changed by one of the
22590@emph{flow-control commands} described below. The commands are not
a71ec265
DH
22591printed as they are executed. An error in any command terminates
22592execution of the command file and control is returned to the console.
c906108c 22593
08001717
DE
22594@value{GDBN} first searches for @var{filename} in the current directory.
22595If the file is not found there, and @var{filename} does not specify a
22596directory, then @value{GDBN} also looks for the file on the source search path
22597(specified with the @samp{directory} command);
22598except that @file{$cdir} is not searched because the compilation directory
22599is not relevant to scripts.
4b505b12 22600
3f7b2faa
DE
22601If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
22602on the search path even if @var{filename} specifies a directory.
22603The search is done by appending @var{filename} to each element of the
22604search path. So, for example, if @var{filename} is @file{mylib/myscript}
22605and the search path contains @file{/home/user} then @value{GDBN} will
22606look for the script @file{/home/user/mylib/myscript}.
22607The search is also done if @var{filename} is an absolute path.
22608For example, if @var{filename} is @file{/tmp/myscript} and
22609the search path contains @file{/home/user} then @value{GDBN} will
22610look for the script @file{/home/user/tmp/myscript}.
22611For DOS-like systems, if @var{filename} contains a drive specification,
22612it is stripped before concatenation. For example, if @var{filename} is
22613@file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
22614will look for the script @file{c:/tmp/myscript}.
22615
16026cd7
AS
22616If @code{-v}, for verbose mode, is given then @value{GDBN} displays
22617each command as it is executed. The option must be given before
22618@var{filename}, and is interpreted as part of the filename anywhere else.
22619
8e04817f
AC
22620Commands that would ask for confirmation if used interactively proceed
22621without asking when used in a command file. Many @value{GDBN} commands that
22622normally print messages to say what they are doing omit the messages
22623when called from command files.
c906108c 22624
8e04817f
AC
22625@value{GDBN} also accepts command input from standard input. In this
22626mode, normal output goes to standard output and error output goes to
22627standard error. Errors in a command file supplied on standard input do
6fc08d32 22628not terminate execution of the command file---execution continues with
8e04817f 22629the next command.
c906108c 22630
474c8240 22631@smallexample
8e04817f 22632gdb < cmds > log 2>&1
474c8240 22633@end smallexample
c906108c 22634
8e04817f
AC
22635(The syntax above will vary depending on the shell used.) This example
22636will execute commands from the file @file{cmds}. All output and errors
22637would be directed to @file{log}.
c906108c 22638
fcc73fe3
EZ
22639Since commands stored on command files tend to be more general than
22640commands typed interactively, they frequently need to deal with
22641complicated situations, such as different or unexpected values of
22642variables and symbols, changes in how the program being debugged is
22643built, etc. @value{GDBN} provides a set of flow-control commands to
22644deal with these complexities. Using these commands, you can write
22645complex scripts that loop over data structures, execute commands
22646conditionally, etc.
22647
22648@table @code
22649@kindex if
22650@kindex else
22651@item if
22652@itemx else
22653This command allows to include in your script conditionally executed
22654commands. The @code{if} command takes a single argument, which is an
22655expression to evaluate. It is followed by a series of commands that
22656are executed only if the expression is true (its value is nonzero).
22657There can then optionally be an @code{else} line, followed by a series
22658of commands that are only executed if the expression was false. The
22659end of the list is marked by a line containing @code{end}.
22660
22661@kindex while
22662@item while
22663This command allows to write loops. Its syntax is similar to
22664@code{if}: the command takes a single argument, which is an expression
22665to evaluate, and must be followed by the commands to execute, one per
22666line, terminated by an @code{end}. These commands are called the
22667@dfn{body} of the loop. The commands in the body of @code{while} are
22668executed repeatedly as long as the expression evaluates to true.
22669
22670@kindex loop_break
22671@item loop_break
22672This command exits the @code{while} loop in whose body it is included.
22673Execution of the script continues after that @code{while}s @code{end}
22674line.
22675
22676@kindex loop_continue
22677@item loop_continue
22678This command skips the execution of the rest of the body of commands
22679in the @code{while} loop in whose body it is included. Execution
22680branches to the beginning of the @code{while} loop, where it evaluates
22681the controlling expression.
ca91424e
EZ
22682
22683@kindex end@r{ (if/else/while commands)}
22684@item end
22685Terminate the block of commands that are the body of @code{if},
22686@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
22687@end table
22688
22689
8e04817f 22690@node Output
d57a3c85 22691@subsection Commands for Controlled Output
c906108c 22692
8e04817f
AC
22693During the execution of a command file or a user-defined command, normal
22694@value{GDBN} output is suppressed; the only output that appears is what is
22695explicitly printed by the commands in the definition. This section
22696describes three commands useful for generating exactly the output you
22697want.
c906108c
SS
22698
22699@table @code
8e04817f
AC
22700@kindex echo
22701@item echo @var{text}
22702@c I do not consider backslash-space a standard C escape sequence
22703@c because it is not in ANSI.
22704Print @var{text}. Nonprinting characters can be included in
22705@var{text} using C escape sequences, such as @samp{\n} to print a
22706newline. @strong{No newline is printed unless you specify one.}
22707In addition to the standard C escape sequences, a backslash followed
22708by a space stands for a space. This is useful for displaying a
22709string with spaces at the beginning or the end, since leading and
22710trailing spaces are otherwise trimmed from all arguments.
22711To print @samp{@w{ }and foo =@w{ }}, use the command
22712@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 22713
8e04817f
AC
22714A backslash at the end of @var{text} can be used, as in C, to continue
22715the command onto subsequent lines. For example,
c906108c 22716
474c8240 22717@smallexample
8e04817f
AC
22718echo This is some text\n\
22719which is continued\n\
22720onto several lines.\n
474c8240 22721@end smallexample
c906108c 22722
8e04817f 22723produces the same output as
c906108c 22724
474c8240 22725@smallexample
8e04817f
AC
22726echo This is some text\n
22727echo which is continued\n
22728echo onto several lines.\n
474c8240 22729@end smallexample
c906108c 22730
8e04817f
AC
22731@kindex output
22732@item output @var{expression}
22733Print the value of @var{expression} and nothing but that value: no
22734newlines, no @samp{$@var{nn} = }. The value is not entered in the
22735value history either. @xref{Expressions, ,Expressions}, for more information
22736on expressions.
c906108c 22737
8e04817f
AC
22738@item output/@var{fmt} @var{expression}
22739Print the value of @var{expression} in format @var{fmt}. You can use
22740the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 22741Formats}, for more information.
c906108c 22742
8e04817f 22743@kindex printf
82160952
EZ
22744@item printf @var{template}, @var{expressions}@dots{}
22745Print the values of one or more @var{expressions} under the control of
22746the string @var{template}. To print several values, make
22747@var{expressions} be a comma-separated list of individual expressions,
22748which may be either numbers or pointers. Their values are printed as
22749specified by @var{template}, exactly as a C program would do by
22750executing the code below:
c906108c 22751
474c8240 22752@smallexample
82160952 22753printf (@var{template}, @var{expressions}@dots{});
474c8240 22754@end smallexample
c906108c 22755
82160952
EZ
22756As in @code{C} @code{printf}, ordinary characters in @var{template}
22757are printed verbatim, while @dfn{conversion specification} introduced
22758by the @samp{%} character cause subsequent @var{expressions} to be
22759evaluated, their values converted and formatted according to type and
22760style information encoded in the conversion specifications, and then
22761printed.
22762
8e04817f 22763For example, you can print two values in hex like this:
c906108c 22764
8e04817f
AC
22765@smallexample
22766printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
22767@end smallexample
c906108c 22768
82160952
EZ
22769@code{printf} supports all the standard @code{C} conversion
22770specifications, including the flags and modifiers between the @samp{%}
22771character and the conversion letter, with the following exceptions:
22772
22773@itemize @bullet
22774@item
22775The argument-ordering modifiers, such as @samp{2$}, are not supported.
22776
22777@item
22778The modifier @samp{*} is not supported for specifying precision or
22779width.
22780
22781@item
22782The @samp{'} flag (for separation of digits into groups according to
22783@code{LC_NUMERIC'}) is not supported.
22784
22785@item
22786The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
22787supported.
22788
22789@item
22790The conversion letter @samp{n} (as in @samp{%n}) is not supported.
22791
22792@item
22793The conversion letters @samp{a} and @samp{A} are not supported.
22794@end itemize
22795
22796@noindent
22797Note that the @samp{ll} type modifier is supported only if the
22798underlying @code{C} implementation used to build @value{GDBN} supports
22799the @code{long long int} type, and the @samp{L} type modifier is
22800supported only if @code{long double} type is available.
22801
22802As in @code{C}, @code{printf} supports simple backslash-escape
22803sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
22804@samp{\a}, and @samp{\f}, that consist of backslash followed by a
22805single character. Octal and hexadecimal escape sequences are not
22806supported.
1a619819
LM
22807
22808Additionally, @code{printf} supports conversion specifications for DFP
0aea4bf3
LM
22809(@dfn{Decimal Floating Point}) types using the following length modifiers
22810together with a floating point specifier.
1a619819
LM
22811letters:
22812
22813@itemize @bullet
22814@item
22815@samp{H} for printing @code{Decimal32} types.
22816
22817@item
22818@samp{D} for printing @code{Decimal64} types.
22819
22820@item
22821@samp{DD} for printing @code{Decimal128} types.
22822@end itemize
22823
22824If the underlying @code{C} implementation used to build @value{GDBN} has
0aea4bf3 22825support for the three length modifiers for DFP types, other modifiers
3b784c4f 22826such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
22827
22828In case there is no such @code{C} support, no additional modifiers will be
22829available and the value will be printed in the standard way.
22830
22831Here's an example of printing DFP types using the above conversion letters:
22832@smallexample
0aea4bf3 22833printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
1a619819
LM
22834@end smallexample
22835
f1421989
HZ
22836@kindex eval
22837@item eval @var{template}, @var{expressions}@dots{}
22838Convert the values of one or more @var{expressions} under the control of
22839the string @var{template} to a command line, and call it.
22840
c906108c
SS
22841@end table
22842
d57a3c85
TJB
22843@node Python
22844@section Scripting @value{GDBN} using Python
22845@cindex python scripting
22846@cindex scripting with python
22847
22848You can script @value{GDBN} using the @uref{http://www.python.org/,
22849Python programming language}. This feature is available only if
22850@value{GDBN} was configured using @option{--with-python}.
22851
9279c692
JB
22852@cindex python directory
22853Python scripts used by @value{GDBN} should be installed in
22854@file{@var{data-directory}/python}, where @var{data-directory} is
9eeee977
DE
22855the data directory as determined at @value{GDBN} startup (@pxref{Data Files}).
22856This directory, known as the @dfn{python directory},
9279c692
JB
22857is automatically added to the Python Search Path in order to allow
22858the Python interpreter to locate all scripts installed at this location.
22859
5e239b84
PM
22860Additionally, @value{GDBN} commands and convenience functions which
22861are written in Python and are located in the
22862@file{@var{data-directory}/python/gdb/command} or
22863@file{@var{data-directory}/python/gdb/function} directories are
22864automatically imported when @value{GDBN} starts.
22865
d57a3c85
TJB
22866@menu
22867* Python Commands:: Accessing Python from @value{GDBN}.
22868* Python API:: Accessing @value{GDBN} from Python.
bf88dd68 22869* Python Auto-loading:: Automatically loading Python code.
0e3509db 22870* Python modules:: Python modules provided by @value{GDBN}.
d57a3c85
TJB
22871@end menu
22872
22873@node Python Commands
22874@subsection Python Commands
22875@cindex python commands
22876@cindex commands to access python
22877
8315665e 22878@value{GDBN} provides two commands for accessing the Python interpreter,
d57a3c85
TJB
22879and one related setting:
22880
22881@table @code
8315665e
YPK
22882@kindex python-interactive
22883@kindex pi
22884@item python-interactive @r{[}@var{command}@r{]}
22885@itemx pi @r{[}@var{command}@r{]}
22886Without an argument, the @code{python-interactive} command can be used
e3480f4a
YPK
22887to start an interactive Python prompt. To return to @value{GDBN},
22888type the @code{EOF} character (e.g., @kbd{Ctrl-D} on an empty prompt).
8315665e
YPK
22889
22890Alternatively, a single-line Python command can be given as an
22891argument and evaluated. If the command is an expression, the result
22892will be printed; otherwise, nothing will be printed. For example:
22893
22894@smallexample
22895(@value{GDBP}) python-interactive 2 + 3
228965
22897@end smallexample
22898
d57a3c85 22899@kindex python
8315665e
YPK
22900@kindex py
22901@item python @r{[}@var{command}@r{]}
22902@itemx py @r{[}@var{command}@r{]}
d57a3c85
TJB
22903The @code{python} command can be used to evaluate Python code.
22904
22905If given an argument, the @code{python} command will evaluate the
22906argument as a Python command. For example:
22907
22908@smallexample
22909(@value{GDBP}) python print 23
2291023
22911@end smallexample
22912
22913If you do not provide an argument to @code{python}, it will act as a
22914multi-line command, like @code{define}. In this case, the Python
22915script is made up of subsequent command lines, given after the
22916@code{python} command. This command list is terminated using a line
22917containing @code{end}. For example:
22918
22919@smallexample
22920(@value{GDBP}) python
22921Type python script
22922End with a line saying just "end".
22923>print 23
22924>end
2292523
22926@end smallexample
22927
713389e0
PM
22928@kindex set python print-stack
22929@item set python print-stack
80b6e756
PM
22930By default, @value{GDBN} will print only the message component of a
22931Python exception when an error occurs in a Python script. This can be
22932controlled using @code{set python print-stack}: if @code{full}, then
22933full Python stack printing is enabled; if @code{none}, then Python stack
22934and message printing is disabled; if @code{message}, the default, only
22935the message component of the error is printed.
d57a3c85
TJB
22936@end table
22937
95433b34
JB
22938It is also possible to execute a Python script from the @value{GDBN}
22939interpreter:
22940
22941@table @code
22942@item source @file{script-name}
22943The script name must end with @samp{.py} and @value{GDBN} must be configured
22944to recognize the script language based on filename extension using
22945the @code{script-extension} setting. @xref{Extending GDB, ,Extending GDB}.
22946
22947@item python execfile ("script-name")
22948This method is based on the @code{execfile} Python built-in function,
22949and thus is always available.
22950@end table
22951
d57a3c85
TJB
22952@node Python API
22953@subsection Python API
22954@cindex python api
22955@cindex programming in python
22956
22957@cindex python stdout
22958@cindex python pagination
22959At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
22960@code{sys.stderr} to print using @value{GDBN}'s output-paging streams.
22961A Python program which outputs to one of these streams may have its
22962output interrupted by the user (@pxref{Screen Size}). In this
22963situation, a Python @code{KeyboardInterrupt} exception is thrown.
22964
22965@menu
22966* Basic Python:: Basic Python Functions.
06e65f44
TT
22967* Exception Handling:: How Python exceptions are translated.
22968* Values From Inferior:: Python representation of values.
4c374409
JK
22969* Types In Python:: Python representation of types.
22970* Pretty Printing API:: Pretty-printing values.
a6bac58e 22971* Selecting Pretty-Printers:: How GDB chooses a pretty-printer.
7b51bc51 22972* Writing a Pretty-Printer:: Writing a Pretty-Printer.
18a9fc12 22973* Type Printing API:: Pretty-printing types.
595939de 22974* Inferiors In Python:: Python representation of inferiors (processes)
505500db 22975* Events In Python:: Listening for events from @value{GDBN}.
595939de 22976* Threads In Python:: Accessing inferior threads from Python.
d8906c6f 22977* Commands In Python:: Implementing new commands in Python.
d7b32ed3 22978* Parameters In Python:: Adding new @value{GDBN} parameters.
bc3b79fd 22979* Functions In Python:: Writing new convenience functions.
fa33c3cd 22980* Progspaces In Python:: Program spaces.
89c73ade 22981* Objfiles In Python:: Object files.
f3e9a817
PM
22982* Frames In Python:: Accessing inferior stack frames from Python.
22983* Blocks In Python:: Accessing frame blocks from Python.
22984* Symbols In Python:: Python representation of symbols.
22985* Symbol Tables In Python:: Python representation of symbol tables.
adc36818 22986* Breakpoints In Python:: Manipulating breakpoints using Python.
cc72b2a2
KP
22987* Finish Breakpoints in Python:: Setting Breakpoints on function return
22988 using Python.
984359d2 22989* Lazy Strings In Python:: Python representation of lazy strings.
bea883fd 22990* Architectures In Python:: Python representation of architectures.
d57a3c85
TJB
22991@end menu
22992
22993@node Basic Python
22994@subsubsection Basic Python
22995
22996@cindex python functions
22997@cindex python module
22998@cindex gdb module
22999@value{GDBN} introduces a new Python module, named @code{gdb}. All
23000methods and classes added by @value{GDBN} are placed in this module.
23001@value{GDBN} automatically @code{import}s the @code{gdb} module for
23002use in all scripts evaluated by the @code{python} command.
23003
9279c692 23004@findex gdb.PYTHONDIR
d812018b 23005@defvar gdb.PYTHONDIR
9279c692
JB
23006A string containing the python directory (@pxref{Python}).
23007@end defvar
23008
d57a3c85 23009@findex gdb.execute
d812018b 23010@defun gdb.execute (command @r{[}, from_tty @r{[}, to_string@r{]]})
d57a3c85
TJB
23011Evaluate @var{command}, a string, as a @value{GDBN} CLI command.
23012If a GDB exception happens while @var{command} runs, it is
23013translated as described in @ref{Exception Handling,,Exception Handling}.
12453b93
TJB
23014
23015@var{from_tty} specifies whether @value{GDBN} ought to consider this
23016command as having originated from the user invoking it interactively.
23017It must be a boolean value. If omitted, it defaults to @code{False}.
bc9f0842
TT
23018
23019By default, any output produced by @var{command} is sent to
23020@value{GDBN}'s standard output. If the @var{to_string} parameter is
23021@code{True}, then output will be collected by @code{gdb.execute} and
23022returned as a string. The default is @code{False}, in which case the
5da1313b
JK
23023return value is @code{None}. If @var{to_string} is @code{True}, the
23024@value{GDBN} virtual terminal will be temporarily set to unlimited width
23025and height, and its pagination will be disabled; @pxref{Screen Size}.
d57a3c85
TJB
23026@end defun
23027
adc36818 23028@findex gdb.breakpoints
d812018b 23029@defun gdb.breakpoints ()
adc36818
PM
23030Return a sequence holding all of @value{GDBN}'s breakpoints.
23031@xref{Breakpoints In Python}, for more information.
23032@end defun
23033
8f500870 23034@findex gdb.parameter
d812018b 23035@defun gdb.parameter (parameter)
d57a3c85
TJB
23036Return the value of a @value{GDBN} parameter. @var{parameter} is a
23037string naming the parameter to look up; @var{parameter} may contain
23038spaces if the parameter has a multi-part name. For example,
23039@samp{print object} is a valid parameter name.
23040
23041If the named parameter does not exist, this function throws a
621c8364
TT
23042@code{gdb.error} (@pxref{Exception Handling}). Otherwise, the
23043parameter's value is converted to a Python value of the appropriate
23044type, and returned.
d57a3c85
TJB
23045@end defun
23046
08c637de 23047@findex gdb.history
d812018b 23048@defun gdb.history (number)
08c637de
TJB
23049Return a value from @value{GDBN}'s value history (@pxref{Value
23050History}). @var{number} indicates which history element to return.
23051If @var{number} is negative, then @value{GDBN} will take its absolute value
23052and count backward from the last element (i.e., the most recent element) to
23053find the value to return. If @var{number} is zero, then @value{GDBN} will
a0c36267 23054return the most recent element. If the element specified by @var{number}
621c8364 23055doesn't exist in the value history, a @code{gdb.error} exception will be
08c637de
TJB
23056raised.
23057
23058If no exception is raised, the return value is always an instance of
23059@code{gdb.Value} (@pxref{Values From Inferior}).
23060@end defun
23061
57a1d736 23062@findex gdb.parse_and_eval
d812018b 23063@defun gdb.parse_and_eval (expression)
57a1d736
TT
23064Parse @var{expression} as an expression in the current language,
23065evaluate it, and return the result as a @code{gdb.Value}.
23066@var{expression} must be a string.
23067
23068This function can be useful when implementing a new command
23069(@pxref{Commands In Python}), as it provides a way to parse the
23070command's argument as an expression. It is also useful simply to
23071compute values, for example, it is the only way to get the value of a
23072convenience variable (@pxref{Convenience Vars}) as a @code{gdb.Value}.
23073@end defun
23074
7efc75aa
SCR
23075@findex gdb.find_pc_line
23076@defun gdb.find_pc_line (pc)
23077Return the @code{gdb.Symtab_and_line} object corresponding to the
23078@var{pc} value. @xref{Symbol Tables In Python}. If an invalid
23079value of @var{pc} is passed as an argument, then the @code{symtab} and
23080@code{line} attributes of the returned @code{gdb.Symtab_and_line} object
23081will be @code{None} and 0 respectively.
23082@end defun
23083
ca5c20b6 23084@findex gdb.post_event
d812018b 23085@defun gdb.post_event (event)
ca5c20b6
PM
23086Put @var{event}, a callable object taking no arguments, into
23087@value{GDBN}'s internal event queue. This callable will be invoked at
23088some later point, during @value{GDBN}'s event processing. Events
23089posted using @code{post_event} will be run in the order in which they
23090were posted; however, there is no way to know when they will be
23091processed relative to other events inside @value{GDBN}.
23092
23093@value{GDBN} is not thread-safe. If your Python program uses multiple
23094threads, you must be careful to only call @value{GDBN}-specific
23095functions in the main @value{GDBN} thread. @code{post_event} ensures
23096this. For example:
23097
23098@smallexample
23099(@value{GDBP}) python
23100>import threading
23101>
23102>class Writer():
23103> def __init__(self, message):
23104> self.message = message;
23105> def __call__(self):
23106> gdb.write(self.message)
23107>
23108>class MyThread1 (threading.Thread):
23109> def run (self):
23110> gdb.post_event(Writer("Hello "))
23111>
23112>class MyThread2 (threading.Thread):
23113> def run (self):
23114> gdb.post_event(Writer("World\n"))
23115>
23116>MyThread1().start()
23117>MyThread2().start()
23118>end
23119(@value{GDBP}) Hello World
23120@end smallexample
23121@end defun
23122
99c3dc11 23123@findex gdb.write
d812018b 23124@defun gdb.write (string @r{[}, stream{]})
99c3dc11
PM
23125Print a string to @value{GDBN}'s paginated output stream. The
23126optional @var{stream} determines the stream to print to. The default
23127stream is @value{GDBN}'s standard output stream. Possible stream
23128values are:
23129
23130@table @code
23131@findex STDOUT
23132@findex gdb.STDOUT
d812018b 23133@item gdb.STDOUT
99c3dc11
PM
23134@value{GDBN}'s standard output stream.
23135
23136@findex STDERR
23137@findex gdb.STDERR
d812018b 23138@item gdb.STDERR
99c3dc11
PM
23139@value{GDBN}'s standard error stream.
23140
23141@findex STDLOG
23142@findex gdb.STDLOG
d812018b 23143@item gdb.STDLOG
99c3dc11
PM
23144@value{GDBN}'s log stream (@pxref{Logging Output}).
23145@end table
23146
d57a3c85 23147Writing to @code{sys.stdout} or @code{sys.stderr} will automatically
99c3dc11
PM
23148call this function and will automatically direct the output to the
23149relevant stream.
d57a3c85
TJB
23150@end defun
23151
23152@findex gdb.flush
d812018b 23153@defun gdb.flush ()
99c3dc11
PM
23154Flush the buffer of a @value{GDBN} paginated stream so that the
23155contents are displayed immediately. @value{GDBN} will flush the
23156contents of a stream automatically when it encounters a newline in the
23157buffer. The optional @var{stream} determines the stream to flush. The
23158default stream is @value{GDBN}'s standard output stream. Possible
23159stream values are:
23160
23161@table @code
23162@findex STDOUT
23163@findex gdb.STDOUT
d812018b 23164@item gdb.STDOUT
99c3dc11
PM
23165@value{GDBN}'s standard output stream.
23166
23167@findex STDERR
23168@findex gdb.STDERR
d812018b 23169@item gdb.STDERR
99c3dc11
PM
23170@value{GDBN}'s standard error stream.
23171
23172@findex STDLOG
23173@findex gdb.STDLOG
d812018b 23174@item gdb.STDLOG
99c3dc11
PM
23175@value{GDBN}'s log stream (@pxref{Logging Output}).
23176
23177@end table
23178
23179Flushing @code{sys.stdout} or @code{sys.stderr} will automatically
23180call this function for the relevant stream.
d57a3c85
TJB
23181@end defun
23182
f870a310 23183@findex gdb.target_charset
d812018b 23184@defun gdb.target_charset ()
f870a310
TT
23185Return the name of the current target character set (@pxref{Character
23186Sets}). This differs from @code{gdb.parameter('target-charset')} in
23187that @samp{auto} is never returned.
23188@end defun
23189
23190@findex gdb.target_wide_charset
d812018b 23191@defun gdb.target_wide_charset ()
f870a310
TT
23192Return the name of the current target wide character set
23193(@pxref{Character Sets}). This differs from
23194@code{gdb.parameter('target-wide-charset')} in that @samp{auto} is
23195never returned.
23196@end defun
23197
cb2e07a6 23198@findex gdb.solib_name
d812018b 23199@defun gdb.solib_name (address)
cb2e07a6
PM
23200Return the name of the shared library holding the given @var{address}
23201as a string, or @code{None}.
23202@end defun
23203
23204@findex gdb.decode_line
d812018b 23205@defun gdb.decode_line @r{[}expression@r{]}
cb2e07a6
PM
23206Return locations of the line specified by @var{expression}, or of the
23207current line if no argument was given. This function returns a Python
23208tuple containing two elements. The first element contains a string
23209holding any unparsed section of @var{expression} (or @code{None} if
23210the expression has been fully parsed). The second element contains
23211either @code{None} or another tuple that contains all the locations
23212that match the expression represented as @code{gdb.Symtab_and_line}
23213objects (@pxref{Symbol Tables In Python}). If @var{expression} is
23214provided, it is decoded the way that @value{GDBN}'s inbuilt
23215@code{break} or @code{edit} commands do (@pxref{Specify Location}).
23216@end defun
23217
d812018b 23218@defun gdb.prompt_hook (current_prompt)
fa3a4f15
PM
23219@anchor{prompt_hook}
23220
d17b6f81
PM
23221If @var{prompt_hook} is callable, @value{GDBN} will call the method
23222assigned to this operation before a prompt is displayed by
23223@value{GDBN}.
23224
23225The parameter @code{current_prompt} contains the current @value{GDBN}
23226prompt. This method must return a Python string, or @code{None}. If
23227a string is returned, the @value{GDBN} prompt will be set to that
23228string. If @code{None} is returned, @value{GDBN} will continue to use
23229the current prompt.
23230
23231Some prompts cannot be substituted in @value{GDBN}. Secondary prompts
23232such as those used by readline for command input, and annotation
23233related prompts are prohibited from being changed.
d812018b 23234@end defun
d17b6f81 23235
d57a3c85
TJB
23236@node Exception Handling
23237@subsubsection Exception Handling
23238@cindex python exceptions
23239@cindex exceptions, python
23240
23241When executing the @code{python} command, Python exceptions
23242uncaught within the Python code are translated to calls to
23243@value{GDBN} error-reporting mechanism. If the command that called
23244@code{python} does not handle the error, @value{GDBN} will
23245terminate it and print an error message containing the Python
23246exception name, the associated value, and the Python call stack
23247backtrace at the point where the exception was raised. Example:
23248
23249@smallexample
23250(@value{GDBP}) python print foo
23251Traceback (most recent call last):
23252 File "<string>", line 1, in <module>
23253NameError: name 'foo' is not defined
23254@end smallexample
23255
621c8364
TT
23256@value{GDBN} errors that happen in @value{GDBN} commands invoked by
23257Python code are converted to Python exceptions. The type of the
23258Python exception depends on the error.
23259
23260@ftable @code
23261@item gdb.error
23262This is the base class for most exceptions generated by @value{GDBN}.
23263It is derived from @code{RuntimeError}, for compatibility with earlier
23264versions of @value{GDBN}.
23265
23266If an error occurring in @value{GDBN} does not fit into some more
23267specific category, then the generated exception will have this type.
23268
23269@item gdb.MemoryError
23270This is a subclass of @code{gdb.error} which is thrown when an
23271operation tried to access invalid memory in the inferior.
23272
23273@item KeyboardInterrupt
23274User interrupt (via @kbd{C-c} or by typing @kbd{q} at a pagination
23275prompt) is translated to a Python @code{KeyboardInterrupt} exception.
23276@end ftable
23277
23278In all cases, your exception handler will see the @value{GDBN} error
23279message as its value and the Python call stack backtrace at the Python
23280statement closest to where the @value{GDBN} error occured as the
d57a3c85
TJB
23281traceback.
23282
07ca107c
DE
23283@findex gdb.GdbError
23284When implementing @value{GDBN} commands in Python via @code{gdb.Command},
23285it is useful to be able to throw an exception that doesn't cause a
23286traceback to be printed. For example, the user may have invoked the
23287command incorrectly. Use the @code{gdb.GdbError} exception
23288to handle this case. Example:
23289
23290@smallexample
23291(gdb) python
23292>class HelloWorld (gdb.Command):
23293> """Greet the whole world."""
23294> def __init__ (self):
7d74f244 23295> super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
07ca107c
DE
23296> def invoke (self, args, from_tty):
23297> argv = gdb.string_to_argv (args)
23298> if len (argv) != 0:
23299> raise gdb.GdbError ("hello-world takes no arguments")
23300> print "Hello, World!"
23301>HelloWorld ()
23302>end
23303(gdb) hello-world 42
23304hello-world takes no arguments
23305@end smallexample
23306
a08702d6
TJB
23307@node Values From Inferior
23308@subsubsection Values From Inferior
23309@cindex values from inferior, with Python
23310@cindex python, working with values from inferior
23311
23312@cindex @code{gdb.Value}
23313@value{GDBN} provides values it obtains from the inferior program in
23314an object of type @code{gdb.Value}. @value{GDBN} uses this object
23315for its internal bookkeeping of the inferior's values, and for
23316fetching values when necessary.
23317
23318Inferior values that are simple scalars can be used directly in
23319Python expressions that are valid for the value's data type. Here's
23320an example for an integer or floating-point value @code{some_val}:
23321
23322@smallexample
23323bar = some_val + 2
23324@end smallexample
23325
23326@noindent
23327As result of this, @code{bar} will also be a @code{gdb.Value} object
23328whose values are of the same type as those of @code{some_val}.
23329
23330Inferior values that are structures or instances of some class can
23331be accessed using the Python @dfn{dictionary syntax}. For example, if
23332@code{some_val} is a @code{gdb.Value} instance holding a structure, you
23333can access its @code{foo} element with:
23334
23335@smallexample
23336bar = some_val['foo']
23337@end smallexample
23338
23339Again, @code{bar} will also be a @code{gdb.Value} object.
23340
5374244e
PM
23341A @code{gdb.Value} that represents a function can be executed via
23342inferior function call. Any arguments provided to the call must match
23343the function's prototype, and must be provided in the order specified
23344by that prototype.
23345
23346For example, @code{some_val} is a @code{gdb.Value} instance
23347representing a function that takes two integers as arguments. To
23348execute this function, call it like so:
23349
23350@smallexample
23351result = some_val (10,20)
23352@end smallexample
23353
23354Any values returned from a function call will be stored as a
23355@code{gdb.Value}.
23356
c0c6f777 23357The following attributes are provided:
a08702d6 23358
d812018b 23359@defvar Value.address
c0c6f777
TJB
23360If this object is addressable, this read-only attribute holds a
23361@code{gdb.Value} object representing the address. Otherwise,
23362this attribute holds @code{None}.
d812018b 23363@end defvar
c0c6f777 23364
def2b000 23365@cindex optimized out value in Python
d812018b 23366@defvar Value.is_optimized_out
def2b000
TJB
23367This read-only boolean attribute is true if the compiler optimized out
23368this value, thus it is not available for fetching from the inferior.
d812018b 23369@end defvar
2c74e833 23370
d812018b 23371@defvar Value.type
2c74e833 23372The type of this @code{gdb.Value}. The value of this attribute is a
44592cc4 23373@code{gdb.Type} object (@pxref{Types In Python}).
d812018b 23374@end defvar
03f17ccf 23375
d812018b 23376@defvar Value.dynamic_type
03f17ccf 23377The dynamic type of this @code{gdb.Value}. This uses C@t{++} run-time
fccd1d1e
EZ
23378type information (@acronym{RTTI}) to determine the dynamic type of the
23379value. If this value is of class type, it will return the class in
23380which the value is embedded, if any. If this value is of pointer or
23381reference to a class type, it will compute the dynamic type of the
23382referenced object, and return a pointer or reference to that type,
23383respectively. In all other cases, it will return the value's static
23384type.
23385
23386Note that this feature will only work when debugging a C@t{++} program
23387that includes @acronym{RTTI} for the object in question. Otherwise,
23388it will just return the static type of the value as in @kbd{ptype foo}
23389(@pxref{Symbols, ptype}).
d812018b 23390@end defvar
22dbab46
PK
23391
23392@defvar Value.is_lazy
23393The value of this read-only boolean attribute is @code{True} if this
23394@code{gdb.Value} has not yet been fetched from the inferior.
23395@value{GDBN} does not fetch values until necessary, for efficiency.
23396For example:
23397
23398@smallexample
23399myval = gdb.parse_and_eval ('somevar')
23400@end smallexample
23401
23402The value of @code{somevar} is not fetched at this time. It will be
23403fetched when the value is needed, or when the @code{fetch_lazy}
23404method is invoked.
23405@end defvar
def2b000
TJB
23406
23407The following methods are provided:
23408
d812018b 23409@defun Value.__init__ (@var{val})
e8467610
TT
23410Many Python values can be converted directly to a @code{gdb.Value} via
23411this object initializer. Specifically:
23412
23413@table @asis
23414@item Python boolean
23415A Python boolean is converted to the boolean type from the current
23416language.
23417
23418@item Python integer
23419A Python integer is converted to the C @code{long} type for the
23420current architecture.
23421
23422@item Python long
23423A Python long is converted to the C @code{long long} type for the
23424current architecture.
23425
23426@item Python float
23427A Python float is converted to the C @code{double} type for the
23428current architecture.
23429
23430@item Python string
23431A Python string is converted to a target string, using the current
23432target encoding.
23433
23434@item @code{gdb.Value}
23435If @code{val} is a @code{gdb.Value}, then a copy of the value is made.
23436
23437@item @code{gdb.LazyString}
23438If @code{val} is a @code{gdb.LazyString} (@pxref{Lazy Strings In
23439Python}), then the lazy string's @code{value} method is called, and
23440its result is used.
23441@end table
d812018b 23442@end defun
e8467610 23443
d812018b 23444@defun Value.cast (type)
14ff2235
PM
23445Return a new instance of @code{gdb.Value} that is the result of
23446casting this instance to the type described by @var{type}, which must
23447be a @code{gdb.Type} object. If the cast cannot be performed for some
23448reason, this method throws an exception.
d812018b 23449@end defun
14ff2235 23450
d812018b 23451@defun Value.dereference ()
def2b000
TJB
23452For pointer data types, this method returns a new @code{gdb.Value} object
23453whose contents is the object pointed to by the pointer. For example, if
23454@code{foo} is a C pointer to an @code{int}, declared in your C program as
a08702d6
TJB
23455
23456@smallexample
23457int *foo;
23458@end smallexample
23459
23460@noindent
23461then you can use the corresponding @code{gdb.Value} to access what
23462@code{foo} points to like this:
23463
23464@smallexample
23465bar = foo.dereference ()
23466@end smallexample
23467
23468The result @code{bar} will be a @code{gdb.Value} object holding the
23469value pointed to by @code{foo}.
7b282c5a
SCR
23470
23471A similar function @code{Value.referenced_value} exists which also
23472returns @code{gdb.Value} objects corresonding to the values pointed to
23473by pointer values (and additionally, values referenced by reference
23474values). However, the behavior of @code{Value.dereference}
23475differs from @code{Value.referenced_value} by the fact that the
23476behavior of @code{Value.dereference} is identical to applying the C
23477unary operator @code{*} on a given value. For example, consider a
23478reference to a pointer @code{ptrref}, declared in your C@t{++} program
23479as
23480
23481@smallexample
23482typedef int *intptr;
23483...
23484int val = 10;
23485intptr ptr = &val;
23486intptr &ptrref = ptr;
23487@end smallexample
23488
23489Though @code{ptrref} is a reference value, one can apply the method
23490@code{Value.dereference} to the @code{gdb.Value} object corresponding
23491to it and obtain a @code{gdb.Value} which is identical to that
23492corresponding to @code{val}. However, if you apply the method
23493@code{Value.referenced_value}, the result would be a @code{gdb.Value}
23494object identical to that corresponding to @code{ptr}.
23495
23496@smallexample
23497py_ptrref = gdb.parse_and_eval ("ptrref")
23498py_val = py_ptrref.dereference ()
23499py_ptr = py_ptrref.referenced_value ()
23500@end smallexample
23501
23502The @code{gdb.Value} object @code{py_val} is identical to that
23503corresponding to @code{val}, and @code{py_ptr} is identical to that
23504corresponding to @code{ptr}. In general, @code{Value.dereference} can
23505be applied whenever the C unary operator @code{*} can be applied
23506to the corresponding C value. For those cases where applying both
23507@code{Value.dereference} and @code{Value.referenced_value} is allowed,
23508the results obtained need not be identical (as we have seen in the above
23509example). The results are however identical when applied on
23510@code{gdb.Value} objects corresponding to pointers (@code{gdb.Value}
23511objects with type code @code{TYPE_CODE_PTR}) in a C/C@t{++} program.
23512@end defun
23513
23514@defun Value.referenced_value ()
23515For pointer or reference data types, this method returns a new
23516@code{gdb.Value} object corresponding to the value referenced by the
23517pointer/reference value. For pointer data types,
23518@code{Value.dereference} and @code{Value.referenced_value} produce
23519identical results. The difference between these methods is that
23520@code{Value.dereference} cannot get the values referenced by reference
23521values. For example, consider a reference to an @code{int}, declared
23522in your C@t{++} program as
23523
23524@smallexample
23525int val = 10;
23526int &ref = val;
23527@end smallexample
23528
23529@noindent
23530then applying @code{Value.dereference} to the @code{gdb.Value} object
23531corresponding to @code{ref} will result in an error, while applying
23532@code{Value.referenced_value} will result in a @code{gdb.Value} object
23533identical to that corresponding to @code{val}.
23534
23535@smallexample
23536py_ref = gdb.parse_and_eval ("ref")
23537er_ref = py_ref.dereference () # Results in error
23538py_val = py_ref.referenced_value () # Returns the referenced value
23539@end smallexample
23540
23541The @code{gdb.Value} object @code{py_val} is identical to that
23542corresponding to @code{val}.
d812018b 23543@end defun
a08702d6 23544
d812018b 23545@defun Value.dynamic_cast (type)
f9ffd4bb
TT
23546Like @code{Value.cast}, but works as if the C@t{++} @code{dynamic_cast}
23547operator were used. Consult a C@t{++} reference for details.
d812018b 23548@end defun
f9ffd4bb 23549
d812018b 23550@defun Value.reinterpret_cast (type)
f9ffd4bb
TT
23551Like @code{Value.cast}, but works as if the C@t{++} @code{reinterpret_cast}
23552operator were used. Consult a C@t{++} reference for details.
d812018b 23553@end defun
f9ffd4bb 23554
d812018b 23555@defun Value.string (@r{[}encoding@r{[}, errors@r{[}, length@r{]]]})
b6cb8e7d
TJB
23556If this @code{gdb.Value} represents a string, then this method
23557converts the contents to a Python string. Otherwise, this method will
23558throw an exception.
23559
23560Strings are recognized in a language-specific way; whether a given
23561@code{gdb.Value} represents a string is determined by the current
23562language.
23563
23564For C-like languages, a value is a string if it is a pointer to or an
23565array of characters or ints. The string is assumed to be terminated
fbb8f299
PM
23566by a zero of the appropriate width. However if the optional length
23567argument is given, the string will be converted to that given length,
23568ignoring any embedded zeros that the string may contain.
b6cb8e7d
TJB
23569
23570If the optional @var{encoding} argument is given, it must be a string
23571naming the encoding of the string in the @code{gdb.Value}, such as
23572@code{"ascii"}, @code{"iso-8859-6"} or @code{"utf-8"}. It accepts
23573the same encodings as the corresponding argument to Python's
23574@code{string.decode} method, and the Python codec machinery will be used
23575to convert the string. If @var{encoding} is not given, or if
23576@var{encoding} is the empty string, then either the @code{target-charset}
23577(@pxref{Character Sets}) will be used, or a language-specific encoding
23578will be used, if the current language is able to supply one.
23579
23580The optional @var{errors} argument is the same as the corresponding
23581argument to Python's @code{string.decode} method.
fbb8f299
PM
23582
23583If the optional @var{length} argument is given, the string will be
23584fetched and converted to the given length.
d812018b 23585@end defun
be759fcf 23586
d812018b 23587@defun Value.lazy_string (@r{[}encoding @r{[}, length@r{]]})
be759fcf
PM
23588If this @code{gdb.Value} represents a string, then this method
23589converts the contents to a @code{gdb.LazyString} (@pxref{Lazy Strings
23590In Python}). Otherwise, this method will throw an exception.
23591
23592If the optional @var{encoding} argument is given, it must be a string
23593naming the encoding of the @code{gdb.LazyString}. Some examples are:
23594@samp{ascii}, @samp{iso-8859-6} or @samp{utf-8}. If the
23595@var{encoding} argument is an encoding that @value{GDBN} does
23596recognize, @value{GDBN} will raise an error.
23597
23598When a lazy string is printed, the @value{GDBN} encoding machinery is
23599used to convert the string during printing. If the optional
23600@var{encoding} argument is not provided, or is an empty string,
23601@value{GDBN} will automatically select the encoding most suitable for
23602the string type. For further information on encoding in @value{GDBN}
23603please see @ref{Character Sets}.
23604
23605If the optional @var{length} argument is given, the string will be
23606fetched and encoded to the length of characters specified. If
23607the @var{length} argument is not provided, the string will be fetched
23608and encoded until a null of appropriate width is found.
d812018b 23609@end defun
22dbab46
PK
23610
23611@defun Value.fetch_lazy ()
23612If the @code{gdb.Value} object is currently a lazy value
23613(@code{gdb.Value.is_lazy} is @code{True}), then the value is
23614fetched from the inferior. Any errors that occur in the process
23615will produce a Python exception.
23616
23617If the @code{gdb.Value} object is not a lazy value, this method
23618has no effect.
23619
23620This method does not return a value.
23621@end defun
23622
b6cb8e7d 23623
2c74e833
TT
23624@node Types In Python
23625@subsubsection Types In Python
23626@cindex types in Python
23627@cindex Python, working with types
23628
23629@tindex gdb.Type
23630@value{GDBN} represents types from the inferior using the class
23631@code{gdb.Type}.
23632
23633The following type-related functions are available in the @code{gdb}
23634module:
23635
23636@findex gdb.lookup_type
d812018b 23637@defun gdb.lookup_type (name @r{[}, block@r{]})
2c74e833
TT
23638This function looks up a type by name. @var{name} is the name of the
23639type to look up. It must be a string.
23640
5107b149
PM
23641If @var{block} is given, then @var{name} is looked up in that scope.
23642Otherwise, it is searched for globally.
23643
2c74e833
TT
23644Ordinarily, this function will return an instance of @code{gdb.Type}.
23645If the named type cannot be found, it will throw an exception.
23646@end defun
23647
a73bb892
PK
23648If the type is a structure or class type, or an enum type, the fields
23649of that type can be accessed using the Python @dfn{dictionary syntax}.
23650For example, if @code{some_type} is a @code{gdb.Type} instance holding
23651a structure type, you can access its @code{foo} field with:
23652
23653@smallexample
23654bar = some_type['foo']
23655@end smallexample
23656
23657@code{bar} will be a @code{gdb.Field} object; see below under the
23658description of the @code{Type.fields} method for a description of the
23659@code{gdb.Field} class.
23660
2c74e833
TT
23661An instance of @code{Type} has the following attributes:
23662
d812018b 23663@defvar Type.code
2c74e833
TT
23664The type code for this type. The type code will be one of the
23665@code{TYPE_CODE_} constants defined below.
d812018b 23666@end defvar
2c74e833 23667
d812018b 23668@defvar Type.sizeof
2c74e833
TT
23669The size of this type, in target @code{char} units. Usually, a
23670target's @code{char} type will be an 8-bit byte. However, on some
23671unusual platforms, this type may have a different size.
d812018b 23672@end defvar
2c74e833 23673
d812018b 23674@defvar Type.tag
2c74e833
TT
23675The tag name for this type. The tag name is the name after
23676@code{struct}, @code{union}, or @code{enum} in C and C@t{++}; not all
23677languages have this concept. If this type has no tag name, then
23678@code{None} is returned.
d812018b 23679@end defvar
2c74e833
TT
23680
23681The following methods are provided:
23682
d812018b 23683@defun Type.fields ()
2c74e833
TT
23684For structure and union types, this method returns the fields. Range
23685types have two fields, the minimum and maximum values. Enum types
23686have one field per enum constant. Function and method types have one
23687field per parameter. The base types of C@t{++} classes are also
23688represented as fields. If the type has no fields, or does not fit
23689into one of these categories, an empty sequence will be returned.
23690
a73bb892 23691Each field is a @code{gdb.Field} object, with some pre-defined attributes:
2c74e833
TT
23692@table @code
23693@item bitpos
23694This attribute is not available for @code{static} fields (as in
23695C@t{++} or Java). For non-@code{static} fields, the value is the bit
a9f54f60
TT
23696position of the field. For @code{enum} fields, the value is the
23697enumeration member's integer representation.
2c74e833
TT
23698
23699@item name
23700The name of the field, or @code{None} for anonymous fields.
23701
23702@item artificial
23703This is @code{True} if the field is artificial, usually meaning that
23704it was provided by the compiler and not the user. This attribute is
23705always provided, and is @code{False} if the field is not artificial.
23706
bfd31e71
PM
23707@item is_base_class
23708This is @code{True} if the field represents a base class of a C@t{++}
23709structure. This attribute is always provided, and is @code{False}
23710if the field is not a base class of the type that is the argument of
23711@code{fields}, or if that type was not a C@t{++} class.
23712
2c74e833
TT
23713@item bitsize
23714If the field is packed, or is a bitfield, then this will have a
23715non-zero value, which is the size of the field in bits. Otherwise,
23716this will be zero; in this case the field's size is given by its type.
23717
23718@item type
23719The type of the field. This is usually an instance of @code{Type},
23720but it can be @code{None} in some situations.
23721@end table
d812018b 23722@end defun
2c74e833 23723
d812018b 23724@defun Type.array (@var{n1} @r{[}, @var{n2}@r{]})
702c2711
TT
23725Return a new @code{gdb.Type} object which represents an array of this
23726type. If one argument is given, it is the inclusive upper bound of
23727the array; in this case the lower bound is zero. If two arguments are
23728given, the first argument is the lower bound of the array, and the
23729second argument is the upper bound of the array. An array's length
23730must not be negative, but the bounds can be.
d812018b 23731@end defun
702c2711 23732
a72c3253
DE
23733@defun Type.vector (@var{n1} @r{[}, @var{n2}@r{]})
23734Return a new @code{gdb.Type} object which represents a vector of this
23735type. If one argument is given, it is the inclusive upper bound of
23736the vector; in this case the lower bound is zero. If two arguments are
23737given, the first argument is the lower bound of the vector, and the
23738second argument is the upper bound of the vector. A vector's length
23739must not be negative, but the bounds can be.
23740
23741The difference between an @code{array} and a @code{vector} is that
23742arrays behave like in C: when used in expressions they decay to a pointer
23743to the first element whereas vectors are treated as first class values.
23744@end defun
23745
d812018b 23746@defun Type.const ()
2c74e833
TT
23747Return a new @code{gdb.Type} object which represents a
23748@code{const}-qualified variant of this type.
d812018b 23749@end defun
2c74e833 23750
d812018b 23751@defun Type.volatile ()
2c74e833
TT
23752Return a new @code{gdb.Type} object which represents a
23753@code{volatile}-qualified variant of this type.
d812018b 23754@end defun
2c74e833 23755
d812018b 23756@defun Type.unqualified ()
2c74e833
TT
23757Return a new @code{gdb.Type} object which represents an unqualified
23758variant of this type. That is, the result is neither @code{const} nor
23759@code{volatile}.
d812018b 23760@end defun
2c74e833 23761
d812018b 23762@defun Type.range ()
361ae042
PM
23763Return a Python @code{Tuple} object that contains two elements: the
23764low bound of the argument type and the high bound of that type. If
23765the type does not have a range, @value{GDBN} will raise a
621c8364 23766@code{gdb.error} exception (@pxref{Exception Handling}).
d812018b 23767@end defun
361ae042 23768
d812018b 23769@defun Type.reference ()
2c74e833
TT
23770Return a new @code{gdb.Type} object which represents a reference to this
23771type.
d812018b 23772@end defun
2c74e833 23773
d812018b 23774@defun Type.pointer ()
7a6973ad
TT
23775Return a new @code{gdb.Type} object which represents a pointer to this
23776type.
d812018b 23777@end defun
7a6973ad 23778
d812018b 23779@defun Type.strip_typedefs ()
2c74e833
TT
23780Return a new @code{gdb.Type} that represents the real type,
23781after removing all layers of typedefs.
d812018b 23782@end defun
2c74e833 23783
d812018b 23784@defun Type.target ()
2c74e833
TT
23785Return a new @code{gdb.Type} object which represents the target type
23786of this type.
23787
23788For a pointer type, the target type is the type of the pointed-to
23789object. For an array type (meaning C-like arrays), the target type is
23790the type of the elements of the array. For a function or method type,
23791the target type is the type of the return value. For a complex type,
23792the target type is the type of the elements. For a typedef, the
23793target type is the aliased type.
23794
23795If the type does not have a target, this method will throw an
23796exception.
d812018b 23797@end defun
2c74e833 23798
d812018b 23799@defun Type.template_argument (n @r{[}, block@r{]})
2c74e833
TT
23800If this @code{gdb.Type} is an instantiation of a template, this will
23801return a new @code{gdb.Type} which represents the type of the
23802@var{n}th template argument.
23803
23804If this @code{gdb.Type} is not a template type, this will throw an
23805exception. Ordinarily, only C@t{++} code will have template types.
23806
5107b149
PM
23807If @var{block} is given, then @var{name} is looked up in that scope.
23808Otherwise, it is searched for globally.
d812018b 23809@end defun
2c74e833
TT
23810
23811
23812Each type has a code, which indicates what category this type falls
23813into. The available type categories are represented by constants
23814defined in the @code{gdb} module:
23815
23816@table @code
23817@findex TYPE_CODE_PTR
23818@findex gdb.TYPE_CODE_PTR
d812018b 23819@item gdb.TYPE_CODE_PTR
2c74e833
TT
23820The type is a pointer.
23821
23822@findex TYPE_CODE_ARRAY
23823@findex gdb.TYPE_CODE_ARRAY
d812018b 23824@item gdb.TYPE_CODE_ARRAY
2c74e833
TT
23825The type is an array.
23826
23827@findex TYPE_CODE_STRUCT
23828@findex gdb.TYPE_CODE_STRUCT
d812018b 23829@item gdb.TYPE_CODE_STRUCT
2c74e833
TT
23830The type is a structure.
23831
23832@findex TYPE_CODE_UNION
23833@findex gdb.TYPE_CODE_UNION
d812018b 23834@item gdb.TYPE_CODE_UNION
2c74e833
TT
23835The type is a union.
23836
23837@findex TYPE_CODE_ENUM
23838@findex gdb.TYPE_CODE_ENUM
d812018b 23839@item gdb.TYPE_CODE_ENUM
2c74e833
TT
23840The type is an enum.
23841
23842@findex TYPE_CODE_FLAGS
23843@findex gdb.TYPE_CODE_FLAGS
d812018b 23844@item gdb.TYPE_CODE_FLAGS
2c74e833
TT
23845A bit flags type, used for things such as status registers.
23846
23847@findex TYPE_CODE_FUNC
23848@findex gdb.TYPE_CODE_FUNC
d812018b 23849@item gdb.TYPE_CODE_FUNC
2c74e833
TT
23850The type is a function.
23851
23852@findex TYPE_CODE_INT
23853@findex gdb.TYPE_CODE_INT
d812018b 23854@item gdb.TYPE_CODE_INT
2c74e833
TT
23855The type is an integer type.
23856
23857@findex TYPE_CODE_FLT
23858@findex gdb.TYPE_CODE_FLT
d812018b 23859@item gdb.TYPE_CODE_FLT
2c74e833
TT
23860A floating point type.
23861
23862@findex TYPE_CODE_VOID
23863@findex gdb.TYPE_CODE_VOID
d812018b 23864@item gdb.TYPE_CODE_VOID
2c74e833
TT
23865The special type @code{void}.
23866
23867@findex TYPE_CODE_SET
23868@findex gdb.TYPE_CODE_SET
d812018b 23869@item gdb.TYPE_CODE_SET
2c74e833
TT
23870A Pascal set type.
23871
23872@findex TYPE_CODE_RANGE
23873@findex gdb.TYPE_CODE_RANGE
d812018b 23874@item gdb.TYPE_CODE_RANGE
2c74e833
TT
23875A range type, that is, an integer type with bounds.
23876
23877@findex TYPE_CODE_STRING
23878@findex gdb.TYPE_CODE_STRING
d812018b 23879@item gdb.TYPE_CODE_STRING
2c74e833
TT
23880A string type. Note that this is only used for certain languages with
23881language-defined string types; C strings are not represented this way.
23882
23883@findex TYPE_CODE_BITSTRING
23884@findex gdb.TYPE_CODE_BITSTRING
d812018b 23885@item gdb.TYPE_CODE_BITSTRING
6b1755ce 23886A string of bits. It is deprecated.
2c74e833
TT
23887
23888@findex TYPE_CODE_ERROR
23889@findex gdb.TYPE_CODE_ERROR
d812018b 23890@item gdb.TYPE_CODE_ERROR
2c74e833
TT
23891An unknown or erroneous type.
23892
23893@findex TYPE_CODE_METHOD
23894@findex gdb.TYPE_CODE_METHOD
d812018b 23895@item gdb.TYPE_CODE_METHOD
2c74e833
TT
23896A method type, as found in C@t{++} or Java.
23897
23898@findex TYPE_CODE_METHODPTR
23899@findex gdb.TYPE_CODE_METHODPTR
d812018b 23900@item gdb.TYPE_CODE_METHODPTR
2c74e833
TT
23901A pointer-to-member-function.
23902
23903@findex TYPE_CODE_MEMBERPTR
23904@findex gdb.TYPE_CODE_MEMBERPTR
d812018b 23905@item gdb.TYPE_CODE_MEMBERPTR
2c74e833
TT
23906A pointer-to-member.
23907
23908@findex TYPE_CODE_REF
23909@findex gdb.TYPE_CODE_REF
d812018b 23910@item gdb.TYPE_CODE_REF
2c74e833
TT
23911A reference type.
23912
23913@findex TYPE_CODE_CHAR
23914@findex gdb.TYPE_CODE_CHAR
d812018b 23915@item gdb.TYPE_CODE_CHAR
2c74e833
TT
23916A character type.
23917
23918@findex TYPE_CODE_BOOL
23919@findex gdb.TYPE_CODE_BOOL
d812018b 23920@item gdb.TYPE_CODE_BOOL
2c74e833
TT
23921A boolean type.
23922
23923@findex TYPE_CODE_COMPLEX
23924@findex gdb.TYPE_CODE_COMPLEX
d812018b 23925@item gdb.TYPE_CODE_COMPLEX
2c74e833
TT
23926A complex float type.
23927
23928@findex TYPE_CODE_TYPEDEF
23929@findex gdb.TYPE_CODE_TYPEDEF
d812018b 23930@item gdb.TYPE_CODE_TYPEDEF
2c74e833
TT
23931A typedef to some other type.
23932
23933@findex TYPE_CODE_NAMESPACE
23934@findex gdb.TYPE_CODE_NAMESPACE
d812018b 23935@item gdb.TYPE_CODE_NAMESPACE
2c74e833
TT
23936A C@t{++} namespace.
23937
23938@findex TYPE_CODE_DECFLOAT
23939@findex gdb.TYPE_CODE_DECFLOAT
d812018b 23940@item gdb.TYPE_CODE_DECFLOAT
2c74e833
TT
23941A decimal floating point type.
23942
23943@findex TYPE_CODE_INTERNAL_FUNCTION
23944@findex gdb.TYPE_CODE_INTERNAL_FUNCTION
d812018b 23945@item gdb.TYPE_CODE_INTERNAL_FUNCTION
2c74e833
TT
23946A function internal to @value{GDBN}. This is the type used to represent
23947convenience functions.
23948@end table
23949
0e3509db
DE
23950Further support for types is provided in the @code{gdb.types}
23951Python module (@pxref{gdb.types}).
23952
4c374409
JK
23953@node Pretty Printing API
23954@subsubsection Pretty Printing API
a6bac58e 23955
4c374409 23956An example output is provided (@pxref{Pretty Printing}).
a6bac58e
TT
23957
23958A pretty-printer is just an object that holds a value and implements a
23959specific interface, defined here.
23960
d812018b 23961@defun pretty_printer.children (self)
a6bac58e
TT
23962@value{GDBN} will call this method on a pretty-printer to compute the
23963children of the pretty-printer's value.
23964
23965This method must return an object conforming to the Python iterator
23966protocol. Each item returned by the iterator must be a tuple holding
23967two elements. The first element is the ``name'' of the child; the
23968second element is the child's value. The value can be any Python
23969object which is convertible to a @value{GDBN} value.
23970
23971This method is optional. If it does not exist, @value{GDBN} will act
23972as though the value has no children.
d812018b 23973@end defun
a6bac58e 23974
d812018b 23975@defun pretty_printer.display_hint (self)
a6bac58e
TT
23976The CLI may call this method and use its result to change the
23977formatting of a value. The result will also be supplied to an MI
23978consumer as a @samp{displayhint} attribute of the variable being
23979printed.
23980
23981This method is optional. If it does exist, this method must return a
23982string.
23983
23984Some display hints are predefined by @value{GDBN}:
23985
23986@table @samp
23987@item array
23988Indicate that the object being printed is ``array-like''. The CLI
23989uses this to respect parameters such as @code{set print elements} and
23990@code{set print array}.
23991
23992@item map
23993Indicate that the object being printed is ``map-like'', and that the
23994children of this value can be assumed to alternate between keys and
23995values.
23996
23997@item string
23998Indicate that the object being printed is ``string-like''. If the
23999printer's @code{to_string} method returns a Python string of some
24000kind, then @value{GDBN} will call its internal language-specific
24001string-printing function to format the string. For the CLI this means
24002adding quotation marks, possibly escaping some characters, respecting
24003@code{set print elements}, and the like.
24004@end table
d812018b 24005@end defun
a6bac58e 24006
d812018b 24007@defun pretty_printer.to_string (self)
a6bac58e
TT
24008@value{GDBN} will call this method to display the string
24009representation of the value passed to the object's constructor.
24010
24011When printing from the CLI, if the @code{to_string} method exists,
24012then @value{GDBN} will prepend its result to the values returned by
24013@code{children}. Exactly how this formatting is done is dependent on
24014the display hint, and may change as more hints are added. Also,
24015depending on the print settings (@pxref{Print Settings}), the CLI may
24016print just the result of @code{to_string} in a stack trace, omitting
24017the result of @code{children}.
24018
24019If this method returns a string, it is printed verbatim.
24020
24021Otherwise, if this method returns an instance of @code{gdb.Value},
24022then @value{GDBN} prints this value. This may result in a call to
24023another pretty-printer.
24024
24025If instead the method returns a Python value which is convertible to a
24026@code{gdb.Value}, then @value{GDBN} performs the conversion and prints
24027the resulting value. Again, this may result in a call to another
24028pretty-printer. Python scalars (integers, floats, and booleans) and
24029strings are convertible to @code{gdb.Value}; other types are not.
24030
79f283fe
PM
24031Finally, if this method returns @code{None} then no further operations
24032are peformed in this method and nothing is printed.
24033
a6bac58e 24034If the result is not one of these types, an exception is raised.
d812018b 24035@end defun
a6bac58e 24036
464b3efb
TT
24037@value{GDBN} provides a function which can be used to look up the
24038default pretty-printer for a @code{gdb.Value}:
24039
24040@findex gdb.default_visualizer
d812018b 24041@defun gdb.default_visualizer (value)
464b3efb
TT
24042This function takes a @code{gdb.Value} object as an argument. If a
24043pretty-printer for this value exists, then it is returned. If no such
24044printer exists, then this returns @code{None}.
24045@end defun
24046
a6bac58e
TT
24047@node Selecting Pretty-Printers
24048@subsubsection Selecting Pretty-Printers
24049
24050The Python list @code{gdb.pretty_printers} contains an array of
967cf477 24051functions or callable objects that have been registered via addition
7b51bc51
DE
24052as a pretty-printer. Printers in this list are called @code{global}
24053printers, they're available when debugging all inferiors.
fa33c3cd 24054Each @code{gdb.Progspace} contains a @code{pretty_printers} attribute.
a6bac58e
TT
24055Each @code{gdb.Objfile} also contains a @code{pretty_printers}
24056attribute.
24057
7b51bc51 24058Each function on these lists is passed a single @code{gdb.Value}
a6bac58e 24059argument and should return a pretty-printer object conforming to the
4c374409 24060interface definition above (@pxref{Pretty Printing API}). If a function
a6bac58e
TT
24061cannot create a pretty-printer for the value, it should return
24062@code{None}.
24063
24064@value{GDBN} first checks the @code{pretty_printers} attribute of each
fa33c3cd 24065@code{gdb.Objfile} in the current program space and iteratively calls
7b51bc51
DE
24066each enabled lookup routine in the list for that @code{gdb.Objfile}
24067until it receives a pretty-printer object.
fa33c3cd
DE
24068If no pretty-printer is found in the objfile lists, @value{GDBN} then
24069searches the pretty-printer list of the current program space,
967cf477 24070calling each enabled function until an object is returned.
a6bac58e 24071After these lists have been exhausted, it tries the global
967cf477 24072@code{gdb.pretty_printers} list, again calling each enabled function until an
a6bac58e
TT
24073object is returned.
24074
24075The order in which the objfiles are searched is not specified. For a
24076given list, functions are always invoked from the head of the list,
24077and iterated over sequentially until the end of the list, or a printer
24078object is returned.
24079
7b51bc51
DE
24080For various reasons a pretty-printer may not work.
24081For example, the underlying data structure may have changed and
24082the pretty-printer is out of date.
24083
24084The consequences of a broken pretty-printer are severe enough that
24085@value{GDBN} provides support for enabling and disabling individual
24086printers. For example, if @code{print frame-arguments} is on,
24087a backtrace can become highly illegible if any argument is printed
24088with a broken printer.
24089
24090Pretty-printers are enabled and disabled by attaching an @code{enabled}
24091attribute to the registered function or callable object. If this attribute
24092is present and its value is @code{False}, the printer is disabled, otherwise
24093the printer is enabled.
24094
24095@node Writing a Pretty-Printer
24096@subsubsection Writing a Pretty-Printer
24097@cindex writing a pretty-printer
24098
24099A pretty-printer consists of two parts: a lookup function to detect
24100if the type is supported, and the printer itself.
24101
a6bac58e 24102Here is an example showing how a @code{std::string} printer might be
7b51bc51
DE
24103written. @xref{Pretty Printing API}, for details on the API this class
24104must provide.
a6bac58e
TT
24105
24106@smallexample
7b51bc51 24107class StdStringPrinter(object):
a6bac58e
TT
24108 "Print a std::string"
24109
7b51bc51 24110 def __init__(self, val):
a6bac58e
TT
24111 self.val = val
24112
7b51bc51 24113 def to_string(self):
a6bac58e
TT
24114 return self.val['_M_dataplus']['_M_p']
24115
7b51bc51 24116 def display_hint(self):
a6bac58e
TT
24117 return 'string'
24118@end smallexample
24119
24120And here is an example showing how a lookup function for the printer
24121example above might be written.
24122
24123@smallexample
7b51bc51 24124def str_lookup_function(val):
a6bac58e 24125 lookup_tag = val.type.tag
a6bac58e
TT
24126 if lookup_tag == None:
24127 return None
7b51bc51
DE
24128 regex = re.compile("^std::basic_string<char,.*>$")
24129 if regex.match(lookup_tag):
24130 return StdStringPrinter(val)
a6bac58e
TT
24131 return None
24132@end smallexample
24133
24134The example lookup function extracts the value's type, and attempts to
24135match it to a type that it can pretty-print. If it is a type the
24136printer can pretty-print, it will return a printer object. If not, it
24137returns @code{None}.
24138
24139We recommend that you put your core pretty-printers into a Python
24140package. If your pretty-printers are for use with a library, we
24141further recommend embedding a version number into the package name.
24142This practice will enable @value{GDBN} to load multiple versions of
24143your pretty-printers at the same time, because they will have
24144different names.
24145
bf88dd68 24146You should write auto-loaded code (@pxref{Python Auto-loading}) such that it
a6bac58e
TT
24147can be evaluated multiple times without changing its meaning. An
24148ideal auto-load file will consist solely of @code{import}s of your
24149printer modules, followed by a call to a register pretty-printers with
24150the current objfile.
24151
24152Taken as a whole, this approach will scale nicely to multiple
24153inferiors, each potentially using a different library version.
24154Embedding a version number in the Python package name will ensure that
24155@value{GDBN} is able to load both sets of printers simultaneously.
24156Then, because the search for pretty-printers is done by objfile, and
24157because your auto-loaded code took care to register your library's
24158printers with a specific objfile, @value{GDBN} will find the correct
24159printers for the specific version of the library used by each
24160inferior.
24161
4c374409 24162To continue the @code{std::string} example (@pxref{Pretty Printing API}),
a6bac58e
TT
24163this code might appear in @code{gdb.libstdcxx.v6}:
24164
24165@smallexample
7b51bc51 24166def register_printers(objfile):
ae6f0d5b 24167 objfile.pretty_printers.append(str_lookup_function)
a6bac58e
TT
24168@end smallexample
24169
24170@noindent
24171And then the corresponding contents of the auto-load file would be:
24172
24173@smallexample
24174import gdb.libstdcxx.v6
7b51bc51 24175gdb.libstdcxx.v6.register_printers(gdb.current_objfile())
a6bac58e
TT
24176@end smallexample
24177
7b51bc51
DE
24178The previous example illustrates a basic pretty-printer.
24179There are a few things that can be improved on.
24180The printer doesn't have a name, making it hard to identify in a
24181list of installed printers. The lookup function has a name, but
24182lookup functions can have arbitrary, even identical, names.
967cf477 24183
7b51bc51
DE
24184Second, the printer only handles one type, whereas a library typically has
24185several types. One could install a lookup function for each desired type
24186in the library, but one could also have a single lookup function recognize
24187several types. The latter is the conventional way this is handled.
24188If a pretty-printer can handle multiple data types, then its
24189@dfn{subprinters} are the printers for the individual data types.
967cf477 24190
7b51bc51
DE
24191The @code{gdb.printing} module provides a formal way of solving these
24192problems (@pxref{gdb.printing}).
24193Here is another example that handles multiple types.
967cf477 24194
7b51bc51
DE
24195These are the types we are going to pretty-print:
24196
24197@smallexample
24198struct foo @{ int a, b; @};
24199struct bar @{ struct foo x, y; @};
24200@end smallexample
24201
24202Here are the printers:
24203
24204@smallexample
24205class fooPrinter:
24206 """Print a foo object."""
24207
24208 def __init__(self, val):
24209 self.val = val
24210
24211 def to_string(self):
24212 return ("a=<" + str(self.val["a"]) +
24213 "> b=<" + str(self.val["b"]) + ">")
24214
24215class barPrinter:
24216 """Print a bar object."""
24217
24218 def __init__(self, val):
24219 self.val = val
24220
24221 def to_string(self):
24222 return ("x=<" + str(self.val["x"]) +
24223 "> y=<" + str(self.val["y"]) + ">")
24224@end smallexample
24225
24226This example doesn't need a lookup function, that is handled by the
24227@code{gdb.printing} module. Instead a function is provided to build up
24228the object that handles the lookup.
24229
24230@smallexample
24231import gdb.printing
24232
24233def build_pretty_printer():
24234 pp = gdb.printing.RegexpCollectionPrettyPrinter(
24235 "my_library")
24236 pp.add_printer('foo', '^foo$', fooPrinter)
24237 pp.add_printer('bar', '^bar$', barPrinter)
24238 return pp
24239@end smallexample
24240
24241And here is the autoload support:
24242
24243@smallexample
24244import gdb.printing
24245import my_library
24246gdb.printing.register_pretty_printer(
24247 gdb.current_objfile(),
24248 my_library.build_pretty_printer())
24249@end smallexample
24250
24251Finally, when this printer is loaded into @value{GDBN}, here is the
24252corresponding output of @samp{info pretty-printer}:
24253
24254@smallexample
24255(gdb) info pretty-printer
24256my_library.so:
24257 my_library
24258 foo
24259 bar
24260@end smallexample
967cf477 24261
18a9fc12
TT
24262@node Type Printing API
24263@subsubsection Type Printing API
24264@cindex type printing API for Python
24265
24266@value{GDBN} provides a way for Python code to customize type display.
24267This is mainly useful for substituting canonical typedef names for
24268types.
24269
24270@cindex type printer
24271A @dfn{type printer} is just a Python object conforming to a certain
24272protocol. A simple base class implementing the protocol is provided;
24273see @ref{gdb.types}. A type printer must supply at least:
24274
24275@defivar type_printer enabled
24276A boolean which is True if the printer is enabled, and False
24277otherwise. This is manipulated by the @code{enable type-printer}
24278and @code{disable type-printer} commands.
24279@end defivar
24280
24281@defivar type_printer name
24282The name of the type printer. This must be a string. This is used by
24283the @code{enable type-printer} and @code{disable type-printer}
24284commands.
24285@end defivar
24286
24287@defmethod type_printer instantiate (self)
24288This is called by @value{GDBN} at the start of type-printing. It is
24289only called if the type printer is enabled. This method must return a
24290new object that supplies a @code{recognize} method, as described below.
24291@end defmethod
24292
24293
24294When displaying a type, say via the @code{ptype} command, @value{GDBN}
24295will compute a list of type recognizers. This is done by iterating
24296first over the per-objfile type printers (@pxref{Objfiles In Python}),
24297followed by the per-progspace type printers (@pxref{Progspaces In
24298Python}), and finally the global type printers.
24299
24300@value{GDBN} will call the @code{instantiate} method of each enabled
24301type printer. If this method returns @code{None}, then the result is
24302ignored; otherwise, it is appended to the list of recognizers.
24303
24304Then, when @value{GDBN} is going to display a type name, it iterates
24305over the list of recognizers. For each one, it calls the recognition
24306function, stopping if the function returns a non-@code{None} value.
24307The recognition function is defined as:
24308
24309@defmethod type_recognizer recognize (self, type)
24310If @var{type} is not recognized, return @code{None}. Otherwise,
24311return a string which is to be printed as the name of @var{type}.
24312@var{type} will be an instance of @code{gdb.Type} (@pxref{Types In
24313Python}).
24314@end defmethod
24315
24316@value{GDBN} uses this two-pass approach so that type printers can
24317efficiently cache information without holding on to it too long. For
24318example, it can be convenient to look up type information in a type
24319printer and hold it for a recognizer's lifetime; if a single pass were
24320done then type printers would have to make use of the event system in
24321order to avoid holding information that could become stale as the
24322inferior changed.
24323
595939de
PM
24324@node Inferiors In Python
24325@subsubsection Inferiors In Python
505500db 24326@cindex inferiors in Python
595939de
PM
24327
24328@findex gdb.Inferior
24329Programs which are being run under @value{GDBN} are called inferiors
24330(@pxref{Inferiors and Programs}). Python scripts can access
24331information about and manipulate inferiors controlled by @value{GDBN}
24332via objects of the @code{gdb.Inferior} class.
24333
24334The following inferior-related functions are available in the @code{gdb}
24335module:
24336
d812018b 24337@defun gdb.inferiors ()
595939de
PM
24338Return a tuple containing all inferior objects.
24339@end defun
24340
d812018b 24341@defun gdb.selected_inferior ()
2aa48337
KP
24342Return an object representing the current inferior.
24343@end defun
24344
595939de
PM
24345A @code{gdb.Inferior} object has the following attributes:
24346
d812018b 24347@defvar Inferior.num
595939de 24348ID of inferior, as assigned by GDB.
d812018b 24349@end defvar
595939de 24350
d812018b 24351@defvar Inferior.pid
595939de
PM
24352Process ID of the inferior, as assigned by the underlying operating
24353system.
d812018b 24354@end defvar
595939de 24355
d812018b 24356@defvar Inferior.was_attached
595939de
PM
24357Boolean signaling whether the inferior was created using `attach', or
24358started by @value{GDBN} itself.
d812018b 24359@end defvar
595939de
PM
24360
24361A @code{gdb.Inferior} object has the following methods:
24362
d812018b 24363@defun Inferior.is_valid ()
29703da4
PM
24364Returns @code{True} if the @code{gdb.Inferior} object is valid,
24365@code{False} if not. A @code{gdb.Inferior} object will become invalid
24366if the inferior no longer exists within @value{GDBN}. All other
24367@code{gdb.Inferior} methods will throw an exception if it is invalid
24368at the time the method is called.
d812018b 24369@end defun
29703da4 24370
d812018b 24371@defun Inferior.threads ()
595939de
PM
24372This method returns a tuple holding all the threads which are valid
24373when it is called. If there are no valid threads, the method will
24374return an empty tuple.
d812018b 24375@end defun
595939de 24376
2678e2af 24377@findex Inferior.read_memory
d812018b 24378@defun Inferior.read_memory (address, length)
595939de
PM
24379Read @var{length} bytes of memory from the inferior, starting at
24380@var{address}. Returns a buffer object, which behaves much like an array
2678e2af 24381or a string. It can be modified and given to the
9a27f2c6
PK
24382@code{Inferior.write_memory} function. In @code{Python} 3, the return
24383value is a @code{memoryview} object.
d812018b 24384@end defun
595939de 24385
2678e2af 24386@findex Inferior.write_memory
d812018b 24387@defun Inferior.write_memory (address, buffer @r{[}, length@r{]})
595939de
PM
24388Write the contents of @var{buffer} to the inferior, starting at
24389@var{address}. The @var{buffer} parameter must be a Python object
24390which supports the buffer protocol, i.e., a string, an array or the
2678e2af 24391object returned from @code{Inferior.read_memory}. If given, @var{length}
595939de 24392determines the number of bytes from @var{buffer} to be written.
d812018b 24393@end defun
595939de
PM
24394
24395@findex gdb.search_memory
d812018b 24396@defun Inferior.search_memory (address, length, pattern)
595939de
PM
24397Search a region of the inferior memory starting at @var{address} with
24398the given @var{length} using the search pattern supplied in
24399@var{pattern}. The @var{pattern} parameter must be a Python object
24400which supports the buffer protocol, i.e., a string, an array or the
24401object returned from @code{gdb.read_memory}. Returns a Python @code{Long}
24402containing the address where the pattern was found, or @code{None} if
24403the pattern could not be found.
d812018b 24404@end defun
595939de 24405
505500db
SW
24406@node Events In Python
24407@subsubsection Events In Python
24408@cindex inferior events in Python
24409
24410@value{GDBN} provides a general event facility so that Python code can be
24411notified of various state changes, particularly changes that occur in
24412the inferior.
24413
24414An @dfn{event} is just an object that describes some state change. The
24415type of the object and its attributes will vary depending on the details
24416of the change. All the existing events are described below.
24417
24418In order to be notified of an event, you must register an event handler
24419with an @dfn{event registry}. An event registry is an object in the
24420@code{gdb.events} module which dispatches particular events. A registry
24421provides methods to register and unregister event handlers:
24422
d812018b 24423@defun EventRegistry.connect (object)
505500db
SW
24424Add the given callable @var{object} to the registry. This object will be
24425called when an event corresponding to this registry occurs.
d812018b 24426@end defun
505500db 24427
d812018b 24428@defun EventRegistry.disconnect (object)
505500db
SW
24429Remove the given @var{object} from the registry. Once removed, the object
24430will no longer receive notifications of events.
d812018b 24431@end defun
505500db
SW
24432
24433Here is an example:
24434
24435@smallexample
24436def exit_handler (event):
24437 print "event type: exit"
24438 print "exit code: %d" % (event.exit_code)
24439
24440gdb.events.exited.connect (exit_handler)
24441@end smallexample
24442
24443In the above example we connect our handler @code{exit_handler} to the
24444registry @code{events.exited}. Once connected, @code{exit_handler} gets
24445called when the inferior exits. The argument @dfn{event} in this example is
24446of type @code{gdb.ExitedEvent}. As you can see in the example the
24447@code{ExitedEvent} object has an attribute which indicates the exit code of
24448the inferior.
24449
24450The following is a listing of the event registries that are available and
24451details of the events they emit:
24452
24453@table @code
24454
24455@item events.cont
24456Emits @code{gdb.ThreadEvent}.
24457
24458Some events can be thread specific when @value{GDBN} is running in non-stop
24459mode. When represented in Python, these events all extend
24460@code{gdb.ThreadEvent}. Note, this event is not emitted directly; instead,
24461events which are emitted by this or other modules might extend this event.
24462Examples of these events are @code{gdb.BreakpointEvent} and
24463@code{gdb.ContinueEvent}.
24464
d812018b 24465@defvar ThreadEvent.inferior_thread
505500db
SW
24466In non-stop mode this attribute will be set to the specific thread which was
24467involved in the emitted event. Otherwise, it will be set to @code{None}.
d812018b 24468@end defvar
505500db
SW
24469
24470Emits @code{gdb.ContinueEvent} which extends @code{gdb.ThreadEvent}.
24471
24472This event indicates that the inferior has been continued after a stop. For
24473inherited attribute refer to @code{gdb.ThreadEvent} above.
24474
24475@item events.exited
24476Emits @code{events.ExitedEvent} which indicates that the inferior has exited.
cb6be26b 24477@code{events.ExitedEvent} has two attributes:
d812018b 24478@defvar ExitedEvent.exit_code
cb6be26b
KP
24479An integer representing the exit code, if available, which the inferior
24480has returned. (The exit code could be unavailable if, for example,
24481@value{GDBN} detaches from the inferior.) If the exit code is unavailable,
24482the attribute does not exist.
24483@end defvar
24484@defvar ExitedEvent inferior
24485A reference to the inferior which triggered the @code{exited} event.
d812018b 24486@end defvar
505500db
SW
24487
24488@item events.stop
24489Emits @code{gdb.StopEvent} which extends @code{gdb.ThreadEvent}.
24490
24491Indicates that the inferior has stopped. All events emitted by this registry
24492extend StopEvent. As a child of @code{gdb.ThreadEvent}, @code{gdb.StopEvent}
24493will indicate the stopped thread when @value{GDBN} is running in non-stop
24494mode. Refer to @code{gdb.ThreadEvent} above for more details.
24495
24496Emits @code{gdb.SignalEvent} which extends @code{gdb.StopEvent}.
24497
24498This event indicates that the inferior or one of its threads has received as
24499signal. @code{gdb.SignalEvent} has the following attributes:
24500
d812018b 24501@defvar SignalEvent.stop_signal
505500db
SW
24502A string representing the signal received by the inferior. A list of possible
24503signal values can be obtained by running the command @code{info signals} in
24504the @value{GDBN} command prompt.
d812018b 24505@end defvar
505500db
SW
24506
24507Also emits @code{gdb.BreakpointEvent} which extends @code{gdb.StopEvent}.
24508
6839b47f
KP
24509@code{gdb.BreakpointEvent} event indicates that one or more breakpoints have
24510been hit, and has the following attributes:
505500db 24511
d812018b 24512@defvar BreakpointEvent.breakpoints
6839b47f
KP
24513A sequence containing references to all the breakpoints (type
24514@code{gdb.Breakpoint}) that were hit.
505500db 24515@xref{Breakpoints In Python}, for details of the @code{gdb.Breakpoint} object.
d812018b
PK
24516@end defvar
24517@defvar BreakpointEvent.breakpoint
6839b47f
KP
24518A reference to the first breakpoint that was hit.
24519This function is maintained for backward compatibility and is now deprecated
d812018b
PK
24520in favor of the @code{gdb.BreakpointEvent.breakpoints} attribute.
24521@end defvar
505500db 24522
20c168b5
KP
24523@item events.new_objfile
24524Emits @code{gdb.NewObjFileEvent} which indicates that a new object file has
24525been loaded by @value{GDBN}. @code{gdb.NewObjFileEvent} has one attribute:
24526
20c168b5
KP
24527@defvar NewObjFileEvent.new_objfile
24528A reference to the object file (@code{gdb.Objfile}) which has been loaded.
24529@xref{Objfiles In Python}, for details of the @code{gdb.Objfile} object.
24530@end defvar
20c168b5 24531
505500db
SW
24532@end table
24533
595939de
PM
24534@node Threads In Python
24535@subsubsection Threads In Python
24536@cindex threads in python
24537
24538@findex gdb.InferiorThread
24539Python scripts can access information about, and manipulate inferior threads
24540controlled by @value{GDBN}, via objects of the @code{gdb.InferiorThread} class.
24541
24542The following thread-related functions are available in the @code{gdb}
24543module:
24544
24545@findex gdb.selected_thread
d812018b 24546@defun gdb.selected_thread ()
595939de
PM
24547This function returns the thread object for the selected thread. If there
24548is no selected thread, this will return @code{None}.
24549@end defun
24550
24551A @code{gdb.InferiorThread} object has the following attributes:
24552
d812018b 24553@defvar InferiorThread.name
4694da01
TT
24554The name of the thread. If the user specified a name using
24555@code{thread name}, then this returns that name. Otherwise, if an
24556OS-supplied name is available, then it is returned. Otherwise, this
24557returns @code{None}.
24558
24559This attribute can be assigned to. The new value must be a string
24560object, which sets the new name, or @code{None}, which removes any
24561user-specified thread name.
d812018b 24562@end defvar
4694da01 24563
d812018b 24564@defvar InferiorThread.num
595939de 24565ID of the thread, as assigned by GDB.
d812018b 24566@end defvar
595939de 24567
d812018b 24568@defvar InferiorThread.ptid
595939de
PM
24569ID of the thread, as assigned by the operating system. This attribute is a
24570tuple containing three integers. The first is the Process ID (PID); the second
24571is the Lightweight Process ID (LWPID), and the third is the Thread ID (TID).
24572Either the LWPID or TID may be 0, which indicates that the operating system
24573does not use that identifier.
d812018b 24574@end defvar
595939de
PM
24575
24576A @code{gdb.InferiorThread} object has the following methods:
24577
d812018b 24578@defun InferiorThread.is_valid ()
29703da4
PM
24579Returns @code{True} if the @code{gdb.InferiorThread} object is valid,
24580@code{False} if not. A @code{gdb.InferiorThread} object will become
24581invalid if the thread exits, or the inferior that the thread belongs
24582is deleted. All other @code{gdb.InferiorThread} methods will throw an
24583exception if it is invalid at the time the method is called.
d812018b 24584@end defun
29703da4 24585
d812018b 24586@defun InferiorThread.switch ()
595939de
PM
24587This changes @value{GDBN}'s currently selected thread to the one represented
24588by this object.
d812018b 24589@end defun
595939de 24590
d812018b 24591@defun InferiorThread.is_stopped ()
595939de 24592Return a Boolean indicating whether the thread is stopped.
d812018b 24593@end defun
595939de 24594
d812018b 24595@defun InferiorThread.is_running ()
595939de 24596Return a Boolean indicating whether the thread is running.
d812018b 24597@end defun
595939de 24598
d812018b 24599@defun InferiorThread.is_exited ()
595939de 24600Return a Boolean indicating whether the thread is exited.
d812018b 24601@end defun
595939de 24602
d8906c6f
TJB
24603@node Commands In Python
24604@subsubsection Commands In Python
24605
24606@cindex commands in python
24607@cindex python commands
d8906c6f
TJB
24608You can implement new @value{GDBN} CLI commands in Python. A CLI
24609command is implemented using an instance of the @code{gdb.Command}
24610class, most commonly using a subclass.
24611
f05e2e1d 24612@defun Command.__init__ (name, @var{command_class} @r{[}, @var{completer_class} @r{[}, @var{prefix}@r{]]})
d8906c6f
TJB
24613The object initializer for @code{Command} registers the new command
24614with @value{GDBN}. This initializer is normally invoked from the
24615subclass' own @code{__init__} method.
24616
24617@var{name} is the name of the command. If @var{name} consists of
24618multiple words, then the initial words are looked for as prefix
24619commands. In this case, if one of the prefix commands does not exist,
24620an exception is raised.
24621
24622There is no support for multi-line commands.
24623
cc924cad 24624@var{command_class} should be one of the @samp{COMMAND_} constants
d8906c6f
TJB
24625defined below. This argument tells @value{GDBN} how to categorize the
24626new command in the help system.
24627
cc924cad 24628@var{completer_class} is an optional argument. If given, it should be
d8906c6f
TJB
24629one of the @samp{COMPLETE_} constants defined below. This argument
24630tells @value{GDBN} how to perform completion for this command. If not
24631given, @value{GDBN} will attempt to complete using the object's
24632@code{complete} method (see below); if no such method is found, an
24633error will occur when completion is attempted.
24634
24635@var{prefix} is an optional argument. If @code{True}, then the new
24636command is a prefix command; sub-commands of this command may be
24637registered.
24638
24639The help text for the new command is taken from the Python
24640documentation string for the command's class, if there is one. If no
24641documentation string is provided, the default value ``This command is
24642not documented.'' is used.
d812018b 24643@end defun
d8906c6f 24644
a0c36267 24645@cindex don't repeat Python command
d812018b 24646@defun Command.dont_repeat ()
d8906c6f
TJB
24647By default, a @value{GDBN} command is repeated when the user enters a
24648blank line at the command prompt. A command can suppress this
24649behavior by invoking the @code{dont_repeat} method. This is similar
24650to the user command @code{dont-repeat}, see @ref{Define, dont-repeat}.
d812018b 24651@end defun
d8906c6f 24652
d812018b 24653@defun Command.invoke (argument, from_tty)
d8906c6f
TJB
24654This method is called by @value{GDBN} when this command is invoked.
24655
24656@var{argument} is a string. It is the argument to the command, after
24657leading and trailing whitespace has been stripped.
24658
24659@var{from_tty} is a boolean argument. When true, this means that the
24660command was entered by the user at the terminal; when false it means
24661that the command came from elsewhere.
24662
24663If this method throws an exception, it is turned into a @value{GDBN}
24664@code{error} call. Otherwise, the return value is ignored.
07ca107c
DE
24665
24666@findex gdb.string_to_argv
24667To break @var{argument} up into an argv-like string use
24668@code{gdb.string_to_argv}. This function behaves identically to
24669@value{GDBN}'s internal argument lexer @code{buildargv}.
24670It is recommended to use this for consistency.
24671Arguments are separated by spaces and may be quoted.
24672Example:
24673
24674@smallexample
24675print gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\"")
24676['1', '2 "3', '4 "5', "6 '7"]
24677@end smallexample
24678
d812018b 24679@end defun
d8906c6f 24680
a0c36267 24681@cindex completion of Python commands
d812018b 24682@defun Command.complete (text, word)
d8906c6f
TJB
24683This method is called by @value{GDBN} when the user attempts
24684completion on this command. All forms of completion are handled by
a0c36267
EZ
24685this method, that is, the @key{TAB} and @key{M-?} key bindings
24686(@pxref{Completion}), and the @code{complete} command (@pxref{Help,
24687complete}).
d8906c6f
TJB
24688
24689The arguments @var{text} and @var{word} are both strings. @var{text}
24690holds the complete command line up to the cursor's location.
24691@var{word} holds the last word of the command line; this is computed
24692using a word-breaking heuristic.
24693
24694The @code{complete} method can return several values:
24695@itemize @bullet
24696@item
24697If the return value is a sequence, the contents of the sequence are
24698used as the completions. It is up to @code{complete} to ensure that the
24699contents actually do complete the word. A zero-length sequence is
24700allowed, it means that there were no completions available. Only
24701string elements of the sequence are used; other elements in the
24702sequence are ignored.
24703
24704@item
24705If the return value is one of the @samp{COMPLETE_} constants defined
24706below, then the corresponding @value{GDBN}-internal completion
24707function is invoked, and its result is used.
24708
24709@item
24710All other results are treated as though there were no available
24711completions.
24712@end itemize
d812018b 24713@end defun
d8906c6f 24714
d8906c6f
TJB
24715When a new command is registered, it must be declared as a member of
24716some general class of commands. This is used to classify top-level
24717commands in the on-line help system; note that prefix commands are not
24718listed under their own category but rather that of their top-level
24719command. The available classifications are represented by constants
24720defined in the @code{gdb} module:
24721
24722@table @code
24723@findex COMMAND_NONE
24724@findex gdb.COMMAND_NONE
d812018b 24725@item gdb.COMMAND_NONE
d8906c6f
TJB
24726The command does not belong to any particular class. A command in
24727this category will not be displayed in any of the help categories.
24728
24729@findex COMMAND_RUNNING
24730@findex gdb.COMMAND_RUNNING
d812018b 24731@item gdb.COMMAND_RUNNING
d8906c6f
TJB
24732The command is related to running the inferior. For example,
24733@code{start}, @code{step}, and @code{continue} are in this category.
a0c36267 24734Type @kbd{help running} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
24735commands in this category.
24736
24737@findex COMMAND_DATA
24738@findex gdb.COMMAND_DATA
d812018b 24739@item gdb.COMMAND_DATA
d8906c6f
TJB
24740The command is related to data or variables. For example,
24741@code{call}, @code{find}, and @code{print} are in this category. Type
a0c36267 24742@kbd{help data} at the @value{GDBN} prompt to see a list of commands
d8906c6f
TJB
24743in this category.
24744
24745@findex COMMAND_STACK
24746@findex gdb.COMMAND_STACK
d812018b 24747@item gdb.COMMAND_STACK
d8906c6f
TJB
24748The command has to do with manipulation of the stack. For example,
24749@code{backtrace}, @code{frame}, and @code{return} are in this
a0c36267 24750category. Type @kbd{help stack} at the @value{GDBN} prompt to see a
d8906c6f
TJB
24751list of commands in this category.
24752
24753@findex COMMAND_FILES
24754@findex gdb.COMMAND_FILES
d812018b 24755@item gdb.COMMAND_FILES
d8906c6f
TJB
24756This class is used for file-related commands. For example,
24757@code{file}, @code{list} and @code{section} are in this category.
a0c36267 24758Type @kbd{help files} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
24759commands in this category.
24760
24761@findex COMMAND_SUPPORT
24762@findex gdb.COMMAND_SUPPORT
d812018b 24763@item gdb.COMMAND_SUPPORT
d8906c6f
TJB
24764This should be used for ``support facilities'', generally meaning
24765things that are useful to the user when interacting with @value{GDBN},
24766but not related to the state of the inferior. For example,
24767@code{help}, @code{make}, and @code{shell} are in this category. Type
a0c36267 24768@kbd{help support} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
24769commands in this category.
24770
24771@findex COMMAND_STATUS
24772@findex gdb.COMMAND_STATUS
d812018b 24773@item gdb.COMMAND_STATUS
d8906c6f
TJB
24774The command is an @samp{info}-related command, that is, related to the
24775state of @value{GDBN} itself. For example, @code{info}, @code{macro},
a0c36267 24776and @code{show} are in this category. Type @kbd{help status} at the
d8906c6f
TJB
24777@value{GDBN} prompt to see a list of commands in this category.
24778
24779@findex COMMAND_BREAKPOINTS
24780@findex gdb.COMMAND_BREAKPOINTS
d812018b 24781@item gdb.COMMAND_BREAKPOINTS
d8906c6f 24782The command has to do with breakpoints. For example, @code{break},
a0c36267 24783@code{clear}, and @code{delete} are in this category. Type @kbd{help
d8906c6f
TJB
24784breakpoints} at the @value{GDBN} prompt to see a list of commands in
24785this category.
24786
24787@findex COMMAND_TRACEPOINTS
24788@findex gdb.COMMAND_TRACEPOINTS
d812018b 24789@item gdb.COMMAND_TRACEPOINTS
d8906c6f
TJB
24790The command has to do with tracepoints. For example, @code{trace},
24791@code{actions}, and @code{tfind} are in this category. Type
a0c36267 24792@kbd{help tracepoints} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
24793commands in this category.
24794
7d74f244
DE
24795@findex COMMAND_USER
24796@findex gdb.COMMAND_USER
24797@item gdb.COMMAND_USER
24798The command is a general purpose command for the user, and typically
24799does not fit in one of the other categories.
24800Type @kbd{help user-defined} at the @value{GDBN} prompt to see
24801a list of commands in this category, as well as the list of gdb macros
24802(@pxref{Sequences}).
24803
d8906c6f
TJB
24804@findex COMMAND_OBSCURE
24805@findex gdb.COMMAND_OBSCURE
d812018b 24806@item gdb.COMMAND_OBSCURE
d8906c6f
TJB
24807The command is only used in unusual circumstances, or is not of
24808general interest to users. For example, @code{checkpoint},
a0c36267 24809@code{fork}, and @code{stop} are in this category. Type @kbd{help
d8906c6f
TJB
24810obscure} at the @value{GDBN} prompt to see a list of commands in this
24811category.
24812
24813@findex COMMAND_MAINTENANCE
24814@findex gdb.COMMAND_MAINTENANCE
d812018b 24815@item gdb.COMMAND_MAINTENANCE
d8906c6f
TJB
24816The command is only useful to @value{GDBN} maintainers. The
24817@code{maintenance} and @code{flushregs} commands are in this category.
a0c36267 24818Type @kbd{help internals} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
24819commands in this category.
24820@end table
24821
d8906c6f
TJB
24822A new command can use a predefined completion function, either by
24823specifying it via an argument at initialization, or by returning it
24824from the @code{complete} method. These predefined completion
24825constants are all defined in the @code{gdb} module:
24826
24827@table @code
24828@findex COMPLETE_NONE
24829@findex gdb.COMPLETE_NONE
d812018b 24830@item gdb.COMPLETE_NONE
d8906c6f
TJB
24831This constant means that no completion should be done.
24832
24833@findex COMPLETE_FILENAME
24834@findex gdb.COMPLETE_FILENAME
d812018b 24835@item gdb.COMPLETE_FILENAME
d8906c6f
TJB
24836This constant means that filename completion should be performed.
24837
24838@findex COMPLETE_LOCATION
24839@findex gdb.COMPLETE_LOCATION
d812018b 24840@item gdb.COMPLETE_LOCATION
d8906c6f
TJB
24841This constant means that location completion should be done.
24842@xref{Specify Location}.
24843
24844@findex COMPLETE_COMMAND
24845@findex gdb.COMPLETE_COMMAND
d812018b 24846@item gdb.COMPLETE_COMMAND
d8906c6f
TJB
24847This constant means that completion should examine @value{GDBN}
24848command names.
24849
24850@findex COMPLETE_SYMBOL
24851@findex gdb.COMPLETE_SYMBOL
d812018b 24852@item gdb.COMPLETE_SYMBOL
d8906c6f
TJB
24853This constant means that completion should be done using symbol names
24854as the source.
24855@end table
24856
24857The following code snippet shows how a trivial CLI command can be
24858implemented in Python:
24859
24860@smallexample
24861class HelloWorld (gdb.Command):
24862 """Greet the whole world."""
24863
24864 def __init__ (self):
7d74f244 24865 super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
d8906c6f
TJB
24866
24867 def invoke (self, arg, from_tty):
24868 print "Hello, World!"
24869
24870HelloWorld ()
24871@end smallexample
24872
24873The last line instantiates the class, and is necessary to trigger the
24874registration of the command with @value{GDBN}. Depending on how the
24875Python code is read into @value{GDBN}, you may need to import the
24876@code{gdb} module explicitly.
24877
d7b32ed3
PM
24878@node Parameters In Python
24879@subsubsection Parameters In Python
24880
24881@cindex parameters in python
24882@cindex python parameters
24883@tindex gdb.Parameter
24884@tindex Parameter
24885You can implement new @value{GDBN} parameters using Python. A new
24886parameter is implemented as an instance of the @code{gdb.Parameter}
24887class.
24888
24889Parameters are exposed to the user via the @code{set} and
24890@code{show} commands. @xref{Help}.
24891
24892There are many parameters that already exist and can be set in
24893@value{GDBN}. Two examples are: @code{set follow fork} and
24894@code{set charset}. Setting these parameters influences certain
24895behavior in @value{GDBN}. Similarly, you can define parameters that
24896can be used to influence behavior in custom Python scripts and commands.
24897
d812018b 24898@defun Parameter.__init__ (name, @var{command-class}, @var{parameter-class} @r{[}, @var{enum-sequence}@r{]})
d7b32ed3
PM
24899The object initializer for @code{Parameter} registers the new
24900parameter with @value{GDBN}. This initializer is normally invoked
24901from the subclass' own @code{__init__} method.
24902
24903@var{name} is the name of the new parameter. If @var{name} consists
24904of multiple words, then the initial words are looked for as prefix
24905parameters. An example of this can be illustrated with the
24906@code{set print} set of parameters. If @var{name} is
24907@code{print foo}, then @code{print} will be searched as the prefix
24908parameter. In this case the parameter can subsequently be accessed in
24909@value{GDBN} as @code{set print foo}.
24910
24911If @var{name} consists of multiple words, and no prefix parameter group
24912can be found, an exception is raised.
24913
24914@var{command-class} should be one of the @samp{COMMAND_} constants
24915(@pxref{Commands In Python}). This argument tells @value{GDBN} how to
24916categorize the new parameter in the help system.
24917
24918@var{parameter-class} should be one of the @samp{PARAM_} constants
24919defined below. This argument tells @value{GDBN} the type of the new
24920parameter; this information is used for input validation and
24921completion.
24922
24923If @var{parameter-class} is @code{PARAM_ENUM}, then
24924@var{enum-sequence} must be a sequence of strings. These strings
24925represent the possible values for the parameter.
24926
24927If @var{parameter-class} is not @code{PARAM_ENUM}, then the presence
24928of a fourth argument will cause an exception to be thrown.
24929
24930The help text for the new parameter is taken from the Python
24931documentation string for the parameter's class, if there is one. If
24932there is no documentation string, a default value is used.
d812018b 24933@end defun
d7b32ed3 24934
d812018b 24935@defvar Parameter.set_doc
d7b32ed3
PM
24936If this attribute exists, and is a string, then its value is used as
24937the help text for this parameter's @code{set} command. The value is
24938examined when @code{Parameter.__init__} is invoked; subsequent changes
24939have no effect.
d812018b 24940@end defvar
d7b32ed3 24941
d812018b 24942@defvar Parameter.show_doc
d7b32ed3
PM
24943If this attribute exists, and is a string, then its value is used as
24944the help text for this parameter's @code{show} command. The value is
24945examined when @code{Parameter.__init__} is invoked; subsequent changes
24946have no effect.
d812018b 24947@end defvar
d7b32ed3 24948
d812018b 24949@defvar Parameter.value
d7b32ed3
PM
24950The @code{value} attribute holds the underlying value of the
24951parameter. It can be read and assigned to just as any other
24952attribute. @value{GDBN} does validation when assignments are made.
d812018b 24953@end defvar
d7b32ed3 24954
ecec24e6
PM
24955There are two methods that should be implemented in any
24956@code{Parameter} class. These are:
24957
d812018b 24958@defun Parameter.get_set_string (self)
ecec24e6
PM
24959@value{GDBN} will call this method when a @var{parameter}'s value has
24960been changed via the @code{set} API (for example, @kbd{set foo off}).
24961The @code{value} attribute has already been populated with the new
24962value and may be used in output. This method must return a string.
d812018b 24963@end defun
ecec24e6 24964
d812018b 24965@defun Parameter.get_show_string (self, svalue)
ecec24e6
PM
24966@value{GDBN} will call this method when a @var{parameter}'s
24967@code{show} API has been invoked (for example, @kbd{show foo}). The
24968argument @code{svalue} receives the string representation of the
24969current value. This method must return a string.
d812018b 24970@end defun
d7b32ed3
PM
24971
24972When a new parameter is defined, its type must be specified. The
24973available types are represented by constants defined in the @code{gdb}
24974module:
24975
24976@table @code
24977@findex PARAM_BOOLEAN
24978@findex gdb.PARAM_BOOLEAN
d812018b 24979@item gdb.PARAM_BOOLEAN
d7b32ed3
PM
24980The value is a plain boolean. The Python boolean values, @code{True}
24981and @code{False} are the only valid values.
24982
24983@findex PARAM_AUTO_BOOLEAN
24984@findex gdb.PARAM_AUTO_BOOLEAN
d812018b 24985@item gdb.PARAM_AUTO_BOOLEAN
d7b32ed3
PM
24986The value has three possible states: true, false, and @samp{auto}. In
24987Python, true and false are represented using boolean constants, and
24988@samp{auto} is represented using @code{None}.
24989
24990@findex PARAM_UINTEGER
24991@findex gdb.PARAM_UINTEGER
d812018b 24992@item gdb.PARAM_UINTEGER
d7b32ed3
PM
24993The value is an unsigned integer. The value of 0 should be
24994interpreted to mean ``unlimited''.
24995
24996@findex PARAM_INTEGER
24997@findex gdb.PARAM_INTEGER
d812018b 24998@item gdb.PARAM_INTEGER
d7b32ed3
PM
24999The value is a signed integer. The value of 0 should be interpreted
25000to mean ``unlimited''.
25001
25002@findex PARAM_STRING
25003@findex gdb.PARAM_STRING
d812018b 25004@item gdb.PARAM_STRING
d7b32ed3
PM
25005The value is a string. When the user modifies the string, any escape
25006sequences, such as @samp{\t}, @samp{\f}, and octal escapes, are
25007translated into corresponding characters and encoded into the current
25008host charset.
25009
25010@findex PARAM_STRING_NOESCAPE
25011@findex gdb.PARAM_STRING_NOESCAPE
d812018b 25012@item gdb.PARAM_STRING_NOESCAPE
d7b32ed3
PM
25013The value is a string. When the user modifies the string, escapes are
25014passed through untranslated.
25015
25016@findex PARAM_OPTIONAL_FILENAME
25017@findex gdb.PARAM_OPTIONAL_FILENAME
d812018b 25018@item gdb.PARAM_OPTIONAL_FILENAME
d7b32ed3
PM
25019The value is a either a filename (a string), or @code{None}.
25020
25021@findex PARAM_FILENAME
25022@findex gdb.PARAM_FILENAME
d812018b 25023@item gdb.PARAM_FILENAME
d7b32ed3
PM
25024The value is a filename. This is just like
25025@code{PARAM_STRING_NOESCAPE}, but uses file names for completion.
25026
25027@findex PARAM_ZINTEGER
25028@findex gdb.PARAM_ZINTEGER
d812018b 25029@item gdb.PARAM_ZINTEGER
d7b32ed3
PM
25030The value is an integer. This is like @code{PARAM_INTEGER}, except 0
25031is interpreted as itself.
25032
25033@findex PARAM_ENUM
25034@findex gdb.PARAM_ENUM
d812018b 25035@item gdb.PARAM_ENUM
d7b32ed3
PM
25036The value is a string, which must be one of a collection string
25037constants provided when the parameter is created.
25038@end table
25039
bc3b79fd
TJB
25040@node Functions In Python
25041@subsubsection Writing new convenience functions
25042
25043@cindex writing convenience functions
25044@cindex convenience functions in python
25045@cindex python convenience functions
25046@tindex gdb.Function
25047@tindex Function
25048You can implement new convenience functions (@pxref{Convenience Vars})
25049in Python. A convenience function is an instance of a subclass of the
25050class @code{gdb.Function}.
25051
d812018b 25052@defun Function.__init__ (name)
bc3b79fd
TJB
25053The initializer for @code{Function} registers the new function with
25054@value{GDBN}. The argument @var{name} is the name of the function,
25055a string. The function will be visible to the user as a convenience
25056variable of type @code{internal function}, whose name is the same as
25057the given @var{name}.
25058
25059The documentation for the new function is taken from the documentation
25060string for the new class.
d812018b 25061@end defun
bc3b79fd 25062
d812018b 25063@defun Function.invoke (@var{*args})
bc3b79fd
TJB
25064When a convenience function is evaluated, its arguments are converted
25065to instances of @code{gdb.Value}, and then the function's
25066@code{invoke} method is called. Note that @value{GDBN} does not
25067predetermine the arity of convenience functions. Instead, all
25068available arguments are passed to @code{invoke}, following the
25069standard Python calling convention. In particular, a convenience
25070function can have default values for parameters without ill effect.
25071
25072The return value of this method is used as its value in the enclosing
25073expression. If an ordinary Python value is returned, it is converted
25074to a @code{gdb.Value} following the usual rules.
d812018b 25075@end defun
bc3b79fd
TJB
25076
25077The following code snippet shows how a trivial convenience function can
25078be implemented in Python:
25079
25080@smallexample
25081class Greet (gdb.Function):
25082 """Return string to greet someone.
25083Takes a name as argument."""
25084
25085 def __init__ (self):
25086 super (Greet, self).__init__ ("greet")
25087
25088 def invoke (self, name):
25089 return "Hello, %s!" % name.string ()
25090
25091Greet ()
25092@end smallexample
25093
25094The last line instantiates the class, and is necessary to trigger the
25095registration of the function with @value{GDBN}. Depending on how the
25096Python code is read into @value{GDBN}, you may need to import the
25097@code{gdb} module explicitly.
25098
dc939229
TT
25099Now you can use the function in an expression:
25100
25101@smallexample
25102(gdb) print $greet("Bob")
25103$1 = "Hello, Bob!"
25104@end smallexample
25105
fa33c3cd
DE
25106@node Progspaces In Python
25107@subsubsection Program Spaces In Python
25108
25109@cindex progspaces in python
25110@tindex gdb.Progspace
25111@tindex Progspace
25112A program space, or @dfn{progspace}, represents a symbolic view
25113of an address space.
25114It consists of all of the objfiles of the program.
25115@xref{Objfiles In Python}.
25116@xref{Inferiors and Programs, program spaces}, for more details
25117about program spaces.
25118
25119The following progspace-related functions are available in the
25120@code{gdb} module:
25121
25122@findex gdb.current_progspace
d812018b 25123@defun gdb.current_progspace ()
fa33c3cd
DE
25124This function returns the program space of the currently selected inferior.
25125@xref{Inferiors and Programs}.
25126@end defun
25127
25128@findex gdb.progspaces
d812018b 25129@defun gdb.progspaces ()
fa33c3cd
DE
25130Return a sequence of all the progspaces currently known to @value{GDBN}.
25131@end defun
25132
25133Each progspace is represented by an instance of the @code{gdb.Progspace}
25134class.
25135
d812018b 25136@defvar Progspace.filename
fa33c3cd 25137The file name of the progspace as a string.
d812018b 25138@end defvar
fa33c3cd 25139
d812018b 25140@defvar Progspace.pretty_printers
fa33c3cd
DE
25141The @code{pretty_printers} attribute is a list of functions. It is
25142used to look up pretty-printers. A @code{Value} is passed to each
25143function in order; if the function returns @code{None}, then the
25144search continues. Otherwise, the return value should be an object
4c374409 25145which is used to format the value. @xref{Pretty Printing API}, for more
fa33c3cd 25146information.
d812018b 25147@end defvar
fa33c3cd 25148
18a9fc12
TT
25149@defvar Progspace.type_printers
25150The @code{type_printers} attribute is a list of type printer objects.
25151@xref{Type Printing API}, for more information.
25152@end defvar
25153
89c73ade
TT
25154@node Objfiles In Python
25155@subsubsection Objfiles In Python
25156
25157@cindex objfiles in python
25158@tindex gdb.Objfile
25159@tindex Objfile
25160@value{GDBN} loads symbols for an inferior from various
25161symbol-containing files (@pxref{Files}). These include the primary
25162executable file, any shared libraries used by the inferior, and any
25163separate debug info files (@pxref{Separate Debug Files}).
25164@value{GDBN} calls these symbol-containing files @dfn{objfiles}.
25165
25166The following objfile-related functions are available in the
25167@code{gdb} module:
25168
25169@findex gdb.current_objfile
d812018b 25170@defun gdb.current_objfile ()
bf88dd68 25171When auto-loading a Python script (@pxref{Python Auto-loading}), @value{GDBN}
89c73ade
TT
25172sets the ``current objfile'' to the corresponding objfile. This
25173function returns the current objfile. If there is no current objfile,
25174this function returns @code{None}.
25175@end defun
25176
25177@findex gdb.objfiles
d812018b 25178@defun gdb.objfiles ()
89c73ade
TT
25179Return a sequence of all the objfiles current known to @value{GDBN}.
25180@xref{Objfiles In Python}.
25181@end defun
25182
25183Each objfile is represented by an instance of the @code{gdb.Objfile}
25184class.
25185
d812018b 25186@defvar Objfile.filename
89c73ade 25187The file name of the objfile as a string.
d812018b 25188@end defvar
89c73ade 25189
d812018b 25190@defvar Objfile.pretty_printers
89c73ade
TT
25191The @code{pretty_printers} attribute is a list of functions. It is
25192used to look up pretty-printers. A @code{Value} is passed to each
25193function in order; if the function returns @code{None}, then the
25194search continues. Otherwise, the return value should be an object
4c374409 25195which is used to format the value. @xref{Pretty Printing API}, for more
a6bac58e 25196information.
d812018b 25197@end defvar
89c73ade 25198
18a9fc12
TT
25199@defvar Objfile.type_printers
25200The @code{type_printers} attribute is a list of type printer objects.
25201@xref{Type Printing API}, for more information.
25202@end defvar
25203
29703da4
PM
25204A @code{gdb.Objfile} object has the following methods:
25205
d812018b 25206@defun Objfile.is_valid ()
29703da4
PM
25207Returns @code{True} if the @code{gdb.Objfile} object is valid,
25208@code{False} if not. A @code{gdb.Objfile} object can become invalid
25209if the object file it refers to is not loaded in @value{GDBN} any
25210longer. All other @code{gdb.Objfile} methods will throw an exception
25211if it is invalid at the time the method is called.
d812018b 25212@end defun
29703da4 25213
f8f6f20b 25214@node Frames In Python
f3e9a817 25215@subsubsection Accessing inferior stack frames from Python.
f8f6f20b
TJB
25216
25217@cindex frames in python
25218When the debugged program stops, @value{GDBN} is able to analyze its call
25219stack (@pxref{Frames,,Stack frames}). The @code{gdb.Frame} class
25220represents a frame in the stack. A @code{gdb.Frame} object is only valid
25221while its corresponding frame exists in the inferior's stack. If you try
621c8364
TT
25222to use an invalid frame object, @value{GDBN} will throw a @code{gdb.error}
25223exception (@pxref{Exception Handling}).
f8f6f20b
TJB
25224
25225Two @code{gdb.Frame} objects can be compared for equality with the @code{==}
25226operator, like:
25227
25228@smallexample
25229(@value{GDBP}) python print gdb.newest_frame() == gdb.selected_frame ()
25230True
25231@end smallexample
25232
25233The following frame-related functions are available in the @code{gdb} module:
25234
25235@findex gdb.selected_frame
d812018b 25236@defun gdb.selected_frame ()
f8f6f20b
TJB
25237Return the selected frame object. (@pxref{Selection,,Selecting a Frame}).
25238@end defun
25239
d8e22779 25240@findex gdb.newest_frame
d812018b 25241@defun gdb.newest_frame ()
d8e22779
TT
25242Return the newest frame object for the selected thread.
25243@end defun
25244
d812018b 25245@defun gdb.frame_stop_reason_string (reason)
f8f6f20b
TJB
25246Return a string explaining the reason why @value{GDBN} stopped unwinding
25247frames, as expressed by the given @var{reason} code (an integer, see the
25248@code{unwind_stop_reason} method further down in this section).
25249@end defun
25250
25251A @code{gdb.Frame} object has the following methods:
25252
d812018b 25253@defun Frame.is_valid ()
f8f6f20b
TJB
25254Returns true if the @code{gdb.Frame} object is valid, false if not.
25255A frame object can become invalid if the frame it refers to doesn't
25256exist anymore in the inferior. All @code{gdb.Frame} methods will throw
25257an exception if it is invalid at the time the method is called.
d812018b 25258@end defun
f8f6f20b 25259
d812018b 25260@defun Frame.name ()
f8f6f20b
TJB
25261Returns the function name of the frame, or @code{None} if it can't be
25262obtained.
d812018b 25263@end defun
f8f6f20b 25264
bea883fd
SCR
25265@defun Frame.architecture ()
25266Returns the @code{gdb.Architecture} object corresponding to the frame's
25267architecture. @xref{Architectures In Python}.
25268@end defun
25269
d812018b 25270@defun Frame.type ()
ccfc3d6e
TT
25271Returns the type of the frame. The value can be one of:
25272@table @code
25273@item gdb.NORMAL_FRAME
25274An ordinary stack frame.
25275
25276@item gdb.DUMMY_FRAME
25277A fake stack frame that was created by @value{GDBN} when performing an
25278inferior function call.
25279
25280@item gdb.INLINE_FRAME
25281A frame representing an inlined function. The function was inlined
25282into a @code{gdb.NORMAL_FRAME} that is older than this one.
25283
111c6489
JK
25284@item gdb.TAILCALL_FRAME
25285A frame representing a tail call. @xref{Tail Call Frames}.
25286
ccfc3d6e
TT
25287@item gdb.SIGTRAMP_FRAME
25288A signal trampoline frame. This is the frame created by the OS when
25289it calls into a signal handler.
25290
25291@item gdb.ARCH_FRAME
25292A fake stack frame representing a cross-architecture call.
25293
25294@item gdb.SENTINEL_FRAME
25295This is like @code{gdb.NORMAL_FRAME}, but it is only used for the
25296newest frame.
25297@end table
d812018b 25298@end defun
f8f6f20b 25299
d812018b 25300@defun Frame.unwind_stop_reason ()
f8f6f20b
TJB
25301Return an integer representing the reason why it's not possible to find
25302more frames toward the outermost frame. Use
25303@code{gdb.frame_stop_reason_string} to convert the value returned by this
a7fc3f37
KP
25304function to a string. The value can be one of:
25305
25306@table @code
25307@item gdb.FRAME_UNWIND_NO_REASON
25308No particular reason (older frames should be available).
25309
25310@item gdb.FRAME_UNWIND_NULL_ID
25311The previous frame's analyzer returns an invalid result.
25312
25313@item gdb.FRAME_UNWIND_OUTERMOST
25314This frame is the outermost.
25315
25316@item gdb.FRAME_UNWIND_UNAVAILABLE
25317Cannot unwind further, because that would require knowing the
25318values of registers or memory that have not been collected.
25319
25320@item gdb.FRAME_UNWIND_INNER_ID
25321This frame ID looks like it ought to belong to a NEXT frame,
25322but we got it for a PREV frame. Normally, this is a sign of
25323unwinder failure. It could also indicate stack corruption.
25324
25325@item gdb.FRAME_UNWIND_SAME_ID
25326This frame has the same ID as the previous one. That means
25327that unwinding further would almost certainly give us another
25328frame with exactly the same ID, so break the chain. Normally,
25329this is a sign of unwinder failure. It could also indicate
25330stack corruption.
25331
25332@item gdb.FRAME_UNWIND_NO_SAVED_PC
25333The frame unwinder did not find any saved PC, but we needed
25334one to unwind further.
2231f1fb
KP
25335
25336@item gdb.FRAME_UNWIND_FIRST_ERROR
25337Any stop reason greater or equal to this value indicates some kind
25338of error. This special value facilitates writing code that tests
25339for errors in unwinding in a way that will work correctly even if
25340the list of the other values is modified in future @value{GDBN}
25341versions. Using it, you could write:
25342@smallexample
25343reason = gdb.selected_frame().unwind_stop_reason ()
25344reason_str = gdb.frame_stop_reason_string (reason)
25345if reason >= gdb.FRAME_UNWIND_FIRST_ERROR:
25346 print "An error occured: %s" % reason_str
25347@end smallexample
a7fc3f37
KP
25348@end table
25349
d812018b 25350@end defun
f8f6f20b 25351
d812018b 25352@defun Frame.pc ()
f8f6f20b 25353Returns the frame's resume address.
d812018b 25354@end defun
f8f6f20b 25355
d812018b 25356@defun Frame.block ()
f3e9a817 25357Return the frame's code block. @xref{Blocks In Python}.
d812018b 25358@end defun
f3e9a817 25359
d812018b 25360@defun Frame.function ()
f3e9a817
PM
25361Return the symbol for the function corresponding to this frame.
25362@xref{Symbols In Python}.
d812018b 25363@end defun
f3e9a817 25364
d812018b 25365@defun Frame.older ()
f8f6f20b 25366Return the frame that called this frame.
d812018b 25367@end defun
f8f6f20b 25368
d812018b 25369@defun Frame.newer ()
f8f6f20b 25370Return the frame called by this frame.
d812018b 25371@end defun
f8f6f20b 25372
d812018b 25373@defun Frame.find_sal ()
f3e9a817
PM
25374Return the frame's symtab and line object.
25375@xref{Symbol Tables In Python}.
d812018b 25376@end defun
f3e9a817 25377
d812018b 25378@defun Frame.read_var (variable @r{[}, block@r{]})
dc00d89f
PM
25379Return the value of @var{variable} in this frame. If the optional
25380argument @var{block} is provided, search for the variable from that
25381block; otherwise start at the frame's current block (which is
25382determined by the frame's current program counter). @var{variable}
25383must be a string or a @code{gdb.Symbol} object. @var{block} must be a
25384@code{gdb.Block} object.
d812018b 25385@end defun
f3e9a817 25386
d812018b 25387@defun Frame.select ()
f3e9a817
PM
25388Set this frame to be the selected frame. @xref{Stack, ,Examining the
25389Stack}.
d812018b 25390@end defun
f3e9a817
PM
25391
25392@node Blocks In Python
25393@subsubsection Accessing frame blocks from Python.
25394
25395@cindex blocks in python
25396@tindex gdb.Block
25397
25398Within each frame, @value{GDBN} maintains information on each block
25399stored in that frame. These blocks are organized hierarchically, and
25400are represented individually in Python as a @code{gdb.Block}.
25401Please see @ref{Frames In Python}, for a more in-depth discussion on
25402frames. Furthermore, see @ref{Stack, ,Examining the Stack}, for more
25403detailed technical information on @value{GDBN}'s book-keeping of the
25404stack.
25405
bdb1994d 25406A @code{gdb.Block} is iterable. The iterator returns the symbols
56af09aa
SCR
25407(@pxref{Symbols In Python}) local to the block. Python programs
25408should not assume that a specific block object will always contain a
25409given symbol, since changes in @value{GDBN} features and
25410infrastructure may cause symbols move across blocks in a symbol
25411table.
bdb1994d 25412
f3e9a817
PM
25413The following block-related functions are available in the @code{gdb}
25414module:
25415
25416@findex gdb.block_for_pc
d812018b 25417@defun gdb.block_for_pc (pc)
f3e9a817
PM
25418Return the @code{gdb.Block} containing the given @var{pc} value. If the
25419block cannot be found for the @var{pc} value specified, the function
25420will return @code{None}.
25421@end defun
25422
29703da4
PM
25423A @code{gdb.Block} object has the following methods:
25424
d812018b 25425@defun Block.is_valid ()
29703da4
PM
25426Returns @code{True} if the @code{gdb.Block} object is valid,
25427@code{False} if not. A block object can become invalid if the block it
25428refers to doesn't exist anymore in the inferior. All other
25429@code{gdb.Block} methods will throw an exception if it is invalid at
bdb1994d
TT
25430the time the method is called. The block's validity is also checked
25431during iteration over symbols of the block.
d812018b 25432@end defun
29703da4 25433
f3e9a817
PM
25434A @code{gdb.Block} object has the following attributes:
25435
d812018b 25436@defvar Block.start
f3e9a817 25437The start address of the block. This attribute is not writable.
d812018b 25438@end defvar
f3e9a817 25439
d812018b 25440@defvar Block.end
f3e9a817 25441The end address of the block. This attribute is not writable.
d812018b 25442@end defvar
f3e9a817 25443
d812018b 25444@defvar Block.function
f3e9a817
PM
25445The name of the block represented as a @code{gdb.Symbol}. If the
25446block is not named, then this attribute holds @code{None}. This
25447attribute is not writable.
d812018b 25448@end defvar
f3e9a817 25449
d812018b 25450@defvar Block.superblock
f3e9a817
PM
25451The block containing this block. If this parent block does not exist,
25452this attribute holds @code{None}. This attribute is not writable.
d812018b 25453@end defvar
9df2fbc4
PM
25454
25455@defvar Block.global_block
25456The global block associated with this block. This attribute is not
25457writable.
25458@end defvar
25459
25460@defvar Block.static_block
25461The static block associated with this block. This attribute is not
25462writable.
25463@end defvar
25464
25465@defvar Block.is_global
25466@code{True} if the @code{gdb.Block} object is a global block,
25467@code{False} if not. This attribute is not
25468writable.
25469@end defvar
25470
25471@defvar Block.is_static
25472@code{True} if the @code{gdb.Block} object is a static block,
25473@code{False} if not. This attribute is not writable.
25474@end defvar
f3e9a817
PM
25475
25476@node Symbols In Python
25477@subsubsection Python representation of Symbols.
25478
25479@cindex symbols in python
25480@tindex gdb.Symbol
25481
25482@value{GDBN} represents every variable, function and type as an
25483entry in a symbol table. @xref{Symbols, ,Examining the Symbol Table}.
25484Similarly, Python represents these symbols in @value{GDBN} with the
25485@code{gdb.Symbol} object.
25486
25487The following symbol-related functions are available in the @code{gdb}
25488module:
25489
25490@findex gdb.lookup_symbol
d812018b 25491@defun gdb.lookup_symbol (name @r{[}, block @r{[}, domain@r{]]})
f3e9a817
PM
25492This function searches for a symbol by name. The search scope can be
25493restricted to the parameters defined in the optional domain and block
25494arguments.
25495
25496@var{name} is the name of the symbol. It must be a string. The
25497optional @var{block} argument restricts the search to symbols visible
25498in that @var{block}. The @var{block} argument must be a
6e6fbe60
DE
25499@code{gdb.Block} object. If omitted, the block for the current frame
25500is used. The optional @var{domain} argument restricts
f3e9a817
PM
25501the search to the domain type. The @var{domain} argument must be a
25502domain constant defined in the @code{gdb} module and described later
25503in this chapter.
6e6fbe60
DE
25504
25505The result is a tuple of two elements.
25506The first element is a @code{gdb.Symbol} object or @code{None} if the symbol
25507is not found.
25508If the symbol is found, the second element is @code{True} if the symbol
82809774 25509is a field of a method's object (e.g., @code{this} in C@t{++}),
6e6fbe60
DE
25510otherwise it is @code{False}.
25511If the symbol is not found, the second element is @code{False}.
25512@end defun
25513
25514@findex gdb.lookup_global_symbol
d812018b 25515@defun gdb.lookup_global_symbol (name @r{[}, domain@r{]})
6e6fbe60
DE
25516This function searches for a global symbol by name.
25517The search scope can be restricted to by the domain argument.
25518
25519@var{name} is the name of the symbol. It must be a string.
25520The optional @var{domain} argument restricts the search to the domain type.
25521The @var{domain} argument must be a domain constant defined in the @code{gdb}
25522module and described later in this chapter.
25523
25524The result is a @code{gdb.Symbol} object or @code{None} if the symbol
25525is not found.
f3e9a817
PM
25526@end defun
25527
25528A @code{gdb.Symbol} object has the following attributes:
25529
d812018b 25530@defvar Symbol.type
457e09f0
DE
25531The type of the symbol or @code{None} if no type is recorded.
25532This attribute is represented as a @code{gdb.Type} object.
25533@xref{Types In Python}. This attribute is not writable.
d812018b 25534@end defvar
457e09f0 25535
d812018b 25536@defvar Symbol.symtab
f3e9a817
PM
25537The symbol table in which the symbol appears. This attribute is
25538represented as a @code{gdb.Symtab} object. @xref{Symbol Tables In
25539Python}. This attribute is not writable.
d812018b 25540@end defvar
f3e9a817 25541
64e7d9dd
TT
25542@defvar Symbol.line
25543The line number in the source code at which the symbol was defined.
25544This is an integer.
25545@end defvar
25546
d812018b 25547@defvar Symbol.name
f3e9a817 25548The name of the symbol as a string. This attribute is not writable.
d812018b 25549@end defvar
f3e9a817 25550
d812018b 25551@defvar Symbol.linkage_name
f3e9a817
PM
25552The name of the symbol, as used by the linker (i.e., may be mangled).
25553This attribute is not writable.
d812018b 25554@end defvar
f3e9a817 25555
d812018b 25556@defvar Symbol.print_name
f3e9a817
PM
25557The name of the symbol in a form suitable for output. This is either
25558@code{name} or @code{linkage_name}, depending on whether the user
25559asked @value{GDBN} to display demangled or mangled names.
d812018b 25560@end defvar
f3e9a817 25561
d812018b 25562@defvar Symbol.addr_class
f3e9a817
PM
25563The address class of the symbol. This classifies how to find the value
25564of a symbol. Each address class is a constant defined in the
25565@code{gdb} module and described later in this chapter.
d812018b 25566@end defvar
f3e9a817 25567
f0823d2c
TT
25568@defvar Symbol.needs_frame
25569This is @code{True} if evaluating this symbol's value requires a frame
25570(@pxref{Frames In Python}) and @code{False} otherwise. Typically,
25571local variables will require a frame, but other symbols will not.
035d1e5b 25572@end defvar
f0823d2c 25573
d812018b 25574@defvar Symbol.is_argument
f3e9a817 25575@code{True} if the symbol is an argument of a function.
d812018b 25576@end defvar
f3e9a817 25577
d812018b 25578@defvar Symbol.is_constant
f3e9a817 25579@code{True} if the symbol is a constant.
d812018b 25580@end defvar
f3e9a817 25581
d812018b 25582@defvar Symbol.is_function
f3e9a817 25583@code{True} if the symbol is a function or a method.
d812018b 25584@end defvar
f3e9a817 25585
d812018b 25586@defvar Symbol.is_variable
f3e9a817 25587@code{True} if the symbol is a variable.
d812018b 25588@end defvar
f3e9a817 25589
29703da4
PM
25590A @code{gdb.Symbol} object has the following methods:
25591
d812018b 25592@defun Symbol.is_valid ()
29703da4
PM
25593Returns @code{True} if the @code{gdb.Symbol} object is valid,
25594@code{False} if not. A @code{gdb.Symbol} object can become invalid if
25595the symbol it refers to does not exist in @value{GDBN} any longer.
25596All other @code{gdb.Symbol} methods will throw an exception if it is
25597invalid at the time the method is called.
d812018b 25598@end defun
f0823d2c
TT
25599
25600@defun Symbol.value (@r{[}frame@r{]})
25601Compute the value of the symbol, as a @code{gdb.Value}. For
25602functions, this computes the address of the function, cast to the
25603appropriate type. If the symbol requires a frame in order to compute
25604its value, then @var{frame} must be given. If @var{frame} is not
25605given, or if @var{frame} is invalid, then this method will throw an
25606exception.
25607@end defun
29703da4 25608
f3e9a817
PM
25609The available domain categories in @code{gdb.Symbol} are represented
25610as constants in the @code{gdb} module:
25611
25612@table @code
25613@findex SYMBOL_UNDEF_DOMAIN
25614@findex gdb.SYMBOL_UNDEF_DOMAIN
d812018b 25615@item gdb.SYMBOL_UNDEF_DOMAIN
f3e9a817
PM
25616This is used when a domain has not been discovered or none of the
25617following domains apply. This usually indicates an error either
25618in the symbol information or in @value{GDBN}'s handling of symbols.
25619@findex SYMBOL_VAR_DOMAIN
25620@findex gdb.SYMBOL_VAR_DOMAIN
d812018b 25621@item gdb.SYMBOL_VAR_DOMAIN
f3e9a817
PM
25622This domain contains variables, function names, typedef names and enum
25623type values.
25624@findex SYMBOL_STRUCT_DOMAIN
25625@findex gdb.SYMBOL_STRUCT_DOMAIN
d812018b 25626@item gdb.SYMBOL_STRUCT_DOMAIN
f3e9a817
PM
25627This domain holds struct, union and enum type names.
25628@findex SYMBOL_LABEL_DOMAIN
25629@findex gdb.SYMBOL_LABEL_DOMAIN
d812018b 25630@item gdb.SYMBOL_LABEL_DOMAIN
f3e9a817
PM
25631This domain contains names of labels (for gotos).
25632@findex SYMBOL_VARIABLES_DOMAIN
25633@findex gdb.SYMBOL_VARIABLES_DOMAIN
d812018b 25634@item gdb.SYMBOL_VARIABLES_DOMAIN
f3e9a817
PM
25635This domain holds a subset of the @code{SYMBOLS_VAR_DOMAIN}; it
25636contains everything minus functions and types.
25637@findex SYMBOL_FUNCTIONS_DOMAIN
25638@findex gdb.SYMBOL_FUNCTIONS_DOMAIN
d812018b 25639@item gdb.SYMBOL_FUNCTION_DOMAIN
f3e9a817
PM
25640This domain contains all functions.
25641@findex SYMBOL_TYPES_DOMAIN
25642@findex gdb.SYMBOL_TYPES_DOMAIN
d812018b 25643@item gdb.SYMBOL_TYPES_DOMAIN
f3e9a817
PM
25644This domain contains all types.
25645@end table
25646
25647The available address class categories in @code{gdb.Symbol} are represented
25648as constants in the @code{gdb} module:
25649
25650@table @code
25651@findex SYMBOL_LOC_UNDEF
25652@findex gdb.SYMBOL_LOC_UNDEF
d812018b 25653@item gdb.SYMBOL_LOC_UNDEF
f3e9a817
PM
25654If this is returned by address class, it indicates an error either in
25655the symbol information or in @value{GDBN}'s handling of symbols.
25656@findex SYMBOL_LOC_CONST
25657@findex gdb.SYMBOL_LOC_CONST
d812018b 25658@item gdb.SYMBOL_LOC_CONST
f3e9a817
PM
25659Value is constant int.
25660@findex SYMBOL_LOC_STATIC
25661@findex gdb.SYMBOL_LOC_STATIC
d812018b 25662@item gdb.SYMBOL_LOC_STATIC
f3e9a817
PM
25663Value is at a fixed address.
25664@findex SYMBOL_LOC_REGISTER
25665@findex gdb.SYMBOL_LOC_REGISTER
d812018b 25666@item gdb.SYMBOL_LOC_REGISTER
f3e9a817
PM
25667Value is in a register.
25668@findex SYMBOL_LOC_ARG
25669@findex gdb.SYMBOL_LOC_ARG
d812018b 25670@item gdb.SYMBOL_LOC_ARG
f3e9a817
PM
25671Value is an argument. This value is at the offset stored within the
25672symbol inside the frame's argument list.
25673@findex SYMBOL_LOC_REF_ARG
25674@findex gdb.SYMBOL_LOC_REF_ARG
d812018b 25675@item gdb.SYMBOL_LOC_REF_ARG
f3e9a817
PM
25676Value address is stored in the frame's argument list. Just like
25677@code{LOC_ARG} except that the value's address is stored at the
25678offset, not the value itself.
25679@findex SYMBOL_LOC_REGPARM_ADDR
25680@findex gdb.SYMBOL_LOC_REGPARM_ADDR
d812018b 25681@item gdb.SYMBOL_LOC_REGPARM_ADDR
f3e9a817
PM
25682Value is a specified register. Just like @code{LOC_REGISTER} except
25683the register holds the address of the argument instead of the argument
25684itself.
25685@findex SYMBOL_LOC_LOCAL
25686@findex gdb.SYMBOL_LOC_LOCAL
d812018b 25687@item gdb.SYMBOL_LOC_LOCAL
f3e9a817
PM
25688Value is a local variable.
25689@findex SYMBOL_LOC_TYPEDEF
25690@findex gdb.SYMBOL_LOC_TYPEDEF
d812018b 25691@item gdb.SYMBOL_LOC_TYPEDEF
f3e9a817
PM
25692Value not used. Symbols in the domain @code{SYMBOL_STRUCT_DOMAIN} all
25693have this class.
25694@findex SYMBOL_LOC_BLOCK
25695@findex gdb.SYMBOL_LOC_BLOCK
d812018b 25696@item gdb.SYMBOL_LOC_BLOCK
f3e9a817
PM
25697Value is a block.
25698@findex SYMBOL_LOC_CONST_BYTES
25699@findex gdb.SYMBOL_LOC_CONST_BYTES
d812018b 25700@item gdb.SYMBOL_LOC_CONST_BYTES
f3e9a817
PM
25701Value is a byte-sequence.
25702@findex SYMBOL_LOC_UNRESOLVED
25703@findex gdb.SYMBOL_LOC_UNRESOLVED
d812018b 25704@item gdb.SYMBOL_LOC_UNRESOLVED
f3e9a817
PM
25705Value is at a fixed address, but the address of the variable has to be
25706determined from the minimal symbol table whenever the variable is
25707referenced.
25708@findex SYMBOL_LOC_OPTIMIZED_OUT
25709@findex gdb.SYMBOL_LOC_OPTIMIZED_OUT
d812018b 25710@item gdb.SYMBOL_LOC_OPTIMIZED_OUT
f3e9a817
PM
25711The value does not actually exist in the program.
25712@findex SYMBOL_LOC_COMPUTED
25713@findex gdb.SYMBOL_LOC_COMPUTED
d812018b 25714@item gdb.SYMBOL_LOC_COMPUTED
f3e9a817
PM
25715The value's address is a computed location.
25716@end table
25717
25718@node Symbol Tables In Python
25719@subsubsection Symbol table representation in Python.
25720
25721@cindex symbol tables in python
25722@tindex gdb.Symtab
25723@tindex gdb.Symtab_and_line
25724
25725Access to symbol table data maintained by @value{GDBN} on the inferior
25726is exposed to Python via two objects: @code{gdb.Symtab_and_line} and
25727@code{gdb.Symtab}. Symbol table and line data for a frame is returned
25728from the @code{find_sal} method in @code{gdb.Frame} object.
25729@xref{Frames In Python}.
25730
25731For more information on @value{GDBN}'s symbol table management, see
25732@ref{Symbols, ,Examining the Symbol Table}, for more information.
25733
25734A @code{gdb.Symtab_and_line} object has the following attributes:
25735
d812018b 25736@defvar Symtab_and_line.symtab
f3e9a817
PM
25737The symbol table object (@code{gdb.Symtab}) for this frame.
25738This attribute is not writable.
d812018b 25739@end defvar
f3e9a817 25740
d812018b 25741@defvar Symtab_and_line.pc
3c15d565
SCR
25742Indicates the start of the address range occupied by code for the
25743current source line. This attribute is not writable.
d812018b 25744@end defvar
f3e9a817 25745
ee0bf529
SCR
25746@defvar Symtab_and_line.last
25747Indicates the end of the address range occupied by code for the current
25748source line. This attribute is not writable.
25749@end defvar
25750
d812018b 25751@defvar Symtab_and_line.line
f3e9a817
PM
25752Indicates the current line number for this object. This
25753attribute is not writable.
d812018b 25754@end defvar
f3e9a817 25755
29703da4
PM
25756A @code{gdb.Symtab_and_line} object has the following methods:
25757
d812018b 25758@defun Symtab_and_line.is_valid ()
29703da4
PM
25759Returns @code{True} if the @code{gdb.Symtab_and_line} object is valid,
25760@code{False} if not. A @code{gdb.Symtab_and_line} object can become
25761invalid if the Symbol table and line object it refers to does not
25762exist in @value{GDBN} any longer. All other
25763@code{gdb.Symtab_and_line} methods will throw an exception if it is
25764invalid at the time the method is called.
d812018b 25765@end defun
29703da4 25766
f3e9a817
PM
25767A @code{gdb.Symtab} object has the following attributes:
25768
d812018b 25769@defvar Symtab.filename
f3e9a817 25770The symbol table's source filename. This attribute is not writable.
d812018b 25771@end defvar
f3e9a817 25772
d812018b 25773@defvar Symtab.objfile
f3e9a817
PM
25774The symbol table's backing object file. @xref{Objfiles In Python}.
25775This attribute is not writable.
d812018b 25776@end defvar
f3e9a817 25777
29703da4 25778A @code{gdb.Symtab} object has the following methods:
f3e9a817 25779
d812018b 25780@defun Symtab.is_valid ()
29703da4
PM
25781Returns @code{True} if the @code{gdb.Symtab} object is valid,
25782@code{False} if not. A @code{gdb.Symtab} object can become invalid if
25783the symbol table it refers to does not exist in @value{GDBN} any
25784longer. All other @code{gdb.Symtab} methods will throw an exception
25785if it is invalid at the time the method is called.
d812018b 25786@end defun
29703da4 25787
d812018b 25788@defun Symtab.fullname ()
f3e9a817 25789Return the symbol table's source absolute file name.
d812018b 25790@end defun
a20ee7a4
SCR
25791
25792@defun Symtab.global_block ()
25793Return the global block of the underlying symbol table.
25794@xref{Blocks In Python}.
25795@end defun
25796
25797@defun Symtab.static_block ()
25798Return the static block of the underlying symbol table.
25799@xref{Blocks In Python}.
25800@end defun
f8f6f20b 25801
adc36818
PM
25802@node Breakpoints In Python
25803@subsubsection Manipulating breakpoints using Python
25804
25805@cindex breakpoints in python
25806@tindex gdb.Breakpoint
25807
25808Python code can manipulate breakpoints via the @code{gdb.Breakpoint}
25809class.
25810
d812018b 25811@defun Breakpoint.__init__ (spec @r{[}, type @r{[}, wp_class @r{[},internal@r{]]]})
adc36818
PM
25812Create a new breakpoint. @var{spec} is a string naming the
25813location of the breakpoint, or an expression that defines a
25814watchpoint. The contents can be any location recognized by the
25815@code{break} command, or in the case of a watchpoint, by the @code{watch}
25816command. The optional @var{type} denotes the breakpoint to create
25817from the types defined later in this chapter. This argument can be
d812018b
PK
25818either: @code{gdb.BP_BREAKPOINT} or @code{gdb.BP_WATCHPOINT}. @var{type}
25819defaults to @code{gdb.BP_BREAKPOINT}. The optional @var{internal} argument
84f4c1fe
PM
25820allows the breakpoint to become invisible to the user. The breakpoint
25821will neither be reported when created, nor will it be listed in the
25822output from @code{info breakpoints} (but will be listed with the
25823@code{maint info breakpoints} command). The optional @var{wp_class}
adc36818 25824argument defines the class of watchpoint to create, if @var{type} is
d812018b
PK
25825@code{gdb.BP_WATCHPOINT}. If a watchpoint class is not provided, it is
25826assumed to be a @code{gdb.WP_WRITE} class.
25827@end defun
adc36818 25828
d812018b 25829@defun Breakpoint.stop (self)
7371cf6d
PM
25830The @code{gdb.Breakpoint} class can be sub-classed and, in
25831particular, you may choose to implement the @code{stop} method.
25832If this method is defined as a sub-class of @code{gdb.Breakpoint},
25833it will be called when the inferior reaches any location of a
25834breakpoint which instantiates that sub-class. If the method returns
25835@code{True}, the inferior will be stopped at the location of the
25836breakpoint, otherwise the inferior will continue.
25837
25838If there are multiple breakpoints at the same location with a
25839@code{stop} method, each one will be called regardless of the
25840return status of the previous. This ensures that all @code{stop}
25841methods have a chance to execute at that location. In this scenario
25842if one of the methods returns @code{True} but the others return
25843@code{False}, the inferior will still be stopped.
25844
99f5279d
PM
25845You should not alter the execution state of the inferior (i.e.@:, step,
25846next, etc.), alter the current frame context (i.e.@:, change the current
25847active frame), or alter, add or delete any breakpoint. As a general
25848rule, you should not alter any data within @value{GDBN} or the inferior
25849at this time.
25850
7371cf6d
PM
25851Example @code{stop} implementation:
25852
25853@smallexample
25854class MyBreakpoint (gdb.Breakpoint):
25855 def stop (self):
25856 inf_val = gdb.parse_and_eval("foo")
25857 if inf_val == 3:
25858 return True
25859 return False
25860@end smallexample
d812018b 25861@end defun
7371cf6d 25862
adc36818
PM
25863The available watchpoint types represented by constants are defined in the
25864@code{gdb} module:
25865
25866@table @code
25867@findex WP_READ
25868@findex gdb.WP_READ
d812018b 25869@item gdb.WP_READ
adc36818
PM
25870Read only watchpoint.
25871
25872@findex WP_WRITE
25873@findex gdb.WP_WRITE
d812018b 25874@item gdb.WP_WRITE
adc36818
PM
25875Write only watchpoint.
25876
25877@findex WP_ACCESS
25878@findex gdb.WP_ACCESS
d812018b 25879@item gdb.WP_ACCESS
adc36818
PM
25880Read/Write watchpoint.
25881@end table
25882
d812018b 25883@defun Breakpoint.is_valid ()
adc36818
PM
25884Return @code{True} if this @code{Breakpoint} object is valid,
25885@code{False} otherwise. A @code{Breakpoint} object can become invalid
25886if the user deletes the breakpoint. In this case, the object still
25887exists, but the underlying breakpoint does not. In the cases of
25888watchpoint scope, the watchpoint remains valid even if execution of the
25889inferior leaves the scope of that watchpoint.
d812018b 25890@end defun
adc36818 25891
d812018b 25892@defun Breakpoint.delete
94b6973e
PM
25893Permanently deletes the @value{GDBN} breakpoint. This also
25894invalidates the Python @code{Breakpoint} object. Any further access
25895to this object's attributes or methods will raise an error.
d812018b 25896@end defun
94b6973e 25897
d812018b 25898@defvar Breakpoint.enabled
adc36818
PM
25899This attribute is @code{True} if the breakpoint is enabled, and
25900@code{False} otherwise. This attribute is writable.
d812018b 25901@end defvar
adc36818 25902
d812018b 25903@defvar Breakpoint.silent
adc36818
PM
25904This attribute is @code{True} if the breakpoint is silent, and
25905@code{False} otherwise. This attribute is writable.
25906
25907Note that a breakpoint can also be silent if it has commands and the
25908first command is @code{silent}. This is not reported by the
25909@code{silent} attribute.
d812018b 25910@end defvar
adc36818 25911
d812018b 25912@defvar Breakpoint.thread
adc36818
PM
25913If the breakpoint is thread-specific, this attribute holds the thread
25914id. If the breakpoint is not thread-specific, this attribute is
25915@code{None}. This attribute is writable.
d812018b 25916@end defvar
adc36818 25917
d812018b 25918@defvar Breakpoint.task
adc36818
PM
25919If the breakpoint is Ada task-specific, this attribute holds the Ada task
25920id. If the breakpoint is not task-specific (or the underlying
25921language is not Ada), this attribute is @code{None}. This attribute
25922is writable.
d812018b 25923@end defvar
adc36818 25924
d812018b 25925@defvar Breakpoint.ignore_count
adc36818
PM
25926This attribute holds the ignore count for the breakpoint, an integer.
25927This attribute is writable.
d812018b 25928@end defvar
adc36818 25929
d812018b 25930@defvar Breakpoint.number
adc36818
PM
25931This attribute holds the breakpoint's number --- the identifier used by
25932the user to manipulate the breakpoint. This attribute is not writable.
d812018b 25933@end defvar
adc36818 25934
d812018b 25935@defvar Breakpoint.type
adc36818
PM
25936This attribute holds the breakpoint's type --- the identifier used to
25937determine the actual breakpoint type or use-case. This attribute is not
25938writable.
d812018b 25939@end defvar
adc36818 25940
d812018b 25941@defvar Breakpoint.visible
84f4c1fe
PM
25942This attribute tells whether the breakpoint is visible to the user
25943when set, or when the @samp{info breakpoints} command is run. This
25944attribute is not writable.
d812018b 25945@end defvar
84f4c1fe 25946
adc36818
PM
25947The available types are represented by constants defined in the @code{gdb}
25948module:
25949
25950@table @code
25951@findex BP_BREAKPOINT
25952@findex gdb.BP_BREAKPOINT
d812018b 25953@item gdb.BP_BREAKPOINT
adc36818
PM
25954Normal code breakpoint.
25955
25956@findex BP_WATCHPOINT
25957@findex gdb.BP_WATCHPOINT
d812018b 25958@item gdb.BP_WATCHPOINT
adc36818
PM
25959Watchpoint breakpoint.
25960
25961@findex BP_HARDWARE_WATCHPOINT
25962@findex gdb.BP_HARDWARE_WATCHPOINT
d812018b 25963@item gdb.BP_HARDWARE_WATCHPOINT
adc36818
PM
25964Hardware assisted watchpoint.
25965
25966@findex BP_READ_WATCHPOINT
25967@findex gdb.BP_READ_WATCHPOINT
d812018b 25968@item gdb.BP_READ_WATCHPOINT
adc36818
PM
25969Hardware assisted read watchpoint.
25970
25971@findex BP_ACCESS_WATCHPOINT
25972@findex gdb.BP_ACCESS_WATCHPOINT
d812018b 25973@item gdb.BP_ACCESS_WATCHPOINT
adc36818
PM
25974Hardware assisted access watchpoint.
25975@end table
25976
d812018b 25977@defvar Breakpoint.hit_count
adc36818
PM
25978This attribute holds the hit count for the breakpoint, an integer.
25979This attribute is writable, but currently it can only be set to zero.
d812018b 25980@end defvar
adc36818 25981
d812018b 25982@defvar Breakpoint.location
adc36818
PM
25983This attribute holds the location of the breakpoint, as specified by
25984the user. It is a string. If the breakpoint does not have a location
25985(that is, it is a watchpoint) the attribute's value is @code{None}. This
25986attribute is not writable.
d812018b 25987@end defvar
adc36818 25988
d812018b 25989@defvar Breakpoint.expression
adc36818
PM
25990This attribute holds a breakpoint expression, as specified by
25991the user. It is a string. If the breakpoint does not have an
25992expression (the breakpoint is not a watchpoint) the attribute's value
25993is @code{None}. This attribute is not writable.
d812018b 25994@end defvar
adc36818 25995
d812018b 25996@defvar Breakpoint.condition
adc36818
PM
25997This attribute holds the condition of the breakpoint, as specified by
25998the user. It is a string. If there is no condition, this attribute's
25999value is @code{None}. This attribute is writable.
d812018b 26000@end defvar
adc36818 26001
d812018b 26002@defvar Breakpoint.commands
adc36818
PM
26003This attribute holds the commands attached to the breakpoint. If
26004there are commands, this attribute's value is a string holding all the
26005commands, separated by newlines. If there are no commands, this
26006attribute is @code{None}. This attribute is not writable.
d812018b 26007@end defvar
adc36818 26008
cc72b2a2
KP
26009@node Finish Breakpoints in Python
26010@subsubsection Finish Breakpoints
26011
26012@cindex python finish breakpoints
26013@tindex gdb.FinishBreakpoint
26014
26015A finish breakpoint is a temporary breakpoint set at the return address of
26016a frame, based on the @code{finish} command. @code{gdb.FinishBreakpoint}
26017extends @code{gdb.Breakpoint}. The underlying breakpoint will be disabled
26018and deleted when the execution will run out of the breakpoint scope (i.e.@:
26019@code{Breakpoint.stop} or @code{FinishBreakpoint.out_of_scope} triggered).
26020Finish breakpoints are thread specific and must be create with the right
26021thread selected.
26022
26023@defun FinishBreakpoint.__init__ (@r{[}frame@r{]} @r{[}, internal@r{]})
26024Create a finish breakpoint at the return address of the @code{gdb.Frame}
26025object @var{frame}. If @var{frame} is not provided, this defaults to the
26026newest frame. The optional @var{internal} argument allows the breakpoint to
26027become invisible to the user. @xref{Breakpoints In Python}, for further
26028details about this argument.
26029@end defun
26030
26031@defun FinishBreakpoint.out_of_scope (self)
26032In some circumstances (e.g.@: @code{longjmp}, C@t{++} exceptions, @value{GDBN}
26033@code{return} command, @dots{}), a function may not properly terminate, and
26034thus never hit the finish breakpoint. When @value{GDBN} notices such a
26035situation, the @code{out_of_scope} callback will be triggered.
26036
26037You may want to sub-class @code{gdb.FinishBreakpoint} and override this
26038method:
26039
26040@smallexample
26041class MyFinishBreakpoint (gdb.FinishBreakpoint)
26042 def stop (self):
26043 print "normal finish"
26044 return True
26045
26046 def out_of_scope ():
26047 print "abnormal finish"
26048@end smallexample
26049@end defun
26050
26051@defvar FinishBreakpoint.return_value
26052When @value{GDBN} is stopped at a finish breakpoint and the frame
26053used to build the @code{gdb.FinishBreakpoint} object had debug symbols, this
26054attribute will contain a @code{gdb.Value} object corresponding to the return
26055value of the function. The value will be @code{None} if the function return
26056type is @code{void} or if the return value was not computable. This attribute
26057is not writable.
26058@end defvar
26059
be759fcf
PM
26060@node Lazy Strings In Python
26061@subsubsection Python representation of lazy strings.
26062
26063@cindex lazy strings in python
26064@tindex gdb.LazyString
26065
26066A @dfn{lazy string} is a string whose contents is not retrieved or
26067encoded until it is needed.
26068
26069A @code{gdb.LazyString} is represented in @value{GDBN} as an
26070@code{address} that points to a region of memory, an @code{encoding}
26071that will be used to encode that region of memory, and a @code{length}
26072to delimit the region of memory that represents the string. The
26073difference between a @code{gdb.LazyString} and a string wrapped within
26074a @code{gdb.Value} is that a @code{gdb.LazyString} will be treated
26075differently by @value{GDBN} when printing. A @code{gdb.LazyString} is
26076retrieved and encoded during printing, while a @code{gdb.Value}
26077wrapping a string is immediately retrieved and encoded on creation.
26078
26079A @code{gdb.LazyString} object has the following functions:
26080
d812018b 26081@defun LazyString.value ()
be759fcf
PM
26082Convert the @code{gdb.LazyString} to a @code{gdb.Value}. This value
26083will point to the string in memory, but will lose all the delayed
26084retrieval, encoding and handling that @value{GDBN} applies to a
26085@code{gdb.LazyString}.
d812018b 26086@end defun
be759fcf 26087
d812018b 26088@defvar LazyString.address
be759fcf
PM
26089This attribute holds the address of the string. This attribute is not
26090writable.
d812018b 26091@end defvar
be759fcf 26092
d812018b 26093@defvar LazyString.length
be759fcf
PM
26094This attribute holds the length of the string in characters. If the
26095length is -1, then the string will be fetched and encoded up to the
26096first null of appropriate width. This attribute is not writable.
d812018b 26097@end defvar
be759fcf 26098
d812018b 26099@defvar LazyString.encoding
be759fcf
PM
26100This attribute holds the encoding that will be applied to the string
26101when the string is printed by @value{GDBN}. If the encoding is not
26102set, or contains an empty string, then @value{GDBN} will select the
26103most appropriate encoding when the string is printed. This attribute
26104is not writable.
d812018b 26105@end defvar
be759fcf 26106
d812018b 26107@defvar LazyString.type
be759fcf
PM
26108This attribute holds the type that is represented by the lazy string's
26109type. For a lazy string this will always be a pointer type. To
26110resolve this to the lazy string's character type, use the type's
26111@code{target} method. @xref{Types In Python}. This attribute is not
26112writable.
d812018b 26113@end defvar
be759fcf 26114
bea883fd
SCR
26115@node Architectures In Python
26116@subsubsection Python representation of architectures
26117@cindex Python architectures
26118
26119@value{GDBN} uses architecture specific parameters and artifacts in a
26120number of its various computations. An architecture is represented
26121by an instance of the @code{gdb.Architecture} class.
26122
26123A @code{gdb.Architecture} class has the following methods:
26124
26125@defun Architecture.name ()
26126Return the name (string value) of the architecture.
26127@end defun
26128
9f44fbc0
SCR
26129@defun Architecture.disassemble (@var{start_pc} @r{[}, @var{end_pc} @r{[}, @var{count}@r{]]})
26130Return a list of disassembled instructions starting from the memory
26131address @var{start_pc}. The optional arguments @var{end_pc} and
26132@var{count} determine the number of instructions in the returned list.
26133If both the optional arguments @var{end_pc} and @var{count} are
26134specified, then a list of at most @var{count} disassembled instructions
26135whose start address falls in the closed memory address interval from
26136@var{start_pc} to @var{end_pc} are returned. If @var{end_pc} is not
26137specified, but @var{count} is specified, then @var{count} number of
26138instructions starting from the address @var{start_pc} are returned. If
26139@var{count} is not specified but @var{end_pc} is specified, then all
26140instructions whose start address falls in the closed memory address
26141interval from @var{start_pc} to @var{end_pc} are returned. If neither
26142@var{end_pc} nor @var{count} are specified, then a single instruction at
26143@var{start_pc} is returned. For all of these cases, each element of the
26144returned list is a Python @code{dict} with the following string keys:
26145
26146@table @code
26147
26148@item addr
26149The value corresponding to this key is a Python long integer capturing
26150the memory address of the instruction.
26151
26152@item asm
26153The value corresponding to this key is a string value which represents
26154the instruction with assembly language mnemonics. The assembly
26155language flavor used is the same as that specified by the current CLI
26156variable @code{disassembly-flavor}. @xref{Machine Code}.
26157
26158@item length
26159The value corresponding to this key is the length (integer value) of the
26160instruction in bytes.
26161
26162@end table
26163@end defun
26164
bf88dd68
JK
26165@node Python Auto-loading
26166@subsection Python Auto-loading
26167@cindex Python auto-loading
8a1ea21f
DE
26168
26169When a new object file is read (for example, due to the @code{file}
26170command, or because the inferior has loaded a shared library),
26171@value{GDBN} will look for Python support scripts in several ways:
3708f05e
JK
26172@file{@var{objfile}-gdb.py} (@pxref{objfile-gdb.py file})
26173and @code{.debug_gdb_scripts} section
26174(@pxref{dotdebug_gdb_scripts section}).
8a1ea21f
DE
26175
26176The auto-loading feature is useful for supplying application-specific
26177debugging commands and scripts.
26178
dbaefcf7
DE
26179Auto-loading can be enabled or disabled,
26180and the list of auto-loaded scripts can be printed.
8a1ea21f
DE
26181
26182@table @code
bf88dd68
JK
26183@anchor{set auto-load python-scripts}
26184@kindex set auto-load python-scripts
26185@item set auto-load python-scripts [on|off]
a86caf66 26186Enable or disable the auto-loading of Python scripts.
8a1ea21f 26187
bf88dd68
JK
26188@anchor{show auto-load python-scripts}
26189@kindex show auto-load python-scripts
26190@item show auto-load python-scripts
a86caf66 26191Show whether auto-loading of Python scripts is enabled or disabled.
dbaefcf7 26192
bf88dd68
JK
26193@anchor{info auto-load python-scripts}
26194@kindex info auto-load python-scripts
26195@cindex print list of auto-loaded Python scripts
26196@item info auto-load python-scripts [@var{regexp}]
26197Print the list of all Python scripts that @value{GDBN} auto-loaded.
75fc9810 26198
bf88dd68 26199Also printed is the list of Python scripts that were mentioned in
75fc9810 26200the @code{.debug_gdb_scripts} section and were not found
8e0583c8 26201(@pxref{dotdebug_gdb_scripts section}).
75fc9810
DE
26202This is useful because their names are not printed when @value{GDBN}
26203tries to load them and fails. There may be many of them, and printing
26204an error message for each one is problematic.
26205
bf88dd68 26206If @var{regexp} is supplied only Python scripts with matching names are printed.
dbaefcf7 26207
75fc9810
DE
26208Example:
26209
dbaefcf7 26210@smallexample
bf88dd68 26211(gdb) info auto-load python-scripts
bccbefd2
JK
26212Loaded Script
26213Yes py-section-script.py
26214 full name: /tmp/py-section-script.py
26215No my-foo-pretty-printers.py
dbaefcf7 26216@end smallexample
8a1ea21f
DE
26217@end table
26218
26219When reading an auto-loaded file, @value{GDBN} sets the
26220@dfn{current objfile}. This is available via the @code{gdb.current_objfile}
26221function (@pxref{Objfiles In Python}). This can be useful for
26222registering objfile-specific pretty-printers.
26223
3708f05e
JK
26224@menu
26225* objfile-gdb.py file:: The @file{@var{objfile}-gdb.py} file
26226* dotdebug_gdb_scripts section:: The @code{.debug_gdb_scripts} section
26227* Which flavor to choose?::
26228@end menu
26229
8a1ea21f
DE
26230@node objfile-gdb.py file
26231@subsubsection The @file{@var{objfile}-gdb.py} file
26232@cindex @file{@var{objfile}-gdb.py}
26233
26234When a new object file is read, @value{GDBN} looks for
7349ff92 26235a file named @file{@var{objfile}-gdb.py} (we call it @var{script-name} below),
8a1ea21f
DE
26236where @var{objfile} is the object file's real name, formed by ensuring
26237that the file name is absolute, following all symlinks, and resolving
26238@code{.} and @code{..} components. If this file exists and is
26239readable, @value{GDBN} will evaluate it as a Python script.
26240
1564a261 26241If this file does not exist, then @value{GDBN} will look for
c1668e4e
JK
26242@var{script-name} file in all of the directories as specified below.
26243
26244Note that loading of this script file also requires accordingly configured
26245@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
7349ff92 26246
e9687799
JK
26247For object files using @file{.exe} suffix @value{GDBN} tries to load first the
26248scripts normally according to its @file{.exe} filename. But if no scripts are
26249found @value{GDBN} also tries script filenames matching the object file without
26250its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
26251is attempted on any platform. This makes the script filenames compatible
26252between Unix and MS-Windows hosts.
26253
7349ff92
JK
26254@table @code
26255@anchor{set auto-load scripts-directory}
26256@kindex set auto-load scripts-directory
26257@item set auto-load scripts-directory @r{[}@var{directories}@r{]}
26258Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
26259may be delimited by the host platform path separator in use
26260(@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
26261
26262Each entry here needs to be covered also by the security setting
26263@code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
26264
26265@anchor{with-auto-load-dir}
1564a261
JK
26266This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
26267@code{set auto-load safe-path} value can be also overriden by @value{GDBN}
26268configuration option @option{--with-auto-load-dir}.
26269
26270Any reference to @file{$debugdir} will get replaced by
26271@var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
26272reference to @file{$datadir} will get replaced by @var{data-directory} which is
26273determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
26274@file{$datadir} must be placed as a directory component --- either alone or
26275delimited by @file{/} or @file{\} directory separators, depending on the host
26276platform.
7349ff92
JK
26277
26278The list of directories uses path separator (@samp{:} on GNU and Unix
26279systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26280to the @env{PATH} environment variable.
26281
26282@anchor{show auto-load scripts-directory}
26283@kindex show auto-load scripts-directory
26284@item show auto-load scripts-directory
26285Show @value{GDBN} auto-loaded scripts location.
26286@end table
8a1ea21f
DE
26287
26288@value{GDBN} does not track which files it has already auto-loaded this way.
26289@value{GDBN} will load the associated script every time the corresponding
26290@var{objfile} is opened.
26291So your @file{-gdb.py} file should be careful to avoid errors if it
26292is evaluated more than once.
26293
8e0583c8 26294@node dotdebug_gdb_scripts section
8a1ea21f
DE
26295@subsubsection The @code{.debug_gdb_scripts} section
26296@cindex @code{.debug_gdb_scripts} section
26297
26298For systems using file formats like ELF and COFF,
26299when @value{GDBN} loads a new object file
26300it will look for a special section named @samp{.debug_gdb_scripts}.
26301If this section exists, its contents is a list of names of scripts to load.
26302
26303@value{GDBN} will look for each specified script file first in the
26304current directory and then along the source search path
26305(@pxref{Source Path, ,Specifying Source Directories}),
26306except that @file{$cdir} is not searched, since the compilation
26307directory is not relevant to scripts.
26308
26309Entries can be placed in section @code{.debug_gdb_scripts} with,
26310for example, this GCC macro:
26311
26312@example
a3a7127e 26313/* Note: The "MS" section flags are to remove duplicates. */
8a1ea21f
DE
26314#define DEFINE_GDB_SCRIPT(script_name) \
26315 asm("\
26316.pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
26317.byte 1\n\
26318.asciz \"" script_name "\"\n\
26319.popsection \n\
26320");
26321@end example
26322
26323@noindent
26324Then one can reference the macro in a header or source file like this:
26325
26326@example
26327DEFINE_GDB_SCRIPT ("my-app-scripts.py")
26328@end example
26329
26330The script name may include directories if desired.
26331
c1668e4e
JK
26332Note that loading of this script file also requires accordingly configured
26333@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26334
8a1ea21f
DE
26335If the macro is put in a header, any application or library
26336using this header will get a reference to the specified script.
26337
26338@node Which flavor to choose?
26339@subsubsection Which flavor to choose?
26340
26341Given the multiple ways of auto-loading Python scripts, it might not always
26342be clear which one to choose. This section provides some guidance.
26343
26344Benefits of the @file{-gdb.py} way:
26345
26346@itemize @bullet
26347@item
26348Can be used with file formats that don't support multiple sections.
26349
26350@item
26351Ease of finding scripts for public libraries.
26352
26353Scripts specified in the @code{.debug_gdb_scripts} section are searched for
26354in the source search path.
26355For publicly installed libraries, e.g., @file{libstdc++}, there typically
26356isn't a source directory in which to find the script.
26357
26358@item
26359Doesn't require source code additions.
26360@end itemize
26361
26362Benefits of the @code{.debug_gdb_scripts} way:
26363
26364@itemize @bullet
26365@item
26366Works with static linking.
26367
26368Scripts for libraries done the @file{-gdb.py} way require an objfile to
26369trigger their loading. When an application is statically linked the only
26370objfile available is the executable, and it is cumbersome to attach all the
26371scripts from all the input libraries to the executable's @file{-gdb.py} script.
26372
26373@item
26374Works with classes that are entirely inlined.
26375
26376Some classes can be entirely inlined, and thus there may not be an associated
26377shared library to attach a @file{-gdb.py} script to.
26378
26379@item
26380Scripts needn't be copied out of the source tree.
26381
26382In some circumstances, apps can be built out of large collections of internal
26383libraries, and the build infrastructure necessary to install the
26384@file{-gdb.py} scripts in a place where @value{GDBN} can find them is
26385cumbersome. It may be easier to specify the scripts in the
26386@code{.debug_gdb_scripts} section as relative paths, and add a path to the
26387top of the source tree to the source search path.
26388@end itemize
26389
0e3509db
DE
26390@node Python modules
26391@subsection Python modules
26392@cindex python modules
26393
fa3a4f15 26394@value{GDBN} comes with several modules to assist writing Python code.
0e3509db
DE
26395
26396@menu
7b51bc51 26397* gdb.printing:: Building and registering pretty-printers.
0e3509db 26398* gdb.types:: Utilities for working with types.
fa3a4f15 26399* gdb.prompt:: Utilities for prompt value substitution.
0e3509db
DE
26400@end menu
26401
7b51bc51
DE
26402@node gdb.printing
26403@subsubsection gdb.printing
26404@cindex gdb.printing
26405
26406This module provides a collection of utilities for working with
26407pretty-printers.
26408
26409@table @code
26410@item PrettyPrinter (@var{name}, @var{subprinters}=None)
26411This class specifies the API that makes @samp{info pretty-printer},
26412@samp{enable pretty-printer} and @samp{disable pretty-printer} work.
26413Pretty-printers should generally inherit from this class.
26414
26415@item SubPrettyPrinter (@var{name})
26416For printers that handle multiple types, this class specifies the
26417corresponding API for the subprinters.
26418
26419@item RegexpCollectionPrettyPrinter (@var{name})
26420Utility class for handling multiple printers, all recognized via
26421regular expressions.
26422@xref{Writing a Pretty-Printer}, for an example.
26423
cafec441
TT
26424@item FlagEnumerationPrinter (@var{name})
26425A pretty-printer which handles printing of @code{enum} values. Unlike
26426@value{GDBN}'s built-in @code{enum} printing, this printer attempts to
26427work properly when there is some overlap between the enumeration
26428constants. @var{name} is the name of the printer and also the name of
26429the @code{enum} type to look up.
26430
9c15afc4 26431@item register_pretty_printer (@var{obj}, @var{printer}, @var{replace}=False)
7b51bc51 26432Register @var{printer} with the pretty-printer list of @var{obj}.
9c15afc4
DE
26433If @var{replace} is @code{True} then any existing copy of the printer
26434is replaced. Otherwise a @code{RuntimeError} exception is raised
26435if a printer with the same name already exists.
7b51bc51
DE
26436@end table
26437
0e3509db
DE
26438@node gdb.types
26439@subsubsection gdb.types
7b51bc51 26440@cindex gdb.types
0e3509db
DE
26441
26442This module provides a collection of utilities for working with
18a9fc12 26443@code{gdb.Type} objects.
0e3509db
DE
26444
26445@table @code
26446@item get_basic_type (@var{type})
26447Return @var{type} with const and volatile qualifiers stripped,
26448and with typedefs and C@t{++} references converted to the underlying type.
26449
26450C@t{++} example:
26451
26452@smallexample
26453typedef const int const_int;
26454const_int foo (3);
26455const_int& foo_ref (foo);
26456int main () @{ return 0; @}
26457@end smallexample
26458
26459Then in gdb:
26460
26461@smallexample
26462(gdb) start
26463(gdb) python import gdb.types
26464(gdb) python foo_ref = gdb.parse_and_eval("foo_ref")
26465(gdb) python print gdb.types.get_basic_type(foo_ref.type)
26466int
26467@end smallexample
26468
26469@item has_field (@var{type}, @var{field})
26470Return @code{True} if @var{type}, assumed to be a type with fields
26471(e.g., a structure or union), has field @var{field}.
26472
26473@item make_enum_dict (@var{enum_type})
26474Return a Python @code{dictionary} type produced from @var{enum_type}.
5110b5df 26475
0aaaf063 26476@item deep_items (@var{type})
5110b5df
PK
26477Returns a Python iterator similar to the standard
26478@code{gdb.Type.iteritems} method, except that the iterator returned
0aaaf063 26479by @code{deep_items} will recursively traverse anonymous struct or
5110b5df
PK
26480union fields. For example:
26481
26482@smallexample
26483struct A
26484@{
26485 int a;
26486 union @{
26487 int b0;
26488 int b1;
26489 @};
26490@};
26491@end smallexample
26492
26493@noindent
26494Then in @value{GDBN}:
26495@smallexample
26496(@value{GDBP}) python import gdb.types
26497(@value{GDBP}) python struct_a = gdb.lookup_type("struct A")
26498(@value{GDBP}) python print struct_a.keys ()
26499@{['a', '']@}
0aaaf063 26500(@value{GDBP}) python print [k for k,v in gdb.types.deep_items(struct_a)]
5110b5df
PK
26501@{['a', 'b0', 'b1']@}
26502@end smallexample
26503
18a9fc12
TT
26504@item get_type_recognizers ()
26505Return a list of the enabled type recognizers for the current context.
26506This is called by @value{GDBN} during the type-printing process
26507(@pxref{Type Printing API}).
26508
26509@item apply_type_recognizers (recognizers, type_obj)
26510Apply the type recognizers, @var{recognizers}, to the type object
26511@var{type_obj}. If any recognizer returns a string, return that
26512string. Otherwise, return @code{None}. This is called by
26513@value{GDBN} during the type-printing process (@pxref{Type Printing
26514API}).
26515
26516@item register_type_printer (locus, printer)
26517This is a convenience function to register a type printer.
26518@var{printer} is the type printer to register. It must implement the
26519type printer protocol. @var{locus} is either a @code{gdb.Objfile}, in
26520which case the printer is registered with that objfile; a
26521@code{gdb.Progspace}, in which case the printer is registered with
26522that progspace; or @code{None}, in which case the printer is
26523registered globally.
26524
26525@item TypePrinter
26526This is a base class that implements the type printer protocol. Type
26527printers are encouraged, but not required, to derive from this class.
26528It defines a constructor:
26529
26530@defmethod TypePrinter __init__ (self, name)
26531Initialize the type printer with the given name. The new printer
26532starts in the enabled state.
26533@end defmethod
26534
0e3509db 26535@end table
fa3a4f15
PM
26536
26537@node gdb.prompt
26538@subsubsection gdb.prompt
26539@cindex gdb.prompt
26540
26541This module provides a method for prompt value-substitution.
26542
26543@table @code
26544@item substitute_prompt (@var{string})
26545Return @var{string} with escape sequences substituted by values. Some
26546escape sequences take arguments. You can specify arguments inside
26547``@{@}'' immediately following the escape sequence.
26548
26549The escape sequences you can pass to this function are:
26550
26551@table @code
26552@item \\
26553Substitute a backslash.
26554@item \e
26555Substitute an ESC character.
26556@item \f
26557Substitute the selected frame; an argument names a frame parameter.
26558@item \n
26559Substitute a newline.
26560@item \p
26561Substitute a parameter's value; the argument names the parameter.
26562@item \r
26563Substitute a carriage return.
26564@item \t
26565Substitute the selected thread; an argument names a thread parameter.
26566@item \v
26567Substitute the version of GDB.
26568@item \w
26569Substitute the current working directory.
26570@item \[
26571Begin a sequence of non-printing characters. These sequences are
26572typically used with the ESC character, and are not counted in the string
26573length. Example: ``\[\e[0;34m\](gdb)\[\e[0m\]'' will return a
26574blue-colored ``(gdb)'' prompt where the length is five.
26575@item \]
26576End a sequence of non-printing characters.
26577@end table
26578
26579For example:
26580
26581@smallexample
26582substitute_prompt (``frame: \f,
26583 print arguments: \p@{print frame-arguments@}'')
26584@end smallexample
26585
26586@exdent will return the string:
26587
26588@smallexample
26589"frame: main, print arguments: scalars"
26590@end smallexample
26591@end table
0e3509db 26592
5a56e9c5
DE
26593@node Aliases
26594@section Creating new spellings of existing commands
26595@cindex aliases for commands
26596
26597It is often useful to define alternate spellings of existing commands.
26598For example, if a new @value{GDBN} command defined in Python has
26599a long name to type, it is handy to have an abbreviated version of it
26600that involves less typing.
26601
26602@value{GDBN} itself uses aliases. For example @samp{s} is an alias
26603of the @samp{step} command even though it is otherwise an ambiguous
26604abbreviation of other commands like @samp{set} and @samp{show}.
26605
26606Aliases are also used to provide shortened or more common versions
26607of multi-word commands. For example, @value{GDBN} provides the
26608@samp{tty} alias of the @samp{set inferior-tty} command.
26609
26610You can define a new alias with the @samp{alias} command.
26611
26612@table @code
26613
26614@kindex alias
26615@item alias [-a] [--] @var{ALIAS} = @var{COMMAND}
26616
26617@end table
26618
26619@var{ALIAS} specifies the name of the new alias.
26620Each word of @var{ALIAS} must consist of letters, numbers, dashes and
26621underscores.
26622
26623@var{COMMAND} specifies the name of an existing command
26624that is being aliased.
26625
26626The @samp{-a} option specifies that the new alias is an abbreviation
26627of the command. Abbreviations are not shown in command
26628lists displayed by the @samp{help} command.
26629
26630The @samp{--} option specifies the end of options,
26631and is useful when @var{ALIAS} begins with a dash.
26632
26633Here is a simple example showing how to make an abbreviation
26634of a command so that there is less to type.
26635Suppose you were tired of typing @samp{disas}, the current
26636shortest unambiguous abbreviation of the @samp{disassemble} command
26637and you wanted an even shorter version named @samp{di}.
26638The following will accomplish this.
26639
26640@smallexample
26641(gdb) alias -a di = disas
26642@end smallexample
26643
26644Note that aliases are different from user-defined commands.
26645With a user-defined command, you also need to write documentation
26646for it with the @samp{document} command.
26647An alias automatically picks up the documentation of the existing command.
26648
26649Here is an example where we make @samp{elms} an abbreviation of
26650@samp{elements} in the @samp{set print elements} command.
26651This is to show that you can make an abbreviation of any part
26652of a command.
26653
26654@smallexample
26655(gdb) alias -a set print elms = set print elements
26656(gdb) alias -a show print elms = show print elements
26657(gdb) set p elms 20
26658(gdb) show p elms
26659Limit on string chars or array elements to print is 200.
26660@end smallexample
26661
26662Note that if you are defining an alias of a @samp{set} command,
26663and you want to have an alias for the corresponding @samp{show}
26664command, then you need to define the latter separately.
26665
26666Unambiguously abbreviated commands are allowed in @var{COMMAND} and
26667@var{ALIAS}, just as they are normally.
26668
26669@smallexample
26670(gdb) alias -a set pr elms = set p ele
26671@end smallexample
26672
26673Finally, here is an example showing the creation of a one word
26674alias for a more complex command.
26675This creates alias @samp{spe} of the command @samp{set print elements}.
26676
26677@smallexample
26678(gdb) alias spe = set print elements
26679(gdb) spe 20
26680@end smallexample
26681
21c294e6
AC
26682@node Interpreters
26683@chapter Command Interpreters
26684@cindex command interpreters
26685
26686@value{GDBN} supports multiple command interpreters, and some command
26687infrastructure to allow users or user interface writers to switch
26688between interpreters or run commands in other interpreters.
26689
26690@value{GDBN} currently supports two command interpreters, the console
26691interpreter (sometimes called the command-line interpreter or @sc{cli})
26692and the machine interface interpreter (or @sc{gdb/mi}). This manual
26693describes both of these interfaces in great detail.
26694
26695By default, @value{GDBN} will start with the console interpreter.
26696However, the user may choose to start @value{GDBN} with another
26697interpreter by specifying the @option{-i} or @option{--interpreter}
26698startup options. Defined interpreters include:
26699
26700@table @code
26701@item console
26702@cindex console interpreter
26703The traditional console or command-line interpreter. This is the most often
26704used interpreter with @value{GDBN}. With no interpreter specified at runtime,
26705@value{GDBN} will use this interpreter.
26706
26707@item mi
26708@cindex mi interpreter
26709The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
26710by programs wishing to use @value{GDBN} as a backend for a debugger GUI
26711or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
26712Interface}.
26713
26714@item mi2
26715@cindex mi2 interpreter
26716The current @sc{gdb/mi} interface.
26717
26718@item mi1
26719@cindex mi1 interpreter
26720The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
26721
26722@end table
26723
26724@cindex invoke another interpreter
26725The interpreter being used by @value{GDBN} may not be dynamically
26726switched at runtime. Although possible, this could lead to a very
26727precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
26728enters the command "interpreter-set console" in a console view,
26729@value{GDBN} would switch to using the console interpreter, rendering
26730the IDE inoperable!
26731
26732@kindex interpreter-exec
26733Although you may only choose a single interpreter at startup, you may execute
26734commands in any interpreter from the current interpreter using the appropriate
26735command. If you are running the console interpreter, simply use the
26736@code{interpreter-exec} command:
26737
26738@smallexample
26739interpreter-exec mi "-data-list-register-names"
26740@end smallexample
26741
26742@sc{gdb/mi} has a similar command, although it is only available in versions of
26743@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
26744
8e04817f
AC
26745@node TUI
26746@chapter @value{GDBN} Text User Interface
26747@cindex TUI
d0d5df6f 26748@cindex Text User Interface
c906108c 26749
8e04817f
AC
26750@menu
26751* TUI Overview:: TUI overview
26752* TUI Keys:: TUI key bindings
7cf36c78 26753* TUI Single Key Mode:: TUI single key mode
db2e3e2e 26754* TUI Commands:: TUI-specific commands
8e04817f
AC
26755* TUI Configuration:: TUI configuration variables
26756@end menu
c906108c 26757
46ba6afa 26758The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
26759interface which uses the @code{curses} library to show the source
26760file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
26761commands in separate text windows. The TUI mode is supported only
26762on platforms where a suitable version of the @code{curses} library
26763is available.
d0d5df6f 26764
46ba6afa 26765The TUI mode is enabled by default when you invoke @value{GDBN} as
217bff3e 26766@samp{@value{GDBP} -tui}.
46ba6afa
BW
26767You can also switch in and out of TUI mode while @value{GDBN} runs by
26768using various TUI commands and key bindings, such as @kbd{C-x C-a}.
26769@xref{TUI Keys, ,TUI Key Bindings}.
c906108c 26770
8e04817f 26771@node TUI Overview
79a6e687 26772@section TUI Overview
c906108c 26773
46ba6afa 26774In TUI mode, @value{GDBN} can display several text windows:
c906108c 26775
8e04817f
AC
26776@table @emph
26777@item command
26778This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
26779prompt and the @value{GDBN} output. The @value{GDBN} input is still
26780managed using readline.
c906108c 26781
8e04817f
AC
26782@item source
26783The source window shows the source file of the program. The current
46ba6afa 26784line and active breakpoints are displayed in this window.
c906108c 26785
8e04817f
AC
26786@item assembly
26787The assembly window shows the disassembly output of the program.
c906108c 26788
8e04817f 26789@item register
46ba6afa
BW
26790This window shows the processor registers. Registers are highlighted
26791when their values change.
c906108c
SS
26792@end table
26793
269c21fe 26794The source and assembly windows show the current program position
46ba6afa
BW
26795by highlighting the current line and marking it with a @samp{>} marker.
26796Breakpoints are indicated with two markers. The first marker
269c21fe
SC
26797indicates the breakpoint type:
26798
26799@table @code
26800@item B
26801Breakpoint which was hit at least once.
26802
26803@item b
26804Breakpoint which was never hit.
26805
26806@item H
26807Hardware breakpoint which was hit at least once.
26808
26809@item h
26810Hardware breakpoint which was never hit.
269c21fe
SC
26811@end table
26812
26813The second marker indicates whether the breakpoint is enabled or not:
26814
26815@table @code
26816@item +
26817Breakpoint is enabled.
26818
26819@item -
26820Breakpoint is disabled.
269c21fe
SC
26821@end table
26822
46ba6afa
BW
26823The source, assembly and register windows are updated when the current
26824thread changes, when the frame changes, or when the program counter
26825changes.
26826
26827These windows are not all visible at the same time. The command
26828window is always visible. The others can be arranged in several
26829layouts:
c906108c 26830
8e04817f
AC
26831@itemize @bullet
26832@item
46ba6afa 26833source only,
2df3850c 26834
8e04817f 26835@item
46ba6afa 26836assembly only,
8e04817f
AC
26837
26838@item
46ba6afa 26839source and assembly,
8e04817f
AC
26840
26841@item
46ba6afa 26842source and registers, or
c906108c 26843
8e04817f 26844@item
46ba6afa 26845assembly and registers.
8e04817f 26846@end itemize
c906108c 26847
46ba6afa 26848A status line above the command window shows the following information:
b7bb15bc
SC
26849
26850@table @emph
26851@item target
46ba6afa 26852Indicates the current @value{GDBN} target.
b7bb15bc
SC
26853(@pxref{Targets, ,Specifying a Debugging Target}).
26854
26855@item process
46ba6afa 26856Gives the current process or thread number.
b7bb15bc
SC
26857When no process is being debugged, this field is set to @code{No process}.
26858
26859@item function
26860Gives the current function name for the selected frame.
26861The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 26862When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
26863the string @code{??} is displayed.
26864
26865@item line
26866Indicates the current line number for the selected frame.
46ba6afa 26867When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
26868
26869@item pc
26870Indicates the current program counter address.
b7bb15bc
SC
26871@end table
26872
8e04817f
AC
26873@node TUI Keys
26874@section TUI Key Bindings
26875@cindex TUI key bindings
c906108c 26876
8e04817f 26877The TUI installs several key bindings in the readline keymaps
39037522
TT
26878@ifset SYSTEM_READLINE
26879(@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
26880@end ifset
26881@ifclear SYSTEM_READLINE
26882(@pxref{Command Line Editing}).
26883@end ifclear
26884The following key bindings are installed for both TUI mode and the
26885@value{GDBN} standard mode.
c906108c 26886
8e04817f
AC
26887@table @kbd
26888@kindex C-x C-a
26889@item C-x C-a
26890@kindex C-x a
26891@itemx C-x a
26892@kindex C-x A
26893@itemx C-x A
46ba6afa
BW
26894Enter or leave the TUI mode. When leaving the TUI mode,
26895the curses window management stops and @value{GDBN} operates using
26896its standard mode, writing on the terminal directly. When reentering
26897the TUI mode, control is given back to the curses windows.
8e04817f 26898The screen is then refreshed.
c906108c 26899
8e04817f
AC
26900@kindex C-x 1
26901@item C-x 1
26902Use a TUI layout with only one window. The layout will
26903either be @samp{source} or @samp{assembly}. When the TUI mode
26904is not active, it will switch to the TUI mode.
2df3850c 26905
8e04817f 26906Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 26907
8e04817f
AC
26908@kindex C-x 2
26909@item C-x 2
26910Use a TUI layout with at least two windows. When the current
46ba6afa 26911layout already has two windows, the next layout with two windows is used.
8e04817f
AC
26912When a new layout is chosen, one window will always be common to the
26913previous layout and the new one.
c906108c 26914
8e04817f 26915Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 26916
72ffddc9
SC
26917@kindex C-x o
26918@item C-x o
26919Change the active window. The TUI associates several key bindings
46ba6afa 26920(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
26921gives the focus to the next TUI window.
26922
26923Think of it as the Emacs @kbd{C-x o} binding.
26924
7cf36c78
SC
26925@kindex C-x s
26926@item C-x s
46ba6afa
BW
26927Switch in and out of the TUI SingleKey mode that binds single
26928keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c906108c
SS
26929@end table
26930
46ba6afa 26931The following key bindings only work in the TUI mode:
5d161b24 26932
46ba6afa 26933@table @asis
8e04817f 26934@kindex PgUp
46ba6afa 26935@item @key{PgUp}
8e04817f 26936Scroll the active window one page up.
c906108c 26937
8e04817f 26938@kindex PgDn
46ba6afa 26939@item @key{PgDn}
8e04817f 26940Scroll the active window one page down.
c906108c 26941
8e04817f 26942@kindex Up
46ba6afa 26943@item @key{Up}
8e04817f 26944Scroll the active window one line up.
c906108c 26945
8e04817f 26946@kindex Down
46ba6afa 26947@item @key{Down}
8e04817f 26948Scroll the active window one line down.
c906108c 26949
8e04817f 26950@kindex Left
46ba6afa 26951@item @key{Left}
8e04817f 26952Scroll the active window one column left.
c906108c 26953
8e04817f 26954@kindex Right
46ba6afa 26955@item @key{Right}
8e04817f 26956Scroll the active window one column right.
c906108c 26957
8e04817f 26958@kindex C-L
46ba6afa 26959@item @kbd{C-L}
8e04817f 26960Refresh the screen.
8e04817f 26961@end table
c906108c 26962
46ba6afa
BW
26963Because the arrow keys scroll the active window in the TUI mode, they
26964are not available for their normal use by readline unless the command
26965window has the focus. When another window is active, you must use
26966other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
26967and @kbd{C-f} to control the command window.
8e04817f 26968
7cf36c78
SC
26969@node TUI Single Key Mode
26970@section TUI Single Key Mode
26971@cindex TUI single key mode
26972
46ba6afa
BW
26973The TUI also provides a @dfn{SingleKey} mode, which binds several
26974frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
26975switch into this mode, where the following key bindings are used:
7cf36c78
SC
26976
26977@table @kbd
26978@kindex c @r{(SingleKey TUI key)}
26979@item c
26980continue
26981
26982@kindex d @r{(SingleKey TUI key)}
26983@item d
26984down
26985
26986@kindex f @r{(SingleKey TUI key)}
26987@item f
26988finish
26989
26990@kindex n @r{(SingleKey TUI key)}
26991@item n
26992next
26993
26994@kindex q @r{(SingleKey TUI key)}
26995@item q
46ba6afa 26996exit the SingleKey mode.
7cf36c78
SC
26997
26998@kindex r @r{(SingleKey TUI key)}
26999@item r
27000run
27001
27002@kindex s @r{(SingleKey TUI key)}
27003@item s
27004step
27005
27006@kindex u @r{(SingleKey TUI key)}
27007@item u
27008up
27009
27010@kindex v @r{(SingleKey TUI key)}
27011@item v
27012info locals
27013
27014@kindex w @r{(SingleKey TUI key)}
27015@item w
27016where
7cf36c78
SC
27017@end table
27018
27019Other keys temporarily switch to the @value{GDBN} command prompt.
27020The key that was pressed is inserted in the editing buffer so that
27021it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
27022with the TUI SingleKey mode. Once the command is entered the TUI
27023SingleKey mode is restored. The only way to permanently leave
7f9087cb 27024this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78
SC
27025
27026
8e04817f 27027@node TUI Commands
db2e3e2e 27028@section TUI-specific Commands
8e04817f
AC
27029@cindex TUI commands
27030
27031The TUI has specific commands to control the text windows.
46ba6afa
BW
27032These commands are always available, even when @value{GDBN} is not in
27033the TUI mode. When @value{GDBN} is in the standard mode, most
27034of these commands will automatically switch to the TUI mode.
c906108c 27035
ff12863f
PA
27036Note that if @value{GDBN}'s @code{stdout} is not connected to a
27037terminal, or @value{GDBN} has been started with the machine interface
27038interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
27039these commands will fail with an error, because it would not be
27040possible or desirable to enable curses window management.
27041
c906108c 27042@table @code
3d757584
SC
27043@item info win
27044@kindex info win
27045List and give the size of all displayed windows.
27046
8e04817f 27047@item layout next
4644b6e3 27048@kindex layout
8e04817f 27049Display the next layout.
2df3850c 27050
8e04817f 27051@item layout prev
8e04817f 27052Display the previous layout.
c906108c 27053
8e04817f 27054@item layout src
8e04817f 27055Display the source window only.
c906108c 27056
8e04817f 27057@item layout asm
8e04817f 27058Display the assembly window only.
c906108c 27059
8e04817f 27060@item layout split
8e04817f 27061Display the source and assembly window.
c906108c 27062
8e04817f 27063@item layout regs
8e04817f
AC
27064Display the register window together with the source or assembly window.
27065
46ba6afa 27066@item focus next
8e04817f 27067@kindex focus
46ba6afa
BW
27068Make the next window active for scrolling.
27069
27070@item focus prev
27071Make the previous window active for scrolling.
27072
27073@item focus src
27074Make the source window active for scrolling.
27075
27076@item focus asm
27077Make the assembly window active for scrolling.
27078
27079@item focus regs
27080Make the register window active for scrolling.
27081
27082@item focus cmd
27083Make the command window active for scrolling.
c906108c 27084
8e04817f
AC
27085@item refresh
27086@kindex refresh
7f9087cb 27087Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 27088
6a1b180d
SC
27089@item tui reg float
27090@kindex tui reg
27091Show the floating point registers in the register window.
27092
27093@item tui reg general
27094Show the general registers in the register window.
27095
27096@item tui reg next
27097Show the next register group. The list of register groups as well as
27098their order is target specific. The predefined register groups are the
27099following: @code{general}, @code{float}, @code{system}, @code{vector},
27100@code{all}, @code{save}, @code{restore}.
27101
27102@item tui reg system
27103Show the system registers in the register window.
27104
8e04817f
AC
27105@item update
27106@kindex update
27107Update the source window and the current execution point.
c906108c 27108
8e04817f
AC
27109@item winheight @var{name} +@var{count}
27110@itemx winheight @var{name} -@var{count}
27111@kindex winheight
27112Change the height of the window @var{name} by @var{count}
27113lines. Positive counts increase the height, while negative counts
27114decrease it.
2df3850c 27115
46ba6afa
BW
27116@item tabset @var{nchars}
27117@kindex tabset
c45da7e6 27118Set the width of tab stops to be @var{nchars} characters.
c906108c
SS
27119@end table
27120
8e04817f 27121@node TUI Configuration
79a6e687 27122@section TUI Configuration Variables
8e04817f 27123@cindex TUI configuration variables
c906108c 27124
46ba6afa 27125Several configuration variables control the appearance of TUI windows.
c906108c 27126
8e04817f
AC
27127@table @code
27128@item set tui border-kind @var{kind}
27129@kindex set tui border-kind
27130Select the border appearance for the source, assembly and register windows.
27131The possible values are the following:
27132@table @code
27133@item space
27134Use a space character to draw the border.
c906108c 27135
8e04817f 27136@item ascii
46ba6afa 27137Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 27138
8e04817f
AC
27139@item acs
27140Use the Alternate Character Set to draw the border. The border is
27141drawn using character line graphics if the terminal supports them.
8e04817f 27142@end table
c78b4128 27143
8e04817f
AC
27144@item set tui border-mode @var{mode}
27145@kindex set tui border-mode
46ba6afa
BW
27146@itemx set tui active-border-mode @var{mode}
27147@kindex set tui active-border-mode
27148Select the display attributes for the borders of the inactive windows
27149or the active window. The @var{mode} can be one of the following:
8e04817f
AC
27150@table @code
27151@item normal
27152Use normal attributes to display the border.
c906108c 27153
8e04817f
AC
27154@item standout
27155Use standout mode.
c906108c 27156
8e04817f
AC
27157@item reverse
27158Use reverse video mode.
c906108c 27159
8e04817f
AC
27160@item half
27161Use half bright mode.
c906108c 27162
8e04817f
AC
27163@item half-standout
27164Use half bright and standout mode.
c906108c 27165
8e04817f
AC
27166@item bold
27167Use extra bright or bold mode.
c78b4128 27168
8e04817f
AC
27169@item bold-standout
27170Use extra bright or bold and standout mode.
8e04817f 27171@end table
8e04817f 27172@end table
c78b4128 27173
8e04817f
AC
27174@node Emacs
27175@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 27176
8e04817f
AC
27177@cindex Emacs
27178@cindex @sc{gnu} Emacs
27179A special interface allows you to use @sc{gnu} Emacs to view (and
27180edit) the source files for the program you are debugging with
27181@value{GDBN}.
c906108c 27182
8e04817f
AC
27183To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
27184executable file you want to debug as an argument. This command starts
27185@value{GDBN} as a subprocess of Emacs, with input and output through a newly
27186created Emacs buffer.
27187@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 27188
5e252a2e 27189Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 27190things:
c906108c 27191
8e04817f
AC
27192@itemize @bullet
27193@item
5e252a2e
NR
27194All ``terminal'' input and output goes through an Emacs buffer, called
27195the GUD buffer.
c906108c 27196
8e04817f
AC
27197This applies both to @value{GDBN} commands and their output, and to the input
27198and output done by the program you are debugging.
bf0184be 27199
8e04817f
AC
27200This is useful because it means that you can copy the text of previous
27201commands and input them again; you can even use parts of the output
27202in this way.
bf0184be 27203
8e04817f
AC
27204All the facilities of Emacs' Shell mode are available for interacting
27205with your program. In particular, you can send signals the usual
27206way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
27207stop.
bf0184be
ND
27208
27209@item
8e04817f 27210@value{GDBN} displays source code through Emacs.
bf0184be 27211
8e04817f
AC
27212Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
27213source file for that frame and puts an arrow (@samp{=>}) at the
27214left margin of the current line. Emacs uses a separate buffer for
27215source display, and splits the screen to show both your @value{GDBN} session
27216and the source.
bf0184be 27217
8e04817f
AC
27218Explicit @value{GDBN} @code{list} or search commands still produce output as
27219usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
27220@end itemize
27221
27222We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
27223a graphical mode, enabled by default, which provides further buffers
27224that can control the execution and describe the state of your program.
27225@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 27226
64fabec2
AC
27227If you specify an absolute file name when prompted for the @kbd{M-x
27228gdb} argument, then Emacs sets your current working directory to where
27229your program resides. If you only specify the file name, then Emacs
7a9dd1b2 27230sets your current working directory to the directory associated
64fabec2
AC
27231with the previous buffer. In this case, @value{GDBN} may find your
27232program by searching your environment's @code{PATH} variable, but on
27233some operating systems it might not find the source. So, although the
27234@value{GDBN} input and output session proceeds normally, the auxiliary
27235buffer does not display the current source and line of execution.
27236
27237The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
27238line of the GUD buffer and this serves as a default for the commands
27239that specify files for @value{GDBN} to operate on. @xref{Files,
27240,Commands to Specify Files}.
64fabec2
AC
27241
27242By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
27243need to call @value{GDBN} by a different name (for example, if you
27244keep several configurations around, with different names) you can
27245customize the Emacs variable @code{gud-gdb-command-name} to run the
27246one you want.
8e04817f 27247
5e252a2e 27248In the GUD buffer, you can use these special Emacs commands in
8e04817f 27249addition to the standard Shell mode commands:
c906108c 27250
8e04817f
AC
27251@table @kbd
27252@item C-h m
5e252a2e 27253Describe the features of Emacs' GUD Mode.
c906108c 27254
64fabec2 27255@item C-c C-s
8e04817f
AC
27256Execute to another source line, like the @value{GDBN} @code{step} command; also
27257update the display window to show the current file and location.
c906108c 27258
64fabec2 27259@item C-c C-n
8e04817f
AC
27260Execute to next source line in this function, skipping all function
27261calls, like the @value{GDBN} @code{next} command. Then update the display window
27262to show the current file and location.
c906108c 27263
64fabec2 27264@item C-c C-i
8e04817f
AC
27265Execute one instruction, like the @value{GDBN} @code{stepi} command; update
27266display window accordingly.
c906108c 27267
8e04817f
AC
27268@item C-c C-f
27269Execute until exit from the selected stack frame, like the @value{GDBN}
27270@code{finish} command.
c906108c 27271
64fabec2 27272@item C-c C-r
8e04817f
AC
27273Continue execution of your program, like the @value{GDBN} @code{continue}
27274command.
b433d00b 27275
64fabec2 27276@item C-c <
8e04817f
AC
27277Go up the number of frames indicated by the numeric argument
27278(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
27279like the @value{GDBN} @code{up} command.
b433d00b 27280
64fabec2 27281@item C-c >
8e04817f
AC
27282Go down the number of frames indicated by the numeric argument, like the
27283@value{GDBN} @code{down} command.
8e04817f 27284@end table
c906108c 27285
7f9087cb 27286In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 27287tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 27288
5e252a2e
NR
27289In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
27290separate frame which shows a backtrace when the GUD buffer is current.
27291Move point to any frame in the stack and type @key{RET} to make it
27292become the current frame and display the associated source in the
27293source buffer. Alternatively, click @kbd{Mouse-2} to make the
27294selected frame become the current one. In graphical mode, the
27295speedbar displays watch expressions.
64fabec2 27296
8e04817f
AC
27297If you accidentally delete the source-display buffer, an easy way to get
27298it back is to type the command @code{f} in the @value{GDBN} buffer, to
27299request a frame display; when you run under Emacs, this recreates
27300the source buffer if necessary to show you the context of the current
27301frame.
c906108c 27302
8e04817f
AC
27303The source files displayed in Emacs are in ordinary Emacs buffers
27304which are visiting the source files in the usual way. You can edit
27305the files with these buffers if you wish; but keep in mind that @value{GDBN}
27306communicates with Emacs in terms of line numbers. If you add or
27307delete lines from the text, the line numbers that @value{GDBN} knows cease
27308to correspond properly with the code.
b383017d 27309
5e252a2e
NR
27310A more detailed description of Emacs' interaction with @value{GDBN} is
27311given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
27312Emacs Manual}).
c906108c 27313
922fbb7b
AC
27314@node GDB/MI
27315@chapter The @sc{gdb/mi} Interface
27316
27317@unnumberedsec Function and Purpose
27318
27319@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
27320@sc{gdb/mi} is a line based machine oriented text interface to
27321@value{GDBN} and is activated by specifying using the
27322@option{--interpreter} command line option (@pxref{Mode Options}). It
27323is specifically intended to support the development of systems which
27324use the debugger as just one small component of a larger system.
922fbb7b
AC
27325
27326This chapter is a specification of the @sc{gdb/mi} interface. It is written
27327in the form of a reference manual.
27328
27329Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
27330features described below are incomplete and subject to change
27331(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
27332
27333@unnumberedsec Notation and Terminology
27334
27335@cindex notational conventions, for @sc{gdb/mi}
27336This chapter uses the following notation:
27337
27338@itemize @bullet
27339@item
27340@code{|} separates two alternatives.
27341
27342@item
27343@code{[ @var{something} ]} indicates that @var{something} is optional:
27344it may or may not be given.
27345
27346@item
27347@code{( @var{group} )*} means that @var{group} inside the parentheses
27348may repeat zero or more times.
27349
27350@item
27351@code{( @var{group} )+} means that @var{group} inside the parentheses
27352may repeat one or more times.
27353
27354@item
27355@code{"@var{string}"} means a literal @var{string}.
27356@end itemize
27357
27358@ignore
27359@heading Dependencies
27360@end ignore
27361
922fbb7b 27362@menu
c3b108f7 27363* GDB/MI General Design::
922fbb7b
AC
27364* GDB/MI Command Syntax::
27365* GDB/MI Compatibility with CLI::
af6eff6f 27366* GDB/MI Development and Front Ends::
922fbb7b 27367* GDB/MI Output Records::
ef21caaf 27368* GDB/MI Simple Examples::
922fbb7b 27369* GDB/MI Command Description Format::
ef21caaf 27370* GDB/MI Breakpoint Commands::
3fa7bf06 27371* GDB/MI Catchpoint Commands::
a2c02241
NR
27372* GDB/MI Program Context::
27373* GDB/MI Thread Commands::
5d77fe44 27374* GDB/MI Ada Tasking Commands::
a2c02241
NR
27375* GDB/MI Program Execution::
27376* GDB/MI Stack Manipulation::
27377* GDB/MI Variable Objects::
922fbb7b 27378* GDB/MI Data Manipulation::
a2c02241
NR
27379* GDB/MI Tracepoint Commands::
27380* GDB/MI Symbol Query::
351ff01a 27381* GDB/MI File Commands::
922fbb7b
AC
27382@ignore
27383* GDB/MI Kod Commands::
27384* GDB/MI Memory Overlay Commands::
27385* GDB/MI Signal Handling Commands::
27386@end ignore
922fbb7b 27387* GDB/MI Target Manipulation::
a6b151f1 27388* GDB/MI File Transfer Commands::
ef21caaf 27389* GDB/MI Miscellaneous Commands::
922fbb7b
AC
27390@end menu
27391
c3b108f7
VP
27392@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27393@node GDB/MI General Design
27394@section @sc{gdb/mi} General Design
27395@cindex GDB/MI General Design
27396
27397Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
27398parts---commands sent to @value{GDBN}, responses to those commands
27399and notifications. Each command results in exactly one response,
27400indicating either successful completion of the command, or an error.
27401For the commands that do not resume the target, the response contains the
27402requested information. For the commands that resume the target, the
27403response only indicates whether the target was successfully resumed.
27404Notifications is the mechanism for reporting changes in the state of the
27405target, or in @value{GDBN} state, that cannot conveniently be associated with
27406a command and reported as part of that command response.
27407
27408The important examples of notifications are:
27409@itemize @bullet
27410
27411@item
27412Exec notifications. These are used to report changes in
27413target state---when a target is resumed, or stopped. It would not
27414be feasible to include this information in response of resuming
27415commands, because one resume commands can result in multiple events in
27416different threads. Also, quite some time may pass before any event
27417happens in the target, while a frontend needs to know whether the resuming
27418command itself was successfully executed.
27419
27420@item
27421Console output, and status notifications. Console output
27422notifications are used to report output of CLI commands, as well as
27423diagnostics for other commands. Status notifications are used to
27424report the progress of a long-running operation. Naturally, including
27425this information in command response would mean no output is produced
27426until the command is finished, which is undesirable.
27427
27428@item
27429General notifications. Commands may have various side effects on
27430the @value{GDBN} or target state beyond their official purpose. For example,
27431a command may change the selected thread. Although such changes can
27432be included in command response, using notification allows for more
27433orthogonal frontend design.
27434
27435@end itemize
27436
27437There's no guarantee that whenever an MI command reports an error,
27438@value{GDBN} or the target are in any specific state, and especially,
27439the state is not reverted to the state before the MI command was
27440processed. Therefore, whenever an MI command results in an error,
27441we recommend that the frontend refreshes all the information shown in
27442the user interface.
27443
508094de
NR
27444
27445@menu
27446* Context management::
27447* Asynchronous and non-stop modes::
27448* Thread groups::
27449@end menu
27450
27451@node Context management
c3b108f7
VP
27452@subsection Context management
27453
27454In most cases when @value{GDBN} accesses the target, this access is
27455done in context of a specific thread and frame (@pxref{Frames}).
27456Often, even when accessing global data, the target requires that a thread
27457be specified. The CLI interface maintains the selected thread and frame,
27458and supplies them to target on each command. This is convenient,
27459because a command line user would not want to specify that information
27460explicitly on each command, and because user interacts with
27461@value{GDBN} via a single terminal, so no confusion is possible as
27462to what thread and frame are the current ones.
27463
27464In the case of MI, the concept of selected thread and frame is less
27465useful. First, a frontend can easily remember this information
27466itself. Second, a graphical frontend can have more than one window,
27467each one used for debugging a different thread, and the frontend might
27468want to access additional threads for internal purposes. This
27469increases the risk that by relying on implicitly selected thread, the
27470frontend may be operating on a wrong one. Therefore, each MI command
27471should explicitly specify which thread and frame to operate on. To
27472make it possible, each MI command accepts the @samp{--thread} and
27473@samp{--frame} options, the value to each is @value{GDBN} identifier
27474for thread and frame to operate on.
27475
27476Usually, each top-level window in a frontend allows the user to select
27477a thread and a frame, and remembers the user selection for further
27478operations. However, in some cases @value{GDBN} may suggest that the
27479current thread be changed. For example, when stopping on a breakpoint
27480it is reasonable to switch to the thread where breakpoint is hit. For
27481another example, if the user issues the CLI @samp{thread} command via
27482the frontend, it is desirable to change the frontend's selected thread to the
27483one specified by user. @value{GDBN} communicates the suggestion to
27484change current thread using the @samp{=thread-selected} notification.
27485No such notification is available for the selected frame at the moment.
27486
27487Note that historically, MI shares the selected thread with CLI, so
27488frontends used the @code{-thread-select} to execute commands in the
27489right context. However, getting this to work right is cumbersome. The
27490simplest way is for frontend to emit @code{-thread-select} command
27491before every command. This doubles the number of commands that need
27492to be sent. The alternative approach is to suppress @code{-thread-select}
27493if the selected thread in @value{GDBN} is supposed to be identical to the
27494thread the frontend wants to operate on. However, getting this
27495optimization right can be tricky. In particular, if the frontend
27496sends several commands to @value{GDBN}, and one of the commands changes the
27497selected thread, then the behaviour of subsequent commands will
27498change. So, a frontend should either wait for response from such
27499problematic commands, or explicitly add @code{-thread-select} for
27500all subsequent commands. No frontend is known to do this exactly
27501right, so it is suggested to just always pass the @samp{--thread} and
27502@samp{--frame} options.
27503
508094de 27504@node Asynchronous and non-stop modes
c3b108f7
VP
27505@subsection Asynchronous command execution and non-stop mode
27506
27507On some targets, @value{GDBN} is capable of processing MI commands
27508even while the target is running. This is called @dfn{asynchronous
27509command execution} (@pxref{Background Execution}). The frontend may
27510specify a preferrence for asynchronous execution using the
27511@code{-gdb-set target-async 1} command, which should be emitted before
27512either running the executable or attaching to the target. After the
27513frontend has started the executable or attached to the target, it can
27514find if asynchronous execution is enabled using the
27515@code{-list-target-features} command.
27516
27517Even if @value{GDBN} can accept a command while target is running,
27518many commands that access the target do not work when the target is
27519running. Therefore, asynchronous command execution is most useful
27520when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
27521it is possible to examine the state of one thread, while other threads
27522are running.
27523
27524When a given thread is running, MI commands that try to access the
27525target in the context of that thread may not work, or may work only on
27526some targets. In particular, commands that try to operate on thread's
27527stack will not work, on any target. Commands that read memory, or
27528modify breakpoints, may work or not work, depending on the target. Note
27529that even commands that operate on global state, such as @code{print},
27530@code{set}, and breakpoint commands, still access the target in the
27531context of a specific thread, so frontend should try to find a
27532stopped thread and perform the operation on that thread (using the
27533@samp{--thread} option).
27534
27535Which commands will work in the context of a running thread is
27536highly target dependent. However, the two commands
27537@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
27538to find the state of a thread, will always work.
27539
508094de 27540@node Thread groups
c3b108f7
VP
27541@subsection Thread groups
27542@value{GDBN} may be used to debug several processes at the same time.
27543On some platfroms, @value{GDBN} may support debugging of several
27544hardware systems, each one having several cores with several different
27545processes running on each core. This section describes the MI
27546mechanism to support such debugging scenarios.
27547
27548The key observation is that regardless of the structure of the
27549target, MI can have a global list of threads, because most commands that
27550accept the @samp{--thread} option do not need to know what process that
27551thread belongs to. Therefore, it is not necessary to introduce
27552neither additional @samp{--process} option, nor an notion of the
27553current process in the MI interface. The only strictly new feature
27554that is required is the ability to find how the threads are grouped
27555into processes.
27556
27557To allow the user to discover such grouping, and to support arbitrary
27558hierarchy of machines/cores/processes, MI introduces the concept of a
27559@dfn{thread group}. Thread group is a collection of threads and other
27560thread groups. A thread group always has a string identifier, a type,
27561and may have additional attributes specific to the type. A new
27562command, @code{-list-thread-groups}, returns the list of top-level
27563thread groups, which correspond to processes that @value{GDBN} is
27564debugging at the moment. By passing an identifier of a thread group
27565to the @code{-list-thread-groups} command, it is possible to obtain
27566the members of specific thread group.
27567
27568To allow the user to easily discover processes, and other objects, he
27569wishes to debug, a concept of @dfn{available thread group} is
27570introduced. Available thread group is an thread group that
27571@value{GDBN} is not debugging, but that can be attached to, using the
27572@code{-target-attach} command. The list of available top-level thread
27573groups can be obtained using @samp{-list-thread-groups --available}.
27574In general, the content of a thread group may be only retrieved only
27575after attaching to that thread group.
27576
a79b8f6e
VP
27577Thread groups are related to inferiors (@pxref{Inferiors and
27578Programs}). Each inferior corresponds to a thread group of a special
27579type @samp{process}, and some additional operations are permitted on
27580such thread groups.
27581
922fbb7b
AC
27582@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27583@node GDB/MI Command Syntax
27584@section @sc{gdb/mi} Command Syntax
27585
27586@menu
27587* GDB/MI Input Syntax::
27588* GDB/MI Output Syntax::
922fbb7b
AC
27589@end menu
27590
27591@node GDB/MI Input Syntax
27592@subsection @sc{gdb/mi} Input Syntax
27593
27594@cindex input syntax for @sc{gdb/mi}
27595@cindex @sc{gdb/mi}, input syntax
27596@table @code
27597@item @var{command} @expansion{}
27598@code{@var{cli-command} | @var{mi-command}}
27599
27600@item @var{cli-command} @expansion{}
27601@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
27602@var{cli-command} is any existing @value{GDBN} CLI command.
27603
27604@item @var{mi-command} @expansion{}
27605@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
27606@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
27607
27608@item @var{token} @expansion{}
27609"any sequence of digits"
27610
27611@item @var{option} @expansion{}
27612@code{"-" @var{parameter} [ " " @var{parameter} ]}
27613
27614@item @var{parameter} @expansion{}
27615@code{@var{non-blank-sequence} | @var{c-string}}
27616
27617@item @var{operation} @expansion{}
27618@emph{any of the operations described in this chapter}
27619
27620@item @var{non-blank-sequence} @expansion{}
27621@emph{anything, provided it doesn't contain special characters such as
27622"-", @var{nl}, """ and of course " "}
27623
27624@item @var{c-string} @expansion{}
27625@code{""" @var{seven-bit-iso-c-string-content} """}
27626
27627@item @var{nl} @expansion{}
27628@code{CR | CR-LF}
27629@end table
27630
27631@noindent
27632Notes:
27633
27634@itemize @bullet
27635@item
27636The CLI commands are still handled by the @sc{mi} interpreter; their
27637output is described below.
27638
27639@item
27640The @code{@var{token}}, when present, is passed back when the command
27641finishes.
27642
27643@item
27644Some @sc{mi} commands accept optional arguments as part of the parameter
27645list. Each option is identified by a leading @samp{-} (dash) and may be
27646followed by an optional argument parameter. Options occur first in the
27647parameter list and can be delimited from normal parameters using
27648@samp{--} (this is useful when some parameters begin with a dash).
27649@end itemize
27650
27651Pragmatics:
27652
27653@itemize @bullet
27654@item
27655We want easy access to the existing CLI syntax (for debugging).
27656
27657@item
27658We want it to be easy to spot a @sc{mi} operation.
27659@end itemize
27660
27661@node GDB/MI Output Syntax
27662@subsection @sc{gdb/mi} Output Syntax
27663
27664@cindex output syntax of @sc{gdb/mi}
27665@cindex @sc{gdb/mi}, output syntax
27666The output from @sc{gdb/mi} consists of zero or more out-of-band records
27667followed, optionally, by a single result record. This result record
27668is for the most recent command. The sequence of output records is
594fe323 27669terminated by @samp{(gdb)}.
922fbb7b
AC
27670
27671If an input command was prefixed with a @code{@var{token}} then the
27672corresponding output for that command will also be prefixed by that same
27673@var{token}.
27674
27675@table @code
27676@item @var{output} @expansion{}
594fe323 27677@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
27678
27679@item @var{result-record} @expansion{}
27680@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
27681
27682@item @var{out-of-band-record} @expansion{}
27683@code{@var{async-record} | @var{stream-record}}
27684
27685@item @var{async-record} @expansion{}
27686@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
27687
27688@item @var{exec-async-output} @expansion{}
27689@code{[ @var{token} ] "*" @var{async-output}}
27690
27691@item @var{status-async-output} @expansion{}
27692@code{[ @var{token} ] "+" @var{async-output}}
27693
27694@item @var{notify-async-output} @expansion{}
27695@code{[ @var{token} ] "=" @var{async-output}}
27696
27697@item @var{async-output} @expansion{}
27698@code{@var{async-class} ( "," @var{result} )* @var{nl}}
27699
27700@item @var{result-class} @expansion{}
27701@code{"done" | "running" | "connected" | "error" | "exit"}
27702
27703@item @var{async-class} @expansion{}
27704@code{"stopped" | @var{others}} (where @var{others} will be added
27705depending on the needs---this is still in development).
27706
27707@item @var{result} @expansion{}
27708@code{ @var{variable} "=" @var{value}}
27709
27710@item @var{variable} @expansion{}
27711@code{ @var{string} }
27712
27713@item @var{value} @expansion{}
27714@code{ @var{const} | @var{tuple} | @var{list} }
27715
27716@item @var{const} @expansion{}
27717@code{@var{c-string}}
27718
27719@item @var{tuple} @expansion{}
27720@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
27721
27722@item @var{list} @expansion{}
27723@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
27724@var{result} ( "," @var{result} )* "]" }
27725
27726@item @var{stream-record} @expansion{}
27727@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
27728
27729@item @var{console-stream-output} @expansion{}
27730@code{"~" @var{c-string}}
27731
27732@item @var{target-stream-output} @expansion{}
27733@code{"@@" @var{c-string}}
27734
27735@item @var{log-stream-output} @expansion{}
27736@code{"&" @var{c-string}}
27737
27738@item @var{nl} @expansion{}
27739@code{CR | CR-LF}
27740
27741@item @var{token} @expansion{}
27742@emph{any sequence of digits}.
27743@end table
27744
27745@noindent
27746Notes:
27747
27748@itemize @bullet
27749@item
27750All output sequences end in a single line containing a period.
27751
27752@item
721c02de
VP
27753The @code{@var{token}} is from the corresponding request. Note that
27754for all async output, while the token is allowed by the grammar and
27755may be output by future versions of @value{GDBN} for select async
27756output messages, it is generally omitted. Frontends should treat
27757all async output as reporting general changes in the state of the
27758target and there should be no need to associate async output to any
27759prior command.
922fbb7b
AC
27760
27761@item
27762@cindex status output in @sc{gdb/mi}
27763@var{status-async-output} contains on-going status information about the
27764progress of a slow operation. It can be discarded. All status output is
27765prefixed by @samp{+}.
27766
27767@item
27768@cindex async output in @sc{gdb/mi}
27769@var{exec-async-output} contains asynchronous state change on the target
27770(stopped, started, disappeared). All async output is prefixed by
27771@samp{*}.
27772
27773@item
27774@cindex notify output in @sc{gdb/mi}
27775@var{notify-async-output} contains supplementary information that the
27776client should handle (e.g., a new breakpoint information). All notify
27777output is prefixed by @samp{=}.
27778
27779@item
27780@cindex console output in @sc{gdb/mi}
27781@var{console-stream-output} is output that should be displayed as is in the
27782console. It is the textual response to a CLI command. All the console
27783output is prefixed by @samp{~}.
27784
27785@item
27786@cindex target output in @sc{gdb/mi}
27787@var{target-stream-output} is the output produced by the target program.
27788All the target output is prefixed by @samp{@@}.
27789
27790@item
27791@cindex log output in @sc{gdb/mi}
27792@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
27793instance messages that should be displayed as part of an error log. All
27794the log output is prefixed by @samp{&}.
27795
27796@item
27797@cindex list output in @sc{gdb/mi}
27798New @sc{gdb/mi} commands should only output @var{lists} containing
27799@var{values}.
27800
27801
27802@end itemize
27803
27804@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
27805details about the various output records.
27806
922fbb7b
AC
27807@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27808@node GDB/MI Compatibility with CLI
27809@section @sc{gdb/mi} Compatibility with CLI
27810
27811@cindex compatibility, @sc{gdb/mi} and CLI
27812@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 27813
a2c02241
NR
27814For the developers convenience CLI commands can be entered directly,
27815but there may be some unexpected behaviour. For example, commands
27816that query the user will behave as if the user replied yes, breakpoint
27817command lists are not executed and some CLI commands, such as
27818@code{if}, @code{when} and @code{define}, prompt for further input with
27819@samp{>}, which is not valid MI output.
ef21caaf
NR
27820
27821This feature may be removed at some stage in the future and it is
a2c02241
NR
27822recommended that front ends use the @code{-interpreter-exec} command
27823(@pxref{-interpreter-exec}).
922fbb7b 27824
af6eff6f
NR
27825@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27826@node GDB/MI Development and Front Ends
27827@section @sc{gdb/mi} Development and Front Ends
27828@cindex @sc{gdb/mi} development
27829
27830The application which takes the MI output and presents the state of the
27831program being debugged to the user is called a @dfn{front end}.
27832
27833Although @sc{gdb/mi} is still incomplete, it is currently being used
27834by a variety of front ends to @value{GDBN}. This makes it difficult
27835to introduce new functionality without breaking existing usage. This
27836section tries to minimize the problems by describing how the protocol
27837might change.
27838
27839Some changes in MI need not break a carefully designed front end, and
27840for these the MI version will remain unchanged. The following is a
27841list of changes that may occur within one level, so front ends should
27842parse MI output in a way that can handle them:
27843
27844@itemize @bullet
27845@item
27846New MI commands may be added.
27847
27848@item
27849New fields may be added to the output of any MI command.
27850
36ece8b3
NR
27851@item
27852The range of values for fields with specified values, e.g.,
9f708cb2 27853@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 27854
af6eff6f
NR
27855@c The format of field's content e.g type prefix, may change so parse it
27856@c at your own risk. Yes, in general?
27857
27858@c The order of fields may change? Shouldn't really matter but it might
27859@c resolve inconsistencies.
27860@end itemize
27861
27862If the changes are likely to break front ends, the MI version level
27863will be increased by one. This will allow the front end to parse the
27864output according to the MI version. Apart from mi0, new versions of
27865@value{GDBN} will not support old versions of MI and it will be the
27866responsibility of the front end to work with the new one.
27867
27868@c Starting with mi3, add a new command -mi-version that prints the MI
27869@c version?
27870
27871The best way to avoid unexpected changes in MI that might break your front
27872end is to make your project known to @value{GDBN} developers and
7a9a6b69 27873follow development on @email{gdb@@sourceware.org} and
fa0f268d 27874@email{gdb-patches@@sourceware.org}.
af6eff6f
NR
27875@cindex mailing lists
27876
922fbb7b
AC
27877@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27878@node GDB/MI Output Records
27879@section @sc{gdb/mi} Output Records
27880
27881@menu
27882* GDB/MI Result Records::
27883* GDB/MI Stream Records::
82f68b1c 27884* GDB/MI Async Records::
54516a0b 27885* GDB/MI Breakpoint Information::
c3b108f7 27886* GDB/MI Frame Information::
dc146f7c 27887* GDB/MI Thread Information::
4368ebeb 27888* GDB/MI Ada Exception Information::
922fbb7b
AC
27889@end menu
27890
27891@node GDB/MI Result Records
27892@subsection @sc{gdb/mi} Result Records
27893
27894@cindex result records in @sc{gdb/mi}
27895@cindex @sc{gdb/mi}, result records
27896In addition to a number of out-of-band notifications, the response to a
27897@sc{gdb/mi} command includes one of the following result indications:
27898
27899@table @code
27900@findex ^done
27901@item "^done" [ "," @var{results} ]
27902The synchronous operation was successful, @code{@var{results}} are the return
27903values.
27904
27905@item "^running"
27906@findex ^running
8e9c5e02
VP
27907This result record is equivalent to @samp{^done}. Historically, it
27908was output instead of @samp{^done} if the command has resumed the
27909target. This behaviour is maintained for backward compatibility, but
27910all frontends should treat @samp{^done} and @samp{^running}
27911identically and rely on the @samp{*running} output record to determine
27912which threads are resumed.
922fbb7b 27913
ef21caaf
NR
27914@item "^connected"
27915@findex ^connected
3f94c067 27916@value{GDBN} has connected to a remote target.
ef21caaf 27917
922fbb7b
AC
27918@item "^error" "," @var{c-string}
27919@findex ^error
27920The operation failed. The @code{@var{c-string}} contains the corresponding
27921error message.
ef21caaf
NR
27922
27923@item "^exit"
27924@findex ^exit
3f94c067 27925@value{GDBN} has terminated.
ef21caaf 27926
922fbb7b
AC
27927@end table
27928
27929@node GDB/MI Stream Records
27930@subsection @sc{gdb/mi} Stream Records
27931
27932@cindex @sc{gdb/mi}, stream records
27933@cindex stream records in @sc{gdb/mi}
27934@value{GDBN} internally maintains a number of output streams: the console, the
27935target, and the log. The output intended for each of these streams is
27936funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
27937
27938Each stream record begins with a unique @dfn{prefix character} which
27939identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
27940Syntax}). In addition to the prefix, each stream record contains a
27941@code{@var{string-output}}. This is either raw text (with an implicit new
27942line) or a quoted C string (which does not contain an implicit newline).
27943
27944@table @code
27945@item "~" @var{string-output}
27946The console output stream contains text that should be displayed in the
27947CLI console window. It contains the textual responses to CLI commands.
27948
27949@item "@@" @var{string-output}
27950The target output stream contains any textual output from the running
ef21caaf
NR
27951target. This is only present when GDB's event loop is truly
27952asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
27953
27954@item "&" @var{string-output}
27955The log stream contains debugging messages being produced by @value{GDBN}'s
27956internals.
27957@end table
27958
82f68b1c
VP
27959@node GDB/MI Async Records
27960@subsection @sc{gdb/mi} Async Records
922fbb7b 27961
82f68b1c
VP
27962@cindex async records in @sc{gdb/mi}
27963@cindex @sc{gdb/mi}, async records
27964@dfn{Async} records are used to notify the @sc{gdb/mi} client of
922fbb7b 27965additional changes that have occurred. Those changes can either be a
82f68b1c 27966consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
922fbb7b
AC
27967target activity (e.g., target stopped).
27968
8eb41542 27969The following is the list of possible async records:
922fbb7b
AC
27970
27971@table @code
034dad6f 27972
e1ac3328
VP
27973@item *running,thread-id="@var{thread}"
27974The target is now running. The @var{thread} field tells which
27975specific thread is now running, and can be @samp{all} if all threads
27976are running. The frontend should assume that no interaction with a
27977running thread is possible after this notification is produced.
27978The frontend should not assume that this notification is output
27979only once for any command. @value{GDBN} may emit this notification
27980several times, either for different threads, because it cannot resume
27981all threads together, or even for a single thread, if the thread must
27982be stepped though some code before letting it run freely.
27983
dc146f7c 27984@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
82f68b1c
VP
27985The target has stopped. The @var{reason} field can have one of the
27986following values:
034dad6f
BR
27987
27988@table @code
27989@item breakpoint-hit
27990A breakpoint was reached.
27991@item watchpoint-trigger
27992A watchpoint was triggered.
27993@item read-watchpoint-trigger
27994A read watchpoint was triggered.
27995@item access-watchpoint-trigger
27996An access watchpoint was triggered.
27997@item function-finished
27998An -exec-finish or similar CLI command was accomplished.
27999@item location-reached
28000An -exec-until or similar CLI command was accomplished.
28001@item watchpoint-scope
28002A watchpoint has gone out of scope.
28003@item end-stepping-range
28004An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
28005similar CLI command was accomplished.
28006@item exited-signalled
28007The inferior exited because of a signal.
28008@item exited
28009The inferior exited.
28010@item exited-normally
28011The inferior exited normally.
28012@item signal-received
28013A signal was received by the inferior.
36dfb11c
TT
28014@item solib-event
28015The inferior has stopped due to a library being loaded or unloaded.
edcc5120
TT
28016This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
28017set or when a @code{catch load} or @code{catch unload} catchpoint is
28018in use (@pxref{Set Catchpoints}).
36dfb11c
TT
28019@item fork
28020The inferior has forked. This is reported when @code{catch fork}
28021(@pxref{Set Catchpoints}) has been used.
28022@item vfork
28023The inferior has vforked. This is reported in when @code{catch vfork}
28024(@pxref{Set Catchpoints}) has been used.
28025@item syscall-entry
28026The inferior entered a system call. This is reported when @code{catch
28027syscall} (@pxref{Set Catchpoints}) has been used.
28028@item syscall-entry
28029The inferior returned from a system call. This is reported when
28030@code{catch syscall} (@pxref{Set Catchpoints}) has been used.
28031@item exec
28032The inferior called @code{exec}. This is reported when @code{catch exec}
28033(@pxref{Set Catchpoints}) has been used.
922fbb7b
AC
28034@end table
28035
c3b108f7
VP
28036The @var{id} field identifies the thread that directly caused the stop
28037-- for example by hitting a breakpoint. Depending on whether all-stop
28038mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
28039stop all threads, or only the thread that directly triggered the stop.
28040If all threads are stopped, the @var{stopped} field will have the
28041value of @code{"all"}. Otherwise, the value of the @var{stopped}
28042field will be a list of thread identifiers. Presently, this list will
28043always include a single thread, but frontend should be prepared to see
dc146f7c
VP
28044several threads in the list. The @var{core} field reports the
28045processor core on which the stop event has happened. This field may be absent
28046if such information is not available.
c3b108f7 28047
a79b8f6e
VP
28048@item =thread-group-added,id="@var{id}"
28049@itemx =thread-group-removed,id="@var{id}"
28050A thread group was either added or removed. The @var{id} field
28051contains the @value{GDBN} identifier of the thread group. When a thread
28052group is added, it generally might not be associated with a running
28053process. When a thread group is removed, its id becomes invalid and
28054cannot be used in any way.
28055
28056@item =thread-group-started,id="@var{id}",pid="@var{pid}"
28057A thread group became associated with a running program,
28058either because the program was just started or the thread group
28059was attached to a program. The @var{id} field contains the
28060@value{GDBN} identifier of the thread group. The @var{pid} field
28061contains process identifier, specific to the operating system.
28062
8cf64490 28063@item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
a79b8f6e
VP
28064A thread group is no longer associated with a running program,
28065either because the program has exited, or because it was detached
c3b108f7 28066from. The @var{id} field contains the @value{GDBN} identifier of the
8cf64490
TT
28067thread group. @var{code} is the exit code of the inferior; it exists
28068only when the inferior exited with some code.
c3b108f7
VP
28069
28070@item =thread-created,id="@var{id}",group-id="@var{gid}"
28071@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
82f68b1c 28072A thread either was created, or has exited. The @var{id} field
c3b108f7
VP
28073contains the @value{GDBN} identifier of the thread. The @var{gid}
28074field identifies the thread group this thread belongs to.
66bb093b
VP
28075
28076@item =thread-selected,id="@var{id}"
28077Informs that the selected thread was changed as result of the last
28078command. This notification is not emitted as result of @code{-thread-select}
28079command but is emitted whenever an MI command that is not documented
28080to change the selected thread actually changes it. In particular,
28081invoking, directly or indirectly (via user-defined command), the CLI
28082@code{thread} command, will generate this notification.
28083
28084We suggest that in response to this notification, front ends
28085highlight the selected thread and cause subsequent commands to apply to
28086that thread.
28087
c86cf029
VP
28088@item =library-loaded,...
28089Reports that a new library file was loaded by the program. This
28090notification has 4 fields---@var{id}, @var{target-name},
134eb42c 28091@var{host-name}, and @var{symbols-loaded}. The @var{id} field is an
c86cf029
VP
28092opaque identifier of the library. For remote debugging case,
28093@var{target-name} and @var{host-name} fields give the name of the
134eb42c
VP
28094library file on the target, and on the host respectively. For native
28095debugging, both those fields have the same value. The
f1cbe1d3
TT
28096@var{symbols-loaded} field is emitted only for backward compatibility
28097and should not be relied on to convey any useful information. The
28098@var{thread-group} field, if present, specifies the id of the thread
28099group in whose context the library was loaded. If the field is
28100absent, it means the library was loaded in the context of all present
28101thread groups.
c86cf029
VP
28102
28103@item =library-unloaded,...
134eb42c 28104Reports that a library was unloaded by the program. This notification
c86cf029 28105has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
a79b8f6e
VP
28106the same meaning as for the @code{=library-loaded} notification.
28107The @var{thread-group} field, if present, specifies the id of the
28108thread group in whose context the library was unloaded. If the field is
28109absent, it means the library was unloaded in the context of all present
28110thread groups.
c86cf029 28111
201b4506
YQ
28112@item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
28113@itemx =traceframe-changed,end
28114Reports that the trace frame was changed and its new number is
28115@var{tfnum}. The number of the tracepoint associated with this trace
28116frame is @var{tpnum}.
28117
134a2066 28118@item =tsv-created,name=@var{name},initial=@var{initial}
bb25a15c 28119Reports that the new trace state variable @var{name} is created with
134a2066 28120initial value @var{initial}.
bb25a15c
YQ
28121
28122@item =tsv-deleted,name=@var{name}
28123@itemx =tsv-deleted
28124Reports that the trace state variable @var{name} is deleted or all
28125trace state variables are deleted.
28126
134a2066
YQ
28127@item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
28128Reports that the trace state variable @var{name} is modified with
28129the initial value @var{initial}. The current value @var{current} of
28130trace state variable is optional and is reported if the current
28131value of trace state variable is known.
28132
8d3788bd
VP
28133@item =breakpoint-created,bkpt=@{...@}
28134@itemx =breakpoint-modified,bkpt=@{...@}
d9f08f52 28135@itemx =breakpoint-deleted,id=@var{number}
8d3788bd
VP
28136Reports that a breakpoint was created, modified, or deleted,
28137respectively. Only user-visible breakpoints are reported to the MI
28138user.
28139
28140The @var{bkpt} argument is of the same form as returned by the various
d9f08f52
YQ
28141breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
28142@var{number} is the ordinal number of the breakpoint.
8d3788bd
VP
28143
28144Note that if a breakpoint is emitted in the result record of a
28145command, then it will not also be emitted in an async record.
28146
82a90ccf
YQ
28147@item =record-started,thread-group="@var{id}"
28148@itemx =record-stopped,thread-group="@var{id}"
28149Execution log recording was either started or stopped on an
28150inferior. The @var{id} is the @value{GDBN} identifier of the thread
28151group corresponding to the affected inferior.
28152
5b9afe8a
YQ
28153@item =cmd-param-changed,param=@var{param},value=@var{value}
28154Reports that a parameter of the command @code{set @var{param}} is
28155changed to @var{value}. In the multi-word @code{set} command,
28156the @var{param} is the whole parameter list to @code{set} command.
28157For example, In command @code{set check type on}, @var{param}
28158is @code{check type} and @var{value} is @code{on}.
8de0566d
YQ
28159
28160@item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
28161Reports that bytes from @var{addr} to @var{data} + @var{len} were
28162written in an inferior. The @var{id} is the identifier of the
28163thread group corresponding to the affected inferior. The optional
28164@code{type="code"} part is reported if the memory written to holds
28165executable code.
82f68b1c
VP
28166@end table
28167
54516a0b
TT
28168@node GDB/MI Breakpoint Information
28169@subsection @sc{gdb/mi} Breakpoint Information
28170
28171When @value{GDBN} reports information about a breakpoint, a
28172tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
28173following fields:
28174
28175@table @code
28176@item number
28177The breakpoint number. For a breakpoint that represents one location
28178of a multi-location breakpoint, this will be a dotted pair, like
28179@samp{1.2}.
28180
28181@item type
28182The type of the breakpoint. For ordinary breakpoints this will be
28183@samp{breakpoint}, but many values are possible.
28184
8ac3646f
TT
28185@item catch-type
28186If the type of the breakpoint is @samp{catchpoint}, then this
28187indicates the exact type of catchpoint.
28188
54516a0b
TT
28189@item disp
28190This is the breakpoint disposition---either @samp{del}, meaning that
28191the breakpoint will be deleted at the next stop, or @samp{keep},
28192meaning that the breakpoint will not be deleted.
28193
28194@item enabled
28195This indicates whether the breakpoint is enabled, in which case the
28196value is @samp{y}, or disabled, in which case the value is @samp{n}.
28197Note that this is not the same as the field @code{enable}.
28198
28199@item addr
28200The address of the breakpoint. This may be a hexidecimal number,
28201giving the address; or the string @samp{<PENDING>}, for a pending
28202breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
28203multiple locations. This field will not be present if no address can
28204be determined. For example, a watchpoint does not have an address.
28205
28206@item func
28207If known, the function in which the breakpoint appears.
28208If not known, this field is not present.
28209
28210@item filename
28211The name of the source file which contains this function, if known.
28212If not known, this field is not present.
28213
28214@item fullname
28215The full file name of the source file which contains this function, if
28216known. If not known, this field is not present.
28217
28218@item line
28219The line number at which this breakpoint appears, if known.
28220If not known, this field is not present.
28221
28222@item at
28223If the source file is not known, this field may be provided. If
28224provided, this holds the address of the breakpoint, possibly followed
28225by a symbol name.
28226
28227@item pending
28228If this breakpoint is pending, this field is present and holds the
28229text used to set the breakpoint, as entered by the user.
28230
28231@item evaluated-by
28232Where this breakpoint's condition is evaluated, either @samp{host} or
28233@samp{target}.
28234
28235@item thread
28236If this is a thread-specific breakpoint, then this identifies the
28237thread in which the breakpoint can trigger.
28238
28239@item task
28240If this breakpoint is restricted to a particular Ada task, then this
28241field will hold the task identifier.
28242
28243@item cond
28244If the breakpoint is conditional, this is the condition expression.
28245
28246@item ignore
28247The ignore count of the breakpoint.
28248
28249@item enable
28250The enable count of the breakpoint.
28251
28252@item traceframe-usage
28253FIXME.
28254
28255@item static-tracepoint-marker-string-id
28256For a static tracepoint, the name of the static tracepoint marker.
28257
28258@item mask
28259For a masked watchpoint, this is the mask.
28260
28261@item pass
28262A tracepoint's pass count.
28263
28264@item original-location
28265The location of the breakpoint as originally specified by the user.
28266This field is optional.
28267
28268@item times
28269The number of times the breakpoint has been hit.
28270
28271@item installed
28272This field is only given for tracepoints. This is either @samp{y},
28273meaning that the tracepoint is installed, or @samp{n}, meaning that it
28274is not.
28275
28276@item what
28277Some extra data, the exact contents of which are type-dependent.
28278
28279@end table
28280
28281For example, here is what the output of @code{-break-insert}
28282(@pxref{GDB/MI Breakpoint Commands}) might be:
28283
28284@smallexample
28285-> -break-insert main
28286<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28287 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
28288 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
28289 times="0"@}
54516a0b
TT
28290<- (gdb)
28291@end smallexample
28292
c3b108f7
VP
28293@node GDB/MI Frame Information
28294@subsection @sc{gdb/mi} Frame Information
28295
28296Response from many MI commands includes an information about stack
28297frame. This information is a tuple that may have the following
28298fields:
28299
28300@table @code
28301@item level
28302The level of the stack frame. The innermost frame has the level of
28303zero. This field is always present.
28304
28305@item func
28306The name of the function corresponding to the frame. This field may
28307be absent if @value{GDBN} is unable to determine the function name.
28308
28309@item addr
28310The code address for the frame. This field is always present.
28311
28312@item file
28313The name of the source files that correspond to the frame's code
28314address. This field may be absent.
28315
28316@item line
28317The source line corresponding to the frames' code address. This field
28318may be absent.
28319
28320@item from
28321The name of the binary file (either executable or shared library) the
28322corresponds to the frame's code address. This field may be absent.
28323
28324@end table
82f68b1c 28325
dc146f7c
VP
28326@node GDB/MI Thread Information
28327@subsection @sc{gdb/mi} Thread Information
28328
28329Whenever @value{GDBN} has to report an information about a thread, it
28330uses a tuple with the following fields:
28331
28332@table @code
28333@item id
28334The numeric id assigned to the thread by @value{GDBN}. This field is
28335always present.
28336
28337@item target-id
28338Target-specific string identifying the thread. This field is always present.
28339
28340@item details
28341Additional information about the thread provided by the target.
28342It is supposed to be human-readable and not interpreted by the
28343frontend. This field is optional.
28344
28345@item state
28346Either @samp{stopped} or @samp{running}, depending on whether the
28347thread is presently running. This field is always present.
28348
28349@item core
28350The value of this field is an integer number of the processor core the
28351thread was last seen on. This field is optional.
28352@end table
28353
956a9fb9
JB
28354@node GDB/MI Ada Exception Information
28355@subsection @sc{gdb/mi} Ada Exception Information
28356
28357Whenever a @code{*stopped} record is emitted because the program
28358stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
28359@value{GDBN} provides the name of the exception that was raised via
28360the @code{exception-name} field.
922fbb7b 28361
ef21caaf
NR
28362@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28363@node GDB/MI Simple Examples
28364@section Simple Examples of @sc{gdb/mi} Interaction
28365@cindex @sc{gdb/mi}, simple examples
28366
28367This subsection presents several simple examples of interaction using
28368the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
28369following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
28370the output received from @sc{gdb/mi}.
28371
d3e8051b 28372Note the line breaks shown in the examples are here only for
ef21caaf
NR
28373readability, they don't appear in the real output.
28374
79a6e687 28375@subheading Setting a Breakpoint
ef21caaf
NR
28376
28377Setting a breakpoint generates synchronous output which contains detailed
28378information of the breakpoint.
28379
28380@smallexample
28381-> -break-insert main
28382<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28383 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
28384 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
28385 times="0"@}
ef21caaf
NR
28386<- (gdb)
28387@end smallexample
28388
28389@subheading Program Execution
28390
28391Program execution generates asynchronous records and MI gives the
28392reason that execution stopped.
28393
28394@smallexample
28395-> -exec-run
28396<- ^running
28397<- (gdb)
a47ec5fe 28398<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
ef21caaf
NR
28399 frame=@{addr="0x08048564",func="main",
28400 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
28401 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
28402<- (gdb)
28403-> -exec-continue
28404<- ^running
28405<- (gdb)
28406<- *stopped,reason="exited-normally"
28407<- (gdb)
28408@end smallexample
28409
3f94c067 28410@subheading Quitting @value{GDBN}
ef21caaf 28411
3f94c067 28412Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
28413
28414@smallexample
28415-> (gdb)
28416<- -gdb-exit
28417<- ^exit
28418@end smallexample
28419
a6b29f87
VP
28420Please note that @samp{^exit} is printed immediately, but it might
28421take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
28422performs necessary cleanups, including killing programs being debugged
28423or disconnecting from debug hardware, so the frontend should wait till
28424@value{GDBN} exits and should only forcibly kill @value{GDBN} if it
28425fails to exit in reasonable time.
28426
a2c02241 28427@subheading A Bad Command
ef21caaf
NR
28428
28429Here's what happens if you pass a non-existent command:
28430
28431@smallexample
28432-> -rubbish
28433<- ^error,msg="Undefined MI command: rubbish"
594fe323 28434<- (gdb)
ef21caaf
NR
28435@end smallexample
28436
28437
922fbb7b
AC
28438@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28439@node GDB/MI Command Description Format
28440@section @sc{gdb/mi} Command Description Format
28441
28442The remaining sections describe blocks of commands. Each block of
28443commands is laid out in a fashion similar to this section.
28444
922fbb7b
AC
28445@subheading Motivation
28446
28447The motivation for this collection of commands.
28448
28449@subheading Introduction
28450
28451A brief introduction to this collection of commands as a whole.
28452
28453@subheading Commands
28454
28455For each command in the block, the following is described:
28456
28457@subsubheading Synopsis
28458
28459@smallexample
28460 -command @var{args}@dots{}
28461@end smallexample
28462
922fbb7b
AC
28463@subsubheading Result
28464
265eeb58 28465@subsubheading @value{GDBN} Command
922fbb7b 28466
265eeb58 28467The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
28468
28469@subsubheading Example
28470
ef21caaf
NR
28471Example(s) formatted for readability. Some of the described commands have
28472not been implemented yet and these are labeled N.A.@: (not available).
28473
28474
922fbb7b 28475@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
28476@node GDB/MI Breakpoint Commands
28477@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
28478
28479@cindex breakpoint commands for @sc{gdb/mi}
28480@cindex @sc{gdb/mi}, breakpoint commands
28481This section documents @sc{gdb/mi} commands for manipulating
28482breakpoints.
28483
28484@subheading The @code{-break-after} Command
28485@findex -break-after
28486
28487@subsubheading Synopsis
28488
28489@smallexample
28490 -break-after @var{number} @var{count}
28491@end smallexample
28492
28493The breakpoint number @var{number} is not in effect until it has been
28494hit @var{count} times. To see how this is reflected in the output of
28495the @samp{-break-list} command, see the description of the
28496@samp{-break-list} command below.
28497
28498@subsubheading @value{GDBN} Command
28499
28500The corresponding @value{GDBN} command is @samp{ignore}.
28501
28502@subsubheading Example
28503
28504@smallexample
594fe323 28505(gdb)
922fbb7b 28506-break-insert main
a47ec5fe
AR
28507^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28508enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
28509fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
28510times="0"@}
594fe323 28511(gdb)
922fbb7b
AC
28512-break-after 1 3
28513~
28514^done
594fe323 28515(gdb)
922fbb7b
AC
28516-break-list
28517^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28518hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28519@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28520@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28521@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28522@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28523@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28524body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 28525addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 28526line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 28527(gdb)
922fbb7b
AC
28528@end smallexample
28529
28530@ignore
28531@subheading The @code{-break-catch} Command
28532@findex -break-catch
48cb2d85 28533@end ignore
922fbb7b
AC
28534
28535@subheading The @code{-break-commands} Command
28536@findex -break-commands
922fbb7b 28537
48cb2d85
VP
28538@subsubheading Synopsis
28539
28540@smallexample
28541 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
28542@end smallexample
28543
28544Specifies the CLI commands that should be executed when breakpoint
28545@var{number} is hit. The parameters @var{command1} to @var{commandN}
28546are the commands. If no command is specified, any previously-set
28547commands are cleared. @xref{Break Commands}. Typical use of this
28548functionality is tracing a program, that is, printing of values of
28549some variables whenever breakpoint is hit and then continuing.
28550
28551@subsubheading @value{GDBN} Command
28552
28553The corresponding @value{GDBN} command is @samp{commands}.
28554
28555@subsubheading Example
28556
28557@smallexample
28558(gdb)
28559-break-insert main
28560^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28561enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
28562fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
28563times="0"@}
48cb2d85
VP
28564(gdb)
28565-break-commands 1 "print v" "continue"
28566^done
28567(gdb)
28568@end smallexample
922fbb7b
AC
28569
28570@subheading The @code{-break-condition} Command
28571@findex -break-condition
28572
28573@subsubheading Synopsis
28574
28575@smallexample
28576 -break-condition @var{number} @var{expr}
28577@end smallexample
28578
28579Breakpoint @var{number} will stop the program only if the condition in
28580@var{expr} is true. The condition becomes part of the
28581@samp{-break-list} output (see the description of the @samp{-break-list}
28582command below).
28583
28584@subsubheading @value{GDBN} Command
28585
28586The corresponding @value{GDBN} command is @samp{condition}.
28587
28588@subsubheading Example
28589
28590@smallexample
594fe323 28591(gdb)
922fbb7b
AC
28592-break-condition 1 1
28593^done
594fe323 28594(gdb)
922fbb7b
AC
28595-break-list
28596^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28597hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28598@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28599@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28600@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28601@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28602@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28603body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 28604addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 28605line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 28606(gdb)
922fbb7b
AC
28607@end smallexample
28608
28609@subheading The @code{-break-delete} Command
28610@findex -break-delete
28611
28612@subsubheading Synopsis
28613
28614@smallexample
28615 -break-delete ( @var{breakpoint} )+
28616@end smallexample
28617
28618Delete the breakpoint(s) whose number(s) are specified in the argument
28619list. This is obviously reflected in the breakpoint list.
28620
79a6e687 28621@subsubheading @value{GDBN} Command
922fbb7b
AC
28622
28623The corresponding @value{GDBN} command is @samp{delete}.
28624
28625@subsubheading Example
28626
28627@smallexample
594fe323 28628(gdb)
922fbb7b
AC
28629-break-delete 1
28630^done
594fe323 28631(gdb)
922fbb7b
AC
28632-break-list
28633^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
28634hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28635@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28636@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28637@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28638@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28639@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28640body=[]@}
594fe323 28641(gdb)
922fbb7b
AC
28642@end smallexample
28643
28644@subheading The @code{-break-disable} Command
28645@findex -break-disable
28646
28647@subsubheading Synopsis
28648
28649@smallexample
28650 -break-disable ( @var{breakpoint} )+
28651@end smallexample
28652
28653Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
28654break list is now set to @samp{n} for the named @var{breakpoint}(s).
28655
28656@subsubheading @value{GDBN} Command
28657
28658The corresponding @value{GDBN} command is @samp{disable}.
28659
28660@subsubheading Example
28661
28662@smallexample
594fe323 28663(gdb)
922fbb7b
AC
28664-break-disable 2
28665^done
594fe323 28666(gdb)
922fbb7b
AC
28667-break-list
28668^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28669hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28670@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28671@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28672@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28673@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28674@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28675body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102 28676addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 28677line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 28678(gdb)
922fbb7b
AC
28679@end smallexample
28680
28681@subheading The @code{-break-enable} Command
28682@findex -break-enable
28683
28684@subsubheading Synopsis
28685
28686@smallexample
28687 -break-enable ( @var{breakpoint} )+
28688@end smallexample
28689
28690Enable (previously disabled) @var{breakpoint}(s).
28691
28692@subsubheading @value{GDBN} Command
28693
28694The corresponding @value{GDBN} command is @samp{enable}.
28695
28696@subsubheading Example
28697
28698@smallexample
594fe323 28699(gdb)
922fbb7b
AC
28700-break-enable 2
28701^done
594fe323 28702(gdb)
922fbb7b
AC
28703-break-list
28704^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28705hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28706@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28707@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28708@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28709@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28710@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28711body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 28712addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 28713line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 28714(gdb)
922fbb7b
AC
28715@end smallexample
28716
28717@subheading The @code{-break-info} Command
28718@findex -break-info
28719
28720@subsubheading Synopsis
28721
28722@smallexample
28723 -break-info @var{breakpoint}
28724@end smallexample
28725
28726@c REDUNDANT???
28727Get information about a single breakpoint.
28728
54516a0b
TT
28729The result is a table of breakpoints. @xref{GDB/MI Breakpoint
28730Information}, for details on the format of each breakpoint in the
28731table.
28732
79a6e687 28733@subsubheading @value{GDBN} Command
922fbb7b
AC
28734
28735The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
28736
28737@subsubheading Example
28738N.A.
28739
28740@subheading The @code{-break-insert} Command
28741@findex -break-insert
28742
28743@subsubheading Synopsis
28744
28745@smallexample
18148017 28746 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
922fbb7b 28747 [ -c @var{condition} ] [ -i @var{ignore-count} ]
472a2379 28748 [ -p @var{thread-id} ] [ @var{location} ]
922fbb7b
AC
28749@end smallexample
28750
28751@noindent
afe8ab22 28752If specified, @var{location}, can be one of:
922fbb7b
AC
28753
28754@itemize @bullet
28755@item function
28756@c @item +offset
28757@c @item -offset
28758@c @item linenum
28759@item filename:linenum
28760@item filename:function
28761@item *address
28762@end itemize
28763
28764The possible optional parameters of this command are:
28765
28766@table @samp
28767@item -t
948d5102 28768Insert a temporary breakpoint.
922fbb7b
AC
28769@item -h
28770Insert a hardware breakpoint.
afe8ab22
VP
28771@item -f
28772If @var{location} cannot be parsed (for example if it
28773refers to unknown files or functions), create a pending
28774breakpoint. Without this flag, @value{GDBN} will report
28775an error, and won't create a breakpoint, if @var{location}
28776cannot be parsed.
41447f92
VP
28777@item -d
28778Create a disabled breakpoint.
18148017
VP
28779@item -a
28780Create a tracepoint. @xref{Tracepoints}. When this parameter
28781is used together with @samp{-h}, a fast tracepoint is created.
472a2379
KS
28782@item -c @var{condition}
28783Make the breakpoint conditional on @var{condition}.
28784@item -i @var{ignore-count}
28785Initialize the @var{ignore-count}.
28786@item -p @var{thread-id}
28787Restrict the breakpoint to the specified @var{thread-id}.
922fbb7b
AC
28788@end table
28789
28790@subsubheading Result
28791
54516a0b
TT
28792@xref{GDB/MI Breakpoint Information}, for details on the format of the
28793resulting breakpoint.
922fbb7b
AC
28794
28795Note: this format is open to change.
28796@c An out-of-band breakpoint instead of part of the result?
28797
28798@subsubheading @value{GDBN} Command
28799
28800The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
496ee73e 28801@samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
922fbb7b
AC
28802
28803@subsubheading Example
28804
28805@smallexample
594fe323 28806(gdb)
922fbb7b 28807-break-insert main
948d5102 28808^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
998580f1
MK
28809fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
28810times="0"@}
594fe323 28811(gdb)
922fbb7b 28812-break-insert -t foo
948d5102 28813^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
998580f1
MK
28814fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
28815times="0"@}
594fe323 28816(gdb)
922fbb7b
AC
28817-break-list
28818^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
28819hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28820@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28821@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28822@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28823@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28824@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28825body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 28826addr="0x0001072c", func="main",file="recursive2.c",
998580f1
MK
28827fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
28828times="0"@},
922fbb7b 28829bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102 28830addr="0x00010774",func="foo",file="recursive2.c",
998580f1
MK
28831fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
28832times="0"@}]@}
594fe323 28833(gdb)
496ee73e
KS
28834@c -break-insert -r foo.*
28835@c ~int foo(int, int);
28836@c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
998580f1
MK
28837@c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
28838@c times="0"@}
496ee73e 28839@c (gdb)
922fbb7b
AC
28840@end smallexample
28841
28842@subheading The @code{-break-list} Command
28843@findex -break-list
28844
28845@subsubheading Synopsis
28846
28847@smallexample
28848 -break-list
28849@end smallexample
28850
28851Displays the list of inserted breakpoints, showing the following fields:
28852
28853@table @samp
28854@item Number
28855number of the breakpoint
28856@item Type
28857type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
28858@item Disposition
28859should the breakpoint be deleted or disabled when it is hit: @samp{keep}
28860or @samp{nokeep}
28861@item Enabled
28862is the breakpoint enabled or no: @samp{y} or @samp{n}
28863@item Address
28864memory location at which the breakpoint is set
28865@item What
28866logical location of the breakpoint, expressed by function name, file
28867name, line number
998580f1
MK
28868@item Thread-groups
28869list of thread groups to which this breakpoint applies
922fbb7b
AC
28870@item Times
28871number of times the breakpoint has been hit
28872@end table
28873
28874If there are no breakpoints or watchpoints, the @code{BreakpointTable}
28875@code{body} field is an empty list.
28876
28877@subsubheading @value{GDBN} Command
28878
28879The corresponding @value{GDBN} command is @samp{info break}.
28880
28881@subsubheading Example
28882
28883@smallexample
594fe323 28884(gdb)
922fbb7b
AC
28885-break-list
28886^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
28887hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28888@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28889@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28890@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28891@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28892@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28893body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
998580f1
MK
28894addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
28895times="0"@},
922fbb7b 28896bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 28897addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
998580f1 28898line="13",thread-groups=["i1"],times="0"@}]@}
594fe323 28899(gdb)
922fbb7b
AC
28900@end smallexample
28901
28902Here's an example of the result when there are no breakpoints:
28903
28904@smallexample
594fe323 28905(gdb)
922fbb7b
AC
28906-break-list
28907^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
28908hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28909@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28910@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28911@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28912@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28913@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28914body=[]@}
594fe323 28915(gdb)
922fbb7b
AC
28916@end smallexample
28917
18148017
VP
28918@subheading The @code{-break-passcount} Command
28919@findex -break-passcount
28920
28921@subsubheading Synopsis
28922
28923@smallexample
28924 -break-passcount @var{tracepoint-number} @var{passcount}
28925@end smallexample
28926
28927Set the passcount for tracepoint @var{tracepoint-number} to
28928@var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
28929is not a tracepoint, error is emitted. This corresponds to CLI
28930command @samp{passcount}.
28931
922fbb7b
AC
28932@subheading The @code{-break-watch} Command
28933@findex -break-watch
28934
28935@subsubheading Synopsis
28936
28937@smallexample
28938 -break-watch [ -a | -r ]
28939@end smallexample
28940
28941Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 28942@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 28943read from or on a write to the memory location. With the @samp{-r}
d3e8051b 28944option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
28945trigger only when the memory location is accessed for reading. Without
28946either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 28947i.e., it will trigger when the memory location is accessed for writing.
79a6e687 28948@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
28949
28950Note that @samp{-break-list} will report a single list of watchpoints and
28951breakpoints inserted.
28952
28953@subsubheading @value{GDBN} Command
28954
28955The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
28956@samp{rwatch}.
28957
28958@subsubheading Example
28959
28960Setting a watchpoint on a variable in the @code{main} function:
28961
28962@smallexample
594fe323 28963(gdb)
922fbb7b
AC
28964-break-watch x
28965^done,wpt=@{number="2",exp="x"@}
594fe323 28966(gdb)
922fbb7b
AC
28967-exec-continue
28968^running
0869d01b
NR
28969(gdb)
28970*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 28971value=@{old="-268439212",new="55"@},
76ff342d 28972frame=@{func="main",args=[],file="recursive2.c",
948d5102 28973fullname="/home/foo/bar/recursive2.c",line="5"@}
594fe323 28974(gdb)
922fbb7b
AC
28975@end smallexample
28976
28977Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
28978the program execution twice: first for the variable changing value, then
28979for the watchpoint going out of scope.
28980
28981@smallexample
594fe323 28982(gdb)
922fbb7b
AC
28983-break-watch C
28984^done,wpt=@{number="5",exp="C"@}
594fe323 28985(gdb)
922fbb7b
AC
28986-exec-continue
28987^running
0869d01b
NR
28988(gdb)
28989*stopped,reason="watchpoint-trigger",
922fbb7b
AC
28990wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
28991frame=@{func="callee4",args=[],
76ff342d
DJ
28992file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28993fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 28994(gdb)
922fbb7b
AC
28995-exec-continue
28996^running
0869d01b
NR
28997(gdb)
28998*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
28999frame=@{func="callee3",args=[@{name="strarg",
29000value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
29001file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29002fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 29003(gdb)
922fbb7b
AC
29004@end smallexample
29005
29006Listing breakpoints and watchpoints, at different points in the program
29007execution. Note that once the watchpoint goes out of scope, it is
29008deleted.
29009
29010@smallexample
594fe323 29011(gdb)
922fbb7b
AC
29012-break-watch C
29013^done,wpt=@{number="2",exp="C"@}
594fe323 29014(gdb)
922fbb7b
AC
29015-break-list
29016^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
29017hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29018@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29019@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29020@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29021@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29022@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29023body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29024addr="0x00010734",func="callee4",
948d5102 29025file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
29026fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
29027times="1"@},
922fbb7b 29028bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 29029enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
594fe323 29030(gdb)
922fbb7b
AC
29031-exec-continue
29032^running
0869d01b
NR
29033(gdb)
29034*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
29035value=@{old="-276895068",new="3"@},
29036frame=@{func="callee4",args=[],
76ff342d
DJ
29037file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29038fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 29039(gdb)
922fbb7b
AC
29040-break-list
29041^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
29042hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29043@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29044@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29045@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29046@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29047@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29048body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29049addr="0x00010734",func="callee4",
948d5102 29050file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
29051fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
29052times="1"@},
922fbb7b 29053bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 29054enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
594fe323 29055(gdb)
922fbb7b
AC
29056-exec-continue
29057^running
29058^done,reason="watchpoint-scope",wpnum="2",
29059frame=@{func="callee3",args=[@{name="strarg",
29060value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
29061file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29062fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 29063(gdb)
922fbb7b
AC
29064-break-list
29065^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29066hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29067@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29068@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29069@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29070@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29071@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29072body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29073addr="0x00010734",func="callee4",
948d5102
NR
29074file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29075fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
998580f1 29076thread-groups=["i1"],times="1"@}]@}
594fe323 29077(gdb)
922fbb7b
AC
29078@end smallexample
29079
3fa7bf06
MG
29080
29081@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29082@node GDB/MI Catchpoint Commands
29083@section @sc{gdb/mi} Catchpoint Commands
29084
29085This section documents @sc{gdb/mi} commands for manipulating
29086catchpoints.
29087
29088@subheading The @code{-catch-load} Command
29089@findex -catch-load
29090
29091@subsubheading Synopsis
29092
29093@smallexample
29094 -catch-load [ -t ] [ -d ] @var{regexp}
29095@end smallexample
29096
29097Add a catchpoint for library load events. If the @samp{-t} option is used,
29098the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
29099Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
29100in a disabled state. The @samp{regexp} argument is a regular
29101expression used to match the name of the loaded library.
29102
29103
29104@subsubheading @value{GDBN} Command
29105
29106The corresponding @value{GDBN} command is @samp{catch load}.
29107
29108@subsubheading Example
29109
29110@smallexample
29111-catch-load -t foo.so
29112^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
8ac3646f 29113what="load of library matching foo.so",catch-type="load",times="0"@}
3fa7bf06
MG
29114(gdb)
29115@end smallexample
29116
29117
29118@subheading The @code{-catch-unload} Command
29119@findex -catch-unload
29120
29121@subsubheading Synopsis
29122
29123@smallexample
29124 -catch-unload [ -t ] [ -d ] @var{regexp}
29125@end smallexample
29126
29127Add a catchpoint for library unload events. If the @samp{-t} option is
29128used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
29129Breakpoints}). If the @samp{-d} option is used, the catchpoint is
29130created in a disabled state. The @samp{regexp} argument is a regular
29131expression used to match the name of the unloaded library.
29132
29133@subsubheading @value{GDBN} Command
29134
29135The corresponding @value{GDBN} command is @samp{catch unload}.
29136
29137@subsubheading Example
29138
29139@smallexample
29140-catch-unload -d bar.so
29141^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
8ac3646f 29142what="load of library matching bar.so",catch-type="unload",times="0"@}
3fa7bf06
MG
29143(gdb)
29144@end smallexample
29145
29146
922fbb7b 29147@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
29148@node GDB/MI Program Context
29149@section @sc{gdb/mi} Program Context
922fbb7b 29150
a2c02241
NR
29151@subheading The @code{-exec-arguments} Command
29152@findex -exec-arguments
922fbb7b 29153
922fbb7b
AC
29154
29155@subsubheading Synopsis
29156
29157@smallexample
a2c02241 29158 -exec-arguments @var{args}
922fbb7b
AC
29159@end smallexample
29160
a2c02241
NR
29161Set the inferior program arguments, to be used in the next
29162@samp{-exec-run}.
922fbb7b 29163
a2c02241 29164@subsubheading @value{GDBN} Command
922fbb7b 29165
a2c02241 29166The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 29167
a2c02241 29168@subsubheading Example
922fbb7b 29169
fbc5282e
MK
29170@smallexample
29171(gdb)
29172-exec-arguments -v word
29173^done
29174(gdb)
29175@end smallexample
922fbb7b 29176
a2c02241 29177
9901a55b 29178@ignore
a2c02241
NR
29179@subheading The @code{-exec-show-arguments} Command
29180@findex -exec-show-arguments
29181
29182@subsubheading Synopsis
29183
29184@smallexample
29185 -exec-show-arguments
29186@end smallexample
29187
29188Print the arguments of the program.
922fbb7b
AC
29189
29190@subsubheading @value{GDBN} Command
29191
a2c02241 29192The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
29193
29194@subsubheading Example
a2c02241 29195N.A.
9901a55b 29196@end ignore
922fbb7b 29197
922fbb7b 29198
a2c02241
NR
29199@subheading The @code{-environment-cd} Command
29200@findex -environment-cd
922fbb7b 29201
a2c02241 29202@subsubheading Synopsis
922fbb7b
AC
29203
29204@smallexample
a2c02241 29205 -environment-cd @var{pathdir}
922fbb7b
AC
29206@end smallexample
29207
a2c02241 29208Set @value{GDBN}'s working directory.
922fbb7b 29209
a2c02241 29210@subsubheading @value{GDBN} Command
922fbb7b 29211
a2c02241
NR
29212The corresponding @value{GDBN} command is @samp{cd}.
29213
29214@subsubheading Example
922fbb7b
AC
29215
29216@smallexample
594fe323 29217(gdb)
a2c02241
NR
29218-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
29219^done
594fe323 29220(gdb)
922fbb7b
AC
29221@end smallexample
29222
29223
a2c02241
NR
29224@subheading The @code{-environment-directory} Command
29225@findex -environment-directory
922fbb7b
AC
29226
29227@subsubheading Synopsis
29228
29229@smallexample
a2c02241 29230 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
29231@end smallexample
29232
a2c02241
NR
29233Add directories @var{pathdir} to beginning of search path for source files.
29234If the @samp{-r} option is used, the search path is reset to the default
29235search path. If directories @var{pathdir} are supplied in addition to the
29236@samp{-r} option, the search path is first reset and then addition
29237occurs as normal.
29238Multiple directories may be specified, separated by blanks. Specifying
29239multiple directories in a single command
29240results in the directories added to the beginning of the
29241search path in the same order they were presented in the command.
29242If blanks are needed as
29243part of a directory name, double-quotes should be used around
29244the name. In the command output, the path will show up separated
d3e8051b 29245by the system directory-separator character. The directory-separator
a2c02241
NR
29246character must not be used
29247in any directory name.
29248If no directories are specified, the current search path is displayed.
922fbb7b
AC
29249
29250@subsubheading @value{GDBN} Command
29251
a2c02241 29252The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
29253
29254@subsubheading Example
29255
922fbb7b 29256@smallexample
594fe323 29257(gdb)
a2c02241
NR
29258-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
29259^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 29260(gdb)
a2c02241
NR
29261-environment-directory ""
29262^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 29263(gdb)
a2c02241
NR
29264-environment-directory -r /home/jjohnstn/src/gdb /usr/src
29265^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 29266(gdb)
a2c02241
NR
29267-environment-directory -r
29268^done,source-path="$cdir:$cwd"
594fe323 29269(gdb)
922fbb7b
AC
29270@end smallexample
29271
29272
a2c02241
NR
29273@subheading The @code{-environment-path} Command
29274@findex -environment-path
922fbb7b
AC
29275
29276@subsubheading Synopsis
29277
29278@smallexample
a2c02241 29279 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
29280@end smallexample
29281
a2c02241
NR
29282Add directories @var{pathdir} to beginning of search path for object files.
29283If the @samp{-r} option is used, the search path is reset to the original
29284search path that existed at gdb start-up. If directories @var{pathdir} are
29285supplied in addition to the
29286@samp{-r} option, the search path is first reset and then addition
29287occurs as normal.
29288Multiple directories may be specified, separated by blanks. Specifying
29289multiple directories in a single command
29290results in the directories added to the beginning of the
29291search path in the same order they were presented in the command.
29292If blanks are needed as
29293part of a directory name, double-quotes should be used around
29294the name. In the command output, the path will show up separated
d3e8051b 29295by the system directory-separator character. The directory-separator
a2c02241
NR
29296character must not be used
29297in any directory name.
29298If no directories are specified, the current path is displayed.
29299
922fbb7b
AC
29300
29301@subsubheading @value{GDBN} Command
29302
a2c02241 29303The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
29304
29305@subsubheading Example
29306
922fbb7b 29307@smallexample
594fe323 29308(gdb)
a2c02241
NR
29309-environment-path
29310^done,path="/usr/bin"
594fe323 29311(gdb)
a2c02241
NR
29312-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
29313^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 29314(gdb)
a2c02241
NR
29315-environment-path -r /usr/local/bin
29316^done,path="/usr/local/bin:/usr/bin"
594fe323 29317(gdb)
922fbb7b
AC
29318@end smallexample
29319
29320
a2c02241
NR
29321@subheading The @code{-environment-pwd} Command
29322@findex -environment-pwd
922fbb7b
AC
29323
29324@subsubheading Synopsis
29325
29326@smallexample
a2c02241 29327 -environment-pwd
922fbb7b
AC
29328@end smallexample
29329
a2c02241 29330Show the current working directory.
922fbb7b 29331
79a6e687 29332@subsubheading @value{GDBN} Command
922fbb7b 29333
a2c02241 29334The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
29335
29336@subsubheading Example
29337
922fbb7b 29338@smallexample
594fe323 29339(gdb)
a2c02241
NR
29340-environment-pwd
29341^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 29342(gdb)
922fbb7b
AC
29343@end smallexample
29344
a2c02241
NR
29345@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29346@node GDB/MI Thread Commands
29347@section @sc{gdb/mi} Thread Commands
29348
29349
29350@subheading The @code{-thread-info} Command
29351@findex -thread-info
922fbb7b
AC
29352
29353@subsubheading Synopsis
29354
29355@smallexample
8e8901c5 29356 -thread-info [ @var{thread-id} ]
922fbb7b
AC
29357@end smallexample
29358
8e8901c5
VP
29359Reports information about either a specific thread, if
29360the @var{thread-id} parameter is present, or about all
29361threads. When printing information about all threads,
29362also reports the current thread.
29363
79a6e687 29364@subsubheading @value{GDBN} Command
922fbb7b 29365
8e8901c5
VP
29366The @samp{info thread} command prints the same information
29367about all threads.
922fbb7b 29368
4694da01 29369@subsubheading Result
922fbb7b 29370
4694da01
TT
29371The result is a list of threads. The following attributes are
29372defined for a given thread:
29373
29374@table @samp
29375@item current
29376This field exists only for the current thread. It has the value @samp{*}.
29377
29378@item id
29379The identifier that @value{GDBN} uses to refer to the thread.
29380
29381@item target-id
29382The identifier that the target uses to refer to the thread.
29383
29384@item details
29385Extra information about the thread, in a target-specific format. This
29386field is optional.
29387
29388@item name
29389The name of the thread. If the user specified a name using the
29390@code{thread name} command, then this name is given. Otherwise, if
29391@value{GDBN} can extract the thread name from the target, then that
29392name is given. If @value{GDBN} cannot find the thread name, then this
29393field is omitted.
29394
29395@item frame
29396The stack frame currently executing in the thread.
922fbb7b 29397
4694da01
TT
29398@item state
29399The thread's state. The @samp{state} field may have the following
29400values:
c3b108f7
VP
29401
29402@table @code
29403@item stopped
29404The thread is stopped. Frame information is available for stopped
29405threads.
29406
29407@item running
29408The thread is running. There's no frame information for running
29409threads.
29410
29411@end table
29412
4694da01
TT
29413@item core
29414If @value{GDBN} can find the CPU core on which this thread is running,
29415then this field is the core identifier. This field is optional.
29416
29417@end table
29418
29419@subsubheading Example
29420
29421@smallexample
29422-thread-info
29423^done,threads=[
29424@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
29425 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
29426 args=[]@},state="running"@},
29427@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
29428 frame=@{level="0",addr="0x0804891f",func="foo",
29429 args=[@{name="i",value="10"@}],
29430 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},
29431 state="running"@}],
29432current-thread-id="1"
29433(gdb)
29434@end smallexample
29435
a2c02241
NR
29436@subheading The @code{-thread-list-ids} Command
29437@findex -thread-list-ids
922fbb7b 29438
a2c02241 29439@subsubheading Synopsis
922fbb7b 29440
a2c02241
NR
29441@smallexample
29442 -thread-list-ids
29443@end smallexample
922fbb7b 29444
a2c02241
NR
29445Produces a list of the currently known @value{GDBN} thread ids. At the
29446end of the list it also prints the total number of such threads.
922fbb7b 29447
c3b108f7
VP
29448This command is retained for historical reasons, the
29449@code{-thread-info} command should be used instead.
29450
922fbb7b
AC
29451@subsubheading @value{GDBN} Command
29452
a2c02241 29453Part of @samp{info threads} supplies the same information.
922fbb7b
AC
29454
29455@subsubheading Example
29456
922fbb7b 29457@smallexample
594fe323 29458(gdb)
a2c02241
NR
29459-thread-list-ids
29460^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
592375cd 29461current-thread-id="1",number-of-threads="3"
594fe323 29462(gdb)
922fbb7b
AC
29463@end smallexample
29464
a2c02241
NR
29465
29466@subheading The @code{-thread-select} Command
29467@findex -thread-select
922fbb7b
AC
29468
29469@subsubheading Synopsis
29470
29471@smallexample
a2c02241 29472 -thread-select @var{threadnum}
922fbb7b
AC
29473@end smallexample
29474
a2c02241
NR
29475Make @var{threadnum} the current thread. It prints the number of the new
29476current thread, and the topmost frame for that thread.
922fbb7b 29477
c3b108f7
VP
29478This command is deprecated in favor of explicitly using the
29479@samp{--thread} option to each command.
29480
922fbb7b
AC
29481@subsubheading @value{GDBN} Command
29482
a2c02241 29483The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
29484
29485@subsubheading Example
922fbb7b
AC
29486
29487@smallexample
594fe323 29488(gdb)
a2c02241
NR
29489-exec-next
29490^running
594fe323 29491(gdb)
a2c02241
NR
29492*stopped,reason="end-stepping-range",thread-id="2",line="187",
29493file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 29494(gdb)
a2c02241
NR
29495-thread-list-ids
29496^done,
29497thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
29498number-of-threads="3"
594fe323 29499(gdb)
a2c02241
NR
29500-thread-select 3
29501^done,new-thread-id="3",
29502frame=@{level="0",func="vprintf",
29503args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
29504@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
594fe323 29505(gdb)
922fbb7b
AC
29506@end smallexample
29507
5d77fe44
JB
29508@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29509@node GDB/MI Ada Tasking Commands
29510@section @sc{gdb/mi} Ada Tasking Commands
29511
29512@subheading The @code{-ada-task-info} Command
29513@findex -ada-task-info
29514
29515@subsubheading Synopsis
29516
29517@smallexample
29518 -ada-task-info [ @var{task-id} ]
29519@end smallexample
29520
29521Reports information about either a specific Ada task, if the
29522@var{task-id} parameter is present, or about all Ada tasks.
29523
29524@subsubheading @value{GDBN} Command
29525
29526The @samp{info tasks} command prints the same information
29527about all Ada tasks (@pxref{Ada Tasks}).
29528
29529@subsubheading Result
29530
29531The result is a table of Ada tasks. The following columns are
29532defined for each Ada task:
29533
29534@table @samp
29535@item current
29536This field exists only for the current thread. It has the value @samp{*}.
29537
29538@item id
29539The identifier that @value{GDBN} uses to refer to the Ada task.
29540
29541@item task-id
29542The identifier that the target uses to refer to the Ada task.
29543
29544@item thread-id
29545The identifier of the thread corresponding to the Ada task.
29546
29547This field should always exist, as Ada tasks are always implemented
29548on top of a thread. But if @value{GDBN} cannot find this corresponding
29549thread for any reason, the field is omitted.
29550
29551@item parent-id
29552This field exists only when the task was created by another task.
29553In this case, it provides the ID of the parent task.
29554
29555@item priority
29556The base priority of the task.
29557
29558@item state
29559The current state of the task. For a detailed description of the
29560possible states, see @ref{Ada Tasks}.
29561
29562@item name
29563The name of the task.
29564
29565@end table
29566
29567@subsubheading Example
29568
29569@smallexample
29570-ada-task-info
29571^done,tasks=@{nr_rows="3",nr_cols="8",
29572hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
29573@{width="3",alignment="1",col_name="id",colhdr="ID"@},
29574@{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
29575@{width="4",alignment="1",col_name="thread-id",colhdr=""@},
29576@{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
29577@{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
29578@{width="22",alignment="-1",col_name="state",colhdr="State"@},
29579@{width="1",alignment="2",col_name="name",colhdr="Name"@}],
29580body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
29581state="Child Termination Wait",name="main_task"@}]@}
29582(gdb)
29583@end smallexample
29584
a2c02241
NR
29585@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29586@node GDB/MI Program Execution
29587@section @sc{gdb/mi} Program Execution
922fbb7b 29588
ef21caaf 29589These are the asynchronous commands which generate the out-of-band
3f94c067 29590record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
29591asynchronously with remote targets and this interaction is mimicked in
29592other cases.
922fbb7b 29593
922fbb7b
AC
29594@subheading The @code{-exec-continue} Command
29595@findex -exec-continue
29596
29597@subsubheading Synopsis
29598
29599@smallexample
540aa8e7 29600 -exec-continue [--reverse] [--all|--thread-group N]
922fbb7b
AC
29601@end smallexample
29602
540aa8e7
MS
29603Resumes the execution of the inferior program, which will continue
29604to execute until it reaches a debugger stop event. If the
29605@samp{--reverse} option is specified, execution resumes in reverse until
29606it reaches a stop event. Stop events may include
29607@itemize @bullet
29608@item
29609breakpoints or watchpoints
29610@item
29611signals or exceptions
29612@item
29613the end of the process (or its beginning under @samp{--reverse})
29614@item
29615the end or beginning of a replay log if one is being used.
29616@end itemize
29617In all-stop mode (@pxref{All-Stop
29618Mode}), may resume only one thread, or all threads, depending on the
29619value of the @samp{scheduler-locking} variable. If @samp{--all} is
a79b8f6e 29620specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
540aa8e7
MS
29621ignored in all-stop mode. If the @samp{--thread-group} options is
29622specified, then all threads in that thread group are resumed.
922fbb7b
AC
29623
29624@subsubheading @value{GDBN} Command
29625
29626The corresponding @value{GDBN} corresponding is @samp{continue}.
29627
29628@subsubheading Example
29629
29630@smallexample
29631-exec-continue
29632^running
594fe323 29633(gdb)
922fbb7b 29634@@Hello world
a47ec5fe
AR
29635*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
29636func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
29637line="13"@}
594fe323 29638(gdb)
922fbb7b
AC
29639@end smallexample
29640
29641
29642@subheading The @code{-exec-finish} Command
29643@findex -exec-finish
29644
29645@subsubheading Synopsis
29646
29647@smallexample
540aa8e7 29648 -exec-finish [--reverse]
922fbb7b
AC
29649@end smallexample
29650
ef21caaf
NR
29651Resumes the execution of the inferior program until the current
29652function is exited. Displays the results returned by the function.
540aa8e7
MS
29653If the @samp{--reverse} option is specified, resumes the reverse
29654execution of the inferior program until the point where current
29655function was called.
922fbb7b
AC
29656
29657@subsubheading @value{GDBN} Command
29658
29659The corresponding @value{GDBN} command is @samp{finish}.
29660
29661@subsubheading Example
29662
29663Function returning @code{void}.
29664
29665@smallexample
29666-exec-finish
29667^running
594fe323 29668(gdb)
922fbb7b
AC
29669@@hello from foo
29670*stopped,reason="function-finished",frame=@{func="main",args=[],
948d5102 29671file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
594fe323 29672(gdb)
922fbb7b
AC
29673@end smallexample
29674
29675Function returning other than @code{void}. The name of the internal
29676@value{GDBN} variable storing the result is printed, together with the
29677value itself.
29678
29679@smallexample
29680-exec-finish
29681^running
594fe323 29682(gdb)
922fbb7b
AC
29683*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
29684args=[@{name="a",value="1"],@{name="b",value="9"@}@},
948d5102 29685file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
922fbb7b 29686gdb-result-var="$1",return-value="0"
594fe323 29687(gdb)
922fbb7b
AC
29688@end smallexample
29689
29690
29691@subheading The @code{-exec-interrupt} Command
29692@findex -exec-interrupt
29693
29694@subsubheading Synopsis
29695
29696@smallexample
c3b108f7 29697 -exec-interrupt [--all|--thread-group N]
922fbb7b
AC
29698@end smallexample
29699
ef21caaf
NR
29700Interrupts the background execution of the target. Note how the token
29701associated with the stop message is the one for the execution command
29702that has been interrupted. The token for the interrupt itself only
29703appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
29704interrupt a non-running program, an error message will be printed.
29705
c3b108f7
VP
29706Note that when asynchronous execution is enabled, this command is
29707asynchronous just like other execution commands. That is, first the
29708@samp{^done} response will be printed, and the target stop will be
29709reported after that using the @samp{*stopped} notification.
29710
29711In non-stop mode, only the context thread is interrupted by default.
a79b8f6e
VP
29712All threads (in all inferiors) will be interrupted if the
29713@samp{--all} option is specified. If the @samp{--thread-group}
29714option is specified, all threads in that group will be interrupted.
c3b108f7 29715
922fbb7b
AC
29716@subsubheading @value{GDBN} Command
29717
29718The corresponding @value{GDBN} command is @samp{interrupt}.
29719
29720@subsubheading Example
29721
29722@smallexample
594fe323 29723(gdb)
922fbb7b
AC
29724111-exec-continue
29725111^running
29726
594fe323 29727(gdb)
922fbb7b
AC
29728222-exec-interrupt
29729222^done
594fe323 29730(gdb)
922fbb7b 29731111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 29732frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
948d5102 29733fullname="/home/foo/bar/try.c",line="13"@}
594fe323 29734(gdb)
922fbb7b 29735
594fe323 29736(gdb)
922fbb7b
AC
29737-exec-interrupt
29738^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 29739(gdb)
922fbb7b
AC
29740@end smallexample
29741
83eba9b7
VP
29742@subheading The @code{-exec-jump} Command
29743@findex -exec-jump
29744
29745@subsubheading Synopsis
29746
29747@smallexample
29748 -exec-jump @var{location}
29749@end smallexample
29750
29751Resumes execution of the inferior program at the location specified by
29752parameter. @xref{Specify Location}, for a description of the
29753different forms of @var{location}.
29754
29755@subsubheading @value{GDBN} Command
29756
29757The corresponding @value{GDBN} command is @samp{jump}.
29758
29759@subsubheading Example
29760
29761@smallexample
29762-exec-jump foo.c:10
29763*running,thread-id="all"
29764^running
29765@end smallexample
29766
922fbb7b
AC
29767
29768@subheading The @code{-exec-next} Command
29769@findex -exec-next
29770
29771@subsubheading Synopsis
29772
29773@smallexample
540aa8e7 29774 -exec-next [--reverse]
922fbb7b
AC
29775@end smallexample
29776
ef21caaf
NR
29777Resumes execution of the inferior program, stopping when the beginning
29778of the next source line is reached.
922fbb7b 29779
540aa8e7
MS
29780If the @samp{--reverse} option is specified, resumes reverse execution
29781of the inferior program, stopping at the beginning of the previous
29782source line. If you issue this command on the first line of a
29783function, it will take you back to the caller of that function, to the
29784source line where the function was called.
29785
29786
922fbb7b
AC
29787@subsubheading @value{GDBN} Command
29788
29789The corresponding @value{GDBN} command is @samp{next}.
29790
29791@subsubheading Example
29792
29793@smallexample
29794-exec-next
29795^running
594fe323 29796(gdb)
922fbb7b 29797*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 29798(gdb)
922fbb7b
AC
29799@end smallexample
29800
29801
29802@subheading The @code{-exec-next-instruction} Command
29803@findex -exec-next-instruction
29804
29805@subsubheading Synopsis
29806
29807@smallexample
540aa8e7 29808 -exec-next-instruction [--reverse]
922fbb7b
AC
29809@end smallexample
29810
ef21caaf
NR
29811Executes one machine instruction. If the instruction is a function
29812call, continues until the function returns. If the program stops at an
29813instruction in the middle of a source line, the address will be
29814printed as well.
922fbb7b 29815
540aa8e7
MS
29816If the @samp{--reverse} option is specified, resumes reverse execution
29817of the inferior program, stopping at the previous instruction. If the
29818previously executed instruction was a return from another function,
29819it will continue to execute in reverse until the call to that function
29820(from the current stack frame) is reached.
29821
922fbb7b
AC
29822@subsubheading @value{GDBN} Command
29823
29824The corresponding @value{GDBN} command is @samp{nexti}.
29825
29826@subsubheading Example
29827
29828@smallexample
594fe323 29829(gdb)
922fbb7b
AC
29830-exec-next-instruction
29831^running
29832
594fe323 29833(gdb)
922fbb7b
AC
29834*stopped,reason="end-stepping-range",
29835addr="0x000100d4",line="5",file="hello.c"
594fe323 29836(gdb)
922fbb7b
AC
29837@end smallexample
29838
29839
29840@subheading The @code{-exec-return} Command
29841@findex -exec-return
29842
29843@subsubheading Synopsis
29844
29845@smallexample
29846 -exec-return
29847@end smallexample
29848
29849Makes current function return immediately. Doesn't execute the inferior.
29850Displays the new current frame.
29851
29852@subsubheading @value{GDBN} Command
29853
29854The corresponding @value{GDBN} command is @samp{return}.
29855
29856@subsubheading Example
29857
29858@smallexample
594fe323 29859(gdb)
922fbb7b
AC
29860200-break-insert callee4
29861200^done,bkpt=@{number="1",addr="0x00010734",
29862file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 29863(gdb)
922fbb7b
AC
29864000-exec-run
29865000^running
594fe323 29866(gdb)
a47ec5fe 29867000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
922fbb7b 29868frame=@{func="callee4",args=[],
76ff342d
DJ
29869file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29870fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 29871(gdb)
922fbb7b
AC
29872205-break-delete
29873205^done
594fe323 29874(gdb)
922fbb7b
AC
29875111-exec-return
29876111^done,frame=@{level="0",func="callee3",
29877args=[@{name="strarg",
29878value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
29879file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29880fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 29881(gdb)
922fbb7b
AC
29882@end smallexample
29883
29884
29885@subheading The @code{-exec-run} Command
29886@findex -exec-run
29887
29888@subsubheading Synopsis
29889
29890@smallexample
a79b8f6e 29891 -exec-run [--all | --thread-group N]
922fbb7b
AC
29892@end smallexample
29893
ef21caaf
NR
29894Starts execution of the inferior from the beginning. The inferior
29895executes until either a breakpoint is encountered or the program
29896exits. In the latter case the output will include an exit code, if
29897the program has exited exceptionally.
922fbb7b 29898
a79b8f6e
VP
29899When no option is specified, the current inferior is started. If the
29900@samp{--thread-group} option is specified, it should refer to a thread
29901group of type @samp{process}, and that thread group will be started.
29902If the @samp{--all} option is specified, then all inferiors will be started.
29903
922fbb7b
AC
29904@subsubheading @value{GDBN} Command
29905
29906The corresponding @value{GDBN} command is @samp{run}.
29907
ef21caaf 29908@subsubheading Examples
922fbb7b
AC
29909
29910@smallexample
594fe323 29911(gdb)
922fbb7b
AC
29912-break-insert main
29913^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 29914(gdb)
922fbb7b
AC
29915-exec-run
29916^running
594fe323 29917(gdb)
a47ec5fe 29918*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
76ff342d 29919frame=@{func="main",args=[],file="recursive2.c",
948d5102 29920fullname="/home/foo/bar/recursive2.c",line="4"@}
594fe323 29921(gdb)
922fbb7b
AC
29922@end smallexample
29923
ef21caaf
NR
29924@noindent
29925Program exited normally:
29926
29927@smallexample
594fe323 29928(gdb)
ef21caaf
NR
29929-exec-run
29930^running
594fe323 29931(gdb)
ef21caaf
NR
29932x = 55
29933*stopped,reason="exited-normally"
594fe323 29934(gdb)
ef21caaf
NR
29935@end smallexample
29936
29937@noindent
29938Program exited exceptionally:
29939
29940@smallexample
594fe323 29941(gdb)
ef21caaf
NR
29942-exec-run
29943^running
594fe323 29944(gdb)
ef21caaf
NR
29945x = 55
29946*stopped,reason="exited",exit-code="01"
594fe323 29947(gdb)
ef21caaf
NR
29948@end smallexample
29949
29950Another way the program can terminate is if it receives a signal such as
29951@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
29952
29953@smallexample
594fe323 29954(gdb)
ef21caaf
NR
29955*stopped,reason="exited-signalled",signal-name="SIGINT",
29956signal-meaning="Interrupt"
29957@end smallexample
29958
922fbb7b 29959
a2c02241
NR
29960@c @subheading -exec-signal
29961
29962
29963@subheading The @code{-exec-step} Command
29964@findex -exec-step
922fbb7b
AC
29965
29966@subsubheading Synopsis
29967
29968@smallexample
540aa8e7 29969 -exec-step [--reverse]
922fbb7b
AC
29970@end smallexample
29971
a2c02241
NR
29972Resumes execution of the inferior program, stopping when the beginning
29973of the next source line is reached, if the next source line is not a
29974function call. If it is, stop at the first instruction of the called
540aa8e7
MS
29975function. If the @samp{--reverse} option is specified, resumes reverse
29976execution of the inferior program, stopping at the beginning of the
29977previously executed source line.
922fbb7b
AC
29978
29979@subsubheading @value{GDBN} Command
29980
a2c02241 29981The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
29982
29983@subsubheading Example
29984
29985Stepping into a function:
29986
29987@smallexample
29988-exec-step
29989^running
594fe323 29990(gdb)
922fbb7b
AC
29991*stopped,reason="end-stepping-range",
29992frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 29993@{name="b",value="0"@}],file="recursive2.c",
948d5102 29994fullname="/home/foo/bar/recursive2.c",line="11"@}
594fe323 29995(gdb)
922fbb7b
AC
29996@end smallexample
29997
29998Regular stepping:
29999
30000@smallexample
30001-exec-step
30002^running
594fe323 30003(gdb)
922fbb7b 30004*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 30005(gdb)
922fbb7b
AC
30006@end smallexample
30007
30008
30009@subheading The @code{-exec-step-instruction} Command
30010@findex -exec-step-instruction
30011
30012@subsubheading Synopsis
30013
30014@smallexample
540aa8e7 30015 -exec-step-instruction [--reverse]
922fbb7b
AC
30016@end smallexample
30017
540aa8e7
MS
30018Resumes the inferior which executes one machine instruction. If the
30019@samp{--reverse} option is specified, resumes reverse execution of the
30020inferior program, stopping at the previously executed instruction.
30021The output, once @value{GDBN} has stopped, will vary depending on
30022whether we have stopped in the middle of a source line or not. In the
30023former case, the address at which the program stopped will be printed
30024as well.
922fbb7b
AC
30025
30026@subsubheading @value{GDBN} Command
30027
30028The corresponding @value{GDBN} command is @samp{stepi}.
30029
30030@subsubheading Example
30031
30032@smallexample
594fe323 30033(gdb)
922fbb7b
AC
30034-exec-step-instruction
30035^running
30036
594fe323 30037(gdb)
922fbb7b 30038*stopped,reason="end-stepping-range",
76ff342d 30039frame=@{func="foo",args=[],file="try.c",
948d5102 30040fullname="/home/foo/bar/try.c",line="10"@}
594fe323 30041(gdb)
922fbb7b
AC
30042-exec-step-instruction
30043^running
30044
594fe323 30045(gdb)
922fbb7b 30046*stopped,reason="end-stepping-range",
76ff342d 30047frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
948d5102 30048fullname="/home/foo/bar/try.c",line="10"@}
594fe323 30049(gdb)
922fbb7b
AC
30050@end smallexample
30051
30052
30053@subheading The @code{-exec-until} Command
30054@findex -exec-until
30055
30056@subsubheading Synopsis
30057
30058@smallexample
30059 -exec-until [ @var{location} ]
30060@end smallexample
30061
ef21caaf
NR
30062Executes the inferior until the @var{location} specified in the
30063argument is reached. If there is no argument, the inferior executes
30064until a source line greater than the current one is reached. The
30065reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
30066
30067@subsubheading @value{GDBN} Command
30068
30069The corresponding @value{GDBN} command is @samp{until}.
30070
30071@subsubheading Example
30072
30073@smallexample
594fe323 30074(gdb)
922fbb7b
AC
30075-exec-until recursive2.c:6
30076^running
594fe323 30077(gdb)
922fbb7b
AC
30078x = 55
30079*stopped,reason="location-reached",frame=@{func="main",args=[],
948d5102 30080file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
594fe323 30081(gdb)
922fbb7b
AC
30082@end smallexample
30083
30084@ignore
30085@subheading -file-clear
30086Is this going away????
30087@end ignore
30088
351ff01a 30089@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
30090@node GDB/MI Stack Manipulation
30091@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 30092
922fbb7b 30093
a2c02241
NR
30094@subheading The @code{-stack-info-frame} Command
30095@findex -stack-info-frame
922fbb7b
AC
30096
30097@subsubheading Synopsis
30098
30099@smallexample
a2c02241 30100 -stack-info-frame
922fbb7b
AC
30101@end smallexample
30102
a2c02241 30103Get info on the selected frame.
922fbb7b
AC
30104
30105@subsubheading @value{GDBN} Command
30106
a2c02241
NR
30107The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
30108(without arguments).
922fbb7b
AC
30109
30110@subsubheading Example
30111
30112@smallexample
594fe323 30113(gdb)
a2c02241
NR
30114-stack-info-frame
30115^done,frame=@{level="1",addr="0x0001076c",func="callee3",
30116file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30117fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
594fe323 30118(gdb)
922fbb7b
AC
30119@end smallexample
30120
a2c02241
NR
30121@subheading The @code{-stack-info-depth} Command
30122@findex -stack-info-depth
922fbb7b
AC
30123
30124@subsubheading Synopsis
30125
30126@smallexample
a2c02241 30127 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
30128@end smallexample
30129
a2c02241
NR
30130Return the depth of the stack. If the integer argument @var{max-depth}
30131is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
30132
30133@subsubheading @value{GDBN} Command
30134
a2c02241 30135There's no equivalent @value{GDBN} command.
922fbb7b
AC
30136
30137@subsubheading Example
30138
a2c02241
NR
30139For a stack with frame levels 0 through 11:
30140
922fbb7b 30141@smallexample
594fe323 30142(gdb)
a2c02241
NR
30143-stack-info-depth
30144^done,depth="12"
594fe323 30145(gdb)
a2c02241
NR
30146-stack-info-depth 4
30147^done,depth="4"
594fe323 30148(gdb)
a2c02241
NR
30149-stack-info-depth 12
30150^done,depth="12"
594fe323 30151(gdb)
a2c02241
NR
30152-stack-info-depth 11
30153^done,depth="11"
594fe323 30154(gdb)
a2c02241
NR
30155-stack-info-depth 13
30156^done,depth="12"
594fe323 30157(gdb)
922fbb7b
AC
30158@end smallexample
30159
a2c02241
NR
30160@subheading The @code{-stack-list-arguments} Command
30161@findex -stack-list-arguments
922fbb7b
AC
30162
30163@subsubheading Synopsis
30164
30165@smallexample
3afae151 30166 -stack-list-arguments @var{print-values}
a2c02241 30167 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
30168@end smallexample
30169
a2c02241
NR
30170Display a list of the arguments for the frames between @var{low-frame}
30171and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
30172@var{high-frame} are not provided, list the arguments for the whole
30173call stack. If the two arguments are equal, show the single frame
30174at the corresponding level. It is an error if @var{low-frame} is
30175larger than the actual number of frames. On the other hand,
30176@var{high-frame} may be larger than the actual number of frames, in
30177which case only existing frames will be returned.
a2c02241 30178
3afae151
VP
30179If @var{print-values} is 0 or @code{--no-values}, print only the names of
30180the variables; if it is 1 or @code{--all-values}, print also their
30181values; and if it is 2 or @code{--simple-values}, print the name,
30182type and value for simple data types, and the name and type for arrays,
30183structures and unions.
922fbb7b 30184
b3372f91
VP
30185Use of this command to obtain arguments in a single frame is
30186deprecated in favor of the @samp{-stack-list-variables} command.
30187
922fbb7b
AC
30188@subsubheading @value{GDBN} Command
30189
a2c02241
NR
30190@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
30191@samp{gdb_get_args} command which partially overlaps with the
30192functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
30193
30194@subsubheading Example
922fbb7b 30195
a2c02241 30196@smallexample
594fe323 30197(gdb)
a2c02241
NR
30198-stack-list-frames
30199^done,
30200stack=[
30201frame=@{level="0",addr="0x00010734",func="callee4",
30202file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30203fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
30204frame=@{level="1",addr="0x0001076c",func="callee3",
30205file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30206fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
30207frame=@{level="2",addr="0x0001078c",func="callee2",
30208file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30209fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
30210frame=@{level="3",addr="0x000107b4",func="callee1",
30211file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30212fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
30213frame=@{level="4",addr="0x000107e0",func="main",
30214file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30215fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
594fe323 30216(gdb)
a2c02241
NR
30217-stack-list-arguments 0
30218^done,
30219stack-args=[
30220frame=@{level="0",args=[]@},
30221frame=@{level="1",args=[name="strarg"]@},
30222frame=@{level="2",args=[name="intarg",name="strarg"]@},
30223frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
30224frame=@{level="4",args=[]@}]
594fe323 30225(gdb)
a2c02241
NR
30226-stack-list-arguments 1
30227^done,
30228stack-args=[
30229frame=@{level="0",args=[]@},
30230frame=@{level="1",
30231 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
30232frame=@{level="2",args=[
30233@{name="intarg",value="2"@},
30234@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
30235@{frame=@{level="3",args=[
30236@{name="intarg",value="2"@},
30237@{name="strarg",value="0x11940 \"A string argument.\""@},
30238@{name="fltarg",value="3.5"@}]@},
30239frame=@{level="4",args=[]@}]
594fe323 30240(gdb)
a2c02241
NR
30241-stack-list-arguments 0 2 2
30242^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 30243(gdb)
a2c02241
NR
30244-stack-list-arguments 1 2 2
30245^done,stack-args=[frame=@{level="2",
30246args=[@{name="intarg",value="2"@},
30247@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 30248(gdb)
a2c02241
NR
30249@end smallexample
30250
30251@c @subheading -stack-list-exception-handlers
922fbb7b 30252
a2c02241
NR
30253
30254@subheading The @code{-stack-list-frames} Command
30255@findex -stack-list-frames
1abaf70c
BR
30256
30257@subsubheading Synopsis
30258
30259@smallexample
a2c02241 30260 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
1abaf70c
BR
30261@end smallexample
30262
a2c02241
NR
30263List the frames currently on the stack. For each frame it displays the
30264following info:
30265
30266@table @samp
30267@item @var{level}
d3e8051b 30268The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
30269@item @var{addr}
30270The @code{$pc} value for that frame.
30271@item @var{func}
30272Function name.
30273@item @var{file}
30274File name of the source file where the function lives.
7d288aaa
TT
30275@item @var{fullname}
30276The full file name of the source file where the function lives.
a2c02241
NR
30277@item @var{line}
30278Line number corresponding to the @code{$pc}.
7d288aaa
TT
30279@item @var{from}
30280The shared library where this function is defined. This is only given
30281if the frame's function is not known.
a2c02241
NR
30282@end table
30283
30284If invoked without arguments, this command prints a backtrace for the
30285whole stack. If given two integer arguments, it shows the frames whose
30286levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
30287are equal, it shows the single frame at the corresponding level. It is
30288an error if @var{low-frame} is larger than the actual number of
a5451f4e 30289frames. On the other hand, @var{high-frame} may be larger than the
2ab1eb7a 30290actual number of frames, in which case only existing frames will be returned.
1abaf70c
BR
30291
30292@subsubheading @value{GDBN} Command
30293
a2c02241 30294The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
30295
30296@subsubheading Example
30297
a2c02241
NR
30298Full stack backtrace:
30299
1abaf70c 30300@smallexample
594fe323 30301(gdb)
a2c02241
NR
30302-stack-list-frames
30303^done,stack=
30304[frame=@{level="0",addr="0x0001076c",func="foo",
30305 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
30306frame=@{level="1",addr="0x000107a4",func="foo",
30307 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30308frame=@{level="2",addr="0x000107a4",func="foo",
30309 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30310frame=@{level="3",addr="0x000107a4",func="foo",
30311 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30312frame=@{level="4",addr="0x000107a4",func="foo",
30313 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30314frame=@{level="5",addr="0x000107a4",func="foo",
30315 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30316frame=@{level="6",addr="0x000107a4",func="foo",
30317 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30318frame=@{level="7",addr="0x000107a4",func="foo",
30319 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30320frame=@{level="8",addr="0x000107a4",func="foo",
30321 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30322frame=@{level="9",addr="0x000107a4",func="foo",
30323 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30324frame=@{level="10",addr="0x000107a4",func="foo",
30325 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30326frame=@{level="11",addr="0x00010738",func="main",
30327 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
594fe323 30328(gdb)
1abaf70c
BR
30329@end smallexample
30330
a2c02241 30331Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 30332
a2c02241 30333@smallexample
594fe323 30334(gdb)
a2c02241
NR
30335-stack-list-frames 3 5
30336^done,stack=
30337[frame=@{level="3",addr="0x000107a4",func="foo",
30338 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30339frame=@{level="4",addr="0x000107a4",func="foo",
30340 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30341frame=@{level="5",addr="0x000107a4",func="foo",
30342 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 30343(gdb)
a2c02241 30344@end smallexample
922fbb7b 30345
a2c02241 30346Show a single frame:
922fbb7b
AC
30347
30348@smallexample
594fe323 30349(gdb)
a2c02241
NR
30350-stack-list-frames 3 3
30351^done,stack=
30352[frame=@{level="3",addr="0x000107a4",func="foo",
30353 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 30354(gdb)
922fbb7b
AC
30355@end smallexample
30356
922fbb7b 30357
a2c02241
NR
30358@subheading The @code{-stack-list-locals} Command
30359@findex -stack-list-locals
57c22c6c 30360
a2c02241 30361@subsubheading Synopsis
922fbb7b
AC
30362
30363@smallexample
a2c02241 30364 -stack-list-locals @var{print-values}
922fbb7b
AC
30365@end smallexample
30366
a2c02241
NR
30367Display the local variable names for the selected frame. If
30368@var{print-values} is 0 or @code{--no-values}, print only the names of
30369the variables; if it is 1 or @code{--all-values}, print also their
30370values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 30371type and value for simple data types, and the name and type for arrays,
a2c02241
NR
30372structures and unions. In this last case, a frontend can immediately
30373display the value of simple data types and create variable objects for
d3e8051b 30374other data types when the user wishes to explore their values in
a2c02241 30375more detail.
922fbb7b 30376
b3372f91
VP
30377This command is deprecated in favor of the
30378@samp{-stack-list-variables} command.
30379
922fbb7b
AC
30380@subsubheading @value{GDBN} Command
30381
a2c02241 30382@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
30383
30384@subsubheading Example
922fbb7b
AC
30385
30386@smallexample
594fe323 30387(gdb)
a2c02241
NR
30388-stack-list-locals 0
30389^done,locals=[name="A",name="B",name="C"]
594fe323 30390(gdb)
a2c02241
NR
30391-stack-list-locals --all-values
30392^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
30393 @{name="C",value="@{1, 2, 3@}"@}]
30394-stack-list-locals --simple-values
30395^done,locals=[@{name="A",type="int",value="1"@},
30396 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 30397(gdb)
922fbb7b
AC
30398@end smallexample
30399
b3372f91
VP
30400@subheading The @code{-stack-list-variables} Command
30401@findex -stack-list-variables
30402
30403@subsubheading Synopsis
30404
30405@smallexample
30406 -stack-list-variables @var{print-values}
30407@end smallexample
30408
30409Display the names of local variables and function arguments for the selected frame. If
30410@var{print-values} is 0 or @code{--no-values}, print only the names of
30411the variables; if it is 1 or @code{--all-values}, print also their
30412values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 30413type and value for simple data types, and the name and type for arrays,
b3372f91
VP
30414structures and unions.
30415
30416@subsubheading Example
30417
30418@smallexample
30419(gdb)
30420-stack-list-variables --thread 1 --frame 0 --all-values
4f412fd0 30421^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
b3372f91
VP
30422(gdb)
30423@end smallexample
30424
922fbb7b 30425
a2c02241
NR
30426@subheading The @code{-stack-select-frame} Command
30427@findex -stack-select-frame
922fbb7b
AC
30428
30429@subsubheading Synopsis
30430
30431@smallexample
a2c02241 30432 -stack-select-frame @var{framenum}
922fbb7b
AC
30433@end smallexample
30434
a2c02241
NR
30435Change the selected frame. Select a different frame @var{framenum} on
30436the stack.
922fbb7b 30437
c3b108f7
VP
30438This command in deprecated in favor of passing the @samp{--frame}
30439option to every command.
30440
922fbb7b
AC
30441@subsubheading @value{GDBN} Command
30442
a2c02241
NR
30443The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
30444@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
30445
30446@subsubheading Example
30447
30448@smallexample
594fe323 30449(gdb)
a2c02241 30450-stack-select-frame 2
922fbb7b 30451^done
594fe323 30452(gdb)
922fbb7b
AC
30453@end smallexample
30454
30455@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
30456@node GDB/MI Variable Objects
30457@section @sc{gdb/mi} Variable Objects
922fbb7b 30458
a1b5960f 30459@ignore
922fbb7b 30460
a2c02241 30461@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 30462
a2c02241
NR
30463For the implementation of a variable debugger window (locals, watched
30464expressions, etc.), we are proposing the adaptation of the existing code
30465used by @code{Insight}.
922fbb7b 30466
a2c02241 30467The two main reasons for that are:
922fbb7b 30468
a2c02241
NR
30469@enumerate 1
30470@item
30471It has been proven in practice (it is already on its second generation).
922fbb7b 30472
a2c02241
NR
30473@item
30474It will shorten development time (needless to say how important it is
30475now).
30476@end enumerate
922fbb7b 30477
a2c02241
NR
30478The original interface was designed to be used by Tcl code, so it was
30479slightly changed so it could be used through @sc{gdb/mi}. This section
30480describes the @sc{gdb/mi} operations that will be available and gives some
30481hints about their use.
922fbb7b 30482
a2c02241
NR
30483@emph{Note}: In addition to the set of operations described here, we
30484expect the @sc{gui} implementation of a variable window to require, at
30485least, the following operations:
922fbb7b 30486
a2c02241
NR
30487@itemize @bullet
30488@item @code{-gdb-show} @code{output-radix}
30489@item @code{-stack-list-arguments}
30490@item @code{-stack-list-locals}
30491@item @code{-stack-select-frame}
30492@end itemize
922fbb7b 30493
a1b5960f
VP
30494@end ignore
30495
c8b2f53c 30496@subheading Introduction to Variable Objects
922fbb7b 30497
a2c02241 30498@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
30499
30500Variable objects are "object-oriented" MI interface for examining and
30501changing values of expressions. Unlike some other MI interfaces that
30502work with expressions, variable objects are specifically designed for
30503simple and efficient presentation in the frontend. A variable object
30504is identified by string name. When a variable object is created, the
30505frontend specifies the expression for that variable object. The
30506expression can be a simple variable, or it can be an arbitrary complex
30507expression, and can even involve CPU registers. After creating a
30508variable object, the frontend can invoke other variable object
30509operations---for example to obtain or change the value of a variable
30510object, or to change display format.
30511
30512Variable objects have hierarchical tree structure. Any variable object
30513that corresponds to a composite type, such as structure in C, has
30514a number of child variable objects, for example corresponding to each
30515element of a structure. A child variable object can itself have
30516children, recursively. Recursion ends when we reach
25d5ea92
VP
30517leaf variable objects, which always have built-in types. Child variable
30518objects are created only by explicit request, so if a frontend
30519is not interested in the children of a particular variable object, no
30520child will be created.
c8b2f53c
VP
30521
30522For a leaf variable object it is possible to obtain its value as a
30523string, or set the value from a string. String value can be also
30524obtained for a non-leaf variable object, but it's generally a string
30525that only indicates the type of the object, and does not list its
30526contents. Assignment to a non-leaf variable object is not allowed.
30527
30528A frontend does not need to read the values of all variable objects each time
30529the program stops. Instead, MI provides an update command that lists all
30530variable objects whose values has changed since the last update
30531operation. This considerably reduces the amount of data that must
25d5ea92
VP
30532be transferred to the frontend. As noted above, children variable
30533objects are created on demand, and only leaf variable objects have a
30534real value. As result, gdb will read target memory only for leaf
30535variables that frontend has created.
30536
30537The automatic update is not always desirable. For example, a frontend
30538might want to keep a value of some expression for future reference,
30539and never update it. For another example, fetching memory is
30540relatively slow for embedded targets, so a frontend might want
30541to disable automatic update for the variables that are either not
30542visible on the screen, or ``closed''. This is possible using so
30543called ``frozen variable objects''. Such variable objects are never
30544implicitly updated.
922fbb7b 30545
c3b108f7
VP
30546Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
30547fixed variable object, the expression is parsed when the variable
30548object is created, including associating identifiers to specific
30549variables. The meaning of expression never changes. For a floating
30550variable object the values of variables whose names appear in the
30551expressions are re-evaluated every time in the context of the current
30552frame. Consider this example:
30553
30554@smallexample
30555void do_work(...)
30556@{
30557 struct work_state state;
30558
30559 if (...)
30560 do_work(...);
30561@}
30562@end smallexample
30563
30564If a fixed variable object for the @code{state} variable is created in
7a9dd1b2 30565this function, and we enter the recursive call, the variable
c3b108f7
VP
30566object will report the value of @code{state} in the top-level
30567@code{do_work} invocation. On the other hand, a floating variable
30568object will report the value of @code{state} in the current frame.
30569
30570If an expression specified when creating a fixed variable object
30571refers to a local variable, the variable object becomes bound to the
30572thread and frame in which the variable object is created. When such
30573variable object is updated, @value{GDBN} makes sure that the
30574thread/frame combination the variable object is bound to still exists,
30575and re-evaluates the variable object in context of that thread/frame.
30576
a2c02241
NR
30577The following is the complete set of @sc{gdb/mi} operations defined to
30578access this functionality:
922fbb7b 30579
a2c02241
NR
30580@multitable @columnfractions .4 .6
30581@item @strong{Operation}
30582@tab @strong{Description}
922fbb7b 30583
0cc7d26f
TT
30584@item @code{-enable-pretty-printing}
30585@tab enable Python-based pretty-printing
a2c02241
NR
30586@item @code{-var-create}
30587@tab create a variable object
30588@item @code{-var-delete}
22d8a470 30589@tab delete the variable object and/or its children
a2c02241
NR
30590@item @code{-var-set-format}
30591@tab set the display format of this variable
30592@item @code{-var-show-format}
30593@tab show the display format of this variable
30594@item @code{-var-info-num-children}
30595@tab tells how many children this object has
30596@item @code{-var-list-children}
30597@tab return a list of the object's children
30598@item @code{-var-info-type}
30599@tab show the type of this variable object
30600@item @code{-var-info-expression}
02142340
VP
30601@tab print parent-relative expression that this variable object represents
30602@item @code{-var-info-path-expression}
30603@tab print full expression that this variable object represents
a2c02241
NR
30604@item @code{-var-show-attributes}
30605@tab is this variable editable? does it exist here?
30606@item @code{-var-evaluate-expression}
30607@tab get the value of this variable
30608@item @code{-var-assign}
30609@tab set the value of this variable
30610@item @code{-var-update}
30611@tab update the variable and its children
25d5ea92
VP
30612@item @code{-var-set-frozen}
30613@tab set frozeness attribute
0cc7d26f
TT
30614@item @code{-var-set-update-range}
30615@tab set range of children to display on update
a2c02241 30616@end multitable
922fbb7b 30617
a2c02241
NR
30618In the next subsection we describe each operation in detail and suggest
30619how it can be used.
922fbb7b 30620
a2c02241 30621@subheading Description And Use of Operations on Variable Objects
922fbb7b 30622
0cc7d26f
TT
30623@subheading The @code{-enable-pretty-printing} Command
30624@findex -enable-pretty-printing
30625
30626@smallexample
30627-enable-pretty-printing
30628@end smallexample
30629
30630@value{GDBN} allows Python-based visualizers to affect the output of the
30631MI variable object commands. However, because there was no way to
30632implement this in a fully backward-compatible way, a front end must
30633request that this functionality be enabled.
30634
30635Once enabled, this feature cannot be disabled.
30636
30637Note that if Python support has not been compiled into @value{GDBN},
30638this command will still succeed (and do nothing).
30639
f43030c4
TT
30640This feature is currently (as of @value{GDBN} 7.0) experimental, and
30641may work differently in future versions of @value{GDBN}.
30642
a2c02241
NR
30643@subheading The @code{-var-create} Command
30644@findex -var-create
ef21caaf 30645
a2c02241 30646@subsubheading Synopsis
ef21caaf 30647
a2c02241
NR
30648@smallexample
30649 -var-create @{@var{name} | "-"@}
c3b108f7 30650 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
a2c02241
NR
30651@end smallexample
30652
30653This operation creates a variable object, which allows the monitoring of
30654a variable, the result of an expression, a memory cell or a CPU
30655register.
ef21caaf 30656
a2c02241
NR
30657The @var{name} parameter is the string by which the object can be
30658referenced. It must be unique. If @samp{-} is specified, the varobj
30659system will generate a string ``varNNNNNN'' automatically. It will be
c3b108f7 30660unique provided that one does not specify @var{name} of that format.
a2c02241 30661The command fails if a duplicate name is found.
ef21caaf 30662
a2c02241
NR
30663The frame under which the expression should be evaluated can be
30664specified by @var{frame-addr}. A @samp{*} indicates that the current
c3b108f7
VP
30665frame should be used. A @samp{@@} indicates that a floating variable
30666object must be created.
922fbb7b 30667
a2c02241
NR
30668@var{expression} is any expression valid on the current language set (must not
30669begin with a @samp{*}), or one of the following:
922fbb7b 30670
a2c02241
NR
30671@itemize @bullet
30672@item
30673@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 30674
a2c02241
NR
30675@item
30676@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 30677
a2c02241
NR
30678@item
30679@samp{$@var{regname}} --- a CPU register name
30680@end itemize
922fbb7b 30681
0cc7d26f
TT
30682@cindex dynamic varobj
30683A varobj's contents may be provided by a Python-based pretty-printer. In this
30684case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
30685have slightly different semantics in some cases. If the
30686@code{-enable-pretty-printing} command is not sent, then @value{GDBN}
30687will never create a dynamic varobj. This ensures backward
30688compatibility for existing clients.
30689
a2c02241 30690@subsubheading Result
922fbb7b 30691
0cc7d26f
TT
30692This operation returns attributes of the newly-created varobj. These
30693are:
30694
30695@table @samp
30696@item name
30697The name of the varobj.
30698
30699@item numchild
30700The number of children of the varobj. This number is not necessarily
30701reliable for a dynamic varobj. Instead, you must examine the
30702@samp{has_more} attribute.
30703
30704@item value
30705The varobj's scalar value. For a varobj whose type is some sort of
30706aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
30707will not be interesting.
30708
30709@item type
30710The varobj's type. This is a string representation of the type, as
8264ba82
AG
30711would be printed by the @value{GDBN} CLI. If @samp{print object}
30712(@pxref{Print Settings, set print object}) is set to @code{on}, the
30713@emph{actual} (derived) type of the object is shown rather than the
30714@emph{declared} one.
0cc7d26f
TT
30715
30716@item thread-id
30717If a variable object is bound to a specific thread, then this is the
30718thread's identifier.
30719
30720@item has_more
30721For a dynamic varobj, this indicates whether there appear to be any
30722children available. For a non-dynamic varobj, this will be 0.
30723
30724@item dynamic
30725This attribute will be present and have the value @samp{1} if the
30726varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
30727then this attribute will not be present.
30728
30729@item displayhint
30730A dynamic varobj can supply a display hint to the front end. The
30731value comes directly from the Python pretty-printer object's
4c374409 30732@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
30733@end table
30734
30735Typical output will look like this:
922fbb7b
AC
30736
30737@smallexample
0cc7d26f
TT
30738 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
30739 has_more="@var{has_more}"
dcaaae04
NR
30740@end smallexample
30741
a2c02241
NR
30742
30743@subheading The @code{-var-delete} Command
30744@findex -var-delete
922fbb7b
AC
30745
30746@subsubheading Synopsis
30747
30748@smallexample
22d8a470 30749 -var-delete [ -c ] @var{name}
922fbb7b
AC
30750@end smallexample
30751
a2c02241 30752Deletes a previously created variable object and all of its children.
22d8a470 30753With the @samp{-c} option, just deletes the children.
922fbb7b 30754
a2c02241 30755Returns an error if the object @var{name} is not found.
922fbb7b 30756
922fbb7b 30757
a2c02241
NR
30758@subheading The @code{-var-set-format} Command
30759@findex -var-set-format
922fbb7b 30760
a2c02241 30761@subsubheading Synopsis
922fbb7b
AC
30762
30763@smallexample
a2c02241 30764 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
30765@end smallexample
30766
a2c02241
NR
30767Sets the output format for the value of the object @var{name} to be
30768@var{format-spec}.
30769
de051565 30770@anchor{-var-set-format}
a2c02241
NR
30771The syntax for the @var{format-spec} is as follows:
30772
30773@smallexample
30774 @var{format-spec} @expansion{}
30775 @{binary | decimal | hexadecimal | octal | natural@}
30776@end smallexample
30777
c8b2f53c
VP
30778The natural format is the default format choosen automatically
30779based on the variable type (like decimal for an @code{int}, hex
30780for pointers, etc.).
30781
30782For a variable with children, the format is set only on the
30783variable itself, and the children are not affected.
a2c02241
NR
30784
30785@subheading The @code{-var-show-format} Command
30786@findex -var-show-format
922fbb7b
AC
30787
30788@subsubheading Synopsis
30789
30790@smallexample
a2c02241 30791 -var-show-format @var{name}
922fbb7b
AC
30792@end smallexample
30793
a2c02241 30794Returns the format used to display the value of the object @var{name}.
922fbb7b 30795
a2c02241
NR
30796@smallexample
30797 @var{format} @expansion{}
30798 @var{format-spec}
30799@end smallexample
922fbb7b 30800
922fbb7b 30801
a2c02241
NR
30802@subheading The @code{-var-info-num-children} Command
30803@findex -var-info-num-children
30804
30805@subsubheading Synopsis
30806
30807@smallexample
30808 -var-info-num-children @var{name}
30809@end smallexample
30810
30811Returns the number of children of a variable object @var{name}:
30812
30813@smallexample
30814 numchild=@var{n}
30815@end smallexample
30816
0cc7d26f
TT
30817Note that this number is not completely reliable for a dynamic varobj.
30818It will return the current number of children, but more children may
30819be available.
30820
a2c02241
NR
30821
30822@subheading The @code{-var-list-children} Command
30823@findex -var-list-children
30824
30825@subsubheading Synopsis
30826
30827@smallexample
0cc7d26f 30828 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
a2c02241 30829@end smallexample
b569d230 30830@anchor{-var-list-children}
a2c02241
NR
30831
30832Return a list of the children of the specified variable object and
30833create variable objects for them, if they do not already exist. With
f5011d11 30834a single argument or if @var{print-values} has a value of 0 or
a2c02241
NR
30835@code{--no-values}, print only the names of the variables; if
30836@var{print-values} is 1 or @code{--all-values}, also print their
30837values; and if it is 2 or @code{--simple-values} print the name and
30838value for simple data types and just the name for arrays, structures
30839and unions.
922fbb7b 30840
0cc7d26f
TT
30841@var{from} and @var{to}, if specified, indicate the range of children
30842to report. If @var{from} or @var{to} is less than zero, the range is
30843reset and all children will be reported. Otherwise, children starting
30844at @var{from} (zero-based) and up to and excluding @var{to} will be
30845reported.
30846
30847If a child range is requested, it will only affect the current call to
30848@code{-var-list-children}, but not future calls to @code{-var-update}.
30849For this, you must instead use @code{-var-set-update-range}. The
30850intent of this approach is to enable a front end to implement any
30851update approach it likes; for example, scrolling a view may cause the
30852front end to request more children with @code{-var-list-children}, and
30853then the front end could call @code{-var-set-update-range} with a
30854different range to ensure that future updates are restricted to just
30855the visible items.
30856
b569d230
EZ
30857For each child the following results are returned:
30858
30859@table @var
30860
30861@item name
30862Name of the variable object created for this child.
30863
30864@item exp
30865The expression to be shown to the user by the front end to designate this child.
30866For example this may be the name of a structure member.
30867
0cc7d26f
TT
30868For a dynamic varobj, this value cannot be used to form an
30869expression. There is no way to do this at all with a dynamic varobj.
30870
b569d230
EZ
30871For C/C@t{++} structures there are several pseudo children returned to
30872designate access qualifiers. For these pseudo children @var{exp} is
30873@samp{public}, @samp{private}, or @samp{protected}. In this case the
30874type and value are not present.
30875
0cc7d26f
TT
30876A dynamic varobj will not report the access qualifying
30877pseudo-children, regardless of the language. This information is not
30878available at all with a dynamic varobj.
30879
b569d230 30880@item numchild
0cc7d26f
TT
30881Number of children this child has. For a dynamic varobj, this will be
308820.
b569d230
EZ
30883
30884@item type
8264ba82
AG
30885The type of the child. If @samp{print object}
30886(@pxref{Print Settings, set print object}) is set to @code{on}, the
30887@emph{actual} (derived) type of the object is shown rather than the
30888@emph{declared} one.
b569d230
EZ
30889
30890@item value
30891If values were requested, this is the value.
30892
30893@item thread-id
30894If this variable object is associated with a thread, this is the thread id.
30895Otherwise this result is not present.
30896
30897@item frozen
30898If the variable object is frozen, this variable will be present with a value of 1.
30899@end table
30900
0cc7d26f
TT
30901The result may have its own attributes:
30902
30903@table @samp
30904@item displayhint
30905A dynamic varobj can supply a display hint to the front end. The
30906value comes directly from the Python pretty-printer object's
4c374409 30907@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
30908
30909@item has_more
30910This is an integer attribute which is nonzero if there are children
30911remaining after the end of the selected range.
30912@end table
30913
922fbb7b
AC
30914@subsubheading Example
30915
30916@smallexample
594fe323 30917(gdb)
a2c02241 30918 -var-list-children n
b569d230 30919 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 30920 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 30921(gdb)
a2c02241 30922 -var-list-children --all-values n
b569d230 30923 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 30924 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
30925@end smallexample
30926
922fbb7b 30927
a2c02241
NR
30928@subheading The @code{-var-info-type} Command
30929@findex -var-info-type
922fbb7b 30930
a2c02241
NR
30931@subsubheading Synopsis
30932
30933@smallexample
30934 -var-info-type @var{name}
30935@end smallexample
30936
30937Returns the type of the specified variable @var{name}. The type is
30938returned as a string in the same format as it is output by the
30939@value{GDBN} CLI:
30940
30941@smallexample
30942 type=@var{typename}
30943@end smallexample
30944
30945
30946@subheading The @code{-var-info-expression} Command
30947@findex -var-info-expression
922fbb7b
AC
30948
30949@subsubheading Synopsis
30950
30951@smallexample
a2c02241 30952 -var-info-expression @var{name}
922fbb7b
AC
30953@end smallexample
30954
02142340
VP
30955Returns a string that is suitable for presenting this
30956variable object in user interface. The string is generally
30957not valid expression in the current language, and cannot be evaluated.
30958
30959For example, if @code{a} is an array, and variable object
30960@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 30961
a2c02241 30962@smallexample
02142340
VP
30963(gdb) -var-info-expression A.1
30964^done,lang="C",exp="1"
a2c02241 30965@end smallexample
922fbb7b 30966
a2c02241 30967@noindent
02142340
VP
30968Here, the values of @code{lang} can be @code{@{"C" | "C++" | "Java"@}}.
30969
30970Note that the output of the @code{-var-list-children} command also
30971includes those expressions, so the @code{-var-info-expression} command
30972is of limited use.
30973
30974@subheading The @code{-var-info-path-expression} Command
30975@findex -var-info-path-expression
30976
30977@subsubheading Synopsis
30978
30979@smallexample
30980 -var-info-path-expression @var{name}
30981@end smallexample
30982
30983Returns an expression that can be evaluated in the current
30984context and will yield the same value that a variable object has.
30985Compare this with the @code{-var-info-expression} command, which
30986result can be used only for UI presentation. Typical use of
30987the @code{-var-info-path-expression} command is creating a
30988watchpoint from a variable object.
30989
0cc7d26f
TT
30990This command is currently not valid for children of a dynamic varobj,
30991and will give an error when invoked on one.
30992
02142340
VP
30993For example, suppose @code{C} is a C@t{++} class, derived from class
30994@code{Base}, and that the @code{Base} class has a member called
30995@code{m_size}. Assume a variable @code{c} is has the type of
30996@code{C} and a variable object @code{C} was created for variable
30997@code{c}. Then, we'll get this output:
30998@smallexample
30999(gdb) -var-info-path-expression C.Base.public.m_size
31000^done,path_expr=((Base)c).m_size)
31001@end smallexample
922fbb7b 31002
a2c02241
NR
31003@subheading The @code{-var-show-attributes} Command
31004@findex -var-show-attributes
922fbb7b 31005
a2c02241 31006@subsubheading Synopsis
922fbb7b 31007
a2c02241
NR
31008@smallexample
31009 -var-show-attributes @var{name}
31010@end smallexample
922fbb7b 31011
a2c02241 31012List attributes of the specified variable object @var{name}:
922fbb7b
AC
31013
31014@smallexample
a2c02241 31015 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
31016@end smallexample
31017
a2c02241
NR
31018@noindent
31019where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
31020
31021@subheading The @code{-var-evaluate-expression} Command
31022@findex -var-evaluate-expression
31023
31024@subsubheading Synopsis
31025
31026@smallexample
de051565 31027 -var-evaluate-expression [-f @var{format-spec}] @var{name}
a2c02241
NR
31028@end smallexample
31029
31030Evaluates the expression that is represented by the specified variable
de051565
MK
31031object and returns its value as a string. The format of the string
31032can be specified with the @samp{-f} option. The possible values of
31033this option are the same as for @code{-var-set-format}
31034(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
31035the current display format will be used. The current display format
31036can be changed using the @code{-var-set-format} command.
a2c02241
NR
31037
31038@smallexample
31039 value=@var{value}
31040@end smallexample
31041
31042Note that one must invoke @code{-var-list-children} for a variable
31043before the value of a child variable can be evaluated.
31044
31045@subheading The @code{-var-assign} Command
31046@findex -var-assign
31047
31048@subsubheading Synopsis
31049
31050@smallexample
31051 -var-assign @var{name} @var{expression}
31052@end smallexample
31053
31054Assigns the value of @var{expression} to the variable object specified
31055by @var{name}. The object must be @samp{editable}. If the variable's
31056value is altered by the assign, the variable will show up in any
31057subsequent @code{-var-update} list.
31058
31059@subsubheading Example
922fbb7b
AC
31060
31061@smallexample
594fe323 31062(gdb)
a2c02241
NR
31063-var-assign var1 3
31064^done,value="3"
594fe323 31065(gdb)
a2c02241
NR
31066-var-update *
31067^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 31068(gdb)
922fbb7b
AC
31069@end smallexample
31070
a2c02241
NR
31071@subheading The @code{-var-update} Command
31072@findex -var-update
31073
31074@subsubheading Synopsis
31075
31076@smallexample
31077 -var-update [@var{print-values}] @{@var{name} | "*"@}
31078@end smallexample
31079
c8b2f53c
VP
31080Reevaluate the expressions corresponding to the variable object
31081@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
31082list of variable objects whose values have changed; @var{name} must
31083be a root variable object. Here, ``changed'' means that the result of
31084@code{-var-evaluate-expression} before and after the
31085@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
31086object names, all existing variable objects are updated, except
31087for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3 31088@var{print-values} determines whether both names and values, or just
de051565 31089names are printed. The possible values of this option are the same
36ece8b3
NR
31090as for @code{-var-list-children} (@pxref{-var-list-children}). It is
31091recommended to use the @samp{--all-values} option, to reduce the
31092number of MI commands needed on each program stop.
c8b2f53c 31093
c3b108f7
VP
31094With the @samp{*} parameter, if a variable object is bound to a
31095currently running thread, it will not be updated, without any
31096diagnostic.
a2c02241 31097
0cc7d26f
TT
31098If @code{-var-set-update-range} was previously used on a varobj, then
31099only the selected range of children will be reported.
922fbb7b 31100
0cc7d26f
TT
31101@code{-var-update} reports all the changed varobjs in a tuple named
31102@samp{changelist}.
31103
31104Each item in the change list is itself a tuple holding:
31105
31106@table @samp
31107@item name
31108The name of the varobj.
31109
31110@item value
31111If values were requested for this update, then this field will be
31112present and will hold the value of the varobj.
922fbb7b 31113
0cc7d26f 31114@item in_scope
9f708cb2 31115@anchor{-var-update}
0cc7d26f 31116This field is a string which may take one of three values:
36ece8b3
NR
31117
31118@table @code
31119@item "true"
31120The variable object's current value is valid.
31121
31122@item "false"
31123The variable object does not currently hold a valid value but it may
31124hold one in the future if its associated expression comes back into
31125scope.
31126
31127@item "invalid"
31128The variable object no longer holds a valid value.
31129This can occur when the executable file being debugged has changed,
31130either through recompilation or by using the @value{GDBN} @code{file}
31131command. The front end should normally choose to delete these variable
31132objects.
31133@end table
31134
31135In the future new values may be added to this list so the front should
31136be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
31137
0cc7d26f
TT
31138@item type_changed
31139This is only present if the varobj is still valid. If the type
31140changed, then this will be the string @samp{true}; otherwise it will
31141be @samp{false}.
31142
7191c139
JB
31143When a varobj's type changes, its children are also likely to have
31144become incorrect. Therefore, the varobj's children are automatically
31145deleted when this attribute is @samp{true}. Also, the varobj's update
31146range, when set using the @code{-var-set-update-range} command, is
31147unset.
31148
0cc7d26f
TT
31149@item new_type
31150If the varobj's type changed, then this field will be present and will
31151hold the new type.
31152
31153@item new_num_children
31154For a dynamic varobj, if the number of children changed, or if the
31155type changed, this will be the new number of children.
31156
31157The @samp{numchild} field in other varobj responses is generally not
31158valid for a dynamic varobj -- it will show the number of children that
31159@value{GDBN} knows about, but because dynamic varobjs lazily
31160instantiate their children, this will not reflect the number of
31161children which may be available.
31162
31163The @samp{new_num_children} attribute only reports changes to the
31164number of children known by @value{GDBN}. This is the only way to
31165detect whether an update has removed children (which necessarily can
31166only happen at the end of the update range).
31167
31168@item displayhint
31169The display hint, if any.
31170
31171@item has_more
31172This is an integer value, which will be 1 if there are more children
31173available outside the varobj's update range.
31174
31175@item dynamic
31176This attribute will be present and have the value @samp{1} if the
31177varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
31178then this attribute will not be present.
31179
31180@item new_children
31181If new children were added to a dynamic varobj within the selected
31182update range (as set by @code{-var-set-update-range}), then they will
31183be listed in this attribute.
31184@end table
31185
31186@subsubheading Example
31187
31188@smallexample
31189(gdb)
31190-var-assign var1 3
31191^done,value="3"
31192(gdb)
31193-var-update --all-values var1
31194^done,changelist=[@{name="var1",value="3",in_scope="true",
31195type_changed="false"@}]
31196(gdb)
31197@end smallexample
31198
25d5ea92
VP
31199@subheading The @code{-var-set-frozen} Command
31200@findex -var-set-frozen
9f708cb2 31201@anchor{-var-set-frozen}
25d5ea92
VP
31202
31203@subsubheading Synopsis
31204
31205@smallexample
9f708cb2 31206 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
31207@end smallexample
31208
9f708cb2 31209Set the frozenness flag on the variable object @var{name}. The
25d5ea92 31210@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 31211frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 31212frozen, then neither itself, nor any of its children, are
9f708cb2 31213implicitly updated by @code{-var-update} of
25d5ea92
VP
31214a parent variable or by @code{-var-update *}. Only
31215@code{-var-update} of the variable itself will update its value and
31216values of its children. After a variable object is unfrozen, it is
31217implicitly updated by all subsequent @code{-var-update} operations.
31218Unfreezing a variable does not update it, only subsequent
31219@code{-var-update} does.
31220
31221@subsubheading Example
31222
31223@smallexample
31224(gdb)
31225-var-set-frozen V 1
31226^done
31227(gdb)
31228@end smallexample
31229
0cc7d26f
TT
31230@subheading The @code{-var-set-update-range} command
31231@findex -var-set-update-range
31232@anchor{-var-set-update-range}
31233
31234@subsubheading Synopsis
31235
31236@smallexample
31237 -var-set-update-range @var{name} @var{from} @var{to}
31238@end smallexample
31239
31240Set the range of children to be returned by future invocations of
31241@code{-var-update}.
31242
31243@var{from} and @var{to} indicate the range of children to report. If
31244@var{from} or @var{to} is less than zero, the range is reset and all
31245children will be reported. Otherwise, children starting at @var{from}
31246(zero-based) and up to and excluding @var{to} will be reported.
31247
31248@subsubheading Example
31249
31250@smallexample
31251(gdb)
31252-var-set-update-range V 1 2
31253^done
31254@end smallexample
31255
b6313243
TT
31256@subheading The @code{-var-set-visualizer} command
31257@findex -var-set-visualizer
31258@anchor{-var-set-visualizer}
31259
31260@subsubheading Synopsis
31261
31262@smallexample
31263 -var-set-visualizer @var{name} @var{visualizer}
31264@end smallexample
31265
31266Set a visualizer for the variable object @var{name}.
31267
31268@var{visualizer} is the visualizer to use. The special value
31269@samp{None} means to disable any visualizer in use.
31270
31271If not @samp{None}, @var{visualizer} must be a Python expression.
31272This expression must evaluate to a callable object which accepts a
31273single argument. @value{GDBN} will call this object with the value of
31274the varobj @var{name} as an argument (this is done so that the same
31275Python pretty-printing code can be used for both the CLI and MI).
31276When called, this object must return an object which conforms to the
4c374409 31277pretty-printing interface (@pxref{Pretty Printing API}).
b6313243
TT
31278
31279The pre-defined function @code{gdb.default_visualizer} may be used to
31280select a visualizer by following the built-in process
31281(@pxref{Selecting Pretty-Printers}). This is done automatically when
31282a varobj is created, and so ordinarily is not needed.
31283
31284This feature is only available if Python support is enabled. The MI
31285command @code{-list-features} (@pxref{GDB/MI Miscellaneous Commands})
31286can be used to check this.
31287
31288@subsubheading Example
31289
31290Resetting the visualizer:
31291
31292@smallexample
31293(gdb)
31294-var-set-visualizer V None
31295^done
31296@end smallexample
31297
31298Reselecting the default (type-based) visualizer:
31299
31300@smallexample
31301(gdb)
31302-var-set-visualizer V gdb.default_visualizer
31303^done
31304@end smallexample
31305
31306Suppose @code{SomeClass} is a visualizer class. A lambda expression
31307can be used to instantiate this class for a varobj:
31308
31309@smallexample
31310(gdb)
31311-var-set-visualizer V "lambda val: SomeClass()"
31312^done
31313@end smallexample
25d5ea92 31314
a2c02241
NR
31315@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31316@node GDB/MI Data Manipulation
31317@section @sc{gdb/mi} Data Manipulation
922fbb7b 31318
a2c02241
NR
31319@cindex data manipulation, in @sc{gdb/mi}
31320@cindex @sc{gdb/mi}, data manipulation
31321This section describes the @sc{gdb/mi} commands that manipulate data:
31322examine memory and registers, evaluate expressions, etc.
31323
31324@c REMOVED FROM THE INTERFACE.
31325@c @subheading -data-assign
31326@c Change the value of a program variable. Plenty of side effects.
79a6e687 31327@c @subsubheading GDB Command
a2c02241
NR
31328@c set variable
31329@c @subsubheading Example
31330@c N.A.
31331
31332@subheading The @code{-data-disassemble} Command
31333@findex -data-disassemble
922fbb7b
AC
31334
31335@subsubheading Synopsis
31336
31337@smallexample
a2c02241
NR
31338 -data-disassemble
31339 [ -s @var{start-addr} -e @var{end-addr} ]
31340 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
31341 -- @var{mode}
922fbb7b
AC
31342@end smallexample
31343
a2c02241
NR
31344@noindent
31345Where:
31346
31347@table @samp
31348@item @var{start-addr}
31349is the beginning address (or @code{$pc})
31350@item @var{end-addr}
31351is the end address
31352@item @var{filename}
31353is the name of the file to disassemble
31354@item @var{linenum}
31355is the line number to disassemble around
31356@item @var{lines}
d3e8051b 31357is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
31358the whole function will be disassembled, in case no @var{end-addr} is
31359specified. If @var{end-addr} is specified as a non-zero value, and
31360@var{lines} is lower than the number of disassembly lines between
31361@var{start-addr} and @var{end-addr}, only @var{lines} lines are
31362displayed; if @var{lines} is higher than the number of lines between
31363@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
31364are displayed.
31365@item @var{mode}
b716877b
AB
31366is either 0 (meaning only disassembly), 1 (meaning mixed source and
31367disassembly), 2 (meaning disassembly with raw opcodes), or 3 (meaning
31368mixed source and disassembly with raw opcodes).
a2c02241
NR
31369@end table
31370
31371@subsubheading Result
31372
ed8a1c2d
AB
31373The result of the @code{-data-disassemble} command will be a list named
31374@samp{asm_insns}, the contents of this list depend on the @var{mode}
31375used with the @code{-data-disassemble} command.
a2c02241 31376
ed8a1c2d
AB
31377For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
31378following fields:
31379
31380@table @code
31381@item address
31382The address at which this instruction was disassembled.
31383
31384@item func-name
31385The name of the function this instruction is within.
31386
31387@item offset
31388The decimal offset in bytes from the start of @samp{func-name}.
31389
31390@item inst
31391The text disassembly for this @samp{address}.
31392
31393@item opcodes
31394This field is only present for mode 2. This contains the raw opcode
31395bytes for the @samp{inst} field.
31396
31397@end table
31398
31399For modes 1 and 3 the @samp{asm_insns} list contains tuples named
31400@samp{src_and_asm_line}, each of which has the following fields:
a2c02241 31401
ed8a1c2d
AB
31402@table @code
31403@item line
31404The line number within @samp{file}.
31405
31406@item file
31407The file name from the compilation unit. This might be an absolute
31408file name or a relative file name depending on the compile command
31409used.
31410
31411@item fullname
f35a17b5
JK
31412Absolute file name of @samp{file}. It is converted to a canonical form
31413using the source file search path
31414(@pxref{Source Path, ,Specifying Source Directories})
31415and after resolving all the symbolic links.
31416
31417If the source file is not found this field will contain the path as
31418present in the debug information.
ed8a1c2d
AB
31419
31420@item line_asm_insn
31421This is a list of tuples containing the disassembly for @samp{line} in
31422@samp{file}. The fields of each tuple are the same as for
31423@code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
31424@samp{func-name}, @samp{offset}, @samp{inst}, and optionally
31425@samp{opcodes}.
31426
31427@end table
31428
31429Note that whatever included in the @samp{inst} field, is not
31430manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
31431adjust its format.
922fbb7b
AC
31432
31433@subsubheading @value{GDBN} Command
31434
ed8a1c2d 31435The corresponding @value{GDBN} command is @samp{disassemble}.
922fbb7b
AC
31436
31437@subsubheading Example
31438
a2c02241
NR
31439Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
31440
922fbb7b 31441@smallexample
594fe323 31442(gdb)
a2c02241
NR
31443-data-disassemble -s $pc -e "$pc + 20" -- 0
31444^done,
31445asm_insns=[
31446@{address="0x000107c0",func-name="main",offset="4",
31447inst="mov 2, %o0"@},
31448@{address="0x000107c4",func-name="main",offset="8",
31449inst="sethi %hi(0x11800), %o2"@},
31450@{address="0x000107c8",func-name="main",offset="12",
31451inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
31452@{address="0x000107cc",func-name="main",offset="16",
31453inst="sethi %hi(0x11800), %o2"@},
31454@{address="0x000107d0",func-name="main",offset="20",
31455inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 31456(gdb)
a2c02241
NR
31457@end smallexample
31458
31459Disassemble the whole @code{main} function. Line 32 is part of
31460@code{main}.
31461
31462@smallexample
31463-data-disassemble -f basics.c -l 32 -- 0
31464^done,asm_insns=[
31465@{address="0x000107bc",func-name="main",offset="0",
31466inst="save %sp, -112, %sp"@},
31467@{address="0x000107c0",func-name="main",offset="4",
31468inst="mov 2, %o0"@},
31469@{address="0x000107c4",func-name="main",offset="8",
31470inst="sethi %hi(0x11800), %o2"@},
31471[@dots{}]
31472@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
31473@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 31474(gdb)
922fbb7b
AC
31475@end smallexample
31476
a2c02241 31477Disassemble 3 instructions from the start of @code{main}:
922fbb7b 31478
a2c02241 31479@smallexample
594fe323 31480(gdb)
a2c02241
NR
31481-data-disassemble -f basics.c -l 32 -n 3 -- 0
31482^done,asm_insns=[
31483@{address="0x000107bc",func-name="main",offset="0",
31484inst="save %sp, -112, %sp"@},
31485@{address="0x000107c0",func-name="main",offset="4",
31486inst="mov 2, %o0"@},
31487@{address="0x000107c4",func-name="main",offset="8",
31488inst="sethi %hi(0x11800), %o2"@}]
594fe323 31489(gdb)
a2c02241
NR
31490@end smallexample
31491
31492Disassemble 3 instructions from the start of @code{main} in mixed mode:
31493
31494@smallexample
594fe323 31495(gdb)
a2c02241
NR
31496-data-disassemble -f basics.c -l 32 -n 3 -- 1
31497^done,asm_insns=[
31498src_and_asm_line=@{line="31",
ed8a1c2d
AB
31499file="../../../src/gdb/testsuite/gdb.mi/basics.c",
31500fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
31501line_asm_insn=[@{address="0x000107bc",
31502func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
a2c02241 31503src_and_asm_line=@{line="32",
ed8a1c2d
AB
31504file="../../../src/gdb/testsuite/gdb.mi/basics.c",
31505fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
31506line_asm_insn=[@{address="0x000107c0",
31507func-name="main",offset="4",inst="mov 2, %o0"@},
a2c02241
NR
31508@{address="0x000107c4",func-name="main",offset="8",
31509inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 31510(gdb)
a2c02241
NR
31511@end smallexample
31512
31513
31514@subheading The @code{-data-evaluate-expression} Command
31515@findex -data-evaluate-expression
922fbb7b
AC
31516
31517@subsubheading Synopsis
31518
31519@smallexample
a2c02241 31520 -data-evaluate-expression @var{expr}
922fbb7b
AC
31521@end smallexample
31522
a2c02241
NR
31523Evaluate @var{expr} as an expression. The expression could contain an
31524inferior function call. The function call will execute synchronously.
31525If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
31526
31527@subsubheading @value{GDBN} Command
31528
a2c02241
NR
31529The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
31530@samp{call}. In @code{gdbtk} only, there's a corresponding
31531@samp{gdb_eval} command.
922fbb7b
AC
31532
31533@subsubheading Example
31534
a2c02241
NR
31535In the following example, the numbers that precede the commands are the
31536@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
31537Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
31538output.
31539
922fbb7b 31540@smallexample
a2c02241
NR
31541211-data-evaluate-expression A
31542211^done,value="1"
594fe323 31543(gdb)
a2c02241
NR
31544311-data-evaluate-expression &A
31545311^done,value="0xefffeb7c"
594fe323 31546(gdb)
a2c02241
NR
31547411-data-evaluate-expression A+3
31548411^done,value="4"
594fe323 31549(gdb)
a2c02241
NR
31550511-data-evaluate-expression "A + 3"
31551511^done,value="4"
594fe323 31552(gdb)
a2c02241 31553@end smallexample
922fbb7b
AC
31554
31555
a2c02241
NR
31556@subheading The @code{-data-list-changed-registers} Command
31557@findex -data-list-changed-registers
922fbb7b
AC
31558
31559@subsubheading Synopsis
31560
31561@smallexample
a2c02241 31562 -data-list-changed-registers
922fbb7b
AC
31563@end smallexample
31564
a2c02241 31565Display a list of the registers that have changed.
922fbb7b
AC
31566
31567@subsubheading @value{GDBN} Command
31568
a2c02241
NR
31569@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
31570has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
31571
31572@subsubheading Example
922fbb7b 31573
a2c02241 31574On a PPC MBX board:
922fbb7b
AC
31575
31576@smallexample
594fe323 31577(gdb)
a2c02241
NR
31578-exec-continue
31579^running
922fbb7b 31580
594fe323 31581(gdb)
a47ec5fe
AR
31582*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
31583func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
31584line="5"@}
594fe323 31585(gdb)
a2c02241
NR
31586-data-list-changed-registers
31587^done,changed-registers=["0","1","2","4","5","6","7","8","9",
31588"10","11","13","14","15","16","17","18","19","20","21","22","23",
31589"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 31590(gdb)
a2c02241 31591@end smallexample
922fbb7b
AC
31592
31593
a2c02241
NR
31594@subheading The @code{-data-list-register-names} Command
31595@findex -data-list-register-names
922fbb7b
AC
31596
31597@subsubheading Synopsis
31598
31599@smallexample
a2c02241 31600 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
31601@end smallexample
31602
a2c02241
NR
31603Show a list of register names for the current target. If no arguments
31604are given, it shows a list of the names of all the registers. If
31605integer numbers are given as arguments, it will print a list of the
31606names of the registers corresponding to the arguments. To ensure
31607consistency between a register name and its number, the output list may
31608include empty register names.
922fbb7b
AC
31609
31610@subsubheading @value{GDBN} Command
31611
a2c02241
NR
31612@value{GDBN} does not have a command which corresponds to
31613@samp{-data-list-register-names}. In @code{gdbtk} there is a
31614corresponding command @samp{gdb_regnames}.
922fbb7b
AC
31615
31616@subsubheading Example
922fbb7b 31617
a2c02241
NR
31618For the PPC MBX board:
31619@smallexample
594fe323 31620(gdb)
a2c02241
NR
31621-data-list-register-names
31622^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
31623"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
31624"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
31625"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
31626"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
31627"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
31628"", "pc","ps","cr","lr","ctr","xer"]
594fe323 31629(gdb)
a2c02241
NR
31630-data-list-register-names 1 2 3
31631^done,register-names=["r1","r2","r3"]
594fe323 31632(gdb)
a2c02241 31633@end smallexample
922fbb7b 31634
a2c02241
NR
31635@subheading The @code{-data-list-register-values} Command
31636@findex -data-list-register-values
922fbb7b
AC
31637
31638@subsubheading Synopsis
31639
31640@smallexample
a2c02241 31641 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
31642@end smallexample
31643
a2c02241
NR
31644Display the registers' contents. @var{fmt} is the format according to
31645which the registers' contents are to be returned, followed by an optional
31646list of numbers specifying the registers to display. A missing list of
31647numbers indicates that the contents of all the registers must be returned.
31648
31649Allowed formats for @var{fmt} are:
31650
31651@table @code
31652@item x
31653Hexadecimal
31654@item o
31655Octal
31656@item t
31657Binary
31658@item d
31659Decimal
31660@item r
31661Raw
31662@item N
31663Natural
31664@end table
922fbb7b
AC
31665
31666@subsubheading @value{GDBN} Command
31667
a2c02241
NR
31668The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
31669all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
31670
31671@subsubheading Example
922fbb7b 31672
a2c02241
NR
31673For a PPC MBX board (note: line breaks are for readability only, they
31674don't appear in the actual output):
31675
31676@smallexample
594fe323 31677(gdb)
a2c02241
NR
31678-data-list-register-values r 64 65
31679^done,register-values=[@{number="64",value="0xfe00a300"@},
31680@{number="65",value="0x00029002"@}]
594fe323 31681(gdb)
a2c02241
NR
31682-data-list-register-values x
31683^done,register-values=[@{number="0",value="0xfe0043c8"@},
31684@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
31685@{number="3",value="0x0"@},@{number="4",value="0xa"@},
31686@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
31687@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
31688@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
31689@{number="11",value="0x1"@},@{number="12",value="0x0"@},
31690@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
31691@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
31692@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
31693@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
31694@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
31695@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
31696@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
31697@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
31698@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
31699@{number="31",value="0x0"@},@{number="32",value="0x0"@},
31700@{number="33",value="0x0"@},@{number="34",value="0x0"@},
31701@{number="35",value="0x0"@},@{number="36",value="0x0"@},
31702@{number="37",value="0x0"@},@{number="38",value="0x0"@},
31703@{number="39",value="0x0"@},@{number="40",value="0x0"@},
31704@{number="41",value="0x0"@},@{number="42",value="0x0"@},
31705@{number="43",value="0x0"@},@{number="44",value="0x0"@},
31706@{number="45",value="0x0"@},@{number="46",value="0x0"@},
31707@{number="47",value="0x0"@},@{number="48",value="0x0"@},
31708@{number="49",value="0x0"@},@{number="50",value="0x0"@},
31709@{number="51",value="0x0"@},@{number="52",value="0x0"@},
31710@{number="53",value="0x0"@},@{number="54",value="0x0"@},
31711@{number="55",value="0x0"@},@{number="56",value="0x0"@},
31712@{number="57",value="0x0"@},@{number="58",value="0x0"@},
31713@{number="59",value="0x0"@},@{number="60",value="0x0"@},
31714@{number="61",value="0x0"@},@{number="62",value="0x0"@},
31715@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
31716@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
31717@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
31718@{number="69",value="0x20002b03"@}]
594fe323 31719(gdb)
a2c02241 31720@end smallexample
922fbb7b 31721
a2c02241
NR
31722
31723@subheading The @code{-data-read-memory} Command
31724@findex -data-read-memory
922fbb7b 31725
8dedea02
VP
31726This command is deprecated, use @code{-data-read-memory-bytes} instead.
31727
922fbb7b
AC
31728@subsubheading Synopsis
31729
31730@smallexample
a2c02241
NR
31731 -data-read-memory [ -o @var{byte-offset} ]
31732 @var{address} @var{word-format} @var{word-size}
31733 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
31734@end smallexample
31735
a2c02241
NR
31736@noindent
31737where:
922fbb7b 31738
a2c02241
NR
31739@table @samp
31740@item @var{address}
31741An expression specifying the address of the first memory word to be
31742read. Complex expressions containing embedded white space should be
31743quoted using the C convention.
922fbb7b 31744
a2c02241
NR
31745@item @var{word-format}
31746The format to be used to print the memory words. The notation is the
31747same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 31748,Output Formats}).
922fbb7b 31749
a2c02241
NR
31750@item @var{word-size}
31751The size of each memory word in bytes.
922fbb7b 31752
a2c02241
NR
31753@item @var{nr-rows}
31754The number of rows in the output table.
922fbb7b 31755
a2c02241
NR
31756@item @var{nr-cols}
31757The number of columns in the output table.
922fbb7b 31758
a2c02241
NR
31759@item @var{aschar}
31760If present, indicates that each row should include an @sc{ascii} dump. The
31761value of @var{aschar} is used as a padding character when a byte is not a
31762member of the printable @sc{ascii} character set (printable @sc{ascii}
31763characters are those whose code is between 32 and 126, inclusively).
922fbb7b 31764
a2c02241
NR
31765@item @var{byte-offset}
31766An offset to add to the @var{address} before fetching memory.
31767@end table
922fbb7b 31768
a2c02241
NR
31769This command displays memory contents as a table of @var{nr-rows} by
31770@var{nr-cols} words, each word being @var{word-size} bytes. In total,
31771@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
31772(returned as @samp{total-bytes}). Should less than the requested number
31773of bytes be returned by the target, the missing words are identified
31774using @samp{N/A}. The number of bytes read from the target is returned
31775in @samp{nr-bytes} and the starting address used to read memory in
31776@samp{addr}.
31777
31778The address of the next/previous row or page is available in
31779@samp{next-row} and @samp{prev-row}, @samp{next-page} and
31780@samp{prev-page}.
922fbb7b
AC
31781
31782@subsubheading @value{GDBN} Command
31783
a2c02241
NR
31784The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
31785@samp{gdb_get_mem} memory read command.
922fbb7b
AC
31786
31787@subsubheading Example
32e7087d 31788
a2c02241
NR
31789Read six bytes of memory starting at @code{bytes+6} but then offset by
31790@code{-6} bytes. Format as three rows of two columns. One byte per
31791word. Display each word in hex.
32e7087d
JB
31792
31793@smallexample
594fe323 31794(gdb)
a2c02241
NR
317959-data-read-memory -o -6 -- bytes+6 x 1 3 2
317969^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
31797next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
31798prev-page="0x0000138a",memory=[
31799@{addr="0x00001390",data=["0x00","0x01"]@},
31800@{addr="0x00001392",data=["0x02","0x03"]@},
31801@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 31802(gdb)
32e7087d
JB
31803@end smallexample
31804
a2c02241
NR
31805Read two bytes of memory starting at address @code{shorts + 64} and
31806display as a single word formatted in decimal.
32e7087d 31807
32e7087d 31808@smallexample
594fe323 31809(gdb)
a2c02241
NR
318105-data-read-memory shorts+64 d 2 1 1
318115^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
31812next-row="0x00001512",prev-row="0x0000150e",
31813next-page="0x00001512",prev-page="0x0000150e",memory=[
31814@{addr="0x00001510",data=["128"]@}]
594fe323 31815(gdb)
32e7087d
JB
31816@end smallexample
31817
a2c02241
NR
31818Read thirty two bytes of memory starting at @code{bytes+16} and format
31819as eight rows of four columns. Include a string encoding with @samp{x}
31820used as the non-printable character.
922fbb7b
AC
31821
31822@smallexample
594fe323 31823(gdb)
a2c02241
NR
318244-data-read-memory bytes+16 x 1 8 4 x
318254^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
31826next-row="0x000013c0",prev-row="0x0000139c",
31827next-page="0x000013c0",prev-page="0x00001380",memory=[
31828@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
31829@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
31830@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
31831@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
31832@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
31833@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
31834@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
31835@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 31836(gdb)
922fbb7b
AC
31837@end smallexample
31838
8dedea02
VP
31839@subheading The @code{-data-read-memory-bytes} Command
31840@findex -data-read-memory-bytes
31841
31842@subsubheading Synopsis
31843
31844@smallexample
31845 -data-read-memory-bytes [ -o @var{byte-offset} ]
31846 @var{address} @var{count}
31847@end smallexample
31848
31849@noindent
31850where:
31851
31852@table @samp
31853@item @var{address}
31854An expression specifying the address of the first memory word to be
31855read. Complex expressions containing embedded white space should be
31856quoted using the C convention.
31857
31858@item @var{count}
31859The number of bytes to read. This should be an integer literal.
31860
31861@item @var{byte-offset}
31862The offsets in bytes relative to @var{address} at which to start
31863reading. This should be an integer literal. This option is provided
31864so that a frontend is not required to first evaluate address and then
31865perform address arithmetics itself.
31866
31867@end table
31868
31869This command attempts to read all accessible memory regions in the
31870specified range. First, all regions marked as unreadable in the memory
31871map (if one is defined) will be skipped. @xref{Memory Region
31872Attributes}. Second, @value{GDBN} will attempt to read the remaining
31873regions. For each one, if reading full region results in an errors,
31874@value{GDBN} will try to read a subset of the region.
31875
31876In general, every single byte in the region may be readable or not,
31877and the only way to read every readable byte is to try a read at
31878every address, which is not practical. Therefore, @value{GDBN} will
31879attempt to read all accessible bytes at either beginning or the end
31880of the region, using a binary division scheme. This heuristic works
31881well for reading accross a memory map boundary. Note that if a region
31882has a readable range that is neither at the beginning or the end,
31883@value{GDBN} will not read it.
31884
31885The result record (@pxref{GDB/MI Result Records}) that is output of
31886the command includes a field named @samp{memory} whose content is a
31887list of tuples. Each tuple represent a successfully read memory block
31888and has the following fields:
31889
31890@table @code
31891@item begin
31892The start address of the memory block, as hexadecimal literal.
31893
31894@item end
31895The end address of the memory block, as hexadecimal literal.
31896
31897@item offset
31898The offset of the memory block, as hexadecimal literal, relative to
31899the start address passed to @code{-data-read-memory-bytes}.
31900
31901@item contents
31902The contents of the memory block, in hex.
31903
31904@end table
31905
31906
31907
31908@subsubheading @value{GDBN} Command
31909
31910The corresponding @value{GDBN} command is @samp{x}.
31911
31912@subsubheading Example
31913
31914@smallexample
31915(gdb)
31916-data-read-memory-bytes &a 10
31917^done,memory=[@{begin="0xbffff154",offset="0x00000000",
31918 end="0xbffff15e",
31919 contents="01000000020000000300"@}]
31920(gdb)
31921@end smallexample
31922
31923
31924@subheading The @code{-data-write-memory-bytes} Command
31925@findex -data-write-memory-bytes
31926
31927@subsubheading Synopsis
31928
31929@smallexample
31930 -data-write-memory-bytes @var{address} @var{contents}
62747a60 31931 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
8dedea02
VP
31932@end smallexample
31933
31934@noindent
31935where:
31936
31937@table @samp
31938@item @var{address}
31939An expression specifying the address of the first memory word to be
31940read. Complex expressions containing embedded white space should be
31941quoted using the C convention.
31942
31943@item @var{contents}
31944The hex-encoded bytes to write.
31945
62747a60
TT
31946@item @var{count}
31947Optional argument indicating the number of bytes to be written. If @var{count}
31948is greater than @var{contents}' length, @value{GDBN} will repeatedly
31949write @var{contents} until it fills @var{count} bytes.
31950
8dedea02
VP
31951@end table
31952
31953@subsubheading @value{GDBN} Command
31954
31955There's no corresponding @value{GDBN} command.
31956
31957@subsubheading Example
31958
31959@smallexample
31960(gdb)
31961-data-write-memory-bytes &a "aabbccdd"
31962^done
31963(gdb)
31964@end smallexample
31965
62747a60
TT
31966@smallexample
31967(gdb)
31968-data-write-memory-bytes &a "aabbccdd" 16e
31969^done
31970(gdb)
31971@end smallexample
8dedea02 31972
a2c02241
NR
31973@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31974@node GDB/MI Tracepoint Commands
31975@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 31976
18148017
VP
31977The commands defined in this section implement MI support for
31978tracepoints. For detailed introduction, see @ref{Tracepoints}.
31979
31980@subheading The @code{-trace-find} Command
31981@findex -trace-find
31982
31983@subsubheading Synopsis
31984
31985@smallexample
31986 -trace-find @var{mode} [@var{parameters}@dots{}]
31987@end smallexample
31988
31989Find a trace frame using criteria defined by @var{mode} and
31990@var{parameters}. The following table lists permissible
31991modes and their parameters. For details of operation, see @ref{tfind}.
31992
31993@table @samp
31994
31995@item none
31996No parameters are required. Stops examining trace frames.
31997
31998@item frame-number
31999An integer is required as parameter. Selects tracepoint frame with
32000that index.
32001
32002@item tracepoint-number
32003An integer is required as parameter. Finds next
32004trace frame that corresponds to tracepoint with the specified number.
32005
32006@item pc
32007An address is required as parameter. Finds
32008next trace frame that corresponds to any tracepoint at the specified
32009address.
32010
32011@item pc-inside-range
32012Two addresses are required as parameters. Finds next trace
32013frame that corresponds to a tracepoint at an address inside the
32014specified range. Both bounds are considered to be inside the range.
32015
32016@item pc-outside-range
32017Two addresses are required as parameters. Finds
32018next trace frame that corresponds to a tracepoint at an address outside
32019the specified range. Both bounds are considered to be inside the range.
32020
32021@item line
32022Line specification is required as parameter. @xref{Specify Location}.
32023Finds next trace frame that corresponds to a tracepoint at
32024the specified location.
32025
32026@end table
32027
32028If @samp{none} was passed as @var{mode}, the response does not
32029have fields. Otherwise, the response may have the following fields:
32030
32031@table @samp
32032@item found
32033This field has either @samp{0} or @samp{1} as the value, depending
32034on whether a matching tracepoint was found.
32035
32036@item traceframe
32037The index of the found traceframe. This field is present iff
32038the @samp{found} field has value of @samp{1}.
32039
32040@item tracepoint
32041The index of the found tracepoint. This field is present iff
32042the @samp{found} field has value of @samp{1}.
32043
32044@item frame
32045The information about the frame corresponding to the found trace
32046frame. This field is present only if a trace frame was found.
cd64ee31 32047@xref{GDB/MI Frame Information}, for description of this field.
18148017
VP
32048
32049@end table
32050
7d13fe92
SS
32051@subsubheading @value{GDBN} Command
32052
32053The corresponding @value{GDBN} command is @samp{tfind}.
32054
18148017
VP
32055@subheading -trace-define-variable
32056@findex -trace-define-variable
32057
32058@subsubheading Synopsis
32059
32060@smallexample
32061 -trace-define-variable @var{name} [ @var{value} ]
32062@end smallexample
32063
32064Create trace variable @var{name} if it does not exist. If
32065@var{value} is specified, sets the initial value of the specified
32066trace variable to that value. Note that the @var{name} should start
32067with the @samp{$} character.
32068
7d13fe92
SS
32069@subsubheading @value{GDBN} Command
32070
32071The corresponding @value{GDBN} command is @samp{tvariable}.
32072
18148017
VP
32073@subheading -trace-list-variables
32074@findex -trace-list-variables
922fbb7b 32075
18148017 32076@subsubheading Synopsis
922fbb7b 32077
18148017
VP
32078@smallexample
32079 -trace-list-variables
32080@end smallexample
922fbb7b 32081
18148017
VP
32082Return a table of all defined trace variables. Each element of the
32083table has the following fields:
922fbb7b 32084
18148017
VP
32085@table @samp
32086@item name
32087The name of the trace variable. This field is always present.
922fbb7b 32088
18148017
VP
32089@item initial
32090The initial value. This is a 64-bit signed integer. This
32091field is always present.
922fbb7b 32092
18148017
VP
32093@item current
32094The value the trace variable has at the moment. This is a 64-bit
32095signed integer. This field is absent iff current value is
32096not defined, for example if the trace was never run, or is
32097presently running.
922fbb7b 32098
18148017 32099@end table
922fbb7b 32100
7d13fe92
SS
32101@subsubheading @value{GDBN} Command
32102
32103The corresponding @value{GDBN} command is @samp{tvariables}.
32104
18148017 32105@subsubheading Example
922fbb7b 32106
18148017
VP
32107@smallexample
32108(gdb)
32109-trace-list-variables
32110^done,trace-variables=@{nr_rows="1",nr_cols="3",
32111hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
32112 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
32113 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
32114body=[variable=@{name="$trace_timestamp",initial="0"@}
32115 variable=@{name="$foo",initial="10",current="15"@}]@}
32116(gdb)
32117@end smallexample
922fbb7b 32118
18148017
VP
32119@subheading -trace-save
32120@findex -trace-save
922fbb7b 32121
18148017
VP
32122@subsubheading Synopsis
32123
32124@smallexample
32125 -trace-save [-r ] @var{filename}
32126@end smallexample
32127
32128Saves the collected trace data to @var{filename}. Without the
32129@samp{-r} option, the data is downloaded from the target and saved
32130in a local file. With the @samp{-r} option the target is asked
32131to perform the save.
32132
7d13fe92
SS
32133@subsubheading @value{GDBN} Command
32134
32135The corresponding @value{GDBN} command is @samp{tsave}.
32136
18148017
VP
32137
32138@subheading -trace-start
32139@findex -trace-start
32140
32141@subsubheading Synopsis
32142
32143@smallexample
32144 -trace-start
32145@end smallexample
922fbb7b 32146
18148017
VP
32147Starts a tracing experiments. The result of this command does not
32148have any fields.
922fbb7b 32149
7d13fe92
SS
32150@subsubheading @value{GDBN} Command
32151
32152The corresponding @value{GDBN} command is @samp{tstart}.
32153
18148017
VP
32154@subheading -trace-status
32155@findex -trace-status
922fbb7b 32156
18148017
VP
32157@subsubheading Synopsis
32158
32159@smallexample
32160 -trace-status
32161@end smallexample
32162
a97153c7 32163Obtains the status of a tracing experiment. The result may include
18148017
VP
32164the following fields:
32165
32166@table @samp
32167
32168@item supported
32169May have a value of either @samp{0}, when no tracing operations are
32170supported, @samp{1}, when all tracing operations are supported, or
32171@samp{file} when examining trace file. In the latter case, examining
32172of trace frame is possible but new tracing experiement cannot be
32173started. This field is always present.
32174
32175@item running
32176May have a value of either @samp{0} or @samp{1} depending on whether
32177tracing experiement is in progress on target. This field is present
32178if @samp{supported} field is not @samp{0}.
32179
32180@item stop-reason
32181Report the reason why the tracing was stopped last time. This field
32182may be absent iff tracing was never stopped on target yet. The
32183value of @samp{request} means the tracing was stopped as result of
32184the @code{-trace-stop} command. The value of @samp{overflow} means
32185the tracing buffer is full. The value of @samp{disconnection} means
32186tracing was automatically stopped when @value{GDBN} has disconnected.
32187The value of @samp{passcount} means tracing was stopped when a
32188tracepoint was passed a maximal number of times for that tracepoint.
32189This field is present if @samp{supported} field is not @samp{0}.
32190
32191@item stopping-tracepoint
32192The number of tracepoint whose passcount as exceeded. This field is
32193present iff the @samp{stop-reason} field has the value of
32194@samp{passcount}.
32195
32196@item frames
87290684
SS
32197@itemx frames-created
32198The @samp{frames} field is a count of the total number of trace frames
32199in the trace buffer, while @samp{frames-created} is the total created
32200during the run, including ones that were discarded, such as when a
32201circular trace buffer filled up. Both fields are optional.
18148017
VP
32202
32203@item buffer-size
32204@itemx buffer-free
32205These fields tell the current size of the tracing buffer and the
87290684 32206remaining space. These fields are optional.
18148017 32207
a97153c7
PA
32208@item circular
32209The value of the circular trace buffer flag. @code{1} means that the
32210trace buffer is circular and old trace frames will be discarded if
32211necessary to make room, @code{0} means that the trace buffer is linear
32212and may fill up.
32213
32214@item disconnected
32215The value of the disconnected tracing flag. @code{1} means that
32216tracing will continue after @value{GDBN} disconnects, @code{0} means
32217that the trace run will stop.
32218
f5911ea1
HAQ
32219@item trace-file
32220The filename of the trace file being examined. This field is
32221optional, and only present when examining a trace file.
32222
18148017
VP
32223@end table
32224
7d13fe92
SS
32225@subsubheading @value{GDBN} Command
32226
32227The corresponding @value{GDBN} command is @samp{tstatus}.
32228
18148017
VP
32229@subheading -trace-stop
32230@findex -trace-stop
32231
32232@subsubheading Synopsis
32233
32234@smallexample
32235 -trace-stop
32236@end smallexample
922fbb7b 32237
18148017
VP
32238Stops a tracing experiment. The result of this command has the same
32239fields as @code{-trace-status}, except that the @samp{supported} and
32240@samp{running} fields are not output.
922fbb7b 32241
7d13fe92
SS
32242@subsubheading @value{GDBN} Command
32243
32244The corresponding @value{GDBN} command is @samp{tstop}.
32245
922fbb7b 32246
a2c02241
NR
32247@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32248@node GDB/MI Symbol Query
32249@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
32250
32251
9901a55b 32252@ignore
a2c02241
NR
32253@subheading The @code{-symbol-info-address} Command
32254@findex -symbol-info-address
922fbb7b
AC
32255
32256@subsubheading Synopsis
32257
32258@smallexample
a2c02241 32259 -symbol-info-address @var{symbol}
922fbb7b
AC
32260@end smallexample
32261
a2c02241 32262Describe where @var{symbol} is stored.
922fbb7b
AC
32263
32264@subsubheading @value{GDBN} Command
32265
a2c02241 32266The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
32267
32268@subsubheading Example
32269N.A.
32270
32271
a2c02241
NR
32272@subheading The @code{-symbol-info-file} Command
32273@findex -symbol-info-file
922fbb7b
AC
32274
32275@subsubheading Synopsis
32276
32277@smallexample
a2c02241 32278 -symbol-info-file
922fbb7b
AC
32279@end smallexample
32280
a2c02241 32281Show the file for the symbol.
922fbb7b 32282
a2c02241 32283@subsubheading @value{GDBN} Command
922fbb7b 32284
a2c02241
NR
32285There's no equivalent @value{GDBN} command. @code{gdbtk} has
32286@samp{gdb_find_file}.
922fbb7b
AC
32287
32288@subsubheading Example
32289N.A.
32290
32291
a2c02241
NR
32292@subheading The @code{-symbol-info-function} Command
32293@findex -symbol-info-function
922fbb7b
AC
32294
32295@subsubheading Synopsis
32296
32297@smallexample
a2c02241 32298 -symbol-info-function
922fbb7b
AC
32299@end smallexample
32300
a2c02241 32301Show which function the symbol lives in.
922fbb7b
AC
32302
32303@subsubheading @value{GDBN} Command
32304
a2c02241 32305@samp{gdb_get_function} in @code{gdbtk}.
922fbb7b
AC
32306
32307@subsubheading Example
32308N.A.
32309
32310
a2c02241
NR
32311@subheading The @code{-symbol-info-line} Command
32312@findex -symbol-info-line
922fbb7b
AC
32313
32314@subsubheading Synopsis
32315
32316@smallexample
a2c02241 32317 -symbol-info-line
922fbb7b
AC
32318@end smallexample
32319
a2c02241 32320Show the core addresses of the code for a source line.
922fbb7b 32321
a2c02241 32322@subsubheading @value{GDBN} Command
922fbb7b 32323
a2c02241
NR
32324The corresponding @value{GDBN} command is @samp{info line}.
32325@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
32326
32327@subsubheading Example
a2c02241 32328N.A.
922fbb7b
AC
32329
32330
a2c02241
NR
32331@subheading The @code{-symbol-info-symbol} Command
32332@findex -symbol-info-symbol
07f31aa6
DJ
32333
32334@subsubheading Synopsis
32335
a2c02241
NR
32336@smallexample
32337 -symbol-info-symbol @var{addr}
32338@end smallexample
07f31aa6 32339
a2c02241 32340Describe what symbol is at location @var{addr}.
07f31aa6 32341
a2c02241 32342@subsubheading @value{GDBN} Command
07f31aa6 32343
a2c02241 32344The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
32345
32346@subsubheading Example
a2c02241 32347N.A.
07f31aa6
DJ
32348
32349
a2c02241
NR
32350@subheading The @code{-symbol-list-functions} Command
32351@findex -symbol-list-functions
922fbb7b
AC
32352
32353@subsubheading Synopsis
32354
32355@smallexample
a2c02241 32356 -symbol-list-functions
922fbb7b
AC
32357@end smallexample
32358
a2c02241 32359List the functions in the executable.
922fbb7b
AC
32360
32361@subsubheading @value{GDBN} Command
32362
a2c02241
NR
32363@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
32364@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
32365
32366@subsubheading Example
a2c02241 32367N.A.
9901a55b 32368@end ignore
922fbb7b
AC
32369
32370
a2c02241
NR
32371@subheading The @code{-symbol-list-lines} Command
32372@findex -symbol-list-lines
922fbb7b
AC
32373
32374@subsubheading Synopsis
32375
32376@smallexample
a2c02241 32377 -symbol-list-lines @var{filename}
922fbb7b
AC
32378@end smallexample
32379
a2c02241
NR
32380Print the list of lines that contain code and their associated program
32381addresses for the given source filename. The entries are sorted in
32382ascending PC order.
922fbb7b
AC
32383
32384@subsubheading @value{GDBN} Command
32385
a2c02241 32386There is no corresponding @value{GDBN} command.
922fbb7b
AC
32387
32388@subsubheading Example
a2c02241 32389@smallexample
594fe323 32390(gdb)
a2c02241
NR
32391-symbol-list-lines basics.c
32392^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 32393(gdb)
a2c02241 32394@end smallexample
922fbb7b
AC
32395
32396
9901a55b 32397@ignore
a2c02241
NR
32398@subheading The @code{-symbol-list-types} Command
32399@findex -symbol-list-types
922fbb7b
AC
32400
32401@subsubheading Synopsis
32402
32403@smallexample
a2c02241 32404 -symbol-list-types
922fbb7b
AC
32405@end smallexample
32406
a2c02241 32407List all the type names.
922fbb7b
AC
32408
32409@subsubheading @value{GDBN} Command
32410
a2c02241
NR
32411The corresponding commands are @samp{info types} in @value{GDBN},
32412@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
32413
32414@subsubheading Example
32415N.A.
32416
32417
a2c02241
NR
32418@subheading The @code{-symbol-list-variables} Command
32419@findex -symbol-list-variables
922fbb7b
AC
32420
32421@subsubheading Synopsis
32422
32423@smallexample
a2c02241 32424 -symbol-list-variables
922fbb7b
AC
32425@end smallexample
32426
a2c02241 32427List all the global and static variable names.
922fbb7b
AC
32428
32429@subsubheading @value{GDBN} Command
32430
a2c02241 32431@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
32432
32433@subsubheading Example
32434N.A.
32435
32436
a2c02241
NR
32437@subheading The @code{-symbol-locate} Command
32438@findex -symbol-locate
922fbb7b
AC
32439
32440@subsubheading Synopsis
32441
32442@smallexample
a2c02241 32443 -symbol-locate
922fbb7b
AC
32444@end smallexample
32445
922fbb7b
AC
32446@subsubheading @value{GDBN} Command
32447
a2c02241 32448@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
32449
32450@subsubheading Example
32451N.A.
32452
32453
a2c02241
NR
32454@subheading The @code{-symbol-type} Command
32455@findex -symbol-type
922fbb7b
AC
32456
32457@subsubheading Synopsis
32458
32459@smallexample
a2c02241 32460 -symbol-type @var{variable}
922fbb7b
AC
32461@end smallexample
32462
a2c02241 32463Show type of @var{variable}.
922fbb7b 32464
a2c02241 32465@subsubheading @value{GDBN} Command
922fbb7b 32466
a2c02241
NR
32467The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
32468@samp{gdb_obj_variable}.
32469
32470@subsubheading Example
32471N.A.
9901a55b 32472@end ignore
a2c02241
NR
32473
32474
32475@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32476@node GDB/MI File Commands
32477@section @sc{gdb/mi} File Commands
32478
32479This section describes the GDB/MI commands to specify executable file names
32480and to read in and obtain symbol table information.
32481
32482@subheading The @code{-file-exec-and-symbols} Command
32483@findex -file-exec-and-symbols
32484
32485@subsubheading Synopsis
922fbb7b
AC
32486
32487@smallexample
a2c02241 32488 -file-exec-and-symbols @var{file}
922fbb7b
AC
32489@end smallexample
32490
a2c02241
NR
32491Specify the executable file to be debugged. This file is the one from
32492which the symbol table is also read. If no file is specified, the
32493command clears the executable and symbol information. If breakpoints
32494are set when using this command with no arguments, @value{GDBN} will produce
32495error messages. Otherwise, no output is produced, except a completion
32496notification.
32497
922fbb7b
AC
32498@subsubheading @value{GDBN} Command
32499
a2c02241 32500The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
32501
32502@subsubheading Example
32503
32504@smallexample
594fe323 32505(gdb)
a2c02241
NR
32506-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
32507^done
594fe323 32508(gdb)
922fbb7b
AC
32509@end smallexample
32510
922fbb7b 32511
a2c02241
NR
32512@subheading The @code{-file-exec-file} Command
32513@findex -file-exec-file
922fbb7b
AC
32514
32515@subsubheading Synopsis
32516
32517@smallexample
a2c02241 32518 -file-exec-file @var{file}
922fbb7b
AC
32519@end smallexample
32520
a2c02241
NR
32521Specify the executable file to be debugged. Unlike
32522@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
32523from this file. If used without argument, @value{GDBN} clears the information
32524about the executable file. No output is produced, except a completion
32525notification.
922fbb7b 32526
a2c02241
NR
32527@subsubheading @value{GDBN} Command
32528
32529The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
32530
32531@subsubheading Example
a2c02241
NR
32532
32533@smallexample
594fe323 32534(gdb)
a2c02241
NR
32535-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
32536^done
594fe323 32537(gdb)
a2c02241 32538@end smallexample
922fbb7b
AC
32539
32540
9901a55b 32541@ignore
a2c02241
NR
32542@subheading The @code{-file-list-exec-sections} Command
32543@findex -file-list-exec-sections
922fbb7b
AC
32544
32545@subsubheading Synopsis
32546
32547@smallexample
a2c02241 32548 -file-list-exec-sections
922fbb7b
AC
32549@end smallexample
32550
a2c02241
NR
32551List the sections of the current executable file.
32552
922fbb7b
AC
32553@subsubheading @value{GDBN} Command
32554
a2c02241
NR
32555The @value{GDBN} command @samp{info file} shows, among the rest, the same
32556information as this command. @code{gdbtk} has a corresponding command
32557@samp{gdb_load_info}.
922fbb7b
AC
32558
32559@subsubheading Example
32560N.A.
9901a55b 32561@end ignore
922fbb7b
AC
32562
32563
a2c02241
NR
32564@subheading The @code{-file-list-exec-source-file} Command
32565@findex -file-list-exec-source-file
922fbb7b
AC
32566
32567@subsubheading Synopsis
32568
32569@smallexample
a2c02241 32570 -file-list-exec-source-file
922fbb7b
AC
32571@end smallexample
32572
a2c02241 32573List the line number, the current source file, and the absolute path
44288b44
NR
32574to the current source file for the current executable. The macro
32575information field has a value of @samp{1} or @samp{0} depending on
32576whether or not the file includes preprocessor macro information.
922fbb7b
AC
32577
32578@subsubheading @value{GDBN} Command
32579
a2c02241 32580The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
32581
32582@subsubheading Example
32583
922fbb7b 32584@smallexample
594fe323 32585(gdb)
a2c02241 32586123-file-list-exec-source-file
44288b44 32587123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
594fe323 32588(gdb)
922fbb7b
AC
32589@end smallexample
32590
32591
a2c02241
NR
32592@subheading The @code{-file-list-exec-source-files} Command
32593@findex -file-list-exec-source-files
922fbb7b
AC
32594
32595@subsubheading Synopsis
32596
32597@smallexample
a2c02241 32598 -file-list-exec-source-files
922fbb7b
AC
32599@end smallexample
32600
a2c02241
NR
32601List the source files for the current executable.
32602
f35a17b5
JK
32603It will always output both the filename and fullname (absolute file
32604name) of a source file.
922fbb7b
AC
32605
32606@subsubheading @value{GDBN} Command
32607
a2c02241
NR
32608The @value{GDBN} equivalent is @samp{info sources}.
32609@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
32610
32611@subsubheading Example
922fbb7b 32612@smallexample
594fe323 32613(gdb)
a2c02241
NR
32614-file-list-exec-source-files
32615^done,files=[
32616@{file=foo.c,fullname=/home/foo.c@},
32617@{file=/home/bar.c,fullname=/home/bar.c@},
32618@{file=gdb_could_not_find_fullpath.c@}]
594fe323 32619(gdb)
922fbb7b
AC
32620@end smallexample
32621
9901a55b 32622@ignore
a2c02241
NR
32623@subheading The @code{-file-list-shared-libraries} Command
32624@findex -file-list-shared-libraries
922fbb7b 32625
a2c02241 32626@subsubheading Synopsis
922fbb7b 32627
a2c02241
NR
32628@smallexample
32629 -file-list-shared-libraries
32630@end smallexample
922fbb7b 32631
a2c02241 32632List the shared libraries in the program.
922fbb7b 32633
a2c02241 32634@subsubheading @value{GDBN} Command
922fbb7b 32635
a2c02241 32636The corresponding @value{GDBN} command is @samp{info shared}.
922fbb7b 32637
a2c02241
NR
32638@subsubheading Example
32639N.A.
922fbb7b
AC
32640
32641
a2c02241
NR
32642@subheading The @code{-file-list-symbol-files} Command
32643@findex -file-list-symbol-files
922fbb7b 32644
a2c02241 32645@subsubheading Synopsis
922fbb7b 32646
a2c02241
NR
32647@smallexample
32648 -file-list-symbol-files
32649@end smallexample
922fbb7b 32650
a2c02241 32651List symbol files.
922fbb7b 32652
a2c02241 32653@subsubheading @value{GDBN} Command
922fbb7b 32654
a2c02241 32655The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 32656
a2c02241
NR
32657@subsubheading Example
32658N.A.
9901a55b 32659@end ignore
922fbb7b 32660
922fbb7b 32661
a2c02241
NR
32662@subheading The @code{-file-symbol-file} Command
32663@findex -file-symbol-file
922fbb7b 32664
a2c02241 32665@subsubheading Synopsis
922fbb7b 32666
a2c02241
NR
32667@smallexample
32668 -file-symbol-file @var{file}
32669@end smallexample
922fbb7b 32670
a2c02241
NR
32671Read symbol table info from the specified @var{file} argument. When
32672used without arguments, clears @value{GDBN}'s symbol table info. No output is
32673produced, except for a completion notification.
922fbb7b 32674
a2c02241 32675@subsubheading @value{GDBN} Command
922fbb7b 32676
a2c02241 32677The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 32678
a2c02241 32679@subsubheading Example
922fbb7b 32680
a2c02241 32681@smallexample
594fe323 32682(gdb)
a2c02241
NR
32683-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
32684^done
594fe323 32685(gdb)
a2c02241 32686@end smallexample
922fbb7b 32687
a2c02241 32688@ignore
a2c02241
NR
32689@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32690@node GDB/MI Memory Overlay Commands
32691@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 32692
a2c02241 32693The memory overlay commands are not implemented.
922fbb7b 32694
a2c02241 32695@c @subheading -overlay-auto
922fbb7b 32696
a2c02241 32697@c @subheading -overlay-list-mapping-state
922fbb7b 32698
a2c02241 32699@c @subheading -overlay-list-overlays
922fbb7b 32700
a2c02241 32701@c @subheading -overlay-map
922fbb7b 32702
a2c02241 32703@c @subheading -overlay-off
922fbb7b 32704
a2c02241 32705@c @subheading -overlay-on
922fbb7b 32706
a2c02241 32707@c @subheading -overlay-unmap
922fbb7b 32708
a2c02241
NR
32709@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32710@node GDB/MI Signal Handling Commands
32711@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 32712
a2c02241 32713Signal handling commands are not implemented.
922fbb7b 32714
a2c02241 32715@c @subheading -signal-handle
922fbb7b 32716
a2c02241 32717@c @subheading -signal-list-handle-actions
922fbb7b 32718
a2c02241
NR
32719@c @subheading -signal-list-signal-types
32720@end ignore
922fbb7b 32721
922fbb7b 32722
a2c02241
NR
32723@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32724@node GDB/MI Target Manipulation
32725@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
32726
32727
a2c02241
NR
32728@subheading The @code{-target-attach} Command
32729@findex -target-attach
922fbb7b
AC
32730
32731@subsubheading Synopsis
32732
32733@smallexample
c3b108f7 32734 -target-attach @var{pid} | @var{gid} | @var{file}
922fbb7b
AC
32735@end smallexample
32736
c3b108f7
VP
32737Attach to a process @var{pid} or a file @var{file} outside of
32738@value{GDBN}, or a thread group @var{gid}. If attaching to a thread
32739group, the id previously returned by
32740@samp{-list-thread-groups --available} must be used.
922fbb7b 32741
79a6e687 32742@subsubheading @value{GDBN} Command
922fbb7b 32743
a2c02241 32744The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 32745
a2c02241 32746@subsubheading Example
b56e7235
VP
32747@smallexample
32748(gdb)
32749-target-attach 34
32750=thread-created,id="1"
5ae4183a 32751*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
b56e7235
VP
32752^done
32753(gdb)
32754@end smallexample
a2c02241 32755
9901a55b 32756@ignore
a2c02241
NR
32757@subheading The @code{-target-compare-sections} Command
32758@findex -target-compare-sections
922fbb7b
AC
32759
32760@subsubheading Synopsis
32761
32762@smallexample
a2c02241 32763 -target-compare-sections [ @var{section} ]
922fbb7b
AC
32764@end smallexample
32765
a2c02241
NR
32766Compare data of section @var{section} on target to the exec file.
32767Without the argument, all sections are compared.
922fbb7b 32768
a2c02241 32769@subsubheading @value{GDBN} Command
922fbb7b 32770
a2c02241 32771The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 32772
a2c02241
NR
32773@subsubheading Example
32774N.A.
9901a55b 32775@end ignore
a2c02241
NR
32776
32777
32778@subheading The @code{-target-detach} Command
32779@findex -target-detach
922fbb7b
AC
32780
32781@subsubheading Synopsis
32782
32783@smallexample
c3b108f7 32784 -target-detach [ @var{pid} | @var{gid} ]
922fbb7b
AC
32785@end smallexample
32786
a2c02241 32787Detach from the remote target which normally resumes its execution.
c3b108f7
VP
32788If either @var{pid} or @var{gid} is specified, detaches from either
32789the specified process, or specified thread group. There's no output.
a2c02241 32790
79a6e687 32791@subsubheading @value{GDBN} Command
a2c02241
NR
32792
32793The corresponding @value{GDBN} command is @samp{detach}.
32794
32795@subsubheading Example
922fbb7b
AC
32796
32797@smallexample
594fe323 32798(gdb)
a2c02241
NR
32799-target-detach
32800^done
594fe323 32801(gdb)
922fbb7b
AC
32802@end smallexample
32803
32804
a2c02241
NR
32805@subheading The @code{-target-disconnect} Command
32806@findex -target-disconnect
922fbb7b
AC
32807
32808@subsubheading Synopsis
32809
123dc839 32810@smallexample
a2c02241 32811 -target-disconnect
123dc839 32812@end smallexample
922fbb7b 32813
a2c02241
NR
32814Disconnect from the remote target. There's no output and the target is
32815generally not resumed.
32816
79a6e687 32817@subsubheading @value{GDBN} Command
a2c02241
NR
32818
32819The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
32820
32821@subsubheading Example
922fbb7b
AC
32822
32823@smallexample
594fe323 32824(gdb)
a2c02241
NR
32825-target-disconnect
32826^done
594fe323 32827(gdb)
922fbb7b
AC
32828@end smallexample
32829
32830
a2c02241
NR
32831@subheading The @code{-target-download} Command
32832@findex -target-download
922fbb7b
AC
32833
32834@subsubheading Synopsis
32835
32836@smallexample
a2c02241 32837 -target-download
922fbb7b
AC
32838@end smallexample
32839
a2c02241
NR
32840Loads the executable onto the remote target.
32841It prints out an update message every half second, which includes the fields:
32842
32843@table @samp
32844@item section
32845The name of the section.
32846@item section-sent
32847The size of what has been sent so far for that section.
32848@item section-size
32849The size of the section.
32850@item total-sent
32851The total size of what was sent so far (the current and the previous sections).
32852@item total-size
32853The size of the overall executable to download.
32854@end table
32855
32856@noindent
32857Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
32858@sc{gdb/mi} Output Syntax}).
32859
32860In addition, it prints the name and size of the sections, as they are
32861downloaded. These messages include the following fields:
32862
32863@table @samp
32864@item section
32865The name of the section.
32866@item section-size
32867The size of the section.
32868@item total-size
32869The size of the overall executable to download.
32870@end table
32871
32872@noindent
32873At the end, a summary is printed.
32874
32875@subsubheading @value{GDBN} Command
32876
32877The corresponding @value{GDBN} command is @samp{load}.
32878
32879@subsubheading Example
32880
32881Note: each status message appears on a single line. Here the messages
32882have been broken down so that they can fit onto a page.
922fbb7b
AC
32883
32884@smallexample
594fe323 32885(gdb)
a2c02241
NR
32886-target-download
32887+download,@{section=".text",section-size="6668",total-size="9880"@}
32888+download,@{section=".text",section-sent="512",section-size="6668",
32889total-sent="512",total-size="9880"@}
32890+download,@{section=".text",section-sent="1024",section-size="6668",
32891total-sent="1024",total-size="9880"@}
32892+download,@{section=".text",section-sent="1536",section-size="6668",
32893total-sent="1536",total-size="9880"@}
32894+download,@{section=".text",section-sent="2048",section-size="6668",
32895total-sent="2048",total-size="9880"@}
32896+download,@{section=".text",section-sent="2560",section-size="6668",
32897total-sent="2560",total-size="9880"@}
32898+download,@{section=".text",section-sent="3072",section-size="6668",
32899total-sent="3072",total-size="9880"@}
32900+download,@{section=".text",section-sent="3584",section-size="6668",
32901total-sent="3584",total-size="9880"@}
32902+download,@{section=".text",section-sent="4096",section-size="6668",
32903total-sent="4096",total-size="9880"@}
32904+download,@{section=".text",section-sent="4608",section-size="6668",
32905total-sent="4608",total-size="9880"@}
32906+download,@{section=".text",section-sent="5120",section-size="6668",
32907total-sent="5120",total-size="9880"@}
32908+download,@{section=".text",section-sent="5632",section-size="6668",
32909total-sent="5632",total-size="9880"@}
32910+download,@{section=".text",section-sent="6144",section-size="6668",
32911total-sent="6144",total-size="9880"@}
32912+download,@{section=".text",section-sent="6656",section-size="6668",
32913total-sent="6656",total-size="9880"@}
32914+download,@{section=".init",section-size="28",total-size="9880"@}
32915+download,@{section=".fini",section-size="28",total-size="9880"@}
32916+download,@{section=".data",section-size="3156",total-size="9880"@}
32917+download,@{section=".data",section-sent="512",section-size="3156",
32918total-sent="7236",total-size="9880"@}
32919+download,@{section=".data",section-sent="1024",section-size="3156",
32920total-sent="7748",total-size="9880"@}
32921+download,@{section=".data",section-sent="1536",section-size="3156",
32922total-sent="8260",total-size="9880"@}
32923+download,@{section=".data",section-sent="2048",section-size="3156",
32924total-sent="8772",total-size="9880"@}
32925+download,@{section=".data",section-sent="2560",section-size="3156",
32926total-sent="9284",total-size="9880"@}
32927+download,@{section=".data",section-sent="3072",section-size="3156",
32928total-sent="9796",total-size="9880"@}
32929^done,address="0x10004",load-size="9880",transfer-rate="6586",
32930write-rate="429"
594fe323 32931(gdb)
922fbb7b
AC
32932@end smallexample
32933
32934
9901a55b 32935@ignore
a2c02241
NR
32936@subheading The @code{-target-exec-status} Command
32937@findex -target-exec-status
922fbb7b
AC
32938
32939@subsubheading Synopsis
32940
32941@smallexample
a2c02241 32942 -target-exec-status
922fbb7b
AC
32943@end smallexample
32944
a2c02241
NR
32945Provide information on the state of the target (whether it is running or
32946not, for instance).
922fbb7b 32947
a2c02241 32948@subsubheading @value{GDBN} Command
922fbb7b 32949
a2c02241
NR
32950There's no equivalent @value{GDBN} command.
32951
32952@subsubheading Example
32953N.A.
922fbb7b 32954
a2c02241
NR
32955
32956@subheading The @code{-target-list-available-targets} Command
32957@findex -target-list-available-targets
922fbb7b
AC
32958
32959@subsubheading Synopsis
32960
32961@smallexample
a2c02241 32962 -target-list-available-targets
922fbb7b
AC
32963@end smallexample
32964
a2c02241 32965List the possible targets to connect to.
922fbb7b 32966
a2c02241 32967@subsubheading @value{GDBN} Command
922fbb7b 32968
a2c02241 32969The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 32970
a2c02241
NR
32971@subsubheading Example
32972N.A.
32973
32974
32975@subheading The @code{-target-list-current-targets} Command
32976@findex -target-list-current-targets
922fbb7b
AC
32977
32978@subsubheading Synopsis
32979
32980@smallexample
a2c02241 32981 -target-list-current-targets
922fbb7b
AC
32982@end smallexample
32983
a2c02241 32984Describe the current target.
922fbb7b 32985
a2c02241 32986@subsubheading @value{GDBN} Command
922fbb7b 32987
a2c02241
NR
32988The corresponding information is printed by @samp{info file} (among
32989other things).
922fbb7b 32990
a2c02241
NR
32991@subsubheading Example
32992N.A.
32993
32994
32995@subheading The @code{-target-list-parameters} Command
32996@findex -target-list-parameters
922fbb7b
AC
32997
32998@subsubheading Synopsis
32999
33000@smallexample
a2c02241 33001 -target-list-parameters
922fbb7b
AC
33002@end smallexample
33003
a2c02241 33004@c ????
9901a55b 33005@end ignore
a2c02241
NR
33006
33007@subsubheading @value{GDBN} Command
33008
33009No equivalent.
922fbb7b
AC
33010
33011@subsubheading Example
a2c02241
NR
33012N.A.
33013
33014
33015@subheading The @code{-target-select} Command
33016@findex -target-select
33017
33018@subsubheading Synopsis
922fbb7b
AC
33019
33020@smallexample
a2c02241 33021 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
33022@end smallexample
33023
a2c02241 33024Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 33025
a2c02241
NR
33026@table @samp
33027@item @var{type}
75c99385 33028The type of target, for instance @samp{remote}, etc.
a2c02241
NR
33029@item @var{parameters}
33030Device names, host names and the like. @xref{Target Commands, ,
79a6e687 33031Commands for Managing Targets}, for more details.
a2c02241
NR
33032@end table
33033
33034The output is a connection notification, followed by the address at
33035which the target program is, in the following form:
922fbb7b
AC
33036
33037@smallexample
a2c02241
NR
33038^connected,addr="@var{address}",func="@var{function name}",
33039 args=[@var{arg list}]
922fbb7b
AC
33040@end smallexample
33041
a2c02241
NR
33042@subsubheading @value{GDBN} Command
33043
33044The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
33045
33046@subsubheading Example
922fbb7b 33047
265eeb58 33048@smallexample
594fe323 33049(gdb)
75c99385 33050-target-select remote /dev/ttya
a2c02241 33051^connected,addr="0xfe00a300",func="??",args=[]
594fe323 33052(gdb)
265eeb58 33053@end smallexample
ef21caaf 33054
a6b151f1
DJ
33055@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33056@node GDB/MI File Transfer Commands
33057@section @sc{gdb/mi} File Transfer Commands
33058
33059
33060@subheading The @code{-target-file-put} Command
33061@findex -target-file-put
33062
33063@subsubheading Synopsis
33064
33065@smallexample
33066 -target-file-put @var{hostfile} @var{targetfile}
33067@end smallexample
33068
33069Copy file @var{hostfile} from the host system (the machine running
33070@value{GDBN}) to @var{targetfile} on the target system.
33071
33072@subsubheading @value{GDBN} Command
33073
33074The corresponding @value{GDBN} command is @samp{remote put}.
33075
33076@subsubheading Example
33077
33078@smallexample
33079(gdb)
33080-target-file-put localfile remotefile
33081^done
33082(gdb)
33083@end smallexample
33084
33085
1763a388 33086@subheading The @code{-target-file-get} Command
a6b151f1
DJ
33087@findex -target-file-get
33088
33089@subsubheading Synopsis
33090
33091@smallexample
33092 -target-file-get @var{targetfile} @var{hostfile}
33093@end smallexample
33094
33095Copy file @var{targetfile} from the target system to @var{hostfile}
33096on the host system.
33097
33098@subsubheading @value{GDBN} Command
33099
33100The corresponding @value{GDBN} command is @samp{remote get}.
33101
33102@subsubheading Example
33103
33104@smallexample
33105(gdb)
33106-target-file-get remotefile localfile
33107^done
33108(gdb)
33109@end smallexample
33110
33111
33112@subheading The @code{-target-file-delete} Command
33113@findex -target-file-delete
33114
33115@subsubheading Synopsis
33116
33117@smallexample
33118 -target-file-delete @var{targetfile}
33119@end smallexample
33120
33121Delete @var{targetfile} from the target system.
33122
33123@subsubheading @value{GDBN} Command
33124
33125The corresponding @value{GDBN} command is @samp{remote delete}.
33126
33127@subsubheading Example
33128
33129@smallexample
33130(gdb)
33131-target-file-delete remotefile
33132^done
33133(gdb)
33134@end smallexample
33135
33136
ef21caaf
NR
33137@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33138@node GDB/MI Miscellaneous Commands
33139@section Miscellaneous @sc{gdb/mi} Commands
33140
33141@c @subheading -gdb-complete
33142
33143@subheading The @code{-gdb-exit} Command
33144@findex -gdb-exit
33145
33146@subsubheading Synopsis
33147
33148@smallexample
33149 -gdb-exit
33150@end smallexample
33151
33152Exit @value{GDBN} immediately.
33153
33154@subsubheading @value{GDBN} Command
33155
33156Approximately corresponds to @samp{quit}.
33157
33158@subsubheading Example
33159
33160@smallexample
594fe323 33161(gdb)
ef21caaf
NR
33162-gdb-exit
33163^exit
33164@end smallexample
33165
a2c02241 33166
9901a55b 33167@ignore
a2c02241
NR
33168@subheading The @code{-exec-abort} Command
33169@findex -exec-abort
33170
33171@subsubheading Synopsis
33172
33173@smallexample
33174 -exec-abort
33175@end smallexample
33176
33177Kill the inferior running program.
33178
33179@subsubheading @value{GDBN} Command
33180
33181The corresponding @value{GDBN} command is @samp{kill}.
33182
33183@subsubheading Example
33184N.A.
9901a55b 33185@end ignore
a2c02241
NR
33186
33187
ef21caaf
NR
33188@subheading The @code{-gdb-set} Command
33189@findex -gdb-set
33190
33191@subsubheading Synopsis
33192
33193@smallexample
33194 -gdb-set
33195@end smallexample
33196
33197Set an internal @value{GDBN} variable.
33198@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
33199
33200@subsubheading @value{GDBN} Command
33201
33202The corresponding @value{GDBN} command is @samp{set}.
33203
33204@subsubheading Example
33205
33206@smallexample
594fe323 33207(gdb)
ef21caaf
NR
33208-gdb-set $foo=3
33209^done
594fe323 33210(gdb)
ef21caaf
NR
33211@end smallexample
33212
33213
33214@subheading The @code{-gdb-show} Command
33215@findex -gdb-show
33216
33217@subsubheading Synopsis
33218
33219@smallexample
33220 -gdb-show
33221@end smallexample
33222
33223Show the current value of a @value{GDBN} variable.
33224
79a6e687 33225@subsubheading @value{GDBN} Command
ef21caaf
NR
33226
33227The corresponding @value{GDBN} command is @samp{show}.
33228
33229@subsubheading Example
33230
33231@smallexample
594fe323 33232(gdb)
ef21caaf
NR
33233-gdb-show annotate
33234^done,value="0"
594fe323 33235(gdb)
ef21caaf
NR
33236@end smallexample
33237
33238@c @subheading -gdb-source
33239
33240
33241@subheading The @code{-gdb-version} Command
33242@findex -gdb-version
33243
33244@subsubheading Synopsis
33245
33246@smallexample
33247 -gdb-version
33248@end smallexample
33249
33250Show version information for @value{GDBN}. Used mostly in testing.
33251
33252@subsubheading @value{GDBN} Command
33253
33254The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
33255default shows this information when you start an interactive session.
33256
33257@subsubheading Example
33258
33259@c This example modifies the actual output from GDB to avoid overfull
33260@c box in TeX.
33261@smallexample
594fe323 33262(gdb)
ef21caaf
NR
33263-gdb-version
33264~GNU gdb 5.2.1
33265~Copyright 2000 Free Software Foundation, Inc.
33266~GDB is free software, covered by the GNU General Public License, and
33267~you are welcome to change it and/or distribute copies of it under
33268~ certain conditions.
33269~Type "show copying" to see the conditions.
33270~There is absolutely no warranty for GDB. Type "show warranty" for
33271~ details.
33272~This GDB was configured as
33273 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
33274^done
594fe323 33275(gdb)
ef21caaf
NR
33276@end smallexample
33277
084344da
VP
33278@subheading The @code{-list-features} Command
33279@findex -list-features
33280
33281Returns a list of particular features of the MI protocol that
33282this version of gdb implements. A feature can be a command,
33283or a new field in an output of some command, or even an
33284important bugfix. While a frontend can sometimes detect presence
33285of a feature at runtime, it is easier to perform detection at debugger
33286startup.
33287
33288The command returns a list of strings, with each string naming an
33289available feature. Each returned string is just a name, it does not
33290have any internal structure. The list of possible feature names
33291is given below.
33292
33293Example output:
33294
33295@smallexample
33296(gdb) -list-features
33297^done,result=["feature1","feature2"]
33298@end smallexample
33299
33300The current list of features is:
33301
30e026bb
VP
33302@table @samp
33303@item frozen-varobjs
a05336a1
JB
33304Indicates support for the @code{-var-set-frozen} command, as well
33305as possible presense of the @code{frozen} field in the output
30e026bb
VP
33306of @code{-varobj-create}.
33307@item pending-breakpoints
a05336a1
JB
33308Indicates support for the @option{-f} option to the @code{-break-insert}
33309command.
b6313243 33310@item python
a05336a1 33311Indicates Python scripting support, Python-based
b6313243
TT
33312pretty-printing commands, and possible presence of the
33313@samp{display_hint} field in the output of @code{-var-list-children}
30e026bb 33314@item thread-info
a05336a1 33315Indicates support for the @code{-thread-info} command.
8dedea02 33316@item data-read-memory-bytes
a05336a1 33317Indicates support for the @code{-data-read-memory-bytes} and the
8dedea02 33318@code{-data-write-memory-bytes} commands.
39c4d40a
TT
33319@item breakpoint-notifications
33320Indicates that changes to breakpoints and breakpoints created via the
33321CLI will be announced via async records.
5d77fe44
JB
33322@item ada-task-info
33323Indicates support for the @code{-ada-task-info} command.
30e026bb 33324@end table
084344da 33325
c6ebd6cf
VP
33326@subheading The @code{-list-target-features} Command
33327@findex -list-target-features
33328
33329Returns a list of particular features that are supported by the
33330target. Those features affect the permitted MI commands, but
33331unlike the features reported by the @code{-list-features} command, the
33332features depend on which target GDB is using at the moment. Whenever
33333a target can change, due to commands such as @code{-target-select},
33334@code{-target-attach} or @code{-exec-run}, the list of target features
33335may change, and the frontend should obtain it again.
33336Example output:
33337
33338@smallexample
33339(gdb) -list-features
33340^done,result=["async"]
33341@end smallexample
33342
33343The current list of features is:
33344
33345@table @samp
33346@item async
33347Indicates that the target is capable of asynchronous command
33348execution, which means that @value{GDBN} will accept further commands
33349while the target is running.
33350
f75d858b
MK
33351@item reverse
33352Indicates that the target is capable of reverse execution.
33353@xref{Reverse Execution}, for more information.
33354
c6ebd6cf
VP
33355@end table
33356
c3b108f7
VP
33357@subheading The @code{-list-thread-groups} Command
33358@findex -list-thread-groups
33359
33360@subheading Synopsis
33361
33362@smallexample
dc146f7c 33363-list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
c3b108f7
VP
33364@end smallexample
33365
dc146f7c
VP
33366Lists thread groups (@pxref{Thread groups}). When a single thread
33367group is passed as the argument, lists the children of that group.
33368When several thread group are passed, lists information about those
33369thread groups. Without any parameters, lists information about all
33370top-level thread groups.
33371
33372Normally, thread groups that are being debugged are reported.
33373With the @samp{--available} option, @value{GDBN} reports thread groups
33374available on the target.
33375
33376The output of this command may have either a @samp{threads} result or
33377a @samp{groups} result. The @samp{thread} result has a list of tuples
33378as value, with each tuple describing a thread (@pxref{GDB/MI Thread
33379Information}). The @samp{groups} result has a list of tuples as value,
33380each tuple describing a thread group. If top-level groups are
33381requested (that is, no parameter is passed), or when several groups
33382are passed, the output always has a @samp{groups} result. The format
33383of the @samp{group} result is described below.
33384
33385To reduce the number of roundtrips it's possible to list thread groups
33386together with their children, by passing the @samp{--recurse} option
33387and the recursion depth. Presently, only recursion depth of 1 is
33388permitted. If this option is present, then every reported thread group
33389will also include its children, either as @samp{group} or
33390@samp{threads} field.
33391
33392In general, any combination of option and parameters is permitted, with
33393the following caveats:
33394
33395@itemize @bullet
33396@item
33397When a single thread group is passed, the output will typically
33398be the @samp{threads} result. Because threads may not contain
33399anything, the @samp{recurse} option will be ignored.
33400
33401@item
33402When the @samp{--available} option is passed, limited information may
33403be available. In particular, the list of threads of a process might
33404be inaccessible. Further, specifying specific thread groups might
33405not give any performance advantage over listing all thread groups.
33406The frontend should assume that @samp{-list-thread-groups --available}
33407is always an expensive operation and cache the results.
33408
33409@end itemize
33410
33411The @samp{groups} result is a list of tuples, where each tuple may
33412have the following fields:
33413
33414@table @code
33415@item id
33416Identifier of the thread group. This field is always present.
a79b8f6e
VP
33417The identifier is an opaque string; frontends should not try to
33418convert it to an integer, even though it might look like one.
dc146f7c
VP
33419
33420@item type
33421The type of the thread group. At present, only @samp{process} is a
33422valid type.
33423
33424@item pid
33425The target-specific process identifier. This field is only present
a79b8f6e 33426for thread groups of type @samp{process} and only if the process exists.
c3b108f7 33427
dc146f7c
VP
33428@item num_children
33429The number of children this thread group has. This field may be
33430absent for an available thread group.
33431
33432@item threads
33433This field has a list of tuples as value, each tuple describing a
33434thread. It may be present if the @samp{--recurse} option is
33435specified, and it's actually possible to obtain the threads.
33436
33437@item cores
33438This field is a list of integers, each identifying a core that one
33439thread of the group is running on. This field may be absent if
33440such information is not available.
33441
a79b8f6e
VP
33442@item executable
33443The name of the executable file that corresponds to this thread group.
33444The field is only present for thread groups of type @samp{process},
33445and only if there is a corresponding executable file.
33446
dc146f7c 33447@end table
c3b108f7
VP
33448
33449@subheading Example
33450
33451@smallexample
33452@value{GDBP}
33453-list-thread-groups
33454^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
33455-list-thread-groups 17
33456^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
33457 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
33458@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
33459 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
33460 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}]]
dc146f7c
VP
33461-list-thread-groups --available
33462^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
33463-list-thread-groups --available --recurse 1
33464 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
33465 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
33466 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
33467-list-thread-groups --available --recurse 1 17 18
33468^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
33469 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
33470 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
c3b108f7 33471@end smallexample
c6ebd6cf 33472
f3e0e960
SS
33473@subheading The @code{-info-os} Command
33474@findex -info-os
33475
33476@subsubheading Synopsis
33477
33478@smallexample
33479-info-os [ @var{type} ]
33480@end smallexample
33481
33482If no argument is supplied, the command returns a table of available
33483operating-system-specific information types. If one of these types is
33484supplied as an argument @var{type}, then the command returns a table
33485of data of that type.
33486
33487The types of information available depend on the target operating
33488system.
33489
33490@subsubheading @value{GDBN} Command
33491
33492The corresponding @value{GDBN} command is @samp{info os}.
33493
33494@subsubheading Example
33495
33496When run on a @sc{gnu}/Linux system, the output will look something
33497like this:
33498
33499@smallexample
33500@value{GDBP}
33501-info-os
71caed83 33502^done,OSDataTable=@{nr_rows="9",nr_cols="3",
f3e0e960 33503hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
71caed83
SS
33504 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
33505 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
33506body=[item=@{col0="processes",col1="Listing of all processes",
33507 col2="Processes"@},
33508 item=@{col0="procgroups",col1="Listing of all process groups",
33509 col2="Process groups"@},
33510 item=@{col0="threads",col1="Listing of all threads",
33511 col2="Threads"@},
33512 item=@{col0="files",col1="Listing of all file descriptors",
33513 col2="File descriptors"@},
33514 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
33515 col2="Sockets"@},
33516 item=@{col0="shm",col1="Listing of all shared-memory regions",
33517 col2="Shared-memory regions"@},
33518 item=@{col0="semaphores",col1="Listing of all semaphores",
33519 col2="Semaphores"@},
33520 item=@{col0="msg",col1="Listing of all message queues",
33521 col2="Message queues"@},
33522 item=@{col0="modules",col1="Listing of all loaded kernel modules",
33523 col2="Kernel modules"@}]@}
f3e0e960
SS
33524@value{GDBP}
33525-info-os processes
33526^done,OSDataTable=@{nr_rows="190",nr_cols="4",
33527hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
33528 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
33529 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
33530 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
33531body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
33532 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
33533 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
33534 ...
33535 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
33536 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
33537(gdb)
33538@end smallexample
a79b8f6e 33539
71caed83
SS
33540(Note that the MI output here includes a @code{"Title"} column that
33541does not appear in command-line @code{info os}; this column is useful
33542for MI clients that want to enumerate the types of data, such as in a
33543popup menu, but is needless clutter on the command line, and
33544@code{info os} omits it.)
33545
a79b8f6e
VP
33546@subheading The @code{-add-inferior} Command
33547@findex -add-inferior
33548
33549@subheading Synopsis
33550
33551@smallexample
33552-add-inferior
33553@end smallexample
33554
33555Creates a new inferior (@pxref{Inferiors and Programs}). The created
33556inferior is not associated with any executable. Such association may
33557be established with the @samp{-file-exec-and-symbols} command
33558(@pxref{GDB/MI File Commands}). The command response has a single
33559field, @samp{thread-group}, whose value is the identifier of the
33560thread group corresponding to the new inferior.
33561
33562@subheading Example
33563
33564@smallexample
33565@value{GDBP}
33566-add-inferior
33567^done,thread-group="i3"
33568@end smallexample
33569
ef21caaf
NR
33570@subheading The @code{-interpreter-exec} Command
33571@findex -interpreter-exec
33572
33573@subheading Synopsis
33574
33575@smallexample
33576-interpreter-exec @var{interpreter} @var{command}
33577@end smallexample
a2c02241 33578@anchor{-interpreter-exec}
ef21caaf
NR
33579
33580Execute the specified @var{command} in the given @var{interpreter}.
33581
33582@subheading @value{GDBN} Command
33583
33584The corresponding @value{GDBN} command is @samp{interpreter-exec}.
33585
33586@subheading Example
33587
33588@smallexample
594fe323 33589(gdb)
ef21caaf
NR
33590-interpreter-exec console "break main"
33591&"During symbol reading, couldn't parse type; debugger out of date?.\n"
33592&"During symbol reading, bad structure-type format.\n"
33593~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
33594^done
594fe323 33595(gdb)
ef21caaf
NR
33596@end smallexample
33597
33598@subheading The @code{-inferior-tty-set} Command
33599@findex -inferior-tty-set
33600
33601@subheading Synopsis
33602
33603@smallexample
33604-inferior-tty-set /dev/pts/1
33605@end smallexample
33606
33607Set terminal for future runs of the program being debugged.
33608
33609@subheading @value{GDBN} Command
33610
33611The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
33612
33613@subheading Example
33614
33615@smallexample
594fe323 33616(gdb)
ef21caaf
NR
33617-inferior-tty-set /dev/pts/1
33618^done
594fe323 33619(gdb)
ef21caaf
NR
33620@end smallexample
33621
33622@subheading The @code{-inferior-tty-show} Command
33623@findex -inferior-tty-show
33624
33625@subheading Synopsis
33626
33627@smallexample
33628-inferior-tty-show
33629@end smallexample
33630
33631Show terminal for future runs of program being debugged.
33632
33633@subheading @value{GDBN} Command
33634
33635The corresponding @value{GDBN} command is @samp{show inferior-tty}.
33636
33637@subheading Example
33638
33639@smallexample
594fe323 33640(gdb)
ef21caaf
NR
33641-inferior-tty-set /dev/pts/1
33642^done
594fe323 33643(gdb)
ef21caaf
NR
33644-inferior-tty-show
33645^done,inferior_tty_terminal="/dev/pts/1"
594fe323 33646(gdb)
ef21caaf 33647@end smallexample
922fbb7b 33648
a4eefcd8
NR
33649@subheading The @code{-enable-timings} Command
33650@findex -enable-timings
33651
33652@subheading Synopsis
33653
33654@smallexample
33655-enable-timings [yes | no]
33656@end smallexample
33657
33658Toggle the printing of the wallclock, user and system times for an MI
33659command as a field in its output. This command is to help frontend
33660developers optimize the performance of their code. No argument is
33661equivalent to @samp{yes}.
33662
33663@subheading @value{GDBN} Command
33664
33665No equivalent.
33666
33667@subheading Example
33668
33669@smallexample
33670(gdb)
33671-enable-timings
33672^done
33673(gdb)
33674-break-insert main
33675^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
33676addr="0x080484ed",func="main",file="myprog.c",
998580f1
MK
33677fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
33678times="0"@},
a4eefcd8
NR
33679time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
33680(gdb)
33681-enable-timings no
33682^done
33683(gdb)
33684-exec-run
33685^running
33686(gdb)
a47ec5fe 33687*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
a4eefcd8
NR
33688frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
33689@{name="argv",value="0xbfb60364"@}],file="myprog.c",
33690fullname="/home/nickrob/myprog.c",line="73"@}
33691(gdb)
33692@end smallexample
33693
922fbb7b
AC
33694@node Annotations
33695@chapter @value{GDBN} Annotations
33696
086432e2
AC
33697This chapter describes annotations in @value{GDBN}. Annotations were
33698designed to interface @value{GDBN} to graphical user interfaces or other
33699similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
33700relatively high level.
33701
d3e8051b 33702The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
33703(@pxref{GDB/MI}).
33704
922fbb7b
AC
33705@ignore
33706This is Edition @value{EDITION}, @value{DATE}.
33707@end ignore
33708
33709@menu
33710* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 33711* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
33712* Prompting:: Annotations marking @value{GDBN}'s need for input.
33713* Errors:: Annotations for error messages.
922fbb7b
AC
33714* Invalidation:: Some annotations describe things now invalid.
33715* Annotations for Running::
33716 Whether the program is running, how it stopped, etc.
33717* Source Annotations:: Annotations describing source code.
922fbb7b
AC
33718@end menu
33719
33720@node Annotations Overview
33721@section What is an Annotation?
33722@cindex annotations
33723
922fbb7b
AC
33724Annotations start with a newline character, two @samp{control-z}
33725characters, and the name of the annotation. If there is no additional
33726information associated with this annotation, the name of the annotation
33727is followed immediately by a newline. If there is additional
33728information, the name of the annotation is followed by a space, the
33729additional information, and a newline. The additional information
33730cannot contain newline characters.
33731
33732Any output not beginning with a newline and two @samp{control-z}
33733characters denotes literal output from @value{GDBN}. Currently there is
33734no need for @value{GDBN} to output a newline followed by two
33735@samp{control-z} characters, but if there was such a need, the
33736annotations could be extended with an @samp{escape} annotation which
33737means those three characters as output.
33738
086432e2
AC
33739The annotation @var{level}, which is specified using the
33740@option{--annotate} command line option (@pxref{Mode Options}), controls
33741how much information @value{GDBN} prints together with its prompt,
33742values of expressions, source lines, and other types of output. Level 0
d3e8051b 33743is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
33744subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
33745for programs that control @value{GDBN}, and level 2 annotations have
33746been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
33747Interface, annotate, GDB's Obsolete Annotations}).
33748
33749@table @code
33750@kindex set annotate
33751@item set annotate @var{level}
e09f16f9 33752The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 33753annotations to the specified @var{level}.
9c16f35a
EZ
33754
33755@item show annotate
33756@kindex show annotate
33757Show the current annotation level.
09d4efe1
EZ
33758@end table
33759
33760This chapter describes level 3 annotations.
086432e2 33761
922fbb7b
AC
33762A simple example of starting up @value{GDBN} with annotations is:
33763
33764@smallexample
086432e2
AC
33765$ @kbd{gdb --annotate=3}
33766GNU gdb 6.0
33767Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
33768GDB is free software, covered by the GNU General Public License,
33769and you are welcome to change it and/or distribute copies of it
33770under certain conditions.
33771Type "show copying" to see the conditions.
33772There is absolutely no warranty for GDB. Type "show warranty"
33773for details.
086432e2 33774This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
33775
33776^Z^Zpre-prompt
f7dc1244 33777(@value{GDBP})
922fbb7b 33778^Z^Zprompt
086432e2 33779@kbd{quit}
922fbb7b
AC
33780
33781^Z^Zpost-prompt
b383017d 33782$
922fbb7b
AC
33783@end smallexample
33784
33785Here @samp{quit} is input to @value{GDBN}; the rest is output from
33786@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
33787denotes a @samp{control-z} character) are annotations; the rest is
33788output from @value{GDBN}.
33789
9e6c4bd5
NR
33790@node Server Prefix
33791@section The Server Prefix
33792@cindex server prefix
33793
33794If you prefix a command with @samp{server } then it will not affect
33795the command history, nor will it affect @value{GDBN}'s notion of which
33796command to repeat if @key{RET} is pressed on a line by itself. This
33797means that commands can be run behind a user's back by a front-end in
33798a transparent manner.
33799
d837706a
NR
33800The @code{server } prefix does not affect the recording of values into
33801the value history; to print a value without recording it into the
33802value history, use the @code{output} command instead of the
33803@code{print} command.
33804
33805Using this prefix also disables confirmation requests
33806(@pxref{confirmation requests}).
9e6c4bd5 33807
922fbb7b
AC
33808@node Prompting
33809@section Annotation for @value{GDBN} Input
33810
33811@cindex annotations for prompts
33812When @value{GDBN} prompts for input, it annotates this fact so it is possible
33813to know when to send output, when the output from a given command is
33814over, etc.
33815
33816Different kinds of input each have a different @dfn{input type}. Each
33817input type has three annotations: a @code{pre-} annotation, which
33818denotes the beginning of any prompt which is being output, a plain
33819annotation, which denotes the end of the prompt, and then a @code{post-}
33820annotation which denotes the end of any echo which may (or may not) be
33821associated with the input. For example, the @code{prompt} input type
33822features the following annotations:
33823
33824@smallexample
33825^Z^Zpre-prompt
33826^Z^Zprompt
33827^Z^Zpost-prompt
33828@end smallexample
33829
33830The input types are
33831
33832@table @code
e5ac9b53
EZ
33833@findex pre-prompt annotation
33834@findex prompt annotation
33835@findex post-prompt annotation
922fbb7b
AC
33836@item prompt
33837When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
33838
e5ac9b53
EZ
33839@findex pre-commands annotation
33840@findex commands annotation
33841@findex post-commands annotation
922fbb7b
AC
33842@item commands
33843When @value{GDBN} prompts for a set of commands, like in the @code{commands}
33844command. The annotations are repeated for each command which is input.
33845
e5ac9b53
EZ
33846@findex pre-overload-choice annotation
33847@findex overload-choice annotation
33848@findex post-overload-choice annotation
922fbb7b
AC
33849@item overload-choice
33850When @value{GDBN} wants the user to select between various overloaded functions.
33851
e5ac9b53
EZ
33852@findex pre-query annotation
33853@findex query annotation
33854@findex post-query annotation
922fbb7b
AC
33855@item query
33856When @value{GDBN} wants the user to confirm a potentially dangerous operation.
33857
e5ac9b53
EZ
33858@findex pre-prompt-for-continue annotation
33859@findex prompt-for-continue annotation
33860@findex post-prompt-for-continue annotation
922fbb7b
AC
33861@item prompt-for-continue
33862When @value{GDBN} is asking the user to press return to continue. Note: Don't
33863expect this to work well; instead use @code{set height 0} to disable
33864prompting. This is because the counting of lines is buggy in the
33865presence of annotations.
33866@end table
33867
33868@node Errors
33869@section Errors
33870@cindex annotations for errors, warnings and interrupts
33871
e5ac9b53 33872@findex quit annotation
922fbb7b
AC
33873@smallexample
33874^Z^Zquit
33875@end smallexample
33876
33877This annotation occurs right before @value{GDBN} responds to an interrupt.
33878
e5ac9b53 33879@findex error annotation
922fbb7b
AC
33880@smallexample
33881^Z^Zerror
33882@end smallexample
33883
33884This annotation occurs right before @value{GDBN} responds to an error.
33885
33886Quit and error annotations indicate that any annotations which @value{GDBN} was
33887in the middle of may end abruptly. For example, if a
33888@code{value-history-begin} annotation is followed by a @code{error}, one
33889cannot expect to receive the matching @code{value-history-end}. One
33890cannot expect not to receive it either, however; an error annotation
33891does not necessarily mean that @value{GDBN} is immediately returning all the way
33892to the top level.
33893
e5ac9b53 33894@findex error-begin annotation
922fbb7b
AC
33895A quit or error annotation may be preceded by
33896
33897@smallexample
33898^Z^Zerror-begin
33899@end smallexample
33900
33901Any output between that and the quit or error annotation is the error
33902message.
33903
33904Warning messages are not yet annotated.
33905@c If we want to change that, need to fix warning(), type_error(),
33906@c range_error(), and possibly other places.
33907
922fbb7b
AC
33908@node Invalidation
33909@section Invalidation Notices
33910
33911@cindex annotations for invalidation messages
33912The following annotations say that certain pieces of state may have
33913changed.
33914
33915@table @code
e5ac9b53 33916@findex frames-invalid annotation
922fbb7b
AC
33917@item ^Z^Zframes-invalid
33918
33919The frames (for example, output from the @code{backtrace} command) may
33920have changed.
33921
e5ac9b53 33922@findex breakpoints-invalid annotation
922fbb7b
AC
33923@item ^Z^Zbreakpoints-invalid
33924
33925The breakpoints may have changed. For example, the user just added or
33926deleted a breakpoint.
33927@end table
33928
33929@node Annotations for Running
33930@section Running the Program
33931@cindex annotations for running programs
33932
e5ac9b53
EZ
33933@findex starting annotation
33934@findex stopping annotation
922fbb7b 33935When the program starts executing due to a @value{GDBN} command such as
b383017d 33936@code{step} or @code{continue},
922fbb7b
AC
33937
33938@smallexample
33939^Z^Zstarting
33940@end smallexample
33941
b383017d 33942is output. When the program stops,
922fbb7b
AC
33943
33944@smallexample
33945^Z^Zstopped
33946@end smallexample
33947
33948is output. Before the @code{stopped} annotation, a variety of
33949annotations describe how the program stopped.
33950
33951@table @code
e5ac9b53 33952@findex exited annotation
922fbb7b
AC
33953@item ^Z^Zexited @var{exit-status}
33954The program exited, and @var{exit-status} is the exit status (zero for
33955successful exit, otherwise nonzero).
33956
e5ac9b53
EZ
33957@findex signalled annotation
33958@findex signal-name annotation
33959@findex signal-name-end annotation
33960@findex signal-string annotation
33961@findex signal-string-end annotation
922fbb7b
AC
33962@item ^Z^Zsignalled
33963The program exited with a signal. After the @code{^Z^Zsignalled}, the
33964annotation continues:
33965
33966@smallexample
33967@var{intro-text}
33968^Z^Zsignal-name
33969@var{name}
33970^Z^Zsignal-name-end
33971@var{middle-text}
33972^Z^Zsignal-string
33973@var{string}
33974^Z^Zsignal-string-end
33975@var{end-text}
33976@end smallexample
33977
33978@noindent
33979where @var{name} is the name of the signal, such as @code{SIGILL} or
33980@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
33981as @code{Illegal Instruction} or @code{Segmentation fault}.
33982@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
33983user's benefit and have no particular format.
33984
e5ac9b53 33985@findex signal annotation
922fbb7b
AC
33986@item ^Z^Zsignal
33987The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
33988just saying that the program received the signal, not that it was
33989terminated with it.
33990
e5ac9b53 33991@findex breakpoint annotation
922fbb7b
AC
33992@item ^Z^Zbreakpoint @var{number}
33993The program hit breakpoint number @var{number}.
33994
e5ac9b53 33995@findex watchpoint annotation
922fbb7b
AC
33996@item ^Z^Zwatchpoint @var{number}
33997The program hit watchpoint number @var{number}.
33998@end table
33999
34000@node Source Annotations
34001@section Displaying Source
34002@cindex annotations for source display
34003
e5ac9b53 34004@findex source annotation
922fbb7b
AC
34005The following annotation is used instead of displaying source code:
34006
34007@smallexample
34008^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
34009@end smallexample
34010
34011where @var{filename} is an absolute file name indicating which source
34012file, @var{line} is the line number within that file (where 1 is the
34013first line in the file), @var{character} is the character position
34014within the file (where 0 is the first character in the file) (for most
34015debug formats this will necessarily point to the beginning of a line),
34016@var{middle} is @samp{middle} if @var{addr} is in the middle of the
34017line, or @samp{beg} if @var{addr} is at the beginning of the line, and
34018@var{addr} is the address in the target program associated with the
34019source which is being displayed. @var{addr} is in the form @samp{0x}
34020followed by one or more lowercase hex digits (note that this does not
34021depend on the language).
34022
4efc6507
DE
34023@node JIT Interface
34024@chapter JIT Compilation Interface
34025@cindex just-in-time compilation
34026@cindex JIT compilation interface
34027
34028This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
34029interface. A JIT compiler is a program or library that generates native
34030executable code at runtime and executes it, usually in order to achieve good
34031performance while maintaining platform independence.
34032
34033Programs that use JIT compilation are normally difficult to debug because
34034portions of their code are generated at runtime, instead of being loaded from
34035object files, which is where @value{GDBN} normally finds the program's symbols
34036and debug information. In order to debug programs that use JIT compilation,
34037@value{GDBN} has an interface that allows the program to register in-memory
34038symbol files with @value{GDBN} at runtime.
34039
34040If you are using @value{GDBN} to debug a program that uses this interface, then
34041it should work transparently so long as you have not stripped the binary. If
34042you are developing a JIT compiler, then the interface is documented in the rest
34043of this chapter. At this time, the only known client of this interface is the
34044LLVM JIT.
34045
34046Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
34047JIT compiler communicates with @value{GDBN} by writing data into a global
34048variable and calling a fuction at a well-known symbol. When @value{GDBN}
34049attaches, it reads a linked list of symbol files from the global variable to
34050find existing code, and puts a breakpoint in the function so that it can find
34051out about additional code.
34052
34053@menu
34054* Declarations:: Relevant C struct declarations
34055* Registering Code:: Steps to register code
34056* Unregistering Code:: Steps to unregister code
f85b53f8 34057* Custom Debug Info:: Emit debug information in a custom format
4efc6507
DE
34058@end menu
34059
34060@node Declarations
34061@section JIT Declarations
34062
34063These are the relevant struct declarations that a C program should include to
34064implement the interface:
34065
34066@smallexample
34067typedef enum
34068@{
34069 JIT_NOACTION = 0,
34070 JIT_REGISTER_FN,
34071 JIT_UNREGISTER_FN
34072@} jit_actions_t;
34073
34074struct jit_code_entry
34075@{
34076 struct jit_code_entry *next_entry;
34077 struct jit_code_entry *prev_entry;
34078 const char *symfile_addr;
34079 uint64_t symfile_size;
34080@};
34081
34082struct jit_descriptor
34083@{
34084 uint32_t version;
34085 /* This type should be jit_actions_t, but we use uint32_t
34086 to be explicit about the bitwidth. */
34087 uint32_t action_flag;
34088 struct jit_code_entry *relevant_entry;
34089 struct jit_code_entry *first_entry;
34090@};
34091
34092/* GDB puts a breakpoint in this function. */
34093void __attribute__((noinline)) __jit_debug_register_code() @{ @};
34094
34095/* Make sure to specify the version statically, because the
34096 debugger may check the version before we can set it. */
34097struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
34098@end smallexample
34099
34100If the JIT is multi-threaded, then it is important that the JIT synchronize any
34101modifications to this global data properly, which can easily be done by putting
34102a global mutex around modifications to these structures.
34103
34104@node Registering Code
34105@section Registering Code
34106
34107To register code with @value{GDBN}, the JIT should follow this protocol:
34108
34109@itemize @bullet
34110@item
34111Generate an object file in memory with symbols and other desired debug
34112information. The file must include the virtual addresses of the sections.
34113
34114@item
34115Create a code entry for the file, which gives the start and size of the symbol
34116file.
34117
34118@item
34119Add it to the linked list in the JIT descriptor.
34120
34121@item
34122Point the relevant_entry field of the descriptor at the entry.
34123
34124@item
34125Set @code{action_flag} to @code{JIT_REGISTER} and call
34126@code{__jit_debug_register_code}.
34127@end itemize
34128
34129When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
34130@code{relevant_entry} pointer so it doesn't have to walk the list looking for
34131new code. However, the linked list must still be maintained in order to allow
34132@value{GDBN} to attach to a running process and still find the symbol files.
34133
34134@node Unregistering Code
34135@section Unregistering Code
34136
34137If code is freed, then the JIT should use the following protocol:
34138
34139@itemize @bullet
34140@item
34141Remove the code entry corresponding to the code from the linked list.
34142
34143@item
34144Point the @code{relevant_entry} field of the descriptor at the code entry.
34145
34146@item
34147Set @code{action_flag} to @code{JIT_UNREGISTER} and call
34148@code{__jit_debug_register_code}.
34149@end itemize
34150
34151If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
34152and the JIT will leak the memory used for the associated symbol files.
34153
f85b53f8
SD
34154@node Custom Debug Info
34155@section Custom Debug Info
34156@cindex custom JIT debug info
34157@cindex JIT debug info reader
34158
34159Generating debug information in platform-native file formats (like ELF
34160or COFF) may be an overkill for JIT compilers; especially if all the
34161debug info is used for is displaying a meaningful backtrace. The
34162issue can be resolved by having the JIT writers decide on a debug info
34163format and also provide a reader that parses the debug info generated
34164by the JIT compiler. This section gives a brief overview on writing
34165such a parser. More specific details can be found in the source file
34166@file{gdb/jit-reader.in}, which is also installed as a header at
34167@file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
34168
34169The reader is implemented as a shared object (so this functionality is
34170not available on platforms which don't allow loading shared objects at
34171runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
34172@code{jit-reader-unload} are provided, to be used to load and unload
34173the readers from a preconfigured directory. Once loaded, the shared
34174object is used the parse the debug information emitted by the JIT
34175compiler.
34176
34177@menu
34178* Using JIT Debug Info Readers:: How to use supplied readers correctly
34179* Writing JIT Debug Info Readers:: Creating a debug-info reader
34180@end menu
34181
34182@node Using JIT Debug Info Readers
34183@subsection Using JIT Debug Info Readers
34184@kindex jit-reader-load
34185@kindex jit-reader-unload
34186
34187Readers can be loaded and unloaded using the @code{jit-reader-load}
34188and @code{jit-reader-unload} commands.
34189
34190@table @code
c9fb1240
SD
34191@item jit-reader-load @var{reader}
34192Load the JIT reader named @var{reader}. @var{reader} is a shared
34193object specified as either an absolute or a relative file name. In
34194the latter case, @value{GDBN} will try to load the reader from a
34195pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
34196system (here @var{libdir} is the system library directory, often
34197@file{/usr/local/lib}).
34198
34199Only one reader can be active at a time; trying to load a second
34200reader when one is already loaded will result in @value{GDBN}
34201reporting an error. A new JIT reader can be loaded by first unloading
34202the current one using @code{jit-reader-unload} and then invoking
34203@code{jit-reader-load}.
f85b53f8
SD
34204
34205@item jit-reader-unload
34206Unload the currently loaded JIT reader.
34207
34208@end table
34209
34210@node Writing JIT Debug Info Readers
34211@subsection Writing JIT Debug Info Readers
34212@cindex writing JIT debug info readers
34213
34214As mentioned, a reader is essentially a shared object conforming to a
34215certain ABI. This ABI is described in @file{jit-reader.h}.
34216
34217@file{jit-reader.h} defines the structures, macros and functions
34218required to write a reader. It is installed (along with
34219@value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
34220the system include directory.
34221
34222Readers need to be released under a GPL compatible license. A reader
34223can be declared as released under such a license by placing the macro
34224@code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
34225
34226The entry point for readers is the symbol @code{gdb_init_reader},
34227which is expected to be a function with the prototype
34228
34229@findex gdb_init_reader
34230@smallexample
34231extern struct gdb_reader_funcs *gdb_init_reader (void);
34232@end smallexample
34233
34234@cindex @code{struct gdb_reader_funcs}
34235
34236@code{struct gdb_reader_funcs} contains a set of pointers to callback
34237functions. These functions are executed to read the debug info
34238generated by the JIT compiler (@code{read}), to unwind stack frames
34239(@code{unwind}) and to create canonical frame IDs
34240(@code{get_Frame_id}). It also has a callback that is called when the
34241reader is being unloaded (@code{destroy}). The struct looks like this
34242
34243@smallexample
34244struct gdb_reader_funcs
34245@{
34246 /* Must be set to GDB_READER_INTERFACE_VERSION. */
34247 int reader_version;
34248
34249 /* For use by the reader. */
34250 void *priv_data;
34251
34252 gdb_read_debug_info *read;
34253 gdb_unwind_frame *unwind;
34254 gdb_get_frame_id *get_frame_id;
34255 gdb_destroy_reader *destroy;
34256@};
34257@end smallexample
34258
34259@cindex @code{struct gdb_symbol_callbacks}
34260@cindex @code{struct gdb_unwind_callbacks}
34261
34262The callbacks are provided with another set of callbacks by
34263@value{GDBN} to do their job. For @code{read}, these callbacks are
34264passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
34265and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
34266@code{struct gdb_symbol_callbacks} has callbacks to create new object
34267files and new symbol tables inside those object files. @code{struct
34268gdb_unwind_callbacks} has callbacks to read registers off the current
34269frame and to write out the values of the registers in the previous
34270frame. Both have a callback (@code{target_read}) to read bytes off the
34271target's address space.
34272
d1feda86
YQ
34273@node In-Process Agent
34274@chapter In-Process Agent
34275@cindex debugging agent
34276The traditional debugging model is conceptually low-speed, but works fine,
34277because most bugs can be reproduced in debugging-mode execution. However,
34278as multi-core or many-core processors are becoming mainstream, and
34279multi-threaded programs become more and more popular, there should be more
34280and more bugs that only manifest themselves at normal-mode execution, for
34281example, thread races, because debugger's interference with the program's
34282timing may conceal the bugs. On the other hand, in some applications,
34283it is not feasible for the debugger to interrupt the program's execution
34284long enough for the developer to learn anything helpful about its behavior.
34285If the program's correctness depends on its real-time behavior, delays
34286introduced by a debugger might cause the program to fail, even when the
34287code itself is correct. It is useful to be able to observe the program's
34288behavior without interrupting it.
34289
34290Therefore, traditional debugging model is too intrusive to reproduce
34291some bugs. In order to reduce the interference with the program, we can
34292reduce the number of operations performed by debugger. The
34293@dfn{In-Process Agent}, a shared library, is running within the same
34294process with inferior, and is able to perform some debugging operations
34295itself. As a result, debugger is only involved when necessary, and
34296performance of debugging can be improved accordingly. Note that
34297interference with program can be reduced but can't be removed completely,
34298because the in-process agent will still stop or slow down the program.
34299
34300The in-process agent can interpret and execute Agent Expressions
34301(@pxref{Agent Expressions}) during performing debugging operations. The
34302agent expressions can be used for different purposes, such as collecting
34303data in tracepoints, and condition evaluation in breakpoints.
34304
34305@anchor{Control Agent}
34306You can control whether the in-process agent is used as an aid for
34307debugging with the following commands:
34308
34309@table @code
34310@kindex set agent on
34311@item set agent on
34312Causes the in-process agent to perform some operations on behalf of the
34313debugger. Just which operations requested by the user will be done
34314by the in-process agent depends on the its capabilities. For example,
34315if you request to evaluate breakpoint conditions in the in-process agent,
34316and the in-process agent has such capability as well, then breakpoint
34317conditions will be evaluated in the in-process agent.
34318
34319@kindex set agent off
34320@item set agent off
34321Disables execution of debugging operations by the in-process agent. All
34322of the operations will be performed by @value{GDBN}.
34323
34324@kindex show agent
34325@item show agent
34326Display the current setting of execution of debugging operations by
34327the in-process agent.
34328@end table
34329
16bdd41f
YQ
34330@menu
34331* In-Process Agent Protocol::
34332@end menu
34333
34334@node In-Process Agent Protocol
34335@section In-Process Agent Protocol
34336@cindex in-process agent protocol
34337
34338The in-process agent is able to communicate with both @value{GDBN} and
34339GDBserver (@pxref{In-Process Agent}). This section documents the protocol
34340used for communications between @value{GDBN} or GDBserver and the IPA.
34341In general, @value{GDBN} or GDBserver sends commands
34342(@pxref{IPA Protocol Commands}) and data to in-process agent, and then
34343in-process agent replies back with the return result of the command, or
34344some other information. The data sent to in-process agent is composed
34345of primitive data types, such as 4-byte or 8-byte type, and composite
34346types, which are called objects (@pxref{IPA Protocol Objects}).
34347
34348@menu
34349* IPA Protocol Objects::
34350* IPA Protocol Commands::
34351@end menu
34352
34353@node IPA Protocol Objects
34354@subsection IPA Protocol Objects
34355@cindex ipa protocol objects
34356
34357The commands sent to and results received from agent may contain some
34358complex data types called @dfn{objects}.
34359
34360The in-process agent is running on the same machine with @value{GDBN}
34361or GDBserver, so it doesn't have to handle as much differences between
34362two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
34363However, there are still some differences of two ends in two processes:
34364
34365@enumerate
34366@item
34367word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
34368compiled as a 64-bit executable, while in-process agent is a 32-bit one.
34369@item
34370ABI. Some machines may have multiple types of ABI, @value{GDBN} or
34371GDBserver is compiled with one, and in-process agent is compiled with
34372the other one.
34373@end enumerate
34374
34375Here are the IPA Protocol Objects:
34376
34377@enumerate
34378@item
34379agent expression object. It represents an agent expression
34380(@pxref{Agent Expressions}).
34381@anchor{agent expression object}
34382@item
34383tracepoint action object. It represents a tracepoint action
34384(@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
34385memory, static trace data and to evaluate expression.
34386@anchor{tracepoint action object}
34387@item
34388tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
34389@anchor{tracepoint object}
34390
34391@end enumerate
34392
34393The following table describes important attributes of each IPA protocol
34394object:
34395
34396@multitable @columnfractions .30 .20 .50
34397@headitem Name @tab Size @tab Description
34398@item @emph{agent expression object} @tab @tab
34399@item length @tab 4 @tab length of bytes code
34400@item byte code @tab @var{length} @tab contents of byte code
34401@item @emph{tracepoint action for collecting memory} @tab @tab
34402@item 'M' @tab 1 @tab type of tracepoint action
34403@item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
34404address of the lowest byte to collect, otherwise @var{addr} is the offset
34405of @var{basereg} for memory collecting.
34406@item len @tab 8 @tab length of memory for collecting
34407@item basereg @tab 4 @tab the register number containing the starting
34408memory address for collecting.
34409@item @emph{tracepoint action for collecting registers} @tab @tab
34410@item 'R' @tab 1 @tab type of tracepoint action
34411@item @emph{tracepoint action for collecting static trace data} @tab @tab
34412@item 'L' @tab 1 @tab type of tracepoint action
34413@item @emph{tracepoint action for expression evaluation} @tab @tab
34414@item 'X' @tab 1 @tab type of tracepoint action
34415@item agent expression @tab length of @tab @ref{agent expression object}
34416@item @emph{tracepoint object} @tab @tab
34417@item number @tab 4 @tab number of tracepoint
34418@item address @tab 8 @tab address of tracepoint inserted on
34419@item type @tab 4 @tab type of tracepoint
34420@item enabled @tab 1 @tab enable or disable of tracepoint
34421@item step_count @tab 8 @tab step
34422@item pass_count @tab 8 @tab pass
34423@item numactions @tab 4 @tab number of tracepoint actions
34424@item hit count @tab 8 @tab hit count
34425@item trace frame usage @tab 8 @tab trace frame usage
34426@item compiled_cond @tab 8 @tab compiled condition
34427@item orig_size @tab 8 @tab orig size
34428@item condition @tab 4 if condition is NULL otherwise length of
34429@ref{agent expression object}
34430@tab zero if condition is NULL, otherwise is
34431@ref{agent expression object}
34432@item actions @tab variable
34433@tab numactions number of @ref{tracepoint action object}
34434@end multitable
34435
34436@node IPA Protocol Commands
34437@subsection IPA Protocol Commands
34438@cindex ipa protocol commands
34439
34440The spaces in each command are delimiters to ease reading this commands
34441specification. They don't exist in real commands.
34442
34443@table @samp
34444
34445@item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
34446Installs a new fast tracepoint described by @var{tracepoint_object}
34447(@pxref{tracepoint object}). @var{gdb_jump_pad_head}, 8-byte long, is the
34448head of @dfn{jumppad}, which is used to jump to data collection routine
34449in IPA finally.
34450
34451Replies:
34452@table @samp
34453@item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
34454@var{target_address} is address of tracepoint in the inferior.
34455@var{gdb_jump_pad_head} is updated head of jumppad. Both of
34456@var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
34457@var{fjump} contains a sequence of instructions jump to jumppad entry.
34458@var{fjump_size}, 4-byte long, is the size of @var{fjump}.
34459@item E @var{NN}
34460for an error
34461
34462@end table
34463
7255706c
YQ
34464@item close
34465Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
34466is about to kill inferiors.
34467
16bdd41f
YQ
34468@item qTfSTM
34469@xref{qTfSTM}.
34470@item qTsSTM
34471@xref{qTsSTM}.
34472@item qTSTMat
34473@xref{qTSTMat}.
34474@item probe_marker_at:@var{address}
34475Asks in-process agent to probe the marker at @var{address}.
34476
34477Replies:
34478@table @samp
34479@item E @var{NN}
34480for an error
34481@end table
34482@item unprobe_marker_at:@var{address}
34483Asks in-process agent to unprobe the marker at @var{address}.
34484@end table
34485
8e04817f
AC
34486@node GDB Bugs
34487@chapter Reporting Bugs in @value{GDBN}
34488@cindex bugs in @value{GDBN}
34489@cindex reporting bugs in @value{GDBN}
c906108c 34490
8e04817f 34491Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 34492
8e04817f
AC
34493Reporting a bug may help you by bringing a solution to your problem, or it
34494may not. But in any case the principal function of a bug report is to help
34495the entire community by making the next version of @value{GDBN} work better. Bug
34496reports are your contribution to the maintenance of @value{GDBN}.
c906108c 34497
8e04817f
AC
34498In order for a bug report to serve its purpose, you must include the
34499information that enables us to fix the bug.
c4555f82
SC
34500
34501@menu
8e04817f
AC
34502* Bug Criteria:: Have you found a bug?
34503* Bug Reporting:: How to report bugs
c4555f82
SC
34504@end menu
34505
8e04817f 34506@node Bug Criteria
79a6e687 34507@section Have You Found a Bug?
8e04817f 34508@cindex bug criteria
c4555f82 34509
8e04817f 34510If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
34511
34512@itemize @bullet
8e04817f
AC
34513@cindex fatal signal
34514@cindex debugger crash
34515@cindex crash of debugger
c4555f82 34516@item
8e04817f
AC
34517If the debugger gets a fatal signal, for any input whatever, that is a
34518@value{GDBN} bug. Reliable debuggers never crash.
34519
34520@cindex error on valid input
34521@item
34522If @value{GDBN} produces an error message for valid input, that is a
34523bug. (Note that if you're cross debugging, the problem may also be
34524somewhere in the connection to the target.)
c4555f82 34525
8e04817f 34526@cindex invalid input
c4555f82 34527@item
8e04817f
AC
34528If @value{GDBN} does not produce an error message for invalid input,
34529that is a bug. However, you should note that your idea of
34530``invalid input'' might be our idea of ``an extension'' or ``support
34531for traditional practice''.
34532
34533@item
34534If you are an experienced user of debugging tools, your suggestions
34535for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
34536@end itemize
34537
8e04817f 34538@node Bug Reporting
79a6e687 34539@section How to Report Bugs
8e04817f
AC
34540@cindex bug reports
34541@cindex @value{GDBN} bugs, reporting
34542
34543A number of companies and individuals offer support for @sc{gnu} products.
34544If you obtained @value{GDBN} from a support organization, we recommend you
34545contact that organization first.
34546
34547You can find contact information for many support companies and
34548individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
34549distribution.
34550@c should add a web page ref...
34551
c16158bc
JM
34552@ifset BUGURL
34553@ifset BUGURL_DEFAULT
129188f6 34554In any event, we also recommend that you submit bug reports for
d3e8051b 34555@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
34556@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
34557page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
34558be used.
8e04817f
AC
34559
34560@strong{Do not send bug reports to @samp{info-gdb}, or to
34561@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
34562not want to receive bug reports. Those that do have arranged to receive
34563@samp{bug-gdb}.
34564
34565The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
34566serves as a repeater. The mailing list and the newsgroup carry exactly
34567the same messages. Often people think of posting bug reports to the
34568newsgroup instead of mailing them. This appears to work, but it has one
34569problem which can be crucial: a newsgroup posting often lacks a mail
34570path back to the sender. Thus, if we need to ask for more information,
34571we may be unable to reach you. For this reason, it is better to send
34572bug reports to the mailing list.
c16158bc
JM
34573@end ifset
34574@ifclear BUGURL_DEFAULT
34575In any event, we also recommend that you submit bug reports for
34576@value{GDBN} to @value{BUGURL}.
34577@end ifclear
34578@end ifset
c4555f82 34579
8e04817f
AC
34580The fundamental principle of reporting bugs usefully is this:
34581@strong{report all the facts}. If you are not sure whether to state a
34582fact or leave it out, state it!
c4555f82 34583
8e04817f
AC
34584Often people omit facts because they think they know what causes the
34585problem and assume that some details do not matter. Thus, you might
34586assume that the name of the variable you use in an example does not matter.
34587Well, probably it does not, but one cannot be sure. Perhaps the bug is a
34588stray memory reference which happens to fetch from the location where that
34589name is stored in memory; perhaps, if the name were different, the contents
34590of that location would fool the debugger into doing the right thing despite
34591the bug. Play it safe and give a specific, complete example. That is the
34592easiest thing for you to do, and the most helpful.
c4555f82 34593
8e04817f
AC
34594Keep in mind that the purpose of a bug report is to enable us to fix the
34595bug. It may be that the bug has been reported previously, but neither
34596you nor we can know that unless your bug report is complete and
34597self-contained.
c4555f82 34598
8e04817f
AC
34599Sometimes people give a few sketchy facts and ask, ``Does this ring a
34600bell?'' Those bug reports are useless, and we urge everyone to
34601@emph{refuse to respond to them} except to chide the sender to report
34602bugs properly.
34603
34604To enable us to fix the bug, you should include all these things:
c4555f82
SC
34605
34606@itemize @bullet
34607@item
8e04817f
AC
34608The version of @value{GDBN}. @value{GDBN} announces it if you start
34609with no arguments; you can also print it at any time using @code{show
34610version}.
c4555f82 34611
8e04817f
AC
34612Without this, we will not know whether there is any point in looking for
34613the bug in the current version of @value{GDBN}.
c4555f82
SC
34614
34615@item
8e04817f
AC
34616The type of machine you are using, and the operating system name and
34617version number.
c4555f82
SC
34618
34619@item
c1468174 34620What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 34621``@value{GCC}--2.8.1''.
c4555f82
SC
34622
34623@item
8e04817f 34624What compiler (and its version) was used to compile the program you are
c1468174 34625debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
34626C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
34627to get this information; for other compilers, see the documentation for
34628those compilers.
c4555f82 34629
8e04817f
AC
34630@item
34631The command arguments you gave the compiler to compile your example and
34632observe the bug. For example, did you use @samp{-O}? To guarantee
34633you will not omit something important, list them all. A copy of the
34634Makefile (or the output from make) is sufficient.
c4555f82 34635
8e04817f
AC
34636If we were to try to guess the arguments, we would probably guess wrong
34637and then we might not encounter the bug.
c4555f82 34638
8e04817f
AC
34639@item
34640A complete input script, and all necessary source files, that will
34641reproduce the bug.
c4555f82 34642
8e04817f
AC
34643@item
34644A description of what behavior you observe that you believe is
34645incorrect. For example, ``It gets a fatal signal.''
c4555f82 34646
8e04817f
AC
34647Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
34648will certainly notice it. But if the bug is incorrect output, we might
34649not notice unless it is glaringly wrong. You might as well not give us
34650a chance to make a mistake.
c4555f82 34651
8e04817f
AC
34652Even if the problem you experience is a fatal signal, you should still
34653say so explicitly. Suppose something strange is going on, such as, your
34654copy of @value{GDBN} is out of synch, or you have encountered a bug in
34655the C library on your system. (This has happened!) Your copy might
34656crash and ours would not. If you told us to expect a crash, then when
34657ours fails to crash, we would know that the bug was not happening for
34658us. If you had not told us to expect a crash, then we would not be able
34659to draw any conclusion from our observations.
c4555f82 34660
e0c07bf0
MC
34661@pindex script
34662@cindex recording a session script
34663To collect all this information, you can use a session recording program
34664such as @command{script}, which is available on many Unix systems.
34665Just run your @value{GDBN} session inside @command{script} and then
34666include the @file{typescript} file with your bug report.
34667
34668Another way to record a @value{GDBN} session is to run @value{GDBN}
34669inside Emacs and then save the entire buffer to a file.
34670
8e04817f
AC
34671@item
34672If you wish to suggest changes to the @value{GDBN} source, send us context
34673diffs. If you even discuss something in the @value{GDBN} source, refer to
34674it by context, not by line number.
c4555f82 34675
8e04817f
AC
34676The line numbers in our development sources will not match those in your
34677sources. Your line numbers would convey no useful information to us.
c4555f82 34678
8e04817f 34679@end itemize
c4555f82 34680
8e04817f 34681Here are some things that are not necessary:
c4555f82 34682
8e04817f
AC
34683@itemize @bullet
34684@item
34685A description of the envelope of the bug.
c4555f82 34686
8e04817f
AC
34687Often people who encounter a bug spend a lot of time investigating
34688which changes to the input file will make the bug go away and which
34689changes will not affect it.
c4555f82 34690
8e04817f
AC
34691This is often time consuming and not very useful, because the way we
34692will find the bug is by running a single example under the debugger
34693with breakpoints, not by pure deduction from a series of examples.
34694We recommend that you save your time for something else.
c4555f82 34695
8e04817f
AC
34696Of course, if you can find a simpler example to report @emph{instead}
34697of the original one, that is a convenience for us. Errors in the
34698output will be easier to spot, running under the debugger will take
34699less time, and so on.
c4555f82 34700
8e04817f
AC
34701However, simplification is not vital; if you do not want to do this,
34702report the bug anyway and send us the entire test case you used.
c4555f82 34703
8e04817f
AC
34704@item
34705A patch for the bug.
c4555f82 34706
8e04817f
AC
34707A patch for the bug does help us if it is a good one. But do not omit
34708the necessary information, such as the test case, on the assumption that
34709a patch is all we need. We might see problems with your patch and decide
34710to fix the problem another way, or we might not understand it at all.
c4555f82 34711
8e04817f
AC
34712Sometimes with a program as complicated as @value{GDBN} it is very hard to
34713construct an example that will make the program follow a certain path
34714through the code. If you do not send us the example, we will not be able
34715to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 34716
8e04817f
AC
34717And if we cannot understand what bug you are trying to fix, or why your
34718patch should be an improvement, we will not install it. A test case will
34719help us to understand.
c4555f82 34720
8e04817f
AC
34721@item
34722A guess about what the bug is or what it depends on.
c4555f82 34723
8e04817f
AC
34724Such guesses are usually wrong. Even we cannot guess right about such
34725things without first using the debugger to find the facts.
34726@end itemize
c4555f82 34727
8e04817f
AC
34728@c The readline documentation is distributed with the readline code
34729@c and consists of the two following files:
cc88a640
JK
34730@c rluser.texi
34731@c hsuser.texi
8e04817f
AC
34732@c Use -I with makeinfo to point to the appropriate directory,
34733@c environment var TEXINPUTS with TeX.
39037522 34734@ifclear SYSTEM_READLINE
5bdf8622 34735@include rluser.texi
cc88a640 34736@include hsuser.texi
39037522 34737@end ifclear
c4555f82 34738
4ceed123
JB
34739@node In Memoriam
34740@appendix In Memoriam
34741
9ed350ad
JB
34742The @value{GDBN} project mourns the loss of the following long-time
34743contributors:
4ceed123
JB
34744
34745@table @code
34746@item Fred Fish
9ed350ad
JB
34747Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
34748to Free Software in general. Outside of @value{GDBN}, he was known in
34749the Amiga world for his series of Fish Disks, and the GeekGadget project.
4ceed123
JB
34750
34751@item Michael Snyder
9ed350ad
JB
34752Michael was one of the Global Maintainers of the @value{GDBN} project,
34753with contributions recorded as early as 1996, until 2011. In addition
34754to his day to day participation, he was a large driving force behind
34755adding Reverse Debugging to @value{GDBN}.
4ceed123
JB
34756@end table
34757
34758Beyond their technical contributions to the project, they were also
34759enjoyable members of the Free Software Community. We will miss them.
c4555f82 34760
8e04817f
AC
34761@node Formatting Documentation
34762@appendix Formatting Documentation
c4555f82 34763
8e04817f
AC
34764@cindex @value{GDBN} reference card
34765@cindex reference card
34766The @value{GDBN} 4 release includes an already-formatted reference card, ready
34767for printing with PostScript or Ghostscript, in the @file{gdb}
34768subdirectory of the main source directory@footnote{In
34769@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
34770release.}. If you can use PostScript or Ghostscript with your printer,
34771you can print the reference card immediately with @file{refcard.ps}.
c4555f82 34772
8e04817f
AC
34773The release also includes the source for the reference card. You
34774can format it, using @TeX{}, by typing:
c4555f82 34775
474c8240 34776@smallexample
8e04817f 34777make refcard.dvi
474c8240 34778@end smallexample
c4555f82 34779
8e04817f
AC
34780The @value{GDBN} reference card is designed to print in @dfn{landscape}
34781mode on US ``letter'' size paper;
34782that is, on a sheet 11 inches wide by 8.5 inches
34783high. You will need to specify this form of printing as an option to
34784your @sc{dvi} output program.
c4555f82 34785
8e04817f 34786@cindex documentation
c4555f82 34787
8e04817f
AC
34788All the documentation for @value{GDBN} comes as part of the machine-readable
34789distribution. The documentation is written in Texinfo format, which is
34790a documentation system that uses a single source file to produce both
34791on-line information and a printed manual. You can use one of the Info
34792formatting commands to create the on-line version of the documentation
34793and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 34794
8e04817f
AC
34795@value{GDBN} includes an already formatted copy of the on-line Info
34796version of this manual in the @file{gdb} subdirectory. The main Info
34797file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
34798subordinate files matching @samp{gdb.info*} in the same directory. If
34799necessary, you can print out these files, or read them with any editor;
34800but they are easier to read using the @code{info} subsystem in @sc{gnu}
34801Emacs or the standalone @code{info} program, available as part of the
34802@sc{gnu} Texinfo distribution.
c4555f82 34803
8e04817f
AC
34804If you want to format these Info files yourself, you need one of the
34805Info formatting programs, such as @code{texinfo-format-buffer} or
34806@code{makeinfo}.
c4555f82 34807
8e04817f
AC
34808If you have @code{makeinfo} installed, and are in the top level
34809@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
34810version @value{GDBVN}), you can make the Info file by typing:
c4555f82 34811
474c8240 34812@smallexample
8e04817f
AC
34813cd gdb
34814make gdb.info
474c8240 34815@end smallexample
c4555f82 34816
8e04817f
AC
34817If you want to typeset and print copies of this manual, you need @TeX{},
34818a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
34819Texinfo definitions file.
c4555f82 34820
8e04817f
AC
34821@TeX{} is a typesetting program; it does not print files directly, but
34822produces output files called @sc{dvi} files. To print a typeset
34823document, you need a program to print @sc{dvi} files. If your system
34824has @TeX{} installed, chances are it has such a program. The precise
34825command to use depends on your system; @kbd{lpr -d} is common; another
34826(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
34827require a file name without any extension or a @samp{.dvi} extension.
c4555f82 34828
8e04817f
AC
34829@TeX{} also requires a macro definitions file called
34830@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
34831written in Texinfo format. On its own, @TeX{} cannot either read or
34832typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
34833and is located in the @file{gdb-@var{version-number}/texinfo}
34834directory.
c4555f82 34835
8e04817f 34836If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 34837typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
34838subdirectory of the main source directory (for example, to
34839@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 34840
474c8240 34841@smallexample
8e04817f 34842make gdb.dvi
474c8240 34843@end smallexample
c4555f82 34844
8e04817f 34845Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 34846
8e04817f
AC
34847@node Installing GDB
34848@appendix Installing @value{GDBN}
8e04817f 34849@cindex installation
c4555f82 34850
7fa2210b
DJ
34851@menu
34852* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 34853* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
34854* Separate Objdir:: Compiling @value{GDBN} in another directory
34855* Config Names:: Specifying names for hosts and targets
34856* Configure Options:: Summary of options for configure
098b41a6 34857* System-wide configuration:: Having a system-wide init file
7fa2210b
DJ
34858@end menu
34859
34860@node Requirements
79a6e687 34861@section Requirements for Building @value{GDBN}
7fa2210b
DJ
34862@cindex building @value{GDBN}, requirements for
34863
34864Building @value{GDBN} requires various tools and packages to be available.
34865Other packages will be used only if they are found.
34866
79a6e687 34867@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b
DJ
34868@table @asis
34869@item ISO C90 compiler
34870@value{GDBN} is written in ISO C90. It should be buildable with any
34871working C90 compiler, e.g.@: GCC.
34872
34873@end table
34874
79a6e687 34875@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
34876@table @asis
34877@item Expat
123dc839 34878@anchor{Expat}
7fa2210b
DJ
34879@value{GDBN} can use the Expat XML parsing library. This library may be
34880included with your operating system distribution; if it is not, you
34881can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 34882The @file{configure} script will search for this library in several
7fa2210b
DJ
34883standard locations; if it is installed in an unusual path, you can
34884use the @option{--with-libexpat-prefix} option to specify its location.
34885
9cceb671
DJ
34886Expat is used for:
34887
34888@itemize @bullet
34889@item
34890Remote protocol memory maps (@pxref{Memory Map Format})
34891@item
34892Target descriptions (@pxref{Target Descriptions})
34893@item
2268b414
JK
34894Remote shared library lists (@xref{Library List Format},
34895or alternatively @pxref{Library List Format for SVR4 Targets})
9cceb671
DJ
34896@item
34897MS-Windows shared libraries (@pxref{Shared Libraries})
b3b9301e
PA
34898@item
34899Traceframe info (@pxref{Traceframe Info Format})
2ae8c8e7
MM
34900@item
34901Branch trace (@pxref{Branch Trace Format})
9cceb671 34902@end itemize
7fa2210b 34903
31fffb02
CS
34904@item zlib
34905@cindex compressed debug sections
34906@value{GDBN} will use the @samp{zlib} library, if available, to read
34907compressed debug sections. Some linkers, such as GNU gold, are capable
34908of producing binaries with compressed debug sections. If @value{GDBN}
34909is compiled with @samp{zlib}, it will be able to read the debug
34910information in such binaries.
34911
34912The @samp{zlib} library is likely included with your operating system
34913distribution; if it is not, you can get the latest version from
34914@url{http://zlib.net}.
34915
6c7a06a3
TT
34916@item iconv
34917@value{GDBN}'s features related to character sets (@pxref{Character
34918Sets}) require a functioning @code{iconv} implementation. If you are
34919on a GNU system, then this is provided by the GNU C Library. Some
34920other systems also provide a working @code{iconv}.
34921
478aac75
DE
34922If @value{GDBN} is using the @code{iconv} program which is installed
34923in a non-standard place, you will need to tell @value{GDBN} where to find it.
34924This is done with @option{--with-iconv-bin} which specifies the
34925directory that contains the @code{iconv} program.
34926
34927On systems without @code{iconv}, you can install GNU Libiconv. If you
6c7a06a3
TT
34928have previously installed Libiconv, you can use the
34929@option{--with-libiconv-prefix} option to configure.
34930
34931@value{GDBN}'s top-level @file{configure} and @file{Makefile} will
34932arrange to build Libiconv if a directory named @file{libiconv} appears
34933in the top-most source directory. If Libiconv is built this way, and
34934if the operating system does not provide a suitable @code{iconv}
34935implementation, then the just-built library will automatically be used
34936by @value{GDBN}. One easy way to set this up is to download GNU
34937Libiconv, unpack it, and then rename the directory holding the
34938Libiconv source code to @samp{libiconv}.
7fa2210b
DJ
34939@end table
34940
34941@node Running Configure
db2e3e2e 34942@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 34943@cindex configuring @value{GDBN}
db2e3e2e 34944@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
34945of preparing @value{GDBN} for installation; you can then use @code{make} to
34946build the @code{gdb} program.
34947@iftex
34948@c irrelevant in info file; it's as current as the code it lives with.
34949@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
34950look at the @file{README} file in the sources; we may have improved the
34951installation procedures since publishing this manual.}
34952@end iftex
c4555f82 34953
8e04817f
AC
34954The @value{GDBN} distribution includes all the source code you need for
34955@value{GDBN} in a single directory, whose name is usually composed by
34956appending the version number to @samp{gdb}.
c4555f82 34957
8e04817f
AC
34958For example, the @value{GDBN} version @value{GDBVN} distribution is in the
34959@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 34960
8e04817f
AC
34961@table @code
34962@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
34963script for configuring @value{GDBN} and all its supporting libraries
c4555f82 34964
8e04817f
AC
34965@item gdb-@value{GDBVN}/gdb
34966the source specific to @value{GDBN} itself
c4555f82 34967
8e04817f
AC
34968@item gdb-@value{GDBVN}/bfd
34969source for the Binary File Descriptor library
c906108c 34970
8e04817f
AC
34971@item gdb-@value{GDBVN}/include
34972@sc{gnu} include files
c906108c 34973
8e04817f
AC
34974@item gdb-@value{GDBVN}/libiberty
34975source for the @samp{-liberty} free software library
c906108c 34976
8e04817f
AC
34977@item gdb-@value{GDBVN}/opcodes
34978source for the library of opcode tables and disassemblers
c906108c 34979
8e04817f
AC
34980@item gdb-@value{GDBVN}/readline
34981source for the @sc{gnu} command-line interface
c906108c 34982
8e04817f
AC
34983@item gdb-@value{GDBVN}/glob
34984source for the @sc{gnu} filename pattern-matching subroutine
c906108c 34985
8e04817f
AC
34986@item gdb-@value{GDBVN}/mmalloc
34987source for the @sc{gnu} memory-mapped malloc package
34988@end table
c906108c 34989
db2e3e2e 34990The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
34991from the @file{gdb-@var{version-number}} source directory, which in
34992this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 34993
8e04817f 34994First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 34995if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
34996identifier for the platform on which @value{GDBN} will run as an
34997argument.
c906108c 34998
8e04817f 34999For example:
c906108c 35000
474c8240 35001@smallexample
8e04817f
AC
35002cd gdb-@value{GDBVN}
35003./configure @var{host}
35004make
474c8240 35005@end smallexample
c906108c 35006
8e04817f
AC
35007@noindent
35008where @var{host} is an identifier such as @samp{sun4} or
35009@samp{decstation}, that identifies the platform where @value{GDBN} will run.
db2e3e2e 35010(You can often leave off @var{host}; @file{configure} tries to guess the
8e04817f 35011correct value by examining your system.)
c906108c 35012
8e04817f
AC
35013Running @samp{configure @var{host}} and then running @code{make} builds the
35014@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
35015libraries, then @code{gdb} itself. The configured source files, and the
35016binaries, are left in the corresponding source directories.
c906108c 35017
8e04817f 35018@need 750
db2e3e2e 35019@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
35020system does not recognize this automatically when you run a different
35021shell, you may need to run @code{sh} on it explicitly:
c906108c 35022
474c8240 35023@smallexample
8e04817f 35024sh configure @var{host}
474c8240 35025@end smallexample
c906108c 35026
db2e3e2e 35027If you run @file{configure} from a directory that contains source
8e04817f 35028directories for multiple libraries or programs, such as the
db2e3e2e
BW
35029@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
35030@file{configure}
8e04817f
AC
35031creates configuration files for every directory level underneath (unless
35032you tell it not to, with the @samp{--norecursion} option).
35033
db2e3e2e 35034You should run the @file{configure} script from the top directory in the
94e91d6d 35035source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 35036@file{configure} from one of the subdirectories, you will configure only
94e91d6d 35037that subdirectory. That is usually not what you want. In particular,
db2e3e2e 35038if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
35039of the @file{gdb-@var{version-number}} directory, you will omit the
35040configuration of @file{bfd}, @file{readline}, and other sibling
35041directories of the @file{gdb} subdirectory. This leads to build errors
35042about missing include files such as @file{bfd/bfd.h}.
c906108c 35043
8e04817f
AC
35044You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
35045However, you should make sure that the shell on your path (named by
35046the @samp{SHELL} environment variable) is publicly readable. Remember
35047that @value{GDBN} uses the shell to start your program---some systems refuse to
35048let @value{GDBN} debug child processes whose programs are not readable.
c906108c 35049
8e04817f 35050@node Separate Objdir
79a6e687 35051@section Compiling @value{GDBN} in Another Directory
c906108c 35052
8e04817f
AC
35053If you want to run @value{GDBN} versions for several host or target machines,
35054you need a different @code{gdb} compiled for each combination of
db2e3e2e 35055host and target. @file{configure} is designed to make this easy by
8e04817f
AC
35056allowing you to generate each configuration in a separate subdirectory,
35057rather than in the source directory. If your @code{make} program
35058handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
35059@code{make} in each of these directories builds the @code{gdb}
35060program specified there.
c906108c 35061
db2e3e2e 35062To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 35063with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
35064(You also need to specify a path to find @file{configure}
35065itself from your working directory. If the path to @file{configure}
8e04817f
AC
35066would be the same as the argument to @samp{--srcdir}, you can leave out
35067the @samp{--srcdir} option; it is assumed.)
c906108c 35068
8e04817f
AC
35069For example, with version @value{GDBVN}, you can build @value{GDBN} in a
35070separate directory for a Sun 4 like this:
c906108c 35071
474c8240 35072@smallexample
8e04817f
AC
35073@group
35074cd gdb-@value{GDBVN}
35075mkdir ../gdb-sun4
35076cd ../gdb-sun4
35077../gdb-@value{GDBVN}/configure sun4
35078make
35079@end group
474c8240 35080@end smallexample
c906108c 35081
db2e3e2e 35082When @file{configure} builds a configuration using a remote source
8e04817f
AC
35083directory, it creates a tree for the binaries with the same structure
35084(and using the same names) as the tree under the source directory. In
35085the example, you'd find the Sun 4 library @file{libiberty.a} in the
35086directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
35087@file{gdb-sun4/gdb}.
c906108c 35088
94e91d6d
MC
35089Make sure that your path to the @file{configure} script has just one
35090instance of @file{gdb} in it. If your path to @file{configure} looks
35091like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
35092one subdirectory of @value{GDBN}, not the whole package. This leads to
35093build errors about missing include files such as @file{bfd/bfd.h}.
35094
8e04817f
AC
35095One popular reason to build several @value{GDBN} configurations in separate
35096directories is to configure @value{GDBN} for cross-compiling (where
35097@value{GDBN} runs on one machine---the @dfn{host}---while debugging
35098programs that run on another machine---the @dfn{target}).
35099You specify a cross-debugging target by
db2e3e2e 35100giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 35101
8e04817f
AC
35102When you run @code{make} to build a program or library, you must run
35103it in a configured directory---whatever directory you were in when you
db2e3e2e 35104called @file{configure} (or one of its subdirectories).
c906108c 35105
db2e3e2e 35106The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
35107directory also runs recursively. If you type @code{make} in a source
35108directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
35109directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
35110will build all the required libraries, and then build GDB.
c906108c 35111
8e04817f
AC
35112When you have multiple hosts or targets configured in separate
35113directories, you can run @code{make} on them in parallel (for example,
35114if they are NFS-mounted on each of the hosts); they will not interfere
35115with each other.
c906108c 35116
8e04817f 35117@node Config Names
79a6e687 35118@section Specifying Names for Hosts and Targets
c906108c 35119
db2e3e2e 35120The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
35121script are based on a three-part naming scheme, but some short predefined
35122aliases are also supported. The full naming scheme encodes three pieces
35123of information in the following pattern:
c906108c 35124
474c8240 35125@smallexample
8e04817f 35126@var{architecture}-@var{vendor}-@var{os}
474c8240 35127@end smallexample
c906108c 35128
8e04817f
AC
35129For example, you can use the alias @code{sun4} as a @var{host} argument,
35130or as the value for @var{target} in a @code{--target=@var{target}}
35131option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 35132
db2e3e2e 35133The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 35134any query facility to list all supported host and target names or
db2e3e2e 35135aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
35136@code{config.sub} to map abbreviations to full names; you can read the
35137script, if you wish, or you can use it to test your guesses on
35138abbreviations---for example:
c906108c 35139
8e04817f
AC
35140@smallexample
35141% sh config.sub i386-linux
35142i386-pc-linux-gnu
35143% sh config.sub alpha-linux
35144alpha-unknown-linux-gnu
35145% sh config.sub hp9k700
35146hppa1.1-hp-hpux
35147% sh config.sub sun4
35148sparc-sun-sunos4.1.1
35149% sh config.sub sun3
35150m68k-sun-sunos4.1.1
35151% sh config.sub i986v
35152Invalid configuration `i986v': machine `i986v' not recognized
35153@end smallexample
c906108c 35154
8e04817f
AC
35155@noindent
35156@code{config.sub} is also distributed in the @value{GDBN} source
35157directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 35158
8e04817f 35159@node Configure Options
db2e3e2e 35160@section @file{configure} Options
c906108c 35161
db2e3e2e
BW
35162Here is a summary of the @file{configure} options and arguments that
35163are most often useful for building @value{GDBN}. @file{configure} also has
8e04817f 35164several other options not listed here. @inforef{What Configure
db2e3e2e 35165Does,,configure.info}, for a full explanation of @file{configure}.
c906108c 35166
474c8240 35167@smallexample
8e04817f
AC
35168configure @r{[}--help@r{]}
35169 @r{[}--prefix=@var{dir}@r{]}
35170 @r{[}--exec-prefix=@var{dir}@r{]}
35171 @r{[}--srcdir=@var{dirname}@r{]}
35172 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
35173 @r{[}--target=@var{target}@r{]}
35174 @var{host}
474c8240 35175@end smallexample
c906108c 35176
8e04817f
AC
35177@noindent
35178You may introduce options with a single @samp{-} rather than
35179@samp{--} if you prefer; but you may abbreviate option names if you use
35180@samp{--}.
c906108c 35181
8e04817f
AC
35182@table @code
35183@item --help
db2e3e2e 35184Display a quick summary of how to invoke @file{configure}.
c906108c 35185
8e04817f
AC
35186@item --prefix=@var{dir}
35187Configure the source to install programs and files under directory
35188@file{@var{dir}}.
c906108c 35189
8e04817f
AC
35190@item --exec-prefix=@var{dir}
35191Configure the source to install programs under directory
35192@file{@var{dir}}.
c906108c 35193
8e04817f
AC
35194@c avoid splitting the warning from the explanation:
35195@need 2000
35196@item --srcdir=@var{dirname}
35197@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
35198@code{make} that implements the @code{VPATH} feature.}@*
35199Use this option to make configurations in directories separate from the
35200@value{GDBN} source directories. Among other things, you can use this to
35201build (or maintain) several configurations simultaneously, in separate
db2e3e2e 35202directories. @file{configure} writes configuration-specific files in
8e04817f 35203the current directory, but arranges for them to use the source in the
db2e3e2e 35204directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
35205the working directory in parallel to the source directories below
35206@var{dirname}.
c906108c 35207
8e04817f 35208@item --norecursion
db2e3e2e 35209Configure only the directory level where @file{configure} is executed; do not
8e04817f 35210propagate configuration to subdirectories.
c906108c 35211
8e04817f
AC
35212@item --target=@var{target}
35213Configure @value{GDBN} for cross-debugging programs running on the specified
35214@var{target}. Without this option, @value{GDBN} is configured to debug
35215programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 35216
8e04817f 35217There is no convenient way to generate a list of all available targets.
c906108c 35218
8e04817f
AC
35219@item @var{host} @dots{}
35220Configure @value{GDBN} to run on the specified @var{host}.
c906108c 35221
8e04817f
AC
35222There is no convenient way to generate a list of all available hosts.
35223@end table
c906108c 35224
8e04817f
AC
35225There are many other options available as well, but they are generally
35226needed for special purposes only.
c906108c 35227
098b41a6
JG
35228@node System-wide configuration
35229@section System-wide configuration and settings
35230@cindex system-wide init file
35231
35232@value{GDBN} can be configured to have a system-wide init file;
35233this file will be read and executed at startup (@pxref{Startup, , What
35234@value{GDBN} does during startup}).
35235
35236Here is the corresponding configure option:
35237
35238@table @code
35239@item --with-system-gdbinit=@var{file}
35240Specify that the default location of the system-wide init file is
35241@var{file}.
35242@end table
35243
35244If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
35245it may be subject to relocation. Two possible cases:
35246
35247@itemize @bullet
35248@item
35249If the default location of this init file contains @file{$prefix},
35250it will be subject to relocation. Suppose that the configure options
35251are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
35252if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
35253init file is looked for as @file{$install/etc/gdbinit} instead of
35254@file{$prefix/etc/gdbinit}.
35255
35256@item
35257By contrast, if the default location does not contain the prefix,
35258it will not be relocated. E.g.@: if @value{GDBN} has been configured with
35259@option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
35260then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
35261wherever @value{GDBN} is installed.
35262@end itemize
35263
e64e0392
DE
35264If the configured location of the system-wide init file (as given by the
35265@option{--with-system-gdbinit} option at configure time) is in the
35266data-directory (as specified by @option{--with-gdb-datadir} at configure
35267time) or in one of its subdirectories, then @value{GDBN} will look for the
35268system-wide init file in the directory specified by the
35269@option{--data-directory} command-line option.
35270Note that the system-wide init file is only read once, during @value{GDBN}
35271initialization. If the data-directory is changed after @value{GDBN} has
35272started with the @code{set data-directory} command, the file will not be
35273reread.
35274
8e04817f
AC
35275@node Maintenance Commands
35276@appendix Maintenance Commands
35277@cindex maintenance commands
35278@cindex internal commands
c906108c 35279
8e04817f 35280In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
35281includes a number of commands intended for @value{GDBN} developers,
35282that are not documented elsewhere in this manual. These commands are
da316a69
EZ
35283provided here for reference. (For commands that turn on debugging
35284messages, see @ref{Debugging Output}.)
c906108c 35285
8e04817f 35286@table @code
09d4efe1 35287@kindex maint agent
782b2b07 35288@kindex maint agent-eval
f77cc5f0
HZ
35289@item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
35290@itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
09d4efe1
EZ
35291Translate the given @var{expression} into remote agent bytecodes.
35292This command is useful for debugging the Agent Expression mechanism
782b2b07
SS
35293(@pxref{Agent Expressions}). The @samp{agent} version produces an
35294expression useful for data collection, such as by tracepoints, while
35295@samp{maint agent-eval} produces an expression that evaluates directly
35296to a result. For instance, a collection expression for @code{globa +
35297globb} will include bytecodes to record four bytes of memory at each
35298of the addresses of @code{globa} and @code{globb}, while discarding
35299the result of the addition, while an evaluation expression will do the
35300addition and return the sum.
f77cc5f0
HZ
35301If @code{-at} is given, generate remote agent bytecode for @var{location}.
35302If not, generate remote agent bytecode for current frame PC address.
09d4efe1 35303
d3ce09f5
SS
35304@kindex maint agent-printf
35305@item maint agent-printf @var{format},@var{expr},...
35306Translate the given format string and list of argument expressions
35307into remote agent bytecodes and display them as a disassembled list.
35308This command is useful for debugging the agent version of dynamic
6dd24dfa 35309printf (@pxref{Dynamic Printf}).
d3ce09f5 35310
8e04817f
AC
35311@kindex maint info breakpoints
35312@item @anchor{maint info breakpoints}maint info breakpoints
35313Using the same format as @samp{info breakpoints}, display both the
35314breakpoints you've set explicitly, and those @value{GDBN} is using for
35315internal purposes. Internal breakpoints are shown with negative
35316breakpoint numbers. The type column identifies what kind of breakpoint
35317is shown:
c906108c 35318
8e04817f
AC
35319@table @code
35320@item breakpoint
35321Normal, explicitly set breakpoint.
c906108c 35322
8e04817f
AC
35323@item watchpoint
35324Normal, explicitly set watchpoint.
c906108c 35325
8e04817f
AC
35326@item longjmp
35327Internal breakpoint, used to handle correctly stepping through
35328@code{longjmp} calls.
c906108c 35329
8e04817f
AC
35330@item longjmp resume
35331Internal breakpoint at the target of a @code{longjmp}.
c906108c 35332
8e04817f
AC
35333@item until
35334Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 35335
8e04817f
AC
35336@item finish
35337Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 35338
8e04817f
AC
35339@item shlib events
35340Shared library events.
c906108c 35341
8e04817f 35342@end table
c906108c 35343
d6b28940
TT
35344@kindex maint info bfds
35345@item maint info bfds
35346This prints information about each @code{bfd} object that is known to
35347@value{GDBN}. @xref{Top, , BFD, bfd, The Binary File Descriptor Library}.
35348
fff08868
HZ
35349@kindex set displaced-stepping
35350@kindex show displaced-stepping
237fc4c9
PA
35351@cindex displaced stepping support
35352@cindex out-of-line single-stepping
fff08868
HZ
35353@item set displaced-stepping
35354@itemx show displaced-stepping
237fc4c9 35355Control whether or not @value{GDBN} will do @dfn{displaced stepping}
fff08868
HZ
35356if the target supports it. Displaced stepping is a way to single-step
35357over breakpoints without removing them from the inferior, by executing
35358an out-of-line copy of the instruction that was originally at the
35359breakpoint location. It is also known as out-of-line single-stepping.
35360
35361@table @code
35362@item set displaced-stepping on
35363If the target architecture supports it, @value{GDBN} will use
35364displaced stepping to step over breakpoints.
35365
35366@item set displaced-stepping off
35367@value{GDBN} will not use displaced stepping to step over breakpoints,
35368even if such is supported by the target architecture.
35369
35370@cindex non-stop mode, and @samp{set displaced-stepping}
35371@item set displaced-stepping auto
35372This is the default mode. @value{GDBN} will use displaced stepping
35373only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
35374architecture supports displaced stepping.
35375@end table
237fc4c9 35376
09d4efe1
EZ
35377@kindex maint check-symtabs
35378@item maint check-symtabs
35379Check the consistency of psymtabs and symtabs.
35380
35381@kindex maint cplus first_component
35382@item maint cplus first_component @var{name}
35383Print the first C@t{++} class/namespace component of @var{name}.
35384
35385@kindex maint cplus namespace
35386@item maint cplus namespace
35387Print the list of possible C@t{++} namespaces.
35388
35389@kindex maint demangle
35390@item maint demangle @var{name}
d3e8051b 35391Demangle a C@t{++} or Objective-C mangled @var{name}.
09d4efe1
EZ
35392
35393@kindex maint deprecate
35394@kindex maint undeprecate
35395@cindex deprecated commands
35396@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
35397@itemx maint undeprecate @var{command}
35398Deprecate or undeprecate the named @var{command}. Deprecated commands
35399cause @value{GDBN} to issue a warning when you use them. The optional
35400argument @var{replacement} says which newer command should be used in
35401favor of the deprecated one; if it is given, @value{GDBN} will mention
35402the replacement as part of the warning.
35403
35404@kindex maint dump-me
35405@item maint dump-me
721c2651 35406@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 35407Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
35408This is supported only on systems which support aborting a program
35409with the @code{SIGQUIT} signal.
09d4efe1 35410
8d30a00d
AC
35411@kindex maint internal-error
35412@kindex maint internal-warning
09d4efe1
EZ
35413@item maint internal-error @r{[}@var{message-text}@r{]}
35414@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
35415Cause @value{GDBN} to call the internal function @code{internal_error}
35416or @code{internal_warning} and hence behave as though an internal error
35417or internal warning has been detected. In addition to reporting the
35418internal problem, these functions give the user the opportunity to
35419either quit @value{GDBN} or create a core file of the current
35420@value{GDBN} session.
35421
09d4efe1
EZ
35422These commands take an optional parameter @var{message-text} that is
35423used as the text of the error or warning message.
35424
d3e8051b 35425Here's an example of using @code{internal-error}:
09d4efe1 35426
8d30a00d 35427@smallexample
f7dc1244 35428(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
35429@dots{}/maint.c:121: internal-error: testing, 1, 2
35430A problem internal to GDB has been detected. Further
35431debugging may prove unreliable.
35432Quit this debugging session? (y or n) @kbd{n}
35433Create a core file? (y or n) @kbd{n}
f7dc1244 35434(@value{GDBP})
8d30a00d
AC
35435@end smallexample
35436
3c16cced
PA
35437@cindex @value{GDBN} internal error
35438@cindex internal errors, control of @value{GDBN} behavior
35439
35440@kindex maint set internal-error
35441@kindex maint show internal-error
35442@kindex maint set internal-warning
35443@kindex maint show internal-warning
35444@item maint set internal-error @var{action} [ask|yes|no]
35445@itemx maint show internal-error @var{action}
35446@itemx maint set internal-warning @var{action} [ask|yes|no]
35447@itemx maint show internal-warning @var{action}
35448When @value{GDBN} reports an internal problem (error or warning) it
35449gives the user the opportunity to both quit @value{GDBN} and create a
35450core file of the current @value{GDBN} session. These commands let you
35451override the default behaviour for each particular @var{action},
35452described in the table below.
35453
35454@table @samp
35455@item quit
35456You can specify that @value{GDBN} should always (yes) or never (no)
35457quit. The default is to ask the user what to do.
35458
35459@item corefile
35460You can specify that @value{GDBN} should always (yes) or never (no)
35461create a core file. The default is to ask the user what to do.
35462@end table
35463
09d4efe1
EZ
35464@kindex maint packet
35465@item maint packet @var{text}
35466If @value{GDBN} is talking to an inferior via the serial protocol,
35467then this command sends the string @var{text} to the inferior, and
35468displays the response packet. @value{GDBN} supplies the initial
35469@samp{$} character, the terminating @samp{#} character, and the
35470checksum.
35471
35472@kindex maint print architecture
35473@item maint print architecture @r{[}@var{file}@r{]}
35474Print the entire architecture configuration. The optional argument
35475@var{file} names the file where the output goes.
8d30a00d 35476
81adfced
DJ
35477@kindex maint print c-tdesc
35478@item maint print c-tdesc
35479Print the current target description (@pxref{Target Descriptions}) as
35480a C source file. The created source file can be used in @value{GDBN}
35481when an XML parser is not available to parse the description.
35482
00905d52
AC
35483@kindex maint print dummy-frames
35484@item maint print dummy-frames
00905d52
AC
35485Prints the contents of @value{GDBN}'s internal dummy-frame stack.
35486
35487@smallexample
f7dc1244 35488(@value{GDBP}) @kbd{b add}
00905d52 35489@dots{}
f7dc1244 35490(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
35491Breakpoint 2, add (a=2, b=3) at @dots{}
3549258 return (a + b);
35493The program being debugged stopped while in a function called from GDB.
35494@dots{}
f7dc1244 35495(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
354960x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
35497 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
35498 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 35499(@value{GDBP})
00905d52
AC
35500@end smallexample
35501
35502Takes an optional file parameter.
35503
0680b120
AC
35504@kindex maint print registers
35505@kindex maint print raw-registers
35506@kindex maint print cooked-registers
617073a9 35507@kindex maint print register-groups
c21236dc 35508@kindex maint print remote-registers
09d4efe1
EZ
35509@item maint print registers @r{[}@var{file}@r{]}
35510@itemx maint print raw-registers @r{[}@var{file}@r{]}
35511@itemx maint print cooked-registers @r{[}@var{file}@r{]}
35512@itemx maint print register-groups @r{[}@var{file}@r{]}
c21236dc 35513@itemx maint print remote-registers @r{[}@var{file}@r{]}
0680b120
AC
35514Print @value{GDBN}'s internal register data structures.
35515
617073a9 35516The command @code{maint print raw-registers} includes the contents of
c21236dc
PA
35517the raw register cache; the command @code{maint print
35518cooked-registers} includes the (cooked) value of all registers,
35519including registers which aren't available on the target nor visible
35520to user; the command @code{maint print register-groups} includes the
35521groups that each register is a member of; and the command @code{maint
35522print remote-registers} includes the remote target's register numbers
35523and offsets in the `G' packets. @xref{Registers,, Registers, gdbint,
617073a9 35524@value{GDBN} Internals}.
0680b120 35525
09d4efe1
EZ
35526These commands take an optional parameter, a file name to which to
35527write the information.
0680b120 35528
617073a9 35529@kindex maint print reggroups
09d4efe1
EZ
35530@item maint print reggroups @r{[}@var{file}@r{]}
35531Print @value{GDBN}'s internal register group data structures. The
35532optional argument @var{file} tells to what file to write the
35533information.
617073a9 35534
09d4efe1 35535The register groups info looks like this:
617073a9
AC
35536
35537@smallexample
f7dc1244 35538(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
35539 Group Type
35540 general user
35541 float user
35542 all user
35543 vector user
35544 system user
35545 save internal
35546 restore internal
617073a9
AC
35547@end smallexample
35548
09d4efe1
EZ
35549@kindex flushregs
35550@item flushregs
35551This command forces @value{GDBN} to flush its internal register cache.
35552
35553@kindex maint print objfiles
35554@cindex info for known object files
35555@item maint print objfiles
35556Print a dump of all known object files. For each object file, this
35557command prints its name, address in memory, and all of its psymtabs
35558and symtabs.
35559
8a1ea21f
DE
35560@kindex maint print section-scripts
35561@cindex info for known .debug_gdb_scripts-loaded scripts
35562@item maint print section-scripts [@var{regexp}]
35563Print a dump of scripts specified in the @code{.debug_gdb_section} section.
35564If @var{regexp} is specified, only print scripts loaded by object files
35565matching @var{regexp}.
35566For each script, this command prints its name as specified in the objfile,
35567and the full path if known.
8e0583c8 35568@xref{dotdebug_gdb_scripts section}.
8a1ea21f 35569
09d4efe1
EZ
35570@kindex maint print statistics
35571@cindex bcache statistics
35572@item maint print statistics
35573This command prints, for each object file in the program, various data
35574about that object file followed by the byte cache (@dfn{bcache})
35575statistics for the object file. The objfile data includes the number
d3e8051b 35576of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
35577defined by the objfile, the number of as yet unexpanded psym tables,
35578the number of line tables and string tables, and the amount of memory
35579used by the various tables. The bcache statistics include the counts,
35580sizes, and counts of duplicates of all and unique objects, max,
35581average, and median entry size, total memory used and its overhead and
35582savings, and various measures of the hash table size and chain
35583lengths.
35584
c7ba131e
JB
35585@kindex maint print target-stack
35586@cindex target stack description
35587@item maint print target-stack
35588A @dfn{target} is an interface between the debugger and a particular
35589kind of file or process. Targets can be stacked in @dfn{strata},
35590so that more than one target can potentially respond to a request.
35591In particular, memory accesses will walk down the stack of targets
35592until they find a target that is interested in handling that particular
35593address.
35594
35595This command prints a short description of each layer that was pushed on
35596the @dfn{target stack}, starting from the top layer down to the bottom one.
35597
09d4efe1
EZ
35598@kindex maint print type
35599@cindex type chain of a data type
35600@item maint print type @var{expr}
35601Print the type chain for a type specified by @var{expr}. The argument
35602can be either a type name or a symbol. If it is a symbol, the type of
35603that symbol is described. The type chain produced by this command is
35604a recursive definition of the data type as stored in @value{GDBN}'s
35605data structures, including its flags and contained types.
35606
9eae7c52
TT
35607@kindex maint set dwarf2 always-disassemble
35608@kindex maint show dwarf2 always-disassemble
35609@item maint set dwarf2 always-disassemble
35610@item maint show dwarf2 always-disassemble
35611Control the behavior of @code{info address} when using DWARF debugging
35612information.
35613
35614The default is @code{off}, which means that @value{GDBN} should try to
35615describe a variable's location in an easily readable format. When
35616@code{on}, @value{GDBN} will instead display the DWARF location
35617expression in an assembly-like format. Note that some locations are
35618too complex for @value{GDBN} to describe simply; in this case you will
35619always see the disassembly form.
35620
35621Here is an example of the resulting disassembly:
35622
35623@smallexample
35624(gdb) info addr argc
35625Symbol "argc" is a complex DWARF expression:
35626 1: DW_OP_fbreg 0
35627@end smallexample
35628
35629For more information on these expressions, see
35630@uref{http://www.dwarfstd.org/, the DWARF standard}.
35631
09d4efe1
EZ
35632@kindex maint set dwarf2 max-cache-age
35633@kindex maint show dwarf2 max-cache-age
35634@item maint set dwarf2 max-cache-age
35635@itemx maint show dwarf2 max-cache-age
35636Control the DWARF 2 compilation unit cache.
35637
35638@cindex DWARF 2 compilation units cache
35639In object files with inter-compilation-unit references, such as those
35640produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
35641reader needs to frequently refer to previously read compilation units.
35642This setting controls how long a compilation unit will remain in the
35643cache if it is not referenced. A higher limit means that cached
35644compilation units will be stored in memory longer, and more total
35645memory will be used. Setting it to zero disables caching, which will
35646slow down @value{GDBN} startup, but reduce memory consumption.
35647
e7ba9c65
DJ
35648@kindex maint set profile
35649@kindex maint show profile
35650@cindex profiling GDB
35651@item maint set profile
35652@itemx maint show profile
35653Control profiling of @value{GDBN}.
35654
35655Profiling will be disabled until you use the @samp{maint set profile}
35656command to enable it. When you enable profiling, the system will begin
35657collecting timing and execution count data; when you disable profiling or
35658exit @value{GDBN}, the results will be written to a log file. Remember that
35659if you use profiling, @value{GDBN} will overwrite the profiling log file
35660(often called @file{gmon.out}). If you have a record of important profiling
35661data in a @file{gmon.out} file, be sure to move it to a safe location.
35662
35663Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 35664compiled with the @samp{-pg} compiler option.
e7ba9c65 35665
cbe54154
PA
35666@kindex maint set show-debug-regs
35667@kindex maint show show-debug-regs
eac35c4e 35668@cindex hardware debug registers
cbe54154
PA
35669@item maint set show-debug-regs
35670@itemx maint show show-debug-regs
eac35c4e 35671Control whether to show variables that mirror the hardware debug
09d4efe1 35672registers. Use @code{ON} to enable, @code{OFF} to disable. If
3f94c067 35673enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
35674removes a hardware breakpoint or watchpoint, and when the inferior
35675triggers a hardware-assisted breakpoint or watchpoint.
35676
711e434b
PM
35677@kindex maint set show-all-tib
35678@kindex maint show show-all-tib
35679@item maint set show-all-tib
35680@itemx maint show show-all-tib
35681Control whether to show all non zero areas within a 1k block starting
35682at thread local base, when using the @samp{info w32 thread-information-block}
35683command.
35684
bd712aed
DE
35685@kindex maint set per-command
35686@kindex maint show per-command
35687@item maint set per-command
35688@itemx maint show per-command
35689@cindex resources used by commands
09d4efe1 35690
bd712aed
DE
35691@value{GDBN} can display the resources used by each command.
35692This is useful in debugging performance problems.
35693
35694@table @code
35695@item maint set per-command space [on|off]
35696@itemx maint show per-command space
35697Enable or disable the printing of the memory used by GDB for each command.
35698If enabled, @value{GDBN} will display how much memory each command
35699took, following the command's own output.
35700This can also be requested by invoking @value{GDBN} with the
35701@option{--statistics} command-line switch (@pxref{Mode Options}).
35702
35703@item maint set per-command time [on|off]
35704@itemx maint show per-command time
35705Enable or disable the printing of the execution time of @value{GDBN}
35706for each command.
35707If enabled, @value{GDBN} will display how much time it
09d4efe1 35708took to execute each command, following the command's own output.
0a1c4d10
DE
35709Both CPU time and wallclock time are printed.
35710Printing both is useful when trying to determine whether the cost is
bd712aed 35711CPU or, e.g., disk/network latency.
0a1c4d10
DE
35712Note that the CPU time printed is for @value{GDBN} only, it does not include
35713the execution time of the inferior because there's no mechanism currently
35714to compute how much time was spent by @value{GDBN} and how much time was
35715spent by the program been debugged.
09d4efe1
EZ
35716This can also be requested by invoking @value{GDBN} with the
35717@option{--statistics} command-line switch (@pxref{Mode Options}).
35718
bd712aed
DE
35719@item maint set per-command symtab [on|off]
35720@itemx maint show per-command symtab
35721Enable or disable the printing of basic symbol table statistics
35722for each command.
35723If enabled, @value{GDBN} will display the following information:
35724
215b9f98
EZ
35725@enumerate a
35726@item
35727number of symbol tables
35728@item
35729number of primary symbol tables
35730@item
35731number of blocks in the blockvector
35732@end enumerate
bd712aed
DE
35733@end table
35734
35735@kindex maint space
35736@cindex memory used by commands
35737@item maint space @var{value}
35738An alias for @code{maint set per-command space}.
35739A non-zero value enables it, zero disables it.
35740
35741@kindex maint time
35742@cindex time of command execution
35743@item maint time @var{value}
35744An alias for @code{maint set per-command time}.
35745A non-zero value enables it, zero disables it.
35746
09d4efe1
EZ
35747@kindex maint translate-address
35748@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
35749Find the symbol stored at the location specified by the address
35750@var{addr} and an optional section name @var{section}. If found,
35751@value{GDBN} prints the name of the closest symbol and an offset from
35752the symbol's location to the specified address. This is similar to
35753the @code{info address} command (@pxref{Symbols}), except that this
35754command also allows to find symbols in other sections.
ae038cb0 35755
c14c28ba
PP
35756If section was not specified, the section in which the symbol was found
35757is also printed. For dynamically linked executables, the name of
35758executable or shared library containing the symbol is printed as well.
35759
8e04817f 35760@end table
c906108c 35761
9c16f35a
EZ
35762The following command is useful for non-interactive invocations of
35763@value{GDBN}, such as in the test suite.
35764
35765@table @code
35766@item set watchdog @var{nsec}
35767@kindex set watchdog
35768@cindex watchdog timer
35769@cindex timeout for commands
35770Set the maximum number of seconds @value{GDBN} will wait for the
35771target operation to finish. If this time expires, @value{GDBN}
35772reports and error and the command is aborted.
35773
35774@item show watchdog
35775Show the current setting of the target wait timeout.
35776@end table
c906108c 35777
e0ce93ac 35778@node Remote Protocol
8e04817f 35779@appendix @value{GDBN} Remote Serial Protocol
c906108c 35780
ee2d5c50
AC
35781@menu
35782* Overview::
35783* Packets::
35784* Stop Reply Packets::
35785* General Query Packets::
a1dcb23a 35786* Architecture-Specific Protocol Details::
9d29849a 35787* Tracepoint Packets::
a6b151f1 35788* Host I/O Packets::
9a6253be 35789* Interrupts::
8b23ecc4
SL
35790* Notification Packets::
35791* Remote Non-Stop::
a6f3e723 35792* Packet Acknowledgment::
ee2d5c50 35793* Examples::
79a6e687 35794* File-I/O Remote Protocol Extension::
cfa9d6d9 35795* Library List Format::
2268b414 35796* Library List Format for SVR4 Targets::
79a6e687 35797* Memory Map Format::
dc146f7c 35798* Thread List Format::
b3b9301e 35799* Traceframe Info Format::
2ae8c8e7 35800* Branch Trace Format::
ee2d5c50
AC
35801@end menu
35802
35803@node Overview
35804@section Overview
35805
8e04817f
AC
35806There may be occasions when you need to know something about the
35807protocol---for example, if there is only one serial port to your target
35808machine, you might want your program to do something special if it
35809recognizes a packet meant for @value{GDBN}.
c906108c 35810
d2c6833e 35811In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 35812transmitted and received data, respectively.
c906108c 35813
8e04817f
AC
35814@cindex protocol, @value{GDBN} remote serial
35815@cindex serial protocol, @value{GDBN} remote
35816@cindex remote serial protocol
8b23ecc4
SL
35817All @value{GDBN} commands and responses (other than acknowledgments
35818and notifications, see @ref{Notification Packets}) are sent as a
35819@var{packet}. A @var{packet} is introduced with the character
8e04817f
AC
35820@samp{$}, the actual @var{packet-data}, and the terminating character
35821@samp{#} followed by a two-digit @var{checksum}:
c906108c 35822
474c8240 35823@smallexample
8e04817f 35824@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 35825@end smallexample
8e04817f 35826@noindent
c906108c 35827
8e04817f
AC
35828@cindex checksum, for @value{GDBN} remote
35829@noindent
35830The two-digit @var{checksum} is computed as the modulo 256 sum of all
35831characters between the leading @samp{$} and the trailing @samp{#} (an
35832eight bit unsigned checksum).
c906108c 35833
8e04817f
AC
35834Implementors should note that prior to @value{GDBN} 5.0 the protocol
35835specification also included an optional two-digit @var{sequence-id}:
c906108c 35836
474c8240 35837@smallexample
8e04817f 35838@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 35839@end smallexample
c906108c 35840
8e04817f
AC
35841@cindex sequence-id, for @value{GDBN} remote
35842@noindent
35843That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
35844has never output @var{sequence-id}s. Stubs that handle packets added
35845since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 35846
8e04817f
AC
35847When either the host or the target machine receives a packet, the first
35848response expected is an acknowledgment: either @samp{+} (to indicate
35849the package was received correctly) or @samp{-} (to request
35850retransmission):
c906108c 35851
474c8240 35852@smallexample
d2c6833e
AC
35853-> @code{$}@var{packet-data}@code{#}@var{checksum}
35854<- @code{+}
474c8240 35855@end smallexample
8e04817f 35856@noindent
53a5351d 35857
a6f3e723
SL
35858The @samp{+}/@samp{-} acknowledgments can be disabled
35859once a connection is established.
35860@xref{Packet Acknowledgment}, for details.
35861
8e04817f
AC
35862The host (@value{GDBN}) sends @var{command}s, and the target (the
35863debugging stub incorporated in your program) sends a @var{response}. In
35864the case of step and continue @var{command}s, the response is only sent
8b23ecc4
SL
35865when the operation has completed, and the target has again stopped all
35866threads in all attached processes. This is the default all-stop mode
35867behavior, but the remote protocol also supports @value{GDBN}'s non-stop
35868execution mode; see @ref{Remote Non-Stop}, for details.
c906108c 35869
8e04817f
AC
35870@var{packet-data} consists of a sequence of characters with the
35871exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
35872exceptions).
c906108c 35873
ee2d5c50 35874@cindex remote protocol, field separator
0876f84a 35875Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 35876@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 35877@sc{hex} with leading zeros suppressed.
c906108c 35878
8e04817f
AC
35879Implementors should note that prior to @value{GDBN} 5.0, the character
35880@samp{:} could not appear as the third character in a packet (as it
35881would potentially conflict with the @var{sequence-id}).
c906108c 35882
0876f84a
DJ
35883@cindex remote protocol, binary data
35884@anchor{Binary Data}
35885Binary data in most packets is encoded either as two hexadecimal
35886digits per byte of binary data. This allowed the traditional remote
35887protocol to work over connections which were only seven-bit clean.
35888Some packets designed more recently assume an eight-bit clean
35889connection, and use a more efficient encoding to send and receive
35890binary data.
35891
35892The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
35893as an escape character. Any escaped byte is transmitted as the escape
35894character followed by the original character XORed with @code{0x20}.
35895For example, the byte @code{0x7d} would be transmitted as the two
35896bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
35897@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
35898@samp{@}}) must always be escaped. Responses sent by the stub
35899must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
35900is not interpreted as the start of a run-length encoded sequence
35901(described next).
35902
1d3811f6
DJ
35903Response @var{data} can be run-length encoded to save space.
35904Run-length encoding replaces runs of identical characters with one
35905instance of the repeated character, followed by a @samp{*} and a
35906repeat count. The repeat count is itself sent encoded, to avoid
35907binary characters in @var{data}: a value of @var{n} is sent as
35908@code{@var{n}+29}. For a repeat count greater or equal to 3, this
35909produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
35910code 32) for a repeat count of 3. (This is because run-length
35911encoding starts to win for counts 3 or more.) Thus, for example,
35912@samp{0* } is a run-length encoding of ``0000'': the space character
35913after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
359143}} more times.
35915
35916The printable characters @samp{#} and @samp{$} or with a numeric value
35917greater than 126 must not be used. Runs of six repeats (@samp{#}) or
35918seven repeats (@samp{$}) can be expanded using a repeat count of only
35919five (@samp{"}). For example, @samp{00000000} can be encoded as
35920@samp{0*"00}.
c906108c 35921
8e04817f
AC
35922The error response returned for some packets includes a two character
35923error number. That number is not well defined.
c906108c 35924
f8da2bff 35925@cindex empty response, for unsupported packets
8e04817f
AC
35926For any @var{command} not supported by the stub, an empty response
35927(@samp{$#00}) should be returned. That way it is possible to extend the
35928protocol. A newer @value{GDBN} can tell if a packet is supported based
35929on that response.
c906108c 35930
393eab54
PA
35931At a minimum, a stub is required to support the @samp{g} and @samp{G}
35932commands for register access, and the @samp{m} and @samp{M} commands
35933for memory access. Stubs that only control single-threaded targets
35934can implement run control with the @samp{c} (continue), and @samp{s}
35935(step) commands. Stubs that support multi-threading targets should
35936support the @samp{vCont} command. All other commands are optional.
c906108c 35937
ee2d5c50
AC
35938@node Packets
35939@section Packets
35940
35941The following table provides a complete list of all currently defined
35942@var{command}s and their corresponding response @var{data}.
79a6e687 35943@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 35944I/O extension of the remote protocol.
ee2d5c50 35945
b8ff78ce
JB
35946Each packet's description has a template showing the packet's overall
35947syntax, followed by an explanation of the packet's meaning. We
35948include spaces in some of the templates for clarity; these are not
35949part of the packet's syntax. No @value{GDBN} packet uses spaces to
35950separate its components. For example, a template like @samp{foo
35951@var{bar} @var{baz}} describes a packet beginning with the three ASCII
35952bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 35953@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
35954@samp{foo} and the @var{bar}, or between the @var{bar} and the
35955@var{baz}.
35956
b90a069a
SL
35957@cindex @var{thread-id}, in remote protocol
35958@anchor{thread-id syntax}
35959Several packets and replies include a @var{thread-id} field to identify
35960a thread. Normally these are positive numbers with a target-specific
35961interpretation, formatted as big-endian hex strings. A @var{thread-id}
35962can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
35963pick any thread.
35964
35965In addition, the remote protocol supports a multiprocess feature in
35966which the @var{thread-id} syntax is extended to optionally include both
35967process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
35968The @var{pid} (process) and @var{tid} (thread) components each have the
35969format described above: a positive number with target-specific
35970interpretation formatted as a big-endian hex string, literal @samp{-1}
35971to indicate all processes or threads (respectively), or @samp{0} to
35972indicate an arbitrary process or thread. Specifying just a process, as
35973@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
35974error to specify all processes but a specific thread, such as
35975@samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
35976for those packets and replies explicitly documented to include a process
35977ID, rather than a @var{thread-id}.
35978
35979The multiprocess @var{thread-id} syntax extensions are only used if both
35980@value{GDBN} and the stub report support for the @samp{multiprocess}
35981feature using @samp{qSupported}. @xref{multiprocess extensions}, for
35982more information.
35983
8ffe2530
JB
35984Note that all packet forms beginning with an upper- or lower-case
35985letter, other than those described here, are reserved for future use.
35986
b8ff78ce 35987Here are the packet descriptions.
ee2d5c50 35988
b8ff78ce 35989@table @samp
ee2d5c50 35990
b8ff78ce
JB
35991@item !
35992@cindex @samp{!} packet
2d717e4f 35993@anchor{extended mode}
8e04817f
AC
35994Enable extended mode. In extended mode, the remote server is made
35995persistent. The @samp{R} packet is used to restart the program being
35996debugged.
ee2d5c50
AC
35997
35998Reply:
35999@table @samp
36000@item OK
8e04817f 36001The remote target both supports and has enabled extended mode.
ee2d5c50 36002@end table
c906108c 36003
b8ff78ce
JB
36004@item ?
36005@cindex @samp{?} packet
ee2d5c50 36006Indicate the reason the target halted. The reply is the same as for
8b23ecc4
SL
36007step and continue. This packet has a special interpretation when the
36008target is in non-stop mode; see @ref{Remote Non-Stop}.
c906108c 36009
ee2d5c50
AC
36010Reply:
36011@xref{Stop Reply Packets}, for the reply specifications.
36012
b8ff78ce
JB
36013@item A @var{arglen},@var{argnum},@var{arg},@dots{}
36014@cindex @samp{A} packet
36015Initialized @code{argv[]} array passed into program. @var{arglen}
36016specifies the number of bytes in the hex encoded byte stream
36017@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
36018
36019Reply:
36020@table @samp
36021@item OK
b8ff78ce
JB
36022The arguments were set.
36023@item E @var{NN}
36024An error occurred.
ee2d5c50
AC
36025@end table
36026
b8ff78ce
JB
36027@item b @var{baud}
36028@cindex @samp{b} packet
36029(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
36030Change the serial line speed to @var{baud}.
36031
36032JTC: @emph{When does the transport layer state change? When it's
36033received, or after the ACK is transmitted. In either case, there are
36034problems if the command or the acknowledgment packet is dropped.}
36035
36036Stan: @emph{If people really wanted to add something like this, and get
36037it working for the first time, they ought to modify ser-unix.c to send
36038some kind of out-of-band message to a specially-setup stub and have the
36039switch happen "in between" packets, so that from remote protocol's point
36040of view, nothing actually happened.}
36041
b8ff78ce
JB
36042@item B @var{addr},@var{mode}
36043@cindex @samp{B} packet
8e04817f 36044Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
36045breakpoint at @var{addr}.
36046
b8ff78ce 36047Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 36048(@pxref{insert breakpoint or watchpoint packet}).
c906108c 36049
bacec72f 36050@cindex @samp{bc} packet
0d772ac9
MS
36051@anchor{bc}
36052@item bc
bacec72f
MS
36053Backward continue. Execute the target system in reverse. No parameter.
36054@xref{Reverse Execution}, for more information.
36055
36056Reply:
36057@xref{Stop Reply Packets}, for the reply specifications.
36058
bacec72f 36059@cindex @samp{bs} packet
0d772ac9
MS
36060@anchor{bs}
36061@item bs
bacec72f
MS
36062Backward single step. Execute one instruction in reverse. No parameter.
36063@xref{Reverse Execution}, for more information.
36064
36065Reply:
36066@xref{Stop Reply Packets}, for the reply specifications.
36067
4f553f88 36068@item c @r{[}@var{addr}@r{]}
b8ff78ce
JB
36069@cindex @samp{c} packet
36070Continue. @var{addr} is address to resume. If @var{addr} is omitted,
36071resume at current address.
c906108c 36072
393eab54
PA
36073This packet is deprecated for multi-threading support. @xref{vCont
36074packet}.
36075
ee2d5c50
AC
36076Reply:
36077@xref{Stop Reply Packets}, for the reply specifications.
36078
4f553f88 36079@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 36080@cindex @samp{C} packet
8e04817f 36081Continue with signal @var{sig} (hex signal number). If
b8ff78ce 36082@samp{;@var{addr}} is omitted, resume at same address.
c906108c 36083
393eab54
PA
36084This packet is deprecated for multi-threading support. @xref{vCont
36085packet}.
36086
ee2d5c50
AC
36087Reply:
36088@xref{Stop Reply Packets}, for the reply specifications.
c906108c 36089
b8ff78ce
JB
36090@item d
36091@cindex @samp{d} packet
ee2d5c50
AC
36092Toggle debug flag.
36093
b8ff78ce
JB
36094Don't use this packet; instead, define a general set packet
36095(@pxref{General Query Packets}).
ee2d5c50 36096
b8ff78ce 36097@item D
b90a069a 36098@itemx D;@var{pid}
b8ff78ce 36099@cindex @samp{D} packet
b90a069a
SL
36100The first form of the packet is used to detach @value{GDBN} from the
36101remote system. It is sent to the remote target
07f31aa6 36102before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50 36103
b90a069a
SL
36104The second form, including a process ID, is used when multiprocess
36105protocol extensions are enabled (@pxref{multiprocess extensions}), to
36106detach only a specific process. The @var{pid} is specified as a
36107big-endian hex string.
36108
ee2d5c50
AC
36109Reply:
36110@table @samp
10fac096
NW
36111@item OK
36112for success
b8ff78ce 36113@item E @var{NN}
10fac096 36114for an error
ee2d5c50 36115@end table
c906108c 36116
b8ff78ce
JB
36117@item F @var{RC},@var{EE},@var{CF};@var{XX}
36118@cindex @samp{F} packet
36119A reply from @value{GDBN} to an @samp{F} packet sent by the target.
36120This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 36121Remote Protocol Extension}, for the specification.
ee2d5c50 36122
b8ff78ce 36123@item g
ee2d5c50 36124@anchor{read registers packet}
b8ff78ce 36125@cindex @samp{g} packet
ee2d5c50
AC
36126Read general registers.
36127
36128Reply:
36129@table @samp
36130@item @var{XX@dots{}}
8e04817f
AC
36131Each byte of register data is described by two hex digits. The bytes
36132with the register are transmitted in target byte order. The size of
b8ff78ce 36133each register and their position within the @samp{g} packet are
4a9bb1df
UW
36134determined by the @value{GDBN} internal gdbarch functions
36135@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}. The
b8ff78ce 36136specification of several standard @samp{g} packets is specified below.
ad196637
PA
36137
36138When reading registers from a trace frame (@pxref{Analyze Collected
36139Data,,Using the Collected Data}), the stub may also return a string of
36140literal @samp{x}'s in place of the register data digits, to indicate
36141that the corresponding register has not been collected, thus its value
36142is unavailable. For example, for an architecture with 4 registers of
361434 bytes each, the following reply indicates to @value{GDBN} that
36144registers 0 and 2 have not been collected, while registers 1 and 3
36145have been collected, and both have zero value:
36146
36147@smallexample
36148-> @code{g}
36149<- @code{xxxxxxxx00000000xxxxxxxx00000000}
36150@end smallexample
36151
b8ff78ce 36152@item E @var{NN}
ee2d5c50
AC
36153for an error.
36154@end table
c906108c 36155
b8ff78ce
JB
36156@item G @var{XX@dots{}}
36157@cindex @samp{G} packet
36158Write general registers. @xref{read registers packet}, for a
36159description of the @var{XX@dots{}} data.
ee2d5c50
AC
36160
36161Reply:
36162@table @samp
36163@item OK
36164for success
b8ff78ce 36165@item E @var{NN}
ee2d5c50
AC
36166for an error
36167@end table
36168
393eab54 36169@item H @var{op} @var{thread-id}
b8ff78ce 36170@cindex @samp{H} packet
8e04817f 36171Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
393eab54
PA
36172@samp{G}, et.al.). @var{op} depends on the operation to be performed:
36173it should be @samp{c} for step and continue operations (note that this
36174is deprecated, supporting the @samp{vCont} command is a better
36175option), @samp{g} for other operations. The thread designator
36176@var{thread-id} has the format and interpretation described in
36177@ref{thread-id syntax}.
ee2d5c50
AC
36178
36179Reply:
36180@table @samp
36181@item OK
36182for success
b8ff78ce 36183@item E @var{NN}
ee2d5c50
AC
36184for an error
36185@end table
c906108c 36186
8e04817f
AC
36187@c FIXME: JTC:
36188@c 'H': How restrictive (or permissive) is the thread model. If a
36189@c thread is selected and stopped, are other threads allowed
36190@c to continue to execute? As I mentioned above, I think the
36191@c semantics of each command when a thread is selected must be
36192@c described. For example:
36193@c
36194@c 'g': If the stub supports threads and a specific thread is
36195@c selected, returns the register block from that thread;
36196@c otherwise returns current registers.
36197@c
36198@c 'G' If the stub supports threads and a specific thread is
36199@c selected, sets the registers of the register block of
36200@c that thread; otherwise sets current registers.
c906108c 36201
b8ff78ce 36202@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 36203@anchor{cycle step packet}
b8ff78ce
JB
36204@cindex @samp{i} packet
36205Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
36206present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
36207step starting at that address.
c906108c 36208
b8ff78ce
JB
36209@item I
36210@cindex @samp{I} packet
36211Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
36212step packet}.
ee2d5c50 36213
b8ff78ce
JB
36214@item k
36215@cindex @samp{k} packet
36216Kill request.
c906108c 36217
ac282366 36218FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
36219thread context has been selected (i.e.@: does 'k' kill only that
36220thread?)}.
c906108c 36221
b8ff78ce
JB
36222@item m @var{addr},@var{length}
36223@cindex @samp{m} packet
8e04817f 36224Read @var{length} bytes of memory starting at address @var{addr}.
fb031cdf
JB
36225Note that @var{addr} may not be aligned to any particular boundary.
36226
36227The stub need not use any particular size or alignment when gathering
36228data from memory for the response; even if @var{addr} is word-aligned
36229and @var{length} is a multiple of the word size, the stub is free to
36230use byte accesses, or not. For this reason, this packet may not be
36231suitable for accessing memory-mapped I/O devices.
c43c5473
JB
36232@cindex alignment of remote memory accesses
36233@cindex size of remote memory accesses
36234@cindex memory, alignment and size of remote accesses
c906108c 36235
ee2d5c50
AC
36236Reply:
36237@table @samp
36238@item @var{XX@dots{}}
599b237a 36239Memory contents; each byte is transmitted as a two-digit hexadecimal
b8ff78ce
JB
36240number. The reply may contain fewer bytes than requested if the
36241server was able to read only part of the region of memory.
36242@item E @var{NN}
ee2d5c50
AC
36243@var{NN} is errno
36244@end table
36245
b8ff78ce
JB
36246@item M @var{addr},@var{length}:@var{XX@dots{}}
36247@cindex @samp{M} packet
8e04817f 36248Write @var{length} bytes of memory starting at address @var{addr}.
b8ff78ce 36249@var{XX@dots{}} is the data; each byte is transmitted as a two-digit
599b237a 36250hexadecimal number.
ee2d5c50
AC
36251
36252Reply:
36253@table @samp
36254@item OK
36255for success
b8ff78ce 36256@item E @var{NN}
8e04817f
AC
36257for an error (this includes the case where only part of the data was
36258written).
ee2d5c50 36259@end table
c906108c 36260
b8ff78ce
JB
36261@item p @var{n}
36262@cindex @samp{p} packet
36263Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
36264@xref{read registers packet}, for a description of how the returned
36265register value is encoded.
ee2d5c50
AC
36266
36267Reply:
36268@table @samp
2e868123
AC
36269@item @var{XX@dots{}}
36270the register's value
b8ff78ce 36271@item E @var{NN}
2e868123 36272for an error
d57350ea 36273@item @w{}
2e868123 36274Indicating an unrecognized @var{query}.
ee2d5c50
AC
36275@end table
36276
b8ff78ce 36277@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 36278@anchor{write register packet}
b8ff78ce
JB
36279@cindex @samp{P} packet
36280Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 36281number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 36282digits for each byte in the register (target byte order).
c906108c 36283
ee2d5c50
AC
36284Reply:
36285@table @samp
36286@item OK
36287for success
b8ff78ce 36288@item E @var{NN}
ee2d5c50
AC
36289for an error
36290@end table
36291
5f3bebba
JB
36292@item q @var{name} @var{params}@dots{}
36293@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 36294@cindex @samp{q} packet
b8ff78ce 36295@cindex @samp{Q} packet
5f3bebba
JB
36296General query (@samp{q}) and set (@samp{Q}). These packets are
36297described fully in @ref{General Query Packets}.
c906108c 36298
b8ff78ce
JB
36299@item r
36300@cindex @samp{r} packet
8e04817f 36301Reset the entire system.
c906108c 36302
b8ff78ce 36303Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 36304
b8ff78ce
JB
36305@item R @var{XX}
36306@cindex @samp{R} packet
8e04817f 36307Restart the program being debugged. @var{XX}, while needed, is ignored.
2d717e4f 36308This packet is only available in extended mode (@pxref{extended mode}).
ee2d5c50 36309
8e04817f 36310The @samp{R} packet has no reply.
ee2d5c50 36311
4f553f88 36312@item s @r{[}@var{addr}@r{]}
b8ff78ce
JB
36313@cindex @samp{s} packet
36314Single step. @var{addr} is the address at which to resume. If
36315@var{addr} is omitted, resume at same address.
c906108c 36316
393eab54
PA
36317This packet is deprecated for multi-threading support. @xref{vCont
36318packet}.
36319
ee2d5c50
AC
36320Reply:
36321@xref{Stop Reply Packets}, for the reply specifications.
36322
4f553f88 36323@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 36324@anchor{step with signal packet}
b8ff78ce
JB
36325@cindex @samp{S} packet
36326Step with signal. This is analogous to the @samp{C} packet, but
36327requests a single-step, rather than a normal resumption of execution.
c906108c 36328
393eab54
PA
36329This packet is deprecated for multi-threading support. @xref{vCont
36330packet}.
36331
ee2d5c50
AC
36332Reply:
36333@xref{Stop Reply Packets}, for the reply specifications.
36334
b8ff78ce
JB
36335@item t @var{addr}:@var{PP},@var{MM}
36336@cindex @samp{t} packet
8e04817f 36337Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
36338@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
36339@var{addr} must be at least 3 digits.
c906108c 36340
b90a069a 36341@item T @var{thread-id}
b8ff78ce 36342@cindex @samp{T} packet
b90a069a 36343Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
c906108c 36344
ee2d5c50
AC
36345Reply:
36346@table @samp
36347@item OK
36348thread is still alive
b8ff78ce 36349@item E @var{NN}
ee2d5c50
AC
36350thread is dead
36351@end table
36352
b8ff78ce
JB
36353@item v
36354Packets starting with @samp{v} are identified by a multi-letter name,
36355up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 36356
2d717e4f
DJ
36357@item vAttach;@var{pid}
36358@cindex @samp{vAttach} packet
8b23ecc4
SL
36359Attach to a new process with the specified process ID @var{pid}.
36360The process ID is a
36361hexadecimal integer identifying the process. In all-stop mode, all
36362threads in the attached process are stopped; in non-stop mode, it may be
36363attached without being stopped if that is supported by the target.
36364
36365@c In non-stop mode, on a successful vAttach, the stub should set the
36366@c current thread to a thread of the newly-attached process. After
36367@c attaching, GDB queries for the attached process's thread ID with qC.
36368@c Also note that, from a user perspective, whether or not the
36369@c target is stopped on attach in non-stop mode depends on whether you
36370@c use the foreground or background version of the attach command, not
36371@c on what vAttach does; GDB does the right thing with respect to either
36372@c stopping or restarting threads.
2d717e4f
DJ
36373
36374This packet is only available in extended mode (@pxref{extended mode}).
36375
36376Reply:
36377@table @samp
36378@item E @var{nn}
36379for an error
36380@item @r{Any stop packet}
8b23ecc4
SL
36381for success in all-stop mode (@pxref{Stop Reply Packets})
36382@item OK
36383for success in non-stop mode (@pxref{Remote Non-Stop})
2d717e4f
DJ
36384@end table
36385
b90a069a 36386@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
b8ff78ce 36387@cindex @samp{vCont} packet
393eab54 36388@anchor{vCont packet}
b8ff78ce 36389Resume the inferior, specifying different actions for each thread.
b90a069a 36390If an action is specified with no @var{thread-id}, then it is applied to any
86d30acc 36391threads that don't have a specific action specified; if no default action is
8b23ecc4
SL
36392specified then other threads should remain stopped in all-stop mode and
36393in their current state in non-stop mode.
36394Specifying multiple
86d30acc 36395default actions is an error; specifying no actions is also an error.
b90a069a
SL
36396Thread IDs are specified using the syntax described in @ref{thread-id syntax}.
36397
36398Currently supported actions are:
86d30acc 36399
b8ff78ce 36400@table @samp
86d30acc
DJ
36401@item c
36402Continue.
b8ff78ce 36403@item C @var{sig}
8b23ecc4 36404Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
36405@item s
36406Step.
b8ff78ce 36407@item S @var{sig}
8b23ecc4
SL
36408Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
36409@item t
36410Stop.
86d30acc
DJ
36411@end table
36412
8b23ecc4
SL
36413The optional argument @var{addr} normally associated with the
36414@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
b8ff78ce 36415not supported in @samp{vCont}.
86d30acc 36416
08a0efd0
PA
36417The @samp{t} action is only relevant in non-stop mode
36418(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
8b23ecc4
SL
36419A stop reply should be generated for any affected thread not already stopped.
36420When a thread is stopped by means of a @samp{t} action,
36421the corresponding stop reply should indicate that the thread has stopped with
36422signal @samp{0}, regardless of whether the target uses some other signal
36423as an implementation detail.
36424
4220b2f8
TS
36425The stub must support @samp{vCont} if it reports support for
36426multiprocess extensions (@pxref{multiprocess extensions}). Note that in
36427this case @samp{vCont} actions can be specified to apply to all threads
36428in a process by using the @samp{p@var{pid}.-1} form of the
36429@var{thread-id}.
36430
86d30acc
DJ
36431Reply:
36432@xref{Stop Reply Packets}, for the reply specifications.
36433
b8ff78ce
JB
36434@item vCont?
36435@cindex @samp{vCont?} packet
d3e8051b 36436Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
36437
36438Reply:
36439@table @samp
b8ff78ce
JB
36440@item vCont@r{[};@var{action}@dots{}@r{]}
36441The @samp{vCont} packet is supported. Each @var{action} is a supported
36442command in the @samp{vCont} packet.
d57350ea 36443@item @w{}
b8ff78ce 36444The @samp{vCont} packet is not supported.
86d30acc 36445@end table
ee2d5c50 36446
a6b151f1
DJ
36447@item vFile:@var{operation}:@var{parameter}@dots{}
36448@cindex @samp{vFile} packet
36449Perform a file operation on the target system. For details,
36450see @ref{Host I/O Packets}.
36451
68437a39
DJ
36452@item vFlashErase:@var{addr},@var{length}
36453@cindex @samp{vFlashErase} packet
36454Direct the stub to erase @var{length} bytes of flash starting at
36455@var{addr}. The region may enclose any number of flash blocks, but
36456its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
36457flash block size appearing in the memory map (@pxref{Memory Map
36458Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
36459together, and sends a @samp{vFlashDone} request after each group; the
36460stub is allowed to delay erase operation until the @samp{vFlashDone}
36461packet is received.
36462
36463Reply:
36464@table @samp
36465@item OK
36466for success
36467@item E @var{NN}
36468for an error
36469@end table
36470
36471@item vFlashWrite:@var{addr}:@var{XX@dots{}}
36472@cindex @samp{vFlashWrite} packet
36473Direct the stub to write data to flash address @var{addr}. The data
36474is passed in binary form using the same encoding as for the @samp{X}
36475packet (@pxref{Binary Data}). The memory ranges specified by
36476@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
36477not overlap, and must appear in order of increasing addresses
36478(although @samp{vFlashErase} packets for higher addresses may already
36479have been received; the ordering is guaranteed only between
36480@samp{vFlashWrite} packets). If a packet writes to an address that was
36481neither erased by a preceding @samp{vFlashErase} packet nor by some other
36482target-specific method, the results are unpredictable.
36483
36484
36485Reply:
36486@table @samp
36487@item OK
36488for success
36489@item E.memtype
36490for vFlashWrite addressing non-flash memory
36491@item E @var{NN}
36492for an error
36493@end table
36494
36495@item vFlashDone
36496@cindex @samp{vFlashDone} packet
36497Indicate to the stub that flash programming operation is finished.
36498The stub is permitted to delay or batch the effects of a group of
36499@samp{vFlashErase} and @samp{vFlashWrite} packets until a
36500@samp{vFlashDone} packet is received. The contents of the affected
36501regions of flash memory are unpredictable until the @samp{vFlashDone}
36502request is completed.
36503
b90a069a
SL
36504@item vKill;@var{pid}
36505@cindex @samp{vKill} packet
36506Kill the process with the specified process ID. @var{pid} is a
36507hexadecimal integer identifying the process. This packet is used in
36508preference to @samp{k} when multiprocess protocol extensions are
36509supported; see @ref{multiprocess extensions}.
36510
36511Reply:
36512@table @samp
36513@item E @var{nn}
36514for an error
36515@item OK
36516for success
36517@end table
36518
2d717e4f
DJ
36519@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
36520@cindex @samp{vRun} packet
36521Run the program @var{filename}, passing it each @var{argument} on its
36522command line. The file and arguments are hex-encoded strings. If
36523@var{filename} is an empty string, the stub may use a default program
36524(e.g.@: the last program run). The program is created in the stopped
9b562ab8 36525state.
2d717e4f 36526
8b23ecc4
SL
36527@c FIXME: What about non-stop mode?
36528
2d717e4f
DJ
36529This packet is only available in extended mode (@pxref{extended mode}).
36530
36531Reply:
36532@table @samp
36533@item E @var{nn}
36534for an error
36535@item @r{Any stop packet}
36536for success (@pxref{Stop Reply Packets})
36537@end table
36538
8b23ecc4 36539@item vStopped
8b23ecc4 36540@cindex @samp{vStopped} packet
8dbe8ece 36541@xref{Notification Packets}.
8b23ecc4 36542
b8ff78ce 36543@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 36544@anchor{X packet}
b8ff78ce
JB
36545@cindex @samp{X} packet
36546Write data to memory, where the data is transmitted in binary.
36547@var{addr} is address, @var{length} is number of bytes,
0876f84a 36548@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 36549
ee2d5c50
AC
36550Reply:
36551@table @samp
36552@item OK
36553for success
b8ff78ce 36554@item E @var{NN}
ee2d5c50
AC
36555for an error
36556@end table
36557
a1dcb23a
DJ
36558@item z @var{type},@var{addr},@var{kind}
36559@itemx Z @var{type},@var{addr},@var{kind}
2f870471 36560@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
36561@cindex @samp{z} packet
36562@cindex @samp{Z} packets
36563Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
a1dcb23a 36564watchpoint starting at address @var{address} of kind @var{kind}.
ee2d5c50 36565
2f870471
AC
36566Each breakpoint and watchpoint packet @var{type} is documented
36567separately.
36568
512217c7
AC
36569@emph{Implementation notes: A remote target shall return an empty string
36570for an unrecognized breakpoint or watchpoint packet @var{type}. A
36571remote target shall support either both or neither of a given
b8ff78ce 36572@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
36573avoid potential problems with duplicate packets, the operations should
36574be implemented in an idempotent way.}
36575
a1dcb23a 36576@item z0,@var{addr},@var{kind}
d3ce09f5 36577@itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
36578@cindex @samp{z0} packet
36579@cindex @samp{Z0} packet
36580Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
a1dcb23a 36581@var{addr} of type @var{kind}.
2f870471
AC
36582
36583A memory breakpoint is implemented by replacing the instruction at
36584@var{addr} with a software breakpoint or trap instruction. The
a1dcb23a
DJ
36585@var{kind} is target-specific and typically indicates the size of
36586the breakpoint in bytes that should be inserted. E.g., the @sc{arm}
36587and @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
36588architectures have additional meanings for @var{kind};
83364271
LM
36589@var{cond_list} is an optional list of conditional expressions in bytecode
36590form that should be evaluated on the target's side. These are the
36591conditions that should be taken into consideration when deciding if
36592the breakpoint trigger should be reported back to @var{GDBN}.
36593
36594The @var{cond_list} parameter is comprised of a series of expressions,
36595concatenated without separators. Each expression has the following form:
36596
36597@table @samp
36598
36599@item X @var{len},@var{expr}
36600@var{len} is the length of the bytecode expression and @var{expr} is the
36601actual conditional expression in bytecode form.
36602
36603@end table
36604
d3ce09f5
SS
36605The optional @var{cmd_list} parameter introduces commands that may be
36606run on the target, rather than being reported back to @value{GDBN}.
36607The parameter starts with a numeric flag @var{persist}; if the flag is
36608nonzero, then the breakpoint may remain active and the commands
36609continue to be run even when @value{GDBN} disconnects from the target.
36610Following this flag is a series of expressions concatenated with no
36611separators. Each expression has the following form:
36612
36613@table @samp
36614
36615@item X @var{len},@var{expr}
36616@var{len} is the length of the bytecode expression and @var{expr} is the
36617actual conditional expression in bytecode form.
36618
36619@end table
36620
a1dcb23a 36621see @ref{Architecture-Specific Protocol Details}.
c906108c 36622
2f870471
AC
36623@emph{Implementation note: It is possible for a target to copy or move
36624code that contains memory breakpoints (e.g., when implementing
36625overlays). The behavior of this packet, in the presence of such a
36626target, is not defined.}
c906108c 36627
ee2d5c50
AC
36628Reply:
36629@table @samp
2f870471
AC
36630@item OK
36631success
d57350ea 36632@item @w{}
2f870471 36633not supported
b8ff78ce 36634@item E @var{NN}
ee2d5c50 36635for an error
2f870471
AC
36636@end table
36637
a1dcb23a 36638@item z1,@var{addr},@var{kind}
83364271 36639@itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}
b8ff78ce
JB
36640@cindex @samp{z1} packet
36641@cindex @samp{Z1} packet
36642Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
a1dcb23a 36643address @var{addr}.
2f870471
AC
36644
36645A hardware breakpoint is implemented using a mechanism that is not
a1dcb23a 36646dependant on being able to modify the target's memory. @var{kind}
83364271 36647and @var{cond_list} have the same meaning as in @samp{Z0} packets.
2f870471
AC
36648
36649@emph{Implementation note: A hardware breakpoint is not affected by code
36650movement.}
36651
36652Reply:
36653@table @samp
ee2d5c50 36654@item OK
2f870471 36655success
d57350ea 36656@item @w{}
2f870471 36657not supported
b8ff78ce 36658@item E @var{NN}
2f870471
AC
36659for an error
36660@end table
36661
a1dcb23a
DJ
36662@item z2,@var{addr},@var{kind}
36663@itemx Z2,@var{addr},@var{kind}
b8ff78ce
JB
36664@cindex @samp{z2} packet
36665@cindex @samp{Z2} packet
a1dcb23a
DJ
36666Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
36667@var{kind} is interpreted as the number of bytes to watch.
2f870471
AC
36668
36669Reply:
36670@table @samp
36671@item OK
36672success
d57350ea 36673@item @w{}
2f870471 36674not supported
b8ff78ce 36675@item E @var{NN}
2f870471
AC
36676for an error
36677@end table
36678
a1dcb23a
DJ
36679@item z3,@var{addr},@var{kind}
36680@itemx Z3,@var{addr},@var{kind}
b8ff78ce
JB
36681@cindex @samp{z3} packet
36682@cindex @samp{Z3} packet
a1dcb23a
DJ
36683Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
36684@var{kind} is interpreted as the number of bytes to watch.
2f870471
AC
36685
36686Reply:
36687@table @samp
36688@item OK
36689success
d57350ea 36690@item @w{}
2f870471 36691not supported
b8ff78ce 36692@item E @var{NN}
2f870471
AC
36693for an error
36694@end table
36695
a1dcb23a
DJ
36696@item z4,@var{addr},@var{kind}
36697@itemx Z4,@var{addr},@var{kind}
b8ff78ce
JB
36698@cindex @samp{z4} packet
36699@cindex @samp{Z4} packet
a1dcb23a
DJ
36700Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
36701@var{kind} is interpreted as the number of bytes to watch.
2f870471
AC
36702
36703Reply:
36704@table @samp
36705@item OK
36706success
d57350ea 36707@item @w{}
2f870471 36708not supported
b8ff78ce 36709@item E @var{NN}
2f870471 36710for an error
ee2d5c50
AC
36711@end table
36712
36713@end table
c906108c 36714
ee2d5c50
AC
36715@node Stop Reply Packets
36716@section Stop Reply Packets
36717@cindex stop reply packets
c906108c 36718
8b23ecc4
SL
36719The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
36720@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
36721receive any of the below as a reply. Except for @samp{?}
36722and @samp{vStopped}, that reply is only returned
b8ff78ce 36723when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
36724number} is defined by the header @file{include/gdb/signals.h} in the
36725@value{GDBN} source code.
c906108c 36726
b8ff78ce
JB
36727As in the description of request packets, we include spaces in the
36728reply templates for clarity; these are not part of the reply packet's
36729syntax. No @value{GDBN} stop reply packet uses spaces to separate its
36730components.
c906108c 36731
b8ff78ce 36732@table @samp
ee2d5c50 36733
b8ff78ce 36734@item S @var{AA}
599b237a 36735The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
36736number). This is equivalent to a @samp{T} response with no
36737@var{n}:@var{r} pairs.
c906108c 36738
b8ff78ce
JB
36739@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
36740@cindex @samp{T} packet reply
599b237a 36741The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
36742number). This is equivalent to an @samp{S} response, except that the
36743@samp{@var{n}:@var{r}} pairs can carry values of important registers
36744and other information directly in the stop reply packet, reducing
36745round-trip latency. Single-step and breakpoint traps are reported
36746this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
36747
36748@itemize @bullet
b8ff78ce 36749@item
599b237a 36750If @var{n} is a hexadecimal number, it is a register number, and the
b8ff78ce
JB
36751corresponding @var{r} gives that register's value. @var{r} is a
36752series of bytes in target byte order, with each byte given by a
36753two-digit hex number.
cfa9d6d9 36754
b8ff78ce 36755@item
b90a069a
SL
36756If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
36757the stopped thread, as specified in @ref{thread-id syntax}.
cfa9d6d9 36758
dc146f7c
VP
36759@item
36760If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
36761the core on which the stop event was detected.
36762
b8ff78ce 36763@item
cfa9d6d9
DJ
36764If @var{n} is a recognized @dfn{stop reason}, it describes a more
36765specific event that stopped the target. The currently defined stop
36766reasons are listed below. @var{aa} should be @samp{05}, the trap
36767signal. At most one stop reason should be present.
36768
b8ff78ce
JB
36769@item
36770Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
36771and go on to the next; this allows us to extend the protocol in the
36772future.
cfa9d6d9
DJ
36773@end itemize
36774
36775The currently defined stop reasons are:
36776
36777@table @samp
36778@item watch
36779@itemx rwatch
36780@itemx awatch
36781The packet indicates a watchpoint hit, and @var{r} is the data address, in
36782hex.
36783
36784@cindex shared library events, remote reply
36785@item library
36786The packet indicates that the loaded libraries have changed.
36787@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
36788list of loaded libraries. @var{r} is ignored.
bacec72f
MS
36789
36790@cindex replay log events, remote reply
36791@item replaylog
36792The packet indicates that the target cannot continue replaying
36793logged execution events, because it has reached the end (or the
36794beginning when executing backward) of the log. The value of @var{r}
36795will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
36796for more information.
cfa9d6d9 36797@end table
ee2d5c50 36798
b8ff78ce 36799@item W @var{AA}
b90a069a 36800@itemx W @var{AA} ; process:@var{pid}
8e04817f 36801The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
36802applicable to certain targets.
36803
b90a069a
SL
36804The second form of the response, including the process ID of the exited
36805process, can be used only when @value{GDBN} has reported support for
36806multiprocess protocol extensions; see @ref{multiprocess extensions}.
36807The @var{pid} is formatted as a big-endian hex string.
36808
b8ff78ce 36809@item X @var{AA}
b90a069a 36810@itemx X @var{AA} ; process:@var{pid}
8e04817f 36811The process terminated with signal @var{AA}.
c906108c 36812
b90a069a
SL
36813The second form of the response, including the process ID of the
36814terminated process, can be used only when @value{GDBN} has reported
36815support for multiprocess protocol extensions; see @ref{multiprocess
36816extensions}. The @var{pid} is formatted as a big-endian hex string.
36817
b8ff78ce
JB
36818@item O @var{XX}@dots{}
36819@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
36820written as the program's console output. This can happen at any time
36821while the program is running and the debugger should continue to wait
8b23ecc4 36822for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
0ce1b118 36823
b8ff78ce 36824@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
36825@var{call-id} is the identifier which says which host system call should
36826be called. This is just the name of the function. Translation into the
36827correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 36828@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
36829system calls.
36830
b8ff78ce
JB
36831@samp{@var{parameter}@dots{}} is a list of parameters as defined for
36832this very system call.
0ce1b118 36833
b8ff78ce
JB
36834The target replies with this packet when it expects @value{GDBN} to
36835call a host system call on behalf of the target. @value{GDBN} replies
36836with an appropriate @samp{F} packet and keeps up waiting for the next
36837reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
36838or @samp{s} action is expected to be continued. @xref{File-I/O Remote
36839Protocol Extension}, for more details.
0ce1b118 36840
ee2d5c50
AC
36841@end table
36842
36843@node General Query Packets
36844@section General Query Packets
9c16f35a 36845@cindex remote query requests
c906108c 36846
5f3bebba
JB
36847Packets starting with @samp{q} are @dfn{general query packets};
36848packets starting with @samp{Q} are @dfn{general set packets}. General
36849query and set packets are a semi-unified form for retrieving and
36850sending information to and from the stub.
36851
36852The initial letter of a query or set packet is followed by a name
36853indicating what sort of thing the packet applies to. For example,
36854@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
36855definitions with the stub. These packet names follow some
36856conventions:
36857
36858@itemize @bullet
36859@item
36860The name must not contain commas, colons or semicolons.
36861@item
36862Most @value{GDBN} query and set packets have a leading upper case
36863letter.
36864@item
36865The names of custom vendor packets should use a company prefix, in
36866lower case, followed by a period. For example, packets designed at
36867the Acme Corporation might begin with @samp{qacme.foo} (for querying
36868foos) or @samp{Qacme.bar} (for setting bars).
36869@end itemize
36870
aa56d27a
JB
36871The name of a query or set packet should be separated from any
36872parameters by a @samp{:}; the parameters themselves should be
36873separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
36874full packet name, and check for a separator or the end of the packet,
36875in case two packet names share a common prefix. New packets should not begin
36876with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
36877packets predate these conventions, and have arguments without any terminator
36878for the packet name; we suspect they are in widespread use in places that
36879are difficult to upgrade. The @samp{qC} packet has no arguments, but some
36880existing stubs (e.g.@: RedBoot) are known to not check for the end of the
36881packet.}.
c906108c 36882
b8ff78ce
JB
36883Like the descriptions of the other packets, each description here
36884has a template showing the packet's overall syntax, followed by an
36885explanation of the packet's meaning. We include spaces in some of the
36886templates for clarity; these are not part of the packet's syntax. No
36887@value{GDBN} packet uses spaces to separate its components.
36888
5f3bebba
JB
36889Here are the currently defined query and set packets:
36890
b8ff78ce 36891@table @samp
c906108c 36892
d1feda86 36893@item QAgent:1
af4238e5 36894@itemx QAgent:0
d1feda86
YQ
36895Turn on or off the agent as a helper to perform some debugging operations
36896delegated from @value{GDBN} (@pxref{Control Agent}).
36897
d914c394
SS
36898@item QAllow:@var{op}:@var{val}@dots{}
36899@cindex @samp{QAllow} packet
36900Specify which operations @value{GDBN} expects to request of the
36901target, as a semicolon-separated list of operation name and value
36902pairs. Possible values for @var{op} include @samp{WriteReg},
36903@samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
36904@samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
36905indicating that @value{GDBN} will not request the operation, or 1,
36906indicating that it may. (The target can then use this to set up its
36907own internals optimally, for instance if the debugger never expects to
36908insert breakpoints, it may not need to install its own trap handler.)
36909
b8ff78ce 36910@item qC
9c16f35a 36911@cindex current thread, remote request
b8ff78ce 36912@cindex @samp{qC} packet
b90a069a 36913Return the current thread ID.
ee2d5c50
AC
36914
36915Reply:
36916@table @samp
b90a069a
SL
36917@item QC @var{thread-id}
36918Where @var{thread-id} is a thread ID as documented in
36919@ref{thread-id syntax}.
b8ff78ce 36920@item @r{(anything else)}
b90a069a 36921Any other reply implies the old thread ID.
ee2d5c50
AC
36922@end table
36923
b8ff78ce 36924@item qCRC:@var{addr},@var{length}
ff2587ec 36925@cindex CRC of memory block, remote request
b8ff78ce 36926@cindex @samp{qCRC} packet
99e008fe
EZ
36927Compute the CRC checksum of a block of memory using CRC-32 defined in
36928IEEE 802.3. The CRC is computed byte at a time, taking the most
36929significant bit of each byte first. The initial pattern code
36930@code{0xffffffff} is used to ensure leading zeros affect the CRC.
36931
36932@emph{Note:} This is the same CRC used in validating separate debug
36933files (@pxref{Separate Debug Files, , Debugging Information in Separate
36934Files}). However the algorithm is slightly different. When validating
36935separate debug files, the CRC is computed taking the @emph{least}
36936significant bit of each byte first, and the final result is inverted to
36937detect trailing zeros.
36938
ff2587ec
WZ
36939Reply:
36940@table @samp
b8ff78ce 36941@item E @var{NN}
ff2587ec 36942An error (such as memory fault)
b8ff78ce
JB
36943@item C @var{crc32}
36944The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
36945@end table
36946
03583c20
UW
36947@item QDisableRandomization:@var{value}
36948@cindex disable address space randomization, remote request
36949@cindex @samp{QDisableRandomization} packet
36950Some target operating systems will randomize the virtual address space
36951of the inferior process as a security feature, but provide a feature
36952to disable such randomization, e.g.@: to allow for a more deterministic
36953debugging experience. On such systems, this packet with a @var{value}
36954of 1 directs the target to disable address space randomization for
36955processes subsequently started via @samp{vRun} packets, while a packet
36956with a @var{value} of 0 tells the target to enable address space
36957randomization.
36958
36959This packet is only available in extended mode (@pxref{extended mode}).
36960
36961Reply:
36962@table @samp
36963@item OK
36964The request succeeded.
36965
36966@item E @var{nn}
36967An error occurred. @var{nn} are hex digits.
36968
d57350ea 36969@item @w{}
03583c20
UW
36970An empty reply indicates that @samp{QDisableRandomization} is not supported
36971by the stub.
36972@end table
36973
36974This packet is not probed by default; the remote stub must request it,
36975by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
36976This should only be done on targets that actually support disabling
36977address space randomization.
36978
b8ff78ce
JB
36979@item qfThreadInfo
36980@itemx qsThreadInfo
9c16f35a 36981@cindex list active threads, remote request
b8ff78ce
JB
36982@cindex @samp{qfThreadInfo} packet
36983@cindex @samp{qsThreadInfo} packet
b90a069a 36984Obtain a list of all active thread IDs from the target (OS). Since there
8e04817f
AC
36985may be too many active threads to fit into one reply packet, this query
36986works iteratively: it may require more than one query/reply sequence to
36987obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
36988be the @samp{qfThreadInfo} query; subsequent queries in the
36989sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 36990
b8ff78ce 36991NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
36992
36993Reply:
36994@table @samp
b90a069a
SL
36995@item m @var{thread-id}
36996A single thread ID
36997@item m @var{thread-id},@var{thread-id}@dots{}
36998a comma-separated list of thread IDs
b8ff78ce
JB
36999@item l
37000(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
37001@end table
37002
37003In response to each query, the target will reply with a list of one or
b90a069a 37004more thread IDs, separated by commas.
e1aac25b 37005@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce 37006ids (using the @samp{qs} form of the query), until the target responds
501994c0 37007with @samp{l} (lower-case ell, for @dfn{last}).
b90a069a
SL
37008Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
37009fields.
c906108c 37010
b8ff78ce 37011@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 37012@cindex get thread-local storage address, remote request
b8ff78ce 37013@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
37014Fetch the address associated with thread local storage specified
37015by @var{thread-id}, @var{offset}, and @var{lm}.
37016
b90a069a
SL
37017@var{thread-id} is the thread ID associated with the
37018thread for which to fetch the TLS address. @xref{thread-id syntax}.
ff2587ec
WZ
37019
37020@var{offset} is the (big endian, hex encoded) offset associated with the
37021thread local variable. (This offset is obtained from the debug
37022information associated with the variable.)
37023
db2e3e2e 37024@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
7a9dd1b2 37025load module associated with the thread local storage. For example,
ff2587ec
WZ
37026a @sc{gnu}/Linux system will pass the link map address of the shared
37027object associated with the thread local storage under consideration.
37028Other operating environments may choose to represent the load module
37029differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
37030
37031Reply:
b8ff78ce
JB
37032@table @samp
37033@item @var{XX}@dots{}
ff2587ec
WZ
37034Hex encoded (big endian) bytes representing the address of the thread
37035local storage requested.
37036
b8ff78ce
JB
37037@item E @var{nn}
37038An error occurred. @var{nn} are hex digits.
ff2587ec 37039
d57350ea 37040@item @w{}
b8ff78ce 37041An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
37042@end table
37043
711e434b
PM
37044@item qGetTIBAddr:@var{thread-id}
37045@cindex get thread information block address
37046@cindex @samp{qGetTIBAddr} packet
37047Fetch address of the Windows OS specific Thread Information Block.
37048
37049@var{thread-id} is the thread ID associated with the thread.
37050
37051Reply:
37052@table @samp
37053@item @var{XX}@dots{}
37054Hex encoded (big endian) bytes representing the linear address of the
37055thread information block.
37056
37057@item E @var{nn}
37058An error occured. This means that either the thread was not found, or the
37059address could not be retrieved.
37060
d57350ea 37061@item @w{}
711e434b
PM
37062An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
37063@end table
37064
b8ff78ce 37065@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
37066Obtain thread information from RTOS. Where: @var{startflag} (one hex
37067digit) is one to indicate the first query and zero to indicate a
37068subsequent query; @var{threadcount} (two hex digits) is the maximum
37069number of threads the response packet can contain; and @var{nextthread}
37070(eight hex digits), for subsequent queries (@var{startflag} is zero), is
37071returned in the response as @var{argthread}.
ee2d5c50 37072
b8ff78ce 37073Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
37074
37075Reply:
37076@table @samp
b8ff78ce 37077@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
37078Where: @var{count} (two hex digits) is the number of threads being
37079returned; @var{done} (one hex digit) is zero to indicate more threads
37080and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 37081digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
ee2d5c50 37082is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 37083digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 37084@end table
c906108c 37085
b8ff78ce 37086@item qOffsets
9c16f35a 37087@cindex section offsets, remote request
b8ff78ce 37088@cindex @samp{qOffsets} packet
31d99776
DJ
37089Get section offsets that the target used when relocating the downloaded
37090image.
c906108c 37091
ee2d5c50
AC
37092Reply:
37093@table @samp
31d99776
DJ
37094@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
37095Relocate the @code{Text} section by @var{xxx} from its original address.
37096Relocate the @code{Data} section by @var{yyy} from its original address.
37097If the object file format provides segment information (e.g.@: @sc{elf}
37098@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
37099segments by the supplied offsets.
37100
37101@emph{Note: while a @code{Bss} offset may be included in the response,
37102@value{GDBN} ignores this and instead applies the @code{Data} offset
37103to the @code{Bss} section.}
37104
37105@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
37106Relocate the first segment of the object file, which conventionally
37107contains program code, to a starting address of @var{xxx}. If
37108@samp{DataSeg} is specified, relocate the second segment, which
37109conventionally contains modifiable data, to a starting address of
37110@var{yyy}. @value{GDBN} will report an error if the object file
37111does not contain segment information, or does not contain at least
37112as many segments as mentioned in the reply. Extra segments are
37113kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
37114@end table
37115
b90a069a 37116@item qP @var{mode} @var{thread-id}
9c16f35a 37117@cindex thread information, remote request
b8ff78ce 37118@cindex @samp{qP} packet
b90a069a
SL
37119Returns information on @var{thread-id}. Where: @var{mode} is a hex
37120encoded 32 bit mode; @var{thread-id} is a thread ID
37121(@pxref{thread-id syntax}).
ee2d5c50 37122
aa56d27a
JB
37123Don't use this packet; use the @samp{qThreadExtraInfo} query instead
37124(see below).
37125
b8ff78ce 37126Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 37127
8b23ecc4 37128@item QNonStop:1
687e43a4 37129@itemx QNonStop:0
8b23ecc4
SL
37130@cindex non-stop mode, remote request
37131@cindex @samp{QNonStop} packet
37132@anchor{QNonStop}
37133Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
37134@xref{Remote Non-Stop}, for more information.
37135
37136Reply:
37137@table @samp
37138@item OK
37139The request succeeded.
37140
37141@item E @var{nn}
37142An error occurred. @var{nn} are hex digits.
37143
d57350ea 37144@item @w{}
8b23ecc4
SL
37145An empty reply indicates that @samp{QNonStop} is not supported by
37146the stub.
37147@end table
37148
37149This packet is not probed by default; the remote stub must request it,
37150by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37151Use of this packet is controlled by the @code{set non-stop} command;
37152@pxref{Non-Stop Mode}.
37153
89be2091
DJ
37154@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
37155@cindex pass signals to inferior, remote request
37156@cindex @samp{QPassSignals} packet
23181151 37157@anchor{QPassSignals}
89be2091
DJ
37158Each listed @var{signal} should be passed directly to the inferior process.
37159Signals are numbered identically to continue packets and stop replies
37160(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
37161strictly greater than the previous item. These signals do not need to stop
37162the inferior, or be reported to @value{GDBN}. All other signals should be
37163reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
37164combine; any earlier @samp{QPassSignals} list is completely replaced by the
37165new list. This packet improves performance when using @samp{handle
37166@var{signal} nostop noprint pass}.
37167
37168Reply:
37169@table @samp
37170@item OK
37171The request succeeded.
37172
37173@item E @var{nn}
37174An error occurred. @var{nn} are hex digits.
37175
d57350ea 37176@item @w{}
89be2091
DJ
37177An empty reply indicates that @samp{QPassSignals} is not supported by
37178the stub.
37179@end table
37180
37181Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 37182command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
37183This packet is not probed by default; the remote stub must request it,
37184by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37185
9b224c5e
PA
37186@item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
37187@cindex signals the inferior may see, remote request
37188@cindex @samp{QProgramSignals} packet
37189@anchor{QProgramSignals}
37190Each listed @var{signal} may be delivered to the inferior process.
37191Others should be silently discarded.
37192
37193In some cases, the remote stub may need to decide whether to deliver a
37194signal to the program or not without @value{GDBN} involvement. One
37195example of that is while detaching --- the program's threads may have
37196stopped for signals that haven't yet had a chance of being reported to
37197@value{GDBN}, and so the remote stub can use the signal list specified
37198by this packet to know whether to deliver or ignore those pending
37199signals.
37200
37201This does not influence whether to deliver a signal as requested by a
37202resumption packet (@pxref{vCont packet}).
37203
37204Signals are numbered identically to continue packets and stop replies
37205(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
37206strictly greater than the previous item. Multiple
37207@samp{QProgramSignals} packets do not combine; any earlier
37208@samp{QProgramSignals} list is completely replaced by the new list.
37209
37210Reply:
37211@table @samp
37212@item OK
37213The request succeeded.
37214
37215@item E @var{nn}
37216An error occurred. @var{nn} are hex digits.
37217
d57350ea 37218@item @w{}
9b224c5e
PA
37219An empty reply indicates that @samp{QProgramSignals} is not supported
37220by the stub.
37221@end table
37222
37223Use of this packet is controlled by the @code{set remote program-signals}
37224command (@pxref{Remote Configuration, set remote program-signals}).
37225This packet is not probed by default; the remote stub must request it,
37226by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37227
b8ff78ce 37228@item qRcmd,@var{command}
ff2587ec 37229@cindex execute remote command, remote request
b8ff78ce 37230@cindex @samp{qRcmd} packet
ff2587ec 37231@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
37232execution. Invalid commands should be reported using the output
37233string. Before the final result packet, the target may also respond
37234with a number of intermediate @samp{O@var{output}} console output
37235packets. @emph{Implementors should note that providing access to a
37236stubs's interpreter may have security implications}.
fa93a9d8 37237
ff2587ec
WZ
37238Reply:
37239@table @samp
37240@item OK
37241A command response with no output.
37242@item @var{OUTPUT}
37243A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 37244@item E @var{NN}
ff2587ec 37245Indicate a badly formed request.
d57350ea 37246@item @w{}
b8ff78ce 37247An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 37248@end table
fa93a9d8 37249
aa56d27a
JB
37250(Note that the @code{qRcmd} packet's name is separated from the
37251command by a @samp{,}, not a @samp{:}, contrary to the naming
37252conventions above. Please don't use this packet as a model for new
37253packets.)
37254
08388c79
DE
37255@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
37256@cindex searching memory, in remote debugging
5c4808ca 37257@ifnotinfo
08388c79 37258@cindex @samp{qSearch:memory} packet
5c4808ca
EZ
37259@end ifnotinfo
37260@cindex @samp{qSearch memory} packet
08388c79
DE
37261@anchor{qSearch memory}
37262Search @var{length} bytes at @var{address} for @var{search-pattern}.
37263@var{address} and @var{length} are encoded in hex.
37264@var{search-pattern} is a sequence of bytes, hex encoded.
37265
37266Reply:
37267@table @samp
37268@item 0
37269The pattern was not found.
37270@item 1,address
37271The pattern was found at @var{address}.
37272@item E @var{NN}
37273A badly formed request or an error was encountered while searching memory.
d57350ea 37274@item @w{}
08388c79
DE
37275An empty reply indicates that @samp{qSearch:memory} is not recognized.
37276@end table
37277
a6f3e723
SL
37278@item QStartNoAckMode
37279@cindex @samp{QStartNoAckMode} packet
37280@anchor{QStartNoAckMode}
37281Request that the remote stub disable the normal @samp{+}/@samp{-}
37282protocol acknowledgments (@pxref{Packet Acknowledgment}).
37283
37284Reply:
37285@table @samp
37286@item OK
37287The stub has switched to no-acknowledgment mode.
37288@value{GDBN} acknowledges this reponse,
37289but neither the stub nor @value{GDBN} shall send or expect further
37290@samp{+}/@samp{-} acknowledgments in the current connection.
d57350ea 37291@item @w{}
a6f3e723
SL
37292An empty reply indicates that the stub does not support no-acknowledgment mode.
37293@end table
37294
be2a5f71
DJ
37295@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
37296@cindex supported packets, remote query
37297@cindex features of the remote protocol
37298@cindex @samp{qSupported} packet
0876f84a 37299@anchor{qSupported}
be2a5f71
DJ
37300Tell the remote stub about features supported by @value{GDBN}, and
37301query the stub for features it supports. This packet allows
37302@value{GDBN} and the remote stub to take advantage of each others'
37303features. @samp{qSupported} also consolidates multiple feature probes
37304at startup, to improve @value{GDBN} performance---a single larger
37305packet performs better than multiple smaller probe packets on
37306high-latency links. Some features may enable behavior which must not
37307be on by default, e.g.@: because it would confuse older clients or
37308stubs. Other features may describe packets which could be
37309automatically probed for, but are not. These features must be
37310reported before @value{GDBN} will use them. This ``default
37311unsupported'' behavior is not appropriate for all packets, but it
37312helps to keep the initial connection time under control with new
37313versions of @value{GDBN} which support increasing numbers of packets.
37314
37315Reply:
37316@table @samp
37317@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
37318The stub supports or does not support each returned @var{stubfeature},
37319depending on the form of each @var{stubfeature} (see below for the
37320possible forms).
d57350ea 37321@item @w{}
be2a5f71
DJ
37322An empty reply indicates that @samp{qSupported} is not recognized,
37323or that no features needed to be reported to @value{GDBN}.
37324@end table
37325
37326The allowed forms for each feature (either a @var{gdbfeature} in the
37327@samp{qSupported} packet, or a @var{stubfeature} in the response)
37328are:
37329
37330@table @samp
37331@item @var{name}=@var{value}
37332The remote protocol feature @var{name} is supported, and associated
37333with the specified @var{value}. The format of @var{value} depends
37334on the feature, but it must not include a semicolon.
37335@item @var{name}+
37336The remote protocol feature @var{name} is supported, and does not
37337need an associated value.
37338@item @var{name}-
37339The remote protocol feature @var{name} is not supported.
37340@item @var{name}?
37341The remote protocol feature @var{name} may be supported, and
37342@value{GDBN} should auto-detect support in some other way when it is
37343needed. This form will not be used for @var{gdbfeature} notifications,
37344but may be used for @var{stubfeature} responses.
37345@end table
37346
37347Whenever the stub receives a @samp{qSupported} request, the
37348supplied set of @value{GDBN} features should override any previous
37349request. This allows @value{GDBN} to put the stub in a known
37350state, even if the stub had previously been communicating with
37351a different version of @value{GDBN}.
37352
b90a069a
SL
37353The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
37354are defined:
37355
37356@table @samp
37357@item multiprocess
37358This feature indicates whether @value{GDBN} supports multiprocess
37359extensions to the remote protocol. @value{GDBN} does not use such
37360extensions unless the stub also reports that it supports them by
37361including @samp{multiprocess+} in its @samp{qSupported} reply.
37362@xref{multiprocess extensions}, for details.
c8d5aac9
L
37363
37364@item xmlRegisters
37365This feature indicates that @value{GDBN} supports the XML target
37366description. If the stub sees @samp{xmlRegisters=} with target
37367specific strings separated by a comma, it will report register
37368description.
dde08ee1
PA
37369
37370@item qRelocInsn
37371This feature indicates whether @value{GDBN} supports the
37372@samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
37373instruction reply packet}).
b90a069a
SL
37374@end table
37375
37376Stubs should ignore any unknown values for
be2a5f71
DJ
37377@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
37378packet supports receiving packets of unlimited length (earlier
b90a069a 37379versions of @value{GDBN} may reject overly long responses). Additional values
be2a5f71
DJ
37380for @var{gdbfeature} may be defined in the future to let the stub take
37381advantage of new features in @value{GDBN}, e.g.@: incompatible
b90a069a
SL
37382improvements in the remote protocol---the @samp{multiprocess} feature is
37383an example of such a feature. The stub's reply should be independent
be2a5f71
DJ
37384of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
37385describes all the features it supports, and then the stub replies with
37386all the features it supports.
37387
37388Similarly, @value{GDBN} will silently ignore unrecognized stub feature
37389responses, as long as each response uses one of the standard forms.
37390
37391Some features are flags. A stub which supports a flag feature
37392should respond with a @samp{+} form response. Other features
37393require values, and the stub should respond with an @samp{=}
37394form response.
37395
37396Each feature has a default value, which @value{GDBN} will use if
37397@samp{qSupported} is not available or if the feature is not mentioned
37398in the @samp{qSupported} response. The default values are fixed; a
37399stub is free to omit any feature responses that match the defaults.
37400
37401Not all features can be probed, but for those which can, the probing
37402mechanism is useful: in some cases, a stub's internal
37403architecture may not allow the protocol layer to know some information
37404about the underlying target in advance. This is especially common in
37405stubs which may be configured for multiple targets.
37406
37407These are the currently defined stub features and their properties:
37408
cfa9d6d9 37409@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
37410@c NOTE: The first row should be @headitem, but we do not yet require
37411@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 37412@item Feature Name
be2a5f71
DJ
37413@tab Value Required
37414@tab Default
37415@tab Probe Allowed
37416
37417@item @samp{PacketSize}
37418@tab Yes
37419@tab @samp{-}
37420@tab No
37421
0876f84a
DJ
37422@item @samp{qXfer:auxv:read}
37423@tab No
37424@tab @samp{-}
37425@tab Yes
37426
2ae8c8e7
MM
37427@item @samp{qXfer:btrace:read}
37428@tab No
37429@tab @samp{-}
37430@tab Yes
37431
23181151
DJ
37432@item @samp{qXfer:features:read}
37433@tab No
37434@tab @samp{-}
37435@tab Yes
37436
cfa9d6d9
DJ
37437@item @samp{qXfer:libraries:read}
37438@tab No
37439@tab @samp{-}
37440@tab Yes
37441
68437a39
DJ
37442@item @samp{qXfer:memory-map:read}
37443@tab No
37444@tab @samp{-}
37445@tab Yes
37446
0fb4aa4b
PA
37447@item @samp{qXfer:sdata:read}
37448@tab No
37449@tab @samp{-}
37450@tab Yes
37451
0e7f50da
UW
37452@item @samp{qXfer:spu:read}
37453@tab No
37454@tab @samp{-}
37455@tab Yes
37456
37457@item @samp{qXfer:spu:write}
37458@tab No
37459@tab @samp{-}
37460@tab Yes
37461
4aa995e1
PA
37462@item @samp{qXfer:siginfo:read}
37463@tab No
37464@tab @samp{-}
37465@tab Yes
37466
37467@item @samp{qXfer:siginfo:write}
37468@tab No
37469@tab @samp{-}
37470@tab Yes
37471
dc146f7c
VP
37472@item @samp{qXfer:threads:read}
37473@tab No
37474@tab @samp{-}
37475@tab Yes
37476
b3b9301e
PA
37477@item @samp{qXfer:traceframe-info:read}
37478@tab No
37479@tab @samp{-}
37480@tab Yes
37481
169081d0
TG
37482@item @samp{qXfer:uib:read}
37483@tab No
37484@tab @samp{-}
37485@tab Yes
37486
78d85199
YQ
37487@item @samp{qXfer:fdpic:read}
37488@tab No
37489@tab @samp{-}
37490@tab Yes
dc146f7c 37491
2ae8c8e7
MM
37492@item @samp{Qbtrace:off}
37493@tab Yes
37494@tab @samp{-}
37495@tab Yes
37496
37497@item @samp{Qbtrace:bts}
37498@tab Yes
37499@tab @samp{-}
37500@tab Yes
37501
8b23ecc4
SL
37502@item @samp{QNonStop}
37503@tab No
37504@tab @samp{-}
37505@tab Yes
37506
89be2091
DJ
37507@item @samp{QPassSignals}
37508@tab No
37509@tab @samp{-}
37510@tab Yes
37511
a6f3e723
SL
37512@item @samp{QStartNoAckMode}
37513@tab No
37514@tab @samp{-}
37515@tab Yes
37516
b90a069a
SL
37517@item @samp{multiprocess}
37518@tab No
37519@tab @samp{-}
37520@tab No
37521
83364271
LM
37522@item @samp{ConditionalBreakpoints}
37523@tab No
37524@tab @samp{-}
37525@tab No
37526
782b2b07
SS
37527@item @samp{ConditionalTracepoints}
37528@tab No
37529@tab @samp{-}
37530@tab No
37531
0d772ac9
MS
37532@item @samp{ReverseContinue}
37533@tab No
2f8132f3 37534@tab @samp{-}
0d772ac9
MS
37535@tab No
37536
37537@item @samp{ReverseStep}
37538@tab No
2f8132f3 37539@tab @samp{-}
0d772ac9
MS
37540@tab No
37541
409873ef
SS
37542@item @samp{TracepointSource}
37543@tab No
37544@tab @samp{-}
37545@tab No
37546
d1feda86
YQ
37547@item @samp{QAgent}
37548@tab No
37549@tab @samp{-}
37550@tab No
37551
d914c394
SS
37552@item @samp{QAllow}
37553@tab No
37554@tab @samp{-}
37555@tab No
37556
03583c20
UW
37557@item @samp{QDisableRandomization}
37558@tab No
37559@tab @samp{-}
37560@tab No
37561
d248b706
KY
37562@item @samp{EnableDisableTracepoints}
37563@tab No
37564@tab @samp{-}
37565@tab No
37566
f6f899bf
HAQ
37567@item @samp{QTBuffer:size}
37568@tab No
37569@tab @samp{-}
37570@tab No
37571
3065dfb6
SS
37572@item @samp{tracenz}
37573@tab No
37574@tab @samp{-}
37575@tab No
37576
d3ce09f5
SS
37577@item @samp{BreakpointCommands}
37578@tab No
37579@tab @samp{-}
37580@tab No
37581
be2a5f71
DJ
37582@end multitable
37583
37584These are the currently defined stub features, in more detail:
37585
37586@table @samp
37587@cindex packet size, remote protocol
37588@item PacketSize=@var{bytes}
37589The remote stub can accept packets up to at least @var{bytes} in
37590length. @value{GDBN} will send packets up to this size for bulk
37591transfers, and will never send larger packets. This is a limit on the
37592data characters in the packet, including the frame and checksum.
37593There is no trailing NUL byte in a remote protocol packet; if the stub
37594stores packets in a NUL-terminated format, it should allow an extra
37595byte in its buffer for the NUL. If this stub feature is not supported,
37596@value{GDBN} guesses based on the size of the @samp{g} packet response.
37597
0876f84a
DJ
37598@item qXfer:auxv:read
37599The remote stub understands the @samp{qXfer:auxv:read} packet
37600(@pxref{qXfer auxiliary vector read}).
37601
2ae8c8e7
MM
37602@item qXfer:btrace:read
37603The remote stub understands the @samp{qXfer:btrace:read}
37604packet (@pxref{qXfer btrace read}).
37605
23181151
DJ
37606@item qXfer:features:read
37607The remote stub understands the @samp{qXfer:features:read} packet
37608(@pxref{qXfer target description read}).
37609
cfa9d6d9
DJ
37610@item qXfer:libraries:read
37611The remote stub understands the @samp{qXfer:libraries:read} packet
37612(@pxref{qXfer library list read}).
37613
2268b414
JK
37614@item qXfer:libraries-svr4:read
37615The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
37616(@pxref{qXfer svr4 library list read}).
37617
23181151
DJ
37618@item qXfer:memory-map:read
37619The remote stub understands the @samp{qXfer:memory-map:read} packet
37620(@pxref{qXfer memory map read}).
37621
0fb4aa4b
PA
37622@item qXfer:sdata:read
37623The remote stub understands the @samp{qXfer:sdata:read} packet
37624(@pxref{qXfer sdata read}).
37625
0e7f50da
UW
37626@item qXfer:spu:read
37627The remote stub understands the @samp{qXfer:spu:read} packet
37628(@pxref{qXfer spu read}).
37629
37630@item qXfer:spu:write
37631The remote stub understands the @samp{qXfer:spu:write} packet
37632(@pxref{qXfer spu write}).
37633
4aa995e1
PA
37634@item qXfer:siginfo:read
37635The remote stub understands the @samp{qXfer:siginfo:read} packet
37636(@pxref{qXfer siginfo read}).
37637
37638@item qXfer:siginfo:write
37639The remote stub understands the @samp{qXfer:siginfo:write} packet
37640(@pxref{qXfer siginfo write}).
37641
dc146f7c
VP
37642@item qXfer:threads:read
37643The remote stub understands the @samp{qXfer:threads:read} packet
37644(@pxref{qXfer threads read}).
37645
b3b9301e
PA
37646@item qXfer:traceframe-info:read
37647The remote stub understands the @samp{qXfer:traceframe-info:read}
37648packet (@pxref{qXfer traceframe info read}).
37649
169081d0
TG
37650@item qXfer:uib:read
37651The remote stub understands the @samp{qXfer:uib:read}
37652packet (@pxref{qXfer unwind info block}).
37653
78d85199
YQ
37654@item qXfer:fdpic:read
37655The remote stub understands the @samp{qXfer:fdpic:read}
37656packet (@pxref{qXfer fdpic loadmap read}).
37657
8b23ecc4
SL
37658@item QNonStop
37659The remote stub understands the @samp{QNonStop} packet
37660(@pxref{QNonStop}).
37661
23181151
DJ
37662@item QPassSignals
37663The remote stub understands the @samp{QPassSignals} packet
37664(@pxref{QPassSignals}).
37665
a6f3e723
SL
37666@item QStartNoAckMode
37667The remote stub understands the @samp{QStartNoAckMode} packet and
37668prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
37669
b90a069a
SL
37670@item multiprocess
37671@anchor{multiprocess extensions}
37672@cindex multiprocess extensions, in remote protocol
37673The remote stub understands the multiprocess extensions to the remote
37674protocol syntax. The multiprocess extensions affect the syntax of
37675thread IDs in both packets and replies (@pxref{thread-id syntax}), and
37676add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
37677replies. Note that reporting this feature indicates support for the
37678syntactic extensions only, not that the stub necessarily supports
37679debugging of more than one process at a time. The stub must not use
37680multiprocess extensions in packet replies unless @value{GDBN} has also
37681indicated it supports them in its @samp{qSupported} request.
37682
07e059b5
VP
37683@item qXfer:osdata:read
37684The remote stub understands the @samp{qXfer:osdata:read} packet
37685((@pxref{qXfer osdata read}).
37686
83364271
LM
37687@item ConditionalBreakpoints
37688The target accepts and implements evaluation of conditional expressions
37689defined for breakpoints. The target will only report breakpoint triggers
37690when such conditions are true (@pxref{Conditions, ,Break Conditions}).
37691
782b2b07
SS
37692@item ConditionalTracepoints
37693The remote stub accepts and implements conditional expressions defined
37694for tracepoints (@pxref{Tracepoint Conditions}).
37695
0d772ac9
MS
37696@item ReverseContinue
37697The remote stub accepts and implements the reverse continue packet
37698(@pxref{bc}).
37699
37700@item ReverseStep
37701The remote stub accepts and implements the reverse step packet
37702(@pxref{bs}).
37703
409873ef
SS
37704@item TracepointSource
37705The remote stub understands the @samp{QTDPsrc} packet that supplies
37706the source form of tracepoint definitions.
37707
d1feda86
YQ
37708@item QAgent
37709The remote stub understands the @samp{QAgent} packet.
37710
d914c394
SS
37711@item QAllow
37712The remote stub understands the @samp{QAllow} packet.
37713
03583c20
UW
37714@item QDisableRandomization
37715The remote stub understands the @samp{QDisableRandomization} packet.
37716
0fb4aa4b
PA
37717@item StaticTracepoint
37718@cindex static tracepoints, in remote protocol
37719The remote stub supports static tracepoints.
37720
1e4d1764
YQ
37721@item InstallInTrace
37722@anchor{install tracepoint in tracing}
37723The remote stub supports installing tracepoint in tracing.
37724
d248b706
KY
37725@item EnableDisableTracepoints
37726The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
37727@samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
37728to be enabled and disabled while a trace experiment is running.
37729
f6f899bf 37730@item QTBuffer:size
28abe188 37731The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
f6f899bf
HAQ
37732packet that allows to change the size of the trace buffer.
37733
3065dfb6
SS
37734@item tracenz
37735@cindex string tracing, in remote protocol
37736The remote stub supports the @samp{tracenz} bytecode for collecting strings.
37737See @ref{Bytecode Descriptions} for details about the bytecode.
37738
d3ce09f5
SS
37739@item BreakpointCommands
37740@cindex breakpoint commands, in remote protocol
37741The remote stub supports running a breakpoint's command list itself,
37742rather than reporting the hit to @value{GDBN}.
37743
2ae8c8e7
MM
37744@item Qbtrace:off
37745The remote stub understands the @samp{Qbtrace:off} packet.
37746
37747@item Qbtrace:bts
37748The remote stub understands the @samp{Qbtrace:bts} packet.
37749
be2a5f71
DJ
37750@end table
37751
b8ff78ce 37752@item qSymbol::
ff2587ec 37753@cindex symbol lookup, remote request
b8ff78ce 37754@cindex @samp{qSymbol} packet
ff2587ec
WZ
37755Notify the target that @value{GDBN} is prepared to serve symbol lookup
37756requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
37757
37758Reply:
ff2587ec 37759@table @samp
b8ff78ce 37760@item OK
ff2587ec 37761The target does not need to look up any (more) symbols.
b8ff78ce 37762@item qSymbol:@var{sym_name}
ff2587ec
WZ
37763The target requests the value of symbol @var{sym_name} (hex encoded).
37764@value{GDBN} may provide the value by using the
b8ff78ce
JB
37765@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
37766below.
ff2587ec 37767@end table
83761cbd 37768
b8ff78ce 37769@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
37770Set the value of @var{sym_name} to @var{sym_value}.
37771
37772@var{sym_name} (hex encoded) is the name of a symbol whose value the
37773target has previously requested.
37774
37775@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
37776@value{GDBN} cannot supply a value for @var{sym_name}, then this field
37777will be empty.
37778
37779Reply:
37780@table @samp
b8ff78ce 37781@item OK
ff2587ec 37782The target does not need to look up any (more) symbols.
b8ff78ce 37783@item qSymbol:@var{sym_name}
ff2587ec
WZ
37784The target requests the value of a new symbol @var{sym_name} (hex
37785encoded). @value{GDBN} will continue to supply the values of symbols
37786(if available), until the target ceases to request them.
fa93a9d8 37787@end table
0abb7bc7 37788
00bf0b85 37789@item qTBuffer
687e43a4
TT
37790@itemx QTBuffer
37791@itemx QTDisconnected
d5551862 37792@itemx QTDP
409873ef 37793@itemx QTDPsrc
d5551862 37794@itemx QTDV
00bf0b85
SS
37795@itemx qTfP
37796@itemx qTfV
9d29849a 37797@itemx QTFrame
405f8e94
SS
37798@itemx qTMinFTPILen
37799
9d29849a
JB
37800@xref{Tracepoint Packets}.
37801
b90a069a 37802@item qThreadExtraInfo,@var{thread-id}
ff2587ec 37803@cindex thread attributes info, remote request
b8ff78ce
JB
37804@cindex @samp{qThreadExtraInfo} packet
37805Obtain a printable string description of a thread's attributes from
b90a069a
SL
37806the target OS. @var{thread-id} is a thread ID;
37807see @ref{thread-id syntax}. This
b8ff78ce
JB
37808string may contain anything that the target OS thinks is interesting
37809for @value{GDBN} to tell the user about the thread. The string is
37810displayed in @value{GDBN}'s @code{info threads} display. Some
37811examples of possible thread extra info strings are @samp{Runnable}, or
37812@samp{Blocked on Mutex}.
ff2587ec
WZ
37813
37814Reply:
37815@table @samp
b8ff78ce
JB
37816@item @var{XX}@dots{}
37817Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
37818comprising the printable string containing the extra information about
37819the thread's attributes.
ff2587ec 37820@end table
814e32d7 37821
aa56d27a
JB
37822(Note that the @code{qThreadExtraInfo} packet's name is separated from
37823the command by a @samp{,}, not a @samp{:}, contrary to the naming
37824conventions above. Please don't use this packet as a model for new
37825packets.)
37826
f196051f 37827@item QTNotes
687e43a4
TT
37828@itemx qTP
37829@itemx QTSave
37830@itemx qTsP
37831@itemx qTsV
d5551862 37832@itemx QTStart
9d29849a 37833@itemx QTStop
d248b706
KY
37834@itemx QTEnable
37835@itemx QTDisable
9d29849a
JB
37836@itemx QTinit
37837@itemx QTro
37838@itemx qTStatus
d5551862 37839@itemx qTV
0fb4aa4b
PA
37840@itemx qTfSTM
37841@itemx qTsSTM
37842@itemx qTSTMat
9d29849a
JB
37843@xref{Tracepoint Packets}.
37844
0876f84a
DJ
37845@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
37846@cindex read special object, remote request
37847@cindex @samp{qXfer} packet
68437a39 37848@anchor{qXfer read}
0876f84a
DJ
37849Read uninterpreted bytes from the target's special data area
37850identified by the keyword @var{object}. Request @var{length} bytes
37851starting at @var{offset} bytes into the data. The content and
0e7f50da 37852encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
37853additional details about what data to access.
37854
37855Here are the specific requests of this form defined so far. All
37856@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
37857formats, listed below.
37858
37859@table @samp
37860@item qXfer:auxv:read::@var{offset},@var{length}
37861@anchor{qXfer auxiliary vector read}
37862Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 37863auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
37864
37865This packet is not probed by default; the remote stub must request it,
89be2091 37866by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 37867
2ae8c8e7
MM
37868@item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
37869@anchor{qXfer btrace read}
37870
37871Return a description of the current branch trace.
37872@xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
37873packet may have one of the following values:
37874
37875@table @code
37876@item all
37877Returns all available branch trace.
37878
37879@item new
37880Returns all available branch trace if the branch trace changed since
37881the last read request.
37882@end table
37883
37884This packet is not probed by default; the remote stub must request it
37885by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37886
23181151
DJ
37887@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
37888@anchor{qXfer target description read}
37889Access the @dfn{target description}. @xref{Target Descriptions}. The
37890annex specifies which XML document to access. The main description is
37891always loaded from the @samp{target.xml} annex.
37892
37893This packet is not probed by default; the remote stub must request it,
37894by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37895
cfa9d6d9
DJ
37896@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
37897@anchor{qXfer library list read}
37898Access the target's list of loaded libraries. @xref{Library List Format}.
37899The annex part of the generic @samp{qXfer} packet must be empty
37900(@pxref{qXfer read}).
37901
37902Targets which maintain a list of libraries in the program's memory do
37903not need to implement this packet; it is designed for platforms where
37904the operating system manages the list of loaded libraries.
37905
37906This packet is not probed by default; the remote stub must request it,
37907by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37908
2268b414
JK
37909@item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
37910@anchor{qXfer svr4 library list read}
37911Access the target's list of loaded libraries when the target is an SVR4
37912platform. @xref{Library List Format for SVR4 Targets}. The annex part
37913of the generic @samp{qXfer} packet must be empty (@pxref{qXfer read}).
37914
37915This packet is optional for better performance on SVR4 targets.
37916@value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
37917
37918This packet is not probed by default; the remote stub must request it,
37919by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37920
68437a39
DJ
37921@item qXfer:memory-map:read::@var{offset},@var{length}
37922@anchor{qXfer memory map read}
79a6e687 37923Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
37924annex part of the generic @samp{qXfer} packet must be empty
37925(@pxref{qXfer read}).
37926
0e7f50da
UW
37927This packet is not probed by default; the remote stub must request it,
37928by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37929
0fb4aa4b
PA
37930@item qXfer:sdata:read::@var{offset},@var{length}
37931@anchor{qXfer sdata read}
37932
37933Read contents of the extra collected static tracepoint marker
37934information. The annex part of the generic @samp{qXfer} packet must
37935be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
37936Action Lists}.
37937
37938This packet is not probed by default; the remote stub must request it,
37939by supplying an appropriate @samp{qSupported} response
37940(@pxref{qSupported}).
37941
4aa995e1
PA
37942@item qXfer:siginfo:read::@var{offset},@var{length}
37943@anchor{qXfer siginfo read}
37944Read contents of the extra signal information on the target
37945system. The annex part of the generic @samp{qXfer} packet must be
37946empty (@pxref{qXfer read}).
37947
37948This packet is not probed by default; the remote stub must request it,
37949by supplying an appropriate @samp{qSupported} response
37950(@pxref{qSupported}).
37951
0e7f50da
UW
37952@item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
37953@anchor{qXfer spu read}
37954Read contents of an @code{spufs} file on the target system. The
37955annex specifies which file to read; it must be of the form
37956@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
37957in the target process, and @var{name} identifes the @code{spufs} file
37958in that context to be accessed.
37959
68437a39 37960This packet is not probed by default; the remote stub must request it,
07e059b5
VP
37961by supplying an appropriate @samp{qSupported} response
37962(@pxref{qSupported}).
37963
dc146f7c
VP
37964@item qXfer:threads:read::@var{offset},@var{length}
37965@anchor{qXfer threads read}
37966Access the list of threads on target. @xref{Thread List Format}. The
37967annex part of the generic @samp{qXfer} packet must be empty
37968(@pxref{qXfer read}).
37969
37970This packet is not probed by default; the remote stub must request it,
37971by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37972
b3b9301e
PA
37973@item qXfer:traceframe-info:read::@var{offset},@var{length}
37974@anchor{qXfer traceframe info read}
37975
37976Return a description of the current traceframe's contents.
37977@xref{Traceframe Info Format}. The annex part of the generic
37978@samp{qXfer} packet must be empty (@pxref{qXfer read}).
37979
37980This packet is not probed by default; the remote stub must request it,
37981by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37982
169081d0
TG
37983@item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
37984@anchor{qXfer unwind info block}
37985
37986Return the unwind information block for @var{pc}. This packet is used
37987on OpenVMS/ia64 to ask the kernel unwind information.
37988
37989This packet is not probed by default.
37990
78d85199
YQ
37991@item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
37992@anchor{qXfer fdpic loadmap read}
37993Read contents of @code{loadmap}s on the target system. The
37994annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
37995executable @code{loadmap} or interpreter @code{loadmap} to read.
37996
37997This packet is not probed by default; the remote stub must request it,
37998by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37999
07e059b5
VP
38000@item qXfer:osdata:read::@var{offset},@var{length}
38001@anchor{qXfer osdata read}
38002Access the target's @dfn{operating system information}.
38003@xref{Operating System Information}.
38004
68437a39
DJ
38005@end table
38006
0876f84a
DJ
38007Reply:
38008@table @samp
38009@item m @var{data}
38010Data @var{data} (@pxref{Binary Data}) has been read from the
38011target. There may be more data at a higher address (although
38012it is permitted to return @samp{m} even for the last valid
38013block of data, as long as at least one byte of data was read).
38014@var{data} may have fewer bytes than the @var{length} in the
38015request.
38016
38017@item l @var{data}
38018Data @var{data} (@pxref{Binary Data}) has been read from the target.
38019There is no more data to be read. @var{data} may have fewer bytes
38020than the @var{length} in the request.
38021
38022@item l
38023The @var{offset} in the request is at the end of the data.
38024There is no more data to be read.
38025
38026@item E00
38027The request was malformed, or @var{annex} was invalid.
38028
38029@item E @var{nn}
38030The offset was invalid, or there was an error encountered reading the data.
38031@var{nn} is a hex-encoded @code{errno} value.
38032
d57350ea 38033@item @w{}
0876f84a
DJ
38034An empty reply indicates the @var{object} string was not recognized by
38035the stub, or that the object does not support reading.
38036@end table
38037
38038@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
38039@cindex write data into object, remote request
4aa995e1 38040@anchor{qXfer write}
0876f84a
DJ
38041Write uninterpreted bytes into the target's special data area
38042identified by the keyword @var{object}, starting at @var{offset} bytes
0e7f50da 38043into the data. @var{data}@dots{} is the binary-encoded data
0876f84a 38044(@pxref{Binary Data}) to be written. The content and encoding of @var{annex}
0e7f50da 38045is specific to @var{object}; it can supply additional details about what data
0876f84a
DJ
38046to access.
38047
0e7f50da
UW
38048Here are the specific requests of this form defined so far. All
38049@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
38050formats, listed below.
38051
38052@table @samp
4aa995e1
PA
38053@item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
38054@anchor{qXfer siginfo write}
38055Write @var{data} to the extra signal information on the target system.
38056The annex part of the generic @samp{qXfer} packet must be
38057empty (@pxref{qXfer write}).
38058
38059This packet is not probed by default; the remote stub must request it,
38060by supplying an appropriate @samp{qSupported} response
38061(@pxref{qSupported}).
38062
84fcdf95 38063@item qXfer:spu:write:@var{annex}:@var{offset}:@var{data}@dots{}
0e7f50da
UW
38064@anchor{qXfer spu write}
38065Write @var{data} to an @code{spufs} file on the target system. The
38066annex specifies which file to write; it must be of the form
38067@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
38068in the target process, and @var{name} identifes the @code{spufs} file
38069in that context to be accessed.
38070
38071This packet is not probed by default; the remote stub must request it,
38072by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38073@end table
0876f84a
DJ
38074
38075Reply:
38076@table @samp
38077@item @var{nn}
38078@var{nn} (hex encoded) is the number of bytes written.
38079This may be fewer bytes than supplied in the request.
38080
38081@item E00
38082The request was malformed, or @var{annex} was invalid.
38083
38084@item E @var{nn}
38085The offset was invalid, or there was an error encountered writing the data.
38086@var{nn} is a hex-encoded @code{errno} value.
38087
d57350ea 38088@item @w{}
0876f84a
DJ
38089An empty reply indicates the @var{object} string was not
38090recognized by the stub, or that the object does not support writing.
38091@end table
38092
38093@item qXfer:@var{object}:@var{operation}:@dots{}
38094Requests of this form may be added in the future. When a stub does
38095not recognize the @var{object} keyword, or its support for
38096@var{object} does not recognize the @var{operation} keyword, the stub
38097must respond with an empty packet.
38098
0b16c5cf
PA
38099@item qAttached:@var{pid}
38100@cindex query attached, remote request
38101@cindex @samp{qAttached} packet
38102Return an indication of whether the remote server attached to an
38103existing process or created a new process. When the multiprocess
38104protocol extensions are supported (@pxref{multiprocess extensions}),
38105@var{pid} is an integer in hexadecimal format identifying the target
38106process. Otherwise, @value{GDBN} will omit the @var{pid} field and
38107the query packet will be simplified as @samp{qAttached}.
38108
38109This query is used, for example, to know whether the remote process
38110should be detached or killed when a @value{GDBN} session is ended with
38111the @code{quit} command.
38112
38113Reply:
38114@table @samp
38115@item 1
38116The remote server attached to an existing process.
38117@item 0
38118The remote server created a new process.
38119@item E @var{NN}
38120A badly formed request or an error was encountered.
38121@end table
38122
2ae8c8e7
MM
38123@item Qbtrace:bts
38124Enable branch tracing for the current thread using bts tracing.
38125
38126Reply:
38127@table @samp
38128@item OK
38129Branch tracing has been enabled.
38130@item E.errtext
38131A badly formed request or an error was encountered.
38132@end table
38133
38134@item Qbtrace:off
38135Disable branch tracing for the current thread.
38136
38137Reply:
38138@table @samp
38139@item OK
38140Branch tracing has been disabled.
38141@item E.errtext
38142A badly formed request or an error was encountered.
38143@end table
38144
ee2d5c50
AC
38145@end table
38146
a1dcb23a
DJ
38147@node Architecture-Specific Protocol Details
38148@section Architecture-Specific Protocol Details
38149
38150This section describes how the remote protocol is applied to specific
38151target architectures. Also see @ref{Standard Target Features}, for
38152details of XML target descriptions for each architecture.
38153
02b67415
MR
38154@menu
38155* ARM-Specific Protocol Details::
38156* MIPS-Specific Protocol Details::
38157@end menu
38158
38159@node ARM-Specific Protocol Details
38160@subsection @acronym{ARM}-specific Protocol Details
38161
38162@menu
38163* ARM Breakpoint Kinds::
38164@end menu
a1dcb23a 38165
02b67415
MR
38166@node ARM Breakpoint Kinds
38167@subsubsection @acronym{ARM} Breakpoint Kinds
38168@cindex breakpoint kinds, @acronym{ARM}
a1dcb23a
DJ
38169
38170These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
38171
38172@table @r
38173
38174@item 2
3817516-bit Thumb mode breakpoint.
38176
38177@item 3
3817832-bit Thumb mode (Thumb-2) breakpoint.
38179
38180@item 4
02b67415 3818132-bit @acronym{ARM} mode breakpoint.
a1dcb23a
DJ
38182
38183@end table
38184
02b67415
MR
38185@node MIPS-Specific Protocol Details
38186@subsection @acronym{MIPS}-specific Protocol Details
38187
38188@menu
38189* MIPS Register packet Format::
4cc0665f 38190* MIPS Breakpoint Kinds::
02b67415 38191@end menu
a1dcb23a 38192
02b67415
MR
38193@node MIPS Register packet Format
38194@subsubsection @acronym{MIPS} Register Packet Format
eb17f351 38195@cindex register packet format, @acronym{MIPS}
eb12ee30 38196
b8ff78ce 38197The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
38198In the below, some thirty-two bit registers are transferred as
38199sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
38200to fill the space allocated. Register bytes are transferred in target
38201byte order. The two nibbles within a register byte are transferred
02b67415 38202most-significant -- least-significant.
eb12ee30 38203
ee2d5c50 38204@table @r
eb12ee30 38205
8e04817f 38206@item MIPS32
599b237a 38207All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
3820832 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
38209registers; fsr; fir; fp.
eb12ee30 38210
8e04817f 38211@item MIPS64
599b237a 38212All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
38213thirty-two bit registers such as @code{sr}). The ordering is the same
38214as @code{MIPS32}.
eb12ee30 38215
ee2d5c50
AC
38216@end table
38217
4cc0665f
MR
38218@node MIPS Breakpoint Kinds
38219@subsubsection @acronym{MIPS} Breakpoint Kinds
38220@cindex breakpoint kinds, @acronym{MIPS}
38221
38222These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
38223
38224@table @r
38225
38226@item 2
3822716-bit @acronym{MIPS16} mode breakpoint.
38228
38229@item 3
3823016-bit @acronym{microMIPS} mode breakpoint.
38231
38232@item 4
3823332-bit standard @acronym{MIPS} mode breakpoint.
38234
38235@item 5
3823632-bit @acronym{microMIPS} mode breakpoint.
38237
38238@end table
38239
9d29849a
JB
38240@node Tracepoint Packets
38241@section Tracepoint Packets
38242@cindex tracepoint packets
38243@cindex packets, tracepoint
38244
38245Here we describe the packets @value{GDBN} uses to implement
38246tracepoints (@pxref{Tracepoints}).
38247
38248@table @samp
38249
7a697b8d 38250@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
c614397c 38251@cindex @samp{QTDP} packet
9d29849a
JB
38252Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
38253is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
38254the tracepoint is disabled. @var{step} is the tracepoint's step
7a697b8d
SS
38255count, and @var{pass} is its pass count. If an @samp{F} is present,
38256then the tracepoint is to be a fast tracepoint, and the @var{flen} is
38257the number of bytes that the target should copy elsewhere to make room
38258for the tracepoint. If an @samp{X} is present, it introduces a
38259tracepoint condition, which consists of a hexadecimal length, followed
38260by a comma and hex-encoded bytes, in a manner similar to action
38261encodings as described below. If the trailing @samp{-} is present,
38262further @samp{QTDP} packets will follow to specify this tracepoint's
38263actions.
9d29849a
JB
38264
38265Replies:
38266@table @samp
38267@item OK
38268The packet was understood and carried out.
dde08ee1
PA
38269@item qRelocInsn
38270@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 38271@item @w{}
9d29849a
JB
38272The packet was not recognized.
38273@end table
38274
38275@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
38276Define actions to be taken when a tracepoint is hit. @var{n} and
38277@var{addr} must be the same as in the initial @samp{QTDP} packet for
38278this tracepoint. This packet may only be sent immediately after
38279another @samp{QTDP} packet that ended with a @samp{-}. If the
38280trailing @samp{-} is present, further @samp{QTDP} packets will follow,
38281specifying more actions for this tracepoint.
38282
38283In the series of action packets for a given tracepoint, at most one
38284can have an @samp{S} before its first @var{action}. If such a packet
38285is sent, it and the following packets define ``while-stepping''
38286actions. Any prior packets define ordinary actions --- that is, those
38287taken when the tracepoint is first hit. If no action packet has an
38288@samp{S}, then all the packets in the series specify ordinary
38289tracepoint actions.
38290
38291The @samp{@var{action}@dots{}} portion of the packet is a series of
38292actions, concatenated without separators. Each action has one of the
38293following forms:
38294
38295@table @samp
38296
38297@item R @var{mask}
38298Collect the registers whose bits are set in @var{mask}. @var{mask} is
599b237a 38299a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
38300@var{i} should be collected. (The least significant bit is numbered
38301zero.) Note that @var{mask} may be any number of digits long; it may
38302not fit in a 32-bit word.
38303
38304@item M @var{basereg},@var{offset},@var{len}
38305Collect @var{len} bytes of memory starting at the address in register
38306number @var{basereg}, plus @var{offset}. If @var{basereg} is
38307@samp{-1}, then the range has a fixed address: @var{offset} is the
38308address of the lowest byte to collect. The @var{basereg},
599b237a 38309@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
38310values (the @samp{-1} value for @var{basereg} is a special case).
38311
38312@item X @var{len},@var{expr}
38313Evaluate @var{expr}, whose length is @var{len}, and collect memory as
38314it directs. @var{expr} is an agent expression, as described in
38315@ref{Agent Expressions}. Each byte of the expression is encoded as a
38316two-digit hex number in the packet; @var{len} is the number of bytes
38317in the expression (and thus one-half the number of hex digits in the
38318packet).
38319
38320@end table
38321
38322Any number of actions may be packed together in a single @samp{QTDP}
38323packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
38324length (400 bytes, for many stubs). There may be only one @samp{R}
38325action per tracepoint, and it must precede any @samp{M} or @samp{X}
38326actions. Any registers referred to by @samp{M} and @samp{X} actions
38327must be collected by a preceding @samp{R} action. (The
38328``while-stepping'' actions are treated as if they were attached to a
38329separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
38330
38331Replies:
38332@table @samp
38333@item OK
38334The packet was understood and carried out.
dde08ee1
PA
38335@item qRelocInsn
38336@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 38337@item @w{}
9d29849a
JB
38338The packet was not recognized.
38339@end table
38340
409873ef
SS
38341@item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
38342@cindex @samp{QTDPsrc} packet
38343Specify a source string of tracepoint @var{n} at address @var{addr}.
38344This is useful to get accurate reproduction of the tracepoints
38345originally downloaded at the beginning of the trace run. @var{type}
38346is the name of the tracepoint part, such as @samp{cond} for the
38347tracepoint's conditional expression (see below for a list of types), while
38348@var{bytes} is the string, encoded in hexadecimal.
38349
38350@var{start} is the offset of the @var{bytes} within the overall source
38351string, while @var{slen} is the total length of the source string.
38352This is intended for handling source strings that are longer than will
38353fit in a single packet.
38354@c Add detailed example when this info is moved into a dedicated
38355@c tracepoint descriptions section.
38356
38357The available string types are @samp{at} for the location,
38358@samp{cond} for the conditional, and @samp{cmd} for an action command.
38359@value{GDBN} sends a separate packet for each command in the action
38360list, in the same order in which the commands are stored in the list.
38361
38362The target does not need to do anything with source strings except
38363report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
38364query packets.
38365
38366Although this packet is optional, and @value{GDBN} will only send it
38367if the target replies with @samp{TracepointSource} @xref{General
38368Query Packets}, it makes both disconnected tracing and trace files
38369much easier to use. Otherwise the user must be careful that the
38370tracepoints in effect while looking at trace frames are identical to
38371the ones in effect during the trace run; even a small discrepancy
38372could cause @samp{tdump} not to work, or a particular trace frame not
38373be found.
38374
f61e138d
SS
38375@item QTDV:@var{n}:@var{value}
38376@cindex define trace state variable, remote request
38377@cindex @samp{QTDV} packet
38378Create a new trace state variable, number @var{n}, with an initial
38379value of @var{value}, which is a 64-bit signed integer. Both @var{n}
38380and @var{value} are encoded as hexadecimal values. @value{GDBN} has
38381the option of not using this packet for initial values of zero; the
38382target should simply create the trace state variables as they are
38383mentioned in expressions.
38384
9d29849a 38385@item QTFrame:@var{n}
c614397c 38386@cindex @samp{QTFrame} packet
9d29849a
JB
38387Select the @var{n}'th tracepoint frame from the buffer, and use the
38388register and memory contents recorded there to answer subsequent
38389request packets from @value{GDBN}.
38390
38391A successful reply from the stub indicates that the stub has found the
38392requested frame. The response is a series of parts, concatenated
38393without separators, describing the frame we selected. Each part has
38394one of the following forms:
38395
38396@table @samp
38397@item F @var{f}
38398The selected frame is number @var{n} in the trace frame buffer;
599b237a 38399@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
38400was no frame matching the criteria in the request packet.
38401
38402@item T @var{t}
38403The selected trace frame records a hit of tracepoint number @var{t};
599b237a 38404@var{t} is a hexadecimal number.
9d29849a
JB
38405
38406@end table
38407
38408@item QTFrame:pc:@var{addr}
38409Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
38410currently selected frame whose PC is @var{addr};
599b237a 38411@var{addr} is a hexadecimal number.
9d29849a
JB
38412
38413@item QTFrame:tdp:@var{t}
38414Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
38415currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 38416is a hexadecimal number.
9d29849a
JB
38417
38418@item QTFrame:range:@var{start}:@var{end}
38419Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
38420currently selected frame whose PC is between @var{start} (inclusive)
081dfbf7 38421and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
38422numbers.
38423
38424@item QTFrame:outside:@var{start}:@var{end}
38425Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
081dfbf7 38426frame @emph{outside} the given range of addresses (exclusive).
9d29849a 38427
405f8e94 38428@item qTMinFTPILen
c614397c 38429@cindex @samp{qTMinFTPILen} packet
405f8e94
SS
38430This packet requests the minimum length of instruction at which a fast
38431tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
38432the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
38433it depends on the target system being able to create trampolines in
38434the first 64K of memory, which might or might not be possible for that
38435system. So the reply to this packet will be 4 if it is able to
38436arrange for that.
38437
38438Replies:
38439
38440@table @samp
38441@item 0
38442The minimum instruction length is currently unknown.
38443@item @var{length}
38444The minimum instruction length is @var{length}, where @var{length} is greater
38445or equal to 1. @var{length} is a hexadecimal number. A reply of 1 means
38446that a fast tracepoint may be placed on any instruction regardless of size.
38447@item E
38448An error has occurred.
d57350ea 38449@item @w{}
405f8e94
SS
38450An empty reply indicates that the request is not supported by the stub.
38451@end table
38452
9d29849a 38453@item QTStart
c614397c 38454@cindex @samp{QTStart} packet
dde08ee1
PA
38455Begin the tracepoint experiment. Begin collecting data from
38456tracepoint hits in the trace frame buffer. This packet supports the
38457@samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
38458instruction reply packet}).
9d29849a
JB
38459
38460@item QTStop
c614397c 38461@cindex @samp{QTStop} packet
9d29849a
JB
38462End the tracepoint experiment. Stop collecting trace frames.
38463
d248b706
KY
38464@item QTEnable:@var{n}:@var{addr}
38465@anchor{QTEnable}
c614397c 38466@cindex @samp{QTEnable} packet
d248b706
KY
38467Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
38468experiment. If the tracepoint was previously disabled, then collection
38469of data from it will resume.
38470
38471@item QTDisable:@var{n}:@var{addr}
38472@anchor{QTDisable}
c614397c 38473@cindex @samp{QTDisable} packet
d248b706
KY
38474Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
38475experiment. No more data will be collected from the tracepoint unless
38476@samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
38477
9d29849a 38478@item QTinit
c614397c 38479@cindex @samp{QTinit} packet
9d29849a
JB
38480Clear the table of tracepoints, and empty the trace frame buffer.
38481
38482@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
c614397c 38483@cindex @samp{QTro} packet
9d29849a
JB
38484Establish the given ranges of memory as ``transparent''. The stub
38485will answer requests for these ranges from memory's current contents,
38486if they were not collected as part of the tracepoint hit.
38487
38488@value{GDBN} uses this to mark read-only regions of memory, like those
38489containing program code. Since these areas never change, they should
38490still have the same contents they did when the tracepoint was hit, so
38491there's no reason for the stub to refuse to provide their contents.
38492
d5551862 38493@item QTDisconnected:@var{value}
c614397c 38494@cindex @samp{QTDisconnected} packet
d5551862
SS
38495Set the choice to what to do with the tracing run when @value{GDBN}
38496disconnects from the target. A @var{value} of 1 directs the target to
38497continue the tracing run, while 0 tells the target to stop tracing if
38498@value{GDBN} is no longer in the picture.
38499
9d29849a 38500@item qTStatus
c614397c 38501@cindex @samp{qTStatus} packet
9d29849a
JB
38502Ask the stub if there is a trace experiment running right now.
38503
4daf5ac0
SS
38504The reply has the form:
38505
38506@table @samp
38507
38508@item T@var{running}@r{[};@var{field}@r{]}@dots{}
38509@var{running} is a single digit @code{1} if the trace is presently
38510running, or @code{0} if not. It is followed by semicolon-separated
38511optional fields that an agent may use to report additional status.
38512
38513@end table
38514
38515If the trace is not running, the agent may report any of several
38516explanations as one of the optional fields:
38517
38518@table @samp
38519
38520@item tnotrun:0
38521No trace has been run yet.
38522
f196051f
SS
38523@item tstop[:@var{text}]:0
38524The trace was stopped by a user-originated stop command. The optional
38525@var{text} field is a user-supplied string supplied as part of the
38526stop command (for instance, an explanation of why the trace was
38527stopped manually). It is hex-encoded.
4daf5ac0
SS
38528
38529@item tfull:0
38530The trace stopped because the trace buffer filled up.
38531
38532@item tdisconnected:0
38533The trace stopped because @value{GDBN} disconnected from the target.
38534
38535@item tpasscount:@var{tpnum}
38536The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
38537
6c28cbf2
SS
38538@item terror:@var{text}:@var{tpnum}
38539The trace stopped because tracepoint @var{tpnum} had an error. The
38540string @var{text} is available to describe the nature of the error
38541(for instance, a divide by zero in the condition expression).
99b5e152 38542@var{text} is hex encoded.
6c28cbf2 38543
4daf5ac0
SS
38544@item tunknown:0
38545The trace stopped for some other reason.
38546
38547@end table
38548
33da3f1c
SS
38549Additional optional fields supply statistical and other information.
38550Although not required, they are extremely useful for users monitoring
38551the progress of a trace run. If a trace has stopped, and these
38552numbers are reported, they must reflect the state of the just-stopped
38553trace.
4daf5ac0 38554
9d29849a 38555@table @samp
4daf5ac0
SS
38556
38557@item tframes:@var{n}
38558The number of trace frames in the buffer.
38559
38560@item tcreated:@var{n}
38561The total number of trace frames created during the run. This may
38562be larger than the trace frame count, if the buffer is circular.
38563
38564@item tsize:@var{n}
38565The total size of the trace buffer, in bytes.
38566
38567@item tfree:@var{n}
38568The number of bytes still unused in the buffer.
38569
33da3f1c
SS
38570@item circular:@var{n}
38571The value of the circular trace buffer flag. @code{1} means that the
38572trace buffer is circular and old trace frames will be discarded if
38573necessary to make room, @code{0} means that the trace buffer is linear
38574and may fill up.
38575
38576@item disconn:@var{n}
38577The value of the disconnected tracing flag. @code{1} means that
38578tracing will continue after @value{GDBN} disconnects, @code{0} means
38579that the trace run will stop.
38580
9d29849a
JB
38581@end table
38582
f196051f
SS
38583@item qTP:@var{tp}:@var{addr}
38584@cindex tracepoint status, remote request
38585@cindex @samp{qTP} packet
38586Ask the stub for the current state of tracepoint number @var{tp} at
38587address @var{addr}.
38588
38589Replies:
38590@table @samp
38591@item V@var{hits}:@var{usage}
38592The tracepoint has been hit @var{hits} times so far during the trace
38593run, and accounts for @var{usage} in the trace buffer. Note that
38594@code{while-stepping} steps are not counted as separate hits, but the
38595steps' space consumption is added into the usage number.
38596
38597@end table
38598
f61e138d
SS
38599@item qTV:@var{var}
38600@cindex trace state variable value, remote request
38601@cindex @samp{qTV} packet
38602Ask the stub for the value of the trace state variable number @var{var}.
38603
38604Replies:
38605@table @samp
38606@item V@var{value}
38607The value of the variable is @var{value}. This will be the current
38608value of the variable if the user is examining a running target, or a
38609saved value if the variable was collected in the trace frame that the
38610user is looking at. Note that multiple requests may result in
38611different reply values, such as when requesting values while the
38612program is running.
38613
38614@item U
38615The value of the variable is unknown. This would occur, for example,
38616if the user is examining a trace frame in which the requested variable
38617was not collected.
9d29849a
JB
38618@end table
38619
d5551862 38620@item qTfP
c614397c 38621@cindex @samp{qTfP} packet
d5551862 38622@itemx qTsP
c614397c 38623@cindex @samp{qTsP} packet
d5551862
SS
38624These packets request data about tracepoints that are being used by
38625the target. @value{GDBN} sends @code{qTfP} to get the first piece
38626of data, and multiple @code{qTsP} to get additional pieces. Replies
38627to these packets generally take the form of the @code{QTDP} packets
38628that define tracepoints. (FIXME add detailed syntax)
38629
00bf0b85 38630@item qTfV
c614397c 38631@cindex @samp{qTfV} packet
00bf0b85 38632@itemx qTsV
c614397c 38633@cindex @samp{qTsV} packet
00bf0b85
SS
38634These packets request data about trace state variables that are on the
38635target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
38636and multiple @code{qTsV} to get additional variables. Replies to
38637these packets follow the syntax of the @code{QTDV} packets that define
38638trace state variables.
38639
0fb4aa4b
PA
38640@item qTfSTM
38641@itemx qTsSTM
16bdd41f
YQ
38642@anchor{qTfSTM}
38643@anchor{qTsSTM}
c614397c
YQ
38644@cindex @samp{qTfSTM} packet
38645@cindex @samp{qTsSTM} packet
0fb4aa4b
PA
38646These packets request data about static tracepoint markers that exist
38647in the target program. @value{GDBN} sends @code{qTfSTM} to get the
38648first piece of data, and multiple @code{qTsSTM} to get additional
38649pieces. Replies to these packets take the following form:
38650
38651Reply:
38652@table @samp
38653@item m @var{address}:@var{id}:@var{extra}
38654A single marker
38655@item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
38656a comma-separated list of markers
38657@item l
38658(lower case letter @samp{L}) denotes end of list.
38659@item E @var{nn}
38660An error occurred. @var{nn} are hex digits.
d57350ea 38661@item @w{}
0fb4aa4b
PA
38662An empty reply indicates that the request is not supported by the
38663stub.
38664@end table
38665
38666@var{address} is encoded in hex.
38667@var{id} and @var{extra} are strings encoded in hex.
38668
38669In response to each query, the target will reply with a list of one or
38670more markers, separated by commas. @value{GDBN} will respond to each
38671reply with a request for more markers (using the @samp{qs} form of the
38672query), until the target responds with @samp{l} (lower-case ell, for
38673@dfn{last}).
38674
38675@item qTSTMat:@var{address}
16bdd41f 38676@anchor{qTSTMat}
c614397c 38677@cindex @samp{qTSTMat} packet
0fb4aa4b
PA
38678This packets requests data about static tracepoint markers in the
38679target program at @var{address}. Replies to this packet follow the
38680syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
38681tracepoint markers.
38682
00bf0b85 38683@item QTSave:@var{filename}
c614397c 38684@cindex @samp{QTSave} packet
00bf0b85
SS
38685This packet directs the target to save trace data to the file name
38686@var{filename} in the target's filesystem. @var{filename} is encoded
38687as a hex string; the interpretation of the file name (relative vs
38688absolute, wild cards, etc) is up to the target.
38689
38690@item qTBuffer:@var{offset},@var{len}
c614397c 38691@cindex @samp{qTBuffer} packet
00bf0b85
SS
38692Return up to @var{len} bytes of the current contents of trace buffer,
38693starting at @var{offset}. The trace buffer is treated as if it were
38694a contiguous collection of traceframes, as per the trace file format.
38695The reply consists as many hex-encoded bytes as the target can deliver
38696in a packet; it is not an error to return fewer than were asked for.
38697A reply consisting of just @code{l} indicates that no bytes are
38698available.
38699
4daf5ac0
SS
38700@item QTBuffer:circular:@var{value}
38701This packet directs the target to use a circular trace buffer if
38702@var{value} is 1, or a linear buffer if the value is 0.
38703
f6f899bf 38704@item QTBuffer:size:@var{size}
28abe188
EZ
38705@anchor{QTBuffer-size}
38706@cindex @samp{QTBuffer size} packet
f6f899bf
HAQ
38707This packet directs the target to make the trace buffer be of size
38708@var{size} if possible. A value of @code{-1} tells the target to
38709use whatever size it prefers.
38710
f196051f 38711@item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
c614397c 38712@cindex @samp{QTNotes} packet
f196051f
SS
38713This packet adds optional textual notes to the trace run. Allowable
38714types include @code{user}, @code{notes}, and @code{tstop}, the
38715@var{text} fields are arbitrary strings, hex-encoded.
38716
f61e138d 38717@end table
9d29849a 38718
dde08ee1
PA
38719@subsection Relocate instruction reply packet
38720When installing fast tracepoints in memory, the target may need to
38721relocate the instruction currently at the tracepoint address to a
38722different address in memory. For most instructions, a simple copy is
38723enough, but, for example, call instructions that implicitly push the
38724return address on the stack, and relative branches or other
38725PC-relative instructions require offset adjustment, so that the effect
38726of executing the instruction at a different address is the same as if
38727it had executed in the original location.
38728
38729In response to several of the tracepoint packets, the target may also
38730respond with a number of intermediate @samp{qRelocInsn} request
38731packets before the final result packet, to have @value{GDBN} handle
38732this relocation operation. If a packet supports this mechanism, its
38733documentation will explicitly say so. See for example the above
38734descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
38735format of the request is:
38736
38737@table @samp
38738@item qRelocInsn:@var{from};@var{to}
38739
38740This requests @value{GDBN} to copy instruction at address @var{from}
38741to address @var{to}, possibly adjusted so that executing the
38742instruction at @var{to} has the same effect as executing it at
38743@var{from}. @value{GDBN} writes the adjusted instruction to target
38744memory starting at @var{to}.
38745@end table
38746
38747Replies:
38748@table @samp
38749@item qRelocInsn:@var{adjusted_size}
38750Informs the stub the relocation is complete. @var{adjusted_size} is
38751the length in bytes of resulting relocated instruction sequence.
38752@item E @var{NN}
38753A badly formed request was detected, or an error was encountered while
38754relocating the instruction.
38755@end table
38756
a6b151f1
DJ
38757@node Host I/O Packets
38758@section Host I/O Packets
38759@cindex Host I/O, remote protocol
38760@cindex file transfer, remote protocol
38761
38762The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
38763operations on the far side of a remote link. For example, Host I/O is
38764used to upload and download files to a remote target with its own
38765filesystem. Host I/O uses the same constant values and data structure
38766layout as the target-initiated File-I/O protocol. However, the
38767Host I/O packets are structured differently. The target-initiated
38768protocol relies on target memory to store parameters and buffers.
38769Host I/O requests are initiated by @value{GDBN}, and the
38770target's memory is not involved. @xref{File-I/O Remote Protocol
38771Extension}, for more details on the target-initiated protocol.
38772
38773The Host I/O request packets all encode a single operation along with
38774its arguments. They have this format:
38775
38776@table @samp
38777
38778@item vFile:@var{operation}: @var{parameter}@dots{}
38779@var{operation} is the name of the particular request; the target
38780should compare the entire packet name up to the second colon when checking
38781for a supported operation. The format of @var{parameter} depends on
38782the operation. Numbers are always passed in hexadecimal. Negative
38783numbers have an explicit minus sign (i.e.@: two's complement is not
38784used). Strings (e.g.@: filenames) are encoded as a series of
38785hexadecimal bytes. The last argument to a system call may be a
38786buffer of escaped binary data (@pxref{Binary Data}).
38787
38788@end table
38789
38790The valid responses to Host I/O packets are:
38791
38792@table @samp
38793
38794@item F @var{result} [, @var{errno}] [; @var{attachment}]
38795@var{result} is the integer value returned by this operation, usually
38796non-negative for success and -1 for errors. If an error has occured,
38797@var{errno} will be included in the result. @var{errno} will have a
38798value defined by the File-I/O protocol (@pxref{Errno Values}). For
38799operations which return data, @var{attachment} supplies the data as a
38800binary buffer. Binary buffers in response packets are escaped in the
38801normal way (@pxref{Binary Data}). See the individual packet
38802documentation for the interpretation of @var{result} and
38803@var{attachment}.
38804
d57350ea 38805@item @w{}
a6b151f1
DJ
38806An empty response indicates that this operation is not recognized.
38807
38808@end table
38809
38810These are the supported Host I/O operations:
38811
38812@table @samp
38813@item vFile:open: @var{pathname}, @var{flags}, @var{mode}
38814Open a file at @var{pathname} and return a file descriptor for it, or
38815return -1 if an error occurs. @var{pathname} is a string,
38816@var{flags} is an integer indicating a mask of open flags
38817(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
38818of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 38819@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
38820
38821@item vFile:close: @var{fd}
38822Close the open file corresponding to @var{fd} and return 0, or
38823-1 if an error occurs.
38824
38825@item vFile:pread: @var{fd}, @var{count}, @var{offset}
38826Read data from the open file corresponding to @var{fd}. Up to
38827@var{count} bytes will be read from the file, starting at @var{offset}
38828relative to the start of the file. The target may read fewer bytes;
38829common reasons include packet size limits and an end-of-file
38830condition. The number of bytes read is returned. Zero should only be
38831returned for a successful read at the end of the file, or if
38832@var{count} was zero.
38833
38834The data read should be returned as a binary attachment on success.
38835If zero bytes were read, the response should include an empty binary
38836attachment (i.e.@: a trailing semicolon). The return value is the
38837number of target bytes read; the binary attachment may be longer if
38838some characters were escaped.
38839
38840@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
38841Write @var{data} (a binary buffer) to the open file corresponding
38842to @var{fd}. Start the write at @var{offset} from the start of the
38843file. Unlike many @code{write} system calls, there is no
38844separate @var{count} argument; the length of @var{data} in the
38845packet is used. @samp{vFile:write} returns the number of bytes written,
38846which may be shorter than the length of @var{data}, or -1 if an
38847error occurred.
38848
38849@item vFile:unlink: @var{pathname}
38850Delete the file at @var{pathname} on the target. Return 0,
38851or -1 if an error occurs. @var{pathname} is a string.
38852
b9e7b9c3
UW
38853@item vFile:readlink: @var{filename}
38854Read value of symbolic link @var{filename} on the target. Return
38855the number of bytes read, or -1 if an error occurs.
38856
38857The data read should be returned as a binary attachment on success.
38858If zero bytes were read, the response should include an empty binary
38859attachment (i.e.@: a trailing semicolon). The return value is the
38860number of target bytes read; the binary attachment may be longer if
38861some characters were escaped.
38862
a6b151f1
DJ
38863@end table
38864
9a6253be
KB
38865@node Interrupts
38866@section Interrupts
38867@cindex interrupts (remote protocol)
38868
38869When a program on the remote target is running, @value{GDBN} may
9a7071a8
JB
38870attempt to interrupt it by sending a @samp{Ctrl-C}, @code{BREAK} or
38871a @code{BREAK} followed by @code{g},
38872control of which is specified via @value{GDBN}'s @samp{interrupt-sequence}.
9a6253be
KB
38873
38874The precise meaning of @code{BREAK} is defined by the transport
8775bb90
MS
38875mechanism and may, in fact, be undefined. @value{GDBN} does not
38876currently define a @code{BREAK} mechanism for any of the network
38877interfaces except for TCP, in which case @value{GDBN} sends the
38878@code{telnet} BREAK sequence.
9a6253be
KB
38879
38880@samp{Ctrl-C}, on the other hand, is defined and implemented for all
38881transport mechanisms. It is represented by sending the single byte
38882@code{0x03} without any of the usual packet overhead described in
38883the Overview section (@pxref{Overview}). When a @code{0x03} byte is
38884transmitted as part of a packet, it is considered to be packet data
38885and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 38886(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
38887@code{0x03} as part of its packet.
38888
9a7071a8
JB
38889@code{BREAK} followed by @code{g} is also known as Magic SysRq g.
38890When Linux kernel receives this sequence from serial port,
38891it stops execution and connects to gdb.
38892
9a6253be
KB
38893Stubs are not required to recognize these interrupt mechanisms and the
38894precise meaning associated with receipt of the interrupt is
8b23ecc4
SL
38895implementation defined. If the target supports debugging of multiple
38896threads and/or processes, it should attempt to interrupt all
38897currently-executing threads and processes.
38898If the stub is successful at interrupting the
38899running program, it should send one of the stop
38900reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
38901of successfully stopping the program in all-stop mode, and a stop reply
38902for each stopped thread in non-stop mode.
38903Interrupts received while the
38904program is stopped are discarded.
38905
38906@node Notification Packets
38907@section Notification Packets
38908@cindex notification packets
38909@cindex packets, notification
38910
38911The @value{GDBN} remote serial protocol includes @dfn{notifications},
38912packets that require no acknowledgment. Both the GDB and the stub
38913may send notifications (although the only notifications defined at
38914present are sent by the stub). Notifications carry information
38915without incurring the round-trip latency of an acknowledgment, and so
38916are useful for low-impact communications where occasional packet loss
38917is not a problem.
38918
38919A notification packet has the form @samp{% @var{data} #
38920@var{checksum}}, where @var{data} is the content of the notification,
38921and @var{checksum} is a checksum of @var{data}, computed and formatted
38922as for ordinary @value{GDBN} packets. A notification's @var{data}
38923never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
38924receiving a notification, the recipient sends no @samp{+} or @samp{-}
38925to acknowledge the notification's receipt or to report its corruption.
38926
38927Every notification's @var{data} begins with a name, which contains no
38928colon characters, followed by a colon character.
38929
38930Recipients should silently ignore corrupted notifications and
38931notifications they do not understand. Recipients should restart
38932timeout periods on receipt of a well-formed notification, whether or
38933not they understand it.
38934
38935Senders should only send the notifications described here when this
38936protocol description specifies that they are permitted. In the
38937future, we may extend the protocol to permit existing notifications in
38938new contexts; this rule helps older senders avoid confusing newer
38939recipients.
38940
38941(Older versions of @value{GDBN} ignore bytes received until they see
38942the @samp{$} byte that begins an ordinary packet, so new stubs may
38943transmit notifications without fear of confusing older clients. There
38944are no notifications defined for @value{GDBN} to send at the moment, but we
38945assume that most older stubs would ignore them, as well.)
38946
8dbe8ece 38947Each notification is comprised of three parts:
8b23ecc4 38948@table @samp
8dbe8ece
YQ
38949@item @var{name}:@var{event}
38950The notification packet is sent by the side that initiates the
38951exchange (currently, only the stub does that), with @var{event}
38952carrying the specific information about the notification.
38953@var{name} is the name of the notification.
38954@item @var{ack}
38955The acknowledge sent by the other side, usually @value{GDBN}, to
38956acknowledge the exchange and request the event.
38957@end table
38958
38959The purpose of an asynchronous notification mechanism is to report to
38960@value{GDBN} that something interesting happened in the remote stub.
38961
38962The remote stub may send notification @var{name}:@var{event}
38963at any time, but @value{GDBN} acknowledges the notification when
38964appropriate. The notification event is pending before @value{GDBN}
38965acknowledges. Only one notification at a time may be pending; if
38966additional events occur before @value{GDBN} has acknowledged the
38967previous notification, they must be queued by the stub for later
38968synchronous transmission in response to @var{ack} packets from
38969@value{GDBN}. Because the notification mechanism is unreliable,
38970the stub is permitted to resend a notification if it believes
38971@value{GDBN} may not have received it.
38972
38973Specifically, notifications may appear when @value{GDBN} is not
38974otherwise reading input from the stub, or when @value{GDBN} is
38975expecting to read a normal synchronous response or a
38976@samp{+}/@samp{-} acknowledgment to a packet it has sent.
38977Notification packets are distinct from any other communication from
38978the stub so there is no ambiguity.
38979
38980After receiving a notification, @value{GDBN} shall acknowledge it by
38981sending a @var{ack} packet as a regular, synchronous request to the
38982stub. Such acknowledgment is not required to happen immediately, as
38983@value{GDBN} is permitted to send other, unrelated packets to the
38984stub first, which the stub should process normally.
38985
38986Upon receiving a @var{ack} packet, if the stub has other queued
38987events to report to @value{GDBN}, it shall respond by sending a
38988normal @var{event}. @value{GDBN} shall then send another @var{ack}
38989packet to solicit further responses; again, it is permitted to send
38990other, unrelated packets as well which the stub should process
38991normally.
38992
38993If the stub receives a @var{ack} packet and there are no additional
38994@var{event} to report, the stub shall return an @samp{OK} response.
38995At this point, @value{GDBN} has finished processing a notification
38996and the stub has completed sending any queued events. @value{GDBN}
38997won't accept any new notifications until the final @samp{OK} is
38998received . If further notification events occur, the stub shall send
38999a new notification, @value{GDBN} shall accept the notification, and
39000the process shall be repeated.
39001
39002The process of asynchronous notification can be illustrated by the
39003following example:
39004@smallexample
39005<- @code{%%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
39006@code{...}
39007-> @code{vStopped}
39008<- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
39009-> @code{vStopped}
39010<- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
39011-> @code{vStopped}
39012<- @code{OK}
39013@end smallexample
39014
39015The following notifications are defined:
39016@multitable @columnfractions 0.12 0.12 0.38 0.38
39017
39018@item Notification
39019@tab Ack
39020@tab Event
39021@tab Description
39022
39023@item Stop
39024@tab vStopped
39025@tab @var{reply}. The @var{reply} has the form of a stop reply, as
8b23ecc4
SL
39026described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
39027for information on how these notifications are acknowledged by
39028@value{GDBN}.
8dbe8ece
YQ
39029@tab Report an asynchronous stop event in non-stop mode.
39030
39031@end multitable
8b23ecc4
SL
39032
39033@node Remote Non-Stop
39034@section Remote Protocol Support for Non-Stop Mode
39035
39036@value{GDBN}'s remote protocol supports non-stop debugging of
39037multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
39038supports non-stop mode, it should report that to @value{GDBN} by including
39039@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
39040
39041@value{GDBN} typically sends a @samp{QNonStop} packet only when
39042establishing a new connection with the stub. Entering non-stop mode
39043does not alter the state of any currently-running threads, but targets
39044must stop all threads in any already-attached processes when entering
39045all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
39046probe the target state after a mode change.
39047
39048In non-stop mode, when an attached process encounters an event that
39049would otherwise be reported with a stop reply, it uses the
39050asynchronous notification mechanism (@pxref{Notification Packets}) to
39051inform @value{GDBN}. In contrast to all-stop mode, where all threads
39052in all processes are stopped when a stop reply is sent, in non-stop
39053mode only the thread reporting the stop event is stopped. That is,
39054when reporting a @samp{S} or @samp{T} response to indicate completion
39055of a step operation, hitting a breakpoint, or a fault, only the
39056affected thread is stopped; any other still-running threads continue
39057to run. When reporting a @samp{W} or @samp{X} response, all running
39058threads belonging to other attached processes continue to run.
39059
8b23ecc4
SL
39060In non-stop mode, the target shall respond to the @samp{?} packet as
39061follows. First, any incomplete stop reply notification/@samp{vStopped}
39062sequence in progress is abandoned. The target must begin a new
39063sequence reporting stop events for all stopped threads, whether or not
39064it has previously reported those events to @value{GDBN}. The first
39065stop reply is sent as a synchronous reply to the @samp{?} packet, and
39066subsequent stop replies are sent as responses to @samp{vStopped} packets
39067using the mechanism described above. The target must not send
39068asynchronous stop reply notifications until the sequence is complete.
39069If all threads are running when the target receives the @samp{?} packet,
39070or if the target is not attached to any process, it shall respond
39071@samp{OK}.
9a6253be 39072
a6f3e723
SL
39073@node Packet Acknowledgment
39074@section Packet Acknowledgment
39075
39076@cindex acknowledgment, for @value{GDBN} remote
39077@cindex packet acknowledgment, for @value{GDBN} remote
39078By default, when either the host or the target machine receives a packet,
39079the first response expected is an acknowledgment: either @samp{+} (to indicate
39080the package was received correctly) or @samp{-} (to request retransmission).
39081This mechanism allows the @value{GDBN} remote protocol to operate over
39082unreliable transport mechanisms, such as a serial line.
39083
39084In cases where the transport mechanism is itself reliable (such as a pipe or
39085TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
39086It may be desirable to disable them in that case to reduce communication
39087overhead, or for other reasons. This can be accomplished by means of the
39088@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
39089
39090When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
39091expect @samp{+}/@samp{-} protocol acknowledgments. The packet
39092and response format still includes the normal checksum, as described in
39093@ref{Overview}, but the checksum may be ignored by the receiver.
39094
39095If the stub supports @samp{QStartNoAckMode} and prefers to operate in
39096no-acknowledgment mode, it should report that to @value{GDBN}
39097by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
39098@pxref{qSupported}.
39099If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
39100disabled via the @code{set remote noack-packet off} command
39101(@pxref{Remote Configuration}),
39102@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
39103Only then may the stub actually turn off packet acknowledgments.
39104@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
39105response, which can be safely ignored by the stub.
39106
39107Note that @code{set remote noack-packet} command only affects negotiation
39108between @value{GDBN} and the stub when subsequent connections are made;
39109it does not affect the protocol acknowledgment state for any current
39110connection.
39111Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
39112new connection is established,
39113there is also no protocol request to re-enable the acknowledgments
39114for the current connection, once disabled.
39115
ee2d5c50
AC
39116@node Examples
39117@section Examples
eb12ee30 39118
8e04817f
AC
39119Example sequence of a target being re-started. Notice how the restart
39120does not get any direct output:
eb12ee30 39121
474c8240 39122@smallexample
d2c6833e
AC
39123-> @code{R00}
39124<- @code{+}
8e04817f 39125@emph{target restarts}
d2c6833e 39126-> @code{?}
8e04817f 39127<- @code{+}
d2c6833e
AC
39128<- @code{T001:1234123412341234}
39129-> @code{+}
474c8240 39130@end smallexample
eb12ee30 39131
8e04817f 39132Example sequence of a target being stepped by a single instruction:
eb12ee30 39133
474c8240 39134@smallexample
d2c6833e 39135-> @code{G1445@dots{}}
8e04817f 39136<- @code{+}
d2c6833e
AC
39137-> @code{s}
39138<- @code{+}
39139@emph{time passes}
39140<- @code{T001:1234123412341234}
8e04817f 39141-> @code{+}
d2c6833e 39142-> @code{g}
8e04817f 39143<- @code{+}
d2c6833e
AC
39144<- @code{1455@dots{}}
39145-> @code{+}
474c8240 39146@end smallexample
eb12ee30 39147
79a6e687
BW
39148@node File-I/O Remote Protocol Extension
39149@section File-I/O Remote Protocol Extension
0ce1b118
CV
39150@cindex File-I/O remote protocol extension
39151
39152@menu
39153* File-I/O Overview::
79a6e687
BW
39154* Protocol Basics::
39155* The F Request Packet::
39156* The F Reply Packet::
39157* The Ctrl-C Message::
0ce1b118 39158* Console I/O::
79a6e687 39159* List of Supported Calls::
db2e3e2e 39160* Protocol-specific Representation of Datatypes::
0ce1b118
CV
39161* Constants::
39162* File-I/O Examples::
39163@end menu
39164
39165@node File-I/O Overview
39166@subsection File-I/O Overview
39167@cindex file-i/o overview
39168
9c16f35a 39169The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 39170target to use the host's file system and console I/O to perform various
0ce1b118 39171system calls. System calls on the target system are translated into a
fc320d37
SL
39172remote protocol packet to the host system, which then performs the needed
39173actions and returns a response packet to the target system.
0ce1b118
CV
39174This simulates file system operations even on targets that lack file systems.
39175
fc320d37
SL
39176The protocol is defined to be independent of both the host and target systems.
39177It uses its own internal representation of datatypes and values. Both
0ce1b118 39178@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
39179translating the system-dependent value representations into the internal
39180protocol representations when data is transmitted.
0ce1b118 39181
fc320d37
SL
39182The communication is synchronous. A system call is possible only when
39183@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
39184or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 39185the target is stopped to allow deterministic access to the target's
fc320d37
SL
39186memory. Therefore File-I/O is not interruptible by target signals. On
39187the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 39188(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
39189
39190The target's request to perform a host system call does not finish
39191the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
39192after finishing the system call, the target returns to continuing the
39193previous activity (continue, step). No additional continue or step
39194request from @value{GDBN} is required.
39195
39196@smallexample
f7dc1244 39197(@value{GDBP}) continue
0ce1b118
CV
39198 <- target requests 'system call X'
39199 target is stopped, @value{GDBN} executes system call
3f94c067
BW
39200 -> @value{GDBN} returns result
39201 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
39202 <- target hits breakpoint and sends a Txx packet
39203@end smallexample
39204
fc320d37
SL
39205The protocol only supports I/O on the console and to regular files on
39206the host file system. Character or block special devices, pipes,
39207named pipes, sockets or any other communication method on the host
0ce1b118
CV
39208system are not supported by this protocol.
39209
8b23ecc4
SL
39210File I/O is not supported in non-stop mode.
39211
79a6e687
BW
39212@node Protocol Basics
39213@subsection Protocol Basics
0ce1b118
CV
39214@cindex protocol basics, file-i/o
39215
fc320d37
SL
39216The File-I/O protocol uses the @code{F} packet as the request as well
39217as reply packet. Since a File-I/O system call can only occur when
39218@value{GDBN} is waiting for a response from the continuing or stepping target,
39219the File-I/O request is a reply that @value{GDBN} has to expect as a result
39220of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
39221This @code{F} packet contains all information needed to allow @value{GDBN}
39222to call the appropriate host system call:
39223
39224@itemize @bullet
b383017d 39225@item
0ce1b118
CV
39226A unique identifier for the requested system call.
39227
39228@item
39229All parameters to the system call. Pointers are given as addresses
39230in the target memory address space. Pointers to strings are given as
b383017d 39231pointer/length pair. Numerical values are given as they are.
db2e3e2e 39232Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
39233
39234@end itemize
39235
fc320d37 39236At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
39237
39238@itemize @bullet
b383017d 39239@item
fc320d37
SL
39240If the parameters include pointer values to data needed as input to a
39241system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
39242standard @code{m} packet request. This additional communication has to be
39243expected by the target implementation and is handled as any other @code{m}
39244packet.
39245
39246@item
39247@value{GDBN} translates all value from protocol representation to host
39248representation as needed. Datatypes are coerced into the host types.
39249
39250@item
fc320d37 39251@value{GDBN} calls the system call.
0ce1b118
CV
39252
39253@item
39254It then coerces datatypes back to protocol representation.
39255
39256@item
fc320d37
SL
39257If the system call is expected to return data in buffer space specified
39258by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
39259target using a @code{M} or @code{X} packet. This packet has to be expected
39260by the target implementation and is handled as any other @code{M} or @code{X}
39261packet.
39262
39263@end itemize
39264
39265Eventually @value{GDBN} replies with another @code{F} packet which contains all
39266necessary information for the target to continue. This at least contains
39267
39268@itemize @bullet
39269@item
39270Return value.
39271
39272@item
39273@code{errno}, if has been changed by the system call.
39274
39275@item
39276``Ctrl-C'' flag.
39277
39278@end itemize
39279
39280After having done the needed type and value coercion, the target continues
39281the latest continue or step action.
39282
79a6e687
BW
39283@node The F Request Packet
39284@subsection The @code{F} Request Packet
0ce1b118
CV
39285@cindex file-i/o request packet
39286@cindex @code{F} request packet
39287
39288The @code{F} request packet has the following format:
39289
39290@table @samp
fc320d37 39291@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
39292
39293@var{call-id} is the identifier to indicate the host system call to be called.
39294This is just the name of the function.
39295
fc320d37
SL
39296@var{parameter@dots{}} are the parameters to the system call.
39297Parameters are hexadecimal integer values, either the actual values in case
39298of scalar datatypes, pointers to target buffer space in case of compound
39299datatypes and unspecified memory areas, or pointer/length pairs in case
39300of string parameters. These are appended to the @var{call-id} as a
39301comma-delimited list. All values are transmitted in ASCII
39302string representation, pointer/length pairs separated by a slash.
0ce1b118 39303
b383017d 39304@end table
0ce1b118 39305
fc320d37 39306
0ce1b118 39307
79a6e687
BW
39308@node The F Reply Packet
39309@subsection The @code{F} Reply Packet
0ce1b118
CV
39310@cindex file-i/o reply packet
39311@cindex @code{F} reply packet
39312
39313The @code{F} reply packet has the following format:
39314
39315@table @samp
39316
d3bdde98 39317@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
39318
39319@var{retcode} is the return code of the system call as hexadecimal value.
39320
db2e3e2e
BW
39321@var{errno} is the @code{errno} set by the call, in protocol-specific
39322representation.
0ce1b118
CV
39323This parameter can be omitted if the call was successful.
39324
fc320d37
SL
39325@var{Ctrl-C flag} is only sent if the user requested a break. In this
39326case, @var{errno} must be sent as well, even if the call was successful.
39327The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
39328
39329@smallexample
39330F0,0,C
39331@end smallexample
39332
39333@noindent
fc320d37 39334or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
39335
39336@smallexample
39337F-1,4,C
39338@end smallexample
39339
39340@noindent
db2e3e2e 39341assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
39342
39343@end table
39344
0ce1b118 39345
79a6e687
BW
39346@node The Ctrl-C Message
39347@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
39348@cindex ctrl-c message, in file-i/o protocol
39349
c8aa23ab 39350If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 39351reply packet (@pxref{The F Reply Packet}),
fc320d37 39352the target should behave as if it had
0ce1b118 39353gotten a break message. The meaning for the target is ``system call
fc320d37 39354interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 39355(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 39356packet.
fc320d37
SL
39357
39358It's important for the target to know in which
39359state the system call was interrupted. There are two possible cases:
0ce1b118
CV
39360
39361@itemize @bullet
39362@item
39363The system call hasn't been performed on the host yet.
39364
39365@item
39366The system call on the host has been finished.
39367
39368@end itemize
39369
39370These two states can be distinguished by the target by the value of the
39371returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
39372call hasn't been performed. This is equivalent to the @code{EINTR} handling
39373on POSIX systems. In any other case, the target may presume that the
fc320d37 39374system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
39375as if the break message arrived right after the system call.
39376
fc320d37 39377@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
39378yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
39379@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
39380before the user requests a break, the full action must be finished by
39381@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
39382The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
39383or the full action has been completed.
39384
39385@node Console I/O
39386@subsection Console I/O
39387@cindex console i/o as part of file-i/o
39388
d3e8051b 39389By default and if not explicitly closed by the target system, the file
0ce1b118
CV
39390descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
39391on the @value{GDBN} console is handled as any other file output operation
39392(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
39393by @value{GDBN} so that after the target read request from file descriptor
393940 all following typing is buffered until either one of the following
39395conditions is met:
39396
39397@itemize @bullet
39398@item
c8aa23ab 39399The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
39400@code{read}
39401system call is treated as finished.
39402
39403@item
7f9087cb 39404The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 39405newline.
0ce1b118
CV
39406
39407@item
c8aa23ab
EZ
39408The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
39409character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
39410
39411@end itemize
39412
fc320d37
SL
39413If the user has typed more characters than fit in the buffer given to
39414the @code{read} call, the trailing characters are buffered in @value{GDBN} until
39415either another @code{read(0, @dots{})} is requested by the target, or debugging
39416is stopped at the user's request.
0ce1b118 39417
0ce1b118 39418
79a6e687
BW
39419@node List of Supported Calls
39420@subsection List of Supported Calls
0ce1b118
CV
39421@cindex list of supported file-i/o calls
39422
39423@menu
39424* open::
39425* close::
39426* read::
39427* write::
39428* lseek::
39429* rename::
39430* unlink::
39431* stat/fstat::
39432* gettimeofday::
39433* isatty::
39434* system::
39435@end menu
39436
39437@node open
39438@unnumberedsubsubsec open
39439@cindex open, file-i/o system call
39440
fc320d37
SL
39441@table @asis
39442@item Synopsis:
0ce1b118 39443@smallexample
0ce1b118
CV
39444int open(const char *pathname, int flags);
39445int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
39446@end smallexample
39447
fc320d37
SL
39448@item Request:
39449@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
39450
0ce1b118 39451@noindent
fc320d37 39452@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
39453
39454@table @code
b383017d 39455@item O_CREAT
0ce1b118
CV
39456If the file does not exist it will be created. The host
39457rules apply as far as file ownership and time stamps
39458are concerned.
39459
b383017d 39460@item O_EXCL
fc320d37 39461When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
39462an error and open() fails.
39463
b383017d 39464@item O_TRUNC
0ce1b118 39465If the file already exists and the open mode allows
fc320d37
SL
39466writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
39467truncated to zero length.
0ce1b118 39468
b383017d 39469@item O_APPEND
0ce1b118
CV
39470The file is opened in append mode.
39471
b383017d 39472@item O_RDONLY
0ce1b118
CV
39473The file is opened for reading only.
39474
b383017d 39475@item O_WRONLY
0ce1b118
CV
39476The file is opened for writing only.
39477
b383017d 39478@item O_RDWR
0ce1b118 39479The file is opened for reading and writing.
fc320d37 39480@end table
0ce1b118
CV
39481
39482@noindent
fc320d37 39483Other bits are silently ignored.
0ce1b118 39484
0ce1b118
CV
39485
39486@noindent
fc320d37 39487@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
39488
39489@table @code
b383017d 39490@item S_IRUSR
0ce1b118
CV
39491User has read permission.
39492
b383017d 39493@item S_IWUSR
0ce1b118
CV
39494User has write permission.
39495
b383017d 39496@item S_IRGRP
0ce1b118
CV
39497Group has read permission.
39498
b383017d 39499@item S_IWGRP
0ce1b118
CV
39500Group has write permission.
39501
b383017d 39502@item S_IROTH
0ce1b118
CV
39503Others have read permission.
39504
b383017d 39505@item S_IWOTH
0ce1b118 39506Others have write permission.
fc320d37 39507@end table
0ce1b118
CV
39508
39509@noindent
fc320d37 39510Other bits are silently ignored.
0ce1b118 39511
0ce1b118 39512
fc320d37
SL
39513@item Return value:
39514@code{open} returns the new file descriptor or -1 if an error
39515occurred.
0ce1b118 39516
fc320d37 39517@item Errors:
0ce1b118
CV
39518
39519@table @code
b383017d 39520@item EEXIST
fc320d37 39521@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 39522
b383017d 39523@item EISDIR
fc320d37 39524@var{pathname} refers to a directory.
0ce1b118 39525
b383017d 39526@item EACCES
0ce1b118
CV
39527The requested access is not allowed.
39528
39529@item ENAMETOOLONG
fc320d37 39530@var{pathname} was too long.
0ce1b118 39531
b383017d 39532@item ENOENT
fc320d37 39533A directory component in @var{pathname} does not exist.
0ce1b118 39534
b383017d 39535@item ENODEV
fc320d37 39536@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 39537
b383017d 39538@item EROFS
fc320d37 39539@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
39540write access was requested.
39541
b383017d 39542@item EFAULT
fc320d37 39543@var{pathname} is an invalid pointer value.
0ce1b118 39544
b383017d 39545@item ENOSPC
0ce1b118
CV
39546No space on device to create the file.
39547
b383017d 39548@item EMFILE
0ce1b118
CV
39549The process already has the maximum number of files open.
39550
b383017d 39551@item ENFILE
0ce1b118
CV
39552The limit on the total number of files open on the system
39553has been reached.
39554
b383017d 39555@item EINTR
0ce1b118
CV
39556The call was interrupted by the user.
39557@end table
39558
fc320d37
SL
39559@end table
39560
0ce1b118
CV
39561@node close
39562@unnumberedsubsubsec close
39563@cindex close, file-i/o system call
39564
fc320d37
SL
39565@table @asis
39566@item Synopsis:
0ce1b118 39567@smallexample
0ce1b118 39568int close(int fd);
fc320d37 39569@end smallexample
0ce1b118 39570
fc320d37
SL
39571@item Request:
39572@samp{Fclose,@var{fd}}
0ce1b118 39573
fc320d37
SL
39574@item Return value:
39575@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 39576
fc320d37 39577@item Errors:
0ce1b118
CV
39578
39579@table @code
b383017d 39580@item EBADF
fc320d37 39581@var{fd} isn't a valid open file descriptor.
0ce1b118 39582
b383017d 39583@item EINTR
0ce1b118
CV
39584The call was interrupted by the user.
39585@end table
39586
fc320d37
SL
39587@end table
39588
0ce1b118
CV
39589@node read
39590@unnumberedsubsubsec read
39591@cindex read, file-i/o system call
39592
fc320d37
SL
39593@table @asis
39594@item Synopsis:
0ce1b118 39595@smallexample
0ce1b118 39596int read(int fd, void *buf, unsigned int count);
fc320d37 39597@end smallexample
0ce1b118 39598
fc320d37
SL
39599@item Request:
39600@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 39601
fc320d37 39602@item Return value:
0ce1b118
CV
39603On success, the number of bytes read is returned.
39604Zero indicates end of file. If count is zero, read
b383017d 39605returns zero as well. On error, -1 is returned.
0ce1b118 39606
fc320d37 39607@item Errors:
0ce1b118
CV
39608
39609@table @code
b383017d 39610@item EBADF
fc320d37 39611@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
39612reading.
39613
b383017d 39614@item EFAULT
fc320d37 39615@var{bufptr} is an invalid pointer value.
0ce1b118 39616
b383017d 39617@item EINTR
0ce1b118
CV
39618The call was interrupted by the user.
39619@end table
39620
fc320d37
SL
39621@end table
39622
0ce1b118
CV
39623@node write
39624@unnumberedsubsubsec write
39625@cindex write, file-i/o system call
39626
fc320d37
SL
39627@table @asis
39628@item Synopsis:
0ce1b118 39629@smallexample
0ce1b118 39630int write(int fd, const void *buf, unsigned int count);
fc320d37 39631@end smallexample
0ce1b118 39632
fc320d37
SL
39633@item Request:
39634@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 39635
fc320d37 39636@item Return value:
0ce1b118
CV
39637On success, the number of bytes written are returned.
39638Zero indicates nothing was written. On error, -1
39639is returned.
39640
fc320d37 39641@item Errors:
0ce1b118
CV
39642
39643@table @code
b383017d 39644@item EBADF
fc320d37 39645@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
39646writing.
39647
b383017d 39648@item EFAULT
fc320d37 39649@var{bufptr} is an invalid pointer value.
0ce1b118 39650
b383017d 39651@item EFBIG
0ce1b118 39652An attempt was made to write a file that exceeds the
db2e3e2e 39653host-specific maximum file size allowed.
0ce1b118 39654
b383017d 39655@item ENOSPC
0ce1b118
CV
39656No space on device to write the data.
39657
b383017d 39658@item EINTR
0ce1b118
CV
39659The call was interrupted by the user.
39660@end table
39661
fc320d37
SL
39662@end table
39663
0ce1b118
CV
39664@node lseek
39665@unnumberedsubsubsec lseek
39666@cindex lseek, file-i/o system call
39667
fc320d37
SL
39668@table @asis
39669@item Synopsis:
0ce1b118 39670@smallexample
0ce1b118 39671long lseek (int fd, long offset, int flag);
0ce1b118
CV
39672@end smallexample
39673
fc320d37
SL
39674@item Request:
39675@samp{Flseek,@var{fd},@var{offset},@var{flag}}
39676
39677@var{flag} is one of:
0ce1b118
CV
39678
39679@table @code
b383017d 39680@item SEEK_SET
fc320d37 39681The offset is set to @var{offset} bytes.
0ce1b118 39682
b383017d 39683@item SEEK_CUR
fc320d37 39684The offset is set to its current location plus @var{offset}
0ce1b118
CV
39685bytes.
39686
b383017d 39687@item SEEK_END
fc320d37 39688The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
39689bytes.
39690@end table
39691
fc320d37 39692@item Return value:
0ce1b118
CV
39693On success, the resulting unsigned offset in bytes from
39694the beginning of the file is returned. Otherwise, a
39695value of -1 is returned.
39696
fc320d37 39697@item Errors:
0ce1b118
CV
39698
39699@table @code
b383017d 39700@item EBADF
fc320d37 39701@var{fd} is not a valid open file descriptor.
0ce1b118 39702
b383017d 39703@item ESPIPE
fc320d37 39704@var{fd} is associated with the @value{GDBN} console.
0ce1b118 39705
b383017d 39706@item EINVAL
fc320d37 39707@var{flag} is not a proper value.
0ce1b118 39708
b383017d 39709@item EINTR
0ce1b118
CV
39710The call was interrupted by the user.
39711@end table
39712
fc320d37
SL
39713@end table
39714
0ce1b118
CV
39715@node rename
39716@unnumberedsubsubsec rename
39717@cindex rename, file-i/o system call
39718
fc320d37
SL
39719@table @asis
39720@item Synopsis:
0ce1b118 39721@smallexample
0ce1b118 39722int rename(const char *oldpath, const char *newpath);
fc320d37 39723@end smallexample
0ce1b118 39724
fc320d37
SL
39725@item Request:
39726@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 39727
fc320d37 39728@item Return value:
0ce1b118
CV
39729On success, zero is returned. On error, -1 is returned.
39730
fc320d37 39731@item Errors:
0ce1b118
CV
39732
39733@table @code
b383017d 39734@item EISDIR
fc320d37 39735@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
39736directory.
39737
b383017d 39738@item EEXIST
fc320d37 39739@var{newpath} is a non-empty directory.
0ce1b118 39740
b383017d 39741@item EBUSY
fc320d37 39742@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
39743process.
39744
b383017d 39745@item EINVAL
0ce1b118
CV
39746An attempt was made to make a directory a subdirectory
39747of itself.
39748
b383017d 39749@item ENOTDIR
fc320d37
SL
39750A component used as a directory in @var{oldpath} or new
39751path is not a directory. Or @var{oldpath} is a directory
39752and @var{newpath} exists but is not a directory.
0ce1b118 39753
b383017d 39754@item EFAULT
fc320d37 39755@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 39756
b383017d 39757@item EACCES
0ce1b118
CV
39758No access to the file or the path of the file.
39759
39760@item ENAMETOOLONG
b383017d 39761
fc320d37 39762@var{oldpath} or @var{newpath} was too long.
0ce1b118 39763
b383017d 39764@item ENOENT
fc320d37 39765A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 39766
b383017d 39767@item EROFS
0ce1b118
CV
39768The file is on a read-only filesystem.
39769
b383017d 39770@item ENOSPC
0ce1b118
CV
39771The device containing the file has no room for the new
39772directory entry.
39773
b383017d 39774@item EINTR
0ce1b118
CV
39775The call was interrupted by the user.
39776@end table
39777
fc320d37
SL
39778@end table
39779
0ce1b118
CV
39780@node unlink
39781@unnumberedsubsubsec unlink
39782@cindex unlink, file-i/o system call
39783
fc320d37
SL
39784@table @asis
39785@item Synopsis:
0ce1b118 39786@smallexample
0ce1b118 39787int unlink(const char *pathname);
fc320d37 39788@end smallexample
0ce1b118 39789
fc320d37
SL
39790@item Request:
39791@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 39792
fc320d37 39793@item Return value:
0ce1b118
CV
39794On success, zero is returned. On error, -1 is returned.
39795
fc320d37 39796@item Errors:
0ce1b118
CV
39797
39798@table @code
b383017d 39799@item EACCES
0ce1b118
CV
39800No access to the file or the path of the file.
39801
b383017d 39802@item EPERM
0ce1b118
CV
39803The system does not allow unlinking of directories.
39804
b383017d 39805@item EBUSY
fc320d37 39806The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
39807being used by another process.
39808
b383017d 39809@item EFAULT
fc320d37 39810@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
39811
39812@item ENAMETOOLONG
fc320d37 39813@var{pathname} was too long.
0ce1b118 39814
b383017d 39815@item ENOENT
fc320d37 39816A directory component in @var{pathname} does not exist.
0ce1b118 39817
b383017d 39818@item ENOTDIR
0ce1b118
CV
39819A component of the path is not a directory.
39820
b383017d 39821@item EROFS
0ce1b118
CV
39822The file is on a read-only filesystem.
39823
b383017d 39824@item EINTR
0ce1b118
CV
39825The call was interrupted by the user.
39826@end table
39827
fc320d37
SL
39828@end table
39829
0ce1b118
CV
39830@node stat/fstat
39831@unnumberedsubsubsec stat/fstat
39832@cindex fstat, file-i/o system call
39833@cindex stat, file-i/o system call
39834
fc320d37
SL
39835@table @asis
39836@item Synopsis:
0ce1b118 39837@smallexample
0ce1b118
CV
39838int stat(const char *pathname, struct stat *buf);
39839int fstat(int fd, struct stat *buf);
fc320d37 39840@end smallexample
0ce1b118 39841
fc320d37
SL
39842@item Request:
39843@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
39844@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 39845
fc320d37 39846@item Return value:
0ce1b118
CV
39847On success, zero is returned. On error, -1 is returned.
39848
fc320d37 39849@item Errors:
0ce1b118
CV
39850
39851@table @code
b383017d 39852@item EBADF
fc320d37 39853@var{fd} is not a valid open file.
0ce1b118 39854
b383017d 39855@item ENOENT
fc320d37 39856A directory component in @var{pathname} does not exist or the
0ce1b118
CV
39857path is an empty string.
39858
b383017d 39859@item ENOTDIR
0ce1b118
CV
39860A component of the path is not a directory.
39861
b383017d 39862@item EFAULT
fc320d37 39863@var{pathnameptr} is an invalid pointer value.
0ce1b118 39864
b383017d 39865@item EACCES
0ce1b118
CV
39866No access to the file or the path of the file.
39867
39868@item ENAMETOOLONG
fc320d37 39869@var{pathname} was too long.
0ce1b118 39870
b383017d 39871@item EINTR
0ce1b118
CV
39872The call was interrupted by the user.
39873@end table
39874
fc320d37
SL
39875@end table
39876
0ce1b118
CV
39877@node gettimeofday
39878@unnumberedsubsubsec gettimeofday
39879@cindex gettimeofday, file-i/o system call
39880
fc320d37
SL
39881@table @asis
39882@item Synopsis:
0ce1b118 39883@smallexample
0ce1b118 39884int gettimeofday(struct timeval *tv, void *tz);
fc320d37 39885@end smallexample
0ce1b118 39886
fc320d37
SL
39887@item Request:
39888@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 39889
fc320d37 39890@item Return value:
0ce1b118
CV
39891On success, 0 is returned, -1 otherwise.
39892
fc320d37 39893@item Errors:
0ce1b118
CV
39894
39895@table @code
b383017d 39896@item EINVAL
fc320d37 39897@var{tz} is a non-NULL pointer.
0ce1b118 39898
b383017d 39899@item EFAULT
fc320d37
SL
39900@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
39901@end table
39902
0ce1b118
CV
39903@end table
39904
39905@node isatty
39906@unnumberedsubsubsec isatty
39907@cindex isatty, file-i/o system call
39908
fc320d37
SL
39909@table @asis
39910@item Synopsis:
0ce1b118 39911@smallexample
0ce1b118 39912int isatty(int fd);
fc320d37 39913@end smallexample
0ce1b118 39914
fc320d37
SL
39915@item Request:
39916@samp{Fisatty,@var{fd}}
0ce1b118 39917
fc320d37
SL
39918@item Return value:
39919Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 39920
fc320d37 39921@item Errors:
0ce1b118
CV
39922
39923@table @code
b383017d 39924@item EINTR
0ce1b118
CV
39925The call was interrupted by the user.
39926@end table
39927
fc320d37
SL
39928@end table
39929
39930Note that the @code{isatty} call is treated as a special case: it returns
399311 to the target if the file descriptor is attached
39932to the @value{GDBN} console, 0 otherwise. Implementing through system calls
39933would require implementing @code{ioctl} and would be more complex than
39934needed.
39935
39936
0ce1b118
CV
39937@node system
39938@unnumberedsubsubsec system
39939@cindex system, file-i/o system call
39940
fc320d37
SL
39941@table @asis
39942@item Synopsis:
0ce1b118 39943@smallexample
0ce1b118 39944int system(const char *command);
fc320d37 39945@end smallexample
0ce1b118 39946
fc320d37
SL
39947@item Request:
39948@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 39949
fc320d37 39950@item Return value:
5600ea19
NS
39951If @var{len} is zero, the return value indicates whether a shell is
39952available. A zero return value indicates a shell is not available.
39953For non-zero @var{len}, the value returned is -1 on error and the
39954return status of the command otherwise. Only the exit status of the
39955command is returned, which is extracted from the host's @code{system}
39956return value by calling @code{WEXITSTATUS(retval)}. In case
39957@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 39958
fc320d37 39959@item Errors:
0ce1b118
CV
39960
39961@table @code
b383017d 39962@item EINTR
0ce1b118
CV
39963The call was interrupted by the user.
39964@end table
39965
fc320d37
SL
39966@end table
39967
39968@value{GDBN} takes over the full task of calling the necessary host calls
39969to perform the @code{system} call. The return value of @code{system} on
39970the host is simplified before it's returned
39971to the target. Any termination signal information from the child process
39972is discarded, and the return value consists
39973entirely of the exit status of the called command.
39974
39975Due to security concerns, the @code{system} call is by default refused
39976by @value{GDBN}. The user has to allow this call explicitly with the
39977@code{set remote system-call-allowed 1} command.
39978
39979@table @code
39980@item set remote system-call-allowed
39981@kindex set remote system-call-allowed
39982Control whether to allow the @code{system} calls in the File I/O
39983protocol for the remote target. The default is zero (disabled).
39984
39985@item show remote system-call-allowed
39986@kindex show remote system-call-allowed
39987Show whether the @code{system} calls are allowed in the File I/O
39988protocol.
39989@end table
39990
db2e3e2e
BW
39991@node Protocol-specific Representation of Datatypes
39992@subsection Protocol-specific Representation of Datatypes
39993@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
39994
39995@menu
79a6e687
BW
39996* Integral Datatypes::
39997* Pointer Values::
39998* Memory Transfer::
0ce1b118
CV
39999* struct stat::
40000* struct timeval::
40001@end menu
40002
79a6e687
BW
40003@node Integral Datatypes
40004@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
40005@cindex integral datatypes, in file-i/o protocol
40006
fc320d37
SL
40007The integral datatypes used in the system calls are @code{int},
40008@code{unsigned int}, @code{long}, @code{unsigned long},
40009@code{mode_t}, and @code{time_t}.
0ce1b118 40010
fc320d37 40011@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
40012implemented as 32 bit values in this protocol.
40013
fc320d37 40014@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 40015
0ce1b118
CV
40016@xref{Limits}, for corresponding MIN and MAX values (similar to those
40017in @file{limits.h}) to allow range checking on host and target.
40018
40019@code{time_t} datatypes are defined as seconds since the Epoch.
40020
40021All integral datatypes transferred as part of a memory read or write of a
40022structured datatype e.g.@: a @code{struct stat} have to be given in big endian
40023byte order.
40024
79a6e687
BW
40025@node Pointer Values
40026@unnumberedsubsubsec Pointer Values
0ce1b118
CV
40027@cindex pointer values, in file-i/o protocol
40028
40029Pointers to target data are transmitted as they are. An exception
40030is made for pointers to buffers for which the length isn't
40031transmitted as part of the function call, namely strings. Strings
40032are transmitted as a pointer/length pair, both as hex values, e.g.@:
40033
40034@smallexample
40035@code{1aaf/12}
40036@end smallexample
40037
40038@noindent
40039which is a pointer to data of length 18 bytes at position 0x1aaf.
40040The length is defined as the full string length in bytes, including
fc320d37
SL
40041the trailing null byte. For example, the string @code{"hello world"}
40042at address 0x123456 is transmitted as
0ce1b118
CV
40043
40044@smallexample
fc320d37 40045@code{123456/d}
0ce1b118
CV
40046@end smallexample
40047
79a6e687
BW
40048@node Memory Transfer
40049@unnumberedsubsubsec Memory Transfer
fc320d37
SL
40050@cindex memory transfer, in file-i/o protocol
40051
40052Structured data which is transferred using a memory read or write (for
db2e3e2e 40053example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
40054with all scalar multibyte datatypes being big endian. Translation to
40055this representation needs to be done both by the target before the @code{F}
40056packet is sent, and by @value{GDBN} before
40057it transfers memory to the target. Transferred pointers to structured
40058data should point to the already-coerced data at any time.
0ce1b118 40059
0ce1b118
CV
40060
40061@node struct stat
40062@unnumberedsubsubsec struct stat
40063@cindex struct stat, in file-i/o protocol
40064
fc320d37
SL
40065The buffer of type @code{struct stat} used by the target and @value{GDBN}
40066is defined as follows:
0ce1b118
CV
40067
40068@smallexample
40069struct stat @{
40070 unsigned int st_dev; /* device */
40071 unsigned int st_ino; /* inode */
40072 mode_t st_mode; /* protection */
40073 unsigned int st_nlink; /* number of hard links */
40074 unsigned int st_uid; /* user ID of owner */
40075 unsigned int st_gid; /* group ID of owner */
40076 unsigned int st_rdev; /* device type (if inode device) */
40077 unsigned long st_size; /* total size, in bytes */
40078 unsigned long st_blksize; /* blocksize for filesystem I/O */
40079 unsigned long st_blocks; /* number of blocks allocated */
40080 time_t st_atime; /* time of last access */
40081 time_t st_mtime; /* time of last modification */
40082 time_t st_ctime; /* time of last change */
40083@};
40084@end smallexample
40085
fc320d37 40086The integral datatypes conform to the definitions given in the
79a6e687 40087appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
40088structure is of size 64 bytes.
40089
40090The values of several fields have a restricted meaning and/or
40091range of values.
40092
fc320d37 40093@table @code
0ce1b118 40094
fc320d37
SL
40095@item st_dev
40096A value of 0 represents a file, 1 the console.
0ce1b118 40097
fc320d37
SL
40098@item st_ino
40099No valid meaning for the target. Transmitted unchanged.
0ce1b118 40100
fc320d37
SL
40101@item st_mode
40102Valid mode bits are described in @ref{Constants}. Any other
40103bits have currently no meaning for the target.
0ce1b118 40104
fc320d37
SL
40105@item st_uid
40106@itemx st_gid
40107@itemx st_rdev
40108No valid meaning for the target. Transmitted unchanged.
0ce1b118 40109
fc320d37
SL
40110@item st_atime
40111@itemx st_mtime
40112@itemx st_ctime
40113These values have a host and file system dependent
40114accuracy. Especially on Windows hosts, the file system may not
40115support exact timing values.
40116@end table
0ce1b118 40117
fc320d37
SL
40118The target gets a @code{struct stat} of the above representation and is
40119responsible for coercing it to the target representation before
0ce1b118
CV
40120continuing.
40121
fc320d37
SL
40122Note that due to size differences between the host, target, and protocol
40123representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
40124get truncated on the target.
40125
40126@node struct timeval
40127@unnumberedsubsubsec struct timeval
40128@cindex struct timeval, in file-i/o protocol
40129
fc320d37 40130The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
40131is defined as follows:
40132
40133@smallexample
b383017d 40134struct timeval @{
0ce1b118
CV
40135 time_t tv_sec; /* second */
40136 long tv_usec; /* microsecond */
40137@};
40138@end smallexample
40139
fc320d37 40140The integral datatypes conform to the definitions given in the
79a6e687 40141appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
40142structure is of size 8 bytes.
40143
40144@node Constants
40145@subsection Constants
40146@cindex constants, in file-i/o protocol
40147
40148The following values are used for the constants inside of the
fc320d37 40149protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
40150values before and after the call as needed.
40151
40152@menu
79a6e687
BW
40153* Open Flags::
40154* mode_t Values::
40155* Errno Values::
40156* Lseek Flags::
0ce1b118
CV
40157* Limits::
40158@end menu
40159
79a6e687
BW
40160@node Open Flags
40161@unnumberedsubsubsec Open Flags
0ce1b118
CV
40162@cindex open flags, in file-i/o protocol
40163
40164All values are given in hexadecimal representation.
40165
40166@smallexample
40167 O_RDONLY 0x0
40168 O_WRONLY 0x1
40169 O_RDWR 0x2
40170 O_APPEND 0x8
40171 O_CREAT 0x200
40172 O_TRUNC 0x400
40173 O_EXCL 0x800
40174@end smallexample
40175
79a6e687
BW
40176@node mode_t Values
40177@unnumberedsubsubsec mode_t Values
0ce1b118
CV
40178@cindex mode_t values, in file-i/o protocol
40179
40180All values are given in octal representation.
40181
40182@smallexample
40183 S_IFREG 0100000
40184 S_IFDIR 040000
40185 S_IRUSR 0400
40186 S_IWUSR 0200
40187 S_IXUSR 0100
40188 S_IRGRP 040
40189 S_IWGRP 020
40190 S_IXGRP 010
40191 S_IROTH 04
40192 S_IWOTH 02
40193 S_IXOTH 01
40194@end smallexample
40195
79a6e687
BW
40196@node Errno Values
40197@unnumberedsubsubsec Errno Values
0ce1b118
CV
40198@cindex errno values, in file-i/o protocol
40199
40200All values are given in decimal representation.
40201
40202@smallexample
40203 EPERM 1
40204 ENOENT 2
40205 EINTR 4
40206 EBADF 9
40207 EACCES 13
40208 EFAULT 14
40209 EBUSY 16
40210 EEXIST 17
40211 ENODEV 19
40212 ENOTDIR 20
40213 EISDIR 21
40214 EINVAL 22
40215 ENFILE 23
40216 EMFILE 24
40217 EFBIG 27
40218 ENOSPC 28
40219 ESPIPE 29
40220 EROFS 30
40221 ENAMETOOLONG 91
40222 EUNKNOWN 9999
40223@end smallexample
40224
fc320d37 40225 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
40226 any error value not in the list of supported error numbers.
40227
79a6e687
BW
40228@node Lseek Flags
40229@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
40230@cindex lseek flags, in file-i/o protocol
40231
40232@smallexample
40233 SEEK_SET 0
40234 SEEK_CUR 1
40235 SEEK_END 2
40236@end smallexample
40237
40238@node Limits
40239@unnumberedsubsubsec Limits
40240@cindex limits, in file-i/o protocol
40241
40242All values are given in decimal representation.
40243
40244@smallexample
40245 INT_MIN -2147483648
40246 INT_MAX 2147483647
40247 UINT_MAX 4294967295
40248 LONG_MIN -9223372036854775808
40249 LONG_MAX 9223372036854775807
40250 ULONG_MAX 18446744073709551615
40251@end smallexample
40252
40253@node File-I/O Examples
40254@subsection File-I/O Examples
40255@cindex file-i/o examples
40256
40257Example sequence of a write call, file descriptor 3, buffer is at target
40258address 0x1234, 6 bytes should be written:
40259
40260@smallexample
40261<- @code{Fwrite,3,1234,6}
40262@emph{request memory read from target}
40263-> @code{m1234,6}
40264<- XXXXXX
40265@emph{return "6 bytes written"}
40266-> @code{F6}
40267@end smallexample
40268
40269Example sequence of a read call, file descriptor 3, buffer is at target
40270address 0x1234, 6 bytes should be read:
40271
40272@smallexample
40273<- @code{Fread,3,1234,6}
40274@emph{request memory write to target}
40275-> @code{X1234,6:XXXXXX}
40276@emph{return "6 bytes read"}
40277-> @code{F6}
40278@end smallexample
40279
40280Example sequence of a read call, call fails on the host due to invalid
fc320d37 40281file descriptor (@code{EBADF}):
0ce1b118
CV
40282
40283@smallexample
40284<- @code{Fread,3,1234,6}
40285-> @code{F-1,9}
40286@end smallexample
40287
c8aa23ab 40288Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
40289host is called:
40290
40291@smallexample
40292<- @code{Fread,3,1234,6}
40293-> @code{F-1,4,C}
40294<- @code{T02}
40295@end smallexample
40296
c8aa23ab 40297Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
40298host is called:
40299
40300@smallexample
40301<- @code{Fread,3,1234,6}
40302-> @code{X1234,6:XXXXXX}
40303<- @code{T02}
40304@end smallexample
40305
cfa9d6d9
DJ
40306@node Library List Format
40307@section Library List Format
40308@cindex library list format, remote protocol
40309
40310On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
40311same process as your application to manage libraries. In this case,
40312@value{GDBN} can use the loader's symbol table and normal memory
40313operations to maintain a list of shared libraries. On other
40314platforms, the operating system manages loaded libraries.
40315@value{GDBN} can not retrieve the list of currently loaded libraries
40316through memory operations, so it uses the @samp{qXfer:libraries:read}
40317packet (@pxref{qXfer library list read}) instead. The remote stub
40318queries the target's operating system and reports which libraries
40319are loaded.
40320
40321The @samp{qXfer:libraries:read} packet returns an XML document which
40322lists loaded libraries and their offsets. Each library has an
1fddbabb
PA
40323associated name and one or more segment or section base addresses,
40324which report where the library was loaded in memory.
40325
40326For the common case of libraries that are fully linked binaries, the
40327library should have a list of segments. If the target supports
40328dynamic linking of a relocatable object file, its library XML element
40329should instead include a list of allocated sections. The segment or
40330section bases are start addresses, not relocation offsets; they do not
40331depend on the library's link-time base addresses.
cfa9d6d9 40332
9cceb671
DJ
40333@value{GDBN} must be linked with the Expat library to support XML
40334library lists. @xref{Expat}.
40335
cfa9d6d9
DJ
40336A simple memory map, with one loaded library relocated by a single
40337offset, looks like this:
40338
40339@smallexample
40340<library-list>
40341 <library name="/lib/libc.so.6">
40342 <segment address="0x10000000"/>
40343 </library>
40344</library-list>
40345@end smallexample
40346
1fddbabb
PA
40347Another simple memory map, with one loaded library with three
40348allocated sections (.text, .data, .bss), looks like this:
40349
40350@smallexample
40351<library-list>
40352 <library name="sharedlib.o">
40353 <section address="0x10000000"/>
40354 <section address="0x20000000"/>
40355 <section address="0x30000000"/>
40356 </library>
40357</library-list>
40358@end smallexample
40359
cfa9d6d9
DJ
40360The format of a library list is described by this DTD:
40361
40362@smallexample
40363<!-- library-list: Root element with versioning -->
40364<!ELEMENT library-list (library)*>
40365<!ATTLIST library-list version CDATA #FIXED "1.0">
1fddbabb 40366<!ELEMENT library (segment*, section*)>
cfa9d6d9
DJ
40367<!ATTLIST library name CDATA #REQUIRED>
40368<!ELEMENT segment EMPTY>
40369<!ATTLIST segment address CDATA #REQUIRED>
1fddbabb
PA
40370<!ELEMENT section EMPTY>
40371<!ATTLIST section address CDATA #REQUIRED>
cfa9d6d9
DJ
40372@end smallexample
40373
1fddbabb
PA
40374In addition, segments and section descriptors cannot be mixed within a
40375single library element, and you must supply at least one segment or
40376section for each library.
40377
2268b414
JK
40378@node Library List Format for SVR4 Targets
40379@section Library List Format for SVR4 Targets
40380@cindex library list format, remote protocol
40381
40382On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
40383(e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
40384shared libraries. Still a special library list provided by this packet is
40385more efficient for the @value{GDBN} remote protocol.
40386
40387The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
40388loaded libraries and their SVR4 linker parameters. For each library on SVR4
40389target, the following parameters are reported:
40390
40391@itemize @minus
40392@item
40393@code{name}, the absolute file name from the @code{l_name} field of
40394@code{struct link_map}.
40395@item
40396@code{lm} with address of @code{struct link_map} used for TLS
40397(Thread Local Storage) access.
40398@item
40399@code{l_addr}, the displacement as read from the field @code{l_addr} of
40400@code{struct link_map}. For prelinked libraries this is not an absolute
40401memory address. It is a displacement of absolute memory address against
40402address the file was prelinked to during the library load.
40403@item
40404@code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
40405@end itemize
40406
40407Additionally the single @code{main-lm} attribute specifies address of
40408@code{struct link_map} used for the main executable. This parameter is used
40409for TLS access and its presence is optional.
40410
40411@value{GDBN} must be linked with the Expat library to support XML
40412SVR4 library lists. @xref{Expat}.
40413
40414A simple memory map, with two loaded libraries (which do not use prelink),
40415looks like this:
40416
40417@smallexample
40418<library-list-svr4 version="1.0" main-lm="0xe4f8f8">
40419 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
40420 l_ld="0xe4eefc"/>
40421 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
40422 l_ld="0x152350"/>
40423</library-list-svr>
40424@end smallexample
40425
40426The format of an SVR4 library list is described by this DTD:
40427
40428@smallexample
40429<!-- library-list-svr4: Root element with versioning -->
40430<!ELEMENT library-list-svr4 (library)*>
40431<!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
40432<!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
40433<!ELEMENT library EMPTY>
40434<!ATTLIST library name CDATA #REQUIRED>
40435<!ATTLIST library lm CDATA #REQUIRED>
40436<!ATTLIST library l_addr CDATA #REQUIRED>
40437<!ATTLIST library l_ld CDATA #REQUIRED>
40438@end smallexample
40439
79a6e687
BW
40440@node Memory Map Format
40441@section Memory Map Format
68437a39
DJ
40442@cindex memory map format
40443
40444To be able to write into flash memory, @value{GDBN} needs to obtain a
40445memory map from the target. This section describes the format of the
40446memory map.
40447
40448The memory map is obtained using the @samp{qXfer:memory-map:read}
40449(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
40450lists memory regions.
40451
40452@value{GDBN} must be linked with the Expat library to support XML
40453memory maps. @xref{Expat}.
40454
40455The top-level structure of the document is shown below:
68437a39
DJ
40456
40457@smallexample
40458<?xml version="1.0"?>
40459<!DOCTYPE memory-map
40460 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
40461 "http://sourceware.org/gdb/gdb-memory-map.dtd">
40462<memory-map>
40463 region...
40464</memory-map>
40465@end smallexample
40466
40467Each region can be either:
40468
40469@itemize
40470
40471@item
40472A region of RAM starting at @var{addr} and extending for @var{length}
40473bytes from there:
40474
40475@smallexample
40476<memory type="ram" start="@var{addr}" length="@var{length}"/>
40477@end smallexample
40478
40479
40480@item
40481A region of read-only memory:
40482
40483@smallexample
40484<memory type="rom" start="@var{addr}" length="@var{length}"/>
40485@end smallexample
40486
40487
40488@item
40489A region of flash memory, with erasure blocks @var{blocksize}
40490bytes in length:
40491
40492@smallexample
40493<memory type="flash" start="@var{addr}" length="@var{length}">
40494 <property name="blocksize">@var{blocksize}</property>
40495</memory>
40496@end smallexample
40497
40498@end itemize
40499
40500Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
40501by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
40502packets to write to addresses in such ranges.
40503
40504The formal DTD for memory map format is given below:
40505
40506@smallexample
40507<!-- ................................................... -->
40508<!-- Memory Map XML DTD ................................ -->
40509<!-- File: memory-map.dtd .............................. -->
40510<!-- .................................... .............. -->
40511<!-- memory-map.dtd -->
40512<!-- memory-map: Root element with versioning -->
40513<!ELEMENT memory-map (memory | property)>
40514<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
40515<!ELEMENT memory (property)>
40516<!-- memory: Specifies a memory region,
40517 and its type, or device. -->
40518<!ATTLIST memory type CDATA #REQUIRED
40519 start CDATA #REQUIRED
40520 length CDATA #REQUIRED
40521 device CDATA #IMPLIED>
40522<!-- property: Generic attribute tag -->
40523<!ELEMENT property (#PCDATA | property)*>
40524<!ATTLIST property name CDATA #REQUIRED>
40525@end smallexample
40526
dc146f7c
VP
40527@node Thread List Format
40528@section Thread List Format
40529@cindex thread list format
40530
40531To efficiently update the list of threads and their attributes,
40532@value{GDBN} issues the @samp{qXfer:threads:read} packet
40533(@pxref{qXfer threads read}) and obtains the XML document with
40534the following structure:
40535
40536@smallexample
40537<?xml version="1.0"?>
40538<threads>
40539 <thread id="id" core="0">
40540 ... description ...
40541 </thread>
40542</threads>
40543@end smallexample
40544
40545Each @samp{thread} element must have the @samp{id} attribute that
40546identifies the thread (@pxref{thread-id syntax}). The
40547@samp{core} attribute, if present, specifies which processor core
40548the thread was last executing on. The content of the of @samp{thread}
40549element is interpreted as human-readable auxilliary information.
40550
b3b9301e
PA
40551@node Traceframe Info Format
40552@section Traceframe Info Format
40553@cindex traceframe info format
40554
40555To be able to know which objects in the inferior can be examined when
40556inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
40557memory ranges, registers and trace state variables that have been
40558collected in a traceframe.
40559
40560This list is obtained using the @samp{qXfer:traceframe-info:read}
40561(@pxref{qXfer traceframe info read}) packet and is an XML document.
40562
40563@value{GDBN} must be linked with the Expat library to support XML
40564traceframe info discovery. @xref{Expat}.
40565
40566The top-level structure of the document is shown below:
40567
40568@smallexample
40569<?xml version="1.0"?>
40570<!DOCTYPE traceframe-info
40571 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
40572 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
40573<traceframe-info>
40574 block...
40575</traceframe-info>
40576@end smallexample
40577
40578Each traceframe block can be either:
40579
40580@itemize
40581
40582@item
40583A region of collected memory starting at @var{addr} and extending for
40584@var{length} bytes from there:
40585
40586@smallexample
40587<memory start="@var{addr}" length="@var{length}"/>
40588@end smallexample
40589
40590@end itemize
40591
40592The formal DTD for the traceframe info format is given below:
40593
40594@smallexample
40595<!ELEMENT traceframe-info (memory)* >
40596<!ATTLIST traceframe-info version CDATA #FIXED "1.0">
40597
40598<!ELEMENT memory EMPTY>
40599<!ATTLIST memory start CDATA #REQUIRED
40600 length CDATA #REQUIRED>
40601@end smallexample
40602
2ae8c8e7
MM
40603@node Branch Trace Format
40604@section Branch Trace Format
40605@cindex branch trace format
40606
40607In order to display the branch trace of an inferior thread,
40608@value{GDBN} needs to obtain the list of branches. This list is
40609represented as list of sequential code blocks that are connected via
40610branches. The code in each block has been executed sequentially.
40611
40612This list is obtained using the @samp{qXfer:btrace:read}
40613(@pxref{qXfer btrace read}) packet and is an XML document.
40614
40615@value{GDBN} must be linked with the Expat library to support XML
40616traceframe info discovery. @xref{Expat}.
40617
40618The top-level structure of the document is shown below:
40619
40620@smallexample
40621<?xml version="1.0"?>
40622<!DOCTYPE btrace
40623 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
40624 "http://sourceware.org/gdb/gdb-btrace.dtd">
40625<btrace>
40626 block...
40627</btrace>
40628@end smallexample
40629
40630@itemize
40631
40632@item
40633A block of sequentially executed instructions starting at @var{begin}
40634and ending at @var{end}:
40635
40636@smallexample
40637<block begin="@var{begin}" end="@var{end}"/>
40638@end smallexample
40639
40640@end itemize
40641
40642The formal DTD for the branch trace format is given below:
40643
40644@smallexample
40645<!ELEMENT btrace (block)* >
40646<!ATTLIST btrace version CDATA #FIXED "1.0">
40647
40648<!ELEMENT block EMPTY>
40649<!ATTLIST block begin CDATA #REQUIRED
40650 end CDATA #REQUIRED>
40651@end smallexample
40652
f418dd93
DJ
40653@include agentexpr.texi
40654
23181151
DJ
40655@node Target Descriptions
40656@appendix Target Descriptions
40657@cindex target descriptions
40658
23181151
DJ
40659One of the challenges of using @value{GDBN} to debug embedded systems
40660is that there are so many minor variants of each processor
40661architecture in use. It is common practice for vendors to start with
eb17f351 40662a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
23181151
DJ
40663and then make changes to adapt it to a particular market niche. Some
40664architectures have hundreds of variants, available from dozens of
40665vendors. This leads to a number of problems:
40666
40667@itemize @bullet
40668@item
40669With so many different customized processors, it is difficult for
40670the @value{GDBN} maintainers to keep up with the changes.
40671@item
40672Since individual variants may have short lifetimes or limited
40673audiences, it may not be worthwhile to carry information about every
40674variant in the @value{GDBN} source tree.
40675@item
40676When @value{GDBN} does support the architecture of the embedded system
40677at hand, the task of finding the correct architecture name to give the
40678@command{set architecture} command can be error-prone.
40679@end itemize
40680
40681To address these problems, the @value{GDBN} remote protocol allows a
40682target system to not only identify itself to @value{GDBN}, but to
40683actually describe its own features. This lets @value{GDBN} support
40684processor variants it has never seen before --- to the extent that the
40685descriptions are accurate, and that @value{GDBN} understands them.
40686
9cceb671
DJ
40687@value{GDBN} must be linked with the Expat library to support XML
40688target descriptions. @xref{Expat}.
123dc839 40689
23181151
DJ
40690@menu
40691* Retrieving Descriptions:: How descriptions are fetched from a target.
40692* Target Description Format:: The contents of a target description.
123dc839
DJ
40693* Predefined Target Types:: Standard types available for target
40694 descriptions.
40695* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
40696@end menu
40697
40698@node Retrieving Descriptions
40699@section Retrieving Descriptions
40700
40701Target descriptions can be read from the target automatically, or
40702specified by the user manually. The default behavior is to read the
40703description from the target. @value{GDBN} retrieves it via the remote
40704protocol using @samp{qXfer} requests (@pxref{General Query Packets,
40705qXfer}). The @var{annex} in the @samp{qXfer} packet will be
40706@samp{target.xml}. The contents of the @samp{target.xml} annex are an
40707XML document, of the form described in @ref{Target Description
40708Format}.
40709
40710Alternatively, you can specify a file to read for the target description.
40711If a file is set, the target will not be queried. The commands to
40712specify a file are:
40713
40714@table @code
40715@cindex set tdesc filename
40716@item set tdesc filename @var{path}
40717Read the target description from @var{path}.
40718
40719@cindex unset tdesc filename
40720@item unset tdesc filename
40721Do not read the XML target description from a file. @value{GDBN}
40722will use the description supplied by the current target.
40723
40724@cindex show tdesc filename
40725@item show tdesc filename
40726Show the filename to read for a target description, if any.
40727@end table
40728
40729
40730@node Target Description Format
40731@section Target Description Format
40732@cindex target descriptions, XML format
40733
40734A target description annex is an @uref{http://www.w3.org/XML/, XML}
40735document which complies with the Document Type Definition provided in
40736the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
40737means you can use generally available tools like @command{xmllint} to
40738check that your feature descriptions are well-formed and valid.
40739However, to help people unfamiliar with XML write descriptions for
40740their targets, we also describe the grammar here.
40741
123dc839
DJ
40742Target descriptions can identify the architecture of the remote target
40743and (for some architectures) provide information about custom register
08d16641
PA
40744sets. They can also identify the OS ABI of the remote target.
40745@value{GDBN} can use this information to autoconfigure for your
123dc839 40746target, or to warn you if you connect to an unsupported target.
23181151
DJ
40747
40748Here is a simple target description:
40749
123dc839 40750@smallexample
1780a0ed 40751<target version="1.0">
23181151
DJ
40752 <architecture>i386:x86-64</architecture>
40753</target>
123dc839 40754@end smallexample
23181151
DJ
40755
40756@noindent
40757This minimal description only says that the target uses
40758the x86-64 architecture.
40759
123dc839
DJ
40760A target description has the following overall form, with [ ] marking
40761optional elements and @dots{} marking repeatable elements. The elements
40762are explained further below.
23181151 40763
123dc839 40764@smallexample
23181151
DJ
40765<?xml version="1.0"?>
40766<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 40767<target version="1.0">
123dc839 40768 @r{[}@var{architecture}@r{]}
08d16641 40769 @r{[}@var{osabi}@r{]}
e35359c5 40770 @r{[}@var{compatible}@r{]}
123dc839 40771 @r{[}@var{feature}@dots{}@r{]}
23181151 40772</target>
123dc839 40773@end smallexample
23181151
DJ
40774
40775@noindent
40776The description is generally insensitive to whitespace and line
40777breaks, under the usual common-sense rules. The XML version
40778declaration and document type declaration can generally be omitted
40779(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
40780useful for XML validation tools. The @samp{version} attribute for
40781@samp{<target>} may also be omitted, but we recommend
40782including it; if future versions of @value{GDBN} use an incompatible
40783revision of @file{gdb-target.dtd}, they will detect and report
40784the version mismatch.
23181151 40785
108546a0
DJ
40786@subsection Inclusion
40787@cindex target descriptions, inclusion
40788@cindex XInclude
40789@ifnotinfo
40790@cindex <xi:include>
40791@end ifnotinfo
40792
40793It can sometimes be valuable to split a target description up into
40794several different annexes, either for organizational purposes, or to
40795share files between different possible target descriptions. You can
40796divide a description into multiple files by replacing any element of
40797the target description with an inclusion directive of the form:
40798
123dc839 40799@smallexample
108546a0 40800<xi:include href="@var{document}"/>
123dc839 40801@end smallexample
108546a0
DJ
40802
40803@noindent
40804When @value{GDBN} encounters an element of this form, it will retrieve
40805the named XML @var{document}, and replace the inclusion directive with
40806the contents of that document. If the current description was read
40807using @samp{qXfer}, then so will be the included document;
40808@var{document} will be interpreted as the name of an annex. If the
40809current description was read from a file, @value{GDBN} will look for
40810@var{document} as a file in the same directory where it found the
40811original description.
40812
123dc839
DJ
40813@subsection Architecture
40814@cindex <architecture>
40815
40816An @samp{<architecture>} element has this form:
40817
40818@smallexample
40819 <architecture>@var{arch}</architecture>
40820@end smallexample
40821
e35359c5
UW
40822@var{arch} is one of the architectures from the set accepted by
40823@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
123dc839 40824
08d16641
PA
40825@subsection OS ABI
40826@cindex @code{<osabi>}
40827
40828This optional field was introduced in @value{GDBN} version 7.0.
40829Previous versions of @value{GDBN} ignore it.
40830
40831An @samp{<osabi>} element has this form:
40832
40833@smallexample
40834 <osabi>@var{abi-name}</osabi>
40835@end smallexample
40836
40837@var{abi-name} is an OS ABI name from the same selection accepted by
40838@w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
40839
e35359c5
UW
40840@subsection Compatible Architecture
40841@cindex @code{<compatible>}
40842
40843This optional field was introduced in @value{GDBN} version 7.0.
40844Previous versions of @value{GDBN} ignore it.
40845
40846A @samp{<compatible>} element has this form:
40847
40848@smallexample
40849 <compatible>@var{arch}</compatible>
40850@end smallexample
40851
40852@var{arch} is one of the architectures from the set accepted by
40853@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
40854
40855A @samp{<compatible>} element is used to specify that the target
40856is able to run binaries in some other than the main target architecture
40857given by the @samp{<architecture>} element. For example, on the
40858Cell Broadband Engine, the main architecture is @code{powerpc:common}
40859or @code{powerpc:common64}, but the system is able to run binaries
40860in the @code{spu} architecture as well. The way to describe this
40861capability with @samp{<compatible>} is as follows:
40862
40863@smallexample
40864 <architecture>powerpc:common</architecture>
40865 <compatible>spu</compatible>
40866@end smallexample
40867
123dc839
DJ
40868@subsection Features
40869@cindex <feature>
40870
40871Each @samp{<feature>} describes some logical portion of the target
40872system. Features are currently used to describe available CPU
40873registers and the types of their contents. A @samp{<feature>} element
40874has this form:
40875
40876@smallexample
40877<feature name="@var{name}">
40878 @r{[}@var{type}@dots{}@r{]}
40879 @var{reg}@dots{}
40880</feature>
40881@end smallexample
40882
40883@noindent
40884Each feature's name should be unique within the description. The name
40885of a feature does not matter unless @value{GDBN} has some special
40886knowledge of the contents of that feature; if it does, the feature
40887should have its standard name. @xref{Standard Target Features}.
40888
40889@subsection Types
40890
40891Any register's value is a collection of bits which @value{GDBN} must
40892interpret. The default interpretation is a two's complement integer,
40893but other types can be requested by name in the register description.
40894Some predefined types are provided by @value{GDBN} (@pxref{Predefined
40895Target Types}), and the description can define additional composite types.
40896
40897Each type element must have an @samp{id} attribute, which gives
40898a unique (within the containing @samp{<feature>}) name to the type.
40899Types must be defined before they are used.
40900
40901@cindex <vector>
40902Some targets offer vector registers, which can be treated as arrays
40903of scalar elements. These types are written as @samp{<vector>} elements,
40904specifying the array element type, @var{type}, and the number of elements,
40905@var{count}:
40906
40907@smallexample
40908<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
40909@end smallexample
40910
40911@cindex <union>
40912If a register's value is usefully viewed in multiple ways, define it
40913with a union type containing the useful representations. The
40914@samp{<union>} element contains one or more @samp{<field>} elements,
40915each of which has a @var{name} and a @var{type}:
40916
40917@smallexample
40918<union id="@var{id}">
40919 <field name="@var{name}" type="@var{type}"/>
40920 @dots{}
40921</union>
40922@end smallexample
40923
f5dff777
DJ
40924@cindex <struct>
40925If a register's value is composed from several separate values, define
40926it with a structure type. There are two forms of the @samp{<struct>}
40927element; a @samp{<struct>} element must either contain only bitfields
40928or contain no bitfields. If the structure contains only bitfields,
40929its total size in bytes must be specified, each bitfield must have an
40930explicit start and end, and bitfields are automatically assigned an
40931integer type. The field's @var{start} should be less than or
40932equal to its @var{end}, and zero represents the least significant bit.
40933
40934@smallexample
40935<struct id="@var{id}" size="@var{size}">
40936 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
40937 @dots{}
40938</struct>
40939@end smallexample
40940
40941If the structure contains no bitfields, then each field has an
40942explicit type, and no implicit padding is added.
40943
40944@smallexample
40945<struct id="@var{id}">
40946 <field name="@var{name}" type="@var{type}"/>
40947 @dots{}
40948</struct>
40949@end smallexample
40950
40951@cindex <flags>
40952If a register's value is a series of single-bit flags, define it with
40953a flags type. The @samp{<flags>} element has an explicit @var{size}
40954and contains one or more @samp{<field>} elements. Each field has a
40955@var{name}, a @var{start}, and an @var{end}. Only single-bit flags
40956are supported.
40957
40958@smallexample
40959<flags id="@var{id}" size="@var{size}">
40960 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
40961 @dots{}
40962</flags>
40963@end smallexample
40964
123dc839
DJ
40965@subsection Registers
40966@cindex <reg>
40967
40968Each register is represented as an element with this form:
40969
40970@smallexample
40971<reg name="@var{name}"
40972 bitsize="@var{size}"
40973 @r{[}regnum="@var{num}"@r{]}
40974 @r{[}save-restore="@var{save-restore}"@r{]}
40975 @r{[}type="@var{type}"@r{]}
40976 @r{[}group="@var{group}"@r{]}/>
40977@end smallexample
40978
40979@noindent
40980The components are as follows:
40981
40982@table @var
40983
40984@item name
40985The register's name; it must be unique within the target description.
40986
40987@item bitsize
40988The register's size, in bits.
40989
40990@item regnum
40991The register's number. If omitted, a register's number is one greater
40992than that of the previous register (either in the current feature or in
177b42fe 40993a preceding feature); the first register in the target description
123dc839
DJ
40994defaults to zero. This register number is used to read or write
40995the register; e.g.@: it is used in the remote @code{p} and @code{P}
40996packets, and registers appear in the @code{g} and @code{G} packets
40997in order of increasing register number.
40998
40999@item save-restore
41000Whether the register should be preserved across inferior function
41001calls; this must be either @code{yes} or @code{no}. The default is
41002@code{yes}, which is appropriate for most registers except for
41003some system control registers; this is not related to the target's
41004ABI.
41005
41006@item type
41007The type of the register. @var{type} may be a predefined type, a type
41008defined in the current feature, or one of the special types @code{int}
41009and @code{float}. @code{int} is an integer type of the correct size
41010for @var{bitsize}, and @code{float} is a floating point type (in the
41011architecture's normal floating point format) of the correct size for
41012@var{bitsize}. The default is @code{int}.
41013
41014@item group
41015The register group to which this register belongs. @var{group} must
41016be either @code{general}, @code{float}, or @code{vector}. If no
41017@var{group} is specified, @value{GDBN} will not display the register
41018in @code{info registers}.
41019
41020@end table
41021
41022@node Predefined Target Types
41023@section Predefined Target Types
41024@cindex target descriptions, predefined types
41025
41026Type definitions in the self-description can build up composite types
41027from basic building blocks, but can not define fundamental types. Instead,
41028standard identifiers are provided by @value{GDBN} for the fundamental
41029types. The currently supported types are:
41030
41031@table @code
41032
41033@item int8
41034@itemx int16
41035@itemx int32
41036@itemx int64
7cc46491 41037@itemx int128
123dc839
DJ
41038Signed integer types holding the specified number of bits.
41039
41040@item uint8
41041@itemx uint16
41042@itemx uint32
41043@itemx uint64
7cc46491 41044@itemx uint128
123dc839
DJ
41045Unsigned integer types holding the specified number of bits.
41046
41047@item code_ptr
41048@itemx data_ptr
41049Pointers to unspecified code and data. The program counter and
41050any dedicated return address register may be marked as code
41051pointers; printing a code pointer converts it into a symbolic
41052address. The stack pointer and any dedicated address registers
41053may be marked as data pointers.
41054
6e3bbd1a
PB
41055@item ieee_single
41056Single precision IEEE floating point.
41057
41058@item ieee_double
41059Double precision IEEE floating point.
41060
123dc839
DJ
41061@item arm_fpa_ext
41062The 12-byte extended precision format used by ARM FPA registers.
41063
075b51b7
L
41064@item i387_ext
41065The 10-byte extended precision format used by x87 registers.
41066
41067@item i386_eflags
4106832bit @sc{eflags} register used by x86.
41069
41070@item i386_mxcsr
4107132bit @sc{mxcsr} register used by x86.
41072
123dc839
DJ
41073@end table
41074
41075@node Standard Target Features
41076@section Standard Target Features
41077@cindex target descriptions, standard features
41078
41079A target description must contain either no registers or all the
41080target's registers. If the description contains no registers, then
41081@value{GDBN} will assume a default register layout, selected based on
41082the architecture. If the description contains any registers, the
41083default layout will not be used; the standard registers must be
41084described in the target description, in such a way that @value{GDBN}
41085can recognize them.
41086
41087This is accomplished by giving specific names to feature elements
41088which contain standard registers. @value{GDBN} will look for features
41089with those names and verify that they contain the expected registers;
41090if any known feature is missing required registers, or if any required
41091feature is missing, @value{GDBN} will reject the target
41092description. You can add additional registers to any of the
41093standard features --- @value{GDBN} will display them just as if
41094they were added to an unrecognized feature.
41095
41096This section lists the known features and their expected contents.
41097Sample XML documents for these features are included in the
41098@value{GDBN} source tree, in the directory @file{gdb/features}.
41099
41100Names recognized by @value{GDBN} should include the name of the
41101company or organization which selected the name, and the overall
41102architecture to which the feature applies; so e.g.@: the feature
41103containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
41104
ff6f572f
DJ
41105The names of registers are not case sensitive for the purpose
41106of recognizing standard features, but @value{GDBN} will only display
41107registers using the capitalization used in the description.
41108
e9c17194 41109@menu
430ed3f0 41110* AArch64 Features::
e9c17194 41111* ARM Features::
3bb8d5c3 41112* i386 Features::
1e26b4f8 41113* MIPS Features::
e9c17194 41114* M68K Features::
1e26b4f8 41115* PowerPC Features::
224bbe49 41116* TIC6x Features::
e9c17194
VP
41117@end menu
41118
41119
430ed3f0
MS
41120@node AArch64 Features
41121@subsection AArch64 Features
41122@cindex target descriptions, AArch64 features
41123
41124The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
41125targets. It should contain registers @samp{x0} through @samp{x30},
41126@samp{sp}, @samp{pc}, and @samp{cpsr}.
41127
41128The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
41129it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
41130and @samp{fpcr}.
41131
e9c17194 41132@node ARM Features
123dc839
DJ
41133@subsection ARM Features
41134@cindex target descriptions, ARM features
41135
9779414d
DJ
41136The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
41137ARM targets.
123dc839
DJ
41138It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
41139@samp{lr}, @samp{pc}, and @samp{cpsr}.
41140
9779414d
DJ
41141For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
41142feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
41143registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
41144and @samp{xpsr}.
41145
123dc839
DJ
41146The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
41147should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
41148
ff6f572f
DJ
41149The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
41150it should contain at least registers @samp{wR0} through @samp{wR15} and
41151@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
41152@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 41153
58d6951d
DJ
41154The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
41155should contain at least registers @samp{d0} through @samp{d15}. If
41156they are present, @samp{d16} through @samp{d31} should also be included.
41157@value{GDBN} will synthesize the single-precision registers from
41158halves of the double-precision registers.
41159
41160The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
41161need to contain registers; it instructs @value{GDBN} to display the
41162VFP double-precision registers as vectors and to synthesize the
41163quad-precision registers from pairs of double-precision registers.
41164If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
41165be present and include 32 double-precision registers.
41166
3bb8d5c3
L
41167@node i386 Features
41168@subsection i386 Features
41169@cindex target descriptions, i386 features
41170
41171The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
41172targets. It should describe the following registers:
41173
41174@itemize @minus
41175@item
41176@samp{eax} through @samp{edi} plus @samp{eip} for i386
41177@item
41178@samp{rax} through @samp{r15} plus @samp{rip} for amd64
41179@item
41180@samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
41181@samp{fs}, @samp{gs}
41182@item
41183@samp{st0} through @samp{st7}
41184@item
41185@samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
41186@samp{foseg}, @samp{fooff} and @samp{fop}
41187@end itemize
41188
41189The register sets may be different, depending on the target.
41190
3a13a53b 41191The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
3bb8d5c3
L
41192describe registers:
41193
41194@itemize @minus
41195@item
41196@samp{xmm0} through @samp{xmm7} for i386
41197@item
41198@samp{xmm0} through @samp{xmm15} for amd64
41199@item
41200@samp{mxcsr}
41201@end itemize
41202
3a13a53b
L
41203The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
41204@samp{org.gnu.gdb.i386.sse} feature. It should
f68eb612
L
41205describe the upper 128 bits of @sc{ymm} registers:
41206
41207@itemize @minus
41208@item
41209@samp{ymm0h} through @samp{ymm7h} for i386
41210@item
41211@samp{ymm0h} through @samp{ymm15h} for amd64
f68eb612
L
41212@end itemize
41213
3bb8d5c3
L
41214The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
41215describe a single register, @samp{orig_eax}.
41216
1e26b4f8 41217@node MIPS Features
eb17f351
EZ
41218@subsection @acronym{MIPS} Features
41219@cindex target descriptions, @acronym{MIPS} features
f8b73d13 41220
eb17f351 41221The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
f8b73d13
DJ
41222It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
41223@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
41224on the target.
41225
41226The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
41227contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
41228registers. They may be 32-bit or 64-bit depending on the target.
41229
41230The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
41231it may be optional in a future version of @value{GDBN}. It should
41232contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
41233@samp{fir}. They may be 32-bit or 64-bit depending on the target.
41234
1faeff08
MR
41235The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
41236contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
41237@samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
41238be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
41239
822b6570
DJ
41240The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
41241contain a single register, @samp{restart}, which is used by the
41242Linux kernel to control restartable syscalls.
41243
e9c17194
VP
41244@node M68K Features
41245@subsection M68K Features
41246@cindex target descriptions, M68K features
41247
41248@table @code
41249@item @samp{org.gnu.gdb.m68k.core}
41250@itemx @samp{org.gnu.gdb.coldfire.core}
41251@itemx @samp{org.gnu.gdb.fido.core}
41252One of those features must be always present.
249e1128 41253The feature that is present determines which flavor of m68k is
e9c17194
VP
41254used. The feature that is present should contain registers
41255@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
41256@samp{sp}, @samp{ps} and @samp{pc}.
41257
41258@item @samp{org.gnu.gdb.coldfire.fp}
41259This feature is optional. If present, it should contain registers
41260@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
41261@samp{fpiaddr}.
41262@end table
41263
1e26b4f8 41264@node PowerPC Features
7cc46491
DJ
41265@subsection PowerPC Features
41266@cindex target descriptions, PowerPC features
41267
41268The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
41269targets. It should contain registers @samp{r0} through @samp{r31},
41270@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
41271@samp{xer}. They may be 32-bit or 64-bit depending on the target.
41272
41273The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
41274contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
41275
41276The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
41277contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
41278and @samp{vrsave}.
41279
677c5bb1
LM
41280The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
41281contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN}
41282will combine these registers with the floating point registers
41283(@samp{f0} through @samp{f31}) and the altivec registers (@samp{vr0}
aeac0ff9 41284through @samp{vr31}) to present the 128-bit wide registers @samp{vs0}
677c5bb1
LM
41285through @samp{vs63}, the set of vector registers for POWER7.
41286
7cc46491
DJ
41287The @samp{org.gnu.gdb.power.spe} feature is optional. It should
41288contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
41289@samp{spefscr}. SPE targets should provide 32-bit registers in
41290@samp{org.gnu.gdb.power.core} and provide the upper halves in
41291@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
41292these to present registers @samp{ev0} through @samp{ev31} to the
41293user.
41294
224bbe49
YQ
41295@node TIC6x Features
41296@subsection TMS320C6x Features
41297@cindex target descriptions, TIC6x features
41298@cindex target descriptions, TMS320C6x features
41299The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
41300targets. It should contain registers @samp{A0} through @samp{A15},
41301registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
41302
41303The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
41304contain registers @samp{A16} through @samp{A31} and @samp{B16}
41305through @samp{B31}.
41306
41307The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
41308contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
41309
07e059b5
VP
41310@node Operating System Information
41311@appendix Operating System Information
41312@cindex operating system information
41313
41314@menu
41315* Process list::
41316@end menu
41317
41318Users of @value{GDBN} often wish to obtain information about the state of
41319the operating system running on the target---for example the list of
41320processes, or the list of open files. This section describes the
41321mechanism that makes it possible. This mechanism is similar to the
41322target features mechanism (@pxref{Target Descriptions}), but focuses
41323on a different aspect of target.
41324
41325Operating system information is retrived from the target via the
41326remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
41327read}). The object name in the request should be @samp{osdata}, and
41328the @var{annex} identifies the data to be fetched.
41329
41330@node Process list
41331@appendixsection Process list
41332@cindex operating system information, process list
41333
41334When requesting the process list, the @var{annex} field in the
41335@samp{qXfer} request should be @samp{processes}. The returned data is
41336an XML document. The formal syntax of this document is defined in
41337@file{gdb/features/osdata.dtd}.
41338
41339An example document is:
41340
41341@smallexample
41342<?xml version="1.0"?>
41343<!DOCTYPE target SYSTEM "osdata.dtd">
41344<osdata type="processes">
41345 <item>
41346 <column name="pid">1</column>
41347 <column name="user">root</column>
41348 <column name="command">/sbin/init</column>
dc146f7c 41349 <column name="cores">1,2,3</column>
07e059b5
VP
41350 </item>
41351</osdata>
41352@end smallexample
41353
41354Each item should include a column whose name is @samp{pid}. The value
41355of that column should identify the process on the target. The
41356@samp{user} and @samp{command} columns are optional, and will be
dc146f7c
VP
41357displayed by @value{GDBN}. The @samp{cores} column, if present,
41358should contain a comma-separated list of cores that this process
41359is running on. Target may provide additional columns,
07e059b5
VP
41360which @value{GDBN} currently ignores.
41361
05c8c3f5
TT
41362@node Trace File Format
41363@appendix Trace File Format
41364@cindex trace file format
41365
41366The trace file comes in three parts: a header, a textual description
41367section, and a trace frame section with binary data.
41368
41369The header has the form @code{\x7fTRACE0\n}. The first byte is
41370@code{0x7f} so as to indicate that the file contains binary data,
41371while the @code{0} is a version number that may have different values
41372in the future.
41373
41374The description section consists of multiple lines of @sc{ascii} text
41375separated by newline characters (@code{0xa}). The lines may include a
41376variety of optional descriptive or context-setting information, such
41377as tracepoint definitions or register set size. @value{GDBN} will
41378ignore any line that it does not recognize. An empty line marks the end
41379of this section.
41380
41381@c FIXME add some specific types of data
41382
41383The trace frame section consists of a number of consecutive frames.
41384Each frame begins with a two-byte tracepoint number, followed by a
41385four-byte size giving the amount of data in the frame. The data in
41386the frame consists of a number of blocks, each introduced by a
41387character indicating its type (at least register, memory, and trace
41388state variable). The data in this section is raw binary, not a
41389hexadecimal or other encoding; its endianness matches the target's
41390endianness.
41391
41392@c FIXME bi-arch may require endianness/arch info in description section
41393
41394@table @code
41395@item R @var{bytes}
41396Register block. The number and ordering of bytes matches that of a
41397@code{g} packet in the remote protocol. Note that these are the
41398actual bytes, in target order and @value{GDBN} register order, not a
41399hexadecimal encoding.
41400
41401@item M @var{address} @var{length} @var{bytes}...
41402Memory block. This is a contiguous block of memory, at the 8-byte
41403address @var{address}, with a 2-byte length @var{length}, followed by
41404@var{length} bytes.
41405
41406@item V @var{number} @var{value}
41407Trace state variable block. This records the 8-byte signed value
41408@var{value} of trace state variable numbered @var{number}.
41409
41410@end table
41411
41412Future enhancements of the trace file format may include additional types
41413of blocks.
41414
90476074
TT
41415@node Index Section Format
41416@appendix @code{.gdb_index} section format
41417@cindex .gdb_index section format
41418@cindex index section format
41419
41420This section documents the index section that is created by @code{save
41421gdb-index} (@pxref{Index Files}). The index section is
41422DWARF-specific; some knowledge of DWARF is assumed in this
41423description.
41424
41425The mapped index file format is designed to be directly
41426@code{mmap}able on any architecture. In most cases, a datum is
41427represented using a little-endian 32-bit integer value, called an
41428@code{offset_type}. Big endian machines must byte-swap the values
41429before using them. Exceptions to this rule are noted. The data is
41430laid out such that alignment is always respected.
41431
41432A mapped index consists of several areas, laid out in order.
41433
41434@enumerate
41435@item
41436The file header. This is a sequence of values, of @code{offset_type}
41437unless otherwise noted:
41438
41439@enumerate
41440@item
796a7ff8 41441The version number, currently 8. Versions 1, 2 and 3 are obsolete.
481860b3 41442Version 4 uses a different hashing function from versions 5 and 6.
b6ba681c
TT
41443Version 6 includes symbols for inlined functions, whereas versions 4
41444and 5 do not. Version 7 adds attributes to the CU indices in the
796a7ff8
DE
41445symbol table. Version 8 specifies that symbols from DWARF type units
41446(@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
41447compilation unit (@samp{DW_TAG_comp_unit}) using the type.
41448
41449@value{GDBN} will only read version 4, 5, or 6 indices
e615022a 41450by specifying @code{set use-deprecated-index-sections on}.
796a7ff8
DE
41451GDB has a workaround for potentially broken version 7 indices so it is
41452currently not flagged as deprecated.
90476074
TT
41453
41454@item
41455The offset, from the start of the file, of the CU list.
41456
41457@item
41458The offset, from the start of the file, of the types CU list. Note
41459that this area can be empty, in which case this offset will be equal
41460to the next offset.
41461
41462@item
41463The offset, from the start of the file, of the address area.
41464
41465@item
41466The offset, from the start of the file, of the symbol table.
41467
41468@item
41469The offset, from the start of the file, of the constant pool.
41470@end enumerate
41471
41472@item
41473The CU list. This is a sequence of pairs of 64-bit little-endian
41474values, sorted by the CU offset. The first element in each pair is
41475the offset of a CU in the @code{.debug_info} section. The second
41476element in each pair is the length of that CU. References to a CU
41477elsewhere in the map are done using a CU index, which is just the
414780-based index into this table. Note that if there are type CUs, then
41479conceptually CUs and type CUs form a single list for the purposes of
41480CU indices.
41481
41482@item
41483The types CU list. This is a sequence of triplets of 64-bit
41484little-endian values. In a triplet, the first value is the CU offset,
41485the second value is the type offset in the CU, and the third value is
41486the type signature. The types CU list is not sorted.
41487
41488@item
41489The address area. The address area consists of a sequence of address
41490entries. Each address entry has three elements:
41491
41492@enumerate
41493@item
41494The low address. This is a 64-bit little-endian value.
41495
41496@item
41497The high address. This is a 64-bit little-endian value. Like
41498@code{DW_AT_high_pc}, the value is one byte beyond the end.
41499
41500@item
41501The CU index. This is an @code{offset_type} value.
41502@end enumerate
41503
41504@item
41505The symbol table. This is an open-addressed hash table. The size of
41506the hash table is always a power of 2.
41507
41508Each slot in the hash table consists of a pair of @code{offset_type}
41509values. The first value is the offset of the symbol's name in the
41510constant pool. The second value is the offset of the CU vector in the
41511constant pool.
41512
41513If both values are 0, then this slot in the hash table is empty. This
41514is ok because while 0 is a valid constant pool index, it cannot be a
41515valid index for both a string and a CU vector.
41516
41517The hash value for a table entry is computed by applying an
41518iterative hash function to the symbol's name. Starting with an
41519initial value of @code{r = 0}, each (unsigned) character @samp{c} in
559a7a62
JK
41520the string is incorporated into the hash using the formula depending on the
41521index version:
41522
41523@table @asis
41524@item Version 4
41525The formula is @code{r = r * 67 + c - 113}.
41526
156942c7 41527@item Versions 5 to 7
559a7a62
JK
41528The formula is @code{r = r * 67 + tolower (c) - 113}.
41529@end table
41530
41531The terminating @samp{\0} is not incorporated into the hash.
90476074
TT
41532
41533The step size used in the hash table is computed via
41534@code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
41535value, and @samp{size} is the size of the hash table. The step size
41536is used to find the next candidate slot when handling a hash
41537collision.
41538
41539The names of C@t{++} symbols in the hash table are canonicalized. We
41540don't currently have a simple description of the canonicalization
41541algorithm; if you intend to create new index sections, you must read
41542the code.
41543
41544@item
41545The constant pool. This is simply a bunch of bytes. It is organized
41546so that alignment is correct: CU vectors are stored first, followed by
41547strings.
41548
41549A CU vector in the constant pool is a sequence of @code{offset_type}
41550values. The first value is the number of CU indices in the vector.
156942c7
DE
41551Each subsequent value is the index and symbol attributes of a CU in
41552the CU list. This element in the hash table is used to indicate which
41553CUs define the symbol and how the symbol is used.
41554See below for the format of each CU index+attributes entry.
90476074
TT
41555
41556A string in the constant pool is zero-terminated.
41557@end enumerate
41558
156942c7
DE
41559Attributes were added to CU index values in @code{.gdb_index} version 7.
41560If a symbol has multiple uses within a CU then there is one
41561CU index+attributes value for each use.
41562
41563The format of each CU index+attributes entry is as follows
41564(bit 0 = LSB):
41565
41566@table @asis
41567
41568@item Bits 0-23
41569This is the index of the CU in the CU list.
41570@item Bits 24-27
41571These bits are reserved for future purposes and must be zero.
41572@item Bits 28-30
41573The kind of the symbol in the CU.
41574
41575@table @asis
41576@item 0
41577This value is reserved and should not be used.
41578By reserving zero the full @code{offset_type} value is backwards compatible
41579with previous versions of the index.
41580@item 1
41581The symbol is a type.
41582@item 2
41583The symbol is a variable or an enum value.
41584@item 3
41585The symbol is a function.
41586@item 4
41587Any other kind of symbol.
41588@item 5,6,7
41589These values are reserved.
41590@end table
41591
41592@item Bit 31
41593This bit is zero if the value is global and one if it is static.
41594
41595The determination of whether a symbol is global or static is complicated.
41596The authorative reference is the file @file{dwarf2read.c} in
41597@value{GDBN} sources.
41598
41599@end table
41600
41601This pseudo-code describes the computation of a symbol's kind and
41602global/static attributes in the index.
41603
41604@smallexample
41605is_external = get_attribute (die, DW_AT_external);
41606language = get_attribute (cu_die, DW_AT_language);
41607switch (die->tag)
41608 @{
41609 case DW_TAG_typedef:
41610 case DW_TAG_base_type:
41611 case DW_TAG_subrange_type:
41612 kind = TYPE;
41613 is_static = 1;
41614 break;
41615 case DW_TAG_enumerator:
41616 kind = VARIABLE;
41617 is_static = (language != CPLUS && language != JAVA);
41618 break;
41619 case DW_TAG_subprogram:
41620 kind = FUNCTION;
41621 is_static = ! (is_external || language == ADA);
41622 break;
41623 case DW_TAG_constant:
41624 kind = VARIABLE;
41625 is_static = ! is_external;
41626 break;
41627 case DW_TAG_variable:
41628 kind = VARIABLE;
41629 is_static = ! is_external;
41630 break;
41631 case DW_TAG_namespace:
41632 kind = TYPE;
41633 is_static = 0;
41634 break;
41635 case DW_TAG_class_type:
41636 case DW_TAG_interface_type:
41637 case DW_TAG_structure_type:
41638 case DW_TAG_union_type:
41639 case DW_TAG_enumeration_type:
41640 kind = TYPE;
41641 is_static = (language != CPLUS && language != JAVA);
41642 break;
41643 default:
41644 assert (0);
41645 @}
41646@end smallexample
41647
43662968
JK
41648@node Man Pages
41649@appendix Manual pages
41650@cindex Man pages
41651
41652@menu
41653* gdb man:: The GNU Debugger man page
41654* gdbserver man:: Remote Server for the GNU Debugger man page
41655* gdbinit man:: gdbinit scripts
41656@end menu
41657
41658@node gdb man
41659@heading gdb man
41660
41661@c man title gdb The GNU Debugger
41662
41663@c man begin SYNOPSIS gdb
41664gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
41665[@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
41666[@option{-b}@w{ }@var{bps}]
41667 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
41668[@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
906ccdf0
JK
41669[@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
41670 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
41671[@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
43662968
JK
41672@c man end
41673
41674@c man begin DESCRIPTION gdb
41675The purpose of a debugger such as @value{GDBN} is to allow you to see what is
41676going on ``inside'' another program while it executes -- or what another
41677program was doing at the moment it crashed.
41678
41679@value{GDBN} can do four main kinds of things (plus other things in support of
41680these) to help you catch bugs in the act:
41681
41682@itemize @bullet
41683@item
41684Start your program, specifying anything that might affect its behavior.
41685
41686@item
41687Make your program stop on specified conditions.
41688
41689@item
41690Examine what has happened, when your program has stopped.
41691
41692@item
41693Change things in your program, so you can experiment with correcting the
41694effects of one bug and go on to learn about another.
41695@end itemize
41696
906ccdf0
JK
41697You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
41698Modula-2.
43662968
JK
41699
41700@value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
41701commands from the terminal until you tell it to exit with the @value{GDBN}
41702command @code{quit}. You can get online help from @value{GDBN} itself
41703by using the command @code{help}.
41704
41705You can run @code{gdb} with no arguments or options; but the most
41706usual way to start @value{GDBN} is with one argument or two, specifying an
41707executable program as the argument:
41708
41709@smallexample
41710gdb program
41711@end smallexample
41712
41713You can also start with both an executable program and a core file specified:
41714
41715@smallexample
41716gdb program core
41717@end smallexample
41718
41719You can, instead, specify a process ID as a second argument, if you want
41720to debug a running process:
41721
41722@smallexample
41723gdb program 1234
906ccdf0 41724gdb -p 1234
43662968
JK
41725@end smallexample
41726
41727@noindent
41728would attach @value{GDBN} to process @code{1234} (unless you also have a file
41729named @file{1234}; @value{GDBN} does check for a core file first).
906ccdf0 41730With option @option{-p} you can omit the @var{program} filename.
43662968
JK
41731
41732Here are some of the most frequently needed @value{GDBN} commands:
41733
41734@c pod2man highlights the right hand side of the @item lines.
41735@table @env
41736@item break [@var{file}:]@var{functiop}
41737Set a breakpoint at @var{function} (in @var{file}).
41738
41739@item run [@var{arglist}]
41740Start your program (with @var{arglist}, if specified).
41741
41742@item bt
41743Backtrace: display the program stack.
41744
41745@item print @var{expr}
41746Display the value of an expression.
41747
41748@item c
41749Continue running your program (after stopping, e.g. at a breakpoint).
41750
41751@item next
41752Execute next program line (after stopping); step @emph{over} any
41753function calls in the line.
41754
41755@item edit [@var{file}:]@var{function}
41756look at the program line where it is presently stopped.
41757
41758@item list [@var{file}:]@var{function}
41759type the text of the program in the vicinity of where it is presently stopped.
41760
41761@item step
41762Execute next program line (after stopping); step @emph{into} any
41763function calls in the line.
41764
41765@item help [@var{name}]
41766Show information about @value{GDBN} command @var{name}, or general information
41767about using @value{GDBN}.
41768
41769@item quit
41770Exit from @value{GDBN}.
41771@end table
41772
41773@ifset man
41774For full details on @value{GDBN},
41775see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
41776by Richard M. Stallman and Roland H. Pesch. The same text is available online
41777as the @code{gdb} entry in the @code{info} program.
41778@end ifset
41779@c man end
41780
41781@c man begin OPTIONS gdb
41782Any arguments other than options specify an executable
41783file and core file (or process ID); that is, the first argument
41784encountered with no
41785associated option flag is equivalent to a @option{-se} option, and the second,
41786if any, is equivalent to a @option{-c} option if it's the name of a file.
41787Many options have
41788both long and short forms; both are shown here. The long forms are also
41789recognized if you truncate them, so long as enough of the option is
41790present to be unambiguous. (If you prefer, you can flag option
41791arguments with @option{+} rather than @option{-}, though we illustrate the
41792more usual convention.)
41793
41794All the options and command line arguments you give are processed
41795in sequential order. The order makes a difference when the @option{-x}
41796option is used.
41797
41798@table @env
41799@item -help
41800@itemx -h
41801List all options, with brief explanations.
41802
41803@item -symbols=@var{file}
41804@itemx -s @var{file}
41805Read symbol table from file @var{file}.
41806
41807@item -write
41808Enable writing into executable and core files.
41809
41810@item -exec=@var{file}
41811@itemx -e @var{file}
41812Use file @var{file} as the executable file to execute when
41813appropriate, and for examining pure data in conjunction with a core
41814dump.
41815
41816@item -se=@var{file}
41817Read symbol table from file @var{file} and use it as the executable
41818file.
41819
41820@item -core=@var{file}
41821@itemx -c @var{file}
41822Use file @var{file} as a core dump to examine.
41823
41824@item -command=@var{file}
41825@itemx -x @var{file}
41826Execute @value{GDBN} commands from file @var{file}.
41827
41828@item -ex @var{command}
41829Execute given @value{GDBN} @var{command}.
41830
41831@item -directory=@var{directory}
41832@itemx -d @var{directory}
41833Add @var{directory} to the path to search for source files.
41834
41835@item -nh
41836Do not execute commands from @file{~/.gdbinit}.
41837
41838@item -nx
41839@itemx -n
41840Do not execute commands from any @file{.gdbinit} initialization files.
41841
41842@item -quiet
41843@itemx -q
41844``Quiet''. Do not print the introductory and copyright messages. These
41845messages are also suppressed in batch mode.
41846
41847@item -batch
41848Run in batch mode. Exit with status @code{0} after processing all the command
41849files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
41850Exit with nonzero status if an error occurs in executing the @value{GDBN}
41851commands in the command files.
41852
41853Batch mode may be useful for running @value{GDBN} as a filter, for example to
41854download and run a program on another computer; in order to make this
41855more useful, the message
41856
41857@smallexample
41858Program exited normally.
41859@end smallexample
41860
41861@noindent
41862(which is ordinarily issued whenever a program running under @value{GDBN} control
41863terminates) is not issued when running in batch mode.
41864
41865@item -cd=@var{directory}
41866Run @value{GDBN} using @var{directory} as its working directory,
41867instead of the current directory.
41868
41869@item -fullname
41870@itemx -f
41871Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
41872@value{GDBN} to output the full file name and line number in a standard,
41873recognizable fashion each time a stack frame is displayed (which
41874includes each time the program stops). This recognizable format looks
41875like two @samp{\032} characters, followed by the file name, line number
41876and character position separated by colons, and a newline. The
41877Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
41878characters as a signal to display the source code for the frame.
41879
41880@item -b @var{bps}
41881Set the line speed (baud rate or bits per second) of any serial
41882interface used by @value{GDBN} for remote debugging.
41883
41884@item -tty=@var{device}
41885Run using @var{device} for your program's standard input and output.
41886@end table
41887@c man end
41888
41889@c man begin SEEALSO gdb
41890@ifset man
41891The full documentation for @value{GDBN} is maintained as a Texinfo manual.
41892If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
41893documentation are properly installed at your site, the command
41894
41895@smallexample
41896info gdb
41897@end smallexample
41898
41899@noindent
41900should give you access to the complete manual.
41901
41902@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
41903Richard M. Stallman and Roland H. Pesch, July 1991.
41904@end ifset
41905@c man end
41906
41907@node gdbserver man
41908@heading gdbserver man
41909
41910@c man title gdbserver Remote Server for the GNU Debugger
41911@format
41912@c man begin SYNOPSIS gdbserver
5b8b6385 41913gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
43662968 41914
5b8b6385
JK
41915gdbserver --attach @var{comm} @var{pid}
41916
41917gdbserver --multi @var{comm}
43662968
JK
41918@c man end
41919@end format
41920
41921@c man begin DESCRIPTION gdbserver
41922@command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
41923than the one which is running the program being debugged.
41924
41925@ifclear man
41926@subheading Usage (server (target) side)
41927@end ifclear
41928@ifset man
41929Usage (server (target) side):
41930@end ifset
41931
41932First, you need to have a copy of the program you want to debug put onto
41933the target system. The program can be stripped to save space if needed, as
41934@command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
41935the @value{GDBN} running on the host system.
41936
41937To use the server, you log on to the target system, and run the @command{gdbserver}
41938program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
41939your program, and (c) its arguments. The general syntax is:
41940
41941@smallexample
41942target> gdbserver @var{comm} @var{program} [@var{args} ...]
41943@end smallexample
41944
41945For example, using a serial port, you might say:
41946
41947@smallexample
41948@ifset man
41949@c @file would wrap it as F</dev/com1>.
41950target> gdbserver /dev/com1 emacs foo.txt
41951@end ifset
41952@ifclear man
41953target> gdbserver @file{/dev/com1} emacs foo.txt
41954@end ifclear
41955@end smallexample
41956
41957This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
41958to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
41959waits patiently for the host @value{GDBN} to communicate with it.
41960
41961To use a TCP connection, you could say:
41962
41963@smallexample
41964target> gdbserver host:2345 emacs foo.txt
41965@end smallexample
41966
41967This says pretty much the same thing as the last example, except that we are
41968going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
41969that we are expecting to see a TCP connection from @code{host} to local TCP port
419702345. (Currently, the @code{host} part is ignored.) You can choose any number you
41971want for the port number as long as it does not conflict with any existing TCP
41972ports on the target system. This same port number must be used in the host
41973@value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
41974you chose a port number that conflicts with another service, @command{gdbserver} will
41975print an error message and exit.
41976
5b8b6385 41977@command{gdbserver} can also attach to running programs.
43662968
JK
41978This is accomplished via the @option{--attach} argument. The syntax is:
41979
41980@smallexample
5b8b6385 41981target> gdbserver --attach @var{comm} @var{pid}
43662968
JK
41982@end smallexample
41983
41984@var{pid} is the process ID of a currently running process. It isn't
41985necessary to point @command{gdbserver} at a binary for the running process.
41986
5b8b6385
JK
41987To start @code{gdbserver} without supplying an initial command to run
41988or process ID to attach, use the @option{--multi} command line option.
41989In such case you should connect using @kbd{target extended-remote} to start
41990the program you want to debug.
41991
41992@smallexample
41993target> gdbserver --multi @var{comm}
41994@end smallexample
41995
43662968
JK
41996@ifclear man
41997@subheading Usage (host side)
41998@end ifclear
41999@ifset man
42000Usage (host side):
42001@end ifset
42002
42003You need an unstripped copy of the target program on your host system, since
42004@value{GDBN} needs to examine it's symbol tables and such. Start up @value{GDBN} as you normally
42005would, with the target program as the first argument. (You may need to use the
42006@option{--baud} option if the serial line is running at anything except 9600 baud.)
42007That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
5b8b6385
JK
42008new command you need to know about is @code{target remote}
42009(or @code{target extended-remote}). Its argument is either
43662968
JK
42010a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
42011descriptor. For example:
42012
42013@smallexample
42014@ifset man
42015@c @file would wrap it as F</dev/ttyb>.
42016(gdb) target remote /dev/ttyb
42017@end ifset
42018@ifclear man
42019(gdb) target remote @file{/dev/ttyb}
42020@end ifclear
42021@end smallexample
42022
42023@noindent
42024communicates with the server via serial line @file{/dev/ttyb}, and:
42025
42026@smallexample
42027(gdb) target remote the-target:2345
42028@end smallexample
42029
42030@noindent
42031communicates via a TCP connection to port 2345 on host `the-target', where
42032you previously started up @command{gdbserver} with the same port number. Note that for
42033TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
42034command, otherwise you may get an error that looks something like
42035`Connection refused'.
5b8b6385
JK
42036
42037@command{gdbserver} can also debug multiple inferiors at once,
42038described in
42039@ifset man
42040the @value{GDBN} manual in node @code{Inferiors and Programs}
42041-- shell command @code{info -f gdb -n 'Inferiors and Programs'}.
42042@end ifset
42043@ifclear man
42044@ref{Inferiors and Programs}.
42045@end ifclear
42046In such case use the @code{extended-remote} @value{GDBN} command variant:
42047
42048@smallexample
42049(gdb) target extended-remote the-target:2345
42050@end smallexample
42051
42052The @command{gdbserver} option @option{--multi} may or may not be used in such
42053case.
43662968
JK
42054@c man end
42055
42056@c man begin OPTIONS gdbserver
5b8b6385
JK
42057There are three different modes for invoking @command{gdbserver}:
42058
42059@itemize @bullet
42060
42061@item
42062Debug a specific program specified by its program name:
42063
42064@smallexample
42065gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
42066@end smallexample
42067
42068The @var{comm} parameter specifies how should the server communicate
42069with @value{GDBN}; it is either a device name (to use a serial line),
42070a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
42071stdin/stdout of @code{gdbserver}. Specify the name of the program to
42072debug in @var{prog}. Any remaining arguments will be passed to the
42073program verbatim. When the program exits, @value{GDBN} will close the
42074connection, and @code{gdbserver} will exit.
42075
42076@item
42077Debug a specific program by specifying the process ID of a running
42078program:
42079
42080@smallexample
42081gdbserver --attach @var{comm} @var{pid}
42082@end smallexample
42083
42084The @var{comm} parameter is as described above. Supply the process ID
42085of a running program in @var{pid}; @value{GDBN} will do everything
42086else. Like with the previous mode, when the process @var{pid} exits,
42087@value{GDBN} will close the connection, and @code{gdbserver} will exit.
42088
42089@item
42090Multi-process mode -- debug more than one program/process:
42091
42092@smallexample
42093gdbserver --multi @var{comm}
42094@end smallexample
42095
42096In this mode, @value{GDBN} can instruct @command{gdbserver} which
42097command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
42098close the connection when a process being debugged exits, so you can
42099debug several processes in the same session.
42100@end itemize
42101
42102In each of the modes you may specify these options:
42103
42104@table @env
42105
42106@item --help
42107List all options, with brief explanations.
42108
42109@item --version
42110This option causes @command{gdbserver} to print its version number and exit.
42111
42112@item --attach
42113@command{gdbserver} will attach to a running program. The syntax is:
42114
42115@smallexample
42116target> gdbserver --attach @var{comm} @var{pid}
42117@end smallexample
42118
42119@var{pid} is the process ID of a currently running process. It isn't
42120necessary to point @command{gdbserver} at a binary for the running process.
42121
42122@item --multi
42123To start @code{gdbserver} without supplying an initial command to run
42124or process ID to attach, use this command line option.
42125Then you can connect using @kbd{target extended-remote} and start
42126the program you want to debug. The syntax is:
42127
42128@smallexample
42129target> gdbserver --multi @var{comm}
42130@end smallexample
42131
42132@item --debug
42133Instruct @code{gdbserver} to display extra status information about the debugging
42134process.
42135This option is intended for @code{gdbserver} development and for bug reports to
42136the developers.
42137
42138@item --remote-debug
42139Instruct @code{gdbserver} to display remote protocol debug output.
42140This option is intended for @code{gdbserver} development and for bug reports to
42141the developers.
42142
42143@item --wrapper
42144Specify a wrapper to launch programs
42145for debugging. The option should be followed by the name of the
42146wrapper, then any command-line arguments to pass to the wrapper, then
42147@kbd{--} indicating the end of the wrapper arguments.
42148
42149@item --once
42150By default, @command{gdbserver} keeps the listening TCP port open, so that
42151additional connections are possible. However, if you start @code{gdbserver}
42152with the @option{--once} option, it will stop listening for any further
42153connection attempts after connecting to the first @value{GDBN} session.
42154
42155@c --disable-packet is not documented for users.
42156
42157@c --disable-randomization and --no-disable-randomization are superseded by
42158@c QDisableRandomization.
42159
42160@end table
43662968
JK
42161@c man end
42162
42163@c man begin SEEALSO gdbserver
42164@ifset man
42165The full documentation for @value{GDBN} is maintained as a Texinfo manual.
42166If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
42167documentation are properly installed at your site, the command
42168
42169@smallexample
42170info gdb
42171@end smallexample
42172
42173should give you access to the complete manual.
42174
42175@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
42176Richard M. Stallman and Roland H. Pesch, July 1991.
42177@end ifset
42178@c man end
42179
42180@node gdbinit man
42181@heading gdbinit
42182
42183@c man title gdbinit GDB initialization scripts
42184
42185@format
42186@c man begin SYNOPSIS gdbinit
42187@ifset SYSTEM_GDBINIT
42188@value{SYSTEM_GDBINIT}
42189@end ifset
42190
42191~/.gdbinit
42192
42193./.gdbinit
42194@c man end
42195@end format
42196
42197@c man begin DESCRIPTION gdbinit
42198These files contain @value{GDBN} commands to automatically execute during
42199@value{GDBN} startup. The lines of contents are canned sequences of commands,
42200described in
42201@ifset man
42202the @value{GDBN} manual in node @code{Sequences}
42203-- shell command @code{info -f gdb -n Sequences}.
42204@end ifset
42205@ifclear man
42206@ref{Sequences}.
42207@end ifclear
42208
42209Please read more in
42210@ifset man
42211the @value{GDBN} manual in node @code{Startup}
42212-- shell command @code{info -f gdb -n Startup}.
42213@end ifset
42214@ifclear man
42215@ref{Startup}.
42216@end ifclear
42217
42218@table @env
42219@ifset SYSTEM_GDBINIT
42220@item @value{SYSTEM_GDBINIT}
42221@end ifset
42222@ifclear SYSTEM_GDBINIT
42223@item (not enabled with @code{--with-system-gdbinit} during compilation)
42224@end ifclear
42225System-wide initialization file. It is executed unless user specified
42226@value{GDBN} option @code{-nx} or @code{-n}.
42227See more in
42228@ifset man
42229the @value{GDBN} manual in node @code{System-wide configuration}
42230-- shell command @code{info -f gdb -n 'System-wide configuration'}.
42231@end ifset
42232@ifclear man
42233@ref{System-wide configuration}.
42234@end ifclear
42235
42236@item ~/.gdbinit
42237User initialization file. It is executed unless user specified
42238@value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
42239
42240@item ./.gdbinit
42241Initialization file for current directory. It may need to be enabled with
42242@value{GDBN} security command @code{set auto-load local-gdbinit}.
42243See more in
42244@ifset man
42245the @value{GDBN} manual in node @code{Init File in the Current Directory}
42246-- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
42247@end ifset
42248@ifclear man
42249@ref{Init File in the Current Directory}.
42250@end ifclear
42251@end table
42252@c man end
42253
42254@c man begin SEEALSO gdbinit
42255@ifset man
42256gdb(1), @code{info -f gdb -n Startup}
42257
42258The full documentation for @value{GDBN} is maintained as a Texinfo manual.
42259If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
42260documentation are properly installed at your site, the command
42261
42262@smallexample
42263info gdb
42264@end smallexample
42265
42266should give you access to the complete manual.
42267
42268@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
42269Richard M. Stallman and Roland H. Pesch, July 1991.
42270@end ifset
42271@c man end
42272
aab4e0ec 42273@include gpl.texi
eb12ee30 42274
e4c0cfae
SS
42275@node GNU Free Documentation License
42276@appendix GNU Free Documentation License
6826cf00
EZ
42277@include fdl.texi
42278
00595b5e
EZ
42279@node Concept Index
42280@unnumbered Concept Index
c906108c
SS
42281
42282@printindex cp
42283
00595b5e
EZ
42284@node Command and Variable Index
42285@unnumbered Command, Variable, and Function Index
42286
42287@printindex fn
42288
c906108c 42289@tex
984359d2 42290% I think something like @@colophon should be in texinfo. In the
c906108c
SS
42291% meantime:
42292\long\def\colophon{\hbox to0pt{}\vfill
42293\centerline{The body of this manual is set in}
42294\centerline{\fontname\tenrm,}
42295\centerline{with headings in {\bf\fontname\tenbf}}
42296\centerline{and examples in {\tt\fontname\tentt}.}
42297\centerline{{\it\fontname\tenit\/},}
42298\centerline{{\bf\fontname\tenbf}, and}
42299\centerline{{\sl\fontname\tensl\/}}
42300\centerline{are used for emphasis.}\vfill}
42301\page\colophon
984359d2 42302% Blame: doc@@cygnus.com, 1991.
c906108c
SS
42303@end tex
42304
c906108c 42305@bye
This page took 5.535506 seconds and 4 git commands to generate.