* emulparams/aarch64linux.sh (LIBPATH_SUFFIX): Set to 64 for
[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
9@include gdb-cfg.texi
10@c
c906108c 11@settitle Debugging with @value{GDBN}
c906108c
SS
12@setchapternewpage odd
13@c %**end of header
14
15@iftex
16@c @smallbook
17@c @cropmarks
18@end iftex
19
20@finalout
00595b5e
EZ
21@c To avoid file-name clashes between index.html and Index.html, when
22@c the manual is produced on a Posix host and then moved to a
23@c case-insensitive filesystem (e.g., MS-Windows), we separate the
24@c indices into two: Concept Index and all the rest.
25@syncodeindex ky fn
26@syncodeindex tp fn
c906108c 27
41afff9a 28@c readline appendices use @vindex, @findex and @ftable,
48e934c6 29@c annotate.texi and gdbmi use @findex.
00595b5e 30@syncodeindex vr fn
c906108c
SS
31
32@c !!set GDB manual's edition---not the same as GDB version!
9fe8321b 33@c This is updated by GNU Press.
26829f2b 34@set EDITION Tenth
c906108c 35
87885426
FN
36@c !!set GDB edit command default editor
37@set EDITOR /bin/ex
c906108c 38
6c0e9fb3 39@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
c906108c 40
c906108c 41@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 42@c manuals to an info tree.
03727ca6 43@dircategory Software development
96a2c332 44@direntry
03727ca6 45* Gdb: (gdb). The GNU debugger.
96a2c332
SS
46@end direntry
47
a67ec3f4 48@copying
28e7fd62 49Copyright @copyright{} 1988-2013 Free Software Foundation, Inc.
c906108c 50
e9c75b65 51Permission is granted to copy, distribute and/or modify this document
4f5d9f07 52under the terms of the GNU Free Documentation License, Version 1.3 or
e9c75b65 53any later version published by the Free Software Foundation; with the
959acfd1
EZ
54Invariant Sections being ``Free Software'' and ``Free Software Needs
55Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
56and with the Back-Cover Texts as in (a) below.
c906108c 57
b8533aec
DJ
58(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
59this GNU Manual. Buying copies from GNU Press supports the FSF in
60developing GNU and promoting software freedom.''
a67ec3f4
JM
61@end copying
62
63@ifnottex
64This file documents the @sc{gnu} debugger @value{GDBN}.
65
66This is the @value{EDITION} Edition, of @cite{Debugging with
67@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
68@ifset VERSION_PACKAGE
69@value{VERSION_PACKAGE}
70@end ifset
71Version @value{GDBVN}.
72
73@insertcopying
74@end ifnottex
c906108c
SS
75
76@titlepage
77@title Debugging with @value{GDBN}
78@subtitle The @sc{gnu} Source-Level Debugger
c906108c 79@sp 1
c906108c 80@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
c16158bc
JM
81@ifset VERSION_PACKAGE
82@sp 1
83@subtitle @value{VERSION_PACKAGE}
84@end ifset
9e9c5ae7 85@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 86@page
c906108c
SS
87@tex
88{\parskip=0pt
c16158bc 89\hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
c906108c
SS
90\hfill {\it Debugging with @value{GDBN}}\par
91\hfill \TeX{}info \texinfoversion\par
92}
93@end tex
53a5351d 94
c906108c 95@vskip 0pt plus 1filll
c906108c 96Published by the Free Software Foundation @*
c02a867d
EZ
9751 Franklin Street, Fifth Floor,
98Boston, MA 02110-1301, USA@*
26829f2b 99ISBN 978-0-9831592-3-0 @*
e9c75b65 100
a67ec3f4 101@insertcopying
c906108c
SS
102@end titlepage
103@page
104
6c0e9fb3 105@ifnottex
6d2ebf8b
SS
106@node Top, Summary, (dir), (dir)
107
c906108c
SS
108@top Debugging with @value{GDBN}
109
110This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
111
c16158bc
JM
112This is the @value{EDITION} Edition, for @value{GDBN}
113@ifset VERSION_PACKAGE
114@value{VERSION_PACKAGE}
115@end ifset
116Version @value{GDBVN}.
c906108c 117
28e7fd62 118Copyright (C) 1988-2013 Free Software Foundation, Inc.
6d2ebf8b 119
3fb6a982
JB
120This edition of the GDB manual is dedicated to the memory of Fred
121Fish. Fred was a long-standing contributor to GDB and to Free
122software in general. We will miss him.
123
6d2ebf8b
SS
124@menu
125* Summary:: Summary of @value{GDBN}
126* Sample Session:: A sample @value{GDBN} session
127
128* Invocation:: Getting in and out of @value{GDBN}
129* Commands:: @value{GDBN} commands
130* Running:: Running programs under @value{GDBN}
131* Stopping:: Stopping and continuing
bacec72f 132* Reverse Execution:: Running programs backward
a2311334 133* Process Record and Replay:: Recording inferior's execution and replaying it
6d2ebf8b
SS
134* Stack:: Examining the stack
135* Source:: Examining source files
136* Data:: Examining data
edb3359d 137* Optimized Code:: Debugging optimized code
e2e0bcd1 138* Macros:: Preprocessor Macros
b37052ae 139* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 140* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
141
142* Languages:: Using @value{GDBN} with different languages
143
144* Symbols:: Examining the symbol table
145* Altering:: Altering execution
146* GDB Files:: @value{GDBN} files
147* Targets:: Specifying a debugging target
6b2f586d 148* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
149* Configurations:: Configuration-specific information
150* Controlling GDB:: Controlling @value{GDBN}
d57a3c85 151* Extending GDB:: Extending @value{GDBN}
21c294e6 152* Interpreters:: Command Interpreters
c8f4133a 153* TUI:: @value{GDBN} Text User Interface
6d2ebf8b 154* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
7162c0ca 155* GDB/MI:: @value{GDBN}'s Machine Interface.
c8f4133a 156* Annotations:: @value{GDBN}'s annotation interface.
4efc6507 157* JIT Interface:: Using the JIT debugging interface.
d1feda86 158* In-Process Agent:: In-Process Agent
6d2ebf8b
SS
159
160* GDB Bugs:: Reporting bugs in @value{GDBN}
6d2ebf8b 161
39037522
TT
162@ifset SYSTEM_READLINE
163* Command Line Editing: (rluserman). Command Line Editing
164* Using History Interactively: (history). Using History Interactively
165@end ifset
166@ifclear SYSTEM_READLINE
6d2ebf8b
SS
167* Command Line Editing:: Command Line Editing
168* Using History Interactively:: Using History Interactively
39037522 169@end ifclear
4ceed123 170* In Memoriam:: In Memoriam
0869d01b 171* Formatting Documentation:: How to format and print @value{GDBN} documentation
6d2ebf8b 172* Installing GDB:: Installing GDB
eb12ee30 173* Maintenance Commands:: Maintenance Commands
e0ce93ac 174* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 175* Agent Expressions:: The GDB Agent Expression Mechanism
23181151
DJ
176* Target Descriptions:: How targets can describe themselves to
177 @value{GDBN}
07e059b5
VP
178* Operating System Information:: Getting additional information from
179 the operating system
00bf0b85 180* Trace File Format:: GDB trace file format
90476074 181* Index Section Format:: .gdb_index section format
aab4e0ec
AC
182* Copying:: GNU General Public License says
183 how you can copy and share GDB
6826cf00 184* GNU Free Documentation License:: The license for this documentation
00595b5e
EZ
185* Concept Index:: Index of @value{GDBN} concepts
186* Command and Variable Index:: Index of @value{GDBN} commands, variables,
187 functions, and Python data types
6d2ebf8b
SS
188@end menu
189
6c0e9fb3 190@end ifnottex
c906108c 191
449f3b6c 192@contents
449f3b6c 193
6d2ebf8b 194@node Summary
c906108c
SS
195@unnumbered Summary of @value{GDBN}
196
197The purpose of a debugger such as @value{GDBN} is to allow you to see what is
198going on ``inside'' another program while it executes---or what another
199program was doing at the moment it crashed.
200
201@value{GDBN} can do four main kinds of things (plus other things in support of
202these) to help you catch bugs in the act:
203
204@itemize @bullet
205@item
206Start your program, specifying anything that might affect its behavior.
207
208@item
209Make your program stop on specified conditions.
210
211@item
212Examine what has happened, when your program has stopped.
213
214@item
215Change things in your program, so you can experiment with correcting the
216effects of one bug and go on to learn about another.
217@end itemize
218
49efadf5 219You can use @value{GDBN} to debug programs written in C and C@t{++}.
79a6e687 220For more information, see @ref{Supported Languages,,Supported Languages}.
c906108c
SS
221For more information, see @ref{C,,C and C++}.
222
6aecb9c2
JB
223Support for D is partial. For information on D, see
224@ref{D,,D}.
225
cce74817 226@cindex Modula-2
e632838e
AC
227Support for Modula-2 is partial. For information on Modula-2, see
228@ref{Modula-2,,Modula-2}.
c906108c 229
f4b8a18d
KW
230Support for OpenCL C is partial. For information on OpenCL C, see
231@ref{OpenCL C,,OpenCL C}.
232
cce74817
JM
233@cindex Pascal
234Debugging Pascal programs which use sets, subranges, file variables, or
235nested functions does not currently work. @value{GDBN} does not support
236entering expressions, printing values, or similar features using Pascal
237syntax.
c906108c 238
c906108c
SS
239@cindex Fortran
240@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 241it may be necessary to refer to some variables with a trailing
cce74817 242underscore.
c906108c 243
b37303ee
AF
244@value{GDBN} can be used to debug programs written in Objective-C,
245using either the Apple/NeXT or the GNU Objective-C runtime.
246
c906108c
SS
247@menu
248* Free Software:: Freely redistributable software
984359d2 249* Free Documentation:: Free Software Needs Free Documentation
c906108c
SS
250* Contributors:: Contributors to GDB
251@end menu
252
6d2ebf8b 253@node Free Software
79a6e687 254@unnumberedsec Free Software
c906108c 255
5d161b24 256@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
257General Public License
258(GPL). The GPL gives you the freedom to copy or adapt a licensed
259program---but every person getting a copy also gets with it the
260freedom to modify that copy (which means that they must get access to
261the source code), and the freedom to distribute further copies.
262Typical software companies use copyrights to limit your freedoms; the
263Free Software Foundation uses the GPL to preserve these freedoms.
264
265Fundamentally, the General Public License is a license which says that
266you have these freedoms and that you cannot take these freedoms away
267from anyone else.
268
984359d2 269@node Free Documentation
2666264b 270@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
271
272The biggest deficiency in the free software community today is not in
273the software---it is the lack of good free documentation that we can
274include with the free software. Many of our most important
275programs do not come with free reference manuals and free introductory
276texts. Documentation is an essential part of any software package;
277when an important free software package does not come with a free
278manual and a free tutorial, that is a major gap. We have many such
279gaps today.
280
281Consider Perl, for instance. The tutorial manuals that people
282normally use are non-free. How did this come about? Because the
283authors of those manuals published them with restrictive terms---no
284copying, no modification, source files not available---which exclude
285them from the free software world.
286
287That wasn't the first time this sort of thing happened, and it was far
288from the last. Many times we have heard a GNU user eagerly describe a
289manual that he is writing, his intended contribution to the community,
290only to learn that he had ruined everything by signing a publication
291contract to make it non-free.
292
293Free documentation, like free software, is a matter of freedom, not
294price. The problem with the non-free manual is not that publishers
295charge a price for printed copies---that in itself is fine. (The Free
296Software Foundation sells printed copies of manuals, too.) The
297problem is the restrictions on the use of the manual. Free manuals
298are available in source code form, and give you permission to copy and
299modify. Non-free manuals do not allow this.
300
301The criteria of freedom for a free manual are roughly the same as for
302free software. Redistribution (including the normal kinds of
303commercial redistribution) must be permitted, so that the manual can
304accompany every copy of the program, both on-line and on paper.
305
306Permission for modification of the technical content is crucial too.
307When people modify the software, adding or changing features, if they
308are conscientious they will change the manual too---so they can
309provide accurate and clear documentation for the modified program. A
310manual that leaves you no choice but to write a new manual to document
311a changed version of the program is not really available to our
312community.
313
314Some kinds of limits on the way modification is handled are
315acceptable. For example, requirements to preserve the original
316author's copyright notice, the distribution terms, or the list of
317authors, are ok. It is also no problem to require modified versions
318to include notice that they were modified. Even entire sections that
319may not be deleted or changed are acceptable, as long as they deal
320with nontechnical topics (like this one). These kinds of restrictions
321are acceptable because they don't obstruct the community's normal use
322of the manual.
323
324However, it must be possible to modify all the @emph{technical}
325content of the manual, and then distribute the result in all the usual
326media, through all the usual channels. Otherwise, the restrictions
327obstruct the use of the manual, it is not free, and we need another
328manual to replace it.
329
330Please spread the word about this issue. Our community continues to
331lose manuals to proprietary publishing. If we spread the word that
332free software needs free reference manuals and free tutorials, perhaps
333the next person who wants to contribute by writing documentation will
334realize, before it is too late, that only free manuals contribute to
335the free software community.
336
337If you are writing documentation, please insist on publishing it under
338the GNU Free Documentation License or another free documentation
339license. Remember that this decision requires your approval---you
340don't have to let the publisher decide. Some commercial publishers
341will use a free license if you insist, but they will not propose the
342option; it is up to you to raise the issue and say firmly that this is
343what you want. If the publisher you are dealing with refuses, please
344try other publishers. If you're not sure whether a proposed license
42584a72 345is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
346
347You can encourage commercial publishers to sell more free, copylefted
348manuals and tutorials by buying them, and particularly by buying
349copies from the publishers that paid for their writing or for major
350improvements. Meanwhile, try to avoid buying non-free documentation
351at all. Check the distribution terms of a manual before you buy it,
352and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
353Check the history of the book, and try to reward the publishers that
354have paid or pay the authors to work on it.
959acfd1
EZ
355
356The Free Software Foundation maintains a list of free documentation
357published by other publishers, at
358@url{http://www.fsf.org/doc/other-free-books.html}.
359
6d2ebf8b 360@node Contributors
96a2c332
SS
361@unnumberedsec Contributors to @value{GDBN}
362
363Richard Stallman was the original author of @value{GDBN}, and of many
364other @sc{gnu} programs. Many others have contributed to its
365development. This section attempts to credit major contributors. One
366of the virtues of free software is that everyone is free to contribute
367to it; with regret, we cannot actually acknowledge everyone here. The
368file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
369blow-by-blow account.
370
371Changes much prior to version 2.0 are lost in the mists of time.
372
373@quotation
374@emph{Plea:} Additions to this section are particularly welcome. If you
375or your friends (or enemies, to be evenhanded) have been unfairly
376omitted from this list, we would like to add your names!
377@end quotation
378
379So that they may not regard their many labors as thankless, we
380particularly thank those who shepherded @value{GDBN} through major
381releases:
7ba3cf9c 382Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
383Jim Blandy (release 4.18);
384Jason Molenda (release 4.17);
385Stan Shebs (release 4.14);
386Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
387Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
388John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
389Jim Kingdon (releases 3.5, 3.4, and 3.3);
390and Randy Smith (releases 3.2, 3.1, and 3.0).
391
392Richard Stallman, assisted at various times by Peter TerMaat, Chris
393Hanson, and Richard Mlynarik, handled releases through 2.8.
394
b37052ae
EZ
395Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
396in @value{GDBN}, with significant additional contributions from Per
397Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
398demangler. Early work on C@t{++} was by Peter TerMaat (who also did
399much general update work leading to release 3.0).
c906108c 400
b37052ae 401@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
402object-file formats; BFD was a joint project of David V.
403Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
404
405David Johnson wrote the original COFF support; Pace Willison did
406the original support for encapsulated COFF.
407
0179ffac 408Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
409
410Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
411Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
412support.
413Jean-Daniel Fekete contributed Sun 386i support.
414Chris Hanson improved the HP9000 support.
415Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
416David Johnson contributed Encore Umax support.
417Jyrki Kuoppala contributed Altos 3068 support.
418Jeff Law contributed HP PA and SOM support.
419Keith Packard contributed NS32K support.
420Doug Rabson contributed Acorn Risc Machine support.
421Bob Rusk contributed Harris Nighthawk CX-UX support.
422Chris Smith contributed Convex support (and Fortran debugging).
423Jonathan Stone contributed Pyramid support.
424Michael Tiemann contributed SPARC support.
425Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
426Pace Willison contributed Intel 386 support.
427Jay Vosburgh contributed Symmetry support.
a37295f9 428Marko Mlinar contributed OpenRISC 1000 support.
c906108c 429
1104b9e7 430Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
431
432Rich Schaefer and Peter Schauer helped with support of SunOS shared
433libraries.
434
435Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
436about several machine instruction sets.
437
438Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
439remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
440contributed remote debugging modules for the i960, VxWorks, A29K UDI,
441and RDI targets, respectively.
442
443Brian Fox is the author of the readline libraries providing
444command-line editing and command history.
445
7a292a7a
SS
446Andrew Beers of SUNY Buffalo wrote the language-switching code, the
447Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 448
5d161b24 449Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 450He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 451symbols.
c906108c 452
f24c5e49
KI
453Hitachi America (now Renesas America), Ltd. sponsored the support for
454H8/300, H8/500, and Super-H processors.
c906108c
SS
455
456NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
457
f24c5e49
KI
458Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
459processors.
c906108c
SS
460
461Toshiba sponsored the support for the TX39 Mips processor.
462
463Matsushita sponsored the support for the MN10200 and MN10300 processors.
464
96a2c332 465Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
466
467Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
468watchpoints.
469
470Michael Snyder added support for tracepoints.
471
472Stu Grossman wrote gdbserver.
473
474Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 475nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
476
477The following people at the Hewlett-Packard Company contributed
478support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 479(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
480compiler, and the Text User Interface (nee Terminal User Interface):
481Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
482Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
483provided HP-specific information in this manual.
c906108c 484
b37052ae
EZ
485DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
486Robert Hoehne made significant contributions to the DJGPP port.
487
96a2c332
SS
488Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
489development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
490fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
491Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
492Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
493Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
494Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
495addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
496JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
497Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
498Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
499Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
500Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
501Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
502Zuhn have made contributions both large and small.
c906108c 503
ffed4509
AC
504Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
505Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
506
e2e0bcd1
JB
507Jim Blandy added support for preprocessor macros, while working for Red
508Hat.
c906108c 509
a9967aef
AC
510Andrew Cagney designed @value{GDBN}'s architecture vector. Many
511people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
512Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
513Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
514Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
515with the migration of old architectures to this new framework.
516
c5e30d01
AC
517Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
518unwinder framework, this consisting of a fresh new design featuring
519frame IDs, independent frame sniffers, and the sentinel frame. Mark
520Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
521libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
db2e3e2e 522trad unwinders. The architecture-specific changes, each involving a
c5e30d01
AC
523complete rewrite of the architecture's frame code, were carried out by
524Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
525Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
526Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
527Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
528Weigand.
529
ca3bf3bd
DJ
530Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
531Tensilica, Inc.@: contributed support for Xtensa processors. Others
532who have worked on the Xtensa port of @value{GDBN} in the past include
533Steve Tjiang, John Newlin, and Scott Foehner.
534
08be9d71
ME
535Michael Eager and staff of Xilinx, Inc., contributed support for the
536Xilinx MicroBlaze architecture.
537
6d2ebf8b 538@node Sample Session
c906108c
SS
539@chapter A Sample @value{GDBN} Session
540
541You can use this manual at your leisure to read all about @value{GDBN}.
542However, a handful of commands are enough to get started using the
543debugger. This chapter illustrates those commands.
544
545@iftex
546In this sample session, we emphasize user input like this: @b{input},
547to make it easier to pick out from the surrounding output.
548@end iftex
549
550@c FIXME: this example may not be appropriate for some configs, where
551@c FIXME...primary interest is in remote use.
552
553One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
554processor) exhibits the following bug: sometimes, when we change its
555quote strings from the default, the commands used to capture one macro
556definition within another stop working. In the following short @code{m4}
557session, we define a macro @code{foo} which expands to @code{0000}; we
558then use the @code{m4} built-in @code{defn} to define @code{bar} as the
559same thing. However, when we change the open quote string to
560@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
561procedure fails to define a new synonym @code{baz}:
562
563@smallexample
564$ @b{cd gnu/m4}
565$ @b{./m4}
566@b{define(foo,0000)}
567
568@b{foo}
5690000
570@b{define(bar,defn(`foo'))}
571
572@b{bar}
5730000
574@b{changequote(<QUOTE>,<UNQUOTE>)}
575
576@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
577@b{baz}
c8aa23ab 578@b{Ctrl-d}
c906108c
SS
579m4: End of input: 0: fatal error: EOF in string
580@end smallexample
581
582@noindent
583Let us use @value{GDBN} to try to see what is going on.
584
c906108c
SS
585@smallexample
586$ @b{@value{GDBP} m4}
587@c FIXME: this falsifies the exact text played out, to permit smallbook
588@c FIXME... format to come out better.
589@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 590 of it under certain conditions; type "show copying" to see
c906108c 591 the conditions.
5d161b24 592There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
593 for details.
594
595@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
596(@value{GDBP})
597@end smallexample
c906108c
SS
598
599@noindent
600@value{GDBN} reads only enough symbol data to know where to find the
601rest when needed; as a result, the first prompt comes up very quickly.
602We now tell @value{GDBN} to use a narrower display width than usual, so
603that examples fit in this manual.
604
605@smallexample
606(@value{GDBP}) @b{set width 70}
607@end smallexample
608
609@noindent
610We need to see how the @code{m4} built-in @code{changequote} works.
611Having looked at the source, we know the relevant subroutine is
612@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
613@code{break} command.
614
615@smallexample
616(@value{GDBP}) @b{break m4_changequote}
617Breakpoint 1 at 0x62f4: file builtin.c, line 879.
618@end smallexample
619
620@noindent
621Using the @code{run} command, we start @code{m4} running under @value{GDBN}
622control; as long as control does not reach the @code{m4_changequote}
623subroutine, the program runs as usual:
624
625@smallexample
626(@value{GDBP}) @b{run}
627Starting program: /work/Editorial/gdb/gnu/m4/m4
628@b{define(foo,0000)}
629
630@b{foo}
6310000
632@end smallexample
633
634@noindent
635To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
636suspends execution of @code{m4}, displaying information about the
637context where it stops.
638
639@smallexample
640@b{changequote(<QUOTE>,<UNQUOTE>)}
641
5d161b24 642Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
643 at builtin.c:879
644879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
645@end smallexample
646
647@noindent
648Now we use the command @code{n} (@code{next}) to advance execution to
649the next line of the current function.
650
651@smallexample
652(@value{GDBP}) @b{n}
653882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
654 : nil,
655@end smallexample
656
657@noindent
658@code{set_quotes} looks like a promising subroutine. We can go into it
659by using the command @code{s} (@code{step}) instead of @code{next}.
660@code{step} goes to the next line to be executed in @emph{any}
661subroutine, so it steps into @code{set_quotes}.
662
663@smallexample
664(@value{GDBP}) @b{s}
665set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
666 at input.c:530
667530 if (lquote != def_lquote)
668@end smallexample
669
670@noindent
671The display that shows the subroutine where @code{m4} is now
672suspended (and its arguments) is called a stack frame display. It
673shows a summary of the stack. We can use the @code{backtrace}
674command (which can also be spelled @code{bt}), to see where we are
675in the stack as a whole: the @code{backtrace} command displays a
676stack frame for each active subroutine.
677
678@smallexample
679(@value{GDBP}) @b{bt}
680#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
681 at input.c:530
5d161b24 682#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
683 at builtin.c:882
684#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
685#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
686 at macro.c:71
687#4 0x79dc in expand_input () at macro.c:40
688#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
689@end smallexample
690
691@noindent
692We step through a few more lines to see what happens. The first two
693times, we can use @samp{s}; the next two times we use @code{n} to avoid
694falling into the @code{xstrdup} subroutine.
695
696@smallexample
697(@value{GDBP}) @b{s}
6980x3b5c 532 if (rquote != def_rquote)
699(@value{GDBP}) @b{s}
7000x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
701def_lquote : xstrdup(lq);
702(@value{GDBP}) @b{n}
703536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
704 : xstrdup(rq);
705(@value{GDBP}) @b{n}
706538 len_lquote = strlen(rquote);
707@end smallexample
708
709@noindent
710The last line displayed looks a little odd; we can examine the variables
711@code{lquote} and @code{rquote} to see if they are in fact the new left
712and right quotes we specified. We use the command @code{p}
713(@code{print}) to see their values.
714
715@smallexample
716(@value{GDBP}) @b{p lquote}
717$1 = 0x35d40 "<QUOTE>"
718(@value{GDBP}) @b{p rquote}
719$2 = 0x35d50 "<UNQUOTE>"
720@end smallexample
721
722@noindent
723@code{lquote} and @code{rquote} are indeed the new left and right quotes.
724To look at some context, we can display ten lines of source
725surrounding the current line with the @code{l} (@code{list}) command.
726
727@smallexample
728(@value{GDBP}) @b{l}
729533 xfree(rquote);
730534
731535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
732 : xstrdup (lq);
733536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
734 : xstrdup (rq);
735537
736538 len_lquote = strlen(rquote);
737539 len_rquote = strlen(lquote);
738540 @}
739541
740542 void
741@end smallexample
742
743@noindent
744Let us step past the two lines that set @code{len_lquote} and
745@code{len_rquote}, and then examine the values of those variables.
746
747@smallexample
748(@value{GDBP}) @b{n}
749539 len_rquote = strlen(lquote);
750(@value{GDBP}) @b{n}
751540 @}
752(@value{GDBP}) @b{p len_lquote}
753$3 = 9
754(@value{GDBP}) @b{p len_rquote}
755$4 = 7
756@end smallexample
757
758@noindent
759That certainly looks wrong, assuming @code{len_lquote} and
760@code{len_rquote} are meant to be the lengths of @code{lquote} and
761@code{rquote} respectively. We can set them to better values using
762the @code{p} command, since it can print the value of
763any expression---and that expression can include subroutine calls and
764assignments.
765
766@smallexample
767(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
768$5 = 7
769(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
770$6 = 9
771@end smallexample
772
773@noindent
774Is that enough to fix the problem of using the new quotes with the
775@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
776executing with the @code{c} (@code{continue}) command, and then try the
777example that caused trouble initially:
778
779@smallexample
780(@value{GDBP}) @b{c}
781Continuing.
782
783@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
784
785baz
7860000
787@end smallexample
788
789@noindent
790Success! The new quotes now work just as well as the default ones. The
791problem seems to have been just the two typos defining the wrong
792lengths. We allow @code{m4} exit by giving it an EOF as input:
793
794@smallexample
c8aa23ab 795@b{Ctrl-d}
c906108c
SS
796Program exited normally.
797@end smallexample
798
799@noindent
800The message @samp{Program exited normally.} is from @value{GDBN}; it
801indicates @code{m4} has finished executing. We can end our @value{GDBN}
802session with the @value{GDBN} @code{quit} command.
803
804@smallexample
805(@value{GDBP}) @b{quit}
806@end smallexample
c906108c 807
6d2ebf8b 808@node Invocation
c906108c
SS
809@chapter Getting In and Out of @value{GDBN}
810
811This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 812The essentials are:
c906108c 813@itemize @bullet
5d161b24 814@item
53a5351d 815type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 816@item
c8aa23ab 817type @kbd{quit} or @kbd{Ctrl-d} to exit.
c906108c
SS
818@end itemize
819
820@menu
821* Invoking GDB:: How to start @value{GDBN}
822* Quitting GDB:: How to quit @value{GDBN}
823* Shell Commands:: How to use shell commands inside @value{GDBN}
79a6e687 824* Logging Output:: How to log @value{GDBN}'s output to a file
c906108c
SS
825@end menu
826
6d2ebf8b 827@node Invoking GDB
c906108c
SS
828@section Invoking @value{GDBN}
829
c906108c
SS
830Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
831@value{GDBN} reads commands from the terminal until you tell it to exit.
832
833You can also run @code{@value{GDBP}} with a variety of arguments and options,
834to specify more of your debugging environment at the outset.
835
c906108c
SS
836The command-line options described here are designed
837to cover a variety of situations; in some environments, some of these
5d161b24 838options may effectively be unavailable.
c906108c
SS
839
840The most usual way to start @value{GDBN} is with one argument,
841specifying an executable program:
842
474c8240 843@smallexample
c906108c 844@value{GDBP} @var{program}
474c8240 845@end smallexample
c906108c 846
c906108c
SS
847@noindent
848You can also start with both an executable program and a core file
849specified:
850
474c8240 851@smallexample
c906108c 852@value{GDBP} @var{program} @var{core}
474c8240 853@end smallexample
c906108c
SS
854
855You can, instead, specify a process ID as a second argument, if you want
856to debug a running process:
857
474c8240 858@smallexample
c906108c 859@value{GDBP} @var{program} 1234
474c8240 860@end smallexample
c906108c
SS
861
862@noindent
863would attach @value{GDBN} to process @code{1234} (unless you also have a file
864named @file{1234}; @value{GDBN} does check for a core file first).
865
c906108c 866Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
867complete operating system; when you use @value{GDBN} as a remote
868debugger attached to a bare board, there may not be any notion of
869``process'', and there is often no way to get a core dump. @value{GDBN}
870will warn you if it is unable to attach or to read core dumps.
c906108c 871
aa26fa3a
TT
872You can optionally have @code{@value{GDBP}} pass any arguments after the
873executable file to the inferior using @code{--args}. This option stops
874option processing.
474c8240 875@smallexample
3f94c067 876@value{GDBP} --args gcc -O2 -c foo.c
474c8240 877@end smallexample
aa26fa3a
TT
878This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
879@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
880
96a2c332 881You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
882@value{GDBN}'s non-warranty, by specifying @code{-silent}:
883
884@smallexample
885@value{GDBP} -silent
886@end smallexample
887
888@noindent
889You can further control how @value{GDBN} starts up by using command-line
890options. @value{GDBN} itself can remind you of the options available.
891
892@noindent
893Type
894
474c8240 895@smallexample
c906108c 896@value{GDBP} -help
474c8240 897@end smallexample
c906108c
SS
898
899@noindent
900to display all available options and briefly describe their use
901(@samp{@value{GDBP} -h} is a shorter equivalent).
902
903All options and command line arguments you give are processed
904in sequential order. The order makes a difference when the
905@samp{-x} option is used.
906
907
908@menu
c906108c
SS
909* File Options:: Choosing files
910* Mode Options:: Choosing modes
6fc08d32 911* Startup:: What @value{GDBN} does during startup
c906108c
SS
912@end menu
913
6d2ebf8b 914@node File Options
79a6e687 915@subsection Choosing Files
c906108c 916
2df3850c 917When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
918specifying an executable file and core file (or process ID). This is
919the same as if the arguments were specified by the @samp{-se} and
d52fb0e9 920@samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
19837790
MS
921first argument that does not have an associated option flag as
922equivalent to the @samp{-se} option followed by that argument; and the
923second argument that does not have an associated option flag, if any, as
924equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
925If the second argument begins with a decimal digit, @value{GDBN} will
926first attempt to attach to it as a process, and if that fails, attempt
927to open it as a corefile. If you have a corefile whose name begins with
b383017d 928a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 929prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
930
931If @value{GDBN} has not been configured to included core file support,
932such as for most embedded targets, then it will complain about a second
933argument and ignore it.
c906108c
SS
934
935Many options have both long and short forms; both are shown in the
936following list. @value{GDBN} also recognizes the long forms if you truncate
937them, so long as enough of the option is present to be unambiguous.
938(If you prefer, you can flag option arguments with @samp{--} rather
939than @samp{-}, though we illustrate the more usual convention.)
940
d700128c
EZ
941@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
942@c way, both those who look for -foo and --foo in the index, will find
943@c it.
944
c906108c
SS
945@table @code
946@item -symbols @var{file}
947@itemx -s @var{file}
d700128c
EZ
948@cindex @code{--symbols}
949@cindex @code{-s}
c906108c
SS
950Read symbol table from file @var{file}.
951
952@item -exec @var{file}
953@itemx -e @var{file}
d700128c
EZ
954@cindex @code{--exec}
955@cindex @code{-e}
7a292a7a
SS
956Use file @var{file} as the executable file to execute when appropriate,
957and for examining pure data in conjunction with a core dump.
c906108c
SS
958
959@item -se @var{file}
d700128c 960@cindex @code{--se}
c906108c
SS
961Read symbol table from file @var{file} and use it as the executable
962file.
963
c906108c
SS
964@item -core @var{file}
965@itemx -c @var{file}
d700128c
EZ
966@cindex @code{--core}
967@cindex @code{-c}
b383017d 968Use file @var{file} as a core dump to examine.
c906108c 969
19837790
MS
970@item -pid @var{number}
971@itemx -p @var{number}
972@cindex @code{--pid}
973@cindex @code{-p}
974Connect to process ID @var{number}, as with the @code{attach} command.
c906108c
SS
975
976@item -command @var{file}
977@itemx -x @var{file}
d700128c
EZ
978@cindex @code{--command}
979@cindex @code{-x}
95433b34
JB
980Execute commands from file @var{file}. The contents of this file is
981evaluated exactly as the @code{source} command would.
8150ff9c 982@xref{Command Files,, Command files}.
c906108c 983
8a5a3c82
AS
984@item -eval-command @var{command}
985@itemx -ex @var{command}
986@cindex @code{--eval-command}
987@cindex @code{-ex}
988Execute a single @value{GDBN} command.
989
990This option may be used multiple times to call multiple commands. It may
991also be interleaved with @samp{-command} as required.
992
993@smallexample
994@value{GDBP} -ex 'target sim' -ex 'load' \
995 -x setbreakpoints -ex 'run' a.out
996@end smallexample
997
8320cc4f
JK
998@item -init-command @var{file}
999@itemx -ix @var{file}
1000@cindex @code{--init-command}
1001@cindex @code{-ix}
2d7b58e8
JK
1002Execute commands from file @var{file} before loading the inferior (but
1003after loading gdbinit files).
8320cc4f
JK
1004@xref{Startup}.
1005
1006@item -init-eval-command @var{command}
1007@itemx -iex @var{command}
1008@cindex @code{--init-eval-command}
1009@cindex @code{-iex}
2d7b58e8
JK
1010Execute a single @value{GDBN} command before loading the inferior (but
1011after loading gdbinit files).
8320cc4f
JK
1012@xref{Startup}.
1013
c906108c
SS
1014@item -directory @var{directory}
1015@itemx -d @var{directory}
d700128c
EZ
1016@cindex @code{--directory}
1017@cindex @code{-d}
4b505b12 1018Add @var{directory} to the path to search for source and script files.
c906108c 1019
c906108c
SS
1020@item -r
1021@itemx -readnow
d700128c
EZ
1022@cindex @code{--readnow}
1023@cindex @code{-r}
c906108c
SS
1024Read each symbol file's entire symbol table immediately, rather than
1025the default, which is to read it incrementally as it is needed.
1026This makes startup slower, but makes future operations faster.
53a5351d 1027
c906108c
SS
1028@end table
1029
6d2ebf8b 1030@node Mode Options
79a6e687 1031@subsection Choosing Modes
c906108c
SS
1032
1033You can run @value{GDBN} in various alternative modes---for example, in
1034batch mode or quiet mode.
1035
1036@table @code
bf88dd68 1037@anchor{-nx}
c906108c
SS
1038@item -nx
1039@itemx -n
d700128c
EZ
1040@cindex @code{--nx}
1041@cindex @code{-n}
07540c15
DE
1042Do not execute commands found in any initialization file.
1043There are three init files, loaded in the following order:
1044
1045@table @code
1046@item @file{system.gdbinit}
1047This is the system-wide init file.
1048Its location is specified with the @code{--with-system-gdbinit}
1049configure option (@pxref{System-wide configuration}).
1050It is loaded first when @value{GDBN} starts, before command line options
1051have been processed.
1052@item @file{~/.gdbinit}
1053This is the init file in your home directory.
1054It is loaded next, after @file{system.gdbinit}, and before
1055command options have been processed.
1056@item @file{./.gdbinit}
1057This is the init file in the current directory.
1058It is loaded last, after command line options other than @code{-x} and
1059@code{-ex} have been processed. Command line options @code{-x} and
1060@code{-ex} are processed last, after @file{./.gdbinit} has been loaded.
1061@end table
1062
1063For further documentation on startup processing, @xref{Startup}.
1064For documentation on how to write command files,
1065@xref{Command Files,,Command Files}.
1066
1067@anchor{-nh}
1068@item -nh
1069@cindex @code{--nh}
1070Do not execute commands found in @file{~/.gdbinit}, the init file
1071in your home directory.
1072@xref{Startup}.
c906108c
SS
1073
1074@item -quiet
d700128c 1075@itemx -silent
c906108c 1076@itemx -q
d700128c
EZ
1077@cindex @code{--quiet}
1078@cindex @code{--silent}
1079@cindex @code{-q}
c906108c
SS
1080``Quiet''. Do not print the introductory and copyright messages. These
1081messages are also suppressed in batch mode.
1082
1083@item -batch
d700128c 1084@cindex @code{--batch}
c906108c
SS
1085Run in batch mode. Exit with status @code{0} after processing all the
1086command files specified with @samp{-x} (and all commands from
1087initialization files, if not inhibited with @samp{-n}). Exit with
1088nonzero status if an error occurs in executing the @value{GDBN} commands
5da1313b
JK
1089in the command files. Batch mode also disables pagination, sets unlimited
1090terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1091off} were in effect (@pxref{Messages/Warnings}).
c906108c 1092
2df3850c
JM
1093Batch mode may be useful for running @value{GDBN} as a filter, for
1094example to download and run a program on another computer; in order to
1095make this more useful, the message
c906108c 1096
474c8240 1097@smallexample
c906108c 1098Program exited normally.
474c8240 1099@end smallexample
c906108c
SS
1100
1101@noindent
2df3850c
JM
1102(which is ordinarily issued whenever a program running under
1103@value{GDBN} control terminates) is not issued when running in batch
1104mode.
1105
1a088d06
AS
1106@item -batch-silent
1107@cindex @code{--batch-silent}
1108Run in batch mode exactly like @samp{-batch}, but totally silently. All
1109@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1110unaffected). This is much quieter than @samp{-silent} and would be useless
1111for an interactive session.
1112
1113This is particularly useful when using targets that give @samp{Loading section}
1114messages, for example.
1115
1116Note that targets that give their output via @value{GDBN}, as opposed to
1117writing directly to @code{stdout}, will also be made silent.
1118
4b0ad762
AS
1119@item -return-child-result
1120@cindex @code{--return-child-result}
1121The return code from @value{GDBN} will be the return code from the child
1122process (the process being debugged), with the following exceptions:
1123
1124@itemize @bullet
1125@item
1126@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1127internal error. In this case the exit code is the same as it would have been
1128without @samp{-return-child-result}.
1129@item
1130The user quits with an explicit value. E.g., @samp{quit 1}.
1131@item
1132The child process never runs, or is not allowed to terminate, in which case
1133the exit code will be -1.
1134@end itemize
1135
1136This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1137when @value{GDBN} is being used as a remote program loader or simulator
1138interface.
1139
2df3850c
JM
1140@item -nowindows
1141@itemx -nw
d700128c
EZ
1142@cindex @code{--nowindows}
1143@cindex @code{-nw}
2df3850c 1144``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1145(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1146interface. If no GUI is available, this option has no effect.
1147
1148@item -windows
1149@itemx -w
d700128c
EZ
1150@cindex @code{--windows}
1151@cindex @code{-w}
2df3850c
JM
1152If @value{GDBN} includes a GUI, then this option requires it to be
1153used if possible.
c906108c
SS
1154
1155@item -cd @var{directory}
d700128c 1156@cindex @code{--cd}
c906108c
SS
1157Run @value{GDBN} using @var{directory} as its working directory,
1158instead of the current directory.
1159
aae1c79a
DE
1160@item -data-directory @var{directory}
1161@cindex @code{--data-directory}
1162Run @value{GDBN} using @var{directory} as its data directory.
1163The data directory is where @value{GDBN} searches for its
1164auxiliary files. @xref{Data Files}.
1165
c906108c
SS
1166@item -fullname
1167@itemx -f
d700128c
EZ
1168@cindex @code{--fullname}
1169@cindex @code{-f}
7a292a7a
SS
1170@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1171subprocess. It tells @value{GDBN} to output the full file name and line
1172number in a standard, recognizable fashion each time a stack frame is
1173displayed (which includes each time your program stops). This
1174recognizable format looks like two @samp{\032} characters, followed by
1175the file name, line number and character position separated by colons,
1176and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1177@samp{\032} characters as a signal to display the source code for the
1178frame.
c906108c 1179
d700128c
EZ
1180@item -annotate @var{level}
1181@cindex @code{--annotate}
1182This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1183effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1184(@pxref{Annotations}). The annotation @var{level} controls how much
1185information @value{GDBN} prints together with its prompt, values of
1186expressions, source lines, and other types of output. Level 0 is the
1187normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1188@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1189that control @value{GDBN}, and level 2 has been deprecated.
1190
265eeb58 1191The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1192(@pxref{GDB/MI}).
d700128c 1193
aa26fa3a
TT
1194@item --args
1195@cindex @code{--args}
1196Change interpretation of command line so that arguments following the
1197executable file are passed as command line arguments to the inferior.
1198This option stops option processing.
1199
2df3850c
JM
1200@item -baud @var{bps}
1201@itemx -b @var{bps}
d700128c
EZ
1202@cindex @code{--baud}
1203@cindex @code{-b}
c906108c
SS
1204Set the line speed (baud rate or bits per second) of any serial
1205interface used by @value{GDBN} for remote debugging.
c906108c 1206
f47b1503
AS
1207@item -l @var{timeout}
1208@cindex @code{-l}
1209Set the timeout (in seconds) of any communication used by @value{GDBN}
1210for remote debugging.
1211
c906108c 1212@item -tty @var{device}
d700128c
EZ
1213@itemx -t @var{device}
1214@cindex @code{--tty}
1215@cindex @code{-t}
c906108c
SS
1216Run using @var{device} for your program's standard input and output.
1217@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1218
53a5351d 1219@c resolve the situation of these eventually
c4555f82
SC
1220@item -tui
1221@cindex @code{--tui}
d0d5df6f
AC
1222Activate the @dfn{Text User Interface} when starting. The Text User
1223Interface manages several text windows on the terminal, showing
1224source, assembly, registers and @value{GDBN} command outputs
217bff3e
JK
1225(@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1226option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1227Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1228
1229@c @item -xdb
d700128c 1230@c @cindex @code{--xdb}
53a5351d
JM
1231@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1232@c For information, see the file @file{xdb_trans.html}, which is usually
1233@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1234@c systems.
1235
d700128c
EZ
1236@item -interpreter @var{interp}
1237@cindex @code{--interpreter}
1238Use the interpreter @var{interp} for interface with the controlling
1239program or device. This option is meant to be set by programs which
94bbb2c0 1240communicate with @value{GDBN} using it as a back end.
21c294e6 1241@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1242
da0f9dcd 1243@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1244@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1245The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1246previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1247selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1248@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1249
1250@item -write
1251@cindex @code{--write}
1252Open the executable and core files for both reading and writing. This
1253is equivalent to the @samp{set write on} command inside @value{GDBN}
1254(@pxref{Patching}).
1255
1256@item -statistics
1257@cindex @code{--statistics}
1258This option causes @value{GDBN} to print statistics about time and
1259memory usage after it completes each command and returns to the prompt.
1260
1261@item -version
1262@cindex @code{--version}
1263This option causes @value{GDBN} to print its version number and
1264no-warranty blurb, and exit.
1265
c906108c
SS
1266@end table
1267
6fc08d32 1268@node Startup
79a6e687 1269@subsection What @value{GDBN} Does During Startup
6fc08d32
EZ
1270@cindex @value{GDBN} startup
1271
1272Here's the description of what @value{GDBN} does during session startup:
1273
1274@enumerate
1275@item
1276Sets up the command interpreter as specified by the command line
1277(@pxref{Mode Options, interpreter}).
1278
1279@item
1280@cindex init file
098b41a6
JG
1281Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1282used when building @value{GDBN}; @pxref{System-wide configuration,
1283 ,System-wide configuration and settings}) and executes all the commands in
1284that file.
1285
bf88dd68 1286@anchor{Home Directory Init File}
098b41a6
JG
1287@item
1288Reads the init file (if any) in your home directory@footnote{On
6fc08d32
EZ
1289DOS/Windows systems, the home directory is the one pointed to by the
1290@code{HOME} environment variable.} and executes all the commands in
1291that file.
1292
2d7b58e8
JK
1293@anchor{Option -init-eval-command}
1294@item
1295Executes commands and command files specified by the @samp{-iex} and
1296@samp{-ix} options in their specified order. Usually you should use the
1297@samp{-ex} and @samp{-x} options instead, but this way you can apply
1298settings before @value{GDBN} init files get executed and before inferior
1299gets loaded.
1300
6fc08d32
EZ
1301@item
1302Processes command line options and operands.
1303
bf88dd68 1304@anchor{Init File in the Current Directory during Startup}
6fc08d32
EZ
1305@item
1306Reads and executes the commands from init file (if any) in the current
bf88dd68
JK
1307working directory as long as @samp{set auto-load local-gdbinit} is set to
1308@samp{on} (@pxref{Init File in the Current Directory}).
1309This is only done if the current directory is
119b882a
EZ
1310different from your home directory. Thus, you can have more than one
1311init file, one generic in your home directory, and another, specific
1312to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1313@value{GDBN}.
1314
a86caf66
DE
1315@item
1316If the command line specified a program to debug, or a process to
1317attach to, or a core file, @value{GDBN} loads any auto-loaded
1318scripts provided for the program or for its loaded shared libraries.
1319@xref{Auto-loading}.
1320
1321If you wish to disable the auto-loading during startup,
1322you must do something like the following:
1323
1324@smallexample
bf88dd68 1325$ gdb -iex "set auto-load python-scripts off" myprogram
a86caf66
DE
1326@end smallexample
1327
8320cc4f
JK
1328Option @samp{-ex} does not work because the auto-loading is then turned
1329off too late.
a86caf66 1330
6fc08d32 1331@item
6fe37d23
JK
1332Executes commands and command files specified by the @samp{-ex} and
1333@samp{-x} options in their specified order. @xref{Command Files}, for
1334more details about @value{GDBN} command files.
6fc08d32
EZ
1335
1336@item
1337Reads the command history recorded in the @dfn{history file}.
d620b259 1338@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1339files where @value{GDBN} records it.
1340@end enumerate
1341
1342Init files use the same syntax as @dfn{command files} (@pxref{Command
1343Files}) and are processed by @value{GDBN} in the same way. The init
1344file in your home directory can set options (such as @samp{set
1345complaints}) that affect subsequent processing of command line options
1346and operands. Init files are not executed if you use the @samp{-nx}
79a6e687 1347option (@pxref{Mode Options, ,Choosing Modes}).
6fc08d32 1348
098b41a6
JG
1349To display the list of init files loaded by gdb at startup, you
1350can use @kbd{gdb --help}.
1351
6fc08d32
EZ
1352@cindex init file name
1353@cindex @file{.gdbinit}
119b882a 1354@cindex @file{gdb.ini}
8807d78b 1355The @value{GDBN} init files are normally called @file{.gdbinit}.
119b882a
EZ
1356The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1357the limitations of file names imposed by DOS filesystems. The Windows
4d3f93a2
JB
1358port of @value{GDBN} uses the standard name, but if it finds a
1359@file{gdb.ini} file in your home directory, it warns you about that
1360and suggests to rename the file to the standard name.
119b882a 1361
6fc08d32 1362
6d2ebf8b 1363@node Quitting GDB
c906108c
SS
1364@section Quitting @value{GDBN}
1365@cindex exiting @value{GDBN}
1366@cindex leaving @value{GDBN}
1367
1368@table @code
1369@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1370@kindex q @r{(@code{quit})}
96a2c332
SS
1371@item quit @r{[}@var{expression}@r{]}
1372@itemx q
1373To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1374@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1375do not supply @var{expression}, @value{GDBN} will terminate normally;
1376otherwise it will terminate using the result of @var{expression} as the
1377error code.
c906108c
SS
1378@end table
1379
1380@cindex interrupt
c8aa23ab 1381An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1382terminates the action of any @value{GDBN} command that is in progress and
1383returns to @value{GDBN} command level. It is safe to type the interrupt
1384character at any time because @value{GDBN} does not allow it to take effect
1385until a time when it is safe.
1386
c906108c
SS
1387If you have been using @value{GDBN} to control an attached process or
1388device, you can release it with the @code{detach} command
79a6e687 1389(@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 1390
6d2ebf8b 1391@node Shell Commands
79a6e687 1392@section Shell Commands
c906108c
SS
1393
1394If you need to execute occasional shell commands during your
1395debugging session, there is no need to leave or suspend @value{GDBN}; you can
1396just use the @code{shell} command.
1397
1398@table @code
1399@kindex shell
ed59ded5 1400@kindex !
c906108c 1401@cindex shell escape
ed59ded5
DE
1402@item shell @var{command-string}
1403@itemx !@var{command-string}
1404Invoke a standard shell to execute @var{command-string}.
1405Note that no space is needed between @code{!} and @var{command-string}.
c906108c 1406If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1407shell to run. Otherwise @value{GDBN} uses the default shell
1408(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1409@end table
1410
1411The utility @code{make} is often needed in development environments.
1412You do not have to use the @code{shell} command for this purpose in
1413@value{GDBN}:
1414
1415@table @code
1416@kindex make
1417@cindex calling make
1418@item make @var{make-args}
1419Execute the @code{make} program with the specified
1420arguments. This is equivalent to @samp{shell make @var{make-args}}.
1421@end table
1422
79a6e687
BW
1423@node Logging Output
1424@section Logging Output
0fac0b41 1425@cindex logging @value{GDBN} output
9c16f35a 1426@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1427
1428You may want to save the output of @value{GDBN} commands to a file.
1429There are several commands to control @value{GDBN}'s logging.
1430
1431@table @code
1432@kindex set logging
1433@item set logging on
1434Enable logging.
1435@item set logging off
1436Disable logging.
9c16f35a 1437@cindex logging file name
0fac0b41
DJ
1438@item set logging file @var{file}
1439Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1440@item set logging overwrite [on|off]
1441By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1442you want @code{set logging on} to overwrite the logfile instead.
1443@item set logging redirect [on|off]
1444By default, @value{GDBN} output will go to both the terminal and the logfile.
1445Set @code{redirect} if you want output to go only to the log file.
1446@kindex show logging
1447@item show logging
1448Show the current values of the logging settings.
1449@end table
1450
6d2ebf8b 1451@node Commands
c906108c
SS
1452@chapter @value{GDBN} Commands
1453
1454You can abbreviate a @value{GDBN} command to the first few letters of the command
1455name, if that abbreviation is unambiguous; and you can repeat certain
1456@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1457key to get @value{GDBN} to fill out the rest of a word in a command (or to
1458show you the alternatives available, if there is more than one possibility).
1459
1460@menu
1461* Command Syntax:: How to give commands to @value{GDBN}
1462* Completion:: Command completion
1463* Help:: How to ask @value{GDBN} for help
1464@end menu
1465
6d2ebf8b 1466@node Command Syntax
79a6e687 1467@section Command Syntax
c906108c
SS
1468
1469A @value{GDBN} command is a single line of input. There is no limit on
1470how long it can be. It starts with a command name, which is followed by
1471arguments whose meaning depends on the command name. For example, the
1472command @code{step} accepts an argument which is the number of times to
1473step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1474with no arguments. Some commands do not allow any arguments.
c906108c
SS
1475
1476@cindex abbreviation
1477@value{GDBN} command names may always be truncated if that abbreviation is
1478unambiguous. Other possible command abbreviations are listed in the
1479documentation for individual commands. In some cases, even ambiguous
1480abbreviations are allowed; for example, @code{s} is specially defined as
1481equivalent to @code{step} even though there are other commands whose
1482names start with @code{s}. You can test abbreviations by using them as
1483arguments to the @code{help} command.
1484
1485@cindex repeating commands
41afff9a 1486@kindex RET @r{(repeat last command)}
c906108c 1487A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1488repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1489will not repeat this way; these are commands whose unintentional
1490repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1491repeat. User-defined commands can disable this feature; see
1492@ref{Define, dont-repeat}.
c906108c
SS
1493
1494The @code{list} and @code{x} commands, when you repeat them with
1495@key{RET}, construct new arguments rather than repeating
1496exactly as typed. This permits easy scanning of source or memory.
1497
1498@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1499output, in a way similar to the common utility @code{more}
79a6e687 1500(@pxref{Screen Size,,Screen Size}). Since it is easy to press one
c906108c
SS
1501@key{RET} too many in this situation, @value{GDBN} disables command
1502repetition after any command that generates this sort of display.
1503
41afff9a 1504@kindex # @r{(a comment)}
c906108c
SS
1505@cindex comment
1506Any text from a @kbd{#} to the end of the line is a comment; it does
1507nothing. This is useful mainly in command files (@pxref{Command
79a6e687 1508Files,,Command Files}).
c906108c 1509
88118b3a 1510@cindex repeating command sequences
c8aa23ab
EZ
1511@kindex Ctrl-o @r{(operate-and-get-next)}
1512The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1513commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1514then fetches the next line relative to the current line from the history
1515for editing.
1516
6d2ebf8b 1517@node Completion
79a6e687 1518@section Command Completion
c906108c
SS
1519
1520@cindex completion
1521@cindex word completion
1522@value{GDBN} can fill in the rest of a word in a command for you, if there is
1523only one possibility; it can also show you what the valid possibilities
1524are for the next word in a command, at any time. This works for @value{GDBN}
1525commands, @value{GDBN} subcommands, and the names of symbols in your program.
1526
1527Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1528of a word. If there is only one possibility, @value{GDBN} fills in the
1529word, and waits for you to finish the command (or press @key{RET} to
1530enter it). For example, if you type
1531
1532@c FIXME "@key" does not distinguish its argument sufficiently to permit
1533@c complete accuracy in these examples; space introduced for clarity.
1534@c If texinfo enhancements make it unnecessary, it would be nice to
1535@c replace " @key" by "@key" in the following...
474c8240 1536@smallexample
c906108c 1537(@value{GDBP}) info bre @key{TAB}
474c8240 1538@end smallexample
c906108c
SS
1539
1540@noindent
1541@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1542the only @code{info} subcommand beginning with @samp{bre}:
1543
474c8240 1544@smallexample
c906108c 1545(@value{GDBP}) info breakpoints
474c8240 1546@end smallexample
c906108c
SS
1547
1548@noindent
1549You can either press @key{RET} at this point, to run the @code{info
1550breakpoints} command, or backspace and enter something else, if
1551@samp{breakpoints} does not look like the command you expected. (If you
1552were sure you wanted @code{info breakpoints} in the first place, you
1553might as well just type @key{RET} immediately after @samp{info bre},
1554to exploit command abbreviations rather than command completion).
1555
1556If there is more than one possibility for the next word when you press
1557@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1558characters and try again, or just press @key{TAB} a second time;
1559@value{GDBN} displays all the possible completions for that word. For
1560example, you might want to set a breakpoint on a subroutine whose name
1561begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1562just sounds the bell. Typing @key{TAB} again displays all the
1563function names in your program that begin with those characters, for
1564example:
1565
474c8240 1566@smallexample
c906108c
SS
1567(@value{GDBP}) b make_ @key{TAB}
1568@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1569make_a_section_from_file make_environ
1570make_abs_section make_function_type
1571make_blockvector make_pointer_type
1572make_cleanup make_reference_type
c906108c
SS
1573make_command make_symbol_completion_list
1574(@value{GDBP}) b make_
474c8240 1575@end smallexample
c906108c
SS
1576
1577@noindent
1578After displaying the available possibilities, @value{GDBN} copies your
1579partial input (@samp{b make_} in the example) so you can finish the
1580command.
1581
1582If you just want to see the list of alternatives in the first place, you
b37052ae 1583can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1584means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1585key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1586one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1587
1588@cindex quotes in commands
1589@cindex completion of quoted strings
1590Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1591parentheses or other characters that @value{GDBN} normally excludes from
1592its notion of a word. To permit word completion to work in this
1593situation, you may enclose words in @code{'} (single quote marks) in
1594@value{GDBN} commands.
c906108c 1595
c906108c 1596The most likely situation where you might need this is in typing the
b37052ae
EZ
1597name of a C@t{++} function. This is because C@t{++} allows function
1598overloading (multiple definitions of the same function, distinguished
1599by argument type). For example, when you want to set a breakpoint you
1600may need to distinguish whether you mean the version of @code{name}
1601that takes an @code{int} parameter, @code{name(int)}, or the version
1602that takes a @code{float} parameter, @code{name(float)}. To use the
1603word-completion facilities in this situation, type a single quote
1604@code{'} at the beginning of the function name. This alerts
1605@value{GDBN} that it may need to consider more information than usual
1606when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1607
474c8240 1608@smallexample
96a2c332 1609(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1610bubble(double,double) bubble(int,int)
1611(@value{GDBP}) b 'bubble(
474c8240 1612@end smallexample
c906108c
SS
1613
1614In some cases, @value{GDBN} can tell that completing a name requires using
1615quotes. When this happens, @value{GDBN} inserts the quote for you (while
1616completing as much as it can) if you do not type the quote in the first
1617place:
1618
474c8240 1619@smallexample
c906108c
SS
1620(@value{GDBP}) b bub @key{TAB}
1621@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1622(@value{GDBP}) b 'bubble(
474c8240 1623@end smallexample
c906108c
SS
1624
1625@noindent
1626In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1627you have not yet started typing the argument list when you ask for
1628completion on an overloaded symbol.
1629
79a6e687
BW
1630For more information about overloaded functions, see @ref{C Plus Plus
1631Expressions, ,C@t{++} Expressions}. You can use the command @code{set
c906108c 1632overload-resolution off} to disable overload resolution;
79a6e687 1633see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
c906108c 1634
65d12d83
TT
1635@cindex completion of structure field names
1636@cindex structure field name completion
1637@cindex completion of union field names
1638@cindex union field name completion
1639When completing in an expression which looks up a field in a
1640structure, @value{GDBN} also tries@footnote{The completer can be
1641confused by certain kinds of invalid expressions. Also, it only
1642examines the static type of the expression, not the dynamic type.} to
1643limit completions to the field names available in the type of the
1644left-hand-side:
1645
1646@smallexample
1647(@value{GDBP}) p gdb_stdout.@kbd{M-?}
01124a23
DE
1648magic to_fputs to_rewind
1649to_data to_isatty to_write
1650to_delete to_put to_write_async_safe
1651to_flush to_read
65d12d83
TT
1652@end smallexample
1653
1654@noindent
1655This is because the @code{gdb_stdout} is a variable of the type
1656@code{struct ui_file} that is defined in @value{GDBN} sources as
1657follows:
1658
1659@smallexample
1660struct ui_file
1661@{
1662 int *magic;
1663 ui_file_flush_ftype *to_flush;
1664 ui_file_write_ftype *to_write;
01124a23 1665 ui_file_write_async_safe_ftype *to_write_async_safe;
65d12d83
TT
1666 ui_file_fputs_ftype *to_fputs;
1667 ui_file_read_ftype *to_read;
1668 ui_file_delete_ftype *to_delete;
1669 ui_file_isatty_ftype *to_isatty;
1670 ui_file_rewind_ftype *to_rewind;
1671 ui_file_put_ftype *to_put;
1672 void *to_data;
1673@}
1674@end smallexample
1675
c906108c 1676
6d2ebf8b 1677@node Help
79a6e687 1678@section Getting Help
c906108c
SS
1679@cindex online documentation
1680@kindex help
1681
5d161b24 1682You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1683using the command @code{help}.
1684
1685@table @code
41afff9a 1686@kindex h @r{(@code{help})}
c906108c
SS
1687@item help
1688@itemx h
1689You can use @code{help} (abbreviated @code{h}) with no arguments to
1690display a short list of named classes of commands:
1691
1692@smallexample
1693(@value{GDBP}) help
1694List of classes of commands:
1695
2df3850c 1696aliases -- Aliases of other commands
c906108c 1697breakpoints -- Making program stop at certain points
2df3850c 1698data -- Examining data
c906108c 1699files -- Specifying and examining files
2df3850c
JM
1700internals -- Maintenance commands
1701obscure -- Obscure features
1702running -- Running the program
1703stack -- Examining the stack
c906108c
SS
1704status -- Status inquiries
1705support -- Support facilities
12c27660 1706tracepoints -- Tracing of program execution without
96a2c332 1707 stopping the program
c906108c 1708user-defined -- User-defined commands
c906108c 1709
5d161b24 1710Type "help" followed by a class name for a list of
c906108c 1711commands in that class.
5d161b24 1712Type "help" followed by command name for full
c906108c
SS
1713documentation.
1714Command name abbreviations are allowed if unambiguous.
1715(@value{GDBP})
1716@end smallexample
96a2c332 1717@c the above line break eliminates huge line overfull...
c906108c
SS
1718
1719@item help @var{class}
1720Using one of the general help classes as an argument, you can get a
1721list of the individual commands in that class. For example, here is the
1722help display for the class @code{status}:
1723
1724@smallexample
1725(@value{GDBP}) help status
1726Status inquiries.
1727
1728List of commands:
1729
1730@c Line break in "show" line falsifies real output, but needed
1731@c to fit in smallbook page size.
2df3850c 1732info -- Generic command for showing things
12c27660 1733 about the program being debugged
2df3850c 1734show -- Generic command for showing things
12c27660 1735 about the debugger
c906108c 1736
5d161b24 1737Type "help" followed by command name for full
c906108c
SS
1738documentation.
1739Command name abbreviations are allowed if unambiguous.
1740(@value{GDBP})
1741@end smallexample
1742
1743@item help @var{command}
1744With a command name as @code{help} argument, @value{GDBN} displays a
1745short paragraph on how to use that command.
1746
6837a0a2
DB
1747@kindex apropos
1748@item apropos @var{args}
09d4efe1 1749The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2 1750commands, and their documentation, for the regular expression specified in
99e008fe 1751@var{args}. It prints out all matches found. For example:
6837a0a2
DB
1752
1753@smallexample
16899756 1754apropos alias
6837a0a2
DB
1755@end smallexample
1756
b37052ae
EZ
1757@noindent
1758results in:
6837a0a2
DB
1759
1760@smallexample
6d2ebf8b 1761@c @group
16899756
DE
1762alias -- Define a new command that is an alias of an existing command
1763aliases -- Aliases of other commands
1764d -- Delete some breakpoints or auto-display expressions
1765del -- Delete some breakpoints or auto-display expressions
1766delete -- Delete some breakpoints or auto-display expressions
6d2ebf8b 1767@c @end group
6837a0a2
DB
1768@end smallexample
1769
c906108c
SS
1770@kindex complete
1771@item complete @var{args}
1772The @code{complete @var{args}} command lists all the possible completions
1773for the beginning of a command. Use @var{args} to specify the beginning of the
1774command you want completed. For example:
1775
1776@smallexample
1777complete i
1778@end smallexample
1779
1780@noindent results in:
1781
1782@smallexample
1783@group
2df3850c
JM
1784if
1785ignore
c906108c
SS
1786info
1787inspect
c906108c
SS
1788@end group
1789@end smallexample
1790
1791@noindent This is intended for use by @sc{gnu} Emacs.
1792@end table
1793
1794In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1795and @code{show} to inquire about the state of your program, or the state
1796of @value{GDBN} itself. Each command supports many topics of inquiry; this
1797manual introduces each of them in the appropriate context. The listings
00595b5e
EZ
1798under @code{info} and under @code{show} in the Command, Variable, and
1799Function Index point to all the sub-commands. @xref{Command and Variable
1800Index}.
c906108c
SS
1801
1802@c @group
1803@table @code
1804@kindex info
41afff9a 1805@kindex i @r{(@code{info})}
c906108c
SS
1806@item info
1807This command (abbreviated @code{i}) is for describing the state of your
cda4ce5a 1808program. For example, you can show the arguments passed to a function
c906108c
SS
1809with @code{info args}, list the registers currently in use with @code{info
1810registers}, or list the breakpoints you have set with @code{info breakpoints}.
1811You can get a complete list of the @code{info} sub-commands with
1812@w{@code{help info}}.
1813
1814@kindex set
1815@item set
5d161b24 1816You can assign the result of an expression to an environment variable with
c906108c
SS
1817@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1818@code{set prompt $}.
1819
1820@kindex show
1821@item show
5d161b24 1822In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1823@value{GDBN} itself.
1824You can change most of the things you can @code{show}, by using the
1825related command @code{set}; for example, you can control what number
1826system is used for displays with @code{set radix}, or simply inquire
1827which is currently in use with @code{show radix}.
1828
1829@kindex info set
1830To display all the settable parameters and their current
1831values, you can use @code{show} with no arguments; you may also use
1832@code{info set}. Both commands produce the same display.
1833@c FIXME: "info set" violates the rule that "info" is for state of
1834@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1835@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1836@end table
1837@c @end group
1838
1839Here are three miscellaneous @code{show} subcommands, all of which are
1840exceptional in lacking corresponding @code{set} commands:
1841
1842@table @code
1843@kindex show version
9c16f35a 1844@cindex @value{GDBN} version number
c906108c
SS
1845@item show version
1846Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1847information in @value{GDBN} bug-reports. If multiple versions of
1848@value{GDBN} are in use at your site, you may need to determine which
1849version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1850commands are introduced, and old ones may wither away. Also, many
1851system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1852variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1853The version number is the same as the one announced when you start
1854@value{GDBN}.
c906108c
SS
1855
1856@kindex show copying
09d4efe1 1857@kindex info copying
9c16f35a 1858@cindex display @value{GDBN} copyright
c906108c 1859@item show copying
09d4efe1 1860@itemx info copying
c906108c
SS
1861Display information about permission for copying @value{GDBN}.
1862
1863@kindex show warranty
09d4efe1 1864@kindex info warranty
c906108c 1865@item show warranty
09d4efe1 1866@itemx info warranty
2df3850c 1867Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1868if your version of @value{GDBN} comes with one.
2df3850c 1869
c906108c
SS
1870@end table
1871
6d2ebf8b 1872@node Running
c906108c
SS
1873@chapter Running Programs Under @value{GDBN}
1874
1875When you run a program under @value{GDBN}, you must first generate
1876debugging information when you compile it.
7a292a7a
SS
1877
1878You may start @value{GDBN} with its arguments, if any, in an environment
1879of your choice. If you are doing native debugging, you may redirect
1880your program's input and output, debug an already running process, or
1881kill a child process.
c906108c
SS
1882
1883@menu
1884* Compilation:: Compiling for debugging
1885* Starting:: Starting your program
c906108c
SS
1886* Arguments:: Your program's arguments
1887* Environment:: Your program's environment
c906108c
SS
1888
1889* Working Directory:: Your program's working directory
1890* Input/Output:: Your program's input and output
1891* Attach:: Debugging an already-running process
1892* Kill Process:: Killing the child process
c906108c 1893
6c95b8df 1894* Inferiors and Programs:: Debugging multiple inferiors and programs
c906108c 1895* Threads:: Debugging programs with multiple threads
6c95b8df 1896* Forks:: Debugging forks
5c95884b 1897* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
1898@end menu
1899
6d2ebf8b 1900@node Compilation
79a6e687 1901@section Compiling for Debugging
c906108c
SS
1902
1903In order to debug a program effectively, you need to generate
1904debugging information when you compile it. This debugging information
1905is stored in the object file; it describes the data type of each
1906variable or function and the correspondence between source line numbers
1907and addresses in the executable code.
1908
1909To request debugging information, specify the @samp{-g} option when you run
1910the compiler.
1911
514c4d71 1912Programs that are to be shipped to your customers are compiled with
edb3359d 1913optimizations, using the @samp{-O} compiler option. However, some
514c4d71
EZ
1914compilers are unable to handle the @samp{-g} and @samp{-O} options
1915together. Using those compilers, you cannot generate optimized
c906108c
SS
1916executables containing debugging information.
1917
514c4d71 1918@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1919without @samp{-O}, making it possible to debug optimized code. We
1920recommend that you @emph{always} use @samp{-g} whenever you compile a
1921program. You may think your program is correct, but there is no sense
edb3359d 1922in pushing your luck. For more information, see @ref{Optimized Code}.
c906108c
SS
1923
1924Older versions of the @sc{gnu} C compiler permitted a variant option
1925@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1926format; if your @sc{gnu} C compiler has this option, do not use it.
1927
514c4d71
EZ
1928@value{GDBN} knows about preprocessor macros and can show you their
1929expansion (@pxref{Macros}). Most compilers do not include information
1930about preprocessor macros in the debugging information if you specify
e0f8f636
TT
1931the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
1932the @sc{gnu} C compiler, provides macro information if you are using
1933the DWARF debugging format, and specify the option @option{-g3}.
1934
1935@xref{Debugging Options,,Options for Debugging Your Program or GCC,
1936gcc.info, Using the @sc{gnu} Compiler Collection (GCC)}, for more
1937information on @value{NGCC} options affecting debug information.
1938
1939You will have the best debugging experience if you use the latest
1940version of the DWARF debugging format that your compiler supports.
1941DWARF is currently the most expressive and best supported debugging
1942format in @value{GDBN}.
514c4d71 1943
c906108c 1944@need 2000
6d2ebf8b 1945@node Starting
79a6e687 1946@section Starting your Program
c906108c
SS
1947@cindex starting
1948@cindex running
1949
1950@table @code
1951@kindex run
41afff9a 1952@kindex r @r{(@code{run})}
c906108c
SS
1953@item run
1954@itemx r
7a292a7a
SS
1955Use the @code{run} command to start your program under @value{GDBN}.
1956You must first specify the program name (except on VxWorks) with an
1957argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1958@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
79a6e687 1959(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
1960
1961@end table
1962
c906108c
SS
1963If you are running your program in an execution environment that
1964supports processes, @code{run} creates an inferior process and makes
8edfe269
DJ
1965that process run your program. In some environments without processes,
1966@code{run} jumps to the start of your program. Other targets,
1967like @samp{remote}, are always running. If you get an error
1968message like this one:
1969
1970@smallexample
1971The "remote" target does not support "run".
1972Try "help target" or "continue".
1973@end smallexample
1974
1975@noindent
1976then use @code{continue} to run your program. You may need @code{load}
1977first (@pxref{load}).
c906108c
SS
1978
1979The execution of a program is affected by certain information it
1980receives from its superior. @value{GDBN} provides ways to specify this
1981information, which you must do @emph{before} starting your program. (You
1982can change it after starting your program, but such changes only affect
1983your program the next time you start it.) This information may be
1984divided into four categories:
1985
1986@table @asis
1987@item The @emph{arguments.}
1988Specify the arguments to give your program as the arguments of the
1989@code{run} command. If a shell is available on your target, the shell
1990is used to pass the arguments, so that you may use normal conventions
1991(such as wildcard expansion or variable substitution) in describing
1992the arguments.
1993In Unix systems, you can control which shell is used with the
1994@code{SHELL} environment variable.
79a6e687 1995@xref{Arguments, ,Your Program's Arguments}.
c906108c
SS
1996
1997@item The @emph{environment.}
1998Your program normally inherits its environment from @value{GDBN}, but you can
1999use the @value{GDBN} commands @code{set environment} and @code{unset
2000environment} to change parts of the environment that affect
79a6e687 2001your program. @xref{Environment, ,Your Program's Environment}.
c906108c
SS
2002
2003@item The @emph{working directory.}
2004Your program inherits its working directory from @value{GDBN}. You can set
2005the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
79a6e687 2006@xref{Working Directory, ,Your Program's Working Directory}.
c906108c
SS
2007
2008@item The @emph{standard input and output.}
2009Your program normally uses the same device for standard input and
2010standard output as @value{GDBN} is using. You can redirect input and output
2011in the @code{run} command line, or you can use the @code{tty} command to
2012set a different device for your program.
79a6e687 2013@xref{Input/Output, ,Your Program's Input and Output}.
c906108c
SS
2014
2015@cindex pipes
2016@emph{Warning:} While input and output redirection work, you cannot use
2017pipes to pass the output of the program you are debugging to another
2018program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2019wrong program.
2020@end table
c906108c
SS
2021
2022When you issue the @code{run} command, your program begins to execute
79a6e687 2023immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
c906108c
SS
2024of how to arrange for your program to stop. Once your program has
2025stopped, you may call functions in your program, using the @code{print}
2026or @code{call} commands. @xref{Data, ,Examining Data}.
2027
2028If the modification time of your symbol file has changed since the last
2029time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2030table, and reads it again. When it does this, @value{GDBN} tries to retain
2031your current breakpoints.
2032
4e8b0763
JB
2033@table @code
2034@kindex start
2035@item start
2036@cindex run to main procedure
2037The name of the main procedure can vary from language to language.
2038With C or C@t{++}, the main procedure name is always @code{main}, but
2039other languages such as Ada do not require a specific name for their
2040main procedure. The debugger provides a convenient way to start the
2041execution of the program and to stop at the beginning of the main
2042procedure, depending on the language used.
2043
2044The @samp{start} command does the equivalent of setting a temporary
2045breakpoint at the beginning of the main procedure and then invoking
2046the @samp{run} command.
2047
f018e82f
EZ
2048@cindex elaboration phase
2049Some programs contain an @dfn{elaboration} phase where some startup code is
2050executed before the main procedure is called. This depends on the
2051languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
2052constructors for static and global objects are executed before
2053@code{main} is called. It is therefore possible that the debugger stops
2054before reaching the main procedure. However, the temporary breakpoint
2055will remain to halt execution.
2056
2057Specify the arguments to give to your program as arguments to the
2058@samp{start} command. These arguments will be given verbatim to the
2059underlying @samp{run} command. Note that the same arguments will be
2060reused if no argument is provided during subsequent calls to
2061@samp{start} or @samp{run}.
2062
2063It is sometimes necessary to debug the program during elaboration. In
2064these cases, using the @code{start} command would stop the execution of
2065your program too late, as the program would have already completed the
2066elaboration phase. Under these circumstances, insert breakpoints in your
2067elaboration code before running your program.
ccd213ac
DJ
2068
2069@kindex set exec-wrapper
2070@item set exec-wrapper @var{wrapper}
2071@itemx show exec-wrapper
2072@itemx unset exec-wrapper
2073When @samp{exec-wrapper} is set, the specified wrapper is used to
2074launch programs for debugging. @value{GDBN} starts your program
2075with a shell command of the form @kbd{exec @var{wrapper}
2076@var{program}}. Quoting is added to @var{program} and its
2077arguments, but not to @var{wrapper}, so you should add quotes if
2078appropriate for your shell. The wrapper runs until it executes
2079your program, and then @value{GDBN} takes control.
2080
2081You can use any program that eventually calls @code{execve} with
2082its arguments as a wrapper. Several standard Unix utilities do
2083this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2084with @code{exec "$@@"} will also work.
2085
2086For example, you can use @code{env} to pass an environment variable to
2087the debugged program, without setting the variable in your shell's
2088environment:
2089
2090@smallexample
2091(@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2092(@value{GDBP}) run
2093@end smallexample
2094
2095This command is available when debugging locally on most targets, excluding
2096@sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2097
10568435
JK
2098@kindex set disable-randomization
2099@item set disable-randomization
2100@itemx set disable-randomization on
2101This option (enabled by default in @value{GDBN}) will turn off the native
2102randomization of the virtual address space of the started program. This option
2103is useful for multiple debugging sessions to make the execution better
2104reproducible and memory addresses reusable across debugging sessions.
2105
03583c20
UW
2106This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2107On @sc{gnu}/Linux you can get the same behavior using
10568435
JK
2108
2109@smallexample
2110(@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2111@end smallexample
2112
2113@item set disable-randomization off
2114Leave the behavior of the started executable unchanged. Some bugs rear their
2115ugly heads only when the program is loaded at certain addresses. If your bug
2116disappears when you run the program under @value{GDBN}, that might be because
2117@value{GDBN} by default disables the address randomization on platforms, such
2118as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2119disable-randomization off} to try to reproduce such elusive bugs.
2120
03583c20
UW
2121On targets where it is available, virtual address space randomization
2122protects the programs against certain kinds of security attacks. In these
10568435
JK
2123cases the attacker needs to know the exact location of a concrete executable
2124code. Randomizing its location makes it impossible to inject jumps misusing
2125a code at its expected addresses.
2126
2127Prelinking shared libraries provides a startup performance advantage but it
2128makes addresses in these libraries predictable for privileged processes by
2129having just unprivileged access at the target system. Reading the shared
2130library binary gives enough information for assembling the malicious code
2131misusing it. Still even a prelinked shared library can get loaded at a new
2132random address just requiring the regular relocation process during the
2133startup. Shared libraries not already prelinked are always loaded at
2134a randomly chosen address.
2135
2136Position independent executables (PIE) contain position independent code
2137similar to the shared libraries and therefore such executables get loaded at
2138a randomly chosen address upon startup. PIE executables always load even
2139already prelinked shared libraries at a random address. You can build such
2140executable using @command{gcc -fPIE -pie}.
2141
2142Heap (malloc storage), stack and custom mmap areas are always placed randomly
2143(as long as the randomization is enabled).
2144
2145@item show disable-randomization
2146Show the current setting of the explicit disable of the native randomization of
2147the virtual address space of the started program.
2148
4e8b0763
JB
2149@end table
2150
6d2ebf8b 2151@node Arguments
79a6e687 2152@section Your Program's Arguments
c906108c
SS
2153
2154@cindex arguments (to your program)
2155The arguments to your program can be specified by the arguments of the
5d161b24 2156@code{run} command.
c906108c
SS
2157They are passed to a shell, which expands wildcard characters and
2158performs redirection of I/O, and thence to your program. Your
2159@code{SHELL} environment variable (if it exists) specifies what shell
2160@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
2161the default shell (@file{/bin/sh} on Unix).
2162
2163On non-Unix systems, the program is usually invoked directly by
2164@value{GDBN}, which emulates I/O redirection via the appropriate system
2165calls, and the wildcard characters are expanded by the startup code of
2166the program, not by the shell.
c906108c
SS
2167
2168@code{run} with no arguments uses the same arguments used by the previous
2169@code{run}, or those set by the @code{set args} command.
2170
c906108c 2171@table @code
41afff9a 2172@kindex set args
c906108c
SS
2173@item set args
2174Specify the arguments to be used the next time your program is run. If
2175@code{set args} has no arguments, @code{run} executes your program
2176with no arguments. Once you have run your program with arguments,
2177using @code{set args} before the next @code{run} is the only way to run
2178it again without arguments.
2179
2180@kindex show args
2181@item show args
2182Show the arguments to give your program when it is started.
2183@end table
2184
6d2ebf8b 2185@node Environment
79a6e687 2186@section Your Program's Environment
c906108c
SS
2187
2188@cindex environment (of your program)
2189The @dfn{environment} consists of a set of environment variables and
2190their values. Environment variables conventionally record such things as
2191your user name, your home directory, your terminal type, and your search
2192path for programs to run. Usually you set up environment variables with
2193the shell and they are inherited by all the other programs you run. When
2194debugging, it can be useful to try running your program with a modified
2195environment without having to start @value{GDBN} over again.
2196
2197@table @code
2198@kindex path
2199@item path @var{directory}
2200Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
2201(the search path for executables) that will be passed to your program.
2202The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
2203You may specify several directory names, separated by whitespace or by a
2204system-dependent separator character (@samp{:} on Unix, @samp{;} on
2205MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2206is moved to the front, so it is searched sooner.
c906108c
SS
2207
2208You can use the string @samp{$cwd} to refer to whatever is the current
2209working directory at the time @value{GDBN} searches the path. If you
2210use @samp{.} instead, it refers to the directory where you executed the
2211@code{path} command. @value{GDBN} replaces @samp{.} in the
2212@var{directory} argument (with the current path) before adding
2213@var{directory} to the search path.
2214@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2215@c document that, since repeating it would be a no-op.
2216
2217@kindex show paths
2218@item show paths
2219Display the list of search paths for executables (the @code{PATH}
2220environment variable).
2221
2222@kindex show environment
2223@item show environment @r{[}@var{varname}@r{]}
2224Print the value of environment variable @var{varname} to be given to
2225your program when it starts. If you do not supply @var{varname},
2226print the names and values of all environment variables to be given to
2227your program. You can abbreviate @code{environment} as @code{env}.
2228
2229@kindex set environment
53a5351d 2230@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
2231Set environment variable @var{varname} to @var{value}. The value
2232changes for your program only, not for @value{GDBN} itself. @var{value} may
2233be any string; the values of environment variables are just strings, and
2234any interpretation is supplied by your program itself. The @var{value}
2235parameter is optional; if it is eliminated, the variable is set to a
2236null value.
2237@c "any string" here does not include leading, trailing
2238@c blanks. Gnu asks: does anyone care?
2239
2240For example, this command:
2241
474c8240 2242@smallexample
c906108c 2243set env USER = foo
474c8240 2244@end smallexample
c906108c
SS
2245
2246@noindent
d4f3574e 2247tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2248@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2249are not actually required.)
2250
2251@kindex unset environment
2252@item unset environment @var{varname}
2253Remove variable @var{varname} from the environment to be passed to your
2254program. This is different from @samp{set env @var{varname} =};
2255@code{unset environment} removes the variable from the environment,
2256rather than assigning it an empty value.
2257@end table
2258
d4f3574e
SS
2259@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2260the shell indicated
c906108c
SS
2261by your @code{SHELL} environment variable if it exists (or
2262@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2263that runs an initialization file---such as @file{.cshrc} for C-shell, or
2264@file{.bashrc} for BASH---any variables you set in that file affect
2265your program. You may wish to move setting of environment variables to
2266files that are only run when you sign on, such as @file{.login} or
2267@file{.profile}.
2268
6d2ebf8b 2269@node Working Directory
79a6e687 2270@section Your Program's Working Directory
c906108c
SS
2271
2272@cindex working directory (of your program)
2273Each time you start your program with @code{run}, it inherits its
2274working directory from the current working directory of @value{GDBN}.
2275The @value{GDBN} working directory is initially whatever it inherited
2276from its parent process (typically the shell), but you can specify a new
2277working directory in @value{GDBN} with the @code{cd} command.
2278
2279The @value{GDBN} working directory also serves as a default for the commands
2280that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
79a6e687 2281Specify Files}.
c906108c
SS
2282
2283@table @code
2284@kindex cd
721c2651 2285@cindex change working directory
f3c8a52a
JK
2286@item cd @r{[}@var{directory}@r{]}
2287Set the @value{GDBN} working directory to @var{directory}. If not
2288given, @var{directory} uses @file{'~'}.
c906108c
SS
2289
2290@kindex pwd
2291@item pwd
2292Print the @value{GDBN} working directory.
2293@end table
2294
60bf7e09
EZ
2295It is generally impossible to find the current working directory of
2296the process being debugged (since a program can change its directory
2297during its run). If you work on a system where @value{GDBN} is
2298configured with the @file{/proc} support, you can use the @code{info
2299proc} command (@pxref{SVR4 Process Information}) to find out the
2300current working directory of the debuggee.
2301
6d2ebf8b 2302@node Input/Output
79a6e687 2303@section Your Program's Input and Output
c906108c
SS
2304
2305@cindex redirection
2306@cindex i/o
2307@cindex terminal
2308By default, the program you run under @value{GDBN} does input and output to
5d161b24 2309the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2310to its own terminal modes to interact with you, but it records the terminal
2311modes your program was using and switches back to them when you continue
2312running your program.
2313
2314@table @code
2315@kindex info terminal
2316@item info terminal
2317Displays information recorded by @value{GDBN} about the terminal modes your
2318program is using.
2319@end table
2320
2321You can redirect your program's input and/or output using shell
2322redirection with the @code{run} command. For example,
2323
474c8240 2324@smallexample
c906108c 2325run > outfile
474c8240 2326@end smallexample
c906108c
SS
2327
2328@noindent
2329starts your program, diverting its output to the file @file{outfile}.
2330
2331@kindex tty
2332@cindex controlling terminal
2333Another way to specify where your program should do input and output is
2334with the @code{tty} command. This command accepts a file name as
2335argument, and causes this file to be the default for future @code{run}
2336commands. It also resets the controlling terminal for the child
2337process, for future @code{run} commands. For example,
2338
474c8240 2339@smallexample
c906108c 2340tty /dev/ttyb
474c8240 2341@end smallexample
c906108c
SS
2342
2343@noindent
2344directs that processes started with subsequent @code{run} commands
2345default to do input and output on the terminal @file{/dev/ttyb} and have
2346that as their controlling terminal.
2347
2348An explicit redirection in @code{run} overrides the @code{tty} command's
2349effect on the input/output device, but not its effect on the controlling
2350terminal.
2351
2352When you use the @code{tty} command or redirect input in the @code{run}
2353command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2354for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2355for @code{set inferior-tty}.
2356
2357@cindex inferior tty
2358@cindex set inferior controlling terminal
2359You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2360display the name of the terminal that will be used for future runs of your
2361program.
2362
2363@table @code
2364@item set inferior-tty /dev/ttyb
2365@kindex set inferior-tty
2366Set the tty for the program being debugged to /dev/ttyb.
2367
2368@item show inferior-tty
2369@kindex show inferior-tty
2370Show the current tty for the program being debugged.
2371@end table
c906108c 2372
6d2ebf8b 2373@node Attach
79a6e687 2374@section Debugging an Already-running Process
c906108c
SS
2375@kindex attach
2376@cindex attach
2377
2378@table @code
2379@item attach @var{process-id}
2380This command attaches to a running process---one that was started
2381outside @value{GDBN}. (@code{info files} shows your active
2382targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2383find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2384or with the @samp{jobs -l} shell command.
2385
2386@code{attach} does not repeat if you press @key{RET} a second time after
2387executing the command.
2388@end table
2389
2390To use @code{attach}, your program must be running in an environment
2391which supports processes; for example, @code{attach} does not work for
2392programs on bare-board targets that lack an operating system. You must
2393also have permission to send the process a signal.
2394
2395When you use @code{attach}, the debugger finds the program running in
2396the process first by looking in the current working directory, then (if
2397the program is not found) by using the source file search path
79a6e687 2398(@pxref{Source Path, ,Specifying Source Directories}). You can also use
c906108c
SS
2399the @code{file} command to load the program. @xref{Files, ,Commands to
2400Specify Files}.
2401
2402The first thing @value{GDBN} does after arranging to debug the specified
2403process is to stop it. You can examine and modify an attached process
53a5351d
JM
2404with all the @value{GDBN} commands that are ordinarily available when
2405you start processes with @code{run}. You can insert breakpoints; you
2406can step and continue; you can modify storage. If you would rather the
2407process continue running, you may use the @code{continue} command after
c906108c
SS
2408attaching @value{GDBN} to the process.
2409
2410@table @code
2411@kindex detach
2412@item detach
2413When you have finished debugging the attached process, you can use the
2414@code{detach} command to release it from @value{GDBN} control. Detaching
2415the process continues its execution. After the @code{detach} command,
2416that process and @value{GDBN} become completely independent once more, and you
2417are ready to @code{attach} another process or start one with @code{run}.
2418@code{detach} does not repeat if you press @key{RET} again after
2419executing the command.
2420@end table
2421
159fcc13
JK
2422If you exit @value{GDBN} while you have an attached process, you detach
2423that process. If you use the @code{run} command, you kill that process.
2424By default, @value{GDBN} asks for confirmation if you try to do either of these
2425things; you can control whether or not you need to confirm by using the
2426@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
79a6e687 2427Messages}).
c906108c 2428
6d2ebf8b 2429@node Kill Process
79a6e687 2430@section Killing the Child Process
c906108c
SS
2431
2432@table @code
2433@kindex kill
2434@item kill
2435Kill the child process in which your program is running under @value{GDBN}.
2436@end table
2437
2438This command is useful if you wish to debug a core dump instead of a
2439running process. @value{GDBN} ignores any core dump file while your program
2440is running.
2441
2442On some operating systems, a program cannot be executed outside @value{GDBN}
2443while you have breakpoints set on it inside @value{GDBN}. You can use the
2444@code{kill} command in this situation to permit running your program
2445outside the debugger.
2446
2447The @code{kill} command is also useful if you wish to recompile and
2448relink your program, since on many systems it is impossible to modify an
2449executable file while it is running in a process. In this case, when you
2450next type @code{run}, @value{GDBN} notices that the file has changed, and
2451reads the symbol table again (while trying to preserve your current
2452breakpoint settings).
2453
6c95b8df
PA
2454@node Inferiors and Programs
2455@section Debugging Multiple Inferiors and Programs
b77209e0 2456
6c95b8df
PA
2457@value{GDBN} lets you run and debug multiple programs in a single
2458session. In addition, @value{GDBN} on some systems may let you run
2459several programs simultaneously (otherwise you have to exit from one
2460before starting another). In the most general case, you can have
2461multiple threads of execution in each of multiple processes, launched
2462from multiple executables.
b77209e0
PA
2463
2464@cindex inferior
2465@value{GDBN} represents the state of each program execution with an
2466object called an @dfn{inferior}. An inferior typically corresponds to
2467a process, but is more general and applies also to targets that do not
2468have processes. Inferiors may be created before a process runs, and
6c95b8df
PA
2469may be retained after a process exits. Inferiors have unique
2470identifiers that are different from process ids. Usually each
2471inferior will also have its own distinct address space, although some
2472embedded targets may have several inferiors running in different parts
2473of a single address space. Each inferior may in turn have multiple
2474threads running in it.
b77209e0 2475
6c95b8df
PA
2476To find out what inferiors exist at any moment, use @w{@code{info
2477inferiors}}:
b77209e0
PA
2478
2479@table @code
2480@kindex info inferiors
2481@item info inferiors
2482Print a list of all inferiors currently being managed by @value{GDBN}.
3a1ff0b6
PA
2483
2484@value{GDBN} displays for each inferior (in this order):
2485
2486@enumerate
2487@item
2488the inferior number assigned by @value{GDBN}
2489
2490@item
2491the target system's inferior identifier
6c95b8df
PA
2492
2493@item
2494the name of the executable the inferior is running.
2495
3a1ff0b6
PA
2496@end enumerate
2497
2498@noindent
2499An asterisk @samp{*} preceding the @value{GDBN} inferior number
2500indicates the current inferior.
2501
2502For example,
2277426b 2503@end table
3a1ff0b6
PA
2504@c end table here to get a little more width for example
2505
2506@smallexample
2507(@value{GDBP}) info inferiors
6c95b8df
PA
2508 Num Description Executable
2509 2 process 2307 hello
2510* 1 process 3401 goodbye
3a1ff0b6 2511@end smallexample
2277426b
PA
2512
2513To switch focus between inferiors, use the @code{inferior} command:
2514
2515@table @code
3a1ff0b6
PA
2516@kindex inferior @var{infno}
2517@item inferior @var{infno}
2518Make inferior number @var{infno} the current inferior. The argument
2519@var{infno} is the inferior number assigned by @value{GDBN}, as shown
2520in the first field of the @samp{info inferiors} display.
2277426b
PA
2521@end table
2522
6c95b8df
PA
2523
2524You can get multiple executables into a debugging session via the
2525@code{add-inferior} and @w{@code{clone-inferior}} commands. On some
2526systems @value{GDBN} can add inferiors to the debug session
2527automatically by following calls to @code{fork} and @code{exec}. To
2528remove inferiors from the debugging session use the
af624141 2529@w{@code{remove-inferiors}} command.
6c95b8df
PA
2530
2531@table @code
2532@kindex add-inferior
2533@item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ]
2534Adds @var{n} inferiors to be run using @var{executable} as the
2535executable. @var{n} defaults to 1. If no executable is specified,
2536the inferiors begins empty, with no program. You can still assign or
2537change the program assigned to the inferior at any time by using the
2538@code{file} command with the executable name as its argument.
2539
2540@kindex clone-inferior
2541@item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
2542Adds @var{n} inferiors ready to execute the same program as inferior
2543@var{infno}. @var{n} defaults to 1. @var{infno} defaults to the
2544number of the current inferior. This is a convenient command when you
2545want to run another instance of the inferior you are debugging.
2546
2547@smallexample
2548(@value{GDBP}) info inferiors
2549 Num Description Executable
2550* 1 process 29964 helloworld
2551(@value{GDBP}) clone-inferior
2552Added inferior 2.
25531 inferiors added.
2554(@value{GDBP}) info inferiors
2555 Num Description Executable
2556 2 <null> helloworld
2557* 1 process 29964 helloworld
2558@end smallexample
2559
2560You can now simply switch focus to inferior 2 and run it.
2561
af624141
MS
2562@kindex remove-inferiors
2563@item remove-inferiors @var{infno}@dots{}
2564Removes the inferior or inferiors @var{infno}@dots{}. It is not
2565possible to remove an inferior that is running with this command. For
2566those, use the @code{kill} or @code{detach} command first.
6c95b8df
PA
2567
2568@end table
2569
2570To quit debugging one of the running inferiors that is not the current
2571inferior, you can either detach from it by using the @w{@code{detach
2572inferior}} command (allowing it to run independently), or kill it
af624141 2573using the @w{@code{kill inferiors}} command:
2277426b
PA
2574
2575@table @code
af624141
MS
2576@kindex detach inferiors @var{infno}@dots{}
2577@item detach inferior @var{infno}@dots{}
2578Detach from the inferior or inferiors identified by @value{GDBN}
5e30da2c 2579inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
af624141
MS
2580still stays on the list of inferiors shown by @code{info inferiors},
2581but its Description will show @samp{<null>}.
2582
2583@kindex kill inferiors @var{infno}@dots{}
2584@item kill inferiors @var{infno}@dots{}
2585Kill the inferior or inferiors identified by @value{GDBN} inferior
2586number(s) @var{infno}@dots{}. Note that the inferior's entry still
2587stays on the list of inferiors shown by @code{info inferiors}, but its
2588Description will show @samp{<null>}.
2277426b
PA
2589@end table
2590
6c95b8df 2591After the successful completion of a command such as @code{detach},
af624141 2592@code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
6c95b8df
PA
2593a normal process exit, the inferior is still valid and listed with
2594@code{info inferiors}, ready to be restarted.
2595
2596
2277426b
PA
2597To be notified when inferiors are started or exit under @value{GDBN}'s
2598control use @w{@code{set print inferior-events}}:
b77209e0 2599
2277426b 2600@table @code
b77209e0
PA
2601@kindex set print inferior-events
2602@cindex print messages on inferior start and exit
2603@item set print inferior-events
2604@itemx set print inferior-events on
2605@itemx set print inferior-events off
2606The @code{set print inferior-events} command allows you to enable or
2607disable printing of messages when @value{GDBN} notices that new
2608inferiors have started or that inferiors have exited or have been
2609detached. By default, these messages will not be printed.
2610
2611@kindex show print inferior-events
2612@item show print inferior-events
2613Show whether messages will be printed when @value{GDBN} detects that
2614inferiors have started, exited or have been detached.
2615@end table
2616
6c95b8df
PA
2617Many commands will work the same with multiple programs as with a
2618single program: e.g., @code{print myglobal} will simply display the
2619value of @code{myglobal} in the current inferior.
2620
2621
2622Occasionaly, when debugging @value{GDBN} itself, it may be useful to
2623get more info about the relationship of inferiors, programs, address
2624spaces in a debug session. You can do that with the @w{@code{maint
2625info program-spaces}} command.
2626
2627@table @code
2628@kindex maint info program-spaces
2629@item maint info program-spaces
2630Print a list of all program spaces currently being managed by
2631@value{GDBN}.
2632
2633@value{GDBN} displays for each program space (in this order):
2634
2635@enumerate
2636@item
2637the program space number assigned by @value{GDBN}
2638
2639@item
2640the name of the executable loaded into the program space, with e.g.,
2641the @code{file} command.
2642
2643@end enumerate
2644
2645@noindent
2646An asterisk @samp{*} preceding the @value{GDBN} program space number
2647indicates the current program space.
2648
2649In addition, below each program space line, @value{GDBN} prints extra
2650information that isn't suitable to display in tabular form. For
2651example, the list of inferiors bound to the program space.
2652
2653@smallexample
2654(@value{GDBP}) maint info program-spaces
2655 Id Executable
2656 2 goodbye
2657 Bound inferiors: ID 1 (process 21561)
2658* 1 hello
2659@end smallexample
2660
2661Here we can see that no inferior is running the program @code{hello},
2662while @code{process 21561} is running the program @code{goodbye}. On
2663some targets, it is possible that multiple inferiors are bound to the
2664same program space. The most common example is that of debugging both
2665the parent and child processes of a @code{vfork} call. For example,
2666
2667@smallexample
2668(@value{GDBP}) maint info program-spaces
2669 Id Executable
2670* 1 vfork-test
2671 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
2672@end smallexample
2673
2674Here, both inferior 2 and inferior 1 are running in the same program
2675space as a result of inferior 1 having executed a @code{vfork} call.
2676@end table
2677
6d2ebf8b 2678@node Threads
79a6e687 2679@section Debugging Programs with Multiple Threads
c906108c
SS
2680
2681@cindex threads of execution
2682@cindex multiple threads
2683@cindex switching threads
2684In some operating systems, such as HP-UX and Solaris, a single program
2685may have more than one @dfn{thread} of execution. The precise semantics
2686of threads differ from one operating system to another, but in general
2687the threads of a single program are akin to multiple processes---except
2688that they share one address space (that is, they can all examine and
2689modify the same variables). On the other hand, each thread has its own
2690registers and execution stack, and perhaps private memory.
2691
2692@value{GDBN} provides these facilities for debugging multi-thread
2693programs:
2694
2695@itemize @bullet
2696@item automatic notification of new threads
2697@item @samp{thread @var{threadno}}, a command to switch among threads
2698@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2699@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2700a command to apply a command to a list of threads
2701@item thread-specific breakpoints
93815fbf
VP
2702@item @samp{set print thread-events}, which controls printing of
2703messages on thread start and exit.
17a37d48
PP
2704@item @samp{set libthread-db-search-path @var{path}}, which lets
2705the user specify which @code{libthread_db} to use if the default choice
2706isn't compatible with the program.
c906108c
SS
2707@end itemize
2708
c906108c
SS
2709@quotation
2710@emph{Warning:} These facilities are not yet available on every
2711@value{GDBN} configuration where the operating system supports threads.
2712If your @value{GDBN} does not support threads, these commands have no
2713effect. For example, a system without thread support shows no output
2714from @samp{info threads}, and always rejects the @code{thread} command,
2715like this:
2716
2717@smallexample
2718(@value{GDBP}) info threads
2719(@value{GDBP}) thread 1
2720Thread ID 1 not known. Use the "info threads" command to
2721see the IDs of currently known threads.
2722@end smallexample
2723@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2724@c doesn't support threads"?
2725@end quotation
c906108c
SS
2726
2727@cindex focus of debugging
2728@cindex current thread
2729The @value{GDBN} thread debugging facility allows you to observe all
2730threads while your program runs---but whenever @value{GDBN} takes
2731control, one thread in particular is always the focus of debugging.
2732This thread is called the @dfn{current thread}. Debugging commands show
2733program information from the perspective of the current thread.
2734
41afff9a 2735@cindex @code{New} @var{systag} message
c906108c
SS
2736@cindex thread identifier (system)
2737@c FIXME-implementors!! It would be more helpful if the [New...] message
2738@c included GDB's numeric thread handle, so you could just go to that
2739@c thread without first checking `info threads'.
2740Whenever @value{GDBN} detects a new thread in your program, it displays
2741the target system's identification for the thread with a message in the
2742form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2743whose form varies depending on the particular system. For example, on
8807d78b 2744@sc{gnu}/Linux, you might see
c906108c 2745
474c8240 2746@smallexample
08e796bc 2747[New Thread 0x41e02940 (LWP 25582)]
474c8240 2748@end smallexample
c906108c
SS
2749
2750@noindent
2751when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2752the @var{systag} is simply something like @samp{process 368}, with no
2753further qualifier.
2754
2755@c FIXME!! (1) Does the [New...] message appear even for the very first
2756@c thread of a program, or does it only appear for the
6ca652b0 2757@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2758@c program?
2759@c (2) *Is* there necessarily a first thread always? Or do some
2760@c multithread systems permit starting a program with multiple
5d161b24 2761@c threads ab initio?
c906108c
SS
2762
2763@cindex thread number
2764@cindex thread identifier (GDB)
2765For debugging purposes, @value{GDBN} associates its own thread
2766number---always a single integer---with each thread in your program.
2767
2768@table @code
2769@kindex info threads
60f98dde
MS
2770@item info threads @r{[}@var{id}@dots{}@r{]}
2771Display a summary of all threads currently in your program. Optional
2772argument @var{id}@dots{} is one or more thread ids separated by spaces, and
2773means to print information only about the specified thread or threads.
2774@value{GDBN} displays for each thread (in this order):
c906108c
SS
2775
2776@enumerate
09d4efe1
EZ
2777@item
2778the thread number assigned by @value{GDBN}
c906108c 2779
09d4efe1
EZ
2780@item
2781the target system's thread identifier (@var{systag})
c906108c 2782
4694da01
TT
2783@item
2784the thread's name, if one is known. A thread can either be named by
2785the user (see @code{thread name}, below), or, in some cases, by the
2786program itself.
2787
09d4efe1
EZ
2788@item
2789the current stack frame summary for that thread
c906108c
SS
2790@end enumerate
2791
2792@noindent
2793An asterisk @samp{*} to the left of the @value{GDBN} thread number
2794indicates the current thread.
2795
5d161b24 2796For example,
c906108c
SS
2797@end table
2798@c end table here to get a little more width for example
2799
2800@smallexample
2801(@value{GDBP}) info threads
13fd8b81
TT
2802 Id Target Id Frame
2803 3 process 35 thread 27 0x34e5 in sigpause ()
2804 2 process 35 thread 23 0x34e5 in sigpause ()
2805* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
c906108c
SS
2806 at threadtest.c:68
2807@end smallexample
53a5351d 2808
c45da7e6
EZ
2809On Solaris, you can display more information about user threads with a
2810Solaris-specific command:
2811
2812@table @code
2813@item maint info sol-threads
2814@kindex maint info sol-threads
2815@cindex thread info (Solaris)
2816Display info on Solaris user threads.
2817@end table
2818
c906108c
SS
2819@table @code
2820@kindex thread @var{threadno}
2821@item thread @var{threadno}
2822Make thread number @var{threadno} the current thread. The command
2823argument @var{threadno} is the internal @value{GDBN} thread number, as
2824shown in the first field of the @samp{info threads} display.
2825@value{GDBN} responds by displaying the system identifier of the thread
2826you selected, and its current stack frame summary:
2827
2828@smallexample
c906108c 2829(@value{GDBP}) thread 2
13fd8b81
TT
2830[Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
2831#0 some_function (ignore=0x0) at example.c:8
28328 printf ("hello\n");
c906108c
SS
2833@end smallexample
2834
2835@noindent
2836As with the @samp{[New @dots{}]} message, the form of the text after
2837@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2838threads.
c906108c 2839
6aed2dbc
SS
2840@vindex $_thread@r{, convenience variable}
2841The debugger convenience variable @samp{$_thread} contains the number
2842of the current thread. You may find this useful in writing breakpoint
2843conditional expressions, command scripts, and so forth. See
2844@xref{Convenience Vars,, Convenience Variables}, for general
2845information on convenience variables.
2846
9c16f35a 2847@kindex thread apply
638ac427 2848@cindex apply command to several threads
13fd8b81 2849@item thread apply [@var{threadno} | all] @var{command}
839c27b7
EZ
2850The @code{thread apply} command allows you to apply the named
2851@var{command} to one or more threads. Specify the numbers of the
2852threads that you want affected with the command argument
2853@var{threadno}. It can be a single thread number, one of the numbers
2854shown in the first field of the @samp{info threads} display; or it
2855could be a range of thread numbers, as in @code{2-4}. To apply a
2856command to all threads, type @kbd{thread apply all @var{command}}.
93815fbf 2857
4694da01
TT
2858@kindex thread name
2859@cindex name a thread
2860@item thread name [@var{name}]
2861This command assigns a name to the current thread. If no argument is
2862given, any existing user-specified name is removed. The thread name
2863appears in the @samp{info threads} display.
2864
2865On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
2866determine the name of the thread as given by the OS. On these
2867systems, a name specified with @samp{thread name} will override the
2868system-give name, and removing the user-specified name will cause
2869@value{GDBN} to once again display the system-specified name.
2870
60f98dde
MS
2871@kindex thread find
2872@cindex search for a thread
2873@item thread find [@var{regexp}]
2874Search for and display thread ids whose name or @var{systag}
2875matches the supplied regular expression.
2876
2877As well as being the complement to the @samp{thread name} command,
2878this command also allows you to identify a thread by its target
2879@var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
2880is the LWP id.
2881
2882@smallexample
2883(@value{GDBN}) thread find 26688
2884Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
2885(@value{GDBN}) info thread 4
2886 Id Target Id Frame
2887 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
2888@end smallexample
2889
93815fbf
VP
2890@kindex set print thread-events
2891@cindex print messages on thread start and exit
2892@item set print thread-events
2893@itemx set print thread-events on
2894@itemx set print thread-events off
2895The @code{set print thread-events} command allows you to enable or
2896disable printing of messages when @value{GDBN} notices that new threads have
2897started or that threads have exited. By default, these messages will
2898be printed if detection of these events is supported by the target.
2899Note that these messages cannot be disabled on all targets.
2900
2901@kindex show print thread-events
2902@item show print thread-events
2903Show whether messages will be printed when @value{GDBN} detects that threads
2904have started and exited.
c906108c
SS
2905@end table
2906
79a6e687 2907@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
c906108c
SS
2908more information about how @value{GDBN} behaves when you stop and start
2909programs with multiple threads.
2910
79a6e687 2911@xref{Set Watchpoints,,Setting Watchpoints}, for information about
c906108c 2912watchpoints in programs with multiple threads.
c906108c 2913
bf88dd68 2914@anchor{set libthread-db-search-path}
17a37d48
PP
2915@table @code
2916@kindex set libthread-db-search-path
2917@cindex search path for @code{libthread_db}
2918@item set libthread-db-search-path @r{[}@var{path}@r{]}
2919If this variable is set, @var{path} is a colon-separated list of
2920directories @value{GDBN} will use to search for @code{libthread_db}.
2921If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
98a5dd13 2922its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
7e0396aa
DE
2923Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
2924macro.
17a37d48
PP
2925
2926On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
2927@code{libthread_db} library to obtain information about threads in the
2928inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
bf88dd68
JK
2929to find @code{libthread_db}. @value{GDBN} also consults first if inferior
2930specific thread debugging library loading is enabled
2931by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
98a5dd13
DE
2932
2933A special entry @samp{$sdir} for @samp{libthread-db-search-path}
2934refers to the default system directories that are
bf88dd68
JK
2935normally searched for loading shared libraries. The @samp{$sdir} entry
2936is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
2937(@pxref{libthread_db.so.1 file}).
98a5dd13
DE
2938
2939A special entry @samp{$pdir} for @samp{libthread-db-search-path}
2940refers to the directory from which @code{libpthread}
2941was loaded in the inferior process.
17a37d48
PP
2942
2943For any @code{libthread_db} library @value{GDBN} finds in above directories,
2944@value{GDBN} attempts to initialize it with the current inferior process.
2945If this initialization fails (which could happen because of a version
2946mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
2947will unload @code{libthread_db}, and continue with the next directory.
2948If none of @code{libthread_db} libraries initialize successfully,
2949@value{GDBN} will issue a warning and thread debugging will be disabled.
2950
2951Setting @code{libthread-db-search-path} is currently implemented
2952only on some platforms.
2953
2954@kindex show libthread-db-search-path
2955@item show libthread-db-search-path
2956Display current libthread_db search path.
02d868e8
PP
2957
2958@kindex set debug libthread-db
2959@kindex show debug libthread-db
2960@cindex debugging @code{libthread_db}
2961@item set debug libthread-db
2962@itemx show debug libthread-db
2963Turns on or off display of @code{libthread_db}-related events.
2964Use @code{1} to enable, @code{0} to disable.
17a37d48
PP
2965@end table
2966
6c95b8df
PA
2967@node Forks
2968@section Debugging Forks
c906108c
SS
2969
2970@cindex fork, debugging programs which call
2971@cindex multiple processes
2972@cindex processes, multiple
53a5351d
JM
2973On most systems, @value{GDBN} has no special support for debugging
2974programs which create additional processes using the @code{fork}
2975function. When a program forks, @value{GDBN} will continue to debug the
2976parent process and the child process will run unimpeded. If you have
2977set a breakpoint in any code which the child then executes, the child
2978will get a @code{SIGTRAP} signal which (unless it catches the signal)
2979will cause it to terminate.
c906108c
SS
2980
2981However, if you want to debug the child process there is a workaround
2982which isn't too painful. Put a call to @code{sleep} in the code which
2983the child process executes after the fork. It may be useful to sleep
2984only if a certain environment variable is set, or a certain file exists,
2985so that the delay need not occur when you don't want to run @value{GDBN}
2986on the child. While the child is sleeping, use the @code{ps} program to
2987get its process ID. Then tell @value{GDBN} (a new invocation of
2988@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2989the child process (@pxref{Attach}). From that point on you can debug
c906108c 2990the child process just like any other process which you attached to.
c906108c 2991
b51970ac
DJ
2992On some systems, @value{GDBN} provides support for debugging programs that
2993create additional processes using the @code{fork} or @code{vfork} functions.
2994Currently, the only platforms with this feature are HP-UX (11.x and later
a6b151f1 2995only?) and @sc{gnu}/Linux (kernel version 2.5.60 and later).
c906108c
SS
2996
2997By default, when a program forks, @value{GDBN} will continue to debug
2998the parent process and the child process will run unimpeded.
2999
3000If you want to follow the child process instead of the parent process,
3001use the command @w{@code{set follow-fork-mode}}.
3002
3003@table @code
3004@kindex set follow-fork-mode
3005@item set follow-fork-mode @var{mode}
3006Set the debugger response to a program call of @code{fork} or
3007@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 3008process. The @var{mode} argument can be:
c906108c
SS
3009
3010@table @code
3011@item parent
3012The original process is debugged after a fork. The child process runs
2df3850c 3013unimpeded. This is the default.
c906108c
SS
3014
3015@item child
3016The new process is debugged after a fork. The parent process runs
3017unimpeded.
3018
c906108c
SS
3019@end table
3020
9c16f35a 3021@kindex show follow-fork-mode
c906108c 3022@item show follow-fork-mode
2df3850c 3023Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
3024@end table
3025
5c95884b
MS
3026@cindex debugging multiple processes
3027On Linux, if you want to debug both the parent and child processes, use the
3028command @w{@code{set detach-on-fork}}.
3029
3030@table @code
3031@kindex set detach-on-fork
3032@item set detach-on-fork @var{mode}
3033Tells gdb whether to detach one of the processes after a fork, or
3034retain debugger control over them both.
3035
3036@table @code
3037@item on
3038The child process (or parent process, depending on the value of
3039@code{follow-fork-mode}) will be detached and allowed to run
3040independently. This is the default.
3041
3042@item off
3043Both processes will be held under the control of @value{GDBN}.
3044One process (child or parent, depending on the value of
3045@code{follow-fork-mode}) is debugged as usual, while the other
3046is held suspended.
3047
3048@end table
3049
11310833
NR
3050@kindex show detach-on-fork
3051@item show detach-on-fork
3052Show whether detach-on-fork mode is on/off.
5c95884b
MS
3053@end table
3054
2277426b
PA
3055If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3056will retain control of all forked processes (including nested forks).
3057You can list the forked processes under the control of @value{GDBN} by
3058using the @w{@code{info inferiors}} command, and switch from one fork
6c95b8df
PA
3059to another by using the @code{inferior} command (@pxref{Inferiors and
3060Programs, ,Debugging Multiple Inferiors and Programs}).
5c95884b
MS
3061
3062To quit debugging one of the forked processes, you can either detach
af624141
MS
3063from it by using the @w{@code{detach inferiors}} command (allowing it
3064to run independently), or kill it using the @w{@code{kill inferiors}}
6c95b8df
PA
3065command. @xref{Inferiors and Programs, ,Debugging Multiple Inferiors
3066and Programs}.
5c95884b 3067
c906108c
SS
3068If you ask to debug a child process and a @code{vfork} is followed by an
3069@code{exec}, @value{GDBN} executes the new target up to the first
3070breakpoint in the new target. If you have a breakpoint set on
3071@code{main} in your original program, the breakpoint will also be set on
3072the child process's @code{main}.
3073
2277426b
PA
3074On some systems, when a child process is spawned by @code{vfork}, you
3075cannot debug the child or parent until an @code{exec} call completes.
c906108c
SS
3076
3077If you issue a @code{run} command to @value{GDBN} after an @code{exec}
6c95b8df
PA
3078call executes, the new target restarts. To restart the parent
3079process, use the @code{file} command with the parent executable name
3080as its argument. By default, after an @code{exec} call executes,
3081@value{GDBN} discards the symbols of the previous executable image.
3082You can change this behaviour with the @w{@code{set follow-exec-mode}}
3083command.
3084
3085@table @code
3086@kindex set follow-exec-mode
3087@item set follow-exec-mode @var{mode}
3088
3089Set debugger response to a program call of @code{exec}. An
3090@code{exec} call replaces the program image of a process.
3091
3092@code{follow-exec-mode} can be:
3093
3094@table @code
3095@item new
3096@value{GDBN} creates a new inferior and rebinds the process to this
3097new inferior. The program the process was running before the
3098@code{exec} call can be restarted afterwards by restarting the
3099original inferior.
3100
3101For example:
3102
3103@smallexample
3104(@value{GDBP}) info inferiors
3105(gdb) info inferior
3106 Id Description Executable
3107* 1 <null> prog1
3108(@value{GDBP}) run
3109process 12020 is executing new program: prog2
3110Program exited normally.
3111(@value{GDBP}) info inferiors
3112 Id Description Executable
3113* 2 <null> prog2
3114 1 <null> prog1
3115@end smallexample
3116
3117@item same
3118@value{GDBN} keeps the process bound to the same inferior. The new
3119executable image replaces the previous executable loaded in the
3120inferior. Restarting the inferior after the @code{exec} call, with
3121e.g., the @code{run} command, restarts the executable the process was
3122running after the @code{exec} call. This is the default mode.
3123
3124For example:
3125
3126@smallexample
3127(@value{GDBP}) info inferiors
3128 Id Description Executable
3129* 1 <null> prog1
3130(@value{GDBP}) run
3131process 12020 is executing new program: prog2
3132Program exited normally.
3133(@value{GDBP}) info inferiors
3134 Id Description Executable
3135* 1 <null> prog2
3136@end smallexample
3137
3138@end table
3139@end table
c906108c
SS
3140
3141You can use the @code{catch} command to make @value{GDBN} stop whenever
3142a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
79a6e687 3143Catchpoints, ,Setting Catchpoints}.
c906108c 3144
5c95884b 3145@node Checkpoint/Restart
79a6e687 3146@section Setting a @emph{Bookmark} to Return to Later
5c95884b
MS
3147
3148@cindex checkpoint
3149@cindex restart
3150@cindex bookmark
3151@cindex snapshot of a process
3152@cindex rewind program state
3153
3154On certain operating systems@footnote{Currently, only
3155@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3156program's state, called a @dfn{checkpoint}, and come back to it
3157later.
3158
3159Returning to a checkpoint effectively undoes everything that has
3160happened in the program since the @code{checkpoint} was saved. This
3161includes changes in memory, registers, and even (within some limits)
3162system state. Effectively, it is like going back in time to the
3163moment when the checkpoint was saved.
3164
3165Thus, if you're stepping thru a program and you think you're
3166getting close to the point where things go wrong, you can save
3167a checkpoint. Then, if you accidentally go too far and miss
3168the critical statement, instead of having to restart your program
3169from the beginning, you can just go back to the checkpoint and
3170start again from there.
3171
3172This can be especially useful if it takes a lot of time or
3173steps to reach the point where you think the bug occurs.
3174
3175To use the @code{checkpoint}/@code{restart} method of debugging:
3176
3177@table @code
3178@kindex checkpoint
3179@item checkpoint
3180Save a snapshot of the debugged program's current execution state.
3181The @code{checkpoint} command takes no arguments, but each checkpoint
3182is assigned a small integer id, similar to a breakpoint id.
3183
3184@kindex info checkpoints
3185@item info checkpoints
3186List the checkpoints that have been saved in the current debugging
3187session. For each checkpoint, the following information will be
3188listed:
3189
3190@table @code
3191@item Checkpoint ID
3192@item Process ID
3193@item Code Address
3194@item Source line, or label
3195@end table
3196
3197@kindex restart @var{checkpoint-id}
3198@item restart @var{checkpoint-id}
3199Restore the program state that was saved as checkpoint number
3200@var{checkpoint-id}. All program variables, registers, stack frames
3201etc.@: will be returned to the values that they had when the checkpoint
3202was saved. In essence, gdb will ``wind back the clock'' to the point
3203in time when the checkpoint was saved.
3204
3205Note that breakpoints, @value{GDBN} variables, command history etc.
3206are not affected by restoring a checkpoint. In general, a checkpoint
3207only restores things that reside in the program being debugged, not in
3208the debugger.
3209
b8db102d
MS
3210@kindex delete checkpoint @var{checkpoint-id}
3211@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
3212Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
3213
3214@end table
3215
3216Returning to a previously saved checkpoint will restore the user state
3217of the program being debugged, plus a significant subset of the system
3218(OS) state, including file pointers. It won't ``un-write'' data from
3219a file, but it will rewind the file pointer to the previous location,
3220so that the previously written data can be overwritten. For files
3221opened in read mode, the pointer will also be restored so that the
3222previously read data can be read again.
3223
3224Of course, characters that have been sent to a printer (or other
3225external device) cannot be ``snatched back'', and characters received
3226from eg.@: a serial device can be removed from internal program buffers,
3227but they cannot be ``pushed back'' into the serial pipeline, ready to
3228be received again. Similarly, the actual contents of files that have
3229been changed cannot be restored (at this time).
3230
3231However, within those constraints, you actually can ``rewind'' your
3232program to a previously saved point in time, and begin debugging it
3233again --- and you can change the course of events so as to debug a
3234different execution path this time.
3235
3236@cindex checkpoints and process id
3237Finally, there is one bit of internal program state that will be
3238different when you return to a checkpoint --- the program's process
3239id. Each checkpoint will have a unique process id (or @var{pid}),
3240and each will be different from the program's original @var{pid}.
3241If your program has saved a local copy of its process id, this could
3242potentially pose a problem.
3243
79a6e687 3244@subsection A Non-obvious Benefit of Using Checkpoints
5c95884b
MS
3245
3246On some systems such as @sc{gnu}/Linux, address space randomization
3247is performed on new processes for security reasons. This makes it
3248difficult or impossible to set a breakpoint, or watchpoint, on an
3249absolute address if you have to restart the program, since the
3250absolute location of a symbol will change from one execution to the
3251next.
3252
3253A checkpoint, however, is an @emph{identical} copy of a process.
3254Therefore if you create a checkpoint at (eg.@:) the start of main,
3255and simply return to that checkpoint instead of restarting the
3256process, you can avoid the effects of address randomization and
3257your symbols will all stay in the same place.
3258
6d2ebf8b 3259@node Stopping
c906108c
SS
3260@chapter Stopping and Continuing
3261
3262The principal purposes of using a debugger are so that you can stop your
3263program before it terminates; or so that, if your program runs into
3264trouble, you can investigate and find out why.
3265
7a292a7a
SS
3266Inside @value{GDBN}, your program may stop for any of several reasons,
3267such as a signal, a breakpoint, or reaching a new line after a
3268@value{GDBN} command such as @code{step}. You may then examine and
3269change variables, set new breakpoints or remove old ones, and then
3270continue execution. Usually, the messages shown by @value{GDBN} provide
3271ample explanation of the status of your program---but you can also
3272explicitly request this information at any time.
c906108c
SS
3273
3274@table @code
3275@kindex info program
3276@item info program
3277Display information about the status of your program: whether it is
7a292a7a 3278running or not, what process it is, and why it stopped.
c906108c
SS
3279@end table
3280
3281@menu
3282* Breakpoints:: Breakpoints, watchpoints, and catchpoints
3283* Continuing and Stepping:: Resuming execution
aad1c02c
TT
3284* Skipping Over Functions and Files::
3285 Skipping over functions and files
c906108c 3286* Signals:: Signals
c906108c 3287* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
3288@end menu
3289
6d2ebf8b 3290@node Breakpoints
79a6e687 3291@section Breakpoints, Watchpoints, and Catchpoints
c906108c
SS
3292
3293@cindex breakpoints
3294A @dfn{breakpoint} makes your program stop whenever a certain point in
3295the program is reached. For each breakpoint, you can add conditions to
3296control in finer detail whether your program stops. You can set
3297breakpoints with the @code{break} command and its variants (@pxref{Set
79a6e687 3298Breaks, ,Setting Breakpoints}), to specify the place where your program
c906108c
SS
3299should stop by line number, function name or exact address in the
3300program.
3301
09d4efe1
EZ
3302On some systems, you can set breakpoints in shared libraries before
3303the executable is run. There is a minor limitation on HP-UX systems:
3304you must wait until the executable is run in order to set breakpoints
3305in shared library routines that are not called directly by the program
3306(for example, routines that are arguments in a @code{pthread_create}
3307call).
c906108c
SS
3308
3309@cindex watchpoints
fd60e0df 3310@cindex data breakpoints
c906108c
SS
3311@cindex memory tracing
3312@cindex breakpoint on memory address
3313@cindex breakpoint on variable modification
3314A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 3315when the value of an expression changes. The expression may be a value
0ced0c34 3316of a variable, or it could involve values of one or more variables
fd60e0df
EZ
3317combined by operators, such as @samp{a + b}. This is sometimes called
3318@dfn{data breakpoints}. You must use a different command to set
79a6e687 3319watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
fd60e0df
EZ
3320from that, you can manage a watchpoint like any other breakpoint: you
3321enable, disable, and delete both breakpoints and watchpoints using the
3322same commands.
c906108c
SS
3323
3324You can arrange to have values from your program displayed automatically
3325whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
79a6e687 3326Automatic Display}.
c906108c
SS
3327
3328@cindex catchpoints
3329@cindex breakpoint on events
3330A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 3331when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
3332exception or the loading of a library. As with watchpoints, you use a
3333different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
79a6e687 3334Catchpoints}), but aside from that, you can manage a catchpoint like any
c906108c 3335other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 3336@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
3337
3338@cindex breakpoint numbers
3339@cindex numbers for breakpoints
3340@value{GDBN} assigns a number to each breakpoint, watchpoint, or
3341catchpoint when you create it; these numbers are successive integers
3342starting with one. In many of the commands for controlling various
3343features of breakpoints you use the breakpoint number to say which
3344breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
3345@dfn{disabled}; if disabled, it has no effect on your program until you
3346enable it again.
3347
c5394b80
JM
3348@cindex breakpoint ranges
3349@cindex ranges of breakpoints
3350Some @value{GDBN} commands accept a range of breakpoints on which to
3351operate. A breakpoint range is either a single breakpoint number, like
3352@samp{5}, or two such numbers, in increasing order, separated by a
3353hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
d52fb0e9 3354all breakpoints in that range are operated on.
c5394b80 3355
c906108c
SS
3356@menu
3357* Set Breaks:: Setting breakpoints
3358* Set Watchpoints:: Setting watchpoints
3359* Set Catchpoints:: Setting catchpoints
3360* Delete Breaks:: Deleting breakpoints
3361* Disabling:: Disabling breakpoints
3362* Conditions:: Break conditions
3363* Break Commands:: Breakpoint command lists
e7e0cddf 3364* Dynamic Printf:: Dynamic printf
6149aea9 3365* Save Breakpoints:: How to save breakpoints in a file
62e5f89c 3366* Static Probe Points:: Listing static probe points
d4f3574e 3367* Error in Breakpoints:: ``Cannot insert breakpoints''
79a6e687 3368* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
c906108c
SS
3369@end menu
3370
6d2ebf8b 3371@node Set Breaks
79a6e687 3372@subsection Setting Breakpoints
c906108c 3373
5d161b24 3374@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
3375@c consider in particular declaration with/without initialization.
3376@c
3377@c FIXME 2 is there stuff on this already? break at fun start, already init?
3378
3379@kindex break
41afff9a
EZ
3380@kindex b @r{(@code{break})}
3381@vindex $bpnum@r{, convenience variable}
c906108c
SS
3382@cindex latest breakpoint
3383Breakpoints are set with the @code{break} command (abbreviated
5d161b24 3384@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 3385number of the breakpoint you've set most recently; see @ref{Convenience
79a6e687 3386Vars,, Convenience Variables}, for a discussion of what you can do with
c906108c
SS
3387convenience variables.
3388
c906108c 3389@table @code
2a25a5ba
EZ
3390@item break @var{location}
3391Set a breakpoint at the given @var{location}, which can specify a
3392function name, a line number, or an address of an instruction.
3393(@xref{Specify Location}, for a list of all the possible ways to
3394specify a @var{location}.) The breakpoint will stop your program just
3395before it executes any of the code in the specified @var{location}.
3396
c906108c 3397When using source languages that permit overloading of symbols, such as
2a25a5ba 3398C@t{++}, a function name may refer to more than one possible place to break.
6ba66d6a
JB
3399@xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
3400that situation.
c906108c 3401
45ac276d 3402It is also possible to insert a breakpoint that will stop the program
2c88c651
JB
3403only if a specific thread (@pxref{Thread-Specific Breakpoints})
3404or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
45ac276d 3405
c906108c
SS
3406@item break
3407When called without any arguments, @code{break} sets a breakpoint at
3408the next instruction to be executed in the selected stack frame
3409(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
3410innermost, this makes your program stop as soon as control
3411returns to that frame. This is similar to the effect of a
3412@code{finish} command in the frame inside the selected frame---except
3413that @code{finish} does not leave an active breakpoint. If you use
3414@code{break} without an argument in the innermost frame, @value{GDBN} stops
3415the next time it reaches the current location; this may be useful
3416inside loops.
3417
3418@value{GDBN} normally ignores breakpoints when it resumes execution, until at
3419least one instruction has been executed. If it did not do this, you
3420would be unable to proceed past a breakpoint without first disabling the
3421breakpoint. This rule applies whether or not the breakpoint already
3422existed when your program stopped.
3423
3424@item break @dots{} if @var{cond}
3425Set a breakpoint with condition @var{cond}; evaluate the expression
3426@var{cond} each time the breakpoint is reached, and stop only if the
3427value is nonzero---that is, if @var{cond} evaluates as true.
3428@samp{@dots{}} stands for one of the possible arguments described
3429above (or no argument) specifying where to break. @xref{Conditions,
79a6e687 3430,Break Conditions}, for more information on breakpoint conditions.
c906108c
SS
3431
3432@kindex tbreak
3433@item tbreak @var{args}
3434Set a breakpoint enabled only for one stop. @var{args} are the
3435same as for the @code{break} command, and the breakpoint is set in the same
3436way, but the breakpoint is automatically deleted after the first time your
79a6e687 3437program stops there. @xref{Disabling, ,Disabling Breakpoints}.
c906108c 3438
c906108c 3439@kindex hbreak
ba04e063 3440@cindex hardware breakpoints
c906108c 3441@item hbreak @var{args}
d4f3574e
SS
3442Set a hardware-assisted breakpoint. @var{args} are the same as for the
3443@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
3444breakpoint requires hardware support and some target hardware may not
3445have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
3446debugging, so you can set a breakpoint at an instruction without
3447changing the instruction. This can be used with the new trap-generation
09d4efe1 3448provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
3449will generate traps when a program accesses some data or instruction
3450address that is assigned to the debug registers. However the hardware
3451breakpoint registers can take a limited number of breakpoints. For
3452example, on the DSU, only two data breakpoints can be set at a time, and
3453@value{GDBN} will reject this command if more than two are used. Delete
3454or disable unused hardware breakpoints before setting new ones
79a6e687
BW
3455(@pxref{Disabling, ,Disabling Breakpoints}).
3456@xref{Conditions, ,Break Conditions}.
9c16f35a
EZ
3457For remote targets, you can restrict the number of hardware
3458breakpoints @value{GDBN} will use, see @ref{set remote
3459hardware-breakpoint-limit}.
501eef12 3460
c906108c
SS
3461@kindex thbreak
3462@item thbreak @var{args}
3463Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
3464are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 3465the same way. However, like the @code{tbreak} command,
c906108c
SS
3466the breakpoint is automatically deleted after the
3467first time your program stops there. Also, like the @code{hbreak}
5d161b24 3468command, the breakpoint requires hardware support and some target hardware
79a6e687
BW
3469may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
3470See also @ref{Conditions, ,Break Conditions}.
c906108c
SS
3471
3472@kindex rbreak
3473@cindex regular expression
8bd10a10 3474@cindex breakpoints at functions matching a regexp
c45da7e6 3475@cindex set breakpoints in many functions
c906108c 3476@item rbreak @var{regex}
c906108c 3477Set breakpoints on all functions matching the regular expression
11cf8741
JM
3478@var{regex}. This command sets an unconditional breakpoint on all
3479matches, printing a list of all breakpoints it set. Once these
3480breakpoints are set, they are treated just like the breakpoints set with
3481the @code{break} command. You can delete them, disable them, or make
3482them conditional the same way as any other breakpoint.
3483
3484The syntax of the regular expression is the standard one used with tools
3485like @file{grep}. Note that this is different from the syntax used by
3486shells, so for instance @code{foo*} matches all functions that include
3487an @code{fo} followed by zero or more @code{o}s. There is an implicit
3488@code{.*} leading and trailing the regular expression you supply, so to
3489match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 3490
f7dc1244 3491@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 3492When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
3493breakpoints on overloaded functions that are not members of any special
3494classes.
c906108c 3495
f7dc1244
EZ
3496@cindex set breakpoints on all functions
3497The @code{rbreak} command can be used to set breakpoints in
3498@strong{all} the functions in a program, like this:
3499
3500@smallexample
3501(@value{GDBP}) rbreak .
3502@end smallexample
3503
8bd10a10
CM
3504@item rbreak @var{file}:@var{regex}
3505If @code{rbreak} is called with a filename qualification, it limits
3506the search for functions matching the given regular expression to the
3507specified @var{file}. This can be used, for example, to set breakpoints on
3508every function in a given file:
3509
3510@smallexample
3511(@value{GDBP}) rbreak file.c:.
3512@end smallexample
3513
3514The colon separating the filename qualifier from the regex may
3515optionally be surrounded by spaces.
3516
c906108c
SS
3517@kindex info breakpoints
3518@cindex @code{$_} and @code{info breakpoints}
e5a67952
MS
3519@item info breakpoints @r{[}@var{n}@dots{}@r{]}
3520@itemx info break @r{[}@var{n}@dots{}@r{]}
c906108c 3521Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734 3522not deleted. Optional argument @var{n} means print information only
e5a67952
MS
3523about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
3524For each breakpoint, following columns are printed:
c906108c
SS
3525
3526@table @emph
3527@item Breakpoint Numbers
3528@item Type
3529Breakpoint, watchpoint, or catchpoint.
3530@item Disposition
3531Whether the breakpoint is marked to be disabled or deleted when hit.
3532@item Enabled or Disabled
3533Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
b3db7447 3534that are not enabled.
c906108c 3535@item Address
fe6fbf8b 3536Where the breakpoint is in your program, as a memory address. For a
b3db7447
NR
3537pending breakpoint whose address is not yet known, this field will
3538contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
3539library that has the symbol or line referred by breakpoint is loaded.
3540See below for details. A breakpoint with several locations will
3b784c4f 3541have @samp{<MULTIPLE>} in this field---see below for details.
c906108c
SS
3542@item What
3543Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
3544line number. For a pending breakpoint, the original string passed to
3545the breakpoint command will be listed as it cannot be resolved until
3546the appropriate shared library is loaded in the future.
c906108c
SS
3547@end table
3548
3549@noindent
83364271
LM
3550If a breakpoint is conditional, there are two evaluation modes: ``host'' and
3551``target''. If mode is ``host'', breakpoint condition evaluation is done by
3552@value{GDBN} on the host's side. If it is ``target'', then the condition
3553is evaluated by the target. The @code{info break} command shows
3554the condition on the line following the affected breakpoint, together with
3555its condition evaluation mode in between parentheses.
3556
3557Breakpoint commands, if any, are listed after that. A pending breakpoint is
3558allowed to have a condition specified for it. The condition is not parsed for
3559validity until a shared library is loaded that allows the pending
3560breakpoint to resolve to a valid location.
c906108c
SS
3561
3562@noindent
3563@code{info break} with a breakpoint
3564number @var{n} as argument lists only that breakpoint. The
3565convenience variable @code{$_} and the default examining-address for
3566the @code{x} command are set to the address of the last breakpoint
79a6e687 3567listed (@pxref{Memory, ,Examining Memory}).
c906108c
SS
3568
3569@noindent
3570@code{info break} displays a count of the number of times the breakpoint
3571has been hit. This is especially useful in conjunction with the
3572@code{ignore} command. You can ignore a large number of breakpoint
3573hits, look at the breakpoint info to see how many times the breakpoint
3574was hit, and then run again, ignoring one less than that number. This
3575will get you quickly to the last hit of that breakpoint.
816338b5
SS
3576
3577@noindent
3578For a breakpoints with an enable count (xref) greater than 1,
3579@code{info break} also displays that count.
3580
c906108c
SS
3581@end table
3582
3583@value{GDBN} allows you to set any number of breakpoints at the same place in
3584your program. There is nothing silly or meaningless about this. When
3585the breakpoints are conditional, this is even useful
79a6e687 3586(@pxref{Conditions, ,Break Conditions}).
c906108c 3587
2e9132cc
EZ
3588@cindex multiple locations, breakpoints
3589@cindex breakpoints, multiple locations
fcda367b 3590It is possible that a breakpoint corresponds to several locations
fe6fbf8b
VP
3591in your program. Examples of this situation are:
3592
3593@itemize @bullet
f8eba3c6
TT
3594@item
3595Multiple functions in the program may have the same name.
3596
fe6fbf8b
VP
3597@item
3598For a C@t{++} constructor, the @value{NGCC} compiler generates several
3599instances of the function body, used in different cases.
3600
3601@item
3602For a C@t{++} template function, a given line in the function can
3603correspond to any number of instantiations.
3604
3605@item
3606For an inlined function, a given source line can correspond to
3607several places where that function is inlined.
fe6fbf8b
VP
3608@end itemize
3609
3610In all those cases, @value{GDBN} will insert a breakpoint at all
f8eba3c6 3611the relevant locations.
fe6fbf8b 3612
3b784c4f
EZ
3613A breakpoint with multiple locations is displayed in the breakpoint
3614table using several rows---one header row, followed by one row for
3615each breakpoint location. The header row has @samp{<MULTIPLE>} in the
3616address column. The rows for individual locations contain the actual
3617addresses for locations, and show the functions to which those
3618locations belong. The number column for a location is of the form
fe6fbf8b
VP
3619@var{breakpoint-number}.@var{location-number}.
3620
3621For example:
3b784c4f 3622
fe6fbf8b
VP
3623@smallexample
3624Num Type Disp Enb Address What
36251 breakpoint keep y <MULTIPLE>
3626 stop only if i==1
3627 breakpoint already hit 1 time
36281.1 y 0x080486a2 in void foo<int>() at t.cc:8
36291.2 y 0x080486ca in void foo<double>() at t.cc:8
3630@end smallexample
3631
3632Each location can be individually enabled or disabled by passing
3633@var{breakpoint-number}.@var{location-number} as argument to the
3b784c4f
EZ
3634@code{enable} and @code{disable} commands. Note that you cannot
3635delete the individual locations from the list, you can only delete the
16bfc218 3636entire list of locations that belong to their parent breakpoint (with
3b784c4f
EZ
3637the @kbd{delete @var{num}} command, where @var{num} is the number of
3638the parent breakpoint, 1 in the above example). Disabling or enabling
3639the parent breakpoint (@pxref{Disabling}) affects all of the locations
3640that belong to that breakpoint.
fe6fbf8b 3641
2650777c 3642@cindex pending breakpoints
fe6fbf8b 3643It's quite common to have a breakpoint inside a shared library.
3b784c4f 3644Shared libraries can be loaded and unloaded explicitly,
fe6fbf8b
VP
3645and possibly repeatedly, as the program is executed. To support
3646this use case, @value{GDBN} updates breakpoint locations whenever
3647any shared library is loaded or unloaded. Typically, you would
fcda367b 3648set a breakpoint in a shared library at the beginning of your
fe6fbf8b
VP
3649debugging session, when the library is not loaded, and when the
3650symbols from the library are not available. When you try to set
3651breakpoint, @value{GDBN} will ask you if you want to set
3b784c4f 3652a so called @dfn{pending breakpoint}---breakpoint whose address
fe6fbf8b
VP
3653is not yet resolved.
3654
3655After the program is run, whenever a new shared library is loaded,
3656@value{GDBN} reevaluates all the breakpoints. When a newly loaded
3657shared library contains the symbol or line referred to by some
3658pending breakpoint, that breakpoint is resolved and becomes an
3659ordinary breakpoint. When a library is unloaded, all breakpoints
3660that refer to its symbols or source lines become pending again.
3661
3662This logic works for breakpoints with multiple locations, too. For
3663example, if you have a breakpoint in a C@t{++} template function, and
3664a newly loaded shared library has an instantiation of that template,
3665a new location is added to the list of locations for the breakpoint.
3666
3667Except for having unresolved address, pending breakpoints do not
3668differ from regular breakpoints. You can set conditions or commands,
3669enable and disable them and perform other breakpoint operations.
3670
3671@value{GDBN} provides some additional commands for controlling what
3672happens when the @samp{break} command cannot resolve breakpoint
3673address specification to an address:
dd79a6cf
JJ
3674
3675@kindex set breakpoint pending
3676@kindex show breakpoint pending
3677@table @code
3678@item set breakpoint pending auto
3679This is the default behavior. When @value{GDBN} cannot find the breakpoint
3680location, it queries you whether a pending breakpoint should be created.
3681
3682@item set breakpoint pending on
3683This indicates that an unrecognized breakpoint location should automatically
3684result in a pending breakpoint being created.
3685
3686@item set breakpoint pending off
3687This indicates that pending breakpoints are not to be created. Any
3688unrecognized breakpoint location results in an error. This setting does
3689not affect any pending breakpoints previously created.
3690
3691@item show breakpoint pending
3692Show the current behavior setting for creating pending breakpoints.
3693@end table
2650777c 3694
fe6fbf8b
VP
3695The settings above only affect the @code{break} command and its
3696variants. Once breakpoint is set, it will be automatically updated
3697as shared libraries are loaded and unloaded.
2650777c 3698
765dc015
VP
3699@cindex automatic hardware breakpoints
3700For some targets, @value{GDBN} can automatically decide if hardware or
3701software breakpoints should be used, depending on whether the
3702breakpoint address is read-only or read-write. This applies to
3703breakpoints set with the @code{break} command as well as to internal
3704breakpoints set by commands like @code{next} and @code{finish}. For
fcda367b 3705breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
765dc015
VP
3706breakpoints.
3707
3708You can control this automatic behaviour with the following commands::
3709
3710@kindex set breakpoint auto-hw
3711@kindex show breakpoint auto-hw
3712@table @code
3713@item set breakpoint auto-hw on
3714This is the default behavior. When @value{GDBN} sets a breakpoint, it
3715will try to use the target memory map to decide if software or hardware
3716breakpoint must be used.
3717
3718@item set breakpoint auto-hw off
3719This indicates @value{GDBN} should not automatically select breakpoint
3720type. If the target provides a memory map, @value{GDBN} will warn when
3721trying to set software breakpoint at a read-only address.
3722@end table
3723
74960c60
VP
3724@value{GDBN} normally implements breakpoints by replacing the program code
3725at the breakpoint address with a special instruction, which, when
3726executed, given control to the debugger. By default, the program
3727code is so modified only when the program is resumed. As soon as
3728the program stops, @value{GDBN} restores the original instructions. This
3729behaviour guards against leaving breakpoints inserted in the
3730target should gdb abrubptly disconnect. However, with slow remote
3731targets, inserting and removing breakpoint can reduce the performance.
3732This behavior can be controlled with the following commands::
3733
3734@kindex set breakpoint always-inserted
3735@kindex show breakpoint always-inserted
3736@table @code
3737@item set breakpoint always-inserted off
33e5cbd6
PA
3738All breakpoints, including newly added by the user, are inserted in
3739the target only when the target is resumed. All breakpoints are
3740removed from the target when it stops.
74960c60
VP
3741
3742@item set breakpoint always-inserted on
3743Causes all breakpoints to be inserted in the target at all times. If
3744the user adds a new breakpoint, or changes an existing breakpoint, the
3745breakpoints in the target are updated immediately. A breakpoint is
3746removed from the target only when breakpoint itself is removed.
33e5cbd6
PA
3747
3748@cindex non-stop mode, and @code{breakpoint always-inserted}
3749@item set breakpoint always-inserted auto
3750This is the default mode. If @value{GDBN} is controlling the inferior
3751in non-stop mode (@pxref{Non-Stop Mode}), gdb behaves as if
3752@code{breakpoint always-inserted} mode is on. If @value{GDBN} is
3753controlling the inferior in all-stop mode, @value{GDBN} behaves as if
3754@code{breakpoint always-inserted} mode is off.
74960c60 3755@end table
765dc015 3756
83364271
LM
3757@value{GDBN} handles conditional breakpoints by evaluating these conditions
3758when a breakpoint breaks. If the condition is true, then the process being
3759debugged stops, otherwise the process is resumed.
3760
3761If the target supports evaluating conditions on its end, @value{GDBN} may
3762download the breakpoint, together with its conditions, to it.
3763
3764This feature can be controlled via the following commands:
3765
3766@kindex set breakpoint condition-evaluation
3767@kindex show breakpoint condition-evaluation
3768@table @code
3769@item set breakpoint condition-evaluation host
3770This option commands @value{GDBN} to evaluate the breakpoint
3771conditions on the host's side. Unconditional breakpoints are sent to
3772the target which in turn receives the triggers and reports them back to GDB
3773for condition evaluation. This is the standard evaluation mode.
3774
3775@item set breakpoint condition-evaluation target
3776This option commands @value{GDBN} to download breakpoint conditions
3777to the target at the moment of their insertion. The target
3778is responsible for evaluating the conditional expression and reporting
3779breakpoint stop events back to @value{GDBN} whenever the condition
3780is true. Due to limitations of target-side evaluation, some conditions
3781cannot be evaluated there, e.g., conditions that depend on local data
3782that is only known to the host. Examples include
3783conditional expressions involving convenience variables, complex types
3784that cannot be handled by the agent expression parser and expressions
3785that are too long to be sent over to the target, specially when the
3786target is a remote system. In these cases, the conditions will be
3787evaluated by @value{GDBN}.
3788
3789@item set breakpoint condition-evaluation auto
3790This is the default mode. If the target supports evaluating breakpoint
3791conditions on its end, @value{GDBN} will download breakpoint conditions to
3792the target (limitations mentioned previously apply). If the target does
3793not support breakpoint condition evaluation, then @value{GDBN} will fallback
3794to evaluating all these conditions on the host's side.
3795@end table
3796
3797
c906108c
SS
3798@cindex negative breakpoint numbers
3799@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
3800@value{GDBN} itself sometimes sets breakpoints in your program for
3801special purposes, such as proper handling of @code{longjmp} (in C
3802programs). These internal breakpoints are assigned negative numbers,
3803starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 3804You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 3805@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
3806
3807
6d2ebf8b 3808@node Set Watchpoints
79a6e687 3809@subsection Setting Watchpoints
c906108c
SS
3810
3811@cindex setting watchpoints
c906108c
SS
3812You can use a watchpoint to stop execution whenever the value of an
3813expression changes, without having to predict a particular place where
fd60e0df
EZ
3814this may happen. (This is sometimes called a @dfn{data breakpoint}.)
3815The expression may be as simple as the value of a single variable, or
3816as complex as many variables combined by operators. Examples include:
3817
3818@itemize @bullet
3819@item
3820A reference to the value of a single variable.
3821
3822@item
3823An address cast to an appropriate data type. For example,
3824@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
3825address (assuming an @code{int} occupies 4 bytes).
3826
3827@item
3828An arbitrarily complex expression, such as @samp{a*b + c/d}. The
3829expression can use any operators valid in the program's native
3830language (@pxref{Languages}).
3831@end itemize
c906108c 3832
fa4727a6
DJ
3833You can set a watchpoint on an expression even if the expression can
3834not be evaluated yet. For instance, you can set a watchpoint on
3835@samp{*global_ptr} before @samp{global_ptr} is initialized.
3836@value{GDBN} will stop when your program sets @samp{global_ptr} and
3837the expression produces a valid value. If the expression becomes
3838valid in some other way than changing a variable (e.g.@: if the memory
3839pointed to by @samp{*global_ptr} becomes readable as the result of a
3840@code{malloc} call), @value{GDBN} may not stop until the next time
3841the expression changes.
3842
82f2d802
EZ
3843@cindex software watchpoints
3844@cindex hardware watchpoints
c906108c 3845Depending on your system, watchpoints may be implemented in software or
2df3850c 3846hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
3847program and testing the variable's value each time, which is hundreds of
3848times slower than normal execution. (But this may still be worth it, to
3849catch errors where you have no clue what part of your program is the
3850culprit.)
3851
37e4754d 3852On some systems, such as HP-UX, PowerPC, @sc{gnu}/Linux and most other
82f2d802
EZ
3853x86-based targets, @value{GDBN} includes support for hardware
3854watchpoints, which do not slow down the running of your program.
c906108c
SS
3855
3856@table @code
3857@kindex watch
9c06b0b4 3858@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
fd60e0df
EZ
3859Set a watchpoint for an expression. @value{GDBN} will break when the
3860expression @var{expr} is written into by the program and its value
3861changes. The simplest (and the most popular) use of this command is
3862to watch the value of a single variable:
3863
3864@smallexample
3865(@value{GDBP}) watch foo
3866@end smallexample
c906108c 3867
d8b2a693 3868If the command includes a @code{@r{[}thread @var{threadnum}@r{]}}
9c06b0b4 3869argument, @value{GDBN} breaks only when the thread identified by
d8b2a693
JB
3870@var{threadnum} changes the value of @var{expr}. If any other threads
3871change the value of @var{expr}, @value{GDBN} will not break. Note
3872that watchpoints restricted to a single thread in this way only work
3873with Hardware Watchpoints.
3874
06a64a0b
TT
3875Ordinarily a watchpoint respects the scope of variables in @var{expr}
3876(see below). The @code{-location} argument tells @value{GDBN} to
3877instead watch the memory referred to by @var{expr}. In this case,
3878@value{GDBN} will evaluate @var{expr}, take the address of the result,
3879and watch the memory at that address. The type of the result is used
3880to determine the size of the watched memory. If the expression's
3881result does not have an address, then @value{GDBN} will print an
3882error.
3883
9c06b0b4
TJB
3884The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
3885of masked watchpoints, if the current architecture supports this
3886feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
3887Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
3888to an address to watch. The mask specifies that some bits of an address
3889(the bits which are reset in the mask) should be ignored when matching
3890the address accessed by the inferior against the watchpoint address.
3891Thus, a masked watchpoint watches many addresses simultaneously---those
3892addresses whose unmasked bits are identical to the unmasked bits in the
3893watchpoint address. The @code{mask} argument implies @code{-location}.
3894Examples:
3895
3896@smallexample
3897(@value{GDBP}) watch foo mask 0xffff00ff
3898(@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
3899@end smallexample
3900
c906108c 3901@kindex rwatch
9c06b0b4 3902@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
3903Set a watchpoint that will break when the value of @var{expr} is read
3904by the program.
c906108c
SS
3905
3906@kindex awatch
9c06b0b4 3907@item awatch @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 @var{expr} is either read from
3909or written into by the program.
c906108c 3910
e5a67952
MS
3911@kindex info watchpoints @r{[}@var{n}@dots{}@r{]}
3912@item info watchpoints @r{[}@var{n}@dots{}@r{]}
d77f58be
SS
3913This command prints a list of watchpoints, using the same format as
3914@code{info break} (@pxref{Set Breaks}).
c906108c
SS
3915@end table
3916
65d79d4b
SDJ
3917If you watch for a change in a numerically entered address you need to
3918dereference it, as the address itself is just a constant number which will
3919never change. @value{GDBN} refuses to create a watchpoint that watches
3920a never-changing value:
3921
3922@smallexample
3923(@value{GDBP}) watch 0x600850
3924Cannot watch constant value 0x600850.
3925(@value{GDBP}) watch *(int *) 0x600850
3926Watchpoint 1: *(int *) 6293584
3927@end smallexample
3928
c906108c
SS
3929@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
3930watchpoints execute very quickly, and the debugger reports a change in
3931value at the exact instruction where the change occurs. If @value{GDBN}
3932cannot set a hardware watchpoint, it sets a software watchpoint, which
3933executes more slowly and reports the change in value at the next
82f2d802
EZ
3934@emph{statement}, not the instruction, after the change occurs.
3935
82f2d802
EZ
3936@cindex use only software watchpoints
3937You can force @value{GDBN} to use only software watchpoints with the
3938@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
3939zero, @value{GDBN} will never try to use hardware watchpoints, even if
3940the underlying system supports them. (Note that hardware-assisted
3941watchpoints that were set @emph{before} setting
3942@code{can-use-hw-watchpoints} to zero will still use the hardware
d3e8051b 3943mechanism of watching expression values.)
c906108c 3944
9c16f35a
EZ
3945@table @code
3946@item set can-use-hw-watchpoints
3947@kindex set can-use-hw-watchpoints
3948Set whether or not to use hardware watchpoints.
3949
3950@item show can-use-hw-watchpoints
3951@kindex show can-use-hw-watchpoints
3952Show the current mode of using hardware watchpoints.
3953@end table
3954
3955For remote targets, you can restrict the number of hardware
3956watchpoints @value{GDBN} will use, see @ref{set remote
3957hardware-breakpoint-limit}.
3958
c906108c
SS
3959When you issue the @code{watch} command, @value{GDBN} reports
3960
474c8240 3961@smallexample
c906108c 3962Hardware watchpoint @var{num}: @var{expr}
474c8240 3963@end smallexample
c906108c
SS
3964
3965@noindent
3966if it was able to set a hardware watchpoint.
3967
7be570e7
JM
3968Currently, the @code{awatch} and @code{rwatch} commands can only set
3969hardware watchpoints, because accesses to data that don't change the
3970value of the watched expression cannot be detected without examining
3971every instruction as it is being executed, and @value{GDBN} does not do
3972that currently. If @value{GDBN} finds that it is unable to set a
3973hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3974will print a message like this:
3975
3976@smallexample
3977Expression cannot be implemented with read/access watchpoint.
3978@end smallexample
3979
3980Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
3981data type of the watched expression is wider than what a hardware
3982watchpoint on the target machine can handle. For example, some systems
3983can only watch regions that are up to 4 bytes wide; on such systems you
3984cannot set hardware watchpoints for an expression that yields a
3985double-precision floating-point number (which is typically 8 bytes
3986wide). As a work-around, it might be possible to break the large region
3987into a series of smaller ones and watch them with separate watchpoints.
3988
3989If you set too many hardware watchpoints, @value{GDBN} might be unable
3990to insert all of them when you resume the execution of your program.
3991Since the precise number of active watchpoints is unknown until such
3992time as the program is about to be resumed, @value{GDBN} might not be
3993able to warn you about this when you set the watchpoints, and the
3994warning will be printed only when the program is resumed:
3995
3996@smallexample
3997Hardware watchpoint @var{num}: Could not insert watchpoint
3998@end smallexample
3999
4000@noindent
4001If this happens, delete or disable some of the watchpoints.
4002
fd60e0df
EZ
4003Watching complex expressions that reference many variables can also
4004exhaust the resources available for hardware-assisted watchpoints.
4005That's because @value{GDBN} needs to watch every variable in the
4006expression with separately allocated resources.
4007
c906108c 4008If you call a function interactively using @code{print} or @code{call},
2df3850c 4009any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
4010kind of breakpoint or the call completes.
4011
7be570e7
JM
4012@value{GDBN} automatically deletes watchpoints that watch local
4013(automatic) variables, or expressions that involve such variables, when
4014they go out of scope, that is, when the execution leaves the block in
4015which these variables were defined. In particular, when the program
4016being debugged terminates, @emph{all} local variables go out of scope,
4017and so only watchpoints that watch global variables remain set. If you
4018rerun the program, you will need to set all such watchpoints again. One
4019way of doing that would be to set a code breakpoint at the entry to the
4020@code{main} function and when it breaks, set all the watchpoints.
4021
c906108c
SS
4022@cindex watchpoints and threads
4023@cindex threads and watchpoints
d983da9c
DJ
4024In multi-threaded programs, watchpoints will detect changes to the
4025watched expression from every thread.
4026
4027@quotation
4028@emph{Warning:} In multi-threaded programs, software watchpoints
53a5351d
JM
4029have only limited usefulness. If @value{GDBN} creates a software
4030watchpoint, it can only watch the value of an expression @emph{in a
4031single thread}. If you are confident that the expression can only
4032change due to the current thread's activity (and if you are also
4033confident that no other thread can become current), then you can use
4034software watchpoints as usual. However, @value{GDBN} may not notice
4035when a non-current thread's activity changes the expression. (Hardware
4036watchpoints, in contrast, watch an expression in all threads.)
c906108c 4037@end quotation
c906108c 4038
501eef12
AC
4039@xref{set remote hardware-watchpoint-limit}.
4040
6d2ebf8b 4041@node Set Catchpoints
79a6e687 4042@subsection Setting Catchpoints
d4f3574e 4043@cindex catchpoints, setting
c906108c
SS
4044@cindex exception handlers
4045@cindex event handling
4046
4047You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 4048kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
4049shared library. Use the @code{catch} command to set a catchpoint.
4050
4051@table @code
4052@kindex catch
4053@item catch @var{event}
4054Stop when @var{event} occurs. @var{event} can be any of the following:
4055@table @code
4056@item throw
4644b6e3 4057@cindex stop on C@t{++} exceptions
b37052ae 4058The throwing of a C@t{++} exception.
c906108c
SS
4059
4060@item catch
b37052ae 4061The catching of a C@t{++} exception.
c906108c 4062
8936fcda
JB
4063@item exception
4064@cindex Ada exception catching
4065@cindex catch Ada exceptions
4066An Ada exception being raised. If an exception name is specified
4067at the end of the command (eg @code{catch exception Program_Error}),
4068the debugger will stop only when this specific exception is raised.
4069Otherwise, the debugger stops execution when any Ada exception is raised.
4070
87f67dba
JB
4071When inserting an exception catchpoint on a user-defined exception whose
4072name is identical to one of the exceptions defined by the language, the
4073fully qualified name must be used as the exception name. Otherwise,
4074@value{GDBN} will assume that it should stop on the pre-defined exception
4075rather than the user-defined one. For instance, assuming an exception
4076called @code{Constraint_Error} is defined in package @code{Pck}, then
4077the command to use to catch such exceptions is @kbd{catch exception
4078Pck.Constraint_Error}.
4079
8936fcda
JB
4080@item exception unhandled
4081An exception that was raised but is not handled by the program.
4082
4083@item assert
4084A failed Ada assertion.
4085
c906108c 4086@item exec
4644b6e3 4087@cindex break on fork/exec
5ee187d7
DJ
4088A call to @code{exec}. This is currently only available for HP-UX
4089and @sc{gnu}/Linux.
c906108c 4090
a96d9b2e 4091@item syscall
ee8e71d4 4092@itemx syscall @r{[}@var{name} @r{|} @var{number}@r{]} @dots{}
a96d9b2e
SDJ
4093@cindex break on a system call.
4094A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
4095syscall is a mechanism for application programs to request a service
4096from the operating system (OS) or one of the OS system services.
4097@value{GDBN} can catch some or all of the syscalls issued by the
4098debuggee, and show the related information for each syscall. If no
4099argument is specified, calls to and returns from all system calls
4100will be caught.
4101
4102@var{name} can be any system call name that is valid for the
4103underlying OS. Just what syscalls are valid depends on the OS. On
4104GNU and Unix systems, you can find the full list of valid syscall
4105names on @file{/usr/include/asm/unistd.h}.
4106
4107@c For MS-Windows, the syscall names and the corresponding numbers
4108@c can be found, e.g., on this URL:
4109@c http://www.metasploit.com/users/opcode/syscalls.html
4110@c but we don't support Windows syscalls yet.
4111
4112Normally, @value{GDBN} knows in advance which syscalls are valid for
4113each OS, so you can use the @value{GDBN} command-line completion
4114facilities (@pxref{Completion,, command completion}) to list the
4115available choices.
4116
4117You may also specify the system call numerically. A syscall's
4118number is the value passed to the OS's syscall dispatcher to
4119identify the requested service. When you specify the syscall by its
4120name, @value{GDBN} uses its database of syscalls to convert the name
4121into the corresponding numeric code, but using the number directly
4122may be useful if @value{GDBN}'s database does not have the complete
4123list of syscalls on your system (e.g., because @value{GDBN} lags
4124behind the OS upgrades).
4125
4126The example below illustrates how this command works if you don't provide
4127arguments to it:
4128
4129@smallexample
4130(@value{GDBP}) catch syscall
4131Catchpoint 1 (syscall)
4132(@value{GDBP}) r
4133Starting program: /tmp/catch-syscall
4134
4135Catchpoint 1 (call to syscall 'close'), \
4136 0xffffe424 in __kernel_vsyscall ()
4137(@value{GDBP}) c
4138Continuing.
4139
4140Catchpoint 1 (returned from syscall 'close'), \
4141 0xffffe424 in __kernel_vsyscall ()
4142(@value{GDBP})
4143@end smallexample
4144
4145Here is an example of catching a system call by name:
4146
4147@smallexample
4148(@value{GDBP}) catch syscall chroot
4149Catchpoint 1 (syscall 'chroot' [61])
4150(@value{GDBP}) r
4151Starting program: /tmp/catch-syscall
4152
4153Catchpoint 1 (call to syscall 'chroot'), \
4154 0xffffe424 in __kernel_vsyscall ()
4155(@value{GDBP}) c
4156Continuing.
4157
4158Catchpoint 1 (returned from syscall 'chroot'), \
4159 0xffffe424 in __kernel_vsyscall ()
4160(@value{GDBP})
4161@end smallexample
4162
4163An example of specifying a system call numerically. In the case
4164below, the syscall number has a corresponding entry in the XML
4165file, so @value{GDBN} finds its name and prints it:
4166
4167@smallexample
4168(@value{GDBP}) catch syscall 252
4169Catchpoint 1 (syscall(s) 'exit_group')
4170(@value{GDBP}) r
4171Starting program: /tmp/catch-syscall
4172
4173Catchpoint 1 (call to syscall 'exit_group'), \
4174 0xffffe424 in __kernel_vsyscall ()
4175(@value{GDBP}) c
4176Continuing.
4177
4178Program exited normally.
4179(@value{GDBP})
4180@end smallexample
4181
4182However, there can be situations when there is no corresponding name
4183in XML file for that syscall number. In this case, @value{GDBN} prints
4184a warning message saying that it was not able to find the syscall name,
4185but the catchpoint will be set anyway. See the example below:
4186
4187@smallexample
4188(@value{GDBP}) catch syscall 764
4189warning: The number '764' does not represent a known syscall.
4190Catchpoint 2 (syscall 764)
4191(@value{GDBP})
4192@end smallexample
4193
4194If you configure @value{GDBN} using the @samp{--without-expat} option,
4195it will not be able to display syscall names. Also, if your
4196architecture does not have an XML file describing its system calls,
4197you will not be able to see the syscall names. It is important to
4198notice that these two features are used for accessing the syscall
4199name database. In either case, you will see a warning like this:
4200
4201@smallexample
4202(@value{GDBP}) catch syscall
4203warning: Could not open "syscalls/i386-linux.xml"
4204warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
4205GDB will not be able to display syscall names.
4206Catchpoint 1 (syscall)
4207(@value{GDBP})
4208@end smallexample
4209
4210Of course, the file name will change depending on your architecture and system.
4211
4212Still using the example above, you can also try to catch a syscall by its
4213number. In this case, you would see something like:
4214
4215@smallexample
4216(@value{GDBP}) catch syscall 252
4217Catchpoint 1 (syscall(s) 252)
4218@end smallexample
4219
4220Again, in this case @value{GDBN} would not be able to display syscall's names.
4221
c906108c 4222@item fork
5ee187d7
DJ
4223A call to @code{fork}. This is currently only available for HP-UX
4224and @sc{gnu}/Linux.
c906108c
SS
4225
4226@item vfork
5ee187d7
DJ
4227A call to @code{vfork}. This is currently only available for HP-UX
4228and @sc{gnu}/Linux.
c906108c 4229
edcc5120
TT
4230@item load @r{[}regexp@r{]}
4231@itemx unload @r{[}regexp@r{]}
4232The loading or unloading of a shared library. If @var{regexp} is
4233given, then the catchpoint will stop only if the regular expression
4234matches one of the affected libraries.
4235
ab04a2af
TT
4236@item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
4237The delivery of a signal.
4238
4239With no arguments, this catchpoint will catch any signal that is not
4240used internally by @value{GDBN}, specifically, all signals except
4241@samp{SIGTRAP} and @samp{SIGINT}.
4242
4243With the argument @samp{all}, all signals, including those used by
4244@value{GDBN}, will be caught. This argument cannot be used with other
4245signal names.
4246
4247Otherwise, the arguments are a list of signal names as given to
4248@code{handle} (@pxref{Signals}). Only signals specified in this list
4249will be caught.
4250
4251One reason that @code{catch signal} can be more useful than
4252@code{handle} is that you can attach commands and conditions to the
4253catchpoint.
4254
4255When a signal is caught by a catchpoint, the signal's @code{stop} and
4256@code{print} settings, as specified by @code{handle}, are ignored.
4257However, whether the signal is still delivered to the inferior depends
4258on the @code{pass} setting; this can be changed in the catchpoint's
4259commands.
4260
c906108c
SS
4261@end table
4262
4263@item tcatch @var{event}
4264Set a catchpoint that is enabled only for one stop. The catchpoint is
4265automatically deleted after the first time the event is caught.
4266
4267@end table
4268
4269Use the @code{info break} command to list the current catchpoints.
4270
b37052ae 4271There are currently some limitations to C@t{++} exception handling
c906108c
SS
4272(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
4273
4274@itemize @bullet
4275@item
4276If you call a function interactively, @value{GDBN} normally returns
4277control to you when the function has finished executing. If the call
4278raises an exception, however, the call may bypass the mechanism that
4279returns control to you and cause your program either to abort or to
4280simply continue running until it hits a breakpoint, catches a signal
4281that @value{GDBN} is listening for, or exits. This is the case even if
4282you set a catchpoint for the exception; catchpoints on exceptions are
4283disabled within interactive calls.
4284
4285@item
4286You cannot raise an exception interactively.
4287
4288@item
4289You cannot install an exception handler interactively.
4290@end itemize
4291
4292@cindex raise exceptions
4293Sometimes @code{catch} is not the best way to debug exception handling:
4294if you need to know exactly where an exception is raised, it is better to
4295stop @emph{before} the exception handler is called, since that way you
4296can see the stack before any unwinding takes place. If you set a
4297breakpoint in an exception handler instead, it may not be easy to find
4298out where the exception was raised.
4299
4300To stop just before an exception handler is called, you need some
b37052ae 4301knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
4302raised by calling a library function named @code{__raise_exception}
4303which has the following ANSI C interface:
4304
474c8240 4305@smallexample
c906108c 4306 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
4307 @var{id} is the exception identifier. */
4308 void __raise_exception (void **addr, void *id);
474c8240 4309@end smallexample
c906108c
SS
4310
4311@noindent
4312To make the debugger catch all exceptions before any stack
4313unwinding takes place, set a breakpoint on @code{__raise_exception}
79a6e687 4314(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Exceptions}).
c906108c 4315
79a6e687 4316With a conditional breakpoint (@pxref{Conditions, ,Break Conditions})
c906108c
SS
4317that depends on the value of @var{id}, you can stop your program when
4318a specific exception is raised. You can use multiple conditional
4319breakpoints to stop your program when any of a number of exceptions are
4320raised.
4321
4322
6d2ebf8b 4323@node Delete Breaks
79a6e687 4324@subsection Deleting Breakpoints
c906108c
SS
4325
4326@cindex clearing breakpoints, watchpoints, catchpoints
4327@cindex deleting breakpoints, watchpoints, catchpoints
4328It is often necessary to eliminate a breakpoint, watchpoint, or
4329catchpoint once it has done its job and you no longer want your program
4330to stop there. This is called @dfn{deleting} the breakpoint. A
4331breakpoint that has been deleted no longer exists; it is forgotten.
4332
4333With the @code{clear} command you can delete breakpoints according to
4334where they are in your program. With the @code{delete} command you can
4335delete individual breakpoints, watchpoints, or catchpoints by specifying
4336their breakpoint numbers.
4337
4338It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
4339automatically ignores breakpoints on the first instruction to be executed
4340when you continue execution without changing the execution address.
4341
4342@table @code
4343@kindex clear
4344@item clear
4345Delete any breakpoints at the next instruction to be executed in the
79a6e687 4346selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
c906108c
SS
4347the innermost frame is selected, this is a good way to delete a
4348breakpoint where your program just stopped.
4349
2a25a5ba
EZ
4350@item clear @var{location}
4351Delete any breakpoints set at the specified @var{location}.
4352@xref{Specify Location}, for the various forms of @var{location}; the
4353most useful ones are listed below:
4354
4355@table @code
c906108c
SS
4356@item clear @var{function}
4357@itemx clear @var{filename}:@var{function}
09d4efe1 4358Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
4359
4360@item clear @var{linenum}
4361@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
4362Delete any breakpoints set at or within the code of the specified
4363@var{linenum} of the specified @var{filename}.
2a25a5ba 4364@end table
c906108c
SS
4365
4366@cindex delete breakpoints
4367@kindex delete
41afff9a 4368@kindex d @r{(@code{delete})}
c5394b80
JM
4369@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4370Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
4371ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
4372breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
4373confirm off}). You can abbreviate this command as @code{d}.
4374@end table
4375
6d2ebf8b 4376@node Disabling
79a6e687 4377@subsection Disabling Breakpoints
c906108c 4378
4644b6e3 4379@cindex enable/disable a breakpoint
c906108c
SS
4380Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
4381prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
4382it had been deleted, but remembers the information on the breakpoint so
4383that you can @dfn{enable} it again later.
4384
4385You disable and enable breakpoints, watchpoints, and catchpoints with
d77f58be
SS
4386the @code{enable} and @code{disable} commands, optionally specifying
4387one or more breakpoint numbers as arguments. Use @code{info break} to
4388print a list of all breakpoints, watchpoints, and catchpoints if you
4389do not know which numbers to use.
c906108c 4390
3b784c4f
EZ
4391Disabling and enabling a breakpoint that has multiple locations
4392affects all of its locations.
4393
816338b5
SS
4394A breakpoint, watchpoint, or catchpoint can have any of several
4395different states of enablement:
c906108c
SS
4396
4397@itemize @bullet
4398@item
4399Enabled. The breakpoint stops your program. A breakpoint set
4400with the @code{break} command starts out in this state.
4401@item
4402Disabled. The breakpoint has no effect on your program.
4403@item
4404Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 4405disabled.
c906108c 4406@item
816338b5
SS
4407Enabled for a count. The breakpoint stops your program for the next
4408N times, then becomes disabled.
4409@item
c906108c 4410Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
4411immediately after it does so it is deleted permanently. A breakpoint
4412set with the @code{tbreak} command starts out in this state.
c906108c
SS
4413@end itemize
4414
4415You can use the following commands to enable or disable breakpoints,
4416watchpoints, and catchpoints:
4417
4418@table @code
c906108c 4419@kindex disable
41afff9a 4420@kindex dis @r{(@code{disable})}
c5394b80 4421@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4422Disable the specified breakpoints---or all breakpoints, if none are
4423listed. A disabled breakpoint has no effect but is not forgotten. All
4424options such as ignore-counts, conditions and commands are remembered in
4425case the breakpoint is enabled again later. You may abbreviate
4426@code{disable} as @code{dis}.
4427
c906108c 4428@kindex enable
c5394b80 4429@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4430Enable the specified breakpoints (or all defined breakpoints). They
4431become effective once again in stopping your program.
4432
c5394b80 4433@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
4434Enable the specified breakpoints temporarily. @value{GDBN} disables any
4435of these breakpoints immediately after stopping your program.
4436
816338b5
SS
4437@item enable @r{[}breakpoints@r{]} count @var{count} @var{range}@dots{}
4438Enable the specified breakpoints temporarily. @value{GDBN} records
4439@var{count} with each of the specified breakpoints, and decrements a
4440breakpoint's count when it is hit. When any count reaches 0,
4441@value{GDBN} disables that breakpoint. If a breakpoint has an ignore
4442count (@pxref{Conditions, ,Break Conditions}), that will be
4443decremented to 0 before @var{count} is affected.
4444
c5394b80 4445@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
4446Enable the specified breakpoints to work once, then die. @value{GDBN}
4447deletes any of these breakpoints as soon as your program stops there.
09d4efe1 4448Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
4449@end table
4450
d4f3574e
SS
4451@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
4452@c confusing: tbreak is also initially enabled.
c906108c 4453Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
79a6e687 4454,Setting Breakpoints}), breakpoints that you set are initially enabled;
c906108c
SS
4455subsequently, they become disabled or enabled only when you use one of
4456the commands above. (The command @code{until} can set and delete a
4457breakpoint of its own, but it does not change the state of your other
4458breakpoints; see @ref{Continuing and Stepping, ,Continuing and
79a6e687 4459Stepping}.)
c906108c 4460
6d2ebf8b 4461@node Conditions
79a6e687 4462@subsection Break Conditions
c906108c
SS
4463@cindex conditional breakpoints
4464@cindex breakpoint conditions
4465
4466@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 4467@c in particular for a watchpoint?
c906108c
SS
4468The simplest sort of breakpoint breaks every time your program reaches a
4469specified place. You can also specify a @dfn{condition} for a
4470breakpoint. A condition is just a Boolean expression in your
4471programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
4472a condition evaluates the expression each time your program reaches it,
4473and your program stops only if the condition is @emph{true}.
4474
4475This is the converse of using assertions for program validation; in that
4476situation, you want to stop when the assertion is violated---that is,
4477when the condition is false. In C, if you want to test an assertion expressed
4478by the condition @var{assert}, you should set the condition
4479@samp{! @var{assert}} on the appropriate breakpoint.
4480
4481Conditions are also accepted for watchpoints; you may not need them,
4482since a watchpoint is inspecting the value of an expression anyhow---but
4483it might be simpler, say, to just set a watchpoint on a variable name,
4484and specify a condition that tests whether the new value is an interesting
4485one.
4486
4487Break conditions can have side effects, and may even call functions in
4488your program. This can be useful, for example, to activate functions
4489that log program progress, or to use your own print functions to
99e008fe 4490format special data structures. The effects are completely predictable
c906108c
SS
4491unless there is another enabled breakpoint at the same address. (In
4492that case, @value{GDBN} might see the other breakpoint first and stop your
4493program without checking the condition of this one.) Note that
d4f3574e
SS
4494breakpoint commands are usually more convenient and flexible than break
4495conditions for the
c906108c 4496purpose of performing side effects when a breakpoint is reached
79a6e687 4497(@pxref{Break Commands, ,Breakpoint Command Lists}).
c906108c 4498
83364271
LM
4499Breakpoint conditions can also be evaluated on the target's side if
4500the target supports it. Instead of evaluating the conditions locally,
4501@value{GDBN} encodes the expression into an agent expression
4502(@pxref{Agent Expressions}) suitable for execution on the target,
4503independently of @value{GDBN}. Global variables become raw memory
4504locations, locals become stack accesses, and so forth.
4505
4506In this case, @value{GDBN} will only be notified of a breakpoint trigger
4507when its condition evaluates to true. This mechanism may provide faster
4508response times depending on the performance characteristics of the target
4509since it does not need to keep @value{GDBN} informed about
4510every breakpoint trigger, even those with false conditions.
4511
c906108c
SS
4512Break conditions can be specified when a breakpoint is set, by using
4513@samp{if} in the arguments to the @code{break} command. @xref{Set
79a6e687 4514Breaks, ,Setting Breakpoints}. They can also be changed at any time
c906108c 4515with the @code{condition} command.
53a5351d 4516
c906108c
SS
4517You can also use the @code{if} keyword with the @code{watch} command.
4518The @code{catch} command does not recognize the @code{if} keyword;
4519@code{condition} is the only way to impose a further condition on a
4520catchpoint.
c906108c
SS
4521
4522@table @code
4523@kindex condition
4524@item condition @var{bnum} @var{expression}
4525Specify @var{expression} as the break condition for breakpoint,
4526watchpoint, or catchpoint number @var{bnum}. After you set a condition,
4527breakpoint @var{bnum} stops your program only if the value of
4528@var{expression} is true (nonzero, in C). When you use
4529@code{condition}, @value{GDBN} checks @var{expression} immediately for
4530syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
4531referents in the context of your breakpoint. If @var{expression} uses
4532symbols not referenced in the context of the breakpoint, @value{GDBN}
4533prints an error message:
4534
474c8240 4535@smallexample
d4f3574e 4536No symbol "foo" in current context.
474c8240 4537@end smallexample
d4f3574e
SS
4538
4539@noindent
c906108c
SS
4540@value{GDBN} does
4541not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
4542command (or a command that sets a breakpoint with a condition, like
4543@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
4544
4545@item condition @var{bnum}
4546Remove the condition from breakpoint number @var{bnum}. It becomes
4547an ordinary unconditional breakpoint.
4548@end table
4549
4550@cindex ignore count (of breakpoint)
4551A special case of a breakpoint condition is to stop only when the
4552breakpoint has been reached a certain number of times. This is so
4553useful that there is a special way to do it, using the @dfn{ignore
4554count} of the breakpoint. Every breakpoint has an ignore count, which
4555is an integer. Most of the time, the ignore count is zero, and
4556therefore has no effect. But if your program reaches a breakpoint whose
4557ignore count is positive, then instead of stopping, it just decrements
4558the ignore count by one and continues. As a result, if the ignore count
4559value is @var{n}, the breakpoint does not stop the next @var{n} times
4560your program reaches it.
4561
4562@table @code
4563@kindex ignore
4564@item ignore @var{bnum} @var{count}
4565Set the ignore count of breakpoint number @var{bnum} to @var{count}.
4566The next @var{count} times the breakpoint is reached, your program's
4567execution does not stop; other than to decrement the ignore count, @value{GDBN}
4568takes no action.
4569
4570To make the breakpoint stop the next time it is reached, specify
4571a count of zero.
4572
4573When you use @code{continue} to resume execution of your program from a
4574breakpoint, you can specify an ignore count directly as an argument to
4575@code{continue}, rather than using @code{ignore}. @xref{Continuing and
79a6e687 4576Stepping,,Continuing and Stepping}.
c906108c
SS
4577
4578If a breakpoint has a positive ignore count and a condition, the
4579condition is not checked. Once the ignore count reaches zero,
4580@value{GDBN} resumes checking the condition.
4581
4582You could achieve the effect of the ignore count with a condition such
4583as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
4584is decremented each time. @xref{Convenience Vars, ,Convenience
79a6e687 4585Variables}.
c906108c
SS
4586@end table
4587
4588Ignore counts apply to breakpoints, watchpoints, and catchpoints.
4589
4590
6d2ebf8b 4591@node Break Commands
79a6e687 4592@subsection Breakpoint Command Lists
c906108c
SS
4593
4594@cindex breakpoint commands
4595You can give any breakpoint (or watchpoint or catchpoint) a series of
4596commands to execute when your program stops due to that breakpoint. For
4597example, you might want to print the values of certain expressions, or
4598enable other breakpoints.
4599
4600@table @code
4601@kindex commands
ca91424e 4602@kindex end@r{ (breakpoint commands)}
95a42b64 4603@item commands @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4604@itemx @dots{} @var{command-list} @dots{}
4605@itemx end
95a42b64 4606Specify a list of commands for the given breakpoints. The commands
c906108c
SS
4607themselves appear on the following lines. Type a line containing just
4608@code{end} to terminate the commands.
4609
4610To remove all commands from a breakpoint, type @code{commands} and
4611follow it immediately with @code{end}; that is, give no commands.
4612
95a42b64
TT
4613With no argument, @code{commands} refers to the last breakpoint,
4614watchpoint, or catchpoint set (not to the breakpoint most recently
4615encountered). If the most recent breakpoints were set with a single
4616command, then the @code{commands} will apply to all the breakpoints
4617set by that command. This applies to breakpoints set by
86b17b60
PA
4618@code{rbreak}, and also applies when a single @code{break} command
4619creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
4620Expressions}).
c906108c
SS
4621@end table
4622
4623Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
4624disabled within a @var{command-list}.
4625
4626You can use breakpoint commands to start your program up again. Simply
4627use the @code{continue} command, or @code{step}, or any other command
4628that resumes execution.
4629
4630Any other commands in the command list, after a command that resumes
4631execution, are ignored. This is because any time you resume execution
4632(even with a simple @code{next} or @code{step}), you may encounter
4633another breakpoint---which could have its own command list, leading to
4634ambiguities about which list to execute.
4635
4636@kindex silent
4637If the first command you specify in a command list is @code{silent}, the
4638usual message about stopping at a breakpoint is not printed. This may
4639be desirable for breakpoints that are to print a specific message and
4640then continue. If none of the remaining commands print anything, you
4641see no sign that the breakpoint was reached. @code{silent} is
4642meaningful only at the beginning of a breakpoint command list.
4643
4644The commands @code{echo}, @code{output}, and @code{printf} allow you to
4645print precisely controlled output, and are often useful in silent
79a6e687 4646breakpoints. @xref{Output, ,Commands for Controlled Output}.
c906108c
SS
4647
4648For example, here is how you could use breakpoint commands to print the
4649value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
4650
474c8240 4651@smallexample
c906108c
SS
4652break foo if x>0
4653commands
4654silent
4655printf "x is %d\n",x
4656cont
4657end
474c8240 4658@end smallexample
c906108c
SS
4659
4660One application for breakpoint commands is to compensate for one bug so
4661you can test for another. Put a breakpoint just after the erroneous line
4662of code, give it a condition to detect the case in which something
4663erroneous has been done, and give it commands to assign correct values
4664to any variables that need them. End with the @code{continue} command
4665so that your program does not stop, and start with the @code{silent}
4666command so that no output is produced. Here is an example:
4667
474c8240 4668@smallexample
c906108c
SS
4669break 403
4670commands
4671silent
4672set x = y + 4
4673cont
4674end
474c8240 4675@end smallexample
c906108c 4676
e7e0cddf
SS
4677@node Dynamic Printf
4678@subsection Dynamic Printf
4679
4680@cindex dynamic printf
4681@cindex dprintf
4682The dynamic printf command @code{dprintf} combines a breakpoint with
4683formatted printing of your program's data to give you the effect of
4684inserting @code{printf} calls into your program on-the-fly, without
4685having to recompile it.
4686
4687In its most basic form, the output goes to the GDB console. However,
4688you can set the variable @code{dprintf-style} for alternate handling.
4689For instance, you can ask to format the output by calling your
4690program's @code{printf} function. This has the advantage that the
4691characters go to the program's output device, so they can recorded in
4692redirects to files and so forth.
4693
d3ce09f5
SS
4694If you are doing remote debugging with a stub or agent, you can also
4695ask to have the printf handled by the remote agent. In addition to
4696ensuring that the output goes to the remote program's device along
4697with any other output the program might produce, you can also ask that
4698the dprintf remain active even after disconnecting from the remote
4699target. Using the stub/agent is also more efficient, as it can do
4700everything without needing to communicate with @value{GDBN}.
4701
e7e0cddf
SS
4702@table @code
4703@kindex dprintf
4704@item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
4705Whenever execution reaches @var{location}, print the values of one or
4706more @var{expressions} under the control of the string @var{template}.
4707To print several values, separate them with commas.
4708
4709@item set dprintf-style @var{style}
4710Set the dprintf output to be handled in one of several different
4711styles enumerated below. A change of style affects all existing
4712dynamic printfs immediately. (If you need individual control over the
4713print commands, simply define normal breakpoints with
4714explicitly-supplied command lists.)
4715
4716@item gdb
4717@kindex dprintf-style gdb
4718Handle the output using the @value{GDBN} @code{printf} command.
4719
4720@item call
4721@kindex dprintf-style call
4722Handle the output by calling a function in your program (normally
4723@code{printf}).
4724
d3ce09f5
SS
4725@item agent
4726@kindex dprintf-style agent
4727Have the remote debugging agent (such as @code{gdbserver}) handle
4728the output itself. This style is only available for agents that
4729support running commands on the target.
4730
e7e0cddf
SS
4731@item set dprintf-function @var{function}
4732Set the function to call if the dprintf style is @code{call}. By
4733default its value is @code{printf}. You may set it to any expression.
4734that @value{GDBN} can evaluate to a function, as per the @code{call}
4735command.
4736
4737@item set dprintf-channel @var{channel}
4738Set a ``channel'' for dprintf. If set to a non-empty value,
4739@value{GDBN} will evaluate it as an expression and pass the result as
4740a first argument to the @code{dprintf-function}, in the manner of
4741@code{fprintf} and similar functions. Otherwise, the dprintf format
4742string will be the first argument, in the manner of @code{printf}.
4743
4744As an example, if you wanted @code{dprintf} output to go to a logfile
4745that is a standard I/O stream assigned to the variable @code{mylog},
4746you could do the following:
4747
4748@example
4749(gdb) set dprintf-style call
4750(gdb) set dprintf-function fprintf
4751(gdb) set dprintf-channel mylog
4752(gdb) dprintf 25,"at line 25, glob=%d\n",glob
4753Dprintf 1 at 0x123456: file main.c, line 25.
4754(gdb) info break
47551 dprintf keep y 0x00123456 in main at main.c:25
4756 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
4757 continue
4758(gdb)
4759@end example
4760
4761Note that the @code{info break} displays the dynamic printf commands
4762as normal breakpoint commands; you can thus easily see the effect of
4763the variable settings.
4764
d3ce09f5
SS
4765@item set disconnected-dprintf on
4766@itemx set disconnected-dprintf off
4767@kindex set disconnected-dprintf
4768Choose whether @code{dprintf} commands should continue to run if
4769@value{GDBN} has disconnected from the target. This only applies
4770if the @code{dprintf-style} is @code{agent}.
4771
4772@item show disconnected-dprintf off
4773@kindex show disconnected-dprintf
4774Show the current choice for disconnected @code{dprintf}.
4775
e7e0cddf
SS
4776@end table
4777
4778@value{GDBN} does not check the validity of function and channel,
4779relying on you to supply values that are meaningful for the contexts
4780in which they are being used. For instance, the function and channel
4781may be the values of local variables, but if that is the case, then
4782all enabled dynamic prints must be at locations within the scope of
4783those locals. If evaluation fails, @value{GDBN} will report an error.
4784
6149aea9
PA
4785@node Save Breakpoints
4786@subsection How to save breakpoints to a file
4787
4788To save breakpoint definitions to a file use the @w{@code{save
4789breakpoints}} command.
4790
4791@table @code
4792@kindex save breakpoints
4793@cindex save breakpoints to a file for future sessions
4794@item save breakpoints [@var{filename}]
4795This command saves all current breakpoint definitions together with
4796their commands and ignore counts, into a file @file{@var{filename}}
4797suitable for use in a later debugging session. This includes all
4798types of breakpoints (breakpoints, watchpoints, catchpoints,
4799tracepoints). To read the saved breakpoint definitions, use the
4800@code{source} command (@pxref{Command Files}). Note that watchpoints
4801with expressions involving local variables may fail to be recreated
4802because it may not be possible to access the context where the
4803watchpoint is valid anymore. Because the saved breakpoint definitions
4804are simply a sequence of @value{GDBN} commands that recreate the
4805breakpoints, you can edit the file in your favorite editing program,
4806and remove the breakpoint definitions you're not interested in, or
4807that can no longer be recreated.
4808@end table
4809
62e5f89c
SDJ
4810@node Static Probe Points
4811@subsection Static Probe Points
4812
4813@cindex static probe point, SystemTap
4814@value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
4815for Statically Defined Tracing, and the probes are designed to have a tiny
4816runtime code and data footprint, and no dynamic relocations. They are
4817usable from assembly, C and C@t{++} languages. See
4818@uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
4819for a good reference on how the @acronym{SDT} probes are implemented.
4820
4821Currently, @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
4822@acronym{SDT} probes are supported on ELF-compatible systems. See
4823@uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
4824for more information on how to add @code{SystemTap} @acronym{SDT} probes
4825in your applications.
4826
4827@cindex semaphores on static probe points
4828Some probes have an associated semaphore variable; for instance, this
4829happens automatically if you defined your probe using a DTrace-style
4830@file{.d} file. If your probe has a semaphore, @value{GDBN} will
4831automatically enable it when you specify a breakpoint using the
4832@samp{-probe-stap} notation. But, if you put a breakpoint at a probe's
4833location by some other method (e.g., @code{break file:line}), then
4834@value{GDBN} will not automatically set the semaphore.
4835
4836You can examine the available static static probes using @code{info
4837probes}, with optional arguments:
4838
4839@table @code
4840@kindex info probes
4841@item info probes stap @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
4842If given, @var{provider} is a regular expression used to match against provider
4843names when selecting which probes to list. If omitted, probes by all
4844probes from all providers are listed.
4845
4846If given, @var{name} is a regular expression to match against probe names
4847when selecting which probes to list. If omitted, probe names are not
4848considered when deciding whether to display them.
4849
4850If given, @var{objfile} is a regular expression used to select which
4851object files (executable or shared libraries) to examine. If not
4852given, all object files are considered.
4853
4854@item info probes all
4855List the available static probes, from all types.
4856@end table
4857
4858@vindex $_probe_arg@r{, convenience variable}
4859A probe may specify up to twelve arguments. These are available at the
4860point at which the probe is defined---that is, when the current PC is
4861at the probe's location. The arguments are available using the
4862convenience variables (@pxref{Convenience Vars})
4863@code{$_probe_arg0}@dots{}@code{$_probe_arg11}. Each probe argument is
4864an integer of the appropriate size; types are not preserved. The
4865convenience variable @code{$_probe_argc} holds the number of arguments
4866at the current probe point.
4867
4868These variables are always available, but attempts to access them at
4869any location other than a probe point will cause @value{GDBN} to give
4870an error message.
4871
4872
c906108c 4873@c @ifclear BARETARGET
6d2ebf8b 4874@node Error in Breakpoints
d4f3574e 4875@subsection ``Cannot insert breakpoints''
c906108c 4876
fa3a767f
PA
4877If you request too many active hardware-assisted breakpoints and
4878watchpoints, you will see this error message:
d4f3574e
SS
4879
4880@c FIXME: the precise wording of this message may change; the relevant
4881@c source change is not committed yet (Sep 3, 1999).
4882@smallexample
4883Stopped; cannot insert breakpoints.
4884You may have requested too many hardware breakpoints and watchpoints.
4885@end smallexample
4886
4887@noindent
4888This message is printed when you attempt to resume the program, since
4889only then @value{GDBN} knows exactly how many hardware breakpoints and
4890watchpoints it needs to insert.
4891
4892When this message is printed, you need to disable or remove some of the
4893hardware-assisted breakpoints and watchpoints, and then continue.
4894
79a6e687 4895@node Breakpoint-related Warnings
1485d690
KB
4896@subsection ``Breakpoint address adjusted...''
4897@cindex breakpoint address adjusted
4898
4899Some processor architectures place constraints on the addresses at
4900which breakpoints may be placed. For architectures thus constrained,
4901@value{GDBN} will attempt to adjust the breakpoint's address to comply
4902with the constraints dictated by the architecture.
4903
4904One example of such an architecture is the Fujitsu FR-V. The FR-V is
4905a VLIW architecture in which a number of RISC-like instructions may be
4906bundled together for parallel execution. The FR-V architecture
4907constrains the location of a breakpoint instruction within such a
4908bundle to the instruction with the lowest address. @value{GDBN}
4909honors this constraint by adjusting a breakpoint's address to the
4910first in the bundle.
4911
4912It is not uncommon for optimized code to have bundles which contain
4913instructions from different source statements, thus it may happen that
4914a breakpoint's address will be adjusted from one source statement to
4915another. Since this adjustment may significantly alter @value{GDBN}'s
4916breakpoint related behavior from what the user expects, a warning is
4917printed when the breakpoint is first set and also when the breakpoint
4918is hit.
4919
4920A warning like the one below is printed when setting a breakpoint
4921that's been subject to address adjustment:
4922
4923@smallexample
4924warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
4925@end smallexample
4926
4927Such warnings are printed both for user settable and @value{GDBN}'s
4928internal breakpoints. If you see one of these warnings, you should
4929verify that a breakpoint set at the adjusted address will have the
4930desired affect. If not, the breakpoint in question may be removed and
b383017d 4931other breakpoints may be set which will have the desired behavior.
1485d690
KB
4932E.g., it may be sufficient to place the breakpoint at a later
4933instruction. A conditional breakpoint may also be useful in some
4934cases to prevent the breakpoint from triggering too often.
4935
4936@value{GDBN} will also issue a warning when stopping at one of these
4937adjusted breakpoints:
4938
4939@smallexample
4940warning: Breakpoint 1 address previously adjusted from 0x00010414
4941to 0x00010410.
4942@end smallexample
4943
4944When this warning is encountered, it may be too late to take remedial
4945action except in cases where the breakpoint is hit earlier or more
4946frequently than expected.
d4f3574e 4947
6d2ebf8b 4948@node Continuing and Stepping
79a6e687 4949@section Continuing and Stepping
c906108c
SS
4950
4951@cindex stepping
4952@cindex continuing
4953@cindex resuming execution
4954@dfn{Continuing} means resuming program execution until your program
4955completes normally. In contrast, @dfn{stepping} means executing just
4956one more ``step'' of your program, where ``step'' may mean either one
4957line of source code, or one machine instruction (depending on what
7a292a7a
SS
4958particular command you use). Either when continuing or when stepping,
4959your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
4960it stops due to a signal, you may want to use @code{handle}, or use
4961@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
4962
4963@table @code
4964@kindex continue
41afff9a
EZ
4965@kindex c @r{(@code{continue})}
4966@kindex fg @r{(resume foreground execution)}
c906108c
SS
4967@item continue @r{[}@var{ignore-count}@r{]}
4968@itemx c @r{[}@var{ignore-count}@r{]}
4969@itemx fg @r{[}@var{ignore-count}@r{]}
4970Resume program execution, at the address where your program last stopped;
4971any breakpoints set at that address are bypassed. The optional argument
4972@var{ignore-count} allows you to specify a further number of times to
4973ignore a breakpoint at this location; its effect is like that of
79a6e687 4974@code{ignore} (@pxref{Conditions, ,Break Conditions}).
c906108c
SS
4975
4976The argument @var{ignore-count} is meaningful only when your program
4977stopped due to a breakpoint. At other times, the argument to
4978@code{continue} is ignored.
4979
d4f3574e
SS
4980The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
4981debugged program is deemed to be the foreground program) are provided
4982purely for convenience, and have exactly the same behavior as
4983@code{continue}.
c906108c
SS
4984@end table
4985
4986To resume execution at a different place, you can use @code{return}
79a6e687 4987(@pxref{Returning, ,Returning from a Function}) to go back to the
c906108c 4988calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
79a6e687 4989Different Address}) to go to an arbitrary location in your program.
c906108c
SS
4990
4991A typical technique for using stepping is to set a breakpoint
79a6e687 4992(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
c906108c
SS
4993beginning of the function or the section of your program where a problem
4994is believed to lie, run your program until it stops at that breakpoint,
4995and then step through the suspect area, examining the variables that are
4996interesting, until you see the problem happen.
4997
4998@table @code
4999@kindex step
41afff9a 5000@kindex s @r{(@code{step})}
c906108c
SS
5001@item step
5002Continue running your program until control reaches a different source
5003line, then stop it and return control to @value{GDBN}. This command is
5004abbreviated @code{s}.
5005
5006@quotation
5007@c "without debugging information" is imprecise; actually "without line
5008@c numbers in the debugging information". (gcc -g1 has debugging info but
5009@c not line numbers). But it seems complex to try to make that
5010@c distinction here.
5011@emph{Warning:} If you use the @code{step} command while control is
5012within a function that was compiled without debugging information,
5013execution proceeds until control reaches a function that does have
5014debugging information. Likewise, it will not step into a function which
5015is compiled without debugging information. To step through functions
5016without debugging information, use the @code{stepi} command, described
5017below.
5018@end quotation
5019
4a92d011
EZ
5020The @code{step} command only stops at the first instruction of a source
5021line. This prevents the multiple stops that could otherwise occur in
5022@code{switch} statements, @code{for} loops, etc. @code{step} continues
5023to stop if a function that has debugging information is called within
5024the line. In other words, @code{step} @emph{steps inside} any functions
5025called within the line.
c906108c 5026
d4f3574e
SS
5027Also, the @code{step} command only enters a function if there is line
5028number information for the function. Otherwise it acts like the
5d161b24 5029@code{next} command. This avoids problems when using @code{cc -gl}
eb17f351 5030on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5d161b24 5031was any debugging information about the routine.
c906108c
SS
5032
5033@item step @var{count}
5034Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
5035breakpoint is reached, or a signal not related to stepping occurs before
5036@var{count} steps, stepping stops right away.
c906108c
SS
5037
5038@kindex next
41afff9a 5039@kindex n @r{(@code{next})}
c906108c
SS
5040@item next @r{[}@var{count}@r{]}
5041Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
5042This is similar to @code{step}, but function calls that appear within
5043the line of code are executed without stopping. Execution stops when
5044control reaches a different line of code at the original stack level
5045that was executing when you gave the @code{next} command. This command
5046is abbreviated @code{n}.
c906108c
SS
5047
5048An argument @var{count} is a repeat count, as for @code{step}.
5049
5050
5051@c FIX ME!! Do we delete this, or is there a way it fits in with
5052@c the following paragraph? --- Vctoria
5053@c
5054@c @code{next} within a function that lacks debugging information acts like
5055@c @code{step}, but any function calls appearing within the code of the
5056@c function are executed without stopping.
5057
d4f3574e
SS
5058The @code{next} command only stops at the first instruction of a
5059source line. This prevents multiple stops that could otherwise occur in
4a92d011 5060@code{switch} statements, @code{for} loops, etc.
c906108c 5061
b90a5f51
CF
5062@kindex set step-mode
5063@item set step-mode
5064@cindex functions without line info, and stepping
5065@cindex stepping into functions with no line info
5066@itemx set step-mode on
4a92d011 5067The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
5068stop at the first instruction of a function which contains no debug line
5069information rather than stepping over it.
5070
4a92d011
EZ
5071This is useful in cases where you may be interested in inspecting the
5072machine instructions of a function which has no symbolic info and do not
5073want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
5074
5075@item set step-mode off
4a92d011 5076Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
5077debug information. This is the default.
5078
9c16f35a
EZ
5079@item show step-mode
5080Show whether @value{GDBN} will stop in or step over functions without
5081source line debug information.
5082
c906108c 5083@kindex finish
8dfa32fc 5084@kindex fin @r{(@code{finish})}
c906108c
SS
5085@item finish
5086Continue running until just after function in the selected stack frame
8dfa32fc
JB
5087returns. Print the returned value (if any). This command can be
5088abbreviated as @code{fin}.
c906108c
SS
5089
5090Contrast this with the @code{return} command (@pxref{Returning,
79a6e687 5091,Returning from a Function}).
c906108c
SS
5092
5093@kindex until
41afff9a 5094@kindex u @r{(@code{until})}
09d4efe1 5095@cindex run until specified location
c906108c
SS
5096@item until
5097@itemx u
5098Continue running until a source line past the current line, in the
5099current stack frame, is reached. This command is used to avoid single
5100stepping through a loop more than once. It is like the @code{next}
5101command, except that when @code{until} encounters a jump, it
5102automatically continues execution until the program counter is greater
5103than the address of the jump.
5104
5105This means that when you reach the end of a loop after single stepping
5106though it, @code{until} makes your program continue execution until it
5107exits the loop. In contrast, a @code{next} command at the end of a loop
5108simply steps back to the beginning of the loop, which forces you to step
5109through the next iteration.
5110
5111@code{until} always stops your program if it attempts to exit the current
5112stack frame.
5113
5114@code{until} may produce somewhat counterintuitive results if the order
5115of machine code does not match the order of the source lines. For
5116example, in the following excerpt from a debugging session, the @code{f}
5117(@code{frame}) command shows that execution is stopped at line
5118@code{206}; yet when we use @code{until}, we get to line @code{195}:
5119
474c8240 5120@smallexample
c906108c
SS
5121(@value{GDBP}) f
5122#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
5123206 expand_input();
5124(@value{GDBP}) until
5125195 for ( ; argc > 0; NEXTARG) @{
474c8240 5126@end smallexample
c906108c
SS
5127
5128This happened because, for execution efficiency, the compiler had
5129generated code for the loop closure test at the end, rather than the
5130start, of the loop---even though the test in a C @code{for}-loop is
5131written before the body of the loop. The @code{until} command appeared
5132to step back to the beginning of the loop when it advanced to this
5133expression; however, it has not really gone to an earlier
5134statement---not in terms of the actual machine code.
5135
5136@code{until} with no argument works by means of single
5137instruction stepping, and hence is slower than @code{until} with an
5138argument.
5139
5140@item until @var{location}
5141@itemx u @var{location}
5142Continue running your program until either the specified location is
5143reached, or the current stack frame returns. @var{location} is any of
2a25a5ba
EZ
5144the forms described in @ref{Specify Location}.
5145This form of the command uses temporary breakpoints, and
c60eb6f1
EZ
5146hence is quicker than @code{until} without an argument. The specified
5147location is actually reached only if it is in the current frame. This
5148implies that @code{until} can be used to skip over recursive function
5149invocations. For instance in the code below, if the current location is
5150line @code{96}, issuing @code{until 99} will execute the program up to
db2e3e2e 5151line @code{99} in the same invocation of factorial, i.e., after the inner
c60eb6f1
EZ
5152invocations have returned.
5153
5154@smallexample
515594 int factorial (int value)
515695 @{
515796 if (value > 1) @{
515897 value *= factorial (value - 1);
515998 @}
516099 return (value);
5161100 @}
5162@end smallexample
5163
5164
5165@kindex advance @var{location}
984359d2 5166@item advance @var{location}
09d4efe1 5167Continue running the program up to the given @var{location}. An argument is
2a25a5ba
EZ
5168required, which should be of one of the forms described in
5169@ref{Specify Location}.
5170Execution will also stop upon exit from the current stack
c60eb6f1
EZ
5171frame. This command is similar to @code{until}, but @code{advance} will
5172not skip over recursive function calls, and the target location doesn't
5173have to be in the same frame as the current one.
5174
c906108c
SS
5175
5176@kindex stepi
41afff9a 5177@kindex si @r{(@code{stepi})}
c906108c 5178@item stepi
96a2c332 5179@itemx stepi @var{arg}
c906108c
SS
5180@itemx si
5181Execute one machine instruction, then stop and return to the debugger.
5182
5183It is often useful to do @samp{display/i $pc} when stepping by machine
5184instructions. This makes @value{GDBN} automatically display the next
5185instruction to be executed, each time your program stops. @xref{Auto
79a6e687 5186Display,, Automatic Display}.
c906108c
SS
5187
5188An argument is a repeat count, as in @code{step}.
5189
5190@need 750
5191@kindex nexti
41afff9a 5192@kindex ni @r{(@code{nexti})}
c906108c 5193@item nexti
96a2c332 5194@itemx nexti @var{arg}
c906108c
SS
5195@itemx ni
5196Execute one machine instruction, but if it is a function call,
5197proceed until the function returns.
5198
5199An argument is a repeat count, as in @code{next}.
5200@end table
5201
aad1c02c
TT
5202@node Skipping Over Functions and Files
5203@section Skipping Over Functions and Files
1bfeeb0f
JL
5204@cindex skipping over functions and files
5205
5206The program you are debugging may contain some functions which are
5207uninteresting to debug. The @code{skip} comand lets you tell @value{GDBN} to
5208skip a function or all functions in a file when stepping.
5209
5210For example, consider the following C function:
5211
5212@smallexample
5213101 int func()
5214102 @{
5215103 foo(boring());
5216104 bar(boring());
5217105 @}
5218@end smallexample
5219
5220@noindent
5221Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
5222are not interested in stepping through @code{boring}. If you run @code{step}
5223at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
5224step over both @code{foo} and @code{boring}!
5225
5226One solution is to @code{step} into @code{boring} and use the @code{finish}
5227command to immediately exit it. But this can become tedious if @code{boring}
5228is called from many places.
5229
5230A more flexible solution is to execute @kbd{skip boring}. This instructs
5231@value{GDBN} never to step into @code{boring}. Now when you execute
5232@code{step} at line 103, you'll step over @code{boring} and directly into
5233@code{foo}.
5234
5235You can also instruct @value{GDBN} to skip all functions in a file, with, for
5236example, @code{skip file boring.c}.
5237
5238@table @code
5239@kindex skip function
5240@item skip @r{[}@var{linespec}@r{]}
5241@itemx skip function @r{[}@var{linespec}@r{]}
5242After running this command, the function named by @var{linespec} or the
5243function containing the line named by @var{linespec} will be skipped over when
983fb131 5244stepping. @xref{Specify Location}.
1bfeeb0f
JL
5245
5246If you do not specify @var{linespec}, the function you're currently debugging
5247will be skipped.
5248
5249(If you have a function called @code{file} that you want to skip, use
5250@kbd{skip function file}.)
5251
5252@kindex skip file
5253@item skip file @r{[}@var{filename}@r{]}
5254After running this command, any function whose source lives in @var{filename}
5255will be skipped over when stepping.
5256
5257If you do not specify @var{filename}, functions whose source lives in the file
5258you're currently debugging will be skipped.
5259@end table
5260
5261Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
5262These are the commands for managing your list of skips:
5263
5264@table @code
5265@kindex info skip
5266@item info skip @r{[}@var{range}@r{]}
5267Print details about the specified skip(s). If @var{range} is not specified,
5268print a table with details about all functions and files marked for skipping.
5269@code{info skip} prints the following information about each skip:
5270
5271@table @emph
5272@item Identifier
5273A number identifying this skip.
5274@item Type
5275The type of this skip, either @samp{function} or @samp{file}.
5276@item Enabled or Disabled
5277Enabled skips are marked with @samp{y}. Disabled skips are marked with @samp{n}.
5278@item Address
5279For function skips, this column indicates the address in memory of the function
5280being skipped. If you've set a function skip on a function which has not yet
5281been loaded, this field will contain @samp{<PENDING>}. Once a shared library
5282which has the function is loaded, @code{info skip} will show the function's
5283address here.
5284@item What
5285For file skips, this field contains the filename being skipped. For functions
5286skips, this field contains the function name and its line number in the file
5287where it is defined.
5288@end table
5289
5290@kindex skip delete
5291@item skip delete @r{[}@var{range}@r{]}
5292Delete the specified skip(s). If @var{range} is not specified, delete all
5293skips.
5294
5295@kindex skip enable
5296@item skip enable @r{[}@var{range}@r{]}
5297Enable the specified skip(s). If @var{range} is not specified, enable all
5298skips.
5299
5300@kindex skip disable
5301@item skip disable @r{[}@var{range}@r{]}
5302Disable the specified skip(s). If @var{range} is not specified, disable all
5303skips.
5304
5305@end table
5306
6d2ebf8b 5307@node Signals
c906108c
SS
5308@section Signals
5309@cindex signals
5310
5311A signal is an asynchronous event that can happen in a program. The
5312operating system defines the possible kinds of signals, and gives each
5313kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 5314signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
5315@code{SIGSEGV} is the signal a program gets from referencing a place in
5316memory far away from all the areas in use; @code{SIGALRM} occurs when
5317the alarm clock timer goes off (which happens only if your program has
5318requested an alarm).
5319
5320@cindex fatal signals
5321Some signals, including @code{SIGALRM}, are a normal part of the
5322functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 5323errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
5324program has not specified in advance some other way to handle the signal.
5325@code{SIGINT} does not indicate an error in your program, but it is normally
5326fatal so it can carry out the purpose of the interrupt: to kill the program.
5327
5328@value{GDBN} has the ability to detect any occurrence of a signal in your
5329program. You can tell @value{GDBN} in advance what to do for each kind of
5330signal.
5331
5332@cindex handling signals
24f93129
EZ
5333Normally, @value{GDBN} is set up to let the non-erroneous signals like
5334@code{SIGALRM} be silently passed to your program
5335(so as not to interfere with their role in the program's functioning)
c906108c
SS
5336but to stop your program immediately whenever an error signal happens.
5337You can change these settings with the @code{handle} command.
5338
5339@table @code
5340@kindex info signals
09d4efe1 5341@kindex info handle
c906108c 5342@item info signals
96a2c332 5343@itemx info handle
c906108c
SS
5344Print a table of all the kinds of signals and how @value{GDBN} has been told to
5345handle each one. You can use this to see the signal numbers of all
5346the defined types of signals.
5347
45ac1734
EZ
5348@item info signals @var{sig}
5349Similar, but print information only about the specified signal number.
5350
d4f3574e 5351@code{info handle} is an alias for @code{info signals}.
c906108c 5352
ab04a2af
TT
5353@item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
5354Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
5355for details about this command.
5356
c906108c 5357@kindex handle
45ac1734 5358@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
5ece1a18
EZ
5359Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
5360can be the number of a signal or its name (with or without the
24f93129 5361@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 5362@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
5363known signals. Optional arguments @var{keywords}, described below,
5364say what change to make.
c906108c
SS
5365@end table
5366
5367@c @group
5368The keywords allowed by the @code{handle} command can be abbreviated.
5369Their full names are:
5370
5371@table @code
5372@item nostop
5373@value{GDBN} should not stop your program when this signal happens. It may
5374still print a message telling you that the signal has come in.
5375
5376@item stop
5377@value{GDBN} should stop your program when this signal happens. This implies
5378the @code{print} keyword as well.
5379
5380@item print
5381@value{GDBN} should print a message when this signal happens.
5382
5383@item noprint
5384@value{GDBN} should not mention the occurrence of the signal at all. This
5385implies the @code{nostop} keyword as well.
5386
5387@item pass
5ece1a18 5388@itemx noignore
c906108c
SS
5389@value{GDBN} should allow your program to see this signal; your program
5390can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 5391and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
5392
5393@item nopass
5ece1a18 5394@itemx ignore
c906108c 5395@value{GDBN} should not allow your program to see this signal.
5ece1a18 5396@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
5397@end table
5398@c @end group
5399
d4f3574e
SS
5400When a signal stops your program, the signal is not visible to the
5401program until you
c906108c
SS
5402continue. Your program sees the signal then, if @code{pass} is in
5403effect for the signal in question @emph{at that time}. In other words,
5404after @value{GDBN} reports a signal, you can use the @code{handle}
5405command with @code{pass} or @code{nopass} to control whether your
5406program sees that signal when you continue.
5407
24f93129
EZ
5408The default is set to @code{nostop}, @code{noprint}, @code{pass} for
5409non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
5410@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
5411erroneous signals.
5412
c906108c
SS
5413You can also use the @code{signal} command to prevent your program from
5414seeing a signal, or cause it to see a signal it normally would not see,
5415or to give it any signal at any time. For example, if your program stopped
5416due to some sort of memory reference error, you might store correct
5417values into the erroneous variables and continue, hoping to see more
5418execution; but your program would probably terminate immediately as
5419a result of the fatal signal once it saw the signal. To prevent this,
5420you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
79a6e687 5421Program a Signal}.
c906108c 5422
4aa995e1
PA
5423@cindex extra signal information
5424@anchor{extra signal information}
5425
5426On some targets, @value{GDBN} can inspect extra signal information
5427associated with the intercepted signal, before it is actually
5428delivered to the program being debugged. This information is exported
5429by the convenience variable @code{$_siginfo}, and consists of data
5430that is passed by the kernel to the signal handler at the time of the
5431receipt of a signal. The data type of the information itself is
5432target dependent. You can see the data type using the @code{ptype
5433$_siginfo} command. On Unix systems, it typically corresponds to the
5434standard @code{siginfo_t} type, as defined in the @file{signal.h}
5435system header.
5436
5437Here's an example, on a @sc{gnu}/Linux system, printing the stray
5438referenced address that raised a segmentation fault.
5439
5440@smallexample
5441@group
5442(@value{GDBP}) continue
5443Program received signal SIGSEGV, Segmentation fault.
54440x0000000000400766 in main ()
544569 *(int *)p = 0;
5446(@value{GDBP}) ptype $_siginfo
5447type = struct @{
5448 int si_signo;
5449 int si_errno;
5450 int si_code;
5451 union @{
5452 int _pad[28];
5453 struct @{...@} _kill;
5454 struct @{...@} _timer;
5455 struct @{...@} _rt;
5456 struct @{...@} _sigchld;
5457 struct @{...@} _sigfault;
5458 struct @{...@} _sigpoll;
5459 @} _sifields;
5460@}
5461(@value{GDBP}) ptype $_siginfo._sifields._sigfault
5462type = struct @{
5463 void *si_addr;
5464@}
5465(@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
5466$1 = (void *) 0x7ffff7ff7000
5467@end group
5468@end smallexample
5469
5470Depending on target support, @code{$_siginfo} may also be writable.
5471
6d2ebf8b 5472@node Thread Stops
79a6e687 5473@section Stopping and Starting Multi-thread Programs
c906108c 5474
0606b73b
SL
5475@cindex stopped threads
5476@cindex threads, stopped
5477
5478@cindex continuing threads
5479@cindex threads, continuing
5480
5481@value{GDBN} supports debugging programs with multiple threads
5482(@pxref{Threads,, Debugging Programs with Multiple Threads}). There
5483are two modes of controlling execution of your program within the
5484debugger. In the default mode, referred to as @dfn{all-stop mode},
5485when any thread in your program stops (for example, at a breakpoint
5486or while being stepped), all other threads in the program are also stopped by
5487@value{GDBN}. On some targets, @value{GDBN} also supports
5488@dfn{non-stop mode}, in which other threads can continue to run freely while
5489you examine the stopped thread in the debugger.
5490
5491@menu
5492* All-Stop Mode:: All threads stop when GDB takes control
5493* Non-Stop Mode:: Other threads continue to execute
5494* Background Execution:: Running your program asynchronously
5495* Thread-Specific Breakpoints:: Controlling breakpoints
5496* Interrupted System Calls:: GDB may interfere with system calls
d914c394 5497* Observer Mode:: GDB does not alter program behavior
0606b73b
SL
5498@end menu
5499
5500@node All-Stop Mode
5501@subsection All-Stop Mode
5502
5503@cindex all-stop mode
5504
5505In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
5506@emph{all} threads of execution stop, not just the current thread. This
5507allows you to examine the overall state of the program, including
5508switching between threads, without worrying that things may change
5509underfoot.
5510
5511Conversely, whenever you restart the program, @emph{all} threads start
5512executing. @emph{This is true even when single-stepping} with commands
5513like @code{step} or @code{next}.
5514
5515In particular, @value{GDBN} cannot single-step all threads in lockstep.
5516Since thread scheduling is up to your debugging target's operating
5517system (not controlled by @value{GDBN}), other threads may
5518execute more than one statement while the current thread completes a
5519single step. Moreover, in general other threads stop in the middle of a
5520statement, rather than at a clean statement boundary, when the program
5521stops.
5522
5523You might even find your program stopped in another thread after
5524continuing or even single-stepping. This happens whenever some other
5525thread runs into a breakpoint, a signal, or an exception before the
5526first thread completes whatever you requested.
5527
5528@cindex automatic thread selection
5529@cindex switching threads automatically
5530@cindex threads, automatic switching
5531Whenever @value{GDBN} stops your program, due to a breakpoint or a
5532signal, it automatically selects the thread where that breakpoint or
5533signal happened. @value{GDBN} alerts you to the context switch with a
5534message such as @samp{[Switching to Thread @var{n}]} to identify the
5535thread.
5536
5537On some OSes, you can modify @value{GDBN}'s default behavior by
5538locking the OS scheduler to allow only a single thread to run.
5539
5540@table @code
5541@item set scheduler-locking @var{mode}
5542@cindex scheduler locking mode
5543@cindex lock scheduler
5544Set the scheduler locking mode. If it is @code{off}, then there is no
5545locking and any thread may run at any time. If @code{on}, then only the
5546current thread may run when the inferior is resumed. The @code{step}
5547mode optimizes for single-stepping; it prevents other threads
5548from preempting the current thread while you are stepping, so that
5549the focus of debugging does not change unexpectedly.
5550Other threads only rarely (or never) get a chance to run
5551when you step. They are more likely to run when you @samp{next} over a
5552function call, and they are completely free to run when you use commands
5553like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
5554thread hits a breakpoint during its timeslice, @value{GDBN} does not change
5555the current thread away from the thread that you are debugging.
5556
5557@item show scheduler-locking
5558Display the current scheduler locking mode.
5559@end table
5560
d4db2f36
PA
5561@cindex resume threads of multiple processes simultaneously
5562By default, when you issue one of the execution commands such as
5563@code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
5564threads of the current inferior to run. For example, if @value{GDBN}
5565is attached to two inferiors, each with two threads, the
5566@code{continue} command resumes only the two threads of the current
5567inferior. This is useful, for example, when you debug a program that
5568forks and you want to hold the parent stopped (so that, for instance,
5569it doesn't run to exit), while you debug the child. In other
5570situations, you may not be interested in inspecting the current state
5571of any of the processes @value{GDBN} is attached to, and you may want
5572to resume them all until some breakpoint is hit. In the latter case,
5573you can instruct @value{GDBN} to allow all threads of all the
5574inferiors to run with the @w{@code{set schedule-multiple}} command.
5575
5576@table @code
5577@kindex set schedule-multiple
5578@item set schedule-multiple
5579Set the mode for allowing threads of multiple processes to be resumed
5580when an execution command is issued. When @code{on}, all threads of
5581all processes are allowed to run. When @code{off}, only the threads
5582of the current process are resumed. The default is @code{off}. The
5583@code{scheduler-locking} mode takes precedence when set to @code{on},
5584or while you are stepping and set to @code{step}.
5585
5586@item show schedule-multiple
5587Display the current mode for resuming the execution of threads of
5588multiple processes.
5589@end table
5590
0606b73b
SL
5591@node Non-Stop Mode
5592@subsection Non-Stop Mode
5593
5594@cindex non-stop mode
5595
5596@c This section is really only a place-holder, and needs to be expanded
5597@c with more details.
5598
5599For some multi-threaded targets, @value{GDBN} supports an optional
5600mode of operation in which you can examine stopped program threads in
5601the debugger while other threads continue to execute freely. This
5602minimizes intrusion when debugging live systems, such as programs
5603where some threads have real-time constraints or must continue to
5604respond to external events. This is referred to as @dfn{non-stop} mode.
5605
5606In non-stop mode, when a thread stops to report a debugging event,
5607@emph{only} that thread is stopped; @value{GDBN} does not stop other
5608threads as well, in contrast to the all-stop mode behavior. Additionally,
5609execution commands such as @code{continue} and @code{step} apply by default
5610only to the current thread in non-stop mode, rather than all threads as
5611in all-stop mode. This allows you to control threads explicitly in
5612ways that are not possible in all-stop mode --- for example, stepping
5613one thread while allowing others to run freely, stepping
5614one thread while holding all others stopped, or stepping several threads
5615independently and simultaneously.
5616
5617To enter non-stop mode, use this sequence of commands before you run
5618or attach to your program:
5619
0606b73b
SL
5620@smallexample
5621# Enable the async interface.
c6ebd6cf 5622set target-async 1
0606b73b 5623
0606b73b
SL
5624# If using the CLI, pagination breaks non-stop.
5625set pagination off
5626
5627# Finally, turn it on!
5628set non-stop on
5629@end smallexample
5630
5631You can use these commands to manipulate the non-stop mode setting:
5632
5633@table @code
5634@kindex set non-stop
5635@item set non-stop on
5636Enable selection of non-stop mode.
5637@item set non-stop off
5638Disable selection of non-stop mode.
5639@kindex show non-stop
5640@item show non-stop
5641Show the current non-stop enablement setting.
5642@end table
5643
5644Note these commands only reflect whether non-stop mode is enabled,
5645not whether the currently-executing program is being run in non-stop mode.
5646In particular, the @code{set non-stop} preference is only consulted when
5647@value{GDBN} starts or connects to the target program, and it is generally
5648not possible to switch modes once debugging has started. Furthermore,
5649since not all targets support non-stop mode, even when you have enabled
5650non-stop mode, @value{GDBN} may still fall back to all-stop operation by
5651default.
5652
5653In non-stop mode, all execution commands apply only to the current thread
5654by default. That is, @code{continue} only continues one thread.
5655To continue all threads, issue @code{continue -a} or @code{c -a}.
5656
5657You can use @value{GDBN}'s background execution commands
5658(@pxref{Background Execution}) to run some threads in the background
5659while you continue to examine or step others from @value{GDBN}.
5660The MI execution commands (@pxref{GDB/MI Program Execution}) are
5661always executed asynchronously in non-stop mode.
5662
5663Suspending execution is done with the @code{interrupt} command when
5664running in the background, or @kbd{Ctrl-c} during foreground execution.
5665In all-stop mode, this stops the whole process;
5666but in non-stop mode the interrupt applies only to the current thread.
5667To stop the whole program, use @code{interrupt -a}.
5668
5669Other execution commands do not currently support the @code{-a} option.
5670
5671In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
5672that thread current, as it does in all-stop mode. This is because the
5673thread stop notifications are asynchronous with respect to @value{GDBN}'s
5674command interpreter, and it would be confusing if @value{GDBN} unexpectedly
5675changed to a different thread just as you entered a command to operate on the
5676previously current thread.
5677
5678@node Background Execution
5679@subsection Background Execution
5680
5681@cindex foreground execution
5682@cindex background execution
5683@cindex asynchronous execution
5684@cindex execution, foreground, background and asynchronous
5685
5686@value{GDBN}'s execution commands have two variants: the normal
5687foreground (synchronous) behavior, and a background
5688(asynchronous) behavior. In foreground execution, @value{GDBN} waits for
5689the program to report that some thread has stopped before prompting for
5690another command. In background execution, @value{GDBN} immediately gives
5691a command prompt so that you can issue other commands while your program runs.
5692
32fc0df9
PA
5693You need to explicitly enable asynchronous mode before you can use
5694background execution commands. You can use these commands to
5695manipulate the asynchronous mode setting:
5696
5697@table @code
5698@kindex set target-async
5699@item set target-async on
5700Enable asynchronous mode.
5701@item set target-async off
5702Disable asynchronous mode.
5703@kindex show target-async
5704@item show target-async
5705Show the current target-async setting.
5706@end table
5707
5708If the target doesn't support async mode, @value{GDBN} issues an error
5709message if you attempt to use the background execution commands.
5710
0606b73b
SL
5711To specify background execution, add a @code{&} to the command. For example,
5712the background form of the @code{continue} command is @code{continue&}, or
5713just @code{c&}. The execution commands that accept background execution
5714are:
5715
5716@table @code
5717@kindex run&
5718@item run
5719@xref{Starting, , Starting your Program}.
5720
5721@item attach
5722@kindex attach&
5723@xref{Attach, , Debugging an Already-running Process}.
5724
5725@item step
5726@kindex step&
5727@xref{Continuing and Stepping, step}.
5728
5729@item stepi
5730@kindex stepi&
5731@xref{Continuing and Stepping, stepi}.
5732
5733@item next
5734@kindex next&
5735@xref{Continuing and Stepping, next}.
5736
7ce58dd2
DE
5737@item nexti
5738@kindex nexti&
5739@xref{Continuing and Stepping, nexti}.
5740
0606b73b
SL
5741@item continue
5742@kindex continue&
5743@xref{Continuing and Stepping, continue}.
5744
5745@item finish
5746@kindex finish&
5747@xref{Continuing and Stepping, finish}.
5748
5749@item until
5750@kindex until&
5751@xref{Continuing and Stepping, until}.
5752
5753@end table
5754
5755Background execution is especially useful in conjunction with non-stop
5756mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
5757However, you can also use these commands in the normal all-stop mode with
5758the restriction that you cannot issue another execution command until the
5759previous one finishes. Examples of commands that are valid in all-stop
5760mode while the program is running include @code{help} and @code{info break}.
5761
5762You can interrupt your program while it is running in the background by
5763using the @code{interrupt} command.
5764
5765@table @code
5766@kindex interrupt
5767@item interrupt
5768@itemx interrupt -a
5769
5770Suspend execution of the running program. In all-stop mode,
5771@code{interrupt} stops the whole process, but in non-stop mode, it stops
5772only the current thread. To stop the whole program in non-stop mode,
5773use @code{interrupt -a}.
5774@end table
5775
0606b73b
SL
5776@node Thread-Specific Breakpoints
5777@subsection Thread-Specific Breakpoints
5778
c906108c 5779When your program has multiple threads (@pxref{Threads,, Debugging
79a6e687 5780Programs with Multiple Threads}), you can choose whether to set
c906108c
SS
5781breakpoints on all threads, or on a particular thread.
5782
5783@table @code
5784@cindex breakpoints and threads
5785@cindex thread breakpoints
5786@kindex break @dots{} thread @var{threadno}
5787@item break @var{linespec} thread @var{threadno}
5788@itemx break @var{linespec} thread @var{threadno} if @dots{}
5789@var{linespec} specifies source lines; there are several ways of
2a25a5ba
EZ
5790writing them (@pxref{Specify Location}), but the effect is always to
5791specify some source line.
c906108c
SS
5792
5793Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
5794to specify that you only want @value{GDBN} to stop the program when a
5795particular thread reaches this breakpoint. @var{threadno} is one of the
5796numeric thread identifiers assigned by @value{GDBN}, shown in the first
5797column of the @samp{info threads} display.
5798
5799If you do not specify @samp{thread @var{threadno}} when you set a
5800breakpoint, the breakpoint applies to @emph{all} threads of your
5801program.
5802
5803You can use the @code{thread} qualifier on conditional breakpoints as
b6199126
DJ
5804well; in this case, place @samp{thread @var{threadno}} before or
5805after the breakpoint condition, like this:
c906108c
SS
5806
5807@smallexample
2df3850c 5808(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
5809@end smallexample
5810
5811@end table
5812
0606b73b
SL
5813@node Interrupted System Calls
5814@subsection Interrupted System Calls
c906108c 5815
36d86913
MC
5816@cindex thread breakpoints and system calls
5817@cindex system calls and thread breakpoints
5818@cindex premature return from system calls
0606b73b
SL
5819There is an unfortunate side effect when using @value{GDBN} to debug
5820multi-threaded programs. If one thread stops for a
36d86913
MC
5821breakpoint, or for some other reason, and another thread is blocked in a
5822system call, then the system call may return prematurely. This is a
5823consequence of the interaction between multiple threads and the signals
5824that @value{GDBN} uses to implement breakpoints and other events that
5825stop execution.
5826
5827To handle this problem, your program should check the return value of
5828each system call and react appropriately. This is good programming
5829style anyways.
5830
5831For example, do not write code like this:
5832
5833@smallexample
5834 sleep (10);
5835@end smallexample
5836
5837The call to @code{sleep} will return early if a different thread stops
5838at a breakpoint or for some other reason.
5839
5840Instead, write this:
5841
5842@smallexample
5843 int unslept = 10;
5844 while (unslept > 0)
5845 unslept = sleep (unslept);
5846@end smallexample
5847
5848A system call is allowed to return early, so the system is still
5849conforming to its specification. But @value{GDBN} does cause your
5850multi-threaded program to behave differently than it would without
5851@value{GDBN}.
5852
5853Also, @value{GDBN} uses internal breakpoints in the thread library to
5854monitor certain events such as thread creation and thread destruction.
5855When such an event happens, a system call in another thread may return
5856prematurely, even though your program does not appear to stop.
5857
d914c394
SS
5858@node Observer Mode
5859@subsection Observer Mode
5860
5861If you want to build on non-stop mode and observe program behavior
5862without any chance of disruption by @value{GDBN}, you can set
5863variables to disable all of the debugger's attempts to modify state,
5864whether by writing memory, inserting breakpoints, etc. These operate
5865at a low level, intercepting operations from all commands.
5866
5867When all of these are set to @code{off}, then @value{GDBN} is said to
5868be @dfn{observer mode}. As a convenience, the variable
5869@code{observer} can be set to disable these, plus enable non-stop
5870mode.
5871
5872Note that @value{GDBN} will not prevent you from making nonsensical
5873combinations of these settings. For instance, if you have enabled
5874@code{may-insert-breakpoints} but disabled @code{may-write-memory},
5875then breakpoints that work by writing trap instructions into the code
5876stream will still not be able to be placed.
5877
5878@table @code
5879
5880@kindex observer
5881@item set observer on
5882@itemx set observer off
5883When set to @code{on}, this disables all the permission variables
5884below (except for @code{insert-fast-tracepoints}), plus enables
5885non-stop debugging. Setting this to @code{off} switches back to
5886normal debugging, though remaining in non-stop mode.
5887
5888@item show observer
5889Show whether observer mode is on or off.
5890
5891@kindex may-write-registers
5892@item set may-write-registers on
5893@itemx set may-write-registers off
5894This controls whether @value{GDBN} will attempt to alter the values of
5895registers, such as with assignment expressions in @code{print}, or the
5896@code{jump} command. It defaults to @code{on}.
5897
5898@item show may-write-registers
5899Show the current permission to write registers.
5900
5901@kindex may-write-memory
5902@item set may-write-memory on
5903@itemx set may-write-memory off
5904This controls whether @value{GDBN} will attempt to alter the contents
5905of memory, such as with assignment expressions in @code{print}. It
5906defaults to @code{on}.
5907
5908@item show may-write-memory
5909Show the current permission to write memory.
5910
5911@kindex may-insert-breakpoints
5912@item set may-insert-breakpoints on
5913@itemx set may-insert-breakpoints off
5914This controls whether @value{GDBN} will attempt to insert breakpoints.
5915This affects all breakpoints, including internal breakpoints defined
5916by @value{GDBN}. It defaults to @code{on}.
5917
5918@item show may-insert-breakpoints
5919Show the current permission to insert breakpoints.
5920
5921@kindex may-insert-tracepoints
5922@item set may-insert-tracepoints on
5923@itemx set may-insert-tracepoints off
5924This controls whether @value{GDBN} will attempt to insert (regular)
5925tracepoints at the beginning of a tracing experiment. It affects only
5926non-fast tracepoints, fast tracepoints being under the control of
5927@code{may-insert-fast-tracepoints}. It defaults to @code{on}.
5928
5929@item show may-insert-tracepoints
5930Show the current permission to insert tracepoints.
5931
5932@kindex may-insert-fast-tracepoints
5933@item set may-insert-fast-tracepoints on
5934@itemx set may-insert-fast-tracepoints off
5935This controls whether @value{GDBN} will attempt to insert fast
5936tracepoints at the beginning of a tracing experiment. It affects only
5937fast tracepoints, regular (non-fast) tracepoints being under the
5938control of @code{may-insert-tracepoints}. It defaults to @code{on}.
5939
5940@item show may-insert-fast-tracepoints
5941Show the current permission to insert fast tracepoints.
5942
5943@kindex may-interrupt
5944@item set may-interrupt on
5945@itemx set may-interrupt off
5946This controls whether @value{GDBN} will attempt to interrupt or stop
5947program execution. When this variable is @code{off}, the
5948@code{interrupt} command will have no effect, nor will
5949@kbd{Ctrl-c}. It defaults to @code{on}.
5950
5951@item show may-interrupt
5952Show the current permission to interrupt or stop the program.
5953
5954@end table
c906108c 5955
bacec72f
MS
5956@node Reverse Execution
5957@chapter Running programs backward
5958@cindex reverse execution
5959@cindex running programs backward
5960
5961When you are debugging a program, it is not unusual to realize that
5962you have gone too far, and some event of interest has already happened.
5963If the target environment supports it, @value{GDBN} can allow you to
5964``rewind'' the program by running it backward.
5965
5966A target environment that supports reverse execution should be able
5967to ``undo'' the changes in machine state that have taken place as the
5968program was executing normally. Variables, registers etc.@: should
5969revert to their previous values. Obviously this requires a great
5970deal of sophistication on the part of the target environment; not
5971all target environments can support reverse execution.
5972
5973When a program is executed in reverse, the instructions that
5974have most recently been executed are ``un-executed'', in reverse
5975order. The program counter runs backward, following the previous
5976thread of execution in reverse. As each instruction is ``un-executed'',
5977the values of memory and/or registers that were changed by that
5978instruction are reverted to their previous states. After executing
5979a piece of source code in reverse, all side effects of that code
5980should be ``undone'', and all variables should be returned to their
5981prior values@footnote{
5982Note that some side effects are easier to undo than others. For instance,
5983memory and registers are relatively easy, but device I/O is hard. Some
5984targets may be able undo things like device I/O, and some may not.
5985
5986The contract between @value{GDBN} and the reverse executing target
5987requires only that the target do something reasonable when
5988@value{GDBN} tells it to execute backwards, and then report the
5989results back to @value{GDBN}. Whatever the target reports back to
5990@value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
5991assumes that the memory and registers that the target reports are in a
5992consistant state, but @value{GDBN} accepts whatever it is given.
5993}.
5994
5995If you are debugging in a target environment that supports
5996reverse execution, @value{GDBN} provides the following commands.
5997
5998@table @code
5999@kindex reverse-continue
6000@kindex rc @r{(@code{reverse-continue})}
6001@item reverse-continue @r{[}@var{ignore-count}@r{]}
6002@itemx rc @r{[}@var{ignore-count}@r{]}
6003Beginning at the point where your program last stopped, start executing
6004in reverse. Reverse execution will stop for breakpoints and synchronous
6005exceptions (signals), just like normal execution. Behavior of
6006asynchronous signals depends on the target environment.
6007
6008@kindex reverse-step
6009@kindex rs @r{(@code{step})}
6010@item reverse-step @r{[}@var{count}@r{]}
6011Run the program backward until control reaches the start of a
6012different source line; then stop it, and return control to @value{GDBN}.
6013
6014Like the @code{step} command, @code{reverse-step} will only stop
6015at the beginning of a source line. It ``un-executes'' the previously
6016executed source line. If the previous source line included calls to
6017debuggable functions, @code{reverse-step} will step (backward) into
6018the called function, stopping at the beginning of the @emph{last}
6019statement in the called function (typically a return statement).
6020
6021Also, as with the @code{step} command, if non-debuggable functions are
6022called, @code{reverse-step} will run thru them backward without stopping.
6023
6024@kindex reverse-stepi
6025@kindex rsi @r{(@code{reverse-stepi})}
6026@item reverse-stepi @r{[}@var{count}@r{]}
6027Reverse-execute one machine instruction. Note that the instruction
6028to be reverse-executed is @emph{not} the one pointed to by the program
6029counter, but the instruction executed prior to that one. For instance,
6030if the last instruction was a jump, @code{reverse-stepi} will take you
6031back from the destination of the jump to the jump instruction itself.
6032
6033@kindex reverse-next
6034@kindex rn @r{(@code{reverse-next})}
6035@item reverse-next @r{[}@var{count}@r{]}
6036Run backward to the beginning of the previous line executed in
6037the current (innermost) stack frame. If the line contains function
6038calls, they will be ``un-executed'' without stopping. Starting from
6039the first line of a function, @code{reverse-next} will take you back
6040to the caller of that function, @emph{before} the function was called,
6041just as the normal @code{next} command would take you from the last
6042line of a function back to its return to its caller
16af530a 6043@footnote{Unless the code is too heavily optimized.}.
bacec72f
MS
6044
6045@kindex reverse-nexti
6046@kindex rni @r{(@code{reverse-nexti})}
6047@item reverse-nexti @r{[}@var{count}@r{]}
6048Like @code{nexti}, @code{reverse-nexti} executes a single instruction
6049in reverse, except that called functions are ``un-executed'' atomically.
6050That is, if the previously executed instruction was a return from
540aa8e7 6051another function, @code{reverse-nexti} will continue to execute
bacec72f
MS
6052in reverse until the call to that function (from the current stack
6053frame) is reached.
6054
6055@kindex reverse-finish
6056@item reverse-finish
6057Just as the @code{finish} command takes you to the point where the
6058current function returns, @code{reverse-finish} takes you to the point
6059where it was called. Instead of ending up at the end of the current
6060function invocation, you end up at the beginning.
6061
6062@kindex set exec-direction
6063@item set exec-direction
6064Set the direction of target execution.
984359d2 6065@item set exec-direction reverse
bacec72f
MS
6066@cindex execute forward or backward in time
6067@value{GDBN} will perform all execution commands in reverse, until the
6068exec-direction mode is changed to ``forward''. Affected commands include
6069@code{step, stepi, next, nexti, continue, and finish}. The @code{return}
6070command cannot be used in reverse mode.
6071@item set exec-direction forward
6072@value{GDBN} will perform all execution commands in the normal fashion.
6073This is the default.
6074@end table
6075
c906108c 6076
a2311334
EZ
6077@node Process Record and Replay
6078@chapter Recording Inferior's Execution and Replaying It
53cc454a
HZ
6079@cindex process record and replay
6080@cindex recording inferior's execution and replaying it
6081
8e05493c
EZ
6082On some platforms, @value{GDBN} provides a special @dfn{process record
6083and replay} target that can record a log of the process execution, and
6084replay it later with both forward and reverse execution commands.
a2311334
EZ
6085
6086@cindex replay mode
6087When this target is in use, if the execution log includes the record
6088for the next instruction, @value{GDBN} will debug in @dfn{replay
6089mode}. In the replay mode, the inferior does not really execute code
6090instructions. Instead, all the events that normally happen during
6091code execution are taken from the execution log. While code is not
6092really executed in replay mode, the values of registers (including the
6093program counter register) and the memory of the inferior are still
8e05493c
EZ
6094changed as they normally would. Their contents are taken from the
6095execution log.
a2311334
EZ
6096
6097@cindex record mode
6098If the record for the next instruction is not in the execution log,
6099@value{GDBN} will debug in @dfn{record mode}. In this mode, the
6100inferior executes normally, and @value{GDBN} records the execution log
6101for future replay.
6102
8e05493c
EZ
6103The process record and replay target supports reverse execution
6104(@pxref{Reverse Execution}), even if the platform on which the
6105inferior runs does not. However, the reverse execution is limited in
6106this case by the range of the instructions recorded in the execution
6107log. In other words, reverse execution on platforms that don't
6108support it directly can only be done in the replay mode.
6109
6110When debugging in the reverse direction, @value{GDBN} will work in
6111replay mode as long as the execution log includes the record for the
6112previous instruction; otherwise, it will work in record mode, if the
6113platform supports reverse execution, or stop if not.
6114
a2311334
EZ
6115For architecture environments that support process record and replay,
6116@value{GDBN} provides the following commands:
53cc454a
HZ
6117
6118@table @code
6119@kindex target record
59ea5688
MM
6120@kindex target record-full
6121@kindex target record-btrace
53cc454a 6122@kindex record
59ea5688
MM
6123@kindex record full
6124@kindex record btrace
53cc454a 6125@kindex rec
59ea5688
MM
6126@kindex rec full
6127@kindex rec btrace
6128@item record @var{method}
6129This command starts the process record and replay target. The
6130recording method can be specified as parameter. Without a parameter
6131the command uses the @code{full} recording method. The following
6132recording methods are available:
a2311334 6133
59ea5688
MM
6134@table @code
6135@item full
6136Full record/replay recording using @value{GDBN}'s software record and
6137replay implementation. This method allows replaying and reverse
6138execution.
6139
6140@item btrace
6141Hardware-supported instruction recording. This method does not allow
6142replaying and reverse execution.
6143
6144This recording method may not be available on all processors.
6145@end table
6146
6147The process record and replay target can only debug a process that is
6148already running. Therefore, you need first to start the process with
6149the @kbd{run} or @kbd{start} commands, and then start the recording
6150with the @kbd{record @var{method}} command.
6151
6152Both @code{record @var{method}} and @code{rec @var{method}} are
6153aliases of @code{target record-@var{method}}.
a2311334
EZ
6154
6155@cindex displaced stepping, and process record and replay
6156Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
6157will be automatically disabled when process record and replay target
6158is started. That's because the process record and replay target
6159doesn't support displaced stepping.
6160
6161@cindex non-stop mode, and process record and replay
6162@cindex asynchronous execution, and process record and replay
6163If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
59ea5688
MM
6164the asynchronous execution mode (@pxref{Background Execution}), not
6165all recording methods are available. The @code{full} recording method
6166does not support these two modes.
53cc454a
HZ
6167
6168@kindex record stop
6169@kindex rec s
6170@item record stop
a2311334
EZ
6171Stop the process record and replay target. When process record and
6172replay target stops, the entire execution log will be deleted and the
6173inferior will either be terminated, or will remain in its final state.
53cc454a 6174
a2311334
EZ
6175When you stop the process record and replay target in record mode (at
6176the end of the execution log), the inferior will be stopped at the
6177next instruction that would have been recorded. In other words, if
6178you record for a while and then stop recording, the inferior process
6179will be left in the same state as if the recording never happened.
53cc454a 6180
a2311334
EZ
6181On the other hand, if the process record and replay target is stopped
6182while in replay mode (that is, not at the end of the execution log,
6183but at some earlier point), the inferior process will become ``live''
6184at that earlier state, and it will then be possible to continue the
6185usual ``live'' debugging of the process from that state.
53cc454a 6186
a2311334
EZ
6187When the inferior process exits, or @value{GDBN} detaches from it,
6188process record and replay target will automatically stop itself.
53cc454a 6189
24e933df
HZ
6190@kindex record save
6191@item record save @var{filename}
6192Save the execution log to a file @file{@var{filename}}.
6193Default filename is @file{gdb_record.@var{process_id}}, where
6194@var{process_id} is the process ID of the inferior.
6195
59ea5688
MM
6196This command may not be available for all recording methods.
6197
24e933df
HZ
6198@kindex record restore
6199@item record restore @var{filename}
6200Restore the execution log from a file @file{@var{filename}}.
6201File must have been created with @code{record save}.
6202
59ea5688
MM
6203@kindex set record full
6204@item set record full insn-number-max @var{limit}
6205Set the limit of instructions to be recorded for the @code{full}
6206recording method. Default value is 200000.
53cc454a 6207
a2311334
EZ
6208If @var{limit} is a positive number, then @value{GDBN} will start
6209deleting instructions from the log once the number of the record
6210instructions becomes greater than @var{limit}. For every new recorded
6211instruction, @value{GDBN} will delete the earliest recorded
6212instruction to keep the number of recorded instructions at the limit.
6213(Since deleting recorded instructions loses information, @value{GDBN}
6214lets you control what happens when the limit is reached, by means of
6215the @code{stop-at-limit} option, described below.)
53cc454a 6216
a2311334
EZ
6217If @var{limit} is zero, @value{GDBN} will never delete recorded
6218instructions from the execution log. The number of recorded
6219instructions is unlimited in this case.
53cc454a 6220
59ea5688
MM
6221@kindex show record full
6222@item show record full insn-number-max
6223Show the limit of instructions to be recorded with the @code{full}
6224recording method.
53cc454a 6225
59ea5688
MM
6226@item set record full stop-at-limit
6227Control the behavior of the @code{full} recording method when the
6228number of recorded instructions reaches the limit. If ON (the
6229default), @value{GDBN} will stop when the limit is reached for the
6230first time and ask you whether you want to stop the inferior or
6231continue running it and recording the execution log. If you decide
6232to continue recording, each new recorded instruction will cause the
6233oldest one to be deleted.
53cc454a 6234
a2311334
EZ
6235If this option is OFF, @value{GDBN} will automatically delete the
6236oldest record to make room for each new one, without asking.
53cc454a 6237
59ea5688 6238@item show record full stop-at-limit
a2311334 6239Show the current setting of @code{stop-at-limit}.
53cc454a 6240
59ea5688 6241@item set record full memory-query
bb08c432 6242Control the behavior when @value{GDBN} is unable to record memory
59ea5688
MM
6243changes caused by an instruction for the @code{full} recording method.
6244If ON, @value{GDBN} will query whether to stop the inferior in that
6245case.
bb08c432
HZ
6246
6247If this option is OFF (the default), @value{GDBN} will automatically
6248ignore the effect of such instructions on memory. Later, when
6249@value{GDBN} replays this execution log, it will mark the log of this
6250instruction as not accessible, and it will not affect the replay
6251results.
6252
59ea5688 6253@item show record full memory-query
bb08c432
HZ
6254Show the current setting of @code{memory-query}.
6255
29153c24
MS
6256@kindex info record
6257@item info record
59ea5688
MM
6258Show various statistics about the recording depending on the recording
6259method:
6260
6261@table @code
6262@item full
6263For the @code{full} recording method, it shows the state of process
6264record and its in-memory execution log buffer, including:
29153c24
MS
6265
6266@itemize @bullet
6267@item
6268Whether in record mode or replay mode.
6269@item
6270Lowest recorded instruction number (counting from when the current execution log started recording instructions).
6271@item
6272Highest recorded instruction number.
6273@item
6274Current instruction about to be replayed (if in replay mode).
6275@item
6276Number of instructions contained in the execution log.
6277@item
6278Maximum number of instructions that may be contained in the execution log.
6279@end itemize
53cc454a 6280
59ea5688
MM
6281@item btrace
6282For the @code{btrace} recording method, it shows the number of
6283instructions that have been recorded and the number of blocks of
6284sequential control-flow that is formed by the recorded instructions.
6285@end table
6286
53cc454a
HZ
6287@kindex record delete
6288@kindex rec del
6289@item record delete
a2311334 6290When record target runs in replay mode (``in the past''), delete the
53cc454a 6291subsequent execution log and begin to record a new execution log starting
a2311334 6292from the current address. This means you will abandon the previously
53cc454a 6293recorded ``future'' and begin recording a new ``future''.
59ea5688
MM
6294
6295@kindex record instruction-history
6296@kindex rec instruction-history
6297@item record instruction-history
6298Disassembles instructions from the recorded execution log. By
6299default, ten instructions are disassembled. This can be changed using
6300the @code{set record instruction-history-size} command. Instructions
6301are printed in execution order. There are several ways to specify
6302what part of the execution log to disassemble:
6303
6304@table @code
6305@item record instruction-history @var{insn}
6306Disassembles ten instructions starting from instruction number
6307@var{insn}.
6308
6309@item record instruction-history @var{insn}, +/-@var{n}
6310Disassembles @var{n} instructions around instruction number
6311@var{insn}. If @var{n} is preceded with @code{+}, disassembles
6312@var{n} instructions after instruction number @var{insn}. If
6313@var{n} is preceded with @code{-}, disassembles @var{n}
6314instructions before instruction number @var{insn}.
6315
6316@item record instruction-history
6317Disassembles ten more instructions after the last disassembly.
6318
6319@item record instruction-history -
6320Disassembles ten more instructions before the last disassembly.
6321
6322@item record instruction-history @var{begin} @var{end}
6323Disassembles instructions beginning with instruction number
6324@var{begin} until instruction number @var{end}. The instruction
6325number @var{end} is not included.
6326@end table
6327
6328This command may not be available for all recording methods.
6329
6330@kindex set record
6331@item set record instruction-history-size
6332Define how many instructions to disassemble in the @code{record
6333instruction-history} command. The default value is 10.
6334
6335@kindex show record
6336@item show record instruction-history-size
6337Show how many instructions to disassemble in the @code{record
6338instruction-history} command.
6339
6340@kindex record function-call-history
6341@kindex rec function-call-history
6342@item record function-call-history
6343Prints the execution history at function granularity. It prints one
6344line for each sequence of instructions that belong to the same
6345function giving the name of that function, the source lines
6346for this instruction sequence (if the @code{/l} modifier is
6347specified), and the instructions numbers that form the sequence (if
6348the @code{/i} modifier is specified).
6349
6350@smallexample
6351(@value{GDBP}) @b{list 1, 10}
63521 void foo (void)
63532 @{
63543 @}
63554
63565 void bar (void)
63576 @{
63587 ...
63598 foo ();
63609 ...
636110 @}
6362(@value{GDBP}) @b{record function-call-history /l}
63631 foo.c:6-8 bar
63642 foo.c:2-3 foo
63653 foo.c:9-10 bar
6366@end smallexample
6367
6368By default, ten lines are printed. This can be changed using the
6369@code{set record function-call-history-size} command. Functions are
6370printed in execution order. There are several ways to specify what
6371to print:
6372
6373@table @code
6374@item record function-call-history @var{func}
6375Prints ten functions starting from function number @var{func}.
6376
6377@item record function-call-history @var{func}, +/-@var{n}
6378Prints @var{n} functions around function number @var{func}. If
6379@var{n} is preceded with @code{+}, prints @var{n} functions after
6380function number @var{func}. If @var{n} is preceded with @code{-},
6381prints @var{n} functions before function number @var{func}.
6382
6383@item record function-call-history
6384Prints ten more functions after the last ten-line print.
6385
6386@item record function-call-history -
6387Prints ten more functions before the last ten-line print.
6388
6389@item record function-call-history @var{begin} @var{end}
6390Prints functions beginning with function number @var{begin} until
6391function number @var{end}. The function number @var{end} is not
6392included.
6393@end table
6394
6395This command may not be available for all recording methods.
6396
6397@item set record function-call-history-size
6398Define how many lines to print in the
6399@code{record function-call-history} command. The default value is 10.
6400
6401@item show record function-call-history-size
6402Show how many lines to print in the
6403@code{record function-call-history} command.
53cc454a
HZ
6404@end table
6405
6406
6d2ebf8b 6407@node Stack
c906108c
SS
6408@chapter Examining the Stack
6409
6410When your program has stopped, the first thing you need to know is where it
6411stopped and how it got there.
6412
6413@cindex call stack
5d161b24
DB
6414Each time your program performs a function call, information about the call
6415is generated.
6416That information includes the location of the call in your program,
6417the arguments of the call,
c906108c 6418and the local variables of the function being called.
5d161b24 6419The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
6420The stack frames are allocated in a region of memory called the @dfn{call
6421stack}.
6422
6423When your program stops, the @value{GDBN} commands for examining the
6424stack allow you to see all of this information.
6425
6426@cindex selected frame
6427One of the stack frames is @dfn{selected} by @value{GDBN} and many
6428@value{GDBN} commands refer implicitly to the selected frame. In
6429particular, whenever you ask @value{GDBN} for the value of a variable in
6430your program, the value is found in the selected frame. There are
6431special @value{GDBN} commands to select whichever frame you are
79a6e687 6432interested in. @xref{Selection, ,Selecting a Frame}.
c906108c
SS
6433
6434When your program stops, @value{GDBN} automatically selects the
5d161b24 6435currently executing frame and describes it briefly, similar to the
79a6e687 6436@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
c906108c
SS
6437
6438@menu
6439* Frames:: Stack frames
6440* Backtrace:: Backtraces
6441* Selection:: Selecting a frame
6442* Frame Info:: Information on a frame
c906108c
SS
6443
6444@end menu
6445
6d2ebf8b 6446@node Frames
79a6e687 6447@section Stack Frames
c906108c 6448
d4f3574e 6449@cindex frame, definition
c906108c
SS
6450@cindex stack frame
6451The call stack is divided up into contiguous pieces called @dfn{stack
6452frames}, or @dfn{frames} for short; each frame is the data associated
6453with one call to one function. The frame contains the arguments given
6454to the function, the function's local variables, and the address at
6455which the function is executing.
6456
6457@cindex initial frame
6458@cindex outermost frame
6459@cindex innermost frame
6460When your program is started, the stack has only one frame, that of the
6461function @code{main}. This is called the @dfn{initial} frame or the
6462@dfn{outermost} frame. Each time a function is called, a new frame is
6463made. Each time a function returns, the frame for that function invocation
6464is eliminated. If a function is recursive, there can be many frames for
6465the same function. The frame for the function in which execution is
6466actually occurring is called the @dfn{innermost} frame. This is the most
6467recently created of all the stack frames that still exist.
6468
6469@cindex frame pointer
6470Inside your program, stack frames are identified by their addresses. A
6471stack frame consists of many bytes, each of which has its own address; each
6472kind of computer has a convention for choosing one byte whose
6473address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
6474in a register called the @dfn{frame pointer register}
6475(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
6476
6477@cindex frame number
6478@value{GDBN} assigns numbers to all existing stack frames, starting with
6479zero for the innermost frame, one for the frame that called it,
6480and so on upward. These numbers do not really exist in your program;
6481they are assigned by @value{GDBN} to give you a way of designating stack
6482frames in @value{GDBN} commands.
6483
6d2ebf8b
SS
6484@c The -fomit-frame-pointer below perennially causes hbox overflow
6485@c underflow problems.
c906108c
SS
6486@cindex frameless execution
6487Some compilers provide a way to compile functions so that they operate
e22ea452 6488without stack frames. (For example, the @value{NGCC} option
474c8240 6489@smallexample
6d2ebf8b 6490@samp{-fomit-frame-pointer}
474c8240 6491@end smallexample
6d2ebf8b 6492generates functions without a frame.)
c906108c
SS
6493This is occasionally done with heavily used library functions to save
6494the frame setup time. @value{GDBN} has limited facilities for dealing
6495with these function invocations. If the innermost function invocation
6496has no stack frame, @value{GDBN} nevertheless regards it as though
6497it had a separate frame, which is numbered zero as usual, allowing
6498correct tracing of the function call chain. However, @value{GDBN} has
6499no provision for frameless functions elsewhere in the stack.
6500
6501@table @code
d4f3574e 6502@kindex frame@r{, command}
41afff9a 6503@cindex current stack frame
c906108c 6504@item frame @var{args}
5d161b24 6505The @code{frame} command allows you to move from one stack frame to another,
c906108c 6506and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
6507address of the frame or the stack frame number. Without an argument,
6508@code{frame} prints the current stack frame.
c906108c
SS
6509
6510@kindex select-frame
41afff9a 6511@cindex selecting frame silently
c906108c
SS
6512@item select-frame
6513The @code{select-frame} command allows you to move from one stack frame
6514to another without printing the frame. This is the silent version of
6515@code{frame}.
6516@end table
6517
6d2ebf8b 6518@node Backtrace
c906108c
SS
6519@section Backtraces
6520
09d4efe1
EZ
6521@cindex traceback
6522@cindex call stack traces
c906108c
SS
6523A backtrace is a summary of how your program got where it is. It shows one
6524line per frame, for many frames, starting with the currently executing
6525frame (frame zero), followed by its caller (frame one), and on up the
6526stack.
6527
6528@table @code
6529@kindex backtrace
41afff9a 6530@kindex bt @r{(@code{backtrace})}
c906108c
SS
6531@item backtrace
6532@itemx bt
6533Print a backtrace of the entire stack: one line per frame for all
6534frames in the stack.
6535
6536You can stop the backtrace at any time by typing the system interrupt
c8aa23ab 6537character, normally @kbd{Ctrl-c}.
c906108c
SS
6538
6539@item backtrace @var{n}
6540@itemx bt @var{n}
6541Similar, but print only the innermost @var{n} frames.
6542
6543@item backtrace -@var{n}
6544@itemx bt -@var{n}
6545Similar, but print only the outermost @var{n} frames.
0f061b69
NR
6546
6547@item backtrace full
0f061b69 6548@itemx bt full
dd74f6ae
NR
6549@itemx bt full @var{n}
6550@itemx bt full -@var{n}
e7109c7e 6551Print the values of the local variables also. @var{n} specifies the
286ba84d 6552number of frames to print, as described above.
c906108c
SS
6553@end table
6554
6555@kindex where
6556@kindex info stack
c906108c
SS
6557The names @code{where} and @code{info stack} (abbreviated @code{info s})
6558are additional aliases for @code{backtrace}.
6559
839c27b7
EZ
6560@cindex multiple threads, backtrace
6561In a multi-threaded program, @value{GDBN} by default shows the
6562backtrace only for the current thread. To display the backtrace for
6563several or all of the threads, use the command @code{thread apply}
6564(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
6565apply all backtrace}, @value{GDBN} will display the backtrace for all
6566the threads; this is handy when you debug a core dump of a
6567multi-threaded program.
6568
c906108c
SS
6569Each line in the backtrace shows the frame number and the function name.
6570The program counter value is also shown---unless you use @code{set
6571print address off}. The backtrace also shows the source file name and
6572line number, as well as the arguments to the function. The program
6573counter value is omitted if it is at the beginning of the code for that
6574line number.
6575
6576Here is an example of a backtrace. It was made with the command
6577@samp{bt 3}, so it shows the innermost three frames.
6578
6579@smallexample
6580@group
5d161b24 6581#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c 6582 at builtin.c:993
4f5376b2 6583#1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
c906108c
SS
6584#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
6585 at macro.c:71
6586(More stack frames follow...)
6587@end group
6588@end smallexample
6589
6590@noindent
6591The display for frame zero does not begin with a program counter
6592value, indicating that your program has stopped at the beginning of the
6593code for line @code{993} of @code{builtin.c}.
6594
4f5376b2
JB
6595@noindent
6596The value of parameter @code{data} in frame 1 has been replaced by
6597@code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
6598only if it is a scalar (integer, pointer, enumeration, etc). See command
6599@kbd{set print frame-arguments} in @ref{Print Settings} for more details
6600on how to configure the way function parameter values are printed.
6601
585fdaa1 6602@cindex optimized out, in backtrace
18999be5
EZ
6603@cindex function call arguments, optimized out
6604If your program was compiled with optimizations, some compilers will
6605optimize away arguments passed to functions if those arguments are
6606never used after the call. Such optimizations generate code that
6607passes arguments through registers, but doesn't store those arguments
6608in the stack frame. @value{GDBN} has no way of displaying such
6609arguments in stack frames other than the innermost one. Here's what
6610such a backtrace might look like:
6611
6612@smallexample
6613@group
6614#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
6615 at builtin.c:993
585fdaa1
PA
6616#1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
6617#2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
18999be5
EZ
6618 at macro.c:71
6619(More stack frames follow...)
6620@end group
6621@end smallexample
6622
6623@noindent
6624The values of arguments that were not saved in their stack frames are
585fdaa1 6625shown as @samp{<optimized out>}.
18999be5
EZ
6626
6627If you need to display the values of such optimized-out arguments,
6628either deduce that from other variables whose values depend on the one
6629you are interested in, or recompile without optimizations.
6630
a8f24a35
EZ
6631@cindex backtrace beyond @code{main} function
6632@cindex program entry point
6633@cindex startup code, and backtrace
25d29d70
AC
6634Most programs have a standard user entry point---a place where system
6635libraries and startup code transition into user code. For C this is
d416eeec
EZ
6636@code{main}@footnote{
6637Note that embedded programs (the so-called ``free-standing''
6638environment) are not required to have a @code{main} function as the
6639entry point. They could even have multiple entry points.}.
6640When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
6641it will terminate the backtrace, to avoid tracing into highly
6642system-specific (and generally uninteresting) code.
6643
6644If you need to examine the startup code, or limit the number of levels
6645in a backtrace, you can change this behavior:
95f90d25
DJ
6646
6647@table @code
25d29d70
AC
6648@item set backtrace past-main
6649@itemx set backtrace past-main on
4644b6e3 6650@kindex set backtrace
25d29d70
AC
6651Backtraces will continue past the user entry point.
6652
6653@item set backtrace past-main off
95f90d25
DJ
6654Backtraces will stop when they encounter the user entry point. This is the
6655default.
6656
25d29d70 6657@item show backtrace past-main
4644b6e3 6658@kindex show backtrace
25d29d70
AC
6659Display the current user entry point backtrace policy.
6660
2315ffec
RC
6661@item set backtrace past-entry
6662@itemx set backtrace past-entry on
a8f24a35 6663Backtraces will continue past the internal entry point of an application.
2315ffec
RC
6664This entry point is encoded by the linker when the application is built,
6665and is likely before the user entry point @code{main} (or equivalent) is called.
6666
6667@item set backtrace past-entry off
d3e8051b 6668Backtraces will stop when they encounter the internal entry point of an
2315ffec
RC
6669application. This is the default.
6670
6671@item show backtrace past-entry
6672Display the current internal entry point backtrace policy.
6673
25d29d70
AC
6674@item set backtrace limit @var{n}
6675@itemx set backtrace limit 0
6676@cindex backtrace limit
6677Limit the backtrace to @var{n} levels. A value of zero means
6678unlimited.
95f90d25 6679
25d29d70
AC
6680@item show backtrace limit
6681Display the current limit on backtrace levels.
95f90d25
DJ
6682@end table
6683
1b56eb55
JK
6684You can control how file names are displayed.
6685
6686@table @code
6687@item set filename-display
6688@itemx set filename-display relative
6689@cindex filename-display
6690Display file names relative to the compilation directory. This is the default.
6691
6692@item set filename-display basename
6693Display only basename of a filename.
6694
6695@item set filename-display absolute
6696Display an absolute filename.
6697
6698@item show filename-display
6699Show the current way to display filenames.
6700@end table
6701
6d2ebf8b 6702@node Selection
79a6e687 6703@section Selecting a Frame
c906108c
SS
6704
6705Most commands for examining the stack and other data in your program work on
6706whichever stack frame is selected at the moment. Here are the commands for
6707selecting a stack frame; all of them finish by printing a brief description
6708of the stack frame just selected.
6709
6710@table @code
d4f3574e 6711@kindex frame@r{, selecting}
41afff9a 6712@kindex f @r{(@code{frame})}
c906108c
SS
6713@item frame @var{n}
6714@itemx f @var{n}
6715Select frame number @var{n}. Recall that frame zero is the innermost
6716(currently executing) frame, frame one is the frame that called the
6717innermost one, and so on. The highest-numbered frame is the one for
6718@code{main}.
6719
6720@item frame @var{addr}
6721@itemx f @var{addr}
6722Select the frame at address @var{addr}. This is useful mainly if the
6723chaining of stack frames has been damaged by a bug, making it
6724impossible for @value{GDBN} to assign numbers properly to all frames. In
6725addition, this can be useful when your program has multiple stacks and
6726switches between them.
6727
c906108c
SS
6728On the SPARC architecture, @code{frame} needs two addresses to
6729select an arbitrary frame: a frame pointer and a stack pointer.
6730
eb17f351 6731On the @acronym{MIPS} and Alpha architecture, it needs two addresses: a stack
c906108c
SS
6732pointer and a program counter.
6733
6734On the 29k architecture, it needs three addresses: a register stack
6735pointer, a program counter, and a memory stack pointer.
c906108c
SS
6736
6737@kindex up
6738@item up @var{n}
6739Move @var{n} frames up the stack. For positive numbers @var{n}, this
6740advances toward the outermost frame, to higher frame numbers, to frames
6741that have existed longer. @var{n} defaults to one.
6742
6743@kindex down
41afff9a 6744@kindex do @r{(@code{down})}
c906108c
SS
6745@item down @var{n}
6746Move @var{n} frames down the stack. For positive numbers @var{n}, this
6747advances toward the innermost frame, to lower frame numbers, to frames
6748that were created more recently. @var{n} defaults to one. You may
6749abbreviate @code{down} as @code{do}.
6750@end table
6751
6752All of these commands end by printing two lines of output describing the
6753frame. The first line shows the frame number, the function name, the
6754arguments, and the source file and line number of execution in that
5d161b24 6755frame. The second line shows the text of that source line.
c906108c
SS
6756
6757@need 1000
6758For example:
6759
6760@smallexample
6761@group
6762(@value{GDBP}) up
6763#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
6764 at env.c:10
676510 read_input_file (argv[i]);
6766@end group
6767@end smallexample
6768
6769After such a printout, the @code{list} command with no arguments
6770prints ten lines centered on the point of execution in the frame.
87885426
FN
6771You can also edit the program at the point of execution with your favorite
6772editing program by typing @code{edit}.
79a6e687 6773@xref{List, ,Printing Source Lines},
87885426 6774for details.
c906108c
SS
6775
6776@table @code
6777@kindex down-silently
6778@kindex up-silently
6779@item up-silently @var{n}
6780@itemx down-silently @var{n}
6781These two commands are variants of @code{up} and @code{down},
6782respectively; they differ in that they do their work silently, without
6783causing display of the new frame. They are intended primarily for use
6784in @value{GDBN} command scripts, where the output might be unnecessary and
6785distracting.
6786@end table
6787
6d2ebf8b 6788@node Frame Info
79a6e687 6789@section Information About a Frame
c906108c
SS
6790
6791There are several other commands to print information about the selected
6792stack frame.
6793
6794@table @code
6795@item frame
6796@itemx f
6797When used without any argument, this command does not change which
6798frame is selected, but prints a brief description of the currently
6799selected stack frame. It can be abbreviated @code{f}. With an
6800argument, this command is used to select a stack frame.
79a6e687 6801@xref{Selection, ,Selecting a Frame}.
c906108c
SS
6802
6803@kindex info frame
41afff9a 6804@kindex info f @r{(@code{info frame})}
c906108c
SS
6805@item info frame
6806@itemx info f
6807This command prints a verbose description of the selected stack frame,
6808including:
6809
6810@itemize @bullet
5d161b24
DB
6811@item
6812the address of the frame
c906108c
SS
6813@item
6814the address of the next frame down (called by this frame)
6815@item
6816the address of the next frame up (caller of this frame)
6817@item
6818the language in which the source code corresponding to this frame is written
6819@item
6820the address of the frame's arguments
6821@item
d4f3574e
SS
6822the address of the frame's local variables
6823@item
c906108c
SS
6824the program counter saved in it (the address of execution in the caller frame)
6825@item
6826which registers were saved in the frame
6827@end itemize
6828
6829@noindent The verbose description is useful when
6830something has gone wrong that has made the stack format fail to fit
6831the usual conventions.
6832
6833@item info frame @var{addr}
6834@itemx info f @var{addr}
6835Print a verbose description of the frame at address @var{addr}, without
6836selecting that frame. The selected frame remains unchanged by this
6837command. This requires the same kind of address (more than one for some
6838architectures) that you specify in the @code{frame} command.
79a6e687 6839@xref{Selection, ,Selecting a Frame}.
c906108c
SS
6840
6841@kindex info args
6842@item info args
6843Print the arguments of the selected frame, each on a separate line.
6844
6845@item info locals
6846@kindex info locals
6847Print the local variables of the selected frame, each on a separate
6848line. These are all variables (declared either static or automatic)
6849accessible at the point of execution of the selected frame.
6850
c906108c
SS
6851@end table
6852
c906108c 6853
6d2ebf8b 6854@node Source
c906108c
SS
6855@chapter Examining Source Files
6856
6857@value{GDBN} can print parts of your program's source, since the debugging
6858information recorded in the program tells @value{GDBN} what source files were
6859used to build it. When your program stops, @value{GDBN} spontaneously prints
6860the line where it stopped. Likewise, when you select a stack frame
79a6e687 6861(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
c906108c
SS
6862execution in that frame has stopped. You can print other portions of
6863source files by explicit command.
6864
7a292a7a 6865If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 6866prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 6867@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
6868
6869@menu
6870* List:: Printing source lines
2a25a5ba 6871* Specify Location:: How to specify code locations
87885426 6872* Edit:: Editing source files
c906108c 6873* Search:: Searching source files
c906108c
SS
6874* Source Path:: Specifying source directories
6875* Machine Code:: Source and machine code
6876@end menu
6877
6d2ebf8b 6878@node List
79a6e687 6879@section Printing Source Lines
c906108c
SS
6880
6881@kindex list
41afff9a 6882@kindex l @r{(@code{list})}
c906108c 6883To print lines from a source file, use the @code{list} command
5d161b24 6884(abbreviated @code{l}). By default, ten lines are printed.
2a25a5ba
EZ
6885There are several ways to specify what part of the file you want to
6886print; see @ref{Specify Location}, for the full list.
c906108c
SS
6887
6888Here are the forms of the @code{list} command most commonly used:
6889
6890@table @code
6891@item list @var{linenum}
6892Print lines centered around line number @var{linenum} in the
6893current source file.
6894
6895@item list @var{function}
6896Print lines centered around the beginning of function
6897@var{function}.
6898
6899@item list
6900Print more lines. If the last lines printed were printed with a
6901@code{list} command, this prints lines following the last lines
6902printed; however, if the last line printed was a solitary line printed
6903as part of displaying a stack frame (@pxref{Stack, ,Examining the
6904Stack}), this prints lines centered around that line.
6905
6906@item list -
6907Print lines just before the lines last printed.
6908@end table
6909
9c16f35a 6910@cindex @code{list}, how many lines to display
c906108c
SS
6911By default, @value{GDBN} prints ten source lines with any of these forms of
6912the @code{list} command. You can change this using @code{set listsize}:
6913
6914@table @code
6915@kindex set listsize
6916@item set listsize @var{count}
6917Make the @code{list} command display @var{count} source lines (unless
6918the @code{list} argument explicitly specifies some other number).
6fc1c773
YQ
6919Setting @var{count} to -1 means there's no limit and 0 means suppress
6920display of source lines.
c906108c
SS
6921
6922@kindex show listsize
6923@item show listsize
6924Display the number of lines that @code{list} prints.
6925@end table
6926
6927Repeating a @code{list} command with @key{RET} discards the argument,
6928so it is equivalent to typing just @code{list}. This is more useful
6929than listing the same lines again. An exception is made for an
6930argument of @samp{-}; that argument is preserved in repetition so that
6931each repetition moves up in the source file.
6932
c906108c
SS
6933In general, the @code{list} command expects you to supply zero, one or two
6934@dfn{linespecs}. Linespecs specify source lines; there are several ways
2a25a5ba
EZ
6935of writing them (@pxref{Specify Location}), but the effect is always
6936to specify some source line.
6937
c906108c
SS
6938Here is a complete description of the possible arguments for @code{list}:
6939
6940@table @code
6941@item list @var{linespec}
6942Print lines centered around the line specified by @var{linespec}.
6943
6944@item list @var{first},@var{last}
6945Print lines from @var{first} to @var{last}. Both arguments are
2a25a5ba
EZ
6946linespecs. When a @code{list} command has two linespecs, and the
6947source file of the second linespec is omitted, this refers to
6948the same source file as the first linespec.
c906108c
SS
6949
6950@item list ,@var{last}
6951Print lines ending with @var{last}.
6952
6953@item list @var{first},
6954Print lines starting with @var{first}.
6955
6956@item list +
6957Print lines just after the lines last printed.
6958
6959@item list -
6960Print lines just before the lines last printed.
6961
6962@item list
6963As described in the preceding table.
6964@end table
6965
2a25a5ba
EZ
6966@node Specify Location
6967@section Specifying a Location
6968@cindex specifying location
6969@cindex linespec
c906108c 6970
2a25a5ba
EZ
6971Several @value{GDBN} commands accept arguments that specify a location
6972of your program's code. Since @value{GDBN} is a source-level
6973debugger, a location usually specifies some line in the source code;
6974for that reason, locations are also known as @dfn{linespecs}.
c906108c 6975
2a25a5ba
EZ
6976Here are all the different ways of specifying a code location that
6977@value{GDBN} understands:
c906108c 6978
2a25a5ba
EZ
6979@table @code
6980@item @var{linenum}
6981Specifies the line number @var{linenum} of the current source file.
c906108c 6982
2a25a5ba
EZ
6983@item -@var{offset}
6984@itemx +@var{offset}
6985Specifies the line @var{offset} lines before or after the @dfn{current
6986line}. For the @code{list} command, the current line is the last one
6987printed; for the breakpoint commands, this is the line at which
6988execution stopped in the currently selected @dfn{stack frame}
6989(@pxref{Frames, ,Frames}, for a description of stack frames.) When
6990used as the second of the two linespecs in a @code{list} command,
6991this specifies the line @var{offset} lines up or down from the first
6992linespec.
6993
6994@item @var{filename}:@var{linenum}
6995Specifies the line @var{linenum} in the source file @var{filename}.
4aac40c8
TT
6996If @var{filename} is a relative file name, then it will match any
6997source file name with the same trailing components. For example, if
6998@var{filename} is @samp{gcc/expr.c}, then it will match source file
6999name of @file{/build/trunk/gcc/expr.c}, but not
7000@file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
c906108c
SS
7001
7002@item @var{function}
7003Specifies the line that begins the body of the function @var{function}.
2a25a5ba 7004For example, in C, this is the line with the open brace.
c906108c 7005
9ef07c8c
TT
7006@item @var{function}:@var{label}
7007Specifies the line where @var{label} appears in @var{function}.
7008
c906108c 7009@item @var{filename}:@var{function}
2a25a5ba
EZ
7010Specifies the line that begins the body of the function @var{function}
7011in the file @var{filename}. You only need the file name with a
7012function name to avoid ambiguity when there are identically named
7013functions in different source files.
c906108c 7014
0f5238ed
TT
7015@item @var{label}
7016Specifies the line at which the label named @var{label} appears.
7017@value{GDBN} searches for the label in the function corresponding to
7018the currently selected stack frame. If there is no current selected
7019stack frame (for instance, if the inferior is not running), then
7020@value{GDBN} will not search for a label.
7021
c906108c 7022@item *@var{address}
2a25a5ba
EZ
7023Specifies the program address @var{address}. For line-oriented
7024commands, such as @code{list} and @code{edit}, this specifies a source
7025line that contains @var{address}. For @code{break} and other
7026breakpoint oriented commands, this can be used to set breakpoints in
7027parts of your program which do not have debugging information or
7028source files.
7029
7030Here @var{address} may be any expression valid in the current working
7031language (@pxref{Languages, working language}) that specifies a code
5fa54e5d
EZ
7032address. In addition, as a convenience, @value{GDBN} extends the
7033semantics of expressions used in locations to cover the situations
7034that frequently happen during debugging. Here are the various forms
7035of @var{address}:
2a25a5ba
EZ
7036
7037@table @code
7038@item @var{expression}
7039Any expression valid in the current working language.
7040
7041@item @var{funcaddr}
7042An address of a function or procedure derived from its name. In C,
7043C@t{++}, Java, Objective-C, Fortran, minimal, and assembly, this is
7044simply the function's name @var{function} (and actually a special case
7045of a valid expression). In Pascal and Modula-2, this is
7046@code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
7047(although the Pascal form also works).
7048
7049This form specifies the address of the function's first instruction,
7050before the stack frame and arguments have been set up.
7051
7052@item '@var{filename}'::@var{funcaddr}
7053Like @var{funcaddr} above, but also specifies the name of the source
7054file explicitly. This is useful if the name of the function does not
7055specify the function unambiguously, e.g., if there are several
7056functions with identical names in different source files.
c906108c
SS
7057@end table
7058
62e5f89c
SDJ
7059@cindex breakpoint at static probe point
7060@item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
7061The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
7062applications to embed static probes. @xref{Static Probe Points}, for more
7063information on finding and using static probes. This form of linespec
7064specifies the location of such a static probe.
7065
7066If @var{objfile} is given, only probes coming from that shared library
7067or executable matching @var{objfile} as a regular expression are considered.
7068If @var{provider} is given, then only probes from that provider are considered.
7069If several probes match the spec, @value{GDBN} will insert a breakpoint at
7070each one of those probes.
7071
2a25a5ba
EZ
7072@end table
7073
7074
87885426 7075@node Edit
79a6e687 7076@section Editing Source Files
87885426
FN
7077@cindex editing source files
7078
7079@kindex edit
7080@kindex e @r{(@code{edit})}
7081To edit the lines in a source file, use the @code{edit} command.
7082The editing program of your choice
7083is invoked with the current line set to
7084the active line in the program.
7085Alternatively, there are several ways to specify what part of the file you
2a25a5ba 7086want to print if you want to see other parts of the program:
87885426
FN
7087
7088@table @code
2a25a5ba
EZ
7089@item edit @var{location}
7090Edit the source file specified by @code{location}. Editing starts at
7091that @var{location}, e.g., at the specified source line of the
7092specified file. @xref{Specify Location}, for all the possible forms
7093of the @var{location} argument; here are the forms of the @code{edit}
7094command most commonly used:
87885426 7095
2a25a5ba 7096@table @code
87885426
FN
7097@item edit @var{number}
7098Edit the current source file with @var{number} as the active line number.
7099
7100@item edit @var{function}
7101Edit the file containing @var{function} at the beginning of its definition.
2a25a5ba 7102@end table
87885426 7103
87885426
FN
7104@end table
7105
79a6e687 7106@subsection Choosing your Editor
87885426
FN
7107You can customize @value{GDBN} to use any editor you want
7108@footnote{
7109The only restriction is that your editor (say @code{ex}), recognizes the
7110following command-line syntax:
10998722 7111@smallexample
87885426 7112ex +@var{number} file
10998722 7113@end smallexample
15387254
EZ
7114The optional numeric value +@var{number} specifies the number of the line in
7115the file where to start editing.}.
7116By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
7117by setting the environment variable @code{EDITOR} before using
7118@value{GDBN}. For example, to configure @value{GDBN} to use the
7119@code{vi} editor, you could use these commands with the @code{sh} shell:
7120@smallexample
87885426
FN
7121EDITOR=/usr/bin/vi
7122export EDITOR
15387254 7123gdb @dots{}
10998722 7124@end smallexample
87885426 7125or in the @code{csh} shell,
10998722 7126@smallexample
87885426 7127setenv EDITOR /usr/bin/vi
15387254 7128gdb @dots{}
10998722 7129@end smallexample
87885426 7130
6d2ebf8b 7131@node Search
79a6e687 7132@section Searching Source Files
15387254 7133@cindex searching source files
c906108c
SS
7134
7135There are two commands for searching through the current source file for a
7136regular expression.
7137
7138@table @code
7139@kindex search
7140@kindex forward-search
1e96de83 7141@kindex fo @r{(@code{forward-search})}
c906108c
SS
7142@item forward-search @var{regexp}
7143@itemx search @var{regexp}
7144The command @samp{forward-search @var{regexp}} checks each line,
7145starting with the one following the last line listed, for a match for
5d161b24 7146@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
7147synonym @samp{search @var{regexp}} or abbreviate the command name as
7148@code{fo}.
7149
09d4efe1 7150@kindex reverse-search
c906108c
SS
7151@item reverse-search @var{regexp}
7152The command @samp{reverse-search @var{regexp}} checks each line, starting
7153with the one before the last line listed and going backward, for a match
7154for @var{regexp}. It lists the line that is found. You can abbreviate
7155this command as @code{rev}.
7156@end table
c906108c 7157
6d2ebf8b 7158@node Source Path
79a6e687 7159@section Specifying Source Directories
c906108c
SS
7160
7161@cindex source path
7162@cindex directories for source files
7163Executable programs sometimes do not record the directories of the source
7164files from which they were compiled, just the names. Even when they do,
7165the directories could be moved between the compilation and your debugging
7166session. @value{GDBN} has a list of directories to search for source files;
7167this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
7168it tries all the directories in the list, in the order they are present
0b66e38c
EZ
7169in the list, until it finds a file with the desired name.
7170
7171For example, suppose an executable references the file
7172@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
7173@file{/mnt/cross}. The file is first looked up literally; if this
7174fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
7175fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
7176message is printed. @value{GDBN} does not look up the parts of the
7177source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
7178Likewise, the subdirectories of the source path are not searched: if
7179the source path is @file{/mnt/cross}, and the binary refers to
7180@file{foo.c}, @value{GDBN} would not find it under
7181@file{/mnt/cross/usr/src/foo-1.0/lib}.
7182
7183Plain file names, relative file names with leading directories, file
7184names containing dots, etc.@: are all treated as described above; for
7185instance, if the source path is @file{/mnt/cross}, and the source file
7186is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
7187@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
7188that---@file{/mnt/cross/foo.c}.
7189
7190Note that the executable search path is @emph{not} used to locate the
cd852561 7191source files.
c906108c
SS
7192
7193Whenever you reset or rearrange the source path, @value{GDBN} clears out
7194any information it has cached about where source files are found and where
7195each line is in the file.
7196
7197@kindex directory
7198@kindex dir
d4f3574e
SS
7199When you start @value{GDBN}, its source path includes only @samp{cdir}
7200and @samp{cwd}, in that order.
c906108c
SS
7201To add other directories, use the @code{directory} command.
7202
4b505b12
AS
7203The search path is used to find both program source files and @value{GDBN}
7204script files (read using the @samp{-command} option and @samp{source} command).
7205
30daae6c
JB
7206In addition to the source path, @value{GDBN} provides a set of commands
7207that manage a list of source path substitution rules. A @dfn{substitution
7208rule} specifies how to rewrite source directories stored in the program's
7209debug information in case the sources were moved to a different
7210directory between compilation and debugging. A rule is made of
7211two strings, the first specifying what needs to be rewritten in
7212the path, and the second specifying how it should be rewritten.
7213In @ref{set substitute-path}, we name these two parts @var{from} and
7214@var{to} respectively. @value{GDBN} does a simple string replacement
7215of @var{from} with @var{to} at the start of the directory part of the
7216source file name, and uses that result instead of the original file
7217name to look up the sources.
7218
7219Using the previous example, suppose the @file{foo-1.0} tree has been
7220moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
3f94c067 7221@value{GDBN} to replace @file{/usr/src} in all source path names with
30daae6c
JB
7222@file{/mnt/cross}. The first lookup will then be
7223@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
7224of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
7225substitution rule, use the @code{set substitute-path} command
7226(@pxref{set substitute-path}).
7227
7228To avoid unexpected substitution results, a rule is applied only if the
7229@var{from} part of the directory name ends at a directory separator.
7230For instance, a rule substituting @file{/usr/source} into
7231@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
7232not to @file{/usr/sourceware/foo-2.0}. And because the substitution
d3e8051b 7233is applied only at the beginning of the directory name, this rule will
30daae6c
JB
7234not be applied to @file{/root/usr/source/baz.c} either.
7235
7236In many cases, you can achieve the same result using the @code{directory}
7237command. However, @code{set substitute-path} can be more efficient in
7238the case where the sources are organized in a complex tree with multiple
7239subdirectories. With the @code{directory} command, you need to add each
7240subdirectory of your project. If you moved the entire tree while
7241preserving its internal organization, then @code{set substitute-path}
7242allows you to direct the debugger to all the sources with one single
7243command.
7244
7245@code{set substitute-path} is also more than just a shortcut command.
7246The source path is only used if the file at the original location no
7247longer exists. On the other hand, @code{set substitute-path} modifies
7248the debugger behavior to look at the rewritten location instead. So, if
7249for any reason a source file that is not relevant to your executable is
7250located at the original location, a substitution rule is the only
3f94c067 7251method available to point @value{GDBN} at the new location.
30daae6c 7252
29b0e8a2
JM
7253@cindex @samp{--with-relocated-sources}
7254@cindex default source path substitution
7255You can configure a default source path substitution rule by
7256configuring @value{GDBN} with the
7257@samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
7258should be the name of a directory under @value{GDBN}'s configured
7259prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
7260directory names in debug information under @var{dir} will be adjusted
7261automatically if the installed @value{GDBN} is moved to a new
7262location. This is useful if @value{GDBN}, libraries or executables
7263with debug information and corresponding source code are being moved
7264together.
7265
c906108c
SS
7266@table @code
7267@item directory @var{dirname} @dots{}
7268@item dir @var{dirname} @dots{}
7269Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
7270directory names may be given to this command, separated by @samp{:}
7271(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
7272part of absolute file names) or
c906108c
SS
7273whitespace. You may specify a directory that is already in the source
7274path; this moves it forward, so @value{GDBN} searches it sooner.
7275
7276@kindex cdir
7277@kindex cwd
41afff9a 7278@vindex $cdir@r{, convenience variable}
d3e8051b 7279@vindex $cwd@r{, convenience variable}
c906108c
SS
7280@cindex compilation directory
7281@cindex current directory
7282@cindex working directory
7283@cindex directory, current
7284@cindex directory, compilation
7285You can use the string @samp{$cdir} to refer to the compilation
7286directory (if one is recorded), and @samp{$cwd} to refer to the current
7287working directory. @samp{$cwd} is not the same as @samp{.}---the former
7288tracks the current working directory as it changes during your @value{GDBN}
7289session, while the latter is immediately expanded to the current
7290directory at the time you add an entry to the source path.
7291
7292@item directory
cd852561 7293Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
7294
7295@c RET-repeat for @code{directory} is explicitly disabled, but since
7296@c repeating it would be a no-op we do not say that. (thanks to RMS)
7297
99e7ae30
DE
7298@item set directories @var{path-list}
7299@kindex set directories
7300Set the source path to @var{path-list}.
7301@samp{$cdir:$cwd} are added if missing.
7302
c906108c
SS
7303@item show directories
7304@kindex show directories
7305Print the source path: show which directories it contains.
30daae6c
JB
7306
7307@anchor{set substitute-path}
7308@item set substitute-path @var{from} @var{to}
7309@kindex set substitute-path
7310Define a source path substitution rule, and add it at the end of the
7311current list of existing substitution rules. If a rule with the same
7312@var{from} was already defined, then the old rule is also deleted.
7313
7314For example, if the file @file{/foo/bar/baz.c} was moved to
7315@file{/mnt/cross/baz.c}, then the command
7316
7317@smallexample
7318(@value{GDBP}) set substitute-path /usr/src /mnt/cross
7319@end smallexample
7320
7321@noindent
7322will tell @value{GDBN} to replace @samp{/usr/src} with
7323@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
7324@file{baz.c} even though it was moved.
7325
7326In the case when more than one substitution rule have been defined,
7327the rules are evaluated one by one in the order where they have been
7328defined. The first one matching, if any, is selected to perform
7329the substitution.
7330
7331For instance, if we had entered the following commands:
7332
7333@smallexample
7334(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
7335(@value{GDBP}) set substitute-path /usr/src /mnt/src
7336@end smallexample
7337
7338@noindent
7339@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
7340@file{/mnt/include/defs.h} by using the first rule. However, it would
7341use the second rule to rewrite @file{/usr/src/lib/foo.c} into
7342@file{/mnt/src/lib/foo.c}.
7343
7344
7345@item unset substitute-path [path]
7346@kindex unset substitute-path
7347If a path is specified, search the current list of substitution rules
7348for a rule that would rewrite that path. Delete that rule if found.
7349A warning is emitted by the debugger if no rule could be found.
7350
7351If no path is specified, then all substitution rules are deleted.
7352
7353@item show substitute-path [path]
7354@kindex show substitute-path
7355If a path is specified, then print the source path substitution rule
7356which would rewrite that path, if any.
7357
7358If no path is specified, then print all existing source path substitution
7359rules.
7360
c906108c
SS
7361@end table
7362
7363If your source path is cluttered with directories that are no longer of
7364interest, @value{GDBN} may sometimes cause confusion by finding the wrong
7365versions of source. You can correct the situation as follows:
7366
7367@enumerate
7368@item
cd852561 7369Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
7370
7371@item
7372Use @code{directory} with suitable arguments to reinstall the
7373directories you want in the source path. You can add all the
7374directories in one command.
7375@end enumerate
7376
6d2ebf8b 7377@node Machine Code
79a6e687 7378@section Source and Machine Code
15387254 7379@cindex source line and its code address
c906108c
SS
7380
7381You can use the command @code{info line} to map source lines to program
7382addresses (and vice versa), and the command @code{disassemble} to display
91440f57
HZ
7383a range of addresses as machine instructions. You can use the command
7384@code{set disassemble-next-line} to set whether to disassemble next
7385source line when execution stops. When run under @sc{gnu} Emacs
d4f3574e 7386mode, the @code{info line} command causes the arrow to point to the
5d161b24 7387line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
7388well as hex.
7389
7390@table @code
7391@kindex info line
7392@item info line @var{linespec}
7393Print the starting and ending addresses of the compiled code for
7394source line @var{linespec}. You can specify source lines in any of
2a25a5ba 7395the ways documented in @ref{Specify Location}.
c906108c
SS
7396@end table
7397
7398For example, we can use @code{info line} to discover the location of
7399the object code for the first line of function
7400@code{m4_changequote}:
7401
d4f3574e
SS
7402@c FIXME: I think this example should also show the addresses in
7403@c symbolic form, as they usually would be displayed.
c906108c 7404@smallexample
96a2c332 7405(@value{GDBP}) info line m4_changequote
c906108c
SS
7406Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
7407@end smallexample
7408
7409@noindent
15387254 7410@cindex code address and its source line
c906108c
SS
7411We can also inquire (using @code{*@var{addr}} as the form for
7412@var{linespec}) what source line covers a particular address:
7413@smallexample
7414(@value{GDBP}) info line *0x63ff
7415Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
7416@end smallexample
7417
7418@cindex @code{$_} and @code{info line}
15387254 7419@cindex @code{x} command, default address
41afff9a 7420@kindex x@r{(examine), and} info line
c906108c
SS
7421After @code{info line}, the default address for the @code{x} command
7422is changed to the starting address of the line, so that @samp{x/i} is
7423sufficient to begin examining the machine code (@pxref{Memory,
79a6e687 7424,Examining Memory}). Also, this address is saved as the value of the
c906108c 7425convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
79a6e687 7426Variables}).
c906108c
SS
7427
7428@table @code
7429@kindex disassemble
7430@cindex assembly instructions
7431@cindex instructions, assembly
7432@cindex machine instructions
7433@cindex listing machine instructions
7434@item disassemble
d14508fe 7435@itemx disassemble /m
9b117ef3 7436@itemx disassemble /r
c906108c 7437This specialized command dumps a range of memory as machine
d14508fe 7438instructions. It can also print mixed source+disassembly by specifying
9b117ef3
HZ
7439the @code{/m} modifier and print the raw instructions in hex as well as
7440in symbolic form by specifying the @code{/r}.
d14508fe 7441The default memory range is the function surrounding the
c906108c
SS
7442program counter of the selected frame. A single argument to this
7443command is a program counter value; @value{GDBN} dumps the function
21a0512e
PP
7444surrounding this value. When two arguments are given, they should
7445be separated by a comma, possibly surrounded by whitespace. The
53a71c06
CR
7446arguments specify a range of addresses to dump, in one of two forms:
7447
7448@table @code
7449@item @var{start},@var{end}
7450the addresses from @var{start} (inclusive) to @var{end} (exclusive)
7451@item @var{start},+@var{length}
7452the addresses from @var{start} (inclusive) to
7453@code{@var{start}+@var{length}} (exclusive).
7454@end table
7455
7456@noindent
7457When 2 arguments are specified, the name of the function is also
7458printed (since there could be several functions in the given range).
21a0512e
PP
7459
7460The argument(s) can be any expression yielding a numeric value, such as
7461@samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
2b28d209
PP
7462
7463If the range of memory being disassembled contains current program counter,
7464the instruction at that location is shown with a @code{=>} marker.
c906108c
SS
7465@end table
7466
c906108c
SS
7467The following example shows the disassembly of a range of addresses of
7468HP PA-RISC 2.0 code:
7469
7470@smallexample
21a0512e 7471(@value{GDBP}) disas 0x32c4, 0x32e4
c906108c 7472Dump of assembler code from 0x32c4 to 0x32e4:
2b28d209
PP
7473 0x32c4 <main+204>: addil 0,dp
7474 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
7475 0x32cc <main+212>: ldil 0x3000,r31
7476 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
7477 0x32d4 <main+220>: ldo 0(r31),rp
7478 0x32d8 <main+224>: addil -0x800,dp
7479 0x32dc <main+228>: ldo 0x588(r1),r26
7480 0x32e0 <main+232>: ldil 0x3000,r31
c906108c
SS
7481End of assembler dump.
7482@end smallexample
c906108c 7483
2b28d209
PP
7484Here is an example showing mixed source+assembly for Intel x86, when the
7485program is stopped just after function prologue:
d14508fe
DE
7486
7487@smallexample
7488(@value{GDBP}) disas /m main
7489Dump of assembler code for function main:
74905 @{
9c419145
PP
7491 0x08048330 <+0>: push %ebp
7492 0x08048331 <+1>: mov %esp,%ebp
7493 0x08048333 <+3>: sub $0x8,%esp
7494 0x08048336 <+6>: and $0xfffffff0,%esp
7495 0x08048339 <+9>: sub $0x10,%esp
d14508fe
DE
7496
74976 printf ("Hello.\n");
9c419145
PP
7498=> 0x0804833c <+12>: movl $0x8048440,(%esp)
7499 0x08048343 <+19>: call 0x8048284 <puts@@plt>
d14508fe
DE
7500
75017 return 0;
75028 @}
9c419145
PP
7503 0x08048348 <+24>: mov $0x0,%eax
7504 0x0804834d <+29>: leave
7505 0x0804834e <+30>: ret
d14508fe
DE
7506
7507End of assembler dump.
7508@end smallexample
7509
53a71c06
CR
7510Here is another example showing raw instructions in hex for AMD x86-64,
7511
7512@smallexample
7513(gdb) disas /r 0x400281,+10
7514Dump of assembler code from 0x400281 to 0x40028b:
7515 0x0000000000400281: 38 36 cmp %dh,(%rsi)
7516 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
7517 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
7518 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
7519End of assembler dump.
7520@end smallexample
7521
7e1e0340
DE
7522Addresses cannot be specified as a linespec (@pxref{Specify Location}).
7523So, for example, if you want to disassemble function @code{bar}
7524in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
7525and not @samp{disassemble foo.c:bar}.
7526
c906108c
SS
7527Some architectures have more than one commonly-used set of instruction
7528mnemonics or other syntax.
7529
76d17f34
EZ
7530For programs that were dynamically linked and use shared libraries,
7531instructions that call functions or branch to locations in the shared
7532libraries might show a seemingly bogus location---it's actually a
7533location of the relocation table. On some architectures, @value{GDBN}
7534might be able to resolve these to actual function names.
7535
c906108c 7536@table @code
d4f3574e 7537@kindex set disassembly-flavor
d4f3574e
SS
7538@cindex Intel disassembly flavor
7539@cindex AT&T disassembly flavor
7540@item set disassembly-flavor @var{instruction-set}
c906108c
SS
7541Select the instruction set to use when disassembling the
7542program via the @code{disassemble} or @code{x/i} commands.
7543
7544Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
7545can set @var{instruction-set} to either @code{intel} or @code{att}.
7546The default is @code{att}, the AT&T flavor used by default by Unix
7547assemblers for x86-based targets.
9c16f35a
EZ
7548
7549@kindex show disassembly-flavor
7550@item show disassembly-flavor
7551Show the current setting of the disassembly flavor.
c906108c
SS
7552@end table
7553
91440f57
HZ
7554@table @code
7555@kindex set disassemble-next-line
7556@kindex show disassemble-next-line
7557@item set disassemble-next-line
7558@itemx show disassemble-next-line
32ae1842
EZ
7559Control whether or not @value{GDBN} will disassemble the next source
7560line or instruction when execution stops. If ON, @value{GDBN} will
7561display disassembly of the next source line when execution of the
7562program being debugged stops. This is @emph{in addition} to
7563displaying the source line itself, which @value{GDBN} always does if
7564possible. If the next source line cannot be displayed for some reason
7565(e.g., if @value{GDBN} cannot find the source file, or there's no line
7566info in the debug info), @value{GDBN} will display disassembly of the
7567next @emph{instruction} instead of showing the next source line. If
7568AUTO, @value{GDBN} will display disassembly of next instruction only
7569if the source line cannot be displayed. This setting causes
7570@value{GDBN} to display some feedback when you step through a function
7571with no line info or whose source file is unavailable. The default is
7572OFF, which means never display the disassembly of the next line or
7573instruction.
91440f57
HZ
7574@end table
7575
c906108c 7576
6d2ebf8b 7577@node Data
c906108c
SS
7578@chapter Examining Data
7579
7580@cindex printing data
7581@cindex examining data
7582@kindex print
7583@kindex inspect
c906108c 7584The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
7585command (abbreviated @code{p}), or its synonym @code{inspect}. It
7586evaluates and prints the value of an expression of the language your
7587program is written in (@pxref{Languages, ,Using @value{GDBN} with
78e2826b
TT
7588Different Languages}). It may also print the expression using a
7589Python-based pretty-printer (@pxref{Pretty Printing}).
c906108c
SS
7590
7591@table @code
d4f3574e
SS
7592@item print @var{expr}
7593@itemx print /@var{f} @var{expr}
7594@var{expr} is an expression (in the source language). By default the
7595value of @var{expr} is printed in a format appropriate to its data type;
c906108c 7596you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 7597@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
79a6e687 7598Formats}.
c906108c
SS
7599
7600@item print
7601@itemx print /@var{f}
15387254 7602@cindex reprint the last value
d4f3574e 7603If you omit @var{expr}, @value{GDBN} displays the last value again (from the
79a6e687 7604@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
c906108c
SS
7605conveniently inspect the same value in an alternative format.
7606@end table
7607
7608A more low-level way of examining data is with the @code{x} command.
7609It examines data in memory at a specified address and prints it in a
79a6e687 7610specified format. @xref{Memory, ,Examining Memory}.
c906108c 7611
7a292a7a 7612If you are interested in information about types, or about how the
d4f3574e
SS
7613fields of a struct or a class are declared, use the @code{ptype @var{exp}}
7614command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 7615Table}.
c906108c 7616
06fc020f
SCR
7617@cindex exploring hierarchical data structures
7618@kindex explore
7619Another way of examining values of expressions and type information is
7620through the Python extension command @code{explore} (available only if
7621the @value{GDBN} build is configured with @code{--with-python}). It
7622offers an interactive way to start at the highest level (or, the most
7623abstract level) of the data type of an expression (or, the data type
7624itself) and explore all the way down to leaf scalar values/fields
7625embedded in the higher level data types.
7626
7627@table @code
7628@item explore @var{arg}
7629@var{arg} is either an expression (in the source language), or a type
7630visible in the current context of the program being debugged.
7631@end table
7632
7633The working of the @code{explore} command can be illustrated with an
7634example. If a data type @code{struct ComplexStruct} is defined in your
7635C program as
7636
7637@smallexample
7638struct SimpleStruct
7639@{
7640 int i;
7641 double d;
7642@};
7643
7644struct ComplexStruct
7645@{
7646 struct SimpleStruct *ss_p;
7647 int arr[10];
7648@};
7649@end smallexample
7650
7651@noindent
7652followed by variable declarations as
7653
7654@smallexample
7655struct SimpleStruct ss = @{ 10, 1.11 @};
7656struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
7657@end smallexample
7658
7659@noindent
7660then, the value of the variable @code{cs} can be explored using the
7661@code{explore} command as follows.
7662
7663@smallexample
7664(gdb) explore cs
7665The value of `cs' is a struct/class of type `struct ComplexStruct' with
7666the following fields:
7667
7668 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
7669 arr = <Enter 1 to explore this field of type `int [10]'>
7670
7671Enter the field number of choice:
7672@end smallexample
7673
7674@noindent
7675Since the fields of @code{cs} are not scalar values, you are being
7676prompted to chose the field you want to explore. Let's say you choose
7677the field @code{ss_p} by entering @code{0}. Then, since this field is a
7678pointer, you will be asked if it is pointing to a single value. From
7679the declaration of @code{cs} above, it is indeed pointing to a single
7680value, hence you enter @code{y}. If you enter @code{n}, then you will
7681be asked if it were pointing to an array of values, in which case this
7682field will be explored as if it were an array.
7683
7684@smallexample
7685`cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
7686Continue exploring it as a pointer to a single value [y/n]: y
7687The value of `*(cs.ss_p)' is a struct/class of type `struct
7688SimpleStruct' with the following fields:
7689
7690 i = 10 .. (Value of type `int')
7691 d = 1.1100000000000001 .. (Value of type `double')
7692
7693Press enter to return to parent value:
7694@end smallexample
7695
7696@noindent
7697If the field @code{arr} of @code{cs} was chosen for exploration by
7698entering @code{1} earlier, then since it is as array, you will be
7699prompted to enter the index of the element in the array that you want
7700to explore.
7701
7702@smallexample
7703`cs.arr' is an array of `int'.
7704Enter the index of the element you want to explore in `cs.arr': 5
7705
7706`(cs.arr)[5]' is a scalar value of type `int'.
7707
7708(cs.arr)[5] = 4
7709
7710Press enter to return to parent value:
7711@end smallexample
7712
7713In general, at any stage of exploration, you can go deeper towards the
7714leaf values by responding to the prompts appropriately, or hit the
7715return key to return to the enclosing data structure (the @i{higher}
7716level data structure).
7717
7718Similar to exploring values, you can use the @code{explore} command to
7719explore types. Instead of specifying a value (which is typically a
7720variable name or an expression valid in the current context of the
7721program being debugged), you specify a type name. If you consider the
7722same example as above, your can explore the type
7723@code{struct ComplexStruct} by passing the argument
7724@code{struct ComplexStruct} to the @code{explore} command.
7725
7726@smallexample
7727(gdb) explore struct ComplexStruct
7728@end smallexample
7729
7730@noindent
7731By responding to the prompts appropriately in the subsequent interactive
7732session, you can explore the type @code{struct ComplexStruct} in a
7733manner similar to how the value @code{cs} was explored in the above
7734example.
7735
7736The @code{explore} command also has two sub-commands,
7737@code{explore value} and @code{explore type}. The former sub-command is
7738a way to explicitly specify that value exploration of the argument is
7739being invoked, while the latter is a way to explicitly specify that type
7740exploration of the argument is being invoked.
7741
7742@table @code
7743@item explore value @var{expr}
7744@cindex explore value
7745This sub-command of @code{explore} explores the value of the
7746expression @var{expr} (if @var{expr} is an expression valid in the
7747current context of the program being debugged). The behavior of this
7748command is identical to that of the behavior of the @code{explore}
7749command being passed the argument @var{expr}.
7750
7751@item explore type @var{arg}
7752@cindex explore type
7753This sub-command of @code{explore} explores the type of @var{arg} (if
7754@var{arg} is a type visible in the current context of program being
7755debugged), or the type of the value/expression @var{arg} (if @var{arg}
7756is an expression valid in the current context of the program being
7757debugged). If @var{arg} is a type, then the behavior of this command is
7758identical to that of the @code{explore} command being passed the
7759argument @var{arg}. If @var{arg} is an expression, then the behavior of
7760this command will be identical to that of the @code{explore} command
7761being passed the type of @var{arg} as the argument.
7762@end table
7763
c906108c
SS
7764@menu
7765* Expressions:: Expressions
6ba66d6a 7766* Ambiguous Expressions:: Ambiguous Expressions
c906108c
SS
7767* Variables:: Program variables
7768* Arrays:: Artificial arrays
7769* Output Formats:: Output formats
7770* Memory:: Examining memory
7771* Auto Display:: Automatic display
7772* Print Settings:: Print settings
4c374409 7773* Pretty Printing:: Python pretty printing
c906108c
SS
7774* Value History:: Value history
7775* Convenience Vars:: Convenience variables
a72c3253 7776* Convenience Funs:: Convenience functions
c906108c 7777* Registers:: Registers
c906108c 7778* Floating Point Hardware:: Floating point hardware
53c69bd7 7779* Vector Unit:: Vector Unit
721c2651 7780* OS Information:: Auxiliary data provided by operating system
29e57380 7781* Memory Region Attributes:: Memory region attributes
16d9dec6 7782* Dump/Restore Files:: Copy between memory and a file
384ee23f 7783* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
7784* Character Sets:: Debugging programs that use a different
7785 character set than GDB does
09d4efe1 7786* Caching Remote Data:: Data caching for remote targets
08388c79 7787* Searching Memory:: Searching memory for a sequence of bytes
c906108c
SS
7788@end menu
7789
6d2ebf8b 7790@node Expressions
c906108c
SS
7791@section Expressions
7792
7793@cindex expressions
7794@code{print} and many other @value{GDBN} commands accept an expression and
7795compute its value. Any kind of constant, variable or operator defined
7796by the programming language you are using is valid in an expression in
e2e0bcd1
JB
7797@value{GDBN}. This includes conditional expressions, function calls,
7798casts, and string constants. It also includes preprocessor macros, if
7799you compiled your program to include this information; see
7800@ref{Compilation}.
c906108c 7801
15387254 7802@cindex arrays in expressions
d4f3574e
SS
7803@value{GDBN} supports array constants in expressions input by
7804the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
63092375
DJ
7805you can use the command @code{print @{1, 2, 3@}} to create an array
7806of three integers. If you pass an array to a function or assign it
7807to a program variable, @value{GDBN} copies the array to memory that
7808is @code{malloc}ed in the target program.
c906108c 7809
c906108c
SS
7810Because C is so widespread, most of the expressions shown in examples in
7811this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
7812Languages}, for information on how to use expressions in other
7813languages.
7814
7815In this section, we discuss operators that you can use in @value{GDBN}
7816expressions regardless of your programming language.
7817
15387254 7818@cindex casts, in expressions
c906108c
SS
7819Casts are supported in all languages, not just in C, because it is so
7820useful to cast a number into a pointer in order to examine a structure
7821at that address in memory.
7822@c FIXME: casts supported---Mod2 true?
c906108c
SS
7823
7824@value{GDBN} supports these operators, in addition to those common
7825to programming languages:
7826
7827@table @code
7828@item @@
7829@samp{@@} is a binary operator for treating parts of memory as arrays.
79a6e687 7830@xref{Arrays, ,Artificial Arrays}, for more information.
c906108c
SS
7831
7832@item ::
7833@samp{::} allows you to specify a variable in terms of the file or
79a6e687 7834function where it is defined. @xref{Variables, ,Program Variables}.
c906108c
SS
7835
7836@cindex @{@var{type}@}
7837@cindex type casting memory
7838@cindex memory, viewing as typed object
7839@cindex casts, to view memory
7840@item @{@var{type}@} @var{addr}
7841Refers to an object of type @var{type} stored at address @var{addr} in
7842memory. @var{addr} may be any expression whose value is an integer or
7843pointer (but parentheses are required around binary operators, just as in
7844a cast). This construct is allowed regardless of what kind of data is
7845normally supposed to reside at @var{addr}.
7846@end table
7847
6ba66d6a
JB
7848@node Ambiguous Expressions
7849@section Ambiguous Expressions
7850@cindex ambiguous expressions
7851
7852Expressions can sometimes contain some ambiguous elements. For instance,
7853some programming languages (notably Ada, C@t{++} and Objective-C) permit
7854a single function name to be defined several times, for application in
7855different contexts. This is called @dfn{overloading}. Another example
7856involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
7857templates and is typically instantiated several times, resulting in
7858the same function name being defined in different contexts.
7859
7860In some cases and depending on the language, it is possible to adjust
7861the expression to remove the ambiguity. For instance in C@t{++}, you
7862can specify the signature of the function you want to break on, as in
7863@kbd{break @var{function}(@var{types})}. In Ada, using the fully
7864qualified name of your function often makes the expression unambiguous
7865as well.
7866
7867When an ambiguity that needs to be resolved is detected, the debugger
7868has the capability to display a menu of numbered choices for each
7869possibility, and then waits for the selection with the prompt @samp{>}.
7870The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
7871aborts the current command. If the command in which the expression was
7872used allows more than one choice to be selected, the next option in the
7873menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
7874choices.
7875
7876For example, the following session excerpt shows an attempt to set a
7877breakpoint at the overloaded symbol @code{String::after}.
7878We choose three particular definitions of that function name:
7879
7880@c FIXME! This is likely to change to show arg type lists, at least
7881@smallexample
7882@group
7883(@value{GDBP}) b String::after
7884[0] cancel
7885[1] all
7886[2] file:String.cc; line number:867
7887[3] file:String.cc; line number:860
7888[4] file:String.cc; line number:875
7889[5] file:String.cc; line number:853
7890[6] file:String.cc; line number:846
7891[7] file:String.cc; line number:735
7892> 2 4 6
7893Breakpoint 1 at 0xb26c: file String.cc, line 867.
7894Breakpoint 2 at 0xb344: file String.cc, line 875.
7895Breakpoint 3 at 0xafcc: file String.cc, line 846.
7896Multiple breakpoints were set.
7897Use the "delete" command to delete unwanted
7898 breakpoints.
7899(@value{GDBP})
7900@end group
7901@end smallexample
7902
7903@table @code
7904@kindex set multiple-symbols
7905@item set multiple-symbols @var{mode}
7906@cindex multiple-symbols menu
7907
7908This option allows you to adjust the debugger behavior when an expression
7909is ambiguous.
7910
7911By default, @var{mode} is set to @code{all}. If the command with which
7912the expression is used allows more than one choice, then @value{GDBN}
7913automatically selects all possible choices. For instance, inserting
7914a breakpoint on a function using an ambiguous name results in a breakpoint
7915inserted on each possible match. However, if a unique choice must be made,
7916then @value{GDBN} uses the menu to help you disambiguate the expression.
7917For instance, printing the address of an overloaded function will result
7918in the use of the menu.
7919
7920When @var{mode} is set to @code{ask}, the debugger always uses the menu
7921when an ambiguity is detected.
7922
7923Finally, when @var{mode} is set to @code{cancel}, the debugger reports
7924an error due to the ambiguity and the command is aborted.
7925
7926@kindex show multiple-symbols
7927@item show multiple-symbols
7928Show the current value of the @code{multiple-symbols} setting.
7929@end table
7930
6d2ebf8b 7931@node Variables
79a6e687 7932@section Program Variables
c906108c
SS
7933
7934The most common kind of expression to use is the name of a variable
7935in your program.
7936
7937Variables in expressions are understood in the selected stack frame
79a6e687 7938(@pxref{Selection, ,Selecting a Frame}); they must be either:
c906108c
SS
7939
7940@itemize @bullet
7941@item
7942global (or file-static)
7943@end itemize
7944
5d161b24 7945@noindent or
c906108c
SS
7946
7947@itemize @bullet
7948@item
7949visible according to the scope rules of the
7950programming language from the point of execution in that frame
5d161b24 7951@end itemize
c906108c
SS
7952
7953@noindent This means that in the function
7954
474c8240 7955@smallexample
c906108c
SS
7956foo (a)
7957 int a;
7958@{
7959 bar (a);
7960 @{
7961 int b = test ();
7962 bar (b);
7963 @}
7964@}
474c8240 7965@end smallexample
c906108c
SS
7966
7967@noindent
7968you can examine and use the variable @code{a} whenever your program is
7969executing within the function @code{foo}, but you can only use or
7970examine the variable @code{b} while your program is executing inside
7971the block where @code{b} is declared.
7972
7973@cindex variable name conflict
7974There is an exception: you can refer to a variable or function whose
7975scope is a single source file even if the current execution point is not
7976in this file. But it is possible to have more than one such variable or
7977function with the same name (in different source files). If that
7978happens, referring to that name has unpredictable effects. If you wish,
72384ba3 7979you can specify a static variable in a particular function or file by
15387254 7980using the colon-colon (@code{::}) notation:
c906108c 7981
d4f3574e 7982@cindex colon-colon, context for variables/functions
12c27660 7983@ifnotinfo
c906108c 7984@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 7985@cindex @code{::}, context for variables/functions
12c27660 7986@end ifnotinfo
474c8240 7987@smallexample
c906108c
SS
7988@var{file}::@var{variable}
7989@var{function}::@var{variable}
474c8240 7990@end smallexample
c906108c
SS
7991
7992@noindent
7993Here @var{file} or @var{function} is the name of the context for the
7994static @var{variable}. In the case of file names, you can use quotes to
7995make sure @value{GDBN} parses the file name as a single word---for example,
7996to print a global value of @code{x} defined in @file{f2.c}:
7997
474c8240 7998@smallexample
c906108c 7999(@value{GDBP}) p 'f2.c'::x
474c8240 8000@end smallexample
c906108c 8001
72384ba3
PH
8002The @code{::} notation is normally used for referring to
8003static variables, since you typically disambiguate uses of local variables
8004in functions by selecting the appropriate frame and using the
8005simple name of the variable. However, you may also use this notation
8006to refer to local variables in frames enclosing the selected frame:
8007
8008@smallexample
8009void
8010foo (int a)
8011@{
8012 if (a < 10)
8013 bar (a);
8014 else
8015 process (a); /* Stop here */
8016@}
8017
8018int
8019bar (int a)
8020@{
8021 foo (a + 5);
8022@}
8023@end smallexample
8024
8025@noindent
8026For example, if there is a breakpoint at the commented line,
8027here is what you might see
8028when the program stops after executing the call @code{bar(0)}:
8029
8030@smallexample
8031(@value{GDBP}) p a
8032$1 = 10
8033(@value{GDBP}) p bar::a
8034$2 = 5
8035(@value{GDBP}) up 2
8036#2 0x080483d0 in foo (a=5) at foobar.c:12
8037(@value{GDBP}) p a
8038$3 = 5
8039(@value{GDBP}) p bar::a
8040$4 = 0
8041@end smallexample
8042
b37052ae 8043@cindex C@t{++} scope resolution
72384ba3 8044These uses of @samp{::} are very rarely in conflict with the very similar
b37052ae 8045use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
8046scope resolution operator in @value{GDBN} expressions.
8047@c FIXME: Um, so what happens in one of those rare cases where it's in
8048@c conflict?? --mew
c906108c
SS
8049
8050@cindex wrong values
8051@cindex variable values, wrong
15387254
EZ
8052@cindex function entry/exit, wrong values of variables
8053@cindex optimized code, wrong values of variables
c906108c
SS
8054@quotation
8055@emph{Warning:} Occasionally, a local variable may appear to have the
8056wrong value at certain points in a function---just after entry to a new
8057scope, and just before exit.
8058@end quotation
8059You may see this problem when you are stepping by machine instructions.
8060This is because, on most machines, it takes more than one instruction to
8061set up a stack frame (including local variable definitions); if you are
8062stepping by machine instructions, variables may appear to have the wrong
8063values until the stack frame is completely built. On exit, it usually
8064also takes more than one machine instruction to destroy a stack frame;
8065after you begin stepping through that group of instructions, local
8066variable definitions may be gone.
8067
8068This may also happen when the compiler does significant optimizations.
8069To be sure of always seeing accurate values, turn off all optimization
8070when compiling.
8071
d4f3574e
SS
8072@cindex ``No symbol "foo" in current context''
8073Another possible effect of compiler optimizations is to optimize
8074unused variables out of existence, or assign variables to registers (as
8075opposed to memory addresses). Depending on the support for such cases
8076offered by the debug info format used by the compiler, @value{GDBN}
8077might not be able to display values for such local variables. If that
8078happens, @value{GDBN} will print a message like this:
8079
474c8240 8080@smallexample
d4f3574e 8081No symbol "foo" in current context.
474c8240 8082@end smallexample
d4f3574e
SS
8083
8084To solve such problems, either recompile without optimizations, or use a
8085different debug info format, if the compiler supports several such
e0f8f636
TT
8086formats. @xref{Compilation}, for more information on choosing compiler
8087options. @xref{C, ,C and C@t{++}}, for more information about debug
8088info formats that are best suited to C@t{++} programs.
d4f3574e 8089
ab1adacd
EZ
8090If you ask to print an object whose contents are unknown to
8091@value{GDBN}, e.g., because its data type is not completely specified
8092by the debug information, @value{GDBN} will say @samp{<incomplete
8093type>}. @xref{Symbols, incomplete type}, for more about this.
8094
36b11add
JK
8095If you append @kbd{@@entry} string to a function parameter name you get its
8096value at the time the function got called. If the value is not available an
8097error message is printed. Entry values are available only with some compilers.
8098Entry values are normally also printed at the function parameter list according
8099to @ref{set print entry-values}.
8100
8101@smallexample
8102Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
810329 i++;
8104(gdb) next
810530 e (i);
8106(gdb) print i
8107$1 = 31
8108(gdb) print i@@entry
8109$2 = 30
8110@end smallexample
8111
3a60f64e
JK
8112Strings are identified as arrays of @code{char} values without specified
8113signedness. Arrays of either @code{signed char} or @code{unsigned char} get
8114printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
8115@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
8116defines literal string type @code{"char"} as @code{char} without a sign.
8117For program code
8118
8119@smallexample
8120char var0[] = "A";
8121signed char var1[] = "A";
8122@end smallexample
8123
8124You get during debugging
8125@smallexample
8126(gdb) print var0
8127$1 = "A"
8128(gdb) print var1
8129$2 = @{65 'A', 0 '\0'@}
8130@end smallexample
8131
6d2ebf8b 8132@node Arrays
79a6e687 8133@section Artificial Arrays
c906108c
SS
8134
8135@cindex artificial array
15387254 8136@cindex arrays
41afff9a 8137@kindex @@@r{, referencing memory as an array}
c906108c
SS
8138It is often useful to print out several successive objects of the
8139same type in memory; a section of an array, or an array of
8140dynamically determined size for which only a pointer exists in the
8141program.
8142
8143You can do this by referring to a contiguous span of memory as an
8144@dfn{artificial array}, using the binary operator @samp{@@}. The left
8145operand of @samp{@@} should be the first element of the desired array
8146and be an individual object. The right operand should be the desired length
8147of the array. The result is an array value whose elements are all of
8148the type of the left argument. The first element is actually the left
8149argument; the second element comes from bytes of memory immediately
8150following those that hold the first element, and so on. Here is an
8151example. If a program says
8152
474c8240 8153@smallexample
c906108c 8154int *array = (int *) malloc (len * sizeof (int));
474c8240 8155@end smallexample
c906108c
SS
8156
8157@noindent
8158you can print the contents of @code{array} with
8159
474c8240 8160@smallexample
c906108c 8161p *array@@len
474c8240 8162@end smallexample
c906108c
SS
8163
8164The left operand of @samp{@@} must reside in memory. Array values made
8165with @samp{@@} in this way behave just like other arrays in terms of
8166subscripting, and are coerced to pointers when used in expressions.
8167Artificial arrays most often appear in expressions via the value history
79a6e687 8168(@pxref{Value History, ,Value History}), after printing one out.
c906108c
SS
8169
8170Another way to create an artificial array is to use a cast.
8171This re-interprets a value as if it were an array.
8172The value need not be in memory:
474c8240 8173@smallexample
c906108c
SS
8174(@value{GDBP}) p/x (short[2])0x12345678
8175$1 = @{0x1234, 0x5678@}
474c8240 8176@end smallexample
c906108c
SS
8177
8178As a convenience, if you leave the array length out (as in
c3f6f71d 8179@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 8180the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 8181@smallexample
c906108c
SS
8182(@value{GDBP}) p/x (short[])0x12345678
8183$2 = @{0x1234, 0x5678@}
474c8240 8184@end smallexample
c906108c
SS
8185
8186Sometimes the artificial array mechanism is not quite enough; in
8187moderately complex data structures, the elements of interest may not
8188actually be adjacent---for example, if you are interested in the values
8189of pointers in an array. One useful work-around in this situation is
8190to use a convenience variable (@pxref{Convenience Vars, ,Convenience
79a6e687 8191Variables}) as a counter in an expression that prints the first
c906108c
SS
8192interesting value, and then repeat that expression via @key{RET}. For
8193instance, suppose you have an array @code{dtab} of pointers to
8194structures, and you are interested in the values of a field @code{fv}
8195in each structure. Here is an example of what you might type:
8196
474c8240 8197@smallexample
c906108c
SS
8198set $i = 0
8199p dtab[$i++]->fv
8200@key{RET}
8201@key{RET}
8202@dots{}
474c8240 8203@end smallexample
c906108c 8204
6d2ebf8b 8205@node Output Formats
79a6e687 8206@section Output Formats
c906108c
SS
8207
8208@cindex formatted output
8209@cindex output formats
8210By default, @value{GDBN} prints a value according to its data type. Sometimes
8211this is not what you want. For example, you might want to print a number
8212in hex, or a pointer in decimal. Or you might want to view data in memory
8213at a certain address as a character string or as an instruction. To do
8214these things, specify an @dfn{output format} when you print a value.
8215
8216The simplest use of output formats is to say how to print a value
8217already computed. This is done by starting the arguments of the
8218@code{print} command with a slash and a format letter. The format
8219letters supported are:
8220
8221@table @code
8222@item x
8223Regard the bits of the value as an integer, and print the integer in
8224hexadecimal.
8225
8226@item d
8227Print as integer in signed decimal.
8228
8229@item u
8230Print as integer in unsigned decimal.
8231
8232@item o
8233Print as integer in octal.
8234
8235@item t
8236Print as integer in binary. The letter @samp{t} stands for ``two''.
8237@footnote{@samp{b} cannot be used because these format letters are also
8238used with the @code{x} command, where @samp{b} stands for ``byte'';
79a6e687 8239see @ref{Memory,,Examining Memory}.}
c906108c
SS
8240
8241@item a
8242@cindex unknown address, locating
3d67e040 8243@cindex locate address
c906108c
SS
8244Print as an address, both absolute in hexadecimal and as an offset from
8245the nearest preceding symbol. You can use this format used to discover
8246where (in what function) an unknown address is located:
8247
474c8240 8248@smallexample
c906108c
SS
8249(@value{GDBP}) p/a 0x54320
8250$3 = 0x54320 <_initialize_vx+396>
474c8240 8251@end smallexample
c906108c 8252
3d67e040
EZ
8253@noindent
8254The command @code{info symbol 0x54320} yields similar results.
8255@xref{Symbols, info symbol}.
8256
c906108c 8257@item c
51274035
EZ
8258Regard as an integer and print it as a character constant. This
8259prints both the numerical value and its character representation. The
8260character representation is replaced with the octal escape @samp{\nnn}
8261for characters outside the 7-bit @sc{ascii} range.
c906108c 8262
ea37ba09
DJ
8263Without this format, @value{GDBN} displays @code{char},
8264@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
8265constants. Single-byte members of vectors are displayed as integer
8266data.
8267
c906108c
SS
8268@item f
8269Regard the bits of the value as a floating point number and print
8270using typical floating point syntax.
ea37ba09
DJ
8271
8272@item s
8273@cindex printing strings
8274@cindex printing byte arrays
8275Regard as a string, if possible. With this format, pointers to single-byte
8276data are displayed as null-terminated strings and arrays of single-byte data
8277are displayed as fixed-length strings. Other values are displayed in their
8278natural types.
8279
8280Without this format, @value{GDBN} displays pointers to and arrays of
8281@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
8282strings. Single-byte members of a vector are displayed as an integer
8283array.
a6bac58e
TT
8284
8285@item r
8286@cindex raw printing
8287Print using the @samp{raw} formatting. By default, @value{GDBN} will
78e2826b
TT
8288use a Python-based pretty-printer, if one is available (@pxref{Pretty
8289Printing}). This typically results in a higher-level display of the
8290value's contents. The @samp{r} format bypasses any Python
8291pretty-printer which might exist.
c906108c
SS
8292@end table
8293
8294For example, to print the program counter in hex (@pxref{Registers}), type
8295
474c8240 8296@smallexample
c906108c 8297p/x $pc
474c8240 8298@end smallexample
c906108c
SS
8299
8300@noindent
8301Note that no space is required before the slash; this is because command
8302names in @value{GDBN} cannot contain a slash.
8303
8304To reprint the last value in the value history with a different format,
8305you can use the @code{print} command with just a format and no
8306expression. For example, @samp{p/x} reprints the last value in hex.
8307
6d2ebf8b 8308@node Memory
79a6e687 8309@section Examining Memory
c906108c
SS
8310
8311You can use the command @code{x} (for ``examine'') to examine memory in
8312any of several formats, independently of your program's data types.
8313
8314@cindex examining memory
8315@table @code
41afff9a 8316@kindex x @r{(examine memory)}
c906108c
SS
8317@item x/@var{nfu} @var{addr}
8318@itemx x @var{addr}
8319@itemx x
8320Use the @code{x} command to examine memory.
8321@end table
8322
8323@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
8324much memory to display and how to format it; @var{addr} is an
8325expression giving the address where you want to start displaying memory.
8326If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
8327Several commands set convenient defaults for @var{addr}.
8328
8329@table @r
8330@item @var{n}, the repeat count
8331The repeat count is a decimal integer; the default is 1. It specifies
8332how much memory (counting by units @var{u}) to display.
8333@c This really is **decimal**; unaffected by 'set radix' as of GDB
8334@c 4.1.2.
8335
8336@item @var{f}, the display format
51274035
EZ
8337The display format is one of the formats used by @code{print}
8338(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
ea37ba09
DJ
8339@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
8340The default is @samp{x} (hexadecimal) initially. The default changes
8341each time you use either @code{x} or @code{print}.
c906108c
SS
8342
8343@item @var{u}, the unit size
8344The unit size is any of
8345
8346@table @code
8347@item b
8348Bytes.
8349@item h
8350Halfwords (two bytes).
8351@item w
8352Words (four bytes). This is the initial default.
8353@item g
8354Giant words (eight bytes).
8355@end table
8356
8357Each time you specify a unit size with @code{x}, that size becomes the
9a22f0d0
PM
8358default unit the next time you use @code{x}. For the @samp{i} format,
8359the unit size is ignored and is normally not written. For the @samp{s} format,
8360the unit size defaults to @samp{b}, unless it is explicitly given.
8361Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
836232-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
8363Note that the results depend on the programming language of the
8364current compilation unit. If the language is C, the @samp{s}
8365modifier will use the UTF-16 encoding while @samp{w} will use
8366UTF-32. The encoding is set by the programming language and cannot
8367be altered.
c906108c
SS
8368
8369@item @var{addr}, starting display address
8370@var{addr} is the address where you want @value{GDBN} to begin displaying
8371memory. The expression need not have a pointer value (though it may);
8372it is always interpreted as an integer address of a byte of memory.
8373@xref{Expressions, ,Expressions}, for more information on expressions. The default for
8374@var{addr} is usually just after the last address examined---but several
8375other commands also set the default address: @code{info breakpoints} (to
8376the address of the last breakpoint listed), @code{info line} (to the
8377starting address of a line), and @code{print} (if you use it to display
8378a value from memory).
8379@end table
8380
8381For example, @samp{x/3uh 0x54320} is a request to display three halfwords
8382(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
8383starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
8384words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 8385@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
8386
8387Since the letters indicating unit sizes are all distinct from the
8388letters specifying output formats, you do not have to remember whether
8389unit size or format comes first; either order works. The output
8390specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
8391(However, the count @var{n} must come first; @samp{wx4} does not work.)
8392
8393Even though the unit size @var{u} is ignored for the formats @samp{s}
8394and @samp{i}, you might still want to use a count @var{n}; for example,
8395@samp{3i} specifies that you want to see three machine instructions,
a4642986
MR
8396including any operands. For convenience, especially when used with
8397the @code{display} command, the @samp{i} format also prints branch delay
8398slot instructions, if any, beyond the count specified, which immediately
8399follow the last instruction that is within the count. The command
8400@code{disassemble} gives an alternative way of inspecting machine
8401instructions; see @ref{Machine Code,,Source and Machine Code}.
c906108c
SS
8402
8403All the defaults for the arguments to @code{x} are designed to make it
8404easy to continue scanning memory with minimal specifications each time
8405you use @code{x}. For example, after you have inspected three machine
8406instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
8407with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
8408the repeat count @var{n} is used again; the other arguments default as
8409for successive uses of @code{x}.
8410
2b28d209
PP
8411When examining machine instructions, the instruction at current program
8412counter is shown with a @code{=>} marker. For example:
8413
8414@smallexample
8415(@value{GDBP}) x/5i $pc-6
8416 0x804837f <main+11>: mov %esp,%ebp
8417 0x8048381 <main+13>: push %ecx
8418 0x8048382 <main+14>: sub $0x4,%esp
8419=> 0x8048385 <main+17>: movl $0x8048460,(%esp)
8420 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
8421@end smallexample
8422
c906108c
SS
8423@cindex @code{$_}, @code{$__}, and value history
8424The addresses and contents printed by the @code{x} command are not saved
8425in the value history because there is often too much of them and they
8426would get in the way. Instead, @value{GDBN} makes these values available for
8427subsequent use in expressions as values of the convenience variables
8428@code{$_} and @code{$__}. After an @code{x} command, the last address
8429examined is available for use in expressions in the convenience variable
8430@code{$_}. The contents of that address, as examined, are available in
8431the convenience variable @code{$__}.
8432
8433If the @code{x} command has a repeat count, the address and contents saved
8434are from the last memory unit printed; this is not the same as the last
8435address printed if several units were printed on the last line of output.
8436
09d4efe1
EZ
8437@cindex remote memory comparison
8438@cindex verify remote memory image
8439When you are debugging a program running on a remote target machine
ea35711c 8440(@pxref{Remote Debugging}), you may wish to verify the program's image in the
09d4efe1
EZ
8441remote machine's memory against the executable file you downloaded to
8442the target. The @code{compare-sections} command is provided for such
8443situations.
8444
8445@table @code
8446@kindex compare-sections
8447@item compare-sections @r{[}@var{section-name}@r{]}
8448Compare the data of a loadable section @var{section-name} in the
8449executable file of the program being debugged with the same section in
8450the remote machine's memory, and report any mismatches. With no
8451arguments, compares all loadable sections. This command's
8452availability depends on the target's support for the @code{"qCRC"}
8453remote request.
8454@end table
8455
6d2ebf8b 8456@node Auto Display
79a6e687 8457@section Automatic Display
c906108c
SS
8458@cindex automatic display
8459@cindex display of expressions
8460
8461If you find that you want to print the value of an expression frequently
8462(to see how it changes), you might want to add it to the @dfn{automatic
8463display list} so that @value{GDBN} prints its value each time your program stops.
8464Each expression added to the list is given a number to identify it;
8465to remove an expression from the list, you specify that number.
8466The automatic display looks like this:
8467
474c8240 8468@smallexample
c906108c
SS
84692: foo = 38
84703: bar[5] = (struct hack *) 0x3804
474c8240 8471@end smallexample
c906108c
SS
8472
8473@noindent
8474This display shows item numbers, expressions and their current values. As with
8475displays you request manually using @code{x} or @code{print}, you can
8476specify the output format you prefer; in fact, @code{display} decides
ea37ba09
DJ
8477whether to use @code{print} or @code{x} depending your format
8478specification---it uses @code{x} if you specify either the @samp{i}
8479or @samp{s} format, or a unit size; otherwise it uses @code{print}.
c906108c
SS
8480
8481@table @code
8482@kindex display
d4f3574e
SS
8483@item display @var{expr}
8484Add the expression @var{expr} to the list of expressions to display
c906108c
SS
8485each time your program stops. @xref{Expressions, ,Expressions}.
8486
8487@code{display} does not repeat if you press @key{RET} again after using it.
8488
d4f3574e 8489@item display/@var{fmt} @var{expr}
c906108c 8490For @var{fmt} specifying only a display format and not a size or
d4f3574e 8491count, add the expression @var{expr} to the auto-display list but
c906108c 8492arrange to display it each time in the specified format @var{fmt}.
79a6e687 8493@xref{Output Formats,,Output Formats}.
c906108c
SS
8494
8495@item display/@var{fmt} @var{addr}
8496For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
8497number of units, add the expression @var{addr} as a memory address to
8498be examined each time your program stops. Examining means in effect
79a6e687 8499doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
c906108c
SS
8500@end table
8501
8502For example, @samp{display/i $pc} can be helpful, to see the machine
8503instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 8504is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
8505
8506@table @code
8507@kindex delete display
8508@kindex undisplay
8509@item undisplay @var{dnums}@dots{}
8510@itemx delete display @var{dnums}@dots{}
c9174737
PA
8511Remove items from the list of expressions to display. Specify the
8512numbers of the displays that you want affected with the command
8513argument @var{dnums}. It can be a single display number, one of the
8514numbers shown in the first field of the @samp{info display} display;
8515or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
8516
8517@code{undisplay} does not repeat if you press @key{RET} after using it.
8518(Otherwise you would just get the error @samp{No display number @dots{}}.)
8519
8520@kindex disable display
8521@item disable display @var{dnums}@dots{}
8522Disable the display of item numbers @var{dnums}. A disabled display
8523item is not printed automatically, but is not forgotten. It may be
c9174737
PA
8524enabled again later. Specify the numbers of the displays that you
8525want affected with the command argument @var{dnums}. It can be a
8526single display number, one of the numbers shown in the first field of
8527the @samp{info display} display; or it could be a range of display
8528numbers, as in @code{2-4}.
c906108c
SS
8529
8530@kindex enable display
8531@item enable display @var{dnums}@dots{}
8532Enable display of item numbers @var{dnums}. It becomes effective once
8533again in auto display of its expression, until you specify otherwise.
c9174737
PA
8534Specify the numbers of the displays that you want affected with the
8535command argument @var{dnums}. It can be a single display number, one
8536of the numbers shown in the first field of the @samp{info display}
8537display; or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
8538
8539@item display
8540Display the current values of the expressions on the list, just as is
8541done when your program stops.
8542
8543@kindex info display
8544@item info display
8545Print the list of expressions previously set up to display
8546automatically, each one with its item number, but without showing the
8547values. This includes disabled expressions, which are marked as such.
8548It also includes expressions which would not be displayed right now
8549because they refer to automatic variables not currently available.
8550@end table
8551
15387254 8552@cindex display disabled out of scope
c906108c
SS
8553If a display expression refers to local variables, then it does not make
8554sense outside the lexical context for which it was set up. Such an
8555expression is disabled when execution enters a context where one of its
8556variables is not defined. For example, if you give the command
8557@code{display last_char} while inside a function with an argument
8558@code{last_char}, @value{GDBN} displays this argument while your program
8559continues to stop inside that function. When it stops elsewhere---where
8560there is no variable @code{last_char}---the display is disabled
8561automatically. The next time your program stops where @code{last_char}
8562is meaningful, you can enable the display expression once again.
8563
6d2ebf8b 8564@node Print Settings
79a6e687 8565@section Print Settings
c906108c
SS
8566
8567@cindex format options
8568@cindex print settings
8569@value{GDBN} provides the following ways to control how arrays, structures,
8570and symbols are printed.
8571
8572@noindent
8573These settings are useful for debugging programs in any language:
8574
8575@table @code
4644b6e3 8576@kindex set print
c906108c
SS
8577@item set print address
8578@itemx set print address on
4644b6e3 8579@cindex print/don't print memory addresses
c906108c
SS
8580@value{GDBN} prints memory addresses showing the location of stack
8581traces, structure values, pointer values, breakpoints, and so forth,
8582even when it also displays the contents of those addresses. The default
8583is @code{on}. For example, this is what a stack frame display looks like with
8584@code{set print address on}:
8585
8586@smallexample
8587@group
8588(@value{GDBP}) f
8589#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
8590 at input.c:530
8591530 if (lquote != def_lquote)
8592@end group
8593@end smallexample
8594
8595@item set print address off
8596Do not print addresses when displaying their contents. For example,
8597this is the same stack frame displayed with @code{set print address off}:
8598
8599@smallexample
8600@group
8601(@value{GDBP}) set print addr off
8602(@value{GDBP}) f
8603#0 set_quotes (lq="<<", rq=">>") at input.c:530
8604530 if (lquote != def_lquote)
8605@end group
8606@end smallexample
8607
8608You can use @samp{set print address off} to eliminate all machine
8609dependent displays from the @value{GDBN} interface. For example, with
8610@code{print address off}, you should get the same text for backtraces on
8611all machines---whether or not they involve pointer arguments.
8612
4644b6e3 8613@kindex show print
c906108c
SS
8614@item show print address
8615Show whether or not addresses are to be printed.
8616@end table
8617
8618When @value{GDBN} prints a symbolic address, it normally prints the
8619closest earlier symbol plus an offset. If that symbol does not uniquely
8620identify the address (for example, it is a name whose scope is a single
8621source file), you may need to clarify. One way to do this is with
8622@code{info line}, for example @samp{info line *0x4537}. Alternately,
8623you can set @value{GDBN} to print the source file and line number when
8624it prints a symbolic address:
8625
8626@table @code
c906108c 8627@item set print symbol-filename on
9c16f35a
EZ
8628@cindex source file and line of a symbol
8629@cindex symbol, source file and line
c906108c
SS
8630Tell @value{GDBN} to print the source file name and line number of a
8631symbol in the symbolic form of an address.
8632
8633@item set print symbol-filename off
8634Do not print source file name and line number of a symbol. This is the
8635default.
8636
c906108c
SS
8637@item show print symbol-filename
8638Show whether or not @value{GDBN} will print the source file name and
8639line number of a symbol in the symbolic form of an address.
8640@end table
8641
8642Another situation where it is helpful to show symbol filenames and line
8643numbers is when disassembling code; @value{GDBN} shows you the line
8644number and source file that corresponds to each instruction.
8645
8646Also, you may wish to see the symbolic form only if the address being
8647printed is reasonably close to the closest earlier symbol:
8648
8649@table @code
c906108c 8650@item set print max-symbolic-offset @var{max-offset}
4644b6e3 8651@cindex maximum value for offset of closest symbol
c906108c
SS
8652Tell @value{GDBN} to only display the symbolic form of an address if the
8653offset between the closest earlier symbol and the address is less than
5d161b24 8654@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
8655to always print the symbolic form of an address if any symbol precedes it.
8656
c906108c
SS
8657@item show print max-symbolic-offset
8658Ask how large the maximum offset is that @value{GDBN} prints in a
8659symbolic address.
8660@end table
8661
8662@cindex wild pointer, interpreting
8663@cindex pointer, finding referent
8664If you have a pointer and you are not sure where it points, try
8665@samp{set print symbol-filename on}. Then you can determine the name
8666and source file location of the variable where it points, using
8667@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
8668For example, here @value{GDBN} shows that a variable @code{ptt} points
8669at another variable @code{t}, defined in @file{hi2.c}:
8670
474c8240 8671@smallexample
c906108c
SS
8672(@value{GDBP}) set print symbol-filename on
8673(@value{GDBP}) p/a ptt
8674$4 = 0xe008 <t in hi2.c>
474c8240 8675@end smallexample
c906108c
SS
8676
8677@quotation
8678@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
8679does not show the symbol name and filename of the referent, even with
8680the appropriate @code{set print} options turned on.
8681@end quotation
8682
9cb709b6
TT
8683You can also enable @samp{/a}-like formatting all the time using
8684@samp{set print symbol on}:
8685
8686@table @code
8687@item set print symbol on
8688Tell @value{GDBN} to print the symbol corresponding to an address, if
8689one exists.
8690
8691@item set print symbol off
8692Tell @value{GDBN} not to print the symbol corresponding to an
8693address. In this mode, @value{GDBN} will still print the symbol
8694corresponding to pointers to functions. This is the default.
8695
8696@item show print symbol
8697Show whether @value{GDBN} will display the symbol corresponding to an
8698address.
8699@end table
8700
c906108c
SS
8701Other settings control how different kinds of objects are printed:
8702
8703@table @code
c906108c
SS
8704@item set print array
8705@itemx set print array on
4644b6e3 8706@cindex pretty print arrays
c906108c
SS
8707Pretty print arrays. This format is more convenient to read,
8708but uses more space. The default is off.
8709
8710@item set print array off
8711Return to compressed format for arrays.
8712
c906108c
SS
8713@item show print array
8714Show whether compressed or pretty format is selected for displaying
8715arrays.
8716
3c9c013a
JB
8717@cindex print array indexes
8718@item set print array-indexes
8719@itemx set print array-indexes on
8720Print the index of each element when displaying arrays. May be more
8721convenient to locate a given element in the array or quickly find the
8722index of a given element in that printed array. The default is off.
8723
8724@item set print array-indexes off
8725Stop printing element indexes when displaying arrays.
8726
8727@item show print array-indexes
8728Show whether the index of each element is printed when displaying
8729arrays.
8730
c906108c 8731@item set print elements @var{number-of-elements}
4644b6e3 8732@cindex number of array elements to print
9c16f35a 8733@cindex limit on number of printed array elements
c906108c
SS
8734Set a limit on how many elements of an array @value{GDBN} will print.
8735If @value{GDBN} is printing a large array, it stops printing after it has
8736printed the number of elements set by the @code{set print elements} command.
8737This limit also applies to the display of strings.
d4f3574e 8738When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
8739Setting @var{number-of-elements} to zero means that the printing is unlimited.
8740
c906108c
SS
8741@item show print elements
8742Display the number of elements of a large array that @value{GDBN} will print.
8743If the number is 0, then the printing is unlimited.
8744
b4740add 8745@item set print frame-arguments @var{value}
a0381d3a 8746@kindex set print frame-arguments
b4740add
JB
8747@cindex printing frame argument values
8748@cindex print all frame argument values
8749@cindex print frame argument values for scalars only
8750@cindex do not print frame argument values
8751This command allows to control how the values of arguments are printed
8752when the debugger prints a frame (@pxref{Frames}). The possible
8753values are:
8754
8755@table @code
8756@item all
4f5376b2 8757The values of all arguments are printed.
b4740add
JB
8758
8759@item scalars
8760Print the value of an argument only if it is a scalar. The value of more
8761complex arguments such as arrays, structures, unions, etc, is replaced
4f5376b2
JB
8762by @code{@dots{}}. This is the default. Here is an example where
8763only scalar arguments are shown:
b4740add
JB
8764
8765@smallexample
8766#1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
8767 at frame-args.c:23
8768@end smallexample
8769
8770@item none
8771None of the argument values are printed. Instead, the value of each argument
8772is replaced by @code{@dots{}}. In this case, the example above now becomes:
8773
8774@smallexample
8775#1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
8776 at frame-args.c:23
8777@end smallexample
8778@end table
8779
4f5376b2
JB
8780By default, only scalar arguments are printed. This command can be used
8781to configure the debugger to print the value of all arguments, regardless
8782of their type. However, it is often advantageous to not print the value
8783of more complex parameters. For instance, it reduces the amount of
8784information printed in each frame, making the backtrace more readable.
8785Also, it improves performance when displaying Ada frames, because
8786the computation of large arguments can sometimes be CPU-intensive,
8787especially in large applications. Setting @code{print frame-arguments}
8788to @code{scalars} (the default) or @code{none} avoids this computation,
8789thus speeding up the display of each Ada frame.
b4740add
JB
8790
8791@item show print frame-arguments
8792Show how the value of arguments should be displayed when printing a frame.
8793
36b11add 8794@anchor{set print entry-values}
e18b2753
JK
8795@item set print entry-values @var{value}
8796@kindex set print entry-values
8797Set printing of frame argument values at function entry. In some cases
8798@value{GDBN} can determine the value of function argument which was passed by
8799the function caller, even if the value was modified inside the called function
8800and therefore is different. With optimized code, the current value could be
8801unavailable, but the entry value may still be known.
8802
8803The default value is @code{default} (see below for its description). Older
8804@value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
8805this feature will behave in the @code{default} setting the same way as with the
8806@code{no} setting.
8807
8808This functionality is currently supported only by DWARF 2 debugging format and
8809the compiler has to produce @samp{DW_TAG_GNU_call_site} tags. With
8810@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
8811this information.
8812
8813The @var{value} parameter can be one of the following:
8814
8815@table @code
8816@item no
8817Print only actual parameter values, never print values from function entry
8818point.
8819@smallexample
8820#0 equal (val=5)
8821#0 different (val=6)
8822#0 lost (val=<optimized out>)
8823#0 born (val=10)
8824#0 invalid (val=<optimized out>)
8825@end smallexample
8826
8827@item only
8828Print only parameter values from function entry point. The actual parameter
8829values are never printed.
8830@smallexample
8831#0 equal (val@@entry=5)
8832#0 different (val@@entry=5)
8833#0 lost (val@@entry=5)
8834#0 born (val@@entry=<optimized out>)
8835#0 invalid (val@@entry=<optimized out>)
8836@end smallexample
8837
8838@item preferred
8839Print only parameter values from function entry point. If value from function
8840entry point is not known while the actual value is known, print the actual
8841value for such parameter.
8842@smallexample
8843#0 equal (val@@entry=5)
8844#0 different (val@@entry=5)
8845#0 lost (val@@entry=5)
8846#0 born (val=10)
8847#0 invalid (val@@entry=<optimized out>)
8848@end smallexample
8849
8850@item if-needed
8851Print actual parameter values. If actual parameter value is not known while
8852value from function entry point is known, print the entry point value for such
8853parameter.
8854@smallexample
8855#0 equal (val=5)
8856#0 different (val=6)
8857#0 lost (val@@entry=5)
8858#0 born (val=10)
8859#0 invalid (val=<optimized out>)
8860@end smallexample
8861
8862@item both
8863Always print both the actual parameter value and its value from function entry
8864point, even if values of one or both are not available due to compiler
8865optimizations.
8866@smallexample
8867#0 equal (val=5, val@@entry=5)
8868#0 different (val=6, val@@entry=5)
8869#0 lost (val=<optimized out>, val@@entry=5)
8870#0 born (val=10, val@@entry=<optimized out>)
8871#0 invalid (val=<optimized out>, val@@entry=<optimized out>)
8872@end smallexample
8873
8874@item compact
8875Print the actual parameter value if it is known and also its value from
8876function entry point if it is known. If neither is known, print for the actual
8877value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
8878values are known and identical, print the shortened
8879@code{param=param@@entry=VALUE} notation.
8880@smallexample
8881#0 equal (val=val@@entry=5)
8882#0 different (val=6, val@@entry=5)
8883#0 lost (val@@entry=5)
8884#0 born (val=10)
8885#0 invalid (val=<optimized out>)
8886@end smallexample
8887
8888@item default
8889Always print the actual parameter value. Print also its value from function
8890entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
8891if both values are known and identical, print the shortened
8892@code{param=param@@entry=VALUE} notation.
8893@smallexample
8894#0 equal (val=val@@entry=5)
8895#0 different (val=6, val@@entry=5)
8896#0 lost (val=<optimized out>, val@@entry=5)
8897#0 born (val=10)
8898#0 invalid (val=<optimized out>)
8899@end smallexample
8900@end table
8901
8902For analysis messages on possible failures of frame argument values at function
8903entry resolution see @ref{set debug entry-values}.
8904
8905@item show print entry-values
8906Show the method being used for printing of frame argument values at function
8907entry.
8908
9c16f35a
EZ
8909@item set print repeats
8910@cindex repeated array elements
8911Set the threshold for suppressing display of repeated array
d3e8051b 8912elements. When the number of consecutive identical elements of an
9c16f35a
EZ
8913array exceeds the threshold, @value{GDBN} prints the string
8914@code{"<repeats @var{n} times>"}, where @var{n} is the number of
8915identical repetitions, instead of displaying the identical elements
8916themselves. Setting the threshold to zero will cause all elements to
8917be individually printed. The default threshold is 10.
8918
8919@item show print repeats
8920Display the current threshold for printing repeated identical
8921elements.
8922
c906108c 8923@item set print null-stop
4644b6e3 8924@cindex @sc{null} elements in arrays
c906108c 8925Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 8926@sc{null} is encountered. This is useful when large arrays actually
c906108c 8927contain only short strings.
d4f3574e 8928The default is off.
c906108c 8929
9c16f35a
EZ
8930@item show print null-stop
8931Show whether @value{GDBN} stops printing an array on the first
8932@sc{null} character.
8933
c906108c 8934@item set print pretty on
9c16f35a
EZ
8935@cindex print structures in indented form
8936@cindex indentation in structure display
5d161b24 8937Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
8938per line, like this:
8939
8940@smallexample
8941@group
8942$1 = @{
8943 next = 0x0,
8944 flags = @{
8945 sweet = 1,
8946 sour = 1
8947 @},
8948 meat = 0x54 "Pork"
8949@}
8950@end group
8951@end smallexample
8952
8953@item set print pretty off
8954Cause @value{GDBN} to print structures in a compact format, like this:
8955
8956@smallexample
8957@group
8958$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
8959meat = 0x54 "Pork"@}
8960@end group
8961@end smallexample
8962
8963@noindent
8964This is the default format.
8965
c906108c
SS
8966@item show print pretty
8967Show which format @value{GDBN} is using to print structures.
8968
c906108c 8969@item set print sevenbit-strings on
4644b6e3
EZ
8970@cindex eight-bit characters in strings
8971@cindex octal escapes in strings
c906108c
SS
8972Print using only seven-bit characters; if this option is set,
8973@value{GDBN} displays any eight-bit characters (in strings or
8974character values) using the notation @code{\}@var{nnn}. This setting is
8975best if you are working in English (@sc{ascii}) and you use the
8976high-order bit of characters as a marker or ``meta'' bit.
8977
8978@item set print sevenbit-strings off
8979Print full eight-bit characters. This allows the use of more
8980international character sets, and is the default.
8981
c906108c
SS
8982@item show print sevenbit-strings
8983Show whether or not @value{GDBN} is printing only seven-bit characters.
8984
c906108c 8985@item set print union on
4644b6e3 8986@cindex unions in structures, printing
9c16f35a
EZ
8987Tell @value{GDBN} to print unions which are contained in structures
8988and other unions. This is the default setting.
c906108c
SS
8989
8990@item set print union off
9c16f35a
EZ
8991Tell @value{GDBN} not to print unions which are contained in
8992structures and other unions. @value{GDBN} will print @code{"@{...@}"}
8993instead.
c906108c 8994
c906108c
SS
8995@item show print union
8996Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 8997structures and other unions.
c906108c
SS
8998
8999For example, given the declarations
9000
9001@smallexample
9002typedef enum @{Tree, Bug@} Species;
9003typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 9004typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
9005 Bug_forms;
9006
9007struct thing @{
9008 Species it;
9009 union @{
9010 Tree_forms tree;
9011 Bug_forms bug;
9012 @} form;
9013@};
9014
9015struct thing foo = @{Tree, @{Acorn@}@};
9016@end smallexample
9017
9018@noindent
9019with @code{set print union on} in effect @samp{p foo} would print
9020
9021@smallexample
9022$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
9023@end smallexample
9024
9025@noindent
9026and with @code{set print union off} in effect it would print
9027
9028@smallexample
9029$1 = @{it = Tree, form = @{...@}@}
9030@end smallexample
9c16f35a
EZ
9031
9032@noindent
9033@code{set print union} affects programs written in C-like languages
9034and in Pascal.
c906108c
SS
9035@end table
9036
c906108c
SS
9037@need 1000
9038@noindent
b37052ae 9039These settings are of interest when debugging C@t{++} programs:
c906108c
SS
9040
9041@table @code
4644b6e3 9042@cindex demangling C@t{++} names
c906108c
SS
9043@item set print demangle
9044@itemx set print demangle on
b37052ae 9045Print C@t{++} names in their source form rather than in the encoded
c906108c 9046(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 9047linkage. The default is on.
c906108c 9048
c906108c 9049@item show print demangle
b37052ae 9050Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 9051
c906108c
SS
9052@item set print asm-demangle
9053@itemx set print asm-demangle on
b37052ae 9054Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
9055in assembler code printouts such as instruction disassemblies.
9056The default is off.
9057
c906108c 9058@item show print asm-demangle
b37052ae 9059Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
9060or demangled form.
9061
b37052ae
EZ
9062@cindex C@t{++} symbol decoding style
9063@cindex symbol decoding style, C@t{++}
a8f24a35 9064@kindex set demangle-style
c906108c
SS
9065@item set demangle-style @var{style}
9066Choose among several encoding schemes used by different compilers to
b37052ae 9067represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
9068
9069@table @code
9070@item auto
9071Allow @value{GDBN} to choose a decoding style by inspecting your program.
891df0ea 9072This is the default.
c906108c
SS
9073
9074@item gnu
b37052ae 9075Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c
SS
9076
9077@item hp
b37052ae 9078Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
9079
9080@item lucid
b37052ae 9081Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
9082
9083@item arm
b37052ae 9084Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
9085@strong{Warning:} this setting alone is not sufficient to allow
9086debugging @code{cfront}-generated executables. @value{GDBN} would
9087require further enhancement to permit that.
9088
9089@end table
9090If you omit @var{style}, you will see a list of possible formats.
9091
c906108c 9092@item show demangle-style
b37052ae 9093Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 9094
c906108c
SS
9095@item set print object
9096@itemx set print object on
4644b6e3 9097@cindex derived type of an object, printing
9c16f35a 9098@cindex display derived types
c906108c
SS
9099When displaying a pointer to an object, identify the @emph{actual}
9100(derived) type of the object rather than the @emph{declared} type, using
625c0d47
TT
9101the virtual function table. Note that the virtual function table is
9102required---this feature can only work for objects that have run-time
9103type identification; a single virtual method in the object's declared
8264ba82
AG
9104type is sufficient. Note that this setting is also taken into account when
9105working with variable objects via MI (@pxref{GDB/MI}).
c906108c
SS
9106
9107@item set print object off
9108Display only the declared type of objects, without reference to the
9109virtual function table. This is the default setting.
9110
c906108c
SS
9111@item show print object
9112Show whether actual, or declared, object types are displayed.
9113
c906108c
SS
9114@item set print static-members
9115@itemx set print static-members on
4644b6e3 9116@cindex static members of C@t{++} objects
b37052ae 9117Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
9118
9119@item set print static-members off
b37052ae 9120Do not print static members when displaying a C@t{++} object.
c906108c 9121
c906108c 9122@item show print static-members
9c16f35a
EZ
9123Show whether C@t{++} static members are printed or not.
9124
9125@item set print pascal_static-members
9126@itemx set print pascal_static-members on
d3e8051b
EZ
9127@cindex static members of Pascal objects
9128@cindex Pascal objects, static members display
9c16f35a
EZ
9129Print static members when displaying a Pascal object. The default is on.
9130
9131@item set print pascal_static-members off
9132Do not print static members when displaying a Pascal object.
9133
9134@item show print pascal_static-members
9135Show whether Pascal static members are printed or not.
c906108c
SS
9136
9137@c These don't work with HP ANSI C++ yet.
c906108c
SS
9138@item set print vtbl
9139@itemx set print vtbl on
4644b6e3 9140@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
9141@cindex virtual functions (C@t{++}) display
9142@cindex VTBL display
b37052ae 9143Pretty print C@t{++} virtual function tables. The default is off.
c906108c 9144(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 9145ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
9146
9147@item set print vtbl off
b37052ae 9148Do not pretty print C@t{++} virtual function tables.
c906108c 9149
c906108c 9150@item show print vtbl
b37052ae 9151Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 9152@end table
c906108c 9153
4c374409
JK
9154@node Pretty Printing
9155@section Pretty Printing
9156
9157@value{GDBN} provides a mechanism to allow pretty-printing of values using
9158Python code. It greatly simplifies the display of complex objects. This
9159mechanism works for both MI and the CLI.
9160
7b51bc51
DE
9161@menu
9162* Pretty-Printer Introduction:: Introduction to pretty-printers
9163* Pretty-Printer Example:: An example pretty-printer
9164* Pretty-Printer Commands:: Pretty-printer commands
9165@end menu
9166
9167@node Pretty-Printer Introduction
9168@subsection Pretty-Printer Introduction
9169
9170When @value{GDBN} prints a value, it first sees if there is a pretty-printer
9171registered for the value. If there is then @value{GDBN} invokes the
9172pretty-printer to print the value. Otherwise the value is printed normally.
9173
9174Pretty-printers are normally named. This makes them easy to manage.
9175The @samp{info pretty-printer} command will list all the installed
9176pretty-printers with their names.
9177If a pretty-printer can handle multiple data types, then its
9178@dfn{subprinters} are the printers for the individual data types.
9179Each such subprinter has its own name.
4e04c971 9180The format of the name is @var{printer-name};@var{subprinter-name}.
7b51bc51
DE
9181
9182Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
9183Typically they are automatically loaded and registered when the corresponding
9184debug information is loaded, thus making them available without having to
9185do anything special.
9186
9187There are three places where a pretty-printer can be registered.
9188
9189@itemize @bullet
9190@item
9191Pretty-printers registered globally are available when debugging
9192all inferiors.
9193
9194@item
9195Pretty-printers registered with a program space are available only
9196when debugging that program.
9197@xref{Progspaces In Python}, for more details on program spaces in Python.
9198
9199@item
9200Pretty-printers registered with an objfile are loaded and unloaded
9201with the corresponding objfile (e.g., shared library).
9202@xref{Objfiles In Python}, for more details on objfiles in Python.
9203@end itemize
9204
9205@xref{Selecting Pretty-Printers}, for further information on how
9206pretty-printers are selected,
9207
9208@xref{Writing a Pretty-Printer}, for implementing pretty printers
9209for new types.
9210
9211@node Pretty-Printer Example
9212@subsection Pretty-Printer Example
9213
9214Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
4c374409
JK
9215
9216@smallexample
9217(@value{GDBP}) print s
9218$1 = @{
9219 static npos = 4294967295,
9220 _M_dataplus = @{
9221 <std::allocator<char>> = @{
9222 <__gnu_cxx::new_allocator<char>> = @{
9223 <No data fields>@}, <No data fields>
9224 @},
9225 members of std::basic_string<char, std::char_traits<char>,
9226 std::allocator<char> >::_Alloc_hider:
9227 _M_p = 0x804a014 "abcd"
9228 @}
9229@}
9230@end smallexample
9231
9232With a pretty-printer for @code{std::string} only the contents are printed:
9233
9234@smallexample
9235(@value{GDBP}) print s
9236$2 = "abcd"
9237@end smallexample
9238
7b51bc51
DE
9239@node Pretty-Printer Commands
9240@subsection Pretty-Printer Commands
9241@cindex pretty-printer commands
9242
9243@table @code
9244@kindex info pretty-printer
9245@item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9246Print the list of installed pretty-printers.
9247This includes disabled pretty-printers, which are marked as such.
9248
9249@var{object-regexp} is a regular expression matching the objects
9250whose pretty-printers to list.
9251Objects can be @code{global}, the program space's file
9252(@pxref{Progspaces In Python}),
9253and the object files within that program space (@pxref{Objfiles In Python}).
9254@xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
9255looks up a printer from these three objects.
9256
9257@var{name-regexp} is a regular expression matching the name of the printers
9258to list.
9259
9260@kindex disable pretty-printer
9261@item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9262Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
9263A disabled pretty-printer is not forgotten, it may be enabled again later.
9264
9265@kindex enable pretty-printer
9266@item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9267Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
9268@end table
9269
9270Example:
9271
9272Suppose we have three pretty-printers installed: one from library1.so
9273named @code{foo} that prints objects of type @code{foo}, and
9274another from library2.so named @code{bar} that prints two types of objects,
9275@code{bar1} and @code{bar2}.
9276
9277@smallexample
9278(gdb) info pretty-printer
9279library1.so:
9280 foo
9281library2.so:
9282 bar
9283 bar1
9284 bar2
9285(gdb) info pretty-printer library2
9286library2.so:
9287 bar
9288 bar1
9289 bar2
9290(gdb) disable pretty-printer library1
92911 printer disabled
92922 of 3 printers enabled
9293(gdb) info pretty-printer
9294library1.so:
9295 foo [disabled]
9296library2.so:
9297 bar
9298 bar1
9299 bar2
9300(gdb) disable pretty-printer library2 bar:bar1
93011 printer disabled
93021 of 3 printers enabled
9303(gdb) info pretty-printer library2
9304library1.so:
9305 foo [disabled]
9306library2.so:
9307 bar
9308 bar1 [disabled]
9309 bar2
9310(gdb) disable pretty-printer library2 bar
93111 printer disabled
93120 of 3 printers enabled
9313(gdb) info pretty-printer library2
9314library1.so:
9315 foo [disabled]
9316library2.so:
9317 bar [disabled]
9318 bar1 [disabled]
9319 bar2
9320@end smallexample
9321
9322Note that for @code{bar} the entire printer can be disabled,
9323as can each individual subprinter.
4c374409 9324
6d2ebf8b 9325@node Value History
79a6e687 9326@section Value History
c906108c
SS
9327
9328@cindex value history
9c16f35a 9329@cindex history of values printed by @value{GDBN}
5d161b24
DB
9330Values printed by the @code{print} command are saved in the @value{GDBN}
9331@dfn{value history}. This allows you to refer to them in other expressions.
9332Values are kept until the symbol table is re-read or discarded
9333(for example with the @code{file} or @code{symbol-file} commands).
9334When the symbol table changes, the value history is discarded,
9335since the values may contain pointers back to the types defined in the
c906108c
SS
9336symbol table.
9337
9338@cindex @code{$}
9339@cindex @code{$$}
9340@cindex history number
9341The values printed are given @dfn{history numbers} by which you can
9342refer to them. These are successive integers starting with one.
9343@code{print} shows you the history number assigned to a value by
9344printing @samp{$@var{num} = } before the value; here @var{num} is the
9345history number.
9346
9347To refer to any previous value, use @samp{$} followed by the value's
9348history number. The way @code{print} labels its output is designed to
9349remind you of this. Just @code{$} refers to the most recent value in
9350the history, and @code{$$} refers to the value before that.
9351@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
9352is the value just prior to @code{$$}, @code{$$1} is equivalent to
9353@code{$$}, and @code{$$0} is equivalent to @code{$}.
9354
9355For example, suppose you have just printed a pointer to a structure and
9356want to see the contents of the structure. It suffices to type
9357
474c8240 9358@smallexample
c906108c 9359p *$
474c8240 9360@end smallexample
c906108c
SS
9361
9362If you have a chain of structures where the component @code{next} points
9363to the next one, you can print the contents of the next one with this:
9364
474c8240 9365@smallexample
c906108c 9366p *$.next
474c8240 9367@end smallexample
c906108c
SS
9368
9369@noindent
9370You can print successive links in the chain by repeating this
9371command---which you can do by just typing @key{RET}.
9372
9373Note that the history records values, not expressions. If the value of
9374@code{x} is 4 and you type these commands:
9375
474c8240 9376@smallexample
c906108c
SS
9377print x
9378set x=5
474c8240 9379@end smallexample
c906108c
SS
9380
9381@noindent
9382then the value recorded in the value history by the @code{print} command
9383remains 4 even though the value of @code{x} has changed.
9384
9385@table @code
9386@kindex show values
9387@item show values
9388Print the last ten values in the value history, with their item numbers.
9389This is like @samp{p@ $$9} repeated ten times, except that @code{show
9390values} does not change the history.
9391
9392@item show values @var{n}
9393Print ten history values centered on history item number @var{n}.
9394
9395@item show values +
9396Print ten history values just after the values last printed. If no more
9397values are available, @code{show values +} produces no display.
9398@end table
9399
9400Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
9401same effect as @samp{show values +}.
9402
6d2ebf8b 9403@node Convenience Vars
79a6e687 9404@section Convenience Variables
c906108c
SS
9405
9406@cindex convenience variables
9c16f35a 9407@cindex user-defined variables
c906108c
SS
9408@value{GDBN} provides @dfn{convenience variables} that you can use within
9409@value{GDBN} to hold on to a value and refer to it later. These variables
9410exist entirely within @value{GDBN}; they are not part of your program, and
9411setting a convenience variable has no direct effect on further execution
9412of your program. That is why you can use them freely.
9413
9414Convenience variables are prefixed with @samp{$}. Any name preceded by
9415@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 9416the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c 9417(Value history references, in contrast, are @emph{numbers} preceded
79a6e687 9418by @samp{$}. @xref{Value History, ,Value History}.)
c906108c
SS
9419
9420You can save a value in a convenience variable with an assignment
9421expression, just as you would set a variable in your program.
9422For example:
9423
474c8240 9424@smallexample
c906108c 9425set $foo = *object_ptr
474c8240 9426@end smallexample
c906108c
SS
9427
9428@noindent
9429would save in @code{$foo} the value contained in the object pointed to by
9430@code{object_ptr}.
9431
9432Using a convenience variable for the first time creates it, but its
9433value is @code{void} until you assign a new value. You can alter the
9434value with another assignment at any time.
9435
9436Convenience variables have no fixed types. You can assign a convenience
9437variable any type of value, including structures and arrays, even if
9438that variable already has a value of a different type. The convenience
9439variable, when used as an expression, has the type of its current value.
9440
9441@table @code
9442@kindex show convenience
f47f77df 9443@cindex show all user variables and functions
c906108c 9444@item show convenience
f47f77df
DE
9445Print a list of convenience variables used so far, and their values,
9446as well as a list of the convenience functions.
d4f3574e 9447Abbreviated @code{show conv}.
53e5f3cf
AS
9448
9449@kindex init-if-undefined
9450@cindex convenience variables, initializing
9451@item init-if-undefined $@var{variable} = @var{expression}
9452Set a convenience variable if it has not already been set. This is useful
9453for user-defined commands that keep some state. It is similar, in concept,
9454to using local static variables with initializers in C (except that
9455convenience variables are global). It can also be used to allow users to
9456override default values used in a command script.
9457
9458If the variable is already defined then the expression is not evaluated so
9459any side-effects do not occur.
c906108c
SS
9460@end table
9461
9462One of the ways to use a convenience variable is as a counter to be
9463incremented or a pointer to be advanced. For example, to print
9464a field from successive elements of an array of structures:
9465
474c8240 9466@smallexample
c906108c
SS
9467set $i = 0
9468print bar[$i++]->contents
474c8240 9469@end smallexample
c906108c 9470
d4f3574e
SS
9471@noindent
9472Repeat that command by typing @key{RET}.
c906108c
SS
9473
9474Some convenience variables are created automatically by @value{GDBN} and given
9475values likely to be useful.
9476
9477@table @code
41afff9a 9478@vindex $_@r{, convenience variable}
c906108c
SS
9479@item $_
9480The variable @code{$_} is automatically set by the @code{x} command to
79a6e687 9481the last address examined (@pxref{Memory, ,Examining Memory}). Other
c906108c
SS
9482commands which provide a default address for @code{x} to examine also
9483set @code{$_} to that address; these commands include @code{info line}
9484and @code{info breakpoint}. The type of @code{$_} is @code{void *}
9485except when set by the @code{x} command, in which case it is a pointer
9486to the type of @code{$__}.
9487
41afff9a 9488@vindex $__@r{, convenience variable}
c906108c
SS
9489@item $__
9490The variable @code{$__} is automatically set by the @code{x} command
9491to the value found in the last address examined. Its type is chosen
9492to match the format in which the data was printed.
9493
9494@item $_exitcode
41afff9a 9495@vindex $_exitcode@r{, convenience variable}
c906108c
SS
9496The variable @code{$_exitcode} is automatically set to the exit code when
9497the program being debugged terminates.
4aa995e1 9498
62e5f89c
SDJ
9499@item $_probe_argc
9500@itemx $_probe_arg0@dots{}$_probe_arg11
9501Arguments to a static probe. @xref{Static Probe Points}.
9502
0fb4aa4b
PA
9503@item $_sdata
9504@vindex $_sdata@r{, inspect, convenience variable}
9505The variable @code{$_sdata} contains extra collected static tracepoint
9506data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
9507@code{$_sdata} could be empty, if not inspecting a trace buffer, or
9508if extra static tracepoint data has not been collected.
9509
4aa995e1
PA
9510@item $_siginfo
9511@vindex $_siginfo@r{, convenience variable}
ec7e75e7
PP
9512The variable @code{$_siginfo} contains extra signal information
9513(@pxref{extra signal information}). Note that @code{$_siginfo}
9514could be empty, if the application has not yet received any signals.
9515For example, it will be empty before you execute the @code{run} command.
711e434b
PM
9516
9517@item $_tlb
9518@vindex $_tlb@r{, convenience variable}
9519The variable @code{$_tlb} is automatically set when debugging
9520applications running on MS-Windows in native mode or connected to
9521gdbserver that supports the @code{qGetTIBAddr} request.
9522@xref{General Query Packets}.
9523This variable contains the address of the thread information block.
9524
c906108c
SS
9525@end table
9526
53a5351d
JM
9527On HP-UX systems, if you refer to a function or variable name that
9528begins with a dollar sign, @value{GDBN} searches for a user or system
9529name first, before it searches for a convenience variable.
c906108c 9530
a72c3253
DE
9531@node Convenience Funs
9532@section Convenience Functions
9533
bc3b79fd
TJB
9534@cindex convenience functions
9535@value{GDBN} also supplies some @dfn{convenience functions}. These
9536have a syntax similar to convenience variables. A convenience
9537function can be used in an expression just like an ordinary function;
9538however, a convenience function is implemented internally to
9539@value{GDBN}.
9540
a72c3253
DE
9541These functions require @value{GDBN} to be configured with
9542@code{Python} support.
9543
9544@table @code
9545
9546@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
9547@findex $_memeq@r{, convenience function}
9548Returns one if the @var{length} bytes at the addresses given by
9549@var{buf1} and @var{buf2} are equal.
9550Otherwise it returns zero.
9551
9552@item $_regex(@var{str}, @var{regex})
9553@findex $_regex@r{, convenience function}
9554Returns one if the string @var{str} matches the regular expression
9555@var{regex}. Otherwise it returns zero.
9556The syntax of the regular expression is that specified by @code{Python}'s
9557regular expression support.
9558
9559@item $_streq(@var{str1}, @var{str2})
9560@findex $_streq@r{, convenience function}
9561Returns one if the strings @var{str1} and @var{str2} are equal.
9562Otherwise it returns zero.
9563
9564@item $_strlen(@var{str})
9565@findex $_strlen@r{, convenience function}
9566Returns the length of string @var{str}.
9567
9568@end table
9569
9570@value{GDBN} provides the ability to list and get help on
9571convenience functions.
9572
bc3b79fd
TJB
9573@table @code
9574@item help function
9575@kindex help function
9576@cindex show all convenience functions
9577Print a list of all convenience functions.
9578@end table
9579
6d2ebf8b 9580@node Registers
c906108c
SS
9581@section Registers
9582
9583@cindex registers
9584You can refer to machine register contents, in expressions, as variables
9585with names starting with @samp{$}. The names of registers are different
9586for each machine; use @code{info registers} to see the names used on
9587your machine.
9588
9589@table @code
9590@kindex info registers
9591@item info registers
9592Print the names and values of all registers except floating-point
c85508ee 9593and vector registers (in the selected stack frame).
c906108c
SS
9594
9595@kindex info all-registers
9596@cindex floating point registers
9597@item info all-registers
9598Print the names and values of all registers, including floating-point
c85508ee 9599and vector registers (in the selected stack frame).
c906108c
SS
9600
9601@item info registers @var{regname} @dots{}
9602Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
9603As discussed in detail below, register values are normally relative to
9604the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
9605the machine you are using, with or without the initial @samp{$}.
9606@end table
9607
e09f16f9
EZ
9608@cindex stack pointer register
9609@cindex program counter register
9610@cindex process status register
9611@cindex frame pointer register
9612@cindex standard registers
c906108c
SS
9613@value{GDBN} has four ``standard'' register names that are available (in
9614expressions) on most machines---whenever they do not conflict with an
9615architecture's canonical mnemonics for registers. The register names
9616@code{$pc} and @code{$sp} are used for the program counter register and
9617the stack pointer. @code{$fp} is used for a register that contains a
9618pointer to the current stack frame, and @code{$ps} is used for a
9619register that contains the processor status. For example,
9620you could print the program counter in hex with
9621
474c8240 9622@smallexample
c906108c 9623p/x $pc
474c8240 9624@end smallexample
c906108c
SS
9625
9626@noindent
9627or print the instruction to be executed next with
9628
474c8240 9629@smallexample
c906108c 9630x/i $pc
474c8240 9631@end smallexample
c906108c
SS
9632
9633@noindent
9634or add four to the stack pointer@footnote{This is a way of removing
9635one word from the stack, on machines where stacks grow downward in
9636memory (most machines, nowadays). This assumes that the innermost
9637stack frame is selected; setting @code{$sp} is not allowed when other
9638stack frames are selected. To pop entire frames off the stack,
9639regardless of machine architecture, use @code{return};
79a6e687 9640see @ref{Returning, ,Returning from a Function}.} with
c906108c 9641
474c8240 9642@smallexample
c906108c 9643set $sp += 4
474c8240 9644@end smallexample
c906108c
SS
9645
9646Whenever possible, these four standard register names are available on
9647your machine even though the machine has different canonical mnemonics,
9648so long as there is no conflict. The @code{info registers} command
9649shows the canonical names. For example, on the SPARC, @code{info
9650registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
9651can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
9652is an alias for the @sc{eflags} register.
c906108c
SS
9653
9654@value{GDBN} always considers the contents of an ordinary register as an
9655integer when the register is examined in this way. Some machines have
9656special registers which can hold nothing but floating point; these
9657registers are considered to have floating point values. There is no way
9658to refer to the contents of an ordinary register as floating point value
9659(although you can @emph{print} it as a floating point value with
9660@samp{print/f $@var{regname}}).
9661
9662Some registers have distinct ``raw'' and ``virtual'' data formats. This
9663means that the data format in which the register contents are saved by
9664the operating system is not the same one that your program normally
9665sees. For example, the registers of the 68881 floating point
9666coprocessor are always saved in ``extended'' (raw) format, but all C
9667programs expect to work with ``double'' (virtual) format. In such
5d161b24 9668cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
9669that makes sense for your program), but the @code{info registers} command
9670prints the data in both formats.
9671
36b80e65
EZ
9672@cindex SSE registers (x86)
9673@cindex MMX registers (x86)
9674Some machines have special registers whose contents can be interpreted
9675in several different ways. For example, modern x86-based machines
9676have SSE and MMX registers that can hold several values packed
9677together in several different formats. @value{GDBN} refers to such
9678registers in @code{struct} notation:
9679
9680@smallexample
9681(@value{GDBP}) print $xmm1
9682$1 = @{
9683 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
9684 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
9685 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
9686 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
9687 v4_int32 = @{0, 20657912, 11, 13@},
9688 v2_int64 = @{88725056443645952, 55834574859@},
9689 uint128 = 0x0000000d0000000b013b36f800000000
9690@}
9691@end smallexample
9692
9693@noindent
9694To set values of such registers, you need to tell @value{GDBN} which
9695view of the register you wish to change, as if you were assigning
9696value to a @code{struct} member:
9697
9698@smallexample
9699 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
9700@end smallexample
9701
c906108c 9702Normally, register values are relative to the selected stack frame
79a6e687 9703(@pxref{Selection, ,Selecting a Frame}). This means that you get the
c906108c
SS
9704value that the register would contain if all stack frames farther in
9705were exited and their saved registers restored. In order to see the
9706true contents of hardware registers, you must select the innermost
9707frame (with @samp{frame 0}).
9708
9709However, @value{GDBN} must deduce where registers are saved, from the machine
9710code generated by your compiler. If some registers are not saved, or if
9711@value{GDBN} is unable to locate the saved registers, the selected stack
9712frame makes no difference.
9713
6d2ebf8b 9714@node Floating Point Hardware
79a6e687 9715@section Floating Point Hardware
c906108c
SS
9716@cindex floating point
9717
9718Depending on the configuration, @value{GDBN} may be able to give
9719you more information about the status of the floating point hardware.
9720
9721@table @code
9722@kindex info float
9723@item info float
9724Display hardware-dependent information about the floating
9725point unit. The exact contents and layout vary depending on the
9726floating point chip. Currently, @samp{info float} is supported on
9727the ARM and x86 machines.
9728@end table
c906108c 9729
e76f1f2e
AC
9730@node Vector Unit
9731@section Vector Unit
9732@cindex vector unit
9733
9734Depending on the configuration, @value{GDBN} may be able to give you
9735more information about the status of the vector unit.
9736
9737@table @code
9738@kindex info vector
9739@item info vector
9740Display information about the vector unit. The exact contents and
9741layout vary depending on the hardware.
9742@end table
9743
721c2651 9744@node OS Information
79a6e687 9745@section Operating System Auxiliary Information
721c2651
EZ
9746@cindex OS information
9747
9748@value{GDBN} provides interfaces to useful OS facilities that can help
9749you debug your program.
9750
b383017d
RM
9751@cindex auxiliary vector
9752@cindex vector, auxiliary
b383017d
RM
9753Some operating systems supply an @dfn{auxiliary vector} to programs at
9754startup. This is akin to the arguments and environment that you
9755specify for a program, but contains a system-dependent variety of
9756binary values that tell system libraries important details about the
9757hardware, operating system, and process. Each value's purpose is
9758identified by an integer tag; the meanings are well-known but system-specific.
9759Depending on the configuration and operating system facilities,
9c16f35a
EZ
9760@value{GDBN} may be able to show you this information. For remote
9761targets, this functionality may further depend on the remote stub's
427c3a89
DJ
9762support of the @samp{qXfer:auxv:read} packet, see
9763@ref{qXfer auxiliary vector read}.
b383017d
RM
9764
9765@table @code
9766@kindex info auxv
9767@item info auxv
9768Display the auxiliary vector of the inferior, which can be either a
e4937fc1 9769live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
9770numerically, and also shows names and text descriptions for recognized
9771tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 9772pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
9773most appropriate form for a recognized tag, and in hexadecimal for
9774an unrecognized tag.
9775@end table
9776
85d4a676
SS
9777On some targets, @value{GDBN} can access operating system-specific
9778information and show it to you. The types of information available
9779will differ depending on the type of operating system running on the
9780target. The mechanism used to fetch the data is described in
9781@ref{Operating System Information}. For remote targets, this
9782functionality depends on the remote stub's support of the
07e059b5
VP
9783@samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
9784
9785@table @code
a61408f8 9786@kindex info os
85d4a676
SS
9787@item info os @var{infotype}
9788
9789Display OS information of the requested type.
a61408f8 9790
85d4a676
SS
9791On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
9792
9793@anchor{linux info os infotypes}
9794@table @code
07e059b5 9795@kindex info os processes
85d4a676 9796@item processes
07e059b5 9797Display the list of processes on the target. For each process,
85d4a676
SS
9798@value{GDBN} prints the process identifier, the name of the user, the
9799command corresponding to the process, and the list of processor cores
9800that the process is currently running on. (To understand what these
9801properties mean, for this and the following info types, please consult
9802the general @sc{gnu}/Linux documentation.)
9803
9804@kindex info os procgroups
9805@item procgroups
9806Display the list of process groups on the target. For each process,
9807@value{GDBN} prints the identifier of the process group that it belongs
9808to, the command corresponding to the process group leader, the process
9809identifier, and the command line of the process. The list is sorted
9810first by the process group identifier, then by the process identifier,
9811so that processes belonging to the same process group are grouped together
9812and the process group leader is listed first.
9813
9814@kindex info os threads
9815@item threads
9816Display the list of threads running on the target. For each thread,
9817@value{GDBN} prints the identifier of the process that the thread
9818belongs to, the command of the process, the thread identifier, and the
9819processor core that it is currently running on. The main thread of a
9820process is not listed.
9821
9822@kindex info os files
9823@item files
9824Display the list of open file descriptors on the target. For each
9825file descriptor, @value{GDBN} prints the identifier of the process
9826owning the descriptor, the command of the owning process, the value
9827of the descriptor, and the target of the descriptor.
9828
9829@kindex info os sockets
9830@item sockets
9831Display the list of Internet-domain sockets on the target. For each
9832socket, @value{GDBN} prints the address and port of the local and
9833remote endpoints, the current state of the connection, the creator of
9834the socket, the IP address family of the socket, and the type of the
9835connection.
9836
9837@kindex info os shm
9838@item shm
9839Display the list of all System V shared-memory regions on the target.
9840For each shared-memory region, @value{GDBN} prints the region key,
9841the shared-memory identifier, the access permissions, the size of the
9842region, the process that created the region, the process that last
9843attached to or detached from the region, the current number of live
9844attaches to the region, and the times at which the region was last
9845attached to, detach from, and changed.
9846
9847@kindex info os semaphores
9848@item semaphores
9849Display the list of all System V semaphore sets on the target. For each
9850semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
9851set identifier, the access permissions, the number of semaphores in the
9852set, the user and group of the owner and creator of the semaphore set,
9853and the times at which the semaphore set was operated upon and changed.
9854
9855@kindex info os msg
9856@item msg
9857Display the list of all System V message queues on the target. For each
9858message queue, @value{GDBN} prints the message queue key, the message
9859queue identifier, the access permissions, the current number of bytes
9860on the queue, the current number of messages on the queue, the processes
9861that last sent and received a message on the queue, the user and group
9862of the owner and creator of the message queue, the times at which a
9863message was last sent and received on the queue, and the time at which
9864the message queue was last changed.
9865
9866@kindex info os modules
9867@item modules
9868Display the list of all loaded kernel modules on the target. For each
9869module, @value{GDBN} prints the module name, the size of the module in
9870bytes, the number of times the module is used, the dependencies of the
9871module, the status of the module, and the address of the loaded module
9872in memory.
9873@end table
9874
9875@item info os
9876If @var{infotype} is omitted, then list the possible values for
9877@var{infotype} and the kind of OS information available for each
9878@var{infotype}. If the target does not return a list of possible
9879types, this command will report an error.
07e059b5 9880@end table
721c2651 9881
29e57380 9882@node Memory Region Attributes
79a6e687 9883@section Memory Region Attributes
29e57380
C
9884@cindex memory region attributes
9885
b383017d 9886@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
9887required by regions of your target's memory. @value{GDBN} uses
9888attributes to determine whether to allow certain types of memory
9889accesses; whether to use specific width accesses; and whether to cache
9890target memory. By default the description of memory regions is
9891fetched from the target (if the current target supports this), but the
9892user can override the fetched regions.
29e57380
C
9893
9894Defined memory regions can be individually enabled and disabled. When a
9895memory region is disabled, @value{GDBN} uses the default attributes when
9896accessing memory in that region. Similarly, if no memory regions have
9897been defined, @value{GDBN} uses the default attributes when accessing
9898all memory.
9899
b383017d 9900When a memory region is defined, it is given a number to identify it;
29e57380
C
9901to enable, disable, or remove a memory region, you specify that number.
9902
9903@table @code
9904@kindex mem
bfac230e 9905@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
9906Define a memory region bounded by @var{lower} and @var{upper} with
9907attributes @var{attributes}@dots{}, and add it to the list of regions
9908monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
d3e8051b 9909case: it is treated as the target's maximum memory address.
bfac230e 9910(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 9911
fd79ecee
DJ
9912@item mem auto
9913Discard any user changes to the memory regions and use target-supplied
9914regions, if available, or no regions if the target does not support.
9915
29e57380
C
9916@kindex delete mem
9917@item delete mem @var{nums}@dots{}
09d4efe1
EZ
9918Remove memory regions @var{nums}@dots{} from the list of regions
9919monitored by @value{GDBN}.
29e57380
C
9920
9921@kindex disable mem
9922@item disable mem @var{nums}@dots{}
09d4efe1 9923Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 9924A disabled memory region is not forgotten.
29e57380
C
9925It may be enabled again later.
9926
9927@kindex enable mem
9928@item enable mem @var{nums}@dots{}
09d4efe1 9929Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
9930
9931@kindex info mem
9932@item info mem
9933Print a table of all defined memory regions, with the following columns
09d4efe1 9934for each region:
29e57380
C
9935
9936@table @emph
9937@item Memory Region Number
9938@item Enabled or Disabled.
b383017d 9939Enabled memory regions are marked with @samp{y}.
29e57380
C
9940Disabled memory regions are marked with @samp{n}.
9941
9942@item Lo Address
9943The address defining the inclusive lower bound of the memory region.
9944
9945@item Hi Address
9946The address defining the exclusive upper bound of the memory region.
9947
9948@item Attributes
9949The list of attributes set for this memory region.
9950@end table
9951@end table
9952
9953
9954@subsection Attributes
9955
b383017d 9956@subsubsection Memory Access Mode
29e57380
C
9957The access mode attributes set whether @value{GDBN} may make read or
9958write accesses to a memory region.
9959
9960While these attributes prevent @value{GDBN} from performing invalid
9961memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 9962etc.@: from accessing memory.
29e57380
C
9963
9964@table @code
9965@item ro
9966Memory is read only.
9967@item wo
9968Memory is write only.
9969@item rw
6ca652b0 9970Memory is read/write. This is the default.
29e57380
C
9971@end table
9972
9973@subsubsection Memory Access Size
d3e8051b 9974The access size attribute tells @value{GDBN} to use specific sized
29e57380
C
9975accesses in the memory region. Often memory mapped device registers
9976require specific sized accesses. If no access size attribute is
9977specified, @value{GDBN} may use accesses of any size.
9978
9979@table @code
9980@item 8
9981Use 8 bit memory accesses.
9982@item 16
9983Use 16 bit memory accesses.
9984@item 32
9985Use 32 bit memory accesses.
9986@item 64
9987Use 64 bit memory accesses.
9988@end table
9989
9990@c @subsubsection Hardware/Software Breakpoints
9991@c The hardware/software breakpoint attributes set whether @value{GDBN}
9992@c will use hardware or software breakpoints for the internal breakpoints
9993@c used by the step, next, finish, until, etc. commands.
9994@c
9995@c @table @code
9996@c @item hwbreak
b383017d 9997@c Always use hardware breakpoints
29e57380
C
9998@c @item swbreak (default)
9999@c @end table
10000
10001@subsubsection Data Cache
10002The data cache attributes set whether @value{GDBN} will cache target
10003memory. While this generally improves performance by reducing debug
10004protocol overhead, it can lead to incorrect results because @value{GDBN}
10005does not know about volatile variables or memory mapped device
10006registers.
10007
10008@table @code
10009@item cache
b383017d 10010Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
10011@item nocache
10012Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
10013@end table
10014
4b5752d0
VP
10015@subsection Memory Access Checking
10016@value{GDBN} can be instructed to refuse accesses to memory that is
10017not explicitly described. This can be useful if accessing such
10018regions has undesired effects for a specific target, or to provide
10019better error checking. The following commands control this behaviour.
10020
10021@table @code
10022@kindex set mem inaccessible-by-default
10023@item set mem inaccessible-by-default [on|off]
10024If @code{on} is specified, make @value{GDBN} treat memory not
10025explicitly described by the memory ranges as non-existent and refuse accesses
10026to such memory. The checks are only performed if there's at least one
10027memory range defined. If @code{off} is specified, make @value{GDBN}
10028treat the memory not explicitly described by the memory ranges as RAM.
56cf5405 10029The default value is @code{on}.
4b5752d0
VP
10030@kindex show mem inaccessible-by-default
10031@item show mem inaccessible-by-default
10032Show the current handling of accesses to unknown memory.
10033@end table
10034
10035
29e57380 10036@c @subsubsection Memory Write Verification
b383017d 10037@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
10038@c will re-reads data after each write to verify the write was successful.
10039@c
10040@c @table @code
10041@c @item verify
10042@c @item noverify (default)
10043@c @end table
10044
16d9dec6 10045@node Dump/Restore Files
79a6e687 10046@section Copy Between Memory and a File
16d9dec6
MS
10047@cindex dump/restore files
10048@cindex append data to a file
10049@cindex dump data to a file
10050@cindex restore data from a file
16d9dec6 10051
df5215a6
JB
10052You can use the commands @code{dump}, @code{append}, and
10053@code{restore} to copy data between target memory and a file. The
10054@code{dump} and @code{append} commands write data to a file, and the
10055@code{restore} command reads data from a file back into the inferior's
10056memory. Files may be in binary, Motorola S-record, Intel hex, or
10057Tektronix Hex format; however, @value{GDBN} can only append to binary
10058files.
10059
10060@table @code
10061
10062@kindex dump
10063@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
10064@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
10065Dump the contents of memory from @var{start_addr} to @var{end_addr},
10066or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 10067
df5215a6 10068The @var{format} parameter may be any one of:
16d9dec6 10069@table @code
df5215a6
JB
10070@item binary
10071Raw binary form.
10072@item ihex
10073Intel hex format.
10074@item srec
10075Motorola S-record format.
10076@item tekhex
10077Tektronix Hex format.
10078@end table
10079
10080@value{GDBN} uses the same definitions of these formats as the
10081@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
10082@var{format} is omitted, @value{GDBN} dumps the data in raw binary
10083form.
10084
10085@kindex append
10086@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
10087@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
10088Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 10089or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
10090(@value{GDBN} can only append data to files in raw binary form.)
10091
10092@kindex restore
10093@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
10094Restore the contents of file @var{filename} into memory. The
10095@code{restore} command can automatically recognize any known @sc{bfd}
10096file format, except for raw binary. To restore a raw binary file you
10097must specify the optional keyword @code{binary} after the filename.
16d9dec6 10098
b383017d 10099If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
10100contained in the file. Binary files always start at address zero, so
10101they will be restored at address @var{bias}. Other bfd files have
10102a built-in location; they will be restored at offset @var{bias}
10103from that location.
10104
10105If @var{start} and/or @var{end} are non-zero, then only data between
10106file offset @var{start} and file offset @var{end} will be restored.
b383017d 10107These offsets are relative to the addresses in the file, before
16d9dec6
MS
10108the @var{bias} argument is applied.
10109
10110@end table
10111
384ee23f
EZ
10112@node Core File Generation
10113@section How to Produce a Core File from Your Program
10114@cindex dump core from inferior
10115
10116A @dfn{core file} or @dfn{core dump} is a file that records the memory
10117image of a running process and its process status (register values
10118etc.). Its primary use is post-mortem debugging of a program that
10119crashed while it ran outside a debugger. A program that crashes
10120automatically produces a core file, unless this feature is disabled by
10121the user. @xref{Files}, for information on invoking @value{GDBN} in
10122the post-mortem debugging mode.
10123
10124Occasionally, you may wish to produce a core file of the program you
10125are debugging in order to preserve a snapshot of its state.
10126@value{GDBN} has a special command for that.
10127
10128@table @code
10129@kindex gcore
10130@kindex generate-core-file
10131@item generate-core-file [@var{file}]
10132@itemx gcore [@var{file}]
10133Produce a core dump of the inferior process. The optional argument
10134@var{file} specifies the file name where to put the core dump. If not
10135specified, the file name defaults to @file{core.@var{pid}}, where
10136@var{pid} is the inferior process ID.
10137
10138Note that this command is implemented only for some systems (as of
05b4bd79 10139this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
384ee23f
EZ
10140@end table
10141
a0eb71c5
KB
10142@node Character Sets
10143@section Character Sets
10144@cindex character sets
10145@cindex charset
10146@cindex translating between character sets
10147@cindex host character set
10148@cindex target character set
10149
10150If the program you are debugging uses a different character set to
10151represent characters and strings than the one @value{GDBN} uses itself,
10152@value{GDBN} can automatically translate between the character sets for
10153you. The character set @value{GDBN} uses we call the @dfn{host
10154character set}; the one the inferior program uses we call the
10155@dfn{target character set}.
10156
10157For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
10158uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
ea35711c 10159remote protocol (@pxref{Remote Debugging}) to debug a program
a0eb71c5
KB
10160running on an IBM mainframe, which uses the @sc{ebcdic} character set,
10161then the host character set is Latin-1, and the target character set is
10162@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 10163target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
10164@sc{ebcdic} and Latin 1 as you print character or string values, or use
10165character and string literals in expressions.
10166
10167@value{GDBN} has no way to automatically recognize which character set
10168the inferior program uses; you must tell it, using the @code{set
10169target-charset} command, described below.
10170
10171Here are the commands for controlling @value{GDBN}'s character set
10172support:
10173
10174@table @code
10175@item set target-charset @var{charset}
10176@kindex set target-charset
10af6951
EZ
10177Set the current target character set to @var{charset}. To display the
10178list of supported target character sets, type
10179@kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
a0eb71c5 10180
a0eb71c5
KB
10181@item set host-charset @var{charset}
10182@kindex set host-charset
10183Set the current host character set to @var{charset}.
10184
10185By default, @value{GDBN} uses a host character set appropriate to the
10186system it is running on; you can override that default using the
732f6a93
TT
10187@code{set host-charset} command. On some systems, @value{GDBN} cannot
10188automatically determine the appropriate host character set. In this
10189case, @value{GDBN} uses @samp{UTF-8}.
a0eb71c5
KB
10190
10191@value{GDBN} can only use certain character sets as its host character
c1b6b909 10192set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
10af6951 10193@value{GDBN} will list the host character sets it supports.
a0eb71c5
KB
10194
10195@item set charset @var{charset}
10196@kindex set charset
e33d66ec 10197Set the current host and target character sets to @var{charset}. As
10af6951
EZ
10198above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
10199@value{GDBN} will list the names of the character sets that can be used
e33d66ec
EZ
10200for both host and target.
10201
a0eb71c5 10202@item show charset
a0eb71c5 10203@kindex show charset
10af6951 10204Show the names of the current host and target character sets.
e33d66ec 10205
10af6951 10206@item show host-charset
a0eb71c5 10207@kindex show host-charset
10af6951 10208Show the name of the current host character set.
e33d66ec 10209
10af6951 10210@item show target-charset
a0eb71c5 10211@kindex show target-charset
10af6951 10212Show the name of the current target character set.
a0eb71c5 10213
10af6951
EZ
10214@item set target-wide-charset @var{charset}
10215@kindex set target-wide-charset
10216Set the current target's wide character set to @var{charset}. This is
10217the character set used by the target's @code{wchar_t} type. To
10218display the list of supported wide character sets, type
10219@kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
10220
10221@item show target-wide-charset
10222@kindex show target-wide-charset
10223Show the name of the current target's wide character set.
a0eb71c5
KB
10224@end table
10225
a0eb71c5
KB
10226Here is an example of @value{GDBN}'s character set support in action.
10227Assume that the following source code has been placed in the file
10228@file{charset-test.c}:
10229
10230@smallexample
10231#include <stdio.h>
10232
10233char ascii_hello[]
10234 = @{72, 101, 108, 108, 111, 44, 32, 119,
10235 111, 114, 108, 100, 33, 10, 0@};
10236char ibm1047_hello[]
10237 = @{200, 133, 147, 147, 150, 107, 64, 166,
10238 150, 153, 147, 132, 90, 37, 0@};
10239
10240main ()
10241@{
10242 printf ("Hello, world!\n");
10243@}
10998722 10244@end smallexample
a0eb71c5
KB
10245
10246In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
10247containing the string @samp{Hello, world!} followed by a newline,
10248encoded in the @sc{ascii} and @sc{ibm1047} character sets.
10249
10250We compile the program, and invoke the debugger on it:
10251
10252@smallexample
10253$ gcc -g charset-test.c -o charset-test
10254$ gdb -nw charset-test
10255GNU gdb 2001-12-19-cvs
10256Copyright 2001 Free Software Foundation, Inc.
10257@dots{}
f7dc1244 10258(@value{GDBP})
10998722 10259@end smallexample
a0eb71c5
KB
10260
10261We can use the @code{show charset} command to see what character sets
10262@value{GDBN} is currently using to interpret and display characters and
10263strings:
10264
10265@smallexample
f7dc1244 10266(@value{GDBP}) show charset
e33d66ec 10267The current host and target character set is `ISO-8859-1'.
f7dc1244 10268(@value{GDBP})
10998722 10269@end smallexample
a0eb71c5
KB
10270
10271For the sake of printing this manual, let's use @sc{ascii} as our
10272initial character set:
10273@smallexample
f7dc1244
EZ
10274(@value{GDBP}) set charset ASCII
10275(@value{GDBP}) show charset
e33d66ec 10276The current host and target character set is `ASCII'.
f7dc1244 10277(@value{GDBP})
10998722 10278@end smallexample
a0eb71c5
KB
10279
10280Let's assume that @sc{ascii} is indeed the correct character set for our
10281host system --- in other words, let's assume that if @value{GDBN} prints
10282characters using the @sc{ascii} character set, our terminal will display
10283them properly. Since our current target character set is also
10284@sc{ascii}, the contents of @code{ascii_hello} print legibly:
10285
10286@smallexample
f7dc1244 10287(@value{GDBP}) print ascii_hello
a0eb71c5 10288$1 = 0x401698 "Hello, world!\n"
f7dc1244 10289(@value{GDBP}) print ascii_hello[0]
a0eb71c5 10290$2 = 72 'H'
f7dc1244 10291(@value{GDBP})
10998722 10292@end smallexample
a0eb71c5
KB
10293
10294@value{GDBN} uses the target character set for character and string
10295literals you use in expressions:
10296
10297@smallexample
f7dc1244 10298(@value{GDBP}) print '+'
a0eb71c5 10299$3 = 43 '+'
f7dc1244 10300(@value{GDBP})
10998722 10301@end smallexample
a0eb71c5
KB
10302
10303The @sc{ascii} character set uses the number 43 to encode the @samp{+}
10304character.
10305
10306@value{GDBN} relies on the user to tell it which character set the
10307target program uses. If we print @code{ibm1047_hello} while our target
10308character set is still @sc{ascii}, we get jibberish:
10309
10310@smallexample
f7dc1244 10311(@value{GDBP}) print ibm1047_hello
a0eb71c5 10312$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 10313(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 10314$5 = 200 '\310'
f7dc1244 10315(@value{GDBP})
10998722 10316@end smallexample
a0eb71c5 10317
e33d66ec 10318If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
10319@value{GDBN} tells us the character sets it supports:
10320
10321@smallexample
f7dc1244 10322(@value{GDBP}) set target-charset
b383017d 10323ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 10324(@value{GDBP}) set target-charset
10998722 10325@end smallexample
a0eb71c5
KB
10326
10327We can select @sc{ibm1047} as our target character set, and examine the
10328program's strings again. Now the @sc{ascii} string is wrong, but
10329@value{GDBN} translates the contents of @code{ibm1047_hello} from the
10330target character set, @sc{ibm1047}, to the host character set,
10331@sc{ascii}, and they display correctly:
10332
10333@smallexample
f7dc1244
EZ
10334(@value{GDBP}) set target-charset IBM1047
10335(@value{GDBP}) show charset
e33d66ec
EZ
10336The current host character set is `ASCII'.
10337The current target character set is `IBM1047'.
f7dc1244 10338(@value{GDBP}) print ascii_hello
a0eb71c5 10339$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 10340(@value{GDBP}) print ascii_hello[0]
a0eb71c5 10341$7 = 72 '\110'
f7dc1244 10342(@value{GDBP}) print ibm1047_hello
a0eb71c5 10343$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 10344(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 10345$9 = 200 'H'
f7dc1244 10346(@value{GDBP})
10998722 10347@end smallexample
a0eb71c5
KB
10348
10349As above, @value{GDBN} uses the target character set for character and
10350string literals you use in expressions:
10351
10352@smallexample
f7dc1244 10353(@value{GDBP}) print '+'
a0eb71c5 10354$10 = 78 '+'
f7dc1244 10355(@value{GDBP})
10998722 10356@end smallexample
a0eb71c5 10357
e33d66ec 10358The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
10359character.
10360
09d4efe1
EZ
10361@node Caching Remote Data
10362@section Caching Data of Remote Targets
10363@cindex caching data of remote targets
10364
4e5d721f 10365@value{GDBN} caches data exchanged between the debugger and a
ea35711c 10366remote target (@pxref{Remote Debugging}). Such caching generally improves
09d4efe1 10367performance, because it reduces the overhead of the remote protocol by
4e5d721f
DE
10368bundling memory reads and writes into large chunks. Unfortunately, simply
10369caching everything would lead to incorrect results, since @value{GDBN}
10370does not necessarily know anything about volatile values, memory-mapped I/O
29b090c0
DE
10371addresses, etc. Furthermore, in non-stop mode (@pxref{Non-Stop Mode})
10372memory can be changed @emph{while} a gdb command is executing.
10373Therefore, by default, @value{GDBN} only caches data
10374known to be on the stack@footnote{In non-stop mode, it is moderately
10375rare for a running thread to modify the stack of a stopped thread
10376in a way that would interfere with a backtrace, and caching of
10377stack reads provides a significant speed up of remote backtraces.}.
10378Other regions of memory can be explicitly marked as
4e5d721f 10379cacheable; see @pxref{Memory Region Attributes}.
09d4efe1
EZ
10380
10381@table @code
10382@kindex set remotecache
10383@item set remotecache on
10384@itemx set remotecache off
4e5d721f
DE
10385This option no longer does anything; it exists for compatibility
10386with old scripts.
09d4efe1
EZ
10387
10388@kindex show remotecache
10389@item show remotecache
4e5d721f
DE
10390Show the current state of the obsolete remotecache flag.
10391
10392@kindex set stack-cache
10393@item set stack-cache on
10394@itemx set stack-cache off
10395Enable or disable caching of stack accesses. When @code{ON}, use
10396caching. By default, this option is @code{ON}.
10397
10398@kindex show stack-cache
10399@item show stack-cache
10400Show the current state of data caching for memory accesses.
09d4efe1
EZ
10401
10402@kindex info dcache
4e5d721f 10403@item info dcache @r{[}line@r{]}
09d4efe1 10404Print the information about the data cache performance. The
4e5d721f
DE
10405information displayed includes the dcache width and depth, and for
10406each cache line, its number, address, and how many times it was
10407referenced. This command is useful for debugging the data cache
10408operation.
10409
10410If a line number is specified, the contents of that line will be
10411printed in hex.
1a532630
PP
10412
10413@item set dcache size @var{size}
10414@cindex dcache size
10415@kindex set dcache size
10416Set maximum number of entries in dcache (dcache depth above).
10417
10418@item set dcache line-size @var{line-size}
10419@cindex dcache line-size
10420@kindex set dcache line-size
10421Set number of bytes each dcache entry caches (dcache width above).
10422Must be a power of 2.
10423
10424@item show dcache size
10425@kindex show dcache size
10426Show maximum number of dcache entries. See also @ref{Caching Remote Data, info dcache}.
10427
10428@item show dcache line-size
10429@kindex show dcache line-size
10430Show default size of dcache lines. See also @ref{Caching Remote Data, info dcache}.
10431
09d4efe1
EZ
10432@end table
10433
08388c79
DE
10434@node Searching Memory
10435@section Search Memory
10436@cindex searching memory
10437
10438Memory can be searched for a particular sequence of bytes with the
10439@code{find} command.
10440
10441@table @code
10442@kindex find
10443@item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
10444@itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
10445Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
10446etc. The search begins at address @var{start_addr} and continues for either
10447@var{len} bytes or through to @var{end_addr} inclusive.
10448@end table
10449
10450@var{s} and @var{n} are optional parameters.
10451They may be specified in either order, apart or together.
10452
10453@table @r
10454@item @var{s}, search query size
10455The size of each search query value.
10456
10457@table @code
10458@item b
10459bytes
10460@item h
10461halfwords (two bytes)
10462@item w
10463words (four bytes)
10464@item g
10465giant words (eight bytes)
10466@end table
10467
10468All values are interpreted in the current language.
10469This means, for example, that if the current source language is C/C@t{++}
10470then searching for the string ``hello'' includes the trailing '\0'.
10471
10472If the value size is not specified, it is taken from the
10473value's type in the current language.
10474This is useful when one wants to specify the search
10475pattern as a mixture of types.
10476Note that this means, for example, that in the case of C-like languages
10477a search for an untyped 0x42 will search for @samp{(int) 0x42}
10478which is typically four bytes.
10479
10480@item @var{n}, maximum number of finds
10481The maximum number of matches to print. The default is to print all finds.
10482@end table
10483
10484You can use strings as search values. Quote them with double-quotes
10485 (@code{"}).
10486The string value is copied into the search pattern byte by byte,
10487regardless of the endianness of the target and the size specification.
10488
10489The address of each match found is printed as well as a count of the
10490number of matches found.
10491
10492The address of the last value found is stored in convenience variable
10493@samp{$_}.
10494A count of the number of matches is stored in @samp{$numfound}.
10495
10496For example, if stopped at the @code{printf} in this function:
10497
10498@smallexample
10499void
10500hello ()
10501@{
10502 static char hello[] = "hello-hello";
10503 static struct @{ char c; short s; int i; @}
10504 __attribute__ ((packed)) mixed
10505 = @{ 'c', 0x1234, 0x87654321 @};
10506 printf ("%s\n", hello);
10507@}
10508@end smallexample
10509
10510@noindent
10511you get during debugging:
10512
10513@smallexample
10514(gdb) find &hello[0], +sizeof(hello), "hello"
105150x804956d <hello.1620+6>
105161 pattern found
10517(gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
105180x8049567 <hello.1620>
105190x804956d <hello.1620+6>
105202 patterns found
10521(gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
105220x8049567 <hello.1620>
105231 pattern found
10524(gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
105250x8049560 <mixed.1625>
105261 pattern found
10527(gdb) print $numfound
10528$1 = 1
10529(gdb) print $_
10530$2 = (void *) 0x8049560
10531@end smallexample
a0eb71c5 10532
edb3359d
DJ
10533@node Optimized Code
10534@chapter Debugging Optimized Code
10535@cindex optimized code, debugging
10536@cindex debugging optimized code
10537
10538Almost all compilers support optimization. With optimization
10539disabled, the compiler generates assembly code that corresponds
10540directly to your source code, in a simplistic way. As the compiler
10541applies more powerful optimizations, the generated assembly code
10542diverges from your original source code. With help from debugging
10543information generated by the compiler, @value{GDBN} can map from
10544the running program back to constructs from your original source.
10545
10546@value{GDBN} is more accurate with optimization disabled. If you
10547can recompile without optimization, it is easier to follow the
10548progress of your program during debugging. But, there are many cases
10549where you may need to debug an optimized version.
10550
10551When you debug a program compiled with @samp{-g -O}, remember that the
10552optimizer has rearranged your code; the debugger shows you what is
10553really there. Do not be too surprised when the execution path does not
10554exactly match your source file! An extreme example: if you define a
10555variable, but never use it, @value{GDBN} never sees that
10556variable---because the compiler optimizes it out of existence.
10557
10558Some things do not work as well with @samp{-g -O} as with just
10559@samp{-g}, particularly on machines with instruction scheduling. If in
10560doubt, recompile with @samp{-g} alone, and if this fixes the problem,
10561please report it to us as a bug (including a test case!).
10562@xref{Variables}, for more information about debugging optimized code.
10563
10564@menu
10565* Inline Functions:: How @value{GDBN} presents inlining
111c6489 10566* Tail Call Frames:: @value{GDBN} analysis of jumps to functions
edb3359d
DJ
10567@end menu
10568
10569@node Inline Functions
10570@section Inline Functions
10571@cindex inline functions, debugging
10572
10573@dfn{Inlining} is an optimization that inserts a copy of the function
10574body directly at each call site, instead of jumping to a shared
10575routine. @value{GDBN} displays inlined functions just like
10576non-inlined functions. They appear in backtraces. You can view their
10577arguments and local variables, step into them with @code{step}, skip
10578them with @code{next}, and escape from them with @code{finish}.
10579You can check whether a function was inlined by using the
10580@code{info frame} command.
10581
10582For @value{GDBN} to support inlined functions, the compiler must
10583record information about inlining in the debug information ---
10584@value{NGCC} using the @sc{dwarf 2} format does this, and several
10585other compilers do also. @value{GDBN} only supports inlined functions
10586when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
10587do not emit two required attributes (@samp{DW_AT_call_file} and
10588@samp{DW_AT_call_line}); @value{GDBN} does not display inlined
10589function calls with earlier versions of @value{NGCC}. It instead
10590displays the arguments and local variables of inlined functions as
10591local variables in the caller.
10592
10593The body of an inlined function is directly included at its call site;
10594unlike a non-inlined function, there are no instructions devoted to
10595the call. @value{GDBN} still pretends that the call site and the
10596start of the inlined function are different instructions. Stepping to
10597the call site shows the call site, and then stepping again shows
10598the first line of the inlined function, even though no additional
10599instructions are executed.
10600
10601This makes source-level debugging much clearer; you can see both the
10602context of the call and then the effect of the call. Only stepping by
10603a single instruction using @code{stepi} or @code{nexti} does not do
10604this; single instruction steps always show the inlined body.
10605
10606There are some ways that @value{GDBN} does not pretend that inlined
10607function calls are the same as normal calls:
10608
10609@itemize @bullet
edb3359d
DJ
10610@item
10611Setting breakpoints at the call site of an inlined function may not
10612work, because the call site does not contain any code. @value{GDBN}
10613may incorrectly move the breakpoint to the next line of the enclosing
10614function, after the call. This limitation will be removed in a future
10615version of @value{GDBN}; until then, set a breakpoint on an earlier line
10616or inside the inlined function instead.
10617
10618@item
10619@value{GDBN} cannot locate the return value of inlined calls after
10620using the @code{finish} command. This is a limitation of compiler-generated
10621debugging information; after @code{finish}, you can step to the next line
10622and print a variable where your program stored the return value.
10623
10624@end itemize
10625
111c6489
JK
10626@node Tail Call Frames
10627@section Tail Call Frames
10628@cindex tail call frames, debugging
10629
10630Function @code{B} can call function @code{C} in its very last statement. In
10631unoptimized compilation the call of @code{C} is immediately followed by return
10632instruction at the end of @code{B} code. Optimizing compiler may replace the
10633call and return in function @code{B} into one jump to function @code{C}
10634instead. Such use of a jump instruction is called @dfn{tail call}.
10635
10636During execution of function @code{C}, there will be no indication in the
10637function call stack frames that it was tail-called from @code{B}. If function
10638@code{A} regularly calls function @code{B} which tail-calls function @code{C},
10639then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
10640some cases @value{GDBN} can determine that @code{C} was tail-called from
10641@code{B}, and it will then create fictitious call frame for that, with the
10642return address set up as if @code{B} called @code{C} normally.
10643
10644This functionality is currently supported only by DWARF 2 debugging format and
10645the compiler has to produce @samp{DW_TAG_GNU_call_site} tags. With
10646@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
10647this information.
10648
10649@kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
10650kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
10651
10652@smallexample
10653(gdb) x/i $pc - 2
10654 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
10655(gdb) info frame
10656Stack level 1, frame at 0x7fffffffda30:
10657 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
10658 tail call frame, caller of frame at 0x7fffffffda30
10659 source language c++.
10660 Arglist at unknown address.
10661 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
10662@end smallexample
10663
10664The detection of all the possible code path executions can find them ambiguous.
10665There is no execution history stored (possible @ref{Reverse Execution} is never
10666used for this purpose) and the last known caller could have reached the known
10667callee by multiple different jump sequences. In such case @value{GDBN} still
10668tries to show at least all the unambiguous top tail callers and all the
10669unambiguous bottom tail calees, if any.
10670
10671@table @code
e18b2753 10672@anchor{set debug entry-values}
111c6489
JK
10673@item set debug entry-values
10674@kindex set debug entry-values
10675When set to on, enables printing of analysis messages for both frame argument
10676values at function entry and tail calls. It will show all the possible valid
10677tail calls code paths it has considered. It will also print the intersection
10678of them with the final unambiguous (possibly partial or even empty) code path
10679result.
10680
10681@item show debug entry-values
10682@kindex show debug entry-values
10683Show the current state of analysis messages printing for both frame argument
10684values at function entry and tail calls.
10685@end table
10686
10687The analysis messages for tail calls can for example show why the virtual tail
10688call frame for function @code{c} has not been recognized (due to the indirect
10689reference by variable @code{x}):
10690
10691@smallexample
10692static void __attribute__((noinline, noclone)) c (void);
10693void (*x) (void) = c;
10694static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
10695static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
10696int main (void) @{ x (); return 0; @}
10697
10698Breakpoint 1, DW_OP_GNU_entry_value resolving cannot find
10699DW_TAG_GNU_call_site 0x40039a in main
10700a () at t.c:3
107013 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
10702(gdb) bt
10703#0 a () at t.c:3
10704#1 0x000000000040039a in main () at t.c:5
10705@end smallexample
10706
10707Another possibility is an ambiguous virtual tail call frames resolution:
10708
10709@smallexample
10710int i;
10711static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
10712static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
10713static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
10714static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
10715static void __attribute__((noinline, noclone)) b (void)
10716@{ if (i) c (); else e (); @}
10717static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
10718int main (void) @{ a (); return 0; @}
10719
10720tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
10721tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
10722tailcall: reduced: 0x4004d2(a) |
10723(gdb) bt
10724#0 f () at t.c:2
10725#1 0x00000000004004d2 in a () at t.c:8
10726#2 0x0000000000400395 in main () at t.c:9
10727@end smallexample
10728
5048e516
JK
10729@set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
10730@set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
10731
10732@c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
10733@ifset HAVE_MAKEINFO_CLICK
10734@set ARROW @click{}
10735@set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
10736@set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
10737@end ifset
10738@ifclear HAVE_MAKEINFO_CLICK
10739@set ARROW ->
10740@set CALLSEQ1B @value{CALLSEQ1A}
10741@set CALLSEQ2B @value{CALLSEQ2A}
10742@end ifclear
10743
10744Frames #0 and #2 are real, #1 is a virtual tail call frame.
10745The code can have possible execution paths @value{CALLSEQ1B} or
10746@value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
111c6489
JK
10747
10748@code{initial:} state shows some random possible calling sequence @value{GDBN}
10749has found. It then finds another possible calling sequcen - that one is
10750prefixed by @code{compare:}. The non-ambiguous intersection of these two is
10751printed as the @code{reduced:} calling sequence. That one could have many
10752futher @code{compare:} and @code{reduced:} statements as long as there remain
10753any non-ambiguous sequence entries.
10754
10755For the frame of function @code{b} in both cases there are different possible
10756@code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
10757also ambigous. The only non-ambiguous frame is the one for function @code{a},
10758therefore this one is displayed to the user while the ambiguous frames are
10759omitted.
edb3359d 10760
e18b2753
JK
10761There can be also reasons why printing of frame argument values at function
10762entry may fail:
10763
10764@smallexample
10765int v;
10766static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
10767static void __attribute__((noinline, noclone)) a (int i);
10768static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
10769static void __attribute__((noinline, noclone)) a (int i)
10770@{ if (i) b (i - 1); else c (0); @}
10771int main (void) @{ a (5); return 0; @}
10772
10773(gdb) bt
10774#0 c (i=i@@entry=0) at t.c:2
10775#1 0x0000000000400428 in a (DW_OP_GNU_entry_value resolving has found
10776function "a" at 0x400420 can call itself via tail calls
10777i=<optimized out>) at t.c:6
10778#2 0x000000000040036e in main () at t.c:7
10779@end smallexample
10780
10781@value{GDBN} cannot find out from the inferior state if and how many times did
10782function @code{a} call itself (via function @code{b}) as these calls would be
10783tail calls. Such tail calls would modify thue @code{i} variable, therefore
10784@value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
10785prints @code{<optimized out>} instead.
10786
e2e0bcd1
JB
10787@node Macros
10788@chapter C Preprocessor Macros
10789
49efadf5 10790Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
10791``preprocessor macros'' which expand into strings of tokens.
10792@value{GDBN} can evaluate expressions containing macro invocations, show
10793the result of macro expansion, and show a macro's definition, including
10794where it was defined.
10795
10796You may need to compile your program specially to provide @value{GDBN}
10797with information about preprocessor macros. Most compilers do not
10798include macros in their debugging information, even when you compile
10799with the @option{-g} flag. @xref{Compilation}.
10800
10801A program may define a macro at one point, remove that definition later,
10802and then provide a different definition after that. Thus, at different
10803points in the program, a macro may have different definitions, or have
10804no definition at all. If there is a current stack frame, @value{GDBN}
10805uses the macros in scope at that frame's source code line. Otherwise,
10806@value{GDBN} uses the macros in scope at the current listing location;
10807see @ref{List}.
10808
e2e0bcd1
JB
10809Whenever @value{GDBN} evaluates an expression, it always expands any
10810macro invocations present in the expression. @value{GDBN} also provides
10811the following commands for working with macros explicitly.
10812
10813@table @code
10814
10815@kindex macro expand
10816@cindex macro expansion, showing the results of preprocessor
10817@cindex preprocessor macro expansion, showing the results of
10818@cindex expanding preprocessor macros
10819@item macro expand @var{expression}
10820@itemx macro exp @var{expression}
10821Show the results of expanding all preprocessor macro invocations in
10822@var{expression}. Since @value{GDBN} simply expands macros, but does
10823not parse the result, @var{expression} need not be a valid expression;
10824it can be any string of tokens.
10825
09d4efe1 10826@kindex macro exp1
e2e0bcd1
JB
10827@item macro expand-once @var{expression}
10828@itemx macro exp1 @var{expression}
4644b6e3 10829@cindex expand macro once
e2e0bcd1
JB
10830@i{(This command is not yet implemented.)} Show the results of
10831expanding those preprocessor macro invocations that appear explicitly in
10832@var{expression}. Macro invocations appearing in that expansion are
10833left unchanged. This command allows you to see the effect of a
10834particular macro more clearly, without being confused by further
10835expansions. Since @value{GDBN} simply expands macros, but does not
10836parse the result, @var{expression} need not be a valid expression; it
10837can be any string of tokens.
10838
475b0867 10839@kindex info macro
e2e0bcd1 10840@cindex macro definition, showing
9b158ba0 10841@cindex definition of a macro, showing
10842@cindex macros, from debug info
71eba9c2 10843@item info macro [-a|-all] [--] @var{macro}
10844Show the current definition or all definitions of the named @var{macro},
10845and describe the source location or compiler command-line where that
10846definition was established. The optional double dash is to signify the end of
10847argument processing and the beginning of @var{macro} for non C-like macros where
10848the macro may begin with a hyphen.
e2e0bcd1 10849
9b158ba0 10850@kindex info macros
10851@item info macros @var{linespec}
10852Show all macro definitions that are in effect at the location specified
10853by @var{linespec}, and describe the source location or compiler
10854command-line where those definitions were established.
10855
e2e0bcd1
JB
10856@kindex macro define
10857@cindex user-defined macros
10858@cindex defining macros interactively
10859@cindex macros, user-defined
10860@item macro define @var{macro} @var{replacement-list}
10861@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
d7d9f01e
TT
10862Introduce a definition for a preprocessor macro named @var{macro},
10863invocations of which are replaced by the tokens given in
10864@var{replacement-list}. The first form of this command defines an
10865``object-like'' macro, which takes no arguments; the second form
10866defines a ``function-like'' macro, which takes the arguments given in
10867@var{arglist}.
10868
10869A definition introduced by this command is in scope in every
10870expression evaluated in @value{GDBN}, until it is removed with the
10871@code{macro undef} command, described below. The definition overrides
10872all definitions for @var{macro} present in the program being debugged,
10873as well as any previous user-supplied definition.
e2e0bcd1
JB
10874
10875@kindex macro undef
10876@item macro undef @var{macro}
d7d9f01e
TT
10877Remove any user-supplied definition for the macro named @var{macro}.
10878This command only affects definitions provided with the @code{macro
10879define} command, described above; it cannot remove definitions present
10880in the program being debugged.
e2e0bcd1 10881
09d4efe1
EZ
10882@kindex macro list
10883@item macro list
d7d9f01e 10884List all the macros defined using the @code{macro define} command.
e2e0bcd1
JB
10885@end table
10886
10887@cindex macros, example of debugging with
10888Here is a transcript showing the above commands in action. First, we
10889show our source files:
10890
10891@smallexample
10892$ cat sample.c
10893#include <stdio.h>
10894#include "sample.h"
10895
10896#define M 42
10897#define ADD(x) (M + x)
10898
10899main ()
10900@{
10901#define N 28
10902 printf ("Hello, world!\n");
10903#undef N
10904 printf ("We're so creative.\n");
10905#define N 1729
10906 printf ("Goodbye, world!\n");
10907@}
10908$ cat sample.h
10909#define Q <
10910$
10911@end smallexample
10912
e0f8f636
TT
10913Now, we compile the program using the @sc{gnu} C compiler,
10914@value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
10915minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
10916and @option{-gdwarf-4}; we recommend always choosing the most recent
10917version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
10918includes information about preprocessor macros in the debugging
e2e0bcd1
JB
10919information.
10920
10921@smallexample
10922$ gcc -gdwarf-2 -g3 sample.c -o sample
10923$
10924@end smallexample
10925
10926Now, we start @value{GDBN} on our sample program:
10927
10928@smallexample
10929$ gdb -nw sample
10930GNU gdb 2002-05-06-cvs
10931Copyright 2002 Free Software Foundation, Inc.
10932GDB is free software, @dots{}
f7dc1244 10933(@value{GDBP})
e2e0bcd1
JB
10934@end smallexample
10935
10936We can expand macros and examine their definitions, even when the
10937program is not running. @value{GDBN} uses the current listing position
10938to decide which macro definitions are in scope:
10939
10940@smallexample
f7dc1244 10941(@value{GDBP}) list main
e2e0bcd1
JB
109423
109434 #define M 42
109445 #define ADD(x) (M + x)
109456
109467 main ()
109478 @{
109489 #define N 28
1094910 printf ("Hello, world!\n");
1095011 #undef N
1095112 printf ("We're so creative.\n");
f7dc1244 10952(@value{GDBP}) info macro ADD
e2e0bcd1
JB
10953Defined at /home/jimb/gdb/macros/play/sample.c:5
10954#define ADD(x) (M + x)
f7dc1244 10955(@value{GDBP}) info macro Q
e2e0bcd1
JB
10956Defined at /home/jimb/gdb/macros/play/sample.h:1
10957 included at /home/jimb/gdb/macros/play/sample.c:2
10958#define Q <
f7dc1244 10959(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 10960expands to: (42 + 1)
f7dc1244 10961(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 10962expands to: once (M + 1)
f7dc1244 10963(@value{GDBP})
e2e0bcd1
JB
10964@end smallexample
10965
d7d9f01e 10966In the example above, note that @code{macro expand-once} expands only
e2e0bcd1
JB
10967the macro invocation explicit in the original text --- the invocation of
10968@code{ADD} --- but does not expand the invocation of the macro @code{M},
10969which was introduced by @code{ADD}.
10970
3f94c067
BW
10971Once the program is running, @value{GDBN} uses the macro definitions in
10972force at the source line of the current stack frame:
e2e0bcd1
JB
10973
10974@smallexample
f7dc1244 10975(@value{GDBP}) break main
e2e0bcd1 10976Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 10977(@value{GDBP}) run
b383017d 10978Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
10979
10980Breakpoint 1, main () at sample.c:10
1098110 printf ("Hello, world!\n");
f7dc1244 10982(@value{GDBP})
e2e0bcd1
JB
10983@end smallexample
10984
10985At line 10, the definition of the macro @code{N} at line 9 is in force:
10986
10987@smallexample
f7dc1244 10988(@value{GDBP}) info macro N
e2e0bcd1
JB
10989Defined at /home/jimb/gdb/macros/play/sample.c:9
10990#define N 28
f7dc1244 10991(@value{GDBP}) macro expand N Q M
e2e0bcd1 10992expands to: 28 < 42
f7dc1244 10993(@value{GDBP}) print N Q M
e2e0bcd1 10994$1 = 1
f7dc1244 10995(@value{GDBP})
e2e0bcd1
JB
10996@end smallexample
10997
10998As we step over directives that remove @code{N}'s definition, and then
10999give it a new definition, @value{GDBN} finds the definition (or lack
11000thereof) in force at each point:
11001
11002@smallexample
f7dc1244 11003(@value{GDBP}) next
e2e0bcd1
JB
11004Hello, world!
1100512 printf ("We're so creative.\n");
f7dc1244 11006(@value{GDBP}) info macro N
e2e0bcd1
JB
11007The symbol `N' has no definition as a C/C++ preprocessor macro
11008at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 11009(@value{GDBP}) next
e2e0bcd1
JB
11010We're so creative.
1101114 printf ("Goodbye, world!\n");
f7dc1244 11012(@value{GDBP}) info macro N
e2e0bcd1
JB
11013Defined at /home/jimb/gdb/macros/play/sample.c:13
11014#define N 1729
f7dc1244 11015(@value{GDBP}) macro expand N Q M
e2e0bcd1 11016expands to: 1729 < 42
f7dc1244 11017(@value{GDBP}) print N Q M
e2e0bcd1 11018$2 = 0
f7dc1244 11019(@value{GDBP})
e2e0bcd1
JB
11020@end smallexample
11021
484086b7
JK
11022In addition to source files, macros can be defined on the compilation command
11023line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
11024such a way, @value{GDBN} displays the location of their definition as line zero
11025of the source file submitted to the compiler.
11026
11027@smallexample
11028(@value{GDBP}) info macro __STDC__
11029Defined at /home/jimb/gdb/macros/play/sample.c:0
11030-D__STDC__=1
11031(@value{GDBP})
11032@end smallexample
11033
e2e0bcd1 11034
b37052ae
EZ
11035@node Tracepoints
11036@chapter Tracepoints
11037@c This chapter is based on the documentation written by Michael
11038@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
11039
11040@cindex tracepoints
11041In some applications, it is not feasible for the debugger to interrupt
11042the program's execution long enough for the developer to learn
11043anything helpful about its behavior. If the program's correctness
11044depends on its real-time behavior, delays introduced by a debugger
11045might cause the program to change its behavior drastically, or perhaps
11046fail, even when the code itself is correct. It is useful to be able
11047to observe the program's behavior without interrupting it.
11048
11049Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
11050specify locations in the program, called @dfn{tracepoints}, and
11051arbitrary expressions to evaluate when those tracepoints are reached.
11052Later, using the @code{tfind} command, you can examine the values
11053those expressions had when the program hit the tracepoints. The
11054expressions may also denote objects in memory---structures or arrays,
11055for example---whose values @value{GDBN} should record; while visiting
11056a particular tracepoint, you may inspect those objects as if they were
11057in memory at that moment. However, because @value{GDBN} records these
11058values without interacting with you, it can do so quickly and
11059unobtrusively, hopefully not disturbing the program's behavior.
11060
11061The tracepoint facility is currently available only for remote
9d29849a
JB
11062targets. @xref{Targets}. In addition, your remote target must know
11063how to collect trace data. This functionality is implemented in the
11064remote stub; however, none of the stubs distributed with @value{GDBN}
11065support tracepoints as of this writing. The format of the remote
11066packets used to implement tracepoints are described in @ref{Tracepoint
11067Packets}.
b37052ae 11068
00bf0b85
SS
11069It is also possible to get trace data from a file, in a manner reminiscent
11070of corefiles; you specify the filename, and use @code{tfind} to search
11071through the file. @xref{Trace Files}, for more details.
11072
b37052ae
EZ
11073This chapter describes the tracepoint commands and features.
11074
11075@menu
b383017d
RM
11076* Set Tracepoints::
11077* Analyze Collected Data::
11078* Tracepoint Variables::
00bf0b85 11079* Trace Files::
b37052ae
EZ
11080@end menu
11081
11082@node Set Tracepoints
11083@section Commands to Set Tracepoints
11084
11085Before running such a @dfn{trace experiment}, an arbitrary number of
1042e4c0
SS
11086tracepoints can be set. A tracepoint is actually a special type of
11087breakpoint (@pxref{Set Breaks}), so you can manipulate it using
11088standard breakpoint commands. For instance, as with breakpoints,
11089tracepoint numbers are successive integers starting from one, and many
11090of the commands associated with tracepoints take the tracepoint number
11091as their argument, to identify which tracepoint to work on.
b37052ae
EZ
11092
11093For each tracepoint, you can specify, in advance, some arbitrary set
11094of data that you want the target to collect in the trace buffer when
11095it hits that tracepoint. The collected data can include registers,
11096local variables, or global data. Later, you can use @value{GDBN}
11097commands to examine the values these data had at the time the
11098tracepoint was hit.
11099
7d13fe92
SS
11100Tracepoints do not support every breakpoint feature. Ignore counts on
11101tracepoints have no effect, and tracepoints cannot run @value{GDBN}
11102commands when they are hit. Tracepoints may not be thread-specific
11103either.
1042e4c0 11104
7a697b8d
SS
11105@cindex fast tracepoints
11106Some targets may support @dfn{fast tracepoints}, which are inserted in
11107a different way (such as with a jump instead of a trap), that is
11108faster but possibly restricted in where they may be installed.
11109
0fb4aa4b
PA
11110@cindex static tracepoints
11111@cindex markers, static tracepoints
11112@cindex probing markers, static tracepoints
11113Regular and fast tracepoints are dynamic tracing facilities, meaning
11114that they can be used to insert tracepoints at (almost) any location
11115in the target. Some targets may also support controlling @dfn{static
11116tracepoints} from @value{GDBN}. With static tracing, a set of
11117instrumentation points, also known as @dfn{markers}, are embedded in
11118the target program, and can be activated or deactivated by name or
11119address. These are usually placed at locations which facilitate
11120investigating what the target is actually doing. @value{GDBN}'s
11121support for static tracing includes being able to list instrumentation
11122points, and attach them with @value{GDBN} defined high level
11123tracepoints that expose the whole range of convenience of
8786b2bd 11124@value{GDBN}'s tracepoints support. Namely, support for collecting
0fb4aa4b
PA
11125registers values and values of global or local (to the instrumentation
11126point) variables; tracepoint conditions and trace state variables.
11127The act of installing a @value{GDBN} static tracepoint on an
11128instrumentation point, or marker, is referred to as @dfn{probing} a
11129static tracepoint marker.
11130
fa593d66
PA
11131@code{gdbserver} supports tracepoints on some target systems.
11132@xref{Server,,Tracepoints support in @code{gdbserver}}.
11133
b37052ae
EZ
11134This section describes commands to set tracepoints and associated
11135conditions and actions.
11136
11137@menu
b383017d
RM
11138* Create and Delete Tracepoints::
11139* Enable and Disable Tracepoints::
11140* Tracepoint Passcounts::
782b2b07 11141* Tracepoint Conditions::
f61e138d 11142* Trace State Variables::
b383017d
RM
11143* Tracepoint Actions::
11144* Listing Tracepoints::
0fb4aa4b 11145* Listing Static Tracepoint Markers::
79a6e687 11146* Starting and Stopping Trace Experiments::
c9429232 11147* Tracepoint Restrictions::
b37052ae
EZ
11148@end menu
11149
11150@node Create and Delete Tracepoints
11151@subsection Create and Delete Tracepoints
11152
11153@table @code
11154@cindex set tracepoint
11155@kindex trace
1042e4c0 11156@item trace @var{location}
b37052ae 11157The @code{trace} command is very similar to the @code{break} command.
1042e4c0
SS
11158Its argument @var{location} can be a source line, a function name, or
11159an address in the target program. @xref{Specify Location}. The
11160@code{trace} command defines a tracepoint, which is a point in the
11161target program where the debugger will briefly stop, collect some
11162data, and then allow the program to continue. Setting a tracepoint or
1e4d1764
YQ
11163changing its actions takes effect immediately if the remote stub
11164supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
11165in tracing}).
11166If remote stub doesn't support the @samp{InstallInTrace} feature, all
11167these changes don't take effect until the next @code{tstart}
1042e4c0 11168command, and once a trace experiment is running, further changes will
bfccc43c
YQ
11169not have any effect until the next trace experiment starts. In addition,
11170@value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
11171address is not yet resolved. (This is similar to pending breakpoints.)
11172Pending tracepoints are not downloaded to the target and not installed
11173until they are resolved. The resolution of pending tracepoints requires
11174@value{GDBN} support---when debugging with the remote target, and
11175@value{GDBN} disconnects from the remote stub (@pxref{disconnected
11176tracing}), pending tracepoints can not be resolved (and downloaded to
11177the remote stub) while @value{GDBN} is disconnected.
b37052ae
EZ
11178
11179Here are some examples of using the @code{trace} command:
11180
11181@smallexample
11182(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
11183
11184(@value{GDBP}) @b{trace +2} // 2 lines forward
11185
11186(@value{GDBP}) @b{trace my_function} // first source line of function
11187
11188(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
11189
11190(@value{GDBP}) @b{trace *0x2117c4} // an address
11191@end smallexample
11192
11193@noindent
11194You can abbreviate @code{trace} as @code{tr}.
11195
782b2b07
SS
11196@item trace @var{location} if @var{cond}
11197Set a tracepoint with condition @var{cond}; evaluate the expression
11198@var{cond} each time the tracepoint is reached, and collect data only
11199if the value is nonzero---that is, if @var{cond} evaluates as true.
11200@xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
11201information on tracepoint conditions.
11202
7a697b8d
SS
11203@item ftrace @var{location} [ if @var{cond} ]
11204@cindex set fast tracepoint
74c761c1 11205@cindex fast tracepoints, setting
7a697b8d
SS
11206@kindex ftrace
11207The @code{ftrace} command sets a fast tracepoint. For targets that
11208support them, fast tracepoints will use a more efficient but possibly
11209less general technique to trigger data collection, such as a jump
11210instruction instead of a trap, or some sort of hardware support. It
11211may not be possible to create a fast tracepoint at the desired
11212location, in which case the command will exit with an explanatory
11213message.
11214
11215@value{GDBN} handles arguments to @code{ftrace} exactly as for
11216@code{trace}.
11217
405f8e94
SS
11218On 32-bit x86-architecture systems, fast tracepoints normally need to
11219be placed at an instruction that is 5 bytes or longer, but can be
11220placed at 4-byte instructions if the low 64K of memory of the target
11221program is available to install trampolines. Some Unix-type systems,
11222such as @sc{gnu}/Linux, exclude low addresses from the program's
11223address space; but for instance with the Linux kernel it is possible
11224to let @value{GDBN} use this area by doing a @command{sysctl} command
11225to set the @code{mmap_min_addr} kernel parameter, as in
11226
11227@example
11228sudo sysctl -w vm.mmap_min_addr=32768
11229@end example
11230
11231@noindent
11232which sets the low address to 32K, which leaves plenty of room for
11233trampolines. The minimum address should be set to a page boundary.
11234
0fb4aa4b 11235@item strace @var{location} [ if @var{cond} ]
74c761c1
PA
11236@cindex set static tracepoint
11237@cindex static tracepoints, setting
11238@cindex probe static tracepoint marker
0fb4aa4b
PA
11239@kindex strace
11240The @code{strace} command sets a static tracepoint. For targets that
11241support it, setting a static tracepoint probes a static
11242instrumentation point, or marker, found at @var{location}. It may not
11243be possible to set a static tracepoint at the desired location, in
11244which case the command will exit with an explanatory message.
11245
11246@value{GDBN} handles arguments to @code{strace} exactly as for
11247@code{trace}, with the addition that the user can also specify
11248@code{-m @var{marker}} as @var{location}. This probes the marker
11249identified by the @var{marker} string identifier. This identifier
11250depends on the static tracepoint backend library your program is
11251using. You can find all the marker identifiers in the @samp{ID} field
11252of the @code{info static-tracepoint-markers} command output.
11253@xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
11254Markers}. For example, in the following small program using the UST
11255tracing engine:
11256
11257@smallexample
11258main ()
11259@{
11260 trace_mark(ust, bar33, "str %s", "FOOBAZ");
11261@}
11262@end smallexample
11263
11264@noindent
11265the marker id is composed of joining the first two arguments to the
11266@code{trace_mark} call with a slash, which translates to:
11267
11268@smallexample
11269(@value{GDBP}) info static-tracepoint-markers
11270Cnt Enb ID Address What
112711 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
11272 Data: "str %s"
11273[etc...]
11274@end smallexample
11275
11276@noindent
11277so you may probe the marker above with:
11278
11279@smallexample
11280(@value{GDBP}) strace -m ust/bar33
11281@end smallexample
11282
11283Static tracepoints accept an extra collect action --- @code{collect
11284$_sdata}. This collects arbitrary user data passed in the probe point
11285call to the tracing library. In the UST example above, you'll see
11286that the third argument to @code{trace_mark} is a printf-like format
11287string. The user data is then the result of running that formating
11288string against the following arguments. Note that @code{info
11289static-tracepoint-markers} command output lists that format string in
11290the @samp{Data:} field.
11291
11292You can inspect this data when analyzing the trace buffer, by printing
11293the $_sdata variable like any other variable available to
11294@value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
11295
b37052ae
EZ
11296@vindex $tpnum
11297@cindex last tracepoint number
11298@cindex recent tracepoint number
11299@cindex tracepoint number
11300The convenience variable @code{$tpnum} records the tracepoint number
11301of the most recently set tracepoint.
11302
11303@kindex delete tracepoint
11304@cindex tracepoint deletion
11305@item delete tracepoint @r{[}@var{num}@r{]}
11306Permanently delete one or more tracepoints. With no argument, the
1042e4c0
SS
11307default is to delete all tracepoints. Note that the regular
11308@code{delete} command can remove tracepoints also.
b37052ae
EZ
11309
11310Examples:
11311
11312@smallexample
11313(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
11314
11315(@value{GDBP}) @b{delete trace} // remove all tracepoints
11316@end smallexample
11317
11318@noindent
11319You can abbreviate this command as @code{del tr}.
11320@end table
11321
11322@node Enable and Disable Tracepoints
11323@subsection Enable and Disable Tracepoints
11324
1042e4c0
SS
11325These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
11326
b37052ae
EZ
11327@table @code
11328@kindex disable tracepoint
11329@item disable tracepoint @r{[}@var{num}@r{]}
11330Disable tracepoint @var{num}, or all tracepoints if no argument
11331@var{num} is given. A disabled tracepoint will have no effect during
d248b706 11332a trace experiment, but it is not forgotten. You can re-enable
b37052ae 11333a disabled tracepoint using the @code{enable tracepoint} command.
d248b706
KY
11334If the command is issued during a trace experiment and the debug target
11335has support for disabling tracepoints during a trace experiment, then the
11336change will be effective immediately. Otherwise, it will be applied to the
11337next trace experiment.
b37052ae
EZ
11338
11339@kindex enable tracepoint
11340@item enable tracepoint @r{[}@var{num}@r{]}
d248b706
KY
11341Enable tracepoint @var{num}, or all tracepoints. If this command is
11342issued during a trace experiment and the debug target supports enabling
11343tracepoints during a trace experiment, then the enabled tracepoints will
11344become effective immediately. Otherwise, they will become effective the
11345next time a trace experiment is run.
b37052ae
EZ
11346@end table
11347
11348@node Tracepoint Passcounts
11349@subsection Tracepoint Passcounts
11350
11351@table @code
11352@kindex passcount
11353@cindex tracepoint pass count
11354@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
11355Set the @dfn{passcount} of a tracepoint. The passcount is a way to
11356automatically stop a trace experiment. If a tracepoint's passcount is
11357@var{n}, then the trace experiment will be automatically stopped on
11358the @var{n}'th time that tracepoint is hit. If the tracepoint number
11359@var{num} is not specified, the @code{passcount} command sets the
11360passcount of the most recently defined tracepoint. If no passcount is
11361given, the trace experiment will run until stopped explicitly by the
11362user.
11363
11364Examples:
11365
11366@smallexample
b383017d 11367(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 11368@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
11369
11370(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 11371@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
11372(@value{GDBP}) @b{trace foo}
11373(@value{GDBP}) @b{pass 3}
11374(@value{GDBP}) @b{trace bar}
11375(@value{GDBP}) @b{pass 2}
11376(@value{GDBP}) @b{trace baz}
11377(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
11378@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
11379@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
11380@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
11381@end smallexample
11382@end table
11383
782b2b07
SS
11384@node Tracepoint Conditions
11385@subsection Tracepoint Conditions
11386@cindex conditional tracepoints
11387@cindex tracepoint conditions
11388
11389The simplest sort of tracepoint collects data every time your program
11390reaches a specified place. You can also specify a @dfn{condition} for
11391a tracepoint. A condition is just a Boolean expression in your
11392programming language (@pxref{Expressions, ,Expressions}). A
11393tracepoint with a condition evaluates the expression each time your
11394program reaches it, and data collection happens only if the condition
11395is true.
11396
11397Tracepoint conditions can be specified when a tracepoint is set, by
11398using @samp{if} in the arguments to the @code{trace} command.
11399@xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
11400also be set or changed at any time with the @code{condition} command,
11401just as with breakpoints.
11402
11403Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
11404the conditional expression itself. Instead, @value{GDBN} encodes the
6dcd5565 11405expression into an agent expression (@pxref{Agent Expressions})
782b2b07
SS
11406suitable for execution on the target, independently of @value{GDBN}.
11407Global variables become raw memory locations, locals become stack
11408accesses, and so forth.
11409
11410For instance, suppose you have a function that is usually called
11411frequently, but should not be called after an error has occurred. You
11412could use the following tracepoint command to collect data about calls
11413of that function that happen while the error code is propagating
11414through the program; an unconditional tracepoint could end up
11415collecting thousands of useless trace frames that you would have to
11416search through.
11417
11418@smallexample
11419(@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
11420@end smallexample
11421
f61e138d
SS
11422@node Trace State Variables
11423@subsection Trace State Variables
11424@cindex trace state variables
11425
11426A @dfn{trace state variable} is a special type of variable that is
11427created and managed by target-side code. The syntax is the same as
11428that for GDB's convenience variables (a string prefixed with ``$''),
11429but they are stored on the target. They must be created explicitly,
11430using a @code{tvariable} command. They are always 64-bit signed
11431integers.
11432
11433Trace state variables are remembered by @value{GDBN}, and downloaded
11434to the target along with tracepoint information when the trace
11435experiment starts. There are no intrinsic limits on the number of
11436trace state variables, beyond memory limitations of the target.
11437
11438@cindex convenience variables, and trace state variables
11439Although trace state variables are managed by the target, you can use
11440them in print commands and expressions as if they were convenience
11441variables; @value{GDBN} will get the current value from the target
11442while the trace experiment is running. Trace state variables share
11443the same namespace as other ``$'' variables, which means that you
11444cannot have trace state variables with names like @code{$23} or
11445@code{$pc}, nor can you have a trace state variable and a convenience
11446variable with the same name.
11447
11448@table @code
11449
11450@item tvariable $@var{name} [ = @var{expression} ]
11451@kindex tvariable
11452The @code{tvariable} command creates a new trace state variable named
11453@code{$@var{name}}, and optionally gives it an initial value of
11454@var{expression}. @var{expression} is evaluated when this command is
11455entered; the result will be converted to an integer if possible,
11456otherwise @value{GDBN} will report an error. A subsequent
11457@code{tvariable} command specifying the same name does not create a
11458variable, but instead assigns the supplied initial value to the
11459existing variable of that name, overwriting any previous initial
11460value. The default initial value is 0.
11461
11462@item info tvariables
11463@kindex info tvariables
11464List all the trace state variables along with their initial values.
11465Their current values may also be displayed, if the trace experiment is
11466currently running.
11467
11468@item delete tvariable @r{[} $@var{name} @dots{} @r{]}
11469@kindex delete tvariable
11470Delete the given trace state variables, or all of them if no arguments
11471are specified.
11472
11473@end table
11474
b37052ae
EZ
11475@node Tracepoint Actions
11476@subsection Tracepoint Action Lists
11477
11478@table @code
11479@kindex actions
11480@cindex tracepoint actions
11481@item actions @r{[}@var{num}@r{]}
11482This command will prompt for a list of actions to be taken when the
11483tracepoint is hit. If the tracepoint number @var{num} is not
11484specified, this command sets the actions for the one that was most
11485recently defined (so that you can define a tracepoint and then say
11486@code{actions} without bothering about its number). You specify the
11487actions themselves on the following lines, one action at a time, and
11488terminate the actions list with a line containing just @code{end}. So
7d13fe92 11489far, the only defined actions are @code{collect}, @code{teval}, and
b37052ae
EZ
11490@code{while-stepping}.
11491
5a9351ae
SS
11492@code{actions} is actually equivalent to @code{commands} (@pxref{Break
11493Commands, ,Breakpoint Command Lists}), except that only the defined
11494actions are allowed; any other @value{GDBN} command is rejected.
11495
b37052ae
EZ
11496@cindex remove actions from a tracepoint
11497To remove all actions from a tracepoint, type @samp{actions @var{num}}
11498and follow it immediately with @samp{end}.
11499
11500@smallexample
11501(@value{GDBP}) @b{collect @var{data}} // collect some data
11502
6826cf00 11503(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 11504
6826cf00 11505(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
11506@end smallexample
11507
11508In the following example, the action list begins with @code{collect}
11509commands indicating the things to be collected when the tracepoint is
11510hit. Then, in order to single-step and collect additional data
11511following the tracepoint, a @code{while-stepping} command is used,
7d13fe92
SS
11512followed by the list of things to be collected after each step in a
11513sequence of single steps. The @code{while-stepping} command is
11514terminated by its own separate @code{end} command. Lastly, the action
11515list is terminated by an @code{end} command.
b37052ae
EZ
11516
11517@smallexample
11518(@value{GDBP}) @b{trace foo}
11519(@value{GDBP}) @b{actions}
11520Enter actions for tracepoint 1, one per line:
11521> collect bar,baz
11522> collect $regs
11523> while-stepping 12
5a9351ae 11524 > collect $pc, arr[i]
b37052ae
EZ
11525 > end
11526end
11527@end smallexample
11528
11529@kindex collect @r{(tracepoints)}
3065dfb6 11530@item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
b37052ae
EZ
11531Collect values of the given expressions when the tracepoint is hit.
11532This command accepts a comma-separated list of any valid expressions.
11533In addition to global, static, or local variables, the following
11534special arguments are supported:
11535
11536@table @code
11537@item $regs
0fb4aa4b 11538Collect all registers.
b37052ae
EZ
11539
11540@item $args
0fb4aa4b 11541Collect all function arguments.
b37052ae
EZ
11542
11543@item $locals
0fb4aa4b
PA
11544Collect all local variables.
11545
6710bf39
SS
11546@item $_ret
11547Collect the return address. This is helpful if you want to see more
11548of a backtrace.
11549
62e5f89c
SDJ
11550@item $_probe_argc
11551Collects the number of arguments from the static probe at which the
11552tracepoint is located.
11553@xref{Static Probe Points}.
11554
11555@item $_probe_arg@var{n}
11556@var{n} is an integer between 0 and 11. Collects the @var{n}th argument
11557from the static probe at which the tracepoint is located.
11558@xref{Static Probe Points}.
11559
0fb4aa4b
PA
11560@item $_sdata
11561@vindex $_sdata@r{, collect}
11562Collect static tracepoint marker specific data. Only available for
11563static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
11564Lists}. On the UST static tracepoints library backend, an
11565instrumentation point resembles a @code{printf} function call. The
11566tracing library is able to collect user specified data formatted to a
11567character string using the format provided by the programmer that
11568instrumented the program. Other backends have similar mechanisms.
11569Here's an example of a UST marker call:
11570
11571@smallexample
11572 const char master_name[] = "$your_name";
11573 trace_mark(channel1, marker1, "hello %s", master_name)
11574@end smallexample
11575
11576In this case, collecting @code{$_sdata} collects the string
11577@samp{hello $yourname}. When analyzing the trace buffer, you can
11578inspect @samp{$_sdata} like any other variable available to
11579@value{GDBN}.
b37052ae
EZ
11580@end table
11581
11582You can give several consecutive @code{collect} commands, each one
11583with a single argument, or one @code{collect} command with several
5a9351ae 11584arguments separated by commas; the effect is the same.
b37052ae 11585
3065dfb6
SS
11586The optional @var{mods} changes the usual handling of the arguments.
11587@code{s} requests that pointers to chars be handled as strings, in
11588particular collecting the contents of the memory being pointed at, up
11589to the first zero. The upper bound is by default the value of the
11590@code{print elements} variable; if @code{s} is followed by a decimal
11591number, that is the upper bound instead. So for instance
11592@samp{collect/s25 mystr} collects as many as 25 characters at
11593@samp{mystr}.
11594
f5c37c66
EZ
11595The command @code{info scope} (@pxref{Symbols, info scope}) is
11596particularly useful for figuring out what data to collect.
11597
6da95a67
SS
11598@kindex teval @r{(tracepoints)}
11599@item teval @var{expr1}, @var{expr2}, @dots{}
11600Evaluate the given expressions when the tracepoint is hit. This
11601command accepts a comma-separated list of expressions. The results
11602are discarded, so this is mainly useful for assigning values to trace
11603state variables (@pxref{Trace State Variables}) without adding those
11604values to the trace buffer, as would be the case if the @code{collect}
11605action were used.
11606
b37052ae
EZ
11607@kindex while-stepping @r{(tracepoints)}
11608@item while-stepping @var{n}
c9429232 11609Perform @var{n} single-step instruction traces after the tracepoint,
7d13fe92 11610collecting new data after each step. The @code{while-stepping}
c9429232
SS
11611command is followed by the list of what to collect while stepping
11612(followed by its own @code{end} command):
b37052ae
EZ
11613
11614@smallexample
11615> while-stepping 12
11616 > collect $regs, myglobal
11617 > end
11618>
11619@end smallexample
11620
11621@noindent
7d13fe92
SS
11622Note that @code{$pc} is not automatically collected by
11623@code{while-stepping}; you need to explicitly collect that register if
11624you need it. You may abbreviate @code{while-stepping} as @code{ws} or
b37052ae 11625@code{stepping}.
236f1d4d
SS
11626
11627@item set default-collect @var{expr1}, @var{expr2}, @dots{}
11628@kindex set default-collect
11629@cindex default collection action
11630This variable is a list of expressions to collect at each tracepoint
11631hit. It is effectively an additional @code{collect} action prepended
11632to every tracepoint action list. The expressions are parsed
11633individually for each tracepoint, so for instance a variable named
11634@code{xyz} may be interpreted as a global for one tracepoint, and a
11635local for another, as appropriate to the tracepoint's location.
11636
11637@item show default-collect
11638@kindex show default-collect
11639Show the list of expressions that are collected by default at each
11640tracepoint hit.
11641
b37052ae
EZ
11642@end table
11643
11644@node Listing Tracepoints
11645@subsection Listing Tracepoints
11646
11647@table @code
e5a67952
MS
11648@kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
11649@kindex info tp @r{[}@var{n}@dots{}@r{]}
b37052ae 11650@cindex information about tracepoints
e5a67952 11651@item info tracepoints @r{[}@var{num}@dots{}@r{]}
1042e4c0
SS
11652Display information about the tracepoint @var{num}. If you don't
11653specify a tracepoint number, displays information about all the
11654tracepoints defined so far. The format is similar to that used for
11655@code{info breakpoints}; in fact, @code{info tracepoints} is the same
11656command, simply restricting itself to tracepoints.
11657
11658A tracepoint's listing may include additional information specific to
11659tracing:
b37052ae
EZ
11660
11661@itemize @bullet
11662@item
b37052ae 11663its passcount as given by the @code{passcount @var{n}} command
f2a8bc8a
YQ
11664
11665@item
11666the state about installed on target of each location
b37052ae
EZ
11667@end itemize
11668
11669@smallexample
11670(@value{GDBP}) @b{info trace}
1042e4c0
SS
11671Num Type Disp Enb Address What
116721 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
5a9351ae
SS
11673 while-stepping 20
11674 collect globfoo, $regs
11675 end
11676 collect globfoo2
11677 end
1042e4c0 11678 pass count 1200
f2a8bc8a
YQ
116792 tracepoint keep y <MULTIPLE>
11680 collect $eip
116812.1 y 0x0804859c in func4 at change-loc.h:35
11682 installed on target
116832.2 y 0xb7ffc480 in func4 at change-loc.h:35
11684 installed on target
116852.3 y <PENDING> set_tracepoint
116863 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
11687 not installed on target
b37052ae
EZ
11688(@value{GDBP})
11689@end smallexample
11690
11691@noindent
11692This command can be abbreviated @code{info tp}.
11693@end table
11694
0fb4aa4b
PA
11695@node Listing Static Tracepoint Markers
11696@subsection Listing Static Tracepoint Markers
11697
11698@table @code
11699@kindex info static-tracepoint-markers
11700@cindex information about static tracepoint markers
11701@item info static-tracepoint-markers
11702Display information about all static tracepoint markers defined in the
11703program.
11704
11705For each marker, the following columns are printed:
11706
11707@table @emph
11708@item Count
11709An incrementing counter, output to help readability. This is not a
11710stable identifier.
11711@item ID
11712The marker ID, as reported by the target.
11713@item Enabled or Disabled
11714Probed markers are tagged with @samp{y}. @samp{n} identifies marks
11715that are not enabled.
11716@item Address
11717Where the marker is in your program, as a memory address.
11718@item What
11719Where the marker is in the source for your program, as a file and line
11720number. If the debug information included in the program does not
11721allow @value{GDBN} to locate the source of the marker, this column
11722will be left blank.
11723@end table
11724
11725@noindent
11726In addition, the following information may be printed for each marker:
11727
11728@table @emph
11729@item Data
11730User data passed to the tracing library by the marker call. In the
11731UST backend, this is the format string passed as argument to the
11732marker call.
11733@item Static tracepoints probing the marker
11734The list of static tracepoints attached to the marker.
11735@end table
11736
11737@smallexample
11738(@value{GDBP}) info static-tracepoint-markers
11739Cnt ID Enb Address What
117401 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
11741 Data: number1 %d number2 %d
11742 Probed by static tracepoints: #2
117432 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
11744 Data: str %s
11745(@value{GDBP})
11746@end smallexample
11747@end table
11748
79a6e687
BW
11749@node Starting and Stopping Trace Experiments
11750@subsection Starting and Stopping Trace Experiments
b37052ae
EZ
11751
11752@table @code
f196051f 11753@kindex tstart [ @var{notes} ]
b37052ae
EZ
11754@cindex start a new trace experiment
11755@cindex collected data discarded
11756@item tstart
f196051f
SS
11757This command starts the trace experiment, and begins collecting data.
11758It has the side effect of discarding all the data collected in the
11759trace buffer during the previous trace experiment. If any arguments
11760are supplied, they are taken as a note and stored with the trace
11761experiment's state. The notes may be arbitrary text, and are
11762especially useful with disconnected tracing in a multi-user context;
11763the notes can explain what the trace is doing, supply user contact
11764information, and so forth.
11765
11766@kindex tstop [ @var{notes} ]
b37052ae
EZ
11767@cindex stop a running trace experiment
11768@item tstop
f196051f
SS
11769This command stops the trace experiment. If any arguments are
11770supplied, they are recorded with the experiment as a note. This is
11771useful if you are stopping a trace started by someone else, for
11772instance if the trace is interfering with the system's behavior and
11773needs to be stopped quickly.
b37052ae 11774
68c71a2e 11775@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
11776automatically if any tracepoint's passcount is reached
11777(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
11778
11779@kindex tstatus
11780@cindex status of trace data collection
11781@cindex trace experiment, status of
11782@item tstatus
11783This command displays the status of the current trace data
11784collection.
11785@end table
11786
11787Here is an example of the commands we described so far:
11788
11789@smallexample
11790(@value{GDBP}) @b{trace gdb_c_test}
11791(@value{GDBP}) @b{actions}
11792Enter actions for tracepoint #1, one per line.
11793> collect $regs,$locals,$args
11794> while-stepping 11
11795 > collect $regs
11796 > end
11797> end
11798(@value{GDBP}) @b{tstart}
11799 [time passes @dots{}]
11800(@value{GDBP}) @b{tstop}
11801@end smallexample
11802
03f2bd59 11803@anchor{disconnected tracing}
d5551862
SS
11804@cindex disconnected tracing
11805You can choose to continue running the trace experiment even if
11806@value{GDBN} disconnects from the target, voluntarily or
11807involuntarily. For commands such as @code{detach}, the debugger will
11808ask what you want to do with the trace. But for unexpected
11809terminations (@value{GDBN} crash, network outage), it would be
11810unfortunate to lose hard-won trace data, so the variable
11811@code{disconnected-tracing} lets you decide whether the trace should
11812continue running without @value{GDBN}.
11813
11814@table @code
11815@item set disconnected-tracing on
11816@itemx set disconnected-tracing off
11817@kindex set disconnected-tracing
11818Choose whether a tracing run should continue to run if @value{GDBN}
11819has disconnected from the target. Note that @code{detach} or
11820@code{quit} will ask you directly what to do about a running trace no
11821matter what this variable's setting, so the variable is mainly useful
11822for handling unexpected situations, such as loss of the network.
11823
11824@item show disconnected-tracing
11825@kindex show disconnected-tracing
11826Show the current choice for disconnected tracing.
11827
11828@end table
11829
11830When you reconnect to the target, the trace experiment may or may not
11831still be running; it might have filled the trace buffer in the
11832meantime, or stopped for one of the other reasons. If it is running,
11833it will continue after reconnection.
11834
11835Upon reconnection, the target will upload information about the
11836tracepoints in effect. @value{GDBN} will then compare that
11837information to the set of tracepoints currently defined, and attempt
11838to match them up, allowing for the possibility that the numbers may
11839have changed due to creation and deletion in the meantime. If one of
11840the target's tracepoints does not match any in @value{GDBN}, the
11841debugger will create a new tracepoint, so that you have a number with
11842which to specify that tracepoint. This matching-up process is
11843necessarily heuristic, and it may result in useless tracepoints being
11844created; you may simply delete them if they are of no use.
b37052ae 11845
4daf5ac0
SS
11846@cindex circular trace buffer
11847If your target agent supports a @dfn{circular trace buffer}, then you
11848can run a trace experiment indefinitely without filling the trace
11849buffer; when space runs out, the agent deletes already-collected trace
11850frames, oldest first, until there is enough room to continue
11851collecting. This is especially useful if your tracepoints are being
11852hit too often, and your trace gets terminated prematurely because the
11853buffer is full. To ask for a circular trace buffer, simply set
81896e36 11854@samp{circular-trace-buffer} to on. You can set this at any time,
4daf5ac0
SS
11855including during tracing; if the agent can do it, it will change
11856buffer handling on the fly, otherwise it will not take effect until
11857the next run.
11858
11859@table @code
11860@item set circular-trace-buffer on
11861@itemx set circular-trace-buffer off
11862@kindex set circular-trace-buffer
11863Choose whether a tracing run should use a linear or circular buffer
11864for trace data. A linear buffer will not lose any trace data, but may
11865fill up prematurely, while a circular buffer will discard old trace
11866data, but it will have always room for the latest tracepoint hits.
11867
11868@item show circular-trace-buffer
11869@kindex show circular-trace-buffer
11870Show the current choice for the trace buffer. Note that this may not
11871match the agent's current buffer handling, nor is it guaranteed to
11872match the setting that might have been in effect during a past run,
11873for instance if you are looking at frames from a trace file.
11874
11875@end table
11876
f6f899bf
HAQ
11877@table @code
11878@item set trace-buffer-size @var{n}
11879@kindex set trace-buffer-size
11880Request that the target use a trace buffer of @var{n} bytes. Not all
11881targets will honor the request; they may have a compiled-in size for
11882the trace buffer, or some other limitation. Set to a value of
11883@code{-1} to let the target use whatever size it likes. This is also
11884the default.
11885
11886@item show trace-buffer-size
11887@kindex show trace-buffer-size
11888Show the current requested size for the trace buffer. Note that this
11889will only match the actual size if the target supports size-setting,
11890and was able to handle the requested size. For instance, if the
11891target can only change buffer size between runs, this variable will
11892not reflect the change until the next run starts. Use @code{tstatus}
11893to get a report of the actual buffer size.
11894@end table
11895
f196051f
SS
11896@table @code
11897@item set trace-user @var{text}
11898@kindex set trace-user
11899
11900@item show trace-user
11901@kindex show trace-user
11902
11903@item set trace-notes @var{text}
11904@kindex set trace-notes
11905Set the trace run's notes.
11906
11907@item show trace-notes
11908@kindex show trace-notes
11909Show the trace run's notes.
11910
11911@item set trace-stop-notes @var{text}
11912@kindex set trace-stop-notes
11913Set the trace run's stop notes. The handling of the note is as for
11914@code{tstop} arguments; the set command is convenient way to fix a
11915stop note that is mistaken or incomplete.
11916
11917@item show trace-stop-notes
11918@kindex show trace-stop-notes
11919Show the trace run's stop notes.
11920
11921@end table
11922
c9429232
SS
11923@node Tracepoint Restrictions
11924@subsection Tracepoint Restrictions
11925
11926@cindex tracepoint restrictions
11927There are a number of restrictions on the use of tracepoints. As
11928described above, tracepoint data gathering occurs on the target
11929without interaction from @value{GDBN}. Thus the full capabilities of
11930the debugger are not available during data gathering, and then at data
11931examination time, you will be limited by only having what was
11932collected. The following items describe some common problems, but it
11933is not exhaustive, and you may run into additional difficulties not
11934mentioned here.
11935
11936@itemize @bullet
11937
11938@item
11939Tracepoint expressions are intended to gather objects (lvalues). Thus
11940the full flexibility of GDB's expression evaluator is not available.
11941You cannot call functions, cast objects to aggregate types, access
11942convenience variables or modify values (except by assignment to trace
11943state variables). Some language features may implicitly call
11944functions (for instance Objective-C fields with accessors), and therefore
11945cannot be collected either.
11946
11947@item
11948Collection of local variables, either individually or in bulk with
11949@code{$locals} or @code{$args}, during @code{while-stepping} may
11950behave erratically. The stepping action may enter a new scope (for
11951instance by stepping into a function), or the location of the variable
11952may change (for instance it is loaded into a register). The
11953tracepoint data recorded uses the location information for the
11954variables that is correct for the tracepoint location. When the
11955tracepoint is created, it is not possible, in general, to determine
11956where the steps of a @code{while-stepping} sequence will advance the
11957program---particularly if a conditional branch is stepped.
11958
11959@item
11960Collection of an incompletely-initialized or partially-destroyed object
11961may result in something that @value{GDBN} cannot display, or displays
11962in a misleading way.
11963
11964@item
11965When @value{GDBN} displays a pointer to character it automatically
11966dereferences the pointer to also display characters of the string
11967being pointed to. However, collecting the pointer during tracing does
11968not automatically collect the string. You need to explicitly
11969dereference the pointer and provide size information if you want to
11970collect not only the pointer, but the memory pointed to. For example,
11971@code{*ptr@@50} can be used to collect the 50 element array pointed to
11972by @code{ptr}.
11973
11974@item
11975It is not possible to collect a complete stack backtrace at a
11976tracepoint. Instead, you may collect the registers and a few hundred
d99f7e48 11977bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
c9429232
SS
11978(adjust to use the name of the actual stack pointer register on your
11979target architecture, and the amount of stack you wish to capture).
11980Then the @code{backtrace} command will show a partial backtrace when
11981using a trace frame. The number of stack frames that can be examined
11982depends on the sizes of the frames in the collected stack. Note that
11983if you ask for a block so large that it goes past the bottom of the
11984stack, the target agent may report an error trying to read from an
11985invalid address.
11986
af54718e
SS
11987@item
11988If you do not collect registers at a tracepoint, @value{GDBN} can
11989infer that the value of @code{$pc} must be the same as the address of
11990the tracepoint and use that when you are looking at a trace frame
11991for that tracepoint. However, this cannot work if the tracepoint has
11992multiple locations (for instance if it was set in a function that was
11993inlined), or if it has a @code{while-stepping} loop. In those cases
11994@value{GDBN} will warn you that it can't infer @code{$pc}, and default
11995it to zero.
11996
c9429232
SS
11997@end itemize
11998
b37052ae 11999@node Analyze Collected Data
79a6e687 12000@section Using the Collected Data
b37052ae
EZ
12001
12002After the tracepoint experiment ends, you use @value{GDBN} commands
12003for examining the trace data. The basic idea is that each tracepoint
12004collects a trace @dfn{snapshot} every time it is hit and another
12005snapshot every time it single-steps. All these snapshots are
12006consecutively numbered from zero and go into a buffer, and you can
12007examine them later. The way you examine them is to @dfn{focus} on a
12008specific trace snapshot. When the remote stub is focused on a trace
12009snapshot, it will respond to all @value{GDBN} requests for memory and
12010registers by reading from the buffer which belongs to that snapshot,
12011rather than from @emph{real} memory or registers of the program being
12012debugged. This means that @strong{all} @value{GDBN} commands
12013(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
12014behave as if we were currently debugging the program state as it was
12015when the tracepoint occurred. Any requests for data that are not in
12016the buffer will fail.
12017
12018@menu
12019* tfind:: How to select a trace snapshot
12020* tdump:: How to display all data for a snapshot
6149aea9 12021* save tracepoints:: How to save tracepoints for a future run
b37052ae
EZ
12022@end menu
12023
12024@node tfind
12025@subsection @code{tfind @var{n}}
12026
12027@kindex tfind
12028@cindex select trace snapshot
12029@cindex find trace snapshot
12030The basic command for selecting a trace snapshot from the buffer is
12031@code{tfind @var{n}}, which finds trace snapshot number @var{n},
12032counting from zero. If no argument @var{n} is given, the next
12033snapshot is selected.
12034
12035Here are the various forms of using the @code{tfind} command.
12036
12037@table @code
12038@item tfind start
12039Find the first snapshot in the buffer. This is a synonym for
12040@code{tfind 0} (since 0 is the number of the first snapshot).
12041
12042@item tfind none
12043Stop debugging trace snapshots, resume @emph{live} debugging.
12044
12045@item tfind end
12046Same as @samp{tfind none}.
12047
12048@item tfind
12049No argument means find the next trace snapshot.
12050
12051@item tfind -
12052Find the previous trace snapshot before the current one. This permits
12053retracing earlier steps.
12054
12055@item tfind tracepoint @var{num}
12056Find the next snapshot associated with tracepoint @var{num}. Search
12057proceeds forward from the last examined trace snapshot. If no
12058argument @var{num} is given, it means find the next snapshot collected
12059for the same tracepoint as the current snapshot.
12060
12061@item tfind pc @var{addr}
12062Find the next snapshot associated with the value @var{addr} of the
12063program counter. Search proceeds forward from the last examined trace
12064snapshot. If no argument @var{addr} is given, it means find the next
12065snapshot with the same value of PC as the current snapshot.
12066
12067@item tfind outside @var{addr1}, @var{addr2}
12068Find the next snapshot whose PC is outside the given range of
081dfbf7 12069addresses (exclusive).
b37052ae
EZ
12070
12071@item tfind range @var{addr1}, @var{addr2}
12072Find the next snapshot whose PC is between @var{addr1} and
081dfbf7 12073@var{addr2} (inclusive).
b37052ae
EZ
12074
12075@item tfind line @r{[}@var{file}:@r{]}@var{n}
12076Find the next snapshot associated with the source line @var{n}. If
12077the optional argument @var{file} is given, refer to line @var{n} in
12078that source file. Search proceeds forward from the last examined
12079trace snapshot. If no argument @var{n} is given, it means find the
12080next line other than the one currently being examined; thus saying
12081@code{tfind line} repeatedly can appear to have the same effect as
12082stepping from line to line in a @emph{live} debugging session.
12083@end table
12084
12085The default arguments for the @code{tfind} commands are specifically
12086designed to make it easy to scan through the trace buffer. For
12087instance, @code{tfind} with no argument selects the next trace
12088snapshot, and @code{tfind -} with no argument selects the previous
12089trace snapshot. So, by giving one @code{tfind} command, and then
12090simply hitting @key{RET} repeatedly you can examine all the trace
12091snapshots in order. Or, by saying @code{tfind -} and then hitting
12092@key{RET} repeatedly you can examine the snapshots in reverse order.
12093The @code{tfind line} command with no argument selects the snapshot
12094for the next source line executed. The @code{tfind pc} command with
12095no argument selects the next snapshot with the same program counter
12096(PC) as the current frame. The @code{tfind tracepoint} command with
12097no argument selects the next trace snapshot collected by the same
12098tracepoint as the current one.
12099
12100In addition to letting you scan through the trace buffer manually,
12101these commands make it easy to construct @value{GDBN} scripts that
12102scan through the trace buffer and print out whatever collected data
12103you are interested in. Thus, if we want to examine the PC, FP, and SP
12104registers from each trace frame in the buffer, we can say this:
12105
12106@smallexample
12107(@value{GDBP}) @b{tfind start}
12108(@value{GDBP}) @b{while ($trace_frame != -1)}
12109> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
12110 $trace_frame, $pc, $sp, $fp
12111> tfind
12112> end
12113
12114Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
12115Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
12116Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
12117Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
12118Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
12119Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
12120Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
12121Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
12122Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
12123Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
12124Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
12125@end smallexample
12126
12127Or, if we want to examine the variable @code{X} at each source line in
12128the buffer:
12129
12130@smallexample
12131(@value{GDBP}) @b{tfind start}
12132(@value{GDBP}) @b{while ($trace_frame != -1)}
12133> printf "Frame %d, X == %d\n", $trace_frame, X
12134> tfind line
12135> end
12136
12137Frame 0, X = 1
12138Frame 7, X = 2
12139Frame 13, X = 255
12140@end smallexample
12141
12142@node tdump
12143@subsection @code{tdump}
12144@kindex tdump
12145@cindex dump all data collected at tracepoint
12146@cindex tracepoint data, display
12147
12148This command takes no arguments. It prints all the data collected at
12149the current trace snapshot.
12150
12151@smallexample
12152(@value{GDBP}) @b{trace 444}
12153(@value{GDBP}) @b{actions}
12154Enter actions for tracepoint #2, one per line:
12155> collect $regs, $locals, $args, gdb_long_test
12156> end
12157
12158(@value{GDBP}) @b{tstart}
12159
12160(@value{GDBP}) @b{tfind line 444}
12161#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
12162at gdb_test.c:444
12163444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
12164
12165(@value{GDBP}) @b{tdump}
12166Data collected at tracepoint 2, trace frame 1:
12167d0 0xc4aa0085 -995491707
12168d1 0x18 24
12169d2 0x80 128
12170d3 0x33 51
12171d4 0x71aea3d 119204413
12172d5 0x22 34
12173d6 0xe0 224
12174d7 0x380035 3670069
12175a0 0x19e24a 1696330
12176a1 0x3000668 50333288
12177a2 0x100 256
12178a3 0x322000 3284992
12179a4 0x3000698 50333336
12180a5 0x1ad3cc 1758156
12181fp 0x30bf3c 0x30bf3c
12182sp 0x30bf34 0x30bf34
12183ps 0x0 0
12184pc 0x20b2c8 0x20b2c8
12185fpcontrol 0x0 0
12186fpstatus 0x0 0
12187fpiaddr 0x0 0
12188p = 0x20e5b4 "gdb-test"
12189p1 = (void *) 0x11
12190p2 = (void *) 0x22
12191p3 = (void *) 0x33
12192p4 = (void *) 0x44
12193p5 = (void *) 0x55
12194p6 = (void *) 0x66
12195gdb_long_test = 17 '\021'
12196
12197(@value{GDBP})
12198@end smallexample
12199
af54718e
SS
12200@code{tdump} works by scanning the tracepoint's current collection
12201actions and printing the value of each expression listed. So
12202@code{tdump} can fail, if after a run, you change the tracepoint's
12203actions to mention variables that were not collected during the run.
12204
12205Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
12206uses the collected value of @code{$pc} to distinguish between trace
12207frames that were collected at the tracepoint hit, and frames that were
12208collected while stepping. This allows it to correctly choose whether
12209to display the basic list of collections, or the collections from the
12210body of the while-stepping loop. However, if @code{$pc} was not collected,
12211then @code{tdump} will always attempt to dump using the basic collection
12212list, and may fail if a while-stepping frame does not include all the
12213same data that is collected at the tracepoint hit.
12214@c This is getting pretty arcane, example would be good.
12215
6149aea9
PA
12216@node save tracepoints
12217@subsection @code{save tracepoints @var{filename}}
12218@kindex save tracepoints
b37052ae
EZ
12219@kindex save-tracepoints
12220@cindex save tracepoints for future sessions
12221
12222This command saves all current tracepoint definitions together with
12223their actions and passcounts, into a file @file{@var{filename}}
12224suitable for use in a later debugging session. To read the saved
12225tracepoint definitions, use the @code{source} command (@pxref{Command
6149aea9
PA
12226Files}). The @w{@code{save-tracepoints}} command is a deprecated
12227alias for @w{@code{save tracepoints}}
b37052ae
EZ
12228
12229@node Tracepoint Variables
12230@section Convenience Variables for Tracepoints
12231@cindex tracepoint variables
12232@cindex convenience variables for tracepoints
12233
12234@table @code
12235@vindex $trace_frame
12236@item (int) $trace_frame
12237The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
12238snapshot is selected.
12239
12240@vindex $tracepoint
12241@item (int) $tracepoint
12242The tracepoint for the current trace snapshot.
12243
12244@vindex $trace_line
12245@item (int) $trace_line
12246The line number for the current trace snapshot.
12247
12248@vindex $trace_file
12249@item (char []) $trace_file
12250The source file for the current trace snapshot.
12251
12252@vindex $trace_func
12253@item (char []) $trace_func
12254The name of the function containing @code{$tracepoint}.
12255@end table
12256
12257Note: @code{$trace_file} is not suitable for use in @code{printf},
12258use @code{output} instead.
12259
12260Here's a simple example of using these convenience variables for
12261stepping through all the trace snapshots and printing some of their
f61e138d
SS
12262data. Note that these are not the same as trace state variables,
12263which are managed by the target.
b37052ae
EZ
12264
12265@smallexample
12266(@value{GDBP}) @b{tfind start}
12267
12268(@value{GDBP}) @b{while $trace_frame != -1}
12269> output $trace_file
12270> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
12271> tfind
12272> end
12273@end smallexample
12274
00bf0b85
SS
12275@node Trace Files
12276@section Using Trace Files
12277@cindex trace files
12278
12279In some situations, the target running a trace experiment may no
12280longer be available; perhaps it crashed, or the hardware was needed
12281for a different activity. To handle these cases, you can arrange to
12282dump the trace data into a file, and later use that file as a source
12283of trace data, via the @code{target tfile} command.
12284
12285@table @code
12286
12287@kindex tsave
12288@item tsave [ -r ] @var{filename}
12289Save the trace data to @var{filename}. By default, this command
12290assumes that @var{filename} refers to the host filesystem, so if
12291necessary @value{GDBN} will copy raw trace data up from the target and
12292then save it. If the target supports it, you can also supply the
12293optional argument @code{-r} (``remote'') to direct the target to save
12294the data directly into @var{filename} in its own filesystem, which may be
12295more efficient if the trace buffer is very large. (Note, however, that
12296@code{target tfile} can only read from files accessible to the host.)
12297
12298@kindex target tfile
12299@kindex tfile
12300@item target tfile @var{filename}
12301Use the file named @var{filename} as a source of trace data. Commands
12302that examine data work as they do with a live target, but it is not
12303possible to run any new trace experiments. @code{tstatus} will report
12304the state of the trace run at the moment the data was saved, as well
12305as the current trace frame you are examining. @var{filename} must be
12306on a filesystem accessible to the host.
12307
12308@end table
12309
df0cd8c5
JB
12310@node Overlays
12311@chapter Debugging Programs That Use Overlays
12312@cindex overlays
12313
12314If your program is too large to fit completely in your target system's
12315memory, you can sometimes use @dfn{overlays} to work around this
12316problem. @value{GDBN} provides some support for debugging programs that
12317use overlays.
12318
12319@menu
12320* How Overlays Work:: A general explanation of overlays.
12321* Overlay Commands:: Managing overlays in @value{GDBN}.
12322* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
12323 mapped by asking the inferior.
12324* Overlay Sample Program:: A sample program using overlays.
12325@end menu
12326
12327@node How Overlays Work
12328@section How Overlays Work
12329@cindex mapped overlays
12330@cindex unmapped overlays
12331@cindex load address, overlay's
12332@cindex mapped address
12333@cindex overlay area
12334
12335Suppose you have a computer whose instruction address space is only 64
12336kilobytes long, but which has much more memory which can be accessed by
12337other means: special instructions, segment registers, or memory
12338management hardware, for example. Suppose further that you want to
12339adapt a program which is larger than 64 kilobytes to run on this system.
12340
12341One solution is to identify modules of your program which are relatively
12342independent, and need not call each other directly; call these modules
12343@dfn{overlays}. Separate the overlays from the main program, and place
12344their machine code in the larger memory. Place your main program in
12345instruction memory, but leave at least enough space there to hold the
12346largest overlay as well.
12347
12348Now, to call a function located in an overlay, you must first copy that
12349overlay's machine code from the large memory into the space set aside
12350for it in the instruction memory, and then jump to its entry point
12351there.
12352
c928edc0
AC
12353@c NB: In the below the mapped area's size is greater or equal to the
12354@c size of all overlays. This is intentional to remind the developer
12355@c that overlays don't necessarily need to be the same size.
12356
474c8240 12357@smallexample
df0cd8c5 12358@group
c928edc0
AC
12359 Data Instruction Larger
12360Address Space Address Space Address Space
12361+-----------+ +-----------+ +-----------+
12362| | | | | |
12363+-----------+ +-----------+ +-----------+<-- overlay 1
12364| program | | main | .----| overlay 1 | load address
12365| variables | | program | | +-----------+
12366| and heap | | | | | |
12367+-----------+ | | | +-----------+<-- overlay 2
12368| | +-----------+ | | | load address
12369+-----------+ | | | .-| overlay 2 |
12370 | | | | | |
12371 mapped --->+-----------+ | | +-----------+
12372 address | | | | | |
12373 | overlay | <-' | | |
12374 | area | <---' +-----------+<-- overlay 3
12375 | | <---. | | load address
12376 +-----------+ `--| overlay 3 |
12377 | | | |
12378 +-----------+ | |
12379 +-----------+
12380 | |
12381 +-----------+
12382
12383 @anchor{A code overlay}A code overlay
df0cd8c5 12384@end group
474c8240 12385@end smallexample
df0cd8c5 12386
c928edc0
AC
12387The diagram (@pxref{A code overlay}) shows a system with separate data
12388and instruction address spaces. To map an overlay, the program copies
12389its code from the larger address space to the instruction address space.
12390Since the overlays shown here all use the same mapped address, only one
12391may be mapped at a time. For a system with a single address space for
12392data and instructions, the diagram would be similar, except that the
12393program variables and heap would share an address space with the main
12394program and the overlay area.
df0cd8c5
JB
12395
12396An overlay loaded into instruction memory and ready for use is called a
12397@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
12398instruction memory. An overlay not present (or only partially present)
12399in instruction memory is called @dfn{unmapped}; its @dfn{load address}
12400is its address in the larger memory. The mapped address is also called
12401the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
12402called the @dfn{load memory address}, or @dfn{LMA}.
12403
12404Unfortunately, overlays are not a completely transparent way to adapt a
12405program to limited instruction memory. They introduce a new set of
12406global constraints you must keep in mind as you design your program:
12407
12408@itemize @bullet
12409
12410@item
12411Before calling or returning to a function in an overlay, your program
12412must make sure that overlay is actually mapped. Otherwise, the call or
12413return will transfer control to the right address, but in the wrong
12414overlay, and your program will probably crash.
12415
12416@item
12417If the process of mapping an overlay is expensive on your system, you
12418will need to choose your overlays carefully to minimize their effect on
12419your program's performance.
12420
12421@item
12422The executable file you load onto your system must contain each
12423overlay's instructions, appearing at the overlay's load address, not its
12424mapped address. However, each overlay's instructions must be relocated
12425and its symbols defined as if the overlay were at its mapped address.
12426You can use GNU linker scripts to specify different load and relocation
12427addresses for pieces of your program; see @ref{Overlay Description,,,
12428ld.info, Using ld: the GNU linker}.
12429
12430@item
12431The procedure for loading executable files onto your system must be able
12432to load their contents into the larger address space as well as the
12433instruction and data spaces.
12434
12435@end itemize
12436
12437The overlay system described above is rather simple, and could be
12438improved in many ways:
12439
12440@itemize @bullet
12441
12442@item
12443If your system has suitable bank switch registers or memory management
12444hardware, you could use those facilities to make an overlay's load area
12445contents simply appear at their mapped address in instruction space.
12446This would probably be faster than copying the overlay to its mapped
12447area in the usual way.
12448
12449@item
12450If your overlays are small enough, you could set aside more than one
12451overlay area, and have more than one overlay mapped at a time.
12452
12453@item
12454You can use overlays to manage data, as well as instructions. In
12455general, data overlays are even less transparent to your design than
12456code overlays: whereas code overlays only require care when you call or
12457return to functions, data overlays require care every time you access
12458the data. Also, if you change the contents of a data overlay, you
12459must copy its contents back out to its load address before you can copy a
12460different data overlay into the same mapped area.
12461
12462@end itemize
12463
12464
12465@node Overlay Commands
12466@section Overlay Commands
12467
12468To use @value{GDBN}'s overlay support, each overlay in your program must
12469correspond to a separate section of the executable file. The section's
12470virtual memory address and load memory address must be the overlay's
12471mapped and load addresses. Identifying overlays with sections allows
12472@value{GDBN} to determine the appropriate address of a function or
12473variable, depending on whether the overlay is mapped or not.
12474
12475@value{GDBN}'s overlay commands all start with the word @code{overlay};
12476you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
12477
12478@table @code
12479@item overlay off
4644b6e3 12480@kindex overlay
df0cd8c5
JB
12481Disable @value{GDBN}'s overlay support. When overlay support is
12482disabled, @value{GDBN} assumes that all functions and variables are
12483always present at their mapped addresses. By default, @value{GDBN}'s
12484overlay support is disabled.
12485
12486@item overlay manual
df0cd8c5
JB
12487@cindex manual overlay debugging
12488Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
12489relies on you to tell it which overlays are mapped, and which are not,
12490using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
12491commands described below.
12492
12493@item overlay map-overlay @var{overlay}
12494@itemx overlay map @var{overlay}
df0cd8c5
JB
12495@cindex map an overlay
12496Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
12497be the name of the object file section containing the overlay. When an
12498overlay is mapped, @value{GDBN} assumes it can find the overlay's
12499functions and variables at their mapped addresses. @value{GDBN} assumes
12500that any other overlays whose mapped ranges overlap that of
12501@var{overlay} are now unmapped.
12502
12503@item overlay unmap-overlay @var{overlay}
12504@itemx overlay unmap @var{overlay}
df0cd8c5
JB
12505@cindex unmap an overlay
12506Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
12507must be the name of the object file section containing the overlay.
12508When an overlay is unmapped, @value{GDBN} assumes it can find the
12509overlay's functions and variables at their load addresses.
12510
12511@item overlay auto
df0cd8c5
JB
12512Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
12513consults a data structure the overlay manager maintains in the inferior
12514to see which overlays are mapped. For details, see @ref{Automatic
12515Overlay Debugging}.
12516
12517@item overlay load-target
12518@itemx overlay load
df0cd8c5
JB
12519@cindex reloading the overlay table
12520Re-read the overlay table from the inferior. Normally, @value{GDBN}
12521re-reads the table @value{GDBN} automatically each time the inferior
12522stops, so this command should only be necessary if you have changed the
12523overlay mapping yourself using @value{GDBN}. This command is only
12524useful when using automatic overlay debugging.
12525
12526@item overlay list-overlays
12527@itemx overlay list
12528@cindex listing mapped overlays
12529Display a list of the overlays currently mapped, along with their mapped
12530addresses, load addresses, and sizes.
12531
12532@end table
12533
12534Normally, when @value{GDBN} prints a code address, it includes the name
12535of the function the address falls in:
12536
474c8240 12537@smallexample
f7dc1244 12538(@value{GDBP}) print main
df0cd8c5 12539$3 = @{int ()@} 0x11a0 <main>
474c8240 12540@end smallexample
df0cd8c5
JB
12541@noindent
12542When overlay debugging is enabled, @value{GDBN} recognizes code in
12543unmapped overlays, and prints the names of unmapped functions with
12544asterisks around them. For example, if @code{foo} is a function in an
12545unmapped overlay, @value{GDBN} prints it this way:
12546
474c8240 12547@smallexample
f7dc1244 12548(@value{GDBP}) overlay list
df0cd8c5 12549No sections are mapped.
f7dc1244 12550(@value{GDBP}) print foo
df0cd8c5 12551$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 12552@end smallexample
df0cd8c5
JB
12553@noindent
12554When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
12555name normally:
12556
474c8240 12557@smallexample
f7dc1244 12558(@value{GDBP}) overlay list
b383017d 12559Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 12560 mapped at 0x1016 - 0x104a
f7dc1244 12561(@value{GDBP}) print foo
df0cd8c5 12562$6 = @{int (int)@} 0x1016 <foo>
474c8240 12563@end smallexample
df0cd8c5
JB
12564
12565When overlay debugging is enabled, @value{GDBN} can find the correct
12566address for functions and variables in an overlay, whether or not the
12567overlay is mapped. This allows most @value{GDBN} commands, like
12568@code{break} and @code{disassemble}, to work normally, even on unmapped
12569code. However, @value{GDBN}'s breakpoint support has some limitations:
12570
12571@itemize @bullet
12572@item
12573@cindex breakpoints in overlays
12574@cindex overlays, setting breakpoints in
12575You can set breakpoints in functions in unmapped overlays, as long as
12576@value{GDBN} can write to the overlay at its load address.
12577@item
12578@value{GDBN} can not set hardware or simulator-based breakpoints in
12579unmapped overlays. However, if you set a breakpoint at the end of your
12580overlay manager (and tell @value{GDBN} which overlays are now mapped, if
12581you are using manual overlay management), @value{GDBN} will re-set its
12582breakpoints properly.
12583@end itemize
12584
12585
12586@node Automatic Overlay Debugging
12587@section Automatic Overlay Debugging
12588@cindex automatic overlay debugging
12589
12590@value{GDBN} can automatically track which overlays are mapped and which
12591are not, given some simple co-operation from the overlay manager in the
12592inferior. If you enable automatic overlay debugging with the
12593@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
12594looks in the inferior's memory for certain variables describing the
12595current state of the overlays.
12596
12597Here are the variables your overlay manager must define to support
12598@value{GDBN}'s automatic overlay debugging:
12599
12600@table @asis
12601
12602@item @code{_ovly_table}:
12603This variable must be an array of the following structures:
12604
474c8240 12605@smallexample
df0cd8c5
JB
12606struct
12607@{
12608 /* The overlay's mapped address. */
12609 unsigned long vma;
12610
12611 /* The size of the overlay, in bytes. */
12612 unsigned long size;
12613
12614 /* The overlay's load address. */
12615 unsigned long lma;
12616
12617 /* Non-zero if the overlay is currently mapped;
12618 zero otherwise. */
12619 unsigned long mapped;
12620@}
474c8240 12621@end smallexample
df0cd8c5
JB
12622
12623@item @code{_novlys}:
12624This variable must be a four-byte signed integer, holding the total
12625number of elements in @code{_ovly_table}.
12626
12627@end table
12628
12629To decide whether a particular overlay is mapped or not, @value{GDBN}
12630looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
12631@code{lma} members equal the VMA and LMA of the overlay's section in the
12632executable file. When @value{GDBN} finds a matching entry, it consults
12633the entry's @code{mapped} member to determine whether the overlay is
12634currently mapped.
12635
81d46470 12636In addition, your overlay manager may define a function called
def71bfa 12637@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
12638will silently set a breakpoint there. If the overlay manager then
12639calls this function whenever it has changed the overlay table, this
12640will enable @value{GDBN} to accurately keep track of which overlays
12641are in program memory, and update any breakpoints that may be set
b383017d 12642in overlays. This will allow breakpoints to work even if the
81d46470
MS
12643overlays are kept in ROM or other non-writable memory while they
12644are not being executed.
df0cd8c5
JB
12645
12646@node Overlay Sample Program
12647@section Overlay Sample Program
12648@cindex overlay example program
12649
12650When linking a program which uses overlays, you must place the overlays
12651at their load addresses, while relocating them to run at their mapped
12652addresses. To do this, you must write a linker script (@pxref{Overlay
12653Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
12654since linker scripts are specific to a particular host system, target
12655architecture, and target memory layout, this manual cannot provide
12656portable sample code demonstrating @value{GDBN}'s overlay support.
12657
12658However, the @value{GDBN} source distribution does contain an overlaid
12659program, with linker scripts for a few systems, as part of its test
12660suite. The program consists of the following files from
12661@file{gdb/testsuite/gdb.base}:
12662
12663@table @file
12664@item overlays.c
12665The main program file.
12666@item ovlymgr.c
12667A simple overlay manager, used by @file{overlays.c}.
12668@item foo.c
12669@itemx bar.c
12670@itemx baz.c
12671@itemx grbx.c
12672Overlay modules, loaded and used by @file{overlays.c}.
12673@item d10v.ld
12674@itemx m32r.ld
12675Linker scripts for linking the test program on the @code{d10v-elf}
12676and @code{m32r-elf} targets.
12677@end table
12678
12679You can build the test program using the @code{d10v-elf} GCC
12680cross-compiler like this:
12681
474c8240 12682@smallexample
df0cd8c5
JB
12683$ d10v-elf-gcc -g -c overlays.c
12684$ d10v-elf-gcc -g -c ovlymgr.c
12685$ d10v-elf-gcc -g -c foo.c
12686$ d10v-elf-gcc -g -c bar.c
12687$ d10v-elf-gcc -g -c baz.c
12688$ d10v-elf-gcc -g -c grbx.c
12689$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
12690 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 12691@end smallexample
df0cd8c5
JB
12692
12693The build process is identical for any other architecture, except that
12694you must substitute the appropriate compiler and linker script for the
12695target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
12696
12697
6d2ebf8b 12698@node Languages
c906108c
SS
12699@chapter Using @value{GDBN} with Different Languages
12700@cindex languages
12701
c906108c
SS
12702Although programming languages generally have common aspects, they are
12703rarely expressed in the same manner. For instance, in ANSI C,
12704dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
12705Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 12706represented (and displayed) differently. Hex numbers in C appear as
c906108c 12707@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
12708
12709@cindex working language
12710Language-specific information is built into @value{GDBN} for some languages,
12711allowing you to express operations like the above in your program's
12712native language, and allowing @value{GDBN} to output values in a manner
12713consistent with the syntax of your program's native language. The
12714language you use to build expressions is called the @dfn{working
12715language}.
12716
12717@menu
12718* Setting:: Switching between source languages
12719* Show:: Displaying the language
c906108c 12720* Checks:: Type and range checks
79a6e687
BW
12721* Supported Languages:: Supported languages
12722* Unsupported Languages:: Unsupported languages
c906108c
SS
12723@end menu
12724
6d2ebf8b 12725@node Setting
79a6e687 12726@section Switching Between Source Languages
c906108c
SS
12727
12728There are two ways to control the working language---either have @value{GDBN}
12729set it automatically, or select it manually yourself. You can use the
12730@code{set language} command for either purpose. On startup, @value{GDBN}
12731defaults to setting the language automatically. The working language is
12732used to determine how expressions you type are interpreted, how values
12733are printed, etc.
12734
12735In addition to the working language, every source file that
12736@value{GDBN} knows about has its own working language. For some object
12737file formats, the compiler might indicate which language a particular
12738source file is in. However, most of the time @value{GDBN} infers the
12739language from the name of the file. The language of a source file
b37052ae 12740controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 12741show each frame appropriately for its own language. There is no way to
d4f3574e
SS
12742set the language of a source file from within @value{GDBN}, but you can
12743set the language associated with a filename extension. @xref{Show, ,
79a6e687 12744Displaying the Language}.
c906108c
SS
12745
12746This is most commonly a problem when you use a program, such
5d161b24 12747as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
12748another language. In that case, make the
12749program use @code{#line} directives in its C output; that way
12750@value{GDBN} will know the correct language of the source code of the original
12751program, and will display that source code, not the generated C code.
12752
12753@menu
12754* Filenames:: Filename extensions and languages.
12755* Manually:: Setting the working language manually
12756* Automatically:: Having @value{GDBN} infer the source language
12757@end menu
12758
6d2ebf8b 12759@node Filenames
79a6e687 12760@subsection List of Filename Extensions and Languages
c906108c
SS
12761
12762If a source file name ends in one of the following extensions, then
12763@value{GDBN} infers that its language is the one indicated.
12764
12765@table @file
e07c999f
PH
12766@item .ada
12767@itemx .ads
12768@itemx .adb
12769@itemx .a
12770Ada source file.
c906108c
SS
12771
12772@item .c
12773C source file
12774
12775@item .C
12776@itemx .cc
12777@itemx .cp
12778@itemx .cpp
12779@itemx .cxx
12780@itemx .c++
b37052ae 12781C@t{++} source file
c906108c 12782
6aecb9c2
JB
12783@item .d
12784D source file
12785
b37303ee
AF
12786@item .m
12787Objective-C source file
12788
c906108c
SS
12789@item .f
12790@itemx .F
12791Fortran source file
12792
c906108c
SS
12793@item .mod
12794Modula-2 source file
c906108c
SS
12795
12796@item .s
12797@itemx .S
12798Assembler source file. This actually behaves almost like C, but
12799@value{GDBN} does not skip over function prologues when stepping.
12800@end table
12801
12802In addition, you may set the language associated with a filename
79a6e687 12803extension. @xref{Show, , Displaying the Language}.
c906108c 12804
6d2ebf8b 12805@node Manually
79a6e687 12806@subsection Setting the Working Language
c906108c
SS
12807
12808If you allow @value{GDBN} to set the language automatically,
12809expressions are interpreted the same way in your debugging session and
12810your program.
12811
12812@kindex set language
12813If you wish, you may set the language manually. To do this, issue the
12814command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 12815a language, such as
c906108c 12816@code{c} or @code{modula-2}.
c906108c
SS
12817For a list of the supported languages, type @samp{set language}.
12818
c906108c
SS
12819Setting the language manually prevents @value{GDBN} from updating the working
12820language automatically. This can lead to confusion if you try
12821to debug a program when the working language is not the same as the
12822source language, when an expression is acceptable to both
12823languages---but means different things. For instance, if the current
12824source file were written in C, and @value{GDBN} was parsing Modula-2, a
12825command such as:
12826
474c8240 12827@smallexample
c906108c 12828print a = b + c
474c8240 12829@end smallexample
c906108c
SS
12830
12831@noindent
12832might not have the effect you intended. In C, this means to add
12833@code{b} and @code{c} and place the result in @code{a}. The result
12834printed would be the value of @code{a}. In Modula-2, this means to compare
12835@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 12836
6d2ebf8b 12837@node Automatically
79a6e687 12838@subsection Having @value{GDBN} Infer the Source Language
c906108c
SS
12839
12840To have @value{GDBN} set the working language automatically, use
12841@samp{set language local} or @samp{set language auto}. @value{GDBN}
12842then infers the working language. That is, when your program stops in a
12843frame (usually by encountering a breakpoint), @value{GDBN} sets the
12844working language to the language recorded for the function in that
12845frame. If the language for a frame is unknown (that is, if the function
12846or block corresponding to the frame was defined in a source file that
12847does not have a recognized extension), the current working language is
12848not changed, and @value{GDBN} issues a warning.
12849
12850This may not seem necessary for most programs, which are written
12851entirely in one source language. However, program modules and libraries
12852written in one source language can be used by a main program written in
12853a different source language. Using @samp{set language auto} in this
12854case frees you from having to set the working language manually.
12855
6d2ebf8b 12856@node Show
79a6e687 12857@section Displaying the Language
c906108c
SS
12858
12859The following commands help you find out which language is the
12860working language, and also what language source files were written in.
12861
c906108c
SS
12862@table @code
12863@item show language
9c16f35a 12864@kindex show language
c906108c
SS
12865Display the current working language. This is the
12866language you can use with commands such as @code{print} to
12867build and compute expressions that may involve variables in your program.
12868
12869@item info frame
4644b6e3 12870@kindex info frame@r{, show the source language}
5d161b24 12871Display the source language for this frame. This language becomes the
c906108c 12872working language if you use an identifier from this frame.
79a6e687 12873@xref{Frame Info, ,Information about a Frame}, to identify the other
c906108c
SS
12874information listed here.
12875
12876@item info source
4644b6e3 12877@kindex info source@r{, show the source language}
c906108c 12878Display the source language of this source file.
5d161b24 12879@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
12880information listed here.
12881@end table
12882
12883In unusual circumstances, you may have source files with extensions
12884not in the standard list. You can then set the extension associated
12885with a language explicitly:
12886
c906108c 12887@table @code
09d4efe1 12888@item set extension-language @var{ext} @var{language}
9c16f35a 12889@kindex set extension-language
09d4efe1
EZ
12890Tell @value{GDBN} that source files with extension @var{ext} are to be
12891assumed as written in the source language @var{language}.
c906108c
SS
12892
12893@item info extensions
9c16f35a 12894@kindex info extensions
c906108c
SS
12895List all the filename extensions and the associated languages.
12896@end table
12897
6d2ebf8b 12898@node Checks
79a6e687 12899@section Type and Range Checking
c906108c 12900
c906108c
SS
12901Some languages are designed to guard you against making seemingly common
12902errors through a series of compile- and run-time checks. These include
a451cb65 12903checking the type of arguments to functions and operators and making
c906108c
SS
12904sure mathematical overflows are caught at run time. Checks such as
12905these help to ensure a program's correctness once it has been compiled
a451cb65 12906by eliminating type mismatches and providing active checks for range
c906108c
SS
12907errors when your program is running.
12908
a451cb65
KS
12909By default @value{GDBN} checks for these errors according to the
12910rules of the current source language. Although @value{GDBN} does not check
12911the statements in your program, it can check expressions entered directly
12912into @value{GDBN} for evaluation via the @code{print} command, for example.
c906108c
SS
12913
12914@menu
12915* Type Checking:: An overview of type checking
12916* Range Checking:: An overview of range checking
12917@end menu
12918
12919@cindex type checking
12920@cindex checks, type
6d2ebf8b 12921@node Type Checking
79a6e687 12922@subsection An Overview of Type Checking
c906108c 12923
a451cb65 12924Some languages, such as C and C@t{++}, are strongly typed, meaning that the
c906108c
SS
12925arguments to operators and functions have to be of the correct type,
12926otherwise an error occurs. These checks prevent type mismatch
12927errors from ever causing any run-time problems. For example,
12928
12929@smallexample
a451cb65
KS
12930int klass::my_method(char *b) @{ return b ? 1 : 2; @}
12931
12932(@value{GDBP}) print obj.my_method (0)
12933$1 = 2
c906108c 12934@exdent but
a451cb65
KS
12935(@value{GDBP}) print obj.my_method (0x1234)
12936Cannot resolve method klass::my_method to any overloaded instance
c906108c
SS
12937@end smallexample
12938
a451cb65
KS
12939The second example fails because in C@t{++} the integer constant
12940@samp{0x1234} is not type-compatible with the pointer parameter type.
c906108c 12941
a451cb65
KS
12942For the expressions you use in @value{GDBN} commands, you can tell
12943@value{GDBN} to not enforce strict type checking or
5d161b24 12944to treat any mismatches as errors and abandon the expression;
a451cb65
KS
12945When type checking is disabled, @value{GDBN} successfully evaluates
12946expressions like the second example above.
c906108c 12947
a451cb65 12948Even if type checking is off, there may be other reasons
5d161b24
DB
12949related to type that prevent @value{GDBN} from evaluating an expression.
12950For instance, @value{GDBN} does not know how to add an @code{int} and
12951a @code{struct foo}. These particular type errors have nothing to do
a451cb65
KS
12952with the language in use and usually arise from expressions which make
12953little sense to evaluate anyway.
c906108c 12954
a451cb65 12955@value{GDBN} provides some additional commands for controlling type checking:
c906108c 12956
c906108c
SS
12957@kindex set check type
12958@kindex show check type
12959@table @code
c906108c
SS
12960@item set check type on
12961@itemx set check type off
a451cb65 12962Set strict type checking on or off. If any type mismatches occur in
d4f3574e 12963evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
12964message and aborts evaluation of the expression.
12965
a451cb65
KS
12966@item show check type
12967Show the current setting of type checking and whether @value{GDBN}
12968is enforcing strict type checking rules.
c906108c
SS
12969@end table
12970
12971@cindex range checking
12972@cindex checks, range
6d2ebf8b 12973@node Range Checking
79a6e687 12974@subsection An Overview of Range Checking
c906108c
SS
12975
12976In some languages (such as Modula-2), it is an error to exceed the
12977bounds of a type; this is enforced with run-time checks. Such range
12978checking is meant to ensure program correctness by making sure
12979computations do not overflow, or indices on an array element access do
12980not exceed the bounds of the array.
12981
12982For expressions you use in @value{GDBN} commands, you can tell
12983@value{GDBN} to treat range errors in one of three ways: ignore them,
12984always treat them as errors and abandon the expression, or issue
12985warnings but evaluate the expression anyway.
12986
12987A range error can result from numerical overflow, from exceeding an
12988array index bound, or when you type a constant that is not a member
12989of any type. Some languages, however, do not treat overflows as an
12990error. In many implementations of C, mathematical overflow causes the
12991result to ``wrap around'' to lower values---for example, if @var{m} is
12992the largest integer value, and @var{s} is the smallest, then
12993
474c8240 12994@smallexample
c906108c 12995@var{m} + 1 @result{} @var{s}
474c8240 12996@end smallexample
c906108c
SS
12997
12998This, too, is specific to individual languages, and in some cases
79a6e687
BW
12999specific to individual compilers or machines. @xref{Supported Languages, ,
13000Supported Languages}, for further details on specific languages.
c906108c
SS
13001
13002@value{GDBN} provides some additional commands for controlling the range checker:
13003
c906108c
SS
13004@kindex set check range
13005@kindex show check range
13006@table @code
13007@item set check range auto
13008Set range checking on or off based on the current working language.
79a6e687 13009@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
13010each language.
13011
13012@item set check range on
13013@itemx set check range off
13014Set range checking on or off, overriding the default setting for the
13015current working language. A warning is issued if the setting does not
c3f6f71d
JM
13016match the language default. If a range error occurs and range checking is on,
13017then a message is printed and evaluation of the expression is aborted.
c906108c
SS
13018
13019@item set check range warn
13020Output messages when the @value{GDBN} range checker detects a range error,
13021but attempt to evaluate the expression anyway. Evaluating the
13022expression may still be impossible for other reasons, such as accessing
13023memory that the process does not own (a typical example from many Unix
13024systems).
13025
13026@item show range
13027Show the current setting of the range checker, and whether or not it is
13028being set automatically by @value{GDBN}.
13029@end table
c906108c 13030
79a6e687
BW
13031@node Supported Languages
13032@section Supported Languages
c906108c 13033
a766d390
DE
13034@value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran, Java,
13035OpenCL C, Pascal, assembly, Modula-2, and Ada.
cce74817 13036@c This is false ...
c906108c
SS
13037Some @value{GDBN} features may be used in expressions regardless of the
13038language you use: the @value{GDBN} @code{@@} and @code{::} operators,
13039and the @samp{@{type@}addr} construct (@pxref{Expressions,
13040,Expressions}) can be used with the constructs of any supported
13041language.
13042
13043The following sections detail to what degree each source language is
13044supported by @value{GDBN}. These sections are not meant to be language
13045tutorials or references, but serve only as a reference guide to what the
13046@value{GDBN} expression parser accepts, and what input and output
13047formats should look like for different languages. There are many good
13048books written on each of these languages; please look to these for a
13049language reference or tutorial.
13050
c906108c 13051@menu
b37303ee 13052* C:: C and C@t{++}
6aecb9c2 13053* D:: D
a766d390 13054* Go:: Go
b383017d 13055* Objective-C:: Objective-C
f4b8a18d 13056* OpenCL C:: OpenCL C
09d4efe1 13057* Fortran:: Fortran
9c16f35a 13058* Pascal:: Pascal
b37303ee 13059* Modula-2:: Modula-2
e07c999f 13060* Ada:: Ada
c906108c
SS
13061@end menu
13062
6d2ebf8b 13063@node C
b37052ae 13064@subsection C and C@t{++}
7a292a7a 13065
b37052ae
EZ
13066@cindex C and C@t{++}
13067@cindex expressions in C or C@t{++}
c906108c 13068
b37052ae 13069Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
13070to both languages. Whenever this is the case, we discuss those languages
13071together.
13072
41afff9a
EZ
13073@cindex C@t{++}
13074@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
13075@cindex @sc{gnu} C@t{++}
13076The C@t{++} debugging facilities are jointly implemented by the C@t{++}
13077compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
13078effectively, you must compile your C@t{++} programs with a supported
13079C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
13080compiler (@code{aCC}).
13081
c906108c 13082@menu
b37052ae
EZ
13083* C Operators:: C and C@t{++} operators
13084* C Constants:: C and C@t{++} constants
79a6e687 13085* C Plus Plus Expressions:: C@t{++} expressions
b37052ae
EZ
13086* C Defaults:: Default settings for C and C@t{++}
13087* C Checks:: C and C@t{++} type and range checks
c906108c 13088* Debugging C:: @value{GDBN} and C
79a6e687 13089* Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
febe4383 13090* Decimal Floating Point:: Numbers in Decimal Floating Point format
c906108c 13091@end menu
c906108c 13092
6d2ebf8b 13093@node C Operators
79a6e687 13094@subsubsection C and C@t{++} Operators
7a292a7a 13095
b37052ae 13096@cindex C and C@t{++} operators
c906108c
SS
13097
13098Operators must be defined on values of specific types. For instance,
13099@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 13100often defined on groups of types.
c906108c 13101
b37052ae 13102For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
13103
13104@itemize @bullet
53a5351d 13105
c906108c 13106@item
c906108c 13107@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 13108specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
13109
13110@item
d4f3574e
SS
13111@emph{Floating-point types} include @code{float}, @code{double}, and
13112@code{long double} (if supported by the target platform).
c906108c
SS
13113
13114@item
53a5351d 13115@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
13116
13117@item
13118@emph{Scalar types} include all of the above.
53a5351d 13119
c906108c
SS
13120@end itemize
13121
13122@noindent
13123The following operators are supported. They are listed here
13124in order of increasing precedence:
13125
13126@table @code
13127@item ,
13128The comma or sequencing operator. Expressions in a comma-separated list
13129are evaluated from left to right, with the result of the entire
13130expression being the last expression evaluated.
13131
13132@item =
13133Assignment. The value of an assignment expression is the value
13134assigned. Defined on scalar types.
13135
13136@item @var{op}=
13137Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
13138and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 13139@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
13140@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
13141@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
13142
13143@item ?:
13144The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
13145of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
13146integral type.
13147
13148@item ||
13149Logical @sc{or}. Defined on integral types.
13150
13151@item &&
13152Logical @sc{and}. Defined on integral types.
13153
13154@item |
13155Bitwise @sc{or}. Defined on integral types.
13156
13157@item ^
13158Bitwise exclusive-@sc{or}. Defined on integral types.
13159
13160@item &
13161Bitwise @sc{and}. Defined on integral types.
13162
13163@item ==@r{, }!=
13164Equality and inequality. Defined on scalar types. The value of these
13165expressions is 0 for false and non-zero for true.
13166
13167@item <@r{, }>@r{, }<=@r{, }>=
13168Less than, greater than, less than or equal, greater than or equal.
13169Defined on scalar types. The value of these expressions is 0 for false
13170and non-zero for true.
13171
13172@item <<@r{, }>>
13173left shift, and right shift. Defined on integral types.
13174
13175@item @@
13176The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
13177
13178@item +@r{, }-
13179Addition and subtraction. Defined on integral types, floating-point types and
13180pointer types.
13181
13182@item *@r{, }/@r{, }%
13183Multiplication, division, and modulus. Multiplication and division are
13184defined on integral and floating-point types. Modulus is defined on
13185integral types.
13186
13187@item ++@r{, }--
13188Increment and decrement. When appearing before a variable, the
13189operation is performed before the variable is used in an expression;
13190when appearing after it, the variable's value is used before the
13191operation takes place.
13192
13193@item *
13194Pointer dereferencing. Defined on pointer types. Same precedence as
13195@code{++}.
13196
13197@item &
13198Address operator. Defined on variables. Same precedence as @code{++}.
13199
b37052ae
EZ
13200For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
13201allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
b17828ca 13202to examine the address
b37052ae 13203where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 13204stored.
c906108c
SS
13205
13206@item -
13207Negative. Defined on integral and floating-point types. Same
13208precedence as @code{++}.
13209
13210@item !
13211Logical negation. Defined on integral types. Same precedence as
13212@code{++}.
13213
13214@item ~
13215Bitwise complement operator. Defined on integral types. Same precedence as
13216@code{++}.
13217
13218
13219@item .@r{, }->
13220Structure member, and pointer-to-structure member. For convenience,
13221@value{GDBN} regards the two as equivalent, choosing whether to dereference a
13222pointer based on the stored type information.
13223Defined on @code{struct} and @code{union} data.
13224
c906108c
SS
13225@item .*@r{, }->*
13226Dereferences of pointers to members.
c906108c
SS
13227
13228@item []
13229Array indexing. @code{@var{a}[@var{i}]} is defined as
13230@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
13231
13232@item ()
13233Function parameter list. Same precedence as @code{->}.
13234
c906108c 13235@item ::
b37052ae 13236C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 13237and @code{class} types.
c906108c
SS
13238
13239@item ::
7a292a7a
SS
13240Doubled colons also represent the @value{GDBN} scope operator
13241(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
13242above.
c906108c
SS
13243@end table
13244
c906108c
SS
13245If an operator is redefined in the user code, @value{GDBN} usually
13246attempts to invoke the redefined version instead of using the operator's
13247predefined meaning.
c906108c 13248
6d2ebf8b 13249@node C Constants
79a6e687 13250@subsubsection C and C@t{++} Constants
c906108c 13251
b37052ae 13252@cindex C and C@t{++} constants
c906108c 13253
b37052ae 13254@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 13255following ways:
c906108c
SS
13256
13257@itemize @bullet
13258@item
13259Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
13260specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
13261by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
13262@samp{l}, specifying that the constant should be treated as a
13263@code{long} value.
13264
13265@item
13266Floating point constants are a sequence of digits, followed by a decimal
13267point, followed by a sequence of digits, and optionally followed by an
13268exponent. An exponent is of the form:
13269@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
13270sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
13271A floating-point constant may also end with a letter @samp{f} or
13272@samp{F}, specifying that the constant should be treated as being of
13273the @code{float} (as opposed to the default @code{double}) type; or with
13274a letter @samp{l} or @samp{L}, which specifies a @code{long double}
13275constant.
c906108c
SS
13276
13277@item
13278Enumerated constants consist of enumerated identifiers, or their
13279integral equivalents.
13280
13281@item
13282Character constants are a single character surrounded by single quotes
13283(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 13284(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
13285be represented by a letter or by @dfn{escape sequences}, which are of
13286the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
13287of the character's ordinal value; or of the form @samp{\@var{x}}, where
13288@samp{@var{x}} is a predefined special character---for example,
13289@samp{\n} for newline.
13290
e0f8f636
TT
13291Wide character constants can be written by prefixing a character
13292constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
13293form of @samp{x}. The target wide character set is used when
13294computing the value of this constant (@pxref{Character Sets}).
13295
c906108c 13296@item
96a2c332
SS
13297String constants are a sequence of character constants surrounded by
13298double quotes (@code{"}). Any valid character constant (as described
13299above) may appear. Double quotes within the string must be preceded by
13300a backslash, so for instance @samp{"a\"b'c"} is a string of five
13301characters.
c906108c 13302
e0f8f636
TT
13303Wide string constants can be written by prefixing a string constant
13304with @samp{L}, as in C. The target wide character set is used when
13305computing the value of this constant (@pxref{Character Sets}).
13306
c906108c
SS
13307@item
13308Pointer constants are an integral value. You can also write pointers
13309to constants using the C operator @samp{&}.
13310
13311@item
13312Array constants are comma-separated lists surrounded by braces @samp{@{}
13313and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
13314integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
13315and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
13316@end itemize
13317
79a6e687
BW
13318@node C Plus Plus Expressions
13319@subsubsection C@t{++} Expressions
b37052ae
EZ
13320
13321@cindex expressions in C@t{++}
13322@value{GDBN} expression handling can interpret most C@t{++} expressions.
13323
0179ffac
DC
13324@cindex debugging C@t{++} programs
13325@cindex C@t{++} compilers
13326@cindex debug formats and C@t{++}
13327@cindex @value{NGCC} and C@t{++}
c906108c 13328@quotation
e0f8f636
TT
13329@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
13330the proper compiler and the proper debug format. Currently,
13331@value{GDBN} works best when debugging C@t{++} code that is compiled
13332with the most recent version of @value{NGCC} possible. The DWARF
13333debugging format is preferred; @value{NGCC} defaults to this on most
13334popular platforms. Other compilers and/or debug formats are likely to
13335work badly or not at all when using @value{GDBN} to debug C@t{++}
13336code. @xref{Compilation}.
c906108c 13337@end quotation
c906108c
SS
13338
13339@enumerate
13340
13341@cindex member functions
13342@item
13343Member function calls are allowed; you can use expressions like
13344
474c8240 13345@smallexample
c906108c 13346count = aml->GetOriginal(x, y)
474c8240 13347@end smallexample
c906108c 13348
41afff9a 13349@vindex this@r{, inside C@t{++} member functions}
b37052ae 13350@cindex namespace in C@t{++}
c906108c
SS
13351@item
13352While a member function is active (in the selected stack frame), your
13353expressions have the same namespace available as the member function;
13354that is, @value{GDBN} allows implicit references to the class instance
e0f8f636
TT
13355pointer @code{this} following the same rules as C@t{++}. @code{using}
13356declarations in the current scope are also respected by @value{GDBN}.
c906108c 13357
c906108c 13358@cindex call overloaded functions
d4f3574e 13359@cindex overloaded functions, calling
b37052ae 13360@cindex type conversions in C@t{++}
c906108c
SS
13361@item
13362You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 13363call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
13364perform overload resolution involving user-defined type conversions,
13365calls to constructors, or instantiations of templates that do not exist
13366in the program. It also cannot handle ellipsis argument lists or
13367default arguments.
13368
13369It does perform integral conversions and promotions, floating-point
13370promotions, arithmetic conversions, pointer conversions, conversions of
13371class objects to base classes, and standard conversions such as those of
13372functions or arrays to pointers; it requires an exact match on the
13373number of function arguments.
13374
13375Overload resolution is always performed, unless you have specified
79a6e687
BW
13376@code{set overload-resolution off}. @xref{Debugging C Plus Plus,
13377,@value{GDBN} Features for C@t{++}}.
c906108c 13378
d4f3574e 13379You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
13380explicit function signature to call an overloaded function, as in
13381@smallexample
13382p 'foo(char,int)'('x', 13)
13383@end smallexample
d4f3574e 13384
c906108c 13385The @value{GDBN} command-completion facility can simplify this;
79a6e687 13386see @ref{Completion, ,Command Completion}.
c906108c 13387
c906108c
SS
13388@cindex reference declarations
13389@item
b37052ae
EZ
13390@value{GDBN} understands variables declared as C@t{++} references; you can use
13391them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
13392dereferenced.
13393
13394In the parameter list shown when @value{GDBN} displays a frame, the values of
13395reference variables are not displayed (unlike other variables); this
13396avoids clutter, since references are often used for large structures.
13397The @emph{address} of a reference variable is always shown, unless
13398you have specified @samp{set print address off}.
13399
13400@item
b37052ae 13401@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
13402expressions can use it just as expressions in your program do. Since
13403one scope may be defined in another, you can use @code{::} repeatedly if
13404necessary, for example in an expression like
13405@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 13406resolving name scope by reference to source files, in both C and C@t{++}
79a6e687 13407debugging (@pxref{Variables, ,Program Variables}).
c906108c 13408
e0f8f636
TT
13409@item
13410@value{GDBN} performs argument-dependent lookup, following the C@t{++}
13411specification.
13412@end enumerate
c906108c 13413
6d2ebf8b 13414@node C Defaults
79a6e687 13415@subsubsection C and C@t{++} Defaults
7a292a7a 13416
b37052ae 13417@cindex C and C@t{++} defaults
c906108c 13418
a451cb65
KS
13419If you allow @value{GDBN} to set range checking automatically, it
13420defaults to @code{off} whenever the working language changes to
b37052ae 13421C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 13422selects the working language.
c906108c
SS
13423
13424If you allow @value{GDBN} to set the language automatically, it
13425recognizes source files whose names end with @file{.c}, @file{.C}, or
13426@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 13427these files, it sets the working language to C or C@t{++}.
79a6e687 13428@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
c906108c
SS
13429for further details.
13430
6d2ebf8b 13431@node C Checks
79a6e687 13432@subsubsection C and C@t{++} Type and Range Checks
7a292a7a 13433
b37052ae 13434@cindex C and C@t{++} checks
c906108c 13435
a451cb65
KS
13436By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
13437checking is used. However, if you turn type checking off, @value{GDBN}
13438will allow certain non-standard conversions, such as promoting integer
13439constants to pointers.
c906108c
SS
13440
13441Range checking, if turned on, is done on mathematical operations. Array
13442indices are not checked, since they are often used to index a pointer
13443that is not itself an array.
c906108c 13444
6d2ebf8b 13445@node Debugging C
c906108c 13446@subsubsection @value{GDBN} and C
c906108c
SS
13447
13448The @code{set print union} and @code{show print union} commands apply to
13449the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
13450inside a @code{struct} or @code{class} is also printed. Otherwise, it
13451appears as @samp{@{...@}}.
c906108c
SS
13452
13453The @code{@@} operator aids in the debugging of dynamic arrays, formed
13454with pointers and a memory allocation function. @xref{Expressions,
13455,Expressions}.
13456
79a6e687
BW
13457@node Debugging C Plus Plus
13458@subsubsection @value{GDBN} Features for C@t{++}
c906108c 13459
b37052ae 13460@cindex commands for C@t{++}
7a292a7a 13461
b37052ae
EZ
13462Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
13463designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
13464
13465@table @code
13466@cindex break in overloaded functions
13467@item @r{breakpoint menus}
13468When you want a breakpoint in a function whose name is overloaded,
6ba66d6a
JB
13469@value{GDBN} has the capability to display a menu of possible breakpoint
13470locations to help you specify which function definition you want.
13471@xref{Ambiguous Expressions,,Ambiguous Expressions}.
c906108c 13472
b37052ae 13473@cindex overloading in C@t{++}
c906108c
SS
13474@item rbreak @var{regex}
13475Setting breakpoints using regular expressions is helpful for setting
13476breakpoints on overloaded functions that are not members of any special
13477classes.
79a6e687 13478@xref{Set Breaks, ,Setting Breakpoints}.
c906108c 13479
b37052ae 13480@cindex C@t{++} exception handling
c906108c
SS
13481@item catch throw
13482@itemx catch catch
b37052ae 13483Debug C@t{++} exception handling using these commands. @xref{Set
79a6e687 13484Catchpoints, , Setting Catchpoints}.
c906108c
SS
13485
13486@cindex inheritance
13487@item ptype @var{typename}
13488Print inheritance relationships as well as other information for type
13489@var{typename}.
13490@xref{Symbols, ,Examining the Symbol Table}.
13491
c4aeac85
TT
13492@item info vtbl @var{expression}.
13493The @code{info vtbl} command can be used to display the virtual
13494method tables of the object computed by @var{expression}. This shows
13495one entry per virtual table; there may be multiple virtual tables when
13496multiple inheritance is in use.
13497
b37052ae 13498@cindex C@t{++} symbol display
c906108c
SS
13499@item set print demangle
13500@itemx show print demangle
13501@itemx set print asm-demangle
13502@itemx show print asm-demangle
b37052ae
EZ
13503Control whether C@t{++} symbols display in their source form, both when
13504displaying code as C@t{++} source and when displaying disassemblies.
79a6e687 13505@xref{Print Settings, ,Print Settings}.
c906108c
SS
13506
13507@item set print object
13508@itemx show print object
13509Choose whether to print derived (actual) or declared types of objects.
79a6e687 13510@xref{Print Settings, ,Print Settings}.
c906108c
SS
13511
13512@item set print vtbl
13513@itemx show print vtbl
13514Control the format for printing virtual function tables.
79a6e687 13515@xref{Print Settings, ,Print Settings}.
c906108c 13516(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 13517ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
13518
13519@kindex set overload-resolution
d4f3574e 13520@cindex overloaded functions, overload resolution
c906108c 13521@item set overload-resolution on
b37052ae 13522Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
13523is on. For overloaded functions, @value{GDBN} evaluates the arguments
13524and searches for a function whose signature matches the argument types,
79a6e687
BW
13525using the standard C@t{++} conversion rules (see @ref{C Plus Plus
13526Expressions, ,C@t{++} Expressions}, for details).
13527If it cannot find a match, it emits a message.
c906108c
SS
13528
13529@item set overload-resolution off
b37052ae 13530Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
13531overloaded functions that are not class member functions, @value{GDBN}
13532chooses the first function of the specified name that it finds in the
13533symbol table, whether or not its arguments are of the correct type. For
13534overloaded functions that are class member functions, @value{GDBN}
13535searches for a function whose signature @emph{exactly} matches the
13536argument types.
c906108c 13537
9c16f35a
EZ
13538@kindex show overload-resolution
13539@item show overload-resolution
13540Show the current setting of overload resolution.
13541
c906108c
SS
13542@item @r{Overloaded symbol names}
13543You can specify a particular definition of an overloaded symbol, using
b37052ae 13544the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
13545@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
13546also use the @value{GDBN} command-line word completion facilities to list the
13547available choices, or to finish the type list for you.
79a6e687 13548@xref{Completion,, Command Completion}, for details on how to do this.
c906108c 13549@end table
c906108c 13550
febe4383
TJB
13551@node Decimal Floating Point
13552@subsubsection Decimal Floating Point format
13553@cindex decimal floating point format
13554
13555@value{GDBN} can examine, set and perform computations with numbers in
13556decimal floating point format, which in the C language correspond to the
13557@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
13558specified by the extension to support decimal floating-point arithmetic.
13559
13560There are two encodings in use, depending on the architecture: BID (Binary
13561Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
99e008fe 13562PowerPC. @value{GDBN} will use the appropriate encoding for the configured
febe4383
TJB
13563target.
13564
13565Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
13566to manipulate decimal floating point numbers, it is not possible to convert
13567(using a cast, for example) integers wider than 32-bit to decimal float.
13568
13569In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
13570point computations, error checking in decimal float operations ignores
13571underflow, overflow and divide by zero exceptions.
13572
4acd40f3 13573In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
99e008fe
EZ
13574to inspect @code{_Decimal128} values stored in floating point registers.
13575See @ref{PowerPC,,PowerPC} for more details.
4acd40f3 13576
6aecb9c2
JB
13577@node D
13578@subsection D
13579
13580@cindex D
13581@value{GDBN} can be used to debug programs written in D and compiled with
13582GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
13583specific feature --- dynamic arrays.
13584
a766d390
DE
13585@node Go
13586@subsection Go
13587
13588@cindex Go (programming language)
13589@value{GDBN} can be used to debug programs written in Go and compiled with
13590@file{gccgo} or @file{6g} compilers.
13591
13592Here is a summary of the Go-specific features and restrictions:
13593
13594@table @code
13595@cindex current Go package
13596@item The current Go package
13597The name of the current package does not need to be specified when
13598specifying global variables and functions.
13599
13600For example, given the program:
13601
13602@example
13603package main
13604var myglob = "Shall we?"
13605func main () @{
13606 // ...
13607@}
13608@end example
13609
13610When stopped inside @code{main} either of these work:
13611
13612@example
13613(gdb) p myglob
13614(gdb) p main.myglob
13615@end example
13616
13617@cindex builtin Go types
13618@item Builtin Go types
13619The @code{string} type is recognized by @value{GDBN} and is printed
13620as a string.
13621
13622@cindex builtin Go functions
13623@item Builtin Go functions
13624The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
13625function and handles it internally.
a766d390
DE
13626
13627@cindex restrictions on Go expressions
13628@item Restrictions on Go expressions
13629All Go operators are supported except @code{&^}.
13630The Go @code{_} ``blank identifier'' is not supported.
13631Automatic dereferencing of pointers is not supported.
50f042b9 13632@end table
a766d390 13633
b37303ee
AF
13634@node Objective-C
13635@subsection Objective-C
13636
13637@cindex Objective-C
13638This section provides information about some commands and command
721c2651
EZ
13639options that are useful for debugging Objective-C code. See also
13640@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
13641few more commands specific to Objective-C support.
b37303ee
AF
13642
13643@menu
b383017d
RM
13644* Method Names in Commands::
13645* The Print Command with Objective-C::
b37303ee
AF
13646@end menu
13647
c8f4133a 13648@node Method Names in Commands
b37303ee
AF
13649@subsubsection Method Names in Commands
13650
13651The following commands have been extended to accept Objective-C method
13652names as line specifications:
13653
13654@kindex clear@r{, and Objective-C}
13655@kindex break@r{, and Objective-C}
13656@kindex info line@r{, and Objective-C}
13657@kindex jump@r{, and Objective-C}
13658@kindex list@r{, and Objective-C}
13659@itemize
13660@item @code{clear}
13661@item @code{break}
13662@item @code{info line}
13663@item @code{jump}
13664@item @code{list}
13665@end itemize
13666
13667A fully qualified Objective-C method name is specified as
13668
13669@smallexample
13670-[@var{Class} @var{methodName}]
13671@end smallexample
13672
c552b3bb
JM
13673where the minus sign is used to indicate an instance method and a
13674plus sign (not shown) is used to indicate a class method. The class
13675name @var{Class} and method name @var{methodName} are enclosed in
13676brackets, similar to the way messages are specified in Objective-C
13677source code. For example, to set a breakpoint at the @code{create}
13678instance method of class @code{Fruit} in the program currently being
13679debugged, enter:
b37303ee
AF
13680
13681@smallexample
13682break -[Fruit create]
13683@end smallexample
13684
13685To list ten program lines around the @code{initialize} class method,
13686enter:
13687
13688@smallexample
13689list +[NSText initialize]
13690@end smallexample
13691
c552b3bb
JM
13692In the current version of @value{GDBN}, the plus or minus sign is
13693required. In future versions of @value{GDBN}, the plus or minus
13694sign will be optional, but you can use it to narrow the search. It
13695is also possible to specify just a method name:
b37303ee
AF
13696
13697@smallexample
13698break create
13699@end smallexample
13700
13701You must specify the complete method name, including any colons. If
13702your program's source files contain more than one @code{create} method,
13703you'll be presented with a numbered list of classes that implement that
13704method. Indicate your choice by number, or type @samp{0} to exit if
13705none apply.
13706
13707As another example, to clear a breakpoint established at the
13708@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
13709
13710@smallexample
13711clear -[NSWindow makeKeyAndOrderFront:]
13712@end smallexample
13713
13714@node The Print Command with Objective-C
13715@subsubsection The Print Command With Objective-C
721c2651 13716@cindex Objective-C, print objects
c552b3bb
JM
13717@kindex print-object
13718@kindex po @r{(@code{print-object})}
b37303ee 13719
c552b3bb 13720The print command has also been extended to accept methods. For example:
b37303ee
AF
13721
13722@smallexample
c552b3bb 13723print -[@var{object} hash]
b37303ee
AF
13724@end smallexample
13725
13726@cindex print an Objective-C object description
c552b3bb
JM
13727@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
13728@noindent
13729will tell @value{GDBN} to send the @code{hash} message to @var{object}
13730and print the result. Also, an additional command has been added,
13731@code{print-object} or @code{po} for short, which is meant to print
13732the description of an object. However, this command may only work
13733with certain Objective-C libraries that have a particular hook
13734function, @code{_NSPrintForDebugger}, defined.
b37303ee 13735
f4b8a18d
KW
13736@node OpenCL C
13737@subsection OpenCL C
13738
13739@cindex OpenCL C
13740This section provides information about @value{GDBN}s OpenCL C support.
13741
13742@menu
13743* OpenCL C Datatypes::
13744* OpenCL C Expressions::
13745* OpenCL C Operators::
13746@end menu
13747
13748@node OpenCL C Datatypes
13749@subsubsection OpenCL C Datatypes
13750
13751@cindex OpenCL C Datatypes
13752@value{GDBN} supports the builtin scalar and vector datatypes specified
13753by OpenCL 1.1. In addition the half- and double-precision floating point
13754data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
13755extensions are also known to @value{GDBN}.
13756
13757@node OpenCL C Expressions
13758@subsubsection OpenCL C Expressions
13759
13760@cindex OpenCL C Expressions
13761@value{GDBN} supports accesses to vector components including the access as
13762lvalue where possible. Since OpenCL C is based on C99 most C expressions
13763supported by @value{GDBN} can be used as well.
13764
13765@node OpenCL C Operators
13766@subsubsection OpenCL C Operators
13767
13768@cindex OpenCL C Operators
13769@value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
13770vector data types.
13771
09d4efe1
EZ
13772@node Fortran
13773@subsection Fortran
13774@cindex Fortran-specific support in @value{GDBN}
13775
814e32d7
WZ
13776@value{GDBN} can be used to debug programs written in Fortran, but it
13777currently supports only the features of Fortran 77 language.
13778
13779@cindex trailing underscore, in Fortran symbols
13780Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
13781among them) append an underscore to the names of variables and
13782functions. When you debug programs compiled by those compilers, you
13783will need to refer to variables and functions with a trailing
13784underscore.
13785
13786@menu
13787* Fortran Operators:: Fortran operators and expressions
13788* Fortran Defaults:: Default settings for Fortran
79a6e687 13789* Special Fortran Commands:: Special @value{GDBN} commands for Fortran
814e32d7
WZ
13790@end menu
13791
13792@node Fortran Operators
79a6e687 13793@subsubsection Fortran Operators and Expressions
814e32d7
WZ
13794
13795@cindex Fortran operators and expressions
13796
13797Operators must be defined on values of specific types. For instance,
13798@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 13799arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
13800
13801@table @code
13802@item **
99e008fe 13803The exponentiation operator. It raises the first operand to the power
814e32d7
WZ
13804of the second one.
13805
13806@item :
13807The range operator. Normally used in the form of array(low:high) to
13808represent a section of array.
68837c9d
MD
13809
13810@item %
13811The access component operator. Normally used to access elements in derived
13812types. Also suitable for unions. As unions aren't part of regular Fortran,
13813this can only happen when accessing a register that uses a gdbarch-defined
13814union type.
814e32d7
WZ
13815@end table
13816
13817@node Fortran Defaults
13818@subsubsection Fortran Defaults
13819
13820@cindex Fortran Defaults
13821
13822Fortran symbols are usually case-insensitive, so @value{GDBN} by
13823default uses case-insensitive matches for Fortran symbols. You can
13824change that with the @samp{set case-insensitive} command, see
13825@ref{Symbols}, for the details.
13826
79a6e687
BW
13827@node Special Fortran Commands
13828@subsubsection Special Fortran Commands
814e32d7
WZ
13829
13830@cindex Special Fortran commands
13831
db2e3e2e
BW
13832@value{GDBN} has some commands to support Fortran-specific features,
13833such as displaying common blocks.
814e32d7 13834
09d4efe1
EZ
13835@table @code
13836@cindex @code{COMMON} blocks, Fortran
13837@kindex info common
13838@item info common @r{[}@var{common-name}@r{]}
13839This command prints the values contained in the Fortran @code{COMMON}
13840block whose name is @var{common-name}. With no argument, the names of
d52fb0e9 13841all @code{COMMON} blocks visible at the current program location are
09d4efe1
EZ
13842printed.
13843@end table
13844
9c16f35a
EZ
13845@node Pascal
13846@subsection Pascal
13847
13848@cindex Pascal support in @value{GDBN}, limitations
13849Debugging Pascal programs which use sets, subranges, file variables, or
13850nested functions does not currently work. @value{GDBN} does not support
13851entering expressions, printing values, or similar features using Pascal
13852syntax.
13853
13854The Pascal-specific command @code{set print pascal_static-members}
13855controls whether static members of Pascal objects are displayed.
13856@xref{Print Settings, pascal_static-members}.
13857
09d4efe1 13858@node Modula-2
c906108c 13859@subsection Modula-2
7a292a7a 13860
d4f3574e 13861@cindex Modula-2, @value{GDBN} support
c906108c
SS
13862
13863The extensions made to @value{GDBN} to support Modula-2 only support
13864output from the @sc{gnu} Modula-2 compiler (which is currently being
13865developed). Other Modula-2 compilers are not currently supported, and
13866attempting to debug executables produced by them is most likely
13867to give an error as @value{GDBN} reads in the executable's symbol
13868table.
13869
13870@cindex expressions in Modula-2
13871@menu
13872* M2 Operators:: Built-in operators
13873* Built-In Func/Proc:: Built-in functions and procedures
13874* M2 Constants:: Modula-2 constants
72019c9c 13875* M2 Types:: Modula-2 types
c906108c
SS
13876* M2 Defaults:: Default settings for Modula-2
13877* Deviations:: Deviations from standard Modula-2
13878* M2 Checks:: Modula-2 type and range checks
13879* M2 Scope:: The scope operators @code{::} and @code{.}
13880* GDB/M2:: @value{GDBN} and Modula-2
13881@end menu
13882
6d2ebf8b 13883@node M2 Operators
c906108c
SS
13884@subsubsection Operators
13885@cindex Modula-2 operators
13886
13887Operators must be defined on values of specific types. For instance,
13888@code{+} is defined on numbers, but not on structures. Operators are
13889often defined on groups of types. For the purposes of Modula-2, the
13890following definitions hold:
13891
13892@itemize @bullet
13893
13894@item
13895@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
13896their subranges.
13897
13898@item
13899@emph{Character types} consist of @code{CHAR} and its subranges.
13900
13901@item
13902@emph{Floating-point types} consist of @code{REAL}.
13903
13904@item
13905@emph{Pointer types} consist of anything declared as @code{POINTER TO
13906@var{type}}.
13907
13908@item
13909@emph{Scalar types} consist of all of the above.
13910
13911@item
13912@emph{Set types} consist of @code{SET} and @code{BITSET} types.
13913
13914@item
13915@emph{Boolean types} consist of @code{BOOLEAN}.
13916@end itemize
13917
13918@noindent
13919The following operators are supported, and appear in order of
13920increasing precedence:
13921
13922@table @code
13923@item ,
13924Function argument or array index separator.
13925
13926@item :=
13927Assignment. The value of @var{var} @code{:=} @var{value} is
13928@var{value}.
13929
13930@item <@r{, }>
13931Less than, greater than on integral, floating-point, or enumerated
13932types.
13933
13934@item <=@r{, }>=
96a2c332 13935Less than or equal to, greater than or equal to
c906108c
SS
13936on integral, floating-point and enumerated types, or set inclusion on
13937set types. Same precedence as @code{<}.
13938
13939@item =@r{, }<>@r{, }#
13940Equality and two ways of expressing inequality, valid on scalar types.
13941Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
13942available for inequality, since @code{#} conflicts with the script
13943comment character.
13944
13945@item IN
13946Set membership. Defined on set types and the types of their members.
13947Same precedence as @code{<}.
13948
13949@item OR
13950Boolean disjunction. Defined on boolean types.
13951
13952@item AND@r{, }&
d4f3574e 13953Boolean conjunction. Defined on boolean types.
c906108c
SS
13954
13955@item @@
13956The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
13957
13958@item +@r{, }-
13959Addition and subtraction on integral and floating-point types, or union
13960and difference on set types.
13961
13962@item *
13963Multiplication on integral and floating-point types, or set intersection
13964on set types.
13965
13966@item /
13967Division on floating-point types, or symmetric set difference on set
13968types. Same precedence as @code{*}.
13969
13970@item DIV@r{, }MOD
13971Integer division and remainder. Defined on integral types. Same
13972precedence as @code{*}.
13973
13974@item -
99e008fe 13975Negative. Defined on @code{INTEGER} and @code{REAL} data.
c906108c
SS
13976
13977@item ^
13978Pointer dereferencing. Defined on pointer types.
13979
13980@item NOT
13981Boolean negation. Defined on boolean types. Same precedence as
13982@code{^}.
13983
13984@item .
13985@code{RECORD} field selector. Defined on @code{RECORD} data. Same
13986precedence as @code{^}.
13987
13988@item []
13989Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
13990
13991@item ()
13992Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
13993as @code{^}.
13994
13995@item ::@r{, }.
13996@value{GDBN} and Modula-2 scope operators.
13997@end table
13998
13999@quotation
72019c9c 14000@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
14001treats the use of the operator @code{IN}, or the use of operators
14002@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
14003@code{<=}, and @code{>=} on sets as an error.
14004@end quotation
14005
cb51c4e0 14006
6d2ebf8b 14007@node Built-In Func/Proc
79a6e687 14008@subsubsection Built-in Functions and Procedures
cb51c4e0 14009@cindex Modula-2 built-ins
c906108c
SS
14010
14011Modula-2 also makes available several built-in procedures and functions.
14012In describing these, the following metavariables are used:
14013
14014@table @var
14015
14016@item a
14017represents an @code{ARRAY} variable.
14018
14019@item c
14020represents a @code{CHAR} constant or variable.
14021
14022@item i
14023represents a variable or constant of integral type.
14024
14025@item m
14026represents an identifier that belongs to a set. Generally used in the
14027same function with the metavariable @var{s}. The type of @var{s} should
14028be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
14029
14030@item n
14031represents a variable or constant of integral or floating-point type.
14032
14033@item r
14034represents a variable or constant of floating-point type.
14035
14036@item t
14037represents a type.
14038
14039@item v
14040represents a variable.
14041
14042@item x
14043represents a variable or constant of one of many types. See the
14044explanation of the function for details.
14045@end table
14046
14047All Modula-2 built-in procedures also return a result, described below.
14048
14049@table @code
14050@item ABS(@var{n})
14051Returns the absolute value of @var{n}.
14052
14053@item CAP(@var{c})
14054If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 14055equivalent, otherwise it returns its argument.
c906108c
SS
14056
14057@item CHR(@var{i})
14058Returns the character whose ordinal value is @var{i}.
14059
14060@item DEC(@var{v})
c3f6f71d 14061Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
14062
14063@item DEC(@var{v},@var{i})
14064Decrements the value in the variable @var{v} by @var{i}. Returns the
14065new value.
14066
14067@item EXCL(@var{m},@var{s})
14068Removes the element @var{m} from the set @var{s}. Returns the new
14069set.
14070
14071@item FLOAT(@var{i})
14072Returns the floating point equivalent of the integer @var{i}.
14073
14074@item HIGH(@var{a})
14075Returns the index of the last member of @var{a}.
14076
14077@item INC(@var{v})
c3f6f71d 14078Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
14079
14080@item INC(@var{v},@var{i})
14081Increments the value in the variable @var{v} by @var{i}. Returns the
14082new value.
14083
14084@item INCL(@var{m},@var{s})
14085Adds the element @var{m} to the set @var{s} if it is not already
14086there. Returns the new set.
14087
14088@item MAX(@var{t})
14089Returns the maximum value of the type @var{t}.
14090
14091@item MIN(@var{t})
14092Returns the minimum value of the type @var{t}.
14093
14094@item ODD(@var{i})
14095Returns boolean TRUE if @var{i} is an odd number.
14096
14097@item ORD(@var{x})
14098Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
14099value of a character is its @sc{ascii} value (on machines supporting the
14100@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
14101integral, character and enumerated types.
14102
14103@item SIZE(@var{x})
14104Returns the size of its argument. @var{x} can be a variable or a type.
14105
14106@item TRUNC(@var{r})
14107Returns the integral part of @var{r}.
14108
844781a1
GM
14109@item TSIZE(@var{x})
14110Returns the size of its argument. @var{x} can be a variable or a type.
14111
c906108c
SS
14112@item VAL(@var{t},@var{i})
14113Returns the member of the type @var{t} whose ordinal value is @var{i}.
14114@end table
14115
14116@quotation
14117@emph{Warning:} Sets and their operations are not yet supported, so
14118@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
14119an error.
14120@end quotation
14121
14122@cindex Modula-2 constants
6d2ebf8b 14123@node M2 Constants
c906108c
SS
14124@subsubsection Constants
14125
14126@value{GDBN} allows you to express the constants of Modula-2 in the following
14127ways:
14128
14129@itemize @bullet
14130
14131@item
14132Integer constants are simply a sequence of digits. When used in an
14133expression, a constant is interpreted to be type-compatible with the
14134rest of the expression. Hexadecimal integers are specified by a
14135trailing @samp{H}, and octal integers by a trailing @samp{B}.
14136
14137@item
14138Floating point constants appear as a sequence of digits, followed by a
14139decimal point and another sequence of digits. An optional exponent can
14140then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
14141@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
14142digits of the floating point constant must be valid decimal (base 10)
14143digits.
14144
14145@item
14146Character constants consist of a single character enclosed by a pair of
14147like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 14148also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
14149followed by a @samp{C}.
14150
14151@item
14152String constants consist of a sequence of characters enclosed by a
14153pair of like quotes, either single (@code{'}) or double (@code{"}).
14154Escape sequences in the style of C are also allowed. @xref{C
79a6e687 14155Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
c906108c
SS
14156sequences.
14157
14158@item
14159Enumerated constants consist of an enumerated identifier.
14160
14161@item
14162Boolean constants consist of the identifiers @code{TRUE} and
14163@code{FALSE}.
14164
14165@item
14166Pointer constants consist of integral values only.
14167
14168@item
14169Set constants are not yet supported.
14170@end itemize
14171
72019c9c
GM
14172@node M2 Types
14173@subsubsection Modula-2 Types
14174@cindex Modula-2 types
14175
14176Currently @value{GDBN} can print the following data types in Modula-2
14177syntax: array types, record types, set types, pointer types, procedure
14178types, enumerated types, subrange types and base types. You can also
14179print the contents of variables declared using these type.
14180This section gives a number of simple source code examples together with
14181sample @value{GDBN} sessions.
14182
14183The first example contains the following section of code:
14184
14185@smallexample
14186VAR
14187 s: SET OF CHAR ;
14188 r: [20..40] ;
14189@end smallexample
14190
14191@noindent
14192and you can request @value{GDBN} to interrogate the type and value of
14193@code{r} and @code{s}.
14194
14195@smallexample
14196(@value{GDBP}) print s
14197@{'A'..'C', 'Z'@}
14198(@value{GDBP}) ptype s
14199SET OF CHAR
14200(@value{GDBP}) print r
1420121
14202(@value{GDBP}) ptype r
14203[20..40]
14204@end smallexample
14205
14206@noindent
14207Likewise if your source code declares @code{s} as:
14208
14209@smallexample
14210VAR
14211 s: SET ['A'..'Z'] ;
14212@end smallexample
14213
14214@noindent
14215then you may query the type of @code{s} by:
14216
14217@smallexample
14218(@value{GDBP}) ptype s
14219type = SET ['A'..'Z']
14220@end smallexample
14221
14222@noindent
14223Note that at present you cannot interactively manipulate set
14224expressions using the debugger.
14225
14226The following example shows how you might declare an array in Modula-2
14227and how you can interact with @value{GDBN} to print its type and contents:
14228
14229@smallexample
14230VAR
14231 s: ARRAY [-10..10] OF CHAR ;
14232@end smallexample
14233
14234@smallexample
14235(@value{GDBP}) ptype s
14236ARRAY [-10..10] OF CHAR
14237@end smallexample
14238
14239Note that the array handling is not yet complete and although the type
14240is printed correctly, expression handling still assumes that all
14241arrays have a lower bound of zero and not @code{-10} as in the example
844781a1 14242above.
72019c9c
GM
14243
14244Here are some more type related Modula-2 examples:
14245
14246@smallexample
14247TYPE
14248 colour = (blue, red, yellow, green) ;
14249 t = [blue..yellow] ;
14250VAR
14251 s: t ;
14252BEGIN
14253 s := blue ;
14254@end smallexample
14255
14256@noindent
14257The @value{GDBN} interaction shows how you can query the data type
14258and value of a variable.
14259
14260@smallexample
14261(@value{GDBP}) print s
14262$1 = blue
14263(@value{GDBP}) ptype t
14264type = [blue..yellow]
14265@end smallexample
14266
14267@noindent
14268In this example a Modula-2 array is declared and its contents
14269displayed. Observe that the contents are written in the same way as
14270their @code{C} counterparts.
14271
14272@smallexample
14273VAR
14274 s: ARRAY [1..5] OF CARDINAL ;
14275BEGIN
14276 s[1] := 1 ;
14277@end smallexample
14278
14279@smallexample
14280(@value{GDBP}) print s
14281$1 = @{1, 0, 0, 0, 0@}
14282(@value{GDBP}) ptype s
14283type = ARRAY [1..5] OF CARDINAL
14284@end smallexample
14285
14286The Modula-2 language interface to @value{GDBN} also understands
14287pointer types as shown in this example:
14288
14289@smallexample
14290VAR
14291 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
14292BEGIN
14293 NEW(s) ;
14294 s^[1] := 1 ;
14295@end smallexample
14296
14297@noindent
14298and you can request that @value{GDBN} describes the type of @code{s}.
14299
14300@smallexample
14301(@value{GDBP}) ptype s
14302type = POINTER TO ARRAY [1..5] OF CARDINAL
14303@end smallexample
14304
14305@value{GDBN} handles compound types as we can see in this example.
14306Here we combine array types, record types, pointer types and subrange
14307types:
14308
14309@smallexample
14310TYPE
14311 foo = RECORD
14312 f1: CARDINAL ;
14313 f2: CHAR ;
14314 f3: myarray ;
14315 END ;
14316
14317 myarray = ARRAY myrange OF CARDINAL ;
14318 myrange = [-2..2] ;
14319VAR
14320 s: POINTER TO ARRAY myrange OF foo ;
14321@end smallexample
14322
14323@noindent
14324and you can ask @value{GDBN} to describe the type of @code{s} as shown
14325below.
14326
14327@smallexample
14328(@value{GDBP}) ptype s
14329type = POINTER TO ARRAY [-2..2] OF foo = RECORD
14330 f1 : CARDINAL;
14331 f2 : CHAR;
14332 f3 : ARRAY [-2..2] OF CARDINAL;
14333END
14334@end smallexample
14335
6d2ebf8b 14336@node M2 Defaults
79a6e687 14337@subsubsection Modula-2 Defaults
c906108c
SS
14338@cindex Modula-2 defaults
14339
14340If type and range checking are set automatically by @value{GDBN}, they
14341both default to @code{on} whenever the working language changes to
d4f3574e 14342Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
14343selected the working language.
14344
14345If you allow @value{GDBN} to set the language automatically, then entering
14346code compiled from a file whose name ends with @file{.mod} sets the
79a6e687
BW
14347working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
14348Infer the Source Language}, for further details.
c906108c 14349
6d2ebf8b 14350@node Deviations
79a6e687 14351@subsubsection Deviations from Standard Modula-2
c906108c
SS
14352@cindex Modula-2, deviations from
14353
14354A few changes have been made to make Modula-2 programs easier to debug.
14355This is done primarily via loosening its type strictness:
14356
14357@itemize @bullet
14358@item
14359Unlike in standard Modula-2, pointer constants can be formed by
14360integers. This allows you to modify pointer variables during
14361debugging. (In standard Modula-2, the actual address contained in a
14362pointer variable is hidden from you; it can only be modified
14363through direct assignment to another pointer variable or expression that
14364returned a pointer.)
14365
14366@item
14367C escape sequences can be used in strings and characters to represent
14368non-printable characters. @value{GDBN} prints out strings with these
14369escape sequences embedded. Single non-printable characters are
14370printed using the @samp{CHR(@var{nnn})} format.
14371
14372@item
14373The assignment operator (@code{:=}) returns the value of its right-hand
14374argument.
14375
14376@item
14377All built-in procedures both modify @emph{and} return their argument.
14378@end itemize
14379
6d2ebf8b 14380@node M2 Checks
79a6e687 14381@subsubsection Modula-2 Type and Range Checks
c906108c
SS
14382@cindex Modula-2 checks
14383
14384@quotation
14385@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
14386range checking.
14387@end quotation
14388@c FIXME remove warning when type/range checks added
14389
14390@value{GDBN} considers two Modula-2 variables type equivalent if:
14391
14392@itemize @bullet
14393@item
14394They are of types that have been declared equivalent via a @code{TYPE
14395@var{t1} = @var{t2}} statement
14396
14397@item
14398They have been declared on the same line. (Note: This is true of the
14399@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
14400@end itemize
14401
14402As long as type checking is enabled, any attempt to combine variables
14403whose types are not equivalent is an error.
14404
14405Range checking is done on all mathematical operations, assignment, array
14406index bounds, and all built-in functions and procedures.
14407
6d2ebf8b 14408@node M2 Scope
79a6e687 14409@subsubsection The Scope Operators @code{::} and @code{.}
c906108c 14410@cindex scope
41afff9a 14411@cindex @code{.}, Modula-2 scope operator
c906108c
SS
14412@cindex colon, doubled as scope operator
14413@ifinfo
41afff9a 14414@vindex colon-colon@r{, in Modula-2}
c906108c
SS
14415@c Info cannot handle :: but TeX can.
14416@end ifinfo
a67ec3f4 14417@ifnotinfo
41afff9a 14418@vindex ::@r{, in Modula-2}
a67ec3f4 14419@end ifnotinfo
c906108c
SS
14420
14421There are a few subtle differences between the Modula-2 scope operator
14422(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
14423similar syntax:
14424
474c8240 14425@smallexample
c906108c
SS
14426
14427@var{module} . @var{id}
14428@var{scope} :: @var{id}
474c8240 14429@end smallexample
c906108c
SS
14430
14431@noindent
14432where @var{scope} is the name of a module or a procedure,
14433@var{module} the name of a module, and @var{id} is any declared
14434identifier within your program, except another module.
14435
14436Using the @code{::} operator makes @value{GDBN} search the scope
14437specified by @var{scope} for the identifier @var{id}. If it is not
14438found in the specified scope, then @value{GDBN} searches all scopes
14439enclosing the one specified by @var{scope}.
14440
14441Using the @code{.} operator makes @value{GDBN} search the current scope for
14442the identifier specified by @var{id} that was imported from the
14443definition module specified by @var{module}. With this operator, it is
14444an error if the identifier @var{id} was not imported from definition
14445module @var{module}, or if @var{id} is not an identifier in
14446@var{module}.
14447
6d2ebf8b 14448@node GDB/M2
c906108c
SS
14449@subsubsection @value{GDBN} and Modula-2
14450
14451Some @value{GDBN} commands have little use when debugging Modula-2 programs.
14452Five subcommands of @code{set print} and @code{show print} apply
b37052ae 14453specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 14454@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 14455apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
14456analogue in Modula-2.
14457
14458The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 14459with any language, is not useful with Modula-2. Its
c906108c 14460intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 14461created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 14462address can be specified by an integral constant, the construct
d4f3574e 14463@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
14464
14465@cindex @code{#} in Modula-2
14466In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
14467interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 14468
e07c999f
PH
14469@node Ada
14470@subsection Ada
14471@cindex Ada
14472
14473The extensions made to @value{GDBN} for Ada only support
14474output from the @sc{gnu} Ada (GNAT) compiler.
14475Other Ada compilers are not currently supported, and
14476attempting to debug executables produced by them is most likely
14477to be difficult.
14478
14479
14480@cindex expressions in Ada
14481@menu
14482* Ada Mode Intro:: General remarks on the Ada syntax
14483 and semantics supported by Ada mode
14484 in @value{GDBN}.
14485* Omissions from Ada:: Restrictions on the Ada expression syntax.
14486* Additions to Ada:: Extensions of the Ada expression syntax.
14487* Stopping Before Main Program:: Debugging the program during elaboration.
20924a55
JB
14488* Ada Tasks:: Listing and setting breakpoints in tasks.
14489* Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
6e1bb179
JB
14490* Ravenscar Profile:: Tasking Support when using the Ravenscar
14491 Profile
e07c999f
PH
14492* Ada Glitches:: Known peculiarities of Ada mode.
14493@end menu
14494
14495@node Ada Mode Intro
14496@subsubsection Introduction
14497@cindex Ada mode, general
14498
14499The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
14500syntax, with some extensions.
14501The philosophy behind the design of this subset is
14502
14503@itemize @bullet
14504@item
14505That @value{GDBN} should provide basic literals and access to operations for
14506arithmetic, dereferencing, field selection, indexing, and subprogram calls,
14507leaving more sophisticated computations to subprograms written into the
14508program (which therefore may be called from @value{GDBN}).
14509
14510@item
14511That type safety and strict adherence to Ada language restrictions
14512are not particularly important to the @value{GDBN} user.
14513
14514@item
14515That brevity is important to the @value{GDBN} user.
14516@end itemize
14517
f3a2dd1a
JB
14518Thus, for brevity, the debugger acts as if all names declared in
14519user-written packages are directly visible, even if they are not visible
14520according to Ada rules, thus making it unnecessary to fully qualify most
14521names with their packages, regardless of context. Where this causes
14522ambiguity, @value{GDBN} asks the user's intent.
e07c999f
PH
14523
14524The debugger will start in Ada mode if it detects an Ada main program.
14525As for other languages, it will enter Ada mode when stopped in a program that
14526was translated from an Ada source file.
14527
14528While in Ada mode, you may use `@t{--}' for comments. This is useful
14529mostly for documenting command files. The standard @value{GDBN} comment
14530(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
14531middle (to allow based literals).
14532
14533The debugger supports limited overloading. Given a subprogram call in which
14534the function symbol has multiple definitions, it will use the number of
14535actual parameters and some information about their types to attempt to narrow
14536the set of definitions. It also makes very limited use of context, preferring
14537procedures to functions in the context of the @code{call} command, and
14538functions to procedures elsewhere.
14539
14540@node Omissions from Ada
14541@subsubsection Omissions from Ada
14542@cindex Ada, omissions from
14543
14544Here are the notable omissions from the subset:
14545
14546@itemize @bullet
14547@item
14548Only a subset of the attributes are supported:
14549
14550@itemize @minus
14551@item
14552@t{'First}, @t{'Last}, and @t{'Length}
14553 on array objects (not on types and subtypes).
14554
14555@item
14556@t{'Min} and @t{'Max}.
14557
14558@item
14559@t{'Pos} and @t{'Val}.
14560
14561@item
14562@t{'Tag}.
14563
14564@item
14565@t{'Range} on array objects (not subtypes), but only as the right
14566operand of the membership (@code{in}) operator.
14567
14568@item
14569@t{'Access}, @t{'Unchecked_Access}, and
14570@t{'Unrestricted_Access} (a GNAT extension).
14571
14572@item
14573@t{'Address}.
14574@end itemize
14575
14576@item
14577The names in
14578@code{Characters.Latin_1} are not available and
14579concatenation is not implemented. Thus, escape characters in strings are
14580not currently available.
14581
14582@item
14583Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
14584equality of representations. They will generally work correctly
14585for strings and arrays whose elements have integer or enumeration types.
14586They may not work correctly for arrays whose element
14587types have user-defined equality, for arrays of real values
14588(in particular, IEEE-conformant floating point, because of negative
14589zeroes and NaNs), and for arrays whose elements contain unused bits with
14590indeterminate values.
14591
14592@item
14593The other component-by-component array operations (@code{and}, @code{or},
14594@code{xor}, @code{not}, and relational tests other than equality)
14595are not implemented.
14596
14597@item
860701dc
PH
14598@cindex array aggregates (Ada)
14599@cindex record aggregates (Ada)
14600@cindex aggregates (Ada)
14601There is limited support for array and record aggregates. They are
14602permitted only on the right sides of assignments, as in these examples:
14603
14604@smallexample
077e0a52
JB
14605(@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
14606(@value{GDBP}) set An_Array := (1, others => 0)
14607(@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
14608(@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
14609(@value{GDBP}) set A_Record := (1, "Peter", True);
14610(@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
860701dc
PH
14611@end smallexample
14612
14613Changing a
14614discriminant's value by assigning an aggregate has an
14615undefined effect if that discriminant is used within the record.
14616However, you can first modify discriminants by directly assigning to
14617them (which normally would not be allowed in Ada), and then performing an
14618aggregate assignment. For example, given a variable @code{A_Rec}
14619declared to have a type such as:
14620
14621@smallexample
14622type Rec (Len : Small_Integer := 0) is record
14623 Id : Integer;
14624 Vals : IntArray (1 .. Len);
14625end record;
14626@end smallexample
14627
14628you can assign a value with a different size of @code{Vals} with two
14629assignments:
14630
14631@smallexample
077e0a52
JB
14632(@value{GDBP}) set A_Rec.Len := 4
14633(@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
860701dc
PH
14634@end smallexample
14635
14636As this example also illustrates, @value{GDBN} is very loose about the usual
14637rules concerning aggregates. You may leave out some of the
14638components of an array or record aggregate (such as the @code{Len}
14639component in the assignment to @code{A_Rec} above); they will retain their
14640original values upon assignment. You may freely use dynamic values as
14641indices in component associations. You may even use overlapping or
14642redundant component associations, although which component values are
14643assigned in such cases is not defined.
e07c999f
PH
14644
14645@item
14646Calls to dispatching subprograms are not implemented.
14647
14648@item
14649The overloading algorithm is much more limited (i.e., less selective)
ae21e955
BW
14650than that of real Ada. It makes only limited use of the context in
14651which a subexpression appears to resolve its meaning, and it is much
14652looser in its rules for allowing type matches. As a result, some
14653function calls will be ambiguous, and the user will be asked to choose
14654the proper resolution.
e07c999f
PH
14655
14656@item
14657The @code{new} operator is not implemented.
14658
14659@item
14660Entry calls are not implemented.
14661
14662@item
14663Aside from printing, arithmetic operations on the native VAX floating-point
14664formats are not supported.
14665
14666@item
14667It is not possible to slice a packed array.
158c7665
PH
14668
14669@item
14670The names @code{True} and @code{False}, when not part of a qualified name,
14671are interpreted as if implicitly prefixed by @code{Standard}, regardless of
14672context.
14673Should your program
14674redefine these names in a package or procedure (at best a dubious practice),
14675you will have to use fully qualified names to access their new definitions.
e07c999f
PH
14676@end itemize
14677
14678@node Additions to Ada
14679@subsubsection Additions to Ada
14680@cindex Ada, deviations from
14681
14682As it does for other languages, @value{GDBN} makes certain generic
14683extensions to Ada (@pxref{Expressions}):
14684
14685@itemize @bullet
14686@item
ae21e955
BW
14687If the expression @var{E} is a variable residing in memory (typically
14688a local variable or array element) and @var{N} is a positive integer,
14689then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
14690@var{N}-1 adjacent variables following it in memory as an array. In
14691Ada, this operator is generally not necessary, since its prime use is
14692in displaying parts of an array, and slicing will usually do this in
14693Ada. However, there are occasional uses when debugging programs in
14694which certain debugging information has been optimized away.
e07c999f
PH
14695
14696@item
ae21e955
BW
14697@code{@var{B}::@var{var}} means ``the variable named @var{var} that
14698appears in function or file @var{B}.'' When @var{B} is a file name,
14699you must typically surround it in single quotes.
e07c999f
PH
14700
14701@item
14702The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
14703@var{type} that appears at address @var{addr}.''
14704
14705@item
14706A name starting with @samp{$} is a convenience variable
14707(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
14708@end itemize
14709
ae21e955
BW
14710In addition, @value{GDBN} provides a few other shortcuts and outright
14711additions specific to Ada:
e07c999f
PH
14712
14713@itemize @bullet
14714@item
14715The assignment statement is allowed as an expression, returning
14716its right-hand operand as its value. Thus, you may enter
14717
14718@smallexample
077e0a52
JB
14719(@value{GDBP}) set x := y + 3
14720(@value{GDBP}) print A(tmp := y + 1)
e07c999f
PH
14721@end smallexample
14722
14723@item
14724The semicolon is allowed as an ``operator,'' returning as its value
14725the value of its right-hand operand.
14726This allows, for example,
14727complex conditional breaks:
14728
14729@smallexample
077e0a52
JB
14730(@value{GDBP}) break f
14731(@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
e07c999f
PH
14732@end smallexample
14733
14734@item
14735Rather than use catenation and symbolic character names to introduce special
14736characters into strings, one may instead use a special bracket notation,
14737which is also used to print strings. A sequence of characters of the form
14738@samp{["@var{XX}"]} within a string or character literal denotes the
14739(single) character whose numeric encoding is @var{XX} in hexadecimal. The
14740sequence of characters @samp{["""]} also denotes a single quotation mark
14741in strings. For example,
14742@smallexample
14743 "One line.["0a"]Next line.["0a"]"
14744@end smallexample
14745@noindent
ae21e955
BW
14746contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
14747after each period.
e07c999f
PH
14748
14749@item
14750The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
14751@t{'Max} is optional (and is ignored in any case). For example, it is valid
14752to write
14753
14754@smallexample
077e0a52 14755(@value{GDBP}) print 'max(x, y)
e07c999f
PH
14756@end smallexample
14757
14758@item
14759When printing arrays, @value{GDBN} uses positional notation when the
14760array has a lower bound of 1, and uses a modified named notation otherwise.
ae21e955
BW
14761For example, a one-dimensional array of three integers with a lower bound
14762of 3 might print as
e07c999f
PH
14763
14764@smallexample
14765(3 => 10, 17, 1)
14766@end smallexample
14767
14768@noindent
14769That is, in contrast to valid Ada, only the first component has a @code{=>}
14770clause.
14771
14772@item
14773You may abbreviate attributes in expressions with any unique,
14774multi-character subsequence of
14775their names (an exact match gets preference).
14776For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
14777in place of @t{a'length}.
14778
14779@item
14780@cindex quoting Ada internal identifiers
14781Since Ada is case-insensitive, the debugger normally maps identifiers you type
14782to lower case. The GNAT compiler uses upper-case characters for
14783some of its internal identifiers, which are normally of no interest to users.
14784For the rare occasions when you actually have to look at them,
14785enclose them in angle brackets to avoid the lower-case mapping.
14786For example,
14787@smallexample
077e0a52 14788(@value{GDBP}) print <JMPBUF_SAVE>[0]
e07c999f
PH
14789@end smallexample
14790
14791@item
14792Printing an object of class-wide type or dereferencing an
14793access-to-class-wide value will display all the components of the object's
14794specific type (as indicated by its run-time tag). Likewise, component
14795selection on such a value will operate on the specific type of the
14796object.
14797
14798@end itemize
14799
14800@node Stopping Before Main Program
14801@subsubsection Stopping at the Very Beginning
14802
14803@cindex breakpointing Ada elaboration code
14804It is sometimes necessary to debug the program during elaboration, and
14805before reaching the main procedure.
14806As defined in the Ada Reference
14807Manual, the elaboration code is invoked from a procedure called
14808@code{adainit}. To run your program up to the beginning of
14809elaboration, simply use the following two commands:
14810@code{tbreak adainit} and @code{run}.
14811
20924a55
JB
14812@node Ada Tasks
14813@subsubsection Extensions for Ada Tasks
14814@cindex Ada, tasking
14815
14816Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
14817@value{GDBN} provides the following task-related commands:
14818
14819@table @code
14820@kindex info tasks
14821@item info tasks
14822This command shows a list of current Ada tasks, as in the following example:
14823
14824
14825@smallexample
14826@iftex
14827@leftskip=0.5cm
14828@end iftex
14829(@value{GDBP}) info tasks
14830 ID TID P-ID Pri State Name
14831 1 8088000 0 15 Child Activation Wait main_task
14832 2 80a4000 1 15 Accept Statement b
14833 3 809a800 1 15 Child Activation Wait a
32cd1edc 14834* 4 80ae800 3 15 Runnable c
20924a55
JB
14835
14836@end smallexample
14837
14838@noindent
14839In this listing, the asterisk before the last task indicates it to be the
14840task currently being inspected.
14841
14842@table @asis
14843@item ID
14844Represents @value{GDBN}'s internal task number.
14845
14846@item TID
14847The Ada task ID.
14848
14849@item P-ID
14850The parent's task ID (@value{GDBN}'s internal task number).
14851
14852@item Pri
14853The base priority of the task.
14854
14855@item State
14856Current state of the task.
14857
14858@table @code
14859@item Unactivated
14860The task has been created but has not been activated. It cannot be
14861executing.
14862
20924a55
JB
14863@item Runnable
14864The task is not blocked for any reason known to Ada. (It may be waiting
14865for a mutex, though.) It is conceptually "executing" in normal mode.
14866
14867@item Terminated
14868The task is terminated, in the sense of ARM 9.3 (5). Any dependents
14869that were waiting on terminate alternatives have been awakened and have
14870terminated themselves.
14871
14872@item Child Activation Wait
14873The task is waiting for created tasks to complete activation.
14874
14875@item Accept Statement
14876The task is waiting on an accept or selective wait statement.
14877
14878@item Waiting on entry call
14879The task is waiting on an entry call.
14880
14881@item Async Select Wait
14882The task is waiting to start the abortable part of an asynchronous
14883select statement.
14884
14885@item Delay Sleep
14886The task is waiting on a select statement with only a delay
14887alternative open.
14888
14889@item Child Termination Wait
14890The task is sleeping having completed a master within itself, and is
14891waiting for the tasks dependent on that master to become terminated or
14892waiting on a terminate Phase.
14893
14894@item Wait Child in Term Alt
14895The task is sleeping waiting for tasks on terminate alternatives to
14896finish terminating.
14897
14898@item Accepting RV with @var{taskno}
14899The task is accepting a rendez-vous with the task @var{taskno}.
14900@end table
14901
14902@item Name
14903Name of the task in the program.
14904
14905@end table
14906
14907@kindex info task @var{taskno}
14908@item info task @var{taskno}
14909This command shows detailled informations on the specified task, as in
14910the following example:
14911@smallexample
14912@iftex
14913@leftskip=0.5cm
14914@end iftex
14915(@value{GDBP}) info tasks
14916 ID TID P-ID Pri State Name
14917 1 8077880 0 15 Child Activation Wait main_task
32cd1edc 14918* 2 807c468 1 15 Runnable task_1
20924a55
JB
14919(@value{GDBP}) info task 2
14920Ada Task: 0x807c468
14921Name: task_1
14922Thread: 0x807f378
14923Parent: 1 (main_task)
14924Base Priority: 15
14925State: Runnable
14926@end smallexample
14927
14928@item task
14929@kindex task@r{ (Ada)}
14930@cindex current Ada task ID
14931This command prints the ID of the current task.
14932
14933@smallexample
14934@iftex
14935@leftskip=0.5cm
14936@end iftex
14937(@value{GDBP}) info tasks
14938 ID TID P-ID Pri State Name
14939 1 8077870 0 15 Child Activation Wait main_task
32cd1edc 14940* 2 807c458 1 15 Runnable t
20924a55
JB
14941(@value{GDBP}) task
14942[Current task is 2]
14943@end smallexample
14944
14945@item task @var{taskno}
14946@cindex Ada task switching
14947This command is like the @code{thread @var{threadno}}
14948command (@pxref{Threads}). It switches the context of debugging
14949from the current task to the given task.
14950
14951@smallexample
14952@iftex
14953@leftskip=0.5cm
14954@end iftex
14955(@value{GDBP}) info tasks
14956 ID TID P-ID Pri State Name
14957 1 8077870 0 15 Child Activation Wait main_task
32cd1edc 14958* 2 807c458 1 15 Runnable t
20924a55
JB
14959(@value{GDBP}) task 1
14960[Switching to task 1]
14961#0 0x8067726 in pthread_cond_wait ()
14962(@value{GDBP}) bt
14963#0 0x8067726 in pthread_cond_wait ()
14964#1 0x8056714 in system.os_interface.pthread_cond_wait ()
14965#2 0x805cb63 in system.task_primitives.operations.sleep ()
14966#3 0x806153e in system.tasking.stages.activate_tasks ()
14967#4 0x804aacc in un () at un.adb:5
14968@end smallexample
14969
45ac276d
JB
14970@item break @var{linespec} task @var{taskno}
14971@itemx break @var{linespec} task @var{taskno} if @dots{}
14972@cindex breakpoints and tasks, in Ada
14973@cindex task breakpoints, in Ada
14974@kindex break @dots{} task @var{taskno}@r{ (Ada)}
14975These commands are like the @code{break @dots{} thread @dots{}}
14976command (@pxref{Thread Stops}).
14977@var{linespec} specifies source lines, as described
14978in @ref{Specify Location}.
14979
14980Use the qualifier @samp{task @var{taskno}} with a breakpoint command
14981to specify that you only want @value{GDBN} to stop the program when a
14982particular Ada task reaches this breakpoint. @var{taskno} is one of the
14983numeric task identifiers assigned by @value{GDBN}, shown in the first
14984column of the @samp{info tasks} display.
14985
14986If you do not specify @samp{task @var{taskno}} when you set a
14987breakpoint, the breakpoint applies to @emph{all} tasks of your
14988program.
14989
14990You can use the @code{task} qualifier on conditional breakpoints as
14991well; in this case, place @samp{task @var{taskno}} before the
14992breakpoint condition (before the @code{if}).
14993
14994For example,
14995
14996@smallexample
14997@iftex
14998@leftskip=0.5cm
14999@end iftex
15000(@value{GDBP}) info tasks
15001 ID TID P-ID Pri State Name
15002 1 140022020 0 15 Child Activation Wait main_task
15003 2 140045060 1 15 Accept/Select Wait t2
15004 3 140044840 1 15 Runnable t1
15005* 4 140056040 1 15 Runnable t3
15006(@value{GDBP}) b 15 task 2
15007Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
15008(@value{GDBP}) cont
15009Continuing.
15010task # 1 running
15011task # 2 running
15012
15013Breakpoint 5, test_task_debug () at test_task_debug.adb:15
1501415 flush;
15015(@value{GDBP}) info tasks
15016 ID TID P-ID Pri State Name
15017 1 140022020 0 15 Child Activation Wait main_task
15018* 2 140045060 1 15 Runnable t2
15019 3 140044840 1 15 Runnable t1
15020 4 140056040 1 15 Delay Sleep t3
15021@end smallexample
20924a55
JB
15022@end table
15023
15024@node Ada Tasks and Core Files
15025@subsubsection Tasking Support when Debugging Core Files
15026@cindex Ada tasking and core file debugging
15027
15028When inspecting a core file, as opposed to debugging a live program,
15029tasking support may be limited or even unavailable, depending on
15030the platform being used.
15031For instance, on x86-linux, the list of tasks is available, but task
15032switching is not supported. On Tru64, however, task switching will work
15033as usual.
15034
15035On certain platforms, including Tru64, the debugger needs to perform some
15036memory writes in order to provide Ada tasking support. When inspecting
15037a core file, this means that the core file must be opened with read-write
15038privileges, using the command @samp{"set write on"} (@pxref{Patching}).
15039Under these circumstances, you should make a backup copy of the core
15040file before inspecting it with @value{GDBN}.
15041
6e1bb179
JB
15042@node Ravenscar Profile
15043@subsubsection Tasking Support when using the Ravenscar Profile
15044@cindex Ravenscar Profile
15045
15046The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
15047specifically designed for systems with safety-critical real-time
15048requirements.
15049
15050@table @code
15051@kindex set ravenscar task-switching on
15052@cindex task switching with program using Ravenscar Profile
15053@item set ravenscar task-switching on
15054Allows task switching when debugging a program that uses the Ravenscar
15055Profile. This is the default.
15056
15057@kindex set ravenscar task-switching off
15058@item set ravenscar task-switching off
15059Turn off task switching when debugging a program that uses the Ravenscar
15060Profile. This is mostly intended to disable the code that adds support
15061for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
15062the Ravenscar runtime is preventing @value{GDBN} from working properly.
15063To be effective, this command should be run before the program is started.
15064
15065@kindex show ravenscar task-switching
15066@item show ravenscar task-switching
15067Show whether it is possible to switch from task to task in a program
15068using the Ravenscar Profile.
15069
15070@end table
15071
e07c999f
PH
15072@node Ada Glitches
15073@subsubsection Known Peculiarities of Ada Mode
15074@cindex Ada, problems
15075
15076Besides the omissions listed previously (@pxref{Omissions from Ada}),
15077we know of several problems with and limitations of Ada mode in
15078@value{GDBN},
15079some of which will be fixed with planned future releases of the debugger
15080and the GNU Ada compiler.
15081
15082@itemize @bullet
e07c999f
PH
15083@item
15084Static constants that the compiler chooses not to materialize as objects in
15085storage are invisible to the debugger.
15086
15087@item
15088Named parameter associations in function argument lists are ignored (the
15089argument lists are treated as positional).
15090
15091@item
15092Many useful library packages are currently invisible to the debugger.
15093
15094@item
15095Fixed-point arithmetic, conversions, input, and output is carried out using
15096floating-point arithmetic, and may give results that only approximate those on
15097the host machine.
15098
e07c999f
PH
15099@item
15100The GNAT compiler never generates the prefix @code{Standard} for any of
15101the standard symbols defined by the Ada language. @value{GDBN} knows about
15102this: it will strip the prefix from names when you use it, and will never
15103look for a name you have so qualified among local symbols, nor match against
15104symbols in other packages or subprograms. If you have
15105defined entities anywhere in your program other than parameters and
15106local variables whose simple names match names in @code{Standard},
15107GNAT's lack of qualification here can cause confusion. When this happens,
15108you can usually resolve the confusion
15109by qualifying the problematic names with package
15110@code{Standard} explicitly.
15111@end itemize
15112
95433b34
JB
15113Older versions of the compiler sometimes generate erroneous debugging
15114information, resulting in the debugger incorrectly printing the value
15115of affected entities. In some cases, the debugger is able to work
15116around an issue automatically. In other cases, the debugger is able
15117to work around the issue, but the work-around has to be specifically
15118enabled.
15119
15120@kindex set ada trust-PAD-over-XVS
15121@kindex show ada trust-PAD-over-XVS
15122@table @code
15123
15124@item set ada trust-PAD-over-XVS on
15125Configure GDB to strictly follow the GNAT encoding when computing the
15126value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
15127types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
15128a complete description of the encoding used by the GNAT compiler).
15129This is the default.
15130
15131@item set ada trust-PAD-over-XVS off
15132This is related to the encoding using by the GNAT compiler. If @value{GDBN}
15133sometimes prints the wrong value for certain entities, changing @code{ada
15134trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
15135the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
15136@code{off}, but this incurs a slight performance penalty, so it is
15137recommended to leave this setting to @code{on} unless necessary.
15138
15139@end table
15140
79a6e687
BW
15141@node Unsupported Languages
15142@section Unsupported Languages
4e562065
JB
15143
15144@cindex unsupported languages
15145@cindex minimal language
15146In addition to the other fully-supported programming languages,
15147@value{GDBN} also provides a pseudo-language, called @code{minimal}.
15148It does not represent a real programming language, but provides a set
15149of capabilities close to what the C or assembly languages provide.
15150This should allow most simple operations to be performed while debugging
15151an application that uses a language currently not supported by @value{GDBN}.
15152
15153If the language is set to @code{auto}, @value{GDBN} will automatically
15154select this language if the current frame corresponds to an unsupported
15155language.
15156
6d2ebf8b 15157@node Symbols
c906108c
SS
15158@chapter Examining the Symbol Table
15159
d4f3574e 15160The commands described in this chapter allow you to inquire about the
c906108c
SS
15161symbols (names of variables, functions and types) defined in your
15162program. This information is inherent in the text of your program and
15163does not change as your program executes. @value{GDBN} finds it in your
15164program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
15165(@pxref{File Options, ,Choosing Files}), or by one of the
15166file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
15167
15168@cindex symbol names
15169@cindex names of symbols
15170@cindex quoting names
15171Occasionally, you may need to refer to symbols that contain unusual
15172characters, which @value{GDBN} ordinarily treats as word delimiters. The
15173most frequent case is in referring to static variables in other
79a6e687 15174source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
15175are recorded in object files as debugging symbols, but @value{GDBN} would
15176ordinarily parse a typical file name, like @file{foo.c}, as the three words
15177@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
15178@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
15179
474c8240 15180@smallexample
c906108c 15181p 'foo.c'::x
474c8240 15182@end smallexample
c906108c
SS
15183
15184@noindent
15185looks up the value of @code{x} in the scope of the file @file{foo.c}.
15186
15187@table @code
a8f24a35
EZ
15188@cindex case-insensitive symbol names
15189@cindex case sensitivity in symbol names
15190@kindex set case-sensitive
15191@item set case-sensitive on
15192@itemx set case-sensitive off
15193@itemx set case-sensitive auto
15194Normally, when @value{GDBN} looks up symbols, it matches their names
15195with case sensitivity determined by the current source language.
15196Occasionally, you may wish to control that. The command @code{set
15197case-sensitive} lets you do that by specifying @code{on} for
15198case-sensitive matches or @code{off} for case-insensitive ones. If
15199you specify @code{auto}, case sensitivity is reset to the default
15200suitable for the source language. The default is case-sensitive
15201matches for all languages except for Fortran, for which the default is
15202case-insensitive matches.
15203
9c16f35a
EZ
15204@kindex show case-sensitive
15205@item show case-sensitive
a8f24a35
EZ
15206This command shows the current setting of case sensitivity for symbols
15207lookups.
15208
53342f27
TT
15209@kindex set print type methods
15210@item set print type methods
15211@itemx set print type methods on
15212@itemx set print type methods off
15213Normally, when @value{GDBN} prints a class, it displays any methods
15214declared in that class. You can control this behavior either by
15215passing the appropriate flag to @code{ptype}, or using @command{set
15216print type methods}. Specifying @code{on} will cause @value{GDBN} to
15217display the methods; this is the default. Specifying @code{off} will
15218cause @value{GDBN} to omit the methods.
15219
15220@kindex show print type methods
15221@item show print type methods
15222This command shows the current setting of method display when printing
15223classes.
15224
15225@kindex set print type typedefs
15226@item set print type typedefs
15227@itemx set print type typedefs on
15228@itemx set print type typedefs off
15229
15230Normally, when @value{GDBN} prints a class, it displays any typedefs
15231defined in that class. You can control this behavior either by
15232passing the appropriate flag to @code{ptype}, or using @command{set
15233print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
15234display the typedef definitions; this is the default. Specifying
15235@code{off} will cause @value{GDBN} to omit the typedef definitions.
15236Note that this controls whether the typedef definition itself is
15237printed, not whether typedef names are substituted when printing other
15238types.
15239
15240@kindex show print type typedefs
15241@item show print type typedefs
15242This command shows the current setting of typedef display when
15243printing classes.
15244
c906108c 15245@kindex info address
b37052ae 15246@cindex address of a symbol
c906108c
SS
15247@item info address @var{symbol}
15248Describe where the data for @var{symbol} is stored. For a register
15249variable, this says which register it is kept in. For a non-register
15250local variable, this prints the stack-frame offset at which the variable
15251is always stored.
15252
15253Note the contrast with @samp{print &@var{symbol}}, which does not work
15254at all for a register variable, and for a stack local variable prints
15255the exact address of the current instantiation of the variable.
15256
3d67e040 15257@kindex info symbol
b37052ae 15258@cindex symbol from address
9c16f35a 15259@cindex closest symbol and offset for an address
3d67e040
EZ
15260@item info symbol @var{addr}
15261Print the name of a symbol which is stored at the address @var{addr}.
15262If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
15263nearest symbol and an offset from it:
15264
474c8240 15265@smallexample
3d67e040
EZ
15266(@value{GDBP}) info symbol 0x54320
15267_initialize_vx + 396 in section .text
474c8240 15268@end smallexample
3d67e040
EZ
15269
15270@noindent
15271This is the opposite of the @code{info address} command. You can use
15272it to find out the name of a variable or a function given its address.
15273
c14c28ba
PP
15274For dynamically linked executables, the name of executable or shared
15275library containing the symbol is also printed:
15276
15277@smallexample
15278(@value{GDBP}) info symbol 0x400225
15279_start + 5 in section .text of /tmp/a.out
15280(@value{GDBP}) info symbol 0x2aaaac2811cf
15281__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
15282@end smallexample
15283
c906108c 15284@kindex whatis
53342f27 15285@item whatis[/@var{flags}] [@var{arg}]
177bc839
JK
15286Print the data type of @var{arg}, which can be either an expression
15287or a name of a data type. With no argument, print the data type of
15288@code{$}, the last value in the value history.
15289
15290If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
15291is not actually evaluated, and any side-effecting operations (such as
15292assignments or function calls) inside it do not take place.
15293
15294If @var{arg} is a variable or an expression, @code{whatis} prints its
15295literal type as it is used in the source code. If the type was
15296defined using a @code{typedef}, @code{whatis} will @emph{not} print
15297the data type underlying the @code{typedef}. If the type of the
15298variable or the expression is a compound data type, such as
15299@code{struct} or @code{class}, @code{whatis} never prints their
15300fields or methods. It just prints the @code{struct}/@code{class}
15301name (a.k.a.@: its @dfn{tag}). If you want to see the members of
15302such a compound data type, use @code{ptype}.
15303
15304If @var{arg} is a type name that was defined using @code{typedef},
15305@code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
15306Unrolling means that @code{whatis} will show the underlying type used
15307in the @code{typedef} declaration of @var{arg}. However, if that
15308underlying type is also a @code{typedef}, @code{whatis} will not
15309unroll it.
15310
15311For C code, the type names may also have the form @samp{class
15312@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
15313@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 15314
53342f27
TT
15315@var{flags} can be used to modify how the type is displayed.
15316Available flags are:
15317
15318@table @code
15319@item r
15320Display in ``raw'' form. Normally, @value{GDBN} substitutes template
15321parameters and typedefs defined in a class when printing the class'
15322members. The @code{/r} flag disables this.
15323
15324@item m
15325Do not print methods defined in the class.
15326
15327@item M
15328Print methods defined in the class. This is the default, but the flag
15329exists in case you change the default with @command{set print type methods}.
15330
15331@item t
15332Do not print typedefs defined in the class. Note that this controls
15333whether the typedef definition itself is printed, not whether typedef
15334names are substituted when printing other types.
15335
15336@item T
15337Print typedefs defined in the class. This is the default, but the flag
15338exists in case you change the default with @command{set print type typedefs}.
15339@end table
15340
c906108c 15341@kindex ptype
53342f27 15342@item ptype[/@var{flags}] [@var{arg}]
62f3a2ba
FF
15343@code{ptype} accepts the same arguments as @code{whatis}, but prints a
15344detailed description of the type, instead of just the name of the type.
15345@xref{Expressions, ,Expressions}.
c906108c 15346
177bc839
JK
15347Contrary to @code{whatis}, @code{ptype} always unrolls any
15348@code{typedef}s in its argument declaration, whether the argument is
15349a variable, expression, or a data type. This means that @code{ptype}
15350of a variable or an expression will not print literally its type as
15351present in the source code---use @code{whatis} for that. @code{typedef}s at
15352the pointer or reference targets are also unrolled. Only @code{typedef}s of
15353fields, methods and inner @code{class typedef}s of @code{struct}s,
15354@code{class}es and @code{union}s are not unrolled even with @code{ptype}.
15355
c906108c
SS
15356For example, for this variable declaration:
15357
474c8240 15358@smallexample
177bc839
JK
15359typedef double real_t;
15360struct complex @{ real_t real; double imag; @};
15361typedef struct complex complex_t;
15362complex_t var;
15363real_t *real_pointer_var;
474c8240 15364@end smallexample
c906108c
SS
15365
15366@noindent
15367the two commands give this output:
15368
474c8240 15369@smallexample
c906108c 15370@group
177bc839
JK
15371(@value{GDBP}) whatis var
15372type = complex_t
15373(@value{GDBP}) ptype var
15374type = struct complex @{
15375 real_t real;
15376 double imag;
15377@}
15378(@value{GDBP}) whatis complex_t
15379type = struct complex
15380(@value{GDBP}) whatis struct complex
c906108c 15381type = struct complex
177bc839 15382(@value{GDBP}) ptype struct complex
c906108c 15383type = struct complex @{
177bc839 15384 real_t real;
c906108c
SS
15385 double imag;
15386@}
177bc839
JK
15387(@value{GDBP}) whatis real_pointer_var
15388type = real_t *
15389(@value{GDBP}) ptype real_pointer_var
15390type = double *
c906108c 15391@end group
474c8240 15392@end smallexample
c906108c
SS
15393
15394@noindent
15395As with @code{whatis}, using @code{ptype} without an argument refers to
15396the type of @code{$}, the last value in the value history.
15397
ab1adacd
EZ
15398@cindex incomplete type
15399Sometimes, programs use opaque data types or incomplete specifications
15400of complex data structure. If the debug information included in the
15401program does not allow @value{GDBN} to display a full declaration of
15402the data type, it will say @samp{<incomplete type>}. For example,
15403given these declarations:
15404
15405@smallexample
15406 struct foo;
15407 struct foo *fooptr;
15408@end smallexample
15409
15410@noindent
15411but no definition for @code{struct foo} itself, @value{GDBN} will say:
15412
15413@smallexample
ddb50cd7 15414 (@value{GDBP}) ptype foo
ab1adacd
EZ
15415 $1 = <incomplete type>
15416@end smallexample
15417
15418@noindent
15419``Incomplete type'' is C terminology for data types that are not
15420completely specified.
15421
c906108c
SS
15422@kindex info types
15423@item info types @var{regexp}
15424@itemx info types
09d4efe1
EZ
15425Print a brief description of all types whose names match the regular
15426expression @var{regexp} (or all types in your program, if you supply
15427no argument). Each complete typename is matched as though it were a
15428complete line; thus, @samp{i type value} gives information on all
15429types in your program whose names include the string @code{value}, but
15430@samp{i type ^value$} gives information only on types whose complete
15431name is @code{value}.
c906108c
SS
15432
15433This command differs from @code{ptype} in two ways: first, like
15434@code{whatis}, it does not print a detailed description; second, it
15435lists all source files where a type is defined.
15436
18a9fc12
TT
15437@kindex info type-printers
15438@item info type-printers
15439Versions of @value{GDBN} that ship with Python scripting enabled may
15440have ``type printers'' available. When using @command{ptype} or
15441@command{whatis}, these printers are consulted when the name of a type
15442is needed. @xref{Type Printing API}, for more information on writing
15443type printers.
15444
15445@code{info type-printers} displays all the available type printers.
15446
15447@kindex enable type-printer
15448@kindex disable type-printer
15449@item enable type-printer @var{name}@dots{}
15450@item disable type-printer @var{name}@dots{}
15451These commands can be used to enable or disable type printers.
15452
b37052ae
EZ
15453@kindex info scope
15454@cindex local variables
09d4efe1 15455@item info scope @var{location}
b37052ae 15456List all the variables local to a particular scope. This command
09d4efe1
EZ
15457accepts a @var{location} argument---a function name, a source line, or
15458an address preceded by a @samp{*}, and prints all the variables local
2a25a5ba
EZ
15459to the scope defined by that location. (@xref{Specify Location}, for
15460details about supported forms of @var{location}.) For example:
b37052ae
EZ
15461
15462@smallexample
15463(@value{GDBP}) @b{info scope command_line_handler}
15464Scope for command_line_handler:
15465Symbol rl is an argument at stack/frame offset 8, length 4.
15466Symbol linebuffer is in static storage at address 0x150a18, length 4.
15467Symbol linelength is in static storage at address 0x150a1c, length 4.
15468Symbol p is a local variable in register $esi, length 4.
15469Symbol p1 is a local variable in register $ebx, length 4.
15470Symbol nline is a local variable in register $edx, length 4.
15471Symbol repeat is a local variable at frame offset -8, length 4.
15472@end smallexample
15473
f5c37c66
EZ
15474@noindent
15475This command is especially useful for determining what data to collect
15476during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
15477collect}.
15478
c906108c
SS
15479@kindex info source
15480@item info source
919d772c
JB
15481Show information about the current source file---that is, the source file for
15482the function containing the current point of execution:
15483@itemize @bullet
15484@item
15485the name of the source file, and the directory containing it,
15486@item
15487the directory it was compiled in,
15488@item
15489its length, in lines,
15490@item
15491which programming language it is written in,
15492@item
15493whether the executable includes debugging information for that file, and
15494if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
15495@item
15496whether the debugging information includes information about
15497preprocessor macros.
15498@end itemize
15499
c906108c
SS
15500
15501@kindex info sources
15502@item info sources
15503Print the names of all source files in your program for which there is
15504debugging information, organized into two lists: files whose symbols
15505have already been read, and files whose symbols will be read when needed.
15506
15507@kindex info functions
15508@item info functions
15509Print the names and data types of all defined functions.
15510
15511@item info functions @var{regexp}
15512Print the names and data types of all defined functions
15513whose names contain a match for regular expression @var{regexp}.
15514Thus, @samp{info fun step} finds all functions whose names
15515include @code{step}; @samp{info fun ^step} finds those whose names
b383017d 15516start with @code{step}. If a function name contains characters
c1468174 15517that conflict with the regular expression language (e.g.@:
1c5dfdad 15518@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
15519
15520@kindex info variables
15521@item info variables
0fe7935b 15522Print the names and data types of all variables that are defined
6ca652b0 15523outside of functions (i.e.@: excluding local variables).
c906108c
SS
15524
15525@item info variables @var{regexp}
15526Print the names and data types of all variables (except for local
15527variables) whose names contain a match for regular expression
15528@var{regexp}.
15529
b37303ee 15530@kindex info classes
721c2651 15531@cindex Objective-C, classes and selectors
b37303ee
AF
15532@item info classes
15533@itemx info classes @var{regexp}
15534Display all Objective-C classes in your program, or
15535(with the @var{regexp} argument) all those matching a particular regular
15536expression.
15537
15538@kindex info selectors
15539@item info selectors
15540@itemx info selectors @var{regexp}
15541Display all Objective-C selectors in your program, or
15542(with the @var{regexp} argument) all those matching a particular regular
15543expression.
15544
c906108c
SS
15545@ignore
15546This was never implemented.
15547@kindex info methods
15548@item info methods
15549@itemx info methods @var{regexp}
15550The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
15551methods within C@t{++} program, or (with the @var{regexp} argument) a
15552specific set of methods found in the various C@t{++} classes. Many
15553C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
15554from the @code{ptype} command can be overwhelming and hard to use. The
15555@code{info-methods} command filters the methods, printing only those
15556which match the regular-expression @var{regexp}.
15557@end ignore
15558
9c16f35a 15559@cindex opaque data types
c906108c
SS
15560@kindex set opaque-type-resolution
15561@item set opaque-type-resolution on
15562Tell @value{GDBN} to resolve opaque types. An opaque type is a type
15563declared as a pointer to a @code{struct}, @code{class}, or
15564@code{union}---for example, @code{struct MyType *}---that is used in one
15565source file although the full declaration of @code{struct MyType} is in
15566another source file. The default is on.
15567
15568A change in the setting of this subcommand will not take effect until
15569the next time symbols for a file are loaded.
15570
15571@item set opaque-type-resolution off
15572Tell @value{GDBN} not to resolve opaque types. In this case, the type
15573is printed as follows:
15574@smallexample
15575@{<no data fields>@}
15576@end smallexample
15577
15578@kindex show opaque-type-resolution
15579@item show opaque-type-resolution
15580Show whether opaque types are resolved or not.
c906108c
SS
15581
15582@kindex maint print symbols
15583@cindex symbol dump
15584@kindex maint print psymbols
15585@cindex partial symbol dump
15586@item maint print symbols @var{filename}
15587@itemx maint print psymbols @var{filename}
15588@itemx maint print msymbols @var{filename}
15589Write a dump of debugging symbol data into the file @var{filename}.
15590These commands are used to debug the @value{GDBN} symbol-reading code. Only
15591symbols with debugging data are included. If you use @samp{maint print
15592symbols}, @value{GDBN} includes all the symbols for which it has already
15593collected full details: that is, @var{filename} reflects symbols for
15594only those files whose symbols @value{GDBN} has read. You can use the
15595command @code{info sources} to find out which files these are. If you
15596use @samp{maint print psymbols} instead, the dump shows information about
15597symbols that @value{GDBN} only knows partially---that is, symbols defined in
15598files that @value{GDBN} has skimmed, but not yet read completely. Finally,
15599@samp{maint print msymbols} dumps just the minimal symbol information
15600required for each object file from which @value{GDBN} has read some symbols.
79a6e687 15601@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 15602@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 15603
5e7b2f39
JB
15604@kindex maint info symtabs
15605@kindex maint info psymtabs
44ea7b70
JB
15606@cindex listing @value{GDBN}'s internal symbol tables
15607@cindex symbol tables, listing @value{GDBN}'s internal
15608@cindex full symbol tables, listing @value{GDBN}'s internal
15609@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
15610@item maint info symtabs @r{[} @var{regexp} @r{]}
15611@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
15612
15613List the @code{struct symtab} or @code{struct partial_symtab}
15614structures whose names match @var{regexp}. If @var{regexp} is not
15615given, list them all. The output includes expressions which you can
15616copy into a @value{GDBN} debugging this one to examine a particular
15617structure in more detail. For example:
15618
15619@smallexample
5e7b2f39 15620(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
15621@{ objfile /home/gnu/build/gdb/gdb
15622 ((struct objfile *) 0x82e69d0)
b383017d 15623 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
15624 ((struct partial_symtab *) 0x8474b10)
15625 readin no
15626 fullname (null)
15627 text addresses 0x814d3c8 -- 0x8158074
15628 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
15629 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
15630 dependencies (none)
15631 @}
15632@}
5e7b2f39 15633(@value{GDBP}) maint info symtabs
44ea7b70
JB
15634(@value{GDBP})
15635@end smallexample
15636@noindent
15637We see that there is one partial symbol table whose filename contains
15638the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
15639and we see that @value{GDBN} has not read in any symtabs yet at all.
15640If we set a breakpoint on a function, that will cause @value{GDBN} to
15641read the symtab for the compilation unit containing that function:
15642
15643@smallexample
15644(@value{GDBP}) break dwarf2_psymtab_to_symtab
15645Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
15646line 1574.
5e7b2f39 15647(@value{GDBP}) maint info symtabs
b383017d 15648@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 15649 ((struct objfile *) 0x82e69d0)
b383017d 15650 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
15651 ((struct symtab *) 0x86c1f38)
15652 dirname (null)
15653 fullname (null)
15654 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 15655 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
15656 debugformat DWARF 2
15657 @}
15658@}
b383017d 15659(@value{GDBP})
44ea7b70 15660@end smallexample
c906108c
SS
15661@end table
15662
44ea7b70 15663
6d2ebf8b 15664@node Altering
c906108c
SS
15665@chapter Altering Execution
15666
15667Once you think you have found an error in your program, you might want to
15668find out for certain whether correcting the apparent error would lead to
15669correct results in the rest of the run. You can find the answer by
15670experiment, using the @value{GDBN} features for altering execution of the
15671program.
15672
15673For example, you can store new values into variables or memory
7a292a7a
SS
15674locations, give your program a signal, restart it at a different
15675address, or even return prematurely from a function.
c906108c
SS
15676
15677@menu
15678* Assignment:: Assignment to variables
15679* Jumping:: Continuing at a different address
c906108c 15680* Signaling:: Giving your program a signal
c906108c
SS
15681* Returning:: Returning from a function
15682* Calling:: Calling your program's functions
15683* Patching:: Patching your program
15684@end menu
15685
6d2ebf8b 15686@node Assignment
79a6e687 15687@section Assignment to Variables
c906108c
SS
15688
15689@cindex assignment
15690@cindex setting variables
15691To alter the value of a variable, evaluate an assignment expression.
15692@xref{Expressions, ,Expressions}. For example,
15693
474c8240 15694@smallexample
c906108c 15695print x=4
474c8240 15696@end smallexample
c906108c
SS
15697
15698@noindent
15699stores the value 4 into the variable @code{x}, and then prints the
5d161b24 15700value of the assignment expression (which is 4).
c906108c
SS
15701@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
15702information on operators in supported languages.
c906108c
SS
15703
15704@kindex set variable
15705@cindex variables, setting
15706If you are not interested in seeing the value of the assignment, use the
15707@code{set} command instead of the @code{print} command. @code{set} is
15708really the same as @code{print} except that the expression's value is
15709not printed and is not put in the value history (@pxref{Value History,
79a6e687 15710,Value History}). The expression is evaluated only for its effects.
c906108c 15711
c906108c
SS
15712If the beginning of the argument string of the @code{set} command
15713appears identical to a @code{set} subcommand, use the @code{set
15714variable} command instead of just @code{set}. This command is identical
15715to @code{set} except for its lack of subcommands. For example, if your
15716program has a variable @code{width}, you get an error if you try to set
15717a new value with just @samp{set width=13}, because @value{GDBN} has the
15718command @code{set width}:
15719
474c8240 15720@smallexample
c906108c
SS
15721(@value{GDBP}) whatis width
15722type = double
15723(@value{GDBP}) p width
15724$4 = 13
15725(@value{GDBP}) set width=47
15726Invalid syntax in expression.
474c8240 15727@end smallexample
c906108c
SS
15728
15729@noindent
15730The invalid expression, of course, is @samp{=47}. In
15731order to actually set the program's variable @code{width}, use
15732
474c8240 15733@smallexample
c906108c 15734(@value{GDBP}) set var width=47
474c8240 15735@end smallexample
53a5351d 15736
c906108c
SS
15737Because the @code{set} command has many subcommands that can conflict
15738with the names of program variables, it is a good idea to use the
15739@code{set variable} command instead of just @code{set}. For example, if
15740your program has a variable @code{g}, you run into problems if you try
15741to set a new value with just @samp{set g=4}, because @value{GDBN} has
15742the command @code{set gnutarget}, abbreviated @code{set g}:
15743
474c8240 15744@smallexample
c906108c
SS
15745@group
15746(@value{GDBP}) whatis g
15747type = double
15748(@value{GDBP}) p g
15749$1 = 1
15750(@value{GDBP}) set g=4
2df3850c 15751(@value{GDBP}) p g
c906108c
SS
15752$2 = 1
15753(@value{GDBP}) r
15754The program being debugged has been started already.
15755Start it from the beginning? (y or n) y
15756Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
15757"/home/smith/cc_progs/a.out": can't open to read symbols:
15758 Invalid bfd target.
c906108c
SS
15759(@value{GDBP}) show g
15760The current BFD target is "=4".
15761@end group
474c8240 15762@end smallexample
c906108c
SS
15763
15764@noindent
15765The program variable @code{g} did not change, and you silently set the
15766@code{gnutarget} to an invalid value. In order to set the variable
15767@code{g}, use
15768
474c8240 15769@smallexample
c906108c 15770(@value{GDBP}) set var g=4
474c8240 15771@end smallexample
c906108c
SS
15772
15773@value{GDBN} allows more implicit conversions in assignments than C; you can
15774freely store an integer value into a pointer variable or vice versa,
15775and you can convert any structure to any other structure that is the
15776same length or shorter.
15777@comment FIXME: how do structs align/pad in these conversions?
15778@comment /doc@cygnus.com 18dec1990
15779
15780To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
15781construct to generate a value of specified type at a specified address
15782(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
15783to memory location @code{0x83040} as an integer (which implies a certain size
15784and representation in memory), and
15785
474c8240 15786@smallexample
c906108c 15787set @{int@}0x83040 = 4
474c8240 15788@end smallexample
c906108c
SS
15789
15790@noindent
15791stores the value 4 into that memory location.
15792
6d2ebf8b 15793@node Jumping
79a6e687 15794@section Continuing at a Different Address
c906108c
SS
15795
15796Ordinarily, when you continue your program, you do so at the place where
15797it stopped, with the @code{continue} command. You can instead continue at
15798an address of your own choosing, with the following commands:
15799
15800@table @code
15801@kindex jump
c1d780c2 15802@kindex j @r{(@code{jump})}
c906108c 15803@item jump @var{linespec}
c1d780c2 15804@itemx j @var{linespec}
2a25a5ba 15805@itemx jump @var{location}
c1d780c2 15806@itemx j @var{location}
2a25a5ba
EZ
15807Resume execution at line @var{linespec} or at address given by
15808@var{location}. Execution stops again immediately if there is a
15809breakpoint there. @xref{Specify Location}, for a description of the
15810different forms of @var{linespec} and @var{location}. It is common
15811practice to use the @code{tbreak} command in conjunction with
15812@code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
c906108c
SS
15813
15814The @code{jump} command does not change the current stack frame, or
15815the stack pointer, or the contents of any memory location or any
15816register other than the program counter. If line @var{linespec} is in
15817a different function from the one currently executing, the results may
15818be bizarre if the two functions expect different patterns of arguments or
15819of local variables. For this reason, the @code{jump} command requests
15820confirmation if the specified line is not in the function currently
15821executing. However, even bizarre results are predictable if you are
15822well acquainted with the machine-language code of your program.
c906108c
SS
15823@end table
15824
c906108c 15825@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
15826On many systems, you can get much the same effect as the @code{jump}
15827command by storing a new value into the register @code{$pc}. The
15828difference is that this does not start your program running; it only
15829changes the address of where it @emph{will} run when you continue. For
15830example,
c906108c 15831
474c8240 15832@smallexample
c906108c 15833set $pc = 0x485
474c8240 15834@end smallexample
c906108c
SS
15835
15836@noindent
15837makes the next @code{continue} command or stepping command execute at
15838address @code{0x485}, rather than at the address where your program stopped.
79a6e687 15839@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
15840
15841The most common occasion to use the @code{jump} command is to back
15842up---perhaps with more breakpoints set---over a portion of a program
15843that has already executed, in order to examine its execution in more
15844detail.
15845
c906108c 15846@c @group
6d2ebf8b 15847@node Signaling
79a6e687 15848@section Giving your Program a Signal
9c16f35a 15849@cindex deliver a signal to a program
c906108c
SS
15850
15851@table @code
15852@kindex signal
15853@item signal @var{signal}
15854Resume execution where your program stopped, but immediately give it the
15855signal @var{signal}. @var{signal} can be the name or the number of a
15856signal. For example, on many systems @code{signal 2} and @code{signal
15857SIGINT} are both ways of sending an interrupt signal.
15858
15859Alternatively, if @var{signal} is zero, continue execution without
15860giving a signal. This is useful when your program stopped on account of
ae606bee 15861a signal and would ordinarily see the signal when resumed with the
c906108c
SS
15862@code{continue} command; @samp{signal 0} causes it to resume without a
15863signal.
15864
15865@code{signal} does not repeat when you press @key{RET} a second time
15866after executing the command.
15867@end table
15868@c @end group
15869
15870Invoking the @code{signal} command is not the same as invoking the
15871@code{kill} utility from the shell. Sending a signal with @code{kill}
15872causes @value{GDBN} to decide what to do with the signal depending on
15873the signal handling tables (@pxref{Signals}). The @code{signal} command
15874passes the signal directly to your program.
15875
c906108c 15876
6d2ebf8b 15877@node Returning
79a6e687 15878@section Returning from a Function
c906108c
SS
15879
15880@table @code
15881@cindex returning from a function
15882@kindex return
15883@item return
15884@itemx return @var{expression}
15885You can cancel execution of a function call with the @code{return}
15886command. If you give an
15887@var{expression} argument, its value is used as the function's return
15888value.
15889@end table
15890
15891When you use @code{return}, @value{GDBN} discards the selected stack frame
15892(and all frames within it). You can think of this as making the
15893discarded frame return prematurely. If you wish to specify a value to
15894be returned, give that value as the argument to @code{return}.
15895
15896This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 15897Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
15898innermost remaining frame. That frame becomes selected. The
15899specified value is stored in the registers used for returning values
15900of functions.
15901
15902The @code{return} command does not resume execution; it leaves the
15903program stopped in the state that would exist if the function had just
15904returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 15905and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
15906selected stack frame returns naturally.
15907
61ff14c6
JK
15908@value{GDBN} needs to know how the @var{expression} argument should be set for
15909the inferior. The concrete registers assignment depends on the OS ABI and the
15910type being returned by the selected stack frame. For example it is common for
15911OS ABI to return floating point values in FPU registers while integer values in
15912CPU registers. Still some ABIs return even floating point values in CPU
15913registers. Larger integer widths (such as @code{long long int}) also have
15914specific placement rules. @value{GDBN} already knows the OS ABI from its
15915current target so it needs to find out also the type being returned to make the
15916assignment into the right register(s).
15917
15918Normally, the selected stack frame has debug info. @value{GDBN} will always
15919use the debug info instead of the implicit type of @var{expression} when the
15920debug info is available. For example, if you type @kbd{return -1}, and the
15921function in the current stack frame is declared to return a @code{long long
15922int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
15923into a @code{long long int}:
15924
15925@smallexample
15926Breakpoint 1, func () at gdb.base/return-nodebug.c:29
1592729 return 31;
15928(@value{GDBP}) return -1
15929Make func return now? (y or n) y
15930#0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
1593143 printf ("result=%lld\n", func ());
15932(@value{GDBP})
15933@end smallexample
15934
15935However, if the selected stack frame does not have a debug info, e.g., if the
15936function was compiled without debug info, @value{GDBN} has to find out the type
15937to return from user. Specifying a different type by mistake may set the value
15938in different inferior registers than the caller code expects. For example,
15939typing @kbd{return -1} with its implicit type @code{int} would set only a part
15940of a @code{long long int} result for a debug info less function (on 32-bit
15941architectures). Therefore the user is required to specify the return type by
15942an appropriate cast explicitly:
15943
15944@smallexample
15945Breakpoint 2, 0x0040050b in func ()
15946(@value{GDBP}) return -1
15947Return value type not available for selected stack frame.
15948Please use an explicit cast of the value to return.
15949(@value{GDBP}) return (long long int) -1
15950Make selected stack frame return now? (y or n) y
15951#0 0x00400526 in main ()
15952(@value{GDBP})
15953@end smallexample
15954
6d2ebf8b 15955@node Calling
79a6e687 15956@section Calling Program Functions
c906108c 15957
f8568604 15958@table @code
c906108c 15959@cindex calling functions
f8568604
EZ
15960@cindex inferior functions, calling
15961@item print @var{expr}
d3e8051b 15962Evaluate the expression @var{expr} and display the resulting value.
f8568604
EZ
15963@var{expr} may include calls to functions in the program being
15964debugged.
15965
c906108c 15966@kindex call
c906108c
SS
15967@item call @var{expr}
15968Evaluate the expression @var{expr} without displaying @code{void}
15969returned values.
c906108c
SS
15970
15971You can use this variant of the @code{print} command if you want to
f8568604
EZ
15972execute a function from your program that does not return anything
15973(a.k.a.@: @dfn{a void function}), but without cluttering the output
15974with @code{void} returned values that @value{GDBN} will otherwise
15975print. If the result is not void, it is printed and saved in the
15976value history.
15977@end table
15978
9c16f35a
EZ
15979It is possible for the function you call via the @code{print} or
15980@code{call} command to generate a signal (e.g., if there's a bug in
15981the function, or if you passed it incorrect arguments). What happens
15982in that case is controlled by the @code{set unwindonsignal} command.
15983
7cd1089b
PM
15984Similarly, with a C@t{++} program it is possible for the function you
15985call via the @code{print} or @code{call} command to generate an
15986exception that is not handled due to the constraints of the dummy
15987frame. In this case, any exception that is raised in the frame, but has
15988an out-of-frame exception handler will not be found. GDB builds a
15989dummy-frame for the inferior function call, and the unwinder cannot
15990seek for exception handlers outside of this dummy-frame. What happens
15991in that case is controlled by the
15992@code{set unwind-on-terminating-exception} command.
15993
9c16f35a
EZ
15994@table @code
15995@item set unwindonsignal
15996@kindex set unwindonsignal
15997@cindex unwind stack in called functions
15998@cindex call dummy stack unwinding
15999Set unwinding of the stack if a signal is received while in a function
16000that @value{GDBN} called in the program being debugged. If set to on,
16001@value{GDBN} unwinds the stack it created for the call and restores
16002the context to what it was before the call. If set to off (the
16003default), @value{GDBN} stops in the frame where the signal was
16004received.
16005
16006@item show unwindonsignal
16007@kindex show unwindonsignal
16008Show the current setting of stack unwinding in the functions called by
16009@value{GDBN}.
7cd1089b
PM
16010
16011@item set unwind-on-terminating-exception
16012@kindex set unwind-on-terminating-exception
16013@cindex unwind stack in called functions with unhandled exceptions
16014@cindex call dummy stack unwinding on unhandled exception.
16015Set unwinding of the stack if a C@t{++} exception is raised, but left
16016unhandled while in a function that @value{GDBN} called in the program being
16017debugged. If set to on (the default), @value{GDBN} unwinds the stack
16018it created for the call and restores the context to what it was before
16019the call. If set to off, @value{GDBN} the exception is delivered to
16020the default C@t{++} exception handler and the inferior terminated.
16021
16022@item show unwind-on-terminating-exception
16023@kindex show unwind-on-terminating-exception
16024Show the current setting of stack unwinding in the functions called by
16025@value{GDBN}.
16026
9c16f35a
EZ
16027@end table
16028
f8568604
EZ
16029@cindex weak alias functions
16030Sometimes, a function you wish to call is actually a @dfn{weak alias}
16031for another function. In such case, @value{GDBN} might not pick up
16032the type information, including the types of the function arguments,
16033which causes @value{GDBN} to call the inferior function incorrectly.
16034As a result, the called function will function erroneously and may
16035even crash. A solution to that is to use the name of the aliased
16036function instead.
c906108c 16037
6d2ebf8b 16038@node Patching
79a6e687 16039@section Patching Programs
7a292a7a 16040
c906108c
SS
16041@cindex patching binaries
16042@cindex writing into executables
c906108c 16043@cindex writing into corefiles
c906108c 16044
7a292a7a
SS
16045By default, @value{GDBN} opens the file containing your program's
16046executable code (or the corefile) read-only. This prevents accidental
16047alterations to machine code; but it also prevents you from intentionally
16048patching your program's binary.
c906108c
SS
16049
16050If you'd like to be able to patch the binary, you can specify that
16051explicitly with the @code{set write} command. For example, you might
16052want to turn on internal debugging flags, or even to make emergency
16053repairs.
16054
16055@table @code
16056@kindex set write
16057@item set write on
16058@itemx set write off
7a292a7a 16059If you specify @samp{set write on}, @value{GDBN} opens executable and
20924a55 16060core files for both reading and writing; if you specify @kbd{set write
c906108c
SS
16061off} (the default), @value{GDBN} opens them read-only.
16062
16063If you have already loaded a file, you must load it again (using the
7a292a7a
SS
16064@code{exec-file} or @code{core-file} command) after changing @code{set
16065write}, for your new setting to take effect.
c906108c
SS
16066
16067@item show write
16068@kindex show write
7a292a7a
SS
16069Display whether executable files and core files are opened for writing
16070as well as reading.
c906108c
SS
16071@end table
16072
6d2ebf8b 16073@node GDB Files
c906108c
SS
16074@chapter @value{GDBN} Files
16075
7a292a7a
SS
16076@value{GDBN} needs to know the file name of the program to be debugged,
16077both in order to read its symbol table and in order to start your
16078program. To debug a core dump of a previous run, you must also tell
16079@value{GDBN} the name of the core dump file.
c906108c
SS
16080
16081@menu
16082* Files:: Commands to specify files
5b5d99cf 16083* Separate Debug Files:: Debugging information in separate files
608e2dbb 16084* MiniDebugInfo:: Debugging information in a special section
9291a0cd 16085* Index Files:: Index files speed up GDB
c906108c 16086* Symbol Errors:: Errors reading symbol files
b14b1491 16087* Data Files:: GDB data files
c906108c
SS
16088@end menu
16089
6d2ebf8b 16090@node Files
79a6e687 16091@section Commands to Specify Files
c906108c 16092
7a292a7a 16093@cindex symbol table
c906108c 16094@cindex core dump file
7a292a7a
SS
16095
16096You may want to specify executable and core dump file names. The usual
16097way to do this is at start-up time, using the arguments to
16098@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
16099Out of @value{GDBN}}).
c906108c
SS
16100
16101Occasionally it is necessary to change to a different file during a
397ca115
EZ
16102@value{GDBN} session. Or you may run @value{GDBN} and forget to
16103specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
16104via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
16105Program}). In these situations the @value{GDBN} commands to specify
0869d01b 16106new files are useful.
c906108c
SS
16107
16108@table @code
16109@cindex executable file
16110@kindex file
16111@item file @var{filename}
16112Use @var{filename} as the program to be debugged. It is read for its
16113symbols and for the contents of pure memory. It is also the program
16114executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
16115directory and the file is not found in the @value{GDBN} working directory,
16116@value{GDBN} uses the environment variable @code{PATH} as a list of
16117directories to search, just as the shell does when looking for a program
16118to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
16119and your program, using the @code{path} command.
16120
fc8be69e
EZ
16121@cindex unlinked object files
16122@cindex patching object files
16123You can load unlinked object @file{.o} files into @value{GDBN} using
16124the @code{file} command. You will not be able to ``run'' an object
16125file, but you can disassemble functions and inspect variables. Also,
16126if the underlying BFD functionality supports it, you could use
16127@kbd{gdb -write} to patch object files using this technique. Note
16128that @value{GDBN} can neither interpret nor modify relocations in this
16129case, so branches and some initialized variables will appear to go to
16130the wrong place. But this feature is still handy from time to time.
16131
c906108c
SS
16132@item file
16133@code{file} with no argument makes @value{GDBN} discard any information it
16134has on both executable file and the symbol table.
16135
16136@kindex exec-file
16137@item exec-file @r{[} @var{filename} @r{]}
16138Specify that the program to be run (but not the symbol table) is found
16139in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
16140if necessary to locate your program. Omitting @var{filename} means to
16141discard information on the executable file.
16142
16143@kindex symbol-file
16144@item symbol-file @r{[} @var{filename} @r{]}
16145Read symbol table information from file @var{filename}. @code{PATH} is
16146searched when necessary. Use the @code{file} command to get both symbol
16147table and program to run from the same file.
16148
16149@code{symbol-file} with no argument clears out @value{GDBN} information on your
16150program's symbol table.
16151
ae5a43e0
DJ
16152The @code{symbol-file} command causes @value{GDBN} to forget the contents of
16153some breakpoints and auto-display expressions. This is because they may
16154contain pointers to the internal data recording symbols and data types,
16155which are part of the old symbol table data being discarded inside
16156@value{GDBN}.
c906108c
SS
16157
16158@code{symbol-file} does not repeat if you press @key{RET} again after
16159executing it once.
16160
16161When @value{GDBN} is configured for a particular environment, it
16162understands debugging information in whatever format is the standard
16163generated for that environment; you may use either a @sc{gnu} compiler, or
16164other compilers that adhere to the local conventions.
c906108c 16165Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 16166using @code{@value{NGCC}} you can generate debugging information for
c906108c 16167optimized code.
c906108c
SS
16168
16169For most kinds of object files, with the exception of old SVR3 systems
16170using COFF, the @code{symbol-file} command does not normally read the
16171symbol table in full right away. Instead, it scans the symbol table
16172quickly to find which source files and which symbols are present. The
16173details are read later, one source file at a time, as they are needed.
16174
16175The purpose of this two-stage reading strategy is to make @value{GDBN}
16176start up faster. For the most part, it is invisible except for
16177occasional pauses while the symbol table details for a particular source
16178file are being read. (The @code{set verbose} command can turn these
16179pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 16180Warnings and Messages}.)
c906108c 16181
c906108c
SS
16182We have not implemented the two-stage strategy for COFF yet. When the
16183symbol table is stored in COFF format, @code{symbol-file} reads the
16184symbol table data in full right away. Note that ``stabs-in-COFF''
16185still does the two-stage strategy, since the debug info is actually
16186in stabs format.
16187
16188@kindex readnow
16189@cindex reading symbols immediately
16190@cindex symbols, reading immediately
6ac33a4e
TT
16191@item symbol-file @r{[} -readnow @r{]} @var{filename}
16192@itemx file @r{[} -readnow @r{]} @var{filename}
c906108c
SS
16193You can override the @value{GDBN} two-stage strategy for reading symbol
16194tables by using the @samp{-readnow} option with any of the commands that
16195load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 16196entire symbol table available.
c906108c 16197
c906108c
SS
16198@c FIXME: for now no mention of directories, since this seems to be in
16199@c flux. 13mar1992 status is that in theory GDB would look either in
16200@c current dir or in same dir as myprog; but issues like competing
16201@c GDB's, or clutter in system dirs, mean that in practice right now
16202@c only current dir is used. FFish says maybe a special GDB hierarchy
16203@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
16204@c files.
16205
c906108c 16206@kindex core-file
09d4efe1 16207@item core-file @r{[}@var{filename}@r{]}
4644b6e3 16208@itemx core
c906108c
SS
16209Specify the whereabouts of a core dump file to be used as the ``contents
16210of memory''. Traditionally, core files contain only some parts of the
16211address space of the process that generated them; @value{GDBN} can access the
16212executable file itself for other parts.
16213
16214@code{core-file} with no argument specifies that no core file is
16215to be used.
16216
16217Note that the core file is ignored when your program is actually running
7a292a7a
SS
16218under @value{GDBN}. So, if you have been running your program and you
16219wish to debug a core file instead, you must kill the subprocess in which
16220the program is running. To do this, use the @code{kill} command
79a6e687 16221(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 16222
c906108c
SS
16223@kindex add-symbol-file
16224@cindex dynamic linking
16225@item add-symbol-file @var{filename} @var{address}
a94ab193 16226@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
24bdad53 16227@itemx add-symbol-file @var{filename} @var{address} -s @var{section} @var{address} @dots{}
96a2c332
SS
16228The @code{add-symbol-file} command reads additional symbol table
16229information from the file @var{filename}. You would use this command
16230when @var{filename} has been dynamically loaded (by some other means)
16231into the program that is running. @var{address} should be the memory
16232address at which the file has been loaded; @value{GDBN} cannot figure
d167840f 16233this out for itself. You can additionally specify an arbitrary number
24bdad53 16234of @samp{-s @var{section} @var{address}} pairs, to give an explicit
d167840f
EZ
16235section name and base address for that section. You can specify any
16236@var{address} as an expression.
c906108c
SS
16237
16238The symbol table of the file @var{filename} is added to the symbol table
16239originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
16240@code{add-symbol-file} command any number of times; the new symbol data
16241thus read keeps adding to the old. To discard all old symbol data
16242instead, use the @code{symbol-file} command without any arguments.
c906108c 16243
17d9d558
JB
16244@cindex relocatable object files, reading symbols from
16245@cindex object files, relocatable, reading symbols from
16246@cindex reading symbols from relocatable object files
16247@cindex symbols, reading from relocatable object files
16248@cindex @file{.o} files, reading symbols from
16249Although @var{filename} is typically a shared library file, an
16250executable file, or some other object file which has been fully
16251relocated for loading into a process, you can also load symbolic
16252information from relocatable @file{.o} files, as long as:
16253
16254@itemize @bullet
16255@item
16256the file's symbolic information refers only to linker symbols defined in
16257that file, not to symbols defined by other object files,
16258@item
16259every section the file's symbolic information refers to has actually
16260been loaded into the inferior, as it appears in the file, and
16261@item
16262you can determine the address at which every section was loaded, and
16263provide these to the @code{add-symbol-file} command.
16264@end itemize
16265
16266@noindent
16267Some embedded operating systems, like Sun Chorus and VxWorks, can load
16268relocatable files into an already running program; such systems
16269typically make the requirements above easy to meet. However, it's
16270important to recognize that many native systems use complex link
49efadf5 16271procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
16272assembly, for example) that make the requirements difficult to meet. In
16273general, one cannot assume that using @code{add-symbol-file} to read a
16274relocatable object file's symbolic information will have the same effect
16275as linking the relocatable object file into the program in the normal
16276way.
16277
c906108c
SS
16278@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
16279
c45da7e6
EZ
16280@kindex add-symbol-file-from-memory
16281@cindex @code{syscall DSO}
16282@cindex load symbols from memory
16283@item add-symbol-file-from-memory @var{address}
16284Load symbols from the given @var{address} in a dynamically loaded
16285object file whose image is mapped directly into the inferior's memory.
16286For example, the Linux kernel maps a @code{syscall DSO} into each
16287process's address space; this DSO provides kernel-specific code for
16288some system calls. The argument can be any expression whose
16289evaluation yields the address of the file's shared object file header.
16290For this command to work, you must have used @code{symbol-file} or
16291@code{exec-file} commands in advance.
16292
09d4efe1
EZ
16293@kindex add-shared-symbol-files
16294@kindex assf
16295@item add-shared-symbol-files @var{library-file}
16296@itemx assf @var{library-file}
16297The @code{add-shared-symbol-files} command can currently be used only
16298in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
16299alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
16300@value{GDBN} automatically looks for shared libraries, however if
16301@value{GDBN} does not find yours, you can invoke
16302@code{add-shared-symbol-files}. It takes one argument: the shared
16303library's file name. @code{assf} is a shorthand alias for
16304@code{add-shared-symbol-files}.
c906108c 16305
c906108c 16306@kindex section
09d4efe1
EZ
16307@item section @var{section} @var{addr}
16308The @code{section} command changes the base address of the named
16309@var{section} of the exec file to @var{addr}. This can be used if the
16310exec file does not contain section addresses, (such as in the
16311@code{a.out} format), or when the addresses specified in the file
16312itself are wrong. Each section must be changed separately. The
16313@code{info files} command, described below, lists all the sections and
16314their addresses.
c906108c
SS
16315
16316@kindex info files
16317@kindex info target
16318@item info files
16319@itemx info target
7a292a7a
SS
16320@code{info files} and @code{info target} are synonymous; both print the
16321current target (@pxref{Targets, ,Specifying a Debugging Target}),
16322including the names of the executable and core dump files currently in
16323use by @value{GDBN}, and the files from which symbols were loaded. The
16324command @code{help target} lists all possible targets rather than
16325current ones.
16326
fe95c787
MS
16327@kindex maint info sections
16328@item maint info sections
16329Another command that can give you extra information about program sections
16330is @code{maint info sections}. In addition to the section information
16331displayed by @code{info files}, this command displays the flags and file
16332offset of each section in the executable and core dump files. In addition,
16333@code{maint info sections} provides the following command options (which
16334may be arbitrarily combined):
16335
16336@table @code
16337@item ALLOBJ
16338Display sections for all loaded object files, including shared libraries.
16339@item @var{sections}
6600abed 16340Display info only for named @var{sections}.
fe95c787
MS
16341@item @var{section-flags}
16342Display info only for sections for which @var{section-flags} are true.
16343The section flags that @value{GDBN} currently knows about are:
16344@table @code
16345@item ALLOC
16346Section will have space allocated in the process when loaded.
16347Set for all sections except those containing debug information.
16348@item LOAD
16349Section will be loaded from the file into the child process memory.
16350Set for pre-initialized code and data, clear for @code{.bss} sections.
16351@item RELOC
16352Section needs to be relocated before loading.
16353@item READONLY
16354Section cannot be modified by the child process.
16355@item CODE
16356Section contains executable code only.
6600abed 16357@item DATA
fe95c787
MS
16358Section contains data only (no executable code).
16359@item ROM
16360Section will reside in ROM.
16361@item CONSTRUCTOR
16362Section contains data for constructor/destructor lists.
16363@item HAS_CONTENTS
16364Section is not empty.
16365@item NEVER_LOAD
16366An instruction to the linker to not output the section.
16367@item COFF_SHARED_LIBRARY
16368A notification to the linker that the section contains
16369COFF shared library information.
16370@item IS_COMMON
16371Section contains common symbols.
16372@end table
16373@end table
6763aef9 16374@kindex set trust-readonly-sections
9c16f35a 16375@cindex read-only sections
6763aef9
MS
16376@item set trust-readonly-sections on
16377Tell @value{GDBN} that readonly sections in your object file
6ca652b0 16378really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
16379In that case, @value{GDBN} can fetch values from these sections
16380out of the object file, rather than from the target program.
16381For some targets (notably embedded ones), this can be a significant
16382enhancement to debugging performance.
16383
16384The default is off.
16385
16386@item set trust-readonly-sections off
15110bc3 16387Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
16388the contents of the section might change while the program is running,
16389and must therefore be fetched from the target when needed.
9c16f35a
EZ
16390
16391@item show trust-readonly-sections
16392Show the current setting of trusting readonly sections.
c906108c
SS
16393@end table
16394
16395All file-specifying commands allow both absolute and relative file names
16396as arguments. @value{GDBN} always converts the file name to an absolute file
16397name and remembers it that way.
16398
c906108c 16399@cindex shared libraries
9cceb671
DJ
16400@anchor{Shared Libraries}
16401@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
9c16f35a 16402and IBM RS/6000 AIX shared libraries.
53a5351d 16403
9cceb671
DJ
16404On MS-Windows @value{GDBN} must be linked with the Expat library to support
16405shared libraries. @xref{Expat}.
16406
c906108c
SS
16407@value{GDBN} automatically loads symbol definitions from shared libraries
16408when you use the @code{run} command, or when you examine a core file.
16409(Before you issue the @code{run} command, @value{GDBN} does not understand
16410references to a function in a shared library, however---unless you are
16411debugging a core file).
53a5351d
JM
16412
16413On HP-UX, if the program loads a library explicitly, @value{GDBN}
16414automatically loads the symbols at the time of the @code{shl_load} call.
16415
c906108c
SS
16416@c FIXME: some @value{GDBN} release may permit some refs to undef
16417@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
16418@c FIXME...lib; check this from time to time when updating manual
16419
b7209cb4
FF
16420There are times, however, when you may wish to not automatically load
16421symbol definitions from shared libraries, such as when they are
16422particularly large or there are many of them.
16423
16424To control the automatic loading of shared library symbols, use the
16425commands:
16426
16427@table @code
16428@kindex set auto-solib-add
16429@item set auto-solib-add @var{mode}
16430If @var{mode} is @code{on}, symbols from all shared object libraries
16431will be loaded automatically when the inferior begins execution, you
16432attach to an independently started inferior, or when the dynamic linker
16433informs @value{GDBN} that a new library has been loaded. If @var{mode}
16434is @code{off}, symbols must be loaded manually, using the
16435@code{sharedlibrary} command. The default value is @code{on}.
16436
dcaf7c2c
EZ
16437@cindex memory used for symbol tables
16438If your program uses lots of shared libraries with debug info that
16439takes large amounts of memory, you can decrease the @value{GDBN}
16440memory footprint by preventing it from automatically loading the
16441symbols from shared libraries. To that end, type @kbd{set
16442auto-solib-add off} before running the inferior, then load each
16443library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 16444@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
16445the libraries whose symbols you want to be loaded.
16446
b7209cb4
FF
16447@kindex show auto-solib-add
16448@item show auto-solib-add
16449Display the current autoloading mode.
16450@end table
16451
c45da7e6 16452@cindex load shared library
b7209cb4
FF
16453To explicitly load shared library symbols, use the @code{sharedlibrary}
16454command:
16455
c906108c
SS
16456@table @code
16457@kindex info sharedlibrary
16458@kindex info share
55333a84
DE
16459@item info share @var{regex}
16460@itemx info sharedlibrary @var{regex}
16461Print the names of the shared libraries which are currently loaded
16462that match @var{regex}. If @var{regex} is omitted then print
16463all shared libraries that are loaded.
c906108c
SS
16464
16465@kindex sharedlibrary
16466@kindex share
16467@item sharedlibrary @var{regex}
16468@itemx share @var{regex}
c906108c
SS
16469Load shared object library symbols for files matching a
16470Unix regular expression.
16471As with files loaded automatically, it only loads shared libraries
16472required by your program for a core file or after typing @code{run}. If
16473@var{regex} is omitted all shared libraries required by your program are
16474loaded.
c45da7e6
EZ
16475
16476@item nosharedlibrary
16477@kindex nosharedlibrary
16478@cindex unload symbols from shared libraries
16479Unload all shared object library symbols. This discards all symbols
16480that have been loaded from all shared libraries. Symbols from shared
16481libraries that were loaded by explicit user requests are not
16482discarded.
c906108c
SS
16483@end table
16484
721c2651 16485Sometimes you may wish that @value{GDBN} stops and gives you control
edcc5120
TT
16486when any of shared library events happen. The best way to do this is
16487to use @code{catch load} and @code{catch unload} (@pxref{Set
16488Catchpoints}).
16489
16490@value{GDBN} also supports the the @code{set stop-on-solib-events}
16491command for this. This command exists for historical reasons. It is
16492less useful than setting a catchpoint, because it does not allow for
16493conditions or commands as a catchpoint does.
721c2651
EZ
16494
16495@table @code
16496@item set stop-on-solib-events
16497@kindex set stop-on-solib-events
16498This command controls whether @value{GDBN} should give you control
16499when the dynamic linker notifies it about some shared library event.
16500The most common event of interest is loading or unloading of a new
16501shared library.
16502
16503@item show stop-on-solib-events
16504@kindex show stop-on-solib-events
16505Show whether @value{GDBN} stops and gives you control when shared
16506library events happen.
16507@end table
16508
f5ebfba0 16509Shared libraries are also supported in many cross or remote debugging
f1838a98
UW
16510configurations. @value{GDBN} needs to have access to the target's libraries;
16511this can be accomplished either by providing copies of the libraries
16512on the host system, or by asking @value{GDBN} to automatically retrieve the
16513libraries from the target. If copies of the target libraries are
16514provided, they need to be the same as the target libraries, although the
f5ebfba0
DJ
16515copies on the target can be stripped as long as the copies on the host are
16516not.
16517
59b7b46f
EZ
16518@cindex where to look for shared libraries
16519For remote debugging, you need to tell @value{GDBN} where the target
16520libraries are, so that it can load the correct copies---otherwise, it
16521may try to load the host's libraries. @value{GDBN} has two variables
16522to specify the search directories for target libraries.
f5ebfba0
DJ
16523
16524@table @code
59b7b46f 16525@cindex prefix for shared library file names
f822c95b 16526@cindex system root, alternate
f5ebfba0 16527@kindex set solib-absolute-prefix
f822c95b
DJ
16528@kindex set sysroot
16529@item set sysroot @var{path}
16530Use @var{path} as the system root for the program being debugged. Any
16531absolute shared library paths will be prefixed with @var{path}; many
16532runtime loaders store the absolute paths to the shared library in the
16533target program's memory. If you use @code{set sysroot} to find shared
16534libraries, they need to be laid out in the same way that they are on
16535the target, with e.g.@: a @file{/lib} and @file{/usr/lib} hierarchy
16536under @var{path}.
16537
f1838a98
UW
16538If @var{path} starts with the sequence @file{remote:}, @value{GDBN} will
16539retrieve the target libraries from the remote system. This is only
16540supported when using a remote target that supports the @code{remote get}
16541command (@pxref{File Transfer,,Sending files to a remote system}).
16542The part of @var{path} following the initial @file{remote:}
16543(if present) is used as system root prefix on the remote file system.
16544@footnote{If you want to specify a local system root using a directory
16545that happens to be named @file{remote:}, you need to use some equivalent
16546variant of the name like @file{./remote:}.}
16547
ab38a727
PA
16548For targets with an MS-DOS based filesystem, such as MS-Windows and
16549SymbianOS, @value{GDBN} tries prefixing a few variants of the target
16550absolute file name with @var{path}. But first, on Unix hosts,
16551@value{GDBN} converts all backslash directory separators into forward
16552slashes, because the backslash is not a directory separator on Unix:
16553
16554@smallexample
16555 c:\foo\bar.dll @result{} c:/foo/bar.dll
16556@end smallexample
16557
16558Then, @value{GDBN} attempts prefixing the target file name with
16559@var{path}, and looks for the resulting file name in the host file
16560system:
16561
16562@smallexample
16563 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
16564@end smallexample
16565
16566If that does not find the shared library, @value{GDBN} tries removing
16567the @samp{:} character from the drive spec, both for convenience, and,
16568for the case of the host file system not supporting file names with
16569colons:
16570
16571@smallexample
16572 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
16573@end smallexample
16574
16575This makes it possible to have a system root that mirrors a target
16576with more than one drive. E.g., you may want to setup your local
16577copies of the target system shared libraries like so (note @samp{c} vs
16578@samp{z}):
16579
16580@smallexample
16581 @file{/path/to/sysroot/c/sys/bin/foo.dll}
16582 @file{/path/to/sysroot/c/sys/bin/bar.dll}
16583 @file{/path/to/sysroot/z/sys/bin/bar.dll}
16584@end smallexample
16585
16586@noindent
16587and point the system root at @file{/path/to/sysroot}, so that
16588@value{GDBN} can find the correct copies of both
16589@file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
16590
16591If that still does not find the shared library, @value{GDBN} tries
16592removing the whole drive spec from the target file name:
16593
16594@smallexample
16595 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
16596@end smallexample
16597
16598This last lookup makes it possible to not care about the drive name,
16599if you don't want or need to.
16600
f822c95b
DJ
16601The @code{set solib-absolute-prefix} command is an alias for @code{set
16602sysroot}.
16603
16604@cindex default system root
59b7b46f 16605@cindex @samp{--with-sysroot}
f822c95b
DJ
16606You can set the default system root by using the configure-time
16607@samp{--with-sysroot} option. If the system root is inside
16608@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
16609@samp{--exec-prefix}), then the default system root will be updated
16610automatically if the installed @value{GDBN} is moved to a new
16611location.
16612
16613@kindex show sysroot
16614@item show sysroot
f5ebfba0
DJ
16615Display the current shared library prefix.
16616
16617@kindex set solib-search-path
16618@item set solib-search-path @var{path}
f822c95b
DJ
16619If this variable is set, @var{path} is a colon-separated list of
16620directories to search for shared libraries. @samp{solib-search-path}
16621is used after @samp{sysroot} fails to locate the library, or if the
16622path to the library is relative instead of absolute. If you want to
16623use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 16624@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 16625finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 16626it to a nonexistent directory may interfere with automatic loading
f822c95b 16627of shared library symbols.
f5ebfba0
DJ
16628
16629@kindex show solib-search-path
16630@item show solib-search-path
16631Display the current shared library search path.
ab38a727
PA
16632
16633@cindex DOS file-name semantics of file names.
16634@kindex set target-file-system-kind (unix|dos-based|auto)
16635@kindex show target-file-system-kind
16636@item set target-file-system-kind @var{kind}
16637Set assumed file system kind for target reported file names.
16638
16639Shared library file names as reported by the target system may not
16640make sense as is on the system @value{GDBN} is running on. For
16641example, when remote debugging a target that has MS-DOS based file
16642system semantics, from a Unix host, the target may be reporting to
16643@value{GDBN} a list of loaded shared libraries with file names such as
16644@file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
16645drive letters, so the @samp{c:\} prefix is not normally understood as
16646indicating an absolute file name, and neither is the backslash
16647normally considered a directory separator character. In that case,
16648the native file system would interpret this whole absolute file name
16649as a relative file name with no directory components. This would make
16650it impossible to point @value{GDBN} at a copy of the remote target's
16651shared libraries on the host using @code{set sysroot}, and impractical
16652with @code{set solib-search-path}. Setting
16653@code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
16654to interpret such file names similarly to how the target would, and to
16655map them to file names valid on @value{GDBN}'s native file system
16656semantics. The value of @var{kind} can be @code{"auto"}, in addition
16657to one of the supported file system kinds. In that case, @value{GDBN}
16658tries to determine the appropriate file system variant based on the
16659current target's operating system (@pxref{ABI, ,Configuring the
16660Current ABI}). The supported file system settings are:
16661
16662@table @code
16663@item unix
16664Instruct @value{GDBN} to assume the target file system is of Unix
16665kind. Only file names starting the forward slash (@samp{/}) character
16666are considered absolute, and the directory separator character is also
16667the forward slash.
16668
16669@item dos-based
16670Instruct @value{GDBN} to assume the target file system is DOS based.
16671File names starting with either a forward slash, or a drive letter
16672followed by a colon (e.g., @samp{c:}), are considered absolute, and
16673both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
16674considered directory separators.
16675
16676@item auto
16677Instruct @value{GDBN} to use the file system kind associated with the
16678target operating system (@pxref{ABI, ,Configuring the Current ABI}).
16679This is the default.
16680@end table
f5ebfba0
DJ
16681@end table
16682
c011a4f4
DE
16683@cindex file name canonicalization
16684@cindex base name differences
16685When processing file names provided by the user, @value{GDBN}
16686frequently needs to compare them to the file names recorded in the
16687program's debug info. Normally, @value{GDBN} compares just the
16688@dfn{base names} of the files as strings, which is reasonably fast
16689even for very large programs. (The base name of a file is the last
16690portion of its name, after stripping all the leading directories.)
16691This shortcut in comparison is based upon the assumption that files
16692cannot have more than one base name. This is usually true, but
16693references to files that use symlinks or similar filesystem
16694facilities violate that assumption. If your program records files
16695using such facilities, or if you provide file names to @value{GDBN}
16696using symlinks etc., you can set @code{basenames-may-differ} to
16697@code{true} to instruct @value{GDBN} to completely canonicalize each
16698pair of file names it needs to compare. This will make file-name
16699comparisons accurate, but at a price of a significant slowdown.
16700
16701@table @code
16702@item set basenames-may-differ
16703@kindex set basenames-may-differ
16704Set whether a source file may have multiple base names.
16705
16706@item show basenames-may-differ
16707@kindex show basenames-may-differ
16708Show whether a source file may have multiple base names.
16709@end table
5b5d99cf
JB
16710
16711@node Separate Debug Files
16712@section Debugging Information in Separate Files
16713@cindex separate debugging information files
16714@cindex debugging information in separate files
16715@cindex @file{.debug} subdirectories
16716@cindex debugging information directory, global
f307c045 16717@cindex global debugging information directories
c7e83d54
EZ
16718@cindex build ID, and separate debugging files
16719@cindex @file{.build-id} directory
5b5d99cf
JB
16720
16721@value{GDBN} allows you to put a program's debugging information in a
16722file separate from the executable itself, in a way that allows
16723@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
16724Since debugging information can be very large---sometimes larger
16725than the executable code itself---some systems distribute debugging
5b5d99cf
JB
16726information for their executables in separate files, which users can
16727install only when they need to debug a problem.
16728
c7e83d54
EZ
16729@value{GDBN} supports two ways of specifying the separate debug info
16730file:
5b5d99cf
JB
16731
16732@itemize @bullet
16733@item
c7e83d54
EZ
16734The executable contains a @dfn{debug link} that specifies the name of
16735the separate debug info file. The separate debug file's name is
16736usually @file{@var{executable}.debug}, where @var{executable} is the
16737name of the corresponding executable file without leading directories
16738(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
99e008fe
EZ
16739debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
16740checksum for the debug file, which @value{GDBN} uses to validate that
16741the executable and the debug file came from the same build.
c7e83d54
EZ
16742
16743@item
7e27a47a 16744The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 16745also present in the corresponding debug info file. (This is supported
7e27a47a
EZ
16746only on some operating systems, notably those which use the ELF format
16747for binary files and the @sc{gnu} Binutils.) For more details about
16748this feature, see the description of the @option{--build-id}
16749command-line option in @ref{Options, , Command Line Options, ld.info,
16750The GNU Linker}. The debug info file's name is not specified
16751explicitly by the build ID, but can be computed from the build ID, see
16752below.
d3750b24
JK
16753@end itemize
16754
c7e83d54
EZ
16755Depending on the way the debug info file is specified, @value{GDBN}
16756uses two different methods of looking for the debug file:
d3750b24
JK
16757
16758@itemize @bullet
16759@item
c7e83d54
EZ
16760For the ``debug link'' method, @value{GDBN} looks up the named file in
16761the directory of the executable file, then in a subdirectory of that
f307c045
JK
16762directory named @file{.debug}, and finally under each one of the global debug
16763directories, in a subdirectory whose name is identical to the leading
c7e83d54
EZ
16764directories of the executable's absolute file name.
16765
16766@item
83f83d7f 16767For the ``build ID'' method, @value{GDBN} looks in the
f307c045
JK
16768@file{.build-id} subdirectory of each one of the global debug directories for
16769a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
16770first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
16771are the rest of the bit string. (Real build ID strings are 32 or more
16772hex characters, not 10.)
c7e83d54
EZ
16773@end itemize
16774
16775So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
16776@file{/usr/bin/ls}, which has a debug link that specifies the
16777file @file{ls.debug}, and a build ID whose value in hex is
f307c045 16778@code{abcdef1234}. If the list of the global debug directories includes
c7e83d54
EZ
16779@file{/usr/lib/debug}, then @value{GDBN} will look for the following
16780debug information files, in the indicated order:
16781
16782@itemize @minus
16783@item
16784@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 16785@item
c7e83d54 16786@file{/usr/bin/ls.debug}
5b5d99cf 16787@item
c7e83d54 16788@file{/usr/bin/.debug/ls.debug}
5b5d99cf 16789@item
c7e83d54 16790@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 16791@end itemize
5b5d99cf 16792
1564a261
JK
16793@anchor{debug-file-directory}
16794Global debugging info directories default to what is set by @value{GDBN}
16795configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
16796you can also set the global debugging info directories, and view the list
16797@value{GDBN} is currently using.
5b5d99cf
JB
16798
16799@table @code
16800
16801@kindex set debug-file-directory
24ddea62
JK
16802@item set debug-file-directory @var{directories}
16803Set the directories which @value{GDBN} searches for separate debugging
d9242c17
JK
16804information files to @var{directory}. Multiple path components can be set
16805concatenating them by a path separator.
5b5d99cf
JB
16806
16807@kindex show debug-file-directory
16808@item show debug-file-directory
24ddea62 16809Show the directories @value{GDBN} searches for separate debugging
5b5d99cf
JB
16810information files.
16811
16812@end table
16813
16814@cindex @code{.gnu_debuglink} sections
c7e83d54 16815@cindex debug link sections
5b5d99cf
JB
16816A debug link is a special section of the executable file named
16817@code{.gnu_debuglink}. The section must contain:
16818
16819@itemize
16820@item
16821A filename, with any leading directory components removed, followed by
16822a zero byte,
16823@item
16824zero to three bytes of padding, as needed to reach the next four-byte
16825boundary within the section, and
16826@item
16827a four-byte CRC checksum, stored in the same endianness used for the
16828executable file itself. The checksum is computed on the debugging
16829information file's full contents by the function given below, passing
16830zero as the @var{crc} argument.
16831@end itemize
16832
16833Any executable file format can carry a debug link, as long as it can
16834contain a section named @code{.gnu_debuglink} with the contents
16835described above.
16836
d3750b24 16837@cindex @code{.note.gnu.build-id} sections
c7e83d54 16838@cindex build ID sections
7e27a47a
EZ
16839The build ID is a special section in the executable file (and in other
16840ELF binary files that @value{GDBN} may consider). This section is
16841often named @code{.note.gnu.build-id}, but that name is not mandatory.
16842It contains unique identification for the built files---the ID remains
16843the same across multiple builds of the same build tree. The default
16844algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
16845content for the build ID string. The same section with an identical
16846value is present in the original built binary with symbols, in its
16847stripped variant, and in the separate debugging information file.
d3750b24 16848
5b5d99cf
JB
16849The debugging information file itself should be an ordinary
16850executable, containing a full set of linker symbols, sections, and
16851debugging information. The sections of the debugging information file
c7e83d54
EZ
16852should have the same names, addresses, and sizes as the original file,
16853but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
16854in an ordinary executable.
16855
7e27a47a 16856The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
16857@samp{objcopy} utility that can produce
16858the separated executable / debugging information file pairs using the
16859following commands:
16860
16861@smallexample
16862@kbd{objcopy --only-keep-debug foo foo.debug}
16863@kbd{strip -g foo}
c7e83d54
EZ
16864@end smallexample
16865
16866@noindent
16867These commands remove the debugging
83f83d7f
JK
16868information from the executable file @file{foo} and place it in the file
16869@file{foo.debug}. You can use the first, second or both methods to link the
16870two files:
16871
16872@itemize @bullet
16873@item
16874The debug link method needs the following additional command to also leave
16875behind a debug link in @file{foo}:
16876
16877@smallexample
16878@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
16879@end smallexample
16880
16881Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 16882a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
16883foo.debug} has the same functionality as the two @code{objcopy} commands and
16884the @code{ln -s} command above, together.
16885
16886@item
16887Build ID gets embedded into the main executable using @code{ld --build-id} or
16888the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
16889compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 16890utilities (Binutils) package since version 2.18.
83f83d7f
JK
16891@end itemize
16892
16893@noindent
d3750b24 16894
99e008fe
EZ
16895@cindex CRC algorithm definition
16896The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
16897IEEE 802.3 using the polynomial:
16898
16899@c TexInfo requires naked braces for multi-digit exponents for Tex
16900@c output, but this causes HTML output to barf. HTML has to be set using
16901@c raw commands. So we end up having to specify this equation in 2
16902@c different ways!
16903@ifhtml
16904@display
16905@html
16906 <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>
16907 + <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
16908@end html
16909@end display
16910@end ifhtml
16911@ifnothtml
16912@display
16913 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
16914 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
16915@end display
16916@end ifnothtml
16917
16918The function is computed byte at a time, taking the least
16919significant bit of each byte first. The initial pattern
16920@code{0xffffffff} is used, to ensure leading zeros affect the CRC and
16921the final result is inverted to ensure trailing zeros also affect the
16922CRC.
16923
16924@emph{Note:} This is the same CRC polynomial as used in handling the
16925@dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{Remote Protocol,
16926, @value{GDBN} Remote Serial Protocol}). However in the
16927case of the Remote Serial Protocol, the CRC is computed @emph{most}
16928significant bit first, and the result is not inverted, so trailing
16929zeros have no effect on the CRC value.
16930
16931To complete the description, we show below the code of the function
16932which produces the CRC used in @code{.gnu_debuglink}. Inverting the
16933initially supplied @code{crc} argument means that an initial call to
16934this function passing in zero will start computing the CRC using
16935@code{0xffffffff}.
5b5d99cf 16936
4644b6e3 16937@kindex gnu_debuglink_crc32
5b5d99cf
JB
16938@smallexample
16939unsigned long
16940gnu_debuglink_crc32 (unsigned long crc,
16941 unsigned char *buf, size_t len)
16942@{
16943 static const unsigned long crc32_table[256] =
16944 @{
16945 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
16946 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
16947 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
16948 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
16949 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
16950 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
16951 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
16952 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
16953 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
16954 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
16955 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
16956 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
16957 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
16958 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
16959 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
16960 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
16961 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
16962 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
16963 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
16964 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
16965 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
16966 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
16967 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
16968 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
16969 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
16970 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
16971 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
16972 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
16973 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
16974 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
16975 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
16976 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
16977 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
16978 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
16979 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
16980 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
16981 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
16982 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
16983 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
16984 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
16985 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
16986 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
16987 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
16988 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
16989 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
16990 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
16991 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
16992 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
16993 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
16994 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
16995 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
16996 0x2d02ef8d
16997 @};
16998 unsigned char *end;
16999
17000 crc = ~crc & 0xffffffff;
17001 for (end = buf + len; buf < end; ++buf)
17002 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 17003 return ~crc & 0xffffffff;
5b5d99cf
JB
17004@}
17005@end smallexample
17006
c7e83d54
EZ
17007@noindent
17008This computation does not apply to the ``build ID'' method.
17009
608e2dbb
TT
17010@node MiniDebugInfo
17011@section Debugging information in a special section
17012@cindex separate debug sections
17013@cindex @samp{.gnu_debugdata} section
17014
17015Some systems ship pre-built executables and libraries that have a
17016special @samp{.gnu_debugdata} section. This feature is called
17017@dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
17018is used to supply extra symbols for backtraces.
17019
17020The intent of this section is to provide extra minimal debugging
17021information for use in simple backtraces. It is not intended to be a
17022replacement for full separate debugging information (@pxref{Separate
17023Debug Files}). The example below shows the intended use; however,
17024@value{GDBN} does not currently put restrictions on what sort of
17025debugging information might be included in the section.
17026
17027@value{GDBN} has support for this extension. If the section exists,
17028then it is used provided that no other source of debugging information
17029can be found, and that @value{GDBN} was configured with LZMA support.
17030
17031This section can be easily created using @command{objcopy} and other
17032standard utilities:
17033
17034@smallexample
17035# Extract the dynamic symbols from the main binary, there is no need
17036# to also have these in the normal symbol table
17037nm -D @var{binary} --format=posix --defined-only \
17038 | awk '@{ print $1 @}' | sort > dynsyms
17039
17040# Extract all the text (i.e. function) symbols from the debuginfo .
17041nm @var{binary} --format=posix --defined-only \
17042 | awk '@{ if ($2 == "T" || $2 == "t") print $1 @}' \
17043 | sort > funcsyms
17044
17045# Keep all the function symbols not already in the dynamic symbol
17046# table.
17047comm -13 dynsyms funcsyms > keep_symbols
17048
17049# Copy the full debuginfo, keeping only a minimal set of symbols and
17050# removing some unnecessary sections.
17051objcopy -S --remove-section .gdb_index --remove-section .comment \
17052 --keep-symbols=keep_symbols @var{binary} mini_debuginfo
17053
17054# Inject the compressed data into the .gnu_debugdata section of the
17055# original binary.
17056xz mini_debuginfo
17057objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
17058@end smallexample
5b5d99cf 17059
9291a0cd
TT
17060@node Index Files
17061@section Index Files Speed Up @value{GDBN}
17062@cindex index files
17063@cindex @samp{.gdb_index} section
17064
17065When @value{GDBN} finds a symbol file, it scans the symbols in the
17066file in order to construct an internal symbol table. This lets most
17067@value{GDBN} operations work quickly---at the cost of a delay early
17068on. For large programs, this delay can be quite lengthy, so
17069@value{GDBN} provides a way to build an index, which speeds up
17070startup.
17071
17072The index is stored as a section in the symbol file. @value{GDBN} can
17073write the index to a file, then you can put it into the symbol file
17074using @command{objcopy}.
17075
17076To create an index file, use the @code{save gdb-index} command:
17077
17078@table @code
17079@item save gdb-index @var{directory}
17080@kindex save gdb-index
17081Create an index file for each symbol file currently known by
17082@value{GDBN}. Each file is named after its corresponding symbol file,
17083with @samp{.gdb-index} appended, and is written into the given
17084@var{directory}.
17085@end table
17086
17087Once you have created an index file you can merge it into your symbol
17088file, here named @file{symfile}, using @command{objcopy}:
17089
17090@smallexample
17091$ objcopy --add-section .gdb_index=symfile.gdb-index \
17092 --set-section-flags .gdb_index=readonly symfile symfile
17093@end smallexample
17094
e615022a
DE
17095@value{GDBN} will normally ignore older versions of @file{.gdb_index}
17096sections that have been deprecated. Usually they are deprecated because
17097they are missing a new feature or have performance issues.
17098To tell @value{GDBN} to use a deprecated index section anyway
17099specify @code{set use-deprecated-index-sections on}.
17100The default is @code{off}.
17101This can speed up startup, but may result in some functionality being lost.
17102@xref{Index Section Format}.
17103
17104@emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
17105must be done before gdb reads the file. The following will not work:
17106
17107@smallexample
17108$ gdb -ex "set use-deprecated-index-sections on" <program>
17109@end smallexample
17110
17111Instead you must do, for example,
17112
17113@smallexample
17114$ gdb -iex "set use-deprecated-index-sections on" <program>
17115@end smallexample
17116
9291a0cd
TT
17117There are currently some limitation on indices. They only work when
17118for DWARF debugging information, not stabs. And, they do not
17119currently work for programs using Ada.
17120
6d2ebf8b 17121@node Symbol Errors
79a6e687 17122@section Errors Reading Symbol Files
c906108c
SS
17123
17124While reading a symbol file, @value{GDBN} occasionally encounters problems,
17125such as symbol types it does not recognize, or known bugs in compiler
17126output. By default, @value{GDBN} does not notify you of such problems, since
17127they are relatively common and primarily of interest to people
17128debugging compilers. If you are interested in seeing information
17129about ill-constructed symbol tables, you can either ask @value{GDBN} to print
17130only one message about each such type of problem, no matter how many
17131times the problem occurs; or you can ask @value{GDBN} to print more messages,
17132to see how many times the problems occur, with the @code{set
79a6e687
BW
17133complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
17134Messages}).
c906108c
SS
17135
17136The messages currently printed, and their meanings, include:
17137
17138@table @code
17139@item inner block not inside outer block in @var{symbol}
17140
17141The symbol information shows where symbol scopes begin and end
17142(such as at the start of a function or a block of statements). This
17143error indicates that an inner scope block is not fully contained
17144in its outer scope blocks.
17145
17146@value{GDBN} circumvents the problem by treating the inner block as if it had
17147the same scope as the outer block. In the error message, @var{symbol}
17148may be shown as ``@code{(don't know)}'' if the outer block is not a
17149function.
17150
17151@item block at @var{address} out of order
17152
17153The symbol information for symbol scope blocks should occur in
17154order of increasing addresses. This error indicates that it does not
17155do so.
17156
17157@value{GDBN} does not circumvent this problem, and has trouble
17158locating symbols in the source file whose symbols it is reading. (You
17159can often determine what source file is affected by specifying
79a6e687
BW
17160@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
17161Messages}.)
c906108c
SS
17162
17163@item bad block start address patched
17164
17165The symbol information for a symbol scope block has a start address
17166smaller than the address of the preceding source line. This is known
17167to occur in the SunOS 4.1.1 (and earlier) C compiler.
17168
17169@value{GDBN} circumvents the problem by treating the symbol scope block as
17170starting on the previous source line.
17171
17172@item bad string table offset in symbol @var{n}
17173
17174@cindex foo
17175Symbol number @var{n} contains a pointer into the string table which is
17176larger than the size of the string table.
17177
17178@value{GDBN} circumvents the problem by considering the symbol to have the
17179name @code{foo}, which may cause other problems if many symbols end up
17180with this name.
17181
17182@item unknown symbol type @code{0x@var{nn}}
17183
7a292a7a
SS
17184The symbol information contains new data types that @value{GDBN} does
17185not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 17186uncomprehended information, in hexadecimal.
c906108c 17187
7a292a7a
SS
17188@value{GDBN} circumvents the error by ignoring this symbol information.
17189This usually allows you to debug your program, though certain symbols
c906108c 17190are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
17191debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
17192on @code{complain}, then go up to the function @code{read_dbx_symtab}
17193and examine @code{*bufp} to see the symbol.
c906108c
SS
17194
17195@item stub type has NULL name
c906108c 17196
7a292a7a 17197@value{GDBN} could not find the full definition for a struct or class.
c906108c 17198
7a292a7a 17199@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 17200The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
17201information that recent versions of the compiler should have output for
17202it.
c906108c
SS
17203
17204@item info mismatch between compiler and debugger
17205
17206@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 17207
c906108c
SS
17208@end table
17209
b14b1491
TT
17210@node Data Files
17211@section GDB Data Files
17212
17213@cindex prefix for data files
17214@value{GDBN} will sometimes read an auxiliary data file. These files
17215are kept in a directory known as the @dfn{data directory}.
17216
17217You can set the data directory's name, and view the name @value{GDBN}
17218is currently using.
17219
17220@table @code
17221@kindex set data-directory
17222@item set data-directory @var{directory}
17223Set the directory which @value{GDBN} searches for auxiliary data files
17224to @var{directory}.
17225
17226@kindex show data-directory
17227@item show data-directory
17228Show the directory @value{GDBN} searches for auxiliary data files.
17229@end table
17230
17231@cindex default data directory
17232@cindex @samp{--with-gdb-datadir}
17233You can set the default data directory by using the configure-time
17234@samp{--with-gdb-datadir} option. If the data directory is inside
17235@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
17236@samp{--exec-prefix}), then the default data directory will be updated
17237automatically if the installed @value{GDBN} is moved to a new
17238location.
17239
aae1c79a
DE
17240The data directory may also be specified with the
17241@code{--data-directory} command line option.
17242@xref{Mode Options}.
17243
6d2ebf8b 17244@node Targets
c906108c 17245@chapter Specifying a Debugging Target
7a292a7a 17246
c906108c 17247@cindex debugging target
c906108c 17248A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
17249
17250Often, @value{GDBN} runs in the same host environment as your program;
17251in that case, the debugging target is specified as a side effect when
17252you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
17253flexibility---for example, running @value{GDBN} on a physically separate
17254host, or controlling a standalone system over a serial port or a
53a5351d
JM
17255realtime system over a TCP/IP connection---you can use the @code{target}
17256command to specify one of the target types configured for @value{GDBN}
79a6e687 17257(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 17258
a8f24a35
EZ
17259@cindex target architecture
17260It is possible to build @value{GDBN} for several different @dfn{target
17261architectures}. When @value{GDBN} is built like that, you can choose
17262one of the available architectures with the @kbd{set architecture}
17263command.
17264
17265@table @code
17266@kindex set architecture
17267@kindex show architecture
17268@item set architecture @var{arch}
17269This command sets the current target architecture to @var{arch}. The
17270value of @var{arch} can be @code{"auto"}, in addition to one of the
17271supported architectures.
17272
17273@item show architecture
17274Show the current target architecture.
9c16f35a
EZ
17275
17276@item set processor
17277@itemx processor
17278@kindex set processor
17279@kindex show processor
17280These are alias commands for, respectively, @code{set architecture}
17281and @code{show architecture}.
a8f24a35
EZ
17282@end table
17283
c906108c
SS
17284@menu
17285* Active Targets:: Active targets
17286* Target Commands:: Commands for managing targets
c906108c 17287* Byte Order:: Choosing target byte order
c906108c
SS
17288@end menu
17289
6d2ebf8b 17290@node Active Targets
79a6e687 17291@section Active Targets
7a292a7a 17292
c906108c
SS
17293@cindex stacking targets
17294@cindex active targets
17295@cindex multiple targets
17296
8ea5bce5 17297There are multiple classes of targets such as: processes, executable files or
c0edd9ed
JK
17298recording sessions. Core files belong to the process class, making core file
17299and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
17300on multiple active targets, one in each class. This allows you to (for
17301example) start a process and inspect its activity, while still having access to
17302the executable file after the process finishes. Or if you start process
17303recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
17304presented a virtual layer of the recording target, while the process target
17305remains stopped at the chronologically last point of the process execution.
17306
17307Use the @code{core-file} and @code{exec-file} commands to select a new core
17308file or executable target (@pxref{Files, ,Commands to Specify Files}). To
17309specify as a target a process that is already running, use the @code{attach}
17310command (@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 17311
6d2ebf8b 17312@node Target Commands
79a6e687 17313@section Commands for Managing Targets
c906108c
SS
17314
17315@table @code
17316@item target @var{type} @var{parameters}
7a292a7a
SS
17317Connects the @value{GDBN} host environment to a target machine or
17318process. A target is typically a protocol for talking to debugging
17319facilities. You use the argument @var{type} to specify the type or
17320protocol of the target machine.
c906108c
SS
17321
17322Further @var{parameters} are interpreted by the target protocol, but
17323typically include things like device names or host names to connect
17324with, process numbers, and baud rates.
c906108c
SS
17325
17326The @code{target} command does not repeat if you press @key{RET} again
17327after executing the command.
17328
17329@kindex help target
17330@item help target
17331Displays the names of all targets available. To display targets
17332currently selected, use either @code{info target} or @code{info files}
79a6e687 17333(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
17334
17335@item help target @var{name}
17336Describe a particular target, including any parameters necessary to
17337select it.
17338
17339@kindex set gnutarget
17340@item set gnutarget @var{args}
5d161b24 17341@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 17342knows whether it is reading an @dfn{executable},
5d161b24
DB
17343a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
17344with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
17345with @code{gnutarget} the @code{target} refers to a program, not a machine.
17346
d4f3574e 17347@quotation
c906108c
SS
17348@emph{Warning:} To specify a file format with @code{set gnutarget},
17349you must know the actual BFD name.
d4f3574e 17350@end quotation
c906108c 17351
d4f3574e 17352@noindent
79a6e687 17353@xref{Files, , Commands to Specify Files}.
c906108c 17354
5d161b24 17355@kindex show gnutarget
c906108c
SS
17356@item show gnutarget
17357Use the @code{show gnutarget} command to display what file format
17358@code{gnutarget} is set to read. If you have not set @code{gnutarget},
17359@value{GDBN} will determine the file format for each file automatically,
c4957902 17360and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
c906108c
SS
17361@end table
17362
4644b6e3 17363@cindex common targets
c906108c
SS
17364Here are some common targets (available, or not, depending on the GDB
17365configuration):
c906108c
SS
17366
17367@table @code
4644b6e3 17368@kindex target
c906108c 17369@item target exec @var{program}
4644b6e3 17370@cindex executable file target
c906108c
SS
17371An executable file. @samp{target exec @var{program}} is the same as
17372@samp{exec-file @var{program}}.
17373
c906108c 17374@item target core @var{filename}
4644b6e3 17375@cindex core dump file target
c906108c
SS
17376A core dump file. @samp{target core @var{filename}} is the same as
17377@samp{core-file @var{filename}}.
c906108c 17378
1a10341b 17379@item target remote @var{medium}
4644b6e3 17380@cindex remote target
1a10341b
JB
17381A remote system connected to @value{GDBN} via a serial line or network
17382connection. This command tells @value{GDBN} to use its own remote
17383protocol over @var{medium} for debugging. @xref{Remote Debugging}.
17384
17385For example, if you have a board connected to @file{/dev/ttya} on the
17386machine running @value{GDBN}, you could say:
17387
17388@smallexample
17389target remote /dev/ttya
17390@end smallexample
17391
17392@code{target remote} supports the @code{load} command. This is only
17393useful if you have some other way of getting the stub to the target
17394system, and you can put it somewhere in memory where it won't get
17395clobbered by the download.
c906108c 17396
ee8e71d4 17397@item target sim @r{[}@var{simargs}@r{]} @dots{}
4644b6e3 17398@cindex built-in simulator target
2df3850c 17399Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 17400In general,
474c8240 17401@smallexample
104c1213
JM
17402 target sim
17403 load
17404 run
474c8240 17405@end smallexample
d4f3574e 17406@noindent
104c1213 17407works; however, you cannot assume that a specific memory map, device
d4f3574e 17408drivers, or even basic I/O is available, although some simulators do
104c1213
JM
17409provide these. For info about any processor-specific simulator details,
17410see the appropriate section in @ref{Embedded Processors, ,Embedded
17411Processors}.
17412
c906108c
SS
17413@end table
17414
104c1213 17415Some configurations may include these targets as well:
c906108c
SS
17416
17417@table @code
17418
c906108c 17419@item target nrom @var{dev}
4644b6e3 17420@cindex NetROM ROM emulator target
c906108c
SS
17421NetROM ROM emulator. This target only supports downloading.
17422
c906108c
SS
17423@end table
17424
5d161b24 17425Different targets are available on different configurations of @value{GDBN};
c906108c 17426your configuration may have more or fewer targets.
c906108c 17427
721c2651
EZ
17428Many remote targets require you to download the executable's code once
17429you've successfully established a connection. You may wish to control
3d00d119
DJ
17430various aspects of this process.
17431
17432@table @code
721c2651
EZ
17433
17434@item set hash
17435@kindex set hash@r{, for remote monitors}
17436@cindex hash mark while downloading
17437This command controls whether a hash mark @samp{#} is displayed while
17438downloading a file to the remote monitor. If on, a hash mark is
17439displayed after each S-record is successfully downloaded to the
17440monitor.
17441
17442@item show hash
17443@kindex show hash@r{, for remote monitors}
17444Show the current status of displaying the hash mark.
17445
17446@item set debug monitor
17447@kindex set debug monitor
17448@cindex display remote monitor communications
17449Enable or disable display of communications messages between
17450@value{GDBN} and the remote monitor.
17451
17452@item show debug monitor
17453@kindex show debug monitor
17454Show the current status of displaying communications between
17455@value{GDBN} and the remote monitor.
a8f24a35 17456@end table
c906108c
SS
17457
17458@table @code
17459
17460@kindex load @var{filename}
17461@item load @var{filename}
8edfe269 17462@anchor{load}
c906108c
SS
17463Depending on what remote debugging facilities are configured into
17464@value{GDBN}, the @code{load} command may be available. Where it exists, it
17465is meant to make @var{filename} (an executable) available for debugging
17466on the remote system---by downloading, or dynamic linking, for example.
17467@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
17468the @code{add-symbol-file} command.
17469
17470If your @value{GDBN} does not have a @code{load} command, attempting to
17471execute it gets the error message ``@code{You can't do that when your
17472target is @dots{}}''
c906108c
SS
17473
17474The file is loaded at whatever address is specified in the executable.
17475For some object file formats, you can specify the load address when you
17476link the program; for other formats, like a.out, the object file format
17477specifies a fixed address.
17478@c FIXME! This would be a good place for an xref to the GNU linker doc.
17479
68437a39
DJ
17480Depending on the remote side capabilities, @value{GDBN} may be able to
17481load programs into flash memory.
17482
c906108c
SS
17483@code{load} does not repeat if you press @key{RET} again after using it.
17484@end table
17485
6d2ebf8b 17486@node Byte Order
79a6e687 17487@section Choosing Target Byte Order
7a292a7a 17488
c906108c
SS
17489@cindex choosing target byte order
17490@cindex target byte order
c906108c 17491
eb17f351 17492Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
c906108c
SS
17493offer the ability to run either big-endian or little-endian byte
17494orders. Usually the executable or symbol will include a bit to
17495designate the endian-ness, and you will not need to worry about
17496which to use. However, you may still find it useful to adjust
d4f3574e 17497@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
17498
17499@table @code
4644b6e3 17500@kindex set endian
c906108c
SS
17501@item set endian big
17502Instruct @value{GDBN} to assume the target is big-endian.
17503
c906108c
SS
17504@item set endian little
17505Instruct @value{GDBN} to assume the target is little-endian.
17506
c906108c
SS
17507@item set endian auto
17508Instruct @value{GDBN} to use the byte order associated with the
17509executable.
17510
17511@item show endian
17512Display @value{GDBN}'s current idea of the target byte order.
17513
17514@end table
17515
17516Note that these commands merely adjust interpretation of symbolic
17517data on the host, and that they have absolutely no effect on the
17518target system.
17519
ea35711c
DJ
17520
17521@node Remote Debugging
17522@chapter Debugging Remote Programs
c906108c
SS
17523@cindex remote debugging
17524
17525If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
17526@value{GDBN} in the usual way, it is often useful to use remote debugging.
17527For example, you might use remote debugging on an operating system kernel,
c906108c
SS
17528or on a small system which does not have a general purpose operating system
17529powerful enough to run a full-featured debugger.
17530
17531Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
17532to make this work with particular debugging targets. In addition,
5d161b24 17533@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
17534but not specific to any particular target system) which you can use if you
17535write the remote stubs---the code that runs on the remote system to
17536communicate with @value{GDBN}.
17537
17538Other remote targets may be available in your
17539configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 17540
6b2f586d 17541@menu
07f31aa6 17542* Connecting:: Connecting to a remote target
a6b151f1 17543* File Transfer:: Sending files to a remote system
6b2f586d 17544* Server:: Using the gdbserver program
79a6e687
BW
17545* Remote Configuration:: Remote configuration
17546* Remote Stub:: Implementing a remote stub
6b2f586d
AC
17547@end menu
17548
07f31aa6 17549@node Connecting
79a6e687 17550@section Connecting to a Remote Target
07f31aa6
DJ
17551
17552On the @value{GDBN} host machine, you will need an unstripped copy of
d3e8051b 17553your program, since @value{GDBN} needs symbol and debugging information.
07f31aa6
DJ
17554Start up @value{GDBN} as usual, using the name of the local copy of your
17555program as the first argument.
17556
86941c27
JB
17557@cindex @code{target remote}
17558@value{GDBN} can communicate with the target over a serial line, or
17559over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
17560each case, @value{GDBN} uses the same protocol for debugging your
17561program; only the medium carrying the debugging packets varies. The
17562@code{target remote} command establishes a connection to the target.
17563Its arguments indicate which medium to use:
17564
17565@table @code
17566
17567@item target remote @var{serial-device}
07f31aa6 17568@cindex serial line, @code{target remote}
86941c27
JB
17569Use @var{serial-device} to communicate with the target. For example,
17570to use a serial line connected to the device named @file{/dev/ttyb}:
17571
17572@smallexample
17573target remote /dev/ttyb
17574@end smallexample
17575
07f31aa6
DJ
17576If you're using a serial line, you may want to give @value{GDBN} the
17577@w{@samp{--baud}} option, or use the @code{set remotebaud} command
79a6e687 17578(@pxref{Remote Configuration, set remotebaud}) before the
9c16f35a 17579@code{target} command.
07f31aa6 17580
86941c27
JB
17581@item target remote @code{@var{host}:@var{port}}
17582@itemx target remote @code{tcp:@var{host}:@var{port}}
17583@cindex @acronym{TCP} port, @code{target remote}
17584Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
17585The @var{host} may be either a host name or a numeric @acronym{IP}
17586address; @var{port} must be a decimal number. The @var{host} could be
17587the target machine itself, if it is directly connected to the net, or
17588it might be a terminal server which in turn has a serial line to the
17589target.
07f31aa6 17590
86941c27
JB
17591For example, to connect to port 2828 on a terminal server named
17592@code{manyfarms}:
07f31aa6
DJ
17593
17594@smallexample
17595target remote manyfarms:2828
17596@end smallexample
17597
86941c27
JB
17598If your remote target is actually running on the same machine as your
17599debugger session (e.g.@: a simulator for your target running on the
17600same host), you can omit the hostname. For example, to connect to
17601port 1234 on your local machine:
07f31aa6
DJ
17602
17603@smallexample
17604target remote :1234
17605@end smallexample
17606@noindent
17607
17608Note that the colon is still required here.
17609
86941c27
JB
17610@item target remote @code{udp:@var{host}:@var{port}}
17611@cindex @acronym{UDP} port, @code{target remote}
17612Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
17613connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
17614
17615@smallexample
17616target remote udp:manyfarms:2828
17617@end smallexample
17618
86941c27
JB
17619When using a @acronym{UDP} connection for remote debugging, you should
17620keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
17621can silently drop packets on busy or unreliable networks, which will
17622cause havoc with your debugging session.
17623
66b8c7f6
JB
17624@item target remote | @var{command}
17625@cindex pipe, @code{target remote} to
17626Run @var{command} in the background and communicate with it using a
17627pipe. The @var{command} is a shell command, to be parsed and expanded
17628by the system's command shell, @code{/bin/sh}; it should expect remote
17629protocol packets on its standard input, and send replies on its
17630standard output. You could use this to run a stand-alone simulator
17631that speaks the remote debugging protocol, to make net connections
17632using programs like @code{ssh}, or for other similar tricks.
17633
17634If @var{command} closes its standard output (perhaps by exiting),
17635@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
17636program has already exited, this will have no effect.)
17637
86941c27 17638@end table
07f31aa6 17639
86941c27 17640Once the connection has been established, you can use all the usual
8edfe269
DJ
17641commands to examine and change data. The remote program is already
17642running; you can use @kbd{step} and @kbd{continue}, and you do not
17643need to use @kbd{run}.
07f31aa6
DJ
17644
17645@cindex interrupting remote programs
17646@cindex remote programs, interrupting
17647Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 17648interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
17649program. This may or may not succeed, depending in part on the hardware
17650and the serial drivers the remote system uses. If you type the
17651interrupt character once again, @value{GDBN} displays this prompt:
17652
17653@smallexample
17654Interrupted while waiting for the program.
17655Give up (and stop debugging it)? (y or n)
17656@end smallexample
17657
17658If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
17659(If you decide you want to try again later, you can use @samp{target
17660remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
17661goes back to waiting.
17662
17663@table @code
17664@kindex detach (remote)
17665@item detach
17666When you have finished debugging the remote program, you can use the
17667@code{detach} command to release it from @value{GDBN} control.
17668Detaching from the target normally resumes its execution, but the results
17669will depend on your particular remote stub. After the @code{detach}
17670command, @value{GDBN} is free to connect to another target.
17671
17672@kindex disconnect
17673@item disconnect
17674The @code{disconnect} command behaves like @code{detach}, except that
17675the target is generally not resumed. It will wait for @value{GDBN}
17676(this instance or another one) to connect and continue debugging. After
17677the @code{disconnect} command, @value{GDBN} is again free to connect to
17678another target.
09d4efe1
EZ
17679
17680@cindex send command to remote monitor
fad38dfa
EZ
17681@cindex extend @value{GDBN} for remote targets
17682@cindex add new commands for external monitor
09d4efe1
EZ
17683@kindex monitor
17684@item monitor @var{cmd}
fad38dfa
EZ
17685This command allows you to send arbitrary commands directly to the
17686remote monitor. Since @value{GDBN} doesn't care about the commands it
17687sends like this, this command is the way to extend @value{GDBN}---you
17688can add new commands that only the external monitor will understand
17689and implement.
07f31aa6
DJ
17690@end table
17691
a6b151f1
DJ
17692@node File Transfer
17693@section Sending files to a remote system
17694@cindex remote target, file transfer
17695@cindex file transfer
17696@cindex sending files to remote systems
17697
17698Some remote targets offer the ability to transfer files over the same
17699connection used to communicate with @value{GDBN}. This is convenient
17700for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
17701running @code{gdbserver} over a network interface. For other targets,
17702e.g.@: embedded devices with only a single serial port, this may be
17703the only way to upload or download files.
17704
17705Not all remote targets support these commands.
17706
17707@table @code
17708@kindex remote put
17709@item remote put @var{hostfile} @var{targetfile}
17710Copy file @var{hostfile} from the host system (the machine running
17711@value{GDBN}) to @var{targetfile} on the target system.
17712
17713@kindex remote get
17714@item remote get @var{targetfile} @var{hostfile}
17715Copy file @var{targetfile} from the target system to @var{hostfile}
17716on the host system.
17717
17718@kindex remote delete
17719@item remote delete @var{targetfile}
17720Delete @var{targetfile} from the target system.
17721
17722@end table
17723
6f05cf9f 17724@node Server
79a6e687 17725@section Using the @code{gdbserver} Program
6f05cf9f
AC
17726
17727@kindex gdbserver
17728@cindex remote connection without stubs
17729@code{gdbserver} is a control program for Unix-like systems, which
17730allows you to connect your program with a remote @value{GDBN} via
17731@code{target remote}---but without linking in the usual debugging stub.
17732
17733@code{gdbserver} is not a complete replacement for the debugging stubs,
17734because it requires essentially the same operating-system facilities
17735that @value{GDBN} itself does. In fact, a system that can run
17736@code{gdbserver} to connect to a remote @value{GDBN} could also run
17737@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
17738because it is a much smaller program than @value{GDBN} itself. It is
17739also easier to port than all of @value{GDBN}, so you may be able to get
17740started more quickly on a new system by using @code{gdbserver}.
17741Finally, if you develop code for real-time systems, you may find that
17742the tradeoffs involved in real-time operation make it more convenient to
17743do as much development work as possible on another system, for example
17744by cross-compiling. You can use @code{gdbserver} to make a similar
17745choice for debugging.
17746
17747@value{GDBN} and @code{gdbserver} communicate via either a serial line
17748or a TCP connection, using the standard @value{GDBN} remote serial
17749protocol.
17750
2d717e4f
DJ
17751@quotation
17752@emph{Warning:} @code{gdbserver} does not have any built-in security.
17753Do not run @code{gdbserver} connected to any public network; a
17754@value{GDBN} connection to @code{gdbserver} provides access to the
17755target system with the same privileges as the user running
17756@code{gdbserver}.
17757@end quotation
17758
17759@subsection Running @code{gdbserver}
17760@cindex arguments, to @code{gdbserver}
d9b1a651 17761@cindex @code{gdbserver}, command-line arguments
2d717e4f
DJ
17762
17763Run @code{gdbserver} on the target system. You need a copy of the
17764program you want to debug, including any libraries it requires.
6f05cf9f
AC
17765@code{gdbserver} does not need your program's symbol table, so you can
17766strip the program if necessary to save space. @value{GDBN} on the host
17767system does all the symbol handling.
17768
17769To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 17770the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
17771syntax is:
17772
17773@smallexample
17774target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
17775@end smallexample
17776
e0f9f062
DE
17777@var{comm} is either a device name (to use a serial line), or a TCP
17778hostname and portnumber, or @code{-} or @code{stdio} to use
17779stdin/stdout of @code{gdbserver}.
17780For example, to debug Emacs with the argument
6f05cf9f
AC
17781@samp{foo.txt} and communicate with @value{GDBN} over the serial port
17782@file{/dev/com1}:
17783
17784@smallexample
17785target> gdbserver /dev/com1 emacs foo.txt
17786@end smallexample
17787
17788@code{gdbserver} waits passively for the host @value{GDBN} to communicate
17789with it.
17790
17791To use a TCP connection instead of a serial line:
17792
17793@smallexample
17794target> gdbserver host:2345 emacs foo.txt
17795@end smallexample
17796
17797The only difference from the previous example is the first argument,
17798specifying that you are communicating with the host @value{GDBN} via
17799TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
17800expect a TCP connection from machine @samp{host} to local TCP port 2345.
17801(Currently, the @samp{host} part is ignored.) You can choose any number
17802you want for the port number as long as it does not conflict with any
17803TCP ports already in use on the target system (for example, @code{23} is
17804reserved for @code{telnet}).@footnote{If you choose a port number that
17805conflicts with another service, @code{gdbserver} prints an error message
17806and exits.} You must use the same port number with the host @value{GDBN}
17807@code{target remote} command.
17808
e0f9f062
DE
17809The @code{stdio} connection is useful when starting @code{gdbserver}
17810with ssh:
17811
17812@smallexample
17813(gdb) target remote | ssh -T hostname gdbserver - hello
17814@end smallexample
17815
17816The @samp{-T} option to ssh is provided because we don't need a remote pty,
17817and we don't want escape-character handling. Ssh does this by default when
17818a command is provided, the flag is provided to make it explicit.
17819You could elide it if you want to.
17820
17821Programs started with stdio-connected gdbserver have @file{/dev/null} for
17822@code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
17823display through a pipe connected to gdbserver.
17824Both @code{stdout} and @code{stderr} use the same pipe.
17825
2d717e4f 17826@subsubsection Attaching to a Running Program
d9b1a651
EZ
17827@cindex attach to a program, @code{gdbserver}
17828@cindex @option{--attach}, @code{gdbserver} option
2d717e4f 17829
56460a61
DJ
17830On some targets, @code{gdbserver} can also attach to running programs.
17831This is accomplished via the @code{--attach} argument. The syntax is:
17832
17833@smallexample
2d717e4f 17834target> gdbserver --attach @var{comm} @var{pid}
56460a61
DJ
17835@end smallexample
17836
17837@var{pid} is the process ID of a currently running process. It isn't necessary
17838to point @code{gdbserver} at a binary for the running process.
17839
b1fe9455 17840@pindex pidof
b1fe9455
DJ
17841You can debug processes by name instead of process ID if your target has the
17842@code{pidof} utility:
17843
17844@smallexample
2d717e4f 17845target> gdbserver --attach @var{comm} `pidof @var{program}`
b1fe9455
DJ
17846@end smallexample
17847
f822c95b 17848In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
17849has multiple threads, most versions of @code{pidof} support the
17850@code{-s} option to only return the first process ID.
17851
2d717e4f 17852@subsubsection Multi-Process Mode for @code{gdbserver}
d9b1a651
EZ
17853@cindex @code{gdbserver}, multiple processes
17854@cindex multiple processes with @code{gdbserver}
2d717e4f
DJ
17855
17856When you connect to @code{gdbserver} using @code{target remote},
17857@code{gdbserver} debugs the specified program only once. When the
17858program exits, or you detach from it, @value{GDBN} closes the connection
17859and @code{gdbserver} exits.
17860
6e6c6f50 17861If you connect using @kbd{target extended-remote}, @code{gdbserver}
2d717e4f
DJ
17862enters multi-process mode. When the debugged program exits, or you
17863detach from it, @value{GDBN} stays connected to @code{gdbserver} even
17864though no program is running. The @code{run} and @code{attach}
17865commands instruct @code{gdbserver} to run or attach to a new program.
17866The @code{run} command uses @code{set remote exec-file} (@pxref{set
17867remote exec-file}) to select the program to run. Command line
17868arguments are supported, except for wildcard expansion and I/O
17869redirection (@pxref{Arguments}).
17870
d9b1a651 17871@cindex @option{--multi}, @code{gdbserver} option
2d717e4f
DJ
17872To start @code{gdbserver} without supplying an initial command to run
17873or process ID to attach, use the @option{--multi} command line option.
6e6c6f50 17874Then you can connect using @kbd{target extended-remote} and start
2d717e4f
DJ
17875the program you want to debug.
17876
03f2bd59
JK
17877In multi-process mode @code{gdbserver} does not automatically exit unless you
17878use the option @option{--once}. You can terminate it by using
17879@code{monitor exit} (@pxref{Monitor Commands for gdbserver}). Note that the
17880conditions under which @code{gdbserver} terminates depend on how @value{GDBN}
17881connects to it (@kbd{target remote} or @kbd{target extended-remote}). The
17882@option{--multi} option to @code{gdbserver} has no influence on that.
17883
17884@subsubsection TCP port allocation lifecycle of @code{gdbserver}
17885
17886This section applies only when @code{gdbserver} is run to listen on a TCP port.
17887
17888@code{gdbserver} normally terminates after all of its debugged processes have
17889terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
17890extended-remote}, @code{gdbserver} stays running even with no processes left.
17891@value{GDBN} normally terminates the spawned debugged process on its exit,
17892which normally also terminates @code{gdbserver} in the @kbd{target remote}
17893mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
17894cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
17895stays running even in the @kbd{target remote} mode.
17896
17897When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
17898Such reconnecting is useful for features like @ref{disconnected tracing}. For
17899completeness, at most one @value{GDBN} can be connected at a time.
17900
17901@cindex @option{--once}, @code{gdbserver} option
17902By default, @code{gdbserver} keeps the listening TCP port open, so that
17903additional connections are possible. However, if you start @code{gdbserver}
17904with the @option{--once} option, it will stop listening for any further
17905connection attempts after connecting to the first @value{GDBN} session. This
17906means no further connections to @code{gdbserver} will be possible after the
17907first one. It also means @code{gdbserver} will terminate after the first
17908connection with remote @value{GDBN} has closed, even for unexpectedly closed
17909connections and even in the @kbd{target extended-remote} mode. The
17910@option{--once} option allows reusing the same port number for connecting to
17911multiple instances of @code{gdbserver} running on the same host, since each
17912instance closes its port after the first connection.
2d717e4f
DJ
17913
17914@subsubsection Other Command-Line Arguments for @code{gdbserver}
17915
d9b1a651 17916@cindex @option{--debug}, @code{gdbserver} option
62709adf 17917The @option{--debug} option tells @code{gdbserver} to display extra
d9b1a651
EZ
17918status information about the debugging process.
17919@cindex @option{--remote-debug}, @code{gdbserver} option
17920The @option{--remote-debug} option tells @code{gdbserver} to display
62709adf
PA
17921remote protocol debug output. These options are intended for
17922@code{gdbserver} development and for bug reports to the developers.
2d717e4f 17923
d9b1a651 17924@cindex @option{--wrapper}, @code{gdbserver} option
ccd213ac
DJ
17925The @option{--wrapper} option specifies a wrapper to launch programs
17926for debugging. The option should be followed by the name of the
17927wrapper, then any command-line arguments to pass to the wrapper, then
17928@kbd{--} indicating the end of the wrapper arguments.
17929
17930@code{gdbserver} runs the specified wrapper program with a combined
17931command line including the wrapper arguments, then the name of the
17932program to debug, then any arguments to the program. The wrapper
17933runs until it executes your program, and then @value{GDBN} gains control.
17934
17935You can use any program that eventually calls @code{execve} with
17936its arguments as a wrapper. Several standard Unix utilities do
17937this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
17938with @code{exec "$@@"} will also work.
17939
17940For example, you can use @code{env} to pass an environment variable to
17941the debugged program, without setting the variable in @code{gdbserver}'s
17942environment:
17943
17944@smallexample
17945$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
17946@end smallexample
17947
2d717e4f
DJ
17948@subsection Connecting to @code{gdbserver}
17949
17950Run @value{GDBN} on the host system.
17951
17952First make sure you have the necessary symbol files. Load symbols for
f822c95b
DJ
17953your application using the @code{file} command before you connect. Use
17954@code{set sysroot} to locate target libraries (unless your @value{GDBN}
2d717e4f 17955was compiled with the correct sysroot using @code{--with-sysroot}).
f822c95b
DJ
17956
17957The symbol file and target libraries must exactly match the executable
17958and libraries on the target, with one exception: the files on the host
17959system should not be stripped, even if the files on the target system
17960are. Mismatched or missing files will lead to confusing results
17961during debugging. On @sc{gnu}/Linux targets, mismatched or missing
17962files may also prevent @code{gdbserver} from debugging multi-threaded
17963programs.
17964
79a6e687 17965Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f
AC
17966For TCP connections, you must start up @code{gdbserver} prior to using
17967the @code{target remote} command. Otherwise you may get an error whose
17968text depends on the host system, but which usually looks something like
2d717e4f 17969@samp{Connection refused}. Don't use the @code{load}
397ca115 17970command in @value{GDBN} when using @code{gdbserver}, since the program is
f822c95b 17971already on the target.
07f31aa6 17972
79a6e687 17973@subsection Monitor Commands for @code{gdbserver}
c74d0ad8 17974@cindex monitor commands, for @code{gdbserver}
2d717e4f 17975@anchor{Monitor Commands for gdbserver}
c74d0ad8
DJ
17976
17977During a @value{GDBN} session using @code{gdbserver}, you can use the
17978@code{monitor} command to send special requests to @code{gdbserver}.
2d717e4f 17979Here are the available commands.
c74d0ad8
DJ
17980
17981@table @code
17982@item monitor help
17983List the available monitor commands.
17984
17985@item monitor set debug 0
17986@itemx monitor set debug 1
17987Disable or enable general debugging messages.
17988
17989@item monitor set remote-debug 0
17990@itemx monitor set remote-debug 1
17991Disable or enable specific debugging messages associated with the remote
17992protocol (@pxref{Remote Protocol}).
17993
cdbfd419
PP
17994@item monitor set libthread-db-search-path [PATH]
17995@cindex gdbserver, search path for @code{libthread_db}
17996When this command is issued, @var{path} is a colon-separated list of
17997directories to search for @code{libthread_db} (@pxref{Threads,,set
17998libthread-db-search-path}). If you omit @var{path},
84e578fb 17999@samp{libthread-db-search-path} will be reset to its default value.
cdbfd419 18000
98a5dd13
DE
18001The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
18002not supported in @code{gdbserver}.
18003
2d717e4f
DJ
18004@item monitor exit
18005Tell gdbserver to exit immediately. This command should be followed by
18006@code{disconnect} to close the debugging session. @code{gdbserver} will
18007detach from any attached processes and kill any processes it created.
18008Use @code{monitor exit} to terminate @code{gdbserver} at the end
18009of a multi-process mode debug session.
18010
c74d0ad8
DJ
18011@end table
18012
fa593d66
PA
18013@subsection Tracepoints support in @code{gdbserver}
18014@cindex tracepoints support in @code{gdbserver}
18015
0fb4aa4b
PA
18016On some targets, @code{gdbserver} supports tracepoints, fast
18017tracepoints and static tracepoints.
fa593d66 18018
0fb4aa4b 18019For fast or static tracepoints to work, a special library called the
fa593d66
PA
18020@dfn{in-process agent} (IPA), must be loaded in the inferior process.
18021This library is built and distributed as an integral part of
0fb4aa4b
PA
18022@code{gdbserver}. In addition, support for static tracepoints
18023requires building the in-process agent library with static tracepoints
18024support. At present, the UST (LTTng Userspace Tracer,
18025@url{http://lttng.org/ust}) tracing engine is supported. This support
18026is automatically available if UST development headers are found in the
18027standard include path when @code{gdbserver} is built, or if
18028@code{gdbserver} was explicitly configured using @option{--with-ust}
18029to point at such headers. You can explicitly disable the support
18030using @option{--with-ust=no}.
fa593d66
PA
18031
18032There are several ways to load the in-process agent in your program:
18033
18034@table @code
18035@item Specifying it as dependency at link time
18036
18037You can link your program dynamically with the in-process agent
18038library. On most systems, this is accomplished by adding
18039@code{-linproctrace} to the link command.
18040
18041@item Using the system's preloading mechanisms
18042
18043You can force loading the in-process agent at startup time by using
18044your system's support for preloading shared libraries. Many Unixes
18045support the concept of preloading user defined libraries. In most
18046cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
18047in the environment. See also the description of @code{gdbserver}'s
18048@option{--wrapper} command line option.
18049
18050@item Using @value{GDBN} to force loading the agent at run time
18051
18052On some systems, you can force the inferior to load a shared library,
18053by calling a dynamic loader function in the inferior that takes care
18054of dynamically looking up and loading a shared library. On most Unix
18055systems, the function is @code{dlopen}. You'll use the @code{call}
18056command for that. For example:
18057
18058@smallexample
18059(@value{GDBP}) call dlopen ("libinproctrace.so", ...)
18060@end smallexample
18061
18062Note that on most Unix systems, for the @code{dlopen} function to be
18063available, the program needs to be linked with @code{-ldl}.
18064@end table
18065
18066On systems that have a userspace dynamic loader, like most Unix
18067systems, when you connect to @code{gdbserver} using @code{target
18068remote}, you'll find that the program is stopped at the dynamic
18069loader's entry point, and no shared library has been loaded in the
18070program's address space yet, including the in-process agent. In that
0fb4aa4b
PA
18071case, before being able to use any of the fast or static tracepoints
18072features, you need to let the loader run and load the shared
18073libraries. The simplest way to do that is to run the program to the
18074main procedure. E.g., if debugging a C or C@t{++} program, start
fa593d66
PA
18075@code{gdbserver} like so:
18076
18077@smallexample
18078$ gdbserver :9999 myprogram
18079@end smallexample
18080
18081Start GDB and connect to @code{gdbserver} like so, and run to main:
18082
18083@smallexample
18084$ gdb myprogram
18085(@value{GDBP}) target remote myhost:9999
180860x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
18087(@value{GDBP}) b main
18088(@value{GDBP}) continue
18089@end smallexample
18090
18091The in-process tracing agent library should now be loaded into the
18092process; you can confirm it with the @code{info sharedlibrary}
18093command, which will list @file{libinproctrace.so} as loaded in the
0fb4aa4b
PA
18094process. You are now ready to install fast tracepoints, list static
18095tracepoint markers, probe static tracepoints markers, and start
fa593d66
PA
18096tracing.
18097
79a6e687
BW
18098@node Remote Configuration
18099@section Remote Configuration
501eef12 18100
9c16f35a
EZ
18101@kindex set remote
18102@kindex show remote
18103This section documents the configuration options available when
18104debugging remote programs. For the options related to the File I/O
fc320d37 18105extensions of the remote protocol, see @ref{system,
9c16f35a 18106system-call-allowed}.
501eef12
AC
18107
18108@table @code
9c16f35a 18109@item set remoteaddresssize @var{bits}
d3e8051b 18110@cindex address size for remote targets
9c16f35a
EZ
18111@cindex bits in remote address
18112Set the maximum size of address in a memory packet to the specified
18113number of bits. @value{GDBN} will mask off the address bits above
18114that number, when it passes addresses to the remote target. The
18115default value is the number of bits in the target's address.
18116
18117@item show remoteaddresssize
18118Show the current value of remote address size in bits.
18119
18120@item set remotebaud @var{n}
18121@cindex baud rate for remote targets
18122Set the baud rate for the remote serial I/O to @var{n} baud. The
18123value is used to set the speed of the serial port used for debugging
18124remote targets.
18125
18126@item show remotebaud
18127Show the current speed of the remote connection.
18128
18129@item set remotebreak
18130@cindex interrupt remote programs
18131@cindex BREAK signal instead of Ctrl-C
9a6253be 18132@anchor{set remotebreak}
9c16f35a 18133If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 18134when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 18135on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
18136character instead. The default is off, since most remote systems
18137expect to see @samp{Ctrl-C} as the interrupt signal.
18138
18139@item show remotebreak
18140Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
18141interrupt the remote program.
18142
23776285
MR
18143@item set remoteflow on
18144@itemx set remoteflow off
18145@kindex set remoteflow
18146Enable or disable hardware flow control (@code{RTS}/@code{CTS})
18147on the serial port used to communicate to the remote target.
18148
18149@item show remoteflow
18150@kindex show remoteflow
18151Show the current setting of hardware flow control.
18152
9c16f35a
EZ
18153@item set remotelogbase @var{base}
18154Set the base (a.k.a.@: radix) of logging serial protocol
18155communications to @var{base}. Supported values of @var{base} are:
18156@code{ascii}, @code{octal}, and @code{hex}. The default is
18157@code{ascii}.
18158
18159@item show remotelogbase
18160Show the current setting of the radix for logging remote serial
18161protocol.
18162
18163@item set remotelogfile @var{file}
18164@cindex record serial communications on file
18165Record remote serial communications on the named @var{file}. The
18166default is not to record at all.
18167
18168@item show remotelogfile.
18169Show the current setting of the file name on which to record the
18170serial communications.
18171
18172@item set remotetimeout @var{num}
18173@cindex timeout for serial communications
18174@cindex remote timeout
18175Set the timeout limit to wait for the remote target to respond to
18176@var{num} seconds. The default is 2 seconds.
18177
18178@item show remotetimeout
18179Show the current number of seconds to wait for the remote target
18180responses.
18181
18182@cindex limit hardware breakpoints and watchpoints
18183@cindex remote target, limit break- and watchpoints
501eef12
AC
18184@anchor{set remote hardware-watchpoint-limit}
18185@anchor{set remote hardware-breakpoint-limit}
18186@item set remote hardware-watchpoint-limit @var{limit}
18187@itemx set remote hardware-breakpoint-limit @var{limit}
18188Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
18189watchpoints. A limit of -1, the default, is treated as unlimited.
2d717e4f 18190
480a3f21
PW
18191@cindex limit hardware watchpoints length
18192@cindex remote target, limit watchpoints length
18193@anchor{set remote hardware-watchpoint-length-limit}
18194@item set remote hardware-watchpoint-length-limit @var{limit}
18195Restrict @value{GDBN} to using @var{limit} bytes for the maximum length of
18196a remote hardware watchpoint. A limit of -1, the default, is treated
18197as unlimited.
18198
18199@item show remote hardware-watchpoint-length-limit
18200Show the current limit (in bytes) of the maximum length of
18201a remote hardware watchpoint.
18202
2d717e4f
DJ
18203@item set remote exec-file @var{filename}
18204@itemx show remote exec-file
18205@anchor{set remote exec-file}
18206@cindex executable file, for remote target
18207Select the file used for @code{run} with @code{target
18208extended-remote}. This should be set to a filename valid on the
18209target system. If it is not set, the target will use a default
18210filename (e.g.@: the last program run).
84603566 18211
9a7071a8
JB
18212@item set remote interrupt-sequence
18213@cindex interrupt remote programs
18214@cindex select Ctrl-C, BREAK or BREAK-g
18215Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
18216@samp{BREAK-g} as the
18217sequence to the remote target in order to interrupt the execution.
18218@samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
18219is high level of serial line for some certain time.
18220Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
18221It is @code{BREAK} signal followed by character @code{g}.
18222
18223@item show interrupt-sequence
18224Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
18225is sent by @value{GDBN} to interrupt the remote program.
18226@code{BREAK-g} is BREAK signal followed by @code{g} and
18227also known as Magic SysRq g.
18228
18229@item set remote interrupt-on-connect
18230@cindex send interrupt-sequence on start
18231Specify whether interrupt-sequence is sent to remote target when
18232@value{GDBN} connects to it. This is mostly needed when you debug
18233Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
18234which is known as Magic SysRq g in order to connect @value{GDBN}.
18235
18236@item show interrupt-on-connect
18237Show whether interrupt-sequence is sent
18238to remote target when @value{GDBN} connects to it.
18239
84603566
SL
18240@kindex set tcp
18241@kindex show tcp
18242@item set tcp auto-retry on
18243@cindex auto-retry, for remote TCP target
18244Enable auto-retry for remote TCP connections. This is useful if the remote
18245debugging agent is launched in parallel with @value{GDBN}; there is a race
18246condition because the agent may not become ready to accept the connection
18247before @value{GDBN} attempts to connect. When auto-retry is
18248enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
18249to establish the connection using the timeout specified by
18250@code{set tcp connect-timeout}.
18251
18252@item set tcp auto-retry off
18253Do not auto-retry failed TCP connections.
18254
18255@item show tcp auto-retry
18256Show the current auto-retry setting.
18257
18258@item set tcp connect-timeout @var{seconds}
18259@cindex connection timeout, for remote TCP target
18260@cindex timeout, for remote target connection
18261Set the timeout for establishing a TCP connection to the remote target to
18262@var{seconds}. The timeout affects both polling to retry failed connections
18263(enabled by @code{set tcp auto-retry on}) and waiting for connections
18264that are merely slow to complete, and represents an approximate cumulative
18265value.
18266
18267@item show tcp connect-timeout
18268Show the current connection timeout setting.
501eef12
AC
18269@end table
18270
427c3a89
DJ
18271@cindex remote packets, enabling and disabling
18272The @value{GDBN} remote protocol autodetects the packets supported by
18273your debugging stub. If you need to override the autodetection, you
18274can use these commands to enable or disable individual packets. Each
18275packet can be set to @samp{on} (the remote target supports this
18276packet), @samp{off} (the remote target does not support this packet),
18277or @samp{auto} (detect remote target support for this packet). They
18278all default to @samp{auto}. For more information about each packet,
18279see @ref{Remote Protocol}.
18280
18281During normal use, you should not have to use any of these commands.
18282If you do, that may be a bug in your remote debugging stub, or a bug
18283in @value{GDBN}. You may want to report the problem to the
18284@value{GDBN} developers.
18285
cfa9d6d9
DJ
18286For each packet @var{name}, the command to enable or disable the
18287packet is @code{set remote @var{name}-packet}. The available settings
18288are:
427c3a89 18289
cfa9d6d9 18290@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
18291@item Command Name
18292@tab Remote Packet
18293@tab Related Features
18294
cfa9d6d9 18295@item @code{fetch-register}
427c3a89
DJ
18296@tab @code{p}
18297@tab @code{info registers}
18298
cfa9d6d9 18299@item @code{set-register}
427c3a89
DJ
18300@tab @code{P}
18301@tab @code{set}
18302
cfa9d6d9 18303@item @code{binary-download}
427c3a89
DJ
18304@tab @code{X}
18305@tab @code{load}, @code{set}
18306
cfa9d6d9 18307@item @code{read-aux-vector}
427c3a89
DJ
18308@tab @code{qXfer:auxv:read}
18309@tab @code{info auxv}
18310
cfa9d6d9 18311@item @code{symbol-lookup}
427c3a89
DJ
18312@tab @code{qSymbol}
18313@tab Detecting multiple threads
18314
2d717e4f
DJ
18315@item @code{attach}
18316@tab @code{vAttach}
18317@tab @code{attach}
18318
cfa9d6d9 18319@item @code{verbose-resume}
427c3a89
DJ
18320@tab @code{vCont}
18321@tab Stepping or resuming multiple threads
18322
2d717e4f
DJ
18323@item @code{run}
18324@tab @code{vRun}
18325@tab @code{run}
18326
cfa9d6d9 18327@item @code{software-breakpoint}
427c3a89
DJ
18328@tab @code{Z0}
18329@tab @code{break}
18330
cfa9d6d9 18331@item @code{hardware-breakpoint}
427c3a89
DJ
18332@tab @code{Z1}
18333@tab @code{hbreak}
18334
cfa9d6d9 18335@item @code{write-watchpoint}
427c3a89
DJ
18336@tab @code{Z2}
18337@tab @code{watch}
18338
cfa9d6d9 18339@item @code{read-watchpoint}
427c3a89
DJ
18340@tab @code{Z3}
18341@tab @code{rwatch}
18342
cfa9d6d9 18343@item @code{access-watchpoint}
427c3a89
DJ
18344@tab @code{Z4}
18345@tab @code{awatch}
18346
cfa9d6d9
DJ
18347@item @code{target-features}
18348@tab @code{qXfer:features:read}
18349@tab @code{set architecture}
18350
18351@item @code{library-info}
18352@tab @code{qXfer:libraries:read}
18353@tab @code{info sharedlibrary}
18354
18355@item @code{memory-map}
18356@tab @code{qXfer:memory-map:read}
18357@tab @code{info mem}
18358
0fb4aa4b
PA
18359@item @code{read-sdata-object}
18360@tab @code{qXfer:sdata:read}
18361@tab @code{print $_sdata}
18362
cfa9d6d9
DJ
18363@item @code{read-spu-object}
18364@tab @code{qXfer:spu:read}
18365@tab @code{info spu}
18366
18367@item @code{write-spu-object}
18368@tab @code{qXfer:spu:write}
18369@tab @code{info spu}
18370
4aa995e1
PA
18371@item @code{read-siginfo-object}
18372@tab @code{qXfer:siginfo:read}
18373@tab @code{print $_siginfo}
18374
18375@item @code{write-siginfo-object}
18376@tab @code{qXfer:siginfo:write}
18377@tab @code{set $_siginfo}
18378
dc146f7c
VP
18379@item @code{threads}
18380@tab @code{qXfer:threads:read}
18381@tab @code{info threads}
18382
cfa9d6d9 18383@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
18384@tab @code{qGetTLSAddr}
18385@tab Displaying @code{__thread} variables
18386
711e434b
PM
18387@item @code{get-thread-information-block-address}
18388@tab @code{qGetTIBAddr}
18389@tab Display MS-Windows Thread Information Block.
18390
08388c79
DE
18391@item @code{search-memory}
18392@tab @code{qSearch:memory}
18393@tab @code{find}
18394
427c3a89
DJ
18395@item @code{supported-packets}
18396@tab @code{qSupported}
18397@tab Remote communications parameters
18398
cfa9d6d9 18399@item @code{pass-signals}
89be2091
DJ
18400@tab @code{QPassSignals}
18401@tab @code{handle @var{signal}}
18402
9b224c5e
PA
18403@item @code{program-signals}
18404@tab @code{QProgramSignals}
18405@tab @code{handle @var{signal}}
18406
a6b151f1
DJ
18407@item @code{hostio-close-packet}
18408@tab @code{vFile:close}
18409@tab @code{remote get}, @code{remote put}
18410
18411@item @code{hostio-open-packet}
18412@tab @code{vFile:open}
18413@tab @code{remote get}, @code{remote put}
18414
18415@item @code{hostio-pread-packet}
18416@tab @code{vFile:pread}
18417@tab @code{remote get}, @code{remote put}
18418
18419@item @code{hostio-pwrite-packet}
18420@tab @code{vFile:pwrite}
18421@tab @code{remote get}, @code{remote put}
18422
18423@item @code{hostio-unlink-packet}
18424@tab @code{vFile:unlink}
18425@tab @code{remote delete}
a6f3e723 18426
b9e7b9c3
UW
18427@item @code{hostio-readlink-packet}
18428@tab @code{vFile:readlink}
18429@tab Host I/O
18430
a6f3e723
SL
18431@item @code{noack-packet}
18432@tab @code{QStartNoAckMode}
18433@tab Packet acknowledgment
07e059b5
VP
18434
18435@item @code{osdata}
18436@tab @code{qXfer:osdata:read}
18437@tab @code{info os}
0b16c5cf
PA
18438
18439@item @code{query-attached}
18440@tab @code{qAttached}
18441@tab Querying remote process attach state.
b3b9301e
PA
18442
18443@item @code{traceframe-info}
18444@tab @code{qXfer:traceframe-info:read}
18445@tab Traceframe info
03583c20 18446
1e4d1764
YQ
18447@item @code{install-in-trace}
18448@tab @code{InstallInTrace}
18449@tab Install tracepoint in tracing
18450
03583c20
UW
18451@item @code{disable-randomization}
18452@tab @code{QDisableRandomization}
18453@tab @code{set disable-randomization}
83364271
LM
18454
18455@item @code{conditional-breakpoints-packet}
18456@tab @code{Z0 and Z1}
18457@tab @code{Support for target-side breakpoint condition evaluation}
427c3a89
DJ
18458@end multitable
18459
79a6e687
BW
18460@node Remote Stub
18461@section Implementing a Remote Stub
7a292a7a 18462
8e04817f
AC
18463@cindex debugging stub, example
18464@cindex remote stub, example
18465@cindex stub example, remote debugging
18466The stub files provided with @value{GDBN} implement the target side of the
18467communication protocol, and the @value{GDBN} side is implemented in the
18468@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
18469these subroutines to communicate, and ignore the details. (If you're
18470implementing your own stub file, you can still ignore the details: start
18471with one of the existing stub files. @file{sparc-stub.c} is the best
18472organized, and therefore the easiest to read.)
18473
104c1213
JM
18474@cindex remote serial debugging, overview
18475To debug a program running on another machine (the debugging
18476@dfn{target} machine), you must first arrange for all the usual
18477prerequisites for the program to run by itself. For example, for a C
18478program, you need:
c906108c 18479
104c1213
JM
18480@enumerate
18481@item
18482A startup routine to set up the C runtime environment; these usually
18483have a name like @file{crt0}. The startup routine may be supplied by
18484your hardware supplier, or you may have to write your own.
96baa820 18485
5d161b24 18486@item
d4f3574e 18487A C subroutine library to support your program's
104c1213 18488subroutine calls, notably managing input and output.
96baa820 18489
104c1213
JM
18490@item
18491A way of getting your program to the other machine---for example, a
18492download program. These are often supplied by the hardware
18493manufacturer, but you may have to write your own from hardware
18494documentation.
18495@end enumerate
96baa820 18496
104c1213
JM
18497The next step is to arrange for your program to use a serial port to
18498communicate with the machine where @value{GDBN} is running (the @dfn{host}
18499machine). In general terms, the scheme looks like this:
96baa820 18500
104c1213
JM
18501@table @emph
18502@item On the host,
18503@value{GDBN} already understands how to use this protocol; when everything
18504else is set up, you can simply use the @samp{target remote} command
18505(@pxref{Targets,,Specifying a Debugging Target}).
18506
18507@item On the target,
18508you must link with your program a few special-purpose subroutines that
18509implement the @value{GDBN} remote serial protocol. The file containing these
18510subroutines is called a @dfn{debugging stub}.
18511
18512On certain remote targets, you can use an auxiliary program
18513@code{gdbserver} instead of linking a stub into your program.
79a6e687 18514@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 18515@end table
96baa820 18516
104c1213
JM
18517The debugging stub is specific to the architecture of the remote
18518machine; for example, use @file{sparc-stub.c} to debug programs on
18519@sc{sparc} boards.
96baa820 18520
104c1213
JM
18521@cindex remote serial stub list
18522These working remote stubs are distributed with @value{GDBN}:
96baa820 18523
104c1213
JM
18524@table @code
18525
18526@item i386-stub.c
41afff9a 18527@cindex @file{i386-stub.c}
104c1213
JM
18528@cindex Intel
18529@cindex i386
18530For Intel 386 and compatible architectures.
18531
18532@item m68k-stub.c
41afff9a 18533@cindex @file{m68k-stub.c}
104c1213
JM
18534@cindex Motorola 680x0
18535@cindex m680x0
18536For Motorola 680x0 architectures.
18537
18538@item sh-stub.c
41afff9a 18539@cindex @file{sh-stub.c}
172c2a43 18540@cindex Renesas
104c1213 18541@cindex SH
172c2a43 18542For Renesas SH architectures.
104c1213
JM
18543
18544@item sparc-stub.c
41afff9a 18545@cindex @file{sparc-stub.c}
104c1213
JM
18546@cindex Sparc
18547For @sc{sparc} architectures.
18548
18549@item sparcl-stub.c
41afff9a 18550@cindex @file{sparcl-stub.c}
104c1213
JM
18551@cindex Fujitsu
18552@cindex SparcLite
18553For Fujitsu @sc{sparclite} architectures.
18554
18555@end table
18556
18557The @file{README} file in the @value{GDBN} distribution may list other
18558recently added stubs.
18559
18560@menu
18561* Stub Contents:: What the stub can do for you
18562* Bootstrapping:: What you must do for the stub
18563* Debug Session:: Putting it all together
104c1213
JM
18564@end menu
18565
6d2ebf8b 18566@node Stub Contents
79a6e687 18567@subsection What the Stub Can Do for You
104c1213
JM
18568
18569@cindex remote serial stub
18570The debugging stub for your architecture supplies these three
18571subroutines:
18572
18573@table @code
18574@item set_debug_traps
4644b6e3 18575@findex set_debug_traps
104c1213
JM
18576@cindex remote serial stub, initialization
18577This routine arranges for @code{handle_exception} to run when your
2fb860fc
PA
18578program stops. You must call this subroutine explicitly in your
18579program's startup code.
104c1213
JM
18580
18581@item handle_exception
4644b6e3 18582@findex handle_exception
104c1213
JM
18583@cindex remote serial stub, main routine
18584This is the central workhorse, but your program never calls it
18585explicitly---the setup code arranges for @code{handle_exception} to
18586run when a trap is triggered.
18587
18588@code{handle_exception} takes control when your program stops during
18589execution (for example, on a breakpoint), and mediates communications
18590with @value{GDBN} on the host machine. This is where the communications
18591protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 18592representative on the target machine. It begins by sending summary
104c1213
JM
18593information on the state of your program, then continues to execute,
18594retrieving and transmitting any information @value{GDBN} needs, until you
18595execute a @value{GDBN} command that makes your program resume; at that point,
18596@code{handle_exception} returns control to your own code on the target
5d161b24 18597machine.
104c1213
JM
18598
18599@item breakpoint
18600@cindex @code{breakpoint} subroutine, remote
18601Use this auxiliary subroutine to make your program contain a
18602breakpoint. Depending on the particular situation, this may be the only
18603way for @value{GDBN} to get control. For instance, if your target
18604machine has some sort of interrupt button, you won't need to call this;
18605pressing the interrupt button transfers control to
18606@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
18607simply receiving characters on the serial port may also trigger a trap;
18608again, in that situation, you don't need to call @code{breakpoint} from
18609your own program---simply running @samp{target remote} from the host
5d161b24 18610@value{GDBN} session gets control.
104c1213
JM
18611
18612Call @code{breakpoint} if none of these is true, or if you simply want
18613to make certain your program stops at a predetermined point for the
18614start of your debugging session.
18615@end table
18616
6d2ebf8b 18617@node Bootstrapping
79a6e687 18618@subsection What You Must Do for the Stub
104c1213
JM
18619
18620@cindex remote stub, support routines
18621The debugging stubs that come with @value{GDBN} are set up for a particular
18622chip architecture, but they have no information about the rest of your
18623debugging target machine.
18624
18625First of all you need to tell the stub how to communicate with the
18626serial port.
18627
18628@table @code
18629@item int getDebugChar()
4644b6e3 18630@findex getDebugChar
104c1213
JM
18631Write this subroutine to read a single character from the serial port.
18632It may be identical to @code{getchar} for your target system; a
18633different name is used to allow you to distinguish the two if you wish.
18634
18635@item void putDebugChar(int)
4644b6e3 18636@findex putDebugChar
104c1213 18637Write this subroutine to write a single character to the serial port.
5d161b24 18638It may be identical to @code{putchar} for your target system; a
104c1213
JM
18639different name is used to allow you to distinguish the two if you wish.
18640@end table
18641
18642@cindex control C, and remote debugging
18643@cindex interrupting remote targets
18644If you want @value{GDBN} to be able to stop your program while it is
18645running, you need to use an interrupt-driven serial driver, and arrange
18646for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
18647character). That is the character which @value{GDBN} uses to tell the
18648remote system to stop.
18649
18650Getting the debugging target to return the proper status to @value{GDBN}
18651probably requires changes to the standard stub; one quick and dirty way
18652is to just execute a breakpoint instruction (the ``dirty'' part is that
18653@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
18654
18655Other routines you need to supply are:
18656
18657@table @code
18658@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 18659@findex exceptionHandler
104c1213
JM
18660Write this function to install @var{exception_address} in the exception
18661handling tables. You need to do this because the stub does not have any
18662way of knowing what the exception handling tables on your target system
18663are like (for example, the processor's table might be in @sc{rom},
18664containing entries which point to a table in @sc{ram}).
18665@var{exception_number} is the exception number which should be changed;
18666its meaning is architecture-dependent (for example, different numbers
18667might represent divide by zero, misaligned access, etc). When this
18668exception occurs, control should be transferred directly to
18669@var{exception_address}, and the processor state (stack, registers,
18670and so on) should be just as it is when a processor exception occurs. So if
18671you want to use a jump instruction to reach @var{exception_address}, it
18672should be a simple jump, not a jump to subroutine.
18673
18674For the 386, @var{exception_address} should be installed as an interrupt
18675gate so that interrupts are masked while the handler runs. The gate
18676should be at privilege level 0 (the most privileged level). The
18677@sc{sparc} and 68k stubs are able to mask interrupts themselves without
18678help from @code{exceptionHandler}.
18679
18680@item void flush_i_cache()
4644b6e3 18681@findex flush_i_cache
d4f3574e 18682On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
18683instruction cache, if any, on your target machine. If there is no
18684instruction cache, this subroutine may be a no-op.
18685
18686On target machines that have instruction caches, @value{GDBN} requires this
18687function to make certain that the state of your program is stable.
18688@end table
18689
18690@noindent
18691You must also make sure this library routine is available:
18692
18693@table @code
18694@item void *memset(void *, int, int)
4644b6e3 18695@findex memset
104c1213
JM
18696This is the standard library function @code{memset} that sets an area of
18697memory to a known value. If you have one of the free versions of
18698@code{libc.a}, @code{memset} can be found there; otherwise, you must
18699either obtain it from your hardware manufacturer, or write your own.
18700@end table
18701
18702If you do not use the GNU C compiler, you may need other standard
18703library subroutines as well; this varies from one stub to another,
18704but in general the stubs are likely to use any of the common library
e22ea452 18705subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
18706
18707
6d2ebf8b 18708@node Debug Session
79a6e687 18709@subsection Putting it All Together
104c1213
JM
18710
18711@cindex remote serial debugging summary
18712In summary, when your program is ready to debug, you must follow these
18713steps.
18714
18715@enumerate
18716@item
6d2ebf8b 18717Make sure you have defined the supporting low-level routines
79a6e687 18718(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
18719@display
18720@code{getDebugChar}, @code{putDebugChar},
18721@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
18722@end display
18723
18724@item
2fb860fc
PA
18725Insert these lines in your program's startup code, before the main
18726procedure is called:
104c1213 18727
474c8240 18728@smallexample
104c1213
JM
18729set_debug_traps();
18730breakpoint();
474c8240 18731@end smallexample
104c1213 18732
2fb860fc
PA
18733On some machines, when a breakpoint trap is raised, the hardware
18734automatically makes the PC point to the instruction after the
18735breakpoint. If your machine doesn't do that, you may need to adjust
18736@code{handle_exception} to arrange for it to return to the instruction
18737after the breakpoint on this first invocation, so that your program
18738doesn't keep hitting the initial breakpoint instead of making
18739progress.
18740
104c1213
JM
18741@item
18742For the 680x0 stub only, you need to provide a variable called
18743@code{exceptionHook}. Normally you just use:
18744
474c8240 18745@smallexample
104c1213 18746void (*exceptionHook)() = 0;
474c8240 18747@end smallexample
104c1213 18748
d4f3574e 18749@noindent
104c1213 18750but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 18751function in your program, that function is called when
104c1213
JM
18752@code{@value{GDBN}} continues after stopping on a trap (for example, bus
18753error). The function indicated by @code{exceptionHook} is called with
18754one parameter: an @code{int} which is the exception number.
18755
18756@item
18757Compile and link together: your program, the @value{GDBN} debugging stub for
18758your target architecture, and the supporting subroutines.
18759
18760@item
18761Make sure you have a serial connection between your target machine and
18762the @value{GDBN} host, and identify the serial port on the host.
18763
18764@item
18765@c The "remote" target now provides a `load' command, so we should
18766@c document that. FIXME.
18767Download your program to your target machine (or get it there by
18768whatever means the manufacturer provides), and start it.
18769
18770@item
07f31aa6 18771Start @value{GDBN} on the host, and connect to the target
79a6e687 18772(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 18773
104c1213
JM
18774@end enumerate
18775
8e04817f
AC
18776@node Configurations
18777@chapter Configuration-Specific Information
104c1213 18778
8e04817f
AC
18779While nearly all @value{GDBN} commands are available for all native and
18780cross versions of the debugger, there are some exceptions. This chapter
18781describes things that are only available in certain configurations.
104c1213 18782
8e04817f
AC
18783There are three major categories of configurations: native
18784configurations, where the host and target are the same, embedded
18785operating system configurations, which are usually the same for several
18786different processor architectures, and bare embedded processors, which
18787are quite different from each other.
104c1213 18788
8e04817f
AC
18789@menu
18790* Native::
18791* Embedded OS::
18792* Embedded Processors::
18793* Architectures::
18794@end menu
104c1213 18795
8e04817f
AC
18796@node Native
18797@section Native
104c1213 18798
8e04817f
AC
18799This section describes details specific to particular native
18800configurations.
6cf7e474 18801
8e04817f
AC
18802@menu
18803* HP-UX:: HP-UX
7561d450 18804* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
18805* SVR4 Process Information:: SVR4 process information
18806* DJGPP Native:: Features specific to the DJGPP port
78c47bea 18807* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 18808* Hurd Native:: Features specific to @sc{gnu} Hurd
a80b95ba 18809* Darwin:: Features specific to Darwin
8e04817f 18810@end menu
6cf7e474 18811
8e04817f
AC
18812@node HP-UX
18813@subsection HP-UX
104c1213 18814
8e04817f
AC
18815On HP-UX systems, if you refer to a function or variable name that
18816begins with a dollar sign, @value{GDBN} searches for a user or system
18817name first, before it searches for a convenience variable.
104c1213 18818
9c16f35a 18819
7561d450
MK
18820@node BSD libkvm Interface
18821@subsection BSD libkvm Interface
18822
18823@cindex libkvm
18824@cindex kernel memory image
18825@cindex kernel crash dump
18826
18827BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
18828interface that provides a uniform interface for accessing kernel virtual
18829memory images, including live systems and crash dumps. @value{GDBN}
18830uses this interface to allow you to debug live kernels and kernel crash
18831dumps on many native BSD configurations. This is implemented as a
18832special @code{kvm} debugging target. For debugging a live system, load
18833the currently running kernel into @value{GDBN} and connect to the
18834@code{kvm} target:
18835
18836@smallexample
18837(@value{GDBP}) @b{target kvm}
18838@end smallexample
18839
18840For debugging crash dumps, provide the file name of the crash dump as an
18841argument:
18842
18843@smallexample
18844(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
18845@end smallexample
18846
18847Once connected to the @code{kvm} target, the following commands are
18848available:
18849
18850@table @code
18851@kindex kvm
18852@item kvm pcb
721c2651 18853Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
18854
18855@item kvm proc
18856Set current context from proc address. This command isn't available on
18857modern FreeBSD systems.
18858@end table
18859
8e04817f 18860@node SVR4 Process Information
79a6e687 18861@subsection SVR4 Process Information
60bf7e09
EZ
18862@cindex /proc
18863@cindex examine process image
18864@cindex process info via @file{/proc}
104c1213 18865
60bf7e09
EZ
18866Many versions of SVR4 and compatible systems provide a facility called
18867@samp{/proc} that can be used to examine the image of a running
451b7c33
TT
18868process using file-system subroutines.
18869
18870If @value{GDBN} is configured for an operating system with this
18871facility, the command @code{info proc} is available to report
18872information about the process running your program, or about any
18873process running on your system. This includes, as of this writing,
18874@sc{gnu}/Linux, OSF/1 (Digital Unix), Solaris, and Irix, but
18875not HP-UX, for example.
18876
18877This command may also work on core files that were created on a system
18878that has the @samp{/proc} facility.
104c1213 18879
8e04817f
AC
18880@table @code
18881@kindex info proc
60bf7e09 18882@cindex process ID
8e04817f 18883@item info proc
60bf7e09
EZ
18884@itemx info proc @var{process-id}
18885Summarize available information about any running process. If a
18886process ID is specified by @var{process-id}, display information about
18887that process; otherwise display information about the program being
18888debugged. The summary includes the debugged process ID, the command
18889line used to invoke it, its current working directory, and its
18890executable file's absolute file name.
18891
18892On some systems, @var{process-id} can be of the form
18893@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
18894within a process. If the optional @var{pid} part is missing, it means
18895a thread from the process being debugged (the leading @samp{/} still
18896needs to be present, or else @value{GDBN} will interpret the number as
18897a process ID rather than a thread ID).
6cf7e474 18898
0c631110
TT
18899@item info proc cmdline
18900@cindex info proc cmdline
18901Show the original command line of the process. This command is
18902specific to @sc{gnu}/Linux.
18903
18904@item info proc cwd
18905@cindex info proc cwd
18906Show the current working directory of the process. This command is
18907specific to @sc{gnu}/Linux.
18908
18909@item info proc exe
18910@cindex info proc exe
18911Show the name of executable of the process. This command is specific
18912to @sc{gnu}/Linux.
18913
8e04817f 18914@item info proc mappings
60bf7e09
EZ
18915@cindex memory address space mappings
18916Report the memory address space ranges accessible in the program, with
18917information on whether the process has read, write, or execute access
18918rights to each range. On @sc{gnu}/Linux systems, each memory range
18919includes the object file which is mapped to that range, instead of the
18920memory access rights to that range.
18921
18922@item info proc stat
18923@itemx info proc status
18924@cindex process detailed status information
18925These subcommands are specific to @sc{gnu}/Linux systems. They show
18926the process-related information, including the user ID and group ID;
18927how many threads are there in the process; its virtual memory usage;
18928the signals that are pending, blocked, and ignored; its TTY; its
18929consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 18930value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
18931(type @kbd{man 5 proc} from your shell prompt).
18932
18933@item info proc all
18934Show all the information about the process described under all of the
18935above @code{info proc} subcommands.
18936
8e04817f
AC
18937@ignore
18938@comment These sub-options of 'info proc' were not included when
18939@comment procfs.c was re-written. Keep their descriptions around
18940@comment against the day when someone finds the time to put them back in.
18941@kindex info proc times
18942@item info proc times
18943Starting time, user CPU time, and system CPU time for your program and
18944its children.
6cf7e474 18945
8e04817f
AC
18946@kindex info proc id
18947@item info proc id
18948Report on the process IDs related to your program: its own process ID,
18949the ID of its parent, the process group ID, and the session ID.
8e04817f 18950@end ignore
721c2651
EZ
18951
18952@item set procfs-trace
18953@kindex set procfs-trace
18954@cindex @code{procfs} API calls
18955This command enables and disables tracing of @code{procfs} API calls.
18956
18957@item show procfs-trace
18958@kindex show procfs-trace
18959Show the current state of @code{procfs} API call tracing.
18960
18961@item set procfs-file @var{file}
18962@kindex set procfs-file
18963Tell @value{GDBN} to write @code{procfs} API trace to the named
18964@var{file}. @value{GDBN} appends the trace info to the previous
18965contents of the file. The default is to display the trace on the
18966standard output.
18967
18968@item show procfs-file
18969@kindex show procfs-file
18970Show the file to which @code{procfs} API trace is written.
18971
18972@item proc-trace-entry
18973@itemx proc-trace-exit
18974@itemx proc-untrace-entry
18975@itemx proc-untrace-exit
18976@kindex proc-trace-entry
18977@kindex proc-trace-exit
18978@kindex proc-untrace-entry
18979@kindex proc-untrace-exit
18980These commands enable and disable tracing of entries into and exits
18981from the @code{syscall} interface.
18982
18983@item info pidlist
18984@kindex info pidlist
18985@cindex process list, QNX Neutrino
18986For QNX Neutrino only, this command displays the list of all the
18987processes and all the threads within each process.
18988
18989@item info meminfo
18990@kindex info meminfo
18991@cindex mapinfo list, QNX Neutrino
18992For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 18993@end table
104c1213 18994
8e04817f
AC
18995@node DJGPP Native
18996@subsection Features for Debugging @sc{djgpp} Programs
18997@cindex @sc{djgpp} debugging
18998@cindex native @sc{djgpp} debugging
18999@cindex MS-DOS-specific commands
104c1213 19000
514c4d71
EZ
19001@cindex DPMI
19002@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
19003MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
19004that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
19005top of real-mode DOS systems and their emulations.
104c1213 19006
8e04817f
AC
19007@value{GDBN} supports native debugging of @sc{djgpp} programs, and
19008defines a few commands specific to the @sc{djgpp} port. This
19009subsection describes those commands.
104c1213 19010
8e04817f
AC
19011@table @code
19012@kindex info dos
19013@item info dos
19014This is a prefix of @sc{djgpp}-specific commands which print
19015information about the target system and important OS structures.
f1251bdd 19016
8e04817f
AC
19017@kindex sysinfo
19018@cindex MS-DOS system info
19019@cindex free memory information (MS-DOS)
19020@item info dos sysinfo
19021This command displays assorted information about the underlying
19022platform: the CPU type and features, the OS version and flavor, the
19023DPMI version, and the available conventional and DPMI memory.
104c1213 19024
8e04817f
AC
19025@cindex GDT
19026@cindex LDT
19027@cindex IDT
19028@cindex segment descriptor tables
19029@cindex descriptor tables display
19030@item info dos gdt
19031@itemx info dos ldt
19032@itemx info dos idt
19033These 3 commands display entries from, respectively, Global, Local,
19034and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
19035tables are data structures which store a descriptor for each segment
19036that is currently in use. The segment's selector is an index into a
19037descriptor table; the table entry for that index holds the
19038descriptor's base address and limit, and its attributes and access
19039rights.
104c1213 19040
8e04817f
AC
19041A typical @sc{djgpp} program uses 3 segments: a code segment, a data
19042segment (used for both data and the stack), and a DOS segment (which
19043allows access to DOS/BIOS data structures and absolute addresses in
19044conventional memory). However, the DPMI host will usually define
19045additional segments in order to support the DPMI environment.
d4f3574e 19046
8e04817f
AC
19047@cindex garbled pointers
19048These commands allow to display entries from the descriptor tables.
19049Without an argument, all entries from the specified table are
19050displayed. An argument, which should be an integer expression, means
19051display a single entry whose index is given by the argument. For
19052example, here's a convenient way to display information about the
19053debugged program's data segment:
104c1213 19054
8e04817f
AC
19055@smallexample
19056@exdent @code{(@value{GDBP}) info dos ldt $ds}
19057@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
19058@end smallexample
104c1213 19059
8e04817f
AC
19060@noindent
19061This comes in handy when you want to see whether a pointer is outside
19062the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 19063
8e04817f
AC
19064@cindex page tables display (MS-DOS)
19065@item info dos pde
19066@itemx info dos pte
19067These two commands display entries from, respectively, the Page
19068Directory and the Page Tables. Page Directories and Page Tables are
19069data structures which control how virtual memory addresses are mapped
19070into physical addresses. A Page Table includes an entry for every
19071page of memory that is mapped into the program's address space; there
19072may be several Page Tables, each one holding up to 4096 entries. A
19073Page Directory has up to 4096 entries, one each for every Page Table
19074that is currently in use.
104c1213 19075
8e04817f
AC
19076Without an argument, @kbd{info dos pde} displays the entire Page
19077Directory, and @kbd{info dos pte} displays all the entries in all of
19078the Page Tables. An argument, an integer expression, given to the
19079@kbd{info dos pde} command means display only that entry from the Page
19080Directory table. An argument given to the @kbd{info dos pte} command
19081means display entries from a single Page Table, the one pointed to by
19082the specified entry in the Page Directory.
104c1213 19083
8e04817f
AC
19084@cindex direct memory access (DMA) on MS-DOS
19085These commands are useful when your program uses @dfn{DMA} (Direct
19086Memory Access), which needs physical addresses to program the DMA
19087controller.
104c1213 19088
8e04817f 19089These commands are supported only with some DPMI servers.
104c1213 19090
8e04817f
AC
19091@cindex physical address from linear address
19092@item info dos address-pte @var{addr}
19093This command displays the Page Table entry for a specified linear
514c4d71
EZ
19094address. The argument @var{addr} is a linear address which should
19095already have the appropriate segment's base address added to it,
19096because this command accepts addresses which may belong to @emph{any}
19097segment. For example, here's how to display the Page Table entry for
19098the page where a variable @code{i} is stored:
104c1213 19099
b383017d 19100@smallexample
8e04817f
AC
19101@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
19102@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 19103@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 19104@end smallexample
104c1213 19105
8e04817f
AC
19106@noindent
19107This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 19108whose physical base address is @code{0x02698000}, and shows all the
8e04817f 19109attributes of that page.
104c1213 19110
8e04817f
AC
19111Note that you must cast the addresses of variables to a @code{char *},
19112since otherwise the value of @code{__djgpp_base_address}, the base
19113address of all variables and functions in a @sc{djgpp} program, will
19114be added using the rules of C pointer arithmetics: if @code{i} is
19115declared an @code{int}, @value{GDBN} will add 4 times the value of
19116@code{__djgpp_base_address} to the address of @code{i}.
104c1213 19117
8e04817f
AC
19118Here's another example, it displays the Page Table entry for the
19119transfer buffer:
104c1213 19120
8e04817f
AC
19121@smallexample
19122@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
19123@exdent @code{Page Table entry for address 0x29110:}
19124@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
19125@end smallexample
104c1213 19126
8e04817f
AC
19127@noindent
19128(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
191293rd member of the @code{_go32_info_block} structure.) The output
19130clearly shows that this DPMI server maps the addresses in conventional
19131memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
19132linear (@code{0x29110}) addresses are identical.
104c1213 19133
8e04817f
AC
19134This command is supported only with some DPMI servers.
19135@end table
104c1213 19136
c45da7e6 19137@cindex DOS serial data link, remote debugging
a8f24a35
EZ
19138In addition to native debugging, the DJGPP port supports remote
19139debugging via a serial data link. The following commands are specific
19140to remote serial debugging in the DJGPP port of @value{GDBN}.
19141
19142@table @code
19143@kindex set com1base
19144@kindex set com1irq
19145@kindex set com2base
19146@kindex set com2irq
19147@kindex set com3base
19148@kindex set com3irq
19149@kindex set com4base
19150@kindex set com4irq
19151@item set com1base @var{addr}
19152This command sets the base I/O port address of the @file{COM1} serial
19153port.
19154
19155@item set com1irq @var{irq}
19156This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
19157for the @file{COM1} serial port.
19158
19159There are similar commands @samp{set com2base}, @samp{set com3irq},
19160etc.@: for setting the port address and the @code{IRQ} lines for the
19161other 3 COM ports.
19162
19163@kindex show com1base
19164@kindex show com1irq
19165@kindex show com2base
19166@kindex show com2irq
19167@kindex show com3base
19168@kindex show com3irq
19169@kindex show com4base
19170@kindex show com4irq
19171The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
19172display the current settings of the base address and the @code{IRQ}
19173lines used by the COM ports.
c45da7e6
EZ
19174
19175@item info serial
19176@kindex info serial
19177@cindex DOS serial port status
19178This command prints the status of the 4 DOS serial ports. For each
19179port, it prints whether it's active or not, its I/O base address and
19180IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
19181counts of various errors encountered so far.
a8f24a35
EZ
19182@end table
19183
19184
78c47bea 19185@node Cygwin Native
79a6e687 19186@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
19187@cindex MS Windows debugging
19188@cindex native Cygwin debugging
19189@cindex Cygwin-specific commands
19190
be448670 19191@value{GDBN} supports native debugging of MS Windows programs, including
cbb8f428
EZ
19192DLLs with and without symbolic debugging information.
19193
19194@cindex Ctrl-BREAK, MS-Windows
19195@cindex interrupt debuggee on MS-Windows
19196MS-Windows programs that call @code{SetConsoleMode} to switch off the
19197special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
19198by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
19199supports @kbd{C-@key{BREAK}} as an alternative interrupt key
19200sequence, which can be used to interrupt the debuggee even if it
19201ignores @kbd{C-c}.
19202
19203There are various additional Cygwin-specific commands, described in
19204this section. Working with DLLs that have no debugging symbols is
19205described in @ref{Non-debug DLL Symbols}.
78c47bea
PM
19206
19207@table @code
19208@kindex info w32
19209@item info w32
db2e3e2e 19210This is a prefix of MS Windows-specific commands which print
78c47bea
PM
19211information about the target system and important OS structures.
19212
19213@item info w32 selector
19214This command displays information returned by
19215the Win32 API @code{GetThreadSelectorEntry} function.
19216It takes an optional argument that is evaluated to
19217a long value to give the information about this given selector.
19218Without argument, this command displays information
d3e8051b 19219about the six segment registers.
78c47bea 19220
711e434b
PM
19221@item info w32 thread-information-block
19222This command displays thread specific information stored in the
19223Thread Information Block (readable on the X86 CPU family using @code{$fs}
19224selector for 32-bit programs and @code{$gs} for 64-bit programs).
19225
78c47bea
PM
19226@kindex info dll
19227@item info dll
db2e3e2e 19228This is a Cygwin-specific alias of @code{info shared}.
78c47bea
PM
19229
19230@kindex dll-symbols
19231@item dll-symbols
19232This command loads symbols from a dll similarly to
19233add-sym command but without the need to specify a base address.
19234
be90c084 19235@kindex set cygwin-exceptions
e16b02ee
EZ
19236@cindex debugging the Cygwin DLL
19237@cindex Cygwin DLL, debugging
be90c084 19238@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
19239If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
19240happen inside the Cygwin DLL. If @var{mode} is @code{off},
19241@value{GDBN} will delay recognition of exceptions, and may ignore some
19242exceptions which seem to be caused by internal Cygwin DLL
19243``bookkeeping''. This option is meant primarily for debugging the
19244Cygwin DLL itself; the default value is @code{off} to avoid annoying
19245@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
19246
19247@kindex show cygwin-exceptions
19248@item show cygwin-exceptions
e16b02ee
EZ
19249Displays whether @value{GDBN} will break on exceptions that happen
19250inside the Cygwin DLL itself.
be90c084 19251
b383017d 19252@kindex set new-console
78c47bea 19253@item set new-console @var{mode}
b383017d 19254If @var{mode} is @code{on} the debuggee will
78c47bea 19255be started in a new console on next start.
e03e5e7b 19256If @var{mode} is @code{off}, the debuggee will
78c47bea
PM
19257be started in the same console as the debugger.
19258
19259@kindex show new-console
19260@item show new-console
19261Displays whether a new console is used
19262when the debuggee is started.
19263
19264@kindex set new-group
19265@item set new-group @var{mode}
19266This boolean value controls whether the debuggee should
19267start a new group or stay in the same group as the debugger.
19268This affects the way the Windows OS handles
c8aa23ab 19269@samp{Ctrl-C}.
78c47bea
PM
19270
19271@kindex show new-group
19272@item show new-group
19273Displays current value of new-group boolean.
19274
19275@kindex set debugevents
19276@item set debugevents
219eec71
EZ
19277This boolean value adds debug output concerning kernel events related
19278to the debuggee seen by the debugger. This includes events that
19279signal thread and process creation and exit, DLL loading and
19280unloading, console interrupts, and debugging messages produced by the
19281Windows @code{OutputDebugString} API call.
78c47bea
PM
19282
19283@kindex set debugexec
19284@item set debugexec
b383017d 19285This boolean value adds debug output concerning execute events
219eec71 19286(such as resume thread) seen by the debugger.
78c47bea
PM
19287
19288@kindex set debugexceptions
19289@item set debugexceptions
219eec71
EZ
19290This boolean value adds debug output concerning exceptions in the
19291debuggee seen by the debugger.
78c47bea
PM
19292
19293@kindex set debugmemory
19294@item set debugmemory
219eec71
EZ
19295This boolean value adds debug output concerning debuggee memory reads
19296and writes by the debugger.
78c47bea
PM
19297
19298@kindex set shell
19299@item set shell
19300This boolean values specifies whether the debuggee is called
19301via a shell or directly (default value is on).
19302
19303@kindex show shell
19304@item show shell
19305Displays if the debuggee will be started with a shell.
19306
19307@end table
19308
be448670 19309@menu
79a6e687 19310* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
19311@end menu
19312
79a6e687
BW
19313@node Non-debug DLL Symbols
19314@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
19315@cindex DLLs with no debugging symbols
19316@cindex Minimal symbols and DLLs
19317
19318Very often on windows, some of the DLLs that your program relies on do
19319not include symbolic debugging information (for example,
db2e3e2e 19320@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 19321symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 19322information contained in the DLL's export table. This section
be448670
CF
19323describes working with such symbols, known internally to @value{GDBN} as
19324``minimal symbols''.
19325
19326Note that before the debugged program has started execution, no DLLs
db2e3e2e 19327will have been loaded. The easiest way around this problem is simply to
be448670 19328start the program --- either by setting a breakpoint or letting the
db2e3e2e 19329program run once to completion. It is also possible to force
be448670 19330@value{GDBN} to load a particular DLL before starting the executable ---
12c27660 19331see the shared library information in @ref{Files}, or the
db2e3e2e 19332@code{dll-symbols} command in @ref{Cygwin Native}. Currently,
be448670
CF
19333explicitly loading symbols from a DLL with no debugging information will
19334cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
19335which may adversely affect symbol lookup performance.
19336
79a6e687 19337@subsubsection DLL Name Prefixes
be448670
CF
19338
19339In keeping with the naming conventions used by the Microsoft debugging
19340tools, DLL export symbols are made available with a prefix based on the
19341DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
19342also entered into the symbol table, so @code{CreateFileA} is often
99e008fe 19343sufficient. In some cases there will be name clashes within a program
be448670
CF
19344(particularly if the executable itself includes full debugging symbols)
19345necessitating the use of the fully qualified name when referring to the
99e008fe 19346contents of the DLL. Use single-quotes around the name to avoid the
be448670
CF
19347exclamation mark (``!'') being interpreted as a language operator.
19348
19349Note that the internal name of the DLL may be all upper-case, even
99e008fe 19350though the file name of the DLL is lower-case, or vice-versa. Since
be448670
CF
19351symbols within @value{GDBN} are @emph{case-sensitive} this may cause
19352some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
19353@code{info variables} commands or even @code{maint print msymbols}
19354(@pxref{Symbols}). Here's an example:
be448670
CF
19355
19356@smallexample
f7dc1244 19357(@value{GDBP}) info function CreateFileA
be448670
CF
19358All functions matching regular expression "CreateFileA":
19359
19360Non-debugging symbols:
193610x77e885f4 CreateFileA
193620x77e885f4 KERNEL32!CreateFileA
19363@end smallexample
19364
19365@smallexample
f7dc1244 19366(@value{GDBP}) info function !
be448670
CF
19367All functions matching regular expression "!":
19368
19369Non-debugging symbols:
193700x6100114c cygwin1!__assert
193710x61004034 cygwin1!_dll_crt0@@0
193720x61004240 cygwin1!dll_crt0(per_process *)
19373[etc...]
19374@end smallexample
19375
79a6e687 19376@subsubsection Working with Minimal Symbols
be448670
CF
19377
19378Symbols extracted from a DLL's export table do not contain very much
19379type information. All that @value{GDBN} can do is guess whether a symbol
19380refers to a function or variable depending on the linker section that
19381contains the symbol. Also note that the actual contents of the memory
19382contained in a DLL are not available unless the program is running. This
19383means that you cannot examine the contents of a variable or disassemble
19384a function within a DLL without a running program.
19385
19386Variables are generally treated as pointers and dereferenced
19387automatically. For this reason, it is often necessary to prefix a
19388variable name with the address-of operator (``&'') and provide explicit
19389type information in the command. Here's an example of the type of
19390problem:
19391
19392@smallexample
f7dc1244 19393(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
19394$1 = 268572168
19395@end smallexample
19396
19397@smallexample
f7dc1244 19398(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
193990x10021610: "\230y\""
19400@end smallexample
19401
19402And two possible solutions:
19403
19404@smallexample
f7dc1244 19405(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
19406$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
19407@end smallexample
19408
19409@smallexample
f7dc1244 19410(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 194110x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 19412(@value{GDBP}) x/x 0x10021608
be448670 194130x10021608: 0x0022fd98
f7dc1244 19414(@value{GDBP}) x/s 0x0022fd98
be448670
CF
194150x22fd98: "/cygdrive/c/mydirectory/myprogram"
19416@end smallexample
19417
19418Setting a break point within a DLL is possible even before the program
19419starts execution. However, under these circumstances, @value{GDBN} can't
19420examine the initial instructions of the function in order to skip the
19421function's frame set-up code. You can work around this by using ``*&''
19422to set the breakpoint at a raw memory address:
19423
19424@smallexample
f7dc1244 19425(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
19426Breakpoint 1 at 0x1e04eff0
19427@end smallexample
19428
19429The author of these extensions is not entirely convinced that setting a
19430break point within a shared DLL like @file{kernel32.dll} is completely
19431safe.
19432
14d6dd68 19433@node Hurd Native
79a6e687 19434@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
19435@cindex @sc{gnu} Hurd debugging
19436
19437This subsection describes @value{GDBN} commands specific to the
19438@sc{gnu} Hurd native debugging.
19439
19440@table @code
19441@item set signals
19442@itemx set sigs
19443@kindex set signals@r{, Hurd command}
19444@kindex set sigs@r{, Hurd command}
19445This command toggles the state of inferior signal interception by
19446@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
19447affected by this command. @code{sigs} is a shorthand alias for
19448@code{signals}.
19449
19450@item show signals
19451@itemx show sigs
19452@kindex show signals@r{, Hurd command}
19453@kindex show sigs@r{, Hurd command}
19454Show the current state of intercepting inferior's signals.
19455
19456@item set signal-thread
19457@itemx set sigthread
19458@kindex set signal-thread
19459@kindex set sigthread
19460This command tells @value{GDBN} which thread is the @code{libc} signal
19461thread. That thread is run when a signal is delivered to a running
19462process. @code{set sigthread} is the shorthand alias of @code{set
19463signal-thread}.
19464
19465@item show signal-thread
19466@itemx show sigthread
19467@kindex show signal-thread
19468@kindex show sigthread
19469These two commands show which thread will run when the inferior is
19470delivered a signal.
19471
19472@item set stopped
19473@kindex set stopped@r{, Hurd command}
19474This commands tells @value{GDBN} that the inferior process is stopped,
19475as with the @code{SIGSTOP} signal. The stopped process can be
19476continued by delivering a signal to it.
19477
19478@item show stopped
19479@kindex show stopped@r{, Hurd command}
19480This command shows whether @value{GDBN} thinks the debuggee is
19481stopped.
19482
19483@item set exceptions
19484@kindex set exceptions@r{, Hurd command}
19485Use this command to turn off trapping of exceptions in the inferior.
19486When exception trapping is off, neither breakpoints nor
19487single-stepping will work. To restore the default, set exception
19488trapping on.
19489
19490@item show exceptions
19491@kindex show exceptions@r{, Hurd command}
19492Show the current state of trapping exceptions in the inferior.
19493
19494@item set task pause
19495@kindex set task@r{, Hurd commands}
19496@cindex task attributes (@sc{gnu} Hurd)
19497@cindex pause current task (@sc{gnu} Hurd)
19498This command toggles task suspension when @value{GDBN} has control.
19499Setting it to on takes effect immediately, and the task is suspended
19500whenever @value{GDBN} gets control. Setting it to off will take
19501effect the next time the inferior is continued. If this option is set
19502to off, you can use @code{set thread default pause on} or @code{set
19503thread pause on} (see below) to pause individual threads.
19504
19505@item show task pause
19506@kindex show task@r{, Hurd commands}
19507Show the current state of task suspension.
19508
19509@item set task detach-suspend-count
19510@cindex task suspend count
19511@cindex detach from task, @sc{gnu} Hurd
19512This command sets the suspend count the task will be left with when
19513@value{GDBN} detaches from it.
19514
19515@item show task detach-suspend-count
19516Show the suspend count the task will be left with when detaching.
19517
19518@item set task exception-port
19519@itemx set task excp
19520@cindex task exception port, @sc{gnu} Hurd
19521This command sets the task exception port to which @value{GDBN} will
19522forward exceptions. The argument should be the value of the @dfn{send
19523rights} of the task. @code{set task excp} is a shorthand alias.
19524
19525@item set noninvasive
19526@cindex noninvasive task options
19527This command switches @value{GDBN} to a mode that is the least
19528invasive as far as interfering with the inferior is concerned. This
19529is the same as using @code{set task pause}, @code{set exceptions}, and
19530@code{set signals} to values opposite to the defaults.
19531
19532@item info send-rights
19533@itemx info receive-rights
19534@itemx info port-rights
19535@itemx info port-sets
19536@itemx info dead-names
19537@itemx info ports
19538@itemx info psets
19539@cindex send rights, @sc{gnu} Hurd
19540@cindex receive rights, @sc{gnu} Hurd
19541@cindex port rights, @sc{gnu} Hurd
19542@cindex port sets, @sc{gnu} Hurd
19543@cindex dead names, @sc{gnu} Hurd
19544These commands display information about, respectively, send rights,
19545receive rights, port rights, port sets, and dead names of a task.
19546There are also shorthand aliases: @code{info ports} for @code{info
19547port-rights} and @code{info psets} for @code{info port-sets}.
19548
19549@item set thread pause
19550@kindex set thread@r{, Hurd command}
19551@cindex thread properties, @sc{gnu} Hurd
19552@cindex pause current thread (@sc{gnu} Hurd)
19553This command toggles current thread suspension when @value{GDBN} has
19554control. Setting it to on takes effect immediately, and the current
19555thread is suspended whenever @value{GDBN} gets control. Setting it to
19556off will take effect the next time the inferior is continued.
19557Normally, this command has no effect, since when @value{GDBN} has
19558control, the whole task is suspended. However, if you used @code{set
19559task pause off} (see above), this command comes in handy to suspend
19560only the current thread.
19561
19562@item show thread pause
19563@kindex show thread@r{, Hurd command}
19564This command shows the state of current thread suspension.
19565
19566@item set thread run
d3e8051b 19567This command sets whether the current thread is allowed to run.
14d6dd68
EZ
19568
19569@item show thread run
19570Show whether the current thread is allowed to run.
19571
19572@item set thread detach-suspend-count
19573@cindex thread suspend count, @sc{gnu} Hurd
19574@cindex detach from thread, @sc{gnu} Hurd
19575This command sets the suspend count @value{GDBN} will leave on a
19576thread when detaching. This number is relative to the suspend count
19577found by @value{GDBN} when it notices the thread; use @code{set thread
19578takeover-suspend-count} to force it to an absolute value.
19579
19580@item show thread detach-suspend-count
19581Show the suspend count @value{GDBN} will leave on the thread when
19582detaching.
19583
19584@item set thread exception-port
19585@itemx set thread excp
19586Set the thread exception port to which to forward exceptions. This
19587overrides the port set by @code{set task exception-port} (see above).
19588@code{set thread excp} is the shorthand alias.
19589
19590@item set thread takeover-suspend-count
19591Normally, @value{GDBN}'s thread suspend counts are relative to the
19592value @value{GDBN} finds when it notices each thread. This command
19593changes the suspend counts to be absolute instead.
19594
19595@item set thread default
19596@itemx show thread default
19597@cindex thread default settings, @sc{gnu} Hurd
19598Each of the above @code{set thread} commands has a @code{set thread
19599default} counterpart (e.g., @code{set thread default pause}, @code{set
19600thread default exception-port}, etc.). The @code{thread default}
19601variety of commands sets the default thread properties for all
19602threads; you can then change the properties of individual threads with
19603the non-default commands.
19604@end table
19605
a80b95ba
TG
19606@node Darwin
19607@subsection Darwin
19608@cindex Darwin
19609
19610@value{GDBN} provides the following commands specific to the Darwin target:
19611
19612@table @code
19613@item set debug darwin @var{num}
19614@kindex set debug darwin
19615When set to a non zero value, enables debugging messages specific to
19616the Darwin support. Higher values produce more verbose output.
19617
19618@item show debug darwin
19619@kindex show debug darwin
19620Show the current state of Darwin messages.
19621
19622@item set debug mach-o @var{num}
19623@kindex set debug mach-o
19624When set to a non zero value, enables debugging messages while
19625@value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
19626file format used on Darwin for object and executable files.) Higher
19627values produce more verbose output. This is a command to diagnose
19628problems internal to @value{GDBN} and should not be needed in normal
19629usage.
19630
19631@item show debug mach-o
19632@kindex show debug mach-o
19633Show the current state of Mach-O file messages.
19634
19635@item set mach-exceptions on
19636@itemx set mach-exceptions off
19637@kindex set mach-exceptions
19638On Darwin, faults are first reported as a Mach exception and are then
19639mapped to a Posix signal. Use this command to turn on trapping of
19640Mach exceptions in the inferior. This might be sometimes useful to
19641better understand the cause of a fault. The default is off.
19642
19643@item show mach-exceptions
19644@kindex show mach-exceptions
19645Show the current state of exceptions trapping.
19646@end table
19647
a64548ea 19648
8e04817f
AC
19649@node Embedded OS
19650@section Embedded Operating Systems
104c1213 19651
8e04817f
AC
19652This section describes configurations involving the debugging of
19653embedded operating systems that are available for several different
19654architectures.
d4f3574e 19655
8e04817f
AC
19656@menu
19657* VxWorks:: Using @value{GDBN} with VxWorks
19658@end menu
104c1213 19659
8e04817f
AC
19660@value{GDBN} includes the ability to debug programs running on
19661various real-time operating systems.
104c1213 19662
8e04817f
AC
19663@node VxWorks
19664@subsection Using @value{GDBN} with VxWorks
104c1213 19665
8e04817f 19666@cindex VxWorks
104c1213 19667
8e04817f 19668@table @code
104c1213 19669
8e04817f
AC
19670@kindex target vxworks
19671@item target vxworks @var{machinename}
19672A VxWorks system, attached via TCP/IP. The argument @var{machinename}
19673is the target system's machine name or IP address.
104c1213 19674
8e04817f 19675@end table
104c1213 19676
8e04817f
AC
19677On VxWorks, @code{load} links @var{filename} dynamically on the
19678current target system as well as adding its symbols in @value{GDBN}.
104c1213 19679
8e04817f
AC
19680@value{GDBN} enables developers to spawn and debug tasks running on networked
19681VxWorks targets from a Unix host. Already-running tasks spawned from
19682the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
19683both the Unix host and on the VxWorks target. The program
19684@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
19685installed with the name @code{vxgdb}, to distinguish it from a
19686@value{GDBN} for debugging programs on the host itself.)
104c1213 19687
8e04817f
AC
19688@table @code
19689@item VxWorks-timeout @var{args}
19690@kindex vxworks-timeout
19691All VxWorks-based targets now support the option @code{vxworks-timeout}.
19692This option is set by the user, and @var{args} represents the number of
19693seconds @value{GDBN} waits for responses to rpc's. You might use this if
19694your VxWorks target is a slow software simulator or is on the far side
19695of a thin network line.
19696@end table
104c1213 19697
8e04817f
AC
19698The following information on connecting to VxWorks was current when
19699this manual was produced; newer releases of VxWorks may use revised
19700procedures.
104c1213 19701
4644b6e3 19702@findex INCLUDE_RDB
8e04817f
AC
19703To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
19704to include the remote debugging interface routines in the VxWorks
19705library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
19706VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
19707kernel. The resulting kernel contains @file{rdb.a}, and spawns the
19708source debugging task @code{tRdbTask} when VxWorks is booted. For more
19709information on configuring and remaking VxWorks, see the manufacturer's
19710manual.
19711@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 19712
8e04817f
AC
19713Once you have included @file{rdb.a} in your VxWorks system image and set
19714your Unix execution search path to find @value{GDBN}, you are ready to
19715run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
19716@code{vxgdb}, depending on your installation).
104c1213 19717
8e04817f 19718@value{GDBN} comes up showing the prompt:
104c1213 19719
474c8240 19720@smallexample
8e04817f 19721(vxgdb)
474c8240 19722@end smallexample
104c1213 19723
8e04817f
AC
19724@menu
19725* VxWorks Connection:: Connecting to VxWorks
19726* VxWorks Download:: VxWorks download
19727* VxWorks Attach:: Running tasks
19728@end menu
104c1213 19729
8e04817f
AC
19730@node VxWorks Connection
19731@subsubsection Connecting to VxWorks
104c1213 19732
8e04817f
AC
19733The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
19734network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 19735
474c8240 19736@smallexample
8e04817f 19737(vxgdb) target vxworks tt
474c8240 19738@end smallexample
104c1213 19739
8e04817f
AC
19740@need 750
19741@value{GDBN} displays messages like these:
104c1213 19742
8e04817f
AC
19743@smallexample
19744Attaching remote machine across net...
19745Connected to tt.
19746@end smallexample
104c1213 19747
8e04817f
AC
19748@need 1000
19749@value{GDBN} then attempts to read the symbol tables of any object modules
19750loaded into the VxWorks target since it was last booted. @value{GDBN} locates
19751these files by searching the directories listed in the command search
79a6e687 19752path (@pxref{Environment, ,Your Program's Environment}); if it fails
8e04817f 19753to find an object file, it displays a message such as:
5d161b24 19754
474c8240 19755@smallexample
8e04817f 19756prog.o: No such file or directory.
474c8240 19757@end smallexample
104c1213 19758
8e04817f
AC
19759When this happens, add the appropriate directory to the search path with
19760the @value{GDBN} command @code{path}, and execute the @code{target}
19761command again.
104c1213 19762
8e04817f 19763@node VxWorks Download
79a6e687 19764@subsubsection VxWorks Download
104c1213 19765
8e04817f
AC
19766@cindex download to VxWorks
19767If you have connected to the VxWorks target and you want to debug an
19768object that has not yet been loaded, you can use the @value{GDBN}
19769@code{load} command to download a file from Unix to VxWorks
19770incrementally. The object file given as an argument to the @code{load}
19771command is actually opened twice: first by the VxWorks target in order
19772to download the code, then by @value{GDBN} in order to read the symbol
19773table. This can lead to problems if the current working directories on
19774the two systems differ. If both systems have NFS mounted the same
19775filesystems, you can avoid these problems by using absolute paths.
19776Otherwise, it is simplest to set the working directory on both systems
19777to the directory in which the object file resides, and then to reference
19778the file by its name, without any path. For instance, a program
19779@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
19780and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
19781program, type this on VxWorks:
104c1213 19782
474c8240 19783@smallexample
8e04817f 19784-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 19785@end smallexample
104c1213 19786
8e04817f
AC
19787@noindent
19788Then, in @value{GDBN}, type:
104c1213 19789
474c8240 19790@smallexample
8e04817f
AC
19791(vxgdb) cd @var{hostpath}/vw/demo/rdb
19792(vxgdb) load prog.o
474c8240 19793@end smallexample
104c1213 19794
8e04817f 19795@value{GDBN} displays a response similar to this:
104c1213 19796
8e04817f
AC
19797@smallexample
19798Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
19799@end smallexample
104c1213 19800
8e04817f
AC
19801You can also use the @code{load} command to reload an object module
19802after editing and recompiling the corresponding source file. Note that
19803this makes @value{GDBN} delete all currently-defined breakpoints,
19804auto-displays, and convenience variables, and to clear the value
19805history. (This is necessary in order to preserve the integrity of
19806debugger's data structures that reference the target system's symbol
19807table.)
104c1213 19808
8e04817f 19809@node VxWorks Attach
79a6e687 19810@subsubsection Running Tasks
104c1213
JM
19811
19812@cindex running VxWorks tasks
19813You can also attach to an existing task using the @code{attach} command as
19814follows:
19815
474c8240 19816@smallexample
104c1213 19817(vxgdb) attach @var{task}
474c8240 19818@end smallexample
104c1213
JM
19819
19820@noindent
19821where @var{task} is the VxWorks hexadecimal task ID. The task can be running
19822or suspended when you attach to it. Running tasks are suspended at
19823the time of attachment.
19824
6d2ebf8b 19825@node Embedded Processors
104c1213
JM
19826@section Embedded Processors
19827
19828This section goes into details specific to particular embedded
19829configurations.
19830
c45da7e6
EZ
19831@cindex send command to simulator
19832Whenever a specific embedded processor has a simulator, @value{GDBN}
19833allows to send an arbitrary command to the simulator.
19834
19835@table @code
19836@item sim @var{command}
19837@kindex sim@r{, a command}
19838Send an arbitrary @var{command} string to the simulator. Consult the
19839documentation for the specific simulator in use for information about
19840acceptable commands.
19841@end table
19842
7d86b5d5 19843
104c1213 19844@menu
c45da7e6 19845* ARM:: ARM RDI
172c2a43 19846* M32R/D:: Renesas M32R/D
104c1213 19847* M68K:: Motorola M68K
08be9d71 19848* MicroBlaze:: Xilinx MicroBlaze
104c1213 19849* MIPS Embedded:: MIPS Embedded
a37295f9 19850* OpenRISC 1000:: OpenRisc 1000
4acd40f3 19851* PowerPC Embedded:: PowerPC Embedded
984359d2 19852* PA:: HP PA Embedded
104c1213
JM
19853* Sparclet:: Tsqware Sparclet
19854* Sparclite:: Fujitsu Sparclite
104c1213 19855* Z8000:: Zilog Z8000
a64548ea
EZ
19856* AVR:: Atmel AVR
19857* CRIS:: CRIS
19858* Super-H:: Renesas Super-H
104c1213
JM
19859@end menu
19860
6d2ebf8b 19861@node ARM
104c1213 19862@subsection ARM
c45da7e6 19863@cindex ARM RDI
104c1213
JM
19864
19865@table @code
8e04817f
AC
19866@kindex target rdi
19867@item target rdi @var{dev}
19868ARM Angel monitor, via RDI library interface to ADP protocol. You may
19869use this target to communicate with both boards running the Angel
19870monitor, or with the EmbeddedICE JTAG debug device.
19871
19872@kindex target rdp
19873@item target rdp @var{dev}
19874ARM Demon monitor.
19875
19876@end table
19877
e2f4edfd
EZ
19878@value{GDBN} provides the following ARM-specific commands:
19879
19880@table @code
19881@item set arm disassembler
19882@kindex set arm
19883This commands selects from a list of disassembly styles. The
19884@code{"std"} style is the standard style.
19885
19886@item show arm disassembler
19887@kindex show arm
19888Show the current disassembly style.
19889
19890@item set arm apcs32
19891@cindex ARM 32-bit mode
19892This command toggles ARM operation mode between 32-bit and 26-bit.
19893
19894@item show arm apcs32
19895Display the current usage of the ARM 32-bit mode.
19896
19897@item set arm fpu @var{fputype}
19898This command sets the ARM floating-point unit (FPU) type. The
19899argument @var{fputype} can be one of these:
19900
19901@table @code
19902@item auto
19903Determine the FPU type by querying the OS ABI.
19904@item softfpa
19905Software FPU, with mixed-endian doubles on little-endian ARM
19906processors.
19907@item fpa
19908GCC-compiled FPA co-processor.
19909@item softvfp
19910Software FPU with pure-endian doubles.
19911@item vfp
19912VFP co-processor.
19913@end table
19914
19915@item show arm fpu
19916Show the current type of the FPU.
19917
19918@item set arm abi
19919This command forces @value{GDBN} to use the specified ABI.
19920
19921@item show arm abi
19922Show the currently used ABI.
19923
0428b8f5
DJ
19924@item set arm fallback-mode (arm|thumb|auto)
19925@value{GDBN} uses the symbol table, when available, to determine
19926whether instructions are ARM or Thumb. This command controls
19927@value{GDBN}'s default behavior when the symbol table is not
19928available. The default is @samp{auto}, which causes @value{GDBN} to
19929use the current execution mode (from the @code{T} bit in the @code{CPSR}
19930register).
19931
19932@item show arm fallback-mode
19933Show the current fallback instruction mode.
19934
19935@item set arm force-mode (arm|thumb|auto)
19936This command overrides use of the symbol table to determine whether
19937instructions are ARM or Thumb. The default is @samp{auto}, which
19938causes @value{GDBN} to use the symbol table and then the setting
19939of @samp{set arm fallback-mode}.
19940
19941@item show arm force-mode
19942Show the current forced instruction mode.
19943
e2f4edfd
EZ
19944@item set debug arm
19945Toggle whether to display ARM-specific debugging messages from the ARM
19946target support subsystem.
19947
19948@item show debug arm
19949Show whether ARM-specific debugging messages are enabled.
19950@end table
19951
c45da7e6
EZ
19952The following commands are available when an ARM target is debugged
19953using the RDI interface:
19954
19955@table @code
19956@item rdilogfile @r{[}@var{file}@r{]}
19957@kindex rdilogfile
19958@cindex ADP (Angel Debugger Protocol) logging
19959Set the filename for the ADP (Angel Debugger Protocol) packet log.
19960With an argument, sets the log file to the specified @var{file}. With
19961no argument, show the current log file name. The default log file is
19962@file{rdi.log}.
19963
19964@item rdilogenable @r{[}@var{arg}@r{]}
19965@kindex rdilogenable
19966Control logging of ADP packets. With an argument of 1 or @code{"yes"}
19967enables logging, with an argument 0 or @code{"no"} disables it. With
19968no arguments displays the current setting. When logging is enabled,
19969ADP packets exchanged between @value{GDBN} and the RDI target device
19970are logged to a file.
19971
19972@item set rdiromatzero
19973@kindex set rdiromatzero
19974@cindex ROM at zero address, RDI
19975Tell @value{GDBN} whether the target has ROM at address 0. If on,
19976vector catching is disabled, so that zero address can be used. If off
19977(the default), vector catching is enabled. For this command to take
19978effect, it needs to be invoked prior to the @code{target rdi} command.
19979
19980@item show rdiromatzero
19981@kindex show rdiromatzero
19982Show the current setting of ROM at zero address.
19983
19984@item set rdiheartbeat
19985@kindex set rdiheartbeat
19986@cindex RDI heartbeat
19987Enable or disable RDI heartbeat packets. It is not recommended to
19988turn on this option, since it confuses ARM and EPI JTAG interface, as
19989well as the Angel monitor.
19990
19991@item show rdiheartbeat
19992@kindex show rdiheartbeat
19993Show the setting of RDI heartbeat packets.
19994@end table
19995
ee8e71d4
EZ
19996@table @code
19997@item target sim @r{[}@var{simargs}@r{]} @dots{}
19998The @value{GDBN} ARM simulator accepts the following optional arguments.
19999
20000@table @code
20001@item --swi-support=@var{type}
20002Tell the simulator which SWI interfaces to support.
20003@var{type} may be a comma separated list of the following values.
20004The default value is @code{all}.
20005
20006@table @code
20007@item none
20008@item demon
20009@item angel
20010@item redboot
20011@item all
20012@end table
20013@end table
20014@end table
e2f4edfd 20015
8e04817f 20016@node M32R/D
ba04e063 20017@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
20018
20019@table @code
8e04817f
AC
20020@kindex target m32r
20021@item target m32r @var{dev}
172c2a43 20022Renesas M32R/D ROM monitor.
8e04817f 20023
fb3e19c0
KI
20024@kindex target m32rsdi
20025@item target m32rsdi @var{dev}
20026Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
20027@end table
20028
20029The following @value{GDBN} commands are specific to the M32R monitor:
20030
20031@table @code
20032@item set download-path @var{path}
20033@kindex set download-path
20034@cindex find downloadable @sc{srec} files (M32R)
d3e8051b 20035Set the default path for finding downloadable @sc{srec} files.
721c2651
EZ
20036
20037@item show download-path
20038@kindex show download-path
20039Show the default path for downloadable @sc{srec} files.
fb3e19c0 20040
721c2651
EZ
20041@item set board-address @var{addr}
20042@kindex set board-address
20043@cindex M32-EVA target board address
20044Set the IP address for the M32R-EVA target board.
20045
20046@item show board-address
20047@kindex show board-address
20048Show the current IP address of the target board.
20049
20050@item set server-address @var{addr}
20051@kindex set server-address
20052@cindex download server address (M32R)
20053Set the IP address for the download server, which is the @value{GDBN}'s
20054host machine.
20055
20056@item show server-address
20057@kindex show server-address
20058Display the IP address of the download server.
20059
20060@item upload @r{[}@var{file}@r{]}
20061@kindex upload@r{, M32R}
20062Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
20063upload capability. If no @var{file} argument is given, the current
20064executable file is uploaded.
20065
20066@item tload @r{[}@var{file}@r{]}
20067@kindex tload@r{, M32R}
20068Test the @code{upload} command.
8e04817f
AC
20069@end table
20070
ba04e063
EZ
20071The following commands are available for M32R/SDI:
20072
20073@table @code
20074@item sdireset
20075@kindex sdireset
20076@cindex reset SDI connection, M32R
20077This command resets the SDI connection.
20078
20079@item sdistatus
20080@kindex sdistatus
20081This command shows the SDI connection status.
20082
20083@item debug_chaos
20084@kindex debug_chaos
20085@cindex M32R/Chaos debugging
20086Instructs the remote that M32R/Chaos debugging is to be used.
20087
20088@item use_debug_dma
20089@kindex use_debug_dma
20090Instructs the remote to use the DEBUG_DMA method of accessing memory.
20091
20092@item use_mon_code
20093@kindex use_mon_code
20094Instructs the remote to use the MON_CODE method of accessing memory.
20095
20096@item use_ib_break
20097@kindex use_ib_break
20098Instructs the remote to set breakpoints by IB break.
20099
20100@item use_dbt_break
20101@kindex use_dbt_break
20102Instructs the remote to set breakpoints by DBT.
20103@end table
20104
8e04817f
AC
20105@node M68K
20106@subsection M68k
20107
7ce59000
DJ
20108The Motorola m68k configuration includes ColdFire support, and a
20109target command for the following ROM monitor.
8e04817f
AC
20110
20111@table @code
20112
8e04817f
AC
20113@kindex target dbug
20114@item target dbug @var{dev}
20115dBUG ROM monitor for Motorola ColdFire.
20116
8e04817f
AC
20117@end table
20118
08be9d71
ME
20119@node MicroBlaze
20120@subsection MicroBlaze
20121@cindex Xilinx MicroBlaze
20122@cindex XMD, Xilinx Microprocessor Debugger
20123
20124The MicroBlaze is a soft-core processor supported on various Xilinx
20125FPGAs, such as Spartan or Virtex series. Boards with these processors
20126usually have JTAG ports which connect to a host system running the Xilinx
20127Embedded Development Kit (EDK) or Software Development Kit (SDK).
20128This host system is used to download the configuration bitstream to
20129the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
20130communicates with the target board using the JTAG interface and
20131presents a @code{gdbserver} interface to the board. By default
20132@code{xmd} uses port @code{1234}. (While it is possible to change
20133this default port, it requires the use of undocumented @code{xmd}
20134commands. Contact Xilinx support if you need to do this.)
20135
20136Use these GDB commands to connect to the MicroBlaze target processor.
20137
20138@table @code
20139@item target remote :1234
20140Use this command to connect to the target if you are running @value{GDBN}
20141on the same system as @code{xmd}.
20142
20143@item target remote @var{xmd-host}:1234
20144Use this command to connect to the target if it is connected to @code{xmd}
20145running on a different system named @var{xmd-host}.
20146
20147@item load
20148Use this command to download a program to the MicroBlaze target.
20149
20150@item set debug microblaze @var{n}
20151Enable MicroBlaze-specific debugging messages if non-zero.
20152
20153@item show debug microblaze @var{n}
20154Show MicroBlaze-specific debugging level.
20155@end table
20156
8e04817f 20157@node MIPS Embedded
eb17f351 20158@subsection @acronym{MIPS} Embedded
8e04817f 20159
eb17f351
EZ
20160@cindex @acronym{MIPS} boards
20161@value{GDBN} can use the @acronym{MIPS} remote debugging protocol to talk to a
20162@acronym{MIPS} board attached to a serial line. This is available when
cc30c4bd 20163you configure @value{GDBN} with @samp{--target=mips-elf}.
104c1213 20164
8e04817f
AC
20165@need 1000
20166Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 20167
8e04817f
AC
20168@table @code
20169@item target mips @var{port}
20170@kindex target mips @var{port}
20171To run a program on the board, start up @code{@value{GDBP}} with the
20172name of your program as the argument. To connect to the board, use the
20173command @samp{target mips @var{port}}, where @var{port} is the name of
20174the serial port connected to the board. If the program has not already
20175been downloaded to the board, you may use the @code{load} command to
20176download it. You can then use all the usual @value{GDBN} commands.
104c1213 20177
8e04817f
AC
20178For example, this sequence connects to the target board through a serial
20179port, and loads and runs a program called @var{prog} through the
20180debugger:
104c1213 20181
474c8240 20182@smallexample
8e04817f
AC
20183host$ @value{GDBP} @var{prog}
20184@value{GDBN} is free software and @dots{}
20185(@value{GDBP}) target mips /dev/ttyb
20186(@value{GDBP}) load @var{prog}
20187(@value{GDBP}) run
474c8240 20188@end smallexample
104c1213 20189
8e04817f
AC
20190@item target mips @var{hostname}:@var{portnumber}
20191On some @value{GDBN} host configurations, you can specify a TCP
20192connection (for instance, to a serial line managed by a terminal
20193concentrator) instead of a serial port, using the syntax
20194@samp{@var{hostname}:@var{portnumber}}.
104c1213 20195
8e04817f
AC
20196@item target pmon @var{port}
20197@kindex target pmon @var{port}
20198PMON ROM monitor.
104c1213 20199
8e04817f
AC
20200@item target ddb @var{port}
20201@kindex target ddb @var{port}
20202NEC's DDB variant of PMON for Vr4300.
104c1213 20203
8e04817f
AC
20204@item target lsi @var{port}
20205@kindex target lsi @var{port}
20206LSI variant of PMON.
104c1213 20207
8e04817f
AC
20208@kindex target r3900
20209@item target r3900 @var{dev}
20210Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 20211
8e04817f
AC
20212@kindex target array
20213@item target array @var{dev}
20214Array Tech LSI33K RAID controller board.
104c1213 20215
8e04817f 20216@end table
104c1213 20217
104c1213 20218
8e04817f 20219@noindent
eb17f351 20220@value{GDBN} also supports these special commands for @acronym{MIPS} targets:
104c1213 20221
8e04817f 20222@table @code
8e04817f
AC
20223@item set mipsfpu double
20224@itemx set mipsfpu single
20225@itemx set mipsfpu none
a64548ea 20226@itemx set mipsfpu auto
8e04817f
AC
20227@itemx show mipsfpu
20228@kindex set mipsfpu
20229@kindex show mipsfpu
eb17f351
EZ
20230@cindex @acronym{MIPS} remote floating point
20231@cindex floating point, @acronym{MIPS} remote
20232If your target board does not support the @acronym{MIPS} floating point
8e04817f
AC
20233coprocessor, you should use the command @samp{set mipsfpu none} (if you
20234need this, you may wish to put the command in your @value{GDBN} init
20235file). This tells @value{GDBN} how to find the return value of
20236functions which return floating point values. It also allows
20237@value{GDBN} to avoid saving the floating point registers when calling
20238functions on the board. If you are using a floating point coprocessor
20239with only single precision floating point support, as on the @sc{r4650}
20240processor, use the command @samp{set mipsfpu single}. The default
20241double precision floating point coprocessor may be selected using
20242@samp{set mipsfpu double}.
104c1213 20243
8e04817f
AC
20244In previous versions the only choices were double precision or no
20245floating point, so @samp{set mipsfpu on} will select double precision
20246and @samp{set mipsfpu off} will select no floating point.
104c1213 20247
8e04817f
AC
20248As usual, you can inquire about the @code{mipsfpu} variable with
20249@samp{show mipsfpu}.
104c1213 20250
8e04817f
AC
20251@item set timeout @var{seconds}
20252@itemx set retransmit-timeout @var{seconds}
20253@itemx show timeout
20254@itemx show retransmit-timeout
eb17f351
EZ
20255@cindex @code{timeout}, @acronym{MIPS} protocol
20256@cindex @code{retransmit-timeout}, @acronym{MIPS} protocol
8e04817f
AC
20257@kindex set timeout
20258@kindex show timeout
20259@kindex set retransmit-timeout
20260@kindex show retransmit-timeout
eb17f351 20261You can control the timeout used while waiting for a packet, in the @acronym{MIPS}
8e04817f
AC
20262remote protocol, with the @code{set timeout @var{seconds}} command. The
20263default is 5 seconds. Similarly, you can control the timeout used while
a6f3e723 20264waiting for an acknowledgment of a packet with the @code{set
8e04817f
AC
20265retransmit-timeout @var{seconds}} command. The default is 3 seconds.
20266You can inspect both values with @code{show timeout} and @code{show
20267retransmit-timeout}. (These commands are @emph{only} available when
cc30c4bd 20268@value{GDBN} is configured for @samp{--target=mips-elf}.)
104c1213 20269
8e04817f
AC
20270The timeout set by @code{set timeout} does not apply when @value{GDBN}
20271is waiting for your program to stop. In that case, @value{GDBN} waits
20272forever because it has no way of knowing how long the program is going
20273to run before stopping.
ba04e063
EZ
20274
20275@item set syn-garbage-limit @var{num}
eb17f351
EZ
20276@kindex set syn-garbage-limit@r{, @acronym{MIPS} remote}
20277@cindex synchronize with remote @acronym{MIPS} target
ba04e063
EZ
20278Limit the maximum number of characters @value{GDBN} should ignore when
20279it tries to synchronize with the remote target. The default is 10
20280characters. Setting the limit to -1 means there's no limit.
20281
20282@item show syn-garbage-limit
eb17f351 20283@kindex show syn-garbage-limit@r{, @acronym{MIPS} remote}
ba04e063
EZ
20284Show the current limit on the number of characters to ignore when
20285trying to synchronize with the remote system.
20286
20287@item set monitor-prompt @var{prompt}
eb17f351 20288@kindex set monitor-prompt@r{, @acronym{MIPS} remote}
ba04e063
EZ
20289@cindex remote monitor prompt
20290Tell @value{GDBN} to expect the specified @var{prompt} string from the
20291remote monitor. The default depends on the target:
20292@table @asis
20293@item pmon target
20294@samp{PMON}
20295@item ddb target
20296@samp{NEC010}
20297@item lsi target
20298@samp{PMON>}
20299@end table
20300
20301@item show monitor-prompt
eb17f351 20302@kindex show monitor-prompt@r{, @acronym{MIPS} remote}
ba04e063
EZ
20303Show the current strings @value{GDBN} expects as the prompt from the
20304remote monitor.
20305
20306@item set monitor-warnings
eb17f351 20307@kindex set monitor-warnings@r{, @acronym{MIPS} remote}
ba04e063
EZ
20308Enable or disable monitor warnings about hardware breakpoints. This
20309has effect only for the @code{lsi} target. When on, @value{GDBN} will
20310display warning messages whose codes are returned by the @code{lsi}
20311PMON monitor for breakpoint commands.
20312
20313@item show monitor-warnings
eb17f351 20314@kindex show monitor-warnings@r{, @acronym{MIPS} remote}
ba04e063
EZ
20315Show the current setting of printing monitor warnings.
20316
20317@item pmon @var{command}
eb17f351 20318@kindex pmon@r{, @acronym{MIPS} remote}
ba04e063
EZ
20319@cindex send PMON command
20320This command allows sending an arbitrary @var{command} string to the
20321monitor. The monitor must be in debug mode for this to work.
8e04817f 20322@end table
104c1213 20323
a37295f9
MM
20324@node OpenRISC 1000
20325@subsection OpenRISC 1000
20326@cindex OpenRISC 1000
20327
20328@cindex or1k boards
20329See OR1k Architecture document (@uref{www.opencores.org}) for more information
20330about platform and commands.
20331
20332@table @code
20333
20334@kindex target jtag
20335@item target jtag jtag://@var{host}:@var{port}
20336
20337Connects to remote JTAG server.
20338JTAG remote server can be either an or1ksim or JTAG server,
20339connected via parallel port to the board.
20340
20341Example: @code{target jtag jtag://localhost:9999}
20342
20343@kindex or1ksim
20344@item or1ksim @var{command}
20345If connected to @code{or1ksim} OpenRISC 1000 Architectural
20346Simulator, proprietary commands can be executed.
20347
20348@kindex info or1k spr
20349@item info or1k spr
20350Displays spr groups.
20351
20352@item info or1k spr @var{group}
20353@itemx info or1k spr @var{groupno}
20354Displays register names in selected group.
20355
20356@item info or1k spr @var{group} @var{register}
20357@itemx info or1k spr @var{register}
20358@itemx info or1k spr @var{groupno} @var{registerno}
20359@itemx info or1k spr @var{registerno}
20360Shows information about specified spr register.
20361
20362@kindex spr
20363@item spr @var{group} @var{register} @var{value}
20364@itemx spr @var{register @var{value}}
20365@itemx spr @var{groupno} @var{registerno @var{value}}
20366@itemx spr @var{registerno @var{value}}
20367Writes @var{value} to specified spr register.
20368@end table
20369
20370Some implementations of OpenRISC 1000 Architecture also have hardware trace.
20371It is very similar to @value{GDBN} trace, except it does not interfere with normal
20372program execution and is thus much faster. Hardware breakpoints/watchpoint
20373triggers can be set using:
20374@table @code
20375@item $LEA/$LDATA
20376Load effective address/data
20377@item $SEA/$SDATA
20378Store effective address/data
20379@item $AEA/$ADATA
20380Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
20381@item $FETCH
20382Fetch data
20383@end table
20384
20385When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
20386@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
20387
20388@code{htrace} commands:
20389@cindex OpenRISC 1000 htrace
20390@table @code
20391@kindex hwatch
20392@item hwatch @var{conditional}
d3e8051b 20393Set hardware watchpoint on combination of Load/Store Effective Address(es)
a37295f9
MM
20394or Data. For example:
20395
20396@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
20397
20398@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
20399
4644b6e3 20400@kindex htrace
a37295f9
MM
20401@item htrace info
20402Display information about current HW trace configuration.
20403
a37295f9
MM
20404@item htrace trigger @var{conditional}
20405Set starting criteria for HW trace.
20406
a37295f9
MM
20407@item htrace qualifier @var{conditional}
20408Set acquisition qualifier for HW trace.
20409
a37295f9
MM
20410@item htrace stop @var{conditional}
20411Set HW trace stopping criteria.
20412
f153cc92 20413@item htrace record [@var{data}]*
a37295f9
MM
20414Selects the data to be recorded, when qualifier is met and HW trace was
20415triggered.
20416
a37295f9 20417@item htrace enable
a37295f9
MM
20418@itemx htrace disable
20419Enables/disables the HW trace.
20420
f153cc92 20421@item htrace rewind [@var{filename}]
a37295f9
MM
20422Clears currently recorded trace data.
20423
20424If filename is specified, new trace file is made and any newly collected data
20425will be written there.
20426
f153cc92 20427@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
20428Prints trace buffer, using current record configuration.
20429
a37295f9
MM
20430@item htrace mode continuous
20431Set continuous trace mode.
20432
a37295f9
MM
20433@item htrace mode suspend
20434Set suspend trace mode.
20435
20436@end table
20437
4acd40f3
TJB
20438@node PowerPC Embedded
20439@subsection PowerPC Embedded
104c1213 20440
66b73624
TJB
20441@cindex DVC register
20442@value{GDBN} supports using the DVC (Data Value Compare) register to
20443implement in hardware simple hardware watchpoint conditions of the form:
20444
20445@smallexample
20446(@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
20447 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
20448@end smallexample
20449
e09342b5
TJB
20450The DVC register will be automatically used when @value{GDBN} detects
20451such pattern in a condition expression, and the created watchpoint uses one
20452debug register (either the @code{exact-watchpoints} option is on and the
20453variable is scalar, or the variable has a length of one byte). This feature
20454is available in native @value{GDBN} running on a Linux kernel version 2.6.34
20455or newer.
20456
20457When running on PowerPC embedded processors, @value{GDBN} automatically uses
20458ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
20459in which case watchpoints using only one debug register are created when
20460watching variables of scalar types.
20461
20462You can create an artificial array to watch an arbitrary memory
20463region using one of the following commands (@pxref{Expressions}):
20464
20465@smallexample
20466(@value{GDBP}) watch *((char *) @var{address})@@@var{length}
20467(@value{GDBP}) watch @{char[@var{length}]@} @var{address}
20468@end smallexample
66b73624 20469
9c06b0b4
TJB
20470PowerPC embedded processors support masked watchpoints. See the discussion
20471about the @code{mask} argument in @ref{Set Watchpoints}.
20472
f1310107
TJB
20473@cindex ranged breakpoint
20474PowerPC embedded processors support hardware accelerated
20475@dfn{ranged breakpoints}. A ranged breakpoint stops execution of
20476the inferior whenever it executes an instruction at any address within
20477the range it specifies. To set a ranged breakpoint in @value{GDBN},
20478use the @code{break-range} command.
20479
55eddb0f
DJ
20480@value{GDBN} provides the following PowerPC-specific commands:
20481
104c1213 20482@table @code
f1310107
TJB
20483@kindex break-range
20484@item break-range @var{start-location}, @var{end-location}
20485Set a breakpoint for an address range.
20486@var{start-location} and @var{end-location} can specify a function name,
20487a line number, an offset of lines from the current line or from the start
20488location, or an address of an instruction (see @ref{Specify Location},
20489for a list of all the possible ways to specify a @var{location}.)
20490The breakpoint will stop execution of the inferior whenever it
20491executes an instruction at any address within the specified range,
20492(including @var{start-location} and @var{end-location}.)
20493
55eddb0f
DJ
20494@kindex set powerpc
20495@item set powerpc soft-float
20496@itemx show powerpc soft-float
20497Force @value{GDBN} to use (or not use) a software floating point calling
20498convention. By default, @value{GDBN} selects the calling convention based
20499on the selected architecture and the provided executable file.
20500
20501@item set powerpc vector-abi
20502@itemx show powerpc vector-abi
20503Force @value{GDBN} to use the specified calling convention for vector
20504arguments and return values. The valid options are @samp{auto};
20505@samp{generic}, to avoid vector registers even if they are present;
20506@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
20507registers. By default, @value{GDBN} selects the calling convention
20508based on the selected architecture and the provided executable file.
20509
e09342b5
TJB
20510@item set powerpc exact-watchpoints
20511@itemx show powerpc exact-watchpoints
20512Allow @value{GDBN} to use only one debug register when watching a variable
20513of scalar type, thus assuming that the variable is accessed through the
20514address of its first byte.
20515
8e04817f
AC
20516@kindex target dink32
20517@item target dink32 @var{dev}
20518DINK32 ROM monitor.
104c1213 20519
8e04817f
AC
20520@kindex target ppcbug
20521@item target ppcbug @var{dev}
20522@kindex target ppcbug1
20523@item target ppcbug1 @var{dev}
20524PPCBUG ROM monitor for PowerPC.
104c1213 20525
8e04817f
AC
20526@kindex target sds
20527@item target sds @var{dev}
20528SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 20529@end table
8e04817f 20530
c45da7e6 20531@cindex SDS protocol
d52fb0e9 20532The following commands specific to the SDS protocol are supported
55eddb0f 20533by @value{GDBN}:
c45da7e6
EZ
20534
20535@table @code
20536@item set sdstimeout @var{nsec}
20537@kindex set sdstimeout
20538Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
20539default is 2 seconds.
20540
20541@item show sdstimeout
20542@kindex show sdstimeout
20543Show the current value of the SDS timeout.
20544
20545@item sds @var{command}
20546@kindex sds@r{, a command}
20547Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
20548@end table
20549
c45da7e6 20550
8e04817f
AC
20551@node PA
20552@subsection HP PA Embedded
104c1213
JM
20553
20554@table @code
20555
8e04817f
AC
20556@kindex target op50n
20557@item target op50n @var{dev}
20558OP50N monitor, running on an OKI HPPA board.
20559
20560@kindex target w89k
20561@item target w89k @var{dev}
20562W89K monitor, running on a Winbond HPPA board.
104c1213
JM
20563
20564@end table
20565
8e04817f
AC
20566@node Sparclet
20567@subsection Tsqware Sparclet
104c1213 20568
8e04817f
AC
20569@cindex Sparclet
20570
20571@value{GDBN} enables developers to debug tasks running on
20572Sparclet targets from a Unix host.
20573@value{GDBN} uses code that runs on
20574both the Unix host and on the Sparclet target. The program
20575@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 20576
8e04817f
AC
20577@table @code
20578@item remotetimeout @var{args}
20579@kindex remotetimeout
20580@value{GDBN} supports the option @code{remotetimeout}.
20581This option is set by the user, and @var{args} represents the number of
20582seconds @value{GDBN} waits for responses.
104c1213
JM
20583@end table
20584
8e04817f
AC
20585@cindex compiling, on Sparclet
20586When compiling for debugging, include the options @samp{-g} to get debug
20587information and @samp{-Ttext} to relocate the program to where you wish to
20588load it on the target. You may also want to add the options @samp{-n} or
20589@samp{-N} in order to reduce the size of the sections. Example:
104c1213 20590
474c8240 20591@smallexample
8e04817f 20592sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 20593@end smallexample
104c1213 20594
8e04817f 20595You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 20596
474c8240 20597@smallexample
8e04817f 20598sparclet-aout-objdump --headers --syms prog
474c8240 20599@end smallexample
104c1213 20600
8e04817f
AC
20601@cindex running, on Sparclet
20602Once you have set
20603your Unix execution search path to find @value{GDBN}, you are ready to
20604run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
20605(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 20606
8e04817f
AC
20607@value{GDBN} comes up showing the prompt:
20608
474c8240 20609@smallexample
8e04817f 20610(gdbslet)
474c8240 20611@end smallexample
104c1213
JM
20612
20613@menu
8e04817f
AC
20614* Sparclet File:: Setting the file to debug
20615* Sparclet Connection:: Connecting to Sparclet
20616* Sparclet Download:: Sparclet download
20617* Sparclet Execution:: Running and debugging
104c1213
JM
20618@end menu
20619
8e04817f 20620@node Sparclet File
79a6e687 20621@subsubsection Setting File to Debug
104c1213 20622
8e04817f 20623The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 20624
474c8240 20625@smallexample
8e04817f 20626(gdbslet) file prog
474c8240 20627@end smallexample
104c1213 20628
8e04817f
AC
20629@need 1000
20630@value{GDBN} then attempts to read the symbol table of @file{prog}.
20631@value{GDBN} locates
20632the file by searching the directories listed in the command search
20633path.
12c27660 20634If the file was compiled with debug information (option @samp{-g}), source
8e04817f
AC
20635files will be searched as well.
20636@value{GDBN} locates
20637the source files by searching the directories listed in the directory search
79a6e687 20638path (@pxref{Environment, ,Your Program's Environment}).
8e04817f
AC
20639If it fails
20640to find a file, it displays a message such as:
104c1213 20641
474c8240 20642@smallexample
8e04817f 20643prog: No such file or directory.
474c8240 20644@end smallexample
104c1213 20645
8e04817f
AC
20646When this happens, add the appropriate directories to the search paths with
20647the @value{GDBN} commands @code{path} and @code{dir}, and execute the
20648@code{target} command again.
104c1213 20649
8e04817f
AC
20650@node Sparclet Connection
20651@subsubsection Connecting to Sparclet
104c1213 20652
8e04817f
AC
20653The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
20654To connect to a target on serial port ``@code{ttya}'', type:
104c1213 20655
474c8240 20656@smallexample
8e04817f
AC
20657(gdbslet) target sparclet /dev/ttya
20658Remote target sparclet connected to /dev/ttya
20659main () at ../prog.c:3
474c8240 20660@end smallexample
104c1213 20661
8e04817f
AC
20662@need 750
20663@value{GDBN} displays messages like these:
104c1213 20664
474c8240 20665@smallexample
8e04817f 20666Connected to ttya.
474c8240 20667@end smallexample
104c1213 20668
8e04817f 20669@node Sparclet Download
79a6e687 20670@subsubsection Sparclet Download
104c1213 20671
8e04817f
AC
20672@cindex download to Sparclet
20673Once connected to the Sparclet target,
20674you can use the @value{GDBN}
20675@code{load} command to download the file from the host to the target.
20676The file name and load offset should be given as arguments to the @code{load}
20677command.
20678Since the file format is aout, the program must be loaded to the starting
20679address. You can use @code{objdump} to find out what this value is. The load
20680offset is an offset which is added to the VMA (virtual memory address)
20681of each of the file's sections.
20682For instance, if the program
20683@file{prog} was linked to text address 0x1201000, with data at 0x12010160
20684and bss at 0x12010170, in @value{GDBN}, type:
104c1213 20685
474c8240 20686@smallexample
8e04817f
AC
20687(gdbslet) load prog 0x12010000
20688Loading section .text, size 0xdb0 vma 0x12010000
474c8240 20689@end smallexample
104c1213 20690
8e04817f
AC
20691If the code is loaded at a different address then what the program was linked
20692to, you may need to use the @code{section} and @code{add-symbol-file} commands
20693to tell @value{GDBN} where to map the symbol table.
20694
20695@node Sparclet Execution
79a6e687 20696@subsubsection Running and Debugging
8e04817f
AC
20697
20698@cindex running and debugging Sparclet programs
20699You can now begin debugging the task using @value{GDBN}'s execution control
20700commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
20701manual for the list of commands.
20702
474c8240 20703@smallexample
8e04817f
AC
20704(gdbslet) b main
20705Breakpoint 1 at 0x12010000: file prog.c, line 3.
20706(gdbslet) run
20707Starting program: prog
20708Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
207093 char *symarg = 0;
20710(gdbslet) step
207114 char *execarg = "hello!";
20712(gdbslet)
474c8240 20713@end smallexample
8e04817f
AC
20714
20715@node Sparclite
20716@subsection Fujitsu Sparclite
104c1213
JM
20717
20718@table @code
20719
8e04817f
AC
20720@kindex target sparclite
20721@item target sparclite @var{dev}
20722Fujitsu sparclite boards, used only for the purpose of loading.
20723You must use an additional command to debug the program.
20724For example: target remote @var{dev} using @value{GDBN} standard
20725remote protocol.
104c1213
JM
20726
20727@end table
20728
8e04817f
AC
20729@node Z8000
20730@subsection Zilog Z8000
104c1213 20731
8e04817f
AC
20732@cindex Z8000
20733@cindex simulator, Z8000
20734@cindex Zilog Z8000 simulator
104c1213 20735
8e04817f
AC
20736When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
20737a Z8000 simulator.
20738
20739For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
20740unsegmented variant of the Z8000 architecture) or the Z8001 (the
20741segmented variant). The simulator recognizes which architecture is
20742appropriate by inspecting the object code.
104c1213 20743
8e04817f
AC
20744@table @code
20745@item target sim @var{args}
20746@kindex sim
20747@kindex target sim@r{, with Z8000}
20748Debug programs on a simulated CPU. If the simulator supports setup
20749options, specify them via @var{args}.
104c1213
JM
20750@end table
20751
8e04817f
AC
20752@noindent
20753After specifying this target, you can debug programs for the simulated
20754CPU in the same style as programs for your host computer; use the
20755@code{file} command to load a new program image, the @code{run} command
20756to run your program, and so on.
20757
20758As well as making available all the usual machine registers
20759(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
20760additional items of information as specially named registers:
104c1213
JM
20761
20762@table @code
20763
8e04817f
AC
20764@item cycles
20765Counts clock-ticks in the simulator.
104c1213 20766
8e04817f
AC
20767@item insts
20768Counts instructions run in the simulator.
104c1213 20769
8e04817f
AC
20770@item time
20771Execution time in 60ths of a second.
104c1213 20772
8e04817f 20773@end table
104c1213 20774
8e04817f
AC
20775You can refer to these values in @value{GDBN} expressions with the usual
20776conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
20777conditional breakpoint that suspends only after at least 5000
20778simulated clock ticks.
104c1213 20779
a64548ea
EZ
20780@node AVR
20781@subsection Atmel AVR
20782@cindex AVR
20783
20784When configured for debugging the Atmel AVR, @value{GDBN} supports the
20785following AVR-specific commands:
20786
20787@table @code
20788@item info io_registers
20789@kindex info io_registers@r{, AVR}
20790@cindex I/O registers (Atmel AVR)
20791This command displays information about the AVR I/O registers. For
20792each register, @value{GDBN} prints its number and value.
20793@end table
20794
20795@node CRIS
20796@subsection CRIS
20797@cindex CRIS
20798
20799When configured for debugging CRIS, @value{GDBN} provides the
20800following CRIS-specific commands:
20801
20802@table @code
20803@item set cris-version @var{ver}
20804@cindex CRIS version
e22e55c9
OF
20805Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
20806The CRIS version affects register names and sizes. This command is useful in
20807case autodetection of the CRIS version fails.
a64548ea
EZ
20808
20809@item show cris-version
20810Show the current CRIS version.
20811
20812@item set cris-dwarf2-cfi
20813@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
20814Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
20815Change to @samp{off} when using @code{gcc-cris} whose version is below
20816@code{R59}.
a64548ea
EZ
20817
20818@item show cris-dwarf2-cfi
20819Show the current state of using DWARF-2 CFI.
e22e55c9
OF
20820
20821@item set cris-mode @var{mode}
20822@cindex CRIS mode
20823Set the current CRIS mode to @var{mode}. It should only be changed when
20824debugging in guru mode, in which case it should be set to
20825@samp{guru} (the default is @samp{normal}).
20826
20827@item show cris-mode
20828Show the current CRIS mode.
a64548ea
EZ
20829@end table
20830
20831@node Super-H
20832@subsection Renesas Super-H
20833@cindex Super-H
20834
20835For the Renesas Super-H processor, @value{GDBN} provides these
20836commands:
20837
20838@table @code
c055b101
CV
20839@item set sh calling-convention @var{convention}
20840@kindex set sh calling-convention
20841Set the calling-convention used when calling functions from @value{GDBN}.
20842Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
20843With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
20844convention. If the DWARF-2 information of the called function specifies
20845that the function follows the Renesas calling convention, the function
20846is called using the Renesas calling convention. If the calling convention
20847is set to @samp{renesas}, the Renesas calling convention is always used,
20848regardless of the DWARF-2 information. This can be used to override the
20849default of @samp{gcc} if debug information is missing, or the compiler
20850does not emit the DWARF-2 calling convention entry for a function.
20851
20852@item show sh calling-convention
20853@kindex show sh calling-convention
20854Show the current calling convention setting.
20855
a64548ea
EZ
20856@end table
20857
20858
8e04817f
AC
20859@node Architectures
20860@section Architectures
104c1213 20861
8e04817f
AC
20862This section describes characteristics of architectures that affect
20863all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 20864
8e04817f 20865@menu
430ed3f0 20866* AArch64::
9c16f35a 20867* i386::
8e04817f
AC
20868* Alpha::
20869* MIPS::
a64548ea 20870* HPPA:: HP PA architecture
23d964e7 20871* SPU:: Cell Broadband Engine SPU architecture
4acd40f3 20872* PowerPC::
8e04817f 20873@end menu
104c1213 20874
430ed3f0
MS
20875@node AArch64
20876@subsection AArch64
20877@cindex AArch64 support
20878
20879When @value{GDBN} is debugging the AArch64 architecture, it provides the
20880following special commands:
20881
20882@table @code
20883@item set debug aarch64
20884@kindex set debug aarch64
20885This command determines whether AArch64 architecture-specific debugging
20886messages are to be displayed.
20887
20888@item show debug aarch64
20889Show whether AArch64 debugging messages are displayed.
20890
20891@end table
20892
9c16f35a 20893@node i386
db2e3e2e 20894@subsection x86 Architecture-specific Issues
9c16f35a
EZ
20895
20896@table @code
20897@item set struct-convention @var{mode}
20898@kindex set struct-convention
20899@cindex struct return convention
20900@cindex struct/union returned in registers
20901Set the convention used by the inferior to return @code{struct}s and
20902@code{union}s from functions to @var{mode}. Possible values of
20903@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
20904default). @code{"default"} or @code{"pcc"} means that @code{struct}s
20905are returned on the stack, while @code{"reg"} means that a
20906@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
20907be returned in a register.
20908
20909@item show struct-convention
20910@kindex show struct-convention
20911Show the current setting of the convention to return @code{struct}s
20912from functions.
20913@end table
20914
8e04817f
AC
20915@node Alpha
20916@subsection Alpha
104c1213 20917
8e04817f 20918See the following section.
104c1213 20919
8e04817f 20920@node MIPS
eb17f351 20921@subsection @acronym{MIPS}
104c1213 20922
8e04817f 20923@cindex stack on Alpha
eb17f351 20924@cindex stack on @acronym{MIPS}
8e04817f 20925@cindex Alpha stack
eb17f351
EZ
20926@cindex @acronym{MIPS} stack
20927Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
8e04817f
AC
20928sometimes requires @value{GDBN} to search backward in the object code to
20929find the beginning of a function.
104c1213 20930
eb17f351 20931@cindex response time, @acronym{MIPS} debugging
8e04817f
AC
20932To improve response time (especially for embedded applications, where
20933@value{GDBN} may be restricted to a slow serial line for this search)
20934you may want to limit the size of this search, using one of these
20935commands:
104c1213 20936
8e04817f 20937@table @code
eb17f351 20938@cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
8e04817f
AC
20939@item set heuristic-fence-post @var{limit}
20940Restrict @value{GDBN} to examining at most @var{limit} bytes in its
20941search for the beginning of a function. A value of @var{0} (the
20942default) means there is no limit. However, except for @var{0}, the
20943larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
20944and therefore the longer it takes to run. You should only need to use
20945this command when debugging a stripped executable.
104c1213 20946
8e04817f
AC
20947@item show heuristic-fence-post
20948Display the current limit.
20949@end table
104c1213
JM
20950
20951@noindent
8e04817f 20952These commands are available @emph{only} when @value{GDBN} is configured
eb17f351 20953for debugging programs on Alpha or @acronym{MIPS} processors.
104c1213 20954
eb17f351 20955Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
a64548ea
EZ
20956programs:
20957
20958@table @code
a64548ea
EZ
20959@item set mips abi @var{arg}
20960@kindex set mips abi
eb17f351
EZ
20961@cindex set ABI for @acronym{MIPS}
20962Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
a64548ea
EZ
20963values of @var{arg} are:
20964
20965@table @samp
20966@item auto
20967The default ABI associated with the current binary (this is the
20968default).
20969@item o32
20970@item o64
20971@item n32
20972@item n64
20973@item eabi32
20974@item eabi64
a64548ea
EZ
20975@end table
20976
20977@item show mips abi
20978@kindex show mips abi
eb17f351 20979Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
a64548ea 20980
4cc0665f
MR
20981@item set mips compression @var{arg}
20982@kindex set mips compression
20983@cindex code compression, @acronym{MIPS}
20984Tell @value{GDBN} which @acronym{MIPS} compressed
20985@acronym{ISA, Instruction Set Architecture} encoding is used by the
20986inferior. @value{GDBN} uses this for code disassembly and other
20987internal interpretation purposes. This setting is only referred to
20988when no executable has been associated with the debugging session or
20989the executable does not provide information about the encoding it uses.
20990Otherwise this setting is automatically updated from information
20991provided by the executable.
20992
20993Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
20994The default compressed @acronym{ISA} encoding is @samp{mips16}, as
20995executables containing @acronym{MIPS16} code frequently are not
20996identified as such.
20997
20998This setting is ``sticky''; that is, it retains its value across
20999debugging sessions until reset either explicitly with this command or
21000implicitly from an executable.
21001
21002The compiler and/or assembler typically add symbol table annotations to
21003identify functions compiled for the @acronym{MIPS16} or
21004@acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
21005are present, @value{GDBN} uses them in preference to the global
21006compressed @acronym{ISA} encoding setting.
21007
21008@item show mips compression
21009@kindex show mips compression
21010Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
21011@value{GDBN} to debug the inferior.
21012
a64548ea
EZ
21013@item set mipsfpu
21014@itemx show mipsfpu
21015@xref{MIPS Embedded, set mipsfpu}.
21016
21017@item set mips mask-address @var{arg}
21018@kindex set mips mask-address
eb17f351 21019@cindex @acronym{MIPS} addresses, masking
a64548ea 21020This command determines whether the most-significant 32 bits of 64-bit
eb17f351 21021@acronym{MIPS} addresses are masked off. The argument @var{arg} can be
a64548ea
EZ
21022@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
21023setting, which lets @value{GDBN} determine the correct value.
21024
21025@item show mips mask-address
21026@kindex show mips mask-address
eb17f351 21027Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
a64548ea
EZ
21028not.
21029
21030@item set remote-mips64-transfers-32bit-regs
21031@kindex set remote-mips64-transfers-32bit-regs
eb17f351
EZ
21032This command controls compatibility with 64-bit @acronym{MIPS} targets that
21033transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
a64548ea
EZ
21034that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
21035and 64 bits for other registers, set this option to @samp{on}.
21036
21037@item show remote-mips64-transfers-32bit-regs
21038@kindex show remote-mips64-transfers-32bit-regs
eb17f351 21039Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
a64548ea
EZ
21040
21041@item set debug mips
21042@kindex set debug mips
eb17f351 21043This command turns on and off debugging messages for the @acronym{MIPS}-specific
a64548ea
EZ
21044target code in @value{GDBN}.
21045
21046@item show debug mips
21047@kindex show debug mips
eb17f351 21048Show the current setting of @acronym{MIPS} debugging messages.
a64548ea
EZ
21049@end table
21050
21051
21052@node HPPA
21053@subsection HPPA
21054@cindex HPPA support
21055
d3e8051b 21056When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
21057following special commands:
21058
21059@table @code
21060@item set debug hppa
21061@kindex set debug hppa
db2e3e2e 21062This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
21063messages are to be displayed.
21064
21065@item show debug hppa
21066Show whether HPPA debugging messages are displayed.
21067
21068@item maint print unwind @var{address}
21069@kindex maint print unwind@r{, HPPA}
21070This command displays the contents of the unwind table entry at the
21071given @var{address}.
21072
21073@end table
21074
104c1213 21075
23d964e7
UW
21076@node SPU
21077@subsection Cell Broadband Engine SPU architecture
21078@cindex Cell Broadband Engine
21079@cindex SPU
21080
21081When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
21082it provides the following special commands:
21083
21084@table @code
21085@item info spu event
21086@kindex info spu
21087Display SPU event facility status. Shows current event mask
21088and pending event status.
21089
21090@item info spu signal
21091Display SPU signal notification facility status. Shows pending
21092signal-control word and signal notification mode of both signal
21093notification channels.
21094
21095@item info spu mailbox
21096Display SPU mailbox facility status. Shows all pending entries,
21097in order of processing, in each of the SPU Write Outbound,
21098SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
21099
21100@item info spu dma
21101Display MFC DMA status. Shows all pending commands in the MFC
21102DMA queue. For each entry, opcode, tag, class IDs, effective
21103and local store addresses and transfer size are shown.
21104
21105@item info spu proxydma
21106Display MFC Proxy-DMA status. Shows all pending commands in the MFC
21107Proxy-DMA queue. For each entry, opcode, tag, class IDs, effective
21108and local store addresses and transfer size are shown.
21109
21110@end table
21111
3285f3fe
UW
21112When @value{GDBN} is debugging a combined PowerPC/SPU application
21113on the Cell Broadband Engine, it provides in addition the following
21114special commands:
21115
21116@table @code
21117@item set spu stop-on-load @var{arg}
21118@kindex set spu
21119Set whether to stop for new SPE threads. When set to @code{on}, @value{GDBN}
21120will give control to the user when a new SPE thread enters its @code{main}
21121function. The default is @code{off}.
21122
21123@item show spu stop-on-load
21124@kindex show spu
21125Show whether to stop for new SPE threads.
21126
ff1a52c6
UW
21127@item set spu auto-flush-cache @var{arg}
21128Set whether to automatically flush the software-managed cache. When set to
21129@code{on}, @value{GDBN} will automatically cause the SPE software-managed
21130cache to be flushed whenever SPE execution stops. This provides a consistent
21131view of PowerPC memory that is accessed via the cache. If an application
21132does not use the software-managed cache, this option has no effect.
21133
21134@item show spu auto-flush-cache
21135Show whether to automatically flush the software-managed cache.
21136
3285f3fe
UW
21137@end table
21138
4acd40f3
TJB
21139@node PowerPC
21140@subsection PowerPC
21141@cindex PowerPC architecture
21142
21143When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
21144pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
21145numbers stored in the floating point registers. These values must be stored
21146in two consecutive registers, always starting at an even register like
21147@code{f0} or @code{f2}.
21148
21149The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
21150by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
21151@code{f2} and @code{f3} for @code{$dl1} and so on.
21152
aeac0ff9 21153For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
677c5bb1
LM
21154wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
21155
23d964e7 21156
8e04817f
AC
21157@node Controlling GDB
21158@chapter Controlling @value{GDBN}
21159
21160You can alter the way @value{GDBN} interacts with you by using the
21161@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 21162data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
21163described here.
21164
21165@menu
21166* Prompt:: Prompt
21167* Editing:: Command editing
d620b259 21168* Command History:: Command history
8e04817f
AC
21169* Screen Size:: Screen size
21170* Numbers:: Numbers
1e698235 21171* ABI:: Configuring the current ABI
bf88dd68 21172* Auto-loading:: Automatically loading associated files
8e04817f
AC
21173* Messages/Warnings:: Optional warnings and messages
21174* Debugging Output:: Optional messages about internal happenings
14fb1bac 21175* Other Misc Settings:: Other Miscellaneous Settings
8e04817f
AC
21176@end menu
21177
21178@node Prompt
21179@section Prompt
104c1213 21180
8e04817f 21181@cindex prompt
104c1213 21182
8e04817f
AC
21183@value{GDBN} indicates its readiness to read a command by printing a string
21184called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
21185can change the prompt string with the @code{set prompt} command. For
21186instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
21187the prompt in one of the @value{GDBN} sessions so that you can always tell
21188which one you are talking to.
104c1213 21189
8e04817f
AC
21190@emph{Note:} @code{set prompt} does not add a space for you after the
21191prompt you set. This allows you to set a prompt which ends in a space
21192or a prompt that does not.
104c1213 21193
8e04817f
AC
21194@table @code
21195@kindex set prompt
21196@item set prompt @var{newprompt}
21197Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 21198
8e04817f
AC
21199@kindex show prompt
21200@item show prompt
21201Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
21202@end table
21203
fa3a4f15
PM
21204Versions of @value{GDBN} that ship with Python scripting enabled have
21205prompt extensions. The commands for interacting with these extensions
21206are:
21207
21208@table @code
21209@kindex set extended-prompt
21210@item set extended-prompt @var{prompt}
21211Set an extended prompt that allows for substitutions.
21212@xref{gdb.prompt}, for a list of escape sequences that can be used for
21213substitution. Any escape sequences specified as part of the prompt
21214string are replaced with the corresponding strings each time the prompt
21215is displayed.
21216
21217For example:
21218
21219@smallexample
21220set extended-prompt Current working directory: \w (gdb)
21221@end smallexample
21222
21223Note that when an extended-prompt is set, it takes control of the
21224@var{prompt_hook} hook. @xref{prompt_hook}, for further information.
21225
21226@kindex show extended-prompt
21227@item show extended-prompt
21228Prints the extended prompt. Any escape sequences specified as part of
21229the prompt string with @code{set extended-prompt}, are replaced with the
21230corresponding strings each time the prompt is displayed.
21231@end table
21232
8e04817f 21233@node Editing
79a6e687 21234@section Command Editing
8e04817f
AC
21235@cindex readline
21236@cindex command line editing
104c1213 21237
703663ab 21238@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
21239@sc{gnu} library provides consistent behavior for programs which provide a
21240command line interface to the user. Advantages are @sc{gnu} Emacs-style
21241or @dfn{vi}-style inline editing of commands, @code{csh}-like history
21242substitution, and a storage and recall of command history across
21243debugging sessions.
104c1213 21244
8e04817f
AC
21245You may control the behavior of command line editing in @value{GDBN} with the
21246command @code{set}.
104c1213 21247
8e04817f
AC
21248@table @code
21249@kindex set editing
21250@cindex editing
21251@item set editing
21252@itemx set editing on
21253Enable command line editing (enabled by default).
104c1213 21254
8e04817f
AC
21255@item set editing off
21256Disable command line editing.
104c1213 21257
8e04817f
AC
21258@kindex show editing
21259@item show editing
21260Show whether command line editing is enabled.
104c1213
JM
21261@end table
21262
39037522
TT
21263@ifset SYSTEM_READLINE
21264@xref{Command Line Editing, , , rluserman, GNU Readline Library},
21265@end ifset
21266@ifclear SYSTEM_READLINE
21267@xref{Command Line Editing},
21268@end ifclear
21269for more details about the Readline
703663ab
EZ
21270interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
21271encouraged to read that chapter.
21272
d620b259 21273@node Command History
79a6e687 21274@section Command History
703663ab 21275@cindex command history
8e04817f
AC
21276
21277@value{GDBN} can keep track of the commands you type during your
21278debugging sessions, so that you can be certain of precisely what
21279happened. Use these commands to manage the @value{GDBN} command
21280history facility.
104c1213 21281
703663ab 21282@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
39037522
TT
21283package, to provide the history facility.
21284@ifset SYSTEM_READLINE
21285@xref{Using History Interactively, , , history, GNU History Library},
21286@end ifset
21287@ifclear SYSTEM_READLINE
21288@xref{Using History Interactively},
21289@end ifclear
21290for the detailed description of the History library.
703663ab 21291
d620b259 21292To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
21293the state which is seen by users, prefix it with @samp{server }
21294(@pxref{Server Prefix}). This
d620b259
NR
21295means that this command will not affect the command history, nor will it
21296affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
21297pressed on a line by itself.
21298
21299@cindex @code{server}, command prefix
21300The server prefix does not affect the recording of values into the value
21301history; to print a value without recording it into the value history,
21302use the @code{output} command instead of the @code{print} command.
21303
703663ab
EZ
21304Here is the description of @value{GDBN} commands related to command
21305history.
21306
104c1213 21307@table @code
8e04817f
AC
21308@cindex history substitution
21309@cindex history file
21310@kindex set history filename
4644b6e3 21311@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
21312@item set history filename @var{fname}
21313Set the name of the @value{GDBN} command history file to @var{fname}.
21314This is the file where @value{GDBN} reads an initial command history
21315list, and where it writes the command history from this session when it
21316exits. You can access this list through history expansion or through
21317the history command editing characters listed below. This file defaults
21318to the value of the environment variable @code{GDBHISTFILE}, or to
21319@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
21320is not set.
104c1213 21321
9c16f35a
EZ
21322@cindex save command history
21323@kindex set history save
8e04817f
AC
21324@item set history save
21325@itemx set history save on
21326Record command history in a file, whose name may be specified with the
21327@code{set history filename} command. By default, this option is disabled.
104c1213 21328
8e04817f
AC
21329@item set history save off
21330Stop recording command history in a file.
104c1213 21331
8e04817f 21332@cindex history size
9c16f35a 21333@kindex set history size
6fc08d32 21334@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
21335@item set history size @var{size}
21336Set the number of commands which @value{GDBN} keeps in its history list.
21337This defaults to the value of the environment variable
21338@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
21339@end table
21340
8e04817f 21341History expansion assigns special meaning to the character @kbd{!}.
39037522
TT
21342@ifset SYSTEM_READLINE
21343@xref{Event Designators, , , history, GNU History Library},
21344@end ifset
21345@ifclear SYSTEM_READLINE
21346@xref{Event Designators},
21347@end ifclear
21348for more details.
8e04817f 21349
703663ab 21350@cindex history expansion, turn on/off
8e04817f
AC
21351Since @kbd{!} is also the logical not operator in C, history expansion
21352is off by default. If you decide to enable history expansion with the
21353@code{set history expansion on} command, you may sometimes need to
21354follow @kbd{!} (when it is used as logical not, in an expression) with
21355a space or a tab to prevent it from being expanded. The readline
21356history facilities do not attempt substitution on the strings
21357@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
21358
21359The commands to control history expansion are:
104c1213
JM
21360
21361@table @code
8e04817f
AC
21362@item set history expansion on
21363@itemx set history expansion
703663ab 21364@kindex set history expansion
8e04817f 21365Enable history expansion. History expansion is off by default.
104c1213 21366
8e04817f
AC
21367@item set history expansion off
21368Disable history expansion.
104c1213 21369
8e04817f
AC
21370@c @group
21371@kindex show history
21372@item show history
21373@itemx show history filename
21374@itemx show history save
21375@itemx show history size
21376@itemx show history expansion
21377These commands display the state of the @value{GDBN} history parameters.
21378@code{show history} by itself displays all four states.
21379@c @end group
21380@end table
21381
21382@table @code
9c16f35a
EZ
21383@kindex show commands
21384@cindex show last commands
21385@cindex display command history
8e04817f
AC
21386@item show commands
21387Display the last ten commands in the command history.
104c1213 21388
8e04817f
AC
21389@item show commands @var{n}
21390Print ten commands centered on command number @var{n}.
21391
21392@item show commands +
21393Print ten commands just after the commands last printed.
104c1213
JM
21394@end table
21395
8e04817f 21396@node Screen Size
79a6e687 21397@section Screen Size
8e04817f
AC
21398@cindex size of screen
21399@cindex pauses in output
104c1213 21400
8e04817f
AC
21401Certain commands to @value{GDBN} may produce large amounts of
21402information output to the screen. To help you read all of it,
21403@value{GDBN} pauses and asks you for input at the end of each page of
21404output. Type @key{RET} when you want to continue the output, or @kbd{q}
21405to discard the remaining output. Also, the screen width setting
21406determines when to wrap lines of output. Depending on what is being
21407printed, @value{GDBN} tries to break the line at a readable place,
21408rather than simply letting it overflow onto the following line.
21409
21410Normally @value{GDBN} knows the size of the screen from the terminal
21411driver software. For example, on Unix @value{GDBN} uses the termcap data base
21412together with the value of the @code{TERM} environment variable and the
21413@code{stty rows} and @code{stty cols} settings. If this is not correct,
21414you can override it with the @code{set height} and @code{set
21415width} commands:
21416
21417@table @code
21418@kindex set height
21419@kindex set width
21420@kindex show width
21421@kindex show height
21422@item set height @var{lpp}
21423@itemx show height
21424@itemx set width @var{cpl}
21425@itemx show width
21426These @code{set} commands specify a screen height of @var{lpp} lines and
21427a screen width of @var{cpl} characters. The associated @code{show}
21428commands display the current settings.
104c1213 21429
8e04817f
AC
21430If you specify a height of zero lines, @value{GDBN} does not pause during
21431output no matter how long the output is. This is useful if output is to a
21432file or to an editor buffer.
104c1213 21433
8e04817f
AC
21434Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
21435from wrapping its output.
9c16f35a
EZ
21436
21437@item set pagination on
21438@itemx set pagination off
21439@kindex set pagination
21440Turn the output pagination on or off; the default is on. Turning
7c953934
TT
21441pagination off is the alternative to @code{set height 0}. Note that
21442running @value{GDBN} with the @option{--batch} option (@pxref{Mode
21443Options, -batch}) also automatically disables pagination.
9c16f35a
EZ
21444
21445@item show pagination
21446@kindex show pagination
21447Show the current pagination mode.
104c1213
JM
21448@end table
21449
8e04817f
AC
21450@node Numbers
21451@section Numbers
21452@cindex number representation
21453@cindex entering numbers
104c1213 21454
8e04817f
AC
21455You can always enter numbers in octal, decimal, or hexadecimal in
21456@value{GDBN} by the usual conventions: octal numbers begin with
21457@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
21458begin with @samp{0x}. Numbers that neither begin with @samp{0} or
21459@samp{0x}, nor end with a @samp{.} are, by default, entered in base
2146010; likewise, the default display for numbers---when no particular
21461format is specified---is base 10. You can change the default base for
21462both input and output with the commands described below.
104c1213 21463
8e04817f
AC
21464@table @code
21465@kindex set input-radix
21466@item set input-radix @var{base}
21467Set the default base for numeric input. Supported choices
21468for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 21469specified either unambiguously or using the current input radix; for
8e04817f 21470example, any of
104c1213 21471
8e04817f 21472@smallexample
9c16f35a
EZ
21473set input-radix 012
21474set input-radix 10.
21475set input-radix 0xa
8e04817f 21476@end smallexample
104c1213 21477
8e04817f 21478@noindent
9c16f35a 21479sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
21480leaves the input radix unchanged, no matter what it was, since
21481@samp{10}, being without any leading or trailing signs of its base, is
21482interpreted in the current radix. Thus, if the current radix is 16,
21483@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
21484change the radix.
104c1213 21485
8e04817f
AC
21486@kindex set output-radix
21487@item set output-radix @var{base}
21488Set the default base for numeric display. Supported choices
21489for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 21490specified either unambiguously or using the current input radix.
104c1213 21491
8e04817f
AC
21492@kindex show input-radix
21493@item show input-radix
21494Display the current default base for numeric input.
104c1213 21495
8e04817f
AC
21496@kindex show output-radix
21497@item show output-radix
21498Display the current default base for numeric display.
9c16f35a
EZ
21499
21500@item set radix @r{[}@var{base}@r{]}
21501@itemx show radix
21502@kindex set radix
21503@kindex show radix
21504These commands set and show the default base for both input and output
21505of numbers. @code{set radix} sets the radix of input and output to
21506the same base; without an argument, it resets the radix back to its
21507default value of 10.
21508
8e04817f 21509@end table
104c1213 21510
1e698235 21511@node ABI
79a6e687 21512@section Configuring the Current ABI
1e698235
DJ
21513
21514@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
21515application automatically. However, sometimes you need to override its
21516conclusions. Use these commands to manage @value{GDBN}'s view of the
21517current ABI.
21518
98b45e30
DJ
21519@cindex OS ABI
21520@kindex set osabi
b4e9345d 21521@kindex show osabi
430ed3f0 21522@cindex Newlib OS ABI and its influence on the longjmp handling
98b45e30
DJ
21523
21524One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 21525system targets, either via remote debugging or native emulation.
98b45e30
DJ
21526@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
21527but you can override its conclusion using the @code{set osabi} command.
21528One example where this is useful is in debugging of binaries which use
21529an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
21530not have the same identifying marks that the standard C library for your
21531platform provides.
21532
430ed3f0
MS
21533When @value{GDBN} is debugging the AArch64 architecture, it provides a
21534``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
21535@code{longjmp} when debugging binaries that use the @sc{newlib} C library.
21536The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
21537
98b45e30
DJ
21538@table @code
21539@item show osabi
21540Show the OS ABI currently in use.
21541
21542@item set osabi
21543With no argument, show the list of registered available OS ABI's.
21544
21545@item set osabi @var{abi}
21546Set the current OS ABI to @var{abi}.
21547@end table
21548
1e698235 21549@cindex float promotion
1e698235
DJ
21550
21551Generally, the way that an argument of type @code{float} is passed to a
21552function depends on whether the function is prototyped. For a prototyped
21553(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
21554according to the architecture's convention for @code{float}. For unprototyped
21555(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
21556@code{double} and then passed.
21557
21558Unfortunately, some forms of debug information do not reliably indicate whether
21559a function is prototyped. If @value{GDBN} calls a function that is not marked
21560as prototyped, it consults @kbd{set coerce-float-to-double}.
21561
21562@table @code
a8f24a35 21563@kindex set coerce-float-to-double
1e698235
DJ
21564@item set coerce-float-to-double
21565@itemx set coerce-float-to-double on
21566Arguments of type @code{float} will be promoted to @code{double} when passed
21567to an unprototyped function. This is the default setting.
21568
21569@item set coerce-float-to-double off
21570Arguments of type @code{float} will be passed directly to unprototyped
21571functions.
9c16f35a
EZ
21572
21573@kindex show coerce-float-to-double
21574@item show coerce-float-to-double
21575Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
21576@end table
21577
f1212245
DJ
21578@kindex set cp-abi
21579@kindex show cp-abi
21580@value{GDBN} needs to know the ABI used for your program's C@t{++}
21581objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
21582used to build your application. @value{GDBN} only fully supports
21583programs with a single C@t{++} ABI; if your program contains code using
21584multiple C@t{++} ABI's or if @value{GDBN} can not identify your
21585program's ABI correctly, you can tell @value{GDBN} which ABI to use.
21586Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
21587before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
21588``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
21589use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
21590``auto''.
21591
21592@table @code
21593@item show cp-abi
21594Show the C@t{++} ABI currently in use.
21595
21596@item set cp-abi
21597With no argument, show the list of supported C@t{++} ABI's.
21598
21599@item set cp-abi @var{abi}
21600@itemx set cp-abi auto
21601Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
21602@end table
21603
bf88dd68
JK
21604@node Auto-loading
21605@section Automatically loading associated files
21606@cindex auto-loading
21607
21608@value{GDBN} sometimes reads files with commands and settings automatically,
21609without being explicitly told so by the user. We call this feature
21610@dfn{auto-loading}. While auto-loading is useful for automatically adapting
21611@value{GDBN} to the needs of your project, it can sometimes produce unexpected
21612results or introduce security risks (e.g., if the file comes from untrusted
21613sources).
21614
c1668e4e
JK
21615Note that loading of these associated files (including the local @file{.gdbinit}
21616file) requires accordingly configured @code{auto-load safe-path}
21617(@pxref{Auto-loading safe path}).
21618
bf88dd68
JK
21619For these reasons, @value{GDBN} includes commands and options to let you
21620control when to auto-load files and which files should be auto-loaded.
21621
21622@table @code
21623@anchor{set auto-load off}
21624@kindex set auto-load off
21625@item set auto-load off
21626Globally disable loading of all auto-loaded files.
21627You may want to use this command with the @samp{-iex} option
21628(@pxref{Option -init-eval-command}) such as:
21629@smallexample
21630$ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
21631@end smallexample
21632
21633Be aware that system init file (@pxref{System-wide configuration})
21634and init files from your home directory (@pxref{Home Directory Init File})
21635still get read (as they come from generally trusted directories).
21636To prevent @value{GDBN} from auto-loading even those init files, use the
21637@option{-nx} option (@pxref{Mode Options}), in addition to
21638@code{set auto-load no}.
21639
21640@anchor{show auto-load}
21641@kindex show auto-load
21642@item show auto-load
21643Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
21644or disabled.
21645
21646@smallexample
21647(gdb) show auto-load
21648gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
21649libthread-db: Auto-loading of inferior specific libthread_db is on.
1ccacbcd
JK
21650local-gdbinit: Auto-loading of .gdbinit script from current directory
21651 is on.
bf88dd68 21652python-scripts: Auto-loading of Python scripts is on.
bccbefd2 21653safe-path: List of directories from which it is safe to auto-load files
1564a261 21654 is $debugdir:$datadir/auto-load.
7349ff92 21655scripts-directory: List of directories from which to load auto-loaded scripts
1564a261 21656 is $debugdir:$datadir/auto-load.
bf88dd68
JK
21657@end smallexample
21658
21659@anchor{info auto-load}
21660@kindex info auto-load
21661@item info auto-load
21662Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
21663not.
21664
21665@smallexample
21666(gdb) info auto-load
21667gdb-scripts:
21668Loaded Script
21669Yes /home/user/gdb/gdb-gdb.gdb
21670libthread-db: No auto-loaded libthread-db.
1ccacbcd
JK
21671local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
21672 loaded.
bf88dd68
JK
21673python-scripts:
21674Loaded Script
21675Yes /home/user/gdb/gdb-gdb.py
21676@end smallexample
21677@end table
21678
21679These are various kinds of files @value{GDBN} can automatically load:
21680
21681@itemize @bullet
21682@item
21683@xref{objfile-gdb.py file}, controlled by @ref{set auto-load python-scripts}.
21684@item
21685@xref{objfile-gdb.gdb file}, controlled by @ref{set auto-load gdb-scripts}.
21686@item
21687@xref{dotdebug_gdb_scripts section},
21688controlled by @ref{set auto-load python-scripts}.
21689@item
21690@xref{Init File in the Current Directory},
21691controlled by @ref{set auto-load local-gdbinit}.
21692@item
21693@xref{libthread_db.so.1 file}, controlled by @ref{set auto-load libthread-db}.
21694@end itemize
21695
21696These are @value{GDBN} control commands for the auto-loading:
21697
21698@multitable @columnfractions .5 .5
21699@item @xref{set auto-load off}.
21700@tab Disable auto-loading globally.
21701@item @xref{show auto-load}.
21702@tab Show setting of all kinds of files.
21703@item @xref{info auto-load}.
21704@tab Show state of all kinds of files.
21705@item @xref{set auto-load gdb-scripts}.
21706@tab Control for @value{GDBN} command scripts.
21707@item @xref{show auto-load gdb-scripts}.
21708@tab Show setting of @value{GDBN} command scripts.
21709@item @xref{info auto-load gdb-scripts}.
21710@tab Show state of @value{GDBN} command scripts.
21711@item @xref{set auto-load python-scripts}.
21712@tab Control for @value{GDBN} Python scripts.
21713@item @xref{show auto-load python-scripts}.
21714@tab Show setting of @value{GDBN} Python scripts.
21715@item @xref{info auto-load python-scripts}.
21716@tab Show state of @value{GDBN} Python scripts.
7349ff92
JK
21717@item @xref{set auto-load scripts-directory}.
21718@tab Control for @value{GDBN} auto-loaded scripts location.
21719@item @xref{show auto-load scripts-directory}.
21720@tab Show @value{GDBN} auto-loaded scripts location.
bf88dd68
JK
21721@item @xref{set auto-load local-gdbinit}.
21722@tab Control for init file in the current directory.
21723@item @xref{show auto-load local-gdbinit}.
21724@tab Show setting of init file in the current directory.
21725@item @xref{info auto-load local-gdbinit}.
21726@tab Show state of init file in the current directory.
21727@item @xref{set auto-load libthread-db}.
21728@tab Control for thread debugging library.
21729@item @xref{show auto-load libthread-db}.
21730@tab Show setting of thread debugging library.
21731@item @xref{info auto-load libthread-db}.
21732@tab Show state of thread debugging library.
bccbefd2
JK
21733@item @xref{set auto-load safe-path}.
21734@tab Control directories trusted for automatic loading.
21735@item @xref{show auto-load safe-path}.
21736@tab Show directories trusted for automatic loading.
21737@item @xref{add-auto-load-safe-path}.
21738@tab Add directory trusted for automatic loading.
bf88dd68
JK
21739@end multitable
21740
21741@menu
21742* Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
21743* libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
21744* objfile-gdb.gdb file:: @samp{set/show/info auto-load gdb-script}
bccbefd2 21745* Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
4dc84fd1 21746* Auto-loading verbose mode:: @samp{set/show debug auto-load}
bf88dd68
JK
21747@xref{Python Auto-loading}.
21748@end menu
21749
21750@node Init File in the Current Directory
21751@subsection Automatically loading init file in the current directory
21752@cindex auto-loading init file in the current directory
21753
21754By default, @value{GDBN} reads and executes the canned sequences of commands
21755from init file (if any) in the current working directory,
21756see @ref{Init File in the Current Directory during Startup}.
21757
c1668e4e
JK
21758Note that loading of this local @file{.gdbinit} file also requires accordingly
21759configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
21760
bf88dd68
JK
21761@table @code
21762@anchor{set auto-load local-gdbinit}
21763@kindex set auto-load local-gdbinit
21764@item set auto-load local-gdbinit [on|off]
21765Enable or disable the auto-loading of canned sequences of commands
21766(@pxref{Sequences}) found in init file in the current directory.
21767
21768@anchor{show auto-load local-gdbinit}
21769@kindex show auto-load local-gdbinit
21770@item show auto-load local-gdbinit
21771Show whether auto-loading of canned sequences of commands from init file in the
21772current directory is enabled or disabled.
21773
21774@anchor{info auto-load local-gdbinit}
21775@kindex info auto-load local-gdbinit
21776@item info auto-load local-gdbinit
21777Print whether canned sequences of commands from init file in the
21778current directory have been auto-loaded.
21779@end table
21780
21781@node libthread_db.so.1 file
21782@subsection Automatically loading thread debugging library
21783@cindex auto-loading libthread_db.so.1
21784
21785This feature is currently present only on @sc{gnu}/Linux native hosts.
21786
21787@value{GDBN} reads in some cases thread debugging library from places specific
21788to the inferior (@pxref{set libthread-db-search-path}).
21789
21790The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
21791without checking this @samp{set auto-load libthread-db} switch as system
21792libraries have to be trusted in general. In all other cases of
21793@samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
21794auto-load libthread-db} is enabled before trying to open such thread debugging
21795library.
21796
c1668e4e
JK
21797Note that loading of this debugging library also requires accordingly configured
21798@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
21799
bf88dd68
JK
21800@table @code
21801@anchor{set auto-load libthread-db}
21802@kindex set auto-load libthread-db
21803@item set auto-load libthread-db [on|off]
21804Enable or disable the auto-loading of inferior specific thread debugging library.
21805
21806@anchor{show auto-load libthread-db}
21807@kindex show auto-load libthread-db
21808@item show auto-load libthread-db
21809Show whether auto-loading of inferior specific thread debugging library is
21810enabled or disabled.
21811
21812@anchor{info auto-load libthread-db}
21813@kindex info auto-load libthread-db
21814@item info auto-load libthread-db
21815Print the list of all loaded inferior specific thread debugging libraries and
21816for each such library print list of inferior @var{pid}s using it.
21817@end table
21818
21819@node objfile-gdb.gdb file
21820@subsection The @file{@var{objfile}-gdb.gdb} file
21821@cindex auto-loading @file{@var{objfile}-gdb.gdb}
21822
21823@value{GDBN} tries to load an @file{@var{objfile}-gdb.gdb} file containing
21824canned sequences of commands (@pxref{Sequences}), as long as @samp{set
21825auto-load gdb-scripts} is set to @samp{on}.
21826
c1668e4e
JK
21827Note that loading of this script file also requires accordingly configured
21828@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
21829
bf88dd68
JK
21830For more background refer to the similar Python scripts auto-loading
21831description (@pxref{objfile-gdb.py file}).
21832
21833@table @code
21834@anchor{set auto-load gdb-scripts}
21835@kindex set auto-load gdb-scripts
21836@item set auto-load gdb-scripts [on|off]
21837Enable or disable the auto-loading of canned sequences of commands scripts.
21838
21839@anchor{show auto-load gdb-scripts}
21840@kindex show auto-load gdb-scripts
21841@item show auto-load gdb-scripts
21842Show whether auto-loading of canned sequences of commands scripts is enabled or
21843disabled.
21844
21845@anchor{info auto-load gdb-scripts}
21846@kindex info auto-load gdb-scripts
21847@cindex print list of auto-loaded canned sequences of commands scripts
21848@item info auto-load gdb-scripts [@var{regexp}]
21849Print the list of all canned sequences of commands scripts that @value{GDBN}
21850auto-loaded.
21851@end table
21852
21853If @var{regexp} is supplied only canned sequences of commands scripts with
21854matching names are printed.
21855
bccbefd2
JK
21856@node Auto-loading safe path
21857@subsection Security restriction for auto-loading
21858@cindex auto-loading safe-path
21859
21860As the files of inferior can come from untrusted source (such as submitted by
21861an application user) @value{GDBN} does not always load any files automatically.
21862@value{GDBN} provides the @samp{set auto-load safe-path} setting to list
21863directories trusted for loading files not explicitly requested by user.
202cbf1c 21864Each directory can also be a shell wildcard pattern.
bccbefd2
JK
21865
21866If the path is not set properly you will see a warning and the file will not
21867get loaded:
21868
21869@smallexample
21870$ ./gdb -q ./gdb
21871Reading symbols from /home/user/gdb/gdb...done.
21872warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
1564a261
JK
21873 declined by your `auto-load safe-path' set
21874 to "$debugdir:$datadir/auto-load".
bccbefd2 21875warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
1564a261
JK
21876 declined by your `auto-load safe-path' set
21877 to "$debugdir:$datadir/auto-load".
bccbefd2
JK
21878@end smallexample
21879
21880The list of trusted directories is controlled by the following commands:
21881
21882@table @code
21883@anchor{set auto-load safe-path}
21884@kindex set auto-load safe-path
af2c1515 21885@item set auto-load safe-path @r{[}@var{directories}@r{]}
bccbefd2
JK
21886Set the list of directories (and their subdirectories) trusted for automatic
21887loading and execution of scripts. You can also enter a specific trusted file.
202cbf1c
JK
21888Each directory can also be a shell wildcard pattern; wildcards do not match
21889directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
21890(@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
af2c1515
JK
21891If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
21892its default value as specified during @value{GDBN} compilation.
21893
d9242c17 21894The list of directories uses path separator (@samp{:} on GNU and Unix
bccbefd2
JK
21895systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
21896to the @env{PATH} environment variable.
21897
21898@anchor{show auto-load safe-path}
21899@kindex show auto-load safe-path
21900@item show auto-load safe-path
21901Show the list of directories trusted for automatic loading and execution of
21902scripts.
21903
21904@anchor{add-auto-load-safe-path}
21905@kindex add-auto-load-safe-path
21906@item add-auto-load-safe-path
21907Add an entry (or list of entries) the list of directories trusted for automatic
21908loading and execution of scripts. Multiple entries may be delimited by the
d9242c17 21909host platform path separator in use.
bccbefd2
JK
21910@end table
21911
7349ff92 21912This variable defaults to what @code{--with-auto-load-dir} has been configured
1564a261
JK
21913to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
21914substitution applies the same as for @ref{set auto-load scripts-directory}.
21915The default @code{set auto-load safe-path} value can be also overriden by
21916@value{GDBN} configuration option @option{--with-auto-load-safe-path}.
6dea1fbd 21917
6dea1fbd
JK
21918Setting this variable to @file{/} disables this security protection,
21919corresponding @value{GDBN} configuration option is
21920@option{--without-auto-load-safe-path}.
bccbefd2
JK
21921This variable is supposed to be set to the system directories writable by the
21922system superuser only. Users can add their source directories in init files in
21923their home directories (@pxref{Home Directory Init File}). See also deprecated
21924init file in the current directory
21925(@pxref{Init File in the Current Directory during Startup}).
21926
21927To force @value{GDBN} to load the files it declined to load in the previous
21928example, you could use one of the following ways:
21929
0511cc75
JK
21930@table @asis
21931@item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
bccbefd2
JK
21932Specify this trusted directory (or a file) as additional component of the list.
21933You have to specify also any existing directories displayed by
21934by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
21935
174bb630 21936@item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
bccbefd2
JK
21937Specify this directory as in the previous case but just for a single
21938@value{GDBN} session.
21939
af2c1515 21940@item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
bccbefd2
JK
21941Disable auto-loading safety for a single @value{GDBN} session.
21942This assumes all the files you debug during this @value{GDBN} session will come
21943from trusted sources.
21944
21945@item @kbd{./configure --without-auto-load-safe-path}
21946During compilation of @value{GDBN} you may disable any auto-loading safety.
21947This assumes all the files you will ever debug with this @value{GDBN} come from
21948trusted sources.
0511cc75 21949@end table
bccbefd2
JK
21950
21951On the other hand you can also explicitly forbid automatic files loading which
21952also suppresses any such warning messages:
21953
0511cc75 21954@table @asis
174bb630 21955@item @kbd{gdb -iex "set auto-load no" @dots{}}
bccbefd2
JK
21956You can use @value{GDBN} command-line option for a single @value{GDBN} session.
21957
0511cc75 21958@item @file{~/.gdbinit}: @samp{set auto-load no}
bccbefd2
JK
21959Disable auto-loading globally for the user
21960(@pxref{Home Directory Init File}). While it is improbable, you could also
21961use system init file instead (@pxref{System-wide configuration}).
0511cc75 21962@end table
bccbefd2
JK
21963
21964This setting applies to the file names as entered by user. If no entry matches
21965@value{GDBN} tries as a last resort to also resolve all the file names into
21966their canonical form (typically resolving symbolic links) and compare the
21967entries again. @value{GDBN} already canonicalizes most of the filenames on its
21968own before starting the comparison so a canonical form of directories is
21969recommended to be entered.
21970
4dc84fd1
JK
21971@node Auto-loading verbose mode
21972@subsection Displaying files tried for auto-load
21973@cindex auto-loading verbose mode
21974
21975For better visibility of all the file locations where you can place scripts to
21976be auto-loaded with inferior --- or to protect yourself against accidental
21977execution of untrusted scripts --- @value{GDBN} provides a feature for printing
21978all the files attempted to be loaded. Both existing and non-existing files may
21979be printed.
21980
21981For example the list of directories from which it is safe to auto-load files
21982(@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
21983may not be too obvious while setting it up.
21984
21985@smallexample
0070f25a 21986(gdb) set debug auto-load on
4dc84fd1
JK
21987(gdb) file ~/src/t/true
21988auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
21989 for objfile "/tmp/true".
21990auto-load: Updating directories of "/usr:/opt".
21991auto-load: Using directory "/usr".
21992auto-load: Using directory "/opt".
21993warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
21994 by your `auto-load safe-path' set to "/usr:/opt".
21995@end smallexample
21996
21997@table @code
21998@anchor{set debug auto-load}
21999@kindex set debug auto-load
22000@item set debug auto-load [on|off]
22001Set whether to print the filenames attempted to be auto-loaded.
22002
22003@anchor{show debug auto-load}
22004@kindex show debug auto-load
22005@item show debug auto-load
22006Show whether printing of the filenames attempted to be auto-loaded is turned
22007on or off.
22008@end table
22009
8e04817f 22010@node Messages/Warnings
79a6e687 22011@section Optional Warnings and Messages
104c1213 22012
9c16f35a
EZ
22013@cindex verbose operation
22014@cindex optional warnings
8e04817f
AC
22015By default, @value{GDBN} is silent about its inner workings. If you are
22016running on a slow machine, you may want to use the @code{set verbose}
22017command. This makes @value{GDBN} tell you when it does a lengthy
22018internal operation, so you will not think it has crashed.
104c1213 22019
8e04817f
AC
22020Currently, the messages controlled by @code{set verbose} are those
22021which announce that the symbol table for a source file is being read;
79a6e687 22022see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 22023
8e04817f
AC
22024@table @code
22025@kindex set verbose
22026@item set verbose on
22027Enables @value{GDBN} output of certain informational messages.
104c1213 22028
8e04817f
AC
22029@item set verbose off
22030Disables @value{GDBN} output of certain informational messages.
104c1213 22031
8e04817f
AC
22032@kindex show verbose
22033@item show verbose
22034Displays whether @code{set verbose} is on or off.
22035@end table
104c1213 22036
8e04817f
AC
22037By default, if @value{GDBN} encounters bugs in the symbol table of an
22038object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
22039find this information useful (@pxref{Symbol Errors, ,Errors Reading
22040Symbol Files}).
104c1213 22041
8e04817f 22042@table @code
104c1213 22043
8e04817f
AC
22044@kindex set complaints
22045@item set complaints @var{limit}
22046Permits @value{GDBN} to output @var{limit} complaints about each type of
22047unusual symbols before becoming silent about the problem. Set
22048@var{limit} to zero to suppress all complaints; set it to a large number
22049to prevent complaints from being suppressed.
104c1213 22050
8e04817f
AC
22051@kindex show complaints
22052@item show complaints
22053Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 22054
8e04817f 22055@end table
104c1213 22056
d837706a 22057@anchor{confirmation requests}
8e04817f
AC
22058By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
22059lot of stupid questions to confirm certain commands. For example, if
22060you try to run a program which is already running:
104c1213 22061
474c8240 22062@smallexample
8e04817f
AC
22063(@value{GDBP}) run
22064The program being debugged has been started already.
22065Start it from the beginning? (y or n)
474c8240 22066@end smallexample
104c1213 22067
8e04817f
AC
22068If you are willing to unflinchingly face the consequences of your own
22069commands, you can disable this ``feature'':
104c1213 22070
8e04817f 22071@table @code
104c1213 22072
8e04817f
AC
22073@kindex set confirm
22074@cindex flinching
22075@cindex confirmation
22076@cindex stupid questions
22077@item set confirm off
7c953934
TT
22078Disables confirmation requests. Note that running @value{GDBN} with
22079the @option{--batch} option (@pxref{Mode Options, -batch}) also
22080automatically disables confirmation requests.
104c1213 22081
8e04817f
AC
22082@item set confirm on
22083Enables confirmation requests (the default).
104c1213 22084
8e04817f
AC
22085@kindex show confirm
22086@item show confirm
22087Displays state of confirmation requests.
22088
22089@end table
104c1213 22090
16026cd7
AS
22091@cindex command tracing
22092If you need to debug user-defined commands or sourced files you may find it
22093useful to enable @dfn{command tracing}. In this mode each command will be
22094printed as it is executed, prefixed with one or more @samp{+} symbols, the
22095quantity denoting the call depth of each command.
22096
22097@table @code
22098@kindex set trace-commands
22099@cindex command scripts, debugging
22100@item set trace-commands on
22101Enable command tracing.
22102@item set trace-commands off
22103Disable command tracing.
22104@item show trace-commands
22105Display the current state of command tracing.
22106@end table
22107
8e04817f 22108@node Debugging Output
79a6e687 22109@section Optional Messages about Internal Happenings
4644b6e3
EZ
22110@cindex optional debugging messages
22111
da316a69
EZ
22112@value{GDBN} has commands that enable optional debugging messages from
22113various @value{GDBN} subsystems; normally these commands are of
22114interest to @value{GDBN} maintainers, or when reporting a bug. This
22115section documents those commands.
22116
104c1213 22117@table @code
a8f24a35
EZ
22118@kindex set exec-done-display
22119@item set exec-done-display
22120Turns on or off the notification of asynchronous commands'
22121completion. When on, @value{GDBN} will print a message when an
22122asynchronous command finishes its execution. The default is off.
22123@kindex show exec-done-display
22124@item show exec-done-display
22125Displays the current setting of asynchronous command completion
22126notification.
4644b6e3
EZ
22127@kindex set debug
22128@cindex gdbarch debugging info
a8f24a35 22129@cindex architecture debugging info
8e04817f 22130@item set debug arch
a8f24a35 22131Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 22132@kindex show debug
8e04817f
AC
22133@item show debug arch
22134Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
22135@item set debug aix-thread
22136@cindex AIX threads
22137Display debugging messages about inner workings of the AIX thread
22138module.
22139@item show debug aix-thread
22140Show the current state of AIX thread debugging info display.
900e11f9
JK
22141@item set debug check-physname
22142@cindex physname
22143Check the results of the ``physname'' computation. When reading DWARF
22144debugging information for C@t{++}, @value{GDBN} attempts to compute
22145each entity's name. @value{GDBN} can do this computation in two
22146different ways, depending on exactly what information is present.
22147When enabled, this setting causes @value{GDBN} to compute the names
22148both ways and display any discrepancies.
22149@item show debug check-physname
22150Show the current state of ``physname'' checking.
d97bc12b
DE
22151@item set debug dwarf2-die
22152@cindex DWARF2 DIEs
22153Dump DWARF2 DIEs after they are read in.
22154The value is the number of nesting levels to print.
22155A value of zero turns off the display.
22156@item show debug dwarf2-die
22157Show the current state of DWARF2 DIE debugging.
45cfd468
DE
22158@item set debug dwarf2-read
22159@cindex DWARF2 Reading
22160Turns on or off display of debugging messages related to reading
22161DWARF debug info. The default is off.
22162@item show debug dwarf2-read
22163Show the current state of DWARF2 reader debugging.
237fc4c9
PA
22164@item set debug displaced
22165@cindex displaced stepping debugging info
22166Turns on or off display of @value{GDBN} debugging info for the
22167displaced stepping support. The default is off.
22168@item show debug displaced
22169Displays the current state of displaying @value{GDBN} debugging info
22170related to displaced stepping.
8e04817f 22171@item set debug event
4644b6e3 22172@cindex event debugging info
a8f24a35 22173Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 22174default is off.
8e04817f
AC
22175@item show debug event
22176Displays the current state of displaying @value{GDBN} event debugging
22177info.
8e04817f 22178@item set debug expression
4644b6e3 22179@cindex expression debugging info
721c2651
EZ
22180Turns on or off display of debugging info about @value{GDBN}
22181expression parsing. The default is off.
8e04817f 22182@item show debug expression
721c2651
EZ
22183Displays the current state of displaying debugging info about
22184@value{GDBN} expression parsing.
7453dc06 22185@item set debug frame
4644b6e3 22186@cindex frame debugging info
7453dc06
AC
22187Turns on or off display of @value{GDBN} frame debugging info. The
22188default is off.
7453dc06
AC
22189@item show debug frame
22190Displays the current state of displaying @value{GDBN} frame debugging
22191info.
cbe54154
PA
22192@item set debug gnu-nat
22193@cindex @sc{gnu}/Hurd debug messages
22194Turns on or off debugging messages from the @sc{gnu}/Hurd debug support.
22195@item show debug gnu-nat
22196Show the current state of @sc{gnu}/Hurd debugging messages.
30e91e0b
RC
22197@item set debug infrun
22198@cindex inferior debugging info
22199Turns on or off display of @value{GDBN} debugging info for running the inferior.
22200The default is off. @file{infrun.c} contains GDB's runtime state machine used
22201for implementing operations such as single-stepping the inferior.
22202@item show debug infrun
22203Displays the current state of @value{GDBN} inferior debugging.
a255712f
PP
22204@item set debug jit
22205@cindex just-in-time compilation, debugging messages
22206Turns on or off debugging messages from JIT debug support.
22207@item show debug jit
22208Displays the current state of @value{GDBN} JIT debugging.
da316a69
EZ
22209@item set debug lin-lwp
22210@cindex @sc{gnu}/Linux LWP debug messages
22211@cindex Linux lightweight processes
721c2651 22212Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
22213@item show debug lin-lwp
22214Show the current state of Linux LWP debugging messages.
c9b6281a
YQ
22215@item set debug notification
22216@cindex remote async notification debugging info
22217Turns on or off debugging messages about remote async notification.
22218The default is off.
22219@item show debug notification
22220Displays the current state of remote async notification debugging messages.
2b4855ab 22221@item set debug observer
4644b6e3 22222@cindex observer debugging info
2b4855ab
AC
22223Turns on or off display of @value{GDBN} observer debugging. This
22224includes info such as the notification of observable events.
2b4855ab
AC
22225@item show debug observer
22226Displays the current state of observer debugging.
8e04817f 22227@item set debug overload
4644b6e3 22228@cindex C@t{++} overload debugging info
8e04817f 22229Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 22230info. This includes info such as ranking of functions, etc. The default
8e04817f 22231is off.
8e04817f
AC
22232@item show debug overload
22233Displays the current state of displaying @value{GDBN} C@t{++} overload
22234debugging info.
92981e24
TT
22235@cindex expression parser, debugging info
22236@cindex debug expression parser
22237@item set debug parser
22238Turns on or off the display of expression parser debugging output.
22239Internally, this sets the @code{yydebug} variable in the expression
22240parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
22241details. The default is off.
22242@item show debug parser
22243Show the current state of expression parser debugging.
8e04817f
AC
22244@cindex packets, reporting on stdout
22245@cindex serial connections, debugging
605a56cb
DJ
22246@cindex debug remote protocol
22247@cindex remote protocol debugging
22248@cindex display remote packets
8e04817f
AC
22249@item set debug remote
22250Turns on or off display of reports on all packets sent back and forth across
22251the serial line to the remote machine. The info is printed on the
22252@value{GDBN} standard output stream. The default is off.
8e04817f
AC
22253@item show debug remote
22254Displays the state of display of remote packets.
8e04817f
AC
22255@item set debug serial
22256Turns on or off display of @value{GDBN} serial debugging info. The
22257default is off.
8e04817f
AC
22258@item show debug serial
22259Displays the current state of displaying @value{GDBN} serial debugging
22260info.
c45da7e6
EZ
22261@item set debug solib-frv
22262@cindex FR-V shared-library debugging
22263Turns on or off debugging messages for FR-V shared-library code.
22264@item show debug solib-frv
22265Display the current state of FR-V shared-library code debugging
22266messages.
45cfd468
DE
22267@item set debug symtab-create
22268@cindex symbol table creation
22269Turns on or off display of debugging messages related to symbol table creation.
22270The default is off.
22271@item show debug symtab-create
22272Show the current state of symbol table creation debugging.
8e04817f 22273@item set debug target
4644b6e3 22274@cindex target debugging info
8e04817f
AC
22275Turns on or off display of @value{GDBN} target debugging info. This info
22276includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
22277default is 0. Set it to 1 to track events, and to 2 to also track the
22278value of large memory transfers. Changes to this flag do not take effect
22279until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
22280@item show debug target
22281Displays the current state of displaying @value{GDBN} target debugging
22282info.
75feb17d
DJ
22283@item set debug timestamp
22284@cindex timestampping debugging info
22285Turns on or off display of timestamps with @value{GDBN} debugging info.
22286When enabled, seconds and microseconds are displayed before each debugging
22287message.
22288@item show debug timestamp
22289Displays the current state of displaying timestamps with @value{GDBN}
22290debugging info.
c45da7e6 22291@item set debugvarobj
4644b6e3 22292@cindex variable object debugging info
8e04817f
AC
22293Turns on or off display of @value{GDBN} variable object debugging
22294info. The default is off.
c45da7e6 22295@item show debugvarobj
8e04817f
AC
22296Displays the current state of displaying @value{GDBN} variable object
22297debugging info.
e776119f
DJ
22298@item set debug xml
22299@cindex XML parser debugging
22300Turns on or off debugging messages for built-in XML parsers.
22301@item show debug xml
22302Displays the current state of XML debugging messages.
8e04817f 22303@end table
104c1213 22304
14fb1bac
JB
22305@node Other Misc Settings
22306@section Other Miscellaneous Settings
22307@cindex miscellaneous settings
22308
22309@table @code
22310@kindex set interactive-mode
22311@item set interactive-mode
7bfc9434
JB
22312If @code{on}, forces @value{GDBN} to assume that GDB was started
22313in a terminal. In practice, this means that @value{GDBN} should wait
22314for the user to answer queries generated by commands entered at
22315the command prompt. If @code{off}, forces @value{GDBN} to operate
22316in the opposite mode, and it uses the default answers to all queries.
22317If @code{auto} (the default), @value{GDBN} tries to determine whether
22318its standard input is a terminal, and works in interactive-mode if it
22319is, non-interactively otherwise.
14fb1bac
JB
22320
22321In the vast majority of cases, the debugger should be able to guess
22322correctly which mode should be used. But this setting can be useful
22323in certain specific cases, such as running a MinGW @value{GDBN}
22324inside a cygwin window.
22325
22326@kindex show interactive-mode
22327@item show interactive-mode
22328Displays whether the debugger is operating in interactive mode or not.
22329@end table
22330
d57a3c85
TJB
22331@node Extending GDB
22332@chapter Extending @value{GDBN}
22333@cindex extending GDB
22334
5a56e9c5
DE
22335@value{GDBN} provides three mechanisms for extension. The first is based
22336on composition of @value{GDBN} commands, the second is based on the
22337Python scripting language, and the third is for defining new aliases of
22338existing commands.
d57a3c85 22339
5a56e9c5 22340To facilitate the use of the first two extensions, @value{GDBN} is capable
95433b34
JB
22341of evaluating the contents of a file. When doing so, @value{GDBN}
22342can recognize which scripting language is being used by looking at
22343the filename extension. Files with an unrecognized filename extension
22344are always treated as a @value{GDBN} Command Files.
22345@xref{Command Files,, Command files}.
22346
22347You can control how @value{GDBN} evaluates these files with the following
22348setting:
22349
22350@table @code
22351@kindex set script-extension
22352@kindex show script-extension
22353@item set script-extension off
22354All scripts are always evaluated as @value{GDBN} Command Files.
22355
22356@item set script-extension soft
22357The debugger determines the scripting language based on filename
22358extension. If this scripting language is supported, @value{GDBN}
22359evaluates the script using that language. Otherwise, it evaluates
22360the file as a @value{GDBN} Command File.
22361
22362@item set script-extension strict
22363The debugger determines the scripting language based on filename
22364extension, and evaluates the script using that language. If the
22365language is not supported, then the evaluation fails.
22366
22367@item show script-extension
22368Display the current value of the @code{script-extension} option.
22369
22370@end table
22371
d57a3c85
TJB
22372@menu
22373* Sequences:: Canned Sequences of Commands
22374* Python:: Scripting @value{GDBN} using Python
5a56e9c5 22375* Aliases:: Creating new spellings of existing commands
d57a3c85
TJB
22376@end menu
22377
8e04817f 22378@node Sequences
d57a3c85 22379@section Canned Sequences of Commands
104c1213 22380
8e04817f 22381Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 22382Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
22383commands for execution as a unit: user-defined commands and command
22384files.
104c1213 22385
8e04817f 22386@menu
fcc73fe3
EZ
22387* Define:: How to define your own commands
22388* Hooks:: Hooks for user-defined commands
22389* Command Files:: How to write scripts of commands to be stored in a file
22390* Output:: Commands for controlled output
8e04817f 22391@end menu
104c1213 22392
8e04817f 22393@node Define
d57a3c85 22394@subsection User-defined Commands
104c1213 22395
8e04817f 22396@cindex user-defined command
fcc73fe3 22397@cindex arguments, to user-defined commands
8e04817f
AC
22398A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
22399which you assign a new name as a command. This is done with the
22400@code{define} command. User commands may accept up to 10 arguments
22401separated by whitespace. Arguments are accessed within the user command
c03c782f 22402via @code{$arg0@dots{}$arg9}. A trivial example:
104c1213 22403
8e04817f
AC
22404@smallexample
22405define adder
22406 print $arg0 + $arg1 + $arg2
c03c782f 22407end
8e04817f 22408@end smallexample
104c1213
JM
22409
22410@noindent
8e04817f 22411To execute the command use:
104c1213 22412
8e04817f
AC
22413@smallexample
22414adder 1 2 3
22415@end smallexample
104c1213 22416
8e04817f
AC
22417@noindent
22418This defines the command @code{adder}, which prints the sum of
22419its three arguments. Note the arguments are text substitutions, so they may
22420reference variables, use complex expressions, or even perform inferior
22421functions calls.
104c1213 22422
fcc73fe3
EZ
22423@cindex argument count in user-defined commands
22424@cindex how many arguments (user-defined commands)
c03c782f
AS
22425In addition, @code{$argc} may be used to find out how many arguments have
22426been passed. This expands to a number in the range 0@dots{}10.
22427
22428@smallexample
22429define adder
22430 if $argc == 2
22431 print $arg0 + $arg1
22432 end
22433 if $argc == 3
22434 print $arg0 + $arg1 + $arg2
22435 end
22436end
22437@end smallexample
22438
104c1213 22439@table @code
104c1213 22440
8e04817f
AC
22441@kindex define
22442@item define @var{commandname}
22443Define a command named @var{commandname}. If there is already a command
22444by that name, you are asked to confirm that you want to redefine it.
adb483fe
DJ
22445@var{commandname} may be a bare command name consisting of letters,
22446numbers, dashes, and underscores. It may also start with any predefined
22447prefix command. For example, @samp{define target my-target} creates
22448a user-defined @samp{target my-target} command.
104c1213 22449
8e04817f
AC
22450The definition of the command is made up of other @value{GDBN} command lines,
22451which are given following the @code{define} command. The end of these
22452commands is marked by a line containing @code{end}.
104c1213 22453
8e04817f 22454@kindex document
ca91424e 22455@kindex end@r{ (user-defined commands)}
8e04817f
AC
22456@item document @var{commandname}
22457Document the user-defined command @var{commandname}, so that it can be
22458accessed by @code{help}. The command @var{commandname} must already be
22459defined. This command reads lines of documentation just as @code{define}
22460reads the lines of the command definition, ending with @code{end}.
22461After the @code{document} command is finished, @code{help} on command
22462@var{commandname} displays the documentation you have written.
104c1213 22463
8e04817f
AC
22464You may use the @code{document} command again to change the
22465documentation of a command. Redefining the command with @code{define}
22466does not change the documentation.
104c1213 22467
c45da7e6
EZ
22468@kindex dont-repeat
22469@cindex don't repeat command
22470@item dont-repeat
22471Used inside a user-defined command, this tells @value{GDBN} that this
22472command should not be repeated when the user hits @key{RET}
22473(@pxref{Command Syntax, repeat last command}).
22474
8e04817f
AC
22475@kindex help user-defined
22476@item help user-defined
7d74f244
DE
22477List all user-defined commands and all python commands defined in class
22478COMAND_USER. The first line of the documentation or docstring is
22479included (if any).
104c1213 22480
8e04817f
AC
22481@kindex show user
22482@item show user
22483@itemx show user @var{commandname}
22484Display the @value{GDBN} commands used to define @var{commandname} (but
22485not its documentation). If no @var{commandname} is given, display the
22486definitions for all user-defined commands.
7d74f244 22487This does not work for user-defined python commands.
104c1213 22488
fcc73fe3 22489@cindex infinite recursion in user-defined commands
20f01a46
DH
22490@kindex show max-user-call-depth
22491@kindex set max-user-call-depth
22492@item show max-user-call-depth
5ca0cb28
DH
22493@itemx set max-user-call-depth
22494The value of @code{max-user-call-depth} controls how many recursion
3f94c067 22495levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 22496infinite recursion and aborts the command.
7d74f244 22497This does not apply to user-defined python commands.
104c1213
JM
22498@end table
22499
fcc73fe3
EZ
22500In addition to the above commands, user-defined commands frequently
22501use control flow commands, described in @ref{Command Files}.
22502
8e04817f
AC
22503When user-defined commands are executed, the
22504commands of the definition are not printed. An error in any command
22505stops execution of the user-defined command.
104c1213 22506
8e04817f
AC
22507If used interactively, commands that would ask for confirmation proceed
22508without asking when used inside a user-defined command. Many @value{GDBN}
22509commands that normally print messages to say what they are doing omit the
22510messages when used in a user-defined command.
104c1213 22511
8e04817f 22512@node Hooks
d57a3c85 22513@subsection User-defined Command Hooks
8e04817f
AC
22514@cindex command hooks
22515@cindex hooks, for commands
22516@cindex hooks, pre-command
104c1213 22517
8e04817f 22518@kindex hook
8e04817f
AC
22519You may define @dfn{hooks}, which are a special kind of user-defined
22520command. Whenever you run the command @samp{foo}, if the user-defined
22521command @samp{hook-foo} exists, it is executed (with no arguments)
22522before that command.
104c1213 22523
8e04817f
AC
22524@cindex hooks, post-command
22525@kindex hookpost
8e04817f
AC
22526A hook may also be defined which is run after the command you executed.
22527Whenever you run the command @samp{foo}, if the user-defined command
22528@samp{hookpost-foo} exists, it is executed (with no arguments) after
22529that command. Post-execution hooks may exist simultaneously with
22530pre-execution hooks, for the same command.
104c1213 22531
8e04817f 22532It is valid for a hook to call the command which it hooks. If this
9f1c6395 22533occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 22534
8e04817f
AC
22535@c It would be nice if hookpost could be passed a parameter indicating
22536@c if the command it hooks executed properly or not. FIXME!
104c1213 22537
8e04817f
AC
22538@kindex stop@r{, a pseudo-command}
22539In addition, a pseudo-command, @samp{stop} exists. Defining
22540(@samp{hook-stop}) makes the associated commands execute every time
22541execution stops in your program: before breakpoint commands are run,
22542displays are printed, or the stack frame is printed.
104c1213 22543
8e04817f
AC
22544For example, to ignore @code{SIGALRM} signals while
22545single-stepping, but treat them normally during normal execution,
22546you could define:
104c1213 22547
474c8240 22548@smallexample
8e04817f
AC
22549define hook-stop
22550handle SIGALRM nopass
22551end
104c1213 22552
8e04817f
AC
22553define hook-run
22554handle SIGALRM pass
22555end
104c1213 22556
8e04817f 22557define hook-continue
d3e8051b 22558handle SIGALRM pass
8e04817f 22559end
474c8240 22560@end smallexample
104c1213 22561
d3e8051b 22562As a further example, to hook at the beginning and end of the @code{echo}
b383017d 22563command, and to add extra text to the beginning and end of the message,
8e04817f 22564you could define:
104c1213 22565
474c8240 22566@smallexample
8e04817f
AC
22567define hook-echo
22568echo <<<---
22569end
104c1213 22570
8e04817f
AC
22571define hookpost-echo
22572echo --->>>\n
22573end
104c1213 22574
8e04817f
AC
22575(@value{GDBP}) echo Hello World
22576<<<---Hello World--->>>
22577(@value{GDBP})
104c1213 22578
474c8240 22579@end smallexample
104c1213 22580
8e04817f
AC
22581You can define a hook for any single-word command in @value{GDBN}, but
22582not for command aliases; you should define a hook for the basic command
c1468174 22583name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
22584@c FIXME! So how does Joe User discover whether a command is an alias
22585@c or not?
adb483fe
DJ
22586You can hook a multi-word command by adding @code{hook-} or
22587@code{hookpost-} to the last word of the command, e.g.@:
22588@samp{define target hook-remote} to add a hook to @samp{target remote}.
22589
8e04817f
AC
22590If an error occurs during the execution of your hook, execution of
22591@value{GDBN} commands stops and @value{GDBN} issues a prompt
22592(before the command that you actually typed had a chance to run).
104c1213 22593
8e04817f
AC
22594If you try to define a hook which does not match any known command, you
22595get a warning from the @code{define} command.
c906108c 22596
8e04817f 22597@node Command Files
d57a3c85 22598@subsection Command Files
c906108c 22599
8e04817f 22600@cindex command files
fcc73fe3 22601@cindex scripting commands
6fc08d32
EZ
22602A command file for @value{GDBN} is a text file made of lines that are
22603@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
22604also be included. An empty line in a command file does nothing; it
22605does not mean to repeat the last command, as it would from the
22606terminal.
c906108c 22607
6fc08d32 22608You can request the execution of a command file with the @code{source}
95433b34
JB
22609command. Note that the @code{source} command is also used to evaluate
22610scripts that are not Command Files. The exact behavior can be configured
22611using the @code{script-extension} setting.
22612@xref{Extending GDB,, Extending GDB}.
c906108c 22613
8e04817f
AC
22614@table @code
22615@kindex source
ca91424e 22616@cindex execute commands from a file
3f7b2faa 22617@item source [-s] [-v] @var{filename}
8e04817f 22618Execute the command file @var{filename}.
c906108c
SS
22619@end table
22620
fcc73fe3
EZ
22621The lines in a command file are generally executed sequentially,
22622unless the order of execution is changed by one of the
22623@emph{flow-control commands} described below. The commands are not
a71ec265
DH
22624printed as they are executed. An error in any command terminates
22625execution of the command file and control is returned to the console.
c906108c 22626
08001717
DE
22627@value{GDBN} first searches for @var{filename} in the current directory.
22628If the file is not found there, and @var{filename} does not specify a
22629directory, then @value{GDBN} also looks for the file on the source search path
22630(specified with the @samp{directory} command);
22631except that @file{$cdir} is not searched because the compilation directory
22632is not relevant to scripts.
4b505b12 22633
3f7b2faa
DE
22634If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
22635on the search path even if @var{filename} specifies a directory.
22636The search is done by appending @var{filename} to each element of the
22637search path. So, for example, if @var{filename} is @file{mylib/myscript}
22638and the search path contains @file{/home/user} then @value{GDBN} will
22639look for the script @file{/home/user/mylib/myscript}.
22640The search is also done if @var{filename} is an absolute path.
22641For example, if @var{filename} is @file{/tmp/myscript} and
22642the search path contains @file{/home/user} then @value{GDBN} will
22643look for the script @file{/home/user/tmp/myscript}.
22644For DOS-like systems, if @var{filename} contains a drive specification,
22645it is stripped before concatenation. For example, if @var{filename} is
22646@file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
22647will look for the script @file{c:/tmp/myscript}.
22648
16026cd7
AS
22649If @code{-v}, for verbose mode, is given then @value{GDBN} displays
22650each command as it is executed. The option must be given before
22651@var{filename}, and is interpreted as part of the filename anywhere else.
22652
8e04817f
AC
22653Commands that would ask for confirmation if used interactively proceed
22654without asking when used in a command file. Many @value{GDBN} commands that
22655normally print messages to say what they are doing omit the messages
22656when called from command files.
c906108c 22657
8e04817f
AC
22658@value{GDBN} also accepts command input from standard input. In this
22659mode, normal output goes to standard output and error output goes to
22660standard error. Errors in a command file supplied on standard input do
6fc08d32 22661not terminate execution of the command file---execution continues with
8e04817f 22662the next command.
c906108c 22663
474c8240 22664@smallexample
8e04817f 22665gdb < cmds > log 2>&1
474c8240 22666@end smallexample
c906108c 22667
8e04817f
AC
22668(The syntax above will vary depending on the shell used.) This example
22669will execute commands from the file @file{cmds}. All output and errors
22670would be directed to @file{log}.
c906108c 22671
fcc73fe3
EZ
22672Since commands stored on command files tend to be more general than
22673commands typed interactively, they frequently need to deal with
22674complicated situations, such as different or unexpected values of
22675variables and symbols, changes in how the program being debugged is
22676built, etc. @value{GDBN} provides a set of flow-control commands to
22677deal with these complexities. Using these commands, you can write
22678complex scripts that loop over data structures, execute commands
22679conditionally, etc.
22680
22681@table @code
22682@kindex if
22683@kindex else
22684@item if
22685@itemx else
22686This command allows to include in your script conditionally executed
22687commands. The @code{if} command takes a single argument, which is an
22688expression to evaluate. It is followed by a series of commands that
22689are executed only if the expression is true (its value is nonzero).
22690There can then optionally be an @code{else} line, followed by a series
22691of commands that are only executed if the expression was false. The
22692end of the list is marked by a line containing @code{end}.
22693
22694@kindex while
22695@item while
22696This command allows to write loops. Its syntax is similar to
22697@code{if}: the command takes a single argument, which is an expression
22698to evaluate, and must be followed by the commands to execute, one per
22699line, terminated by an @code{end}. These commands are called the
22700@dfn{body} of the loop. The commands in the body of @code{while} are
22701executed repeatedly as long as the expression evaluates to true.
22702
22703@kindex loop_break
22704@item loop_break
22705This command exits the @code{while} loop in whose body it is included.
22706Execution of the script continues after that @code{while}s @code{end}
22707line.
22708
22709@kindex loop_continue
22710@item loop_continue
22711This command skips the execution of the rest of the body of commands
22712in the @code{while} loop in whose body it is included. Execution
22713branches to the beginning of the @code{while} loop, where it evaluates
22714the controlling expression.
ca91424e
EZ
22715
22716@kindex end@r{ (if/else/while commands)}
22717@item end
22718Terminate the block of commands that are the body of @code{if},
22719@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
22720@end table
22721
22722
8e04817f 22723@node Output
d57a3c85 22724@subsection Commands for Controlled Output
c906108c 22725
8e04817f
AC
22726During the execution of a command file or a user-defined command, normal
22727@value{GDBN} output is suppressed; the only output that appears is what is
22728explicitly printed by the commands in the definition. This section
22729describes three commands useful for generating exactly the output you
22730want.
c906108c
SS
22731
22732@table @code
8e04817f
AC
22733@kindex echo
22734@item echo @var{text}
22735@c I do not consider backslash-space a standard C escape sequence
22736@c because it is not in ANSI.
22737Print @var{text}. Nonprinting characters can be included in
22738@var{text} using C escape sequences, such as @samp{\n} to print a
22739newline. @strong{No newline is printed unless you specify one.}
22740In addition to the standard C escape sequences, a backslash followed
22741by a space stands for a space. This is useful for displaying a
22742string with spaces at the beginning or the end, since leading and
22743trailing spaces are otherwise trimmed from all arguments.
22744To print @samp{@w{ }and foo =@w{ }}, use the command
22745@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 22746
8e04817f
AC
22747A backslash at the end of @var{text} can be used, as in C, to continue
22748the command onto subsequent lines. For example,
c906108c 22749
474c8240 22750@smallexample
8e04817f
AC
22751echo This is some text\n\
22752which is continued\n\
22753onto several lines.\n
474c8240 22754@end smallexample
c906108c 22755
8e04817f 22756produces the same output as
c906108c 22757
474c8240 22758@smallexample
8e04817f
AC
22759echo This is some text\n
22760echo which is continued\n
22761echo onto several lines.\n
474c8240 22762@end smallexample
c906108c 22763
8e04817f
AC
22764@kindex output
22765@item output @var{expression}
22766Print the value of @var{expression} and nothing but that value: no
22767newlines, no @samp{$@var{nn} = }. The value is not entered in the
22768value history either. @xref{Expressions, ,Expressions}, for more information
22769on expressions.
c906108c 22770
8e04817f
AC
22771@item output/@var{fmt} @var{expression}
22772Print the value of @var{expression} in format @var{fmt}. You can use
22773the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 22774Formats}, for more information.
c906108c 22775
8e04817f 22776@kindex printf
82160952
EZ
22777@item printf @var{template}, @var{expressions}@dots{}
22778Print the values of one or more @var{expressions} under the control of
22779the string @var{template}. To print several values, make
22780@var{expressions} be a comma-separated list of individual expressions,
22781which may be either numbers or pointers. Their values are printed as
22782specified by @var{template}, exactly as a C program would do by
22783executing the code below:
c906108c 22784
474c8240 22785@smallexample
82160952 22786printf (@var{template}, @var{expressions}@dots{});
474c8240 22787@end smallexample
c906108c 22788
82160952
EZ
22789As in @code{C} @code{printf}, ordinary characters in @var{template}
22790are printed verbatim, while @dfn{conversion specification} introduced
22791by the @samp{%} character cause subsequent @var{expressions} to be
22792evaluated, their values converted and formatted according to type and
22793style information encoded in the conversion specifications, and then
22794printed.
22795
8e04817f 22796For example, you can print two values in hex like this:
c906108c 22797
8e04817f
AC
22798@smallexample
22799printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
22800@end smallexample
c906108c 22801
82160952
EZ
22802@code{printf} supports all the standard @code{C} conversion
22803specifications, including the flags and modifiers between the @samp{%}
22804character and the conversion letter, with the following exceptions:
22805
22806@itemize @bullet
22807@item
22808The argument-ordering modifiers, such as @samp{2$}, are not supported.
22809
22810@item
22811The modifier @samp{*} is not supported for specifying precision or
22812width.
22813
22814@item
22815The @samp{'} flag (for separation of digits into groups according to
22816@code{LC_NUMERIC'}) is not supported.
22817
22818@item
22819The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
22820supported.
22821
22822@item
22823The conversion letter @samp{n} (as in @samp{%n}) is not supported.
22824
22825@item
22826The conversion letters @samp{a} and @samp{A} are not supported.
22827@end itemize
22828
22829@noindent
22830Note that the @samp{ll} type modifier is supported only if the
22831underlying @code{C} implementation used to build @value{GDBN} supports
22832the @code{long long int} type, and the @samp{L} type modifier is
22833supported only if @code{long double} type is available.
22834
22835As in @code{C}, @code{printf} supports simple backslash-escape
22836sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
22837@samp{\a}, and @samp{\f}, that consist of backslash followed by a
22838single character. Octal and hexadecimal escape sequences are not
22839supported.
1a619819
LM
22840
22841Additionally, @code{printf} supports conversion specifications for DFP
0aea4bf3
LM
22842(@dfn{Decimal Floating Point}) types using the following length modifiers
22843together with a floating point specifier.
1a619819
LM
22844letters:
22845
22846@itemize @bullet
22847@item
22848@samp{H} for printing @code{Decimal32} types.
22849
22850@item
22851@samp{D} for printing @code{Decimal64} types.
22852
22853@item
22854@samp{DD} for printing @code{Decimal128} types.
22855@end itemize
22856
22857If the underlying @code{C} implementation used to build @value{GDBN} has
0aea4bf3 22858support for the three length modifiers for DFP types, other modifiers
3b784c4f 22859such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
22860
22861In case there is no such @code{C} support, no additional modifiers will be
22862available and the value will be printed in the standard way.
22863
22864Here's an example of printing DFP types using the above conversion letters:
22865@smallexample
0aea4bf3 22866printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
1a619819
LM
22867@end smallexample
22868
f1421989
HZ
22869@kindex eval
22870@item eval @var{template}, @var{expressions}@dots{}
22871Convert the values of one or more @var{expressions} under the control of
22872the string @var{template} to a command line, and call it.
22873
c906108c
SS
22874@end table
22875
d57a3c85
TJB
22876@node Python
22877@section Scripting @value{GDBN} using Python
22878@cindex python scripting
22879@cindex scripting with python
22880
22881You can script @value{GDBN} using the @uref{http://www.python.org/,
22882Python programming language}. This feature is available only if
22883@value{GDBN} was configured using @option{--with-python}.
22884
9279c692
JB
22885@cindex python directory
22886Python scripts used by @value{GDBN} should be installed in
22887@file{@var{data-directory}/python}, where @var{data-directory} is
9eeee977
DE
22888the data directory as determined at @value{GDBN} startup (@pxref{Data Files}).
22889This directory, known as the @dfn{python directory},
9279c692
JB
22890is automatically added to the Python Search Path in order to allow
22891the Python interpreter to locate all scripts installed at this location.
22892
5e239b84
PM
22893Additionally, @value{GDBN} commands and convenience functions which
22894are written in Python and are located in the
22895@file{@var{data-directory}/python/gdb/command} or
22896@file{@var{data-directory}/python/gdb/function} directories are
22897automatically imported when @value{GDBN} starts.
22898
d57a3c85
TJB
22899@menu
22900* Python Commands:: Accessing Python from @value{GDBN}.
22901* Python API:: Accessing @value{GDBN} from Python.
bf88dd68 22902* Python Auto-loading:: Automatically loading Python code.
0e3509db 22903* Python modules:: Python modules provided by @value{GDBN}.
d57a3c85
TJB
22904@end menu
22905
22906@node Python Commands
22907@subsection Python Commands
22908@cindex python commands
22909@cindex commands to access python
22910
8315665e 22911@value{GDBN} provides two commands for accessing the Python interpreter,
d57a3c85
TJB
22912and one related setting:
22913
22914@table @code
8315665e
YPK
22915@kindex python-interactive
22916@kindex pi
22917@item python-interactive @r{[}@var{command}@r{]}
22918@itemx pi @r{[}@var{command}@r{]}
22919Without an argument, the @code{python-interactive} command can be used
e3480f4a
YPK
22920to start an interactive Python prompt. To return to @value{GDBN},
22921type the @code{EOF} character (e.g., @kbd{Ctrl-D} on an empty prompt).
8315665e
YPK
22922
22923Alternatively, a single-line Python command can be given as an
22924argument and evaluated. If the command is an expression, the result
22925will be printed; otherwise, nothing will be printed. For example:
22926
22927@smallexample
22928(@value{GDBP}) python-interactive 2 + 3
229295
22930@end smallexample
22931
d57a3c85 22932@kindex python
8315665e
YPK
22933@kindex py
22934@item python @r{[}@var{command}@r{]}
22935@itemx py @r{[}@var{command}@r{]}
d57a3c85
TJB
22936The @code{python} command can be used to evaluate Python code.
22937
22938If given an argument, the @code{python} command will evaluate the
22939argument as a Python command. For example:
22940
22941@smallexample
22942(@value{GDBP}) python print 23
2294323
22944@end smallexample
22945
22946If you do not provide an argument to @code{python}, it will act as a
22947multi-line command, like @code{define}. In this case, the Python
22948script is made up of subsequent command lines, given after the
22949@code{python} command. This command list is terminated using a line
22950containing @code{end}. For example:
22951
22952@smallexample
22953(@value{GDBP}) python
22954Type python script
22955End with a line saying just "end".
22956>print 23
22957>end
2295823
22959@end smallexample
22960
713389e0
PM
22961@kindex set python print-stack
22962@item set python print-stack
80b6e756
PM
22963By default, @value{GDBN} will print only the message component of a
22964Python exception when an error occurs in a Python script. This can be
22965controlled using @code{set python print-stack}: if @code{full}, then
22966full Python stack printing is enabled; if @code{none}, then Python stack
22967and message printing is disabled; if @code{message}, the default, only
22968the message component of the error is printed.
d57a3c85
TJB
22969@end table
22970
95433b34
JB
22971It is also possible to execute a Python script from the @value{GDBN}
22972interpreter:
22973
22974@table @code
22975@item source @file{script-name}
22976The script name must end with @samp{.py} and @value{GDBN} must be configured
22977to recognize the script language based on filename extension using
22978the @code{script-extension} setting. @xref{Extending GDB, ,Extending GDB}.
22979
22980@item python execfile ("script-name")
22981This method is based on the @code{execfile} Python built-in function,
22982and thus is always available.
22983@end table
22984
d57a3c85
TJB
22985@node Python API
22986@subsection Python API
22987@cindex python api
22988@cindex programming in python
22989
22990@cindex python stdout
22991@cindex python pagination
22992At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
22993@code{sys.stderr} to print using @value{GDBN}'s output-paging streams.
22994A Python program which outputs to one of these streams may have its
22995output interrupted by the user (@pxref{Screen Size}). In this
22996situation, a Python @code{KeyboardInterrupt} exception is thrown.
22997
22998@menu
22999* Basic Python:: Basic Python Functions.
06e65f44
TT
23000* Exception Handling:: How Python exceptions are translated.
23001* Values From Inferior:: Python representation of values.
4c374409
JK
23002* Types In Python:: Python representation of types.
23003* Pretty Printing API:: Pretty-printing values.
a6bac58e 23004* Selecting Pretty-Printers:: How GDB chooses a pretty-printer.
7b51bc51 23005* Writing a Pretty-Printer:: Writing a Pretty-Printer.
18a9fc12 23006* Type Printing API:: Pretty-printing types.
595939de 23007* Inferiors In Python:: Python representation of inferiors (processes)
505500db 23008* Events In Python:: Listening for events from @value{GDBN}.
595939de 23009* Threads In Python:: Accessing inferior threads from Python.
d8906c6f 23010* Commands In Python:: Implementing new commands in Python.
d7b32ed3 23011* Parameters In Python:: Adding new @value{GDBN} parameters.
bc3b79fd 23012* Functions In Python:: Writing new convenience functions.
fa33c3cd 23013* Progspaces In Python:: Program spaces.
89c73ade 23014* Objfiles In Python:: Object files.
f3e9a817
PM
23015* Frames In Python:: Accessing inferior stack frames from Python.
23016* Blocks In Python:: Accessing frame blocks from Python.
23017* Symbols In Python:: Python representation of symbols.
23018* Symbol Tables In Python:: Python representation of symbol tables.
adc36818 23019* Breakpoints In Python:: Manipulating breakpoints using Python.
cc72b2a2
KP
23020* Finish Breakpoints in Python:: Setting Breakpoints on function return
23021 using Python.
984359d2 23022* Lazy Strings In Python:: Python representation of lazy strings.
bea883fd 23023* Architectures In Python:: Python representation of architectures.
d57a3c85
TJB
23024@end menu
23025
23026@node Basic Python
23027@subsubsection Basic Python
23028
23029@cindex python functions
23030@cindex python module
23031@cindex gdb module
23032@value{GDBN} introduces a new Python module, named @code{gdb}. All
23033methods and classes added by @value{GDBN} are placed in this module.
23034@value{GDBN} automatically @code{import}s the @code{gdb} module for
23035use in all scripts evaluated by the @code{python} command.
23036
9279c692 23037@findex gdb.PYTHONDIR
d812018b 23038@defvar gdb.PYTHONDIR
9279c692
JB
23039A string containing the python directory (@pxref{Python}).
23040@end defvar
23041
d57a3c85 23042@findex gdb.execute
d812018b 23043@defun gdb.execute (command @r{[}, from_tty @r{[}, to_string@r{]]})
d57a3c85
TJB
23044Evaluate @var{command}, a string, as a @value{GDBN} CLI command.
23045If a GDB exception happens while @var{command} runs, it is
23046translated as described in @ref{Exception Handling,,Exception Handling}.
12453b93
TJB
23047
23048@var{from_tty} specifies whether @value{GDBN} ought to consider this
23049command as having originated from the user invoking it interactively.
23050It must be a boolean value. If omitted, it defaults to @code{False}.
bc9f0842
TT
23051
23052By default, any output produced by @var{command} is sent to
23053@value{GDBN}'s standard output. If the @var{to_string} parameter is
23054@code{True}, then output will be collected by @code{gdb.execute} and
23055returned as a string. The default is @code{False}, in which case the
5da1313b
JK
23056return value is @code{None}. If @var{to_string} is @code{True}, the
23057@value{GDBN} virtual terminal will be temporarily set to unlimited width
23058and height, and its pagination will be disabled; @pxref{Screen Size}.
d57a3c85
TJB
23059@end defun
23060
adc36818 23061@findex gdb.breakpoints
d812018b 23062@defun gdb.breakpoints ()
adc36818
PM
23063Return a sequence holding all of @value{GDBN}'s breakpoints.
23064@xref{Breakpoints In Python}, for more information.
23065@end defun
23066
8f500870 23067@findex gdb.parameter
d812018b 23068@defun gdb.parameter (parameter)
d57a3c85
TJB
23069Return the value of a @value{GDBN} parameter. @var{parameter} is a
23070string naming the parameter to look up; @var{parameter} may contain
23071spaces if the parameter has a multi-part name. For example,
23072@samp{print object} is a valid parameter name.
23073
23074If the named parameter does not exist, this function throws a
621c8364
TT
23075@code{gdb.error} (@pxref{Exception Handling}). Otherwise, the
23076parameter's value is converted to a Python value of the appropriate
23077type, and returned.
d57a3c85
TJB
23078@end defun
23079
08c637de 23080@findex gdb.history
d812018b 23081@defun gdb.history (number)
08c637de
TJB
23082Return a value from @value{GDBN}'s value history (@pxref{Value
23083History}). @var{number} indicates which history element to return.
23084If @var{number} is negative, then @value{GDBN} will take its absolute value
23085and count backward from the last element (i.e., the most recent element) to
23086find the value to return. If @var{number} is zero, then @value{GDBN} will
a0c36267 23087return the most recent element. If the element specified by @var{number}
621c8364 23088doesn't exist in the value history, a @code{gdb.error} exception will be
08c637de
TJB
23089raised.
23090
23091If no exception is raised, the return value is always an instance of
23092@code{gdb.Value} (@pxref{Values From Inferior}).
23093@end defun
23094
57a1d736 23095@findex gdb.parse_and_eval
d812018b 23096@defun gdb.parse_and_eval (expression)
57a1d736
TT
23097Parse @var{expression} as an expression in the current language,
23098evaluate it, and return the result as a @code{gdb.Value}.
23099@var{expression} must be a string.
23100
23101This function can be useful when implementing a new command
23102(@pxref{Commands In Python}), as it provides a way to parse the
23103command's argument as an expression. It is also useful simply to
23104compute values, for example, it is the only way to get the value of a
23105convenience variable (@pxref{Convenience Vars}) as a @code{gdb.Value}.
23106@end defun
23107
7efc75aa
SCR
23108@findex gdb.find_pc_line
23109@defun gdb.find_pc_line (pc)
23110Return the @code{gdb.Symtab_and_line} object corresponding to the
23111@var{pc} value. @xref{Symbol Tables In Python}. If an invalid
23112value of @var{pc} is passed as an argument, then the @code{symtab} and
23113@code{line} attributes of the returned @code{gdb.Symtab_and_line} object
23114will be @code{None} and 0 respectively.
23115@end defun
23116
ca5c20b6 23117@findex gdb.post_event
d812018b 23118@defun gdb.post_event (event)
ca5c20b6
PM
23119Put @var{event}, a callable object taking no arguments, into
23120@value{GDBN}'s internal event queue. This callable will be invoked at
23121some later point, during @value{GDBN}'s event processing. Events
23122posted using @code{post_event} will be run in the order in which they
23123were posted; however, there is no way to know when they will be
23124processed relative to other events inside @value{GDBN}.
23125
23126@value{GDBN} is not thread-safe. If your Python program uses multiple
23127threads, you must be careful to only call @value{GDBN}-specific
23128functions in the main @value{GDBN} thread. @code{post_event} ensures
23129this. For example:
23130
23131@smallexample
23132(@value{GDBP}) python
23133>import threading
23134>
23135>class Writer():
23136> def __init__(self, message):
23137> self.message = message;
23138> def __call__(self):
23139> gdb.write(self.message)
23140>
23141>class MyThread1 (threading.Thread):
23142> def run (self):
23143> gdb.post_event(Writer("Hello "))
23144>
23145>class MyThread2 (threading.Thread):
23146> def run (self):
23147> gdb.post_event(Writer("World\n"))
23148>
23149>MyThread1().start()
23150>MyThread2().start()
23151>end
23152(@value{GDBP}) Hello World
23153@end smallexample
23154@end defun
23155
99c3dc11 23156@findex gdb.write
d812018b 23157@defun gdb.write (string @r{[}, stream{]})
99c3dc11
PM
23158Print a string to @value{GDBN}'s paginated output stream. The
23159optional @var{stream} determines the stream to print to. The default
23160stream is @value{GDBN}'s standard output stream. Possible stream
23161values are:
23162
23163@table @code
23164@findex STDOUT
23165@findex gdb.STDOUT
d812018b 23166@item gdb.STDOUT
99c3dc11
PM
23167@value{GDBN}'s standard output stream.
23168
23169@findex STDERR
23170@findex gdb.STDERR
d812018b 23171@item gdb.STDERR
99c3dc11
PM
23172@value{GDBN}'s standard error stream.
23173
23174@findex STDLOG
23175@findex gdb.STDLOG
d812018b 23176@item gdb.STDLOG
99c3dc11
PM
23177@value{GDBN}'s log stream (@pxref{Logging Output}).
23178@end table
23179
d57a3c85 23180Writing to @code{sys.stdout} or @code{sys.stderr} will automatically
99c3dc11
PM
23181call this function and will automatically direct the output to the
23182relevant stream.
d57a3c85
TJB
23183@end defun
23184
23185@findex gdb.flush
d812018b 23186@defun gdb.flush ()
99c3dc11
PM
23187Flush the buffer of a @value{GDBN} paginated stream so that the
23188contents are displayed immediately. @value{GDBN} will flush the
23189contents of a stream automatically when it encounters a newline in the
23190buffer. The optional @var{stream} determines the stream to flush. The
23191default stream is @value{GDBN}'s standard output stream. Possible
23192stream values are:
23193
23194@table @code
23195@findex STDOUT
23196@findex gdb.STDOUT
d812018b 23197@item gdb.STDOUT
99c3dc11
PM
23198@value{GDBN}'s standard output stream.
23199
23200@findex STDERR
23201@findex gdb.STDERR
d812018b 23202@item gdb.STDERR
99c3dc11
PM
23203@value{GDBN}'s standard error stream.
23204
23205@findex STDLOG
23206@findex gdb.STDLOG
d812018b 23207@item gdb.STDLOG
99c3dc11
PM
23208@value{GDBN}'s log stream (@pxref{Logging Output}).
23209
23210@end table
23211
23212Flushing @code{sys.stdout} or @code{sys.stderr} will automatically
23213call this function for the relevant stream.
d57a3c85
TJB
23214@end defun
23215
f870a310 23216@findex gdb.target_charset
d812018b 23217@defun gdb.target_charset ()
f870a310
TT
23218Return the name of the current target character set (@pxref{Character
23219Sets}). This differs from @code{gdb.parameter('target-charset')} in
23220that @samp{auto} is never returned.
23221@end defun
23222
23223@findex gdb.target_wide_charset
d812018b 23224@defun gdb.target_wide_charset ()
f870a310
TT
23225Return the name of the current target wide character set
23226(@pxref{Character Sets}). This differs from
23227@code{gdb.parameter('target-wide-charset')} in that @samp{auto} is
23228never returned.
23229@end defun
23230
cb2e07a6 23231@findex gdb.solib_name
d812018b 23232@defun gdb.solib_name (address)
cb2e07a6
PM
23233Return the name of the shared library holding the given @var{address}
23234as a string, or @code{None}.
23235@end defun
23236
23237@findex gdb.decode_line
d812018b 23238@defun gdb.decode_line @r{[}expression@r{]}
cb2e07a6
PM
23239Return locations of the line specified by @var{expression}, or of the
23240current line if no argument was given. This function returns a Python
23241tuple containing two elements. The first element contains a string
23242holding any unparsed section of @var{expression} (or @code{None} if
23243the expression has been fully parsed). The second element contains
23244either @code{None} or another tuple that contains all the locations
23245that match the expression represented as @code{gdb.Symtab_and_line}
23246objects (@pxref{Symbol Tables In Python}). If @var{expression} is
23247provided, it is decoded the way that @value{GDBN}'s inbuilt
23248@code{break} or @code{edit} commands do (@pxref{Specify Location}).
23249@end defun
23250
d812018b 23251@defun gdb.prompt_hook (current_prompt)
fa3a4f15
PM
23252@anchor{prompt_hook}
23253
d17b6f81
PM
23254If @var{prompt_hook} is callable, @value{GDBN} will call the method
23255assigned to this operation before a prompt is displayed by
23256@value{GDBN}.
23257
23258The parameter @code{current_prompt} contains the current @value{GDBN}
23259prompt. This method must return a Python string, or @code{None}. If
23260a string is returned, the @value{GDBN} prompt will be set to that
23261string. If @code{None} is returned, @value{GDBN} will continue to use
23262the current prompt.
23263
23264Some prompts cannot be substituted in @value{GDBN}. Secondary prompts
23265such as those used by readline for command input, and annotation
23266related prompts are prohibited from being changed.
d812018b 23267@end defun
d17b6f81 23268
d57a3c85
TJB
23269@node Exception Handling
23270@subsubsection Exception Handling
23271@cindex python exceptions
23272@cindex exceptions, python
23273
23274When executing the @code{python} command, Python exceptions
23275uncaught within the Python code are translated to calls to
23276@value{GDBN} error-reporting mechanism. If the command that called
23277@code{python} does not handle the error, @value{GDBN} will
23278terminate it and print an error message containing the Python
23279exception name, the associated value, and the Python call stack
23280backtrace at the point where the exception was raised. Example:
23281
23282@smallexample
23283(@value{GDBP}) python print foo
23284Traceback (most recent call last):
23285 File "<string>", line 1, in <module>
23286NameError: name 'foo' is not defined
23287@end smallexample
23288
621c8364
TT
23289@value{GDBN} errors that happen in @value{GDBN} commands invoked by
23290Python code are converted to Python exceptions. The type of the
23291Python exception depends on the error.
23292
23293@ftable @code
23294@item gdb.error
23295This is the base class for most exceptions generated by @value{GDBN}.
23296It is derived from @code{RuntimeError}, for compatibility with earlier
23297versions of @value{GDBN}.
23298
23299If an error occurring in @value{GDBN} does not fit into some more
23300specific category, then the generated exception will have this type.
23301
23302@item gdb.MemoryError
23303This is a subclass of @code{gdb.error} which is thrown when an
23304operation tried to access invalid memory in the inferior.
23305
23306@item KeyboardInterrupt
23307User interrupt (via @kbd{C-c} or by typing @kbd{q} at a pagination
23308prompt) is translated to a Python @code{KeyboardInterrupt} exception.
23309@end ftable
23310
23311In all cases, your exception handler will see the @value{GDBN} error
23312message as its value and the Python call stack backtrace at the Python
23313statement closest to where the @value{GDBN} error occured as the
d57a3c85
TJB
23314traceback.
23315
07ca107c
DE
23316@findex gdb.GdbError
23317When implementing @value{GDBN} commands in Python via @code{gdb.Command},
23318it is useful to be able to throw an exception that doesn't cause a
23319traceback to be printed. For example, the user may have invoked the
23320command incorrectly. Use the @code{gdb.GdbError} exception
23321to handle this case. Example:
23322
23323@smallexample
23324(gdb) python
23325>class HelloWorld (gdb.Command):
23326> """Greet the whole world."""
23327> def __init__ (self):
7d74f244 23328> super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
07ca107c
DE
23329> def invoke (self, args, from_tty):
23330> argv = gdb.string_to_argv (args)
23331> if len (argv) != 0:
23332> raise gdb.GdbError ("hello-world takes no arguments")
23333> print "Hello, World!"
23334>HelloWorld ()
23335>end
23336(gdb) hello-world 42
23337hello-world takes no arguments
23338@end smallexample
23339
a08702d6
TJB
23340@node Values From Inferior
23341@subsubsection Values From Inferior
23342@cindex values from inferior, with Python
23343@cindex python, working with values from inferior
23344
23345@cindex @code{gdb.Value}
23346@value{GDBN} provides values it obtains from the inferior program in
23347an object of type @code{gdb.Value}. @value{GDBN} uses this object
23348for its internal bookkeeping of the inferior's values, and for
23349fetching values when necessary.
23350
23351Inferior values that are simple scalars can be used directly in
23352Python expressions that are valid for the value's data type. Here's
23353an example for an integer or floating-point value @code{some_val}:
23354
23355@smallexample
23356bar = some_val + 2
23357@end smallexample
23358
23359@noindent
23360As result of this, @code{bar} will also be a @code{gdb.Value} object
23361whose values are of the same type as those of @code{some_val}.
23362
23363Inferior values that are structures or instances of some class can
23364be accessed using the Python @dfn{dictionary syntax}. For example, if
23365@code{some_val} is a @code{gdb.Value} instance holding a structure, you
23366can access its @code{foo} element with:
23367
23368@smallexample
23369bar = some_val['foo']
23370@end smallexample
23371
23372Again, @code{bar} will also be a @code{gdb.Value} object.
23373
5374244e
PM
23374A @code{gdb.Value} that represents a function can be executed via
23375inferior function call. Any arguments provided to the call must match
23376the function's prototype, and must be provided in the order specified
23377by that prototype.
23378
23379For example, @code{some_val} is a @code{gdb.Value} instance
23380representing a function that takes two integers as arguments. To
23381execute this function, call it like so:
23382
23383@smallexample
23384result = some_val (10,20)
23385@end smallexample
23386
23387Any values returned from a function call will be stored as a
23388@code{gdb.Value}.
23389
c0c6f777 23390The following attributes are provided:
a08702d6 23391
d812018b 23392@defvar Value.address
c0c6f777
TJB
23393If this object is addressable, this read-only attribute holds a
23394@code{gdb.Value} object representing the address. Otherwise,
23395this attribute holds @code{None}.
d812018b 23396@end defvar
c0c6f777 23397
def2b000 23398@cindex optimized out value in Python
d812018b 23399@defvar Value.is_optimized_out
def2b000
TJB
23400This read-only boolean attribute is true if the compiler optimized out
23401this value, thus it is not available for fetching from the inferior.
d812018b 23402@end defvar
2c74e833 23403
d812018b 23404@defvar Value.type
2c74e833 23405The type of this @code{gdb.Value}. The value of this attribute is a
44592cc4 23406@code{gdb.Type} object (@pxref{Types In Python}).
d812018b 23407@end defvar
03f17ccf 23408
d812018b 23409@defvar Value.dynamic_type
03f17ccf 23410The dynamic type of this @code{gdb.Value}. This uses C@t{++} run-time
fccd1d1e
EZ
23411type information (@acronym{RTTI}) to determine the dynamic type of the
23412value. If this value is of class type, it will return the class in
23413which the value is embedded, if any. If this value is of pointer or
23414reference to a class type, it will compute the dynamic type of the
23415referenced object, and return a pointer or reference to that type,
23416respectively. In all other cases, it will return the value's static
23417type.
23418
23419Note that this feature will only work when debugging a C@t{++} program
23420that includes @acronym{RTTI} for the object in question. Otherwise,
23421it will just return the static type of the value as in @kbd{ptype foo}
23422(@pxref{Symbols, ptype}).
d812018b 23423@end defvar
22dbab46
PK
23424
23425@defvar Value.is_lazy
23426The value of this read-only boolean attribute is @code{True} if this
23427@code{gdb.Value} has not yet been fetched from the inferior.
23428@value{GDBN} does not fetch values until necessary, for efficiency.
23429For example:
23430
23431@smallexample
23432myval = gdb.parse_and_eval ('somevar')
23433@end smallexample
23434
23435The value of @code{somevar} is not fetched at this time. It will be
23436fetched when the value is needed, or when the @code{fetch_lazy}
23437method is invoked.
23438@end defvar
def2b000
TJB
23439
23440The following methods are provided:
23441
d812018b 23442@defun Value.__init__ (@var{val})
e8467610
TT
23443Many Python values can be converted directly to a @code{gdb.Value} via
23444this object initializer. Specifically:
23445
23446@table @asis
23447@item Python boolean
23448A Python boolean is converted to the boolean type from the current
23449language.
23450
23451@item Python integer
23452A Python integer is converted to the C @code{long} type for the
23453current architecture.
23454
23455@item Python long
23456A Python long is converted to the C @code{long long} type for the
23457current architecture.
23458
23459@item Python float
23460A Python float is converted to the C @code{double} type for the
23461current architecture.
23462
23463@item Python string
23464A Python string is converted to a target string, using the current
23465target encoding.
23466
23467@item @code{gdb.Value}
23468If @code{val} is a @code{gdb.Value}, then a copy of the value is made.
23469
23470@item @code{gdb.LazyString}
23471If @code{val} is a @code{gdb.LazyString} (@pxref{Lazy Strings In
23472Python}), then the lazy string's @code{value} method is called, and
23473its result is used.
23474@end table
d812018b 23475@end defun
e8467610 23476
d812018b 23477@defun Value.cast (type)
14ff2235
PM
23478Return a new instance of @code{gdb.Value} that is the result of
23479casting this instance to the type described by @var{type}, which must
23480be a @code{gdb.Type} object. If the cast cannot be performed for some
23481reason, this method throws an exception.
d812018b 23482@end defun
14ff2235 23483
d812018b 23484@defun Value.dereference ()
def2b000
TJB
23485For pointer data types, this method returns a new @code{gdb.Value} object
23486whose contents is the object pointed to by the pointer. For example, if
23487@code{foo} is a C pointer to an @code{int}, declared in your C program as
a08702d6
TJB
23488
23489@smallexample
23490int *foo;
23491@end smallexample
23492
23493@noindent
23494then you can use the corresponding @code{gdb.Value} to access what
23495@code{foo} points to like this:
23496
23497@smallexample
23498bar = foo.dereference ()
23499@end smallexample
23500
23501The result @code{bar} will be a @code{gdb.Value} object holding the
23502value pointed to by @code{foo}.
7b282c5a
SCR
23503
23504A similar function @code{Value.referenced_value} exists which also
23505returns @code{gdb.Value} objects corresonding to the values pointed to
23506by pointer values (and additionally, values referenced by reference
23507values). However, the behavior of @code{Value.dereference}
23508differs from @code{Value.referenced_value} by the fact that the
23509behavior of @code{Value.dereference} is identical to applying the C
23510unary operator @code{*} on a given value. For example, consider a
23511reference to a pointer @code{ptrref}, declared in your C@t{++} program
23512as
23513
23514@smallexample
23515typedef int *intptr;
23516...
23517int val = 10;
23518intptr ptr = &val;
23519intptr &ptrref = ptr;
23520@end smallexample
23521
23522Though @code{ptrref} is a reference value, one can apply the method
23523@code{Value.dereference} to the @code{gdb.Value} object corresponding
23524to it and obtain a @code{gdb.Value} which is identical to that
23525corresponding to @code{val}. However, if you apply the method
23526@code{Value.referenced_value}, the result would be a @code{gdb.Value}
23527object identical to that corresponding to @code{ptr}.
23528
23529@smallexample
23530py_ptrref = gdb.parse_and_eval ("ptrref")
23531py_val = py_ptrref.dereference ()
23532py_ptr = py_ptrref.referenced_value ()
23533@end smallexample
23534
23535The @code{gdb.Value} object @code{py_val} is identical to that
23536corresponding to @code{val}, and @code{py_ptr} is identical to that
23537corresponding to @code{ptr}. In general, @code{Value.dereference} can
23538be applied whenever the C unary operator @code{*} can be applied
23539to the corresponding C value. For those cases where applying both
23540@code{Value.dereference} and @code{Value.referenced_value} is allowed,
23541the results obtained need not be identical (as we have seen in the above
23542example). The results are however identical when applied on
23543@code{gdb.Value} objects corresponding to pointers (@code{gdb.Value}
23544objects with type code @code{TYPE_CODE_PTR}) in a C/C@t{++} program.
23545@end defun
23546
23547@defun Value.referenced_value ()
23548For pointer or reference data types, this method returns a new
23549@code{gdb.Value} object corresponding to the value referenced by the
23550pointer/reference value. For pointer data types,
23551@code{Value.dereference} and @code{Value.referenced_value} produce
23552identical results. The difference between these methods is that
23553@code{Value.dereference} cannot get the values referenced by reference
23554values. For example, consider a reference to an @code{int}, declared
23555in your C@t{++} program as
23556
23557@smallexample
23558int val = 10;
23559int &ref = val;
23560@end smallexample
23561
23562@noindent
23563then applying @code{Value.dereference} to the @code{gdb.Value} object
23564corresponding to @code{ref} will result in an error, while applying
23565@code{Value.referenced_value} will result in a @code{gdb.Value} object
23566identical to that corresponding to @code{val}.
23567
23568@smallexample
23569py_ref = gdb.parse_and_eval ("ref")
23570er_ref = py_ref.dereference () # Results in error
23571py_val = py_ref.referenced_value () # Returns the referenced value
23572@end smallexample
23573
23574The @code{gdb.Value} object @code{py_val} is identical to that
23575corresponding to @code{val}.
d812018b 23576@end defun
a08702d6 23577
d812018b 23578@defun Value.dynamic_cast (type)
f9ffd4bb
TT
23579Like @code{Value.cast}, but works as if the C@t{++} @code{dynamic_cast}
23580operator were used. Consult a C@t{++} reference for details.
d812018b 23581@end defun
f9ffd4bb 23582
d812018b 23583@defun Value.reinterpret_cast (type)
f9ffd4bb
TT
23584Like @code{Value.cast}, but works as if the C@t{++} @code{reinterpret_cast}
23585operator were used. Consult a C@t{++} reference for details.
d812018b 23586@end defun
f9ffd4bb 23587
d812018b 23588@defun Value.string (@r{[}encoding@r{[}, errors@r{[}, length@r{]]]})
b6cb8e7d
TJB
23589If this @code{gdb.Value} represents a string, then this method
23590converts the contents to a Python string. Otherwise, this method will
23591throw an exception.
23592
23593Strings are recognized in a language-specific way; whether a given
23594@code{gdb.Value} represents a string is determined by the current
23595language.
23596
23597For C-like languages, a value is a string if it is a pointer to or an
23598array of characters or ints. The string is assumed to be terminated
fbb8f299
PM
23599by a zero of the appropriate width. However if the optional length
23600argument is given, the string will be converted to that given length,
23601ignoring any embedded zeros that the string may contain.
b6cb8e7d
TJB
23602
23603If the optional @var{encoding} argument is given, it must be a string
23604naming the encoding of the string in the @code{gdb.Value}, such as
23605@code{"ascii"}, @code{"iso-8859-6"} or @code{"utf-8"}. It accepts
23606the same encodings as the corresponding argument to Python's
23607@code{string.decode} method, and the Python codec machinery will be used
23608to convert the string. If @var{encoding} is not given, or if
23609@var{encoding} is the empty string, then either the @code{target-charset}
23610(@pxref{Character Sets}) will be used, or a language-specific encoding
23611will be used, if the current language is able to supply one.
23612
23613The optional @var{errors} argument is the same as the corresponding
23614argument to Python's @code{string.decode} method.
fbb8f299
PM
23615
23616If the optional @var{length} argument is given, the string will be
23617fetched and converted to the given length.
d812018b 23618@end defun
be759fcf 23619
d812018b 23620@defun Value.lazy_string (@r{[}encoding @r{[}, length@r{]]})
be759fcf
PM
23621If this @code{gdb.Value} represents a string, then this method
23622converts the contents to a @code{gdb.LazyString} (@pxref{Lazy Strings
23623In Python}). Otherwise, this method will throw an exception.
23624
23625If the optional @var{encoding} argument is given, it must be a string
23626naming the encoding of the @code{gdb.LazyString}. Some examples are:
23627@samp{ascii}, @samp{iso-8859-6} or @samp{utf-8}. If the
23628@var{encoding} argument is an encoding that @value{GDBN} does
23629recognize, @value{GDBN} will raise an error.
23630
23631When a lazy string is printed, the @value{GDBN} encoding machinery is
23632used to convert the string during printing. If the optional
23633@var{encoding} argument is not provided, or is an empty string,
23634@value{GDBN} will automatically select the encoding most suitable for
23635the string type. For further information on encoding in @value{GDBN}
23636please see @ref{Character Sets}.
23637
23638If the optional @var{length} argument is given, the string will be
23639fetched and encoded to the length of characters specified. If
23640the @var{length} argument is not provided, the string will be fetched
23641and encoded until a null of appropriate width is found.
d812018b 23642@end defun
22dbab46
PK
23643
23644@defun Value.fetch_lazy ()
23645If the @code{gdb.Value} object is currently a lazy value
23646(@code{gdb.Value.is_lazy} is @code{True}), then the value is
23647fetched from the inferior. Any errors that occur in the process
23648will produce a Python exception.
23649
23650If the @code{gdb.Value} object is not a lazy value, this method
23651has no effect.
23652
23653This method does not return a value.
23654@end defun
23655
b6cb8e7d 23656
2c74e833
TT
23657@node Types In Python
23658@subsubsection Types In Python
23659@cindex types in Python
23660@cindex Python, working with types
23661
23662@tindex gdb.Type
23663@value{GDBN} represents types from the inferior using the class
23664@code{gdb.Type}.
23665
23666The following type-related functions are available in the @code{gdb}
23667module:
23668
23669@findex gdb.lookup_type
d812018b 23670@defun gdb.lookup_type (name @r{[}, block@r{]})
2c74e833
TT
23671This function looks up a type by name. @var{name} is the name of the
23672type to look up. It must be a string.
23673
5107b149
PM
23674If @var{block} is given, then @var{name} is looked up in that scope.
23675Otherwise, it is searched for globally.
23676
2c74e833
TT
23677Ordinarily, this function will return an instance of @code{gdb.Type}.
23678If the named type cannot be found, it will throw an exception.
23679@end defun
23680
a73bb892
PK
23681If the type is a structure or class type, or an enum type, the fields
23682of that type can be accessed using the Python @dfn{dictionary syntax}.
23683For example, if @code{some_type} is a @code{gdb.Type} instance holding
23684a structure type, you can access its @code{foo} field with:
23685
23686@smallexample
23687bar = some_type['foo']
23688@end smallexample
23689
23690@code{bar} will be a @code{gdb.Field} object; see below under the
23691description of the @code{Type.fields} method for a description of the
23692@code{gdb.Field} class.
23693
2c74e833
TT
23694An instance of @code{Type} has the following attributes:
23695
d812018b 23696@defvar Type.code
2c74e833
TT
23697The type code for this type. The type code will be one of the
23698@code{TYPE_CODE_} constants defined below.
d812018b 23699@end defvar
2c74e833 23700
d812018b 23701@defvar Type.sizeof
2c74e833
TT
23702The size of this type, in target @code{char} units. Usually, a
23703target's @code{char} type will be an 8-bit byte. However, on some
23704unusual platforms, this type may have a different size.
d812018b 23705@end defvar
2c74e833 23706
d812018b 23707@defvar Type.tag
2c74e833
TT
23708The tag name for this type. The tag name is the name after
23709@code{struct}, @code{union}, or @code{enum} in C and C@t{++}; not all
23710languages have this concept. If this type has no tag name, then
23711@code{None} is returned.
d812018b 23712@end defvar
2c74e833
TT
23713
23714The following methods are provided:
23715
d812018b 23716@defun Type.fields ()
2c74e833
TT
23717For structure and union types, this method returns the fields. Range
23718types have two fields, the minimum and maximum values. Enum types
23719have one field per enum constant. Function and method types have one
23720field per parameter. The base types of C@t{++} classes are also
23721represented as fields. If the type has no fields, or does not fit
23722into one of these categories, an empty sequence will be returned.
23723
a73bb892 23724Each field is a @code{gdb.Field} object, with some pre-defined attributes:
2c74e833
TT
23725@table @code
23726@item bitpos
23727This attribute is not available for @code{static} fields (as in
23728C@t{++} or Java). For non-@code{static} fields, the value is the bit
a9f54f60
TT
23729position of the field. For @code{enum} fields, the value is the
23730enumeration member's integer representation.
2c74e833
TT
23731
23732@item name
23733The name of the field, or @code{None} for anonymous fields.
23734
23735@item artificial
23736This is @code{True} if the field is artificial, usually meaning that
23737it was provided by the compiler and not the user. This attribute is
23738always provided, and is @code{False} if the field is not artificial.
23739
bfd31e71
PM
23740@item is_base_class
23741This is @code{True} if the field represents a base class of a C@t{++}
23742structure. This attribute is always provided, and is @code{False}
23743if the field is not a base class of the type that is the argument of
23744@code{fields}, or if that type was not a C@t{++} class.
23745
2c74e833
TT
23746@item bitsize
23747If the field is packed, or is a bitfield, then this will have a
23748non-zero value, which is the size of the field in bits. Otherwise,
23749this will be zero; in this case the field's size is given by its type.
23750
23751@item type
23752The type of the field. This is usually an instance of @code{Type},
23753but it can be @code{None} in some situations.
23754@end table
d812018b 23755@end defun
2c74e833 23756
d812018b 23757@defun Type.array (@var{n1} @r{[}, @var{n2}@r{]})
702c2711
TT
23758Return a new @code{gdb.Type} object which represents an array of this
23759type. If one argument is given, it is the inclusive upper bound of
23760the array; in this case the lower bound is zero. If two arguments are
23761given, the first argument is the lower bound of the array, and the
23762second argument is the upper bound of the array. An array's length
23763must not be negative, but the bounds can be.
d812018b 23764@end defun
702c2711 23765
a72c3253
DE
23766@defun Type.vector (@var{n1} @r{[}, @var{n2}@r{]})
23767Return a new @code{gdb.Type} object which represents a vector of this
23768type. If one argument is given, it is the inclusive upper bound of
23769the vector; in this case the lower bound is zero. If two arguments are
23770given, the first argument is the lower bound of the vector, and the
23771second argument is the upper bound of the vector. A vector's length
23772must not be negative, but the bounds can be.
23773
23774The difference between an @code{array} and a @code{vector} is that
23775arrays behave like in C: when used in expressions they decay to a pointer
23776to the first element whereas vectors are treated as first class values.
23777@end defun
23778
d812018b 23779@defun Type.const ()
2c74e833
TT
23780Return a new @code{gdb.Type} object which represents a
23781@code{const}-qualified variant of this type.
d812018b 23782@end defun
2c74e833 23783
d812018b 23784@defun Type.volatile ()
2c74e833
TT
23785Return a new @code{gdb.Type} object which represents a
23786@code{volatile}-qualified variant of this type.
d812018b 23787@end defun
2c74e833 23788
d812018b 23789@defun Type.unqualified ()
2c74e833
TT
23790Return a new @code{gdb.Type} object which represents an unqualified
23791variant of this type. That is, the result is neither @code{const} nor
23792@code{volatile}.
d812018b 23793@end defun
2c74e833 23794
d812018b 23795@defun Type.range ()
361ae042
PM
23796Return a Python @code{Tuple} object that contains two elements: the
23797low bound of the argument type and the high bound of that type. If
23798the type does not have a range, @value{GDBN} will raise a
621c8364 23799@code{gdb.error} exception (@pxref{Exception Handling}).
d812018b 23800@end defun
361ae042 23801
d812018b 23802@defun Type.reference ()
2c74e833
TT
23803Return a new @code{gdb.Type} object which represents a reference to this
23804type.
d812018b 23805@end defun
2c74e833 23806
d812018b 23807@defun Type.pointer ()
7a6973ad
TT
23808Return a new @code{gdb.Type} object which represents a pointer to this
23809type.
d812018b 23810@end defun
7a6973ad 23811
d812018b 23812@defun Type.strip_typedefs ()
2c74e833
TT
23813Return a new @code{gdb.Type} that represents the real type,
23814after removing all layers of typedefs.
d812018b 23815@end defun
2c74e833 23816
d812018b 23817@defun Type.target ()
2c74e833
TT
23818Return a new @code{gdb.Type} object which represents the target type
23819of this type.
23820
23821For a pointer type, the target type is the type of the pointed-to
23822object. For an array type (meaning C-like arrays), the target type is
23823the type of the elements of the array. For a function or method type,
23824the target type is the type of the return value. For a complex type,
23825the target type is the type of the elements. For a typedef, the
23826target type is the aliased type.
23827
23828If the type does not have a target, this method will throw an
23829exception.
d812018b 23830@end defun
2c74e833 23831
d812018b 23832@defun Type.template_argument (n @r{[}, block@r{]})
2c74e833
TT
23833If this @code{gdb.Type} is an instantiation of a template, this will
23834return a new @code{gdb.Type} which represents the type of the
23835@var{n}th template argument.
23836
23837If this @code{gdb.Type} is not a template type, this will throw an
23838exception. Ordinarily, only C@t{++} code will have template types.
23839
5107b149
PM
23840If @var{block} is given, then @var{name} is looked up in that scope.
23841Otherwise, it is searched for globally.
d812018b 23842@end defun
2c74e833
TT
23843
23844
23845Each type has a code, which indicates what category this type falls
23846into. The available type categories are represented by constants
23847defined in the @code{gdb} module:
23848
23849@table @code
23850@findex TYPE_CODE_PTR
23851@findex gdb.TYPE_CODE_PTR
d812018b 23852@item gdb.TYPE_CODE_PTR
2c74e833
TT
23853The type is a pointer.
23854
23855@findex TYPE_CODE_ARRAY
23856@findex gdb.TYPE_CODE_ARRAY
d812018b 23857@item gdb.TYPE_CODE_ARRAY
2c74e833
TT
23858The type is an array.
23859
23860@findex TYPE_CODE_STRUCT
23861@findex gdb.TYPE_CODE_STRUCT
d812018b 23862@item gdb.TYPE_CODE_STRUCT
2c74e833
TT
23863The type is a structure.
23864
23865@findex TYPE_CODE_UNION
23866@findex gdb.TYPE_CODE_UNION
d812018b 23867@item gdb.TYPE_CODE_UNION
2c74e833
TT
23868The type is a union.
23869
23870@findex TYPE_CODE_ENUM
23871@findex gdb.TYPE_CODE_ENUM
d812018b 23872@item gdb.TYPE_CODE_ENUM
2c74e833
TT
23873The type is an enum.
23874
23875@findex TYPE_CODE_FLAGS
23876@findex gdb.TYPE_CODE_FLAGS
d812018b 23877@item gdb.TYPE_CODE_FLAGS
2c74e833
TT
23878A bit flags type, used for things such as status registers.
23879
23880@findex TYPE_CODE_FUNC
23881@findex gdb.TYPE_CODE_FUNC
d812018b 23882@item gdb.TYPE_CODE_FUNC
2c74e833
TT
23883The type is a function.
23884
23885@findex TYPE_CODE_INT
23886@findex gdb.TYPE_CODE_INT
d812018b 23887@item gdb.TYPE_CODE_INT
2c74e833
TT
23888The type is an integer type.
23889
23890@findex TYPE_CODE_FLT
23891@findex gdb.TYPE_CODE_FLT
d812018b 23892@item gdb.TYPE_CODE_FLT
2c74e833
TT
23893A floating point type.
23894
23895@findex TYPE_CODE_VOID
23896@findex gdb.TYPE_CODE_VOID
d812018b 23897@item gdb.TYPE_CODE_VOID
2c74e833
TT
23898The special type @code{void}.
23899
23900@findex TYPE_CODE_SET
23901@findex gdb.TYPE_CODE_SET
d812018b 23902@item gdb.TYPE_CODE_SET
2c74e833
TT
23903A Pascal set type.
23904
23905@findex TYPE_CODE_RANGE
23906@findex gdb.TYPE_CODE_RANGE
d812018b 23907@item gdb.TYPE_CODE_RANGE
2c74e833
TT
23908A range type, that is, an integer type with bounds.
23909
23910@findex TYPE_CODE_STRING
23911@findex gdb.TYPE_CODE_STRING
d812018b 23912@item gdb.TYPE_CODE_STRING
2c74e833
TT
23913A string type. Note that this is only used for certain languages with
23914language-defined string types; C strings are not represented this way.
23915
23916@findex TYPE_CODE_BITSTRING
23917@findex gdb.TYPE_CODE_BITSTRING
d812018b 23918@item gdb.TYPE_CODE_BITSTRING
6b1755ce 23919A string of bits. It is deprecated.
2c74e833
TT
23920
23921@findex TYPE_CODE_ERROR
23922@findex gdb.TYPE_CODE_ERROR
d812018b 23923@item gdb.TYPE_CODE_ERROR
2c74e833
TT
23924An unknown or erroneous type.
23925
23926@findex TYPE_CODE_METHOD
23927@findex gdb.TYPE_CODE_METHOD
d812018b 23928@item gdb.TYPE_CODE_METHOD
2c74e833
TT
23929A method type, as found in C@t{++} or Java.
23930
23931@findex TYPE_CODE_METHODPTR
23932@findex gdb.TYPE_CODE_METHODPTR
d812018b 23933@item gdb.TYPE_CODE_METHODPTR
2c74e833
TT
23934A pointer-to-member-function.
23935
23936@findex TYPE_CODE_MEMBERPTR
23937@findex gdb.TYPE_CODE_MEMBERPTR
d812018b 23938@item gdb.TYPE_CODE_MEMBERPTR
2c74e833
TT
23939A pointer-to-member.
23940
23941@findex TYPE_CODE_REF
23942@findex gdb.TYPE_CODE_REF
d812018b 23943@item gdb.TYPE_CODE_REF
2c74e833
TT
23944A reference type.
23945
23946@findex TYPE_CODE_CHAR
23947@findex gdb.TYPE_CODE_CHAR
d812018b 23948@item gdb.TYPE_CODE_CHAR
2c74e833
TT
23949A character type.
23950
23951@findex TYPE_CODE_BOOL
23952@findex gdb.TYPE_CODE_BOOL
d812018b 23953@item gdb.TYPE_CODE_BOOL
2c74e833
TT
23954A boolean type.
23955
23956@findex TYPE_CODE_COMPLEX
23957@findex gdb.TYPE_CODE_COMPLEX
d812018b 23958@item gdb.TYPE_CODE_COMPLEX
2c74e833
TT
23959A complex float type.
23960
23961@findex TYPE_CODE_TYPEDEF
23962@findex gdb.TYPE_CODE_TYPEDEF
d812018b 23963@item gdb.TYPE_CODE_TYPEDEF
2c74e833
TT
23964A typedef to some other type.
23965
23966@findex TYPE_CODE_NAMESPACE
23967@findex gdb.TYPE_CODE_NAMESPACE
d812018b 23968@item gdb.TYPE_CODE_NAMESPACE
2c74e833
TT
23969A C@t{++} namespace.
23970
23971@findex TYPE_CODE_DECFLOAT
23972@findex gdb.TYPE_CODE_DECFLOAT
d812018b 23973@item gdb.TYPE_CODE_DECFLOAT
2c74e833
TT
23974A decimal floating point type.
23975
23976@findex TYPE_CODE_INTERNAL_FUNCTION
23977@findex gdb.TYPE_CODE_INTERNAL_FUNCTION
d812018b 23978@item gdb.TYPE_CODE_INTERNAL_FUNCTION
2c74e833
TT
23979A function internal to @value{GDBN}. This is the type used to represent
23980convenience functions.
23981@end table
23982
0e3509db
DE
23983Further support for types is provided in the @code{gdb.types}
23984Python module (@pxref{gdb.types}).
23985
4c374409
JK
23986@node Pretty Printing API
23987@subsubsection Pretty Printing API
a6bac58e 23988
4c374409 23989An example output is provided (@pxref{Pretty Printing}).
a6bac58e
TT
23990
23991A pretty-printer is just an object that holds a value and implements a
23992specific interface, defined here.
23993
d812018b 23994@defun pretty_printer.children (self)
a6bac58e
TT
23995@value{GDBN} will call this method on a pretty-printer to compute the
23996children of the pretty-printer's value.
23997
23998This method must return an object conforming to the Python iterator
23999protocol. Each item returned by the iterator must be a tuple holding
24000two elements. The first element is the ``name'' of the child; the
24001second element is the child's value. The value can be any Python
24002object which is convertible to a @value{GDBN} value.
24003
24004This method is optional. If it does not exist, @value{GDBN} will act
24005as though the value has no children.
d812018b 24006@end defun
a6bac58e 24007
d812018b 24008@defun pretty_printer.display_hint (self)
a6bac58e
TT
24009The CLI may call this method and use its result to change the
24010formatting of a value. The result will also be supplied to an MI
24011consumer as a @samp{displayhint} attribute of the variable being
24012printed.
24013
24014This method is optional. If it does exist, this method must return a
24015string.
24016
24017Some display hints are predefined by @value{GDBN}:
24018
24019@table @samp
24020@item array
24021Indicate that the object being printed is ``array-like''. The CLI
24022uses this to respect parameters such as @code{set print elements} and
24023@code{set print array}.
24024
24025@item map
24026Indicate that the object being printed is ``map-like'', and that the
24027children of this value can be assumed to alternate between keys and
24028values.
24029
24030@item string
24031Indicate that the object being printed is ``string-like''. If the
24032printer's @code{to_string} method returns a Python string of some
24033kind, then @value{GDBN} will call its internal language-specific
24034string-printing function to format the string. For the CLI this means
24035adding quotation marks, possibly escaping some characters, respecting
24036@code{set print elements}, and the like.
24037@end table
d812018b 24038@end defun
a6bac58e 24039
d812018b 24040@defun pretty_printer.to_string (self)
a6bac58e
TT
24041@value{GDBN} will call this method to display the string
24042representation of the value passed to the object's constructor.
24043
24044When printing from the CLI, if the @code{to_string} method exists,
24045then @value{GDBN} will prepend its result to the values returned by
24046@code{children}. Exactly how this formatting is done is dependent on
24047the display hint, and may change as more hints are added. Also,
24048depending on the print settings (@pxref{Print Settings}), the CLI may
24049print just the result of @code{to_string} in a stack trace, omitting
24050the result of @code{children}.
24051
24052If this method returns a string, it is printed verbatim.
24053
24054Otherwise, if this method returns an instance of @code{gdb.Value},
24055then @value{GDBN} prints this value. This may result in a call to
24056another pretty-printer.
24057
24058If instead the method returns a Python value which is convertible to a
24059@code{gdb.Value}, then @value{GDBN} performs the conversion and prints
24060the resulting value. Again, this may result in a call to another
24061pretty-printer. Python scalars (integers, floats, and booleans) and
24062strings are convertible to @code{gdb.Value}; other types are not.
24063
79f283fe
PM
24064Finally, if this method returns @code{None} then no further operations
24065are peformed in this method and nothing is printed.
24066
a6bac58e 24067If the result is not one of these types, an exception is raised.
d812018b 24068@end defun
a6bac58e 24069
464b3efb
TT
24070@value{GDBN} provides a function which can be used to look up the
24071default pretty-printer for a @code{gdb.Value}:
24072
24073@findex gdb.default_visualizer
d812018b 24074@defun gdb.default_visualizer (value)
464b3efb
TT
24075This function takes a @code{gdb.Value} object as an argument. If a
24076pretty-printer for this value exists, then it is returned. If no such
24077printer exists, then this returns @code{None}.
24078@end defun
24079
a6bac58e
TT
24080@node Selecting Pretty-Printers
24081@subsubsection Selecting Pretty-Printers
24082
24083The Python list @code{gdb.pretty_printers} contains an array of
967cf477 24084functions or callable objects that have been registered via addition
7b51bc51
DE
24085as a pretty-printer. Printers in this list are called @code{global}
24086printers, they're available when debugging all inferiors.
fa33c3cd 24087Each @code{gdb.Progspace} contains a @code{pretty_printers} attribute.
a6bac58e
TT
24088Each @code{gdb.Objfile} also contains a @code{pretty_printers}
24089attribute.
24090
7b51bc51 24091Each function on these lists is passed a single @code{gdb.Value}
a6bac58e 24092argument and should return a pretty-printer object conforming to the
4c374409 24093interface definition above (@pxref{Pretty Printing API}). If a function
a6bac58e
TT
24094cannot create a pretty-printer for the value, it should return
24095@code{None}.
24096
24097@value{GDBN} first checks the @code{pretty_printers} attribute of each
fa33c3cd 24098@code{gdb.Objfile} in the current program space and iteratively calls
7b51bc51
DE
24099each enabled lookup routine in the list for that @code{gdb.Objfile}
24100until it receives a pretty-printer object.
fa33c3cd
DE
24101If no pretty-printer is found in the objfile lists, @value{GDBN} then
24102searches the pretty-printer list of the current program space,
967cf477 24103calling each enabled function until an object is returned.
a6bac58e 24104After these lists have been exhausted, it tries the global
967cf477 24105@code{gdb.pretty_printers} list, again calling each enabled function until an
a6bac58e
TT
24106object is returned.
24107
24108The order in which the objfiles are searched is not specified. For a
24109given list, functions are always invoked from the head of the list,
24110and iterated over sequentially until the end of the list, or a printer
24111object is returned.
24112
7b51bc51
DE
24113For various reasons a pretty-printer may not work.
24114For example, the underlying data structure may have changed and
24115the pretty-printer is out of date.
24116
24117The consequences of a broken pretty-printer are severe enough that
24118@value{GDBN} provides support for enabling and disabling individual
24119printers. For example, if @code{print frame-arguments} is on,
24120a backtrace can become highly illegible if any argument is printed
24121with a broken printer.
24122
24123Pretty-printers are enabled and disabled by attaching an @code{enabled}
24124attribute to the registered function or callable object. If this attribute
24125is present and its value is @code{False}, the printer is disabled, otherwise
24126the printer is enabled.
24127
24128@node Writing a Pretty-Printer
24129@subsubsection Writing a Pretty-Printer
24130@cindex writing a pretty-printer
24131
24132A pretty-printer consists of two parts: a lookup function to detect
24133if the type is supported, and the printer itself.
24134
a6bac58e 24135Here is an example showing how a @code{std::string} printer might be
7b51bc51
DE
24136written. @xref{Pretty Printing API}, for details on the API this class
24137must provide.
a6bac58e
TT
24138
24139@smallexample
7b51bc51 24140class StdStringPrinter(object):
a6bac58e
TT
24141 "Print a std::string"
24142
7b51bc51 24143 def __init__(self, val):
a6bac58e
TT
24144 self.val = val
24145
7b51bc51 24146 def to_string(self):
a6bac58e
TT
24147 return self.val['_M_dataplus']['_M_p']
24148
7b51bc51 24149 def display_hint(self):
a6bac58e
TT
24150 return 'string'
24151@end smallexample
24152
24153And here is an example showing how a lookup function for the printer
24154example above might be written.
24155
24156@smallexample
7b51bc51 24157def str_lookup_function(val):
a6bac58e 24158 lookup_tag = val.type.tag
a6bac58e
TT
24159 if lookup_tag == None:
24160 return None
7b51bc51
DE
24161 regex = re.compile("^std::basic_string<char,.*>$")
24162 if regex.match(lookup_tag):
24163 return StdStringPrinter(val)
a6bac58e
TT
24164 return None
24165@end smallexample
24166
24167The example lookup function extracts the value's type, and attempts to
24168match it to a type that it can pretty-print. If it is a type the
24169printer can pretty-print, it will return a printer object. If not, it
24170returns @code{None}.
24171
24172We recommend that you put your core pretty-printers into a Python
24173package. If your pretty-printers are for use with a library, we
24174further recommend embedding a version number into the package name.
24175This practice will enable @value{GDBN} to load multiple versions of
24176your pretty-printers at the same time, because they will have
24177different names.
24178
bf88dd68 24179You should write auto-loaded code (@pxref{Python Auto-loading}) such that it
a6bac58e
TT
24180can be evaluated multiple times without changing its meaning. An
24181ideal auto-load file will consist solely of @code{import}s of your
24182printer modules, followed by a call to a register pretty-printers with
24183the current objfile.
24184
24185Taken as a whole, this approach will scale nicely to multiple
24186inferiors, each potentially using a different library version.
24187Embedding a version number in the Python package name will ensure that
24188@value{GDBN} is able to load both sets of printers simultaneously.
24189Then, because the search for pretty-printers is done by objfile, and
24190because your auto-loaded code took care to register your library's
24191printers with a specific objfile, @value{GDBN} will find the correct
24192printers for the specific version of the library used by each
24193inferior.
24194
4c374409 24195To continue the @code{std::string} example (@pxref{Pretty Printing API}),
a6bac58e
TT
24196this code might appear in @code{gdb.libstdcxx.v6}:
24197
24198@smallexample
7b51bc51 24199def register_printers(objfile):
ae6f0d5b 24200 objfile.pretty_printers.append(str_lookup_function)
a6bac58e
TT
24201@end smallexample
24202
24203@noindent
24204And then the corresponding contents of the auto-load file would be:
24205
24206@smallexample
24207import gdb.libstdcxx.v6
7b51bc51 24208gdb.libstdcxx.v6.register_printers(gdb.current_objfile())
a6bac58e
TT
24209@end smallexample
24210
7b51bc51
DE
24211The previous example illustrates a basic pretty-printer.
24212There are a few things that can be improved on.
24213The printer doesn't have a name, making it hard to identify in a
24214list of installed printers. The lookup function has a name, but
24215lookup functions can have arbitrary, even identical, names.
967cf477 24216
7b51bc51
DE
24217Second, the printer only handles one type, whereas a library typically has
24218several types. One could install a lookup function for each desired type
24219in the library, but one could also have a single lookup function recognize
24220several types. The latter is the conventional way this is handled.
24221If a pretty-printer can handle multiple data types, then its
24222@dfn{subprinters} are the printers for the individual data types.
967cf477 24223
7b51bc51
DE
24224The @code{gdb.printing} module provides a formal way of solving these
24225problems (@pxref{gdb.printing}).
24226Here is another example that handles multiple types.
967cf477 24227
7b51bc51
DE
24228These are the types we are going to pretty-print:
24229
24230@smallexample
24231struct foo @{ int a, b; @};
24232struct bar @{ struct foo x, y; @};
24233@end smallexample
24234
24235Here are the printers:
24236
24237@smallexample
24238class fooPrinter:
24239 """Print a foo object."""
24240
24241 def __init__(self, val):
24242 self.val = val
24243
24244 def to_string(self):
24245 return ("a=<" + str(self.val["a"]) +
24246 "> b=<" + str(self.val["b"]) + ">")
24247
24248class barPrinter:
24249 """Print a bar object."""
24250
24251 def __init__(self, val):
24252 self.val = val
24253
24254 def to_string(self):
24255 return ("x=<" + str(self.val["x"]) +
24256 "> y=<" + str(self.val["y"]) + ">")
24257@end smallexample
24258
24259This example doesn't need a lookup function, that is handled by the
24260@code{gdb.printing} module. Instead a function is provided to build up
24261the object that handles the lookup.
24262
24263@smallexample
24264import gdb.printing
24265
24266def build_pretty_printer():
24267 pp = gdb.printing.RegexpCollectionPrettyPrinter(
24268 "my_library")
24269 pp.add_printer('foo', '^foo$', fooPrinter)
24270 pp.add_printer('bar', '^bar$', barPrinter)
24271 return pp
24272@end smallexample
24273
24274And here is the autoload support:
24275
24276@smallexample
24277import gdb.printing
24278import my_library
24279gdb.printing.register_pretty_printer(
24280 gdb.current_objfile(),
24281 my_library.build_pretty_printer())
24282@end smallexample
24283
24284Finally, when this printer is loaded into @value{GDBN}, here is the
24285corresponding output of @samp{info pretty-printer}:
24286
24287@smallexample
24288(gdb) info pretty-printer
24289my_library.so:
24290 my_library
24291 foo
24292 bar
24293@end smallexample
967cf477 24294
18a9fc12
TT
24295@node Type Printing API
24296@subsubsection Type Printing API
24297@cindex type printing API for Python
24298
24299@value{GDBN} provides a way for Python code to customize type display.
24300This is mainly useful for substituting canonical typedef names for
24301types.
24302
24303@cindex type printer
24304A @dfn{type printer} is just a Python object conforming to a certain
24305protocol. A simple base class implementing the protocol is provided;
24306see @ref{gdb.types}. A type printer must supply at least:
24307
24308@defivar type_printer enabled
24309A boolean which is True if the printer is enabled, and False
24310otherwise. This is manipulated by the @code{enable type-printer}
24311and @code{disable type-printer} commands.
24312@end defivar
24313
24314@defivar type_printer name
24315The name of the type printer. This must be a string. This is used by
24316the @code{enable type-printer} and @code{disable type-printer}
24317commands.
24318@end defivar
24319
24320@defmethod type_printer instantiate (self)
24321This is called by @value{GDBN} at the start of type-printing. It is
24322only called if the type printer is enabled. This method must return a
24323new object that supplies a @code{recognize} method, as described below.
24324@end defmethod
24325
24326
24327When displaying a type, say via the @code{ptype} command, @value{GDBN}
24328will compute a list of type recognizers. This is done by iterating
24329first over the per-objfile type printers (@pxref{Objfiles In Python}),
24330followed by the per-progspace type printers (@pxref{Progspaces In
24331Python}), and finally the global type printers.
24332
24333@value{GDBN} will call the @code{instantiate} method of each enabled
24334type printer. If this method returns @code{None}, then the result is
24335ignored; otherwise, it is appended to the list of recognizers.
24336
24337Then, when @value{GDBN} is going to display a type name, it iterates
24338over the list of recognizers. For each one, it calls the recognition
24339function, stopping if the function returns a non-@code{None} value.
24340The recognition function is defined as:
24341
24342@defmethod type_recognizer recognize (self, type)
24343If @var{type} is not recognized, return @code{None}. Otherwise,
24344return a string which is to be printed as the name of @var{type}.
24345@var{type} will be an instance of @code{gdb.Type} (@pxref{Types In
24346Python}).
24347@end defmethod
24348
24349@value{GDBN} uses this two-pass approach so that type printers can
24350efficiently cache information without holding on to it too long. For
24351example, it can be convenient to look up type information in a type
24352printer and hold it for a recognizer's lifetime; if a single pass were
24353done then type printers would have to make use of the event system in
24354order to avoid holding information that could become stale as the
24355inferior changed.
24356
595939de
PM
24357@node Inferiors In Python
24358@subsubsection Inferiors In Python
505500db 24359@cindex inferiors in Python
595939de
PM
24360
24361@findex gdb.Inferior
24362Programs which are being run under @value{GDBN} are called inferiors
24363(@pxref{Inferiors and Programs}). Python scripts can access
24364information about and manipulate inferiors controlled by @value{GDBN}
24365via objects of the @code{gdb.Inferior} class.
24366
24367The following inferior-related functions are available in the @code{gdb}
24368module:
24369
d812018b 24370@defun gdb.inferiors ()
595939de
PM
24371Return a tuple containing all inferior objects.
24372@end defun
24373
d812018b 24374@defun gdb.selected_inferior ()
2aa48337
KP
24375Return an object representing the current inferior.
24376@end defun
24377
595939de
PM
24378A @code{gdb.Inferior} object has the following attributes:
24379
d812018b 24380@defvar Inferior.num
595939de 24381ID of inferior, as assigned by GDB.
d812018b 24382@end defvar
595939de 24383
d812018b 24384@defvar Inferior.pid
595939de
PM
24385Process ID of the inferior, as assigned by the underlying operating
24386system.
d812018b 24387@end defvar
595939de 24388
d812018b 24389@defvar Inferior.was_attached
595939de
PM
24390Boolean signaling whether the inferior was created using `attach', or
24391started by @value{GDBN} itself.
d812018b 24392@end defvar
595939de
PM
24393
24394A @code{gdb.Inferior} object has the following methods:
24395
d812018b 24396@defun Inferior.is_valid ()
29703da4
PM
24397Returns @code{True} if the @code{gdb.Inferior} object is valid,
24398@code{False} if not. A @code{gdb.Inferior} object will become invalid
24399if the inferior no longer exists within @value{GDBN}. All other
24400@code{gdb.Inferior} methods will throw an exception if it is invalid
24401at the time the method is called.
d812018b 24402@end defun
29703da4 24403
d812018b 24404@defun Inferior.threads ()
595939de
PM
24405This method returns a tuple holding all the threads which are valid
24406when it is called. If there are no valid threads, the method will
24407return an empty tuple.
d812018b 24408@end defun
595939de 24409
2678e2af 24410@findex Inferior.read_memory
d812018b 24411@defun Inferior.read_memory (address, length)
595939de
PM
24412Read @var{length} bytes of memory from the inferior, starting at
24413@var{address}. Returns a buffer object, which behaves much like an array
2678e2af 24414or a string. It can be modified and given to the
9a27f2c6
PK
24415@code{Inferior.write_memory} function. In @code{Python} 3, the return
24416value is a @code{memoryview} object.
d812018b 24417@end defun
595939de 24418
2678e2af 24419@findex Inferior.write_memory
d812018b 24420@defun Inferior.write_memory (address, buffer @r{[}, length@r{]})
595939de
PM
24421Write the contents of @var{buffer} to the inferior, starting at
24422@var{address}. The @var{buffer} parameter must be a Python object
24423which supports the buffer protocol, i.e., a string, an array or the
2678e2af 24424object returned from @code{Inferior.read_memory}. If given, @var{length}
595939de 24425determines the number of bytes from @var{buffer} to be written.
d812018b 24426@end defun
595939de
PM
24427
24428@findex gdb.search_memory
d812018b 24429@defun Inferior.search_memory (address, length, pattern)
595939de
PM
24430Search a region of the inferior memory starting at @var{address} with
24431the given @var{length} using the search pattern supplied in
24432@var{pattern}. The @var{pattern} parameter must be a Python object
24433which supports the buffer protocol, i.e., a string, an array or the
24434object returned from @code{gdb.read_memory}. Returns a Python @code{Long}
24435containing the address where the pattern was found, or @code{None} if
24436the pattern could not be found.
d812018b 24437@end defun
595939de 24438
505500db
SW
24439@node Events In Python
24440@subsubsection Events In Python
24441@cindex inferior events in Python
24442
24443@value{GDBN} provides a general event facility so that Python code can be
24444notified of various state changes, particularly changes that occur in
24445the inferior.
24446
24447An @dfn{event} is just an object that describes some state change. The
24448type of the object and its attributes will vary depending on the details
24449of the change. All the existing events are described below.
24450
24451In order to be notified of an event, you must register an event handler
24452with an @dfn{event registry}. An event registry is an object in the
24453@code{gdb.events} module which dispatches particular events. A registry
24454provides methods to register and unregister event handlers:
24455
d812018b 24456@defun EventRegistry.connect (object)
505500db
SW
24457Add the given callable @var{object} to the registry. This object will be
24458called when an event corresponding to this registry occurs.
d812018b 24459@end defun
505500db 24460
d812018b 24461@defun EventRegistry.disconnect (object)
505500db
SW
24462Remove the given @var{object} from the registry. Once removed, the object
24463will no longer receive notifications of events.
d812018b 24464@end defun
505500db
SW
24465
24466Here is an example:
24467
24468@smallexample
24469def exit_handler (event):
24470 print "event type: exit"
24471 print "exit code: %d" % (event.exit_code)
24472
24473gdb.events.exited.connect (exit_handler)
24474@end smallexample
24475
24476In the above example we connect our handler @code{exit_handler} to the
24477registry @code{events.exited}. Once connected, @code{exit_handler} gets
24478called when the inferior exits. The argument @dfn{event} in this example is
24479of type @code{gdb.ExitedEvent}. As you can see in the example the
24480@code{ExitedEvent} object has an attribute which indicates the exit code of
24481the inferior.
24482
24483The following is a listing of the event registries that are available and
24484details of the events they emit:
24485
24486@table @code
24487
24488@item events.cont
24489Emits @code{gdb.ThreadEvent}.
24490
24491Some events can be thread specific when @value{GDBN} is running in non-stop
24492mode. When represented in Python, these events all extend
24493@code{gdb.ThreadEvent}. Note, this event is not emitted directly; instead,
24494events which are emitted by this or other modules might extend this event.
24495Examples of these events are @code{gdb.BreakpointEvent} and
24496@code{gdb.ContinueEvent}.
24497
d812018b 24498@defvar ThreadEvent.inferior_thread
505500db
SW
24499In non-stop mode this attribute will be set to the specific thread which was
24500involved in the emitted event. Otherwise, it will be set to @code{None}.
d812018b 24501@end defvar
505500db
SW
24502
24503Emits @code{gdb.ContinueEvent} which extends @code{gdb.ThreadEvent}.
24504
24505This event indicates that the inferior has been continued after a stop. For
24506inherited attribute refer to @code{gdb.ThreadEvent} above.
24507
24508@item events.exited
24509Emits @code{events.ExitedEvent} which indicates that the inferior has exited.
cb6be26b 24510@code{events.ExitedEvent} has two attributes:
d812018b 24511@defvar ExitedEvent.exit_code
cb6be26b
KP
24512An integer representing the exit code, if available, which the inferior
24513has returned. (The exit code could be unavailable if, for example,
24514@value{GDBN} detaches from the inferior.) If the exit code is unavailable,
24515the attribute does not exist.
24516@end defvar
24517@defvar ExitedEvent inferior
24518A reference to the inferior which triggered the @code{exited} event.
d812018b 24519@end defvar
505500db
SW
24520
24521@item events.stop
24522Emits @code{gdb.StopEvent} which extends @code{gdb.ThreadEvent}.
24523
24524Indicates that the inferior has stopped. All events emitted by this registry
24525extend StopEvent. As a child of @code{gdb.ThreadEvent}, @code{gdb.StopEvent}
24526will indicate the stopped thread when @value{GDBN} is running in non-stop
24527mode. Refer to @code{gdb.ThreadEvent} above for more details.
24528
24529Emits @code{gdb.SignalEvent} which extends @code{gdb.StopEvent}.
24530
24531This event indicates that the inferior or one of its threads has received as
24532signal. @code{gdb.SignalEvent} has the following attributes:
24533
d812018b 24534@defvar SignalEvent.stop_signal
505500db
SW
24535A string representing the signal received by the inferior. A list of possible
24536signal values can be obtained by running the command @code{info signals} in
24537the @value{GDBN} command prompt.
d812018b 24538@end defvar
505500db
SW
24539
24540Also emits @code{gdb.BreakpointEvent} which extends @code{gdb.StopEvent}.
24541
6839b47f
KP
24542@code{gdb.BreakpointEvent} event indicates that one or more breakpoints have
24543been hit, and has the following attributes:
505500db 24544
d812018b 24545@defvar BreakpointEvent.breakpoints
6839b47f
KP
24546A sequence containing references to all the breakpoints (type
24547@code{gdb.Breakpoint}) that were hit.
505500db 24548@xref{Breakpoints In Python}, for details of the @code{gdb.Breakpoint} object.
d812018b
PK
24549@end defvar
24550@defvar BreakpointEvent.breakpoint
6839b47f
KP
24551A reference to the first breakpoint that was hit.
24552This function is maintained for backward compatibility and is now deprecated
d812018b
PK
24553in favor of the @code{gdb.BreakpointEvent.breakpoints} attribute.
24554@end defvar
505500db 24555
20c168b5
KP
24556@item events.new_objfile
24557Emits @code{gdb.NewObjFileEvent} which indicates that a new object file has
24558been loaded by @value{GDBN}. @code{gdb.NewObjFileEvent} has one attribute:
24559
20c168b5
KP
24560@defvar NewObjFileEvent.new_objfile
24561A reference to the object file (@code{gdb.Objfile}) which has been loaded.
24562@xref{Objfiles In Python}, for details of the @code{gdb.Objfile} object.
24563@end defvar
20c168b5 24564
505500db
SW
24565@end table
24566
595939de
PM
24567@node Threads In Python
24568@subsubsection Threads In Python
24569@cindex threads in python
24570
24571@findex gdb.InferiorThread
24572Python scripts can access information about, and manipulate inferior threads
24573controlled by @value{GDBN}, via objects of the @code{gdb.InferiorThread} class.
24574
24575The following thread-related functions are available in the @code{gdb}
24576module:
24577
24578@findex gdb.selected_thread
d812018b 24579@defun gdb.selected_thread ()
595939de
PM
24580This function returns the thread object for the selected thread. If there
24581is no selected thread, this will return @code{None}.
24582@end defun
24583
24584A @code{gdb.InferiorThread} object has the following attributes:
24585
d812018b 24586@defvar InferiorThread.name
4694da01
TT
24587The name of the thread. If the user specified a name using
24588@code{thread name}, then this returns that name. Otherwise, if an
24589OS-supplied name is available, then it is returned. Otherwise, this
24590returns @code{None}.
24591
24592This attribute can be assigned to. The new value must be a string
24593object, which sets the new name, or @code{None}, which removes any
24594user-specified thread name.
d812018b 24595@end defvar
4694da01 24596
d812018b 24597@defvar InferiorThread.num
595939de 24598ID of the thread, as assigned by GDB.
d812018b 24599@end defvar
595939de 24600
d812018b 24601@defvar InferiorThread.ptid
595939de
PM
24602ID of the thread, as assigned by the operating system. This attribute is a
24603tuple containing three integers. The first is the Process ID (PID); the second
24604is the Lightweight Process ID (LWPID), and the third is the Thread ID (TID).
24605Either the LWPID or TID may be 0, which indicates that the operating system
24606does not use that identifier.
d812018b 24607@end defvar
595939de
PM
24608
24609A @code{gdb.InferiorThread} object has the following methods:
24610
d812018b 24611@defun InferiorThread.is_valid ()
29703da4
PM
24612Returns @code{True} if the @code{gdb.InferiorThread} object is valid,
24613@code{False} if not. A @code{gdb.InferiorThread} object will become
24614invalid if the thread exits, or the inferior that the thread belongs
24615is deleted. All other @code{gdb.InferiorThread} methods will throw an
24616exception if it is invalid at the time the method is called.
d812018b 24617@end defun
29703da4 24618
d812018b 24619@defun InferiorThread.switch ()
595939de
PM
24620This changes @value{GDBN}'s currently selected thread to the one represented
24621by this object.
d812018b 24622@end defun
595939de 24623
d812018b 24624@defun InferiorThread.is_stopped ()
595939de 24625Return a Boolean indicating whether the thread is stopped.
d812018b 24626@end defun
595939de 24627
d812018b 24628@defun InferiorThread.is_running ()
595939de 24629Return a Boolean indicating whether the thread is running.
d812018b 24630@end defun
595939de 24631
d812018b 24632@defun InferiorThread.is_exited ()
595939de 24633Return a Boolean indicating whether the thread is exited.
d812018b 24634@end defun
595939de 24635
d8906c6f
TJB
24636@node Commands In Python
24637@subsubsection Commands In Python
24638
24639@cindex commands in python
24640@cindex python commands
d8906c6f
TJB
24641You can implement new @value{GDBN} CLI commands in Python. A CLI
24642command is implemented using an instance of the @code{gdb.Command}
24643class, most commonly using a subclass.
24644
f05e2e1d 24645@defun Command.__init__ (name, @var{command_class} @r{[}, @var{completer_class} @r{[}, @var{prefix}@r{]]})
d8906c6f
TJB
24646The object initializer for @code{Command} registers the new command
24647with @value{GDBN}. This initializer is normally invoked from the
24648subclass' own @code{__init__} method.
24649
24650@var{name} is the name of the command. If @var{name} consists of
24651multiple words, then the initial words are looked for as prefix
24652commands. In this case, if one of the prefix commands does not exist,
24653an exception is raised.
24654
24655There is no support for multi-line commands.
24656
cc924cad 24657@var{command_class} should be one of the @samp{COMMAND_} constants
d8906c6f
TJB
24658defined below. This argument tells @value{GDBN} how to categorize the
24659new command in the help system.
24660
cc924cad 24661@var{completer_class} is an optional argument. If given, it should be
d8906c6f
TJB
24662one of the @samp{COMPLETE_} constants defined below. This argument
24663tells @value{GDBN} how to perform completion for this command. If not
24664given, @value{GDBN} will attempt to complete using the object's
24665@code{complete} method (see below); if no such method is found, an
24666error will occur when completion is attempted.
24667
24668@var{prefix} is an optional argument. If @code{True}, then the new
24669command is a prefix command; sub-commands of this command may be
24670registered.
24671
24672The help text for the new command is taken from the Python
24673documentation string for the command's class, if there is one. If no
24674documentation string is provided, the default value ``This command is
24675not documented.'' is used.
d812018b 24676@end defun
d8906c6f 24677
a0c36267 24678@cindex don't repeat Python command
d812018b 24679@defun Command.dont_repeat ()
d8906c6f
TJB
24680By default, a @value{GDBN} command is repeated when the user enters a
24681blank line at the command prompt. A command can suppress this
24682behavior by invoking the @code{dont_repeat} method. This is similar
24683to the user command @code{dont-repeat}, see @ref{Define, dont-repeat}.
d812018b 24684@end defun
d8906c6f 24685
d812018b 24686@defun Command.invoke (argument, from_tty)
d8906c6f
TJB
24687This method is called by @value{GDBN} when this command is invoked.
24688
24689@var{argument} is a string. It is the argument to the command, after
24690leading and trailing whitespace has been stripped.
24691
24692@var{from_tty} is a boolean argument. When true, this means that the
24693command was entered by the user at the terminal; when false it means
24694that the command came from elsewhere.
24695
24696If this method throws an exception, it is turned into a @value{GDBN}
24697@code{error} call. Otherwise, the return value is ignored.
07ca107c
DE
24698
24699@findex gdb.string_to_argv
24700To break @var{argument} up into an argv-like string use
24701@code{gdb.string_to_argv}. This function behaves identically to
24702@value{GDBN}'s internal argument lexer @code{buildargv}.
24703It is recommended to use this for consistency.
24704Arguments are separated by spaces and may be quoted.
24705Example:
24706
24707@smallexample
24708print gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\"")
24709['1', '2 "3', '4 "5', "6 '7"]
24710@end smallexample
24711
d812018b 24712@end defun
d8906c6f 24713
a0c36267 24714@cindex completion of Python commands
d812018b 24715@defun Command.complete (text, word)
d8906c6f
TJB
24716This method is called by @value{GDBN} when the user attempts
24717completion on this command. All forms of completion are handled by
a0c36267
EZ
24718this method, that is, the @key{TAB} and @key{M-?} key bindings
24719(@pxref{Completion}), and the @code{complete} command (@pxref{Help,
24720complete}).
d8906c6f
TJB
24721
24722The arguments @var{text} and @var{word} are both strings. @var{text}
24723holds the complete command line up to the cursor's location.
24724@var{word} holds the last word of the command line; this is computed
24725using a word-breaking heuristic.
24726
24727The @code{complete} method can return several values:
24728@itemize @bullet
24729@item
24730If the return value is a sequence, the contents of the sequence are
24731used as the completions. It is up to @code{complete} to ensure that the
24732contents actually do complete the word. A zero-length sequence is
24733allowed, it means that there were no completions available. Only
24734string elements of the sequence are used; other elements in the
24735sequence are ignored.
24736
24737@item
24738If the return value is one of the @samp{COMPLETE_} constants defined
24739below, then the corresponding @value{GDBN}-internal completion
24740function is invoked, and its result is used.
24741
24742@item
24743All other results are treated as though there were no available
24744completions.
24745@end itemize
d812018b 24746@end defun
d8906c6f 24747
d8906c6f
TJB
24748When a new command is registered, it must be declared as a member of
24749some general class of commands. This is used to classify top-level
24750commands in the on-line help system; note that prefix commands are not
24751listed under their own category but rather that of their top-level
24752command. The available classifications are represented by constants
24753defined in the @code{gdb} module:
24754
24755@table @code
24756@findex COMMAND_NONE
24757@findex gdb.COMMAND_NONE
d812018b 24758@item gdb.COMMAND_NONE
d8906c6f
TJB
24759The command does not belong to any particular class. A command in
24760this category will not be displayed in any of the help categories.
24761
24762@findex COMMAND_RUNNING
24763@findex gdb.COMMAND_RUNNING
d812018b 24764@item gdb.COMMAND_RUNNING
d8906c6f
TJB
24765The command is related to running the inferior. For example,
24766@code{start}, @code{step}, and @code{continue} are in this category.
a0c36267 24767Type @kbd{help running} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
24768commands in this category.
24769
24770@findex COMMAND_DATA
24771@findex gdb.COMMAND_DATA
d812018b 24772@item gdb.COMMAND_DATA
d8906c6f
TJB
24773The command is related to data or variables. For example,
24774@code{call}, @code{find}, and @code{print} are in this category. Type
a0c36267 24775@kbd{help data} at the @value{GDBN} prompt to see a list of commands
d8906c6f
TJB
24776in this category.
24777
24778@findex COMMAND_STACK
24779@findex gdb.COMMAND_STACK
d812018b 24780@item gdb.COMMAND_STACK
d8906c6f
TJB
24781The command has to do with manipulation of the stack. For example,
24782@code{backtrace}, @code{frame}, and @code{return} are in this
a0c36267 24783category. Type @kbd{help stack} at the @value{GDBN} prompt to see a
d8906c6f
TJB
24784list of commands in this category.
24785
24786@findex COMMAND_FILES
24787@findex gdb.COMMAND_FILES
d812018b 24788@item gdb.COMMAND_FILES
d8906c6f
TJB
24789This class is used for file-related commands. For example,
24790@code{file}, @code{list} and @code{section} are in this category.
a0c36267 24791Type @kbd{help files} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
24792commands in this category.
24793
24794@findex COMMAND_SUPPORT
24795@findex gdb.COMMAND_SUPPORT
d812018b 24796@item gdb.COMMAND_SUPPORT
d8906c6f
TJB
24797This should be used for ``support facilities'', generally meaning
24798things that are useful to the user when interacting with @value{GDBN},
24799but not related to the state of the inferior. For example,
24800@code{help}, @code{make}, and @code{shell} are in this category. Type
a0c36267 24801@kbd{help support} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
24802commands in this category.
24803
24804@findex COMMAND_STATUS
24805@findex gdb.COMMAND_STATUS
d812018b 24806@item gdb.COMMAND_STATUS
d8906c6f
TJB
24807The command is an @samp{info}-related command, that is, related to the
24808state of @value{GDBN} itself. For example, @code{info}, @code{macro},
a0c36267 24809and @code{show} are in this category. Type @kbd{help status} at the
d8906c6f
TJB
24810@value{GDBN} prompt to see a list of commands in this category.
24811
24812@findex COMMAND_BREAKPOINTS
24813@findex gdb.COMMAND_BREAKPOINTS
d812018b 24814@item gdb.COMMAND_BREAKPOINTS
d8906c6f 24815The command has to do with breakpoints. For example, @code{break},
a0c36267 24816@code{clear}, and @code{delete} are in this category. Type @kbd{help
d8906c6f
TJB
24817breakpoints} at the @value{GDBN} prompt to see a list of commands in
24818this category.
24819
24820@findex COMMAND_TRACEPOINTS
24821@findex gdb.COMMAND_TRACEPOINTS
d812018b 24822@item gdb.COMMAND_TRACEPOINTS
d8906c6f
TJB
24823The command has to do with tracepoints. For example, @code{trace},
24824@code{actions}, and @code{tfind} are in this category. Type
a0c36267 24825@kbd{help tracepoints} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
24826commands in this category.
24827
7d74f244
DE
24828@findex COMMAND_USER
24829@findex gdb.COMMAND_USER
24830@item gdb.COMMAND_USER
24831The command is a general purpose command for the user, and typically
24832does not fit in one of the other categories.
24833Type @kbd{help user-defined} at the @value{GDBN} prompt to see
24834a list of commands in this category, as well as the list of gdb macros
24835(@pxref{Sequences}).
24836
d8906c6f
TJB
24837@findex COMMAND_OBSCURE
24838@findex gdb.COMMAND_OBSCURE
d812018b 24839@item gdb.COMMAND_OBSCURE
d8906c6f
TJB
24840The command is only used in unusual circumstances, or is not of
24841general interest to users. For example, @code{checkpoint},
a0c36267 24842@code{fork}, and @code{stop} are in this category. Type @kbd{help
d8906c6f
TJB
24843obscure} at the @value{GDBN} prompt to see a list of commands in this
24844category.
24845
24846@findex COMMAND_MAINTENANCE
24847@findex gdb.COMMAND_MAINTENANCE
d812018b 24848@item gdb.COMMAND_MAINTENANCE
d8906c6f
TJB
24849The command is only useful to @value{GDBN} maintainers. The
24850@code{maintenance} and @code{flushregs} commands are in this category.
a0c36267 24851Type @kbd{help internals} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
24852commands in this category.
24853@end table
24854
d8906c6f
TJB
24855A new command can use a predefined completion function, either by
24856specifying it via an argument at initialization, or by returning it
24857from the @code{complete} method. These predefined completion
24858constants are all defined in the @code{gdb} module:
24859
24860@table @code
24861@findex COMPLETE_NONE
24862@findex gdb.COMPLETE_NONE
d812018b 24863@item gdb.COMPLETE_NONE
d8906c6f
TJB
24864This constant means that no completion should be done.
24865
24866@findex COMPLETE_FILENAME
24867@findex gdb.COMPLETE_FILENAME
d812018b 24868@item gdb.COMPLETE_FILENAME
d8906c6f
TJB
24869This constant means that filename completion should be performed.
24870
24871@findex COMPLETE_LOCATION
24872@findex gdb.COMPLETE_LOCATION
d812018b 24873@item gdb.COMPLETE_LOCATION
d8906c6f
TJB
24874This constant means that location completion should be done.
24875@xref{Specify Location}.
24876
24877@findex COMPLETE_COMMAND
24878@findex gdb.COMPLETE_COMMAND
d812018b 24879@item gdb.COMPLETE_COMMAND
d8906c6f
TJB
24880This constant means that completion should examine @value{GDBN}
24881command names.
24882
24883@findex COMPLETE_SYMBOL
24884@findex gdb.COMPLETE_SYMBOL
d812018b 24885@item gdb.COMPLETE_SYMBOL
d8906c6f
TJB
24886This constant means that completion should be done using symbol names
24887as the source.
24888@end table
24889
24890The following code snippet shows how a trivial CLI command can be
24891implemented in Python:
24892
24893@smallexample
24894class HelloWorld (gdb.Command):
24895 """Greet the whole world."""
24896
24897 def __init__ (self):
7d74f244 24898 super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
d8906c6f
TJB
24899
24900 def invoke (self, arg, from_tty):
24901 print "Hello, World!"
24902
24903HelloWorld ()
24904@end smallexample
24905
24906The last line instantiates the class, and is necessary to trigger the
24907registration of the command with @value{GDBN}. Depending on how the
24908Python code is read into @value{GDBN}, you may need to import the
24909@code{gdb} module explicitly.
24910
d7b32ed3
PM
24911@node Parameters In Python
24912@subsubsection Parameters In Python
24913
24914@cindex parameters in python
24915@cindex python parameters
24916@tindex gdb.Parameter
24917@tindex Parameter
24918You can implement new @value{GDBN} parameters using Python. A new
24919parameter is implemented as an instance of the @code{gdb.Parameter}
24920class.
24921
24922Parameters are exposed to the user via the @code{set} and
24923@code{show} commands. @xref{Help}.
24924
24925There are many parameters that already exist and can be set in
24926@value{GDBN}. Two examples are: @code{set follow fork} and
24927@code{set charset}. Setting these parameters influences certain
24928behavior in @value{GDBN}. Similarly, you can define parameters that
24929can be used to influence behavior in custom Python scripts and commands.
24930
d812018b 24931@defun Parameter.__init__ (name, @var{command-class}, @var{parameter-class} @r{[}, @var{enum-sequence}@r{]})
d7b32ed3
PM
24932The object initializer for @code{Parameter} registers the new
24933parameter with @value{GDBN}. This initializer is normally invoked
24934from the subclass' own @code{__init__} method.
24935
24936@var{name} is the name of the new parameter. If @var{name} consists
24937of multiple words, then the initial words are looked for as prefix
24938parameters. An example of this can be illustrated with the
24939@code{set print} set of parameters. If @var{name} is
24940@code{print foo}, then @code{print} will be searched as the prefix
24941parameter. In this case the parameter can subsequently be accessed in
24942@value{GDBN} as @code{set print foo}.
24943
24944If @var{name} consists of multiple words, and no prefix parameter group
24945can be found, an exception is raised.
24946
24947@var{command-class} should be one of the @samp{COMMAND_} constants
24948(@pxref{Commands In Python}). This argument tells @value{GDBN} how to
24949categorize the new parameter in the help system.
24950
24951@var{parameter-class} should be one of the @samp{PARAM_} constants
24952defined below. This argument tells @value{GDBN} the type of the new
24953parameter; this information is used for input validation and
24954completion.
24955
24956If @var{parameter-class} is @code{PARAM_ENUM}, then
24957@var{enum-sequence} must be a sequence of strings. These strings
24958represent the possible values for the parameter.
24959
24960If @var{parameter-class} is not @code{PARAM_ENUM}, then the presence
24961of a fourth argument will cause an exception to be thrown.
24962
24963The help text for the new parameter is taken from the Python
24964documentation string for the parameter's class, if there is one. If
24965there is no documentation string, a default value is used.
d812018b 24966@end defun
d7b32ed3 24967
d812018b 24968@defvar Parameter.set_doc
d7b32ed3
PM
24969If this attribute exists, and is a string, then its value is used as
24970the help text for this parameter's @code{set} command. The value is
24971examined when @code{Parameter.__init__} is invoked; subsequent changes
24972have no effect.
d812018b 24973@end defvar
d7b32ed3 24974
d812018b 24975@defvar Parameter.show_doc
d7b32ed3
PM
24976If this attribute exists, and is a string, then its value is used as
24977the help text for this parameter's @code{show} command. The value is
24978examined when @code{Parameter.__init__} is invoked; subsequent changes
24979have no effect.
d812018b 24980@end defvar
d7b32ed3 24981
d812018b 24982@defvar Parameter.value
d7b32ed3
PM
24983The @code{value} attribute holds the underlying value of the
24984parameter. It can be read and assigned to just as any other
24985attribute. @value{GDBN} does validation when assignments are made.
d812018b 24986@end defvar
d7b32ed3 24987
ecec24e6
PM
24988There are two methods that should be implemented in any
24989@code{Parameter} class. These are:
24990
d812018b 24991@defun Parameter.get_set_string (self)
ecec24e6
PM
24992@value{GDBN} will call this method when a @var{parameter}'s value has
24993been changed via the @code{set} API (for example, @kbd{set foo off}).
24994The @code{value} attribute has already been populated with the new
24995value and may be used in output. This method must return a string.
d812018b 24996@end defun
ecec24e6 24997
d812018b 24998@defun Parameter.get_show_string (self, svalue)
ecec24e6
PM
24999@value{GDBN} will call this method when a @var{parameter}'s
25000@code{show} API has been invoked (for example, @kbd{show foo}). The
25001argument @code{svalue} receives the string representation of the
25002current value. This method must return a string.
d812018b 25003@end defun
d7b32ed3
PM
25004
25005When a new parameter is defined, its type must be specified. The
25006available types are represented by constants defined in the @code{gdb}
25007module:
25008
25009@table @code
25010@findex PARAM_BOOLEAN
25011@findex gdb.PARAM_BOOLEAN
d812018b 25012@item gdb.PARAM_BOOLEAN
d7b32ed3
PM
25013The value is a plain boolean. The Python boolean values, @code{True}
25014and @code{False} are the only valid values.
25015
25016@findex PARAM_AUTO_BOOLEAN
25017@findex gdb.PARAM_AUTO_BOOLEAN
d812018b 25018@item gdb.PARAM_AUTO_BOOLEAN
d7b32ed3
PM
25019The value has three possible states: true, false, and @samp{auto}. In
25020Python, true and false are represented using boolean constants, and
25021@samp{auto} is represented using @code{None}.
25022
25023@findex PARAM_UINTEGER
25024@findex gdb.PARAM_UINTEGER
d812018b 25025@item gdb.PARAM_UINTEGER
d7b32ed3
PM
25026The value is an unsigned integer. The value of 0 should be
25027interpreted to mean ``unlimited''.
25028
25029@findex PARAM_INTEGER
25030@findex gdb.PARAM_INTEGER
d812018b 25031@item gdb.PARAM_INTEGER
d7b32ed3
PM
25032The value is a signed integer. The value of 0 should be interpreted
25033to mean ``unlimited''.
25034
25035@findex PARAM_STRING
25036@findex gdb.PARAM_STRING
d812018b 25037@item gdb.PARAM_STRING
d7b32ed3
PM
25038The value is a string. When the user modifies the string, any escape
25039sequences, such as @samp{\t}, @samp{\f}, and octal escapes, are
25040translated into corresponding characters and encoded into the current
25041host charset.
25042
25043@findex PARAM_STRING_NOESCAPE
25044@findex gdb.PARAM_STRING_NOESCAPE
d812018b 25045@item gdb.PARAM_STRING_NOESCAPE
d7b32ed3
PM
25046The value is a string. When the user modifies the string, escapes are
25047passed through untranslated.
25048
25049@findex PARAM_OPTIONAL_FILENAME
25050@findex gdb.PARAM_OPTIONAL_FILENAME
d812018b 25051@item gdb.PARAM_OPTIONAL_FILENAME
d7b32ed3
PM
25052The value is a either a filename (a string), or @code{None}.
25053
25054@findex PARAM_FILENAME
25055@findex gdb.PARAM_FILENAME
d812018b 25056@item gdb.PARAM_FILENAME
d7b32ed3
PM
25057The value is a filename. This is just like
25058@code{PARAM_STRING_NOESCAPE}, but uses file names for completion.
25059
25060@findex PARAM_ZINTEGER
25061@findex gdb.PARAM_ZINTEGER
d812018b 25062@item gdb.PARAM_ZINTEGER
d7b32ed3
PM
25063The value is an integer. This is like @code{PARAM_INTEGER}, except 0
25064is interpreted as itself.
25065
25066@findex PARAM_ENUM
25067@findex gdb.PARAM_ENUM
d812018b 25068@item gdb.PARAM_ENUM
d7b32ed3
PM
25069The value is a string, which must be one of a collection string
25070constants provided when the parameter is created.
25071@end table
25072
bc3b79fd
TJB
25073@node Functions In Python
25074@subsubsection Writing new convenience functions
25075
25076@cindex writing convenience functions
25077@cindex convenience functions in python
25078@cindex python convenience functions
25079@tindex gdb.Function
25080@tindex Function
25081You can implement new convenience functions (@pxref{Convenience Vars})
25082in Python. A convenience function is an instance of a subclass of the
25083class @code{gdb.Function}.
25084
d812018b 25085@defun Function.__init__ (name)
bc3b79fd
TJB
25086The initializer for @code{Function} registers the new function with
25087@value{GDBN}. The argument @var{name} is the name of the function,
25088a string. The function will be visible to the user as a convenience
25089variable of type @code{internal function}, whose name is the same as
25090the given @var{name}.
25091
25092The documentation for the new function is taken from the documentation
25093string for the new class.
d812018b 25094@end defun
bc3b79fd 25095
d812018b 25096@defun Function.invoke (@var{*args})
bc3b79fd
TJB
25097When a convenience function is evaluated, its arguments are converted
25098to instances of @code{gdb.Value}, and then the function's
25099@code{invoke} method is called. Note that @value{GDBN} does not
25100predetermine the arity of convenience functions. Instead, all
25101available arguments are passed to @code{invoke}, following the
25102standard Python calling convention. In particular, a convenience
25103function can have default values for parameters without ill effect.
25104
25105The return value of this method is used as its value in the enclosing
25106expression. If an ordinary Python value is returned, it is converted
25107to a @code{gdb.Value} following the usual rules.
d812018b 25108@end defun
bc3b79fd
TJB
25109
25110The following code snippet shows how a trivial convenience function can
25111be implemented in Python:
25112
25113@smallexample
25114class Greet (gdb.Function):
25115 """Return string to greet someone.
25116Takes a name as argument."""
25117
25118 def __init__ (self):
25119 super (Greet, self).__init__ ("greet")
25120
25121 def invoke (self, name):
25122 return "Hello, %s!" % name.string ()
25123
25124Greet ()
25125@end smallexample
25126
25127The last line instantiates the class, and is necessary to trigger the
25128registration of the function with @value{GDBN}. Depending on how the
25129Python code is read into @value{GDBN}, you may need to import the
25130@code{gdb} module explicitly.
25131
dc939229
TT
25132Now you can use the function in an expression:
25133
25134@smallexample
25135(gdb) print $greet("Bob")
25136$1 = "Hello, Bob!"
25137@end smallexample
25138
fa33c3cd
DE
25139@node Progspaces In Python
25140@subsubsection Program Spaces In Python
25141
25142@cindex progspaces in python
25143@tindex gdb.Progspace
25144@tindex Progspace
25145A program space, or @dfn{progspace}, represents a symbolic view
25146of an address space.
25147It consists of all of the objfiles of the program.
25148@xref{Objfiles In Python}.
25149@xref{Inferiors and Programs, program spaces}, for more details
25150about program spaces.
25151
25152The following progspace-related functions are available in the
25153@code{gdb} module:
25154
25155@findex gdb.current_progspace
d812018b 25156@defun gdb.current_progspace ()
fa33c3cd
DE
25157This function returns the program space of the currently selected inferior.
25158@xref{Inferiors and Programs}.
25159@end defun
25160
25161@findex gdb.progspaces
d812018b 25162@defun gdb.progspaces ()
fa33c3cd
DE
25163Return a sequence of all the progspaces currently known to @value{GDBN}.
25164@end defun
25165
25166Each progspace is represented by an instance of the @code{gdb.Progspace}
25167class.
25168
d812018b 25169@defvar Progspace.filename
fa33c3cd 25170The file name of the progspace as a string.
d812018b 25171@end defvar
fa33c3cd 25172
d812018b 25173@defvar Progspace.pretty_printers
fa33c3cd
DE
25174The @code{pretty_printers} attribute is a list of functions. It is
25175used to look up pretty-printers. A @code{Value} is passed to each
25176function in order; if the function returns @code{None}, then the
25177search continues. Otherwise, the return value should be an object
4c374409 25178which is used to format the value. @xref{Pretty Printing API}, for more
fa33c3cd 25179information.
d812018b 25180@end defvar
fa33c3cd 25181
18a9fc12
TT
25182@defvar Progspace.type_printers
25183The @code{type_printers} attribute is a list of type printer objects.
25184@xref{Type Printing API}, for more information.
25185@end defvar
25186
89c73ade
TT
25187@node Objfiles In Python
25188@subsubsection Objfiles In Python
25189
25190@cindex objfiles in python
25191@tindex gdb.Objfile
25192@tindex Objfile
25193@value{GDBN} loads symbols for an inferior from various
25194symbol-containing files (@pxref{Files}). These include the primary
25195executable file, any shared libraries used by the inferior, and any
25196separate debug info files (@pxref{Separate Debug Files}).
25197@value{GDBN} calls these symbol-containing files @dfn{objfiles}.
25198
25199The following objfile-related functions are available in the
25200@code{gdb} module:
25201
25202@findex gdb.current_objfile
d812018b 25203@defun gdb.current_objfile ()
bf88dd68 25204When auto-loading a Python script (@pxref{Python Auto-loading}), @value{GDBN}
89c73ade
TT
25205sets the ``current objfile'' to the corresponding objfile. This
25206function returns the current objfile. If there is no current objfile,
25207this function returns @code{None}.
25208@end defun
25209
25210@findex gdb.objfiles
d812018b 25211@defun gdb.objfiles ()
89c73ade
TT
25212Return a sequence of all the objfiles current known to @value{GDBN}.
25213@xref{Objfiles In Python}.
25214@end defun
25215
25216Each objfile is represented by an instance of the @code{gdb.Objfile}
25217class.
25218
d812018b 25219@defvar Objfile.filename
89c73ade 25220The file name of the objfile as a string.
d812018b 25221@end defvar
89c73ade 25222
d812018b 25223@defvar Objfile.pretty_printers
89c73ade
TT
25224The @code{pretty_printers} attribute is a list of functions. It is
25225used to look up pretty-printers. A @code{Value} is passed to each
25226function in order; if the function returns @code{None}, then the
25227search continues. Otherwise, the return value should be an object
4c374409 25228which is used to format the value. @xref{Pretty Printing API}, for more
a6bac58e 25229information.
d812018b 25230@end defvar
89c73ade 25231
18a9fc12
TT
25232@defvar Objfile.type_printers
25233The @code{type_printers} attribute is a list of type printer objects.
25234@xref{Type Printing API}, for more information.
25235@end defvar
25236
29703da4
PM
25237A @code{gdb.Objfile} object has the following methods:
25238
d812018b 25239@defun Objfile.is_valid ()
29703da4
PM
25240Returns @code{True} if the @code{gdb.Objfile} object is valid,
25241@code{False} if not. A @code{gdb.Objfile} object can become invalid
25242if the object file it refers to is not loaded in @value{GDBN} any
25243longer. All other @code{gdb.Objfile} methods will throw an exception
25244if it is invalid at the time the method is called.
d812018b 25245@end defun
29703da4 25246
f8f6f20b 25247@node Frames In Python
f3e9a817 25248@subsubsection Accessing inferior stack frames from Python.
f8f6f20b
TJB
25249
25250@cindex frames in python
25251When the debugged program stops, @value{GDBN} is able to analyze its call
25252stack (@pxref{Frames,,Stack frames}). The @code{gdb.Frame} class
25253represents a frame in the stack. A @code{gdb.Frame} object is only valid
25254while its corresponding frame exists in the inferior's stack. If you try
621c8364
TT
25255to use an invalid frame object, @value{GDBN} will throw a @code{gdb.error}
25256exception (@pxref{Exception Handling}).
f8f6f20b
TJB
25257
25258Two @code{gdb.Frame} objects can be compared for equality with the @code{==}
25259operator, like:
25260
25261@smallexample
25262(@value{GDBP}) python print gdb.newest_frame() == gdb.selected_frame ()
25263True
25264@end smallexample
25265
25266The following frame-related functions are available in the @code{gdb} module:
25267
25268@findex gdb.selected_frame
d812018b 25269@defun gdb.selected_frame ()
f8f6f20b
TJB
25270Return the selected frame object. (@pxref{Selection,,Selecting a Frame}).
25271@end defun
25272
d8e22779 25273@findex gdb.newest_frame
d812018b 25274@defun gdb.newest_frame ()
d8e22779
TT
25275Return the newest frame object for the selected thread.
25276@end defun
25277
d812018b 25278@defun gdb.frame_stop_reason_string (reason)
f8f6f20b
TJB
25279Return a string explaining the reason why @value{GDBN} stopped unwinding
25280frames, as expressed by the given @var{reason} code (an integer, see the
25281@code{unwind_stop_reason} method further down in this section).
25282@end defun
25283
25284A @code{gdb.Frame} object has the following methods:
25285
d812018b 25286@defun Frame.is_valid ()
f8f6f20b
TJB
25287Returns true if the @code{gdb.Frame} object is valid, false if not.
25288A frame object can become invalid if the frame it refers to doesn't
25289exist anymore in the inferior. All @code{gdb.Frame} methods will throw
25290an exception if it is invalid at the time the method is called.
d812018b 25291@end defun
f8f6f20b 25292
d812018b 25293@defun Frame.name ()
f8f6f20b
TJB
25294Returns the function name of the frame, or @code{None} if it can't be
25295obtained.
d812018b 25296@end defun
f8f6f20b 25297
bea883fd
SCR
25298@defun Frame.architecture ()
25299Returns the @code{gdb.Architecture} object corresponding to the frame's
25300architecture. @xref{Architectures In Python}.
25301@end defun
25302
d812018b 25303@defun Frame.type ()
ccfc3d6e
TT
25304Returns the type of the frame. The value can be one of:
25305@table @code
25306@item gdb.NORMAL_FRAME
25307An ordinary stack frame.
25308
25309@item gdb.DUMMY_FRAME
25310A fake stack frame that was created by @value{GDBN} when performing an
25311inferior function call.
25312
25313@item gdb.INLINE_FRAME
25314A frame representing an inlined function. The function was inlined
25315into a @code{gdb.NORMAL_FRAME} that is older than this one.
25316
111c6489
JK
25317@item gdb.TAILCALL_FRAME
25318A frame representing a tail call. @xref{Tail Call Frames}.
25319
ccfc3d6e
TT
25320@item gdb.SIGTRAMP_FRAME
25321A signal trampoline frame. This is the frame created by the OS when
25322it calls into a signal handler.
25323
25324@item gdb.ARCH_FRAME
25325A fake stack frame representing a cross-architecture call.
25326
25327@item gdb.SENTINEL_FRAME
25328This is like @code{gdb.NORMAL_FRAME}, but it is only used for the
25329newest frame.
25330@end table
d812018b 25331@end defun
f8f6f20b 25332
d812018b 25333@defun Frame.unwind_stop_reason ()
f8f6f20b
TJB
25334Return an integer representing the reason why it's not possible to find
25335more frames toward the outermost frame. Use
25336@code{gdb.frame_stop_reason_string} to convert the value returned by this
a7fc3f37
KP
25337function to a string. The value can be one of:
25338
25339@table @code
25340@item gdb.FRAME_UNWIND_NO_REASON
25341No particular reason (older frames should be available).
25342
25343@item gdb.FRAME_UNWIND_NULL_ID
25344The previous frame's analyzer returns an invalid result.
25345
25346@item gdb.FRAME_UNWIND_OUTERMOST
25347This frame is the outermost.
25348
25349@item gdb.FRAME_UNWIND_UNAVAILABLE
25350Cannot unwind further, because that would require knowing the
25351values of registers or memory that have not been collected.
25352
25353@item gdb.FRAME_UNWIND_INNER_ID
25354This frame ID looks like it ought to belong to a NEXT frame,
25355but we got it for a PREV frame. Normally, this is a sign of
25356unwinder failure. It could also indicate stack corruption.
25357
25358@item gdb.FRAME_UNWIND_SAME_ID
25359This frame has the same ID as the previous one. That means
25360that unwinding further would almost certainly give us another
25361frame with exactly the same ID, so break the chain. Normally,
25362this is a sign of unwinder failure. It could also indicate
25363stack corruption.
25364
25365@item gdb.FRAME_UNWIND_NO_SAVED_PC
25366The frame unwinder did not find any saved PC, but we needed
25367one to unwind further.
2231f1fb
KP
25368
25369@item gdb.FRAME_UNWIND_FIRST_ERROR
25370Any stop reason greater or equal to this value indicates some kind
25371of error. This special value facilitates writing code that tests
25372for errors in unwinding in a way that will work correctly even if
25373the list of the other values is modified in future @value{GDBN}
25374versions. Using it, you could write:
25375@smallexample
25376reason = gdb.selected_frame().unwind_stop_reason ()
25377reason_str = gdb.frame_stop_reason_string (reason)
25378if reason >= gdb.FRAME_UNWIND_FIRST_ERROR:
25379 print "An error occured: %s" % reason_str
25380@end smallexample
a7fc3f37
KP
25381@end table
25382
d812018b 25383@end defun
f8f6f20b 25384
d812018b 25385@defun Frame.pc ()
f8f6f20b 25386Returns the frame's resume address.
d812018b 25387@end defun
f8f6f20b 25388
d812018b 25389@defun Frame.block ()
f3e9a817 25390Return the frame's code block. @xref{Blocks In Python}.
d812018b 25391@end defun
f3e9a817 25392
d812018b 25393@defun Frame.function ()
f3e9a817
PM
25394Return the symbol for the function corresponding to this frame.
25395@xref{Symbols In Python}.
d812018b 25396@end defun
f3e9a817 25397
d812018b 25398@defun Frame.older ()
f8f6f20b 25399Return the frame that called this frame.
d812018b 25400@end defun
f8f6f20b 25401
d812018b 25402@defun Frame.newer ()
f8f6f20b 25403Return the frame called by this frame.
d812018b 25404@end defun
f8f6f20b 25405
d812018b 25406@defun Frame.find_sal ()
f3e9a817
PM
25407Return the frame's symtab and line object.
25408@xref{Symbol Tables In Python}.
d812018b 25409@end defun
f3e9a817 25410
d812018b 25411@defun Frame.read_var (variable @r{[}, block@r{]})
dc00d89f
PM
25412Return the value of @var{variable} in this frame. If the optional
25413argument @var{block} is provided, search for the variable from that
25414block; otherwise start at the frame's current block (which is
25415determined by the frame's current program counter). @var{variable}
25416must be a string or a @code{gdb.Symbol} object. @var{block} must be a
25417@code{gdb.Block} object.
d812018b 25418@end defun
f3e9a817 25419
d812018b 25420@defun Frame.select ()
f3e9a817
PM
25421Set this frame to be the selected frame. @xref{Stack, ,Examining the
25422Stack}.
d812018b 25423@end defun
f3e9a817
PM
25424
25425@node Blocks In Python
25426@subsubsection Accessing frame blocks from Python.
25427
25428@cindex blocks in python
25429@tindex gdb.Block
25430
25431Within each frame, @value{GDBN} maintains information on each block
25432stored in that frame. These blocks are organized hierarchically, and
25433are represented individually in Python as a @code{gdb.Block}.
25434Please see @ref{Frames In Python}, for a more in-depth discussion on
25435frames. Furthermore, see @ref{Stack, ,Examining the Stack}, for more
25436detailed technical information on @value{GDBN}'s book-keeping of the
25437stack.
25438
bdb1994d 25439A @code{gdb.Block} is iterable. The iterator returns the symbols
56af09aa
SCR
25440(@pxref{Symbols In Python}) local to the block. Python programs
25441should not assume that a specific block object will always contain a
25442given symbol, since changes in @value{GDBN} features and
25443infrastructure may cause symbols move across blocks in a symbol
25444table.
bdb1994d 25445
f3e9a817
PM
25446The following block-related functions are available in the @code{gdb}
25447module:
25448
25449@findex gdb.block_for_pc
d812018b 25450@defun gdb.block_for_pc (pc)
f3e9a817
PM
25451Return the @code{gdb.Block} containing the given @var{pc} value. If the
25452block cannot be found for the @var{pc} value specified, the function
25453will return @code{None}.
25454@end defun
25455
29703da4
PM
25456A @code{gdb.Block} object has the following methods:
25457
d812018b 25458@defun Block.is_valid ()
29703da4
PM
25459Returns @code{True} if the @code{gdb.Block} object is valid,
25460@code{False} if not. A block object can become invalid if the block it
25461refers to doesn't exist anymore in the inferior. All other
25462@code{gdb.Block} methods will throw an exception if it is invalid at
bdb1994d
TT
25463the time the method is called. The block's validity is also checked
25464during iteration over symbols of the block.
d812018b 25465@end defun
29703da4 25466
f3e9a817
PM
25467A @code{gdb.Block} object has the following attributes:
25468
d812018b 25469@defvar Block.start
f3e9a817 25470The start address of the block. This attribute is not writable.
d812018b 25471@end defvar
f3e9a817 25472
d812018b 25473@defvar Block.end
f3e9a817 25474The end address of the block. This attribute is not writable.
d812018b 25475@end defvar
f3e9a817 25476
d812018b 25477@defvar Block.function
f3e9a817
PM
25478The name of the block represented as a @code{gdb.Symbol}. If the
25479block is not named, then this attribute holds @code{None}. This
25480attribute is not writable.
d812018b 25481@end defvar
f3e9a817 25482
d812018b 25483@defvar Block.superblock
f3e9a817
PM
25484The block containing this block. If this parent block does not exist,
25485this attribute holds @code{None}. This attribute is not writable.
d812018b 25486@end defvar
9df2fbc4
PM
25487
25488@defvar Block.global_block
25489The global block associated with this block. This attribute is not
25490writable.
25491@end defvar
25492
25493@defvar Block.static_block
25494The static block associated with this block. This attribute is not
25495writable.
25496@end defvar
25497
25498@defvar Block.is_global
25499@code{True} if the @code{gdb.Block} object is a global block,
25500@code{False} if not. This attribute is not
25501writable.
25502@end defvar
25503
25504@defvar Block.is_static
25505@code{True} if the @code{gdb.Block} object is a static block,
25506@code{False} if not. This attribute is not writable.
25507@end defvar
f3e9a817
PM
25508
25509@node Symbols In Python
25510@subsubsection Python representation of Symbols.
25511
25512@cindex symbols in python
25513@tindex gdb.Symbol
25514
25515@value{GDBN} represents every variable, function and type as an
25516entry in a symbol table. @xref{Symbols, ,Examining the Symbol Table}.
25517Similarly, Python represents these symbols in @value{GDBN} with the
25518@code{gdb.Symbol} object.
25519
25520The following symbol-related functions are available in the @code{gdb}
25521module:
25522
25523@findex gdb.lookup_symbol
d812018b 25524@defun gdb.lookup_symbol (name @r{[}, block @r{[}, domain@r{]]})
f3e9a817
PM
25525This function searches for a symbol by name. The search scope can be
25526restricted to the parameters defined in the optional domain and block
25527arguments.
25528
25529@var{name} is the name of the symbol. It must be a string. The
25530optional @var{block} argument restricts the search to symbols visible
25531in that @var{block}. The @var{block} argument must be a
6e6fbe60
DE
25532@code{gdb.Block} object. If omitted, the block for the current frame
25533is used. The optional @var{domain} argument restricts
f3e9a817
PM
25534the search to the domain type. The @var{domain} argument must be a
25535domain constant defined in the @code{gdb} module and described later
25536in this chapter.
6e6fbe60
DE
25537
25538The result is a tuple of two elements.
25539The first element is a @code{gdb.Symbol} object or @code{None} if the symbol
25540is not found.
25541If the symbol is found, the second element is @code{True} if the symbol
82809774 25542is a field of a method's object (e.g., @code{this} in C@t{++}),
6e6fbe60
DE
25543otherwise it is @code{False}.
25544If the symbol is not found, the second element is @code{False}.
25545@end defun
25546
25547@findex gdb.lookup_global_symbol
d812018b 25548@defun gdb.lookup_global_symbol (name @r{[}, domain@r{]})
6e6fbe60
DE
25549This function searches for a global symbol by name.
25550The search scope can be restricted to by the domain argument.
25551
25552@var{name} is the name of the symbol. It must be a string.
25553The optional @var{domain} argument restricts the search to the domain type.
25554The @var{domain} argument must be a domain constant defined in the @code{gdb}
25555module and described later in this chapter.
25556
25557The result is a @code{gdb.Symbol} object or @code{None} if the symbol
25558is not found.
f3e9a817
PM
25559@end defun
25560
25561A @code{gdb.Symbol} object has the following attributes:
25562
d812018b 25563@defvar Symbol.type
457e09f0
DE
25564The type of the symbol or @code{None} if no type is recorded.
25565This attribute is represented as a @code{gdb.Type} object.
25566@xref{Types In Python}. This attribute is not writable.
d812018b 25567@end defvar
457e09f0 25568
d812018b 25569@defvar Symbol.symtab
f3e9a817
PM
25570The symbol table in which the symbol appears. This attribute is
25571represented as a @code{gdb.Symtab} object. @xref{Symbol Tables In
25572Python}. This attribute is not writable.
d812018b 25573@end defvar
f3e9a817 25574
64e7d9dd
TT
25575@defvar Symbol.line
25576The line number in the source code at which the symbol was defined.
25577This is an integer.
25578@end defvar
25579
d812018b 25580@defvar Symbol.name
f3e9a817 25581The name of the symbol as a string. This attribute is not writable.
d812018b 25582@end defvar
f3e9a817 25583
d812018b 25584@defvar Symbol.linkage_name
f3e9a817
PM
25585The name of the symbol, as used by the linker (i.e., may be mangled).
25586This attribute is not writable.
d812018b 25587@end defvar
f3e9a817 25588
d812018b 25589@defvar Symbol.print_name
f3e9a817
PM
25590The name of the symbol in a form suitable for output. This is either
25591@code{name} or @code{linkage_name}, depending on whether the user
25592asked @value{GDBN} to display demangled or mangled names.
d812018b 25593@end defvar
f3e9a817 25594
d812018b 25595@defvar Symbol.addr_class
f3e9a817
PM
25596The address class of the symbol. This classifies how to find the value
25597of a symbol. Each address class is a constant defined in the
25598@code{gdb} module and described later in this chapter.
d812018b 25599@end defvar
f3e9a817 25600
f0823d2c
TT
25601@defvar Symbol.needs_frame
25602This is @code{True} if evaluating this symbol's value requires a frame
25603(@pxref{Frames In Python}) and @code{False} otherwise. Typically,
25604local variables will require a frame, but other symbols will not.
035d1e5b 25605@end defvar
f0823d2c 25606
d812018b 25607@defvar Symbol.is_argument
f3e9a817 25608@code{True} if the symbol is an argument of a function.
d812018b 25609@end defvar
f3e9a817 25610
d812018b 25611@defvar Symbol.is_constant
f3e9a817 25612@code{True} if the symbol is a constant.
d812018b 25613@end defvar
f3e9a817 25614
d812018b 25615@defvar Symbol.is_function
f3e9a817 25616@code{True} if the symbol is a function or a method.
d812018b 25617@end defvar
f3e9a817 25618
d812018b 25619@defvar Symbol.is_variable
f3e9a817 25620@code{True} if the symbol is a variable.
d812018b 25621@end defvar
f3e9a817 25622
29703da4
PM
25623A @code{gdb.Symbol} object has the following methods:
25624
d812018b 25625@defun Symbol.is_valid ()
29703da4
PM
25626Returns @code{True} if the @code{gdb.Symbol} object is valid,
25627@code{False} if not. A @code{gdb.Symbol} object can become invalid if
25628the symbol it refers to does not exist in @value{GDBN} any longer.
25629All other @code{gdb.Symbol} methods will throw an exception if it is
25630invalid at the time the method is called.
d812018b 25631@end defun
f0823d2c
TT
25632
25633@defun Symbol.value (@r{[}frame@r{]})
25634Compute the value of the symbol, as a @code{gdb.Value}. For
25635functions, this computes the address of the function, cast to the
25636appropriate type. If the symbol requires a frame in order to compute
25637its value, then @var{frame} must be given. If @var{frame} is not
25638given, or if @var{frame} is invalid, then this method will throw an
25639exception.
25640@end defun
29703da4 25641
f3e9a817
PM
25642The available domain categories in @code{gdb.Symbol} are represented
25643as constants in the @code{gdb} module:
25644
25645@table @code
25646@findex SYMBOL_UNDEF_DOMAIN
25647@findex gdb.SYMBOL_UNDEF_DOMAIN
d812018b 25648@item gdb.SYMBOL_UNDEF_DOMAIN
f3e9a817
PM
25649This is used when a domain has not been discovered or none of the
25650following domains apply. This usually indicates an error either
25651in the symbol information or in @value{GDBN}'s handling of symbols.
25652@findex SYMBOL_VAR_DOMAIN
25653@findex gdb.SYMBOL_VAR_DOMAIN
d812018b 25654@item gdb.SYMBOL_VAR_DOMAIN
f3e9a817
PM
25655This domain contains variables, function names, typedef names and enum
25656type values.
25657@findex SYMBOL_STRUCT_DOMAIN
25658@findex gdb.SYMBOL_STRUCT_DOMAIN
d812018b 25659@item gdb.SYMBOL_STRUCT_DOMAIN
f3e9a817
PM
25660This domain holds struct, union and enum type names.
25661@findex SYMBOL_LABEL_DOMAIN
25662@findex gdb.SYMBOL_LABEL_DOMAIN
d812018b 25663@item gdb.SYMBOL_LABEL_DOMAIN
f3e9a817
PM
25664This domain contains names of labels (for gotos).
25665@findex SYMBOL_VARIABLES_DOMAIN
25666@findex gdb.SYMBOL_VARIABLES_DOMAIN
d812018b 25667@item gdb.SYMBOL_VARIABLES_DOMAIN
f3e9a817
PM
25668This domain holds a subset of the @code{SYMBOLS_VAR_DOMAIN}; it
25669contains everything minus functions and types.
25670@findex SYMBOL_FUNCTIONS_DOMAIN
25671@findex gdb.SYMBOL_FUNCTIONS_DOMAIN
d812018b 25672@item gdb.SYMBOL_FUNCTION_DOMAIN
f3e9a817
PM
25673This domain contains all functions.
25674@findex SYMBOL_TYPES_DOMAIN
25675@findex gdb.SYMBOL_TYPES_DOMAIN
d812018b 25676@item gdb.SYMBOL_TYPES_DOMAIN
f3e9a817
PM
25677This domain contains all types.
25678@end table
25679
25680The available address class categories in @code{gdb.Symbol} are represented
25681as constants in the @code{gdb} module:
25682
25683@table @code
25684@findex SYMBOL_LOC_UNDEF
25685@findex gdb.SYMBOL_LOC_UNDEF
d812018b 25686@item gdb.SYMBOL_LOC_UNDEF
f3e9a817
PM
25687If this is returned by address class, it indicates an error either in
25688the symbol information or in @value{GDBN}'s handling of symbols.
25689@findex SYMBOL_LOC_CONST
25690@findex gdb.SYMBOL_LOC_CONST
d812018b 25691@item gdb.SYMBOL_LOC_CONST
f3e9a817
PM
25692Value is constant int.
25693@findex SYMBOL_LOC_STATIC
25694@findex gdb.SYMBOL_LOC_STATIC
d812018b 25695@item gdb.SYMBOL_LOC_STATIC
f3e9a817
PM
25696Value is at a fixed address.
25697@findex SYMBOL_LOC_REGISTER
25698@findex gdb.SYMBOL_LOC_REGISTER
d812018b 25699@item gdb.SYMBOL_LOC_REGISTER
f3e9a817
PM
25700Value is in a register.
25701@findex SYMBOL_LOC_ARG
25702@findex gdb.SYMBOL_LOC_ARG
d812018b 25703@item gdb.SYMBOL_LOC_ARG
f3e9a817
PM
25704Value is an argument. This value is at the offset stored within the
25705symbol inside the frame's argument list.
25706@findex SYMBOL_LOC_REF_ARG
25707@findex gdb.SYMBOL_LOC_REF_ARG
d812018b 25708@item gdb.SYMBOL_LOC_REF_ARG
f3e9a817
PM
25709Value address is stored in the frame's argument list. Just like
25710@code{LOC_ARG} except that the value's address is stored at the
25711offset, not the value itself.
25712@findex SYMBOL_LOC_REGPARM_ADDR
25713@findex gdb.SYMBOL_LOC_REGPARM_ADDR
d812018b 25714@item gdb.SYMBOL_LOC_REGPARM_ADDR
f3e9a817
PM
25715Value is a specified register. Just like @code{LOC_REGISTER} except
25716the register holds the address of the argument instead of the argument
25717itself.
25718@findex SYMBOL_LOC_LOCAL
25719@findex gdb.SYMBOL_LOC_LOCAL
d812018b 25720@item gdb.SYMBOL_LOC_LOCAL
f3e9a817
PM
25721Value is a local variable.
25722@findex SYMBOL_LOC_TYPEDEF
25723@findex gdb.SYMBOL_LOC_TYPEDEF
d812018b 25724@item gdb.SYMBOL_LOC_TYPEDEF
f3e9a817
PM
25725Value not used. Symbols in the domain @code{SYMBOL_STRUCT_DOMAIN} all
25726have this class.
25727@findex SYMBOL_LOC_BLOCK
25728@findex gdb.SYMBOL_LOC_BLOCK
d812018b 25729@item gdb.SYMBOL_LOC_BLOCK
f3e9a817
PM
25730Value is a block.
25731@findex SYMBOL_LOC_CONST_BYTES
25732@findex gdb.SYMBOL_LOC_CONST_BYTES
d812018b 25733@item gdb.SYMBOL_LOC_CONST_BYTES
f3e9a817
PM
25734Value is a byte-sequence.
25735@findex SYMBOL_LOC_UNRESOLVED
25736@findex gdb.SYMBOL_LOC_UNRESOLVED
d812018b 25737@item gdb.SYMBOL_LOC_UNRESOLVED
f3e9a817
PM
25738Value is at a fixed address, but the address of the variable has to be
25739determined from the minimal symbol table whenever the variable is
25740referenced.
25741@findex SYMBOL_LOC_OPTIMIZED_OUT
25742@findex gdb.SYMBOL_LOC_OPTIMIZED_OUT
d812018b 25743@item gdb.SYMBOL_LOC_OPTIMIZED_OUT
f3e9a817
PM
25744The value does not actually exist in the program.
25745@findex SYMBOL_LOC_COMPUTED
25746@findex gdb.SYMBOL_LOC_COMPUTED
d812018b 25747@item gdb.SYMBOL_LOC_COMPUTED
f3e9a817
PM
25748The value's address is a computed location.
25749@end table
25750
25751@node Symbol Tables In Python
25752@subsubsection Symbol table representation in Python.
25753
25754@cindex symbol tables in python
25755@tindex gdb.Symtab
25756@tindex gdb.Symtab_and_line
25757
25758Access to symbol table data maintained by @value{GDBN} on the inferior
25759is exposed to Python via two objects: @code{gdb.Symtab_and_line} and
25760@code{gdb.Symtab}. Symbol table and line data for a frame is returned
25761from the @code{find_sal} method in @code{gdb.Frame} object.
25762@xref{Frames In Python}.
25763
25764For more information on @value{GDBN}'s symbol table management, see
25765@ref{Symbols, ,Examining the Symbol Table}, for more information.
25766
25767A @code{gdb.Symtab_and_line} object has the following attributes:
25768
d812018b 25769@defvar Symtab_and_line.symtab
f3e9a817
PM
25770The symbol table object (@code{gdb.Symtab}) for this frame.
25771This attribute is not writable.
d812018b 25772@end defvar
f3e9a817 25773
d812018b 25774@defvar Symtab_and_line.pc
3c15d565
SCR
25775Indicates the start of the address range occupied by code for the
25776current source line. This attribute is not writable.
d812018b 25777@end defvar
f3e9a817 25778
ee0bf529
SCR
25779@defvar Symtab_and_line.last
25780Indicates the end of the address range occupied by code for the current
25781source line. This attribute is not writable.
25782@end defvar
25783
d812018b 25784@defvar Symtab_and_line.line
f3e9a817
PM
25785Indicates the current line number for this object. This
25786attribute is not writable.
d812018b 25787@end defvar
f3e9a817 25788
29703da4
PM
25789A @code{gdb.Symtab_and_line} object has the following methods:
25790
d812018b 25791@defun Symtab_and_line.is_valid ()
29703da4
PM
25792Returns @code{True} if the @code{gdb.Symtab_and_line} object is valid,
25793@code{False} if not. A @code{gdb.Symtab_and_line} object can become
25794invalid if the Symbol table and line object it refers to does not
25795exist in @value{GDBN} any longer. All other
25796@code{gdb.Symtab_and_line} methods will throw an exception if it is
25797invalid at the time the method is called.
d812018b 25798@end defun
29703da4 25799
f3e9a817
PM
25800A @code{gdb.Symtab} object has the following attributes:
25801
d812018b 25802@defvar Symtab.filename
f3e9a817 25803The symbol table's source filename. This attribute is not writable.
d812018b 25804@end defvar
f3e9a817 25805
d812018b 25806@defvar Symtab.objfile
f3e9a817
PM
25807The symbol table's backing object file. @xref{Objfiles In Python}.
25808This attribute is not writable.
d812018b 25809@end defvar
f3e9a817 25810
29703da4 25811A @code{gdb.Symtab} object has the following methods:
f3e9a817 25812
d812018b 25813@defun Symtab.is_valid ()
29703da4
PM
25814Returns @code{True} if the @code{gdb.Symtab} object is valid,
25815@code{False} if not. A @code{gdb.Symtab} object can become invalid if
25816the symbol table it refers to does not exist in @value{GDBN} any
25817longer. All other @code{gdb.Symtab} methods will throw an exception
25818if it is invalid at the time the method is called.
d812018b 25819@end defun
29703da4 25820
d812018b 25821@defun Symtab.fullname ()
f3e9a817 25822Return the symbol table's source absolute file name.
d812018b 25823@end defun
a20ee7a4
SCR
25824
25825@defun Symtab.global_block ()
25826Return the global block of the underlying symbol table.
25827@xref{Blocks In Python}.
25828@end defun
25829
25830@defun Symtab.static_block ()
25831Return the static block of the underlying symbol table.
25832@xref{Blocks In Python}.
25833@end defun
f8f6f20b 25834
adc36818
PM
25835@node Breakpoints In Python
25836@subsubsection Manipulating breakpoints using Python
25837
25838@cindex breakpoints in python
25839@tindex gdb.Breakpoint
25840
25841Python code can manipulate breakpoints via the @code{gdb.Breakpoint}
25842class.
25843
d812018b 25844@defun Breakpoint.__init__ (spec @r{[}, type @r{[}, wp_class @r{[},internal@r{]]]})
adc36818
PM
25845Create a new breakpoint. @var{spec} is a string naming the
25846location of the breakpoint, or an expression that defines a
25847watchpoint. The contents can be any location recognized by the
25848@code{break} command, or in the case of a watchpoint, by the @code{watch}
25849command. The optional @var{type} denotes the breakpoint to create
25850from the types defined later in this chapter. This argument can be
d812018b
PK
25851either: @code{gdb.BP_BREAKPOINT} or @code{gdb.BP_WATCHPOINT}. @var{type}
25852defaults to @code{gdb.BP_BREAKPOINT}. The optional @var{internal} argument
84f4c1fe
PM
25853allows the breakpoint to become invisible to the user. The breakpoint
25854will neither be reported when created, nor will it be listed in the
25855output from @code{info breakpoints} (but will be listed with the
25856@code{maint info breakpoints} command). The optional @var{wp_class}
adc36818 25857argument defines the class of watchpoint to create, if @var{type} is
d812018b
PK
25858@code{gdb.BP_WATCHPOINT}. If a watchpoint class is not provided, it is
25859assumed to be a @code{gdb.WP_WRITE} class.
25860@end defun
adc36818 25861
d812018b 25862@defun Breakpoint.stop (self)
7371cf6d
PM
25863The @code{gdb.Breakpoint} class can be sub-classed and, in
25864particular, you may choose to implement the @code{stop} method.
25865If this method is defined as a sub-class of @code{gdb.Breakpoint},
25866it will be called when the inferior reaches any location of a
25867breakpoint which instantiates that sub-class. If the method returns
25868@code{True}, the inferior will be stopped at the location of the
25869breakpoint, otherwise the inferior will continue.
25870
25871If there are multiple breakpoints at the same location with a
25872@code{stop} method, each one will be called regardless of the
25873return status of the previous. This ensures that all @code{stop}
25874methods have a chance to execute at that location. In this scenario
25875if one of the methods returns @code{True} but the others return
25876@code{False}, the inferior will still be stopped.
25877
99f5279d
PM
25878You should not alter the execution state of the inferior (i.e.@:, step,
25879next, etc.), alter the current frame context (i.e.@:, change the current
25880active frame), or alter, add or delete any breakpoint. As a general
25881rule, you should not alter any data within @value{GDBN} or the inferior
25882at this time.
25883
7371cf6d
PM
25884Example @code{stop} implementation:
25885
25886@smallexample
25887class MyBreakpoint (gdb.Breakpoint):
25888 def stop (self):
25889 inf_val = gdb.parse_and_eval("foo")
25890 if inf_val == 3:
25891 return True
25892 return False
25893@end smallexample
d812018b 25894@end defun
7371cf6d 25895
adc36818
PM
25896The available watchpoint types represented by constants are defined in the
25897@code{gdb} module:
25898
25899@table @code
25900@findex WP_READ
25901@findex gdb.WP_READ
d812018b 25902@item gdb.WP_READ
adc36818
PM
25903Read only watchpoint.
25904
25905@findex WP_WRITE
25906@findex gdb.WP_WRITE
d812018b 25907@item gdb.WP_WRITE
adc36818
PM
25908Write only watchpoint.
25909
25910@findex WP_ACCESS
25911@findex gdb.WP_ACCESS
d812018b 25912@item gdb.WP_ACCESS
adc36818
PM
25913Read/Write watchpoint.
25914@end table
25915
d812018b 25916@defun Breakpoint.is_valid ()
adc36818
PM
25917Return @code{True} if this @code{Breakpoint} object is valid,
25918@code{False} otherwise. A @code{Breakpoint} object can become invalid
25919if the user deletes the breakpoint. In this case, the object still
25920exists, but the underlying breakpoint does not. In the cases of
25921watchpoint scope, the watchpoint remains valid even if execution of the
25922inferior leaves the scope of that watchpoint.
d812018b 25923@end defun
adc36818 25924
d812018b 25925@defun Breakpoint.delete
94b6973e
PM
25926Permanently deletes the @value{GDBN} breakpoint. This also
25927invalidates the Python @code{Breakpoint} object. Any further access
25928to this object's attributes or methods will raise an error.
d812018b 25929@end defun
94b6973e 25930
d812018b 25931@defvar Breakpoint.enabled
adc36818
PM
25932This attribute is @code{True} if the breakpoint is enabled, and
25933@code{False} otherwise. This attribute is writable.
d812018b 25934@end defvar
adc36818 25935
d812018b 25936@defvar Breakpoint.silent
adc36818
PM
25937This attribute is @code{True} if the breakpoint is silent, and
25938@code{False} otherwise. This attribute is writable.
25939
25940Note that a breakpoint can also be silent if it has commands and the
25941first command is @code{silent}. This is not reported by the
25942@code{silent} attribute.
d812018b 25943@end defvar
adc36818 25944
d812018b 25945@defvar Breakpoint.thread
adc36818
PM
25946If the breakpoint is thread-specific, this attribute holds the thread
25947id. If the breakpoint is not thread-specific, this attribute is
25948@code{None}. This attribute is writable.
d812018b 25949@end defvar
adc36818 25950
d812018b 25951@defvar Breakpoint.task
adc36818
PM
25952If the breakpoint is Ada task-specific, this attribute holds the Ada task
25953id. If the breakpoint is not task-specific (or the underlying
25954language is not Ada), this attribute is @code{None}. This attribute
25955is writable.
d812018b 25956@end defvar
adc36818 25957
d812018b 25958@defvar Breakpoint.ignore_count
adc36818
PM
25959This attribute holds the ignore count for the breakpoint, an integer.
25960This attribute is writable.
d812018b 25961@end defvar
adc36818 25962
d812018b 25963@defvar Breakpoint.number
adc36818
PM
25964This attribute holds the breakpoint's number --- the identifier used by
25965the user to manipulate the breakpoint. This attribute is not writable.
d812018b 25966@end defvar
adc36818 25967
d812018b 25968@defvar Breakpoint.type
adc36818
PM
25969This attribute holds the breakpoint's type --- the identifier used to
25970determine the actual breakpoint type or use-case. This attribute is not
25971writable.
d812018b 25972@end defvar
adc36818 25973
d812018b 25974@defvar Breakpoint.visible
84f4c1fe
PM
25975This attribute tells whether the breakpoint is visible to the user
25976when set, or when the @samp{info breakpoints} command is run. This
25977attribute is not writable.
d812018b 25978@end defvar
84f4c1fe 25979
adc36818
PM
25980The available types are represented by constants defined in the @code{gdb}
25981module:
25982
25983@table @code
25984@findex BP_BREAKPOINT
25985@findex gdb.BP_BREAKPOINT
d812018b 25986@item gdb.BP_BREAKPOINT
adc36818
PM
25987Normal code breakpoint.
25988
25989@findex BP_WATCHPOINT
25990@findex gdb.BP_WATCHPOINT
d812018b 25991@item gdb.BP_WATCHPOINT
adc36818
PM
25992Watchpoint breakpoint.
25993
25994@findex BP_HARDWARE_WATCHPOINT
25995@findex gdb.BP_HARDWARE_WATCHPOINT
d812018b 25996@item gdb.BP_HARDWARE_WATCHPOINT
adc36818
PM
25997Hardware assisted watchpoint.
25998
25999@findex BP_READ_WATCHPOINT
26000@findex gdb.BP_READ_WATCHPOINT
d812018b 26001@item gdb.BP_READ_WATCHPOINT
adc36818
PM
26002Hardware assisted read watchpoint.
26003
26004@findex BP_ACCESS_WATCHPOINT
26005@findex gdb.BP_ACCESS_WATCHPOINT
d812018b 26006@item gdb.BP_ACCESS_WATCHPOINT
adc36818
PM
26007Hardware assisted access watchpoint.
26008@end table
26009
d812018b 26010@defvar Breakpoint.hit_count
adc36818
PM
26011This attribute holds the hit count for the breakpoint, an integer.
26012This attribute is writable, but currently it can only be set to zero.
d812018b 26013@end defvar
adc36818 26014
d812018b 26015@defvar Breakpoint.location
adc36818
PM
26016This attribute holds the location of the breakpoint, as specified by
26017the user. It is a string. If the breakpoint does not have a location
26018(that is, it is a watchpoint) the attribute's value is @code{None}. This
26019attribute is not writable.
d812018b 26020@end defvar
adc36818 26021
d812018b 26022@defvar Breakpoint.expression
adc36818
PM
26023This attribute holds a breakpoint expression, as specified by
26024the user. It is a string. If the breakpoint does not have an
26025expression (the breakpoint is not a watchpoint) the attribute's value
26026is @code{None}. This attribute is not writable.
d812018b 26027@end defvar
adc36818 26028
d812018b 26029@defvar Breakpoint.condition
adc36818
PM
26030This attribute holds the condition of the breakpoint, as specified by
26031the user. It is a string. If there is no condition, this attribute's
26032value is @code{None}. This attribute is writable.
d812018b 26033@end defvar
adc36818 26034
d812018b 26035@defvar Breakpoint.commands
adc36818
PM
26036This attribute holds the commands attached to the breakpoint. If
26037there are commands, this attribute's value is a string holding all the
26038commands, separated by newlines. If there are no commands, this
26039attribute is @code{None}. This attribute is not writable.
d812018b 26040@end defvar
adc36818 26041
cc72b2a2
KP
26042@node Finish Breakpoints in Python
26043@subsubsection Finish Breakpoints
26044
26045@cindex python finish breakpoints
26046@tindex gdb.FinishBreakpoint
26047
26048A finish breakpoint is a temporary breakpoint set at the return address of
26049a frame, based on the @code{finish} command. @code{gdb.FinishBreakpoint}
26050extends @code{gdb.Breakpoint}. The underlying breakpoint will be disabled
26051and deleted when the execution will run out of the breakpoint scope (i.e.@:
26052@code{Breakpoint.stop} or @code{FinishBreakpoint.out_of_scope} triggered).
26053Finish breakpoints are thread specific and must be create with the right
26054thread selected.
26055
26056@defun FinishBreakpoint.__init__ (@r{[}frame@r{]} @r{[}, internal@r{]})
26057Create a finish breakpoint at the return address of the @code{gdb.Frame}
26058object @var{frame}. If @var{frame} is not provided, this defaults to the
26059newest frame. The optional @var{internal} argument allows the breakpoint to
26060become invisible to the user. @xref{Breakpoints In Python}, for further
26061details about this argument.
26062@end defun
26063
26064@defun FinishBreakpoint.out_of_scope (self)
26065In some circumstances (e.g.@: @code{longjmp}, C@t{++} exceptions, @value{GDBN}
26066@code{return} command, @dots{}), a function may not properly terminate, and
26067thus never hit the finish breakpoint. When @value{GDBN} notices such a
26068situation, the @code{out_of_scope} callback will be triggered.
26069
26070You may want to sub-class @code{gdb.FinishBreakpoint} and override this
26071method:
26072
26073@smallexample
26074class MyFinishBreakpoint (gdb.FinishBreakpoint)
26075 def stop (self):
26076 print "normal finish"
26077 return True
26078
26079 def out_of_scope ():
26080 print "abnormal finish"
26081@end smallexample
26082@end defun
26083
26084@defvar FinishBreakpoint.return_value
26085When @value{GDBN} is stopped at a finish breakpoint and the frame
26086used to build the @code{gdb.FinishBreakpoint} object had debug symbols, this
26087attribute will contain a @code{gdb.Value} object corresponding to the return
26088value of the function. The value will be @code{None} if the function return
26089type is @code{void} or if the return value was not computable. This attribute
26090is not writable.
26091@end defvar
26092
be759fcf
PM
26093@node Lazy Strings In Python
26094@subsubsection Python representation of lazy strings.
26095
26096@cindex lazy strings in python
26097@tindex gdb.LazyString
26098
26099A @dfn{lazy string} is a string whose contents is not retrieved or
26100encoded until it is needed.
26101
26102A @code{gdb.LazyString} is represented in @value{GDBN} as an
26103@code{address} that points to a region of memory, an @code{encoding}
26104that will be used to encode that region of memory, and a @code{length}
26105to delimit the region of memory that represents the string. The
26106difference between a @code{gdb.LazyString} and a string wrapped within
26107a @code{gdb.Value} is that a @code{gdb.LazyString} will be treated
26108differently by @value{GDBN} when printing. A @code{gdb.LazyString} is
26109retrieved and encoded during printing, while a @code{gdb.Value}
26110wrapping a string is immediately retrieved and encoded on creation.
26111
26112A @code{gdb.LazyString} object has the following functions:
26113
d812018b 26114@defun LazyString.value ()
be759fcf
PM
26115Convert the @code{gdb.LazyString} to a @code{gdb.Value}. This value
26116will point to the string in memory, but will lose all the delayed
26117retrieval, encoding and handling that @value{GDBN} applies to a
26118@code{gdb.LazyString}.
d812018b 26119@end defun
be759fcf 26120
d812018b 26121@defvar LazyString.address
be759fcf
PM
26122This attribute holds the address of the string. This attribute is not
26123writable.
d812018b 26124@end defvar
be759fcf 26125
d812018b 26126@defvar LazyString.length
be759fcf
PM
26127This attribute holds the length of the string in characters. If the
26128length is -1, then the string will be fetched and encoded up to the
26129first null of appropriate width. This attribute is not writable.
d812018b 26130@end defvar
be759fcf 26131
d812018b 26132@defvar LazyString.encoding
be759fcf
PM
26133This attribute holds the encoding that will be applied to the string
26134when the string is printed by @value{GDBN}. If the encoding is not
26135set, or contains an empty string, then @value{GDBN} will select the
26136most appropriate encoding when the string is printed. This attribute
26137is not writable.
d812018b 26138@end defvar
be759fcf 26139
d812018b 26140@defvar LazyString.type
be759fcf
PM
26141This attribute holds the type that is represented by the lazy string's
26142type. For a lazy string this will always be a pointer type. To
26143resolve this to the lazy string's character type, use the type's
26144@code{target} method. @xref{Types In Python}. This attribute is not
26145writable.
d812018b 26146@end defvar
be759fcf 26147
bea883fd
SCR
26148@node Architectures In Python
26149@subsubsection Python representation of architectures
26150@cindex Python architectures
26151
26152@value{GDBN} uses architecture specific parameters and artifacts in a
26153number of its various computations. An architecture is represented
26154by an instance of the @code{gdb.Architecture} class.
26155
26156A @code{gdb.Architecture} class has the following methods:
26157
26158@defun Architecture.name ()
26159Return the name (string value) of the architecture.
26160@end defun
26161
9f44fbc0
SCR
26162@defun Architecture.disassemble (@var{start_pc} @r{[}, @var{end_pc} @r{[}, @var{count}@r{]]})
26163Return a list of disassembled instructions starting from the memory
26164address @var{start_pc}. The optional arguments @var{end_pc} and
26165@var{count} determine the number of instructions in the returned list.
26166If both the optional arguments @var{end_pc} and @var{count} are
26167specified, then a list of at most @var{count} disassembled instructions
26168whose start address falls in the closed memory address interval from
26169@var{start_pc} to @var{end_pc} are returned. If @var{end_pc} is not
26170specified, but @var{count} is specified, then @var{count} number of
26171instructions starting from the address @var{start_pc} are returned. If
26172@var{count} is not specified but @var{end_pc} is specified, then all
26173instructions whose start address falls in the closed memory address
26174interval from @var{start_pc} to @var{end_pc} are returned. If neither
26175@var{end_pc} nor @var{count} are specified, then a single instruction at
26176@var{start_pc} is returned. For all of these cases, each element of the
26177returned list is a Python @code{dict} with the following string keys:
26178
26179@table @code
26180
26181@item addr
26182The value corresponding to this key is a Python long integer capturing
26183the memory address of the instruction.
26184
26185@item asm
26186The value corresponding to this key is a string value which represents
26187the instruction with assembly language mnemonics. The assembly
26188language flavor used is the same as that specified by the current CLI
26189variable @code{disassembly-flavor}. @xref{Machine Code}.
26190
26191@item length
26192The value corresponding to this key is the length (integer value) of the
26193instruction in bytes.
26194
26195@end table
26196@end defun
26197
bf88dd68
JK
26198@node Python Auto-loading
26199@subsection Python Auto-loading
26200@cindex Python auto-loading
8a1ea21f
DE
26201
26202When a new object file is read (for example, due to the @code{file}
26203command, or because the inferior has loaded a shared library),
26204@value{GDBN} will look for Python support scripts in several ways:
3708f05e
JK
26205@file{@var{objfile}-gdb.py} (@pxref{objfile-gdb.py file})
26206and @code{.debug_gdb_scripts} section
26207(@pxref{dotdebug_gdb_scripts section}).
8a1ea21f
DE
26208
26209The auto-loading feature is useful for supplying application-specific
26210debugging commands and scripts.
26211
dbaefcf7
DE
26212Auto-loading can be enabled or disabled,
26213and the list of auto-loaded scripts can be printed.
8a1ea21f
DE
26214
26215@table @code
bf88dd68
JK
26216@anchor{set auto-load python-scripts}
26217@kindex set auto-load python-scripts
26218@item set auto-load python-scripts [on|off]
a86caf66 26219Enable or disable the auto-loading of Python scripts.
8a1ea21f 26220
bf88dd68
JK
26221@anchor{show auto-load python-scripts}
26222@kindex show auto-load python-scripts
26223@item show auto-load python-scripts
a86caf66 26224Show whether auto-loading of Python scripts is enabled or disabled.
dbaefcf7 26225
bf88dd68
JK
26226@anchor{info auto-load python-scripts}
26227@kindex info auto-load python-scripts
26228@cindex print list of auto-loaded Python scripts
26229@item info auto-load python-scripts [@var{regexp}]
26230Print the list of all Python scripts that @value{GDBN} auto-loaded.
75fc9810 26231
bf88dd68 26232Also printed is the list of Python scripts that were mentioned in
75fc9810 26233the @code{.debug_gdb_scripts} section and were not found
8e0583c8 26234(@pxref{dotdebug_gdb_scripts section}).
75fc9810
DE
26235This is useful because their names are not printed when @value{GDBN}
26236tries to load them and fails. There may be many of them, and printing
26237an error message for each one is problematic.
26238
bf88dd68 26239If @var{regexp} is supplied only Python scripts with matching names are printed.
dbaefcf7 26240
75fc9810
DE
26241Example:
26242
dbaefcf7 26243@smallexample
bf88dd68 26244(gdb) info auto-load python-scripts
bccbefd2
JK
26245Loaded Script
26246Yes py-section-script.py
26247 full name: /tmp/py-section-script.py
26248No my-foo-pretty-printers.py
dbaefcf7 26249@end smallexample
8a1ea21f
DE
26250@end table
26251
26252When reading an auto-loaded file, @value{GDBN} sets the
26253@dfn{current objfile}. This is available via the @code{gdb.current_objfile}
26254function (@pxref{Objfiles In Python}). This can be useful for
26255registering objfile-specific pretty-printers.
26256
3708f05e
JK
26257@menu
26258* objfile-gdb.py file:: The @file{@var{objfile}-gdb.py} file
26259* dotdebug_gdb_scripts section:: The @code{.debug_gdb_scripts} section
26260* Which flavor to choose?::
26261@end menu
26262
8a1ea21f
DE
26263@node objfile-gdb.py file
26264@subsubsection The @file{@var{objfile}-gdb.py} file
26265@cindex @file{@var{objfile}-gdb.py}
26266
26267When a new object file is read, @value{GDBN} looks for
7349ff92 26268a file named @file{@var{objfile}-gdb.py} (we call it @var{script-name} below),
8a1ea21f
DE
26269where @var{objfile} is the object file's real name, formed by ensuring
26270that the file name is absolute, following all symlinks, and resolving
26271@code{.} and @code{..} components. If this file exists and is
26272readable, @value{GDBN} will evaluate it as a Python script.
26273
1564a261 26274If this file does not exist, then @value{GDBN} will look for
c1668e4e
JK
26275@var{script-name} file in all of the directories as specified below.
26276
26277Note that loading of this script file also requires accordingly configured
26278@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
7349ff92 26279
e9687799
JK
26280For object files using @file{.exe} suffix @value{GDBN} tries to load first the
26281scripts normally according to its @file{.exe} filename. But if no scripts are
26282found @value{GDBN} also tries script filenames matching the object file without
26283its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
26284is attempted on any platform. This makes the script filenames compatible
26285between Unix and MS-Windows hosts.
26286
7349ff92
JK
26287@table @code
26288@anchor{set auto-load scripts-directory}
26289@kindex set auto-load scripts-directory
26290@item set auto-load scripts-directory @r{[}@var{directories}@r{]}
26291Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
26292may be delimited by the host platform path separator in use
26293(@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
26294
26295Each entry here needs to be covered also by the security setting
26296@code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
26297
26298@anchor{with-auto-load-dir}
1564a261
JK
26299This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
26300@code{set auto-load safe-path} value can be also overriden by @value{GDBN}
26301configuration option @option{--with-auto-load-dir}.
26302
26303Any reference to @file{$debugdir} will get replaced by
26304@var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
26305reference to @file{$datadir} will get replaced by @var{data-directory} which is
26306determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
26307@file{$datadir} must be placed as a directory component --- either alone or
26308delimited by @file{/} or @file{\} directory separators, depending on the host
26309platform.
7349ff92
JK
26310
26311The list of directories uses path separator (@samp{:} on GNU and Unix
26312systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26313to the @env{PATH} environment variable.
26314
26315@anchor{show auto-load scripts-directory}
26316@kindex show auto-load scripts-directory
26317@item show auto-load scripts-directory
26318Show @value{GDBN} auto-loaded scripts location.
26319@end table
8a1ea21f
DE
26320
26321@value{GDBN} does not track which files it has already auto-loaded this way.
26322@value{GDBN} will load the associated script every time the corresponding
26323@var{objfile} is opened.
26324So your @file{-gdb.py} file should be careful to avoid errors if it
26325is evaluated more than once.
26326
8e0583c8 26327@node dotdebug_gdb_scripts section
8a1ea21f
DE
26328@subsubsection The @code{.debug_gdb_scripts} section
26329@cindex @code{.debug_gdb_scripts} section
26330
26331For systems using file formats like ELF and COFF,
26332when @value{GDBN} loads a new object file
26333it will look for a special section named @samp{.debug_gdb_scripts}.
26334If this section exists, its contents is a list of names of scripts to load.
26335
26336@value{GDBN} will look for each specified script file first in the
26337current directory and then along the source search path
26338(@pxref{Source Path, ,Specifying Source Directories}),
26339except that @file{$cdir} is not searched, since the compilation
26340directory is not relevant to scripts.
26341
26342Entries can be placed in section @code{.debug_gdb_scripts} with,
26343for example, this GCC macro:
26344
26345@example
a3a7127e 26346/* Note: The "MS" section flags are to remove duplicates. */
8a1ea21f
DE
26347#define DEFINE_GDB_SCRIPT(script_name) \
26348 asm("\
26349.pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
26350.byte 1\n\
26351.asciz \"" script_name "\"\n\
26352.popsection \n\
26353");
26354@end example
26355
26356@noindent
26357Then one can reference the macro in a header or source file like this:
26358
26359@example
26360DEFINE_GDB_SCRIPT ("my-app-scripts.py")
26361@end example
26362
26363The script name may include directories if desired.
26364
c1668e4e
JK
26365Note that loading of this script file also requires accordingly configured
26366@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26367
8a1ea21f
DE
26368If the macro is put in a header, any application or library
26369using this header will get a reference to the specified script.
26370
26371@node Which flavor to choose?
26372@subsubsection Which flavor to choose?
26373
26374Given the multiple ways of auto-loading Python scripts, it might not always
26375be clear which one to choose. This section provides some guidance.
26376
26377Benefits of the @file{-gdb.py} way:
26378
26379@itemize @bullet
26380@item
26381Can be used with file formats that don't support multiple sections.
26382
26383@item
26384Ease of finding scripts for public libraries.
26385
26386Scripts specified in the @code{.debug_gdb_scripts} section are searched for
26387in the source search path.
26388For publicly installed libraries, e.g., @file{libstdc++}, there typically
26389isn't a source directory in which to find the script.
26390
26391@item
26392Doesn't require source code additions.
26393@end itemize
26394
26395Benefits of the @code{.debug_gdb_scripts} way:
26396
26397@itemize @bullet
26398@item
26399Works with static linking.
26400
26401Scripts for libraries done the @file{-gdb.py} way require an objfile to
26402trigger their loading. When an application is statically linked the only
26403objfile available is the executable, and it is cumbersome to attach all the
26404scripts from all the input libraries to the executable's @file{-gdb.py} script.
26405
26406@item
26407Works with classes that are entirely inlined.
26408
26409Some classes can be entirely inlined, and thus there may not be an associated
26410shared library to attach a @file{-gdb.py} script to.
26411
26412@item
26413Scripts needn't be copied out of the source tree.
26414
26415In some circumstances, apps can be built out of large collections of internal
26416libraries, and the build infrastructure necessary to install the
26417@file{-gdb.py} scripts in a place where @value{GDBN} can find them is
26418cumbersome. It may be easier to specify the scripts in the
26419@code{.debug_gdb_scripts} section as relative paths, and add a path to the
26420top of the source tree to the source search path.
26421@end itemize
26422
0e3509db
DE
26423@node Python modules
26424@subsection Python modules
26425@cindex python modules
26426
fa3a4f15 26427@value{GDBN} comes with several modules to assist writing Python code.
0e3509db
DE
26428
26429@menu
7b51bc51 26430* gdb.printing:: Building and registering pretty-printers.
0e3509db 26431* gdb.types:: Utilities for working with types.
fa3a4f15 26432* gdb.prompt:: Utilities for prompt value substitution.
0e3509db
DE
26433@end menu
26434
7b51bc51
DE
26435@node gdb.printing
26436@subsubsection gdb.printing
26437@cindex gdb.printing
26438
26439This module provides a collection of utilities for working with
26440pretty-printers.
26441
26442@table @code
26443@item PrettyPrinter (@var{name}, @var{subprinters}=None)
26444This class specifies the API that makes @samp{info pretty-printer},
26445@samp{enable pretty-printer} and @samp{disable pretty-printer} work.
26446Pretty-printers should generally inherit from this class.
26447
26448@item SubPrettyPrinter (@var{name})
26449For printers that handle multiple types, this class specifies the
26450corresponding API for the subprinters.
26451
26452@item RegexpCollectionPrettyPrinter (@var{name})
26453Utility class for handling multiple printers, all recognized via
26454regular expressions.
26455@xref{Writing a Pretty-Printer}, for an example.
26456
cafec441
TT
26457@item FlagEnumerationPrinter (@var{name})
26458A pretty-printer which handles printing of @code{enum} values. Unlike
26459@value{GDBN}'s built-in @code{enum} printing, this printer attempts to
26460work properly when there is some overlap between the enumeration
26461constants. @var{name} is the name of the printer and also the name of
26462the @code{enum} type to look up.
26463
9c15afc4 26464@item register_pretty_printer (@var{obj}, @var{printer}, @var{replace}=False)
7b51bc51 26465Register @var{printer} with the pretty-printer list of @var{obj}.
9c15afc4
DE
26466If @var{replace} is @code{True} then any existing copy of the printer
26467is replaced. Otherwise a @code{RuntimeError} exception is raised
26468if a printer with the same name already exists.
7b51bc51
DE
26469@end table
26470
0e3509db
DE
26471@node gdb.types
26472@subsubsection gdb.types
7b51bc51 26473@cindex gdb.types
0e3509db
DE
26474
26475This module provides a collection of utilities for working with
18a9fc12 26476@code{gdb.Type} objects.
0e3509db
DE
26477
26478@table @code
26479@item get_basic_type (@var{type})
26480Return @var{type} with const and volatile qualifiers stripped,
26481and with typedefs and C@t{++} references converted to the underlying type.
26482
26483C@t{++} example:
26484
26485@smallexample
26486typedef const int const_int;
26487const_int foo (3);
26488const_int& foo_ref (foo);
26489int main () @{ return 0; @}
26490@end smallexample
26491
26492Then in gdb:
26493
26494@smallexample
26495(gdb) start
26496(gdb) python import gdb.types
26497(gdb) python foo_ref = gdb.parse_and_eval("foo_ref")
26498(gdb) python print gdb.types.get_basic_type(foo_ref.type)
26499int
26500@end smallexample
26501
26502@item has_field (@var{type}, @var{field})
26503Return @code{True} if @var{type}, assumed to be a type with fields
26504(e.g., a structure or union), has field @var{field}.
26505
26506@item make_enum_dict (@var{enum_type})
26507Return a Python @code{dictionary} type produced from @var{enum_type}.
5110b5df 26508
0aaaf063 26509@item deep_items (@var{type})
5110b5df
PK
26510Returns a Python iterator similar to the standard
26511@code{gdb.Type.iteritems} method, except that the iterator returned
0aaaf063 26512by @code{deep_items} will recursively traverse anonymous struct or
5110b5df
PK
26513union fields. For example:
26514
26515@smallexample
26516struct A
26517@{
26518 int a;
26519 union @{
26520 int b0;
26521 int b1;
26522 @};
26523@};
26524@end smallexample
26525
26526@noindent
26527Then in @value{GDBN}:
26528@smallexample
26529(@value{GDBP}) python import gdb.types
26530(@value{GDBP}) python struct_a = gdb.lookup_type("struct A")
26531(@value{GDBP}) python print struct_a.keys ()
26532@{['a', '']@}
0aaaf063 26533(@value{GDBP}) python print [k for k,v in gdb.types.deep_items(struct_a)]
5110b5df
PK
26534@{['a', 'b0', 'b1']@}
26535@end smallexample
26536
18a9fc12
TT
26537@item get_type_recognizers ()
26538Return a list of the enabled type recognizers for the current context.
26539This is called by @value{GDBN} during the type-printing process
26540(@pxref{Type Printing API}).
26541
26542@item apply_type_recognizers (recognizers, type_obj)
26543Apply the type recognizers, @var{recognizers}, to the type object
26544@var{type_obj}. If any recognizer returns a string, return that
26545string. Otherwise, return @code{None}. This is called by
26546@value{GDBN} during the type-printing process (@pxref{Type Printing
26547API}).
26548
26549@item register_type_printer (locus, printer)
26550This is a convenience function to register a type printer.
26551@var{printer} is the type printer to register. It must implement the
26552type printer protocol. @var{locus} is either a @code{gdb.Objfile}, in
26553which case the printer is registered with that objfile; a
26554@code{gdb.Progspace}, in which case the printer is registered with
26555that progspace; or @code{None}, in which case the printer is
26556registered globally.
26557
26558@item TypePrinter
26559This is a base class that implements the type printer protocol. Type
26560printers are encouraged, but not required, to derive from this class.
26561It defines a constructor:
26562
26563@defmethod TypePrinter __init__ (self, name)
26564Initialize the type printer with the given name. The new printer
26565starts in the enabled state.
26566@end defmethod
26567
0e3509db 26568@end table
fa3a4f15
PM
26569
26570@node gdb.prompt
26571@subsubsection gdb.prompt
26572@cindex gdb.prompt
26573
26574This module provides a method for prompt value-substitution.
26575
26576@table @code
26577@item substitute_prompt (@var{string})
26578Return @var{string} with escape sequences substituted by values. Some
26579escape sequences take arguments. You can specify arguments inside
26580``@{@}'' immediately following the escape sequence.
26581
26582The escape sequences you can pass to this function are:
26583
26584@table @code
26585@item \\
26586Substitute a backslash.
26587@item \e
26588Substitute an ESC character.
26589@item \f
26590Substitute the selected frame; an argument names a frame parameter.
26591@item \n
26592Substitute a newline.
26593@item \p
26594Substitute a parameter's value; the argument names the parameter.
26595@item \r
26596Substitute a carriage return.
26597@item \t
26598Substitute the selected thread; an argument names a thread parameter.
26599@item \v
26600Substitute the version of GDB.
26601@item \w
26602Substitute the current working directory.
26603@item \[
26604Begin a sequence of non-printing characters. These sequences are
26605typically used with the ESC character, and are not counted in the string
26606length. Example: ``\[\e[0;34m\](gdb)\[\e[0m\]'' will return a
26607blue-colored ``(gdb)'' prompt where the length is five.
26608@item \]
26609End a sequence of non-printing characters.
26610@end table
26611
26612For example:
26613
26614@smallexample
26615substitute_prompt (``frame: \f,
26616 print arguments: \p@{print frame-arguments@}'')
26617@end smallexample
26618
26619@exdent will return the string:
26620
26621@smallexample
26622"frame: main, print arguments: scalars"
26623@end smallexample
26624@end table
0e3509db 26625
5a56e9c5
DE
26626@node Aliases
26627@section Creating new spellings of existing commands
26628@cindex aliases for commands
26629
26630It is often useful to define alternate spellings of existing commands.
26631For example, if a new @value{GDBN} command defined in Python has
26632a long name to type, it is handy to have an abbreviated version of it
26633that involves less typing.
26634
26635@value{GDBN} itself uses aliases. For example @samp{s} is an alias
26636of the @samp{step} command even though it is otherwise an ambiguous
26637abbreviation of other commands like @samp{set} and @samp{show}.
26638
26639Aliases are also used to provide shortened or more common versions
26640of multi-word commands. For example, @value{GDBN} provides the
26641@samp{tty} alias of the @samp{set inferior-tty} command.
26642
26643You can define a new alias with the @samp{alias} command.
26644
26645@table @code
26646
26647@kindex alias
26648@item alias [-a] [--] @var{ALIAS} = @var{COMMAND}
26649
26650@end table
26651
26652@var{ALIAS} specifies the name of the new alias.
26653Each word of @var{ALIAS} must consist of letters, numbers, dashes and
26654underscores.
26655
26656@var{COMMAND} specifies the name of an existing command
26657that is being aliased.
26658
26659The @samp{-a} option specifies that the new alias is an abbreviation
26660of the command. Abbreviations are not shown in command
26661lists displayed by the @samp{help} command.
26662
26663The @samp{--} option specifies the end of options,
26664and is useful when @var{ALIAS} begins with a dash.
26665
26666Here is a simple example showing how to make an abbreviation
26667of a command so that there is less to type.
26668Suppose you were tired of typing @samp{disas}, the current
26669shortest unambiguous abbreviation of the @samp{disassemble} command
26670and you wanted an even shorter version named @samp{di}.
26671The following will accomplish this.
26672
26673@smallexample
26674(gdb) alias -a di = disas
26675@end smallexample
26676
26677Note that aliases are different from user-defined commands.
26678With a user-defined command, you also need to write documentation
26679for it with the @samp{document} command.
26680An alias automatically picks up the documentation of the existing command.
26681
26682Here is an example where we make @samp{elms} an abbreviation of
26683@samp{elements} in the @samp{set print elements} command.
26684This is to show that you can make an abbreviation of any part
26685of a command.
26686
26687@smallexample
26688(gdb) alias -a set print elms = set print elements
26689(gdb) alias -a show print elms = show print elements
26690(gdb) set p elms 20
26691(gdb) show p elms
26692Limit on string chars or array elements to print is 200.
26693@end smallexample
26694
26695Note that if you are defining an alias of a @samp{set} command,
26696and you want to have an alias for the corresponding @samp{show}
26697command, then you need to define the latter separately.
26698
26699Unambiguously abbreviated commands are allowed in @var{COMMAND} and
26700@var{ALIAS}, just as they are normally.
26701
26702@smallexample
26703(gdb) alias -a set pr elms = set p ele
26704@end smallexample
26705
26706Finally, here is an example showing the creation of a one word
26707alias for a more complex command.
26708This creates alias @samp{spe} of the command @samp{set print elements}.
26709
26710@smallexample
26711(gdb) alias spe = set print elements
26712(gdb) spe 20
26713@end smallexample
26714
21c294e6
AC
26715@node Interpreters
26716@chapter Command Interpreters
26717@cindex command interpreters
26718
26719@value{GDBN} supports multiple command interpreters, and some command
26720infrastructure to allow users or user interface writers to switch
26721between interpreters or run commands in other interpreters.
26722
26723@value{GDBN} currently supports two command interpreters, the console
26724interpreter (sometimes called the command-line interpreter or @sc{cli})
26725and the machine interface interpreter (or @sc{gdb/mi}). This manual
26726describes both of these interfaces in great detail.
26727
26728By default, @value{GDBN} will start with the console interpreter.
26729However, the user may choose to start @value{GDBN} with another
26730interpreter by specifying the @option{-i} or @option{--interpreter}
26731startup options. Defined interpreters include:
26732
26733@table @code
26734@item console
26735@cindex console interpreter
26736The traditional console or command-line interpreter. This is the most often
26737used interpreter with @value{GDBN}. With no interpreter specified at runtime,
26738@value{GDBN} will use this interpreter.
26739
26740@item mi
26741@cindex mi interpreter
26742The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
26743by programs wishing to use @value{GDBN} as a backend for a debugger GUI
26744or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
26745Interface}.
26746
26747@item mi2
26748@cindex mi2 interpreter
26749The current @sc{gdb/mi} interface.
26750
26751@item mi1
26752@cindex mi1 interpreter
26753The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
26754
26755@end table
26756
26757@cindex invoke another interpreter
26758The interpreter being used by @value{GDBN} may not be dynamically
26759switched at runtime. Although possible, this could lead to a very
26760precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
26761enters the command "interpreter-set console" in a console view,
26762@value{GDBN} would switch to using the console interpreter, rendering
26763the IDE inoperable!
26764
26765@kindex interpreter-exec
26766Although you may only choose a single interpreter at startup, you may execute
26767commands in any interpreter from the current interpreter using the appropriate
26768command. If you are running the console interpreter, simply use the
26769@code{interpreter-exec} command:
26770
26771@smallexample
26772interpreter-exec mi "-data-list-register-names"
26773@end smallexample
26774
26775@sc{gdb/mi} has a similar command, although it is only available in versions of
26776@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
26777
8e04817f
AC
26778@node TUI
26779@chapter @value{GDBN} Text User Interface
26780@cindex TUI
d0d5df6f 26781@cindex Text User Interface
c906108c 26782
8e04817f
AC
26783@menu
26784* TUI Overview:: TUI overview
26785* TUI Keys:: TUI key bindings
7cf36c78 26786* TUI Single Key Mode:: TUI single key mode
db2e3e2e 26787* TUI Commands:: TUI-specific commands
8e04817f
AC
26788* TUI Configuration:: TUI configuration variables
26789@end menu
c906108c 26790
46ba6afa 26791The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
26792interface which uses the @code{curses} library to show the source
26793file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
26794commands in separate text windows. The TUI mode is supported only
26795on platforms where a suitable version of the @code{curses} library
26796is available.
d0d5df6f 26797
46ba6afa 26798The TUI mode is enabled by default when you invoke @value{GDBN} as
217bff3e 26799@samp{@value{GDBP} -tui}.
46ba6afa
BW
26800You can also switch in and out of TUI mode while @value{GDBN} runs by
26801using various TUI commands and key bindings, such as @kbd{C-x C-a}.
26802@xref{TUI Keys, ,TUI Key Bindings}.
c906108c 26803
8e04817f 26804@node TUI Overview
79a6e687 26805@section TUI Overview
c906108c 26806
46ba6afa 26807In TUI mode, @value{GDBN} can display several text windows:
c906108c 26808
8e04817f
AC
26809@table @emph
26810@item command
26811This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
26812prompt and the @value{GDBN} output. The @value{GDBN} input is still
26813managed using readline.
c906108c 26814
8e04817f
AC
26815@item source
26816The source window shows the source file of the program. The current
46ba6afa 26817line and active breakpoints are displayed in this window.
c906108c 26818
8e04817f
AC
26819@item assembly
26820The assembly window shows the disassembly output of the program.
c906108c 26821
8e04817f 26822@item register
46ba6afa
BW
26823This window shows the processor registers. Registers are highlighted
26824when their values change.
c906108c
SS
26825@end table
26826
269c21fe 26827The source and assembly windows show the current program position
46ba6afa
BW
26828by highlighting the current line and marking it with a @samp{>} marker.
26829Breakpoints are indicated with two markers. The first marker
269c21fe
SC
26830indicates the breakpoint type:
26831
26832@table @code
26833@item B
26834Breakpoint which was hit at least once.
26835
26836@item b
26837Breakpoint which was never hit.
26838
26839@item H
26840Hardware breakpoint which was hit at least once.
26841
26842@item h
26843Hardware breakpoint which was never hit.
269c21fe
SC
26844@end table
26845
26846The second marker indicates whether the breakpoint is enabled or not:
26847
26848@table @code
26849@item +
26850Breakpoint is enabled.
26851
26852@item -
26853Breakpoint is disabled.
269c21fe
SC
26854@end table
26855
46ba6afa
BW
26856The source, assembly and register windows are updated when the current
26857thread changes, when the frame changes, or when the program counter
26858changes.
26859
26860These windows are not all visible at the same time. The command
26861window is always visible. The others can be arranged in several
26862layouts:
c906108c 26863
8e04817f
AC
26864@itemize @bullet
26865@item
46ba6afa 26866source only,
2df3850c 26867
8e04817f 26868@item
46ba6afa 26869assembly only,
8e04817f
AC
26870
26871@item
46ba6afa 26872source and assembly,
8e04817f
AC
26873
26874@item
46ba6afa 26875source and registers, or
c906108c 26876
8e04817f 26877@item
46ba6afa 26878assembly and registers.
8e04817f 26879@end itemize
c906108c 26880
46ba6afa 26881A status line above the command window shows the following information:
b7bb15bc
SC
26882
26883@table @emph
26884@item target
46ba6afa 26885Indicates the current @value{GDBN} target.
b7bb15bc
SC
26886(@pxref{Targets, ,Specifying a Debugging Target}).
26887
26888@item process
46ba6afa 26889Gives the current process or thread number.
b7bb15bc
SC
26890When no process is being debugged, this field is set to @code{No process}.
26891
26892@item function
26893Gives the current function name for the selected frame.
26894The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 26895When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
26896the string @code{??} is displayed.
26897
26898@item line
26899Indicates the current line number for the selected frame.
46ba6afa 26900When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
26901
26902@item pc
26903Indicates the current program counter address.
b7bb15bc
SC
26904@end table
26905
8e04817f
AC
26906@node TUI Keys
26907@section TUI Key Bindings
26908@cindex TUI key bindings
c906108c 26909
8e04817f 26910The TUI installs several key bindings in the readline keymaps
39037522
TT
26911@ifset SYSTEM_READLINE
26912(@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
26913@end ifset
26914@ifclear SYSTEM_READLINE
26915(@pxref{Command Line Editing}).
26916@end ifclear
26917The following key bindings are installed for both TUI mode and the
26918@value{GDBN} standard mode.
c906108c 26919
8e04817f
AC
26920@table @kbd
26921@kindex C-x C-a
26922@item C-x C-a
26923@kindex C-x a
26924@itemx C-x a
26925@kindex C-x A
26926@itemx C-x A
46ba6afa
BW
26927Enter or leave the TUI mode. When leaving the TUI mode,
26928the curses window management stops and @value{GDBN} operates using
26929its standard mode, writing on the terminal directly. When reentering
26930the TUI mode, control is given back to the curses windows.
8e04817f 26931The screen is then refreshed.
c906108c 26932
8e04817f
AC
26933@kindex C-x 1
26934@item C-x 1
26935Use a TUI layout with only one window. The layout will
26936either be @samp{source} or @samp{assembly}. When the TUI mode
26937is not active, it will switch to the TUI mode.
2df3850c 26938
8e04817f 26939Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 26940
8e04817f
AC
26941@kindex C-x 2
26942@item C-x 2
26943Use a TUI layout with at least two windows. When the current
46ba6afa 26944layout already has two windows, the next layout with two windows is used.
8e04817f
AC
26945When a new layout is chosen, one window will always be common to the
26946previous layout and the new one.
c906108c 26947
8e04817f 26948Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 26949
72ffddc9
SC
26950@kindex C-x o
26951@item C-x o
26952Change the active window. The TUI associates several key bindings
46ba6afa 26953(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
26954gives the focus to the next TUI window.
26955
26956Think of it as the Emacs @kbd{C-x o} binding.
26957
7cf36c78
SC
26958@kindex C-x s
26959@item C-x s
46ba6afa
BW
26960Switch in and out of the TUI SingleKey mode that binds single
26961keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c906108c
SS
26962@end table
26963
46ba6afa 26964The following key bindings only work in the TUI mode:
5d161b24 26965
46ba6afa 26966@table @asis
8e04817f 26967@kindex PgUp
46ba6afa 26968@item @key{PgUp}
8e04817f 26969Scroll the active window one page up.
c906108c 26970
8e04817f 26971@kindex PgDn
46ba6afa 26972@item @key{PgDn}
8e04817f 26973Scroll the active window one page down.
c906108c 26974
8e04817f 26975@kindex Up
46ba6afa 26976@item @key{Up}
8e04817f 26977Scroll the active window one line up.
c906108c 26978
8e04817f 26979@kindex Down
46ba6afa 26980@item @key{Down}
8e04817f 26981Scroll the active window one line down.
c906108c 26982
8e04817f 26983@kindex Left
46ba6afa 26984@item @key{Left}
8e04817f 26985Scroll the active window one column left.
c906108c 26986
8e04817f 26987@kindex Right
46ba6afa 26988@item @key{Right}
8e04817f 26989Scroll the active window one column right.
c906108c 26990
8e04817f 26991@kindex C-L
46ba6afa 26992@item @kbd{C-L}
8e04817f 26993Refresh the screen.
8e04817f 26994@end table
c906108c 26995
46ba6afa
BW
26996Because the arrow keys scroll the active window in the TUI mode, they
26997are not available for their normal use by readline unless the command
26998window has the focus. When another window is active, you must use
26999other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
27000and @kbd{C-f} to control the command window.
8e04817f 27001
7cf36c78
SC
27002@node TUI Single Key Mode
27003@section TUI Single Key Mode
27004@cindex TUI single key mode
27005
46ba6afa
BW
27006The TUI also provides a @dfn{SingleKey} mode, which binds several
27007frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
27008switch into this mode, where the following key bindings are used:
7cf36c78
SC
27009
27010@table @kbd
27011@kindex c @r{(SingleKey TUI key)}
27012@item c
27013continue
27014
27015@kindex d @r{(SingleKey TUI key)}
27016@item d
27017down
27018
27019@kindex f @r{(SingleKey TUI key)}
27020@item f
27021finish
27022
27023@kindex n @r{(SingleKey TUI key)}
27024@item n
27025next
27026
27027@kindex q @r{(SingleKey TUI key)}
27028@item q
46ba6afa 27029exit the SingleKey mode.
7cf36c78
SC
27030
27031@kindex r @r{(SingleKey TUI key)}
27032@item r
27033run
27034
27035@kindex s @r{(SingleKey TUI key)}
27036@item s
27037step
27038
27039@kindex u @r{(SingleKey TUI key)}
27040@item u
27041up
27042
27043@kindex v @r{(SingleKey TUI key)}
27044@item v
27045info locals
27046
27047@kindex w @r{(SingleKey TUI key)}
27048@item w
27049where
7cf36c78
SC
27050@end table
27051
27052Other keys temporarily switch to the @value{GDBN} command prompt.
27053The key that was pressed is inserted in the editing buffer so that
27054it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
27055with the TUI SingleKey mode. Once the command is entered the TUI
27056SingleKey mode is restored. The only way to permanently leave
7f9087cb 27057this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78
SC
27058
27059
8e04817f 27060@node TUI Commands
db2e3e2e 27061@section TUI-specific Commands
8e04817f
AC
27062@cindex TUI commands
27063
27064The TUI has specific commands to control the text windows.
46ba6afa
BW
27065These commands are always available, even when @value{GDBN} is not in
27066the TUI mode. When @value{GDBN} is in the standard mode, most
27067of these commands will automatically switch to the TUI mode.
c906108c 27068
ff12863f
PA
27069Note that if @value{GDBN}'s @code{stdout} is not connected to a
27070terminal, or @value{GDBN} has been started with the machine interface
27071interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
27072these commands will fail with an error, because it would not be
27073possible or desirable to enable curses window management.
27074
c906108c 27075@table @code
3d757584
SC
27076@item info win
27077@kindex info win
27078List and give the size of all displayed windows.
27079
8e04817f 27080@item layout next
4644b6e3 27081@kindex layout
8e04817f 27082Display the next layout.
2df3850c 27083
8e04817f 27084@item layout prev
8e04817f 27085Display the previous layout.
c906108c 27086
8e04817f 27087@item layout src
8e04817f 27088Display the source window only.
c906108c 27089
8e04817f 27090@item layout asm
8e04817f 27091Display the assembly window only.
c906108c 27092
8e04817f 27093@item layout split
8e04817f 27094Display the source and assembly window.
c906108c 27095
8e04817f 27096@item layout regs
8e04817f
AC
27097Display the register window together with the source or assembly window.
27098
46ba6afa 27099@item focus next
8e04817f 27100@kindex focus
46ba6afa
BW
27101Make the next window active for scrolling.
27102
27103@item focus prev
27104Make the previous window active for scrolling.
27105
27106@item focus src
27107Make the source window active for scrolling.
27108
27109@item focus asm
27110Make the assembly window active for scrolling.
27111
27112@item focus regs
27113Make the register window active for scrolling.
27114
27115@item focus cmd
27116Make the command window active for scrolling.
c906108c 27117
8e04817f
AC
27118@item refresh
27119@kindex refresh
7f9087cb 27120Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 27121
6a1b180d
SC
27122@item tui reg float
27123@kindex tui reg
27124Show the floating point registers in the register window.
27125
27126@item tui reg general
27127Show the general registers in the register window.
27128
27129@item tui reg next
27130Show the next register group. The list of register groups as well as
27131their order is target specific. The predefined register groups are the
27132following: @code{general}, @code{float}, @code{system}, @code{vector},
27133@code{all}, @code{save}, @code{restore}.
27134
27135@item tui reg system
27136Show the system registers in the register window.
27137
8e04817f
AC
27138@item update
27139@kindex update
27140Update the source window and the current execution point.
c906108c 27141
8e04817f
AC
27142@item winheight @var{name} +@var{count}
27143@itemx winheight @var{name} -@var{count}
27144@kindex winheight
27145Change the height of the window @var{name} by @var{count}
27146lines. Positive counts increase the height, while negative counts
27147decrease it.
2df3850c 27148
46ba6afa
BW
27149@item tabset @var{nchars}
27150@kindex tabset
c45da7e6 27151Set the width of tab stops to be @var{nchars} characters.
c906108c
SS
27152@end table
27153
8e04817f 27154@node TUI Configuration
79a6e687 27155@section TUI Configuration Variables
8e04817f 27156@cindex TUI configuration variables
c906108c 27157
46ba6afa 27158Several configuration variables control the appearance of TUI windows.
c906108c 27159
8e04817f
AC
27160@table @code
27161@item set tui border-kind @var{kind}
27162@kindex set tui border-kind
27163Select the border appearance for the source, assembly and register windows.
27164The possible values are the following:
27165@table @code
27166@item space
27167Use a space character to draw the border.
c906108c 27168
8e04817f 27169@item ascii
46ba6afa 27170Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 27171
8e04817f
AC
27172@item acs
27173Use the Alternate Character Set to draw the border. The border is
27174drawn using character line graphics if the terminal supports them.
8e04817f 27175@end table
c78b4128 27176
8e04817f
AC
27177@item set tui border-mode @var{mode}
27178@kindex set tui border-mode
46ba6afa
BW
27179@itemx set tui active-border-mode @var{mode}
27180@kindex set tui active-border-mode
27181Select the display attributes for the borders of the inactive windows
27182or the active window. The @var{mode} can be one of the following:
8e04817f
AC
27183@table @code
27184@item normal
27185Use normal attributes to display the border.
c906108c 27186
8e04817f
AC
27187@item standout
27188Use standout mode.
c906108c 27189
8e04817f
AC
27190@item reverse
27191Use reverse video mode.
c906108c 27192
8e04817f
AC
27193@item half
27194Use half bright mode.
c906108c 27195
8e04817f
AC
27196@item half-standout
27197Use half bright and standout mode.
c906108c 27198
8e04817f
AC
27199@item bold
27200Use extra bright or bold mode.
c78b4128 27201
8e04817f
AC
27202@item bold-standout
27203Use extra bright or bold and standout mode.
8e04817f 27204@end table
8e04817f 27205@end table
c78b4128 27206
8e04817f
AC
27207@node Emacs
27208@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 27209
8e04817f
AC
27210@cindex Emacs
27211@cindex @sc{gnu} Emacs
27212A special interface allows you to use @sc{gnu} Emacs to view (and
27213edit) the source files for the program you are debugging with
27214@value{GDBN}.
c906108c 27215
8e04817f
AC
27216To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
27217executable file you want to debug as an argument. This command starts
27218@value{GDBN} as a subprocess of Emacs, with input and output through a newly
27219created Emacs buffer.
27220@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 27221
5e252a2e 27222Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 27223things:
c906108c 27224
8e04817f
AC
27225@itemize @bullet
27226@item
5e252a2e
NR
27227All ``terminal'' input and output goes through an Emacs buffer, called
27228the GUD buffer.
c906108c 27229
8e04817f
AC
27230This applies both to @value{GDBN} commands and their output, and to the input
27231and output done by the program you are debugging.
bf0184be 27232
8e04817f
AC
27233This is useful because it means that you can copy the text of previous
27234commands and input them again; you can even use parts of the output
27235in this way.
bf0184be 27236
8e04817f
AC
27237All the facilities of Emacs' Shell mode are available for interacting
27238with your program. In particular, you can send signals the usual
27239way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
27240stop.
bf0184be
ND
27241
27242@item
8e04817f 27243@value{GDBN} displays source code through Emacs.
bf0184be 27244
8e04817f
AC
27245Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
27246source file for that frame and puts an arrow (@samp{=>}) at the
27247left margin of the current line. Emacs uses a separate buffer for
27248source display, and splits the screen to show both your @value{GDBN} session
27249and the source.
bf0184be 27250
8e04817f
AC
27251Explicit @value{GDBN} @code{list} or search commands still produce output as
27252usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
27253@end itemize
27254
27255We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
27256a graphical mode, enabled by default, which provides further buffers
27257that can control the execution and describe the state of your program.
27258@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 27259
64fabec2
AC
27260If you specify an absolute file name when prompted for the @kbd{M-x
27261gdb} argument, then Emacs sets your current working directory to where
27262your program resides. If you only specify the file name, then Emacs
7a9dd1b2 27263sets your current working directory to the directory associated
64fabec2
AC
27264with the previous buffer. In this case, @value{GDBN} may find your
27265program by searching your environment's @code{PATH} variable, but on
27266some operating systems it might not find the source. So, although the
27267@value{GDBN} input and output session proceeds normally, the auxiliary
27268buffer does not display the current source and line of execution.
27269
27270The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
27271line of the GUD buffer and this serves as a default for the commands
27272that specify files for @value{GDBN} to operate on. @xref{Files,
27273,Commands to Specify Files}.
64fabec2
AC
27274
27275By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
27276need to call @value{GDBN} by a different name (for example, if you
27277keep several configurations around, with different names) you can
27278customize the Emacs variable @code{gud-gdb-command-name} to run the
27279one you want.
8e04817f 27280
5e252a2e 27281In the GUD buffer, you can use these special Emacs commands in
8e04817f 27282addition to the standard Shell mode commands:
c906108c 27283
8e04817f
AC
27284@table @kbd
27285@item C-h m
5e252a2e 27286Describe the features of Emacs' GUD Mode.
c906108c 27287
64fabec2 27288@item C-c C-s
8e04817f
AC
27289Execute to another source line, like the @value{GDBN} @code{step} command; also
27290update the display window to show the current file and location.
c906108c 27291
64fabec2 27292@item C-c C-n
8e04817f
AC
27293Execute to next source line in this function, skipping all function
27294calls, like the @value{GDBN} @code{next} command. Then update the display window
27295to show the current file and location.
c906108c 27296
64fabec2 27297@item C-c C-i
8e04817f
AC
27298Execute one instruction, like the @value{GDBN} @code{stepi} command; update
27299display window accordingly.
c906108c 27300
8e04817f
AC
27301@item C-c C-f
27302Execute until exit from the selected stack frame, like the @value{GDBN}
27303@code{finish} command.
c906108c 27304
64fabec2 27305@item C-c C-r
8e04817f
AC
27306Continue execution of your program, like the @value{GDBN} @code{continue}
27307command.
b433d00b 27308
64fabec2 27309@item C-c <
8e04817f
AC
27310Go up the number of frames indicated by the numeric argument
27311(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
27312like the @value{GDBN} @code{up} command.
b433d00b 27313
64fabec2 27314@item C-c >
8e04817f
AC
27315Go down the number of frames indicated by the numeric argument, like the
27316@value{GDBN} @code{down} command.
8e04817f 27317@end table
c906108c 27318
7f9087cb 27319In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 27320tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 27321
5e252a2e
NR
27322In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
27323separate frame which shows a backtrace when the GUD buffer is current.
27324Move point to any frame in the stack and type @key{RET} to make it
27325become the current frame and display the associated source in the
27326source buffer. Alternatively, click @kbd{Mouse-2} to make the
27327selected frame become the current one. In graphical mode, the
27328speedbar displays watch expressions.
64fabec2 27329
8e04817f
AC
27330If you accidentally delete the source-display buffer, an easy way to get
27331it back is to type the command @code{f} in the @value{GDBN} buffer, to
27332request a frame display; when you run under Emacs, this recreates
27333the source buffer if necessary to show you the context of the current
27334frame.
c906108c 27335
8e04817f
AC
27336The source files displayed in Emacs are in ordinary Emacs buffers
27337which are visiting the source files in the usual way. You can edit
27338the files with these buffers if you wish; but keep in mind that @value{GDBN}
27339communicates with Emacs in terms of line numbers. If you add or
27340delete lines from the text, the line numbers that @value{GDBN} knows cease
27341to correspond properly with the code.
b383017d 27342
5e252a2e
NR
27343A more detailed description of Emacs' interaction with @value{GDBN} is
27344given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
27345Emacs Manual}).
c906108c 27346
922fbb7b
AC
27347@node GDB/MI
27348@chapter The @sc{gdb/mi} Interface
27349
27350@unnumberedsec Function and Purpose
27351
27352@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
27353@sc{gdb/mi} is a line based machine oriented text interface to
27354@value{GDBN} and is activated by specifying using the
27355@option{--interpreter} command line option (@pxref{Mode Options}). It
27356is specifically intended to support the development of systems which
27357use the debugger as just one small component of a larger system.
922fbb7b
AC
27358
27359This chapter is a specification of the @sc{gdb/mi} interface. It is written
27360in the form of a reference manual.
27361
27362Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
27363features described below are incomplete and subject to change
27364(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
27365
27366@unnumberedsec Notation and Terminology
27367
27368@cindex notational conventions, for @sc{gdb/mi}
27369This chapter uses the following notation:
27370
27371@itemize @bullet
27372@item
27373@code{|} separates two alternatives.
27374
27375@item
27376@code{[ @var{something} ]} indicates that @var{something} is optional:
27377it may or may not be given.
27378
27379@item
27380@code{( @var{group} )*} means that @var{group} inside the parentheses
27381may repeat zero or more times.
27382
27383@item
27384@code{( @var{group} )+} means that @var{group} inside the parentheses
27385may repeat one or more times.
27386
27387@item
27388@code{"@var{string}"} means a literal @var{string}.
27389@end itemize
27390
27391@ignore
27392@heading Dependencies
27393@end ignore
27394
922fbb7b 27395@menu
c3b108f7 27396* GDB/MI General Design::
922fbb7b
AC
27397* GDB/MI Command Syntax::
27398* GDB/MI Compatibility with CLI::
af6eff6f 27399* GDB/MI Development and Front Ends::
922fbb7b 27400* GDB/MI Output Records::
ef21caaf 27401* GDB/MI Simple Examples::
922fbb7b 27402* GDB/MI Command Description Format::
ef21caaf 27403* GDB/MI Breakpoint Commands::
3fa7bf06 27404* GDB/MI Catchpoint Commands::
a2c02241
NR
27405* GDB/MI Program Context::
27406* GDB/MI Thread Commands::
5d77fe44 27407* GDB/MI Ada Tasking Commands::
a2c02241
NR
27408* GDB/MI Program Execution::
27409* GDB/MI Stack Manipulation::
27410* GDB/MI Variable Objects::
922fbb7b 27411* GDB/MI Data Manipulation::
a2c02241
NR
27412* GDB/MI Tracepoint Commands::
27413* GDB/MI Symbol Query::
351ff01a 27414* GDB/MI File Commands::
922fbb7b
AC
27415@ignore
27416* GDB/MI Kod Commands::
27417* GDB/MI Memory Overlay Commands::
27418* GDB/MI Signal Handling Commands::
27419@end ignore
922fbb7b 27420* GDB/MI Target Manipulation::
a6b151f1 27421* GDB/MI File Transfer Commands::
ef21caaf 27422* GDB/MI Miscellaneous Commands::
922fbb7b
AC
27423@end menu
27424
c3b108f7
VP
27425@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27426@node GDB/MI General Design
27427@section @sc{gdb/mi} General Design
27428@cindex GDB/MI General Design
27429
27430Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
27431parts---commands sent to @value{GDBN}, responses to those commands
27432and notifications. Each command results in exactly one response,
27433indicating either successful completion of the command, or an error.
27434For the commands that do not resume the target, the response contains the
27435requested information. For the commands that resume the target, the
27436response only indicates whether the target was successfully resumed.
27437Notifications is the mechanism for reporting changes in the state of the
27438target, or in @value{GDBN} state, that cannot conveniently be associated with
27439a command and reported as part of that command response.
27440
27441The important examples of notifications are:
27442@itemize @bullet
27443
27444@item
27445Exec notifications. These are used to report changes in
27446target state---when a target is resumed, or stopped. It would not
27447be feasible to include this information in response of resuming
27448commands, because one resume commands can result in multiple events in
27449different threads. Also, quite some time may pass before any event
27450happens in the target, while a frontend needs to know whether the resuming
27451command itself was successfully executed.
27452
27453@item
27454Console output, and status notifications. Console output
27455notifications are used to report output of CLI commands, as well as
27456diagnostics for other commands. Status notifications are used to
27457report the progress of a long-running operation. Naturally, including
27458this information in command response would mean no output is produced
27459until the command is finished, which is undesirable.
27460
27461@item
27462General notifications. Commands may have various side effects on
27463the @value{GDBN} or target state beyond their official purpose. For example,
27464a command may change the selected thread. Although such changes can
27465be included in command response, using notification allows for more
27466orthogonal frontend design.
27467
27468@end itemize
27469
27470There's no guarantee that whenever an MI command reports an error,
27471@value{GDBN} or the target are in any specific state, and especially,
27472the state is not reverted to the state before the MI command was
27473processed. Therefore, whenever an MI command results in an error,
27474we recommend that the frontend refreshes all the information shown in
27475the user interface.
27476
508094de
NR
27477
27478@menu
27479* Context management::
27480* Asynchronous and non-stop modes::
27481* Thread groups::
27482@end menu
27483
27484@node Context management
c3b108f7
VP
27485@subsection Context management
27486
27487In most cases when @value{GDBN} accesses the target, this access is
27488done in context of a specific thread and frame (@pxref{Frames}).
27489Often, even when accessing global data, the target requires that a thread
27490be specified. The CLI interface maintains the selected thread and frame,
27491and supplies them to target on each command. This is convenient,
27492because a command line user would not want to specify that information
27493explicitly on each command, and because user interacts with
27494@value{GDBN} via a single terminal, so no confusion is possible as
27495to what thread and frame are the current ones.
27496
27497In the case of MI, the concept of selected thread and frame is less
27498useful. First, a frontend can easily remember this information
27499itself. Second, a graphical frontend can have more than one window,
27500each one used for debugging a different thread, and the frontend might
27501want to access additional threads for internal purposes. This
27502increases the risk that by relying on implicitly selected thread, the
27503frontend may be operating on a wrong one. Therefore, each MI command
27504should explicitly specify which thread and frame to operate on. To
27505make it possible, each MI command accepts the @samp{--thread} and
27506@samp{--frame} options, the value to each is @value{GDBN} identifier
27507for thread and frame to operate on.
27508
27509Usually, each top-level window in a frontend allows the user to select
27510a thread and a frame, and remembers the user selection for further
27511operations. However, in some cases @value{GDBN} may suggest that the
27512current thread be changed. For example, when stopping on a breakpoint
27513it is reasonable to switch to the thread where breakpoint is hit. For
27514another example, if the user issues the CLI @samp{thread} command via
27515the frontend, it is desirable to change the frontend's selected thread to the
27516one specified by user. @value{GDBN} communicates the suggestion to
27517change current thread using the @samp{=thread-selected} notification.
27518No such notification is available for the selected frame at the moment.
27519
27520Note that historically, MI shares the selected thread with CLI, so
27521frontends used the @code{-thread-select} to execute commands in the
27522right context. However, getting this to work right is cumbersome. The
27523simplest way is for frontend to emit @code{-thread-select} command
27524before every command. This doubles the number of commands that need
27525to be sent. The alternative approach is to suppress @code{-thread-select}
27526if the selected thread in @value{GDBN} is supposed to be identical to the
27527thread the frontend wants to operate on. However, getting this
27528optimization right can be tricky. In particular, if the frontend
27529sends several commands to @value{GDBN}, and one of the commands changes the
27530selected thread, then the behaviour of subsequent commands will
27531change. So, a frontend should either wait for response from such
27532problematic commands, or explicitly add @code{-thread-select} for
27533all subsequent commands. No frontend is known to do this exactly
27534right, so it is suggested to just always pass the @samp{--thread} and
27535@samp{--frame} options.
27536
508094de 27537@node Asynchronous and non-stop modes
c3b108f7
VP
27538@subsection Asynchronous command execution and non-stop mode
27539
27540On some targets, @value{GDBN} is capable of processing MI commands
27541even while the target is running. This is called @dfn{asynchronous
27542command execution} (@pxref{Background Execution}). The frontend may
27543specify a preferrence for asynchronous execution using the
27544@code{-gdb-set target-async 1} command, which should be emitted before
27545either running the executable or attaching to the target. After the
27546frontend has started the executable or attached to the target, it can
27547find if asynchronous execution is enabled using the
27548@code{-list-target-features} command.
27549
27550Even if @value{GDBN} can accept a command while target is running,
27551many commands that access the target do not work when the target is
27552running. Therefore, asynchronous command execution is most useful
27553when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
27554it is possible to examine the state of one thread, while other threads
27555are running.
27556
27557When a given thread is running, MI commands that try to access the
27558target in the context of that thread may not work, or may work only on
27559some targets. In particular, commands that try to operate on thread's
27560stack will not work, on any target. Commands that read memory, or
27561modify breakpoints, may work or not work, depending on the target. Note
27562that even commands that operate on global state, such as @code{print},
27563@code{set}, and breakpoint commands, still access the target in the
27564context of a specific thread, so frontend should try to find a
27565stopped thread and perform the operation on that thread (using the
27566@samp{--thread} option).
27567
27568Which commands will work in the context of a running thread is
27569highly target dependent. However, the two commands
27570@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
27571to find the state of a thread, will always work.
27572
508094de 27573@node Thread groups
c3b108f7
VP
27574@subsection Thread groups
27575@value{GDBN} may be used to debug several processes at the same time.
27576On some platfroms, @value{GDBN} may support debugging of several
27577hardware systems, each one having several cores with several different
27578processes running on each core. This section describes the MI
27579mechanism to support such debugging scenarios.
27580
27581The key observation is that regardless of the structure of the
27582target, MI can have a global list of threads, because most commands that
27583accept the @samp{--thread} option do not need to know what process that
27584thread belongs to. Therefore, it is not necessary to introduce
27585neither additional @samp{--process} option, nor an notion of the
27586current process in the MI interface. The only strictly new feature
27587that is required is the ability to find how the threads are grouped
27588into processes.
27589
27590To allow the user to discover such grouping, and to support arbitrary
27591hierarchy of machines/cores/processes, MI introduces the concept of a
27592@dfn{thread group}. Thread group is a collection of threads and other
27593thread groups. A thread group always has a string identifier, a type,
27594and may have additional attributes specific to the type. A new
27595command, @code{-list-thread-groups}, returns the list of top-level
27596thread groups, which correspond to processes that @value{GDBN} is
27597debugging at the moment. By passing an identifier of a thread group
27598to the @code{-list-thread-groups} command, it is possible to obtain
27599the members of specific thread group.
27600
27601To allow the user to easily discover processes, and other objects, he
27602wishes to debug, a concept of @dfn{available thread group} is
27603introduced. Available thread group is an thread group that
27604@value{GDBN} is not debugging, but that can be attached to, using the
27605@code{-target-attach} command. The list of available top-level thread
27606groups can be obtained using @samp{-list-thread-groups --available}.
27607In general, the content of a thread group may be only retrieved only
27608after attaching to that thread group.
27609
a79b8f6e
VP
27610Thread groups are related to inferiors (@pxref{Inferiors and
27611Programs}). Each inferior corresponds to a thread group of a special
27612type @samp{process}, and some additional operations are permitted on
27613such thread groups.
27614
922fbb7b
AC
27615@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27616@node GDB/MI Command Syntax
27617@section @sc{gdb/mi} Command Syntax
27618
27619@menu
27620* GDB/MI Input Syntax::
27621* GDB/MI Output Syntax::
922fbb7b
AC
27622@end menu
27623
27624@node GDB/MI Input Syntax
27625@subsection @sc{gdb/mi} Input Syntax
27626
27627@cindex input syntax for @sc{gdb/mi}
27628@cindex @sc{gdb/mi}, input syntax
27629@table @code
27630@item @var{command} @expansion{}
27631@code{@var{cli-command} | @var{mi-command}}
27632
27633@item @var{cli-command} @expansion{}
27634@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
27635@var{cli-command} is any existing @value{GDBN} CLI command.
27636
27637@item @var{mi-command} @expansion{}
27638@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
27639@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
27640
27641@item @var{token} @expansion{}
27642"any sequence of digits"
27643
27644@item @var{option} @expansion{}
27645@code{"-" @var{parameter} [ " " @var{parameter} ]}
27646
27647@item @var{parameter} @expansion{}
27648@code{@var{non-blank-sequence} | @var{c-string}}
27649
27650@item @var{operation} @expansion{}
27651@emph{any of the operations described in this chapter}
27652
27653@item @var{non-blank-sequence} @expansion{}
27654@emph{anything, provided it doesn't contain special characters such as
27655"-", @var{nl}, """ and of course " "}
27656
27657@item @var{c-string} @expansion{}
27658@code{""" @var{seven-bit-iso-c-string-content} """}
27659
27660@item @var{nl} @expansion{}
27661@code{CR | CR-LF}
27662@end table
27663
27664@noindent
27665Notes:
27666
27667@itemize @bullet
27668@item
27669The CLI commands are still handled by the @sc{mi} interpreter; their
27670output is described below.
27671
27672@item
27673The @code{@var{token}}, when present, is passed back when the command
27674finishes.
27675
27676@item
27677Some @sc{mi} commands accept optional arguments as part of the parameter
27678list. Each option is identified by a leading @samp{-} (dash) and may be
27679followed by an optional argument parameter. Options occur first in the
27680parameter list and can be delimited from normal parameters using
27681@samp{--} (this is useful when some parameters begin with a dash).
27682@end itemize
27683
27684Pragmatics:
27685
27686@itemize @bullet
27687@item
27688We want easy access to the existing CLI syntax (for debugging).
27689
27690@item
27691We want it to be easy to spot a @sc{mi} operation.
27692@end itemize
27693
27694@node GDB/MI Output Syntax
27695@subsection @sc{gdb/mi} Output Syntax
27696
27697@cindex output syntax of @sc{gdb/mi}
27698@cindex @sc{gdb/mi}, output syntax
27699The output from @sc{gdb/mi} consists of zero or more out-of-band records
27700followed, optionally, by a single result record. This result record
27701is for the most recent command. The sequence of output records is
594fe323 27702terminated by @samp{(gdb)}.
922fbb7b
AC
27703
27704If an input command was prefixed with a @code{@var{token}} then the
27705corresponding output for that command will also be prefixed by that same
27706@var{token}.
27707
27708@table @code
27709@item @var{output} @expansion{}
594fe323 27710@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
27711
27712@item @var{result-record} @expansion{}
27713@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
27714
27715@item @var{out-of-band-record} @expansion{}
27716@code{@var{async-record} | @var{stream-record}}
27717
27718@item @var{async-record} @expansion{}
27719@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
27720
27721@item @var{exec-async-output} @expansion{}
27722@code{[ @var{token} ] "*" @var{async-output}}
27723
27724@item @var{status-async-output} @expansion{}
27725@code{[ @var{token} ] "+" @var{async-output}}
27726
27727@item @var{notify-async-output} @expansion{}
27728@code{[ @var{token} ] "=" @var{async-output}}
27729
27730@item @var{async-output} @expansion{}
27731@code{@var{async-class} ( "," @var{result} )* @var{nl}}
27732
27733@item @var{result-class} @expansion{}
27734@code{"done" | "running" | "connected" | "error" | "exit"}
27735
27736@item @var{async-class} @expansion{}
27737@code{"stopped" | @var{others}} (where @var{others} will be added
27738depending on the needs---this is still in development).
27739
27740@item @var{result} @expansion{}
27741@code{ @var{variable} "=" @var{value}}
27742
27743@item @var{variable} @expansion{}
27744@code{ @var{string} }
27745
27746@item @var{value} @expansion{}
27747@code{ @var{const} | @var{tuple} | @var{list} }
27748
27749@item @var{const} @expansion{}
27750@code{@var{c-string}}
27751
27752@item @var{tuple} @expansion{}
27753@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
27754
27755@item @var{list} @expansion{}
27756@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
27757@var{result} ( "," @var{result} )* "]" }
27758
27759@item @var{stream-record} @expansion{}
27760@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
27761
27762@item @var{console-stream-output} @expansion{}
27763@code{"~" @var{c-string}}
27764
27765@item @var{target-stream-output} @expansion{}
27766@code{"@@" @var{c-string}}
27767
27768@item @var{log-stream-output} @expansion{}
27769@code{"&" @var{c-string}}
27770
27771@item @var{nl} @expansion{}
27772@code{CR | CR-LF}
27773
27774@item @var{token} @expansion{}
27775@emph{any sequence of digits}.
27776@end table
27777
27778@noindent
27779Notes:
27780
27781@itemize @bullet
27782@item
27783All output sequences end in a single line containing a period.
27784
27785@item
721c02de
VP
27786The @code{@var{token}} is from the corresponding request. Note that
27787for all async output, while the token is allowed by the grammar and
27788may be output by future versions of @value{GDBN} for select async
27789output messages, it is generally omitted. Frontends should treat
27790all async output as reporting general changes in the state of the
27791target and there should be no need to associate async output to any
27792prior command.
922fbb7b
AC
27793
27794@item
27795@cindex status output in @sc{gdb/mi}
27796@var{status-async-output} contains on-going status information about the
27797progress of a slow operation. It can be discarded. All status output is
27798prefixed by @samp{+}.
27799
27800@item
27801@cindex async output in @sc{gdb/mi}
27802@var{exec-async-output} contains asynchronous state change on the target
27803(stopped, started, disappeared). All async output is prefixed by
27804@samp{*}.
27805
27806@item
27807@cindex notify output in @sc{gdb/mi}
27808@var{notify-async-output} contains supplementary information that the
27809client should handle (e.g., a new breakpoint information). All notify
27810output is prefixed by @samp{=}.
27811
27812@item
27813@cindex console output in @sc{gdb/mi}
27814@var{console-stream-output} is output that should be displayed as is in the
27815console. It is the textual response to a CLI command. All the console
27816output is prefixed by @samp{~}.
27817
27818@item
27819@cindex target output in @sc{gdb/mi}
27820@var{target-stream-output} is the output produced by the target program.
27821All the target output is prefixed by @samp{@@}.
27822
27823@item
27824@cindex log output in @sc{gdb/mi}
27825@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
27826instance messages that should be displayed as part of an error log. All
27827the log output is prefixed by @samp{&}.
27828
27829@item
27830@cindex list output in @sc{gdb/mi}
27831New @sc{gdb/mi} commands should only output @var{lists} containing
27832@var{values}.
27833
27834
27835@end itemize
27836
27837@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
27838details about the various output records.
27839
922fbb7b
AC
27840@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27841@node GDB/MI Compatibility with CLI
27842@section @sc{gdb/mi} Compatibility with CLI
27843
27844@cindex compatibility, @sc{gdb/mi} and CLI
27845@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 27846
a2c02241
NR
27847For the developers convenience CLI commands can be entered directly,
27848but there may be some unexpected behaviour. For example, commands
27849that query the user will behave as if the user replied yes, breakpoint
27850command lists are not executed and some CLI commands, such as
27851@code{if}, @code{when} and @code{define}, prompt for further input with
27852@samp{>}, which is not valid MI output.
ef21caaf
NR
27853
27854This feature may be removed at some stage in the future and it is
a2c02241
NR
27855recommended that front ends use the @code{-interpreter-exec} command
27856(@pxref{-interpreter-exec}).
922fbb7b 27857
af6eff6f
NR
27858@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27859@node GDB/MI Development and Front Ends
27860@section @sc{gdb/mi} Development and Front Ends
27861@cindex @sc{gdb/mi} development
27862
27863The application which takes the MI output and presents the state of the
27864program being debugged to the user is called a @dfn{front end}.
27865
27866Although @sc{gdb/mi} is still incomplete, it is currently being used
27867by a variety of front ends to @value{GDBN}. This makes it difficult
27868to introduce new functionality without breaking existing usage. This
27869section tries to minimize the problems by describing how the protocol
27870might change.
27871
27872Some changes in MI need not break a carefully designed front end, and
27873for these the MI version will remain unchanged. The following is a
27874list of changes that may occur within one level, so front ends should
27875parse MI output in a way that can handle them:
27876
27877@itemize @bullet
27878@item
27879New MI commands may be added.
27880
27881@item
27882New fields may be added to the output of any MI command.
27883
36ece8b3
NR
27884@item
27885The range of values for fields with specified values, e.g.,
9f708cb2 27886@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 27887
af6eff6f
NR
27888@c The format of field's content e.g type prefix, may change so parse it
27889@c at your own risk. Yes, in general?
27890
27891@c The order of fields may change? Shouldn't really matter but it might
27892@c resolve inconsistencies.
27893@end itemize
27894
27895If the changes are likely to break front ends, the MI version level
27896will be increased by one. This will allow the front end to parse the
27897output according to the MI version. Apart from mi0, new versions of
27898@value{GDBN} will not support old versions of MI and it will be the
27899responsibility of the front end to work with the new one.
27900
27901@c Starting with mi3, add a new command -mi-version that prints the MI
27902@c version?
27903
27904The best way to avoid unexpected changes in MI that might break your front
27905end is to make your project known to @value{GDBN} developers and
7a9a6b69 27906follow development on @email{gdb@@sourceware.org} and
fa0f268d 27907@email{gdb-patches@@sourceware.org}.
af6eff6f
NR
27908@cindex mailing lists
27909
922fbb7b
AC
27910@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27911@node GDB/MI Output Records
27912@section @sc{gdb/mi} Output Records
27913
27914@menu
27915* GDB/MI Result Records::
27916* GDB/MI Stream Records::
82f68b1c 27917* GDB/MI Async Records::
54516a0b 27918* GDB/MI Breakpoint Information::
c3b108f7 27919* GDB/MI Frame Information::
dc146f7c 27920* GDB/MI Thread Information::
4368ebeb 27921* GDB/MI Ada Exception Information::
922fbb7b
AC
27922@end menu
27923
27924@node GDB/MI Result Records
27925@subsection @sc{gdb/mi} Result Records
27926
27927@cindex result records in @sc{gdb/mi}
27928@cindex @sc{gdb/mi}, result records
27929In addition to a number of out-of-band notifications, the response to a
27930@sc{gdb/mi} command includes one of the following result indications:
27931
27932@table @code
27933@findex ^done
27934@item "^done" [ "," @var{results} ]
27935The synchronous operation was successful, @code{@var{results}} are the return
27936values.
27937
27938@item "^running"
27939@findex ^running
8e9c5e02
VP
27940This result record is equivalent to @samp{^done}. Historically, it
27941was output instead of @samp{^done} if the command has resumed the
27942target. This behaviour is maintained for backward compatibility, but
27943all frontends should treat @samp{^done} and @samp{^running}
27944identically and rely on the @samp{*running} output record to determine
27945which threads are resumed.
922fbb7b 27946
ef21caaf
NR
27947@item "^connected"
27948@findex ^connected
3f94c067 27949@value{GDBN} has connected to a remote target.
ef21caaf 27950
922fbb7b
AC
27951@item "^error" "," @var{c-string}
27952@findex ^error
27953The operation failed. The @code{@var{c-string}} contains the corresponding
27954error message.
ef21caaf
NR
27955
27956@item "^exit"
27957@findex ^exit
3f94c067 27958@value{GDBN} has terminated.
ef21caaf 27959
922fbb7b
AC
27960@end table
27961
27962@node GDB/MI Stream Records
27963@subsection @sc{gdb/mi} Stream Records
27964
27965@cindex @sc{gdb/mi}, stream records
27966@cindex stream records in @sc{gdb/mi}
27967@value{GDBN} internally maintains a number of output streams: the console, the
27968target, and the log. The output intended for each of these streams is
27969funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
27970
27971Each stream record begins with a unique @dfn{prefix character} which
27972identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
27973Syntax}). In addition to the prefix, each stream record contains a
27974@code{@var{string-output}}. This is either raw text (with an implicit new
27975line) or a quoted C string (which does not contain an implicit newline).
27976
27977@table @code
27978@item "~" @var{string-output}
27979The console output stream contains text that should be displayed in the
27980CLI console window. It contains the textual responses to CLI commands.
27981
27982@item "@@" @var{string-output}
27983The target output stream contains any textual output from the running
ef21caaf
NR
27984target. This is only present when GDB's event loop is truly
27985asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
27986
27987@item "&" @var{string-output}
27988The log stream contains debugging messages being produced by @value{GDBN}'s
27989internals.
27990@end table
27991
82f68b1c
VP
27992@node GDB/MI Async Records
27993@subsection @sc{gdb/mi} Async Records
922fbb7b 27994
82f68b1c
VP
27995@cindex async records in @sc{gdb/mi}
27996@cindex @sc{gdb/mi}, async records
27997@dfn{Async} records are used to notify the @sc{gdb/mi} client of
922fbb7b 27998additional changes that have occurred. Those changes can either be a
82f68b1c 27999consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
922fbb7b
AC
28000target activity (e.g., target stopped).
28001
8eb41542 28002The following is the list of possible async records:
922fbb7b
AC
28003
28004@table @code
034dad6f 28005
e1ac3328
VP
28006@item *running,thread-id="@var{thread}"
28007The target is now running. The @var{thread} field tells which
28008specific thread is now running, and can be @samp{all} if all threads
28009are running. The frontend should assume that no interaction with a
28010running thread is possible after this notification is produced.
28011The frontend should not assume that this notification is output
28012only once for any command. @value{GDBN} may emit this notification
28013several times, either for different threads, because it cannot resume
28014all threads together, or even for a single thread, if the thread must
28015be stepped though some code before letting it run freely.
28016
dc146f7c 28017@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
82f68b1c
VP
28018The target has stopped. The @var{reason} field can have one of the
28019following values:
034dad6f
BR
28020
28021@table @code
28022@item breakpoint-hit
28023A breakpoint was reached.
28024@item watchpoint-trigger
28025A watchpoint was triggered.
28026@item read-watchpoint-trigger
28027A read watchpoint was triggered.
28028@item access-watchpoint-trigger
28029An access watchpoint was triggered.
28030@item function-finished
28031An -exec-finish or similar CLI command was accomplished.
28032@item location-reached
28033An -exec-until or similar CLI command was accomplished.
28034@item watchpoint-scope
28035A watchpoint has gone out of scope.
28036@item end-stepping-range
28037An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
28038similar CLI command was accomplished.
28039@item exited-signalled
28040The inferior exited because of a signal.
28041@item exited
28042The inferior exited.
28043@item exited-normally
28044The inferior exited normally.
28045@item signal-received
28046A signal was received by the inferior.
36dfb11c
TT
28047@item solib-event
28048The inferior has stopped due to a library being loaded or unloaded.
edcc5120
TT
28049This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
28050set or when a @code{catch load} or @code{catch unload} catchpoint is
28051in use (@pxref{Set Catchpoints}).
36dfb11c
TT
28052@item fork
28053The inferior has forked. This is reported when @code{catch fork}
28054(@pxref{Set Catchpoints}) has been used.
28055@item vfork
28056The inferior has vforked. This is reported in when @code{catch vfork}
28057(@pxref{Set Catchpoints}) has been used.
28058@item syscall-entry
28059The inferior entered a system call. This is reported when @code{catch
28060syscall} (@pxref{Set Catchpoints}) has been used.
28061@item syscall-entry
28062The inferior returned from a system call. This is reported when
28063@code{catch syscall} (@pxref{Set Catchpoints}) has been used.
28064@item exec
28065The inferior called @code{exec}. This is reported when @code{catch exec}
28066(@pxref{Set Catchpoints}) has been used.
922fbb7b
AC
28067@end table
28068
c3b108f7
VP
28069The @var{id} field identifies the thread that directly caused the stop
28070-- for example by hitting a breakpoint. Depending on whether all-stop
28071mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
28072stop all threads, or only the thread that directly triggered the stop.
28073If all threads are stopped, the @var{stopped} field will have the
28074value of @code{"all"}. Otherwise, the value of the @var{stopped}
28075field will be a list of thread identifiers. Presently, this list will
28076always include a single thread, but frontend should be prepared to see
dc146f7c
VP
28077several threads in the list. The @var{core} field reports the
28078processor core on which the stop event has happened. This field may be absent
28079if such information is not available.
c3b108f7 28080
a79b8f6e
VP
28081@item =thread-group-added,id="@var{id}"
28082@itemx =thread-group-removed,id="@var{id}"
28083A thread group was either added or removed. The @var{id} field
28084contains the @value{GDBN} identifier of the thread group. When a thread
28085group is added, it generally might not be associated with a running
28086process. When a thread group is removed, its id becomes invalid and
28087cannot be used in any way.
28088
28089@item =thread-group-started,id="@var{id}",pid="@var{pid}"
28090A thread group became associated with a running program,
28091either because the program was just started or the thread group
28092was attached to a program. The @var{id} field contains the
28093@value{GDBN} identifier of the thread group. The @var{pid} field
28094contains process identifier, specific to the operating system.
28095
8cf64490 28096@item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
a79b8f6e
VP
28097A thread group is no longer associated with a running program,
28098either because the program has exited, or because it was detached
c3b108f7 28099from. The @var{id} field contains the @value{GDBN} identifier of the
8cf64490
TT
28100thread group. @var{code} is the exit code of the inferior; it exists
28101only when the inferior exited with some code.
c3b108f7
VP
28102
28103@item =thread-created,id="@var{id}",group-id="@var{gid}"
28104@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
82f68b1c 28105A thread either was created, or has exited. The @var{id} field
c3b108f7
VP
28106contains the @value{GDBN} identifier of the thread. The @var{gid}
28107field identifies the thread group this thread belongs to.
66bb093b
VP
28108
28109@item =thread-selected,id="@var{id}"
28110Informs that the selected thread was changed as result of the last
28111command. This notification is not emitted as result of @code{-thread-select}
28112command but is emitted whenever an MI command that is not documented
28113to change the selected thread actually changes it. In particular,
28114invoking, directly or indirectly (via user-defined command), the CLI
28115@code{thread} command, will generate this notification.
28116
28117We suggest that in response to this notification, front ends
28118highlight the selected thread and cause subsequent commands to apply to
28119that thread.
28120
c86cf029
VP
28121@item =library-loaded,...
28122Reports that a new library file was loaded by the program. This
28123notification has 4 fields---@var{id}, @var{target-name},
134eb42c 28124@var{host-name}, and @var{symbols-loaded}. The @var{id} field is an
c86cf029
VP
28125opaque identifier of the library. For remote debugging case,
28126@var{target-name} and @var{host-name} fields give the name of the
134eb42c
VP
28127library file on the target, and on the host respectively. For native
28128debugging, both those fields have the same value. The
f1cbe1d3
TT
28129@var{symbols-loaded} field is emitted only for backward compatibility
28130and should not be relied on to convey any useful information. The
28131@var{thread-group} field, if present, specifies the id of the thread
28132group in whose context the library was loaded. If the field is
28133absent, it means the library was loaded in the context of all present
28134thread groups.
c86cf029
VP
28135
28136@item =library-unloaded,...
134eb42c 28137Reports that a library was unloaded by the program. This notification
c86cf029 28138has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
a79b8f6e
VP
28139the same meaning as for the @code{=library-loaded} notification.
28140The @var{thread-group} field, if present, specifies the id of the
28141thread group in whose context the library was unloaded. If the field is
28142absent, it means the library was unloaded in the context of all present
28143thread groups.
c86cf029 28144
201b4506
YQ
28145@item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
28146@itemx =traceframe-changed,end
28147Reports that the trace frame was changed and its new number is
28148@var{tfnum}. The number of the tracepoint associated with this trace
28149frame is @var{tpnum}.
28150
134a2066 28151@item =tsv-created,name=@var{name},initial=@var{initial}
bb25a15c 28152Reports that the new trace state variable @var{name} is created with
134a2066 28153initial value @var{initial}.
bb25a15c
YQ
28154
28155@item =tsv-deleted,name=@var{name}
28156@itemx =tsv-deleted
28157Reports that the trace state variable @var{name} is deleted or all
28158trace state variables are deleted.
28159
134a2066
YQ
28160@item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
28161Reports that the trace state variable @var{name} is modified with
28162the initial value @var{initial}. The current value @var{current} of
28163trace state variable is optional and is reported if the current
28164value of trace state variable is known.
28165
8d3788bd
VP
28166@item =breakpoint-created,bkpt=@{...@}
28167@itemx =breakpoint-modified,bkpt=@{...@}
d9f08f52 28168@itemx =breakpoint-deleted,id=@var{number}
8d3788bd
VP
28169Reports that a breakpoint was created, modified, or deleted,
28170respectively. Only user-visible breakpoints are reported to the MI
28171user.
28172
28173The @var{bkpt} argument is of the same form as returned by the various
d9f08f52
YQ
28174breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
28175@var{number} is the ordinal number of the breakpoint.
8d3788bd
VP
28176
28177Note that if a breakpoint is emitted in the result record of a
28178command, then it will not also be emitted in an async record.
28179
82a90ccf
YQ
28180@item =record-started,thread-group="@var{id}"
28181@itemx =record-stopped,thread-group="@var{id}"
28182Execution log recording was either started or stopped on an
28183inferior. The @var{id} is the @value{GDBN} identifier of the thread
28184group corresponding to the affected inferior.
28185
5b9afe8a
YQ
28186@item =cmd-param-changed,param=@var{param},value=@var{value}
28187Reports that a parameter of the command @code{set @var{param}} is
28188changed to @var{value}. In the multi-word @code{set} command,
28189the @var{param} is the whole parameter list to @code{set} command.
28190For example, In command @code{set check type on}, @var{param}
28191is @code{check type} and @var{value} is @code{on}.
8de0566d
YQ
28192
28193@item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
28194Reports that bytes from @var{addr} to @var{data} + @var{len} were
28195written in an inferior. The @var{id} is the identifier of the
28196thread group corresponding to the affected inferior. The optional
28197@code{type="code"} part is reported if the memory written to holds
28198executable code.
82f68b1c
VP
28199@end table
28200
54516a0b
TT
28201@node GDB/MI Breakpoint Information
28202@subsection @sc{gdb/mi} Breakpoint Information
28203
28204When @value{GDBN} reports information about a breakpoint, a
28205tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
28206following fields:
28207
28208@table @code
28209@item number
28210The breakpoint number. For a breakpoint that represents one location
28211of a multi-location breakpoint, this will be a dotted pair, like
28212@samp{1.2}.
28213
28214@item type
28215The type of the breakpoint. For ordinary breakpoints this will be
28216@samp{breakpoint}, but many values are possible.
28217
8ac3646f
TT
28218@item catch-type
28219If the type of the breakpoint is @samp{catchpoint}, then this
28220indicates the exact type of catchpoint.
28221
54516a0b
TT
28222@item disp
28223This is the breakpoint disposition---either @samp{del}, meaning that
28224the breakpoint will be deleted at the next stop, or @samp{keep},
28225meaning that the breakpoint will not be deleted.
28226
28227@item enabled
28228This indicates whether the breakpoint is enabled, in which case the
28229value is @samp{y}, or disabled, in which case the value is @samp{n}.
28230Note that this is not the same as the field @code{enable}.
28231
28232@item addr
28233The address of the breakpoint. This may be a hexidecimal number,
28234giving the address; or the string @samp{<PENDING>}, for a pending
28235breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
28236multiple locations. This field will not be present if no address can
28237be determined. For example, a watchpoint does not have an address.
28238
28239@item func
28240If known, the function in which the breakpoint appears.
28241If not known, this field is not present.
28242
28243@item filename
28244The name of the source file which contains this function, if known.
28245If not known, this field is not present.
28246
28247@item fullname
28248The full file name of the source file which contains this function, if
28249known. If not known, this field is not present.
28250
28251@item line
28252The line number at which this breakpoint appears, if known.
28253If not known, this field is not present.
28254
28255@item at
28256If the source file is not known, this field may be provided. If
28257provided, this holds the address of the breakpoint, possibly followed
28258by a symbol name.
28259
28260@item pending
28261If this breakpoint is pending, this field is present and holds the
28262text used to set the breakpoint, as entered by the user.
28263
28264@item evaluated-by
28265Where this breakpoint's condition is evaluated, either @samp{host} or
28266@samp{target}.
28267
28268@item thread
28269If this is a thread-specific breakpoint, then this identifies the
28270thread in which the breakpoint can trigger.
28271
28272@item task
28273If this breakpoint is restricted to a particular Ada task, then this
28274field will hold the task identifier.
28275
28276@item cond
28277If the breakpoint is conditional, this is the condition expression.
28278
28279@item ignore
28280The ignore count of the breakpoint.
28281
28282@item enable
28283The enable count of the breakpoint.
28284
28285@item traceframe-usage
28286FIXME.
28287
28288@item static-tracepoint-marker-string-id
28289For a static tracepoint, the name of the static tracepoint marker.
28290
28291@item mask
28292For a masked watchpoint, this is the mask.
28293
28294@item pass
28295A tracepoint's pass count.
28296
28297@item original-location
28298The location of the breakpoint as originally specified by the user.
28299This field is optional.
28300
28301@item times
28302The number of times the breakpoint has been hit.
28303
28304@item installed
28305This field is only given for tracepoints. This is either @samp{y},
28306meaning that the tracepoint is installed, or @samp{n}, meaning that it
28307is not.
28308
28309@item what
28310Some extra data, the exact contents of which are type-dependent.
28311
28312@end table
28313
28314For example, here is what the output of @code{-break-insert}
28315(@pxref{GDB/MI Breakpoint Commands}) might be:
28316
28317@smallexample
28318-> -break-insert main
28319<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28320 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
28321 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
28322 times="0"@}
54516a0b
TT
28323<- (gdb)
28324@end smallexample
28325
c3b108f7
VP
28326@node GDB/MI Frame Information
28327@subsection @sc{gdb/mi} Frame Information
28328
28329Response from many MI commands includes an information about stack
28330frame. This information is a tuple that may have the following
28331fields:
28332
28333@table @code
28334@item level
28335The level of the stack frame. The innermost frame has the level of
28336zero. This field is always present.
28337
28338@item func
28339The name of the function corresponding to the frame. This field may
28340be absent if @value{GDBN} is unable to determine the function name.
28341
28342@item addr
28343The code address for the frame. This field is always present.
28344
28345@item file
28346The name of the source files that correspond to the frame's code
28347address. This field may be absent.
28348
28349@item line
28350The source line corresponding to the frames' code address. This field
28351may be absent.
28352
28353@item from
28354The name of the binary file (either executable or shared library) the
28355corresponds to the frame's code address. This field may be absent.
28356
28357@end table
82f68b1c 28358
dc146f7c
VP
28359@node GDB/MI Thread Information
28360@subsection @sc{gdb/mi} Thread Information
28361
28362Whenever @value{GDBN} has to report an information about a thread, it
28363uses a tuple with the following fields:
28364
28365@table @code
28366@item id
28367The numeric id assigned to the thread by @value{GDBN}. This field is
28368always present.
28369
28370@item target-id
28371Target-specific string identifying the thread. This field is always present.
28372
28373@item details
28374Additional information about the thread provided by the target.
28375It is supposed to be human-readable and not interpreted by the
28376frontend. This field is optional.
28377
28378@item state
28379Either @samp{stopped} or @samp{running}, depending on whether the
28380thread is presently running. This field is always present.
28381
28382@item core
28383The value of this field is an integer number of the processor core the
28384thread was last seen on. This field is optional.
28385@end table
28386
956a9fb9
JB
28387@node GDB/MI Ada Exception Information
28388@subsection @sc{gdb/mi} Ada Exception Information
28389
28390Whenever a @code{*stopped} record is emitted because the program
28391stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
28392@value{GDBN} provides the name of the exception that was raised via
28393the @code{exception-name} field.
922fbb7b 28394
ef21caaf
NR
28395@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28396@node GDB/MI Simple Examples
28397@section Simple Examples of @sc{gdb/mi} Interaction
28398@cindex @sc{gdb/mi}, simple examples
28399
28400This subsection presents several simple examples of interaction using
28401the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
28402following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
28403the output received from @sc{gdb/mi}.
28404
d3e8051b 28405Note the line breaks shown in the examples are here only for
ef21caaf
NR
28406readability, they don't appear in the real output.
28407
79a6e687 28408@subheading Setting a Breakpoint
ef21caaf
NR
28409
28410Setting a breakpoint generates synchronous output which contains detailed
28411information of the breakpoint.
28412
28413@smallexample
28414-> -break-insert main
28415<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28416 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
28417 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
28418 times="0"@}
ef21caaf
NR
28419<- (gdb)
28420@end smallexample
28421
28422@subheading Program Execution
28423
28424Program execution generates asynchronous records and MI gives the
28425reason that execution stopped.
28426
28427@smallexample
28428-> -exec-run
28429<- ^running
28430<- (gdb)
a47ec5fe 28431<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
ef21caaf
NR
28432 frame=@{addr="0x08048564",func="main",
28433 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
28434 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
28435<- (gdb)
28436-> -exec-continue
28437<- ^running
28438<- (gdb)
28439<- *stopped,reason="exited-normally"
28440<- (gdb)
28441@end smallexample
28442
3f94c067 28443@subheading Quitting @value{GDBN}
ef21caaf 28444
3f94c067 28445Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
28446
28447@smallexample
28448-> (gdb)
28449<- -gdb-exit
28450<- ^exit
28451@end smallexample
28452
a6b29f87
VP
28453Please note that @samp{^exit} is printed immediately, but it might
28454take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
28455performs necessary cleanups, including killing programs being debugged
28456or disconnecting from debug hardware, so the frontend should wait till
28457@value{GDBN} exits and should only forcibly kill @value{GDBN} if it
28458fails to exit in reasonable time.
28459
a2c02241 28460@subheading A Bad Command
ef21caaf
NR
28461
28462Here's what happens if you pass a non-existent command:
28463
28464@smallexample
28465-> -rubbish
28466<- ^error,msg="Undefined MI command: rubbish"
594fe323 28467<- (gdb)
ef21caaf
NR
28468@end smallexample
28469
28470
922fbb7b
AC
28471@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28472@node GDB/MI Command Description Format
28473@section @sc{gdb/mi} Command Description Format
28474
28475The remaining sections describe blocks of commands. Each block of
28476commands is laid out in a fashion similar to this section.
28477
922fbb7b
AC
28478@subheading Motivation
28479
28480The motivation for this collection of commands.
28481
28482@subheading Introduction
28483
28484A brief introduction to this collection of commands as a whole.
28485
28486@subheading Commands
28487
28488For each command in the block, the following is described:
28489
28490@subsubheading Synopsis
28491
28492@smallexample
28493 -command @var{args}@dots{}
28494@end smallexample
28495
922fbb7b
AC
28496@subsubheading Result
28497
265eeb58 28498@subsubheading @value{GDBN} Command
922fbb7b 28499
265eeb58 28500The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
28501
28502@subsubheading Example
28503
ef21caaf
NR
28504Example(s) formatted for readability. Some of the described commands have
28505not been implemented yet and these are labeled N.A.@: (not available).
28506
28507
922fbb7b 28508@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
28509@node GDB/MI Breakpoint Commands
28510@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
28511
28512@cindex breakpoint commands for @sc{gdb/mi}
28513@cindex @sc{gdb/mi}, breakpoint commands
28514This section documents @sc{gdb/mi} commands for manipulating
28515breakpoints.
28516
28517@subheading The @code{-break-after} Command
28518@findex -break-after
28519
28520@subsubheading Synopsis
28521
28522@smallexample
28523 -break-after @var{number} @var{count}
28524@end smallexample
28525
28526The breakpoint number @var{number} is not in effect until it has been
28527hit @var{count} times. To see how this is reflected in the output of
28528the @samp{-break-list} command, see the description of the
28529@samp{-break-list} command below.
28530
28531@subsubheading @value{GDBN} Command
28532
28533The corresponding @value{GDBN} command is @samp{ignore}.
28534
28535@subsubheading Example
28536
28537@smallexample
594fe323 28538(gdb)
922fbb7b 28539-break-insert main
a47ec5fe
AR
28540^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28541enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
28542fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
28543times="0"@}
594fe323 28544(gdb)
922fbb7b
AC
28545-break-after 1 3
28546~
28547^done
594fe323 28548(gdb)
922fbb7b
AC
28549-break-list
28550^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28551hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28552@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28553@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28554@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28555@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28556@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28557body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 28558addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 28559line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 28560(gdb)
922fbb7b
AC
28561@end smallexample
28562
28563@ignore
28564@subheading The @code{-break-catch} Command
28565@findex -break-catch
48cb2d85 28566@end ignore
922fbb7b
AC
28567
28568@subheading The @code{-break-commands} Command
28569@findex -break-commands
922fbb7b 28570
48cb2d85
VP
28571@subsubheading Synopsis
28572
28573@smallexample
28574 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
28575@end smallexample
28576
28577Specifies the CLI commands that should be executed when breakpoint
28578@var{number} is hit. The parameters @var{command1} to @var{commandN}
28579are the commands. If no command is specified, any previously-set
28580commands are cleared. @xref{Break Commands}. Typical use of this
28581functionality is tracing a program, that is, printing of values of
28582some variables whenever breakpoint is hit and then continuing.
28583
28584@subsubheading @value{GDBN} Command
28585
28586The corresponding @value{GDBN} command is @samp{commands}.
28587
28588@subsubheading Example
28589
28590@smallexample
28591(gdb)
28592-break-insert main
28593^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28594enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
28595fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
28596times="0"@}
48cb2d85
VP
28597(gdb)
28598-break-commands 1 "print v" "continue"
28599^done
28600(gdb)
28601@end smallexample
922fbb7b
AC
28602
28603@subheading The @code{-break-condition} Command
28604@findex -break-condition
28605
28606@subsubheading Synopsis
28607
28608@smallexample
28609 -break-condition @var{number} @var{expr}
28610@end smallexample
28611
28612Breakpoint @var{number} will stop the program only if the condition in
28613@var{expr} is true. The condition becomes part of the
28614@samp{-break-list} output (see the description of the @samp{-break-list}
28615command below).
28616
28617@subsubheading @value{GDBN} Command
28618
28619The corresponding @value{GDBN} command is @samp{condition}.
28620
28621@subsubheading Example
28622
28623@smallexample
594fe323 28624(gdb)
922fbb7b
AC
28625-break-condition 1 1
28626^done
594fe323 28627(gdb)
922fbb7b
AC
28628-break-list
28629^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28630hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28631@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28632@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28633@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28634@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28635@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28636body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 28637addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 28638line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 28639(gdb)
922fbb7b
AC
28640@end smallexample
28641
28642@subheading The @code{-break-delete} Command
28643@findex -break-delete
28644
28645@subsubheading Synopsis
28646
28647@smallexample
28648 -break-delete ( @var{breakpoint} )+
28649@end smallexample
28650
28651Delete the breakpoint(s) whose number(s) are specified in the argument
28652list. This is obviously reflected in the breakpoint list.
28653
79a6e687 28654@subsubheading @value{GDBN} Command
922fbb7b
AC
28655
28656The corresponding @value{GDBN} command is @samp{delete}.
28657
28658@subsubheading Example
28659
28660@smallexample
594fe323 28661(gdb)
922fbb7b
AC
28662-break-delete 1
28663^done
594fe323 28664(gdb)
922fbb7b
AC
28665-break-list
28666^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
28667hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28668@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28669@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28670@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28671@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28672@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28673body=[]@}
594fe323 28674(gdb)
922fbb7b
AC
28675@end smallexample
28676
28677@subheading The @code{-break-disable} Command
28678@findex -break-disable
28679
28680@subsubheading Synopsis
28681
28682@smallexample
28683 -break-disable ( @var{breakpoint} )+
28684@end smallexample
28685
28686Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
28687break list is now set to @samp{n} for the named @var{breakpoint}(s).
28688
28689@subsubheading @value{GDBN} Command
28690
28691The corresponding @value{GDBN} command is @samp{disable}.
28692
28693@subsubheading Example
28694
28695@smallexample
594fe323 28696(gdb)
922fbb7b
AC
28697-break-disable 2
28698^done
594fe323 28699(gdb)
922fbb7b
AC
28700-break-list
28701^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28702hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28703@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28704@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28705@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28706@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28707@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28708body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102 28709addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 28710line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 28711(gdb)
922fbb7b
AC
28712@end smallexample
28713
28714@subheading The @code{-break-enable} Command
28715@findex -break-enable
28716
28717@subsubheading Synopsis
28718
28719@smallexample
28720 -break-enable ( @var{breakpoint} )+
28721@end smallexample
28722
28723Enable (previously disabled) @var{breakpoint}(s).
28724
28725@subsubheading @value{GDBN} Command
28726
28727The corresponding @value{GDBN} command is @samp{enable}.
28728
28729@subsubheading Example
28730
28731@smallexample
594fe323 28732(gdb)
922fbb7b
AC
28733-break-enable 2
28734^done
594fe323 28735(gdb)
922fbb7b
AC
28736-break-list
28737^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28738hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28739@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28740@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28741@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28742@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28743@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28744body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 28745addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 28746line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 28747(gdb)
922fbb7b
AC
28748@end smallexample
28749
28750@subheading The @code{-break-info} Command
28751@findex -break-info
28752
28753@subsubheading Synopsis
28754
28755@smallexample
28756 -break-info @var{breakpoint}
28757@end smallexample
28758
28759@c REDUNDANT???
28760Get information about a single breakpoint.
28761
54516a0b
TT
28762The result is a table of breakpoints. @xref{GDB/MI Breakpoint
28763Information}, for details on the format of each breakpoint in the
28764table.
28765
79a6e687 28766@subsubheading @value{GDBN} Command
922fbb7b
AC
28767
28768The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
28769
28770@subsubheading Example
28771N.A.
28772
28773@subheading The @code{-break-insert} Command
28774@findex -break-insert
28775
28776@subsubheading Synopsis
28777
28778@smallexample
18148017 28779 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
922fbb7b 28780 [ -c @var{condition} ] [ -i @var{ignore-count} ]
472a2379 28781 [ -p @var{thread-id} ] [ @var{location} ]
922fbb7b
AC
28782@end smallexample
28783
28784@noindent
afe8ab22 28785If specified, @var{location}, can be one of:
922fbb7b
AC
28786
28787@itemize @bullet
28788@item function
28789@c @item +offset
28790@c @item -offset
28791@c @item linenum
28792@item filename:linenum
28793@item filename:function
28794@item *address
28795@end itemize
28796
28797The possible optional parameters of this command are:
28798
28799@table @samp
28800@item -t
948d5102 28801Insert a temporary breakpoint.
922fbb7b
AC
28802@item -h
28803Insert a hardware breakpoint.
afe8ab22
VP
28804@item -f
28805If @var{location} cannot be parsed (for example if it
28806refers to unknown files or functions), create a pending
28807breakpoint. Without this flag, @value{GDBN} will report
28808an error, and won't create a breakpoint, if @var{location}
28809cannot be parsed.
41447f92
VP
28810@item -d
28811Create a disabled breakpoint.
18148017
VP
28812@item -a
28813Create a tracepoint. @xref{Tracepoints}. When this parameter
28814is used together with @samp{-h}, a fast tracepoint is created.
472a2379
KS
28815@item -c @var{condition}
28816Make the breakpoint conditional on @var{condition}.
28817@item -i @var{ignore-count}
28818Initialize the @var{ignore-count}.
28819@item -p @var{thread-id}
28820Restrict the breakpoint to the specified @var{thread-id}.
922fbb7b
AC
28821@end table
28822
28823@subsubheading Result
28824
54516a0b
TT
28825@xref{GDB/MI Breakpoint Information}, for details on the format of the
28826resulting breakpoint.
922fbb7b
AC
28827
28828Note: this format is open to change.
28829@c An out-of-band breakpoint instead of part of the result?
28830
28831@subsubheading @value{GDBN} Command
28832
28833The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
496ee73e 28834@samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
922fbb7b
AC
28835
28836@subsubheading Example
28837
28838@smallexample
594fe323 28839(gdb)
922fbb7b 28840-break-insert main
948d5102 28841^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
998580f1
MK
28842fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
28843times="0"@}
594fe323 28844(gdb)
922fbb7b 28845-break-insert -t foo
948d5102 28846^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
998580f1
MK
28847fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
28848times="0"@}
594fe323 28849(gdb)
922fbb7b
AC
28850-break-list
28851^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
28852hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28853@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28854@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28855@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28856@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28857@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28858body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 28859addr="0x0001072c", func="main",file="recursive2.c",
998580f1
MK
28860fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
28861times="0"@},
922fbb7b 28862bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102 28863addr="0x00010774",func="foo",file="recursive2.c",
998580f1
MK
28864fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
28865times="0"@}]@}
594fe323 28866(gdb)
496ee73e
KS
28867@c -break-insert -r foo.*
28868@c ~int foo(int, int);
28869@c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
998580f1
MK
28870@c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
28871@c times="0"@}
496ee73e 28872@c (gdb)
922fbb7b
AC
28873@end smallexample
28874
28875@subheading The @code{-break-list} Command
28876@findex -break-list
28877
28878@subsubheading Synopsis
28879
28880@smallexample
28881 -break-list
28882@end smallexample
28883
28884Displays the list of inserted breakpoints, showing the following fields:
28885
28886@table @samp
28887@item Number
28888number of the breakpoint
28889@item Type
28890type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
28891@item Disposition
28892should the breakpoint be deleted or disabled when it is hit: @samp{keep}
28893or @samp{nokeep}
28894@item Enabled
28895is the breakpoint enabled or no: @samp{y} or @samp{n}
28896@item Address
28897memory location at which the breakpoint is set
28898@item What
28899logical location of the breakpoint, expressed by function name, file
28900name, line number
998580f1
MK
28901@item Thread-groups
28902list of thread groups to which this breakpoint applies
922fbb7b
AC
28903@item Times
28904number of times the breakpoint has been hit
28905@end table
28906
28907If there are no breakpoints or watchpoints, the @code{BreakpointTable}
28908@code{body} field is an empty list.
28909
28910@subsubheading @value{GDBN} Command
28911
28912The corresponding @value{GDBN} command is @samp{info break}.
28913
28914@subsubheading Example
28915
28916@smallexample
594fe323 28917(gdb)
922fbb7b
AC
28918-break-list
28919^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
28920hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28921@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28922@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28923@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28924@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28925@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28926body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
998580f1
MK
28927addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
28928times="0"@},
922fbb7b 28929bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 28930addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
998580f1 28931line="13",thread-groups=["i1"],times="0"@}]@}
594fe323 28932(gdb)
922fbb7b
AC
28933@end smallexample
28934
28935Here's an example of the result when there are no breakpoints:
28936
28937@smallexample
594fe323 28938(gdb)
922fbb7b
AC
28939-break-list
28940^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
28941hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28942@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28943@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28944@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28945@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28946@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28947body=[]@}
594fe323 28948(gdb)
922fbb7b
AC
28949@end smallexample
28950
18148017
VP
28951@subheading The @code{-break-passcount} Command
28952@findex -break-passcount
28953
28954@subsubheading Synopsis
28955
28956@smallexample
28957 -break-passcount @var{tracepoint-number} @var{passcount}
28958@end smallexample
28959
28960Set the passcount for tracepoint @var{tracepoint-number} to
28961@var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
28962is not a tracepoint, error is emitted. This corresponds to CLI
28963command @samp{passcount}.
28964
922fbb7b
AC
28965@subheading The @code{-break-watch} Command
28966@findex -break-watch
28967
28968@subsubheading Synopsis
28969
28970@smallexample
28971 -break-watch [ -a | -r ]
28972@end smallexample
28973
28974Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 28975@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 28976read from or on a write to the memory location. With the @samp{-r}
d3e8051b 28977option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
28978trigger only when the memory location is accessed for reading. Without
28979either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 28980i.e., it will trigger when the memory location is accessed for writing.
79a6e687 28981@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
28982
28983Note that @samp{-break-list} will report a single list of watchpoints and
28984breakpoints inserted.
28985
28986@subsubheading @value{GDBN} Command
28987
28988The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
28989@samp{rwatch}.
28990
28991@subsubheading Example
28992
28993Setting a watchpoint on a variable in the @code{main} function:
28994
28995@smallexample
594fe323 28996(gdb)
922fbb7b
AC
28997-break-watch x
28998^done,wpt=@{number="2",exp="x"@}
594fe323 28999(gdb)
922fbb7b
AC
29000-exec-continue
29001^running
0869d01b
NR
29002(gdb)
29003*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 29004value=@{old="-268439212",new="55"@},
76ff342d 29005frame=@{func="main",args=[],file="recursive2.c",
948d5102 29006fullname="/home/foo/bar/recursive2.c",line="5"@}
594fe323 29007(gdb)
922fbb7b
AC
29008@end smallexample
29009
29010Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
29011the program execution twice: first for the variable changing value, then
29012for the watchpoint going out of scope.
29013
29014@smallexample
594fe323 29015(gdb)
922fbb7b
AC
29016-break-watch C
29017^done,wpt=@{number="5",exp="C"@}
594fe323 29018(gdb)
922fbb7b
AC
29019-exec-continue
29020^running
0869d01b
NR
29021(gdb)
29022*stopped,reason="watchpoint-trigger",
922fbb7b
AC
29023wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
29024frame=@{func="callee4",args=[],
76ff342d
DJ
29025file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29026fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 29027(gdb)
922fbb7b
AC
29028-exec-continue
29029^running
0869d01b
NR
29030(gdb)
29031*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
29032frame=@{func="callee3",args=[@{name="strarg",
29033value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
29034file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29035fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 29036(gdb)
922fbb7b
AC
29037@end smallexample
29038
29039Listing breakpoints and watchpoints, at different points in the program
29040execution. Note that once the watchpoint goes out of scope, it is
29041deleted.
29042
29043@smallexample
594fe323 29044(gdb)
922fbb7b
AC
29045-break-watch C
29046^done,wpt=@{number="2",exp="C"@}
594fe323 29047(gdb)
922fbb7b
AC
29048-break-list
29049^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
29050hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29051@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29052@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29053@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29054@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29055@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29056body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29057addr="0x00010734",func="callee4",
948d5102 29058file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
29059fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
29060times="1"@},
922fbb7b 29061bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 29062enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
594fe323 29063(gdb)
922fbb7b
AC
29064-exec-continue
29065^running
0869d01b
NR
29066(gdb)
29067*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
29068value=@{old="-276895068",new="3"@},
29069frame=@{func="callee4",args=[],
76ff342d
DJ
29070file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29071fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 29072(gdb)
922fbb7b
AC
29073-break-list
29074^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
29075hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29076@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29077@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29078@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29079@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29080@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29081body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29082addr="0x00010734",func="callee4",
948d5102 29083file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
29084fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
29085times="1"@},
922fbb7b 29086bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 29087enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
594fe323 29088(gdb)
922fbb7b
AC
29089-exec-continue
29090^running
29091^done,reason="watchpoint-scope",wpnum="2",
29092frame=@{func="callee3",args=[@{name="strarg",
29093value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
29094file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29095fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 29096(gdb)
922fbb7b
AC
29097-break-list
29098^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29099hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29100@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29101@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29102@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29103@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29104@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29105body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29106addr="0x00010734",func="callee4",
948d5102
NR
29107file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29108fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
998580f1 29109thread-groups=["i1"],times="1"@}]@}
594fe323 29110(gdb)
922fbb7b
AC
29111@end smallexample
29112
3fa7bf06
MG
29113
29114@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29115@node GDB/MI Catchpoint Commands
29116@section @sc{gdb/mi} Catchpoint Commands
29117
29118This section documents @sc{gdb/mi} commands for manipulating
29119catchpoints.
29120
29121@subheading The @code{-catch-load} Command
29122@findex -catch-load
29123
29124@subsubheading Synopsis
29125
29126@smallexample
29127 -catch-load [ -t ] [ -d ] @var{regexp}
29128@end smallexample
29129
29130Add a catchpoint for library load events. If the @samp{-t} option is used,
29131the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
29132Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
29133in a disabled state. The @samp{regexp} argument is a regular
29134expression used to match the name of the loaded library.
29135
29136
29137@subsubheading @value{GDBN} Command
29138
29139The corresponding @value{GDBN} command is @samp{catch load}.
29140
29141@subsubheading Example
29142
29143@smallexample
29144-catch-load -t foo.so
29145^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
8ac3646f 29146what="load of library matching foo.so",catch-type="load",times="0"@}
3fa7bf06
MG
29147(gdb)
29148@end smallexample
29149
29150
29151@subheading The @code{-catch-unload} Command
29152@findex -catch-unload
29153
29154@subsubheading Synopsis
29155
29156@smallexample
29157 -catch-unload [ -t ] [ -d ] @var{regexp}
29158@end smallexample
29159
29160Add a catchpoint for library unload events. If the @samp{-t} option is
29161used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
29162Breakpoints}). If the @samp{-d} option is used, the catchpoint is
29163created in a disabled state. The @samp{regexp} argument is a regular
29164expression used to match the name of the unloaded library.
29165
29166@subsubheading @value{GDBN} Command
29167
29168The corresponding @value{GDBN} command is @samp{catch unload}.
29169
29170@subsubheading Example
29171
29172@smallexample
29173-catch-unload -d bar.so
29174^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
8ac3646f 29175what="load of library matching bar.so",catch-type="unload",times="0"@}
3fa7bf06
MG
29176(gdb)
29177@end smallexample
29178
29179
922fbb7b 29180@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
29181@node GDB/MI Program Context
29182@section @sc{gdb/mi} Program Context
922fbb7b 29183
a2c02241
NR
29184@subheading The @code{-exec-arguments} Command
29185@findex -exec-arguments
922fbb7b 29186
922fbb7b
AC
29187
29188@subsubheading Synopsis
29189
29190@smallexample
a2c02241 29191 -exec-arguments @var{args}
922fbb7b
AC
29192@end smallexample
29193
a2c02241
NR
29194Set the inferior program arguments, to be used in the next
29195@samp{-exec-run}.
922fbb7b 29196
a2c02241 29197@subsubheading @value{GDBN} Command
922fbb7b 29198
a2c02241 29199The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 29200
a2c02241 29201@subsubheading Example
922fbb7b 29202
fbc5282e
MK
29203@smallexample
29204(gdb)
29205-exec-arguments -v word
29206^done
29207(gdb)
29208@end smallexample
922fbb7b 29209
a2c02241 29210
9901a55b 29211@ignore
a2c02241
NR
29212@subheading The @code{-exec-show-arguments} Command
29213@findex -exec-show-arguments
29214
29215@subsubheading Synopsis
29216
29217@smallexample
29218 -exec-show-arguments
29219@end smallexample
29220
29221Print the arguments of the program.
922fbb7b
AC
29222
29223@subsubheading @value{GDBN} Command
29224
a2c02241 29225The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
29226
29227@subsubheading Example
a2c02241 29228N.A.
9901a55b 29229@end ignore
922fbb7b 29230
922fbb7b 29231
a2c02241
NR
29232@subheading The @code{-environment-cd} Command
29233@findex -environment-cd
922fbb7b 29234
a2c02241 29235@subsubheading Synopsis
922fbb7b
AC
29236
29237@smallexample
a2c02241 29238 -environment-cd @var{pathdir}
922fbb7b
AC
29239@end smallexample
29240
a2c02241 29241Set @value{GDBN}'s working directory.
922fbb7b 29242
a2c02241 29243@subsubheading @value{GDBN} Command
922fbb7b 29244
a2c02241
NR
29245The corresponding @value{GDBN} command is @samp{cd}.
29246
29247@subsubheading Example
922fbb7b
AC
29248
29249@smallexample
594fe323 29250(gdb)
a2c02241
NR
29251-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
29252^done
594fe323 29253(gdb)
922fbb7b
AC
29254@end smallexample
29255
29256
a2c02241
NR
29257@subheading The @code{-environment-directory} Command
29258@findex -environment-directory
922fbb7b
AC
29259
29260@subsubheading Synopsis
29261
29262@smallexample
a2c02241 29263 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
29264@end smallexample
29265
a2c02241
NR
29266Add directories @var{pathdir} to beginning of search path for source files.
29267If the @samp{-r} option is used, the search path is reset to the default
29268search path. If directories @var{pathdir} are supplied in addition to the
29269@samp{-r} option, the search path is first reset and then addition
29270occurs as normal.
29271Multiple directories may be specified, separated by blanks. Specifying
29272multiple directories in a single command
29273results in the directories added to the beginning of the
29274search path in the same order they were presented in the command.
29275If blanks are needed as
29276part of a directory name, double-quotes should be used around
29277the name. In the command output, the path will show up separated
d3e8051b 29278by the system directory-separator character. The directory-separator
a2c02241
NR
29279character must not be used
29280in any directory name.
29281If no directories are specified, the current search path is displayed.
922fbb7b
AC
29282
29283@subsubheading @value{GDBN} Command
29284
a2c02241 29285The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
29286
29287@subsubheading Example
29288
922fbb7b 29289@smallexample
594fe323 29290(gdb)
a2c02241
NR
29291-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
29292^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 29293(gdb)
a2c02241
NR
29294-environment-directory ""
29295^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 29296(gdb)
a2c02241
NR
29297-environment-directory -r /home/jjohnstn/src/gdb /usr/src
29298^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 29299(gdb)
a2c02241
NR
29300-environment-directory -r
29301^done,source-path="$cdir:$cwd"
594fe323 29302(gdb)
922fbb7b
AC
29303@end smallexample
29304
29305
a2c02241
NR
29306@subheading The @code{-environment-path} Command
29307@findex -environment-path
922fbb7b
AC
29308
29309@subsubheading Synopsis
29310
29311@smallexample
a2c02241 29312 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
29313@end smallexample
29314
a2c02241
NR
29315Add directories @var{pathdir} to beginning of search path for object files.
29316If the @samp{-r} option is used, the search path is reset to the original
29317search path that existed at gdb start-up. If directories @var{pathdir} are
29318supplied in addition to the
29319@samp{-r} option, the search path is first reset and then addition
29320occurs as normal.
29321Multiple directories may be specified, separated by blanks. Specifying
29322multiple directories in a single command
29323results in the directories added to the beginning of the
29324search path in the same order they were presented in the command.
29325If blanks are needed as
29326part of a directory name, double-quotes should be used around
29327the name. In the command output, the path will show up separated
d3e8051b 29328by the system directory-separator character. The directory-separator
a2c02241
NR
29329character must not be used
29330in any directory name.
29331If no directories are specified, the current path is displayed.
29332
922fbb7b
AC
29333
29334@subsubheading @value{GDBN} Command
29335
a2c02241 29336The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
29337
29338@subsubheading Example
29339
922fbb7b 29340@smallexample
594fe323 29341(gdb)
a2c02241
NR
29342-environment-path
29343^done,path="/usr/bin"
594fe323 29344(gdb)
a2c02241
NR
29345-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
29346^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 29347(gdb)
a2c02241
NR
29348-environment-path -r /usr/local/bin
29349^done,path="/usr/local/bin:/usr/bin"
594fe323 29350(gdb)
922fbb7b
AC
29351@end smallexample
29352
29353
a2c02241
NR
29354@subheading The @code{-environment-pwd} Command
29355@findex -environment-pwd
922fbb7b
AC
29356
29357@subsubheading Synopsis
29358
29359@smallexample
a2c02241 29360 -environment-pwd
922fbb7b
AC
29361@end smallexample
29362
a2c02241 29363Show the current working directory.
922fbb7b 29364
79a6e687 29365@subsubheading @value{GDBN} Command
922fbb7b 29366
a2c02241 29367The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
29368
29369@subsubheading Example
29370
922fbb7b 29371@smallexample
594fe323 29372(gdb)
a2c02241
NR
29373-environment-pwd
29374^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 29375(gdb)
922fbb7b
AC
29376@end smallexample
29377
a2c02241
NR
29378@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29379@node GDB/MI Thread Commands
29380@section @sc{gdb/mi} Thread Commands
29381
29382
29383@subheading The @code{-thread-info} Command
29384@findex -thread-info
922fbb7b
AC
29385
29386@subsubheading Synopsis
29387
29388@smallexample
8e8901c5 29389 -thread-info [ @var{thread-id} ]
922fbb7b
AC
29390@end smallexample
29391
8e8901c5
VP
29392Reports information about either a specific thread, if
29393the @var{thread-id} parameter is present, or about all
29394threads. When printing information about all threads,
29395also reports the current thread.
29396
79a6e687 29397@subsubheading @value{GDBN} Command
922fbb7b 29398
8e8901c5
VP
29399The @samp{info thread} command prints the same information
29400about all threads.
922fbb7b 29401
4694da01 29402@subsubheading Result
922fbb7b 29403
4694da01
TT
29404The result is a list of threads. The following attributes are
29405defined for a given thread:
29406
29407@table @samp
29408@item current
29409This field exists only for the current thread. It has the value @samp{*}.
29410
29411@item id
29412The identifier that @value{GDBN} uses to refer to the thread.
29413
29414@item target-id
29415The identifier that the target uses to refer to the thread.
29416
29417@item details
29418Extra information about the thread, in a target-specific format. This
29419field is optional.
29420
29421@item name
29422The name of the thread. If the user specified a name using the
29423@code{thread name} command, then this name is given. Otherwise, if
29424@value{GDBN} can extract the thread name from the target, then that
29425name is given. If @value{GDBN} cannot find the thread name, then this
29426field is omitted.
29427
29428@item frame
29429The stack frame currently executing in the thread.
922fbb7b 29430
4694da01
TT
29431@item state
29432The thread's state. The @samp{state} field may have the following
29433values:
c3b108f7
VP
29434
29435@table @code
29436@item stopped
29437The thread is stopped. Frame information is available for stopped
29438threads.
29439
29440@item running
29441The thread is running. There's no frame information for running
29442threads.
29443
29444@end table
29445
4694da01
TT
29446@item core
29447If @value{GDBN} can find the CPU core on which this thread is running,
29448then this field is the core identifier. This field is optional.
29449
29450@end table
29451
29452@subsubheading Example
29453
29454@smallexample
29455-thread-info
29456^done,threads=[
29457@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
29458 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
29459 args=[]@},state="running"@},
29460@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
29461 frame=@{level="0",addr="0x0804891f",func="foo",
29462 args=[@{name="i",value="10"@}],
29463 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},
29464 state="running"@}],
29465current-thread-id="1"
29466(gdb)
29467@end smallexample
29468
a2c02241
NR
29469@subheading The @code{-thread-list-ids} Command
29470@findex -thread-list-ids
922fbb7b 29471
a2c02241 29472@subsubheading Synopsis
922fbb7b 29473
a2c02241
NR
29474@smallexample
29475 -thread-list-ids
29476@end smallexample
922fbb7b 29477
a2c02241
NR
29478Produces a list of the currently known @value{GDBN} thread ids. At the
29479end of the list it also prints the total number of such threads.
922fbb7b 29480
c3b108f7
VP
29481This command is retained for historical reasons, the
29482@code{-thread-info} command should be used instead.
29483
922fbb7b
AC
29484@subsubheading @value{GDBN} Command
29485
a2c02241 29486Part of @samp{info threads} supplies the same information.
922fbb7b
AC
29487
29488@subsubheading Example
29489
922fbb7b 29490@smallexample
594fe323 29491(gdb)
a2c02241
NR
29492-thread-list-ids
29493^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
592375cd 29494current-thread-id="1",number-of-threads="3"
594fe323 29495(gdb)
922fbb7b
AC
29496@end smallexample
29497
a2c02241
NR
29498
29499@subheading The @code{-thread-select} Command
29500@findex -thread-select
922fbb7b
AC
29501
29502@subsubheading Synopsis
29503
29504@smallexample
a2c02241 29505 -thread-select @var{threadnum}
922fbb7b
AC
29506@end smallexample
29507
a2c02241
NR
29508Make @var{threadnum} the current thread. It prints the number of the new
29509current thread, and the topmost frame for that thread.
922fbb7b 29510
c3b108f7
VP
29511This command is deprecated in favor of explicitly using the
29512@samp{--thread} option to each command.
29513
922fbb7b
AC
29514@subsubheading @value{GDBN} Command
29515
a2c02241 29516The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
29517
29518@subsubheading Example
922fbb7b
AC
29519
29520@smallexample
594fe323 29521(gdb)
a2c02241
NR
29522-exec-next
29523^running
594fe323 29524(gdb)
a2c02241
NR
29525*stopped,reason="end-stepping-range",thread-id="2",line="187",
29526file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 29527(gdb)
a2c02241
NR
29528-thread-list-ids
29529^done,
29530thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
29531number-of-threads="3"
594fe323 29532(gdb)
a2c02241
NR
29533-thread-select 3
29534^done,new-thread-id="3",
29535frame=@{level="0",func="vprintf",
29536args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
29537@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
594fe323 29538(gdb)
922fbb7b
AC
29539@end smallexample
29540
5d77fe44
JB
29541@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29542@node GDB/MI Ada Tasking Commands
29543@section @sc{gdb/mi} Ada Tasking Commands
29544
29545@subheading The @code{-ada-task-info} Command
29546@findex -ada-task-info
29547
29548@subsubheading Synopsis
29549
29550@smallexample
29551 -ada-task-info [ @var{task-id} ]
29552@end smallexample
29553
29554Reports information about either a specific Ada task, if the
29555@var{task-id} parameter is present, or about all Ada tasks.
29556
29557@subsubheading @value{GDBN} Command
29558
29559The @samp{info tasks} command prints the same information
29560about all Ada tasks (@pxref{Ada Tasks}).
29561
29562@subsubheading Result
29563
29564The result is a table of Ada tasks. The following columns are
29565defined for each Ada task:
29566
29567@table @samp
29568@item current
29569This field exists only for the current thread. It has the value @samp{*}.
29570
29571@item id
29572The identifier that @value{GDBN} uses to refer to the Ada task.
29573
29574@item task-id
29575The identifier that the target uses to refer to the Ada task.
29576
29577@item thread-id
29578The identifier of the thread corresponding to the Ada task.
29579
29580This field should always exist, as Ada tasks are always implemented
29581on top of a thread. But if @value{GDBN} cannot find this corresponding
29582thread for any reason, the field is omitted.
29583
29584@item parent-id
29585This field exists only when the task was created by another task.
29586In this case, it provides the ID of the parent task.
29587
29588@item priority
29589The base priority of the task.
29590
29591@item state
29592The current state of the task. For a detailed description of the
29593possible states, see @ref{Ada Tasks}.
29594
29595@item name
29596The name of the task.
29597
29598@end table
29599
29600@subsubheading Example
29601
29602@smallexample
29603-ada-task-info
29604^done,tasks=@{nr_rows="3",nr_cols="8",
29605hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
29606@{width="3",alignment="1",col_name="id",colhdr="ID"@},
29607@{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
29608@{width="4",alignment="1",col_name="thread-id",colhdr=""@},
29609@{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
29610@{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
29611@{width="22",alignment="-1",col_name="state",colhdr="State"@},
29612@{width="1",alignment="2",col_name="name",colhdr="Name"@}],
29613body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
29614state="Child Termination Wait",name="main_task"@}]@}
29615(gdb)
29616@end smallexample
29617
a2c02241
NR
29618@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29619@node GDB/MI Program Execution
29620@section @sc{gdb/mi} Program Execution
922fbb7b 29621
ef21caaf 29622These are the asynchronous commands which generate the out-of-band
3f94c067 29623record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
29624asynchronously with remote targets and this interaction is mimicked in
29625other cases.
922fbb7b 29626
922fbb7b
AC
29627@subheading The @code{-exec-continue} Command
29628@findex -exec-continue
29629
29630@subsubheading Synopsis
29631
29632@smallexample
540aa8e7 29633 -exec-continue [--reverse] [--all|--thread-group N]
922fbb7b
AC
29634@end smallexample
29635
540aa8e7
MS
29636Resumes the execution of the inferior program, which will continue
29637to execute until it reaches a debugger stop event. If the
29638@samp{--reverse} option is specified, execution resumes in reverse until
29639it reaches a stop event. Stop events may include
29640@itemize @bullet
29641@item
29642breakpoints or watchpoints
29643@item
29644signals or exceptions
29645@item
29646the end of the process (or its beginning under @samp{--reverse})
29647@item
29648the end or beginning of a replay log if one is being used.
29649@end itemize
29650In all-stop mode (@pxref{All-Stop
29651Mode}), may resume only one thread, or all threads, depending on the
29652value of the @samp{scheduler-locking} variable. If @samp{--all} is
a79b8f6e 29653specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
540aa8e7
MS
29654ignored in all-stop mode. If the @samp{--thread-group} options is
29655specified, then all threads in that thread group are resumed.
922fbb7b
AC
29656
29657@subsubheading @value{GDBN} Command
29658
29659The corresponding @value{GDBN} corresponding is @samp{continue}.
29660
29661@subsubheading Example
29662
29663@smallexample
29664-exec-continue
29665^running
594fe323 29666(gdb)
922fbb7b 29667@@Hello world
a47ec5fe
AR
29668*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
29669func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
29670line="13"@}
594fe323 29671(gdb)
922fbb7b
AC
29672@end smallexample
29673
29674
29675@subheading The @code{-exec-finish} Command
29676@findex -exec-finish
29677
29678@subsubheading Synopsis
29679
29680@smallexample
540aa8e7 29681 -exec-finish [--reverse]
922fbb7b
AC
29682@end smallexample
29683
ef21caaf
NR
29684Resumes the execution of the inferior program until the current
29685function is exited. Displays the results returned by the function.
540aa8e7
MS
29686If the @samp{--reverse} option is specified, resumes the reverse
29687execution of the inferior program until the point where current
29688function was called.
922fbb7b
AC
29689
29690@subsubheading @value{GDBN} Command
29691
29692The corresponding @value{GDBN} command is @samp{finish}.
29693
29694@subsubheading Example
29695
29696Function returning @code{void}.
29697
29698@smallexample
29699-exec-finish
29700^running
594fe323 29701(gdb)
922fbb7b
AC
29702@@hello from foo
29703*stopped,reason="function-finished",frame=@{func="main",args=[],
948d5102 29704file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
594fe323 29705(gdb)
922fbb7b
AC
29706@end smallexample
29707
29708Function returning other than @code{void}. The name of the internal
29709@value{GDBN} variable storing the result is printed, together with the
29710value itself.
29711
29712@smallexample
29713-exec-finish
29714^running
594fe323 29715(gdb)
922fbb7b
AC
29716*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
29717args=[@{name="a",value="1"],@{name="b",value="9"@}@},
948d5102 29718file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
922fbb7b 29719gdb-result-var="$1",return-value="0"
594fe323 29720(gdb)
922fbb7b
AC
29721@end smallexample
29722
29723
29724@subheading The @code{-exec-interrupt} Command
29725@findex -exec-interrupt
29726
29727@subsubheading Synopsis
29728
29729@smallexample
c3b108f7 29730 -exec-interrupt [--all|--thread-group N]
922fbb7b
AC
29731@end smallexample
29732
ef21caaf
NR
29733Interrupts the background execution of the target. Note how the token
29734associated with the stop message is the one for the execution command
29735that has been interrupted. The token for the interrupt itself only
29736appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
29737interrupt a non-running program, an error message will be printed.
29738
c3b108f7
VP
29739Note that when asynchronous execution is enabled, this command is
29740asynchronous just like other execution commands. That is, first the
29741@samp{^done} response will be printed, and the target stop will be
29742reported after that using the @samp{*stopped} notification.
29743
29744In non-stop mode, only the context thread is interrupted by default.
a79b8f6e
VP
29745All threads (in all inferiors) will be interrupted if the
29746@samp{--all} option is specified. If the @samp{--thread-group}
29747option is specified, all threads in that group will be interrupted.
c3b108f7 29748
922fbb7b
AC
29749@subsubheading @value{GDBN} Command
29750
29751The corresponding @value{GDBN} command is @samp{interrupt}.
29752
29753@subsubheading Example
29754
29755@smallexample
594fe323 29756(gdb)
922fbb7b
AC
29757111-exec-continue
29758111^running
29759
594fe323 29760(gdb)
922fbb7b
AC
29761222-exec-interrupt
29762222^done
594fe323 29763(gdb)
922fbb7b 29764111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 29765frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
948d5102 29766fullname="/home/foo/bar/try.c",line="13"@}
594fe323 29767(gdb)
922fbb7b 29768
594fe323 29769(gdb)
922fbb7b
AC
29770-exec-interrupt
29771^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 29772(gdb)
922fbb7b
AC
29773@end smallexample
29774
83eba9b7
VP
29775@subheading The @code{-exec-jump} Command
29776@findex -exec-jump
29777
29778@subsubheading Synopsis
29779
29780@smallexample
29781 -exec-jump @var{location}
29782@end smallexample
29783
29784Resumes execution of the inferior program at the location specified by
29785parameter. @xref{Specify Location}, for a description of the
29786different forms of @var{location}.
29787
29788@subsubheading @value{GDBN} Command
29789
29790The corresponding @value{GDBN} command is @samp{jump}.
29791
29792@subsubheading Example
29793
29794@smallexample
29795-exec-jump foo.c:10
29796*running,thread-id="all"
29797^running
29798@end smallexample
29799
922fbb7b
AC
29800
29801@subheading The @code{-exec-next} Command
29802@findex -exec-next
29803
29804@subsubheading Synopsis
29805
29806@smallexample
540aa8e7 29807 -exec-next [--reverse]
922fbb7b
AC
29808@end smallexample
29809
ef21caaf
NR
29810Resumes execution of the inferior program, stopping when the beginning
29811of the next source line is reached.
922fbb7b 29812
540aa8e7
MS
29813If the @samp{--reverse} option is specified, resumes reverse execution
29814of the inferior program, stopping at the beginning of the previous
29815source line. If you issue this command on the first line of a
29816function, it will take you back to the caller of that function, to the
29817source line where the function was called.
29818
29819
922fbb7b
AC
29820@subsubheading @value{GDBN} Command
29821
29822The corresponding @value{GDBN} command is @samp{next}.
29823
29824@subsubheading Example
29825
29826@smallexample
29827-exec-next
29828^running
594fe323 29829(gdb)
922fbb7b 29830*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 29831(gdb)
922fbb7b
AC
29832@end smallexample
29833
29834
29835@subheading The @code{-exec-next-instruction} Command
29836@findex -exec-next-instruction
29837
29838@subsubheading Synopsis
29839
29840@smallexample
540aa8e7 29841 -exec-next-instruction [--reverse]
922fbb7b
AC
29842@end smallexample
29843
ef21caaf
NR
29844Executes one machine instruction. If the instruction is a function
29845call, continues until the function returns. If the program stops at an
29846instruction in the middle of a source line, the address will be
29847printed as well.
922fbb7b 29848
540aa8e7
MS
29849If the @samp{--reverse} option is specified, resumes reverse execution
29850of the inferior program, stopping at the previous instruction. If the
29851previously executed instruction was a return from another function,
29852it will continue to execute in reverse until the call to that function
29853(from the current stack frame) is reached.
29854
922fbb7b
AC
29855@subsubheading @value{GDBN} Command
29856
29857The corresponding @value{GDBN} command is @samp{nexti}.
29858
29859@subsubheading Example
29860
29861@smallexample
594fe323 29862(gdb)
922fbb7b
AC
29863-exec-next-instruction
29864^running
29865
594fe323 29866(gdb)
922fbb7b
AC
29867*stopped,reason="end-stepping-range",
29868addr="0x000100d4",line="5",file="hello.c"
594fe323 29869(gdb)
922fbb7b
AC
29870@end smallexample
29871
29872
29873@subheading The @code{-exec-return} Command
29874@findex -exec-return
29875
29876@subsubheading Synopsis
29877
29878@smallexample
29879 -exec-return
29880@end smallexample
29881
29882Makes current function return immediately. Doesn't execute the inferior.
29883Displays the new current frame.
29884
29885@subsubheading @value{GDBN} Command
29886
29887The corresponding @value{GDBN} command is @samp{return}.
29888
29889@subsubheading Example
29890
29891@smallexample
594fe323 29892(gdb)
922fbb7b
AC
29893200-break-insert callee4
29894200^done,bkpt=@{number="1",addr="0x00010734",
29895file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 29896(gdb)
922fbb7b
AC
29897000-exec-run
29898000^running
594fe323 29899(gdb)
a47ec5fe 29900000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
922fbb7b 29901frame=@{func="callee4",args=[],
76ff342d
DJ
29902file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29903fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 29904(gdb)
922fbb7b
AC
29905205-break-delete
29906205^done
594fe323 29907(gdb)
922fbb7b
AC
29908111-exec-return
29909111^done,frame=@{level="0",func="callee3",
29910args=[@{name="strarg",
29911value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
29912file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29913fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 29914(gdb)
922fbb7b
AC
29915@end smallexample
29916
29917
29918@subheading The @code{-exec-run} Command
29919@findex -exec-run
29920
29921@subsubheading Synopsis
29922
29923@smallexample
a79b8f6e 29924 -exec-run [--all | --thread-group N]
922fbb7b
AC
29925@end smallexample
29926
ef21caaf
NR
29927Starts execution of the inferior from the beginning. The inferior
29928executes until either a breakpoint is encountered or the program
29929exits. In the latter case the output will include an exit code, if
29930the program has exited exceptionally.
922fbb7b 29931
a79b8f6e
VP
29932When no option is specified, the current inferior is started. If the
29933@samp{--thread-group} option is specified, it should refer to a thread
29934group of type @samp{process}, and that thread group will be started.
29935If the @samp{--all} option is specified, then all inferiors will be started.
29936
922fbb7b
AC
29937@subsubheading @value{GDBN} Command
29938
29939The corresponding @value{GDBN} command is @samp{run}.
29940
ef21caaf 29941@subsubheading Examples
922fbb7b
AC
29942
29943@smallexample
594fe323 29944(gdb)
922fbb7b
AC
29945-break-insert main
29946^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 29947(gdb)
922fbb7b
AC
29948-exec-run
29949^running
594fe323 29950(gdb)
a47ec5fe 29951*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
76ff342d 29952frame=@{func="main",args=[],file="recursive2.c",
948d5102 29953fullname="/home/foo/bar/recursive2.c",line="4"@}
594fe323 29954(gdb)
922fbb7b
AC
29955@end smallexample
29956
ef21caaf
NR
29957@noindent
29958Program exited normally:
29959
29960@smallexample
594fe323 29961(gdb)
ef21caaf
NR
29962-exec-run
29963^running
594fe323 29964(gdb)
ef21caaf
NR
29965x = 55
29966*stopped,reason="exited-normally"
594fe323 29967(gdb)
ef21caaf
NR
29968@end smallexample
29969
29970@noindent
29971Program exited exceptionally:
29972
29973@smallexample
594fe323 29974(gdb)
ef21caaf
NR
29975-exec-run
29976^running
594fe323 29977(gdb)
ef21caaf
NR
29978x = 55
29979*stopped,reason="exited",exit-code="01"
594fe323 29980(gdb)
ef21caaf
NR
29981@end smallexample
29982
29983Another way the program can terminate is if it receives a signal such as
29984@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
29985
29986@smallexample
594fe323 29987(gdb)
ef21caaf
NR
29988*stopped,reason="exited-signalled",signal-name="SIGINT",
29989signal-meaning="Interrupt"
29990@end smallexample
29991
922fbb7b 29992
a2c02241
NR
29993@c @subheading -exec-signal
29994
29995
29996@subheading The @code{-exec-step} Command
29997@findex -exec-step
922fbb7b
AC
29998
29999@subsubheading Synopsis
30000
30001@smallexample
540aa8e7 30002 -exec-step [--reverse]
922fbb7b
AC
30003@end smallexample
30004
a2c02241
NR
30005Resumes execution of the inferior program, stopping when the beginning
30006of the next source line is reached, if the next source line is not a
30007function call. If it is, stop at the first instruction of the called
540aa8e7
MS
30008function. If the @samp{--reverse} option is specified, resumes reverse
30009execution of the inferior program, stopping at the beginning of the
30010previously executed source line.
922fbb7b
AC
30011
30012@subsubheading @value{GDBN} Command
30013
a2c02241 30014The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
30015
30016@subsubheading Example
30017
30018Stepping into a function:
30019
30020@smallexample
30021-exec-step
30022^running
594fe323 30023(gdb)
922fbb7b
AC
30024*stopped,reason="end-stepping-range",
30025frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 30026@{name="b",value="0"@}],file="recursive2.c",
948d5102 30027fullname="/home/foo/bar/recursive2.c",line="11"@}
594fe323 30028(gdb)
922fbb7b
AC
30029@end smallexample
30030
30031Regular stepping:
30032
30033@smallexample
30034-exec-step
30035^running
594fe323 30036(gdb)
922fbb7b 30037*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 30038(gdb)
922fbb7b
AC
30039@end smallexample
30040
30041
30042@subheading The @code{-exec-step-instruction} Command
30043@findex -exec-step-instruction
30044
30045@subsubheading Synopsis
30046
30047@smallexample
540aa8e7 30048 -exec-step-instruction [--reverse]
922fbb7b
AC
30049@end smallexample
30050
540aa8e7
MS
30051Resumes the inferior which executes one machine instruction. If the
30052@samp{--reverse} option is specified, resumes reverse execution of the
30053inferior program, stopping at the previously executed instruction.
30054The output, once @value{GDBN} has stopped, will vary depending on
30055whether we have stopped in the middle of a source line or not. In the
30056former case, the address at which the program stopped will be printed
30057as well.
922fbb7b
AC
30058
30059@subsubheading @value{GDBN} Command
30060
30061The corresponding @value{GDBN} command is @samp{stepi}.
30062
30063@subsubheading Example
30064
30065@smallexample
594fe323 30066(gdb)
922fbb7b
AC
30067-exec-step-instruction
30068^running
30069
594fe323 30070(gdb)
922fbb7b 30071*stopped,reason="end-stepping-range",
76ff342d 30072frame=@{func="foo",args=[],file="try.c",
948d5102 30073fullname="/home/foo/bar/try.c",line="10"@}
594fe323 30074(gdb)
922fbb7b
AC
30075-exec-step-instruction
30076^running
30077
594fe323 30078(gdb)
922fbb7b 30079*stopped,reason="end-stepping-range",
76ff342d 30080frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
948d5102 30081fullname="/home/foo/bar/try.c",line="10"@}
594fe323 30082(gdb)
922fbb7b
AC
30083@end smallexample
30084
30085
30086@subheading The @code{-exec-until} Command
30087@findex -exec-until
30088
30089@subsubheading Synopsis
30090
30091@smallexample
30092 -exec-until [ @var{location} ]
30093@end smallexample
30094
ef21caaf
NR
30095Executes the inferior until the @var{location} specified in the
30096argument is reached. If there is no argument, the inferior executes
30097until a source line greater than the current one is reached. The
30098reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
30099
30100@subsubheading @value{GDBN} Command
30101
30102The corresponding @value{GDBN} command is @samp{until}.
30103
30104@subsubheading Example
30105
30106@smallexample
594fe323 30107(gdb)
922fbb7b
AC
30108-exec-until recursive2.c:6
30109^running
594fe323 30110(gdb)
922fbb7b
AC
30111x = 55
30112*stopped,reason="location-reached",frame=@{func="main",args=[],
948d5102 30113file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
594fe323 30114(gdb)
922fbb7b
AC
30115@end smallexample
30116
30117@ignore
30118@subheading -file-clear
30119Is this going away????
30120@end ignore
30121
351ff01a 30122@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
30123@node GDB/MI Stack Manipulation
30124@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 30125
922fbb7b 30126
a2c02241
NR
30127@subheading The @code{-stack-info-frame} Command
30128@findex -stack-info-frame
922fbb7b
AC
30129
30130@subsubheading Synopsis
30131
30132@smallexample
a2c02241 30133 -stack-info-frame
922fbb7b
AC
30134@end smallexample
30135
a2c02241 30136Get info on the selected frame.
922fbb7b
AC
30137
30138@subsubheading @value{GDBN} Command
30139
a2c02241
NR
30140The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
30141(without arguments).
922fbb7b
AC
30142
30143@subsubheading Example
30144
30145@smallexample
594fe323 30146(gdb)
a2c02241
NR
30147-stack-info-frame
30148^done,frame=@{level="1",addr="0x0001076c",func="callee3",
30149file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30150fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
594fe323 30151(gdb)
922fbb7b
AC
30152@end smallexample
30153
a2c02241
NR
30154@subheading The @code{-stack-info-depth} Command
30155@findex -stack-info-depth
922fbb7b
AC
30156
30157@subsubheading Synopsis
30158
30159@smallexample
a2c02241 30160 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
30161@end smallexample
30162
a2c02241
NR
30163Return the depth of the stack. If the integer argument @var{max-depth}
30164is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
30165
30166@subsubheading @value{GDBN} Command
30167
a2c02241 30168There's no equivalent @value{GDBN} command.
922fbb7b
AC
30169
30170@subsubheading Example
30171
a2c02241
NR
30172For a stack with frame levels 0 through 11:
30173
922fbb7b 30174@smallexample
594fe323 30175(gdb)
a2c02241
NR
30176-stack-info-depth
30177^done,depth="12"
594fe323 30178(gdb)
a2c02241
NR
30179-stack-info-depth 4
30180^done,depth="4"
594fe323 30181(gdb)
a2c02241
NR
30182-stack-info-depth 12
30183^done,depth="12"
594fe323 30184(gdb)
a2c02241
NR
30185-stack-info-depth 11
30186^done,depth="11"
594fe323 30187(gdb)
a2c02241
NR
30188-stack-info-depth 13
30189^done,depth="12"
594fe323 30190(gdb)
922fbb7b
AC
30191@end smallexample
30192
a2c02241
NR
30193@subheading The @code{-stack-list-arguments} Command
30194@findex -stack-list-arguments
922fbb7b
AC
30195
30196@subsubheading Synopsis
30197
30198@smallexample
3afae151 30199 -stack-list-arguments @var{print-values}
a2c02241 30200 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
30201@end smallexample
30202
a2c02241
NR
30203Display a list of the arguments for the frames between @var{low-frame}
30204and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
30205@var{high-frame} are not provided, list the arguments for the whole
30206call stack. If the two arguments are equal, show the single frame
30207at the corresponding level. It is an error if @var{low-frame} is
30208larger than the actual number of frames. On the other hand,
30209@var{high-frame} may be larger than the actual number of frames, in
30210which case only existing frames will be returned.
a2c02241 30211
3afae151
VP
30212If @var{print-values} is 0 or @code{--no-values}, print only the names of
30213the variables; if it is 1 or @code{--all-values}, print also their
30214values; and if it is 2 or @code{--simple-values}, print the name,
30215type and value for simple data types, and the name and type for arrays,
30216structures and unions.
922fbb7b 30217
b3372f91
VP
30218Use of this command to obtain arguments in a single frame is
30219deprecated in favor of the @samp{-stack-list-variables} command.
30220
922fbb7b
AC
30221@subsubheading @value{GDBN} Command
30222
a2c02241
NR
30223@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
30224@samp{gdb_get_args} command which partially overlaps with the
30225functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
30226
30227@subsubheading Example
922fbb7b 30228
a2c02241 30229@smallexample
594fe323 30230(gdb)
a2c02241
NR
30231-stack-list-frames
30232^done,
30233stack=[
30234frame=@{level="0",addr="0x00010734",func="callee4",
30235file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30236fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
30237frame=@{level="1",addr="0x0001076c",func="callee3",
30238file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30239fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
30240frame=@{level="2",addr="0x0001078c",func="callee2",
30241file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30242fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
30243frame=@{level="3",addr="0x000107b4",func="callee1",
30244file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30245fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
30246frame=@{level="4",addr="0x000107e0",func="main",
30247file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30248fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
594fe323 30249(gdb)
a2c02241
NR
30250-stack-list-arguments 0
30251^done,
30252stack-args=[
30253frame=@{level="0",args=[]@},
30254frame=@{level="1",args=[name="strarg"]@},
30255frame=@{level="2",args=[name="intarg",name="strarg"]@},
30256frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
30257frame=@{level="4",args=[]@}]
594fe323 30258(gdb)
a2c02241
NR
30259-stack-list-arguments 1
30260^done,
30261stack-args=[
30262frame=@{level="0",args=[]@},
30263frame=@{level="1",
30264 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
30265frame=@{level="2",args=[
30266@{name="intarg",value="2"@},
30267@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
30268@{frame=@{level="3",args=[
30269@{name="intarg",value="2"@},
30270@{name="strarg",value="0x11940 \"A string argument.\""@},
30271@{name="fltarg",value="3.5"@}]@},
30272frame=@{level="4",args=[]@}]
594fe323 30273(gdb)
a2c02241
NR
30274-stack-list-arguments 0 2 2
30275^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 30276(gdb)
a2c02241
NR
30277-stack-list-arguments 1 2 2
30278^done,stack-args=[frame=@{level="2",
30279args=[@{name="intarg",value="2"@},
30280@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 30281(gdb)
a2c02241
NR
30282@end smallexample
30283
30284@c @subheading -stack-list-exception-handlers
922fbb7b 30285
a2c02241
NR
30286
30287@subheading The @code{-stack-list-frames} Command
30288@findex -stack-list-frames
1abaf70c
BR
30289
30290@subsubheading Synopsis
30291
30292@smallexample
a2c02241 30293 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
1abaf70c
BR
30294@end smallexample
30295
a2c02241
NR
30296List the frames currently on the stack. For each frame it displays the
30297following info:
30298
30299@table @samp
30300@item @var{level}
d3e8051b 30301The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
30302@item @var{addr}
30303The @code{$pc} value for that frame.
30304@item @var{func}
30305Function name.
30306@item @var{file}
30307File name of the source file where the function lives.
7d288aaa
TT
30308@item @var{fullname}
30309The full file name of the source file where the function lives.
a2c02241
NR
30310@item @var{line}
30311Line number corresponding to the @code{$pc}.
7d288aaa
TT
30312@item @var{from}
30313The shared library where this function is defined. This is only given
30314if the frame's function is not known.
a2c02241
NR
30315@end table
30316
30317If invoked without arguments, this command prints a backtrace for the
30318whole stack. If given two integer arguments, it shows the frames whose
30319levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
30320are equal, it shows the single frame at the corresponding level. It is
30321an error if @var{low-frame} is larger than the actual number of
a5451f4e 30322frames. On the other hand, @var{high-frame} may be larger than the
2ab1eb7a 30323actual number of frames, in which case only existing frames will be returned.
1abaf70c
BR
30324
30325@subsubheading @value{GDBN} Command
30326
a2c02241 30327The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
30328
30329@subsubheading Example
30330
a2c02241
NR
30331Full stack backtrace:
30332
1abaf70c 30333@smallexample
594fe323 30334(gdb)
a2c02241
NR
30335-stack-list-frames
30336^done,stack=
30337[frame=@{level="0",addr="0x0001076c",func="foo",
30338 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
30339frame=@{level="1",addr="0x000107a4",func="foo",
30340 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30341frame=@{level="2",addr="0x000107a4",func="foo",
30342 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30343frame=@{level="3",addr="0x000107a4",func="foo",
30344 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30345frame=@{level="4",addr="0x000107a4",func="foo",
30346 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30347frame=@{level="5",addr="0x000107a4",func="foo",
30348 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30349frame=@{level="6",addr="0x000107a4",func="foo",
30350 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30351frame=@{level="7",addr="0x000107a4",func="foo",
30352 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30353frame=@{level="8",addr="0x000107a4",func="foo",
30354 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30355frame=@{level="9",addr="0x000107a4",func="foo",
30356 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30357frame=@{level="10",addr="0x000107a4",func="foo",
30358 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30359frame=@{level="11",addr="0x00010738",func="main",
30360 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
594fe323 30361(gdb)
1abaf70c
BR
30362@end smallexample
30363
a2c02241 30364Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 30365
a2c02241 30366@smallexample
594fe323 30367(gdb)
a2c02241
NR
30368-stack-list-frames 3 5
30369^done,stack=
30370[frame=@{level="3",addr="0x000107a4",func="foo",
30371 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30372frame=@{level="4",addr="0x000107a4",func="foo",
30373 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30374frame=@{level="5",addr="0x000107a4",func="foo",
30375 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 30376(gdb)
a2c02241 30377@end smallexample
922fbb7b 30378
a2c02241 30379Show a single frame:
922fbb7b
AC
30380
30381@smallexample
594fe323 30382(gdb)
a2c02241
NR
30383-stack-list-frames 3 3
30384^done,stack=
30385[frame=@{level="3",addr="0x000107a4",func="foo",
30386 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 30387(gdb)
922fbb7b
AC
30388@end smallexample
30389
922fbb7b 30390
a2c02241
NR
30391@subheading The @code{-stack-list-locals} Command
30392@findex -stack-list-locals
57c22c6c 30393
a2c02241 30394@subsubheading Synopsis
922fbb7b
AC
30395
30396@smallexample
a2c02241 30397 -stack-list-locals @var{print-values}
922fbb7b
AC
30398@end smallexample
30399
a2c02241
NR
30400Display the local variable names for the selected frame. If
30401@var{print-values} is 0 or @code{--no-values}, print only the names of
30402the variables; if it is 1 or @code{--all-values}, print also their
30403values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 30404type and value for simple data types, and the name and type for arrays,
a2c02241
NR
30405structures and unions. In this last case, a frontend can immediately
30406display the value of simple data types and create variable objects for
d3e8051b 30407other data types when the user wishes to explore their values in
a2c02241 30408more detail.
922fbb7b 30409
b3372f91
VP
30410This command is deprecated in favor of the
30411@samp{-stack-list-variables} command.
30412
922fbb7b
AC
30413@subsubheading @value{GDBN} Command
30414
a2c02241 30415@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
30416
30417@subsubheading Example
922fbb7b
AC
30418
30419@smallexample
594fe323 30420(gdb)
a2c02241
NR
30421-stack-list-locals 0
30422^done,locals=[name="A",name="B",name="C"]
594fe323 30423(gdb)
a2c02241
NR
30424-stack-list-locals --all-values
30425^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
30426 @{name="C",value="@{1, 2, 3@}"@}]
30427-stack-list-locals --simple-values
30428^done,locals=[@{name="A",type="int",value="1"@},
30429 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 30430(gdb)
922fbb7b
AC
30431@end smallexample
30432
b3372f91
VP
30433@subheading The @code{-stack-list-variables} Command
30434@findex -stack-list-variables
30435
30436@subsubheading Synopsis
30437
30438@smallexample
30439 -stack-list-variables @var{print-values}
30440@end smallexample
30441
30442Display the names of local variables and function arguments for the selected frame. If
30443@var{print-values} is 0 or @code{--no-values}, print only the names of
30444the variables; if it is 1 or @code{--all-values}, print also their
30445values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 30446type and value for simple data types, and the name and type for arrays,
b3372f91
VP
30447structures and unions.
30448
30449@subsubheading Example
30450
30451@smallexample
30452(gdb)
30453-stack-list-variables --thread 1 --frame 0 --all-values
4f412fd0 30454^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
b3372f91
VP
30455(gdb)
30456@end smallexample
30457
922fbb7b 30458
a2c02241
NR
30459@subheading The @code{-stack-select-frame} Command
30460@findex -stack-select-frame
922fbb7b
AC
30461
30462@subsubheading Synopsis
30463
30464@smallexample
a2c02241 30465 -stack-select-frame @var{framenum}
922fbb7b
AC
30466@end smallexample
30467
a2c02241
NR
30468Change the selected frame. Select a different frame @var{framenum} on
30469the stack.
922fbb7b 30470
c3b108f7
VP
30471This command in deprecated in favor of passing the @samp{--frame}
30472option to every command.
30473
922fbb7b
AC
30474@subsubheading @value{GDBN} Command
30475
a2c02241
NR
30476The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
30477@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
30478
30479@subsubheading Example
30480
30481@smallexample
594fe323 30482(gdb)
a2c02241 30483-stack-select-frame 2
922fbb7b 30484^done
594fe323 30485(gdb)
922fbb7b
AC
30486@end smallexample
30487
30488@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
30489@node GDB/MI Variable Objects
30490@section @sc{gdb/mi} Variable Objects
922fbb7b 30491
a1b5960f 30492@ignore
922fbb7b 30493
a2c02241 30494@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 30495
a2c02241
NR
30496For the implementation of a variable debugger window (locals, watched
30497expressions, etc.), we are proposing the adaptation of the existing code
30498used by @code{Insight}.
922fbb7b 30499
a2c02241 30500The two main reasons for that are:
922fbb7b 30501
a2c02241
NR
30502@enumerate 1
30503@item
30504It has been proven in practice (it is already on its second generation).
922fbb7b 30505
a2c02241
NR
30506@item
30507It will shorten development time (needless to say how important it is
30508now).
30509@end enumerate
922fbb7b 30510
a2c02241
NR
30511The original interface was designed to be used by Tcl code, so it was
30512slightly changed so it could be used through @sc{gdb/mi}. This section
30513describes the @sc{gdb/mi} operations that will be available and gives some
30514hints about their use.
922fbb7b 30515
a2c02241
NR
30516@emph{Note}: In addition to the set of operations described here, we
30517expect the @sc{gui} implementation of a variable window to require, at
30518least, the following operations:
922fbb7b 30519
a2c02241
NR
30520@itemize @bullet
30521@item @code{-gdb-show} @code{output-radix}
30522@item @code{-stack-list-arguments}
30523@item @code{-stack-list-locals}
30524@item @code{-stack-select-frame}
30525@end itemize
922fbb7b 30526
a1b5960f
VP
30527@end ignore
30528
c8b2f53c 30529@subheading Introduction to Variable Objects
922fbb7b 30530
a2c02241 30531@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
30532
30533Variable objects are "object-oriented" MI interface for examining and
30534changing values of expressions. Unlike some other MI interfaces that
30535work with expressions, variable objects are specifically designed for
30536simple and efficient presentation in the frontend. A variable object
30537is identified by string name. When a variable object is created, the
30538frontend specifies the expression for that variable object. The
30539expression can be a simple variable, or it can be an arbitrary complex
30540expression, and can even involve CPU registers. After creating a
30541variable object, the frontend can invoke other variable object
30542operations---for example to obtain or change the value of a variable
30543object, or to change display format.
30544
30545Variable objects have hierarchical tree structure. Any variable object
30546that corresponds to a composite type, such as structure in C, has
30547a number of child variable objects, for example corresponding to each
30548element of a structure. A child variable object can itself have
30549children, recursively. Recursion ends when we reach
25d5ea92
VP
30550leaf variable objects, which always have built-in types. Child variable
30551objects are created only by explicit request, so if a frontend
30552is not interested in the children of a particular variable object, no
30553child will be created.
c8b2f53c
VP
30554
30555For a leaf variable object it is possible to obtain its value as a
30556string, or set the value from a string. String value can be also
30557obtained for a non-leaf variable object, but it's generally a string
30558that only indicates the type of the object, and does not list its
30559contents. Assignment to a non-leaf variable object is not allowed.
30560
30561A frontend does not need to read the values of all variable objects each time
30562the program stops. Instead, MI provides an update command that lists all
30563variable objects whose values has changed since the last update
30564operation. This considerably reduces the amount of data that must
25d5ea92
VP
30565be transferred to the frontend. As noted above, children variable
30566objects are created on demand, and only leaf variable objects have a
30567real value. As result, gdb will read target memory only for leaf
30568variables that frontend has created.
30569
30570The automatic update is not always desirable. For example, a frontend
30571might want to keep a value of some expression for future reference,
30572and never update it. For another example, fetching memory is
30573relatively slow for embedded targets, so a frontend might want
30574to disable automatic update for the variables that are either not
30575visible on the screen, or ``closed''. This is possible using so
30576called ``frozen variable objects''. Such variable objects are never
30577implicitly updated.
922fbb7b 30578
c3b108f7
VP
30579Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
30580fixed variable object, the expression is parsed when the variable
30581object is created, including associating identifiers to specific
30582variables. The meaning of expression never changes. For a floating
30583variable object the values of variables whose names appear in the
30584expressions are re-evaluated every time in the context of the current
30585frame. Consider this example:
30586
30587@smallexample
30588void do_work(...)
30589@{
30590 struct work_state state;
30591
30592 if (...)
30593 do_work(...);
30594@}
30595@end smallexample
30596
30597If a fixed variable object for the @code{state} variable is created in
7a9dd1b2 30598this function, and we enter the recursive call, the variable
c3b108f7
VP
30599object will report the value of @code{state} in the top-level
30600@code{do_work} invocation. On the other hand, a floating variable
30601object will report the value of @code{state} in the current frame.
30602
30603If an expression specified when creating a fixed variable object
30604refers to a local variable, the variable object becomes bound to the
30605thread and frame in which the variable object is created. When such
30606variable object is updated, @value{GDBN} makes sure that the
30607thread/frame combination the variable object is bound to still exists,
30608and re-evaluates the variable object in context of that thread/frame.
30609
a2c02241
NR
30610The following is the complete set of @sc{gdb/mi} operations defined to
30611access this functionality:
922fbb7b 30612
a2c02241
NR
30613@multitable @columnfractions .4 .6
30614@item @strong{Operation}
30615@tab @strong{Description}
922fbb7b 30616
0cc7d26f
TT
30617@item @code{-enable-pretty-printing}
30618@tab enable Python-based pretty-printing
a2c02241
NR
30619@item @code{-var-create}
30620@tab create a variable object
30621@item @code{-var-delete}
22d8a470 30622@tab delete the variable object and/or its children
a2c02241
NR
30623@item @code{-var-set-format}
30624@tab set the display format of this variable
30625@item @code{-var-show-format}
30626@tab show the display format of this variable
30627@item @code{-var-info-num-children}
30628@tab tells how many children this object has
30629@item @code{-var-list-children}
30630@tab return a list of the object's children
30631@item @code{-var-info-type}
30632@tab show the type of this variable object
30633@item @code{-var-info-expression}
02142340
VP
30634@tab print parent-relative expression that this variable object represents
30635@item @code{-var-info-path-expression}
30636@tab print full expression that this variable object represents
a2c02241
NR
30637@item @code{-var-show-attributes}
30638@tab is this variable editable? does it exist here?
30639@item @code{-var-evaluate-expression}
30640@tab get the value of this variable
30641@item @code{-var-assign}
30642@tab set the value of this variable
30643@item @code{-var-update}
30644@tab update the variable and its children
25d5ea92
VP
30645@item @code{-var-set-frozen}
30646@tab set frozeness attribute
0cc7d26f
TT
30647@item @code{-var-set-update-range}
30648@tab set range of children to display on update
a2c02241 30649@end multitable
922fbb7b 30650
a2c02241
NR
30651In the next subsection we describe each operation in detail and suggest
30652how it can be used.
922fbb7b 30653
a2c02241 30654@subheading Description And Use of Operations on Variable Objects
922fbb7b 30655
0cc7d26f
TT
30656@subheading The @code{-enable-pretty-printing} Command
30657@findex -enable-pretty-printing
30658
30659@smallexample
30660-enable-pretty-printing
30661@end smallexample
30662
30663@value{GDBN} allows Python-based visualizers to affect the output of the
30664MI variable object commands. However, because there was no way to
30665implement this in a fully backward-compatible way, a front end must
30666request that this functionality be enabled.
30667
30668Once enabled, this feature cannot be disabled.
30669
30670Note that if Python support has not been compiled into @value{GDBN},
30671this command will still succeed (and do nothing).
30672
f43030c4
TT
30673This feature is currently (as of @value{GDBN} 7.0) experimental, and
30674may work differently in future versions of @value{GDBN}.
30675
a2c02241
NR
30676@subheading The @code{-var-create} Command
30677@findex -var-create
ef21caaf 30678
a2c02241 30679@subsubheading Synopsis
ef21caaf 30680
a2c02241
NR
30681@smallexample
30682 -var-create @{@var{name} | "-"@}
c3b108f7 30683 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
a2c02241
NR
30684@end smallexample
30685
30686This operation creates a variable object, which allows the monitoring of
30687a variable, the result of an expression, a memory cell or a CPU
30688register.
ef21caaf 30689
a2c02241
NR
30690The @var{name} parameter is the string by which the object can be
30691referenced. It must be unique. If @samp{-} is specified, the varobj
30692system will generate a string ``varNNNNNN'' automatically. It will be
c3b108f7 30693unique provided that one does not specify @var{name} of that format.
a2c02241 30694The command fails if a duplicate name is found.
ef21caaf 30695
a2c02241
NR
30696The frame under which the expression should be evaluated can be
30697specified by @var{frame-addr}. A @samp{*} indicates that the current
c3b108f7
VP
30698frame should be used. A @samp{@@} indicates that a floating variable
30699object must be created.
922fbb7b 30700
a2c02241
NR
30701@var{expression} is any expression valid on the current language set (must not
30702begin with a @samp{*}), or one of the following:
922fbb7b 30703
a2c02241
NR
30704@itemize @bullet
30705@item
30706@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 30707
a2c02241
NR
30708@item
30709@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 30710
a2c02241
NR
30711@item
30712@samp{$@var{regname}} --- a CPU register name
30713@end itemize
922fbb7b 30714
0cc7d26f
TT
30715@cindex dynamic varobj
30716A varobj's contents may be provided by a Python-based pretty-printer. In this
30717case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
30718have slightly different semantics in some cases. If the
30719@code{-enable-pretty-printing} command is not sent, then @value{GDBN}
30720will never create a dynamic varobj. This ensures backward
30721compatibility for existing clients.
30722
a2c02241 30723@subsubheading Result
922fbb7b 30724
0cc7d26f
TT
30725This operation returns attributes of the newly-created varobj. These
30726are:
30727
30728@table @samp
30729@item name
30730The name of the varobj.
30731
30732@item numchild
30733The number of children of the varobj. This number is not necessarily
30734reliable for a dynamic varobj. Instead, you must examine the
30735@samp{has_more} attribute.
30736
30737@item value
30738The varobj's scalar value. For a varobj whose type is some sort of
30739aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
30740will not be interesting.
30741
30742@item type
30743The varobj's type. This is a string representation of the type, as
8264ba82
AG
30744would be printed by the @value{GDBN} CLI. If @samp{print object}
30745(@pxref{Print Settings, set print object}) is set to @code{on}, the
30746@emph{actual} (derived) type of the object is shown rather than the
30747@emph{declared} one.
0cc7d26f
TT
30748
30749@item thread-id
30750If a variable object is bound to a specific thread, then this is the
30751thread's identifier.
30752
30753@item has_more
30754For a dynamic varobj, this indicates whether there appear to be any
30755children available. For a non-dynamic varobj, this will be 0.
30756
30757@item dynamic
30758This attribute will be present and have the value @samp{1} if the
30759varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
30760then this attribute will not be present.
30761
30762@item displayhint
30763A dynamic varobj can supply a display hint to the front end. The
30764value comes directly from the Python pretty-printer object's
4c374409 30765@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
30766@end table
30767
30768Typical output will look like this:
922fbb7b
AC
30769
30770@smallexample
0cc7d26f
TT
30771 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
30772 has_more="@var{has_more}"
dcaaae04
NR
30773@end smallexample
30774
a2c02241
NR
30775
30776@subheading The @code{-var-delete} Command
30777@findex -var-delete
922fbb7b
AC
30778
30779@subsubheading Synopsis
30780
30781@smallexample
22d8a470 30782 -var-delete [ -c ] @var{name}
922fbb7b
AC
30783@end smallexample
30784
a2c02241 30785Deletes a previously created variable object and all of its children.
22d8a470 30786With the @samp{-c} option, just deletes the children.
922fbb7b 30787
a2c02241 30788Returns an error if the object @var{name} is not found.
922fbb7b 30789
922fbb7b 30790
a2c02241
NR
30791@subheading The @code{-var-set-format} Command
30792@findex -var-set-format
922fbb7b 30793
a2c02241 30794@subsubheading Synopsis
922fbb7b
AC
30795
30796@smallexample
a2c02241 30797 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
30798@end smallexample
30799
a2c02241
NR
30800Sets the output format for the value of the object @var{name} to be
30801@var{format-spec}.
30802
de051565 30803@anchor{-var-set-format}
a2c02241
NR
30804The syntax for the @var{format-spec} is as follows:
30805
30806@smallexample
30807 @var{format-spec} @expansion{}
30808 @{binary | decimal | hexadecimal | octal | natural@}
30809@end smallexample
30810
c8b2f53c
VP
30811The natural format is the default format choosen automatically
30812based on the variable type (like decimal for an @code{int}, hex
30813for pointers, etc.).
30814
30815For a variable with children, the format is set only on the
30816variable itself, and the children are not affected.
a2c02241
NR
30817
30818@subheading The @code{-var-show-format} Command
30819@findex -var-show-format
922fbb7b
AC
30820
30821@subsubheading Synopsis
30822
30823@smallexample
a2c02241 30824 -var-show-format @var{name}
922fbb7b
AC
30825@end smallexample
30826
a2c02241 30827Returns the format used to display the value of the object @var{name}.
922fbb7b 30828
a2c02241
NR
30829@smallexample
30830 @var{format} @expansion{}
30831 @var{format-spec}
30832@end smallexample
922fbb7b 30833
922fbb7b 30834
a2c02241
NR
30835@subheading The @code{-var-info-num-children} Command
30836@findex -var-info-num-children
30837
30838@subsubheading Synopsis
30839
30840@smallexample
30841 -var-info-num-children @var{name}
30842@end smallexample
30843
30844Returns the number of children of a variable object @var{name}:
30845
30846@smallexample
30847 numchild=@var{n}
30848@end smallexample
30849
0cc7d26f
TT
30850Note that this number is not completely reliable for a dynamic varobj.
30851It will return the current number of children, but more children may
30852be available.
30853
a2c02241
NR
30854
30855@subheading The @code{-var-list-children} Command
30856@findex -var-list-children
30857
30858@subsubheading Synopsis
30859
30860@smallexample
0cc7d26f 30861 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
a2c02241 30862@end smallexample
b569d230 30863@anchor{-var-list-children}
a2c02241
NR
30864
30865Return a list of the children of the specified variable object and
30866create variable objects for them, if they do not already exist. With
f5011d11 30867a single argument or if @var{print-values} has a value of 0 or
a2c02241
NR
30868@code{--no-values}, print only the names of the variables; if
30869@var{print-values} is 1 or @code{--all-values}, also print their
30870values; and if it is 2 or @code{--simple-values} print the name and
30871value for simple data types and just the name for arrays, structures
30872and unions.
922fbb7b 30873
0cc7d26f
TT
30874@var{from} and @var{to}, if specified, indicate the range of children
30875to report. If @var{from} or @var{to} is less than zero, the range is
30876reset and all children will be reported. Otherwise, children starting
30877at @var{from} (zero-based) and up to and excluding @var{to} will be
30878reported.
30879
30880If a child range is requested, it will only affect the current call to
30881@code{-var-list-children}, but not future calls to @code{-var-update}.
30882For this, you must instead use @code{-var-set-update-range}. The
30883intent of this approach is to enable a front end to implement any
30884update approach it likes; for example, scrolling a view may cause the
30885front end to request more children with @code{-var-list-children}, and
30886then the front end could call @code{-var-set-update-range} with a
30887different range to ensure that future updates are restricted to just
30888the visible items.
30889
b569d230
EZ
30890For each child the following results are returned:
30891
30892@table @var
30893
30894@item name
30895Name of the variable object created for this child.
30896
30897@item exp
30898The expression to be shown to the user by the front end to designate this child.
30899For example this may be the name of a structure member.
30900
0cc7d26f
TT
30901For a dynamic varobj, this value cannot be used to form an
30902expression. There is no way to do this at all with a dynamic varobj.
30903
b569d230
EZ
30904For C/C@t{++} structures there are several pseudo children returned to
30905designate access qualifiers. For these pseudo children @var{exp} is
30906@samp{public}, @samp{private}, or @samp{protected}. In this case the
30907type and value are not present.
30908
0cc7d26f
TT
30909A dynamic varobj will not report the access qualifying
30910pseudo-children, regardless of the language. This information is not
30911available at all with a dynamic varobj.
30912
b569d230 30913@item numchild
0cc7d26f
TT
30914Number of children this child has. For a dynamic varobj, this will be
309150.
b569d230
EZ
30916
30917@item type
8264ba82
AG
30918The type of the child. If @samp{print object}
30919(@pxref{Print Settings, set print object}) is set to @code{on}, the
30920@emph{actual} (derived) type of the object is shown rather than the
30921@emph{declared} one.
b569d230
EZ
30922
30923@item value
30924If values were requested, this is the value.
30925
30926@item thread-id
30927If this variable object is associated with a thread, this is the thread id.
30928Otherwise this result is not present.
30929
30930@item frozen
30931If the variable object is frozen, this variable will be present with a value of 1.
30932@end table
30933
0cc7d26f
TT
30934The result may have its own attributes:
30935
30936@table @samp
30937@item displayhint
30938A dynamic varobj can supply a display hint to the front end. The
30939value comes directly from the Python pretty-printer object's
4c374409 30940@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
30941
30942@item has_more
30943This is an integer attribute which is nonzero if there are children
30944remaining after the end of the selected range.
30945@end table
30946
922fbb7b
AC
30947@subsubheading Example
30948
30949@smallexample
594fe323 30950(gdb)
a2c02241 30951 -var-list-children n
b569d230 30952 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 30953 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 30954(gdb)
a2c02241 30955 -var-list-children --all-values n
b569d230 30956 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 30957 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
30958@end smallexample
30959
922fbb7b 30960
a2c02241
NR
30961@subheading The @code{-var-info-type} Command
30962@findex -var-info-type
922fbb7b 30963
a2c02241
NR
30964@subsubheading Synopsis
30965
30966@smallexample
30967 -var-info-type @var{name}
30968@end smallexample
30969
30970Returns the type of the specified variable @var{name}. The type is
30971returned as a string in the same format as it is output by the
30972@value{GDBN} CLI:
30973
30974@smallexample
30975 type=@var{typename}
30976@end smallexample
30977
30978
30979@subheading The @code{-var-info-expression} Command
30980@findex -var-info-expression
922fbb7b
AC
30981
30982@subsubheading Synopsis
30983
30984@smallexample
a2c02241 30985 -var-info-expression @var{name}
922fbb7b
AC
30986@end smallexample
30987
02142340
VP
30988Returns a string that is suitable for presenting this
30989variable object in user interface. The string is generally
30990not valid expression in the current language, and cannot be evaluated.
30991
30992For example, if @code{a} is an array, and variable object
30993@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 30994
a2c02241 30995@smallexample
02142340
VP
30996(gdb) -var-info-expression A.1
30997^done,lang="C",exp="1"
a2c02241 30998@end smallexample
922fbb7b 30999
a2c02241 31000@noindent
02142340
VP
31001Here, the values of @code{lang} can be @code{@{"C" | "C++" | "Java"@}}.
31002
31003Note that the output of the @code{-var-list-children} command also
31004includes those expressions, so the @code{-var-info-expression} command
31005is of limited use.
31006
31007@subheading The @code{-var-info-path-expression} Command
31008@findex -var-info-path-expression
31009
31010@subsubheading Synopsis
31011
31012@smallexample
31013 -var-info-path-expression @var{name}
31014@end smallexample
31015
31016Returns an expression that can be evaluated in the current
31017context and will yield the same value that a variable object has.
31018Compare this with the @code{-var-info-expression} command, which
31019result can be used only for UI presentation. Typical use of
31020the @code{-var-info-path-expression} command is creating a
31021watchpoint from a variable object.
31022
0cc7d26f
TT
31023This command is currently not valid for children of a dynamic varobj,
31024and will give an error when invoked on one.
31025
02142340
VP
31026For example, suppose @code{C} is a C@t{++} class, derived from class
31027@code{Base}, and that the @code{Base} class has a member called
31028@code{m_size}. Assume a variable @code{c} is has the type of
31029@code{C} and a variable object @code{C} was created for variable
31030@code{c}. Then, we'll get this output:
31031@smallexample
31032(gdb) -var-info-path-expression C.Base.public.m_size
31033^done,path_expr=((Base)c).m_size)
31034@end smallexample
922fbb7b 31035
a2c02241
NR
31036@subheading The @code{-var-show-attributes} Command
31037@findex -var-show-attributes
922fbb7b 31038
a2c02241 31039@subsubheading Synopsis
922fbb7b 31040
a2c02241
NR
31041@smallexample
31042 -var-show-attributes @var{name}
31043@end smallexample
922fbb7b 31044
a2c02241 31045List attributes of the specified variable object @var{name}:
922fbb7b
AC
31046
31047@smallexample
a2c02241 31048 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
31049@end smallexample
31050
a2c02241
NR
31051@noindent
31052where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
31053
31054@subheading The @code{-var-evaluate-expression} Command
31055@findex -var-evaluate-expression
31056
31057@subsubheading Synopsis
31058
31059@smallexample
de051565 31060 -var-evaluate-expression [-f @var{format-spec}] @var{name}
a2c02241
NR
31061@end smallexample
31062
31063Evaluates the expression that is represented by the specified variable
de051565
MK
31064object and returns its value as a string. The format of the string
31065can be specified with the @samp{-f} option. The possible values of
31066this option are the same as for @code{-var-set-format}
31067(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
31068the current display format will be used. The current display format
31069can be changed using the @code{-var-set-format} command.
a2c02241
NR
31070
31071@smallexample
31072 value=@var{value}
31073@end smallexample
31074
31075Note that one must invoke @code{-var-list-children} for a variable
31076before the value of a child variable can be evaluated.
31077
31078@subheading The @code{-var-assign} Command
31079@findex -var-assign
31080
31081@subsubheading Synopsis
31082
31083@smallexample
31084 -var-assign @var{name} @var{expression}
31085@end smallexample
31086
31087Assigns the value of @var{expression} to the variable object specified
31088by @var{name}. The object must be @samp{editable}. If the variable's
31089value is altered by the assign, the variable will show up in any
31090subsequent @code{-var-update} list.
31091
31092@subsubheading Example
922fbb7b
AC
31093
31094@smallexample
594fe323 31095(gdb)
a2c02241
NR
31096-var-assign var1 3
31097^done,value="3"
594fe323 31098(gdb)
a2c02241
NR
31099-var-update *
31100^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 31101(gdb)
922fbb7b
AC
31102@end smallexample
31103
a2c02241
NR
31104@subheading The @code{-var-update} Command
31105@findex -var-update
31106
31107@subsubheading Synopsis
31108
31109@smallexample
31110 -var-update [@var{print-values}] @{@var{name} | "*"@}
31111@end smallexample
31112
c8b2f53c
VP
31113Reevaluate the expressions corresponding to the variable object
31114@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
31115list of variable objects whose values have changed; @var{name} must
31116be a root variable object. Here, ``changed'' means that the result of
31117@code{-var-evaluate-expression} before and after the
31118@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
31119object names, all existing variable objects are updated, except
31120for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3 31121@var{print-values} determines whether both names and values, or just
de051565 31122names are printed. The possible values of this option are the same
36ece8b3
NR
31123as for @code{-var-list-children} (@pxref{-var-list-children}). It is
31124recommended to use the @samp{--all-values} option, to reduce the
31125number of MI commands needed on each program stop.
c8b2f53c 31126
c3b108f7
VP
31127With the @samp{*} parameter, if a variable object is bound to a
31128currently running thread, it will not be updated, without any
31129diagnostic.
a2c02241 31130
0cc7d26f
TT
31131If @code{-var-set-update-range} was previously used on a varobj, then
31132only the selected range of children will be reported.
922fbb7b 31133
0cc7d26f
TT
31134@code{-var-update} reports all the changed varobjs in a tuple named
31135@samp{changelist}.
31136
31137Each item in the change list is itself a tuple holding:
31138
31139@table @samp
31140@item name
31141The name of the varobj.
31142
31143@item value
31144If values were requested for this update, then this field will be
31145present and will hold the value of the varobj.
922fbb7b 31146
0cc7d26f 31147@item in_scope
9f708cb2 31148@anchor{-var-update}
0cc7d26f 31149This field is a string which may take one of three values:
36ece8b3
NR
31150
31151@table @code
31152@item "true"
31153The variable object's current value is valid.
31154
31155@item "false"
31156The variable object does not currently hold a valid value but it may
31157hold one in the future if its associated expression comes back into
31158scope.
31159
31160@item "invalid"
31161The variable object no longer holds a valid value.
31162This can occur when the executable file being debugged has changed,
31163either through recompilation or by using the @value{GDBN} @code{file}
31164command. The front end should normally choose to delete these variable
31165objects.
31166@end table
31167
31168In the future new values may be added to this list so the front should
31169be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
31170
0cc7d26f
TT
31171@item type_changed
31172This is only present if the varobj is still valid. If the type
31173changed, then this will be the string @samp{true}; otherwise it will
31174be @samp{false}.
31175
7191c139
JB
31176When a varobj's type changes, its children are also likely to have
31177become incorrect. Therefore, the varobj's children are automatically
31178deleted when this attribute is @samp{true}. Also, the varobj's update
31179range, when set using the @code{-var-set-update-range} command, is
31180unset.
31181
0cc7d26f
TT
31182@item new_type
31183If the varobj's type changed, then this field will be present and will
31184hold the new type.
31185
31186@item new_num_children
31187For a dynamic varobj, if the number of children changed, or if the
31188type changed, this will be the new number of children.
31189
31190The @samp{numchild} field in other varobj responses is generally not
31191valid for a dynamic varobj -- it will show the number of children that
31192@value{GDBN} knows about, but because dynamic varobjs lazily
31193instantiate their children, this will not reflect the number of
31194children which may be available.
31195
31196The @samp{new_num_children} attribute only reports changes to the
31197number of children known by @value{GDBN}. This is the only way to
31198detect whether an update has removed children (which necessarily can
31199only happen at the end of the update range).
31200
31201@item displayhint
31202The display hint, if any.
31203
31204@item has_more
31205This is an integer value, which will be 1 if there are more children
31206available outside the varobj's update range.
31207
31208@item dynamic
31209This attribute will be present and have the value @samp{1} if the
31210varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
31211then this attribute will not be present.
31212
31213@item new_children
31214If new children were added to a dynamic varobj within the selected
31215update range (as set by @code{-var-set-update-range}), then they will
31216be listed in this attribute.
31217@end table
31218
31219@subsubheading Example
31220
31221@smallexample
31222(gdb)
31223-var-assign var1 3
31224^done,value="3"
31225(gdb)
31226-var-update --all-values var1
31227^done,changelist=[@{name="var1",value="3",in_scope="true",
31228type_changed="false"@}]
31229(gdb)
31230@end smallexample
31231
25d5ea92
VP
31232@subheading The @code{-var-set-frozen} Command
31233@findex -var-set-frozen
9f708cb2 31234@anchor{-var-set-frozen}
25d5ea92
VP
31235
31236@subsubheading Synopsis
31237
31238@smallexample
9f708cb2 31239 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
31240@end smallexample
31241
9f708cb2 31242Set the frozenness flag on the variable object @var{name}. The
25d5ea92 31243@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 31244frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 31245frozen, then neither itself, nor any of its children, are
9f708cb2 31246implicitly updated by @code{-var-update} of
25d5ea92
VP
31247a parent variable or by @code{-var-update *}. Only
31248@code{-var-update} of the variable itself will update its value and
31249values of its children. After a variable object is unfrozen, it is
31250implicitly updated by all subsequent @code{-var-update} operations.
31251Unfreezing a variable does not update it, only subsequent
31252@code{-var-update} does.
31253
31254@subsubheading Example
31255
31256@smallexample
31257(gdb)
31258-var-set-frozen V 1
31259^done
31260(gdb)
31261@end smallexample
31262
0cc7d26f
TT
31263@subheading The @code{-var-set-update-range} command
31264@findex -var-set-update-range
31265@anchor{-var-set-update-range}
31266
31267@subsubheading Synopsis
31268
31269@smallexample
31270 -var-set-update-range @var{name} @var{from} @var{to}
31271@end smallexample
31272
31273Set the range of children to be returned by future invocations of
31274@code{-var-update}.
31275
31276@var{from} and @var{to} indicate the range of children to report. If
31277@var{from} or @var{to} is less than zero, the range is reset and all
31278children will be reported. Otherwise, children starting at @var{from}
31279(zero-based) and up to and excluding @var{to} will be reported.
31280
31281@subsubheading Example
31282
31283@smallexample
31284(gdb)
31285-var-set-update-range V 1 2
31286^done
31287@end smallexample
31288
b6313243
TT
31289@subheading The @code{-var-set-visualizer} command
31290@findex -var-set-visualizer
31291@anchor{-var-set-visualizer}
31292
31293@subsubheading Synopsis
31294
31295@smallexample
31296 -var-set-visualizer @var{name} @var{visualizer}
31297@end smallexample
31298
31299Set a visualizer for the variable object @var{name}.
31300
31301@var{visualizer} is the visualizer to use. The special value
31302@samp{None} means to disable any visualizer in use.
31303
31304If not @samp{None}, @var{visualizer} must be a Python expression.
31305This expression must evaluate to a callable object which accepts a
31306single argument. @value{GDBN} will call this object with the value of
31307the varobj @var{name} as an argument (this is done so that the same
31308Python pretty-printing code can be used for both the CLI and MI).
31309When called, this object must return an object which conforms to the
4c374409 31310pretty-printing interface (@pxref{Pretty Printing API}).
b6313243
TT
31311
31312The pre-defined function @code{gdb.default_visualizer} may be used to
31313select a visualizer by following the built-in process
31314(@pxref{Selecting Pretty-Printers}). This is done automatically when
31315a varobj is created, and so ordinarily is not needed.
31316
31317This feature is only available if Python support is enabled. The MI
31318command @code{-list-features} (@pxref{GDB/MI Miscellaneous Commands})
31319can be used to check this.
31320
31321@subsubheading Example
31322
31323Resetting the visualizer:
31324
31325@smallexample
31326(gdb)
31327-var-set-visualizer V None
31328^done
31329@end smallexample
31330
31331Reselecting the default (type-based) visualizer:
31332
31333@smallexample
31334(gdb)
31335-var-set-visualizer V gdb.default_visualizer
31336^done
31337@end smallexample
31338
31339Suppose @code{SomeClass} is a visualizer class. A lambda expression
31340can be used to instantiate this class for a varobj:
31341
31342@smallexample
31343(gdb)
31344-var-set-visualizer V "lambda val: SomeClass()"
31345^done
31346@end smallexample
25d5ea92 31347
a2c02241
NR
31348@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31349@node GDB/MI Data Manipulation
31350@section @sc{gdb/mi} Data Manipulation
922fbb7b 31351
a2c02241
NR
31352@cindex data manipulation, in @sc{gdb/mi}
31353@cindex @sc{gdb/mi}, data manipulation
31354This section describes the @sc{gdb/mi} commands that manipulate data:
31355examine memory and registers, evaluate expressions, etc.
31356
31357@c REMOVED FROM THE INTERFACE.
31358@c @subheading -data-assign
31359@c Change the value of a program variable. Plenty of side effects.
79a6e687 31360@c @subsubheading GDB Command
a2c02241
NR
31361@c set variable
31362@c @subsubheading Example
31363@c N.A.
31364
31365@subheading The @code{-data-disassemble} Command
31366@findex -data-disassemble
922fbb7b
AC
31367
31368@subsubheading Synopsis
31369
31370@smallexample
a2c02241
NR
31371 -data-disassemble
31372 [ -s @var{start-addr} -e @var{end-addr} ]
31373 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
31374 -- @var{mode}
922fbb7b
AC
31375@end smallexample
31376
a2c02241
NR
31377@noindent
31378Where:
31379
31380@table @samp
31381@item @var{start-addr}
31382is the beginning address (or @code{$pc})
31383@item @var{end-addr}
31384is the end address
31385@item @var{filename}
31386is the name of the file to disassemble
31387@item @var{linenum}
31388is the line number to disassemble around
31389@item @var{lines}
d3e8051b 31390is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
31391the whole function will be disassembled, in case no @var{end-addr} is
31392specified. If @var{end-addr} is specified as a non-zero value, and
31393@var{lines} is lower than the number of disassembly lines between
31394@var{start-addr} and @var{end-addr}, only @var{lines} lines are
31395displayed; if @var{lines} is higher than the number of lines between
31396@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
31397are displayed.
31398@item @var{mode}
b716877b
AB
31399is either 0 (meaning only disassembly), 1 (meaning mixed source and
31400disassembly), 2 (meaning disassembly with raw opcodes), or 3 (meaning
31401mixed source and disassembly with raw opcodes).
a2c02241
NR
31402@end table
31403
31404@subsubheading Result
31405
ed8a1c2d
AB
31406The result of the @code{-data-disassemble} command will be a list named
31407@samp{asm_insns}, the contents of this list depend on the @var{mode}
31408used with the @code{-data-disassemble} command.
a2c02241 31409
ed8a1c2d
AB
31410For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
31411following fields:
31412
31413@table @code
31414@item address
31415The address at which this instruction was disassembled.
31416
31417@item func-name
31418The name of the function this instruction is within.
31419
31420@item offset
31421The decimal offset in bytes from the start of @samp{func-name}.
31422
31423@item inst
31424The text disassembly for this @samp{address}.
31425
31426@item opcodes
31427This field is only present for mode 2. This contains the raw opcode
31428bytes for the @samp{inst} field.
31429
31430@end table
31431
31432For modes 1 and 3 the @samp{asm_insns} list contains tuples named
31433@samp{src_and_asm_line}, each of which has the following fields:
a2c02241 31434
ed8a1c2d
AB
31435@table @code
31436@item line
31437The line number within @samp{file}.
31438
31439@item file
31440The file name from the compilation unit. This might be an absolute
31441file name or a relative file name depending on the compile command
31442used.
31443
31444@item fullname
f35a17b5
JK
31445Absolute file name of @samp{file}. It is converted to a canonical form
31446using the source file search path
31447(@pxref{Source Path, ,Specifying Source Directories})
31448and after resolving all the symbolic links.
31449
31450If the source file is not found this field will contain the path as
31451present in the debug information.
ed8a1c2d
AB
31452
31453@item line_asm_insn
31454This is a list of tuples containing the disassembly for @samp{line} in
31455@samp{file}. The fields of each tuple are the same as for
31456@code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
31457@samp{func-name}, @samp{offset}, @samp{inst}, and optionally
31458@samp{opcodes}.
31459
31460@end table
31461
31462Note that whatever included in the @samp{inst} field, is not
31463manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
31464adjust its format.
922fbb7b
AC
31465
31466@subsubheading @value{GDBN} Command
31467
ed8a1c2d 31468The corresponding @value{GDBN} command is @samp{disassemble}.
922fbb7b
AC
31469
31470@subsubheading Example
31471
a2c02241
NR
31472Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
31473
922fbb7b 31474@smallexample
594fe323 31475(gdb)
a2c02241
NR
31476-data-disassemble -s $pc -e "$pc + 20" -- 0
31477^done,
31478asm_insns=[
31479@{address="0x000107c0",func-name="main",offset="4",
31480inst="mov 2, %o0"@},
31481@{address="0x000107c4",func-name="main",offset="8",
31482inst="sethi %hi(0x11800), %o2"@},
31483@{address="0x000107c8",func-name="main",offset="12",
31484inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
31485@{address="0x000107cc",func-name="main",offset="16",
31486inst="sethi %hi(0x11800), %o2"@},
31487@{address="0x000107d0",func-name="main",offset="20",
31488inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 31489(gdb)
a2c02241
NR
31490@end smallexample
31491
31492Disassemble the whole @code{main} function. Line 32 is part of
31493@code{main}.
31494
31495@smallexample
31496-data-disassemble -f basics.c -l 32 -- 0
31497^done,asm_insns=[
31498@{address="0x000107bc",func-name="main",offset="0",
31499inst="save %sp, -112, %sp"@},
31500@{address="0x000107c0",func-name="main",offset="4",
31501inst="mov 2, %o0"@},
31502@{address="0x000107c4",func-name="main",offset="8",
31503inst="sethi %hi(0x11800), %o2"@},
31504[@dots{}]
31505@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
31506@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 31507(gdb)
922fbb7b
AC
31508@end smallexample
31509
a2c02241 31510Disassemble 3 instructions from the start of @code{main}:
922fbb7b 31511
a2c02241 31512@smallexample
594fe323 31513(gdb)
a2c02241
NR
31514-data-disassemble -f basics.c -l 32 -n 3 -- 0
31515^done,asm_insns=[
31516@{address="0x000107bc",func-name="main",offset="0",
31517inst="save %sp, -112, %sp"@},
31518@{address="0x000107c0",func-name="main",offset="4",
31519inst="mov 2, %o0"@},
31520@{address="0x000107c4",func-name="main",offset="8",
31521inst="sethi %hi(0x11800), %o2"@}]
594fe323 31522(gdb)
a2c02241
NR
31523@end smallexample
31524
31525Disassemble 3 instructions from the start of @code{main} in mixed mode:
31526
31527@smallexample
594fe323 31528(gdb)
a2c02241
NR
31529-data-disassemble -f basics.c -l 32 -n 3 -- 1
31530^done,asm_insns=[
31531src_and_asm_line=@{line="31",
ed8a1c2d
AB
31532file="../../../src/gdb/testsuite/gdb.mi/basics.c",
31533fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
31534line_asm_insn=[@{address="0x000107bc",
31535func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
a2c02241 31536src_and_asm_line=@{line="32",
ed8a1c2d
AB
31537file="../../../src/gdb/testsuite/gdb.mi/basics.c",
31538fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
31539line_asm_insn=[@{address="0x000107c0",
31540func-name="main",offset="4",inst="mov 2, %o0"@},
a2c02241
NR
31541@{address="0x000107c4",func-name="main",offset="8",
31542inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 31543(gdb)
a2c02241
NR
31544@end smallexample
31545
31546
31547@subheading The @code{-data-evaluate-expression} Command
31548@findex -data-evaluate-expression
922fbb7b
AC
31549
31550@subsubheading Synopsis
31551
31552@smallexample
a2c02241 31553 -data-evaluate-expression @var{expr}
922fbb7b
AC
31554@end smallexample
31555
a2c02241
NR
31556Evaluate @var{expr} as an expression. The expression could contain an
31557inferior function call. The function call will execute synchronously.
31558If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
31559
31560@subsubheading @value{GDBN} Command
31561
a2c02241
NR
31562The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
31563@samp{call}. In @code{gdbtk} only, there's a corresponding
31564@samp{gdb_eval} command.
922fbb7b
AC
31565
31566@subsubheading Example
31567
a2c02241
NR
31568In the following example, the numbers that precede the commands are the
31569@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
31570Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
31571output.
31572
922fbb7b 31573@smallexample
a2c02241
NR
31574211-data-evaluate-expression A
31575211^done,value="1"
594fe323 31576(gdb)
a2c02241
NR
31577311-data-evaluate-expression &A
31578311^done,value="0xefffeb7c"
594fe323 31579(gdb)
a2c02241
NR
31580411-data-evaluate-expression A+3
31581411^done,value="4"
594fe323 31582(gdb)
a2c02241
NR
31583511-data-evaluate-expression "A + 3"
31584511^done,value="4"
594fe323 31585(gdb)
a2c02241 31586@end smallexample
922fbb7b
AC
31587
31588
a2c02241
NR
31589@subheading The @code{-data-list-changed-registers} Command
31590@findex -data-list-changed-registers
922fbb7b
AC
31591
31592@subsubheading Synopsis
31593
31594@smallexample
a2c02241 31595 -data-list-changed-registers
922fbb7b
AC
31596@end smallexample
31597
a2c02241 31598Display a list of the registers that have changed.
922fbb7b
AC
31599
31600@subsubheading @value{GDBN} Command
31601
a2c02241
NR
31602@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
31603has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
31604
31605@subsubheading Example
922fbb7b 31606
a2c02241 31607On a PPC MBX board:
922fbb7b
AC
31608
31609@smallexample
594fe323 31610(gdb)
a2c02241
NR
31611-exec-continue
31612^running
922fbb7b 31613
594fe323 31614(gdb)
a47ec5fe
AR
31615*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
31616func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
31617line="5"@}
594fe323 31618(gdb)
a2c02241
NR
31619-data-list-changed-registers
31620^done,changed-registers=["0","1","2","4","5","6","7","8","9",
31621"10","11","13","14","15","16","17","18","19","20","21","22","23",
31622"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 31623(gdb)
a2c02241 31624@end smallexample
922fbb7b
AC
31625
31626
a2c02241
NR
31627@subheading The @code{-data-list-register-names} Command
31628@findex -data-list-register-names
922fbb7b
AC
31629
31630@subsubheading Synopsis
31631
31632@smallexample
a2c02241 31633 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
31634@end smallexample
31635
a2c02241
NR
31636Show a list of register names for the current target. If no arguments
31637are given, it shows a list of the names of all the registers. If
31638integer numbers are given as arguments, it will print a list of the
31639names of the registers corresponding to the arguments. To ensure
31640consistency between a register name and its number, the output list may
31641include empty register names.
922fbb7b
AC
31642
31643@subsubheading @value{GDBN} Command
31644
a2c02241
NR
31645@value{GDBN} does not have a command which corresponds to
31646@samp{-data-list-register-names}. In @code{gdbtk} there is a
31647corresponding command @samp{gdb_regnames}.
922fbb7b
AC
31648
31649@subsubheading Example
922fbb7b 31650
a2c02241
NR
31651For the PPC MBX board:
31652@smallexample
594fe323 31653(gdb)
a2c02241
NR
31654-data-list-register-names
31655^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
31656"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
31657"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
31658"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
31659"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
31660"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
31661"", "pc","ps","cr","lr","ctr","xer"]
594fe323 31662(gdb)
a2c02241
NR
31663-data-list-register-names 1 2 3
31664^done,register-names=["r1","r2","r3"]
594fe323 31665(gdb)
a2c02241 31666@end smallexample
922fbb7b 31667
a2c02241
NR
31668@subheading The @code{-data-list-register-values} Command
31669@findex -data-list-register-values
922fbb7b
AC
31670
31671@subsubheading Synopsis
31672
31673@smallexample
a2c02241 31674 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
31675@end smallexample
31676
a2c02241
NR
31677Display the registers' contents. @var{fmt} is the format according to
31678which the registers' contents are to be returned, followed by an optional
31679list of numbers specifying the registers to display. A missing list of
31680numbers indicates that the contents of all the registers must be returned.
31681
31682Allowed formats for @var{fmt} are:
31683
31684@table @code
31685@item x
31686Hexadecimal
31687@item o
31688Octal
31689@item t
31690Binary
31691@item d
31692Decimal
31693@item r
31694Raw
31695@item N
31696Natural
31697@end table
922fbb7b
AC
31698
31699@subsubheading @value{GDBN} Command
31700
a2c02241
NR
31701The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
31702all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
31703
31704@subsubheading Example
922fbb7b 31705
a2c02241
NR
31706For a PPC MBX board (note: line breaks are for readability only, they
31707don't appear in the actual output):
31708
31709@smallexample
594fe323 31710(gdb)
a2c02241
NR
31711-data-list-register-values r 64 65
31712^done,register-values=[@{number="64",value="0xfe00a300"@},
31713@{number="65",value="0x00029002"@}]
594fe323 31714(gdb)
a2c02241
NR
31715-data-list-register-values x
31716^done,register-values=[@{number="0",value="0xfe0043c8"@},
31717@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
31718@{number="3",value="0x0"@},@{number="4",value="0xa"@},
31719@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
31720@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
31721@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
31722@{number="11",value="0x1"@},@{number="12",value="0x0"@},
31723@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
31724@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
31725@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
31726@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
31727@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
31728@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
31729@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
31730@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
31731@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
31732@{number="31",value="0x0"@},@{number="32",value="0x0"@},
31733@{number="33",value="0x0"@},@{number="34",value="0x0"@},
31734@{number="35",value="0x0"@},@{number="36",value="0x0"@},
31735@{number="37",value="0x0"@},@{number="38",value="0x0"@},
31736@{number="39",value="0x0"@},@{number="40",value="0x0"@},
31737@{number="41",value="0x0"@},@{number="42",value="0x0"@},
31738@{number="43",value="0x0"@},@{number="44",value="0x0"@},
31739@{number="45",value="0x0"@},@{number="46",value="0x0"@},
31740@{number="47",value="0x0"@},@{number="48",value="0x0"@},
31741@{number="49",value="0x0"@},@{number="50",value="0x0"@},
31742@{number="51",value="0x0"@},@{number="52",value="0x0"@},
31743@{number="53",value="0x0"@},@{number="54",value="0x0"@},
31744@{number="55",value="0x0"@},@{number="56",value="0x0"@},
31745@{number="57",value="0x0"@},@{number="58",value="0x0"@},
31746@{number="59",value="0x0"@},@{number="60",value="0x0"@},
31747@{number="61",value="0x0"@},@{number="62",value="0x0"@},
31748@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
31749@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
31750@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
31751@{number="69",value="0x20002b03"@}]
594fe323 31752(gdb)
a2c02241 31753@end smallexample
922fbb7b 31754
a2c02241
NR
31755
31756@subheading The @code{-data-read-memory} Command
31757@findex -data-read-memory
922fbb7b 31758
8dedea02
VP
31759This command is deprecated, use @code{-data-read-memory-bytes} instead.
31760
922fbb7b
AC
31761@subsubheading Synopsis
31762
31763@smallexample
a2c02241
NR
31764 -data-read-memory [ -o @var{byte-offset} ]
31765 @var{address} @var{word-format} @var{word-size}
31766 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
31767@end smallexample
31768
a2c02241
NR
31769@noindent
31770where:
922fbb7b 31771
a2c02241
NR
31772@table @samp
31773@item @var{address}
31774An expression specifying the address of the first memory word to be
31775read. Complex expressions containing embedded white space should be
31776quoted using the C convention.
922fbb7b 31777
a2c02241
NR
31778@item @var{word-format}
31779The format to be used to print the memory words. The notation is the
31780same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 31781,Output Formats}).
922fbb7b 31782
a2c02241
NR
31783@item @var{word-size}
31784The size of each memory word in bytes.
922fbb7b 31785
a2c02241
NR
31786@item @var{nr-rows}
31787The number of rows in the output table.
922fbb7b 31788
a2c02241
NR
31789@item @var{nr-cols}
31790The number of columns in the output table.
922fbb7b 31791
a2c02241
NR
31792@item @var{aschar}
31793If present, indicates that each row should include an @sc{ascii} dump. The
31794value of @var{aschar} is used as a padding character when a byte is not a
31795member of the printable @sc{ascii} character set (printable @sc{ascii}
31796characters are those whose code is between 32 and 126, inclusively).
922fbb7b 31797
a2c02241
NR
31798@item @var{byte-offset}
31799An offset to add to the @var{address} before fetching memory.
31800@end table
922fbb7b 31801
a2c02241
NR
31802This command displays memory contents as a table of @var{nr-rows} by
31803@var{nr-cols} words, each word being @var{word-size} bytes. In total,
31804@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
31805(returned as @samp{total-bytes}). Should less than the requested number
31806of bytes be returned by the target, the missing words are identified
31807using @samp{N/A}. The number of bytes read from the target is returned
31808in @samp{nr-bytes} and the starting address used to read memory in
31809@samp{addr}.
31810
31811The address of the next/previous row or page is available in
31812@samp{next-row} and @samp{prev-row}, @samp{next-page} and
31813@samp{prev-page}.
922fbb7b
AC
31814
31815@subsubheading @value{GDBN} Command
31816
a2c02241
NR
31817The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
31818@samp{gdb_get_mem} memory read command.
922fbb7b
AC
31819
31820@subsubheading Example
32e7087d 31821
a2c02241
NR
31822Read six bytes of memory starting at @code{bytes+6} but then offset by
31823@code{-6} bytes. Format as three rows of two columns. One byte per
31824word. Display each word in hex.
32e7087d
JB
31825
31826@smallexample
594fe323 31827(gdb)
a2c02241
NR
318289-data-read-memory -o -6 -- bytes+6 x 1 3 2
318299^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
31830next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
31831prev-page="0x0000138a",memory=[
31832@{addr="0x00001390",data=["0x00","0x01"]@},
31833@{addr="0x00001392",data=["0x02","0x03"]@},
31834@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 31835(gdb)
32e7087d
JB
31836@end smallexample
31837
a2c02241
NR
31838Read two bytes of memory starting at address @code{shorts + 64} and
31839display as a single word formatted in decimal.
32e7087d 31840
32e7087d 31841@smallexample
594fe323 31842(gdb)
a2c02241
NR
318435-data-read-memory shorts+64 d 2 1 1
318445^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
31845next-row="0x00001512",prev-row="0x0000150e",
31846next-page="0x00001512",prev-page="0x0000150e",memory=[
31847@{addr="0x00001510",data=["128"]@}]
594fe323 31848(gdb)
32e7087d
JB
31849@end smallexample
31850
a2c02241
NR
31851Read thirty two bytes of memory starting at @code{bytes+16} and format
31852as eight rows of four columns. Include a string encoding with @samp{x}
31853used as the non-printable character.
922fbb7b
AC
31854
31855@smallexample
594fe323 31856(gdb)
a2c02241
NR
318574-data-read-memory bytes+16 x 1 8 4 x
318584^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
31859next-row="0x000013c0",prev-row="0x0000139c",
31860next-page="0x000013c0",prev-page="0x00001380",memory=[
31861@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
31862@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
31863@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
31864@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
31865@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
31866@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
31867@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
31868@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 31869(gdb)
922fbb7b
AC
31870@end smallexample
31871
8dedea02
VP
31872@subheading The @code{-data-read-memory-bytes} Command
31873@findex -data-read-memory-bytes
31874
31875@subsubheading Synopsis
31876
31877@smallexample
31878 -data-read-memory-bytes [ -o @var{byte-offset} ]
31879 @var{address} @var{count}
31880@end smallexample
31881
31882@noindent
31883where:
31884
31885@table @samp
31886@item @var{address}
31887An expression specifying the address of the first memory word to be
31888read. Complex expressions containing embedded white space should be
31889quoted using the C convention.
31890
31891@item @var{count}
31892The number of bytes to read. This should be an integer literal.
31893
31894@item @var{byte-offset}
31895The offsets in bytes relative to @var{address} at which to start
31896reading. This should be an integer literal. This option is provided
31897so that a frontend is not required to first evaluate address and then
31898perform address arithmetics itself.
31899
31900@end table
31901
31902This command attempts to read all accessible memory regions in the
31903specified range. First, all regions marked as unreadable in the memory
31904map (if one is defined) will be skipped. @xref{Memory Region
31905Attributes}. Second, @value{GDBN} will attempt to read the remaining
31906regions. For each one, if reading full region results in an errors,
31907@value{GDBN} will try to read a subset of the region.
31908
31909In general, every single byte in the region may be readable or not,
31910and the only way to read every readable byte is to try a read at
31911every address, which is not practical. Therefore, @value{GDBN} will
31912attempt to read all accessible bytes at either beginning or the end
31913of the region, using a binary division scheme. This heuristic works
31914well for reading accross a memory map boundary. Note that if a region
31915has a readable range that is neither at the beginning or the end,
31916@value{GDBN} will not read it.
31917
31918The result record (@pxref{GDB/MI Result Records}) that is output of
31919the command includes a field named @samp{memory} whose content is a
31920list of tuples. Each tuple represent a successfully read memory block
31921and has the following fields:
31922
31923@table @code
31924@item begin
31925The start address of the memory block, as hexadecimal literal.
31926
31927@item end
31928The end address of the memory block, as hexadecimal literal.
31929
31930@item offset
31931The offset of the memory block, as hexadecimal literal, relative to
31932the start address passed to @code{-data-read-memory-bytes}.
31933
31934@item contents
31935The contents of the memory block, in hex.
31936
31937@end table
31938
31939
31940
31941@subsubheading @value{GDBN} Command
31942
31943The corresponding @value{GDBN} command is @samp{x}.
31944
31945@subsubheading Example
31946
31947@smallexample
31948(gdb)
31949-data-read-memory-bytes &a 10
31950^done,memory=[@{begin="0xbffff154",offset="0x00000000",
31951 end="0xbffff15e",
31952 contents="01000000020000000300"@}]
31953(gdb)
31954@end smallexample
31955
31956
31957@subheading The @code{-data-write-memory-bytes} Command
31958@findex -data-write-memory-bytes
31959
31960@subsubheading Synopsis
31961
31962@smallexample
31963 -data-write-memory-bytes @var{address} @var{contents}
62747a60 31964 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
8dedea02
VP
31965@end smallexample
31966
31967@noindent
31968where:
31969
31970@table @samp
31971@item @var{address}
31972An expression specifying the address of the first memory word to be
31973read. Complex expressions containing embedded white space should be
31974quoted using the C convention.
31975
31976@item @var{contents}
31977The hex-encoded bytes to write.
31978
62747a60
TT
31979@item @var{count}
31980Optional argument indicating the number of bytes to be written. If @var{count}
31981is greater than @var{contents}' length, @value{GDBN} will repeatedly
31982write @var{contents} until it fills @var{count} bytes.
31983
8dedea02
VP
31984@end table
31985
31986@subsubheading @value{GDBN} Command
31987
31988There's no corresponding @value{GDBN} command.
31989
31990@subsubheading Example
31991
31992@smallexample
31993(gdb)
31994-data-write-memory-bytes &a "aabbccdd"
31995^done
31996(gdb)
31997@end smallexample
31998
62747a60
TT
31999@smallexample
32000(gdb)
32001-data-write-memory-bytes &a "aabbccdd" 16e
32002^done
32003(gdb)
32004@end smallexample
8dedea02 32005
a2c02241
NR
32006@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32007@node GDB/MI Tracepoint Commands
32008@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 32009
18148017
VP
32010The commands defined in this section implement MI support for
32011tracepoints. For detailed introduction, see @ref{Tracepoints}.
32012
32013@subheading The @code{-trace-find} Command
32014@findex -trace-find
32015
32016@subsubheading Synopsis
32017
32018@smallexample
32019 -trace-find @var{mode} [@var{parameters}@dots{}]
32020@end smallexample
32021
32022Find a trace frame using criteria defined by @var{mode} and
32023@var{parameters}. The following table lists permissible
32024modes and their parameters. For details of operation, see @ref{tfind}.
32025
32026@table @samp
32027
32028@item none
32029No parameters are required. Stops examining trace frames.
32030
32031@item frame-number
32032An integer is required as parameter. Selects tracepoint frame with
32033that index.
32034
32035@item tracepoint-number
32036An integer is required as parameter. Finds next
32037trace frame that corresponds to tracepoint with the specified number.
32038
32039@item pc
32040An address is required as parameter. Finds
32041next trace frame that corresponds to any tracepoint at the specified
32042address.
32043
32044@item pc-inside-range
32045Two addresses are required as parameters. Finds next trace
32046frame that corresponds to a tracepoint at an address inside the
32047specified range. Both bounds are considered to be inside the range.
32048
32049@item pc-outside-range
32050Two addresses are required as parameters. Finds
32051next trace frame that corresponds to a tracepoint at an address outside
32052the specified range. Both bounds are considered to be inside the range.
32053
32054@item line
32055Line specification is required as parameter. @xref{Specify Location}.
32056Finds next trace frame that corresponds to a tracepoint at
32057the specified location.
32058
32059@end table
32060
32061If @samp{none} was passed as @var{mode}, the response does not
32062have fields. Otherwise, the response may have the following fields:
32063
32064@table @samp
32065@item found
32066This field has either @samp{0} or @samp{1} as the value, depending
32067on whether a matching tracepoint was found.
32068
32069@item traceframe
32070The index of the found traceframe. This field is present iff
32071the @samp{found} field has value of @samp{1}.
32072
32073@item tracepoint
32074The index of the found tracepoint. This field is present iff
32075the @samp{found} field has value of @samp{1}.
32076
32077@item frame
32078The information about the frame corresponding to the found trace
32079frame. This field is present only if a trace frame was found.
cd64ee31 32080@xref{GDB/MI Frame Information}, for description of this field.
18148017
VP
32081
32082@end table
32083
7d13fe92
SS
32084@subsubheading @value{GDBN} Command
32085
32086The corresponding @value{GDBN} command is @samp{tfind}.
32087
18148017
VP
32088@subheading -trace-define-variable
32089@findex -trace-define-variable
32090
32091@subsubheading Synopsis
32092
32093@smallexample
32094 -trace-define-variable @var{name} [ @var{value} ]
32095@end smallexample
32096
32097Create trace variable @var{name} if it does not exist. If
32098@var{value} is specified, sets the initial value of the specified
32099trace variable to that value. Note that the @var{name} should start
32100with the @samp{$} character.
32101
7d13fe92
SS
32102@subsubheading @value{GDBN} Command
32103
32104The corresponding @value{GDBN} command is @samp{tvariable}.
32105
18148017
VP
32106@subheading -trace-list-variables
32107@findex -trace-list-variables
922fbb7b 32108
18148017 32109@subsubheading Synopsis
922fbb7b 32110
18148017
VP
32111@smallexample
32112 -trace-list-variables
32113@end smallexample
922fbb7b 32114
18148017
VP
32115Return a table of all defined trace variables. Each element of the
32116table has the following fields:
922fbb7b 32117
18148017
VP
32118@table @samp
32119@item name
32120The name of the trace variable. This field is always present.
922fbb7b 32121
18148017
VP
32122@item initial
32123The initial value. This is a 64-bit signed integer. This
32124field is always present.
922fbb7b 32125
18148017
VP
32126@item current
32127The value the trace variable has at the moment. This is a 64-bit
32128signed integer. This field is absent iff current value is
32129not defined, for example if the trace was never run, or is
32130presently running.
922fbb7b 32131
18148017 32132@end table
922fbb7b 32133
7d13fe92
SS
32134@subsubheading @value{GDBN} Command
32135
32136The corresponding @value{GDBN} command is @samp{tvariables}.
32137
18148017 32138@subsubheading Example
922fbb7b 32139
18148017
VP
32140@smallexample
32141(gdb)
32142-trace-list-variables
32143^done,trace-variables=@{nr_rows="1",nr_cols="3",
32144hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
32145 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
32146 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
32147body=[variable=@{name="$trace_timestamp",initial="0"@}
32148 variable=@{name="$foo",initial="10",current="15"@}]@}
32149(gdb)
32150@end smallexample
922fbb7b 32151
18148017
VP
32152@subheading -trace-save
32153@findex -trace-save
922fbb7b 32154
18148017
VP
32155@subsubheading Synopsis
32156
32157@smallexample
32158 -trace-save [-r ] @var{filename}
32159@end smallexample
32160
32161Saves the collected trace data to @var{filename}. Without the
32162@samp{-r} option, the data is downloaded from the target and saved
32163in a local file. With the @samp{-r} option the target is asked
32164to perform the save.
32165
7d13fe92
SS
32166@subsubheading @value{GDBN} Command
32167
32168The corresponding @value{GDBN} command is @samp{tsave}.
32169
18148017
VP
32170
32171@subheading -trace-start
32172@findex -trace-start
32173
32174@subsubheading Synopsis
32175
32176@smallexample
32177 -trace-start
32178@end smallexample
922fbb7b 32179
18148017
VP
32180Starts a tracing experiments. The result of this command does not
32181have any fields.
922fbb7b 32182
7d13fe92
SS
32183@subsubheading @value{GDBN} Command
32184
32185The corresponding @value{GDBN} command is @samp{tstart}.
32186
18148017
VP
32187@subheading -trace-status
32188@findex -trace-status
922fbb7b 32189
18148017
VP
32190@subsubheading Synopsis
32191
32192@smallexample
32193 -trace-status
32194@end smallexample
32195
a97153c7 32196Obtains the status of a tracing experiment. The result may include
18148017
VP
32197the following fields:
32198
32199@table @samp
32200
32201@item supported
32202May have a value of either @samp{0}, when no tracing operations are
32203supported, @samp{1}, when all tracing operations are supported, or
32204@samp{file} when examining trace file. In the latter case, examining
32205of trace frame is possible but new tracing experiement cannot be
32206started. This field is always present.
32207
32208@item running
32209May have a value of either @samp{0} or @samp{1} depending on whether
32210tracing experiement is in progress on target. This field is present
32211if @samp{supported} field is not @samp{0}.
32212
32213@item stop-reason
32214Report the reason why the tracing was stopped last time. This field
32215may be absent iff tracing was never stopped on target yet. The
32216value of @samp{request} means the tracing was stopped as result of
32217the @code{-trace-stop} command. The value of @samp{overflow} means
32218the tracing buffer is full. The value of @samp{disconnection} means
32219tracing was automatically stopped when @value{GDBN} has disconnected.
32220The value of @samp{passcount} means tracing was stopped when a
32221tracepoint was passed a maximal number of times for that tracepoint.
32222This field is present if @samp{supported} field is not @samp{0}.
32223
32224@item stopping-tracepoint
32225The number of tracepoint whose passcount as exceeded. This field is
32226present iff the @samp{stop-reason} field has the value of
32227@samp{passcount}.
32228
32229@item frames
87290684
SS
32230@itemx frames-created
32231The @samp{frames} field is a count of the total number of trace frames
32232in the trace buffer, while @samp{frames-created} is the total created
32233during the run, including ones that were discarded, such as when a
32234circular trace buffer filled up. Both fields are optional.
18148017
VP
32235
32236@item buffer-size
32237@itemx buffer-free
32238These fields tell the current size of the tracing buffer and the
87290684 32239remaining space. These fields are optional.
18148017 32240
a97153c7
PA
32241@item circular
32242The value of the circular trace buffer flag. @code{1} means that the
32243trace buffer is circular and old trace frames will be discarded if
32244necessary to make room, @code{0} means that the trace buffer is linear
32245and may fill up.
32246
32247@item disconnected
32248The value of the disconnected tracing flag. @code{1} means that
32249tracing will continue after @value{GDBN} disconnects, @code{0} means
32250that the trace run will stop.
32251
f5911ea1
HAQ
32252@item trace-file
32253The filename of the trace file being examined. This field is
32254optional, and only present when examining a trace file.
32255
18148017
VP
32256@end table
32257
7d13fe92
SS
32258@subsubheading @value{GDBN} Command
32259
32260The corresponding @value{GDBN} command is @samp{tstatus}.
32261
18148017
VP
32262@subheading -trace-stop
32263@findex -trace-stop
32264
32265@subsubheading Synopsis
32266
32267@smallexample
32268 -trace-stop
32269@end smallexample
922fbb7b 32270
18148017
VP
32271Stops a tracing experiment. The result of this command has the same
32272fields as @code{-trace-status}, except that the @samp{supported} and
32273@samp{running} fields are not output.
922fbb7b 32274
7d13fe92
SS
32275@subsubheading @value{GDBN} Command
32276
32277The corresponding @value{GDBN} command is @samp{tstop}.
32278
922fbb7b 32279
a2c02241
NR
32280@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32281@node GDB/MI Symbol Query
32282@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
32283
32284
9901a55b 32285@ignore
a2c02241
NR
32286@subheading The @code{-symbol-info-address} Command
32287@findex -symbol-info-address
922fbb7b
AC
32288
32289@subsubheading Synopsis
32290
32291@smallexample
a2c02241 32292 -symbol-info-address @var{symbol}
922fbb7b
AC
32293@end smallexample
32294
a2c02241 32295Describe where @var{symbol} is stored.
922fbb7b
AC
32296
32297@subsubheading @value{GDBN} Command
32298
a2c02241 32299The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
32300
32301@subsubheading Example
32302N.A.
32303
32304
a2c02241
NR
32305@subheading The @code{-symbol-info-file} Command
32306@findex -symbol-info-file
922fbb7b
AC
32307
32308@subsubheading Synopsis
32309
32310@smallexample
a2c02241 32311 -symbol-info-file
922fbb7b
AC
32312@end smallexample
32313
a2c02241 32314Show the file for the symbol.
922fbb7b 32315
a2c02241 32316@subsubheading @value{GDBN} Command
922fbb7b 32317
a2c02241
NR
32318There's no equivalent @value{GDBN} command. @code{gdbtk} has
32319@samp{gdb_find_file}.
922fbb7b
AC
32320
32321@subsubheading Example
32322N.A.
32323
32324
a2c02241
NR
32325@subheading The @code{-symbol-info-function} Command
32326@findex -symbol-info-function
922fbb7b
AC
32327
32328@subsubheading Synopsis
32329
32330@smallexample
a2c02241 32331 -symbol-info-function
922fbb7b
AC
32332@end smallexample
32333
a2c02241 32334Show which function the symbol lives in.
922fbb7b
AC
32335
32336@subsubheading @value{GDBN} Command
32337
a2c02241 32338@samp{gdb_get_function} in @code{gdbtk}.
922fbb7b
AC
32339
32340@subsubheading Example
32341N.A.
32342
32343
a2c02241
NR
32344@subheading The @code{-symbol-info-line} Command
32345@findex -symbol-info-line
922fbb7b
AC
32346
32347@subsubheading Synopsis
32348
32349@smallexample
a2c02241 32350 -symbol-info-line
922fbb7b
AC
32351@end smallexample
32352
a2c02241 32353Show the core addresses of the code for a source line.
922fbb7b 32354
a2c02241 32355@subsubheading @value{GDBN} Command
922fbb7b 32356
a2c02241
NR
32357The corresponding @value{GDBN} command is @samp{info line}.
32358@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
32359
32360@subsubheading Example
a2c02241 32361N.A.
922fbb7b
AC
32362
32363
a2c02241
NR
32364@subheading The @code{-symbol-info-symbol} Command
32365@findex -symbol-info-symbol
07f31aa6
DJ
32366
32367@subsubheading Synopsis
32368
a2c02241
NR
32369@smallexample
32370 -symbol-info-symbol @var{addr}
32371@end smallexample
07f31aa6 32372
a2c02241 32373Describe what symbol is at location @var{addr}.
07f31aa6 32374
a2c02241 32375@subsubheading @value{GDBN} Command
07f31aa6 32376
a2c02241 32377The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
32378
32379@subsubheading Example
a2c02241 32380N.A.
07f31aa6
DJ
32381
32382
a2c02241
NR
32383@subheading The @code{-symbol-list-functions} Command
32384@findex -symbol-list-functions
922fbb7b
AC
32385
32386@subsubheading Synopsis
32387
32388@smallexample
a2c02241 32389 -symbol-list-functions
922fbb7b
AC
32390@end smallexample
32391
a2c02241 32392List the functions in the executable.
922fbb7b
AC
32393
32394@subsubheading @value{GDBN} Command
32395
a2c02241
NR
32396@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
32397@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
32398
32399@subsubheading Example
a2c02241 32400N.A.
9901a55b 32401@end ignore
922fbb7b
AC
32402
32403
a2c02241
NR
32404@subheading The @code{-symbol-list-lines} Command
32405@findex -symbol-list-lines
922fbb7b
AC
32406
32407@subsubheading Synopsis
32408
32409@smallexample
a2c02241 32410 -symbol-list-lines @var{filename}
922fbb7b
AC
32411@end smallexample
32412
a2c02241
NR
32413Print the list of lines that contain code and their associated program
32414addresses for the given source filename. The entries are sorted in
32415ascending PC order.
922fbb7b
AC
32416
32417@subsubheading @value{GDBN} Command
32418
a2c02241 32419There is no corresponding @value{GDBN} command.
922fbb7b
AC
32420
32421@subsubheading Example
a2c02241 32422@smallexample
594fe323 32423(gdb)
a2c02241
NR
32424-symbol-list-lines basics.c
32425^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 32426(gdb)
a2c02241 32427@end smallexample
922fbb7b
AC
32428
32429
9901a55b 32430@ignore
a2c02241
NR
32431@subheading The @code{-symbol-list-types} Command
32432@findex -symbol-list-types
922fbb7b
AC
32433
32434@subsubheading Synopsis
32435
32436@smallexample
a2c02241 32437 -symbol-list-types
922fbb7b
AC
32438@end smallexample
32439
a2c02241 32440List all the type names.
922fbb7b
AC
32441
32442@subsubheading @value{GDBN} Command
32443
a2c02241
NR
32444The corresponding commands are @samp{info types} in @value{GDBN},
32445@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
32446
32447@subsubheading Example
32448N.A.
32449
32450
a2c02241
NR
32451@subheading The @code{-symbol-list-variables} Command
32452@findex -symbol-list-variables
922fbb7b
AC
32453
32454@subsubheading Synopsis
32455
32456@smallexample
a2c02241 32457 -symbol-list-variables
922fbb7b
AC
32458@end smallexample
32459
a2c02241 32460List all the global and static variable names.
922fbb7b
AC
32461
32462@subsubheading @value{GDBN} Command
32463
a2c02241 32464@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
32465
32466@subsubheading Example
32467N.A.
32468
32469
a2c02241
NR
32470@subheading The @code{-symbol-locate} Command
32471@findex -symbol-locate
922fbb7b
AC
32472
32473@subsubheading Synopsis
32474
32475@smallexample
a2c02241 32476 -symbol-locate
922fbb7b
AC
32477@end smallexample
32478
922fbb7b
AC
32479@subsubheading @value{GDBN} Command
32480
a2c02241 32481@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
32482
32483@subsubheading Example
32484N.A.
32485
32486
a2c02241
NR
32487@subheading The @code{-symbol-type} Command
32488@findex -symbol-type
922fbb7b
AC
32489
32490@subsubheading Synopsis
32491
32492@smallexample
a2c02241 32493 -symbol-type @var{variable}
922fbb7b
AC
32494@end smallexample
32495
a2c02241 32496Show type of @var{variable}.
922fbb7b 32497
a2c02241 32498@subsubheading @value{GDBN} Command
922fbb7b 32499
a2c02241
NR
32500The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
32501@samp{gdb_obj_variable}.
32502
32503@subsubheading Example
32504N.A.
9901a55b 32505@end ignore
a2c02241
NR
32506
32507
32508@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32509@node GDB/MI File Commands
32510@section @sc{gdb/mi} File Commands
32511
32512This section describes the GDB/MI commands to specify executable file names
32513and to read in and obtain symbol table information.
32514
32515@subheading The @code{-file-exec-and-symbols} Command
32516@findex -file-exec-and-symbols
32517
32518@subsubheading Synopsis
922fbb7b
AC
32519
32520@smallexample
a2c02241 32521 -file-exec-and-symbols @var{file}
922fbb7b
AC
32522@end smallexample
32523
a2c02241
NR
32524Specify the executable file to be debugged. This file is the one from
32525which the symbol table is also read. If no file is specified, the
32526command clears the executable and symbol information. If breakpoints
32527are set when using this command with no arguments, @value{GDBN} will produce
32528error messages. Otherwise, no output is produced, except a completion
32529notification.
32530
922fbb7b
AC
32531@subsubheading @value{GDBN} Command
32532
a2c02241 32533The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
32534
32535@subsubheading Example
32536
32537@smallexample
594fe323 32538(gdb)
a2c02241
NR
32539-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
32540^done
594fe323 32541(gdb)
922fbb7b
AC
32542@end smallexample
32543
922fbb7b 32544
a2c02241
NR
32545@subheading The @code{-file-exec-file} Command
32546@findex -file-exec-file
922fbb7b
AC
32547
32548@subsubheading Synopsis
32549
32550@smallexample
a2c02241 32551 -file-exec-file @var{file}
922fbb7b
AC
32552@end smallexample
32553
a2c02241
NR
32554Specify the executable file to be debugged. Unlike
32555@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
32556from this file. If used without argument, @value{GDBN} clears the information
32557about the executable file. No output is produced, except a completion
32558notification.
922fbb7b 32559
a2c02241
NR
32560@subsubheading @value{GDBN} Command
32561
32562The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
32563
32564@subsubheading Example
a2c02241
NR
32565
32566@smallexample
594fe323 32567(gdb)
a2c02241
NR
32568-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
32569^done
594fe323 32570(gdb)
a2c02241 32571@end smallexample
922fbb7b
AC
32572
32573
9901a55b 32574@ignore
a2c02241
NR
32575@subheading The @code{-file-list-exec-sections} Command
32576@findex -file-list-exec-sections
922fbb7b
AC
32577
32578@subsubheading Synopsis
32579
32580@smallexample
a2c02241 32581 -file-list-exec-sections
922fbb7b
AC
32582@end smallexample
32583
a2c02241
NR
32584List the sections of the current executable file.
32585
922fbb7b
AC
32586@subsubheading @value{GDBN} Command
32587
a2c02241
NR
32588The @value{GDBN} command @samp{info file} shows, among the rest, the same
32589information as this command. @code{gdbtk} has a corresponding command
32590@samp{gdb_load_info}.
922fbb7b
AC
32591
32592@subsubheading Example
32593N.A.
9901a55b 32594@end ignore
922fbb7b
AC
32595
32596
a2c02241
NR
32597@subheading The @code{-file-list-exec-source-file} Command
32598@findex -file-list-exec-source-file
922fbb7b
AC
32599
32600@subsubheading Synopsis
32601
32602@smallexample
a2c02241 32603 -file-list-exec-source-file
922fbb7b
AC
32604@end smallexample
32605
a2c02241 32606List the line number, the current source file, and the absolute path
44288b44
NR
32607to the current source file for the current executable. The macro
32608information field has a value of @samp{1} or @samp{0} depending on
32609whether or not the file includes preprocessor macro information.
922fbb7b
AC
32610
32611@subsubheading @value{GDBN} Command
32612
a2c02241 32613The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
32614
32615@subsubheading Example
32616
922fbb7b 32617@smallexample
594fe323 32618(gdb)
a2c02241 32619123-file-list-exec-source-file
44288b44 32620123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
594fe323 32621(gdb)
922fbb7b
AC
32622@end smallexample
32623
32624
a2c02241
NR
32625@subheading The @code{-file-list-exec-source-files} Command
32626@findex -file-list-exec-source-files
922fbb7b
AC
32627
32628@subsubheading Synopsis
32629
32630@smallexample
a2c02241 32631 -file-list-exec-source-files
922fbb7b
AC
32632@end smallexample
32633
a2c02241
NR
32634List the source files for the current executable.
32635
f35a17b5
JK
32636It will always output both the filename and fullname (absolute file
32637name) of a source file.
922fbb7b
AC
32638
32639@subsubheading @value{GDBN} Command
32640
a2c02241
NR
32641The @value{GDBN} equivalent is @samp{info sources}.
32642@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
32643
32644@subsubheading Example
922fbb7b 32645@smallexample
594fe323 32646(gdb)
a2c02241
NR
32647-file-list-exec-source-files
32648^done,files=[
32649@{file=foo.c,fullname=/home/foo.c@},
32650@{file=/home/bar.c,fullname=/home/bar.c@},
32651@{file=gdb_could_not_find_fullpath.c@}]
594fe323 32652(gdb)
922fbb7b
AC
32653@end smallexample
32654
9901a55b 32655@ignore
a2c02241
NR
32656@subheading The @code{-file-list-shared-libraries} Command
32657@findex -file-list-shared-libraries
922fbb7b 32658
a2c02241 32659@subsubheading Synopsis
922fbb7b 32660
a2c02241
NR
32661@smallexample
32662 -file-list-shared-libraries
32663@end smallexample
922fbb7b 32664
a2c02241 32665List the shared libraries in the program.
922fbb7b 32666
a2c02241 32667@subsubheading @value{GDBN} Command
922fbb7b 32668
a2c02241 32669The corresponding @value{GDBN} command is @samp{info shared}.
922fbb7b 32670
a2c02241
NR
32671@subsubheading Example
32672N.A.
922fbb7b
AC
32673
32674
a2c02241
NR
32675@subheading The @code{-file-list-symbol-files} Command
32676@findex -file-list-symbol-files
922fbb7b 32677
a2c02241 32678@subsubheading Synopsis
922fbb7b 32679
a2c02241
NR
32680@smallexample
32681 -file-list-symbol-files
32682@end smallexample
922fbb7b 32683
a2c02241 32684List symbol files.
922fbb7b 32685
a2c02241 32686@subsubheading @value{GDBN} Command
922fbb7b 32687
a2c02241 32688The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 32689
a2c02241
NR
32690@subsubheading Example
32691N.A.
9901a55b 32692@end ignore
922fbb7b 32693
922fbb7b 32694
a2c02241
NR
32695@subheading The @code{-file-symbol-file} Command
32696@findex -file-symbol-file
922fbb7b 32697
a2c02241 32698@subsubheading Synopsis
922fbb7b 32699
a2c02241
NR
32700@smallexample
32701 -file-symbol-file @var{file}
32702@end smallexample
922fbb7b 32703
a2c02241
NR
32704Read symbol table info from the specified @var{file} argument. When
32705used without arguments, clears @value{GDBN}'s symbol table info. No output is
32706produced, except for a completion notification.
922fbb7b 32707
a2c02241 32708@subsubheading @value{GDBN} Command
922fbb7b 32709
a2c02241 32710The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 32711
a2c02241 32712@subsubheading Example
922fbb7b 32713
a2c02241 32714@smallexample
594fe323 32715(gdb)
a2c02241
NR
32716-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
32717^done
594fe323 32718(gdb)
a2c02241 32719@end smallexample
922fbb7b 32720
a2c02241 32721@ignore
a2c02241
NR
32722@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32723@node GDB/MI Memory Overlay Commands
32724@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 32725
a2c02241 32726The memory overlay commands are not implemented.
922fbb7b 32727
a2c02241 32728@c @subheading -overlay-auto
922fbb7b 32729
a2c02241 32730@c @subheading -overlay-list-mapping-state
922fbb7b 32731
a2c02241 32732@c @subheading -overlay-list-overlays
922fbb7b 32733
a2c02241 32734@c @subheading -overlay-map
922fbb7b 32735
a2c02241 32736@c @subheading -overlay-off
922fbb7b 32737
a2c02241 32738@c @subheading -overlay-on
922fbb7b 32739
a2c02241 32740@c @subheading -overlay-unmap
922fbb7b 32741
a2c02241
NR
32742@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32743@node GDB/MI Signal Handling Commands
32744@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 32745
a2c02241 32746Signal handling commands are not implemented.
922fbb7b 32747
a2c02241 32748@c @subheading -signal-handle
922fbb7b 32749
a2c02241 32750@c @subheading -signal-list-handle-actions
922fbb7b 32751
a2c02241
NR
32752@c @subheading -signal-list-signal-types
32753@end ignore
922fbb7b 32754
922fbb7b 32755
a2c02241
NR
32756@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32757@node GDB/MI Target Manipulation
32758@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
32759
32760
a2c02241
NR
32761@subheading The @code{-target-attach} Command
32762@findex -target-attach
922fbb7b
AC
32763
32764@subsubheading Synopsis
32765
32766@smallexample
c3b108f7 32767 -target-attach @var{pid} | @var{gid} | @var{file}
922fbb7b
AC
32768@end smallexample
32769
c3b108f7
VP
32770Attach to a process @var{pid} or a file @var{file} outside of
32771@value{GDBN}, or a thread group @var{gid}. If attaching to a thread
32772group, the id previously returned by
32773@samp{-list-thread-groups --available} must be used.
922fbb7b 32774
79a6e687 32775@subsubheading @value{GDBN} Command
922fbb7b 32776
a2c02241 32777The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 32778
a2c02241 32779@subsubheading Example
b56e7235
VP
32780@smallexample
32781(gdb)
32782-target-attach 34
32783=thread-created,id="1"
5ae4183a 32784*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
b56e7235
VP
32785^done
32786(gdb)
32787@end smallexample
a2c02241 32788
9901a55b 32789@ignore
a2c02241
NR
32790@subheading The @code{-target-compare-sections} Command
32791@findex -target-compare-sections
922fbb7b
AC
32792
32793@subsubheading Synopsis
32794
32795@smallexample
a2c02241 32796 -target-compare-sections [ @var{section} ]
922fbb7b
AC
32797@end smallexample
32798
a2c02241
NR
32799Compare data of section @var{section} on target to the exec file.
32800Without the argument, all sections are compared.
922fbb7b 32801
a2c02241 32802@subsubheading @value{GDBN} Command
922fbb7b 32803
a2c02241 32804The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 32805
a2c02241
NR
32806@subsubheading Example
32807N.A.
9901a55b 32808@end ignore
a2c02241
NR
32809
32810
32811@subheading The @code{-target-detach} Command
32812@findex -target-detach
922fbb7b
AC
32813
32814@subsubheading Synopsis
32815
32816@smallexample
c3b108f7 32817 -target-detach [ @var{pid} | @var{gid} ]
922fbb7b
AC
32818@end smallexample
32819
a2c02241 32820Detach from the remote target which normally resumes its execution.
c3b108f7
VP
32821If either @var{pid} or @var{gid} is specified, detaches from either
32822the specified process, or specified thread group. There's no output.
a2c02241 32823
79a6e687 32824@subsubheading @value{GDBN} Command
a2c02241
NR
32825
32826The corresponding @value{GDBN} command is @samp{detach}.
32827
32828@subsubheading Example
922fbb7b
AC
32829
32830@smallexample
594fe323 32831(gdb)
a2c02241
NR
32832-target-detach
32833^done
594fe323 32834(gdb)
922fbb7b
AC
32835@end smallexample
32836
32837
a2c02241
NR
32838@subheading The @code{-target-disconnect} Command
32839@findex -target-disconnect
922fbb7b
AC
32840
32841@subsubheading Synopsis
32842
123dc839 32843@smallexample
a2c02241 32844 -target-disconnect
123dc839 32845@end smallexample
922fbb7b 32846
a2c02241
NR
32847Disconnect from the remote target. There's no output and the target is
32848generally not resumed.
32849
79a6e687 32850@subsubheading @value{GDBN} Command
a2c02241
NR
32851
32852The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
32853
32854@subsubheading Example
922fbb7b
AC
32855
32856@smallexample
594fe323 32857(gdb)
a2c02241
NR
32858-target-disconnect
32859^done
594fe323 32860(gdb)
922fbb7b
AC
32861@end smallexample
32862
32863
a2c02241
NR
32864@subheading The @code{-target-download} Command
32865@findex -target-download
922fbb7b
AC
32866
32867@subsubheading Synopsis
32868
32869@smallexample
a2c02241 32870 -target-download
922fbb7b
AC
32871@end smallexample
32872
a2c02241
NR
32873Loads the executable onto the remote target.
32874It prints out an update message every half second, which includes the fields:
32875
32876@table @samp
32877@item section
32878The name of the section.
32879@item section-sent
32880The size of what has been sent so far for that section.
32881@item section-size
32882The size of the section.
32883@item total-sent
32884The total size of what was sent so far (the current and the previous sections).
32885@item total-size
32886The size of the overall executable to download.
32887@end table
32888
32889@noindent
32890Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
32891@sc{gdb/mi} Output Syntax}).
32892
32893In addition, it prints the name and size of the sections, as they are
32894downloaded. These messages include the following fields:
32895
32896@table @samp
32897@item section
32898The name of the section.
32899@item section-size
32900The size of the section.
32901@item total-size
32902The size of the overall executable to download.
32903@end table
32904
32905@noindent
32906At the end, a summary is printed.
32907
32908@subsubheading @value{GDBN} Command
32909
32910The corresponding @value{GDBN} command is @samp{load}.
32911
32912@subsubheading Example
32913
32914Note: each status message appears on a single line. Here the messages
32915have been broken down so that they can fit onto a page.
922fbb7b
AC
32916
32917@smallexample
594fe323 32918(gdb)
a2c02241
NR
32919-target-download
32920+download,@{section=".text",section-size="6668",total-size="9880"@}
32921+download,@{section=".text",section-sent="512",section-size="6668",
32922total-sent="512",total-size="9880"@}
32923+download,@{section=".text",section-sent="1024",section-size="6668",
32924total-sent="1024",total-size="9880"@}
32925+download,@{section=".text",section-sent="1536",section-size="6668",
32926total-sent="1536",total-size="9880"@}
32927+download,@{section=".text",section-sent="2048",section-size="6668",
32928total-sent="2048",total-size="9880"@}
32929+download,@{section=".text",section-sent="2560",section-size="6668",
32930total-sent="2560",total-size="9880"@}
32931+download,@{section=".text",section-sent="3072",section-size="6668",
32932total-sent="3072",total-size="9880"@}
32933+download,@{section=".text",section-sent="3584",section-size="6668",
32934total-sent="3584",total-size="9880"@}
32935+download,@{section=".text",section-sent="4096",section-size="6668",
32936total-sent="4096",total-size="9880"@}
32937+download,@{section=".text",section-sent="4608",section-size="6668",
32938total-sent="4608",total-size="9880"@}
32939+download,@{section=".text",section-sent="5120",section-size="6668",
32940total-sent="5120",total-size="9880"@}
32941+download,@{section=".text",section-sent="5632",section-size="6668",
32942total-sent="5632",total-size="9880"@}
32943+download,@{section=".text",section-sent="6144",section-size="6668",
32944total-sent="6144",total-size="9880"@}
32945+download,@{section=".text",section-sent="6656",section-size="6668",
32946total-sent="6656",total-size="9880"@}
32947+download,@{section=".init",section-size="28",total-size="9880"@}
32948+download,@{section=".fini",section-size="28",total-size="9880"@}
32949+download,@{section=".data",section-size="3156",total-size="9880"@}
32950+download,@{section=".data",section-sent="512",section-size="3156",
32951total-sent="7236",total-size="9880"@}
32952+download,@{section=".data",section-sent="1024",section-size="3156",
32953total-sent="7748",total-size="9880"@}
32954+download,@{section=".data",section-sent="1536",section-size="3156",
32955total-sent="8260",total-size="9880"@}
32956+download,@{section=".data",section-sent="2048",section-size="3156",
32957total-sent="8772",total-size="9880"@}
32958+download,@{section=".data",section-sent="2560",section-size="3156",
32959total-sent="9284",total-size="9880"@}
32960+download,@{section=".data",section-sent="3072",section-size="3156",
32961total-sent="9796",total-size="9880"@}
32962^done,address="0x10004",load-size="9880",transfer-rate="6586",
32963write-rate="429"
594fe323 32964(gdb)
922fbb7b
AC
32965@end smallexample
32966
32967
9901a55b 32968@ignore
a2c02241
NR
32969@subheading The @code{-target-exec-status} Command
32970@findex -target-exec-status
922fbb7b
AC
32971
32972@subsubheading Synopsis
32973
32974@smallexample
a2c02241 32975 -target-exec-status
922fbb7b
AC
32976@end smallexample
32977
a2c02241
NR
32978Provide information on the state of the target (whether it is running or
32979not, for instance).
922fbb7b 32980
a2c02241 32981@subsubheading @value{GDBN} Command
922fbb7b 32982
a2c02241
NR
32983There's no equivalent @value{GDBN} command.
32984
32985@subsubheading Example
32986N.A.
922fbb7b 32987
a2c02241
NR
32988
32989@subheading The @code{-target-list-available-targets} Command
32990@findex -target-list-available-targets
922fbb7b
AC
32991
32992@subsubheading Synopsis
32993
32994@smallexample
a2c02241 32995 -target-list-available-targets
922fbb7b
AC
32996@end smallexample
32997
a2c02241 32998List the possible targets to connect to.
922fbb7b 32999
a2c02241 33000@subsubheading @value{GDBN} Command
922fbb7b 33001
a2c02241 33002The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 33003
a2c02241
NR
33004@subsubheading Example
33005N.A.
33006
33007
33008@subheading The @code{-target-list-current-targets} Command
33009@findex -target-list-current-targets
922fbb7b
AC
33010
33011@subsubheading Synopsis
33012
33013@smallexample
a2c02241 33014 -target-list-current-targets
922fbb7b
AC
33015@end smallexample
33016
a2c02241 33017Describe the current target.
922fbb7b 33018
a2c02241 33019@subsubheading @value{GDBN} Command
922fbb7b 33020
a2c02241
NR
33021The corresponding information is printed by @samp{info file} (among
33022other things).
922fbb7b 33023
a2c02241
NR
33024@subsubheading Example
33025N.A.
33026
33027
33028@subheading The @code{-target-list-parameters} Command
33029@findex -target-list-parameters
922fbb7b
AC
33030
33031@subsubheading Synopsis
33032
33033@smallexample
a2c02241 33034 -target-list-parameters
922fbb7b
AC
33035@end smallexample
33036
a2c02241 33037@c ????
9901a55b 33038@end ignore
a2c02241
NR
33039
33040@subsubheading @value{GDBN} Command
33041
33042No equivalent.
922fbb7b
AC
33043
33044@subsubheading Example
a2c02241
NR
33045N.A.
33046
33047
33048@subheading The @code{-target-select} Command
33049@findex -target-select
33050
33051@subsubheading Synopsis
922fbb7b
AC
33052
33053@smallexample
a2c02241 33054 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
33055@end smallexample
33056
a2c02241 33057Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 33058
a2c02241
NR
33059@table @samp
33060@item @var{type}
75c99385 33061The type of target, for instance @samp{remote}, etc.
a2c02241
NR
33062@item @var{parameters}
33063Device names, host names and the like. @xref{Target Commands, ,
79a6e687 33064Commands for Managing Targets}, for more details.
a2c02241
NR
33065@end table
33066
33067The output is a connection notification, followed by the address at
33068which the target program is, in the following form:
922fbb7b
AC
33069
33070@smallexample
a2c02241
NR
33071^connected,addr="@var{address}",func="@var{function name}",
33072 args=[@var{arg list}]
922fbb7b
AC
33073@end smallexample
33074
a2c02241
NR
33075@subsubheading @value{GDBN} Command
33076
33077The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
33078
33079@subsubheading Example
922fbb7b 33080
265eeb58 33081@smallexample
594fe323 33082(gdb)
75c99385 33083-target-select remote /dev/ttya
a2c02241 33084^connected,addr="0xfe00a300",func="??",args=[]
594fe323 33085(gdb)
265eeb58 33086@end smallexample
ef21caaf 33087
a6b151f1
DJ
33088@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33089@node GDB/MI File Transfer Commands
33090@section @sc{gdb/mi} File Transfer Commands
33091
33092
33093@subheading The @code{-target-file-put} Command
33094@findex -target-file-put
33095
33096@subsubheading Synopsis
33097
33098@smallexample
33099 -target-file-put @var{hostfile} @var{targetfile}
33100@end smallexample
33101
33102Copy file @var{hostfile} from the host system (the machine running
33103@value{GDBN}) to @var{targetfile} on the target system.
33104
33105@subsubheading @value{GDBN} Command
33106
33107The corresponding @value{GDBN} command is @samp{remote put}.
33108
33109@subsubheading Example
33110
33111@smallexample
33112(gdb)
33113-target-file-put localfile remotefile
33114^done
33115(gdb)
33116@end smallexample
33117
33118
1763a388 33119@subheading The @code{-target-file-get} Command
a6b151f1
DJ
33120@findex -target-file-get
33121
33122@subsubheading Synopsis
33123
33124@smallexample
33125 -target-file-get @var{targetfile} @var{hostfile}
33126@end smallexample
33127
33128Copy file @var{targetfile} from the target system to @var{hostfile}
33129on the host system.
33130
33131@subsubheading @value{GDBN} Command
33132
33133The corresponding @value{GDBN} command is @samp{remote get}.
33134
33135@subsubheading Example
33136
33137@smallexample
33138(gdb)
33139-target-file-get remotefile localfile
33140^done
33141(gdb)
33142@end smallexample
33143
33144
33145@subheading The @code{-target-file-delete} Command
33146@findex -target-file-delete
33147
33148@subsubheading Synopsis
33149
33150@smallexample
33151 -target-file-delete @var{targetfile}
33152@end smallexample
33153
33154Delete @var{targetfile} from the target system.
33155
33156@subsubheading @value{GDBN} Command
33157
33158The corresponding @value{GDBN} command is @samp{remote delete}.
33159
33160@subsubheading Example
33161
33162@smallexample
33163(gdb)
33164-target-file-delete remotefile
33165^done
33166(gdb)
33167@end smallexample
33168
33169
ef21caaf
NR
33170@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33171@node GDB/MI Miscellaneous Commands
33172@section Miscellaneous @sc{gdb/mi} Commands
33173
33174@c @subheading -gdb-complete
33175
33176@subheading The @code{-gdb-exit} Command
33177@findex -gdb-exit
33178
33179@subsubheading Synopsis
33180
33181@smallexample
33182 -gdb-exit
33183@end smallexample
33184
33185Exit @value{GDBN} immediately.
33186
33187@subsubheading @value{GDBN} Command
33188
33189Approximately corresponds to @samp{quit}.
33190
33191@subsubheading Example
33192
33193@smallexample
594fe323 33194(gdb)
ef21caaf
NR
33195-gdb-exit
33196^exit
33197@end smallexample
33198
a2c02241 33199
9901a55b 33200@ignore
a2c02241
NR
33201@subheading The @code{-exec-abort} Command
33202@findex -exec-abort
33203
33204@subsubheading Synopsis
33205
33206@smallexample
33207 -exec-abort
33208@end smallexample
33209
33210Kill the inferior running program.
33211
33212@subsubheading @value{GDBN} Command
33213
33214The corresponding @value{GDBN} command is @samp{kill}.
33215
33216@subsubheading Example
33217N.A.
9901a55b 33218@end ignore
a2c02241
NR
33219
33220
ef21caaf
NR
33221@subheading The @code{-gdb-set} Command
33222@findex -gdb-set
33223
33224@subsubheading Synopsis
33225
33226@smallexample
33227 -gdb-set
33228@end smallexample
33229
33230Set an internal @value{GDBN} variable.
33231@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
33232
33233@subsubheading @value{GDBN} Command
33234
33235The corresponding @value{GDBN} command is @samp{set}.
33236
33237@subsubheading Example
33238
33239@smallexample
594fe323 33240(gdb)
ef21caaf
NR
33241-gdb-set $foo=3
33242^done
594fe323 33243(gdb)
ef21caaf
NR
33244@end smallexample
33245
33246
33247@subheading The @code{-gdb-show} Command
33248@findex -gdb-show
33249
33250@subsubheading Synopsis
33251
33252@smallexample
33253 -gdb-show
33254@end smallexample
33255
33256Show the current value of a @value{GDBN} variable.
33257
79a6e687 33258@subsubheading @value{GDBN} Command
ef21caaf
NR
33259
33260The corresponding @value{GDBN} command is @samp{show}.
33261
33262@subsubheading Example
33263
33264@smallexample
594fe323 33265(gdb)
ef21caaf
NR
33266-gdb-show annotate
33267^done,value="0"
594fe323 33268(gdb)
ef21caaf
NR
33269@end smallexample
33270
33271@c @subheading -gdb-source
33272
33273
33274@subheading The @code{-gdb-version} Command
33275@findex -gdb-version
33276
33277@subsubheading Synopsis
33278
33279@smallexample
33280 -gdb-version
33281@end smallexample
33282
33283Show version information for @value{GDBN}. Used mostly in testing.
33284
33285@subsubheading @value{GDBN} Command
33286
33287The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
33288default shows this information when you start an interactive session.
33289
33290@subsubheading Example
33291
33292@c This example modifies the actual output from GDB to avoid overfull
33293@c box in TeX.
33294@smallexample
594fe323 33295(gdb)
ef21caaf
NR
33296-gdb-version
33297~GNU gdb 5.2.1
33298~Copyright 2000 Free Software Foundation, Inc.
33299~GDB is free software, covered by the GNU General Public License, and
33300~you are welcome to change it and/or distribute copies of it under
33301~ certain conditions.
33302~Type "show copying" to see the conditions.
33303~There is absolutely no warranty for GDB. Type "show warranty" for
33304~ details.
33305~This GDB was configured as
33306 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
33307^done
594fe323 33308(gdb)
ef21caaf
NR
33309@end smallexample
33310
084344da
VP
33311@subheading The @code{-list-features} Command
33312@findex -list-features
33313
33314Returns a list of particular features of the MI protocol that
33315this version of gdb implements. A feature can be a command,
33316or a new field in an output of some command, or even an
33317important bugfix. While a frontend can sometimes detect presence
33318of a feature at runtime, it is easier to perform detection at debugger
33319startup.
33320
33321The command returns a list of strings, with each string naming an
33322available feature. Each returned string is just a name, it does not
33323have any internal structure. The list of possible feature names
33324is given below.
33325
33326Example output:
33327
33328@smallexample
33329(gdb) -list-features
33330^done,result=["feature1","feature2"]
33331@end smallexample
33332
33333The current list of features is:
33334
30e026bb
VP
33335@table @samp
33336@item frozen-varobjs
a05336a1
JB
33337Indicates support for the @code{-var-set-frozen} command, as well
33338as possible presense of the @code{frozen} field in the output
30e026bb
VP
33339of @code{-varobj-create}.
33340@item pending-breakpoints
a05336a1
JB
33341Indicates support for the @option{-f} option to the @code{-break-insert}
33342command.
b6313243 33343@item python
a05336a1 33344Indicates Python scripting support, Python-based
b6313243
TT
33345pretty-printing commands, and possible presence of the
33346@samp{display_hint} field in the output of @code{-var-list-children}
30e026bb 33347@item thread-info
a05336a1 33348Indicates support for the @code{-thread-info} command.
8dedea02 33349@item data-read-memory-bytes
a05336a1 33350Indicates support for the @code{-data-read-memory-bytes} and the
8dedea02 33351@code{-data-write-memory-bytes} commands.
39c4d40a
TT
33352@item breakpoint-notifications
33353Indicates that changes to breakpoints and breakpoints created via the
33354CLI will be announced via async records.
5d77fe44
JB
33355@item ada-task-info
33356Indicates support for the @code{-ada-task-info} command.
30e026bb 33357@end table
084344da 33358
c6ebd6cf
VP
33359@subheading The @code{-list-target-features} Command
33360@findex -list-target-features
33361
33362Returns a list of particular features that are supported by the
33363target. Those features affect the permitted MI commands, but
33364unlike the features reported by the @code{-list-features} command, the
33365features depend on which target GDB is using at the moment. Whenever
33366a target can change, due to commands such as @code{-target-select},
33367@code{-target-attach} or @code{-exec-run}, the list of target features
33368may change, and the frontend should obtain it again.
33369Example output:
33370
33371@smallexample
33372(gdb) -list-features
33373^done,result=["async"]
33374@end smallexample
33375
33376The current list of features is:
33377
33378@table @samp
33379@item async
33380Indicates that the target is capable of asynchronous command
33381execution, which means that @value{GDBN} will accept further commands
33382while the target is running.
33383
f75d858b
MK
33384@item reverse
33385Indicates that the target is capable of reverse execution.
33386@xref{Reverse Execution}, for more information.
33387
c6ebd6cf
VP
33388@end table
33389
c3b108f7
VP
33390@subheading The @code{-list-thread-groups} Command
33391@findex -list-thread-groups
33392
33393@subheading Synopsis
33394
33395@smallexample
dc146f7c 33396-list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
c3b108f7
VP
33397@end smallexample
33398
dc146f7c
VP
33399Lists thread groups (@pxref{Thread groups}). When a single thread
33400group is passed as the argument, lists the children of that group.
33401When several thread group are passed, lists information about those
33402thread groups. Without any parameters, lists information about all
33403top-level thread groups.
33404
33405Normally, thread groups that are being debugged are reported.
33406With the @samp{--available} option, @value{GDBN} reports thread groups
33407available on the target.
33408
33409The output of this command may have either a @samp{threads} result or
33410a @samp{groups} result. The @samp{thread} result has a list of tuples
33411as value, with each tuple describing a thread (@pxref{GDB/MI Thread
33412Information}). The @samp{groups} result has a list of tuples as value,
33413each tuple describing a thread group. If top-level groups are
33414requested (that is, no parameter is passed), or when several groups
33415are passed, the output always has a @samp{groups} result. The format
33416of the @samp{group} result is described below.
33417
33418To reduce the number of roundtrips it's possible to list thread groups
33419together with their children, by passing the @samp{--recurse} option
33420and the recursion depth. Presently, only recursion depth of 1 is
33421permitted. If this option is present, then every reported thread group
33422will also include its children, either as @samp{group} or
33423@samp{threads} field.
33424
33425In general, any combination of option and parameters is permitted, with
33426the following caveats:
33427
33428@itemize @bullet
33429@item
33430When a single thread group is passed, the output will typically
33431be the @samp{threads} result. Because threads may not contain
33432anything, the @samp{recurse} option will be ignored.
33433
33434@item
33435When the @samp{--available} option is passed, limited information may
33436be available. In particular, the list of threads of a process might
33437be inaccessible. Further, specifying specific thread groups might
33438not give any performance advantage over listing all thread groups.
33439The frontend should assume that @samp{-list-thread-groups --available}
33440is always an expensive operation and cache the results.
33441
33442@end itemize
33443
33444The @samp{groups} result is a list of tuples, where each tuple may
33445have the following fields:
33446
33447@table @code
33448@item id
33449Identifier of the thread group. This field is always present.
a79b8f6e
VP
33450The identifier is an opaque string; frontends should not try to
33451convert it to an integer, even though it might look like one.
dc146f7c
VP
33452
33453@item type
33454The type of the thread group. At present, only @samp{process} is a
33455valid type.
33456
33457@item pid
33458The target-specific process identifier. This field is only present
a79b8f6e 33459for thread groups of type @samp{process} and only if the process exists.
c3b108f7 33460
dc146f7c
VP
33461@item num_children
33462The number of children this thread group has. This field may be
33463absent for an available thread group.
33464
33465@item threads
33466This field has a list of tuples as value, each tuple describing a
33467thread. It may be present if the @samp{--recurse} option is
33468specified, and it's actually possible to obtain the threads.
33469
33470@item cores
33471This field is a list of integers, each identifying a core that one
33472thread of the group is running on. This field may be absent if
33473such information is not available.
33474
a79b8f6e
VP
33475@item executable
33476The name of the executable file that corresponds to this thread group.
33477The field is only present for thread groups of type @samp{process},
33478and only if there is a corresponding executable file.
33479
dc146f7c 33480@end table
c3b108f7
VP
33481
33482@subheading Example
33483
33484@smallexample
33485@value{GDBP}
33486-list-thread-groups
33487^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
33488-list-thread-groups 17
33489^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
33490 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
33491@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
33492 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
33493 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}]]
dc146f7c
VP
33494-list-thread-groups --available
33495^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
33496-list-thread-groups --available --recurse 1
33497 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
33498 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
33499 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
33500-list-thread-groups --available --recurse 1 17 18
33501^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
33502 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
33503 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
c3b108f7 33504@end smallexample
c6ebd6cf 33505
f3e0e960
SS
33506@subheading The @code{-info-os} Command
33507@findex -info-os
33508
33509@subsubheading Synopsis
33510
33511@smallexample
33512-info-os [ @var{type} ]
33513@end smallexample
33514
33515If no argument is supplied, the command returns a table of available
33516operating-system-specific information types. If one of these types is
33517supplied as an argument @var{type}, then the command returns a table
33518of data of that type.
33519
33520The types of information available depend on the target operating
33521system.
33522
33523@subsubheading @value{GDBN} Command
33524
33525The corresponding @value{GDBN} command is @samp{info os}.
33526
33527@subsubheading Example
33528
33529When run on a @sc{gnu}/Linux system, the output will look something
33530like this:
33531
33532@smallexample
33533@value{GDBP}
33534-info-os
71caed83 33535^done,OSDataTable=@{nr_rows="9",nr_cols="3",
f3e0e960 33536hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
71caed83
SS
33537 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
33538 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
33539body=[item=@{col0="processes",col1="Listing of all processes",
33540 col2="Processes"@},
33541 item=@{col0="procgroups",col1="Listing of all process groups",
33542 col2="Process groups"@},
33543 item=@{col0="threads",col1="Listing of all threads",
33544 col2="Threads"@},
33545 item=@{col0="files",col1="Listing of all file descriptors",
33546 col2="File descriptors"@},
33547 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
33548 col2="Sockets"@},
33549 item=@{col0="shm",col1="Listing of all shared-memory regions",
33550 col2="Shared-memory regions"@},
33551 item=@{col0="semaphores",col1="Listing of all semaphores",
33552 col2="Semaphores"@},
33553 item=@{col0="msg",col1="Listing of all message queues",
33554 col2="Message queues"@},
33555 item=@{col0="modules",col1="Listing of all loaded kernel modules",
33556 col2="Kernel modules"@}]@}
f3e0e960
SS
33557@value{GDBP}
33558-info-os processes
33559^done,OSDataTable=@{nr_rows="190",nr_cols="4",
33560hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
33561 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
33562 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
33563 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
33564body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
33565 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
33566 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
33567 ...
33568 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
33569 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
33570(gdb)
33571@end smallexample
a79b8f6e 33572
71caed83
SS
33573(Note that the MI output here includes a @code{"Title"} column that
33574does not appear in command-line @code{info os}; this column is useful
33575for MI clients that want to enumerate the types of data, such as in a
33576popup menu, but is needless clutter on the command line, and
33577@code{info os} omits it.)
33578
a79b8f6e
VP
33579@subheading The @code{-add-inferior} Command
33580@findex -add-inferior
33581
33582@subheading Synopsis
33583
33584@smallexample
33585-add-inferior
33586@end smallexample
33587
33588Creates a new inferior (@pxref{Inferiors and Programs}). The created
33589inferior is not associated with any executable. Such association may
33590be established with the @samp{-file-exec-and-symbols} command
33591(@pxref{GDB/MI File Commands}). The command response has a single
33592field, @samp{thread-group}, whose value is the identifier of the
33593thread group corresponding to the new inferior.
33594
33595@subheading Example
33596
33597@smallexample
33598@value{GDBP}
33599-add-inferior
33600^done,thread-group="i3"
33601@end smallexample
33602
ef21caaf
NR
33603@subheading The @code{-interpreter-exec} Command
33604@findex -interpreter-exec
33605
33606@subheading Synopsis
33607
33608@smallexample
33609-interpreter-exec @var{interpreter} @var{command}
33610@end smallexample
a2c02241 33611@anchor{-interpreter-exec}
ef21caaf
NR
33612
33613Execute the specified @var{command} in the given @var{interpreter}.
33614
33615@subheading @value{GDBN} Command
33616
33617The corresponding @value{GDBN} command is @samp{interpreter-exec}.
33618
33619@subheading Example
33620
33621@smallexample
594fe323 33622(gdb)
ef21caaf
NR
33623-interpreter-exec console "break main"
33624&"During symbol reading, couldn't parse type; debugger out of date?.\n"
33625&"During symbol reading, bad structure-type format.\n"
33626~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
33627^done
594fe323 33628(gdb)
ef21caaf
NR
33629@end smallexample
33630
33631@subheading The @code{-inferior-tty-set} Command
33632@findex -inferior-tty-set
33633
33634@subheading Synopsis
33635
33636@smallexample
33637-inferior-tty-set /dev/pts/1
33638@end smallexample
33639
33640Set terminal for future runs of the program being debugged.
33641
33642@subheading @value{GDBN} Command
33643
33644The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
33645
33646@subheading Example
33647
33648@smallexample
594fe323 33649(gdb)
ef21caaf
NR
33650-inferior-tty-set /dev/pts/1
33651^done
594fe323 33652(gdb)
ef21caaf
NR
33653@end smallexample
33654
33655@subheading The @code{-inferior-tty-show} Command
33656@findex -inferior-tty-show
33657
33658@subheading Synopsis
33659
33660@smallexample
33661-inferior-tty-show
33662@end smallexample
33663
33664Show terminal for future runs of program being debugged.
33665
33666@subheading @value{GDBN} Command
33667
33668The corresponding @value{GDBN} command is @samp{show inferior-tty}.
33669
33670@subheading Example
33671
33672@smallexample
594fe323 33673(gdb)
ef21caaf
NR
33674-inferior-tty-set /dev/pts/1
33675^done
594fe323 33676(gdb)
ef21caaf
NR
33677-inferior-tty-show
33678^done,inferior_tty_terminal="/dev/pts/1"
594fe323 33679(gdb)
ef21caaf 33680@end smallexample
922fbb7b 33681
a4eefcd8
NR
33682@subheading The @code{-enable-timings} Command
33683@findex -enable-timings
33684
33685@subheading Synopsis
33686
33687@smallexample
33688-enable-timings [yes | no]
33689@end smallexample
33690
33691Toggle the printing of the wallclock, user and system times for an MI
33692command as a field in its output. This command is to help frontend
33693developers optimize the performance of their code. No argument is
33694equivalent to @samp{yes}.
33695
33696@subheading @value{GDBN} Command
33697
33698No equivalent.
33699
33700@subheading Example
33701
33702@smallexample
33703(gdb)
33704-enable-timings
33705^done
33706(gdb)
33707-break-insert main
33708^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
33709addr="0x080484ed",func="main",file="myprog.c",
998580f1
MK
33710fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
33711times="0"@},
a4eefcd8
NR
33712time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
33713(gdb)
33714-enable-timings no
33715^done
33716(gdb)
33717-exec-run
33718^running
33719(gdb)
a47ec5fe 33720*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
a4eefcd8
NR
33721frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
33722@{name="argv",value="0xbfb60364"@}],file="myprog.c",
33723fullname="/home/nickrob/myprog.c",line="73"@}
33724(gdb)
33725@end smallexample
33726
922fbb7b
AC
33727@node Annotations
33728@chapter @value{GDBN} Annotations
33729
086432e2
AC
33730This chapter describes annotations in @value{GDBN}. Annotations were
33731designed to interface @value{GDBN} to graphical user interfaces or other
33732similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
33733relatively high level.
33734
d3e8051b 33735The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
33736(@pxref{GDB/MI}).
33737
922fbb7b
AC
33738@ignore
33739This is Edition @value{EDITION}, @value{DATE}.
33740@end ignore
33741
33742@menu
33743* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 33744* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
33745* Prompting:: Annotations marking @value{GDBN}'s need for input.
33746* Errors:: Annotations for error messages.
922fbb7b
AC
33747* Invalidation:: Some annotations describe things now invalid.
33748* Annotations for Running::
33749 Whether the program is running, how it stopped, etc.
33750* Source Annotations:: Annotations describing source code.
922fbb7b
AC
33751@end menu
33752
33753@node Annotations Overview
33754@section What is an Annotation?
33755@cindex annotations
33756
922fbb7b
AC
33757Annotations start with a newline character, two @samp{control-z}
33758characters, and the name of the annotation. If there is no additional
33759information associated with this annotation, the name of the annotation
33760is followed immediately by a newline. If there is additional
33761information, the name of the annotation is followed by a space, the
33762additional information, and a newline. The additional information
33763cannot contain newline characters.
33764
33765Any output not beginning with a newline and two @samp{control-z}
33766characters denotes literal output from @value{GDBN}. Currently there is
33767no need for @value{GDBN} to output a newline followed by two
33768@samp{control-z} characters, but if there was such a need, the
33769annotations could be extended with an @samp{escape} annotation which
33770means those three characters as output.
33771
086432e2
AC
33772The annotation @var{level}, which is specified using the
33773@option{--annotate} command line option (@pxref{Mode Options}), controls
33774how much information @value{GDBN} prints together with its prompt,
33775values of expressions, source lines, and other types of output. Level 0
d3e8051b 33776is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
33777subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
33778for programs that control @value{GDBN}, and level 2 annotations have
33779been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
33780Interface, annotate, GDB's Obsolete Annotations}).
33781
33782@table @code
33783@kindex set annotate
33784@item set annotate @var{level}
e09f16f9 33785The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 33786annotations to the specified @var{level}.
9c16f35a
EZ
33787
33788@item show annotate
33789@kindex show annotate
33790Show the current annotation level.
09d4efe1
EZ
33791@end table
33792
33793This chapter describes level 3 annotations.
086432e2 33794
922fbb7b
AC
33795A simple example of starting up @value{GDBN} with annotations is:
33796
33797@smallexample
086432e2
AC
33798$ @kbd{gdb --annotate=3}
33799GNU gdb 6.0
33800Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
33801GDB is free software, covered by the GNU General Public License,
33802and you are welcome to change it and/or distribute copies of it
33803under certain conditions.
33804Type "show copying" to see the conditions.
33805There is absolutely no warranty for GDB. Type "show warranty"
33806for details.
086432e2 33807This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
33808
33809^Z^Zpre-prompt
f7dc1244 33810(@value{GDBP})
922fbb7b 33811^Z^Zprompt
086432e2 33812@kbd{quit}
922fbb7b
AC
33813
33814^Z^Zpost-prompt
b383017d 33815$
922fbb7b
AC
33816@end smallexample
33817
33818Here @samp{quit} is input to @value{GDBN}; the rest is output from
33819@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
33820denotes a @samp{control-z} character) are annotations; the rest is
33821output from @value{GDBN}.
33822
9e6c4bd5
NR
33823@node Server Prefix
33824@section The Server Prefix
33825@cindex server prefix
33826
33827If you prefix a command with @samp{server } then it will not affect
33828the command history, nor will it affect @value{GDBN}'s notion of which
33829command to repeat if @key{RET} is pressed on a line by itself. This
33830means that commands can be run behind a user's back by a front-end in
33831a transparent manner.
33832
d837706a
NR
33833The @code{server } prefix does not affect the recording of values into
33834the value history; to print a value without recording it into the
33835value history, use the @code{output} command instead of the
33836@code{print} command.
33837
33838Using this prefix also disables confirmation requests
33839(@pxref{confirmation requests}).
9e6c4bd5 33840
922fbb7b
AC
33841@node Prompting
33842@section Annotation for @value{GDBN} Input
33843
33844@cindex annotations for prompts
33845When @value{GDBN} prompts for input, it annotates this fact so it is possible
33846to know when to send output, when the output from a given command is
33847over, etc.
33848
33849Different kinds of input each have a different @dfn{input type}. Each
33850input type has three annotations: a @code{pre-} annotation, which
33851denotes the beginning of any prompt which is being output, a plain
33852annotation, which denotes the end of the prompt, and then a @code{post-}
33853annotation which denotes the end of any echo which may (or may not) be
33854associated with the input. For example, the @code{prompt} input type
33855features the following annotations:
33856
33857@smallexample
33858^Z^Zpre-prompt
33859^Z^Zprompt
33860^Z^Zpost-prompt
33861@end smallexample
33862
33863The input types are
33864
33865@table @code
e5ac9b53
EZ
33866@findex pre-prompt annotation
33867@findex prompt annotation
33868@findex post-prompt annotation
922fbb7b
AC
33869@item prompt
33870When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
33871
e5ac9b53
EZ
33872@findex pre-commands annotation
33873@findex commands annotation
33874@findex post-commands annotation
922fbb7b
AC
33875@item commands
33876When @value{GDBN} prompts for a set of commands, like in the @code{commands}
33877command. The annotations are repeated for each command which is input.
33878
e5ac9b53
EZ
33879@findex pre-overload-choice annotation
33880@findex overload-choice annotation
33881@findex post-overload-choice annotation
922fbb7b
AC
33882@item overload-choice
33883When @value{GDBN} wants the user to select between various overloaded functions.
33884
e5ac9b53
EZ
33885@findex pre-query annotation
33886@findex query annotation
33887@findex post-query annotation
922fbb7b
AC
33888@item query
33889When @value{GDBN} wants the user to confirm a potentially dangerous operation.
33890
e5ac9b53
EZ
33891@findex pre-prompt-for-continue annotation
33892@findex prompt-for-continue annotation
33893@findex post-prompt-for-continue annotation
922fbb7b
AC
33894@item prompt-for-continue
33895When @value{GDBN} is asking the user to press return to continue. Note: Don't
33896expect this to work well; instead use @code{set height 0} to disable
33897prompting. This is because the counting of lines is buggy in the
33898presence of annotations.
33899@end table
33900
33901@node Errors
33902@section Errors
33903@cindex annotations for errors, warnings and interrupts
33904
e5ac9b53 33905@findex quit annotation
922fbb7b
AC
33906@smallexample
33907^Z^Zquit
33908@end smallexample
33909
33910This annotation occurs right before @value{GDBN} responds to an interrupt.
33911
e5ac9b53 33912@findex error annotation
922fbb7b
AC
33913@smallexample
33914^Z^Zerror
33915@end smallexample
33916
33917This annotation occurs right before @value{GDBN} responds to an error.
33918
33919Quit and error annotations indicate that any annotations which @value{GDBN} was
33920in the middle of may end abruptly. For example, if a
33921@code{value-history-begin} annotation is followed by a @code{error}, one
33922cannot expect to receive the matching @code{value-history-end}. One
33923cannot expect not to receive it either, however; an error annotation
33924does not necessarily mean that @value{GDBN} is immediately returning all the way
33925to the top level.
33926
e5ac9b53 33927@findex error-begin annotation
922fbb7b
AC
33928A quit or error annotation may be preceded by
33929
33930@smallexample
33931^Z^Zerror-begin
33932@end smallexample
33933
33934Any output between that and the quit or error annotation is the error
33935message.
33936
33937Warning messages are not yet annotated.
33938@c If we want to change that, need to fix warning(), type_error(),
33939@c range_error(), and possibly other places.
33940
922fbb7b
AC
33941@node Invalidation
33942@section Invalidation Notices
33943
33944@cindex annotations for invalidation messages
33945The following annotations say that certain pieces of state may have
33946changed.
33947
33948@table @code
e5ac9b53 33949@findex frames-invalid annotation
922fbb7b
AC
33950@item ^Z^Zframes-invalid
33951
33952The frames (for example, output from the @code{backtrace} command) may
33953have changed.
33954
e5ac9b53 33955@findex breakpoints-invalid annotation
922fbb7b
AC
33956@item ^Z^Zbreakpoints-invalid
33957
33958The breakpoints may have changed. For example, the user just added or
33959deleted a breakpoint.
33960@end table
33961
33962@node Annotations for Running
33963@section Running the Program
33964@cindex annotations for running programs
33965
e5ac9b53
EZ
33966@findex starting annotation
33967@findex stopping annotation
922fbb7b 33968When the program starts executing due to a @value{GDBN} command such as
b383017d 33969@code{step} or @code{continue},
922fbb7b
AC
33970
33971@smallexample
33972^Z^Zstarting
33973@end smallexample
33974
b383017d 33975is output. When the program stops,
922fbb7b
AC
33976
33977@smallexample
33978^Z^Zstopped
33979@end smallexample
33980
33981is output. Before the @code{stopped} annotation, a variety of
33982annotations describe how the program stopped.
33983
33984@table @code
e5ac9b53 33985@findex exited annotation
922fbb7b
AC
33986@item ^Z^Zexited @var{exit-status}
33987The program exited, and @var{exit-status} is the exit status (zero for
33988successful exit, otherwise nonzero).
33989
e5ac9b53
EZ
33990@findex signalled annotation
33991@findex signal-name annotation
33992@findex signal-name-end annotation
33993@findex signal-string annotation
33994@findex signal-string-end annotation
922fbb7b
AC
33995@item ^Z^Zsignalled
33996The program exited with a signal. After the @code{^Z^Zsignalled}, the
33997annotation continues:
33998
33999@smallexample
34000@var{intro-text}
34001^Z^Zsignal-name
34002@var{name}
34003^Z^Zsignal-name-end
34004@var{middle-text}
34005^Z^Zsignal-string
34006@var{string}
34007^Z^Zsignal-string-end
34008@var{end-text}
34009@end smallexample
34010
34011@noindent
34012where @var{name} is the name of the signal, such as @code{SIGILL} or
34013@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
34014as @code{Illegal Instruction} or @code{Segmentation fault}.
34015@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
34016user's benefit and have no particular format.
34017
e5ac9b53 34018@findex signal annotation
922fbb7b
AC
34019@item ^Z^Zsignal
34020The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
34021just saying that the program received the signal, not that it was
34022terminated with it.
34023
e5ac9b53 34024@findex breakpoint annotation
922fbb7b
AC
34025@item ^Z^Zbreakpoint @var{number}
34026The program hit breakpoint number @var{number}.
34027
e5ac9b53 34028@findex watchpoint annotation
922fbb7b
AC
34029@item ^Z^Zwatchpoint @var{number}
34030The program hit watchpoint number @var{number}.
34031@end table
34032
34033@node Source Annotations
34034@section Displaying Source
34035@cindex annotations for source display
34036
e5ac9b53 34037@findex source annotation
922fbb7b
AC
34038The following annotation is used instead of displaying source code:
34039
34040@smallexample
34041^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
34042@end smallexample
34043
34044where @var{filename} is an absolute file name indicating which source
34045file, @var{line} is the line number within that file (where 1 is the
34046first line in the file), @var{character} is the character position
34047within the file (where 0 is the first character in the file) (for most
34048debug formats this will necessarily point to the beginning of a line),
34049@var{middle} is @samp{middle} if @var{addr} is in the middle of the
34050line, or @samp{beg} if @var{addr} is at the beginning of the line, and
34051@var{addr} is the address in the target program associated with the
34052source which is being displayed. @var{addr} is in the form @samp{0x}
34053followed by one or more lowercase hex digits (note that this does not
34054depend on the language).
34055
4efc6507
DE
34056@node JIT Interface
34057@chapter JIT Compilation Interface
34058@cindex just-in-time compilation
34059@cindex JIT compilation interface
34060
34061This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
34062interface. A JIT compiler is a program or library that generates native
34063executable code at runtime and executes it, usually in order to achieve good
34064performance while maintaining platform independence.
34065
34066Programs that use JIT compilation are normally difficult to debug because
34067portions of their code are generated at runtime, instead of being loaded from
34068object files, which is where @value{GDBN} normally finds the program's symbols
34069and debug information. In order to debug programs that use JIT compilation,
34070@value{GDBN} has an interface that allows the program to register in-memory
34071symbol files with @value{GDBN} at runtime.
34072
34073If you are using @value{GDBN} to debug a program that uses this interface, then
34074it should work transparently so long as you have not stripped the binary. If
34075you are developing a JIT compiler, then the interface is documented in the rest
34076of this chapter. At this time, the only known client of this interface is the
34077LLVM JIT.
34078
34079Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
34080JIT compiler communicates with @value{GDBN} by writing data into a global
34081variable and calling a fuction at a well-known symbol. When @value{GDBN}
34082attaches, it reads a linked list of symbol files from the global variable to
34083find existing code, and puts a breakpoint in the function so that it can find
34084out about additional code.
34085
34086@menu
34087* Declarations:: Relevant C struct declarations
34088* Registering Code:: Steps to register code
34089* Unregistering Code:: Steps to unregister code
f85b53f8 34090* Custom Debug Info:: Emit debug information in a custom format
4efc6507
DE
34091@end menu
34092
34093@node Declarations
34094@section JIT Declarations
34095
34096These are the relevant struct declarations that a C program should include to
34097implement the interface:
34098
34099@smallexample
34100typedef enum
34101@{
34102 JIT_NOACTION = 0,
34103 JIT_REGISTER_FN,
34104 JIT_UNREGISTER_FN
34105@} jit_actions_t;
34106
34107struct jit_code_entry
34108@{
34109 struct jit_code_entry *next_entry;
34110 struct jit_code_entry *prev_entry;
34111 const char *symfile_addr;
34112 uint64_t symfile_size;
34113@};
34114
34115struct jit_descriptor
34116@{
34117 uint32_t version;
34118 /* This type should be jit_actions_t, but we use uint32_t
34119 to be explicit about the bitwidth. */
34120 uint32_t action_flag;
34121 struct jit_code_entry *relevant_entry;
34122 struct jit_code_entry *first_entry;
34123@};
34124
34125/* GDB puts a breakpoint in this function. */
34126void __attribute__((noinline)) __jit_debug_register_code() @{ @};
34127
34128/* Make sure to specify the version statically, because the
34129 debugger may check the version before we can set it. */
34130struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
34131@end smallexample
34132
34133If the JIT is multi-threaded, then it is important that the JIT synchronize any
34134modifications to this global data properly, which can easily be done by putting
34135a global mutex around modifications to these structures.
34136
34137@node Registering Code
34138@section Registering Code
34139
34140To register code with @value{GDBN}, the JIT should follow this protocol:
34141
34142@itemize @bullet
34143@item
34144Generate an object file in memory with symbols and other desired debug
34145information. The file must include the virtual addresses of the sections.
34146
34147@item
34148Create a code entry for the file, which gives the start and size of the symbol
34149file.
34150
34151@item
34152Add it to the linked list in the JIT descriptor.
34153
34154@item
34155Point the relevant_entry field of the descriptor at the entry.
34156
34157@item
34158Set @code{action_flag} to @code{JIT_REGISTER} and call
34159@code{__jit_debug_register_code}.
34160@end itemize
34161
34162When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
34163@code{relevant_entry} pointer so it doesn't have to walk the list looking for
34164new code. However, the linked list must still be maintained in order to allow
34165@value{GDBN} to attach to a running process and still find the symbol files.
34166
34167@node Unregistering Code
34168@section Unregistering Code
34169
34170If code is freed, then the JIT should use the following protocol:
34171
34172@itemize @bullet
34173@item
34174Remove the code entry corresponding to the code from the linked list.
34175
34176@item
34177Point the @code{relevant_entry} field of the descriptor at the code entry.
34178
34179@item
34180Set @code{action_flag} to @code{JIT_UNREGISTER} and call
34181@code{__jit_debug_register_code}.
34182@end itemize
34183
34184If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
34185and the JIT will leak the memory used for the associated symbol files.
34186
f85b53f8
SD
34187@node Custom Debug Info
34188@section Custom Debug Info
34189@cindex custom JIT debug info
34190@cindex JIT debug info reader
34191
34192Generating debug information in platform-native file formats (like ELF
34193or COFF) may be an overkill for JIT compilers; especially if all the
34194debug info is used for is displaying a meaningful backtrace. The
34195issue can be resolved by having the JIT writers decide on a debug info
34196format and also provide a reader that parses the debug info generated
34197by the JIT compiler. This section gives a brief overview on writing
34198such a parser. More specific details can be found in the source file
34199@file{gdb/jit-reader.in}, which is also installed as a header at
34200@file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
34201
34202The reader is implemented as a shared object (so this functionality is
34203not available on platforms which don't allow loading shared objects at
34204runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
34205@code{jit-reader-unload} are provided, to be used to load and unload
34206the readers from a preconfigured directory. Once loaded, the shared
34207object is used the parse the debug information emitted by the JIT
34208compiler.
34209
34210@menu
34211* Using JIT Debug Info Readers:: How to use supplied readers correctly
34212* Writing JIT Debug Info Readers:: Creating a debug-info reader
34213@end menu
34214
34215@node Using JIT Debug Info Readers
34216@subsection Using JIT Debug Info Readers
34217@kindex jit-reader-load
34218@kindex jit-reader-unload
34219
34220Readers can be loaded and unloaded using the @code{jit-reader-load}
34221and @code{jit-reader-unload} commands.
34222
34223@table @code
c9fb1240
SD
34224@item jit-reader-load @var{reader}
34225Load the JIT reader named @var{reader}. @var{reader} is a shared
34226object specified as either an absolute or a relative file name. In
34227the latter case, @value{GDBN} will try to load the reader from a
34228pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
34229system (here @var{libdir} is the system library directory, often
34230@file{/usr/local/lib}).
34231
34232Only one reader can be active at a time; trying to load a second
34233reader when one is already loaded will result in @value{GDBN}
34234reporting an error. A new JIT reader can be loaded by first unloading
34235the current one using @code{jit-reader-unload} and then invoking
34236@code{jit-reader-load}.
f85b53f8
SD
34237
34238@item jit-reader-unload
34239Unload the currently loaded JIT reader.
34240
34241@end table
34242
34243@node Writing JIT Debug Info Readers
34244@subsection Writing JIT Debug Info Readers
34245@cindex writing JIT debug info readers
34246
34247As mentioned, a reader is essentially a shared object conforming to a
34248certain ABI. This ABI is described in @file{jit-reader.h}.
34249
34250@file{jit-reader.h} defines the structures, macros and functions
34251required to write a reader. It is installed (along with
34252@value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
34253the system include directory.
34254
34255Readers need to be released under a GPL compatible license. A reader
34256can be declared as released under such a license by placing the macro
34257@code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
34258
34259The entry point for readers is the symbol @code{gdb_init_reader},
34260which is expected to be a function with the prototype
34261
34262@findex gdb_init_reader
34263@smallexample
34264extern struct gdb_reader_funcs *gdb_init_reader (void);
34265@end smallexample
34266
34267@cindex @code{struct gdb_reader_funcs}
34268
34269@code{struct gdb_reader_funcs} contains a set of pointers to callback
34270functions. These functions are executed to read the debug info
34271generated by the JIT compiler (@code{read}), to unwind stack frames
34272(@code{unwind}) and to create canonical frame IDs
34273(@code{get_Frame_id}). It also has a callback that is called when the
34274reader is being unloaded (@code{destroy}). The struct looks like this
34275
34276@smallexample
34277struct gdb_reader_funcs
34278@{
34279 /* Must be set to GDB_READER_INTERFACE_VERSION. */
34280 int reader_version;
34281
34282 /* For use by the reader. */
34283 void *priv_data;
34284
34285 gdb_read_debug_info *read;
34286 gdb_unwind_frame *unwind;
34287 gdb_get_frame_id *get_frame_id;
34288 gdb_destroy_reader *destroy;
34289@};
34290@end smallexample
34291
34292@cindex @code{struct gdb_symbol_callbacks}
34293@cindex @code{struct gdb_unwind_callbacks}
34294
34295The callbacks are provided with another set of callbacks by
34296@value{GDBN} to do their job. For @code{read}, these callbacks are
34297passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
34298and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
34299@code{struct gdb_symbol_callbacks} has callbacks to create new object
34300files and new symbol tables inside those object files. @code{struct
34301gdb_unwind_callbacks} has callbacks to read registers off the current
34302frame and to write out the values of the registers in the previous
34303frame. Both have a callback (@code{target_read}) to read bytes off the
34304target's address space.
34305
d1feda86
YQ
34306@node In-Process Agent
34307@chapter In-Process Agent
34308@cindex debugging agent
34309The traditional debugging model is conceptually low-speed, but works fine,
34310because most bugs can be reproduced in debugging-mode execution. However,
34311as multi-core or many-core processors are becoming mainstream, and
34312multi-threaded programs become more and more popular, there should be more
34313and more bugs that only manifest themselves at normal-mode execution, for
34314example, thread races, because debugger's interference with the program's
34315timing may conceal the bugs. On the other hand, in some applications,
34316it is not feasible for the debugger to interrupt the program's execution
34317long enough for the developer to learn anything helpful about its behavior.
34318If the program's correctness depends on its real-time behavior, delays
34319introduced by a debugger might cause the program to fail, even when the
34320code itself is correct. It is useful to be able to observe the program's
34321behavior without interrupting it.
34322
34323Therefore, traditional debugging model is too intrusive to reproduce
34324some bugs. In order to reduce the interference with the program, we can
34325reduce the number of operations performed by debugger. The
34326@dfn{In-Process Agent}, a shared library, is running within the same
34327process with inferior, and is able to perform some debugging operations
34328itself. As a result, debugger is only involved when necessary, and
34329performance of debugging can be improved accordingly. Note that
34330interference with program can be reduced but can't be removed completely,
34331because the in-process agent will still stop or slow down the program.
34332
34333The in-process agent can interpret and execute Agent Expressions
34334(@pxref{Agent Expressions}) during performing debugging operations. The
34335agent expressions can be used for different purposes, such as collecting
34336data in tracepoints, and condition evaluation in breakpoints.
34337
34338@anchor{Control Agent}
34339You can control whether the in-process agent is used as an aid for
34340debugging with the following commands:
34341
34342@table @code
34343@kindex set agent on
34344@item set agent on
34345Causes the in-process agent to perform some operations on behalf of the
34346debugger. Just which operations requested by the user will be done
34347by the in-process agent depends on the its capabilities. For example,
34348if you request to evaluate breakpoint conditions in the in-process agent,
34349and the in-process agent has such capability as well, then breakpoint
34350conditions will be evaluated in the in-process agent.
34351
34352@kindex set agent off
34353@item set agent off
34354Disables execution of debugging operations by the in-process agent. All
34355of the operations will be performed by @value{GDBN}.
34356
34357@kindex show agent
34358@item show agent
34359Display the current setting of execution of debugging operations by
34360the in-process agent.
34361@end table
34362
16bdd41f
YQ
34363@menu
34364* In-Process Agent Protocol::
34365@end menu
34366
34367@node In-Process Agent Protocol
34368@section In-Process Agent Protocol
34369@cindex in-process agent protocol
34370
34371The in-process agent is able to communicate with both @value{GDBN} and
34372GDBserver (@pxref{In-Process Agent}). This section documents the protocol
34373used for communications between @value{GDBN} or GDBserver and the IPA.
34374In general, @value{GDBN} or GDBserver sends commands
34375(@pxref{IPA Protocol Commands}) and data to in-process agent, and then
34376in-process agent replies back with the return result of the command, or
34377some other information. The data sent to in-process agent is composed
34378of primitive data types, such as 4-byte or 8-byte type, and composite
34379types, which are called objects (@pxref{IPA Protocol Objects}).
34380
34381@menu
34382* IPA Protocol Objects::
34383* IPA Protocol Commands::
34384@end menu
34385
34386@node IPA Protocol Objects
34387@subsection IPA Protocol Objects
34388@cindex ipa protocol objects
34389
34390The commands sent to and results received from agent may contain some
34391complex data types called @dfn{objects}.
34392
34393The in-process agent is running on the same machine with @value{GDBN}
34394or GDBserver, so it doesn't have to handle as much differences between
34395two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
34396However, there are still some differences of two ends in two processes:
34397
34398@enumerate
34399@item
34400word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
34401compiled as a 64-bit executable, while in-process agent is a 32-bit one.
34402@item
34403ABI. Some machines may have multiple types of ABI, @value{GDBN} or
34404GDBserver is compiled with one, and in-process agent is compiled with
34405the other one.
34406@end enumerate
34407
34408Here are the IPA Protocol Objects:
34409
34410@enumerate
34411@item
34412agent expression object. It represents an agent expression
34413(@pxref{Agent Expressions}).
34414@anchor{agent expression object}
34415@item
34416tracepoint action object. It represents a tracepoint action
34417(@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
34418memory, static trace data and to evaluate expression.
34419@anchor{tracepoint action object}
34420@item
34421tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
34422@anchor{tracepoint object}
34423
34424@end enumerate
34425
34426The following table describes important attributes of each IPA protocol
34427object:
34428
34429@multitable @columnfractions .30 .20 .50
34430@headitem Name @tab Size @tab Description
34431@item @emph{agent expression object} @tab @tab
34432@item length @tab 4 @tab length of bytes code
34433@item byte code @tab @var{length} @tab contents of byte code
34434@item @emph{tracepoint action for collecting memory} @tab @tab
34435@item 'M' @tab 1 @tab type of tracepoint action
34436@item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
34437address of the lowest byte to collect, otherwise @var{addr} is the offset
34438of @var{basereg} for memory collecting.
34439@item len @tab 8 @tab length of memory for collecting
34440@item basereg @tab 4 @tab the register number containing the starting
34441memory address for collecting.
34442@item @emph{tracepoint action for collecting registers} @tab @tab
34443@item 'R' @tab 1 @tab type of tracepoint action
34444@item @emph{tracepoint action for collecting static trace data} @tab @tab
34445@item 'L' @tab 1 @tab type of tracepoint action
34446@item @emph{tracepoint action for expression evaluation} @tab @tab
34447@item 'X' @tab 1 @tab type of tracepoint action
34448@item agent expression @tab length of @tab @ref{agent expression object}
34449@item @emph{tracepoint object} @tab @tab
34450@item number @tab 4 @tab number of tracepoint
34451@item address @tab 8 @tab address of tracepoint inserted on
34452@item type @tab 4 @tab type of tracepoint
34453@item enabled @tab 1 @tab enable or disable of tracepoint
34454@item step_count @tab 8 @tab step
34455@item pass_count @tab 8 @tab pass
34456@item numactions @tab 4 @tab number of tracepoint actions
34457@item hit count @tab 8 @tab hit count
34458@item trace frame usage @tab 8 @tab trace frame usage
34459@item compiled_cond @tab 8 @tab compiled condition
34460@item orig_size @tab 8 @tab orig size
34461@item condition @tab 4 if condition is NULL otherwise length of
34462@ref{agent expression object}
34463@tab zero if condition is NULL, otherwise is
34464@ref{agent expression object}
34465@item actions @tab variable
34466@tab numactions number of @ref{tracepoint action object}
34467@end multitable
34468
34469@node IPA Protocol Commands
34470@subsection IPA Protocol Commands
34471@cindex ipa protocol commands
34472
34473The spaces in each command are delimiters to ease reading this commands
34474specification. They don't exist in real commands.
34475
34476@table @samp
34477
34478@item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
34479Installs a new fast tracepoint described by @var{tracepoint_object}
34480(@pxref{tracepoint object}). @var{gdb_jump_pad_head}, 8-byte long, is the
34481head of @dfn{jumppad}, which is used to jump to data collection routine
34482in IPA finally.
34483
34484Replies:
34485@table @samp
34486@item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
34487@var{target_address} is address of tracepoint in the inferior.
34488@var{gdb_jump_pad_head} is updated head of jumppad. Both of
34489@var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
34490@var{fjump} contains a sequence of instructions jump to jumppad entry.
34491@var{fjump_size}, 4-byte long, is the size of @var{fjump}.
34492@item E @var{NN}
34493for an error
34494
34495@end table
34496
7255706c
YQ
34497@item close
34498Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
34499is about to kill inferiors.
34500
16bdd41f
YQ
34501@item qTfSTM
34502@xref{qTfSTM}.
34503@item qTsSTM
34504@xref{qTsSTM}.
34505@item qTSTMat
34506@xref{qTSTMat}.
34507@item probe_marker_at:@var{address}
34508Asks in-process agent to probe the marker at @var{address}.
34509
34510Replies:
34511@table @samp
34512@item E @var{NN}
34513for an error
34514@end table
34515@item unprobe_marker_at:@var{address}
34516Asks in-process agent to unprobe the marker at @var{address}.
34517@end table
34518
8e04817f
AC
34519@node GDB Bugs
34520@chapter Reporting Bugs in @value{GDBN}
34521@cindex bugs in @value{GDBN}
34522@cindex reporting bugs in @value{GDBN}
c906108c 34523
8e04817f 34524Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 34525
8e04817f
AC
34526Reporting a bug may help you by bringing a solution to your problem, or it
34527may not. But in any case the principal function of a bug report is to help
34528the entire community by making the next version of @value{GDBN} work better. Bug
34529reports are your contribution to the maintenance of @value{GDBN}.
c906108c 34530
8e04817f
AC
34531In order for a bug report to serve its purpose, you must include the
34532information that enables us to fix the bug.
c4555f82
SC
34533
34534@menu
8e04817f
AC
34535* Bug Criteria:: Have you found a bug?
34536* Bug Reporting:: How to report bugs
c4555f82
SC
34537@end menu
34538
8e04817f 34539@node Bug Criteria
79a6e687 34540@section Have You Found a Bug?
8e04817f 34541@cindex bug criteria
c4555f82 34542
8e04817f 34543If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
34544
34545@itemize @bullet
8e04817f
AC
34546@cindex fatal signal
34547@cindex debugger crash
34548@cindex crash of debugger
c4555f82 34549@item
8e04817f
AC
34550If the debugger gets a fatal signal, for any input whatever, that is a
34551@value{GDBN} bug. Reliable debuggers never crash.
34552
34553@cindex error on valid input
34554@item
34555If @value{GDBN} produces an error message for valid input, that is a
34556bug. (Note that if you're cross debugging, the problem may also be
34557somewhere in the connection to the target.)
c4555f82 34558
8e04817f 34559@cindex invalid input
c4555f82 34560@item
8e04817f
AC
34561If @value{GDBN} does not produce an error message for invalid input,
34562that is a bug. However, you should note that your idea of
34563``invalid input'' might be our idea of ``an extension'' or ``support
34564for traditional practice''.
34565
34566@item
34567If you are an experienced user of debugging tools, your suggestions
34568for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
34569@end itemize
34570
8e04817f 34571@node Bug Reporting
79a6e687 34572@section How to Report Bugs
8e04817f
AC
34573@cindex bug reports
34574@cindex @value{GDBN} bugs, reporting
34575
34576A number of companies and individuals offer support for @sc{gnu} products.
34577If you obtained @value{GDBN} from a support organization, we recommend you
34578contact that organization first.
34579
34580You can find contact information for many support companies and
34581individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
34582distribution.
34583@c should add a web page ref...
34584
c16158bc
JM
34585@ifset BUGURL
34586@ifset BUGURL_DEFAULT
129188f6 34587In any event, we also recommend that you submit bug reports for
d3e8051b 34588@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
34589@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
34590page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
34591be used.
8e04817f
AC
34592
34593@strong{Do not send bug reports to @samp{info-gdb}, or to
34594@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
34595not want to receive bug reports. Those that do have arranged to receive
34596@samp{bug-gdb}.
34597
34598The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
34599serves as a repeater. The mailing list and the newsgroup carry exactly
34600the same messages. Often people think of posting bug reports to the
34601newsgroup instead of mailing them. This appears to work, but it has one
34602problem which can be crucial: a newsgroup posting often lacks a mail
34603path back to the sender. Thus, if we need to ask for more information,
34604we may be unable to reach you. For this reason, it is better to send
34605bug reports to the mailing list.
c16158bc
JM
34606@end ifset
34607@ifclear BUGURL_DEFAULT
34608In any event, we also recommend that you submit bug reports for
34609@value{GDBN} to @value{BUGURL}.
34610@end ifclear
34611@end ifset
c4555f82 34612
8e04817f
AC
34613The fundamental principle of reporting bugs usefully is this:
34614@strong{report all the facts}. If you are not sure whether to state a
34615fact or leave it out, state it!
c4555f82 34616
8e04817f
AC
34617Often people omit facts because they think they know what causes the
34618problem and assume that some details do not matter. Thus, you might
34619assume that the name of the variable you use in an example does not matter.
34620Well, probably it does not, but one cannot be sure. Perhaps the bug is a
34621stray memory reference which happens to fetch from the location where that
34622name is stored in memory; perhaps, if the name were different, the contents
34623of that location would fool the debugger into doing the right thing despite
34624the bug. Play it safe and give a specific, complete example. That is the
34625easiest thing for you to do, and the most helpful.
c4555f82 34626
8e04817f
AC
34627Keep in mind that the purpose of a bug report is to enable us to fix the
34628bug. It may be that the bug has been reported previously, but neither
34629you nor we can know that unless your bug report is complete and
34630self-contained.
c4555f82 34631
8e04817f
AC
34632Sometimes people give a few sketchy facts and ask, ``Does this ring a
34633bell?'' Those bug reports are useless, and we urge everyone to
34634@emph{refuse to respond to them} except to chide the sender to report
34635bugs properly.
34636
34637To enable us to fix the bug, you should include all these things:
c4555f82
SC
34638
34639@itemize @bullet
34640@item
8e04817f
AC
34641The version of @value{GDBN}. @value{GDBN} announces it if you start
34642with no arguments; you can also print it at any time using @code{show
34643version}.
c4555f82 34644
8e04817f
AC
34645Without this, we will not know whether there is any point in looking for
34646the bug in the current version of @value{GDBN}.
c4555f82
SC
34647
34648@item
8e04817f
AC
34649The type of machine you are using, and the operating system name and
34650version number.
c4555f82
SC
34651
34652@item
c1468174 34653What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 34654``@value{GCC}--2.8.1''.
c4555f82
SC
34655
34656@item
8e04817f 34657What compiler (and its version) was used to compile the program you are
c1468174 34658debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
34659C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
34660to get this information; for other compilers, see the documentation for
34661those compilers.
c4555f82 34662
8e04817f
AC
34663@item
34664The command arguments you gave the compiler to compile your example and
34665observe the bug. For example, did you use @samp{-O}? To guarantee
34666you will not omit something important, list them all. A copy of the
34667Makefile (or the output from make) is sufficient.
c4555f82 34668
8e04817f
AC
34669If we were to try to guess the arguments, we would probably guess wrong
34670and then we might not encounter the bug.
c4555f82 34671
8e04817f
AC
34672@item
34673A complete input script, and all necessary source files, that will
34674reproduce the bug.
c4555f82 34675
8e04817f
AC
34676@item
34677A description of what behavior you observe that you believe is
34678incorrect. For example, ``It gets a fatal signal.''
c4555f82 34679
8e04817f
AC
34680Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
34681will certainly notice it. But if the bug is incorrect output, we might
34682not notice unless it is glaringly wrong. You might as well not give us
34683a chance to make a mistake.
c4555f82 34684
8e04817f
AC
34685Even if the problem you experience is a fatal signal, you should still
34686say so explicitly. Suppose something strange is going on, such as, your
34687copy of @value{GDBN} is out of synch, or you have encountered a bug in
34688the C library on your system. (This has happened!) Your copy might
34689crash and ours would not. If you told us to expect a crash, then when
34690ours fails to crash, we would know that the bug was not happening for
34691us. If you had not told us to expect a crash, then we would not be able
34692to draw any conclusion from our observations.
c4555f82 34693
e0c07bf0
MC
34694@pindex script
34695@cindex recording a session script
34696To collect all this information, you can use a session recording program
34697such as @command{script}, which is available on many Unix systems.
34698Just run your @value{GDBN} session inside @command{script} and then
34699include the @file{typescript} file with your bug report.
34700
34701Another way to record a @value{GDBN} session is to run @value{GDBN}
34702inside Emacs and then save the entire buffer to a file.
34703
8e04817f
AC
34704@item
34705If you wish to suggest changes to the @value{GDBN} source, send us context
34706diffs. If you even discuss something in the @value{GDBN} source, refer to
34707it by context, not by line number.
c4555f82 34708
8e04817f
AC
34709The line numbers in our development sources will not match those in your
34710sources. Your line numbers would convey no useful information to us.
c4555f82 34711
8e04817f 34712@end itemize
c4555f82 34713
8e04817f 34714Here are some things that are not necessary:
c4555f82 34715
8e04817f
AC
34716@itemize @bullet
34717@item
34718A description of the envelope of the bug.
c4555f82 34719
8e04817f
AC
34720Often people who encounter a bug spend a lot of time investigating
34721which changes to the input file will make the bug go away and which
34722changes will not affect it.
c4555f82 34723
8e04817f
AC
34724This is often time consuming and not very useful, because the way we
34725will find the bug is by running a single example under the debugger
34726with breakpoints, not by pure deduction from a series of examples.
34727We recommend that you save your time for something else.
c4555f82 34728
8e04817f
AC
34729Of course, if you can find a simpler example to report @emph{instead}
34730of the original one, that is a convenience for us. Errors in the
34731output will be easier to spot, running under the debugger will take
34732less time, and so on.
c4555f82 34733
8e04817f
AC
34734However, simplification is not vital; if you do not want to do this,
34735report the bug anyway and send us the entire test case you used.
c4555f82 34736
8e04817f
AC
34737@item
34738A patch for the bug.
c4555f82 34739
8e04817f
AC
34740A patch for the bug does help us if it is a good one. But do not omit
34741the necessary information, such as the test case, on the assumption that
34742a patch is all we need. We might see problems with your patch and decide
34743to fix the problem another way, or we might not understand it at all.
c4555f82 34744
8e04817f
AC
34745Sometimes with a program as complicated as @value{GDBN} it is very hard to
34746construct an example that will make the program follow a certain path
34747through the code. If you do not send us the example, we will not be able
34748to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 34749
8e04817f
AC
34750And if we cannot understand what bug you are trying to fix, or why your
34751patch should be an improvement, we will not install it. A test case will
34752help us to understand.
c4555f82 34753
8e04817f
AC
34754@item
34755A guess about what the bug is or what it depends on.
c4555f82 34756
8e04817f
AC
34757Such guesses are usually wrong. Even we cannot guess right about such
34758things without first using the debugger to find the facts.
34759@end itemize
c4555f82 34760
8e04817f
AC
34761@c The readline documentation is distributed with the readline code
34762@c and consists of the two following files:
cc88a640
JK
34763@c rluser.texi
34764@c hsuser.texi
8e04817f
AC
34765@c Use -I with makeinfo to point to the appropriate directory,
34766@c environment var TEXINPUTS with TeX.
39037522 34767@ifclear SYSTEM_READLINE
5bdf8622 34768@include rluser.texi
cc88a640 34769@include hsuser.texi
39037522 34770@end ifclear
c4555f82 34771
4ceed123
JB
34772@node In Memoriam
34773@appendix In Memoriam
34774
9ed350ad
JB
34775The @value{GDBN} project mourns the loss of the following long-time
34776contributors:
4ceed123
JB
34777
34778@table @code
34779@item Fred Fish
9ed350ad
JB
34780Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
34781to Free Software in general. Outside of @value{GDBN}, he was known in
34782the Amiga world for his series of Fish Disks, and the GeekGadget project.
4ceed123
JB
34783
34784@item Michael Snyder
9ed350ad
JB
34785Michael was one of the Global Maintainers of the @value{GDBN} project,
34786with contributions recorded as early as 1996, until 2011. In addition
34787to his day to day participation, he was a large driving force behind
34788adding Reverse Debugging to @value{GDBN}.
4ceed123
JB
34789@end table
34790
34791Beyond their technical contributions to the project, they were also
34792enjoyable members of the Free Software Community. We will miss them.
c4555f82 34793
8e04817f
AC
34794@node Formatting Documentation
34795@appendix Formatting Documentation
c4555f82 34796
8e04817f
AC
34797@cindex @value{GDBN} reference card
34798@cindex reference card
34799The @value{GDBN} 4 release includes an already-formatted reference card, ready
34800for printing with PostScript or Ghostscript, in the @file{gdb}
34801subdirectory of the main source directory@footnote{In
34802@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
34803release.}. If you can use PostScript or Ghostscript with your printer,
34804you can print the reference card immediately with @file{refcard.ps}.
c4555f82 34805
8e04817f
AC
34806The release also includes the source for the reference card. You
34807can format it, using @TeX{}, by typing:
c4555f82 34808
474c8240 34809@smallexample
8e04817f 34810make refcard.dvi
474c8240 34811@end smallexample
c4555f82 34812
8e04817f
AC
34813The @value{GDBN} reference card is designed to print in @dfn{landscape}
34814mode on US ``letter'' size paper;
34815that is, on a sheet 11 inches wide by 8.5 inches
34816high. You will need to specify this form of printing as an option to
34817your @sc{dvi} output program.
c4555f82 34818
8e04817f 34819@cindex documentation
c4555f82 34820
8e04817f
AC
34821All the documentation for @value{GDBN} comes as part of the machine-readable
34822distribution. The documentation is written in Texinfo format, which is
34823a documentation system that uses a single source file to produce both
34824on-line information and a printed manual. You can use one of the Info
34825formatting commands to create the on-line version of the documentation
34826and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 34827
8e04817f
AC
34828@value{GDBN} includes an already formatted copy of the on-line Info
34829version of this manual in the @file{gdb} subdirectory. The main Info
34830file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
34831subordinate files matching @samp{gdb.info*} in the same directory. If
34832necessary, you can print out these files, or read them with any editor;
34833but they are easier to read using the @code{info} subsystem in @sc{gnu}
34834Emacs or the standalone @code{info} program, available as part of the
34835@sc{gnu} Texinfo distribution.
c4555f82 34836
8e04817f
AC
34837If you want to format these Info files yourself, you need one of the
34838Info formatting programs, such as @code{texinfo-format-buffer} or
34839@code{makeinfo}.
c4555f82 34840
8e04817f
AC
34841If you have @code{makeinfo} installed, and are in the top level
34842@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
34843version @value{GDBVN}), you can make the Info file by typing:
c4555f82 34844
474c8240 34845@smallexample
8e04817f
AC
34846cd gdb
34847make gdb.info
474c8240 34848@end smallexample
c4555f82 34849
8e04817f
AC
34850If you want to typeset and print copies of this manual, you need @TeX{},
34851a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
34852Texinfo definitions file.
c4555f82 34853
8e04817f
AC
34854@TeX{} is a typesetting program; it does not print files directly, but
34855produces output files called @sc{dvi} files. To print a typeset
34856document, you need a program to print @sc{dvi} files. If your system
34857has @TeX{} installed, chances are it has such a program. The precise
34858command to use depends on your system; @kbd{lpr -d} is common; another
34859(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
34860require a file name without any extension or a @samp{.dvi} extension.
c4555f82 34861
8e04817f
AC
34862@TeX{} also requires a macro definitions file called
34863@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
34864written in Texinfo format. On its own, @TeX{} cannot either read or
34865typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
34866and is located in the @file{gdb-@var{version-number}/texinfo}
34867directory.
c4555f82 34868
8e04817f 34869If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 34870typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
34871subdirectory of the main source directory (for example, to
34872@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 34873
474c8240 34874@smallexample
8e04817f 34875make gdb.dvi
474c8240 34876@end smallexample
c4555f82 34877
8e04817f 34878Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 34879
8e04817f
AC
34880@node Installing GDB
34881@appendix Installing @value{GDBN}
8e04817f 34882@cindex installation
c4555f82 34883
7fa2210b
DJ
34884@menu
34885* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 34886* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
34887* Separate Objdir:: Compiling @value{GDBN} in another directory
34888* Config Names:: Specifying names for hosts and targets
34889* Configure Options:: Summary of options for configure
098b41a6 34890* System-wide configuration:: Having a system-wide init file
7fa2210b
DJ
34891@end menu
34892
34893@node Requirements
79a6e687 34894@section Requirements for Building @value{GDBN}
7fa2210b
DJ
34895@cindex building @value{GDBN}, requirements for
34896
34897Building @value{GDBN} requires various tools and packages to be available.
34898Other packages will be used only if they are found.
34899
79a6e687 34900@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b
DJ
34901@table @asis
34902@item ISO C90 compiler
34903@value{GDBN} is written in ISO C90. It should be buildable with any
34904working C90 compiler, e.g.@: GCC.
34905
34906@end table
34907
79a6e687 34908@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
34909@table @asis
34910@item Expat
123dc839 34911@anchor{Expat}
7fa2210b
DJ
34912@value{GDBN} can use the Expat XML parsing library. This library may be
34913included with your operating system distribution; if it is not, you
34914can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 34915The @file{configure} script will search for this library in several
7fa2210b
DJ
34916standard locations; if it is installed in an unusual path, you can
34917use the @option{--with-libexpat-prefix} option to specify its location.
34918
9cceb671
DJ
34919Expat is used for:
34920
34921@itemize @bullet
34922@item
34923Remote protocol memory maps (@pxref{Memory Map Format})
34924@item
34925Target descriptions (@pxref{Target Descriptions})
34926@item
2268b414
JK
34927Remote shared library lists (@xref{Library List Format},
34928or alternatively @pxref{Library List Format for SVR4 Targets})
9cceb671
DJ
34929@item
34930MS-Windows shared libraries (@pxref{Shared Libraries})
b3b9301e
PA
34931@item
34932Traceframe info (@pxref{Traceframe Info Format})
2ae8c8e7
MM
34933@item
34934Branch trace (@pxref{Branch Trace Format})
9cceb671 34935@end itemize
7fa2210b 34936
31fffb02
CS
34937@item zlib
34938@cindex compressed debug sections
34939@value{GDBN} will use the @samp{zlib} library, if available, to read
34940compressed debug sections. Some linkers, such as GNU gold, are capable
34941of producing binaries with compressed debug sections. If @value{GDBN}
34942is compiled with @samp{zlib}, it will be able to read the debug
34943information in such binaries.
34944
34945The @samp{zlib} library is likely included with your operating system
34946distribution; if it is not, you can get the latest version from
34947@url{http://zlib.net}.
34948
6c7a06a3
TT
34949@item iconv
34950@value{GDBN}'s features related to character sets (@pxref{Character
34951Sets}) require a functioning @code{iconv} implementation. If you are
34952on a GNU system, then this is provided by the GNU C Library. Some
34953other systems also provide a working @code{iconv}.
34954
478aac75
DE
34955If @value{GDBN} is using the @code{iconv} program which is installed
34956in a non-standard place, you will need to tell @value{GDBN} where to find it.
34957This is done with @option{--with-iconv-bin} which specifies the
34958directory that contains the @code{iconv} program.
34959
34960On systems without @code{iconv}, you can install GNU Libiconv. If you
6c7a06a3
TT
34961have previously installed Libiconv, you can use the
34962@option{--with-libiconv-prefix} option to configure.
34963
34964@value{GDBN}'s top-level @file{configure} and @file{Makefile} will
34965arrange to build Libiconv if a directory named @file{libiconv} appears
34966in the top-most source directory. If Libiconv is built this way, and
34967if the operating system does not provide a suitable @code{iconv}
34968implementation, then the just-built library will automatically be used
34969by @value{GDBN}. One easy way to set this up is to download GNU
34970Libiconv, unpack it, and then rename the directory holding the
34971Libiconv source code to @samp{libiconv}.
7fa2210b
DJ
34972@end table
34973
34974@node Running Configure
db2e3e2e 34975@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 34976@cindex configuring @value{GDBN}
db2e3e2e 34977@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
34978of preparing @value{GDBN} for installation; you can then use @code{make} to
34979build the @code{gdb} program.
34980@iftex
34981@c irrelevant in info file; it's as current as the code it lives with.
34982@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
34983look at the @file{README} file in the sources; we may have improved the
34984installation procedures since publishing this manual.}
34985@end iftex
c4555f82 34986
8e04817f
AC
34987The @value{GDBN} distribution includes all the source code you need for
34988@value{GDBN} in a single directory, whose name is usually composed by
34989appending the version number to @samp{gdb}.
c4555f82 34990
8e04817f
AC
34991For example, the @value{GDBN} version @value{GDBVN} distribution is in the
34992@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 34993
8e04817f
AC
34994@table @code
34995@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
34996script for configuring @value{GDBN} and all its supporting libraries
c4555f82 34997
8e04817f
AC
34998@item gdb-@value{GDBVN}/gdb
34999the source specific to @value{GDBN} itself
c4555f82 35000
8e04817f
AC
35001@item gdb-@value{GDBVN}/bfd
35002source for the Binary File Descriptor library
c906108c 35003
8e04817f
AC
35004@item gdb-@value{GDBVN}/include
35005@sc{gnu} include files
c906108c 35006
8e04817f
AC
35007@item gdb-@value{GDBVN}/libiberty
35008source for the @samp{-liberty} free software library
c906108c 35009
8e04817f
AC
35010@item gdb-@value{GDBVN}/opcodes
35011source for the library of opcode tables and disassemblers
c906108c 35012
8e04817f
AC
35013@item gdb-@value{GDBVN}/readline
35014source for the @sc{gnu} command-line interface
c906108c 35015
8e04817f
AC
35016@item gdb-@value{GDBVN}/glob
35017source for the @sc{gnu} filename pattern-matching subroutine
c906108c 35018
8e04817f
AC
35019@item gdb-@value{GDBVN}/mmalloc
35020source for the @sc{gnu} memory-mapped malloc package
35021@end table
c906108c 35022
db2e3e2e 35023The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
35024from the @file{gdb-@var{version-number}} source directory, which in
35025this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 35026
8e04817f 35027First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 35028if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
35029identifier for the platform on which @value{GDBN} will run as an
35030argument.
c906108c 35031
8e04817f 35032For example:
c906108c 35033
474c8240 35034@smallexample
8e04817f
AC
35035cd gdb-@value{GDBVN}
35036./configure @var{host}
35037make
474c8240 35038@end smallexample
c906108c 35039
8e04817f
AC
35040@noindent
35041where @var{host} is an identifier such as @samp{sun4} or
35042@samp{decstation}, that identifies the platform where @value{GDBN} will run.
db2e3e2e 35043(You can often leave off @var{host}; @file{configure} tries to guess the
8e04817f 35044correct value by examining your system.)
c906108c 35045
8e04817f
AC
35046Running @samp{configure @var{host}} and then running @code{make} builds the
35047@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
35048libraries, then @code{gdb} itself. The configured source files, and the
35049binaries, are left in the corresponding source directories.
c906108c 35050
8e04817f 35051@need 750
db2e3e2e 35052@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
35053system does not recognize this automatically when you run a different
35054shell, you may need to run @code{sh} on it explicitly:
c906108c 35055
474c8240 35056@smallexample
8e04817f 35057sh configure @var{host}
474c8240 35058@end smallexample
c906108c 35059
db2e3e2e 35060If you run @file{configure} from a directory that contains source
8e04817f 35061directories for multiple libraries or programs, such as the
db2e3e2e
BW
35062@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
35063@file{configure}
8e04817f
AC
35064creates configuration files for every directory level underneath (unless
35065you tell it not to, with the @samp{--norecursion} option).
35066
db2e3e2e 35067You should run the @file{configure} script from the top directory in the
94e91d6d 35068source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 35069@file{configure} from one of the subdirectories, you will configure only
94e91d6d 35070that subdirectory. That is usually not what you want. In particular,
db2e3e2e 35071if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
35072of the @file{gdb-@var{version-number}} directory, you will omit the
35073configuration of @file{bfd}, @file{readline}, and other sibling
35074directories of the @file{gdb} subdirectory. This leads to build errors
35075about missing include files such as @file{bfd/bfd.h}.
c906108c 35076
8e04817f
AC
35077You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
35078However, you should make sure that the shell on your path (named by
35079the @samp{SHELL} environment variable) is publicly readable. Remember
35080that @value{GDBN} uses the shell to start your program---some systems refuse to
35081let @value{GDBN} debug child processes whose programs are not readable.
c906108c 35082
8e04817f 35083@node Separate Objdir
79a6e687 35084@section Compiling @value{GDBN} in Another Directory
c906108c 35085
8e04817f
AC
35086If you want to run @value{GDBN} versions for several host or target machines,
35087you need a different @code{gdb} compiled for each combination of
db2e3e2e 35088host and target. @file{configure} is designed to make this easy by
8e04817f
AC
35089allowing you to generate each configuration in a separate subdirectory,
35090rather than in the source directory. If your @code{make} program
35091handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
35092@code{make} in each of these directories builds the @code{gdb}
35093program specified there.
c906108c 35094
db2e3e2e 35095To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 35096with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
35097(You also need to specify a path to find @file{configure}
35098itself from your working directory. If the path to @file{configure}
8e04817f
AC
35099would be the same as the argument to @samp{--srcdir}, you can leave out
35100the @samp{--srcdir} option; it is assumed.)
c906108c 35101
8e04817f
AC
35102For example, with version @value{GDBVN}, you can build @value{GDBN} in a
35103separate directory for a Sun 4 like this:
c906108c 35104
474c8240 35105@smallexample
8e04817f
AC
35106@group
35107cd gdb-@value{GDBVN}
35108mkdir ../gdb-sun4
35109cd ../gdb-sun4
35110../gdb-@value{GDBVN}/configure sun4
35111make
35112@end group
474c8240 35113@end smallexample
c906108c 35114
db2e3e2e 35115When @file{configure} builds a configuration using a remote source
8e04817f
AC
35116directory, it creates a tree for the binaries with the same structure
35117(and using the same names) as the tree under the source directory. In
35118the example, you'd find the Sun 4 library @file{libiberty.a} in the
35119directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
35120@file{gdb-sun4/gdb}.
c906108c 35121
94e91d6d
MC
35122Make sure that your path to the @file{configure} script has just one
35123instance of @file{gdb} in it. If your path to @file{configure} looks
35124like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
35125one subdirectory of @value{GDBN}, not the whole package. This leads to
35126build errors about missing include files such as @file{bfd/bfd.h}.
35127
8e04817f
AC
35128One popular reason to build several @value{GDBN} configurations in separate
35129directories is to configure @value{GDBN} for cross-compiling (where
35130@value{GDBN} runs on one machine---the @dfn{host}---while debugging
35131programs that run on another machine---the @dfn{target}).
35132You specify a cross-debugging target by
db2e3e2e 35133giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 35134
8e04817f
AC
35135When you run @code{make} to build a program or library, you must run
35136it in a configured directory---whatever directory you were in when you
db2e3e2e 35137called @file{configure} (or one of its subdirectories).
c906108c 35138
db2e3e2e 35139The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
35140directory also runs recursively. If you type @code{make} in a source
35141directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
35142directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
35143will build all the required libraries, and then build GDB.
c906108c 35144
8e04817f
AC
35145When you have multiple hosts or targets configured in separate
35146directories, you can run @code{make} on them in parallel (for example,
35147if they are NFS-mounted on each of the hosts); they will not interfere
35148with each other.
c906108c 35149
8e04817f 35150@node Config Names
79a6e687 35151@section Specifying Names for Hosts and Targets
c906108c 35152
db2e3e2e 35153The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
35154script are based on a three-part naming scheme, but some short predefined
35155aliases are also supported. The full naming scheme encodes three pieces
35156of information in the following pattern:
c906108c 35157
474c8240 35158@smallexample
8e04817f 35159@var{architecture}-@var{vendor}-@var{os}
474c8240 35160@end smallexample
c906108c 35161
8e04817f
AC
35162For example, you can use the alias @code{sun4} as a @var{host} argument,
35163or as the value for @var{target} in a @code{--target=@var{target}}
35164option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 35165
db2e3e2e 35166The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 35167any query facility to list all supported host and target names or
db2e3e2e 35168aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
35169@code{config.sub} to map abbreviations to full names; you can read the
35170script, if you wish, or you can use it to test your guesses on
35171abbreviations---for example:
c906108c 35172
8e04817f
AC
35173@smallexample
35174% sh config.sub i386-linux
35175i386-pc-linux-gnu
35176% sh config.sub alpha-linux
35177alpha-unknown-linux-gnu
35178% sh config.sub hp9k700
35179hppa1.1-hp-hpux
35180% sh config.sub sun4
35181sparc-sun-sunos4.1.1
35182% sh config.sub sun3
35183m68k-sun-sunos4.1.1
35184% sh config.sub i986v
35185Invalid configuration `i986v': machine `i986v' not recognized
35186@end smallexample
c906108c 35187
8e04817f
AC
35188@noindent
35189@code{config.sub} is also distributed in the @value{GDBN} source
35190directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 35191
8e04817f 35192@node Configure Options
db2e3e2e 35193@section @file{configure} Options
c906108c 35194
db2e3e2e
BW
35195Here is a summary of the @file{configure} options and arguments that
35196are most often useful for building @value{GDBN}. @file{configure} also has
8e04817f 35197several other options not listed here. @inforef{What Configure
db2e3e2e 35198Does,,configure.info}, for a full explanation of @file{configure}.
c906108c 35199
474c8240 35200@smallexample
8e04817f
AC
35201configure @r{[}--help@r{]}
35202 @r{[}--prefix=@var{dir}@r{]}
35203 @r{[}--exec-prefix=@var{dir}@r{]}
35204 @r{[}--srcdir=@var{dirname}@r{]}
35205 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
35206 @r{[}--target=@var{target}@r{]}
35207 @var{host}
474c8240 35208@end smallexample
c906108c 35209
8e04817f
AC
35210@noindent
35211You may introduce options with a single @samp{-} rather than
35212@samp{--} if you prefer; but you may abbreviate option names if you use
35213@samp{--}.
c906108c 35214
8e04817f
AC
35215@table @code
35216@item --help
db2e3e2e 35217Display a quick summary of how to invoke @file{configure}.
c906108c 35218
8e04817f
AC
35219@item --prefix=@var{dir}
35220Configure the source to install programs and files under directory
35221@file{@var{dir}}.
c906108c 35222
8e04817f
AC
35223@item --exec-prefix=@var{dir}
35224Configure the source to install programs under directory
35225@file{@var{dir}}.
c906108c 35226
8e04817f
AC
35227@c avoid splitting the warning from the explanation:
35228@need 2000
35229@item --srcdir=@var{dirname}
35230@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
35231@code{make} that implements the @code{VPATH} feature.}@*
35232Use this option to make configurations in directories separate from the
35233@value{GDBN} source directories. Among other things, you can use this to
35234build (or maintain) several configurations simultaneously, in separate
db2e3e2e 35235directories. @file{configure} writes configuration-specific files in
8e04817f 35236the current directory, but arranges for them to use the source in the
db2e3e2e 35237directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
35238the working directory in parallel to the source directories below
35239@var{dirname}.
c906108c 35240
8e04817f 35241@item --norecursion
db2e3e2e 35242Configure only the directory level where @file{configure} is executed; do not
8e04817f 35243propagate configuration to subdirectories.
c906108c 35244
8e04817f
AC
35245@item --target=@var{target}
35246Configure @value{GDBN} for cross-debugging programs running on the specified
35247@var{target}. Without this option, @value{GDBN} is configured to debug
35248programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 35249
8e04817f 35250There is no convenient way to generate a list of all available targets.
c906108c 35251
8e04817f
AC
35252@item @var{host} @dots{}
35253Configure @value{GDBN} to run on the specified @var{host}.
c906108c 35254
8e04817f
AC
35255There is no convenient way to generate a list of all available hosts.
35256@end table
c906108c 35257
8e04817f
AC
35258There are many other options available as well, but they are generally
35259needed for special purposes only.
c906108c 35260
098b41a6
JG
35261@node System-wide configuration
35262@section System-wide configuration and settings
35263@cindex system-wide init file
35264
35265@value{GDBN} can be configured to have a system-wide init file;
35266this file will be read and executed at startup (@pxref{Startup, , What
35267@value{GDBN} does during startup}).
35268
35269Here is the corresponding configure option:
35270
35271@table @code
35272@item --with-system-gdbinit=@var{file}
35273Specify that the default location of the system-wide init file is
35274@var{file}.
35275@end table
35276
35277If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
35278it may be subject to relocation. Two possible cases:
35279
35280@itemize @bullet
35281@item
35282If the default location of this init file contains @file{$prefix},
35283it will be subject to relocation. Suppose that the configure options
35284are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
35285if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
35286init file is looked for as @file{$install/etc/gdbinit} instead of
35287@file{$prefix/etc/gdbinit}.
35288
35289@item
35290By contrast, if the default location does not contain the prefix,
35291it will not be relocated. E.g.@: if @value{GDBN} has been configured with
35292@option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
35293then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
35294wherever @value{GDBN} is installed.
35295@end itemize
35296
e64e0392
DE
35297If the configured location of the system-wide init file (as given by the
35298@option{--with-system-gdbinit} option at configure time) is in the
35299data-directory (as specified by @option{--with-gdb-datadir} at configure
35300time) or in one of its subdirectories, then @value{GDBN} will look for the
35301system-wide init file in the directory specified by the
35302@option{--data-directory} command-line option.
35303Note that the system-wide init file is only read once, during @value{GDBN}
35304initialization. If the data-directory is changed after @value{GDBN} has
35305started with the @code{set data-directory} command, the file will not be
35306reread.
35307
8e04817f
AC
35308@node Maintenance Commands
35309@appendix Maintenance Commands
35310@cindex maintenance commands
35311@cindex internal commands
c906108c 35312
8e04817f 35313In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
35314includes a number of commands intended for @value{GDBN} developers,
35315that are not documented elsewhere in this manual. These commands are
da316a69
EZ
35316provided here for reference. (For commands that turn on debugging
35317messages, see @ref{Debugging Output}.)
c906108c 35318
8e04817f 35319@table @code
09d4efe1 35320@kindex maint agent
782b2b07 35321@kindex maint agent-eval
f77cc5f0
HZ
35322@item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
35323@itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
09d4efe1
EZ
35324Translate the given @var{expression} into remote agent bytecodes.
35325This command is useful for debugging the Agent Expression mechanism
782b2b07
SS
35326(@pxref{Agent Expressions}). The @samp{agent} version produces an
35327expression useful for data collection, such as by tracepoints, while
35328@samp{maint agent-eval} produces an expression that evaluates directly
35329to a result. For instance, a collection expression for @code{globa +
35330globb} will include bytecodes to record four bytes of memory at each
35331of the addresses of @code{globa} and @code{globb}, while discarding
35332the result of the addition, while an evaluation expression will do the
35333addition and return the sum.
f77cc5f0
HZ
35334If @code{-at} is given, generate remote agent bytecode for @var{location}.
35335If not, generate remote agent bytecode for current frame PC address.
09d4efe1 35336
d3ce09f5
SS
35337@kindex maint agent-printf
35338@item maint agent-printf @var{format},@var{expr},...
35339Translate the given format string and list of argument expressions
35340into remote agent bytecodes and display them as a disassembled list.
35341This command is useful for debugging the agent version of dynamic
6dd24dfa 35342printf (@pxref{Dynamic Printf}).
d3ce09f5 35343
8e04817f
AC
35344@kindex maint info breakpoints
35345@item @anchor{maint info breakpoints}maint info breakpoints
35346Using the same format as @samp{info breakpoints}, display both the
35347breakpoints you've set explicitly, and those @value{GDBN} is using for
35348internal purposes. Internal breakpoints are shown with negative
35349breakpoint numbers. The type column identifies what kind of breakpoint
35350is shown:
c906108c 35351
8e04817f
AC
35352@table @code
35353@item breakpoint
35354Normal, explicitly set breakpoint.
c906108c 35355
8e04817f
AC
35356@item watchpoint
35357Normal, explicitly set watchpoint.
c906108c 35358
8e04817f
AC
35359@item longjmp
35360Internal breakpoint, used to handle correctly stepping through
35361@code{longjmp} calls.
c906108c 35362
8e04817f
AC
35363@item longjmp resume
35364Internal breakpoint at the target of a @code{longjmp}.
c906108c 35365
8e04817f
AC
35366@item until
35367Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 35368
8e04817f
AC
35369@item finish
35370Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 35371
8e04817f
AC
35372@item shlib events
35373Shared library events.
c906108c 35374
8e04817f 35375@end table
c906108c 35376
d6b28940
TT
35377@kindex maint info bfds
35378@item maint info bfds
35379This prints information about each @code{bfd} object that is known to
35380@value{GDBN}. @xref{Top, , BFD, bfd, The Binary File Descriptor Library}.
35381
fff08868
HZ
35382@kindex set displaced-stepping
35383@kindex show displaced-stepping
237fc4c9
PA
35384@cindex displaced stepping support
35385@cindex out-of-line single-stepping
fff08868
HZ
35386@item set displaced-stepping
35387@itemx show displaced-stepping
237fc4c9 35388Control whether or not @value{GDBN} will do @dfn{displaced stepping}
fff08868
HZ
35389if the target supports it. Displaced stepping is a way to single-step
35390over breakpoints without removing them from the inferior, by executing
35391an out-of-line copy of the instruction that was originally at the
35392breakpoint location. It is also known as out-of-line single-stepping.
35393
35394@table @code
35395@item set displaced-stepping on
35396If the target architecture supports it, @value{GDBN} will use
35397displaced stepping to step over breakpoints.
35398
35399@item set displaced-stepping off
35400@value{GDBN} will not use displaced stepping to step over breakpoints,
35401even if such is supported by the target architecture.
35402
35403@cindex non-stop mode, and @samp{set displaced-stepping}
35404@item set displaced-stepping auto
35405This is the default mode. @value{GDBN} will use displaced stepping
35406only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
35407architecture supports displaced stepping.
35408@end table
237fc4c9 35409
09d4efe1
EZ
35410@kindex maint check-symtabs
35411@item maint check-symtabs
35412Check the consistency of psymtabs and symtabs.
35413
35414@kindex maint cplus first_component
35415@item maint cplus first_component @var{name}
35416Print the first C@t{++} class/namespace component of @var{name}.
35417
35418@kindex maint cplus namespace
35419@item maint cplus namespace
35420Print the list of possible C@t{++} namespaces.
35421
35422@kindex maint demangle
35423@item maint demangle @var{name}
d3e8051b 35424Demangle a C@t{++} or Objective-C mangled @var{name}.
09d4efe1
EZ
35425
35426@kindex maint deprecate
35427@kindex maint undeprecate
35428@cindex deprecated commands
35429@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
35430@itemx maint undeprecate @var{command}
35431Deprecate or undeprecate the named @var{command}. Deprecated commands
35432cause @value{GDBN} to issue a warning when you use them. The optional
35433argument @var{replacement} says which newer command should be used in
35434favor of the deprecated one; if it is given, @value{GDBN} will mention
35435the replacement as part of the warning.
35436
35437@kindex maint dump-me
35438@item maint dump-me
721c2651 35439@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 35440Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
35441This is supported only on systems which support aborting a program
35442with the @code{SIGQUIT} signal.
09d4efe1 35443
8d30a00d
AC
35444@kindex maint internal-error
35445@kindex maint internal-warning
09d4efe1
EZ
35446@item maint internal-error @r{[}@var{message-text}@r{]}
35447@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
35448Cause @value{GDBN} to call the internal function @code{internal_error}
35449or @code{internal_warning} and hence behave as though an internal error
35450or internal warning has been detected. In addition to reporting the
35451internal problem, these functions give the user the opportunity to
35452either quit @value{GDBN} or create a core file of the current
35453@value{GDBN} session.
35454
09d4efe1
EZ
35455These commands take an optional parameter @var{message-text} that is
35456used as the text of the error or warning message.
35457
d3e8051b 35458Here's an example of using @code{internal-error}:
09d4efe1 35459
8d30a00d 35460@smallexample
f7dc1244 35461(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
35462@dots{}/maint.c:121: internal-error: testing, 1, 2
35463A problem internal to GDB has been detected. Further
35464debugging may prove unreliable.
35465Quit this debugging session? (y or n) @kbd{n}
35466Create a core file? (y or n) @kbd{n}
f7dc1244 35467(@value{GDBP})
8d30a00d
AC
35468@end smallexample
35469
3c16cced
PA
35470@cindex @value{GDBN} internal error
35471@cindex internal errors, control of @value{GDBN} behavior
35472
35473@kindex maint set internal-error
35474@kindex maint show internal-error
35475@kindex maint set internal-warning
35476@kindex maint show internal-warning
35477@item maint set internal-error @var{action} [ask|yes|no]
35478@itemx maint show internal-error @var{action}
35479@itemx maint set internal-warning @var{action} [ask|yes|no]
35480@itemx maint show internal-warning @var{action}
35481When @value{GDBN} reports an internal problem (error or warning) it
35482gives the user the opportunity to both quit @value{GDBN} and create a
35483core file of the current @value{GDBN} session. These commands let you
35484override the default behaviour for each particular @var{action},
35485described in the table below.
35486
35487@table @samp
35488@item quit
35489You can specify that @value{GDBN} should always (yes) or never (no)
35490quit. The default is to ask the user what to do.
35491
35492@item corefile
35493You can specify that @value{GDBN} should always (yes) or never (no)
35494create a core file. The default is to ask the user what to do.
35495@end table
35496
09d4efe1
EZ
35497@kindex maint packet
35498@item maint packet @var{text}
35499If @value{GDBN} is talking to an inferior via the serial protocol,
35500then this command sends the string @var{text} to the inferior, and
35501displays the response packet. @value{GDBN} supplies the initial
35502@samp{$} character, the terminating @samp{#} character, and the
35503checksum.
35504
35505@kindex maint print architecture
35506@item maint print architecture @r{[}@var{file}@r{]}
35507Print the entire architecture configuration. The optional argument
35508@var{file} names the file where the output goes.
8d30a00d 35509
81adfced
DJ
35510@kindex maint print c-tdesc
35511@item maint print c-tdesc
35512Print the current target description (@pxref{Target Descriptions}) as
35513a C source file. The created source file can be used in @value{GDBN}
35514when an XML parser is not available to parse the description.
35515
00905d52
AC
35516@kindex maint print dummy-frames
35517@item maint print dummy-frames
00905d52
AC
35518Prints the contents of @value{GDBN}'s internal dummy-frame stack.
35519
35520@smallexample
f7dc1244 35521(@value{GDBP}) @kbd{b add}
00905d52 35522@dots{}
f7dc1244 35523(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
35524Breakpoint 2, add (a=2, b=3) at @dots{}
3552558 return (a + b);
35526The program being debugged stopped while in a function called from GDB.
35527@dots{}
f7dc1244 35528(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
355290x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
35530 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
35531 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 35532(@value{GDBP})
00905d52
AC
35533@end smallexample
35534
35535Takes an optional file parameter.
35536
0680b120
AC
35537@kindex maint print registers
35538@kindex maint print raw-registers
35539@kindex maint print cooked-registers
617073a9 35540@kindex maint print register-groups
c21236dc 35541@kindex maint print remote-registers
09d4efe1
EZ
35542@item maint print registers @r{[}@var{file}@r{]}
35543@itemx maint print raw-registers @r{[}@var{file}@r{]}
35544@itemx maint print cooked-registers @r{[}@var{file}@r{]}
35545@itemx maint print register-groups @r{[}@var{file}@r{]}
c21236dc 35546@itemx maint print remote-registers @r{[}@var{file}@r{]}
0680b120
AC
35547Print @value{GDBN}'s internal register data structures.
35548
617073a9 35549The command @code{maint print raw-registers} includes the contents of
c21236dc
PA
35550the raw register cache; the command @code{maint print
35551cooked-registers} includes the (cooked) value of all registers,
35552including registers which aren't available on the target nor visible
35553to user; the command @code{maint print register-groups} includes the
35554groups that each register is a member of; and the command @code{maint
35555print remote-registers} includes the remote target's register numbers
35556and offsets in the `G' packets. @xref{Registers,, Registers, gdbint,
617073a9 35557@value{GDBN} Internals}.
0680b120 35558
09d4efe1
EZ
35559These commands take an optional parameter, a file name to which to
35560write the information.
0680b120 35561
617073a9 35562@kindex maint print reggroups
09d4efe1
EZ
35563@item maint print reggroups @r{[}@var{file}@r{]}
35564Print @value{GDBN}'s internal register group data structures. The
35565optional argument @var{file} tells to what file to write the
35566information.
617073a9 35567
09d4efe1 35568The register groups info looks like this:
617073a9
AC
35569
35570@smallexample
f7dc1244 35571(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
35572 Group Type
35573 general user
35574 float user
35575 all user
35576 vector user
35577 system user
35578 save internal
35579 restore internal
617073a9
AC
35580@end smallexample
35581
09d4efe1
EZ
35582@kindex flushregs
35583@item flushregs
35584This command forces @value{GDBN} to flush its internal register cache.
35585
35586@kindex maint print objfiles
35587@cindex info for known object files
35588@item maint print objfiles
35589Print a dump of all known object files. For each object file, this
35590command prints its name, address in memory, and all of its psymtabs
35591and symtabs.
35592
8a1ea21f
DE
35593@kindex maint print section-scripts
35594@cindex info for known .debug_gdb_scripts-loaded scripts
35595@item maint print section-scripts [@var{regexp}]
35596Print a dump of scripts specified in the @code{.debug_gdb_section} section.
35597If @var{regexp} is specified, only print scripts loaded by object files
35598matching @var{regexp}.
35599For each script, this command prints its name as specified in the objfile,
35600and the full path if known.
8e0583c8 35601@xref{dotdebug_gdb_scripts section}.
8a1ea21f 35602
09d4efe1
EZ
35603@kindex maint print statistics
35604@cindex bcache statistics
35605@item maint print statistics
35606This command prints, for each object file in the program, various data
35607about that object file followed by the byte cache (@dfn{bcache})
35608statistics for the object file. The objfile data includes the number
d3e8051b 35609of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
35610defined by the objfile, the number of as yet unexpanded psym tables,
35611the number of line tables and string tables, and the amount of memory
35612used by the various tables. The bcache statistics include the counts,
35613sizes, and counts of duplicates of all and unique objects, max,
35614average, and median entry size, total memory used and its overhead and
35615savings, and various measures of the hash table size and chain
35616lengths.
35617
c7ba131e
JB
35618@kindex maint print target-stack
35619@cindex target stack description
35620@item maint print target-stack
35621A @dfn{target} is an interface between the debugger and a particular
35622kind of file or process. Targets can be stacked in @dfn{strata},
35623so that more than one target can potentially respond to a request.
35624In particular, memory accesses will walk down the stack of targets
35625until they find a target that is interested in handling that particular
35626address.
35627
35628This command prints a short description of each layer that was pushed on
35629the @dfn{target stack}, starting from the top layer down to the bottom one.
35630
09d4efe1
EZ
35631@kindex maint print type
35632@cindex type chain of a data type
35633@item maint print type @var{expr}
35634Print the type chain for a type specified by @var{expr}. The argument
35635can be either a type name or a symbol. If it is a symbol, the type of
35636that symbol is described. The type chain produced by this command is
35637a recursive definition of the data type as stored in @value{GDBN}'s
35638data structures, including its flags and contained types.
35639
9eae7c52
TT
35640@kindex maint set dwarf2 always-disassemble
35641@kindex maint show dwarf2 always-disassemble
35642@item maint set dwarf2 always-disassemble
35643@item maint show dwarf2 always-disassemble
35644Control the behavior of @code{info address} when using DWARF debugging
35645information.
35646
35647The default is @code{off}, which means that @value{GDBN} should try to
35648describe a variable's location in an easily readable format. When
35649@code{on}, @value{GDBN} will instead display the DWARF location
35650expression in an assembly-like format. Note that some locations are
35651too complex for @value{GDBN} to describe simply; in this case you will
35652always see the disassembly form.
35653
35654Here is an example of the resulting disassembly:
35655
35656@smallexample
35657(gdb) info addr argc
35658Symbol "argc" is a complex DWARF expression:
35659 1: DW_OP_fbreg 0
35660@end smallexample
35661
35662For more information on these expressions, see
35663@uref{http://www.dwarfstd.org/, the DWARF standard}.
35664
09d4efe1
EZ
35665@kindex maint set dwarf2 max-cache-age
35666@kindex maint show dwarf2 max-cache-age
35667@item maint set dwarf2 max-cache-age
35668@itemx maint show dwarf2 max-cache-age
35669Control the DWARF 2 compilation unit cache.
35670
35671@cindex DWARF 2 compilation units cache
35672In object files with inter-compilation-unit references, such as those
35673produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
35674reader needs to frequently refer to previously read compilation units.
35675This setting controls how long a compilation unit will remain in the
35676cache if it is not referenced. A higher limit means that cached
35677compilation units will be stored in memory longer, and more total
35678memory will be used. Setting it to zero disables caching, which will
35679slow down @value{GDBN} startup, but reduce memory consumption.
35680
e7ba9c65
DJ
35681@kindex maint set profile
35682@kindex maint show profile
35683@cindex profiling GDB
35684@item maint set profile
35685@itemx maint show profile
35686Control profiling of @value{GDBN}.
35687
35688Profiling will be disabled until you use the @samp{maint set profile}
35689command to enable it. When you enable profiling, the system will begin
35690collecting timing and execution count data; when you disable profiling or
35691exit @value{GDBN}, the results will be written to a log file. Remember that
35692if you use profiling, @value{GDBN} will overwrite the profiling log file
35693(often called @file{gmon.out}). If you have a record of important profiling
35694data in a @file{gmon.out} file, be sure to move it to a safe location.
35695
35696Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 35697compiled with the @samp{-pg} compiler option.
e7ba9c65 35698
cbe54154
PA
35699@kindex maint set show-debug-regs
35700@kindex maint show show-debug-regs
eac35c4e 35701@cindex hardware debug registers
cbe54154
PA
35702@item maint set show-debug-regs
35703@itemx maint show show-debug-regs
eac35c4e 35704Control whether to show variables that mirror the hardware debug
09d4efe1 35705registers. Use @code{ON} to enable, @code{OFF} to disable. If
3f94c067 35706enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
35707removes a hardware breakpoint or watchpoint, and when the inferior
35708triggers a hardware-assisted breakpoint or watchpoint.
35709
711e434b
PM
35710@kindex maint set show-all-tib
35711@kindex maint show show-all-tib
35712@item maint set show-all-tib
35713@itemx maint show show-all-tib
35714Control whether to show all non zero areas within a 1k block starting
35715at thread local base, when using the @samp{info w32 thread-information-block}
35716command.
35717
09d4efe1
EZ
35718@kindex maint space
35719@cindex memory used by commands
35720@item maint space
35721Control whether to display memory usage for each command. If set to a
35722nonzero value, @value{GDBN} will display how much memory each command
35723took, following the command's own output. This can also be requested
35724by invoking @value{GDBN} with the @option{--statistics} command-line
35725switch (@pxref{Mode Options}).
35726
35727@kindex maint time
35728@cindex time of command execution
35729@item maint time
0a1c4d10
DE
35730Control whether to display the execution time of @value{GDBN} for each command.
35731If set to a nonzero value, @value{GDBN} will display how much time it
09d4efe1 35732took to execute each command, following the command's own output.
0a1c4d10
DE
35733Both CPU time and wallclock time are printed.
35734Printing both is useful when trying to determine whether the cost is
35735CPU or, e.g., disk/network, latency.
35736Note that the CPU time printed is for @value{GDBN} only, it does not include
35737the execution time of the inferior because there's no mechanism currently
35738to compute how much time was spent by @value{GDBN} and how much time was
35739spent by the program been debugged.
09d4efe1
EZ
35740This can also be requested by invoking @value{GDBN} with the
35741@option{--statistics} command-line switch (@pxref{Mode Options}).
35742
35743@kindex maint translate-address
35744@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
35745Find the symbol stored at the location specified by the address
35746@var{addr} and an optional section name @var{section}. If found,
35747@value{GDBN} prints the name of the closest symbol and an offset from
35748the symbol's location to the specified address. This is similar to
35749the @code{info address} command (@pxref{Symbols}), except that this
35750command also allows to find symbols in other sections.
ae038cb0 35751
c14c28ba
PP
35752If section was not specified, the section in which the symbol was found
35753is also printed. For dynamically linked executables, the name of
35754executable or shared library containing the symbol is printed as well.
35755
8e04817f 35756@end table
c906108c 35757
9c16f35a
EZ
35758The following command is useful for non-interactive invocations of
35759@value{GDBN}, such as in the test suite.
35760
35761@table @code
35762@item set watchdog @var{nsec}
35763@kindex set watchdog
35764@cindex watchdog timer
35765@cindex timeout for commands
35766Set the maximum number of seconds @value{GDBN} will wait for the
35767target operation to finish. If this time expires, @value{GDBN}
35768reports and error and the command is aborted.
35769
35770@item show watchdog
35771Show the current setting of the target wait timeout.
35772@end table
c906108c 35773
e0ce93ac 35774@node Remote Protocol
8e04817f 35775@appendix @value{GDBN} Remote Serial Protocol
c906108c 35776
ee2d5c50
AC
35777@menu
35778* Overview::
35779* Packets::
35780* Stop Reply Packets::
35781* General Query Packets::
a1dcb23a 35782* Architecture-Specific Protocol Details::
9d29849a 35783* Tracepoint Packets::
a6b151f1 35784* Host I/O Packets::
9a6253be 35785* Interrupts::
8b23ecc4
SL
35786* Notification Packets::
35787* Remote Non-Stop::
a6f3e723 35788* Packet Acknowledgment::
ee2d5c50 35789* Examples::
79a6e687 35790* File-I/O Remote Protocol Extension::
cfa9d6d9 35791* Library List Format::
2268b414 35792* Library List Format for SVR4 Targets::
79a6e687 35793* Memory Map Format::
dc146f7c 35794* Thread List Format::
b3b9301e 35795* Traceframe Info Format::
2ae8c8e7 35796* Branch Trace Format::
ee2d5c50
AC
35797@end menu
35798
35799@node Overview
35800@section Overview
35801
8e04817f
AC
35802There may be occasions when you need to know something about the
35803protocol---for example, if there is only one serial port to your target
35804machine, you might want your program to do something special if it
35805recognizes a packet meant for @value{GDBN}.
c906108c 35806
d2c6833e 35807In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 35808transmitted and received data, respectively.
c906108c 35809
8e04817f
AC
35810@cindex protocol, @value{GDBN} remote serial
35811@cindex serial protocol, @value{GDBN} remote
35812@cindex remote serial protocol
8b23ecc4
SL
35813All @value{GDBN} commands and responses (other than acknowledgments
35814and notifications, see @ref{Notification Packets}) are sent as a
35815@var{packet}. A @var{packet} is introduced with the character
8e04817f
AC
35816@samp{$}, the actual @var{packet-data}, and the terminating character
35817@samp{#} followed by a two-digit @var{checksum}:
c906108c 35818
474c8240 35819@smallexample
8e04817f 35820@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 35821@end smallexample
8e04817f 35822@noindent
c906108c 35823
8e04817f
AC
35824@cindex checksum, for @value{GDBN} remote
35825@noindent
35826The two-digit @var{checksum} is computed as the modulo 256 sum of all
35827characters between the leading @samp{$} and the trailing @samp{#} (an
35828eight bit unsigned checksum).
c906108c 35829
8e04817f
AC
35830Implementors should note that prior to @value{GDBN} 5.0 the protocol
35831specification also included an optional two-digit @var{sequence-id}:
c906108c 35832
474c8240 35833@smallexample
8e04817f 35834@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 35835@end smallexample
c906108c 35836
8e04817f
AC
35837@cindex sequence-id, for @value{GDBN} remote
35838@noindent
35839That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
35840has never output @var{sequence-id}s. Stubs that handle packets added
35841since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 35842
8e04817f
AC
35843When either the host or the target machine receives a packet, the first
35844response expected is an acknowledgment: either @samp{+} (to indicate
35845the package was received correctly) or @samp{-} (to request
35846retransmission):
c906108c 35847
474c8240 35848@smallexample
d2c6833e
AC
35849-> @code{$}@var{packet-data}@code{#}@var{checksum}
35850<- @code{+}
474c8240 35851@end smallexample
8e04817f 35852@noindent
53a5351d 35853
a6f3e723
SL
35854The @samp{+}/@samp{-} acknowledgments can be disabled
35855once a connection is established.
35856@xref{Packet Acknowledgment}, for details.
35857
8e04817f
AC
35858The host (@value{GDBN}) sends @var{command}s, and the target (the
35859debugging stub incorporated in your program) sends a @var{response}. In
35860the case of step and continue @var{command}s, the response is only sent
8b23ecc4
SL
35861when the operation has completed, and the target has again stopped all
35862threads in all attached processes. This is the default all-stop mode
35863behavior, but the remote protocol also supports @value{GDBN}'s non-stop
35864execution mode; see @ref{Remote Non-Stop}, for details.
c906108c 35865
8e04817f
AC
35866@var{packet-data} consists of a sequence of characters with the
35867exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
35868exceptions).
c906108c 35869
ee2d5c50 35870@cindex remote protocol, field separator
0876f84a 35871Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 35872@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 35873@sc{hex} with leading zeros suppressed.
c906108c 35874
8e04817f
AC
35875Implementors should note that prior to @value{GDBN} 5.0, the character
35876@samp{:} could not appear as the third character in a packet (as it
35877would potentially conflict with the @var{sequence-id}).
c906108c 35878
0876f84a
DJ
35879@cindex remote protocol, binary data
35880@anchor{Binary Data}
35881Binary data in most packets is encoded either as two hexadecimal
35882digits per byte of binary data. This allowed the traditional remote
35883protocol to work over connections which were only seven-bit clean.
35884Some packets designed more recently assume an eight-bit clean
35885connection, and use a more efficient encoding to send and receive
35886binary data.
35887
35888The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
35889as an escape character. Any escaped byte is transmitted as the escape
35890character followed by the original character XORed with @code{0x20}.
35891For example, the byte @code{0x7d} would be transmitted as the two
35892bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
35893@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
35894@samp{@}}) must always be escaped. Responses sent by the stub
35895must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
35896is not interpreted as the start of a run-length encoded sequence
35897(described next).
35898
1d3811f6
DJ
35899Response @var{data} can be run-length encoded to save space.
35900Run-length encoding replaces runs of identical characters with one
35901instance of the repeated character, followed by a @samp{*} and a
35902repeat count. The repeat count is itself sent encoded, to avoid
35903binary characters in @var{data}: a value of @var{n} is sent as
35904@code{@var{n}+29}. For a repeat count greater or equal to 3, this
35905produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
35906code 32) for a repeat count of 3. (This is because run-length
35907encoding starts to win for counts 3 or more.) Thus, for example,
35908@samp{0* } is a run-length encoding of ``0000'': the space character
35909after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
359103}} more times.
35911
35912The printable characters @samp{#} and @samp{$} or with a numeric value
35913greater than 126 must not be used. Runs of six repeats (@samp{#}) or
35914seven repeats (@samp{$}) can be expanded using a repeat count of only
35915five (@samp{"}). For example, @samp{00000000} can be encoded as
35916@samp{0*"00}.
c906108c 35917
8e04817f
AC
35918The error response returned for some packets includes a two character
35919error number. That number is not well defined.
c906108c 35920
f8da2bff 35921@cindex empty response, for unsupported packets
8e04817f
AC
35922For any @var{command} not supported by the stub, an empty response
35923(@samp{$#00}) should be returned. That way it is possible to extend the
35924protocol. A newer @value{GDBN} can tell if a packet is supported based
35925on that response.
c906108c 35926
393eab54
PA
35927At a minimum, a stub is required to support the @samp{g} and @samp{G}
35928commands for register access, and the @samp{m} and @samp{M} commands
35929for memory access. Stubs that only control single-threaded targets
35930can implement run control with the @samp{c} (continue), and @samp{s}
35931(step) commands. Stubs that support multi-threading targets should
35932support the @samp{vCont} command. All other commands are optional.
c906108c 35933
ee2d5c50
AC
35934@node Packets
35935@section Packets
35936
35937The following table provides a complete list of all currently defined
35938@var{command}s and their corresponding response @var{data}.
79a6e687 35939@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 35940I/O extension of the remote protocol.
ee2d5c50 35941
b8ff78ce
JB
35942Each packet's description has a template showing the packet's overall
35943syntax, followed by an explanation of the packet's meaning. We
35944include spaces in some of the templates for clarity; these are not
35945part of the packet's syntax. No @value{GDBN} packet uses spaces to
35946separate its components. For example, a template like @samp{foo
35947@var{bar} @var{baz}} describes a packet beginning with the three ASCII
35948bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 35949@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
35950@samp{foo} and the @var{bar}, or between the @var{bar} and the
35951@var{baz}.
35952
b90a069a
SL
35953@cindex @var{thread-id}, in remote protocol
35954@anchor{thread-id syntax}
35955Several packets and replies include a @var{thread-id} field to identify
35956a thread. Normally these are positive numbers with a target-specific
35957interpretation, formatted as big-endian hex strings. A @var{thread-id}
35958can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
35959pick any thread.
35960
35961In addition, the remote protocol supports a multiprocess feature in
35962which the @var{thread-id} syntax is extended to optionally include both
35963process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
35964The @var{pid} (process) and @var{tid} (thread) components each have the
35965format described above: a positive number with target-specific
35966interpretation formatted as a big-endian hex string, literal @samp{-1}
35967to indicate all processes or threads (respectively), or @samp{0} to
35968indicate an arbitrary process or thread. Specifying just a process, as
35969@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
35970error to specify all processes but a specific thread, such as
35971@samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
35972for those packets and replies explicitly documented to include a process
35973ID, rather than a @var{thread-id}.
35974
35975The multiprocess @var{thread-id} syntax extensions are only used if both
35976@value{GDBN} and the stub report support for the @samp{multiprocess}
35977feature using @samp{qSupported}. @xref{multiprocess extensions}, for
35978more information.
35979
8ffe2530
JB
35980Note that all packet forms beginning with an upper- or lower-case
35981letter, other than those described here, are reserved for future use.
35982
b8ff78ce 35983Here are the packet descriptions.
ee2d5c50 35984
b8ff78ce 35985@table @samp
ee2d5c50 35986
b8ff78ce
JB
35987@item !
35988@cindex @samp{!} packet
2d717e4f 35989@anchor{extended mode}
8e04817f
AC
35990Enable extended mode. In extended mode, the remote server is made
35991persistent. The @samp{R} packet is used to restart the program being
35992debugged.
ee2d5c50
AC
35993
35994Reply:
35995@table @samp
35996@item OK
8e04817f 35997The remote target both supports and has enabled extended mode.
ee2d5c50 35998@end table
c906108c 35999
b8ff78ce
JB
36000@item ?
36001@cindex @samp{?} packet
ee2d5c50 36002Indicate the reason the target halted. The reply is the same as for
8b23ecc4
SL
36003step and continue. This packet has a special interpretation when the
36004target is in non-stop mode; see @ref{Remote Non-Stop}.
c906108c 36005
ee2d5c50
AC
36006Reply:
36007@xref{Stop Reply Packets}, for the reply specifications.
36008
b8ff78ce
JB
36009@item A @var{arglen},@var{argnum},@var{arg},@dots{}
36010@cindex @samp{A} packet
36011Initialized @code{argv[]} array passed into program. @var{arglen}
36012specifies the number of bytes in the hex encoded byte stream
36013@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
36014
36015Reply:
36016@table @samp
36017@item OK
b8ff78ce
JB
36018The arguments were set.
36019@item E @var{NN}
36020An error occurred.
ee2d5c50
AC
36021@end table
36022
b8ff78ce
JB
36023@item b @var{baud}
36024@cindex @samp{b} packet
36025(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
36026Change the serial line speed to @var{baud}.
36027
36028JTC: @emph{When does the transport layer state change? When it's
36029received, or after the ACK is transmitted. In either case, there are
36030problems if the command or the acknowledgment packet is dropped.}
36031
36032Stan: @emph{If people really wanted to add something like this, and get
36033it working for the first time, they ought to modify ser-unix.c to send
36034some kind of out-of-band message to a specially-setup stub and have the
36035switch happen "in between" packets, so that from remote protocol's point
36036of view, nothing actually happened.}
36037
b8ff78ce
JB
36038@item B @var{addr},@var{mode}
36039@cindex @samp{B} packet
8e04817f 36040Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
36041breakpoint at @var{addr}.
36042
b8ff78ce 36043Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 36044(@pxref{insert breakpoint or watchpoint packet}).
c906108c 36045
bacec72f 36046@cindex @samp{bc} packet
0d772ac9
MS
36047@anchor{bc}
36048@item bc
bacec72f
MS
36049Backward continue. Execute the target system in reverse. No parameter.
36050@xref{Reverse Execution}, for more information.
36051
36052Reply:
36053@xref{Stop Reply Packets}, for the reply specifications.
36054
bacec72f 36055@cindex @samp{bs} packet
0d772ac9
MS
36056@anchor{bs}
36057@item bs
bacec72f
MS
36058Backward single step. Execute one instruction in reverse. No parameter.
36059@xref{Reverse Execution}, for more information.
36060
36061Reply:
36062@xref{Stop Reply Packets}, for the reply specifications.
36063
4f553f88 36064@item c @r{[}@var{addr}@r{]}
b8ff78ce
JB
36065@cindex @samp{c} packet
36066Continue. @var{addr} is address to resume. If @var{addr} is omitted,
36067resume at current address.
c906108c 36068
393eab54
PA
36069This packet is deprecated for multi-threading support. @xref{vCont
36070packet}.
36071
ee2d5c50
AC
36072Reply:
36073@xref{Stop Reply Packets}, for the reply specifications.
36074
4f553f88 36075@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 36076@cindex @samp{C} packet
8e04817f 36077Continue with signal @var{sig} (hex signal number). If
b8ff78ce 36078@samp{;@var{addr}} is omitted, resume at same address.
c906108c 36079
393eab54
PA
36080This packet is deprecated for multi-threading support. @xref{vCont
36081packet}.
36082
ee2d5c50
AC
36083Reply:
36084@xref{Stop Reply Packets}, for the reply specifications.
c906108c 36085
b8ff78ce
JB
36086@item d
36087@cindex @samp{d} packet
ee2d5c50
AC
36088Toggle debug flag.
36089
b8ff78ce
JB
36090Don't use this packet; instead, define a general set packet
36091(@pxref{General Query Packets}).
ee2d5c50 36092
b8ff78ce 36093@item D
b90a069a 36094@itemx D;@var{pid}
b8ff78ce 36095@cindex @samp{D} packet
b90a069a
SL
36096The first form of the packet is used to detach @value{GDBN} from the
36097remote system. It is sent to the remote target
07f31aa6 36098before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50 36099
b90a069a
SL
36100The second form, including a process ID, is used when multiprocess
36101protocol extensions are enabled (@pxref{multiprocess extensions}), to
36102detach only a specific process. The @var{pid} is specified as a
36103big-endian hex string.
36104
ee2d5c50
AC
36105Reply:
36106@table @samp
10fac096
NW
36107@item OK
36108for success
b8ff78ce 36109@item E @var{NN}
10fac096 36110for an error
ee2d5c50 36111@end table
c906108c 36112
b8ff78ce
JB
36113@item F @var{RC},@var{EE},@var{CF};@var{XX}
36114@cindex @samp{F} packet
36115A reply from @value{GDBN} to an @samp{F} packet sent by the target.
36116This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 36117Remote Protocol Extension}, for the specification.
ee2d5c50 36118
b8ff78ce 36119@item g
ee2d5c50 36120@anchor{read registers packet}
b8ff78ce 36121@cindex @samp{g} packet
ee2d5c50
AC
36122Read general registers.
36123
36124Reply:
36125@table @samp
36126@item @var{XX@dots{}}
8e04817f
AC
36127Each byte of register data is described by two hex digits. The bytes
36128with the register are transmitted in target byte order. The size of
b8ff78ce 36129each register and their position within the @samp{g} packet are
4a9bb1df
UW
36130determined by the @value{GDBN} internal gdbarch functions
36131@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}. The
b8ff78ce 36132specification of several standard @samp{g} packets is specified below.
ad196637
PA
36133
36134When reading registers from a trace frame (@pxref{Analyze Collected
36135Data,,Using the Collected Data}), the stub may also return a string of
36136literal @samp{x}'s in place of the register data digits, to indicate
36137that the corresponding register has not been collected, thus its value
36138is unavailable. For example, for an architecture with 4 registers of
361394 bytes each, the following reply indicates to @value{GDBN} that
36140registers 0 and 2 have not been collected, while registers 1 and 3
36141have been collected, and both have zero value:
36142
36143@smallexample
36144-> @code{g}
36145<- @code{xxxxxxxx00000000xxxxxxxx00000000}
36146@end smallexample
36147
b8ff78ce 36148@item E @var{NN}
ee2d5c50
AC
36149for an error.
36150@end table
c906108c 36151
b8ff78ce
JB
36152@item G @var{XX@dots{}}
36153@cindex @samp{G} packet
36154Write general registers. @xref{read registers packet}, for a
36155description of the @var{XX@dots{}} data.
ee2d5c50
AC
36156
36157Reply:
36158@table @samp
36159@item OK
36160for success
b8ff78ce 36161@item E @var{NN}
ee2d5c50
AC
36162for an error
36163@end table
36164
393eab54 36165@item H @var{op} @var{thread-id}
b8ff78ce 36166@cindex @samp{H} packet
8e04817f 36167Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
393eab54
PA
36168@samp{G}, et.al.). @var{op} depends on the operation to be performed:
36169it should be @samp{c} for step and continue operations (note that this
36170is deprecated, supporting the @samp{vCont} command is a better
36171option), @samp{g} for other operations. The thread designator
36172@var{thread-id} has the format and interpretation described in
36173@ref{thread-id syntax}.
ee2d5c50
AC
36174
36175Reply:
36176@table @samp
36177@item OK
36178for success
b8ff78ce 36179@item E @var{NN}
ee2d5c50
AC
36180for an error
36181@end table
c906108c 36182
8e04817f
AC
36183@c FIXME: JTC:
36184@c 'H': How restrictive (or permissive) is the thread model. If a
36185@c thread is selected and stopped, are other threads allowed
36186@c to continue to execute? As I mentioned above, I think the
36187@c semantics of each command when a thread is selected must be
36188@c described. For example:
36189@c
36190@c 'g': If the stub supports threads and a specific thread is
36191@c selected, returns the register block from that thread;
36192@c otherwise returns current registers.
36193@c
36194@c 'G' If the stub supports threads and a specific thread is
36195@c selected, sets the registers of the register block of
36196@c that thread; otherwise sets current registers.
c906108c 36197
b8ff78ce 36198@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 36199@anchor{cycle step packet}
b8ff78ce
JB
36200@cindex @samp{i} packet
36201Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
36202present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
36203step starting at that address.
c906108c 36204
b8ff78ce
JB
36205@item I
36206@cindex @samp{I} packet
36207Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
36208step packet}.
ee2d5c50 36209
b8ff78ce
JB
36210@item k
36211@cindex @samp{k} packet
36212Kill request.
c906108c 36213
ac282366 36214FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
36215thread context has been selected (i.e.@: does 'k' kill only that
36216thread?)}.
c906108c 36217
b8ff78ce
JB
36218@item m @var{addr},@var{length}
36219@cindex @samp{m} packet
8e04817f 36220Read @var{length} bytes of memory starting at address @var{addr}.
fb031cdf
JB
36221Note that @var{addr} may not be aligned to any particular boundary.
36222
36223The stub need not use any particular size or alignment when gathering
36224data from memory for the response; even if @var{addr} is word-aligned
36225and @var{length} is a multiple of the word size, the stub is free to
36226use byte accesses, or not. For this reason, this packet may not be
36227suitable for accessing memory-mapped I/O devices.
c43c5473
JB
36228@cindex alignment of remote memory accesses
36229@cindex size of remote memory accesses
36230@cindex memory, alignment and size of remote accesses
c906108c 36231
ee2d5c50
AC
36232Reply:
36233@table @samp
36234@item @var{XX@dots{}}
599b237a 36235Memory contents; each byte is transmitted as a two-digit hexadecimal
b8ff78ce
JB
36236number. The reply may contain fewer bytes than requested if the
36237server was able to read only part of the region of memory.
36238@item E @var{NN}
ee2d5c50
AC
36239@var{NN} is errno
36240@end table
36241
b8ff78ce
JB
36242@item M @var{addr},@var{length}:@var{XX@dots{}}
36243@cindex @samp{M} packet
8e04817f 36244Write @var{length} bytes of memory starting at address @var{addr}.
b8ff78ce 36245@var{XX@dots{}} is the data; each byte is transmitted as a two-digit
599b237a 36246hexadecimal number.
ee2d5c50
AC
36247
36248Reply:
36249@table @samp
36250@item OK
36251for success
b8ff78ce 36252@item E @var{NN}
8e04817f
AC
36253for an error (this includes the case where only part of the data was
36254written).
ee2d5c50 36255@end table
c906108c 36256
b8ff78ce
JB
36257@item p @var{n}
36258@cindex @samp{p} packet
36259Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
36260@xref{read registers packet}, for a description of how the returned
36261register value is encoded.
ee2d5c50
AC
36262
36263Reply:
36264@table @samp
2e868123
AC
36265@item @var{XX@dots{}}
36266the register's value
b8ff78ce 36267@item E @var{NN}
2e868123 36268for an error
d57350ea 36269@item @w{}
2e868123 36270Indicating an unrecognized @var{query}.
ee2d5c50
AC
36271@end table
36272
b8ff78ce 36273@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 36274@anchor{write register packet}
b8ff78ce
JB
36275@cindex @samp{P} packet
36276Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 36277number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 36278digits for each byte in the register (target byte order).
c906108c 36279
ee2d5c50
AC
36280Reply:
36281@table @samp
36282@item OK
36283for success
b8ff78ce 36284@item E @var{NN}
ee2d5c50
AC
36285for an error
36286@end table
36287
5f3bebba
JB
36288@item q @var{name} @var{params}@dots{}
36289@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 36290@cindex @samp{q} packet
b8ff78ce 36291@cindex @samp{Q} packet
5f3bebba
JB
36292General query (@samp{q}) and set (@samp{Q}). These packets are
36293described fully in @ref{General Query Packets}.
c906108c 36294
b8ff78ce
JB
36295@item r
36296@cindex @samp{r} packet
8e04817f 36297Reset the entire system.
c906108c 36298
b8ff78ce 36299Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 36300
b8ff78ce
JB
36301@item R @var{XX}
36302@cindex @samp{R} packet
8e04817f 36303Restart the program being debugged. @var{XX}, while needed, is ignored.
2d717e4f 36304This packet is only available in extended mode (@pxref{extended mode}).
ee2d5c50 36305
8e04817f 36306The @samp{R} packet has no reply.
ee2d5c50 36307
4f553f88 36308@item s @r{[}@var{addr}@r{]}
b8ff78ce
JB
36309@cindex @samp{s} packet
36310Single step. @var{addr} is the address at which to resume. If
36311@var{addr} is omitted, resume at same address.
c906108c 36312
393eab54
PA
36313This packet is deprecated for multi-threading support. @xref{vCont
36314packet}.
36315
ee2d5c50
AC
36316Reply:
36317@xref{Stop Reply Packets}, for the reply specifications.
36318
4f553f88 36319@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 36320@anchor{step with signal packet}
b8ff78ce
JB
36321@cindex @samp{S} packet
36322Step with signal. This is analogous to the @samp{C} packet, but
36323requests a single-step, rather than a normal resumption of execution.
c906108c 36324
393eab54
PA
36325This packet is deprecated for multi-threading support. @xref{vCont
36326packet}.
36327
ee2d5c50
AC
36328Reply:
36329@xref{Stop Reply Packets}, for the reply specifications.
36330
b8ff78ce
JB
36331@item t @var{addr}:@var{PP},@var{MM}
36332@cindex @samp{t} packet
8e04817f 36333Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
36334@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
36335@var{addr} must be at least 3 digits.
c906108c 36336
b90a069a 36337@item T @var{thread-id}
b8ff78ce 36338@cindex @samp{T} packet
b90a069a 36339Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
c906108c 36340
ee2d5c50
AC
36341Reply:
36342@table @samp
36343@item OK
36344thread is still alive
b8ff78ce 36345@item E @var{NN}
ee2d5c50
AC
36346thread is dead
36347@end table
36348
b8ff78ce
JB
36349@item v
36350Packets starting with @samp{v} are identified by a multi-letter name,
36351up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 36352
2d717e4f
DJ
36353@item vAttach;@var{pid}
36354@cindex @samp{vAttach} packet
8b23ecc4
SL
36355Attach to a new process with the specified process ID @var{pid}.
36356The process ID is a
36357hexadecimal integer identifying the process. In all-stop mode, all
36358threads in the attached process are stopped; in non-stop mode, it may be
36359attached without being stopped if that is supported by the target.
36360
36361@c In non-stop mode, on a successful vAttach, the stub should set the
36362@c current thread to a thread of the newly-attached process. After
36363@c attaching, GDB queries for the attached process's thread ID with qC.
36364@c Also note that, from a user perspective, whether or not the
36365@c target is stopped on attach in non-stop mode depends on whether you
36366@c use the foreground or background version of the attach command, not
36367@c on what vAttach does; GDB does the right thing with respect to either
36368@c stopping or restarting threads.
2d717e4f
DJ
36369
36370This packet is only available in extended mode (@pxref{extended mode}).
36371
36372Reply:
36373@table @samp
36374@item E @var{nn}
36375for an error
36376@item @r{Any stop packet}
8b23ecc4
SL
36377for success in all-stop mode (@pxref{Stop Reply Packets})
36378@item OK
36379for success in non-stop mode (@pxref{Remote Non-Stop})
2d717e4f
DJ
36380@end table
36381
b90a069a 36382@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
b8ff78ce 36383@cindex @samp{vCont} packet
393eab54 36384@anchor{vCont packet}
b8ff78ce 36385Resume the inferior, specifying different actions for each thread.
b90a069a 36386If an action is specified with no @var{thread-id}, then it is applied to any
86d30acc 36387threads that don't have a specific action specified; if no default action is
8b23ecc4
SL
36388specified then other threads should remain stopped in all-stop mode and
36389in their current state in non-stop mode.
36390Specifying multiple
86d30acc 36391default actions is an error; specifying no actions is also an error.
b90a069a
SL
36392Thread IDs are specified using the syntax described in @ref{thread-id syntax}.
36393
36394Currently supported actions are:
86d30acc 36395
b8ff78ce 36396@table @samp
86d30acc
DJ
36397@item c
36398Continue.
b8ff78ce 36399@item C @var{sig}
8b23ecc4 36400Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
36401@item s
36402Step.
b8ff78ce 36403@item S @var{sig}
8b23ecc4
SL
36404Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
36405@item t
36406Stop.
86d30acc
DJ
36407@end table
36408
8b23ecc4
SL
36409The optional argument @var{addr} normally associated with the
36410@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
b8ff78ce 36411not supported in @samp{vCont}.
86d30acc 36412
08a0efd0
PA
36413The @samp{t} action is only relevant in non-stop mode
36414(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
8b23ecc4
SL
36415A stop reply should be generated for any affected thread not already stopped.
36416When a thread is stopped by means of a @samp{t} action,
36417the corresponding stop reply should indicate that the thread has stopped with
36418signal @samp{0}, regardless of whether the target uses some other signal
36419as an implementation detail.
36420
4220b2f8
TS
36421The stub must support @samp{vCont} if it reports support for
36422multiprocess extensions (@pxref{multiprocess extensions}). Note that in
36423this case @samp{vCont} actions can be specified to apply to all threads
36424in a process by using the @samp{p@var{pid}.-1} form of the
36425@var{thread-id}.
36426
86d30acc
DJ
36427Reply:
36428@xref{Stop Reply Packets}, for the reply specifications.
36429
b8ff78ce
JB
36430@item vCont?
36431@cindex @samp{vCont?} packet
d3e8051b 36432Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
36433
36434Reply:
36435@table @samp
b8ff78ce
JB
36436@item vCont@r{[};@var{action}@dots{}@r{]}
36437The @samp{vCont} packet is supported. Each @var{action} is a supported
36438command in the @samp{vCont} packet.
d57350ea 36439@item @w{}
b8ff78ce 36440The @samp{vCont} packet is not supported.
86d30acc 36441@end table
ee2d5c50 36442
a6b151f1
DJ
36443@item vFile:@var{operation}:@var{parameter}@dots{}
36444@cindex @samp{vFile} packet
36445Perform a file operation on the target system. For details,
36446see @ref{Host I/O Packets}.
36447
68437a39
DJ
36448@item vFlashErase:@var{addr},@var{length}
36449@cindex @samp{vFlashErase} packet
36450Direct the stub to erase @var{length} bytes of flash starting at
36451@var{addr}. The region may enclose any number of flash blocks, but
36452its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
36453flash block size appearing in the memory map (@pxref{Memory Map
36454Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
36455together, and sends a @samp{vFlashDone} request after each group; the
36456stub is allowed to delay erase operation until the @samp{vFlashDone}
36457packet is received.
36458
36459Reply:
36460@table @samp
36461@item OK
36462for success
36463@item E @var{NN}
36464for an error
36465@end table
36466
36467@item vFlashWrite:@var{addr}:@var{XX@dots{}}
36468@cindex @samp{vFlashWrite} packet
36469Direct the stub to write data to flash address @var{addr}. The data
36470is passed in binary form using the same encoding as for the @samp{X}
36471packet (@pxref{Binary Data}). The memory ranges specified by
36472@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
36473not overlap, and must appear in order of increasing addresses
36474(although @samp{vFlashErase} packets for higher addresses may already
36475have been received; the ordering is guaranteed only between
36476@samp{vFlashWrite} packets). If a packet writes to an address that was
36477neither erased by a preceding @samp{vFlashErase} packet nor by some other
36478target-specific method, the results are unpredictable.
36479
36480
36481Reply:
36482@table @samp
36483@item OK
36484for success
36485@item E.memtype
36486for vFlashWrite addressing non-flash memory
36487@item E @var{NN}
36488for an error
36489@end table
36490
36491@item vFlashDone
36492@cindex @samp{vFlashDone} packet
36493Indicate to the stub that flash programming operation is finished.
36494The stub is permitted to delay or batch the effects of a group of
36495@samp{vFlashErase} and @samp{vFlashWrite} packets until a
36496@samp{vFlashDone} packet is received. The contents of the affected
36497regions of flash memory are unpredictable until the @samp{vFlashDone}
36498request is completed.
36499
b90a069a
SL
36500@item vKill;@var{pid}
36501@cindex @samp{vKill} packet
36502Kill the process with the specified process ID. @var{pid} is a
36503hexadecimal integer identifying the process. This packet is used in
36504preference to @samp{k} when multiprocess protocol extensions are
36505supported; see @ref{multiprocess extensions}.
36506
36507Reply:
36508@table @samp
36509@item E @var{nn}
36510for an error
36511@item OK
36512for success
36513@end table
36514
2d717e4f
DJ
36515@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
36516@cindex @samp{vRun} packet
36517Run the program @var{filename}, passing it each @var{argument} on its
36518command line. The file and arguments are hex-encoded strings. If
36519@var{filename} is an empty string, the stub may use a default program
36520(e.g.@: the last program run). The program is created in the stopped
9b562ab8 36521state.
2d717e4f 36522
8b23ecc4
SL
36523@c FIXME: What about non-stop mode?
36524
2d717e4f
DJ
36525This packet is only available in extended mode (@pxref{extended mode}).
36526
36527Reply:
36528@table @samp
36529@item E @var{nn}
36530for an error
36531@item @r{Any stop packet}
36532for success (@pxref{Stop Reply Packets})
36533@end table
36534
8b23ecc4 36535@item vStopped
8b23ecc4 36536@cindex @samp{vStopped} packet
8dbe8ece 36537@xref{Notification Packets}.
8b23ecc4 36538
b8ff78ce 36539@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 36540@anchor{X packet}
b8ff78ce
JB
36541@cindex @samp{X} packet
36542Write data to memory, where the data is transmitted in binary.
36543@var{addr} is address, @var{length} is number of bytes,
0876f84a 36544@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 36545
ee2d5c50
AC
36546Reply:
36547@table @samp
36548@item OK
36549for success
b8ff78ce 36550@item E @var{NN}
ee2d5c50
AC
36551for an error
36552@end table
36553
a1dcb23a
DJ
36554@item z @var{type},@var{addr},@var{kind}
36555@itemx Z @var{type},@var{addr},@var{kind}
2f870471 36556@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
36557@cindex @samp{z} packet
36558@cindex @samp{Z} packets
36559Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
a1dcb23a 36560watchpoint starting at address @var{address} of kind @var{kind}.
ee2d5c50 36561
2f870471
AC
36562Each breakpoint and watchpoint packet @var{type} is documented
36563separately.
36564
512217c7
AC
36565@emph{Implementation notes: A remote target shall return an empty string
36566for an unrecognized breakpoint or watchpoint packet @var{type}. A
36567remote target shall support either both or neither of a given
b8ff78ce 36568@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
36569avoid potential problems with duplicate packets, the operations should
36570be implemented in an idempotent way.}
36571
a1dcb23a 36572@item z0,@var{addr},@var{kind}
d3ce09f5 36573@itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
36574@cindex @samp{z0} packet
36575@cindex @samp{Z0} packet
36576Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
a1dcb23a 36577@var{addr} of type @var{kind}.
2f870471
AC
36578
36579A memory breakpoint is implemented by replacing the instruction at
36580@var{addr} with a software breakpoint or trap instruction. The
a1dcb23a
DJ
36581@var{kind} is target-specific and typically indicates the size of
36582the breakpoint in bytes that should be inserted. E.g., the @sc{arm}
36583and @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
36584architectures have additional meanings for @var{kind};
83364271
LM
36585@var{cond_list} is an optional list of conditional expressions in bytecode
36586form that should be evaluated on the target's side. These are the
36587conditions that should be taken into consideration when deciding if
36588the breakpoint trigger should be reported back to @var{GDBN}.
36589
36590The @var{cond_list} parameter is comprised of a series of expressions,
36591concatenated without separators. Each expression has the following form:
36592
36593@table @samp
36594
36595@item X @var{len},@var{expr}
36596@var{len} is the length of the bytecode expression and @var{expr} is the
36597actual conditional expression in bytecode form.
36598
36599@end table
36600
d3ce09f5
SS
36601The optional @var{cmd_list} parameter introduces commands that may be
36602run on the target, rather than being reported back to @value{GDBN}.
36603The parameter starts with a numeric flag @var{persist}; if the flag is
36604nonzero, then the breakpoint may remain active and the commands
36605continue to be run even when @value{GDBN} disconnects from the target.
36606Following this flag is a series of expressions concatenated with no
36607separators. Each expression has the following form:
36608
36609@table @samp
36610
36611@item X @var{len},@var{expr}
36612@var{len} is the length of the bytecode expression and @var{expr} is the
36613actual conditional expression in bytecode form.
36614
36615@end table
36616
a1dcb23a 36617see @ref{Architecture-Specific Protocol Details}.
c906108c 36618
2f870471
AC
36619@emph{Implementation note: It is possible for a target to copy or move
36620code that contains memory breakpoints (e.g., when implementing
36621overlays). The behavior of this packet, in the presence of such a
36622target, is not defined.}
c906108c 36623
ee2d5c50
AC
36624Reply:
36625@table @samp
2f870471
AC
36626@item OK
36627success
d57350ea 36628@item @w{}
2f870471 36629not supported
b8ff78ce 36630@item E @var{NN}
ee2d5c50 36631for an error
2f870471
AC
36632@end table
36633
a1dcb23a 36634@item z1,@var{addr},@var{kind}
83364271 36635@itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}
b8ff78ce
JB
36636@cindex @samp{z1} packet
36637@cindex @samp{Z1} packet
36638Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
a1dcb23a 36639address @var{addr}.
2f870471
AC
36640
36641A hardware breakpoint is implemented using a mechanism that is not
a1dcb23a 36642dependant on being able to modify the target's memory. @var{kind}
83364271 36643and @var{cond_list} have the same meaning as in @samp{Z0} packets.
2f870471
AC
36644
36645@emph{Implementation note: A hardware breakpoint is not affected by code
36646movement.}
36647
36648Reply:
36649@table @samp
ee2d5c50 36650@item OK
2f870471 36651success
d57350ea 36652@item @w{}
2f870471 36653not supported
b8ff78ce 36654@item E @var{NN}
2f870471
AC
36655for an error
36656@end table
36657
a1dcb23a
DJ
36658@item z2,@var{addr},@var{kind}
36659@itemx Z2,@var{addr},@var{kind}
b8ff78ce
JB
36660@cindex @samp{z2} packet
36661@cindex @samp{Z2} packet
a1dcb23a
DJ
36662Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
36663@var{kind} is interpreted as the number of bytes to watch.
2f870471
AC
36664
36665Reply:
36666@table @samp
36667@item OK
36668success
d57350ea 36669@item @w{}
2f870471 36670not supported
b8ff78ce 36671@item E @var{NN}
2f870471
AC
36672for an error
36673@end table
36674
a1dcb23a
DJ
36675@item z3,@var{addr},@var{kind}
36676@itemx Z3,@var{addr},@var{kind}
b8ff78ce
JB
36677@cindex @samp{z3} packet
36678@cindex @samp{Z3} packet
a1dcb23a
DJ
36679Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
36680@var{kind} is interpreted as the number of bytes to watch.
2f870471
AC
36681
36682Reply:
36683@table @samp
36684@item OK
36685success
d57350ea 36686@item @w{}
2f870471 36687not supported
b8ff78ce 36688@item E @var{NN}
2f870471
AC
36689for an error
36690@end table
36691
a1dcb23a
DJ
36692@item z4,@var{addr},@var{kind}
36693@itemx Z4,@var{addr},@var{kind}
b8ff78ce
JB
36694@cindex @samp{z4} packet
36695@cindex @samp{Z4} packet
a1dcb23a
DJ
36696Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
36697@var{kind} is interpreted as the number of bytes to watch.
2f870471
AC
36698
36699Reply:
36700@table @samp
36701@item OK
36702success
d57350ea 36703@item @w{}
2f870471 36704not supported
b8ff78ce 36705@item E @var{NN}
2f870471 36706for an error
ee2d5c50
AC
36707@end table
36708
36709@end table
c906108c 36710
ee2d5c50
AC
36711@node Stop Reply Packets
36712@section Stop Reply Packets
36713@cindex stop reply packets
c906108c 36714
8b23ecc4
SL
36715The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
36716@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
36717receive any of the below as a reply. Except for @samp{?}
36718and @samp{vStopped}, that reply is only returned
b8ff78ce 36719when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
36720number} is defined by the header @file{include/gdb/signals.h} in the
36721@value{GDBN} source code.
c906108c 36722
b8ff78ce
JB
36723As in the description of request packets, we include spaces in the
36724reply templates for clarity; these are not part of the reply packet's
36725syntax. No @value{GDBN} stop reply packet uses spaces to separate its
36726components.
c906108c 36727
b8ff78ce 36728@table @samp
ee2d5c50 36729
b8ff78ce 36730@item S @var{AA}
599b237a 36731The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
36732number). This is equivalent to a @samp{T} response with no
36733@var{n}:@var{r} pairs.
c906108c 36734
b8ff78ce
JB
36735@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
36736@cindex @samp{T} packet reply
599b237a 36737The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
36738number). This is equivalent to an @samp{S} response, except that the
36739@samp{@var{n}:@var{r}} pairs can carry values of important registers
36740and other information directly in the stop reply packet, reducing
36741round-trip latency. Single-step and breakpoint traps are reported
36742this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
36743
36744@itemize @bullet
b8ff78ce 36745@item
599b237a 36746If @var{n} is a hexadecimal number, it is a register number, and the
b8ff78ce
JB
36747corresponding @var{r} gives that register's value. @var{r} is a
36748series of bytes in target byte order, with each byte given by a
36749two-digit hex number.
cfa9d6d9 36750
b8ff78ce 36751@item
b90a069a
SL
36752If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
36753the stopped thread, as specified in @ref{thread-id syntax}.
cfa9d6d9 36754
dc146f7c
VP
36755@item
36756If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
36757the core on which the stop event was detected.
36758
b8ff78ce 36759@item
cfa9d6d9
DJ
36760If @var{n} is a recognized @dfn{stop reason}, it describes a more
36761specific event that stopped the target. The currently defined stop
36762reasons are listed below. @var{aa} should be @samp{05}, the trap
36763signal. At most one stop reason should be present.
36764
b8ff78ce
JB
36765@item
36766Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
36767and go on to the next; this allows us to extend the protocol in the
36768future.
cfa9d6d9
DJ
36769@end itemize
36770
36771The currently defined stop reasons are:
36772
36773@table @samp
36774@item watch
36775@itemx rwatch
36776@itemx awatch
36777The packet indicates a watchpoint hit, and @var{r} is the data address, in
36778hex.
36779
36780@cindex shared library events, remote reply
36781@item library
36782The packet indicates that the loaded libraries have changed.
36783@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
36784list of loaded libraries. @var{r} is ignored.
bacec72f
MS
36785
36786@cindex replay log events, remote reply
36787@item replaylog
36788The packet indicates that the target cannot continue replaying
36789logged execution events, because it has reached the end (or the
36790beginning when executing backward) of the log. The value of @var{r}
36791will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
36792for more information.
cfa9d6d9 36793@end table
ee2d5c50 36794
b8ff78ce 36795@item W @var{AA}
b90a069a 36796@itemx W @var{AA} ; process:@var{pid}
8e04817f 36797The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
36798applicable to certain targets.
36799
b90a069a
SL
36800The second form of the response, including the process ID of the exited
36801process, can be used only when @value{GDBN} has reported support for
36802multiprocess protocol extensions; see @ref{multiprocess extensions}.
36803The @var{pid} is formatted as a big-endian hex string.
36804
b8ff78ce 36805@item X @var{AA}
b90a069a 36806@itemx X @var{AA} ; process:@var{pid}
8e04817f 36807The process terminated with signal @var{AA}.
c906108c 36808
b90a069a
SL
36809The second form of the response, including the process ID of the
36810terminated process, can be used only when @value{GDBN} has reported
36811support for multiprocess protocol extensions; see @ref{multiprocess
36812extensions}. The @var{pid} is formatted as a big-endian hex string.
36813
b8ff78ce
JB
36814@item O @var{XX}@dots{}
36815@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
36816written as the program's console output. This can happen at any time
36817while the program is running and the debugger should continue to wait
8b23ecc4 36818for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
0ce1b118 36819
b8ff78ce 36820@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
36821@var{call-id} is the identifier which says which host system call should
36822be called. This is just the name of the function. Translation into the
36823correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 36824@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
36825system calls.
36826
b8ff78ce
JB
36827@samp{@var{parameter}@dots{}} is a list of parameters as defined for
36828this very system call.
0ce1b118 36829
b8ff78ce
JB
36830The target replies with this packet when it expects @value{GDBN} to
36831call a host system call on behalf of the target. @value{GDBN} replies
36832with an appropriate @samp{F} packet and keeps up waiting for the next
36833reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
36834or @samp{s} action is expected to be continued. @xref{File-I/O Remote
36835Protocol Extension}, for more details.
0ce1b118 36836
ee2d5c50
AC
36837@end table
36838
36839@node General Query Packets
36840@section General Query Packets
9c16f35a 36841@cindex remote query requests
c906108c 36842
5f3bebba
JB
36843Packets starting with @samp{q} are @dfn{general query packets};
36844packets starting with @samp{Q} are @dfn{general set packets}. General
36845query and set packets are a semi-unified form for retrieving and
36846sending information to and from the stub.
36847
36848The initial letter of a query or set packet is followed by a name
36849indicating what sort of thing the packet applies to. For example,
36850@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
36851definitions with the stub. These packet names follow some
36852conventions:
36853
36854@itemize @bullet
36855@item
36856The name must not contain commas, colons or semicolons.
36857@item
36858Most @value{GDBN} query and set packets have a leading upper case
36859letter.
36860@item
36861The names of custom vendor packets should use a company prefix, in
36862lower case, followed by a period. For example, packets designed at
36863the Acme Corporation might begin with @samp{qacme.foo} (for querying
36864foos) or @samp{Qacme.bar} (for setting bars).
36865@end itemize
36866
aa56d27a
JB
36867The name of a query or set packet should be separated from any
36868parameters by a @samp{:}; the parameters themselves should be
36869separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
36870full packet name, and check for a separator or the end of the packet,
36871in case two packet names share a common prefix. New packets should not begin
36872with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
36873packets predate these conventions, and have arguments without any terminator
36874for the packet name; we suspect they are in widespread use in places that
36875are difficult to upgrade. The @samp{qC} packet has no arguments, but some
36876existing stubs (e.g.@: RedBoot) are known to not check for the end of the
36877packet.}.
c906108c 36878
b8ff78ce
JB
36879Like the descriptions of the other packets, each description here
36880has a template showing the packet's overall syntax, followed by an
36881explanation of the packet's meaning. We include spaces in some of the
36882templates for clarity; these are not part of the packet's syntax. No
36883@value{GDBN} packet uses spaces to separate its components.
36884
5f3bebba
JB
36885Here are the currently defined query and set packets:
36886
b8ff78ce 36887@table @samp
c906108c 36888
d1feda86 36889@item QAgent:1
af4238e5 36890@itemx QAgent:0
d1feda86
YQ
36891Turn on or off the agent as a helper to perform some debugging operations
36892delegated from @value{GDBN} (@pxref{Control Agent}).
36893
d914c394
SS
36894@item QAllow:@var{op}:@var{val}@dots{}
36895@cindex @samp{QAllow} packet
36896Specify which operations @value{GDBN} expects to request of the
36897target, as a semicolon-separated list of operation name and value
36898pairs. Possible values for @var{op} include @samp{WriteReg},
36899@samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
36900@samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
36901indicating that @value{GDBN} will not request the operation, or 1,
36902indicating that it may. (The target can then use this to set up its
36903own internals optimally, for instance if the debugger never expects to
36904insert breakpoints, it may not need to install its own trap handler.)
36905
b8ff78ce 36906@item qC
9c16f35a 36907@cindex current thread, remote request
b8ff78ce 36908@cindex @samp{qC} packet
b90a069a 36909Return the current thread ID.
ee2d5c50
AC
36910
36911Reply:
36912@table @samp
b90a069a
SL
36913@item QC @var{thread-id}
36914Where @var{thread-id} is a thread ID as documented in
36915@ref{thread-id syntax}.
b8ff78ce 36916@item @r{(anything else)}
b90a069a 36917Any other reply implies the old thread ID.
ee2d5c50
AC
36918@end table
36919
b8ff78ce 36920@item qCRC:@var{addr},@var{length}
ff2587ec 36921@cindex CRC of memory block, remote request
b8ff78ce 36922@cindex @samp{qCRC} packet
99e008fe
EZ
36923Compute the CRC checksum of a block of memory using CRC-32 defined in
36924IEEE 802.3. The CRC is computed byte at a time, taking the most
36925significant bit of each byte first. The initial pattern code
36926@code{0xffffffff} is used to ensure leading zeros affect the CRC.
36927
36928@emph{Note:} This is the same CRC used in validating separate debug
36929files (@pxref{Separate Debug Files, , Debugging Information in Separate
36930Files}). However the algorithm is slightly different. When validating
36931separate debug files, the CRC is computed taking the @emph{least}
36932significant bit of each byte first, and the final result is inverted to
36933detect trailing zeros.
36934
ff2587ec
WZ
36935Reply:
36936@table @samp
b8ff78ce 36937@item E @var{NN}
ff2587ec 36938An error (such as memory fault)
b8ff78ce
JB
36939@item C @var{crc32}
36940The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
36941@end table
36942
03583c20
UW
36943@item QDisableRandomization:@var{value}
36944@cindex disable address space randomization, remote request
36945@cindex @samp{QDisableRandomization} packet
36946Some target operating systems will randomize the virtual address space
36947of the inferior process as a security feature, but provide a feature
36948to disable such randomization, e.g.@: to allow for a more deterministic
36949debugging experience. On such systems, this packet with a @var{value}
36950of 1 directs the target to disable address space randomization for
36951processes subsequently started via @samp{vRun} packets, while a packet
36952with a @var{value} of 0 tells the target to enable address space
36953randomization.
36954
36955This packet is only available in extended mode (@pxref{extended mode}).
36956
36957Reply:
36958@table @samp
36959@item OK
36960The request succeeded.
36961
36962@item E @var{nn}
36963An error occurred. @var{nn} are hex digits.
36964
d57350ea 36965@item @w{}
03583c20
UW
36966An empty reply indicates that @samp{QDisableRandomization} is not supported
36967by the stub.
36968@end table
36969
36970This packet is not probed by default; the remote stub must request it,
36971by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
36972This should only be done on targets that actually support disabling
36973address space randomization.
36974
b8ff78ce
JB
36975@item qfThreadInfo
36976@itemx qsThreadInfo
9c16f35a 36977@cindex list active threads, remote request
b8ff78ce
JB
36978@cindex @samp{qfThreadInfo} packet
36979@cindex @samp{qsThreadInfo} packet
b90a069a 36980Obtain a list of all active thread IDs from the target (OS). Since there
8e04817f
AC
36981may be too many active threads to fit into one reply packet, this query
36982works iteratively: it may require more than one query/reply sequence to
36983obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
36984be the @samp{qfThreadInfo} query; subsequent queries in the
36985sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 36986
b8ff78ce 36987NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
36988
36989Reply:
36990@table @samp
b90a069a
SL
36991@item m @var{thread-id}
36992A single thread ID
36993@item m @var{thread-id},@var{thread-id}@dots{}
36994a comma-separated list of thread IDs
b8ff78ce
JB
36995@item l
36996(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
36997@end table
36998
36999In response to each query, the target will reply with a list of one or
b90a069a 37000more thread IDs, separated by commas.
e1aac25b 37001@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce 37002ids (using the @samp{qs} form of the query), until the target responds
501994c0 37003with @samp{l} (lower-case ell, for @dfn{last}).
b90a069a
SL
37004Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
37005fields.
c906108c 37006
b8ff78ce 37007@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 37008@cindex get thread-local storage address, remote request
b8ff78ce 37009@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
37010Fetch the address associated with thread local storage specified
37011by @var{thread-id}, @var{offset}, and @var{lm}.
37012
b90a069a
SL
37013@var{thread-id} is the thread ID associated with the
37014thread for which to fetch the TLS address. @xref{thread-id syntax}.
ff2587ec
WZ
37015
37016@var{offset} is the (big endian, hex encoded) offset associated with the
37017thread local variable. (This offset is obtained from the debug
37018information associated with the variable.)
37019
db2e3e2e 37020@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
7a9dd1b2 37021load module associated with the thread local storage. For example,
ff2587ec
WZ
37022a @sc{gnu}/Linux system will pass the link map address of the shared
37023object associated with the thread local storage under consideration.
37024Other operating environments may choose to represent the load module
37025differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
37026
37027Reply:
b8ff78ce
JB
37028@table @samp
37029@item @var{XX}@dots{}
ff2587ec
WZ
37030Hex encoded (big endian) bytes representing the address of the thread
37031local storage requested.
37032
b8ff78ce
JB
37033@item E @var{nn}
37034An error occurred. @var{nn} are hex digits.
ff2587ec 37035
d57350ea 37036@item @w{}
b8ff78ce 37037An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
37038@end table
37039
711e434b
PM
37040@item qGetTIBAddr:@var{thread-id}
37041@cindex get thread information block address
37042@cindex @samp{qGetTIBAddr} packet
37043Fetch address of the Windows OS specific Thread Information Block.
37044
37045@var{thread-id} is the thread ID associated with the thread.
37046
37047Reply:
37048@table @samp
37049@item @var{XX}@dots{}
37050Hex encoded (big endian) bytes representing the linear address of the
37051thread information block.
37052
37053@item E @var{nn}
37054An error occured. This means that either the thread was not found, or the
37055address could not be retrieved.
37056
d57350ea 37057@item @w{}
711e434b
PM
37058An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
37059@end table
37060
b8ff78ce 37061@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
37062Obtain thread information from RTOS. Where: @var{startflag} (one hex
37063digit) is one to indicate the first query and zero to indicate a
37064subsequent query; @var{threadcount} (two hex digits) is the maximum
37065number of threads the response packet can contain; and @var{nextthread}
37066(eight hex digits), for subsequent queries (@var{startflag} is zero), is
37067returned in the response as @var{argthread}.
ee2d5c50 37068
b8ff78ce 37069Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
37070
37071Reply:
37072@table @samp
b8ff78ce 37073@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
37074Where: @var{count} (two hex digits) is the number of threads being
37075returned; @var{done} (one hex digit) is zero to indicate more threads
37076and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 37077digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
ee2d5c50 37078is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 37079digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 37080@end table
c906108c 37081
b8ff78ce 37082@item qOffsets
9c16f35a 37083@cindex section offsets, remote request
b8ff78ce 37084@cindex @samp{qOffsets} packet
31d99776
DJ
37085Get section offsets that the target used when relocating the downloaded
37086image.
c906108c 37087
ee2d5c50
AC
37088Reply:
37089@table @samp
31d99776
DJ
37090@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
37091Relocate the @code{Text} section by @var{xxx} from its original address.
37092Relocate the @code{Data} section by @var{yyy} from its original address.
37093If the object file format provides segment information (e.g.@: @sc{elf}
37094@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
37095segments by the supplied offsets.
37096
37097@emph{Note: while a @code{Bss} offset may be included in the response,
37098@value{GDBN} ignores this and instead applies the @code{Data} offset
37099to the @code{Bss} section.}
37100
37101@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
37102Relocate the first segment of the object file, which conventionally
37103contains program code, to a starting address of @var{xxx}. If
37104@samp{DataSeg} is specified, relocate the second segment, which
37105conventionally contains modifiable data, to a starting address of
37106@var{yyy}. @value{GDBN} will report an error if the object file
37107does not contain segment information, or does not contain at least
37108as many segments as mentioned in the reply. Extra segments are
37109kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
37110@end table
37111
b90a069a 37112@item qP @var{mode} @var{thread-id}
9c16f35a 37113@cindex thread information, remote request
b8ff78ce 37114@cindex @samp{qP} packet
b90a069a
SL
37115Returns information on @var{thread-id}. Where: @var{mode} is a hex
37116encoded 32 bit mode; @var{thread-id} is a thread ID
37117(@pxref{thread-id syntax}).
ee2d5c50 37118
aa56d27a
JB
37119Don't use this packet; use the @samp{qThreadExtraInfo} query instead
37120(see below).
37121
b8ff78ce 37122Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 37123
8b23ecc4 37124@item QNonStop:1
687e43a4 37125@itemx QNonStop:0
8b23ecc4
SL
37126@cindex non-stop mode, remote request
37127@cindex @samp{QNonStop} packet
37128@anchor{QNonStop}
37129Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
37130@xref{Remote Non-Stop}, for more information.
37131
37132Reply:
37133@table @samp
37134@item OK
37135The request succeeded.
37136
37137@item E @var{nn}
37138An error occurred. @var{nn} are hex digits.
37139
d57350ea 37140@item @w{}
8b23ecc4
SL
37141An empty reply indicates that @samp{QNonStop} is not supported by
37142the stub.
37143@end table
37144
37145This packet is not probed by default; the remote stub must request it,
37146by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37147Use of this packet is controlled by the @code{set non-stop} command;
37148@pxref{Non-Stop Mode}.
37149
89be2091
DJ
37150@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
37151@cindex pass signals to inferior, remote request
37152@cindex @samp{QPassSignals} packet
23181151 37153@anchor{QPassSignals}
89be2091
DJ
37154Each listed @var{signal} should be passed directly to the inferior process.
37155Signals are numbered identically to continue packets and stop replies
37156(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
37157strictly greater than the previous item. These signals do not need to stop
37158the inferior, or be reported to @value{GDBN}. All other signals should be
37159reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
37160combine; any earlier @samp{QPassSignals} list is completely replaced by the
37161new list. This packet improves performance when using @samp{handle
37162@var{signal} nostop noprint pass}.
37163
37164Reply:
37165@table @samp
37166@item OK
37167The request succeeded.
37168
37169@item E @var{nn}
37170An error occurred. @var{nn} are hex digits.
37171
d57350ea 37172@item @w{}
89be2091
DJ
37173An empty reply indicates that @samp{QPassSignals} is not supported by
37174the stub.
37175@end table
37176
37177Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 37178command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
37179This packet is not probed by default; the remote stub must request it,
37180by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37181
9b224c5e
PA
37182@item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
37183@cindex signals the inferior may see, remote request
37184@cindex @samp{QProgramSignals} packet
37185@anchor{QProgramSignals}
37186Each listed @var{signal} may be delivered to the inferior process.
37187Others should be silently discarded.
37188
37189In some cases, the remote stub may need to decide whether to deliver a
37190signal to the program or not without @value{GDBN} involvement. One
37191example of that is while detaching --- the program's threads may have
37192stopped for signals that haven't yet had a chance of being reported to
37193@value{GDBN}, and so the remote stub can use the signal list specified
37194by this packet to know whether to deliver or ignore those pending
37195signals.
37196
37197This does not influence whether to deliver a signal as requested by a
37198resumption packet (@pxref{vCont packet}).
37199
37200Signals are numbered identically to continue packets and stop replies
37201(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
37202strictly greater than the previous item. Multiple
37203@samp{QProgramSignals} packets do not combine; any earlier
37204@samp{QProgramSignals} list is completely replaced by the new list.
37205
37206Reply:
37207@table @samp
37208@item OK
37209The request succeeded.
37210
37211@item E @var{nn}
37212An error occurred. @var{nn} are hex digits.
37213
d57350ea 37214@item @w{}
9b224c5e
PA
37215An empty reply indicates that @samp{QProgramSignals} is not supported
37216by the stub.
37217@end table
37218
37219Use of this packet is controlled by the @code{set remote program-signals}
37220command (@pxref{Remote Configuration, set remote program-signals}).
37221This packet is not probed by default; the remote stub must request it,
37222by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37223
b8ff78ce 37224@item qRcmd,@var{command}
ff2587ec 37225@cindex execute remote command, remote request
b8ff78ce 37226@cindex @samp{qRcmd} packet
ff2587ec 37227@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
37228execution. Invalid commands should be reported using the output
37229string. Before the final result packet, the target may also respond
37230with a number of intermediate @samp{O@var{output}} console output
37231packets. @emph{Implementors should note that providing access to a
37232stubs's interpreter may have security implications}.
fa93a9d8 37233
ff2587ec
WZ
37234Reply:
37235@table @samp
37236@item OK
37237A command response with no output.
37238@item @var{OUTPUT}
37239A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 37240@item E @var{NN}
ff2587ec 37241Indicate a badly formed request.
d57350ea 37242@item @w{}
b8ff78ce 37243An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 37244@end table
fa93a9d8 37245
aa56d27a
JB
37246(Note that the @code{qRcmd} packet's name is separated from the
37247command by a @samp{,}, not a @samp{:}, contrary to the naming
37248conventions above. Please don't use this packet as a model for new
37249packets.)
37250
08388c79
DE
37251@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
37252@cindex searching memory, in remote debugging
5c4808ca 37253@ifnotinfo
08388c79 37254@cindex @samp{qSearch:memory} packet
5c4808ca
EZ
37255@end ifnotinfo
37256@cindex @samp{qSearch memory} packet
08388c79
DE
37257@anchor{qSearch memory}
37258Search @var{length} bytes at @var{address} for @var{search-pattern}.
37259@var{address} and @var{length} are encoded in hex.
37260@var{search-pattern} is a sequence of bytes, hex encoded.
37261
37262Reply:
37263@table @samp
37264@item 0
37265The pattern was not found.
37266@item 1,address
37267The pattern was found at @var{address}.
37268@item E @var{NN}
37269A badly formed request or an error was encountered while searching memory.
d57350ea 37270@item @w{}
08388c79
DE
37271An empty reply indicates that @samp{qSearch:memory} is not recognized.
37272@end table
37273
a6f3e723
SL
37274@item QStartNoAckMode
37275@cindex @samp{QStartNoAckMode} packet
37276@anchor{QStartNoAckMode}
37277Request that the remote stub disable the normal @samp{+}/@samp{-}
37278protocol acknowledgments (@pxref{Packet Acknowledgment}).
37279
37280Reply:
37281@table @samp
37282@item OK
37283The stub has switched to no-acknowledgment mode.
37284@value{GDBN} acknowledges this reponse,
37285but neither the stub nor @value{GDBN} shall send or expect further
37286@samp{+}/@samp{-} acknowledgments in the current connection.
d57350ea 37287@item @w{}
a6f3e723
SL
37288An empty reply indicates that the stub does not support no-acknowledgment mode.
37289@end table
37290
be2a5f71
DJ
37291@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
37292@cindex supported packets, remote query
37293@cindex features of the remote protocol
37294@cindex @samp{qSupported} packet
0876f84a 37295@anchor{qSupported}
be2a5f71
DJ
37296Tell the remote stub about features supported by @value{GDBN}, and
37297query the stub for features it supports. This packet allows
37298@value{GDBN} and the remote stub to take advantage of each others'
37299features. @samp{qSupported} also consolidates multiple feature probes
37300at startup, to improve @value{GDBN} performance---a single larger
37301packet performs better than multiple smaller probe packets on
37302high-latency links. Some features may enable behavior which must not
37303be on by default, e.g.@: because it would confuse older clients or
37304stubs. Other features may describe packets which could be
37305automatically probed for, but are not. These features must be
37306reported before @value{GDBN} will use them. This ``default
37307unsupported'' behavior is not appropriate for all packets, but it
37308helps to keep the initial connection time under control with new
37309versions of @value{GDBN} which support increasing numbers of packets.
37310
37311Reply:
37312@table @samp
37313@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
37314The stub supports or does not support each returned @var{stubfeature},
37315depending on the form of each @var{stubfeature} (see below for the
37316possible forms).
d57350ea 37317@item @w{}
be2a5f71
DJ
37318An empty reply indicates that @samp{qSupported} is not recognized,
37319or that no features needed to be reported to @value{GDBN}.
37320@end table
37321
37322The allowed forms for each feature (either a @var{gdbfeature} in the
37323@samp{qSupported} packet, or a @var{stubfeature} in the response)
37324are:
37325
37326@table @samp
37327@item @var{name}=@var{value}
37328The remote protocol feature @var{name} is supported, and associated
37329with the specified @var{value}. The format of @var{value} depends
37330on the feature, but it must not include a semicolon.
37331@item @var{name}+
37332The remote protocol feature @var{name} is supported, and does not
37333need an associated value.
37334@item @var{name}-
37335The remote protocol feature @var{name} is not supported.
37336@item @var{name}?
37337The remote protocol feature @var{name} may be supported, and
37338@value{GDBN} should auto-detect support in some other way when it is
37339needed. This form will not be used for @var{gdbfeature} notifications,
37340but may be used for @var{stubfeature} responses.
37341@end table
37342
37343Whenever the stub receives a @samp{qSupported} request, the
37344supplied set of @value{GDBN} features should override any previous
37345request. This allows @value{GDBN} to put the stub in a known
37346state, even if the stub had previously been communicating with
37347a different version of @value{GDBN}.
37348
b90a069a
SL
37349The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
37350are defined:
37351
37352@table @samp
37353@item multiprocess
37354This feature indicates whether @value{GDBN} supports multiprocess
37355extensions to the remote protocol. @value{GDBN} does not use such
37356extensions unless the stub also reports that it supports them by
37357including @samp{multiprocess+} in its @samp{qSupported} reply.
37358@xref{multiprocess extensions}, for details.
c8d5aac9
L
37359
37360@item xmlRegisters
37361This feature indicates that @value{GDBN} supports the XML target
37362description. If the stub sees @samp{xmlRegisters=} with target
37363specific strings separated by a comma, it will report register
37364description.
dde08ee1
PA
37365
37366@item qRelocInsn
37367This feature indicates whether @value{GDBN} supports the
37368@samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
37369instruction reply packet}).
b90a069a
SL
37370@end table
37371
37372Stubs should ignore any unknown values for
be2a5f71
DJ
37373@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
37374packet supports receiving packets of unlimited length (earlier
b90a069a 37375versions of @value{GDBN} may reject overly long responses). Additional values
be2a5f71
DJ
37376for @var{gdbfeature} may be defined in the future to let the stub take
37377advantage of new features in @value{GDBN}, e.g.@: incompatible
b90a069a
SL
37378improvements in the remote protocol---the @samp{multiprocess} feature is
37379an example of such a feature. The stub's reply should be independent
be2a5f71
DJ
37380of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
37381describes all the features it supports, and then the stub replies with
37382all the features it supports.
37383
37384Similarly, @value{GDBN} will silently ignore unrecognized stub feature
37385responses, as long as each response uses one of the standard forms.
37386
37387Some features are flags. A stub which supports a flag feature
37388should respond with a @samp{+} form response. Other features
37389require values, and the stub should respond with an @samp{=}
37390form response.
37391
37392Each feature has a default value, which @value{GDBN} will use if
37393@samp{qSupported} is not available or if the feature is not mentioned
37394in the @samp{qSupported} response. The default values are fixed; a
37395stub is free to omit any feature responses that match the defaults.
37396
37397Not all features can be probed, but for those which can, the probing
37398mechanism is useful: in some cases, a stub's internal
37399architecture may not allow the protocol layer to know some information
37400about the underlying target in advance. This is especially common in
37401stubs which may be configured for multiple targets.
37402
37403These are the currently defined stub features and their properties:
37404
cfa9d6d9 37405@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
37406@c NOTE: The first row should be @headitem, but we do not yet require
37407@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 37408@item Feature Name
be2a5f71
DJ
37409@tab Value Required
37410@tab Default
37411@tab Probe Allowed
37412
37413@item @samp{PacketSize}
37414@tab Yes
37415@tab @samp{-}
37416@tab No
37417
0876f84a
DJ
37418@item @samp{qXfer:auxv:read}
37419@tab No
37420@tab @samp{-}
37421@tab Yes
37422
2ae8c8e7
MM
37423@item @samp{qXfer:btrace:read}
37424@tab No
37425@tab @samp{-}
37426@tab Yes
37427
23181151
DJ
37428@item @samp{qXfer:features:read}
37429@tab No
37430@tab @samp{-}
37431@tab Yes
37432
cfa9d6d9
DJ
37433@item @samp{qXfer:libraries:read}
37434@tab No
37435@tab @samp{-}
37436@tab Yes
37437
68437a39
DJ
37438@item @samp{qXfer:memory-map:read}
37439@tab No
37440@tab @samp{-}
37441@tab Yes
37442
0fb4aa4b
PA
37443@item @samp{qXfer:sdata:read}
37444@tab No
37445@tab @samp{-}
37446@tab Yes
37447
0e7f50da
UW
37448@item @samp{qXfer:spu:read}
37449@tab No
37450@tab @samp{-}
37451@tab Yes
37452
37453@item @samp{qXfer:spu:write}
37454@tab No
37455@tab @samp{-}
37456@tab Yes
37457
4aa995e1
PA
37458@item @samp{qXfer:siginfo:read}
37459@tab No
37460@tab @samp{-}
37461@tab Yes
37462
37463@item @samp{qXfer:siginfo:write}
37464@tab No
37465@tab @samp{-}
37466@tab Yes
37467
dc146f7c
VP
37468@item @samp{qXfer:threads:read}
37469@tab No
37470@tab @samp{-}
37471@tab Yes
37472
b3b9301e
PA
37473@item @samp{qXfer:traceframe-info:read}
37474@tab No
37475@tab @samp{-}
37476@tab Yes
37477
169081d0
TG
37478@item @samp{qXfer:uib:read}
37479@tab No
37480@tab @samp{-}
37481@tab Yes
37482
78d85199
YQ
37483@item @samp{qXfer:fdpic:read}
37484@tab No
37485@tab @samp{-}
37486@tab Yes
dc146f7c 37487
2ae8c8e7
MM
37488@item @samp{Qbtrace:off}
37489@tab Yes
37490@tab @samp{-}
37491@tab Yes
37492
37493@item @samp{Qbtrace:bts}
37494@tab Yes
37495@tab @samp{-}
37496@tab Yes
37497
8b23ecc4
SL
37498@item @samp{QNonStop}
37499@tab No
37500@tab @samp{-}
37501@tab Yes
37502
89be2091
DJ
37503@item @samp{QPassSignals}
37504@tab No
37505@tab @samp{-}
37506@tab Yes
37507
a6f3e723
SL
37508@item @samp{QStartNoAckMode}
37509@tab No
37510@tab @samp{-}
37511@tab Yes
37512
b90a069a
SL
37513@item @samp{multiprocess}
37514@tab No
37515@tab @samp{-}
37516@tab No
37517
83364271
LM
37518@item @samp{ConditionalBreakpoints}
37519@tab No
37520@tab @samp{-}
37521@tab No
37522
782b2b07
SS
37523@item @samp{ConditionalTracepoints}
37524@tab No
37525@tab @samp{-}
37526@tab No
37527
0d772ac9
MS
37528@item @samp{ReverseContinue}
37529@tab No
2f8132f3 37530@tab @samp{-}
0d772ac9
MS
37531@tab No
37532
37533@item @samp{ReverseStep}
37534@tab No
2f8132f3 37535@tab @samp{-}
0d772ac9
MS
37536@tab No
37537
409873ef
SS
37538@item @samp{TracepointSource}
37539@tab No
37540@tab @samp{-}
37541@tab No
37542
d1feda86
YQ
37543@item @samp{QAgent}
37544@tab No
37545@tab @samp{-}
37546@tab No
37547
d914c394
SS
37548@item @samp{QAllow}
37549@tab No
37550@tab @samp{-}
37551@tab No
37552
03583c20
UW
37553@item @samp{QDisableRandomization}
37554@tab No
37555@tab @samp{-}
37556@tab No
37557
d248b706
KY
37558@item @samp{EnableDisableTracepoints}
37559@tab No
37560@tab @samp{-}
37561@tab No
37562
f6f899bf
HAQ
37563@item @samp{QTBuffer:size}
37564@tab No
37565@tab @samp{-}
37566@tab No
37567
3065dfb6
SS
37568@item @samp{tracenz}
37569@tab No
37570@tab @samp{-}
37571@tab No
37572
d3ce09f5
SS
37573@item @samp{BreakpointCommands}
37574@tab No
37575@tab @samp{-}
37576@tab No
37577
be2a5f71
DJ
37578@end multitable
37579
37580These are the currently defined stub features, in more detail:
37581
37582@table @samp
37583@cindex packet size, remote protocol
37584@item PacketSize=@var{bytes}
37585The remote stub can accept packets up to at least @var{bytes} in
37586length. @value{GDBN} will send packets up to this size for bulk
37587transfers, and will never send larger packets. This is a limit on the
37588data characters in the packet, including the frame and checksum.
37589There is no trailing NUL byte in a remote protocol packet; if the stub
37590stores packets in a NUL-terminated format, it should allow an extra
37591byte in its buffer for the NUL. If this stub feature is not supported,
37592@value{GDBN} guesses based on the size of the @samp{g} packet response.
37593
0876f84a
DJ
37594@item qXfer:auxv:read
37595The remote stub understands the @samp{qXfer:auxv:read} packet
37596(@pxref{qXfer auxiliary vector read}).
37597
2ae8c8e7
MM
37598@item qXfer:btrace:read
37599The remote stub understands the @samp{qXfer:btrace:read}
37600packet (@pxref{qXfer btrace read}).
37601
23181151
DJ
37602@item qXfer:features:read
37603The remote stub understands the @samp{qXfer:features:read} packet
37604(@pxref{qXfer target description read}).
37605
cfa9d6d9
DJ
37606@item qXfer:libraries:read
37607The remote stub understands the @samp{qXfer:libraries:read} packet
37608(@pxref{qXfer library list read}).
37609
2268b414
JK
37610@item qXfer:libraries-svr4:read
37611The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
37612(@pxref{qXfer svr4 library list read}).
37613
23181151
DJ
37614@item qXfer:memory-map:read
37615The remote stub understands the @samp{qXfer:memory-map:read} packet
37616(@pxref{qXfer memory map read}).
37617
0fb4aa4b
PA
37618@item qXfer:sdata:read
37619The remote stub understands the @samp{qXfer:sdata:read} packet
37620(@pxref{qXfer sdata read}).
37621
0e7f50da
UW
37622@item qXfer:spu:read
37623The remote stub understands the @samp{qXfer:spu:read} packet
37624(@pxref{qXfer spu read}).
37625
37626@item qXfer:spu:write
37627The remote stub understands the @samp{qXfer:spu:write} packet
37628(@pxref{qXfer spu write}).
37629
4aa995e1
PA
37630@item qXfer:siginfo:read
37631The remote stub understands the @samp{qXfer:siginfo:read} packet
37632(@pxref{qXfer siginfo read}).
37633
37634@item qXfer:siginfo:write
37635The remote stub understands the @samp{qXfer:siginfo:write} packet
37636(@pxref{qXfer siginfo write}).
37637
dc146f7c
VP
37638@item qXfer:threads:read
37639The remote stub understands the @samp{qXfer:threads:read} packet
37640(@pxref{qXfer threads read}).
37641
b3b9301e
PA
37642@item qXfer:traceframe-info:read
37643The remote stub understands the @samp{qXfer:traceframe-info:read}
37644packet (@pxref{qXfer traceframe info read}).
37645
169081d0
TG
37646@item qXfer:uib:read
37647The remote stub understands the @samp{qXfer:uib:read}
37648packet (@pxref{qXfer unwind info block}).
37649
78d85199
YQ
37650@item qXfer:fdpic:read
37651The remote stub understands the @samp{qXfer:fdpic:read}
37652packet (@pxref{qXfer fdpic loadmap read}).
37653
8b23ecc4
SL
37654@item QNonStop
37655The remote stub understands the @samp{QNonStop} packet
37656(@pxref{QNonStop}).
37657
23181151
DJ
37658@item QPassSignals
37659The remote stub understands the @samp{QPassSignals} packet
37660(@pxref{QPassSignals}).
37661
a6f3e723
SL
37662@item QStartNoAckMode
37663The remote stub understands the @samp{QStartNoAckMode} packet and
37664prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
37665
b90a069a
SL
37666@item multiprocess
37667@anchor{multiprocess extensions}
37668@cindex multiprocess extensions, in remote protocol
37669The remote stub understands the multiprocess extensions to the remote
37670protocol syntax. The multiprocess extensions affect the syntax of
37671thread IDs in both packets and replies (@pxref{thread-id syntax}), and
37672add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
37673replies. Note that reporting this feature indicates support for the
37674syntactic extensions only, not that the stub necessarily supports
37675debugging of more than one process at a time. The stub must not use
37676multiprocess extensions in packet replies unless @value{GDBN} has also
37677indicated it supports them in its @samp{qSupported} request.
37678
07e059b5
VP
37679@item qXfer:osdata:read
37680The remote stub understands the @samp{qXfer:osdata:read} packet
37681((@pxref{qXfer osdata read}).
37682
83364271
LM
37683@item ConditionalBreakpoints
37684The target accepts and implements evaluation of conditional expressions
37685defined for breakpoints. The target will only report breakpoint triggers
37686when such conditions are true (@pxref{Conditions, ,Break Conditions}).
37687
782b2b07
SS
37688@item ConditionalTracepoints
37689The remote stub accepts and implements conditional expressions defined
37690for tracepoints (@pxref{Tracepoint Conditions}).
37691
0d772ac9
MS
37692@item ReverseContinue
37693The remote stub accepts and implements the reverse continue packet
37694(@pxref{bc}).
37695
37696@item ReverseStep
37697The remote stub accepts and implements the reverse step packet
37698(@pxref{bs}).
37699
409873ef
SS
37700@item TracepointSource
37701The remote stub understands the @samp{QTDPsrc} packet that supplies
37702the source form of tracepoint definitions.
37703
d1feda86
YQ
37704@item QAgent
37705The remote stub understands the @samp{QAgent} packet.
37706
d914c394
SS
37707@item QAllow
37708The remote stub understands the @samp{QAllow} packet.
37709
03583c20
UW
37710@item QDisableRandomization
37711The remote stub understands the @samp{QDisableRandomization} packet.
37712
0fb4aa4b
PA
37713@item StaticTracepoint
37714@cindex static tracepoints, in remote protocol
37715The remote stub supports static tracepoints.
37716
1e4d1764
YQ
37717@item InstallInTrace
37718@anchor{install tracepoint in tracing}
37719The remote stub supports installing tracepoint in tracing.
37720
d248b706
KY
37721@item EnableDisableTracepoints
37722The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
37723@samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
37724to be enabled and disabled while a trace experiment is running.
37725
f6f899bf 37726@item QTBuffer:size
28abe188 37727The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
f6f899bf
HAQ
37728packet that allows to change the size of the trace buffer.
37729
3065dfb6
SS
37730@item tracenz
37731@cindex string tracing, in remote protocol
37732The remote stub supports the @samp{tracenz} bytecode for collecting strings.
37733See @ref{Bytecode Descriptions} for details about the bytecode.
37734
d3ce09f5
SS
37735@item BreakpointCommands
37736@cindex breakpoint commands, in remote protocol
37737The remote stub supports running a breakpoint's command list itself,
37738rather than reporting the hit to @value{GDBN}.
37739
2ae8c8e7
MM
37740@item Qbtrace:off
37741The remote stub understands the @samp{Qbtrace:off} packet.
37742
37743@item Qbtrace:bts
37744The remote stub understands the @samp{Qbtrace:bts} packet.
37745
be2a5f71
DJ
37746@end table
37747
b8ff78ce 37748@item qSymbol::
ff2587ec 37749@cindex symbol lookup, remote request
b8ff78ce 37750@cindex @samp{qSymbol} packet
ff2587ec
WZ
37751Notify the target that @value{GDBN} is prepared to serve symbol lookup
37752requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
37753
37754Reply:
ff2587ec 37755@table @samp
b8ff78ce 37756@item OK
ff2587ec 37757The target does not need to look up any (more) symbols.
b8ff78ce 37758@item qSymbol:@var{sym_name}
ff2587ec
WZ
37759The target requests the value of symbol @var{sym_name} (hex encoded).
37760@value{GDBN} may provide the value by using the
b8ff78ce
JB
37761@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
37762below.
ff2587ec 37763@end table
83761cbd 37764
b8ff78ce 37765@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
37766Set the value of @var{sym_name} to @var{sym_value}.
37767
37768@var{sym_name} (hex encoded) is the name of a symbol whose value the
37769target has previously requested.
37770
37771@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
37772@value{GDBN} cannot supply a value for @var{sym_name}, then this field
37773will be empty.
37774
37775Reply:
37776@table @samp
b8ff78ce 37777@item OK
ff2587ec 37778The target does not need to look up any (more) symbols.
b8ff78ce 37779@item qSymbol:@var{sym_name}
ff2587ec
WZ
37780The target requests the value of a new symbol @var{sym_name} (hex
37781encoded). @value{GDBN} will continue to supply the values of symbols
37782(if available), until the target ceases to request them.
fa93a9d8 37783@end table
0abb7bc7 37784
00bf0b85 37785@item qTBuffer
687e43a4
TT
37786@itemx QTBuffer
37787@itemx QTDisconnected
d5551862 37788@itemx QTDP
409873ef 37789@itemx QTDPsrc
d5551862 37790@itemx QTDV
00bf0b85
SS
37791@itemx qTfP
37792@itemx qTfV
9d29849a 37793@itemx QTFrame
405f8e94
SS
37794@itemx qTMinFTPILen
37795
9d29849a
JB
37796@xref{Tracepoint Packets}.
37797
b90a069a 37798@item qThreadExtraInfo,@var{thread-id}
ff2587ec 37799@cindex thread attributes info, remote request
b8ff78ce
JB
37800@cindex @samp{qThreadExtraInfo} packet
37801Obtain a printable string description of a thread's attributes from
b90a069a
SL
37802the target OS. @var{thread-id} is a thread ID;
37803see @ref{thread-id syntax}. This
b8ff78ce
JB
37804string may contain anything that the target OS thinks is interesting
37805for @value{GDBN} to tell the user about the thread. The string is
37806displayed in @value{GDBN}'s @code{info threads} display. Some
37807examples of possible thread extra info strings are @samp{Runnable}, or
37808@samp{Blocked on Mutex}.
ff2587ec
WZ
37809
37810Reply:
37811@table @samp
b8ff78ce
JB
37812@item @var{XX}@dots{}
37813Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
37814comprising the printable string containing the extra information about
37815the thread's attributes.
ff2587ec 37816@end table
814e32d7 37817
aa56d27a
JB
37818(Note that the @code{qThreadExtraInfo} packet's name is separated from
37819the command by a @samp{,}, not a @samp{:}, contrary to the naming
37820conventions above. Please don't use this packet as a model for new
37821packets.)
37822
f196051f 37823@item QTNotes
687e43a4
TT
37824@itemx qTP
37825@itemx QTSave
37826@itemx qTsP
37827@itemx qTsV
d5551862 37828@itemx QTStart
9d29849a 37829@itemx QTStop
d248b706
KY
37830@itemx QTEnable
37831@itemx QTDisable
9d29849a
JB
37832@itemx QTinit
37833@itemx QTro
37834@itemx qTStatus
d5551862 37835@itemx qTV
0fb4aa4b
PA
37836@itemx qTfSTM
37837@itemx qTsSTM
37838@itemx qTSTMat
9d29849a
JB
37839@xref{Tracepoint Packets}.
37840
0876f84a
DJ
37841@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
37842@cindex read special object, remote request
37843@cindex @samp{qXfer} packet
68437a39 37844@anchor{qXfer read}
0876f84a
DJ
37845Read uninterpreted bytes from the target's special data area
37846identified by the keyword @var{object}. Request @var{length} bytes
37847starting at @var{offset} bytes into the data. The content and
0e7f50da 37848encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
37849additional details about what data to access.
37850
37851Here are the specific requests of this form defined so far. All
37852@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
37853formats, listed below.
37854
37855@table @samp
37856@item qXfer:auxv:read::@var{offset},@var{length}
37857@anchor{qXfer auxiliary vector read}
37858Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 37859auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
37860
37861This packet is not probed by default; the remote stub must request it,
89be2091 37862by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 37863
2ae8c8e7
MM
37864@item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
37865@anchor{qXfer btrace read}
37866
37867Return a description of the current branch trace.
37868@xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
37869packet may have one of the following values:
37870
37871@table @code
37872@item all
37873Returns all available branch trace.
37874
37875@item new
37876Returns all available branch trace if the branch trace changed since
37877the last read request.
37878@end table
37879
37880This packet is not probed by default; the remote stub must request it
37881by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37882
23181151
DJ
37883@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
37884@anchor{qXfer target description read}
37885Access the @dfn{target description}. @xref{Target Descriptions}. The
37886annex specifies which XML document to access. The main description is
37887always loaded from the @samp{target.xml} annex.
37888
37889This packet is not probed by default; the remote stub must request it,
37890by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37891
cfa9d6d9
DJ
37892@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
37893@anchor{qXfer library list read}
37894Access the target's list of loaded libraries. @xref{Library List Format}.
37895The annex part of the generic @samp{qXfer} packet must be empty
37896(@pxref{qXfer read}).
37897
37898Targets which maintain a list of libraries in the program's memory do
37899not need to implement this packet; it is designed for platforms where
37900the operating system manages the list of loaded libraries.
37901
37902This packet is not probed by default; the remote stub must request it,
37903by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37904
2268b414
JK
37905@item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
37906@anchor{qXfer svr4 library list read}
37907Access the target's list of loaded libraries when the target is an SVR4
37908platform. @xref{Library List Format for SVR4 Targets}. The annex part
37909of the generic @samp{qXfer} packet must be empty (@pxref{qXfer read}).
37910
37911This packet is optional for better performance on SVR4 targets.
37912@value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
37913
37914This packet is not probed by default; the remote stub must request it,
37915by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37916
68437a39
DJ
37917@item qXfer:memory-map:read::@var{offset},@var{length}
37918@anchor{qXfer memory map read}
79a6e687 37919Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
37920annex part of the generic @samp{qXfer} packet must be empty
37921(@pxref{qXfer read}).
37922
0e7f50da
UW
37923This packet is not probed by default; the remote stub must request it,
37924by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37925
0fb4aa4b
PA
37926@item qXfer:sdata:read::@var{offset},@var{length}
37927@anchor{qXfer sdata read}
37928
37929Read contents of the extra collected static tracepoint marker
37930information. The annex part of the generic @samp{qXfer} packet must
37931be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
37932Action Lists}.
37933
37934This packet is not probed by default; the remote stub must request it,
37935by supplying an appropriate @samp{qSupported} response
37936(@pxref{qSupported}).
37937
4aa995e1
PA
37938@item qXfer:siginfo:read::@var{offset},@var{length}
37939@anchor{qXfer siginfo read}
37940Read contents of the extra signal information on the target
37941system. The annex part of the generic @samp{qXfer} packet must be
37942empty (@pxref{qXfer read}).
37943
37944This packet is not probed by default; the remote stub must request it,
37945by supplying an appropriate @samp{qSupported} response
37946(@pxref{qSupported}).
37947
0e7f50da
UW
37948@item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
37949@anchor{qXfer spu read}
37950Read contents of an @code{spufs} file on the target system. The
37951annex specifies which file to read; it must be of the form
37952@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
37953in the target process, and @var{name} identifes the @code{spufs} file
37954in that context to be accessed.
37955
68437a39 37956This packet is not probed by default; the remote stub must request it,
07e059b5
VP
37957by supplying an appropriate @samp{qSupported} response
37958(@pxref{qSupported}).
37959
dc146f7c
VP
37960@item qXfer:threads:read::@var{offset},@var{length}
37961@anchor{qXfer threads read}
37962Access the list of threads on target. @xref{Thread List Format}. The
37963annex part of the generic @samp{qXfer} packet must be empty
37964(@pxref{qXfer read}).
37965
37966This packet is not probed by default; the remote stub must request it,
37967by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37968
b3b9301e
PA
37969@item qXfer:traceframe-info:read::@var{offset},@var{length}
37970@anchor{qXfer traceframe info read}
37971
37972Return a description of the current traceframe's contents.
37973@xref{Traceframe Info Format}. The annex part of the generic
37974@samp{qXfer} packet must be empty (@pxref{qXfer read}).
37975
37976This packet is not probed by default; the remote stub must request it,
37977by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37978
169081d0
TG
37979@item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
37980@anchor{qXfer unwind info block}
37981
37982Return the unwind information block for @var{pc}. This packet is used
37983on OpenVMS/ia64 to ask the kernel unwind information.
37984
37985This packet is not probed by default.
37986
78d85199
YQ
37987@item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
37988@anchor{qXfer fdpic loadmap read}
37989Read contents of @code{loadmap}s on the target system. The
37990annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
37991executable @code{loadmap} or interpreter @code{loadmap} to read.
37992
37993This packet is not probed by default; the remote stub must request it,
37994by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37995
07e059b5
VP
37996@item qXfer:osdata:read::@var{offset},@var{length}
37997@anchor{qXfer osdata read}
37998Access the target's @dfn{operating system information}.
37999@xref{Operating System Information}.
38000
68437a39
DJ
38001@end table
38002
0876f84a
DJ
38003Reply:
38004@table @samp
38005@item m @var{data}
38006Data @var{data} (@pxref{Binary Data}) has been read from the
38007target. There may be more data at a higher address (although
38008it is permitted to return @samp{m} even for the last valid
38009block of data, as long as at least one byte of data was read).
38010@var{data} may have fewer bytes than the @var{length} in the
38011request.
38012
38013@item l @var{data}
38014Data @var{data} (@pxref{Binary Data}) has been read from the target.
38015There is no more data to be read. @var{data} may have fewer bytes
38016than the @var{length} in the request.
38017
38018@item l
38019The @var{offset} in the request is at the end of the data.
38020There is no more data to be read.
38021
38022@item E00
38023The request was malformed, or @var{annex} was invalid.
38024
38025@item E @var{nn}
38026The offset was invalid, or there was an error encountered reading the data.
38027@var{nn} is a hex-encoded @code{errno} value.
38028
d57350ea 38029@item @w{}
0876f84a
DJ
38030An empty reply indicates the @var{object} string was not recognized by
38031the stub, or that the object does not support reading.
38032@end table
38033
38034@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
38035@cindex write data into object, remote request
4aa995e1 38036@anchor{qXfer write}
0876f84a
DJ
38037Write uninterpreted bytes into the target's special data area
38038identified by the keyword @var{object}, starting at @var{offset} bytes
0e7f50da 38039into the data. @var{data}@dots{} is the binary-encoded data
0876f84a 38040(@pxref{Binary Data}) to be written. The content and encoding of @var{annex}
0e7f50da 38041is specific to @var{object}; it can supply additional details about what data
0876f84a
DJ
38042to access.
38043
0e7f50da
UW
38044Here are the specific requests of this form defined so far. All
38045@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
38046formats, listed below.
38047
38048@table @samp
4aa995e1
PA
38049@item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
38050@anchor{qXfer siginfo write}
38051Write @var{data} to the extra signal information on the target system.
38052The annex part of the generic @samp{qXfer} packet must be
38053empty (@pxref{qXfer write}).
38054
38055This packet is not probed by default; the remote stub must request it,
38056by supplying an appropriate @samp{qSupported} response
38057(@pxref{qSupported}).
38058
84fcdf95 38059@item qXfer:spu:write:@var{annex}:@var{offset}:@var{data}@dots{}
0e7f50da
UW
38060@anchor{qXfer spu write}
38061Write @var{data} to an @code{spufs} file on the target system. The
38062annex specifies which file to write; it must be of the form
38063@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
38064in the target process, and @var{name} identifes the @code{spufs} file
38065in that context to be accessed.
38066
38067This packet is not probed by default; the remote stub must request it,
38068by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38069@end table
0876f84a
DJ
38070
38071Reply:
38072@table @samp
38073@item @var{nn}
38074@var{nn} (hex encoded) is the number of bytes written.
38075This may be fewer bytes than supplied in the request.
38076
38077@item E00
38078The request was malformed, or @var{annex} was invalid.
38079
38080@item E @var{nn}
38081The offset was invalid, or there was an error encountered writing the data.
38082@var{nn} is a hex-encoded @code{errno} value.
38083
d57350ea 38084@item @w{}
0876f84a
DJ
38085An empty reply indicates the @var{object} string was not
38086recognized by the stub, or that the object does not support writing.
38087@end table
38088
38089@item qXfer:@var{object}:@var{operation}:@dots{}
38090Requests of this form may be added in the future. When a stub does
38091not recognize the @var{object} keyword, or its support for
38092@var{object} does not recognize the @var{operation} keyword, the stub
38093must respond with an empty packet.
38094
0b16c5cf
PA
38095@item qAttached:@var{pid}
38096@cindex query attached, remote request
38097@cindex @samp{qAttached} packet
38098Return an indication of whether the remote server attached to an
38099existing process or created a new process. When the multiprocess
38100protocol extensions are supported (@pxref{multiprocess extensions}),
38101@var{pid} is an integer in hexadecimal format identifying the target
38102process. Otherwise, @value{GDBN} will omit the @var{pid} field and
38103the query packet will be simplified as @samp{qAttached}.
38104
38105This query is used, for example, to know whether the remote process
38106should be detached or killed when a @value{GDBN} session is ended with
38107the @code{quit} command.
38108
38109Reply:
38110@table @samp
38111@item 1
38112The remote server attached to an existing process.
38113@item 0
38114The remote server created a new process.
38115@item E @var{NN}
38116A badly formed request or an error was encountered.
38117@end table
38118
2ae8c8e7
MM
38119@item Qbtrace:bts
38120Enable branch tracing for the current thread using bts tracing.
38121
38122Reply:
38123@table @samp
38124@item OK
38125Branch tracing has been enabled.
38126@item E.errtext
38127A badly formed request or an error was encountered.
38128@end table
38129
38130@item Qbtrace:off
38131Disable branch tracing for the current thread.
38132
38133Reply:
38134@table @samp
38135@item OK
38136Branch tracing has been disabled.
38137@item E.errtext
38138A badly formed request or an error was encountered.
38139@end table
38140
ee2d5c50
AC
38141@end table
38142
a1dcb23a
DJ
38143@node Architecture-Specific Protocol Details
38144@section Architecture-Specific Protocol Details
38145
38146This section describes how the remote protocol is applied to specific
38147target architectures. Also see @ref{Standard Target Features}, for
38148details of XML target descriptions for each architecture.
38149
02b67415
MR
38150@menu
38151* ARM-Specific Protocol Details::
38152* MIPS-Specific Protocol Details::
38153@end menu
38154
38155@node ARM-Specific Protocol Details
38156@subsection @acronym{ARM}-specific Protocol Details
38157
38158@menu
38159* ARM Breakpoint Kinds::
38160@end menu
a1dcb23a 38161
02b67415
MR
38162@node ARM Breakpoint Kinds
38163@subsubsection @acronym{ARM} Breakpoint Kinds
38164@cindex breakpoint kinds, @acronym{ARM}
a1dcb23a
DJ
38165
38166These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
38167
38168@table @r
38169
38170@item 2
3817116-bit Thumb mode breakpoint.
38172
38173@item 3
3817432-bit Thumb mode (Thumb-2) breakpoint.
38175
38176@item 4
02b67415 3817732-bit @acronym{ARM} mode breakpoint.
a1dcb23a
DJ
38178
38179@end table
38180
02b67415
MR
38181@node MIPS-Specific Protocol Details
38182@subsection @acronym{MIPS}-specific Protocol Details
38183
38184@menu
38185* MIPS Register packet Format::
4cc0665f 38186* MIPS Breakpoint Kinds::
02b67415 38187@end menu
a1dcb23a 38188
02b67415
MR
38189@node MIPS Register packet Format
38190@subsubsection @acronym{MIPS} Register Packet Format
eb17f351 38191@cindex register packet format, @acronym{MIPS}
eb12ee30 38192
b8ff78ce 38193The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
38194In the below, some thirty-two bit registers are transferred as
38195sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
38196to fill the space allocated. Register bytes are transferred in target
38197byte order. The two nibbles within a register byte are transferred
02b67415 38198most-significant -- least-significant.
eb12ee30 38199
ee2d5c50 38200@table @r
eb12ee30 38201
8e04817f 38202@item MIPS32
599b237a 38203All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
3820432 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
38205registers; fsr; fir; fp.
eb12ee30 38206
8e04817f 38207@item MIPS64
599b237a 38208All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
38209thirty-two bit registers such as @code{sr}). The ordering is the same
38210as @code{MIPS32}.
eb12ee30 38211
ee2d5c50
AC
38212@end table
38213
4cc0665f
MR
38214@node MIPS Breakpoint Kinds
38215@subsubsection @acronym{MIPS} Breakpoint Kinds
38216@cindex breakpoint kinds, @acronym{MIPS}
38217
38218These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
38219
38220@table @r
38221
38222@item 2
3822316-bit @acronym{MIPS16} mode breakpoint.
38224
38225@item 3
3822616-bit @acronym{microMIPS} mode breakpoint.
38227
38228@item 4
3822932-bit standard @acronym{MIPS} mode breakpoint.
38230
38231@item 5
3823232-bit @acronym{microMIPS} mode breakpoint.
38233
38234@end table
38235
9d29849a
JB
38236@node Tracepoint Packets
38237@section Tracepoint Packets
38238@cindex tracepoint packets
38239@cindex packets, tracepoint
38240
38241Here we describe the packets @value{GDBN} uses to implement
38242tracepoints (@pxref{Tracepoints}).
38243
38244@table @samp
38245
7a697b8d 38246@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
c614397c 38247@cindex @samp{QTDP} packet
9d29849a
JB
38248Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
38249is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
38250the tracepoint is disabled. @var{step} is the tracepoint's step
7a697b8d
SS
38251count, and @var{pass} is its pass count. If an @samp{F} is present,
38252then the tracepoint is to be a fast tracepoint, and the @var{flen} is
38253the number of bytes that the target should copy elsewhere to make room
38254for the tracepoint. If an @samp{X} is present, it introduces a
38255tracepoint condition, which consists of a hexadecimal length, followed
38256by a comma and hex-encoded bytes, in a manner similar to action
38257encodings as described below. If the trailing @samp{-} is present,
38258further @samp{QTDP} packets will follow to specify this tracepoint's
38259actions.
9d29849a
JB
38260
38261Replies:
38262@table @samp
38263@item OK
38264The packet was understood and carried out.
dde08ee1
PA
38265@item qRelocInsn
38266@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 38267@item @w{}
9d29849a
JB
38268The packet was not recognized.
38269@end table
38270
38271@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
38272Define actions to be taken when a tracepoint is hit. @var{n} and
38273@var{addr} must be the same as in the initial @samp{QTDP} packet for
38274this tracepoint. This packet may only be sent immediately after
38275another @samp{QTDP} packet that ended with a @samp{-}. If the
38276trailing @samp{-} is present, further @samp{QTDP} packets will follow,
38277specifying more actions for this tracepoint.
38278
38279In the series of action packets for a given tracepoint, at most one
38280can have an @samp{S} before its first @var{action}. If such a packet
38281is sent, it and the following packets define ``while-stepping''
38282actions. Any prior packets define ordinary actions --- that is, those
38283taken when the tracepoint is first hit. If no action packet has an
38284@samp{S}, then all the packets in the series specify ordinary
38285tracepoint actions.
38286
38287The @samp{@var{action}@dots{}} portion of the packet is a series of
38288actions, concatenated without separators. Each action has one of the
38289following forms:
38290
38291@table @samp
38292
38293@item R @var{mask}
38294Collect the registers whose bits are set in @var{mask}. @var{mask} is
599b237a 38295a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
38296@var{i} should be collected. (The least significant bit is numbered
38297zero.) Note that @var{mask} may be any number of digits long; it may
38298not fit in a 32-bit word.
38299
38300@item M @var{basereg},@var{offset},@var{len}
38301Collect @var{len} bytes of memory starting at the address in register
38302number @var{basereg}, plus @var{offset}. If @var{basereg} is
38303@samp{-1}, then the range has a fixed address: @var{offset} is the
38304address of the lowest byte to collect. The @var{basereg},
599b237a 38305@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
38306values (the @samp{-1} value for @var{basereg} is a special case).
38307
38308@item X @var{len},@var{expr}
38309Evaluate @var{expr}, whose length is @var{len}, and collect memory as
38310it directs. @var{expr} is an agent expression, as described in
38311@ref{Agent Expressions}. Each byte of the expression is encoded as a
38312two-digit hex number in the packet; @var{len} is the number of bytes
38313in the expression (and thus one-half the number of hex digits in the
38314packet).
38315
38316@end table
38317
38318Any number of actions may be packed together in a single @samp{QTDP}
38319packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
38320length (400 bytes, for many stubs). There may be only one @samp{R}
38321action per tracepoint, and it must precede any @samp{M} or @samp{X}
38322actions. Any registers referred to by @samp{M} and @samp{X} actions
38323must be collected by a preceding @samp{R} action. (The
38324``while-stepping'' actions are treated as if they were attached to a
38325separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
38326
38327Replies:
38328@table @samp
38329@item OK
38330The packet was understood and carried out.
dde08ee1
PA
38331@item qRelocInsn
38332@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 38333@item @w{}
9d29849a
JB
38334The packet was not recognized.
38335@end table
38336
409873ef
SS
38337@item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
38338@cindex @samp{QTDPsrc} packet
38339Specify a source string of tracepoint @var{n} at address @var{addr}.
38340This is useful to get accurate reproduction of the tracepoints
38341originally downloaded at the beginning of the trace run. @var{type}
38342is the name of the tracepoint part, such as @samp{cond} for the
38343tracepoint's conditional expression (see below for a list of types), while
38344@var{bytes} is the string, encoded in hexadecimal.
38345
38346@var{start} is the offset of the @var{bytes} within the overall source
38347string, while @var{slen} is the total length of the source string.
38348This is intended for handling source strings that are longer than will
38349fit in a single packet.
38350@c Add detailed example when this info is moved into a dedicated
38351@c tracepoint descriptions section.
38352
38353The available string types are @samp{at} for the location,
38354@samp{cond} for the conditional, and @samp{cmd} for an action command.
38355@value{GDBN} sends a separate packet for each command in the action
38356list, in the same order in which the commands are stored in the list.
38357
38358The target does not need to do anything with source strings except
38359report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
38360query packets.
38361
38362Although this packet is optional, and @value{GDBN} will only send it
38363if the target replies with @samp{TracepointSource} @xref{General
38364Query Packets}, it makes both disconnected tracing and trace files
38365much easier to use. Otherwise the user must be careful that the
38366tracepoints in effect while looking at trace frames are identical to
38367the ones in effect during the trace run; even a small discrepancy
38368could cause @samp{tdump} not to work, or a particular trace frame not
38369be found.
38370
f61e138d
SS
38371@item QTDV:@var{n}:@var{value}
38372@cindex define trace state variable, remote request
38373@cindex @samp{QTDV} packet
38374Create a new trace state variable, number @var{n}, with an initial
38375value of @var{value}, which is a 64-bit signed integer. Both @var{n}
38376and @var{value} are encoded as hexadecimal values. @value{GDBN} has
38377the option of not using this packet for initial values of zero; the
38378target should simply create the trace state variables as they are
38379mentioned in expressions.
38380
9d29849a 38381@item QTFrame:@var{n}
c614397c 38382@cindex @samp{QTFrame} packet
9d29849a
JB
38383Select the @var{n}'th tracepoint frame from the buffer, and use the
38384register and memory contents recorded there to answer subsequent
38385request packets from @value{GDBN}.
38386
38387A successful reply from the stub indicates that the stub has found the
38388requested frame. The response is a series of parts, concatenated
38389without separators, describing the frame we selected. Each part has
38390one of the following forms:
38391
38392@table @samp
38393@item F @var{f}
38394The selected frame is number @var{n} in the trace frame buffer;
599b237a 38395@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
38396was no frame matching the criteria in the request packet.
38397
38398@item T @var{t}
38399The selected trace frame records a hit of tracepoint number @var{t};
599b237a 38400@var{t} is a hexadecimal number.
9d29849a
JB
38401
38402@end table
38403
38404@item QTFrame:pc:@var{addr}
38405Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
38406currently selected frame whose PC is @var{addr};
599b237a 38407@var{addr} is a hexadecimal number.
9d29849a
JB
38408
38409@item QTFrame:tdp:@var{t}
38410Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
38411currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 38412is a hexadecimal number.
9d29849a
JB
38413
38414@item QTFrame:range:@var{start}:@var{end}
38415Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
38416currently selected frame whose PC is between @var{start} (inclusive)
081dfbf7 38417and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
38418numbers.
38419
38420@item QTFrame:outside:@var{start}:@var{end}
38421Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
081dfbf7 38422frame @emph{outside} the given range of addresses (exclusive).
9d29849a 38423
405f8e94 38424@item qTMinFTPILen
c614397c 38425@cindex @samp{qTMinFTPILen} packet
405f8e94
SS
38426This packet requests the minimum length of instruction at which a fast
38427tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
38428the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
38429it depends on the target system being able to create trampolines in
38430the first 64K of memory, which might or might not be possible for that
38431system. So the reply to this packet will be 4 if it is able to
38432arrange for that.
38433
38434Replies:
38435
38436@table @samp
38437@item 0
38438The minimum instruction length is currently unknown.
38439@item @var{length}
38440The minimum instruction length is @var{length}, where @var{length} is greater
38441or equal to 1. @var{length} is a hexadecimal number. A reply of 1 means
38442that a fast tracepoint may be placed on any instruction regardless of size.
38443@item E
38444An error has occurred.
d57350ea 38445@item @w{}
405f8e94
SS
38446An empty reply indicates that the request is not supported by the stub.
38447@end table
38448
9d29849a 38449@item QTStart
c614397c 38450@cindex @samp{QTStart} packet
dde08ee1
PA
38451Begin the tracepoint experiment. Begin collecting data from
38452tracepoint hits in the trace frame buffer. This packet supports the
38453@samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
38454instruction reply packet}).
9d29849a
JB
38455
38456@item QTStop
c614397c 38457@cindex @samp{QTStop} packet
9d29849a
JB
38458End the tracepoint experiment. Stop collecting trace frames.
38459
d248b706
KY
38460@item QTEnable:@var{n}:@var{addr}
38461@anchor{QTEnable}
c614397c 38462@cindex @samp{QTEnable} packet
d248b706
KY
38463Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
38464experiment. If the tracepoint was previously disabled, then collection
38465of data from it will resume.
38466
38467@item QTDisable:@var{n}:@var{addr}
38468@anchor{QTDisable}
c614397c 38469@cindex @samp{QTDisable} packet
d248b706
KY
38470Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
38471experiment. No more data will be collected from the tracepoint unless
38472@samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
38473
9d29849a 38474@item QTinit
c614397c 38475@cindex @samp{QTinit} packet
9d29849a
JB
38476Clear the table of tracepoints, and empty the trace frame buffer.
38477
38478@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
c614397c 38479@cindex @samp{QTro} packet
9d29849a
JB
38480Establish the given ranges of memory as ``transparent''. The stub
38481will answer requests for these ranges from memory's current contents,
38482if they were not collected as part of the tracepoint hit.
38483
38484@value{GDBN} uses this to mark read-only regions of memory, like those
38485containing program code. Since these areas never change, they should
38486still have the same contents they did when the tracepoint was hit, so
38487there's no reason for the stub to refuse to provide their contents.
38488
d5551862 38489@item QTDisconnected:@var{value}
c614397c 38490@cindex @samp{QTDisconnected} packet
d5551862
SS
38491Set the choice to what to do with the tracing run when @value{GDBN}
38492disconnects from the target. A @var{value} of 1 directs the target to
38493continue the tracing run, while 0 tells the target to stop tracing if
38494@value{GDBN} is no longer in the picture.
38495
9d29849a 38496@item qTStatus
c614397c 38497@cindex @samp{qTStatus} packet
9d29849a
JB
38498Ask the stub if there is a trace experiment running right now.
38499
4daf5ac0
SS
38500The reply has the form:
38501
38502@table @samp
38503
38504@item T@var{running}@r{[};@var{field}@r{]}@dots{}
38505@var{running} is a single digit @code{1} if the trace is presently
38506running, or @code{0} if not. It is followed by semicolon-separated
38507optional fields that an agent may use to report additional status.
38508
38509@end table
38510
38511If the trace is not running, the agent may report any of several
38512explanations as one of the optional fields:
38513
38514@table @samp
38515
38516@item tnotrun:0
38517No trace has been run yet.
38518
f196051f
SS
38519@item tstop[:@var{text}]:0
38520The trace was stopped by a user-originated stop command. The optional
38521@var{text} field is a user-supplied string supplied as part of the
38522stop command (for instance, an explanation of why the trace was
38523stopped manually). It is hex-encoded.
4daf5ac0
SS
38524
38525@item tfull:0
38526The trace stopped because the trace buffer filled up.
38527
38528@item tdisconnected:0
38529The trace stopped because @value{GDBN} disconnected from the target.
38530
38531@item tpasscount:@var{tpnum}
38532The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
38533
6c28cbf2
SS
38534@item terror:@var{text}:@var{tpnum}
38535The trace stopped because tracepoint @var{tpnum} had an error. The
38536string @var{text} is available to describe the nature of the error
38537(for instance, a divide by zero in the condition expression).
99b5e152 38538@var{text} is hex encoded.
6c28cbf2 38539
4daf5ac0
SS
38540@item tunknown:0
38541The trace stopped for some other reason.
38542
38543@end table
38544
33da3f1c
SS
38545Additional optional fields supply statistical and other information.
38546Although not required, they are extremely useful for users monitoring
38547the progress of a trace run. If a trace has stopped, and these
38548numbers are reported, they must reflect the state of the just-stopped
38549trace.
4daf5ac0 38550
9d29849a 38551@table @samp
4daf5ac0
SS
38552
38553@item tframes:@var{n}
38554The number of trace frames in the buffer.
38555
38556@item tcreated:@var{n}
38557The total number of trace frames created during the run. This may
38558be larger than the trace frame count, if the buffer is circular.
38559
38560@item tsize:@var{n}
38561The total size of the trace buffer, in bytes.
38562
38563@item tfree:@var{n}
38564The number of bytes still unused in the buffer.
38565
33da3f1c
SS
38566@item circular:@var{n}
38567The value of the circular trace buffer flag. @code{1} means that the
38568trace buffer is circular and old trace frames will be discarded if
38569necessary to make room, @code{0} means that the trace buffer is linear
38570and may fill up.
38571
38572@item disconn:@var{n}
38573The value of the disconnected tracing flag. @code{1} means that
38574tracing will continue after @value{GDBN} disconnects, @code{0} means
38575that the trace run will stop.
38576
9d29849a
JB
38577@end table
38578
f196051f
SS
38579@item qTP:@var{tp}:@var{addr}
38580@cindex tracepoint status, remote request
38581@cindex @samp{qTP} packet
38582Ask the stub for the current state of tracepoint number @var{tp} at
38583address @var{addr}.
38584
38585Replies:
38586@table @samp
38587@item V@var{hits}:@var{usage}
38588The tracepoint has been hit @var{hits} times so far during the trace
38589run, and accounts for @var{usage} in the trace buffer. Note that
38590@code{while-stepping} steps are not counted as separate hits, but the
38591steps' space consumption is added into the usage number.
38592
38593@end table
38594
f61e138d
SS
38595@item qTV:@var{var}
38596@cindex trace state variable value, remote request
38597@cindex @samp{qTV} packet
38598Ask the stub for the value of the trace state variable number @var{var}.
38599
38600Replies:
38601@table @samp
38602@item V@var{value}
38603The value of the variable is @var{value}. This will be the current
38604value of the variable if the user is examining a running target, or a
38605saved value if the variable was collected in the trace frame that the
38606user is looking at. Note that multiple requests may result in
38607different reply values, such as when requesting values while the
38608program is running.
38609
38610@item U
38611The value of the variable is unknown. This would occur, for example,
38612if the user is examining a trace frame in which the requested variable
38613was not collected.
9d29849a
JB
38614@end table
38615
d5551862 38616@item qTfP
c614397c 38617@cindex @samp{qTfP} packet
d5551862 38618@itemx qTsP
c614397c 38619@cindex @samp{qTsP} packet
d5551862
SS
38620These packets request data about tracepoints that are being used by
38621the target. @value{GDBN} sends @code{qTfP} to get the first piece
38622of data, and multiple @code{qTsP} to get additional pieces. Replies
38623to these packets generally take the form of the @code{QTDP} packets
38624that define tracepoints. (FIXME add detailed syntax)
38625
00bf0b85 38626@item qTfV
c614397c 38627@cindex @samp{qTfV} packet
00bf0b85 38628@itemx qTsV
c614397c 38629@cindex @samp{qTsV} packet
00bf0b85
SS
38630These packets request data about trace state variables that are on the
38631target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
38632and multiple @code{qTsV} to get additional variables. Replies to
38633these packets follow the syntax of the @code{QTDV} packets that define
38634trace state variables.
38635
0fb4aa4b
PA
38636@item qTfSTM
38637@itemx qTsSTM
16bdd41f
YQ
38638@anchor{qTfSTM}
38639@anchor{qTsSTM}
c614397c
YQ
38640@cindex @samp{qTfSTM} packet
38641@cindex @samp{qTsSTM} packet
0fb4aa4b
PA
38642These packets request data about static tracepoint markers that exist
38643in the target program. @value{GDBN} sends @code{qTfSTM} to get the
38644first piece of data, and multiple @code{qTsSTM} to get additional
38645pieces. Replies to these packets take the following form:
38646
38647Reply:
38648@table @samp
38649@item m @var{address}:@var{id}:@var{extra}
38650A single marker
38651@item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
38652a comma-separated list of markers
38653@item l
38654(lower case letter @samp{L}) denotes end of list.
38655@item E @var{nn}
38656An error occurred. @var{nn} are hex digits.
d57350ea 38657@item @w{}
0fb4aa4b
PA
38658An empty reply indicates that the request is not supported by the
38659stub.
38660@end table
38661
38662@var{address} is encoded in hex.
38663@var{id} and @var{extra} are strings encoded in hex.
38664
38665In response to each query, the target will reply with a list of one or
38666more markers, separated by commas. @value{GDBN} will respond to each
38667reply with a request for more markers (using the @samp{qs} form of the
38668query), until the target responds with @samp{l} (lower-case ell, for
38669@dfn{last}).
38670
38671@item qTSTMat:@var{address}
16bdd41f 38672@anchor{qTSTMat}
c614397c 38673@cindex @samp{qTSTMat} packet
0fb4aa4b
PA
38674This packets requests data about static tracepoint markers in the
38675target program at @var{address}. Replies to this packet follow the
38676syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
38677tracepoint markers.
38678
00bf0b85 38679@item QTSave:@var{filename}
c614397c 38680@cindex @samp{QTSave} packet
00bf0b85
SS
38681This packet directs the target to save trace data to the file name
38682@var{filename} in the target's filesystem. @var{filename} is encoded
38683as a hex string; the interpretation of the file name (relative vs
38684absolute, wild cards, etc) is up to the target.
38685
38686@item qTBuffer:@var{offset},@var{len}
c614397c 38687@cindex @samp{qTBuffer} packet
00bf0b85
SS
38688Return up to @var{len} bytes of the current contents of trace buffer,
38689starting at @var{offset}. The trace buffer is treated as if it were
38690a contiguous collection of traceframes, as per the trace file format.
38691The reply consists as many hex-encoded bytes as the target can deliver
38692in a packet; it is not an error to return fewer than were asked for.
38693A reply consisting of just @code{l} indicates that no bytes are
38694available.
38695
4daf5ac0
SS
38696@item QTBuffer:circular:@var{value}
38697This packet directs the target to use a circular trace buffer if
38698@var{value} is 1, or a linear buffer if the value is 0.
38699
f6f899bf 38700@item QTBuffer:size:@var{size}
28abe188
EZ
38701@anchor{QTBuffer-size}
38702@cindex @samp{QTBuffer size} packet
f6f899bf
HAQ
38703This packet directs the target to make the trace buffer be of size
38704@var{size} if possible. A value of @code{-1} tells the target to
38705use whatever size it prefers.
38706
f196051f 38707@item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
c614397c 38708@cindex @samp{QTNotes} packet
f196051f
SS
38709This packet adds optional textual notes to the trace run. Allowable
38710types include @code{user}, @code{notes}, and @code{tstop}, the
38711@var{text} fields are arbitrary strings, hex-encoded.
38712
f61e138d 38713@end table
9d29849a 38714
dde08ee1
PA
38715@subsection Relocate instruction reply packet
38716When installing fast tracepoints in memory, the target may need to
38717relocate the instruction currently at the tracepoint address to a
38718different address in memory. For most instructions, a simple copy is
38719enough, but, for example, call instructions that implicitly push the
38720return address on the stack, and relative branches or other
38721PC-relative instructions require offset adjustment, so that the effect
38722of executing the instruction at a different address is the same as if
38723it had executed in the original location.
38724
38725In response to several of the tracepoint packets, the target may also
38726respond with a number of intermediate @samp{qRelocInsn} request
38727packets before the final result packet, to have @value{GDBN} handle
38728this relocation operation. If a packet supports this mechanism, its
38729documentation will explicitly say so. See for example the above
38730descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
38731format of the request is:
38732
38733@table @samp
38734@item qRelocInsn:@var{from};@var{to}
38735
38736This requests @value{GDBN} to copy instruction at address @var{from}
38737to address @var{to}, possibly adjusted so that executing the
38738instruction at @var{to} has the same effect as executing it at
38739@var{from}. @value{GDBN} writes the adjusted instruction to target
38740memory starting at @var{to}.
38741@end table
38742
38743Replies:
38744@table @samp
38745@item qRelocInsn:@var{adjusted_size}
38746Informs the stub the relocation is complete. @var{adjusted_size} is
38747the length in bytes of resulting relocated instruction sequence.
38748@item E @var{NN}
38749A badly formed request was detected, or an error was encountered while
38750relocating the instruction.
38751@end table
38752
a6b151f1
DJ
38753@node Host I/O Packets
38754@section Host I/O Packets
38755@cindex Host I/O, remote protocol
38756@cindex file transfer, remote protocol
38757
38758The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
38759operations on the far side of a remote link. For example, Host I/O is
38760used to upload and download files to a remote target with its own
38761filesystem. Host I/O uses the same constant values and data structure
38762layout as the target-initiated File-I/O protocol. However, the
38763Host I/O packets are structured differently. The target-initiated
38764protocol relies on target memory to store parameters and buffers.
38765Host I/O requests are initiated by @value{GDBN}, and the
38766target's memory is not involved. @xref{File-I/O Remote Protocol
38767Extension}, for more details on the target-initiated protocol.
38768
38769The Host I/O request packets all encode a single operation along with
38770its arguments. They have this format:
38771
38772@table @samp
38773
38774@item vFile:@var{operation}: @var{parameter}@dots{}
38775@var{operation} is the name of the particular request; the target
38776should compare the entire packet name up to the second colon when checking
38777for a supported operation. The format of @var{parameter} depends on
38778the operation. Numbers are always passed in hexadecimal. Negative
38779numbers have an explicit minus sign (i.e.@: two's complement is not
38780used). Strings (e.g.@: filenames) are encoded as a series of
38781hexadecimal bytes. The last argument to a system call may be a
38782buffer of escaped binary data (@pxref{Binary Data}).
38783
38784@end table
38785
38786The valid responses to Host I/O packets are:
38787
38788@table @samp
38789
38790@item F @var{result} [, @var{errno}] [; @var{attachment}]
38791@var{result} is the integer value returned by this operation, usually
38792non-negative for success and -1 for errors. If an error has occured,
38793@var{errno} will be included in the result. @var{errno} will have a
38794value defined by the File-I/O protocol (@pxref{Errno Values}). For
38795operations which return data, @var{attachment} supplies the data as a
38796binary buffer. Binary buffers in response packets are escaped in the
38797normal way (@pxref{Binary Data}). See the individual packet
38798documentation for the interpretation of @var{result} and
38799@var{attachment}.
38800
d57350ea 38801@item @w{}
a6b151f1
DJ
38802An empty response indicates that this operation is not recognized.
38803
38804@end table
38805
38806These are the supported Host I/O operations:
38807
38808@table @samp
38809@item vFile:open: @var{pathname}, @var{flags}, @var{mode}
38810Open a file at @var{pathname} and return a file descriptor for it, or
38811return -1 if an error occurs. @var{pathname} is a string,
38812@var{flags} is an integer indicating a mask of open flags
38813(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
38814of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 38815@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
38816
38817@item vFile:close: @var{fd}
38818Close the open file corresponding to @var{fd} and return 0, or
38819-1 if an error occurs.
38820
38821@item vFile:pread: @var{fd}, @var{count}, @var{offset}
38822Read data from the open file corresponding to @var{fd}. Up to
38823@var{count} bytes will be read from the file, starting at @var{offset}
38824relative to the start of the file. The target may read fewer bytes;
38825common reasons include packet size limits and an end-of-file
38826condition. The number of bytes read is returned. Zero should only be
38827returned for a successful read at the end of the file, or if
38828@var{count} was zero.
38829
38830The data read should be returned as a binary attachment on success.
38831If zero bytes were read, the response should include an empty binary
38832attachment (i.e.@: a trailing semicolon). The return value is the
38833number of target bytes read; the binary attachment may be longer if
38834some characters were escaped.
38835
38836@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
38837Write @var{data} (a binary buffer) to the open file corresponding
38838to @var{fd}. Start the write at @var{offset} from the start of the
38839file. Unlike many @code{write} system calls, there is no
38840separate @var{count} argument; the length of @var{data} in the
38841packet is used. @samp{vFile:write} returns the number of bytes written,
38842which may be shorter than the length of @var{data}, or -1 if an
38843error occurred.
38844
38845@item vFile:unlink: @var{pathname}
38846Delete the file at @var{pathname} on the target. Return 0,
38847or -1 if an error occurs. @var{pathname} is a string.
38848
b9e7b9c3
UW
38849@item vFile:readlink: @var{filename}
38850Read value of symbolic link @var{filename} on the target. Return
38851the number of bytes read, or -1 if an error occurs.
38852
38853The data read should be returned as a binary attachment on success.
38854If zero bytes were read, the response should include an empty binary
38855attachment (i.e.@: a trailing semicolon). The return value is the
38856number of target bytes read; the binary attachment may be longer if
38857some characters were escaped.
38858
a6b151f1
DJ
38859@end table
38860
9a6253be
KB
38861@node Interrupts
38862@section Interrupts
38863@cindex interrupts (remote protocol)
38864
38865When a program on the remote target is running, @value{GDBN} may
9a7071a8
JB
38866attempt to interrupt it by sending a @samp{Ctrl-C}, @code{BREAK} or
38867a @code{BREAK} followed by @code{g},
38868control of which is specified via @value{GDBN}'s @samp{interrupt-sequence}.
9a6253be
KB
38869
38870The precise meaning of @code{BREAK} is defined by the transport
8775bb90
MS
38871mechanism and may, in fact, be undefined. @value{GDBN} does not
38872currently define a @code{BREAK} mechanism for any of the network
38873interfaces except for TCP, in which case @value{GDBN} sends the
38874@code{telnet} BREAK sequence.
9a6253be
KB
38875
38876@samp{Ctrl-C}, on the other hand, is defined and implemented for all
38877transport mechanisms. It is represented by sending the single byte
38878@code{0x03} without any of the usual packet overhead described in
38879the Overview section (@pxref{Overview}). When a @code{0x03} byte is
38880transmitted as part of a packet, it is considered to be packet data
38881and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 38882(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
38883@code{0x03} as part of its packet.
38884
9a7071a8
JB
38885@code{BREAK} followed by @code{g} is also known as Magic SysRq g.
38886When Linux kernel receives this sequence from serial port,
38887it stops execution and connects to gdb.
38888
9a6253be
KB
38889Stubs are not required to recognize these interrupt mechanisms and the
38890precise meaning associated with receipt of the interrupt is
8b23ecc4
SL
38891implementation defined. If the target supports debugging of multiple
38892threads and/or processes, it should attempt to interrupt all
38893currently-executing threads and processes.
38894If the stub is successful at interrupting the
38895running program, it should send one of the stop
38896reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
38897of successfully stopping the program in all-stop mode, and a stop reply
38898for each stopped thread in non-stop mode.
38899Interrupts received while the
38900program is stopped are discarded.
38901
38902@node Notification Packets
38903@section Notification Packets
38904@cindex notification packets
38905@cindex packets, notification
38906
38907The @value{GDBN} remote serial protocol includes @dfn{notifications},
38908packets that require no acknowledgment. Both the GDB and the stub
38909may send notifications (although the only notifications defined at
38910present are sent by the stub). Notifications carry information
38911without incurring the round-trip latency of an acknowledgment, and so
38912are useful for low-impact communications where occasional packet loss
38913is not a problem.
38914
38915A notification packet has the form @samp{% @var{data} #
38916@var{checksum}}, where @var{data} is the content of the notification,
38917and @var{checksum} is a checksum of @var{data}, computed and formatted
38918as for ordinary @value{GDBN} packets. A notification's @var{data}
38919never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
38920receiving a notification, the recipient sends no @samp{+} or @samp{-}
38921to acknowledge the notification's receipt or to report its corruption.
38922
38923Every notification's @var{data} begins with a name, which contains no
38924colon characters, followed by a colon character.
38925
38926Recipients should silently ignore corrupted notifications and
38927notifications they do not understand. Recipients should restart
38928timeout periods on receipt of a well-formed notification, whether or
38929not they understand it.
38930
38931Senders should only send the notifications described here when this
38932protocol description specifies that they are permitted. In the
38933future, we may extend the protocol to permit existing notifications in
38934new contexts; this rule helps older senders avoid confusing newer
38935recipients.
38936
38937(Older versions of @value{GDBN} ignore bytes received until they see
38938the @samp{$} byte that begins an ordinary packet, so new stubs may
38939transmit notifications without fear of confusing older clients. There
38940are no notifications defined for @value{GDBN} to send at the moment, but we
38941assume that most older stubs would ignore them, as well.)
38942
8dbe8ece 38943Each notification is comprised of three parts:
8b23ecc4 38944@table @samp
8dbe8ece
YQ
38945@item @var{name}:@var{event}
38946The notification packet is sent by the side that initiates the
38947exchange (currently, only the stub does that), with @var{event}
38948carrying the specific information about the notification.
38949@var{name} is the name of the notification.
38950@item @var{ack}
38951The acknowledge sent by the other side, usually @value{GDBN}, to
38952acknowledge the exchange and request the event.
38953@end table
38954
38955The purpose of an asynchronous notification mechanism is to report to
38956@value{GDBN} that something interesting happened in the remote stub.
38957
38958The remote stub may send notification @var{name}:@var{event}
38959at any time, but @value{GDBN} acknowledges the notification when
38960appropriate. The notification event is pending before @value{GDBN}
38961acknowledges. Only one notification at a time may be pending; if
38962additional events occur before @value{GDBN} has acknowledged the
38963previous notification, they must be queued by the stub for later
38964synchronous transmission in response to @var{ack} packets from
38965@value{GDBN}. Because the notification mechanism is unreliable,
38966the stub is permitted to resend a notification if it believes
38967@value{GDBN} may not have received it.
38968
38969Specifically, notifications may appear when @value{GDBN} is not
38970otherwise reading input from the stub, or when @value{GDBN} is
38971expecting to read a normal synchronous response or a
38972@samp{+}/@samp{-} acknowledgment to a packet it has sent.
38973Notification packets are distinct from any other communication from
38974the stub so there is no ambiguity.
38975
38976After receiving a notification, @value{GDBN} shall acknowledge it by
38977sending a @var{ack} packet as a regular, synchronous request to the
38978stub. Such acknowledgment is not required to happen immediately, as
38979@value{GDBN} is permitted to send other, unrelated packets to the
38980stub first, which the stub should process normally.
38981
38982Upon receiving a @var{ack} packet, if the stub has other queued
38983events to report to @value{GDBN}, it shall respond by sending a
38984normal @var{event}. @value{GDBN} shall then send another @var{ack}
38985packet to solicit further responses; again, it is permitted to send
38986other, unrelated packets as well which the stub should process
38987normally.
38988
38989If the stub receives a @var{ack} packet and there are no additional
38990@var{event} to report, the stub shall return an @samp{OK} response.
38991At this point, @value{GDBN} has finished processing a notification
38992and the stub has completed sending any queued events. @value{GDBN}
38993won't accept any new notifications until the final @samp{OK} is
38994received . If further notification events occur, the stub shall send
38995a new notification, @value{GDBN} shall accept the notification, and
38996the process shall be repeated.
38997
38998The process of asynchronous notification can be illustrated by the
38999following example:
39000@smallexample
39001<- @code{%%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
39002@code{...}
39003-> @code{vStopped}
39004<- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
39005-> @code{vStopped}
39006<- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
39007-> @code{vStopped}
39008<- @code{OK}
39009@end smallexample
39010
39011The following notifications are defined:
39012@multitable @columnfractions 0.12 0.12 0.38 0.38
39013
39014@item Notification
39015@tab Ack
39016@tab Event
39017@tab Description
39018
39019@item Stop
39020@tab vStopped
39021@tab @var{reply}. The @var{reply} has the form of a stop reply, as
8b23ecc4
SL
39022described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
39023for information on how these notifications are acknowledged by
39024@value{GDBN}.
8dbe8ece
YQ
39025@tab Report an asynchronous stop event in non-stop mode.
39026
39027@end multitable
8b23ecc4
SL
39028
39029@node Remote Non-Stop
39030@section Remote Protocol Support for Non-Stop Mode
39031
39032@value{GDBN}'s remote protocol supports non-stop debugging of
39033multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
39034supports non-stop mode, it should report that to @value{GDBN} by including
39035@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
39036
39037@value{GDBN} typically sends a @samp{QNonStop} packet only when
39038establishing a new connection with the stub. Entering non-stop mode
39039does not alter the state of any currently-running threads, but targets
39040must stop all threads in any already-attached processes when entering
39041all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
39042probe the target state after a mode change.
39043
39044In non-stop mode, when an attached process encounters an event that
39045would otherwise be reported with a stop reply, it uses the
39046asynchronous notification mechanism (@pxref{Notification Packets}) to
39047inform @value{GDBN}. In contrast to all-stop mode, where all threads
39048in all processes are stopped when a stop reply is sent, in non-stop
39049mode only the thread reporting the stop event is stopped. That is,
39050when reporting a @samp{S} or @samp{T} response to indicate completion
39051of a step operation, hitting a breakpoint, or a fault, only the
39052affected thread is stopped; any other still-running threads continue
39053to run. When reporting a @samp{W} or @samp{X} response, all running
39054threads belonging to other attached processes continue to run.
39055
8b23ecc4
SL
39056In non-stop mode, the target shall respond to the @samp{?} packet as
39057follows. First, any incomplete stop reply notification/@samp{vStopped}
39058sequence in progress is abandoned. The target must begin a new
39059sequence reporting stop events for all stopped threads, whether or not
39060it has previously reported those events to @value{GDBN}. The first
39061stop reply is sent as a synchronous reply to the @samp{?} packet, and
39062subsequent stop replies are sent as responses to @samp{vStopped} packets
39063using the mechanism described above. The target must not send
39064asynchronous stop reply notifications until the sequence is complete.
39065If all threads are running when the target receives the @samp{?} packet,
39066or if the target is not attached to any process, it shall respond
39067@samp{OK}.
9a6253be 39068
a6f3e723
SL
39069@node Packet Acknowledgment
39070@section Packet Acknowledgment
39071
39072@cindex acknowledgment, for @value{GDBN} remote
39073@cindex packet acknowledgment, for @value{GDBN} remote
39074By default, when either the host or the target machine receives a packet,
39075the first response expected is an acknowledgment: either @samp{+} (to indicate
39076the package was received correctly) or @samp{-} (to request retransmission).
39077This mechanism allows the @value{GDBN} remote protocol to operate over
39078unreliable transport mechanisms, such as a serial line.
39079
39080In cases where the transport mechanism is itself reliable (such as a pipe or
39081TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
39082It may be desirable to disable them in that case to reduce communication
39083overhead, or for other reasons. This can be accomplished by means of the
39084@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
39085
39086When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
39087expect @samp{+}/@samp{-} protocol acknowledgments. The packet
39088and response format still includes the normal checksum, as described in
39089@ref{Overview}, but the checksum may be ignored by the receiver.
39090
39091If the stub supports @samp{QStartNoAckMode} and prefers to operate in
39092no-acknowledgment mode, it should report that to @value{GDBN}
39093by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
39094@pxref{qSupported}.
39095If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
39096disabled via the @code{set remote noack-packet off} command
39097(@pxref{Remote Configuration}),
39098@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
39099Only then may the stub actually turn off packet acknowledgments.
39100@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
39101response, which can be safely ignored by the stub.
39102
39103Note that @code{set remote noack-packet} command only affects negotiation
39104between @value{GDBN} and the stub when subsequent connections are made;
39105it does not affect the protocol acknowledgment state for any current
39106connection.
39107Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
39108new connection is established,
39109there is also no protocol request to re-enable the acknowledgments
39110for the current connection, once disabled.
39111
ee2d5c50
AC
39112@node Examples
39113@section Examples
eb12ee30 39114
8e04817f
AC
39115Example sequence of a target being re-started. Notice how the restart
39116does not get any direct output:
eb12ee30 39117
474c8240 39118@smallexample
d2c6833e
AC
39119-> @code{R00}
39120<- @code{+}
8e04817f 39121@emph{target restarts}
d2c6833e 39122-> @code{?}
8e04817f 39123<- @code{+}
d2c6833e
AC
39124<- @code{T001:1234123412341234}
39125-> @code{+}
474c8240 39126@end smallexample
eb12ee30 39127
8e04817f 39128Example sequence of a target being stepped by a single instruction:
eb12ee30 39129
474c8240 39130@smallexample
d2c6833e 39131-> @code{G1445@dots{}}
8e04817f 39132<- @code{+}
d2c6833e
AC
39133-> @code{s}
39134<- @code{+}
39135@emph{time passes}
39136<- @code{T001:1234123412341234}
8e04817f 39137-> @code{+}
d2c6833e 39138-> @code{g}
8e04817f 39139<- @code{+}
d2c6833e
AC
39140<- @code{1455@dots{}}
39141-> @code{+}
474c8240 39142@end smallexample
eb12ee30 39143
79a6e687
BW
39144@node File-I/O Remote Protocol Extension
39145@section File-I/O Remote Protocol Extension
0ce1b118
CV
39146@cindex File-I/O remote protocol extension
39147
39148@menu
39149* File-I/O Overview::
79a6e687
BW
39150* Protocol Basics::
39151* The F Request Packet::
39152* The F Reply Packet::
39153* The Ctrl-C Message::
0ce1b118 39154* Console I/O::
79a6e687 39155* List of Supported Calls::
db2e3e2e 39156* Protocol-specific Representation of Datatypes::
0ce1b118
CV
39157* Constants::
39158* File-I/O Examples::
39159@end menu
39160
39161@node File-I/O Overview
39162@subsection File-I/O Overview
39163@cindex file-i/o overview
39164
9c16f35a 39165The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 39166target to use the host's file system and console I/O to perform various
0ce1b118 39167system calls. System calls on the target system are translated into a
fc320d37
SL
39168remote protocol packet to the host system, which then performs the needed
39169actions and returns a response packet to the target system.
0ce1b118
CV
39170This simulates file system operations even on targets that lack file systems.
39171
fc320d37
SL
39172The protocol is defined to be independent of both the host and target systems.
39173It uses its own internal representation of datatypes and values. Both
0ce1b118 39174@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
39175translating the system-dependent value representations into the internal
39176protocol representations when data is transmitted.
0ce1b118 39177
fc320d37
SL
39178The communication is synchronous. A system call is possible only when
39179@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
39180or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 39181the target is stopped to allow deterministic access to the target's
fc320d37
SL
39182memory. Therefore File-I/O is not interruptible by target signals. On
39183the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 39184(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
39185
39186The target's request to perform a host system call does not finish
39187the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
39188after finishing the system call, the target returns to continuing the
39189previous activity (continue, step). No additional continue or step
39190request from @value{GDBN} is required.
39191
39192@smallexample
f7dc1244 39193(@value{GDBP}) continue
0ce1b118
CV
39194 <- target requests 'system call X'
39195 target is stopped, @value{GDBN} executes system call
3f94c067
BW
39196 -> @value{GDBN} returns result
39197 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
39198 <- target hits breakpoint and sends a Txx packet
39199@end smallexample
39200
fc320d37
SL
39201The protocol only supports I/O on the console and to regular files on
39202the host file system. Character or block special devices, pipes,
39203named pipes, sockets or any other communication method on the host
0ce1b118
CV
39204system are not supported by this protocol.
39205
8b23ecc4
SL
39206File I/O is not supported in non-stop mode.
39207
79a6e687
BW
39208@node Protocol Basics
39209@subsection Protocol Basics
0ce1b118
CV
39210@cindex protocol basics, file-i/o
39211
fc320d37
SL
39212The File-I/O protocol uses the @code{F} packet as the request as well
39213as reply packet. Since a File-I/O system call can only occur when
39214@value{GDBN} is waiting for a response from the continuing or stepping target,
39215the File-I/O request is a reply that @value{GDBN} has to expect as a result
39216of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
39217This @code{F} packet contains all information needed to allow @value{GDBN}
39218to call the appropriate host system call:
39219
39220@itemize @bullet
b383017d 39221@item
0ce1b118
CV
39222A unique identifier for the requested system call.
39223
39224@item
39225All parameters to the system call. Pointers are given as addresses
39226in the target memory address space. Pointers to strings are given as
b383017d 39227pointer/length pair. Numerical values are given as they are.
db2e3e2e 39228Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
39229
39230@end itemize
39231
fc320d37 39232At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
39233
39234@itemize @bullet
b383017d 39235@item
fc320d37
SL
39236If the parameters include pointer values to data needed as input to a
39237system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
39238standard @code{m} packet request. This additional communication has to be
39239expected by the target implementation and is handled as any other @code{m}
39240packet.
39241
39242@item
39243@value{GDBN} translates all value from protocol representation to host
39244representation as needed. Datatypes are coerced into the host types.
39245
39246@item
fc320d37 39247@value{GDBN} calls the system call.
0ce1b118
CV
39248
39249@item
39250It then coerces datatypes back to protocol representation.
39251
39252@item
fc320d37
SL
39253If the system call is expected to return data in buffer space specified
39254by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
39255target using a @code{M} or @code{X} packet. This packet has to be expected
39256by the target implementation and is handled as any other @code{M} or @code{X}
39257packet.
39258
39259@end itemize
39260
39261Eventually @value{GDBN} replies with another @code{F} packet which contains all
39262necessary information for the target to continue. This at least contains
39263
39264@itemize @bullet
39265@item
39266Return value.
39267
39268@item
39269@code{errno}, if has been changed by the system call.
39270
39271@item
39272``Ctrl-C'' flag.
39273
39274@end itemize
39275
39276After having done the needed type and value coercion, the target continues
39277the latest continue or step action.
39278
79a6e687
BW
39279@node The F Request Packet
39280@subsection The @code{F} Request Packet
0ce1b118
CV
39281@cindex file-i/o request packet
39282@cindex @code{F} request packet
39283
39284The @code{F} request packet has the following format:
39285
39286@table @samp
fc320d37 39287@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
39288
39289@var{call-id} is the identifier to indicate the host system call to be called.
39290This is just the name of the function.
39291
fc320d37
SL
39292@var{parameter@dots{}} are the parameters to the system call.
39293Parameters are hexadecimal integer values, either the actual values in case
39294of scalar datatypes, pointers to target buffer space in case of compound
39295datatypes and unspecified memory areas, or pointer/length pairs in case
39296of string parameters. These are appended to the @var{call-id} as a
39297comma-delimited list. All values are transmitted in ASCII
39298string representation, pointer/length pairs separated by a slash.
0ce1b118 39299
b383017d 39300@end table
0ce1b118 39301
fc320d37 39302
0ce1b118 39303
79a6e687
BW
39304@node The F Reply Packet
39305@subsection The @code{F} Reply Packet
0ce1b118
CV
39306@cindex file-i/o reply packet
39307@cindex @code{F} reply packet
39308
39309The @code{F} reply packet has the following format:
39310
39311@table @samp
39312
d3bdde98 39313@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
39314
39315@var{retcode} is the return code of the system call as hexadecimal value.
39316
db2e3e2e
BW
39317@var{errno} is the @code{errno} set by the call, in protocol-specific
39318representation.
0ce1b118
CV
39319This parameter can be omitted if the call was successful.
39320
fc320d37
SL
39321@var{Ctrl-C flag} is only sent if the user requested a break. In this
39322case, @var{errno} must be sent as well, even if the call was successful.
39323The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
39324
39325@smallexample
39326F0,0,C
39327@end smallexample
39328
39329@noindent
fc320d37 39330or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
39331
39332@smallexample
39333F-1,4,C
39334@end smallexample
39335
39336@noindent
db2e3e2e 39337assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
39338
39339@end table
39340
0ce1b118 39341
79a6e687
BW
39342@node The Ctrl-C Message
39343@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
39344@cindex ctrl-c message, in file-i/o protocol
39345
c8aa23ab 39346If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 39347reply packet (@pxref{The F Reply Packet}),
fc320d37 39348the target should behave as if it had
0ce1b118 39349gotten a break message. The meaning for the target is ``system call
fc320d37 39350interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 39351(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 39352packet.
fc320d37
SL
39353
39354It's important for the target to know in which
39355state the system call was interrupted. There are two possible cases:
0ce1b118
CV
39356
39357@itemize @bullet
39358@item
39359The system call hasn't been performed on the host yet.
39360
39361@item
39362The system call on the host has been finished.
39363
39364@end itemize
39365
39366These two states can be distinguished by the target by the value of the
39367returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
39368call hasn't been performed. This is equivalent to the @code{EINTR} handling
39369on POSIX systems. In any other case, the target may presume that the
fc320d37 39370system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
39371as if the break message arrived right after the system call.
39372
fc320d37 39373@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
39374yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
39375@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
39376before the user requests a break, the full action must be finished by
39377@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
39378The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
39379or the full action has been completed.
39380
39381@node Console I/O
39382@subsection Console I/O
39383@cindex console i/o as part of file-i/o
39384
d3e8051b 39385By default and if not explicitly closed by the target system, the file
0ce1b118
CV
39386descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
39387on the @value{GDBN} console is handled as any other file output operation
39388(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
39389by @value{GDBN} so that after the target read request from file descriptor
393900 all following typing is buffered until either one of the following
39391conditions is met:
39392
39393@itemize @bullet
39394@item
c8aa23ab 39395The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
39396@code{read}
39397system call is treated as finished.
39398
39399@item
7f9087cb 39400The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 39401newline.
0ce1b118
CV
39402
39403@item
c8aa23ab
EZ
39404The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
39405character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
39406
39407@end itemize
39408
fc320d37
SL
39409If the user has typed more characters than fit in the buffer given to
39410the @code{read} call, the trailing characters are buffered in @value{GDBN} until
39411either another @code{read(0, @dots{})} is requested by the target, or debugging
39412is stopped at the user's request.
0ce1b118 39413
0ce1b118 39414
79a6e687
BW
39415@node List of Supported Calls
39416@subsection List of Supported Calls
0ce1b118
CV
39417@cindex list of supported file-i/o calls
39418
39419@menu
39420* open::
39421* close::
39422* read::
39423* write::
39424* lseek::
39425* rename::
39426* unlink::
39427* stat/fstat::
39428* gettimeofday::
39429* isatty::
39430* system::
39431@end menu
39432
39433@node open
39434@unnumberedsubsubsec open
39435@cindex open, file-i/o system call
39436
fc320d37
SL
39437@table @asis
39438@item Synopsis:
0ce1b118 39439@smallexample
0ce1b118
CV
39440int open(const char *pathname, int flags);
39441int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
39442@end smallexample
39443
fc320d37
SL
39444@item Request:
39445@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
39446
0ce1b118 39447@noindent
fc320d37 39448@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
39449
39450@table @code
b383017d 39451@item O_CREAT
0ce1b118
CV
39452If the file does not exist it will be created. The host
39453rules apply as far as file ownership and time stamps
39454are concerned.
39455
b383017d 39456@item O_EXCL
fc320d37 39457When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
39458an error and open() fails.
39459
b383017d 39460@item O_TRUNC
0ce1b118 39461If the file already exists and the open mode allows
fc320d37
SL
39462writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
39463truncated to zero length.
0ce1b118 39464
b383017d 39465@item O_APPEND
0ce1b118
CV
39466The file is opened in append mode.
39467
b383017d 39468@item O_RDONLY
0ce1b118
CV
39469The file is opened for reading only.
39470
b383017d 39471@item O_WRONLY
0ce1b118
CV
39472The file is opened for writing only.
39473
b383017d 39474@item O_RDWR
0ce1b118 39475The file is opened for reading and writing.
fc320d37 39476@end table
0ce1b118
CV
39477
39478@noindent
fc320d37 39479Other bits are silently ignored.
0ce1b118 39480
0ce1b118
CV
39481
39482@noindent
fc320d37 39483@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
39484
39485@table @code
b383017d 39486@item S_IRUSR
0ce1b118
CV
39487User has read permission.
39488
b383017d 39489@item S_IWUSR
0ce1b118
CV
39490User has write permission.
39491
b383017d 39492@item S_IRGRP
0ce1b118
CV
39493Group has read permission.
39494
b383017d 39495@item S_IWGRP
0ce1b118
CV
39496Group has write permission.
39497
b383017d 39498@item S_IROTH
0ce1b118
CV
39499Others have read permission.
39500
b383017d 39501@item S_IWOTH
0ce1b118 39502Others have write permission.
fc320d37 39503@end table
0ce1b118
CV
39504
39505@noindent
fc320d37 39506Other bits are silently ignored.
0ce1b118 39507
0ce1b118 39508
fc320d37
SL
39509@item Return value:
39510@code{open} returns the new file descriptor or -1 if an error
39511occurred.
0ce1b118 39512
fc320d37 39513@item Errors:
0ce1b118
CV
39514
39515@table @code
b383017d 39516@item EEXIST
fc320d37 39517@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 39518
b383017d 39519@item EISDIR
fc320d37 39520@var{pathname} refers to a directory.
0ce1b118 39521
b383017d 39522@item EACCES
0ce1b118
CV
39523The requested access is not allowed.
39524
39525@item ENAMETOOLONG
fc320d37 39526@var{pathname} was too long.
0ce1b118 39527
b383017d 39528@item ENOENT
fc320d37 39529A directory component in @var{pathname} does not exist.
0ce1b118 39530
b383017d 39531@item ENODEV
fc320d37 39532@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 39533
b383017d 39534@item EROFS
fc320d37 39535@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
39536write access was requested.
39537
b383017d 39538@item EFAULT
fc320d37 39539@var{pathname} is an invalid pointer value.
0ce1b118 39540
b383017d 39541@item ENOSPC
0ce1b118
CV
39542No space on device to create the file.
39543
b383017d 39544@item EMFILE
0ce1b118
CV
39545The process already has the maximum number of files open.
39546
b383017d 39547@item ENFILE
0ce1b118
CV
39548The limit on the total number of files open on the system
39549has been reached.
39550
b383017d 39551@item EINTR
0ce1b118
CV
39552The call was interrupted by the user.
39553@end table
39554
fc320d37
SL
39555@end table
39556
0ce1b118
CV
39557@node close
39558@unnumberedsubsubsec close
39559@cindex close, file-i/o system call
39560
fc320d37
SL
39561@table @asis
39562@item Synopsis:
0ce1b118 39563@smallexample
0ce1b118 39564int close(int fd);
fc320d37 39565@end smallexample
0ce1b118 39566
fc320d37
SL
39567@item Request:
39568@samp{Fclose,@var{fd}}
0ce1b118 39569
fc320d37
SL
39570@item Return value:
39571@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 39572
fc320d37 39573@item Errors:
0ce1b118
CV
39574
39575@table @code
b383017d 39576@item EBADF
fc320d37 39577@var{fd} isn't a valid open file descriptor.
0ce1b118 39578
b383017d 39579@item EINTR
0ce1b118
CV
39580The call was interrupted by the user.
39581@end table
39582
fc320d37
SL
39583@end table
39584
0ce1b118
CV
39585@node read
39586@unnumberedsubsubsec read
39587@cindex read, file-i/o system call
39588
fc320d37
SL
39589@table @asis
39590@item Synopsis:
0ce1b118 39591@smallexample
0ce1b118 39592int read(int fd, void *buf, unsigned int count);
fc320d37 39593@end smallexample
0ce1b118 39594
fc320d37
SL
39595@item Request:
39596@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 39597
fc320d37 39598@item Return value:
0ce1b118
CV
39599On success, the number of bytes read is returned.
39600Zero indicates end of file. If count is zero, read
b383017d 39601returns zero as well. On error, -1 is returned.
0ce1b118 39602
fc320d37 39603@item Errors:
0ce1b118
CV
39604
39605@table @code
b383017d 39606@item EBADF
fc320d37 39607@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
39608reading.
39609
b383017d 39610@item EFAULT
fc320d37 39611@var{bufptr} is an invalid pointer value.
0ce1b118 39612
b383017d 39613@item EINTR
0ce1b118
CV
39614The call was interrupted by the user.
39615@end table
39616
fc320d37
SL
39617@end table
39618
0ce1b118
CV
39619@node write
39620@unnumberedsubsubsec write
39621@cindex write, file-i/o system call
39622
fc320d37
SL
39623@table @asis
39624@item Synopsis:
0ce1b118 39625@smallexample
0ce1b118 39626int write(int fd, const void *buf, unsigned int count);
fc320d37 39627@end smallexample
0ce1b118 39628
fc320d37
SL
39629@item Request:
39630@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 39631
fc320d37 39632@item Return value:
0ce1b118
CV
39633On success, the number of bytes written are returned.
39634Zero indicates nothing was written. On error, -1
39635is returned.
39636
fc320d37 39637@item Errors:
0ce1b118
CV
39638
39639@table @code
b383017d 39640@item EBADF
fc320d37 39641@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
39642writing.
39643
b383017d 39644@item EFAULT
fc320d37 39645@var{bufptr} is an invalid pointer value.
0ce1b118 39646
b383017d 39647@item EFBIG
0ce1b118 39648An attempt was made to write a file that exceeds the
db2e3e2e 39649host-specific maximum file size allowed.
0ce1b118 39650
b383017d 39651@item ENOSPC
0ce1b118
CV
39652No space on device to write the data.
39653
b383017d 39654@item EINTR
0ce1b118
CV
39655The call was interrupted by the user.
39656@end table
39657
fc320d37
SL
39658@end table
39659
0ce1b118
CV
39660@node lseek
39661@unnumberedsubsubsec lseek
39662@cindex lseek, file-i/o system call
39663
fc320d37
SL
39664@table @asis
39665@item Synopsis:
0ce1b118 39666@smallexample
0ce1b118 39667long lseek (int fd, long offset, int flag);
0ce1b118
CV
39668@end smallexample
39669
fc320d37
SL
39670@item Request:
39671@samp{Flseek,@var{fd},@var{offset},@var{flag}}
39672
39673@var{flag} is one of:
0ce1b118
CV
39674
39675@table @code
b383017d 39676@item SEEK_SET
fc320d37 39677The offset is set to @var{offset} bytes.
0ce1b118 39678
b383017d 39679@item SEEK_CUR
fc320d37 39680The offset is set to its current location plus @var{offset}
0ce1b118
CV
39681bytes.
39682
b383017d 39683@item SEEK_END
fc320d37 39684The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
39685bytes.
39686@end table
39687
fc320d37 39688@item Return value:
0ce1b118
CV
39689On success, the resulting unsigned offset in bytes from
39690the beginning of the file is returned. Otherwise, a
39691value of -1 is returned.
39692
fc320d37 39693@item Errors:
0ce1b118
CV
39694
39695@table @code
b383017d 39696@item EBADF
fc320d37 39697@var{fd} is not a valid open file descriptor.
0ce1b118 39698
b383017d 39699@item ESPIPE
fc320d37 39700@var{fd} is associated with the @value{GDBN} console.
0ce1b118 39701
b383017d 39702@item EINVAL
fc320d37 39703@var{flag} is not a proper value.
0ce1b118 39704
b383017d 39705@item EINTR
0ce1b118
CV
39706The call was interrupted by the user.
39707@end table
39708
fc320d37
SL
39709@end table
39710
0ce1b118
CV
39711@node rename
39712@unnumberedsubsubsec rename
39713@cindex rename, file-i/o system call
39714
fc320d37
SL
39715@table @asis
39716@item Synopsis:
0ce1b118 39717@smallexample
0ce1b118 39718int rename(const char *oldpath, const char *newpath);
fc320d37 39719@end smallexample
0ce1b118 39720
fc320d37
SL
39721@item Request:
39722@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 39723
fc320d37 39724@item Return value:
0ce1b118
CV
39725On success, zero is returned. On error, -1 is returned.
39726
fc320d37 39727@item Errors:
0ce1b118
CV
39728
39729@table @code
b383017d 39730@item EISDIR
fc320d37 39731@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
39732directory.
39733
b383017d 39734@item EEXIST
fc320d37 39735@var{newpath} is a non-empty directory.
0ce1b118 39736
b383017d 39737@item EBUSY
fc320d37 39738@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
39739process.
39740
b383017d 39741@item EINVAL
0ce1b118
CV
39742An attempt was made to make a directory a subdirectory
39743of itself.
39744
b383017d 39745@item ENOTDIR
fc320d37
SL
39746A component used as a directory in @var{oldpath} or new
39747path is not a directory. Or @var{oldpath} is a directory
39748and @var{newpath} exists but is not a directory.
0ce1b118 39749
b383017d 39750@item EFAULT
fc320d37 39751@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 39752
b383017d 39753@item EACCES
0ce1b118
CV
39754No access to the file or the path of the file.
39755
39756@item ENAMETOOLONG
b383017d 39757
fc320d37 39758@var{oldpath} or @var{newpath} was too long.
0ce1b118 39759
b383017d 39760@item ENOENT
fc320d37 39761A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 39762
b383017d 39763@item EROFS
0ce1b118
CV
39764The file is on a read-only filesystem.
39765
b383017d 39766@item ENOSPC
0ce1b118
CV
39767The device containing the file has no room for the new
39768directory entry.
39769
b383017d 39770@item EINTR
0ce1b118
CV
39771The call was interrupted by the user.
39772@end table
39773
fc320d37
SL
39774@end table
39775
0ce1b118
CV
39776@node unlink
39777@unnumberedsubsubsec unlink
39778@cindex unlink, file-i/o system call
39779
fc320d37
SL
39780@table @asis
39781@item Synopsis:
0ce1b118 39782@smallexample
0ce1b118 39783int unlink(const char *pathname);
fc320d37 39784@end smallexample
0ce1b118 39785
fc320d37
SL
39786@item Request:
39787@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 39788
fc320d37 39789@item Return value:
0ce1b118
CV
39790On success, zero is returned. On error, -1 is returned.
39791
fc320d37 39792@item Errors:
0ce1b118
CV
39793
39794@table @code
b383017d 39795@item EACCES
0ce1b118
CV
39796No access to the file or the path of the file.
39797
b383017d 39798@item EPERM
0ce1b118
CV
39799The system does not allow unlinking of directories.
39800
b383017d 39801@item EBUSY
fc320d37 39802The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
39803being used by another process.
39804
b383017d 39805@item EFAULT
fc320d37 39806@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
39807
39808@item ENAMETOOLONG
fc320d37 39809@var{pathname} was too long.
0ce1b118 39810
b383017d 39811@item ENOENT
fc320d37 39812A directory component in @var{pathname} does not exist.
0ce1b118 39813
b383017d 39814@item ENOTDIR
0ce1b118
CV
39815A component of the path is not a directory.
39816
b383017d 39817@item EROFS
0ce1b118
CV
39818The file is on a read-only filesystem.
39819
b383017d 39820@item EINTR
0ce1b118
CV
39821The call was interrupted by the user.
39822@end table
39823
fc320d37
SL
39824@end table
39825
0ce1b118
CV
39826@node stat/fstat
39827@unnumberedsubsubsec stat/fstat
39828@cindex fstat, file-i/o system call
39829@cindex stat, file-i/o system call
39830
fc320d37
SL
39831@table @asis
39832@item Synopsis:
0ce1b118 39833@smallexample
0ce1b118
CV
39834int stat(const char *pathname, struct stat *buf);
39835int fstat(int fd, struct stat *buf);
fc320d37 39836@end smallexample
0ce1b118 39837
fc320d37
SL
39838@item Request:
39839@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
39840@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 39841
fc320d37 39842@item Return value:
0ce1b118
CV
39843On success, zero is returned. On error, -1 is returned.
39844
fc320d37 39845@item Errors:
0ce1b118
CV
39846
39847@table @code
b383017d 39848@item EBADF
fc320d37 39849@var{fd} is not a valid open file.
0ce1b118 39850
b383017d 39851@item ENOENT
fc320d37 39852A directory component in @var{pathname} does not exist or the
0ce1b118
CV
39853path is an empty string.
39854
b383017d 39855@item ENOTDIR
0ce1b118
CV
39856A component of the path is not a directory.
39857
b383017d 39858@item EFAULT
fc320d37 39859@var{pathnameptr} is an invalid pointer value.
0ce1b118 39860
b383017d 39861@item EACCES
0ce1b118
CV
39862No access to the file or the path of the file.
39863
39864@item ENAMETOOLONG
fc320d37 39865@var{pathname} was too long.
0ce1b118 39866
b383017d 39867@item EINTR
0ce1b118
CV
39868The call was interrupted by the user.
39869@end table
39870
fc320d37
SL
39871@end table
39872
0ce1b118
CV
39873@node gettimeofday
39874@unnumberedsubsubsec gettimeofday
39875@cindex gettimeofday, file-i/o system call
39876
fc320d37
SL
39877@table @asis
39878@item Synopsis:
0ce1b118 39879@smallexample
0ce1b118 39880int gettimeofday(struct timeval *tv, void *tz);
fc320d37 39881@end smallexample
0ce1b118 39882
fc320d37
SL
39883@item Request:
39884@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 39885
fc320d37 39886@item Return value:
0ce1b118
CV
39887On success, 0 is returned, -1 otherwise.
39888
fc320d37 39889@item Errors:
0ce1b118
CV
39890
39891@table @code
b383017d 39892@item EINVAL
fc320d37 39893@var{tz} is a non-NULL pointer.
0ce1b118 39894
b383017d 39895@item EFAULT
fc320d37
SL
39896@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
39897@end table
39898
0ce1b118
CV
39899@end table
39900
39901@node isatty
39902@unnumberedsubsubsec isatty
39903@cindex isatty, file-i/o system call
39904
fc320d37
SL
39905@table @asis
39906@item Synopsis:
0ce1b118 39907@smallexample
0ce1b118 39908int isatty(int fd);
fc320d37 39909@end smallexample
0ce1b118 39910
fc320d37
SL
39911@item Request:
39912@samp{Fisatty,@var{fd}}
0ce1b118 39913
fc320d37
SL
39914@item Return value:
39915Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 39916
fc320d37 39917@item Errors:
0ce1b118
CV
39918
39919@table @code
b383017d 39920@item EINTR
0ce1b118
CV
39921The call was interrupted by the user.
39922@end table
39923
fc320d37
SL
39924@end table
39925
39926Note that the @code{isatty} call is treated as a special case: it returns
399271 to the target if the file descriptor is attached
39928to the @value{GDBN} console, 0 otherwise. Implementing through system calls
39929would require implementing @code{ioctl} and would be more complex than
39930needed.
39931
39932
0ce1b118
CV
39933@node system
39934@unnumberedsubsubsec system
39935@cindex system, file-i/o system call
39936
fc320d37
SL
39937@table @asis
39938@item Synopsis:
0ce1b118 39939@smallexample
0ce1b118 39940int system(const char *command);
fc320d37 39941@end smallexample
0ce1b118 39942
fc320d37
SL
39943@item Request:
39944@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 39945
fc320d37 39946@item Return value:
5600ea19
NS
39947If @var{len} is zero, the return value indicates whether a shell is
39948available. A zero return value indicates a shell is not available.
39949For non-zero @var{len}, the value returned is -1 on error and the
39950return status of the command otherwise. Only the exit status of the
39951command is returned, which is extracted from the host's @code{system}
39952return value by calling @code{WEXITSTATUS(retval)}. In case
39953@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 39954
fc320d37 39955@item Errors:
0ce1b118
CV
39956
39957@table @code
b383017d 39958@item EINTR
0ce1b118
CV
39959The call was interrupted by the user.
39960@end table
39961
fc320d37
SL
39962@end table
39963
39964@value{GDBN} takes over the full task of calling the necessary host calls
39965to perform the @code{system} call. The return value of @code{system} on
39966the host is simplified before it's returned
39967to the target. Any termination signal information from the child process
39968is discarded, and the return value consists
39969entirely of the exit status of the called command.
39970
39971Due to security concerns, the @code{system} call is by default refused
39972by @value{GDBN}. The user has to allow this call explicitly with the
39973@code{set remote system-call-allowed 1} command.
39974
39975@table @code
39976@item set remote system-call-allowed
39977@kindex set remote system-call-allowed
39978Control whether to allow the @code{system} calls in the File I/O
39979protocol for the remote target. The default is zero (disabled).
39980
39981@item show remote system-call-allowed
39982@kindex show remote system-call-allowed
39983Show whether the @code{system} calls are allowed in the File I/O
39984protocol.
39985@end table
39986
db2e3e2e
BW
39987@node Protocol-specific Representation of Datatypes
39988@subsection Protocol-specific Representation of Datatypes
39989@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
39990
39991@menu
79a6e687
BW
39992* Integral Datatypes::
39993* Pointer Values::
39994* Memory Transfer::
0ce1b118
CV
39995* struct stat::
39996* struct timeval::
39997@end menu
39998
79a6e687
BW
39999@node Integral Datatypes
40000@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
40001@cindex integral datatypes, in file-i/o protocol
40002
fc320d37
SL
40003The integral datatypes used in the system calls are @code{int},
40004@code{unsigned int}, @code{long}, @code{unsigned long},
40005@code{mode_t}, and @code{time_t}.
0ce1b118 40006
fc320d37 40007@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
40008implemented as 32 bit values in this protocol.
40009
fc320d37 40010@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 40011
0ce1b118
CV
40012@xref{Limits}, for corresponding MIN and MAX values (similar to those
40013in @file{limits.h}) to allow range checking on host and target.
40014
40015@code{time_t} datatypes are defined as seconds since the Epoch.
40016
40017All integral datatypes transferred as part of a memory read or write of a
40018structured datatype e.g.@: a @code{struct stat} have to be given in big endian
40019byte order.
40020
79a6e687
BW
40021@node Pointer Values
40022@unnumberedsubsubsec Pointer Values
0ce1b118
CV
40023@cindex pointer values, in file-i/o protocol
40024
40025Pointers to target data are transmitted as they are. An exception
40026is made for pointers to buffers for which the length isn't
40027transmitted as part of the function call, namely strings. Strings
40028are transmitted as a pointer/length pair, both as hex values, e.g.@:
40029
40030@smallexample
40031@code{1aaf/12}
40032@end smallexample
40033
40034@noindent
40035which is a pointer to data of length 18 bytes at position 0x1aaf.
40036The length is defined as the full string length in bytes, including
fc320d37
SL
40037the trailing null byte. For example, the string @code{"hello world"}
40038at address 0x123456 is transmitted as
0ce1b118
CV
40039
40040@smallexample
fc320d37 40041@code{123456/d}
0ce1b118
CV
40042@end smallexample
40043
79a6e687
BW
40044@node Memory Transfer
40045@unnumberedsubsubsec Memory Transfer
fc320d37
SL
40046@cindex memory transfer, in file-i/o protocol
40047
40048Structured data which is transferred using a memory read or write (for
db2e3e2e 40049example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
40050with all scalar multibyte datatypes being big endian. Translation to
40051this representation needs to be done both by the target before the @code{F}
40052packet is sent, and by @value{GDBN} before
40053it transfers memory to the target. Transferred pointers to structured
40054data should point to the already-coerced data at any time.
0ce1b118 40055
0ce1b118
CV
40056
40057@node struct stat
40058@unnumberedsubsubsec struct stat
40059@cindex struct stat, in file-i/o protocol
40060
fc320d37
SL
40061The buffer of type @code{struct stat} used by the target and @value{GDBN}
40062is defined as follows:
0ce1b118
CV
40063
40064@smallexample
40065struct stat @{
40066 unsigned int st_dev; /* device */
40067 unsigned int st_ino; /* inode */
40068 mode_t st_mode; /* protection */
40069 unsigned int st_nlink; /* number of hard links */
40070 unsigned int st_uid; /* user ID of owner */
40071 unsigned int st_gid; /* group ID of owner */
40072 unsigned int st_rdev; /* device type (if inode device) */
40073 unsigned long st_size; /* total size, in bytes */
40074 unsigned long st_blksize; /* blocksize for filesystem I/O */
40075 unsigned long st_blocks; /* number of blocks allocated */
40076 time_t st_atime; /* time of last access */
40077 time_t st_mtime; /* time of last modification */
40078 time_t st_ctime; /* time of last change */
40079@};
40080@end smallexample
40081
fc320d37 40082The integral datatypes conform to the definitions given in the
79a6e687 40083appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
40084structure is of size 64 bytes.
40085
40086The values of several fields have a restricted meaning and/or
40087range of values.
40088
fc320d37 40089@table @code
0ce1b118 40090
fc320d37
SL
40091@item st_dev
40092A value of 0 represents a file, 1 the console.
0ce1b118 40093
fc320d37
SL
40094@item st_ino
40095No valid meaning for the target. Transmitted unchanged.
0ce1b118 40096
fc320d37
SL
40097@item st_mode
40098Valid mode bits are described in @ref{Constants}. Any other
40099bits have currently no meaning for the target.
0ce1b118 40100
fc320d37
SL
40101@item st_uid
40102@itemx st_gid
40103@itemx st_rdev
40104No valid meaning for the target. Transmitted unchanged.
0ce1b118 40105
fc320d37
SL
40106@item st_atime
40107@itemx st_mtime
40108@itemx st_ctime
40109These values have a host and file system dependent
40110accuracy. Especially on Windows hosts, the file system may not
40111support exact timing values.
40112@end table
0ce1b118 40113
fc320d37
SL
40114The target gets a @code{struct stat} of the above representation and is
40115responsible for coercing it to the target representation before
0ce1b118
CV
40116continuing.
40117
fc320d37
SL
40118Note that due to size differences between the host, target, and protocol
40119representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
40120get truncated on the target.
40121
40122@node struct timeval
40123@unnumberedsubsubsec struct timeval
40124@cindex struct timeval, in file-i/o protocol
40125
fc320d37 40126The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
40127is defined as follows:
40128
40129@smallexample
b383017d 40130struct timeval @{
0ce1b118
CV
40131 time_t tv_sec; /* second */
40132 long tv_usec; /* microsecond */
40133@};
40134@end smallexample
40135
fc320d37 40136The integral datatypes conform to the definitions given in the
79a6e687 40137appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
40138structure is of size 8 bytes.
40139
40140@node Constants
40141@subsection Constants
40142@cindex constants, in file-i/o protocol
40143
40144The following values are used for the constants inside of the
fc320d37 40145protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
40146values before and after the call as needed.
40147
40148@menu
79a6e687
BW
40149* Open Flags::
40150* mode_t Values::
40151* Errno Values::
40152* Lseek Flags::
0ce1b118
CV
40153* Limits::
40154@end menu
40155
79a6e687
BW
40156@node Open Flags
40157@unnumberedsubsubsec Open Flags
0ce1b118
CV
40158@cindex open flags, in file-i/o protocol
40159
40160All values are given in hexadecimal representation.
40161
40162@smallexample
40163 O_RDONLY 0x0
40164 O_WRONLY 0x1
40165 O_RDWR 0x2
40166 O_APPEND 0x8
40167 O_CREAT 0x200
40168 O_TRUNC 0x400
40169 O_EXCL 0x800
40170@end smallexample
40171
79a6e687
BW
40172@node mode_t Values
40173@unnumberedsubsubsec mode_t Values
0ce1b118
CV
40174@cindex mode_t values, in file-i/o protocol
40175
40176All values are given in octal representation.
40177
40178@smallexample
40179 S_IFREG 0100000
40180 S_IFDIR 040000
40181 S_IRUSR 0400
40182 S_IWUSR 0200
40183 S_IXUSR 0100
40184 S_IRGRP 040
40185 S_IWGRP 020
40186 S_IXGRP 010
40187 S_IROTH 04
40188 S_IWOTH 02
40189 S_IXOTH 01
40190@end smallexample
40191
79a6e687
BW
40192@node Errno Values
40193@unnumberedsubsubsec Errno Values
0ce1b118
CV
40194@cindex errno values, in file-i/o protocol
40195
40196All values are given in decimal representation.
40197
40198@smallexample
40199 EPERM 1
40200 ENOENT 2
40201 EINTR 4
40202 EBADF 9
40203 EACCES 13
40204 EFAULT 14
40205 EBUSY 16
40206 EEXIST 17
40207 ENODEV 19
40208 ENOTDIR 20
40209 EISDIR 21
40210 EINVAL 22
40211 ENFILE 23
40212 EMFILE 24
40213 EFBIG 27
40214 ENOSPC 28
40215 ESPIPE 29
40216 EROFS 30
40217 ENAMETOOLONG 91
40218 EUNKNOWN 9999
40219@end smallexample
40220
fc320d37 40221 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
40222 any error value not in the list of supported error numbers.
40223
79a6e687
BW
40224@node Lseek Flags
40225@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
40226@cindex lseek flags, in file-i/o protocol
40227
40228@smallexample
40229 SEEK_SET 0
40230 SEEK_CUR 1
40231 SEEK_END 2
40232@end smallexample
40233
40234@node Limits
40235@unnumberedsubsubsec Limits
40236@cindex limits, in file-i/o protocol
40237
40238All values are given in decimal representation.
40239
40240@smallexample
40241 INT_MIN -2147483648
40242 INT_MAX 2147483647
40243 UINT_MAX 4294967295
40244 LONG_MIN -9223372036854775808
40245 LONG_MAX 9223372036854775807
40246 ULONG_MAX 18446744073709551615
40247@end smallexample
40248
40249@node File-I/O Examples
40250@subsection File-I/O Examples
40251@cindex file-i/o examples
40252
40253Example sequence of a write call, file descriptor 3, buffer is at target
40254address 0x1234, 6 bytes should be written:
40255
40256@smallexample
40257<- @code{Fwrite,3,1234,6}
40258@emph{request memory read from target}
40259-> @code{m1234,6}
40260<- XXXXXX
40261@emph{return "6 bytes written"}
40262-> @code{F6}
40263@end smallexample
40264
40265Example sequence of a read call, file descriptor 3, buffer is at target
40266address 0x1234, 6 bytes should be read:
40267
40268@smallexample
40269<- @code{Fread,3,1234,6}
40270@emph{request memory write to target}
40271-> @code{X1234,6:XXXXXX}
40272@emph{return "6 bytes read"}
40273-> @code{F6}
40274@end smallexample
40275
40276Example sequence of a read call, call fails on the host due to invalid
fc320d37 40277file descriptor (@code{EBADF}):
0ce1b118
CV
40278
40279@smallexample
40280<- @code{Fread,3,1234,6}
40281-> @code{F-1,9}
40282@end smallexample
40283
c8aa23ab 40284Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
40285host is called:
40286
40287@smallexample
40288<- @code{Fread,3,1234,6}
40289-> @code{F-1,4,C}
40290<- @code{T02}
40291@end smallexample
40292
c8aa23ab 40293Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
40294host is called:
40295
40296@smallexample
40297<- @code{Fread,3,1234,6}
40298-> @code{X1234,6:XXXXXX}
40299<- @code{T02}
40300@end smallexample
40301
cfa9d6d9
DJ
40302@node Library List Format
40303@section Library List Format
40304@cindex library list format, remote protocol
40305
40306On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
40307same process as your application to manage libraries. In this case,
40308@value{GDBN} can use the loader's symbol table and normal memory
40309operations to maintain a list of shared libraries. On other
40310platforms, the operating system manages loaded libraries.
40311@value{GDBN} can not retrieve the list of currently loaded libraries
40312through memory operations, so it uses the @samp{qXfer:libraries:read}
40313packet (@pxref{qXfer library list read}) instead. The remote stub
40314queries the target's operating system and reports which libraries
40315are loaded.
40316
40317The @samp{qXfer:libraries:read} packet returns an XML document which
40318lists loaded libraries and their offsets. Each library has an
1fddbabb
PA
40319associated name and one or more segment or section base addresses,
40320which report where the library was loaded in memory.
40321
40322For the common case of libraries that are fully linked binaries, the
40323library should have a list of segments. If the target supports
40324dynamic linking of a relocatable object file, its library XML element
40325should instead include a list of allocated sections. The segment or
40326section bases are start addresses, not relocation offsets; they do not
40327depend on the library's link-time base addresses.
cfa9d6d9 40328
9cceb671
DJ
40329@value{GDBN} must be linked with the Expat library to support XML
40330library lists. @xref{Expat}.
40331
cfa9d6d9
DJ
40332A simple memory map, with one loaded library relocated by a single
40333offset, looks like this:
40334
40335@smallexample
40336<library-list>
40337 <library name="/lib/libc.so.6">
40338 <segment address="0x10000000"/>
40339 </library>
40340</library-list>
40341@end smallexample
40342
1fddbabb
PA
40343Another simple memory map, with one loaded library with three
40344allocated sections (.text, .data, .bss), looks like this:
40345
40346@smallexample
40347<library-list>
40348 <library name="sharedlib.o">
40349 <section address="0x10000000"/>
40350 <section address="0x20000000"/>
40351 <section address="0x30000000"/>
40352 </library>
40353</library-list>
40354@end smallexample
40355
cfa9d6d9
DJ
40356The format of a library list is described by this DTD:
40357
40358@smallexample
40359<!-- library-list: Root element with versioning -->
40360<!ELEMENT library-list (library)*>
40361<!ATTLIST library-list version CDATA #FIXED "1.0">
1fddbabb 40362<!ELEMENT library (segment*, section*)>
cfa9d6d9
DJ
40363<!ATTLIST library name CDATA #REQUIRED>
40364<!ELEMENT segment EMPTY>
40365<!ATTLIST segment address CDATA #REQUIRED>
1fddbabb
PA
40366<!ELEMENT section EMPTY>
40367<!ATTLIST section address CDATA #REQUIRED>
cfa9d6d9
DJ
40368@end smallexample
40369
1fddbabb
PA
40370In addition, segments and section descriptors cannot be mixed within a
40371single library element, and you must supply at least one segment or
40372section for each library.
40373
2268b414
JK
40374@node Library List Format for SVR4 Targets
40375@section Library List Format for SVR4 Targets
40376@cindex library list format, remote protocol
40377
40378On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
40379(e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
40380shared libraries. Still a special library list provided by this packet is
40381more efficient for the @value{GDBN} remote protocol.
40382
40383The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
40384loaded libraries and their SVR4 linker parameters. For each library on SVR4
40385target, the following parameters are reported:
40386
40387@itemize @minus
40388@item
40389@code{name}, the absolute file name from the @code{l_name} field of
40390@code{struct link_map}.
40391@item
40392@code{lm} with address of @code{struct link_map} used for TLS
40393(Thread Local Storage) access.
40394@item
40395@code{l_addr}, the displacement as read from the field @code{l_addr} of
40396@code{struct link_map}. For prelinked libraries this is not an absolute
40397memory address. It is a displacement of absolute memory address against
40398address the file was prelinked to during the library load.
40399@item
40400@code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
40401@end itemize
40402
40403Additionally the single @code{main-lm} attribute specifies address of
40404@code{struct link_map} used for the main executable. This parameter is used
40405for TLS access and its presence is optional.
40406
40407@value{GDBN} must be linked with the Expat library to support XML
40408SVR4 library lists. @xref{Expat}.
40409
40410A simple memory map, with two loaded libraries (which do not use prelink),
40411looks like this:
40412
40413@smallexample
40414<library-list-svr4 version="1.0" main-lm="0xe4f8f8">
40415 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
40416 l_ld="0xe4eefc"/>
40417 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
40418 l_ld="0x152350"/>
40419</library-list-svr>
40420@end smallexample
40421
40422The format of an SVR4 library list is described by this DTD:
40423
40424@smallexample
40425<!-- library-list-svr4: Root element with versioning -->
40426<!ELEMENT library-list-svr4 (library)*>
40427<!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
40428<!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
40429<!ELEMENT library EMPTY>
40430<!ATTLIST library name CDATA #REQUIRED>
40431<!ATTLIST library lm CDATA #REQUIRED>
40432<!ATTLIST library l_addr CDATA #REQUIRED>
40433<!ATTLIST library l_ld CDATA #REQUIRED>
40434@end smallexample
40435
79a6e687
BW
40436@node Memory Map Format
40437@section Memory Map Format
68437a39
DJ
40438@cindex memory map format
40439
40440To be able to write into flash memory, @value{GDBN} needs to obtain a
40441memory map from the target. This section describes the format of the
40442memory map.
40443
40444The memory map is obtained using the @samp{qXfer:memory-map:read}
40445(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
40446lists memory regions.
40447
40448@value{GDBN} must be linked with the Expat library to support XML
40449memory maps. @xref{Expat}.
40450
40451The top-level structure of the document is shown below:
68437a39
DJ
40452
40453@smallexample
40454<?xml version="1.0"?>
40455<!DOCTYPE memory-map
40456 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
40457 "http://sourceware.org/gdb/gdb-memory-map.dtd">
40458<memory-map>
40459 region...
40460</memory-map>
40461@end smallexample
40462
40463Each region can be either:
40464
40465@itemize
40466
40467@item
40468A region of RAM starting at @var{addr} and extending for @var{length}
40469bytes from there:
40470
40471@smallexample
40472<memory type="ram" start="@var{addr}" length="@var{length}"/>
40473@end smallexample
40474
40475
40476@item
40477A region of read-only memory:
40478
40479@smallexample
40480<memory type="rom" start="@var{addr}" length="@var{length}"/>
40481@end smallexample
40482
40483
40484@item
40485A region of flash memory, with erasure blocks @var{blocksize}
40486bytes in length:
40487
40488@smallexample
40489<memory type="flash" start="@var{addr}" length="@var{length}">
40490 <property name="blocksize">@var{blocksize}</property>
40491</memory>
40492@end smallexample
40493
40494@end itemize
40495
40496Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
40497by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
40498packets to write to addresses in such ranges.
40499
40500The formal DTD for memory map format is given below:
40501
40502@smallexample
40503<!-- ................................................... -->
40504<!-- Memory Map XML DTD ................................ -->
40505<!-- File: memory-map.dtd .............................. -->
40506<!-- .................................... .............. -->
40507<!-- memory-map.dtd -->
40508<!-- memory-map: Root element with versioning -->
40509<!ELEMENT memory-map (memory | property)>
40510<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
40511<!ELEMENT memory (property)>
40512<!-- memory: Specifies a memory region,
40513 and its type, or device. -->
40514<!ATTLIST memory type CDATA #REQUIRED
40515 start CDATA #REQUIRED
40516 length CDATA #REQUIRED
40517 device CDATA #IMPLIED>
40518<!-- property: Generic attribute tag -->
40519<!ELEMENT property (#PCDATA | property)*>
40520<!ATTLIST property name CDATA #REQUIRED>
40521@end smallexample
40522
dc146f7c
VP
40523@node Thread List Format
40524@section Thread List Format
40525@cindex thread list format
40526
40527To efficiently update the list of threads and their attributes,
40528@value{GDBN} issues the @samp{qXfer:threads:read} packet
40529(@pxref{qXfer threads read}) and obtains the XML document with
40530the following structure:
40531
40532@smallexample
40533<?xml version="1.0"?>
40534<threads>
40535 <thread id="id" core="0">
40536 ... description ...
40537 </thread>
40538</threads>
40539@end smallexample
40540
40541Each @samp{thread} element must have the @samp{id} attribute that
40542identifies the thread (@pxref{thread-id syntax}). The
40543@samp{core} attribute, if present, specifies which processor core
40544the thread was last executing on. The content of the of @samp{thread}
40545element is interpreted as human-readable auxilliary information.
40546
b3b9301e
PA
40547@node Traceframe Info Format
40548@section Traceframe Info Format
40549@cindex traceframe info format
40550
40551To be able to know which objects in the inferior can be examined when
40552inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
40553memory ranges, registers and trace state variables that have been
40554collected in a traceframe.
40555
40556This list is obtained using the @samp{qXfer:traceframe-info:read}
40557(@pxref{qXfer traceframe info read}) packet and is an XML document.
40558
40559@value{GDBN} must be linked with the Expat library to support XML
40560traceframe info discovery. @xref{Expat}.
40561
40562The top-level structure of the document is shown below:
40563
40564@smallexample
40565<?xml version="1.0"?>
40566<!DOCTYPE traceframe-info
40567 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
40568 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
40569<traceframe-info>
40570 block...
40571</traceframe-info>
40572@end smallexample
40573
40574Each traceframe block can be either:
40575
40576@itemize
40577
40578@item
40579A region of collected memory starting at @var{addr} and extending for
40580@var{length} bytes from there:
40581
40582@smallexample
40583<memory start="@var{addr}" length="@var{length}"/>
40584@end smallexample
40585
40586@end itemize
40587
40588The formal DTD for the traceframe info format is given below:
40589
40590@smallexample
40591<!ELEMENT traceframe-info (memory)* >
40592<!ATTLIST traceframe-info version CDATA #FIXED "1.0">
40593
40594<!ELEMENT memory EMPTY>
40595<!ATTLIST memory start CDATA #REQUIRED
40596 length CDATA #REQUIRED>
40597@end smallexample
40598
2ae8c8e7
MM
40599@node Branch Trace Format
40600@section Branch Trace Format
40601@cindex branch trace format
40602
40603In order to display the branch trace of an inferior thread,
40604@value{GDBN} needs to obtain the list of branches. This list is
40605represented as list of sequential code blocks that are connected via
40606branches. The code in each block has been executed sequentially.
40607
40608This list is obtained using the @samp{qXfer:btrace:read}
40609(@pxref{qXfer btrace read}) packet and is an XML document.
40610
40611@value{GDBN} must be linked with the Expat library to support XML
40612traceframe info discovery. @xref{Expat}.
40613
40614The top-level structure of the document is shown below:
40615
40616@smallexample
40617<?xml version="1.0"?>
40618<!DOCTYPE btrace
40619 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
40620 "http://sourceware.org/gdb/gdb-btrace.dtd">
40621<btrace>
40622 block...
40623</btrace>
40624@end smallexample
40625
40626@itemize
40627
40628@item
40629A block of sequentially executed instructions starting at @var{begin}
40630and ending at @var{end}:
40631
40632@smallexample
40633<block begin="@var{begin}" end="@var{end}"/>
40634@end smallexample
40635
40636@end itemize
40637
40638The formal DTD for the branch trace format is given below:
40639
40640@smallexample
40641<!ELEMENT btrace (block)* >
40642<!ATTLIST btrace version CDATA #FIXED "1.0">
40643
40644<!ELEMENT block EMPTY>
40645<!ATTLIST block begin CDATA #REQUIRED
40646 end CDATA #REQUIRED>
40647@end smallexample
40648
f418dd93
DJ
40649@include agentexpr.texi
40650
23181151
DJ
40651@node Target Descriptions
40652@appendix Target Descriptions
40653@cindex target descriptions
40654
23181151
DJ
40655One of the challenges of using @value{GDBN} to debug embedded systems
40656is that there are so many minor variants of each processor
40657architecture in use. It is common practice for vendors to start with
eb17f351 40658a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
23181151
DJ
40659and then make changes to adapt it to a particular market niche. Some
40660architectures have hundreds of variants, available from dozens of
40661vendors. This leads to a number of problems:
40662
40663@itemize @bullet
40664@item
40665With so many different customized processors, it is difficult for
40666the @value{GDBN} maintainers to keep up with the changes.
40667@item
40668Since individual variants may have short lifetimes or limited
40669audiences, it may not be worthwhile to carry information about every
40670variant in the @value{GDBN} source tree.
40671@item
40672When @value{GDBN} does support the architecture of the embedded system
40673at hand, the task of finding the correct architecture name to give the
40674@command{set architecture} command can be error-prone.
40675@end itemize
40676
40677To address these problems, the @value{GDBN} remote protocol allows a
40678target system to not only identify itself to @value{GDBN}, but to
40679actually describe its own features. This lets @value{GDBN} support
40680processor variants it has never seen before --- to the extent that the
40681descriptions are accurate, and that @value{GDBN} understands them.
40682
9cceb671
DJ
40683@value{GDBN} must be linked with the Expat library to support XML
40684target descriptions. @xref{Expat}.
123dc839 40685
23181151
DJ
40686@menu
40687* Retrieving Descriptions:: How descriptions are fetched from a target.
40688* Target Description Format:: The contents of a target description.
123dc839
DJ
40689* Predefined Target Types:: Standard types available for target
40690 descriptions.
40691* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
40692@end menu
40693
40694@node Retrieving Descriptions
40695@section Retrieving Descriptions
40696
40697Target descriptions can be read from the target automatically, or
40698specified by the user manually. The default behavior is to read the
40699description from the target. @value{GDBN} retrieves it via the remote
40700protocol using @samp{qXfer} requests (@pxref{General Query Packets,
40701qXfer}). The @var{annex} in the @samp{qXfer} packet will be
40702@samp{target.xml}. The contents of the @samp{target.xml} annex are an
40703XML document, of the form described in @ref{Target Description
40704Format}.
40705
40706Alternatively, you can specify a file to read for the target description.
40707If a file is set, the target will not be queried. The commands to
40708specify a file are:
40709
40710@table @code
40711@cindex set tdesc filename
40712@item set tdesc filename @var{path}
40713Read the target description from @var{path}.
40714
40715@cindex unset tdesc filename
40716@item unset tdesc filename
40717Do not read the XML target description from a file. @value{GDBN}
40718will use the description supplied by the current target.
40719
40720@cindex show tdesc filename
40721@item show tdesc filename
40722Show the filename to read for a target description, if any.
40723@end table
40724
40725
40726@node Target Description Format
40727@section Target Description Format
40728@cindex target descriptions, XML format
40729
40730A target description annex is an @uref{http://www.w3.org/XML/, XML}
40731document which complies with the Document Type Definition provided in
40732the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
40733means you can use generally available tools like @command{xmllint} to
40734check that your feature descriptions are well-formed and valid.
40735However, to help people unfamiliar with XML write descriptions for
40736their targets, we also describe the grammar here.
40737
123dc839
DJ
40738Target descriptions can identify the architecture of the remote target
40739and (for some architectures) provide information about custom register
08d16641
PA
40740sets. They can also identify the OS ABI of the remote target.
40741@value{GDBN} can use this information to autoconfigure for your
123dc839 40742target, or to warn you if you connect to an unsupported target.
23181151
DJ
40743
40744Here is a simple target description:
40745
123dc839 40746@smallexample
1780a0ed 40747<target version="1.0">
23181151
DJ
40748 <architecture>i386:x86-64</architecture>
40749</target>
123dc839 40750@end smallexample
23181151
DJ
40751
40752@noindent
40753This minimal description only says that the target uses
40754the x86-64 architecture.
40755
123dc839
DJ
40756A target description has the following overall form, with [ ] marking
40757optional elements and @dots{} marking repeatable elements. The elements
40758are explained further below.
23181151 40759
123dc839 40760@smallexample
23181151
DJ
40761<?xml version="1.0"?>
40762<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 40763<target version="1.0">
123dc839 40764 @r{[}@var{architecture}@r{]}
08d16641 40765 @r{[}@var{osabi}@r{]}
e35359c5 40766 @r{[}@var{compatible}@r{]}
123dc839 40767 @r{[}@var{feature}@dots{}@r{]}
23181151 40768</target>
123dc839 40769@end smallexample
23181151
DJ
40770
40771@noindent
40772The description is generally insensitive to whitespace and line
40773breaks, under the usual common-sense rules. The XML version
40774declaration and document type declaration can generally be omitted
40775(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
40776useful for XML validation tools. The @samp{version} attribute for
40777@samp{<target>} may also be omitted, but we recommend
40778including it; if future versions of @value{GDBN} use an incompatible
40779revision of @file{gdb-target.dtd}, they will detect and report
40780the version mismatch.
23181151 40781
108546a0
DJ
40782@subsection Inclusion
40783@cindex target descriptions, inclusion
40784@cindex XInclude
40785@ifnotinfo
40786@cindex <xi:include>
40787@end ifnotinfo
40788
40789It can sometimes be valuable to split a target description up into
40790several different annexes, either for organizational purposes, or to
40791share files between different possible target descriptions. You can
40792divide a description into multiple files by replacing any element of
40793the target description with an inclusion directive of the form:
40794
123dc839 40795@smallexample
108546a0 40796<xi:include href="@var{document}"/>
123dc839 40797@end smallexample
108546a0
DJ
40798
40799@noindent
40800When @value{GDBN} encounters an element of this form, it will retrieve
40801the named XML @var{document}, and replace the inclusion directive with
40802the contents of that document. If the current description was read
40803using @samp{qXfer}, then so will be the included document;
40804@var{document} will be interpreted as the name of an annex. If the
40805current description was read from a file, @value{GDBN} will look for
40806@var{document} as a file in the same directory where it found the
40807original description.
40808
123dc839
DJ
40809@subsection Architecture
40810@cindex <architecture>
40811
40812An @samp{<architecture>} element has this form:
40813
40814@smallexample
40815 <architecture>@var{arch}</architecture>
40816@end smallexample
40817
e35359c5
UW
40818@var{arch} is one of the architectures from the set accepted by
40819@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
123dc839 40820
08d16641
PA
40821@subsection OS ABI
40822@cindex @code{<osabi>}
40823
40824This optional field was introduced in @value{GDBN} version 7.0.
40825Previous versions of @value{GDBN} ignore it.
40826
40827An @samp{<osabi>} element has this form:
40828
40829@smallexample
40830 <osabi>@var{abi-name}</osabi>
40831@end smallexample
40832
40833@var{abi-name} is an OS ABI name from the same selection accepted by
40834@w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
40835
e35359c5
UW
40836@subsection Compatible Architecture
40837@cindex @code{<compatible>}
40838
40839This optional field was introduced in @value{GDBN} version 7.0.
40840Previous versions of @value{GDBN} ignore it.
40841
40842A @samp{<compatible>} element has this form:
40843
40844@smallexample
40845 <compatible>@var{arch}</compatible>
40846@end smallexample
40847
40848@var{arch} is one of the architectures from the set accepted by
40849@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
40850
40851A @samp{<compatible>} element is used to specify that the target
40852is able to run binaries in some other than the main target architecture
40853given by the @samp{<architecture>} element. For example, on the
40854Cell Broadband Engine, the main architecture is @code{powerpc:common}
40855or @code{powerpc:common64}, but the system is able to run binaries
40856in the @code{spu} architecture as well. The way to describe this
40857capability with @samp{<compatible>} is as follows:
40858
40859@smallexample
40860 <architecture>powerpc:common</architecture>
40861 <compatible>spu</compatible>
40862@end smallexample
40863
123dc839
DJ
40864@subsection Features
40865@cindex <feature>
40866
40867Each @samp{<feature>} describes some logical portion of the target
40868system. Features are currently used to describe available CPU
40869registers and the types of their contents. A @samp{<feature>} element
40870has this form:
40871
40872@smallexample
40873<feature name="@var{name}">
40874 @r{[}@var{type}@dots{}@r{]}
40875 @var{reg}@dots{}
40876</feature>
40877@end smallexample
40878
40879@noindent
40880Each feature's name should be unique within the description. The name
40881of a feature does not matter unless @value{GDBN} has some special
40882knowledge of the contents of that feature; if it does, the feature
40883should have its standard name. @xref{Standard Target Features}.
40884
40885@subsection Types
40886
40887Any register's value is a collection of bits which @value{GDBN} must
40888interpret. The default interpretation is a two's complement integer,
40889but other types can be requested by name in the register description.
40890Some predefined types are provided by @value{GDBN} (@pxref{Predefined
40891Target Types}), and the description can define additional composite types.
40892
40893Each type element must have an @samp{id} attribute, which gives
40894a unique (within the containing @samp{<feature>}) name to the type.
40895Types must be defined before they are used.
40896
40897@cindex <vector>
40898Some targets offer vector registers, which can be treated as arrays
40899of scalar elements. These types are written as @samp{<vector>} elements,
40900specifying the array element type, @var{type}, and the number of elements,
40901@var{count}:
40902
40903@smallexample
40904<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
40905@end smallexample
40906
40907@cindex <union>
40908If a register's value is usefully viewed in multiple ways, define it
40909with a union type containing the useful representations. The
40910@samp{<union>} element contains one or more @samp{<field>} elements,
40911each of which has a @var{name} and a @var{type}:
40912
40913@smallexample
40914<union id="@var{id}">
40915 <field name="@var{name}" type="@var{type}"/>
40916 @dots{}
40917</union>
40918@end smallexample
40919
f5dff777
DJ
40920@cindex <struct>
40921If a register's value is composed from several separate values, define
40922it with a structure type. There are two forms of the @samp{<struct>}
40923element; a @samp{<struct>} element must either contain only bitfields
40924or contain no bitfields. If the structure contains only bitfields,
40925its total size in bytes must be specified, each bitfield must have an
40926explicit start and end, and bitfields are automatically assigned an
40927integer type. The field's @var{start} should be less than or
40928equal to its @var{end}, and zero represents the least significant bit.
40929
40930@smallexample
40931<struct id="@var{id}" size="@var{size}">
40932 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
40933 @dots{}
40934</struct>
40935@end smallexample
40936
40937If the structure contains no bitfields, then each field has an
40938explicit type, and no implicit padding is added.
40939
40940@smallexample
40941<struct id="@var{id}">
40942 <field name="@var{name}" type="@var{type}"/>
40943 @dots{}
40944</struct>
40945@end smallexample
40946
40947@cindex <flags>
40948If a register's value is a series of single-bit flags, define it with
40949a flags type. The @samp{<flags>} element has an explicit @var{size}
40950and contains one or more @samp{<field>} elements. Each field has a
40951@var{name}, a @var{start}, and an @var{end}. Only single-bit flags
40952are supported.
40953
40954@smallexample
40955<flags id="@var{id}" size="@var{size}">
40956 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
40957 @dots{}
40958</flags>
40959@end smallexample
40960
123dc839
DJ
40961@subsection Registers
40962@cindex <reg>
40963
40964Each register is represented as an element with this form:
40965
40966@smallexample
40967<reg name="@var{name}"
40968 bitsize="@var{size}"
40969 @r{[}regnum="@var{num}"@r{]}
40970 @r{[}save-restore="@var{save-restore}"@r{]}
40971 @r{[}type="@var{type}"@r{]}
40972 @r{[}group="@var{group}"@r{]}/>
40973@end smallexample
40974
40975@noindent
40976The components are as follows:
40977
40978@table @var
40979
40980@item name
40981The register's name; it must be unique within the target description.
40982
40983@item bitsize
40984The register's size, in bits.
40985
40986@item regnum
40987The register's number. If omitted, a register's number is one greater
40988than that of the previous register (either in the current feature or in
177b42fe 40989a preceding feature); the first register in the target description
123dc839
DJ
40990defaults to zero. This register number is used to read or write
40991the register; e.g.@: it is used in the remote @code{p} and @code{P}
40992packets, and registers appear in the @code{g} and @code{G} packets
40993in order of increasing register number.
40994
40995@item save-restore
40996Whether the register should be preserved across inferior function
40997calls; this must be either @code{yes} or @code{no}. The default is
40998@code{yes}, which is appropriate for most registers except for
40999some system control registers; this is not related to the target's
41000ABI.
41001
41002@item type
41003The type of the register. @var{type} may be a predefined type, a type
41004defined in the current feature, or one of the special types @code{int}
41005and @code{float}. @code{int} is an integer type of the correct size
41006for @var{bitsize}, and @code{float} is a floating point type (in the
41007architecture's normal floating point format) of the correct size for
41008@var{bitsize}. The default is @code{int}.
41009
41010@item group
41011The register group to which this register belongs. @var{group} must
41012be either @code{general}, @code{float}, or @code{vector}. If no
41013@var{group} is specified, @value{GDBN} will not display the register
41014in @code{info registers}.
41015
41016@end table
41017
41018@node Predefined Target Types
41019@section Predefined Target Types
41020@cindex target descriptions, predefined types
41021
41022Type definitions in the self-description can build up composite types
41023from basic building blocks, but can not define fundamental types. Instead,
41024standard identifiers are provided by @value{GDBN} for the fundamental
41025types. The currently supported types are:
41026
41027@table @code
41028
41029@item int8
41030@itemx int16
41031@itemx int32
41032@itemx int64
7cc46491 41033@itemx int128
123dc839
DJ
41034Signed integer types holding the specified number of bits.
41035
41036@item uint8
41037@itemx uint16
41038@itemx uint32
41039@itemx uint64
7cc46491 41040@itemx uint128
123dc839
DJ
41041Unsigned integer types holding the specified number of bits.
41042
41043@item code_ptr
41044@itemx data_ptr
41045Pointers to unspecified code and data. The program counter and
41046any dedicated return address register may be marked as code
41047pointers; printing a code pointer converts it into a symbolic
41048address. The stack pointer and any dedicated address registers
41049may be marked as data pointers.
41050
6e3bbd1a
PB
41051@item ieee_single
41052Single precision IEEE floating point.
41053
41054@item ieee_double
41055Double precision IEEE floating point.
41056
123dc839
DJ
41057@item arm_fpa_ext
41058The 12-byte extended precision format used by ARM FPA registers.
41059
075b51b7
L
41060@item i387_ext
41061The 10-byte extended precision format used by x87 registers.
41062
41063@item i386_eflags
4106432bit @sc{eflags} register used by x86.
41065
41066@item i386_mxcsr
4106732bit @sc{mxcsr} register used by x86.
41068
123dc839
DJ
41069@end table
41070
41071@node Standard Target Features
41072@section Standard Target Features
41073@cindex target descriptions, standard features
41074
41075A target description must contain either no registers or all the
41076target's registers. If the description contains no registers, then
41077@value{GDBN} will assume a default register layout, selected based on
41078the architecture. If the description contains any registers, the
41079default layout will not be used; the standard registers must be
41080described in the target description, in such a way that @value{GDBN}
41081can recognize them.
41082
41083This is accomplished by giving specific names to feature elements
41084which contain standard registers. @value{GDBN} will look for features
41085with those names and verify that they contain the expected registers;
41086if any known feature is missing required registers, or if any required
41087feature is missing, @value{GDBN} will reject the target
41088description. You can add additional registers to any of the
41089standard features --- @value{GDBN} will display them just as if
41090they were added to an unrecognized feature.
41091
41092This section lists the known features and their expected contents.
41093Sample XML documents for these features are included in the
41094@value{GDBN} source tree, in the directory @file{gdb/features}.
41095
41096Names recognized by @value{GDBN} should include the name of the
41097company or organization which selected the name, and the overall
41098architecture to which the feature applies; so e.g.@: the feature
41099containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
41100
ff6f572f
DJ
41101The names of registers are not case sensitive for the purpose
41102of recognizing standard features, but @value{GDBN} will only display
41103registers using the capitalization used in the description.
41104
e9c17194 41105@menu
430ed3f0 41106* AArch64 Features::
e9c17194 41107* ARM Features::
3bb8d5c3 41108* i386 Features::
1e26b4f8 41109* MIPS Features::
e9c17194 41110* M68K Features::
1e26b4f8 41111* PowerPC Features::
224bbe49 41112* TIC6x Features::
e9c17194
VP
41113@end menu
41114
41115
430ed3f0
MS
41116@node AArch64 Features
41117@subsection AArch64 Features
41118@cindex target descriptions, AArch64 features
41119
41120The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
41121targets. It should contain registers @samp{x0} through @samp{x30},
41122@samp{sp}, @samp{pc}, and @samp{cpsr}.
41123
41124The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
41125it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
41126and @samp{fpcr}.
41127
e9c17194 41128@node ARM Features
123dc839
DJ
41129@subsection ARM Features
41130@cindex target descriptions, ARM features
41131
9779414d
DJ
41132The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
41133ARM targets.
123dc839
DJ
41134It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
41135@samp{lr}, @samp{pc}, and @samp{cpsr}.
41136
9779414d
DJ
41137For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
41138feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
41139registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
41140and @samp{xpsr}.
41141
123dc839
DJ
41142The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
41143should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
41144
ff6f572f
DJ
41145The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
41146it should contain at least registers @samp{wR0} through @samp{wR15} and
41147@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
41148@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 41149
58d6951d
DJ
41150The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
41151should contain at least registers @samp{d0} through @samp{d15}. If
41152they are present, @samp{d16} through @samp{d31} should also be included.
41153@value{GDBN} will synthesize the single-precision registers from
41154halves of the double-precision registers.
41155
41156The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
41157need to contain registers; it instructs @value{GDBN} to display the
41158VFP double-precision registers as vectors and to synthesize the
41159quad-precision registers from pairs of double-precision registers.
41160If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
41161be present and include 32 double-precision registers.
41162
3bb8d5c3
L
41163@node i386 Features
41164@subsection i386 Features
41165@cindex target descriptions, i386 features
41166
41167The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
41168targets. It should describe the following registers:
41169
41170@itemize @minus
41171@item
41172@samp{eax} through @samp{edi} plus @samp{eip} for i386
41173@item
41174@samp{rax} through @samp{r15} plus @samp{rip} for amd64
41175@item
41176@samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
41177@samp{fs}, @samp{gs}
41178@item
41179@samp{st0} through @samp{st7}
41180@item
41181@samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
41182@samp{foseg}, @samp{fooff} and @samp{fop}
41183@end itemize
41184
41185The register sets may be different, depending on the target.
41186
3a13a53b 41187The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
3bb8d5c3
L
41188describe registers:
41189
41190@itemize @minus
41191@item
41192@samp{xmm0} through @samp{xmm7} for i386
41193@item
41194@samp{xmm0} through @samp{xmm15} for amd64
41195@item
41196@samp{mxcsr}
41197@end itemize
41198
3a13a53b
L
41199The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
41200@samp{org.gnu.gdb.i386.sse} feature. It should
f68eb612
L
41201describe the upper 128 bits of @sc{ymm} registers:
41202
41203@itemize @minus
41204@item
41205@samp{ymm0h} through @samp{ymm7h} for i386
41206@item
41207@samp{ymm0h} through @samp{ymm15h} for amd64
f68eb612
L
41208@end itemize
41209
3bb8d5c3
L
41210The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
41211describe a single register, @samp{orig_eax}.
41212
1e26b4f8 41213@node MIPS Features
eb17f351
EZ
41214@subsection @acronym{MIPS} Features
41215@cindex target descriptions, @acronym{MIPS} features
f8b73d13 41216
eb17f351 41217The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
f8b73d13
DJ
41218It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
41219@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
41220on the target.
41221
41222The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
41223contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
41224registers. They may be 32-bit or 64-bit depending on the target.
41225
41226The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
41227it may be optional in a future version of @value{GDBN}. It should
41228contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
41229@samp{fir}. They may be 32-bit or 64-bit depending on the target.
41230
1faeff08
MR
41231The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
41232contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
41233@samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
41234be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
41235
822b6570
DJ
41236The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
41237contain a single register, @samp{restart}, which is used by the
41238Linux kernel to control restartable syscalls.
41239
e9c17194
VP
41240@node M68K Features
41241@subsection M68K Features
41242@cindex target descriptions, M68K features
41243
41244@table @code
41245@item @samp{org.gnu.gdb.m68k.core}
41246@itemx @samp{org.gnu.gdb.coldfire.core}
41247@itemx @samp{org.gnu.gdb.fido.core}
41248One of those features must be always present.
249e1128 41249The feature that is present determines which flavor of m68k is
e9c17194
VP
41250used. The feature that is present should contain registers
41251@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
41252@samp{sp}, @samp{ps} and @samp{pc}.
41253
41254@item @samp{org.gnu.gdb.coldfire.fp}
41255This feature is optional. If present, it should contain registers
41256@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
41257@samp{fpiaddr}.
41258@end table
41259
1e26b4f8 41260@node PowerPC Features
7cc46491
DJ
41261@subsection PowerPC Features
41262@cindex target descriptions, PowerPC features
41263
41264The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
41265targets. It should contain registers @samp{r0} through @samp{r31},
41266@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
41267@samp{xer}. They may be 32-bit or 64-bit depending on the target.
41268
41269The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
41270contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
41271
41272The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
41273contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
41274and @samp{vrsave}.
41275
677c5bb1
LM
41276The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
41277contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN}
41278will combine these registers with the floating point registers
41279(@samp{f0} through @samp{f31}) and the altivec registers (@samp{vr0}
aeac0ff9 41280through @samp{vr31}) to present the 128-bit wide registers @samp{vs0}
677c5bb1
LM
41281through @samp{vs63}, the set of vector registers for POWER7.
41282
7cc46491
DJ
41283The @samp{org.gnu.gdb.power.spe} feature is optional. It should
41284contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
41285@samp{spefscr}. SPE targets should provide 32-bit registers in
41286@samp{org.gnu.gdb.power.core} and provide the upper halves in
41287@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
41288these to present registers @samp{ev0} through @samp{ev31} to the
41289user.
41290
224bbe49
YQ
41291@node TIC6x Features
41292@subsection TMS320C6x Features
41293@cindex target descriptions, TIC6x features
41294@cindex target descriptions, TMS320C6x features
41295The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
41296targets. It should contain registers @samp{A0} through @samp{A15},
41297registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
41298
41299The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
41300contain registers @samp{A16} through @samp{A31} and @samp{B16}
41301through @samp{B31}.
41302
41303The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
41304contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
41305
07e059b5
VP
41306@node Operating System Information
41307@appendix Operating System Information
41308@cindex operating system information
41309
41310@menu
41311* Process list::
41312@end menu
41313
41314Users of @value{GDBN} often wish to obtain information about the state of
41315the operating system running on the target---for example the list of
41316processes, or the list of open files. This section describes the
41317mechanism that makes it possible. This mechanism is similar to the
41318target features mechanism (@pxref{Target Descriptions}), but focuses
41319on a different aspect of target.
41320
41321Operating system information is retrived from the target via the
41322remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
41323read}). The object name in the request should be @samp{osdata}, and
41324the @var{annex} identifies the data to be fetched.
41325
41326@node Process list
41327@appendixsection Process list
41328@cindex operating system information, process list
41329
41330When requesting the process list, the @var{annex} field in the
41331@samp{qXfer} request should be @samp{processes}. The returned data is
41332an XML document. The formal syntax of this document is defined in
41333@file{gdb/features/osdata.dtd}.
41334
41335An example document is:
41336
41337@smallexample
41338<?xml version="1.0"?>
41339<!DOCTYPE target SYSTEM "osdata.dtd">
41340<osdata type="processes">
41341 <item>
41342 <column name="pid">1</column>
41343 <column name="user">root</column>
41344 <column name="command">/sbin/init</column>
dc146f7c 41345 <column name="cores">1,2,3</column>
07e059b5
VP
41346 </item>
41347</osdata>
41348@end smallexample
41349
41350Each item should include a column whose name is @samp{pid}. The value
41351of that column should identify the process on the target. The
41352@samp{user} and @samp{command} columns are optional, and will be
dc146f7c
VP
41353displayed by @value{GDBN}. The @samp{cores} column, if present,
41354should contain a comma-separated list of cores that this process
41355is running on. Target may provide additional columns,
07e059b5
VP
41356which @value{GDBN} currently ignores.
41357
05c8c3f5
TT
41358@node Trace File Format
41359@appendix Trace File Format
41360@cindex trace file format
41361
41362The trace file comes in three parts: a header, a textual description
41363section, and a trace frame section with binary data.
41364
41365The header has the form @code{\x7fTRACE0\n}. The first byte is
41366@code{0x7f} so as to indicate that the file contains binary data,
41367while the @code{0} is a version number that may have different values
41368in the future.
41369
41370The description section consists of multiple lines of @sc{ascii} text
41371separated by newline characters (@code{0xa}). The lines may include a
41372variety of optional descriptive or context-setting information, such
41373as tracepoint definitions or register set size. @value{GDBN} will
41374ignore any line that it does not recognize. An empty line marks the end
41375of this section.
41376
41377@c FIXME add some specific types of data
41378
41379The trace frame section consists of a number of consecutive frames.
41380Each frame begins with a two-byte tracepoint number, followed by a
41381four-byte size giving the amount of data in the frame. The data in
41382the frame consists of a number of blocks, each introduced by a
41383character indicating its type (at least register, memory, and trace
41384state variable). The data in this section is raw binary, not a
41385hexadecimal or other encoding; its endianness matches the target's
41386endianness.
41387
41388@c FIXME bi-arch may require endianness/arch info in description section
41389
41390@table @code
41391@item R @var{bytes}
41392Register block. The number and ordering of bytes matches that of a
41393@code{g} packet in the remote protocol. Note that these are the
41394actual bytes, in target order and @value{GDBN} register order, not a
41395hexadecimal encoding.
41396
41397@item M @var{address} @var{length} @var{bytes}...
41398Memory block. This is a contiguous block of memory, at the 8-byte
41399address @var{address}, with a 2-byte length @var{length}, followed by
41400@var{length} bytes.
41401
41402@item V @var{number} @var{value}
41403Trace state variable block. This records the 8-byte signed value
41404@var{value} of trace state variable numbered @var{number}.
41405
41406@end table
41407
41408Future enhancements of the trace file format may include additional types
41409of blocks.
41410
90476074
TT
41411@node Index Section Format
41412@appendix @code{.gdb_index} section format
41413@cindex .gdb_index section format
41414@cindex index section format
41415
41416This section documents the index section that is created by @code{save
41417gdb-index} (@pxref{Index Files}). The index section is
41418DWARF-specific; some knowledge of DWARF is assumed in this
41419description.
41420
41421The mapped index file format is designed to be directly
41422@code{mmap}able on any architecture. In most cases, a datum is
41423represented using a little-endian 32-bit integer value, called an
41424@code{offset_type}. Big endian machines must byte-swap the values
41425before using them. Exceptions to this rule are noted. The data is
41426laid out such that alignment is always respected.
41427
41428A mapped index consists of several areas, laid out in order.
41429
41430@enumerate
41431@item
41432The file header. This is a sequence of values, of @code{offset_type}
41433unless otherwise noted:
41434
41435@enumerate
41436@item
796a7ff8 41437The version number, currently 8. Versions 1, 2 and 3 are obsolete.
481860b3 41438Version 4 uses a different hashing function from versions 5 and 6.
b6ba681c
TT
41439Version 6 includes symbols for inlined functions, whereas versions 4
41440and 5 do not. Version 7 adds attributes to the CU indices in the
796a7ff8
DE
41441symbol table. Version 8 specifies that symbols from DWARF type units
41442(@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
41443compilation unit (@samp{DW_TAG_comp_unit}) using the type.
41444
41445@value{GDBN} will only read version 4, 5, or 6 indices
e615022a 41446by specifying @code{set use-deprecated-index-sections on}.
796a7ff8
DE
41447GDB has a workaround for potentially broken version 7 indices so it is
41448currently not flagged as deprecated.
90476074
TT
41449
41450@item
41451The offset, from the start of the file, of the CU list.
41452
41453@item
41454The offset, from the start of the file, of the types CU list. Note
41455that this area can be empty, in which case this offset will be equal
41456to the next offset.
41457
41458@item
41459The offset, from the start of the file, of the address area.
41460
41461@item
41462The offset, from the start of the file, of the symbol table.
41463
41464@item
41465The offset, from the start of the file, of the constant pool.
41466@end enumerate
41467
41468@item
41469The CU list. This is a sequence of pairs of 64-bit little-endian
41470values, sorted by the CU offset. The first element in each pair is
41471the offset of a CU in the @code{.debug_info} section. The second
41472element in each pair is the length of that CU. References to a CU
41473elsewhere in the map are done using a CU index, which is just the
414740-based index into this table. Note that if there are type CUs, then
41475conceptually CUs and type CUs form a single list for the purposes of
41476CU indices.
41477
41478@item
41479The types CU list. This is a sequence of triplets of 64-bit
41480little-endian values. In a triplet, the first value is the CU offset,
41481the second value is the type offset in the CU, and the third value is
41482the type signature. The types CU list is not sorted.
41483
41484@item
41485The address area. The address area consists of a sequence of address
41486entries. Each address entry has three elements:
41487
41488@enumerate
41489@item
41490The low address. This is a 64-bit little-endian value.
41491
41492@item
41493The high address. This is a 64-bit little-endian value. Like
41494@code{DW_AT_high_pc}, the value is one byte beyond the end.
41495
41496@item
41497The CU index. This is an @code{offset_type} value.
41498@end enumerate
41499
41500@item
41501The symbol table. This is an open-addressed hash table. The size of
41502the hash table is always a power of 2.
41503
41504Each slot in the hash table consists of a pair of @code{offset_type}
41505values. The first value is the offset of the symbol's name in the
41506constant pool. The second value is the offset of the CU vector in the
41507constant pool.
41508
41509If both values are 0, then this slot in the hash table is empty. This
41510is ok because while 0 is a valid constant pool index, it cannot be a
41511valid index for both a string and a CU vector.
41512
41513The hash value for a table entry is computed by applying an
41514iterative hash function to the symbol's name. Starting with an
41515initial value of @code{r = 0}, each (unsigned) character @samp{c} in
559a7a62
JK
41516the string is incorporated into the hash using the formula depending on the
41517index version:
41518
41519@table @asis
41520@item Version 4
41521The formula is @code{r = r * 67 + c - 113}.
41522
156942c7 41523@item Versions 5 to 7
559a7a62
JK
41524The formula is @code{r = r * 67 + tolower (c) - 113}.
41525@end table
41526
41527The terminating @samp{\0} is not incorporated into the hash.
90476074
TT
41528
41529The step size used in the hash table is computed via
41530@code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
41531value, and @samp{size} is the size of the hash table. The step size
41532is used to find the next candidate slot when handling a hash
41533collision.
41534
41535The names of C@t{++} symbols in the hash table are canonicalized. We
41536don't currently have a simple description of the canonicalization
41537algorithm; if you intend to create new index sections, you must read
41538the code.
41539
41540@item
41541The constant pool. This is simply a bunch of bytes. It is organized
41542so that alignment is correct: CU vectors are stored first, followed by
41543strings.
41544
41545A CU vector in the constant pool is a sequence of @code{offset_type}
41546values. The first value is the number of CU indices in the vector.
156942c7
DE
41547Each subsequent value is the index and symbol attributes of a CU in
41548the CU list. This element in the hash table is used to indicate which
41549CUs define the symbol and how the symbol is used.
41550See below for the format of each CU index+attributes entry.
90476074
TT
41551
41552A string in the constant pool is zero-terminated.
41553@end enumerate
41554
156942c7
DE
41555Attributes were added to CU index values in @code{.gdb_index} version 7.
41556If a symbol has multiple uses within a CU then there is one
41557CU index+attributes value for each use.
41558
41559The format of each CU index+attributes entry is as follows
41560(bit 0 = LSB):
41561
41562@table @asis
41563
41564@item Bits 0-23
41565This is the index of the CU in the CU list.
41566@item Bits 24-27
41567These bits are reserved for future purposes and must be zero.
41568@item Bits 28-30
41569The kind of the symbol in the CU.
41570
41571@table @asis
41572@item 0
41573This value is reserved and should not be used.
41574By reserving zero the full @code{offset_type} value is backwards compatible
41575with previous versions of the index.
41576@item 1
41577The symbol is a type.
41578@item 2
41579The symbol is a variable or an enum value.
41580@item 3
41581The symbol is a function.
41582@item 4
41583Any other kind of symbol.
41584@item 5,6,7
41585These values are reserved.
41586@end table
41587
41588@item Bit 31
41589This bit is zero if the value is global and one if it is static.
41590
41591The determination of whether a symbol is global or static is complicated.
41592The authorative reference is the file @file{dwarf2read.c} in
41593@value{GDBN} sources.
41594
41595@end table
41596
41597This pseudo-code describes the computation of a symbol's kind and
41598global/static attributes in the index.
41599
41600@smallexample
41601is_external = get_attribute (die, DW_AT_external);
41602language = get_attribute (cu_die, DW_AT_language);
41603switch (die->tag)
41604 @{
41605 case DW_TAG_typedef:
41606 case DW_TAG_base_type:
41607 case DW_TAG_subrange_type:
41608 kind = TYPE;
41609 is_static = 1;
41610 break;
41611 case DW_TAG_enumerator:
41612 kind = VARIABLE;
41613 is_static = (language != CPLUS && language != JAVA);
41614 break;
41615 case DW_TAG_subprogram:
41616 kind = FUNCTION;
41617 is_static = ! (is_external || language == ADA);
41618 break;
41619 case DW_TAG_constant:
41620 kind = VARIABLE;
41621 is_static = ! is_external;
41622 break;
41623 case DW_TAG_variable:
41624 kind = VARIABLE;
41625 is_static = ! is_external;
41626 break;
41627 case DW_TAG_namespace:
41628 kind = TYPE;
41629 is_static = 0;
41630 break;
41631 case DW_TAG_class_type:
41632 case DW_TAG_interface_type:
41633 case DW_TAG_structure_type:
41634 case DW_TAG_union_type:
41635 case DW_TAG_enumeration_type:
41636 kind = TYPE;
41637 is_static = (language != CPLUS && language != JAVA);
41638 break;
41639 default:
41640 assert (0);
41641 @}
41642@end smallexample
41643
aab4e0ec 41644@include gpl.texi
eb12ee30 41645
e4c0cfae
SS
41646@node GNU Free Documentation License
41647@appendix GNU Free Documentation License
6826cf00
EZ
41648@include fdl.texi
41649
00595b5e
EZ
41650@node Concept Index
41651@unnumbered Concept Index
c906108c
SS
41652
41653@printindex cp
41654
00595b5e
EZ
41655@node Command and Variable Index
41656@unnumbered Command, Variable, and Function Index
41657
41658@printindex fn
41659
c906108c 41660@tex
984359d2 41661% I think something like @@colophon should be in texinfo. In the
c906108c
SS
41662% meantime:
41663\long\def\colophon{\hbox to0pt{}\vfill
41664\centerline{The body of this manual is set in}
41665\centerline{\fontname\tenrm,}
41666\centerline{with headings in {\bf\fontname\tenbf}}
41667\centerline{and examples in {\tt\fontname\tentt}.}
41668\centerline{{\it\fontname\tenit\/},}
41669\centerline{{\bf\fontname\tenbf}, and}
41670\centerline{{\sl\fontname\tensl\/}}
41671\centerline{are used for emphasis.}\vfill}
41672\page\colophon
984359d2 41673% Blame: doc@@cygnus.com, 1991.
c906108c
SS
41674@end tex
41675
c906108c 41676@bye
This page took 5.424853 seconds and 4 git commands to generate.